From a1f262eda8553e2989b1c556e50966a31cfdf364 Mon Sep 17 00:00:00 2001 From: Liu Ying Date: Fri, 15 Jun 2018 14:09:47 +0800 Subject: MLK-18617-3 pwm: imx: Use 32k clock if it is supplied The PWM in i.MX8qxp MIPI subsystem needs to use the '32k' clock to work properly. This patch gets this clock in the PWM driver and uses it if it is supplied. Signed-off-by: Liu Ying (cherry picked from commit a343cc44ee9aa4be408c51b02176c8d0970a698d) Conflicts: drivers/pwm/pwm-imx.c --- drivers/pwm/pwm-imx.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'drivers/pwm') diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c index e942ab6c2fd3..46ecd46d1ede 100644 --- a/drivers/pwm/pwm-imx.c +++ b/drivers/pwm/pwm-imx.c @@ -51,6 +51,7 @@ struct imx_chip { struct clk *clk_per; struct clk *clk_ipg; + struct clk *clk_32k; void __iomem *mmio_base; @@ -64,17 +65,28 @@ static int imx_pwm_clk_prepare_enable(struct pwm_chip *chip) struct imx_chip *imx = to_imx_chip(chip); int ret; + if (imx->clk_32k) { + ret = clk_prepare_enable(imx->clk_32k); + if (ret) + goto err1; + } + ret = clk_prepare_enable(imx->clk_per); if (ret) - return ret; + goto err2; ret = clk_prepare_enable(imx->clk_ipg); - if (ret) { - clk_disable_unprepare(imx->clk_per); - return ret; - } + if (ret) + goto err3; return 0; +err3: + clk_disable_unprepare(imx->clk_per); +err2: + if (imx->clk_32k) + clk_disable_unprepare(imx->clk_32k); +err1: + return ret; } static void imx_pwm_clk_disable_unprepare(struct pwm_chip *chip) @@ -83,6 +95,8 @@ static void imx_pwm_clk_disable_unprepare(struct pwm_chip *chip) clk_disable_unprepare(imx->clk_ipg); clk_disable_unprepare(imx->clk_per); + if (imx->clk_32k) + clk_disable_unprepare(imx->clk_32k); } static int imx_pwm_config_v1(struct pwm_chip *chip, @@ -319,6 +333,10 @@ static int imx_pwm_probe(struct platform_device *pdev) return PTR_ERR(imx->clk_ipg); } + imx->clk_32k = devm_clk_get(&pdev->dev, "32k"); + if (IS_ERR(imx->clk_32k)) + imx->clk_32k = NULL; + imx->chip.ops = data->ops; imx->chip.dev = &pdev->dev; imx->chip.base = -1; -- cgit v1.2.3