• Home
  • Raw
  • Download

Lines Matching +full:pwm +full:- +full:off +full:- +full:delay +full:- +full:ms

13 #include <linux/delay.h>
19 #include <linux/pwm.h>
43 static int stmpe_24xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in stmpe_24xx_pwm_enable() argument
49 ret = stmpe_reg_read(stmpe_pwm->stmpe, STMPE24XX_PWMCS); in stmpe_24xx_pwm_enable()
51 dev_err(chip->dev, "error reading PWM#%u control\n", in stmpe_24xx_pwm_enable()
52 pwm->hwpwm); in stmpe_24xx_pwm_enable()
56 value = ret | BIT(pwm->hwpwm); in stmpe_24xx_pwm_enable()
58 ret = stmpe_reg_write(stmpe_pwm->stmpe, STMPE24XX_PWMCS, value); in stmpe_24xx_pwm_enable()
60 dev_err(chip->dev, "error writing PWM#%u control\n", in stmpe_24xx_pwm_enable()
61 pwm->hwpwm); in stmpe_24xx_pwm_enable()
69 struct pwm_device *pwm) in stmpe_24xx_pwm_disable() argument
75 ret = stmpe_reg_read(stmpe_pwm->stmpe, STMPE24XX_PWMCS); in stmpe_24xx_pwm_disable()
77 dev_err(chip->dev, "error reading PWM#%u control\n", in stmpe_24xx_pwm_disable()
78 pwm->hwpwm); in stmpe_24xx_pwm_disable()
82 value = ret & ~BIT(pwm->hwpwm); in stmpe_24xx_pwm_disable()
84 ret = stmpe_reg_write(stmpe_pwm->stmpe, STMPE24XX_PWMCS, value); in stmpe_24xx_pwm_disable()
86 dev_err(chip->dev, "error writing PWM#%u control\n", in stmpe_24xx_pwm_disable()
87 pwm->hwpwm); in stmpe_24xx_pwm_disable()
92 /* STMPE 24xx PWM instructions */
103 static int stmpe_24xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in stmpe_24xx_pwm_config() argument
117 if (pwm_is_enabled(pwm)) { in stmpe_24xx_pwm_config()
118 stmpe_24xx_pwm_disable(chip, pwm); in stmpe_24xx_pwm_config()
120 /* Connect the PWM to the pin */ in stmpe_24xx_pwm_config()
121 pin = pwm->hwpwm; in stmpe_24xx_pwm_config()
124 if (stmpe_pwm->stmpe->partnum == STMPE2401 || in stmpe_24xx_pwm_config()
125 stmpe_pwm->stmpe->partnum == STMPE2403) in stmpe_24xx_pwm_config()
128 ret = stmpe_set_altfunc(stmpe_pwm->stmpe, BIT(pin), in stmpe_24xx_pwm_config()
131 dev_err(chip->dev, "unable to connect PWM#%u to pin\n", in stmpe_24xx_pwm_config()
132 pwm->hwpwm); in stmpe_24xx_pwm_config()
138 switch (pwm->hwpwm) { in stmpe_24xx_pwm_config()
153 return -ENODEV; in stmpe_24xx_pwm_config()
156 dev_dbg(chip->dev, "PWM#%u: config duty %d ns, period %d ns\n", in stmpe_24xx_pwm_config()
157 pwm->hwpwm, duty_ns, period_ns); in stmpe_24xx_pwm_config()
160 if (stmpe_pwm->stmpe->partnum == STMPE2401) in stmpe_24xx_pwm_config()
161 program[0] = SMAX; /* off all the time */ in stmpe_24xx_pwm_config()
163 if (stmpe_pwm->stmpe->partnum == STMPE2403) in stmpe_24xx_pwm_config()
166 stmpe_pwm->last_duty = 0x00; in stmpe_24xx_pwm_config()
168 if (stmpe_pwm->stmpe->partnum == STMPE2401) in stmpe_24xx_pwm_config()
171 if (stmpe_pwm->stmpe->partnum == STMPE2403) in stmpe_24xx_pwm_config()
174 stmpe_pwm->last_duty = 0xff; in stmpe_24xx_pwm_config()
176 u8 value, last = stmpe_pwm->last_duty; in stmpe_24xx_pwm_config()
182 * counter from the ramp, if this is >= PWM counter the output in stmpe_24xx_pwm_config()
186 * Prescale = 0 -> 2 kHz -> T = 1/f = 488281.25 ns in stmpe_24xx_pwm_config()
196 if (pwm_is_enabled(pwm)) in stmpe_24xx_pwm_config()
197 stmpe_24xx_pwm_enable(chip, pwm); in stmpe_24xx_pwm_config()
200 } else if (stmpe_pwm->stmpe->partnum == STMPE2403) { in stmpe_24xx_pwm_config()
201 /* STMPE2403 can simply set the right PWM value */ in stmpe_24xx_pwm_config()
204 } else if (stmpe_pwm->stmpe->partnum == STMPE2401) { in stmpe_24xx_pwm_config()
210 incdec = RAMPUP | (value - last); in stmpe_24xx_pwm_config()
213 incdec = RAMPDOWN | (last - value); in stmpe_24xx_pwm_config()
222 dev_dbg(chip->dev, in stmpe_24xx_pwm_config()
223 "PWM#%u: value = %02x, last_duty = %02x, program=%04x,%04x,%04x\n", in stmpe_24xx_pwm_config()
224 pwm->hwpwm, value, last, program[0], program[1], in stmpe_24xx_pwm_config()
226 stmpe_pwm->last_duty = value; in stmpe_24xx_pwm_config()
230 * We can write programs of up to 64 16-bit words into this channel. in stmpe_24xx_pwm_config()
237 ret = stmpe_reg_write(stmpe_pwm->stmpe, offset, value); in stmpe_24xx_pwm_config()
239 dev_err(chip->dev, "error writing register %02x: %d\n", in stmpe_24xx_pwm_config()
246 ret = stmpe_reg_write(stmpe_pwm->stmpe, offset, value); in stmpe_24xx_pwm_config()
248 dev_err(chip->dev, "error writing register %02x: %d\n", in stmpe_24xx_pwm_config()
254 /* If we were enabled, re-enable this PWM */ in stmpe_24xx_pwm_config()
255 if (pwm_is_enabled(pwm)) in stmpe_24xx_pwm_config()
256 stmpe_24xx_pwm_enable(chip, pwm); in stmpe_24xx_pwm_config()
258 /* Sleep for 200ms so we're sure it will take effect */ in stmpe_24xx_pwm_config()
261 dev_dbg(chip->dev, "programmed PWM#%u, %u bytes\n", pwm->hwpwm, i); in stmpe_24xx_pwm_config()
275 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); in stmpe_pwm_probe()
276 struct stmpe_pwm *pwm; in stmpe_pwm_probe() local
279 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); in stmpe_pwm_probe()
280 if (!pwm) in stmpe_pwm_probe()
281 return -ENOMEM; in stmpe_pwm_probe()
283 pwm->stmpe = stmpe; in stmpe_pwm_probe()
284 pwm->chip.dev = &pdev->dev; in stmpe_pwm_probe()
285 pwm->chip.base = -1; in stmpe_pwm_probe()
287 if (stmpe->partnum == STMPE2401 || stmpe->partnum == STMPE2403) { in stmpe_pwm_probe()
288 pwm->chip.ops = &stmpe_24xx_pwm_ops; in stmpe_pwm_probe()
289 pwm->chip.npwm = 3; in stmpe_pwm_probe()
291 if (stmpe->partnum == STMPE1601) in stmpe_pwm_probe()
292 dev_err(&pdev->dev, "STMPE1601 not yet supported\n"); in stmpe_pwm_probe()
294 dev_err(&pdev->dev, "Unknown STMPE PWM\n"); in stmpe_pwm_probe()
296 return -ENODEV; in stmpe_pwm_probe()
303 ret = pwmchip_add(&pwm->chip); in stmpe_pwm_probe()
309 platform_set_drvdata(pdev, pwm); in stmpe_pwm_probe()
316 .name = "stmpe-pwm",