16 #include <linux/module.h>
17 #include <linux/kernel.h>
19 #include <linux/slab.h>
25 #include <asm/div64.h>
27 #define VT8500_NR_PWMS 4
34 #define to_vt8500_chip(chip) container_of(chip, struct vt8500_chip, chip)
36 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
40 while ((
readb(reg) & bitmask) && --loops)
44 pr_warn(
"Waiting for status bits 0x%x to clear timed out\n",
49 int duty_ns,
int period_ns)
60 if (period_cycles < 1)
62 prescale = (period_cycles - 1) / 4096;
63 pv = period_cycles / (prescale + 1) - 1;
70 c = (
unsigned long long)pv * duty_ns;
74 pwm_busy_wait(vt8500->
base + 0x40 + pwm->
hwpwm, (1 << 1));
77 pwm_busy_wait(vt8500->
base + 0x40 + pwm->
hwpwm, (1 << 2));
80 pwm_busy_wait(vt8500->
base + 0x40 + pwm->
hwpwm, (1 << 3));
90 pwm_busy_wait(vt8500->
base + 0x40 + pwm->
hwpwm, (1 << 0));
99 pwm_busy_wait(vt8500->
base + 0x40 + pwm->
hwpwm, (1 << 0));
103 static struct pwm_ops vt8500_pwm_ops = {
104 .enable = vt8500_pwm_enable,
105 .disable = vt8500_pwm_disable,
106 .config = vt8500_pwm_config,
118 dev_err(&pdev->
dev,
"failed to allocate memory\n");
123 chip->
chip.ops = &vt8500_pwm_ops;
124 chip->
chip.base = -1;
129 dev_err(&pdev->
dev,
"no memory resource defined\n");
141 platform_set_drvdata(pdev, chip);
149 chip = platform_get_drvdata(pdev);
158 .name =
"vt8500-pwm",
165 static int __init pwm_init(
void)
171 static void __exit pwm_exit(
void)