--- zzzz-none-000/linux-3.10.107/drivers/pwm/pwm-mxs.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/pwm/pwm-mxs.c 2021-02-04 17:41:59.000000000 +0000 @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -36,6 +35,10 @@ #define PERIOD_CDIV(div) (((div) & 0x7) << 20) #define PERIOD_CDIV_MAX 8 +static const unsigned int cdiv[PERIOD_CDIV_MAX] = { + 1, 2, 4, 8, 16, 64, 256, 1024 +}; + struct mxs_pwm_chip { struct pwm_chip chip; struct clk *clk; @@ -55,13 +58,13 @@ rate = clk_get_rate(mxs->clk); while (1) { - c = rate / (1 << div); + c = rate / cdiv[div]; c = c * period_ns; do_div(c, 1000000000); if (c < PERIOD_PERIOD_MAX) break; div++; - if (div > PERIOD_CDIV_MAX) + if (div >= PERIOD_CDIV_MAX) return -EINVAL; } @@ -74,7 +77,7 @@ * If the PWM channel is disabled, make sure to turn on the clock * before writing the register. Otherwise, keep it enabled. */ - if (!test_bit(PWMF_ENABLED, &pwm->flags)) { + if (!pwm_is_enabled(pwm)) { ret = clk_prepare_enable(mxs->clk); if (ret) return ret; @@ -89,7 +92,7 @@ /* * If the PWM is not enabled, turn the clock off again to save power. */ - if (!test_bit(PWMF_ENABLED, &pwm->flags)) + if (!pwm_is_enabled(pwm)) clk_disable_unprepare(mxs->clk); return 0; @@ -130,7 +133,6 @@ struct device_node *np = pdev->dev.of_node; struct mxs_pwm_chip *mxs; struct resource *res; - struct pinctrl *pinctrl; int ret; mxs = devm_kzalloc(&pdev->dev, sizeof(*mxs), GFP_KERNEL); @@ -142,10 +144,6 @@ if (IS_ERR(mxs->base)) return PTR_ERR(mxs->base); - pinctrl = devm_pinctrl_get_select_default(&pdev->dev); - if (IS_ERR(pinctrl)) - return PTR_ERR(pinctrl); - mxs->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(mxs->clk)) return PTR_ERR(mxs->clk); @@ -153,6 +151,7 @@ mxs->chip.dev = &pdev->dev; mxs->chip.ops = &mxs_pwm_ops; mxs->chip.base = -1; + mxs->chip.can_sleep = true; ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); if (ret < 0) { dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); @@ -167,9 +166,15 @@ platform_set_drvdata(pdev, mxs); - stmp_reset_block(mxs->base); + ret = stmp_reset_block(mxs->base); + if (ret) + goto pwm_remove; return 0; + +pwm_remove: + pwmchip_remove(&mxs->chip); + return ret; } static int mxs_pwm_remove(struct platform_device *pdev) @@ -188,7 +193,7 @@ static struct platform_driver mxs_pwm_driver = { .driver = { .name = "mxs-pwm", - .of_match_table = of_match_ptr(mxs_pwm_dt_ids), + .of_match_table = mxs_pwm_dt_ids, }, .probe = mxs_pwm_probe, .remove = mxs_pwm_remove,