staticint stmpe_24xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns)
{ struct stmpe_pwm *stmpe_pwm = to_stmpe_pwm(chip); unsignedint i, pin;
u16 program[3] = {
SMAX,
GTS,
GTS,
};
u8 offset; int ret;
/* Make sure we are disabled */ if (pwm_is_enabled(pwm)) {
ret = stmpe_24xx_pwm_disable(chip, pwm); if (ret) return ret;
} else { /* Connect the PWM to the pin */
pin = pwm->hwpwm;
/* On STMPE2401 and 2403 pins 21,22,23 are used */ if (stmpe_pwm->stmpe->partnum == STMPE2401 ||
stmpe_pwm->stmpe->partnum == STMPE2403)
pin += STMPE_PWM_24XX_PINBASE;
ret = stmpe_set_altfunc(stmpe_pwm->stmpe, BIT(pin),
STMPE_BLOCK_PWM); if (ret) {
dev_err(pwmchip_parent(chip), "unable to connect PWM#%u to pin\n",
pwm->hwpwm); return ret;
}
}
/* * Counter goes from 0x00 to 0xff repeatedly at 32768 Hz, * (means a period of 30517 ns) then this is compared to the * counter from the ramp, if this is >= PWM counter the output * is high. With LOAD we can define how much of the cycle it * is on. * * Prescale = 0 -> 2 kHz -> T = 1/f = 488281.25 ns
*/
/* Scale to 0..0xff */
duty = duty_ns * 256;
duty = DIV_ROUND_CLOSEST(duty, period_ns);
value = duty;
if (value == last) { /* Run the old program */ if (pwm_is_enabled(pwm))
stmpe_24xx_pwm_enable(chip, pwm);
return 0;
} elseif (stmpe_pwm->stmpe->partnum == STMPE2403) { /* STMPE2403 can simply set the right PWM value */
program[0] = LOAD | value;
program[1] = 0x0000;
} elseif (stmpe_pwm->stmpe->partnum == STMPE2401) { /* STMPE2401 need a complex program */
u16 incdec = 0x0000;
if (last < value) /* Count up */
incdec = RAMPUP | (value - last); else /* Count down */
incdec = RAMPDOWN | (last - value);
/* * stmpe_pwm_remove() lives in .exit.text. For drivers registered via * module_platform_driver_probe() this is ok because they cannot get unbound at * runtime. So mark the driver struct with __refdata to prevent modpost * triggering a section mismatch warning.
*/ staticstruct platform_driver stmpe_pwm_driver __refdata = {
.driver = {
.name = "stmpe-pwm",
},
.remove = __exit_p(stmpe_pwm_remove),
};
module_platform_driver_probe(stmpe_pwm_driver, stmpe_pwm_probe);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.0Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.