diff options
Diffstat (limited to 'drivers/pwm/pwm-lpc32xx.c')
| -rw-r--r-- | drivers/pwm/pwm-lpc32xx.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/drivers/pwm/pwm-lpc32xx.c b/drivers/pwm/pwm-lpc32xx.c index adb87f0c1633..14106440294f 100644 --- a/drivers/pwm/pwm-lpc32xx.c +++ b/drivers/pwm/pwm-lpc32xx.c | |||
| @@ -49,9 +49,24 @@ static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, | |||
| 49 | c = 0; /* 0 set division by 256 */ | 49 | c = 0; /* 0 set division by 256 */ |
| 50 | period_cycles = c; | 50 | period_cycles = c; |
| 51 | 51 | ||
| 52 | /* The duty-cycle value is as follows: | ||
| 53 | * | ||
| 54 | * DUTY-CYCLE HIGH LEVEL | ||
| 55 | * 1 99.9% | ||
| 56 | * 25 90.0% | ||
| 57 | * 128 50.0% | ||
| 58 | * 220 10.0% | ||
| 59 | * 255 0.1% | ||
| 60 | * 0 0.0% | ||
| 61 | * | ||
| 62 | * In other words, the register value is duty-cycle % 256 with | ||
| 63 | * duty-cycle in the range 1-256. | ||
| 64 | */ | ||
| 52 | c = 256 * duty_ns; | 65 | c = 256 * duty_ns; |
| 53 | do_div(c, period_ns); | 66 | do_div(c, period_ns); |
| 54 | duty_cycles = c; | 67 | if (c > 255) |
| 68 | c = 255; | ||
| 69 | duty_cycles = 256 - c; | ||
| 55 | 70 | ||
| 56 | writel(PWM_ENABLE | PWM_RELOADV(period_cycles) | PWM_DUTY(duty_cycles), | 71 | writel(PWM_ENABLE | PWM_RELOADV(period_cycles) | PWM_DUTY(duty_cycles), |
| 57 | lpc32xx->base + (pwm->hwpwm << 2)); | 72 | lpc32xx->base + (pwm->hwpwm << 2)); |
| @@ -106,6 +121,7 @@ static int lpc32xx_pwm_probe(struct platform_device *pdev) | |||
| 106 | lpc32xx->chip.dev = &pdev->dev; | 121 | lpc32xx->chip.dev = &pdev->dev; |
| 107 | lpc32xx->chip.ops = &lpc32xx_pwm_ops; | 122 | lpc32xx->chip.ops = &lpc32xx_pwm_ops; |
| 108 | lpc32xx->chip.npwm = 2; | 123 | lpc32xx->chip.npwm = 2; |
| 124 | lpc32xx->chip.base = -1; | ||
| 109 | 125 | ||
| 110 | ret = pwmchip_add(&lpc32xx->chip); | 126 | ret = pwmchip_add(&lpc32xx->chip); |
| 111 | if (ret < 0) { | 127 | if (ret < 0) { |
| @@ -118,11 +134,14 @@ static int lpc32xx_pwm_probe(struct platform_device *pdev) | |||
| 118 | return 0; | 134 | return 0; |
| 119 | } | 135 | } |
| 120 | 136 | ||
| 121 | static int __devexit lpc32xx_pwm_remove(struct platform_device *pdev) | 137 | static int lpc32xx_pwm_remove(struct platform_device *pdev) |
| 122 | { | 138 | { |
| 123 | struct lpc32xx_pwm_chip *lpc32xx = platform_get_drvdata(pdev); | 139 | struct lpc32xx_pwm_chip *lpc32xx = platform_get_drvdata(pdev); |
| 140 | unsigned int i; | ||
| 141 | |||
| 142 | for (i = 0; i < lpc32xx->chip.npwm; i++) | ||
| 143 | pwm_disable(&lpc32xx->chip.pwms[i]); | ||
| 124 | 144 | ||
| 125 | clk_disable(lpc32xx->clk); | ||
| 126 | return pwmchip_remove(&lpc32xx->chip); | 145 | return pwmchip_remove(&lpc32xx->chip); |
| 127 | } | 146 | } |
| 128 | 147 | ||
| @@ -138,7 +157,7 @@ static struct platform_driver lpc32xx_pwm_driver = { | |||
| 138 | .of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids), | 157 | .of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids), |
| 139 | }, | 158 | }, |
| 140 | .probe = lpc32xx_pwm_probe, | 159 | .probe = lpc32xx_pwm_probe, |
| 141 | .remove = __devexit_p(lpc32xx_pwm_remove), | 160 | .remove = lpc32xx_pwm_remove, |
| 142 | }; | 161 | }; |
| 143 | module_platform_driver(lpc32xx_pwm_driver); | 162 | module_platform_driver(lpc32xx_pwm_driver); |
| 144 | 163 | ||
