aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-fsl-ftm.c
diff options
context:
space:
mode:
authorshenwei.wang@nxp.com <shenwei.wang@nxp.com>2018-06-08 15:22:34 -0400
committerThierry Reding <thierry.reding@gmail.com>2018-07-09 13:04:19 -0400
commit82a9c55a2bb0a47b16c75e93d8ce54e8944758c0 (patch)
tree7b871204f0d87fe7d27cc27acba7e67b7b3bf5ae /drivers/pwm/pwm-fsl-ftm.c
parent4964cb52b27a834ce22e515007a74ba74886074a (diff)
pwm: fsl-ftm: Added a dedicated IP interface clock
The current driver assumes that the ftm_sys clock works as one of the clock sources for the IP block as well as the IP interface clock. This assumption does not apply any more on the latest i.MX8x SoC family. On i.MX8x SoCs, a dedicated IP interface clock is introduced and it must be enabled before accessing any FTM registers. Moreover, the clock can not be used as the source clock for the FTM IP block. This patch introduces the ipg_clk as the dedicated IP interface clock and by default it is the same as the ftm_sys clock if not specified. Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-fsl-ftm.c')
-rw-r--r--drivers/pwm/pwm-fsl-ftm.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c
index 557b4ea16796..bcc55edad9ec 100644
--- a/drivers/pwm/pwm-fsl-ftm.c
+++ b/drivers/pwm/pwm-fsl-ftm.c
@@ -87,6 +87,7 @@ struct fsl_pwm_chip {
87 87
88 int period_ns; 88 int period_ns;
89 89
90 struct clk *ipg_clk;
90 struct clk *clk[FSL_PWM_CLK_MAX]; 91 struct clk *clk[FSL_PWM_CLK_MAX];
91}; 92};
92 93
@@ -99,14 +100,14 @@ static int fsl_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
99{ 100{
100 struct fsl_pwm_chip *fpc = to_fsl_chip(chip); 101 struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
101 102
102 return clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 103 return clk_prepare_enable(fpc->ipg_clk);
103} 104}
104 105
105static void fsl_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 106static void fsl_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
106{ 107{
107 struct fsl_pwm_chip *fpc = to_fsl_chip(chip); 108 struct fsl_pwm_chip *fpc = to_fsl_chip(chip);
108 109
109 clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 110 clk_disable_unprepare(fpc->ipg_clk);
110} 111}
111 112
112static int fsl_pwm_calculate_default_ps(struct fsl_pwm_chip *fpc, 113static int fsl_pwm_calculate_default_ps(struct fsl_pwm_chip *fpc,
@@ -363,7 +364,7 @@ static int fsl_pwm_init(struct fsl_pwm_chip *fpc)
363{ 364{
364 int ret; 365 int ret;
365 366
366 ret = clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 367 ret = clk_prepare_enable(fpc->ipg_clk);
367 if (ret) 368 if (ret)
368 return ret; 369 return ret;
369 370
@@ -371,7 +372,7 @@ static int fsl_pwm_init(struct fsl_pwm_chip *fpc)
371 regmap_write(fpc->regmap, FTM_OUTINIT, 0x00); 372 regmap_write(fpc->regmap, FTM_OUTINIT, 0x00);
372 regmap_write(fpc->regmap, FTM_OUTMASK, 0xFF); 373 regmap_write(fpc->regmap, FTM_OUTMASK, 0xFF);
373 374
374 clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 375 clk_disable_unprepare(fpc->ipg_clk);
375 376
376 return 0; 377 return 0;
377} 378}
@@ -441,6 +442,15 @@ static int fsl_pwm_probe(struct platform_device *pdev)
441 if (IS_ERR(fpc->clk[FSL_PWM_CLK_CNTEN])) 442 if (IS_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]))
442 return PTR_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]); 443 return PTR_ERR(fpc->clk[FSL_PWM_CLK_CNTEN]);
443 444
445 /*
446 * ipg_clk is the interface clock for the IP. If not provided, use the
447 * ftm_sys clock as the default.
448 */
449 fpc->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
450 if (IS_ERR(fpc->ipg_clk))
451 fpc->ipg_clk = fpc->clk[FSL_PWM_CLK_SYS];
452
453
444 fpc->chip.ops = &fsl_pwm_ops; 454 fpc->chip.ops = &fsl_pwm_ops;
445 fpc->chip.of_xlate = of_pwm_xlate_with_flags; 455 fpc->chip.of_xlate = of_pwm_xlate_with_flags;
446 fpc->chip.of_pwm_n_cells = 3; 456 fpc->chip.of_pwm_n_cells = 3;
@@ -480,7 +490,7 @@ static int fsl_pwm_suspend(struct device *dev)
480 if (!test_bit(PWMF_REQUESTED, &pwm->flags)) 490 if (!test_bit(PWMF_REQUESTED, &pwm->flags))
481 continue; 491 continue;
482 492
483 clk_disable_unprepare(fpc->clk[FSL_PWM_CLK_SYS]); 493 clk_disable_unprepare(fpc->ipg_clk);
484 494
485 if (!pwm_is_enabled(pwm)) 495 if (!pwm_is_enabled(pwm))
486 continue; 496 continue;
@@ -503,7 +513,7 @@ static int fsl_pwm_resume(struct device *dev)
503 if (!test_bit(PWMF_REQUESTED, &pwm->flags)) 513 if (!test_bit(PWMF_REQUESTED, &pwm->flags))
504 continue; 514 continue;
505 515
506 clk_prepare_enable(fpc->clk[FSL_PWM_CLK_SYS]); 516 clk_prepare_enable(fpc->ipg_clk);
507 517
508 if (!pwm_is_enabled(pwm)) 518 if (!pwm_is_enabled(pwm))
509 continue; 519 continue;