Lines Matching +full:multi +full:- +full:channel
39 #define IPROC_PWM_PRESCALE_SHIFT(ch) ((3 - (ch)) * \
57 static void iproc_pwmc_enable(struct iproc_pwmc *ip, unsigned int channel) in iproc_pwmc_enable() argument
61 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_enable()
62 value |= 1 << IPROC_PWM_CTRL_EN_SHIFT(channel); in iproc_pwmc_enable()
63 writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_enable()
69 static void iproc_pwmc_disable(struct iproc_pwmc *ip, unsigned int channel) in iproc_pwmc_disable() argument
73 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_disable()
74 value &= ~(1 << IPROC_PWM_CTRL_EN_SHIFT(channel)); in iproc_pwmc_disable()
75 writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_disable()
85 u64 tmp, multi, rate; in iproc_pwmc_get_state() local
88 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_get_state()
90 if (value & BIT(IPROC_PWM_CTRL_EN_SHIFT(pwm->hwpwm))) in iproc_pwmc_get_state()
91 state->enabled = true; in iproc_pwmc_get_state()
93 state->enabled = false; in iproc_pwmc_get_state()
95 if (value & BIT(IPROC_PWM_CTRL_POLARITY_SHIFT(pwm->hwpwm))) in iproc_pwmc_get_state()
96 state->polarity = PWM_POLARITY_NORMAL; in iproc_pwmc_get_state()
98 state->polarity = PWM_POLARITY_INVERSED; in iproc_pwmc_get_state()
100 rate = clk_get_rate(ip->clk); in iproc_pwmc_get_state()
102 state->period = 0; in iproc_pwmc_get_state()
103 state->duty_cycle = 0; in iproc_pwmc_get_state()
107 value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); in iproc_pwmc_get_state()
108 prescale = value >> IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); in iproc_pwmc_get_state()
111 multi = NSEC_PER_SEC * (prescale + 1); in iproc_pwmc_get_state()
113 value = readl(ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm)); in iproc_pwmc_get_state()
114 tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; in iproc_pwmc_get_state()
115 state->period = div64_u64(tmp, rate); in iproc_pwmc_get_state()
117 value = readl(ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm)); in iproc_pwmc_get_state()
118 tmp = (value & IPROC_PWM_PERIOD_MAX) * multi; in iproc_pwmc_get_state()
119 state->duty_cycle = div64_u64(tmp, rate); in iproc_pwmc_get_state()
130 rate = clk_get_rate(ip->clk); in iproc_pwmc_apply()
146 value = rate * state->period; in iproc_pwmc_apply()
148 value = rate * state->duty_cycle; in iproc_pwmc_apply()
152 return -EINVAL; in iproc_pwmc_apply()
160 return -EINVAL; in iproc_pwmc_apply()
163 iproc_pwmc_disable(ip, pwm->hwpwm); in iproc_pwmc_apply()
166 value = readl(ip->base + IPROC_PWM_PRESCALE_OFFSET); in iproc_pwmc_apply()
167 value &= ~IPROC_PWM_PRESCALE_MASK(pwm->hwpwm); in iproc_pwmc_apply()
168 value |= prescale << IPROC_PWM_PRESCALE_SHIFT(pwm->hwpwm); in iproc_pwmc_apply()
169 writel(value, ip->base + IPROC_PWM_PRESCALE_OFFSET); in iproc_pwmc_apply()
172 writel(period, ip->base + IPROC_PWM_PERIOD_OFFSET(pwm->hwpwm)); in iproc_pwmc_apply()
173 writel(duty, ip->base + IPROC_PWM_DUTY_CYCLE_OFFSET(pwm->hwpwm)); in iproc_pwmc_apply()
176 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_apply()
178 if (state->polarity == PWM_POLARITY_NORMAL) in iproc_pwmc_apply()
179 value |= 1 << IPROC_PWM_CTRL_POLARITY_SHIFT(pwm->hwpwm); in iproc_pwmc_apply()
181 value &= ~(1 << IPROC_PWM_CTRL_POLARITY_SHIFT(pwm->hwpwm)); in iproc_pwmc_apply()
183 writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_apply()
185 if (state->enabled) in iproc_pwmc_apply()
186 iproc_pwmc_enable(ip, pwm->hwpwm); in iproc_pwmc_apply()
205 ip = devm_kzalloc(&pdev->dev, sizeof(*ip), GFP_KERNEL); in iproc_pwmc_probe()
207 return -ENOMEM; in iproc_pwmc_probe()
211 ip->chip.dev = &pdev->dev; in iproc_pwmc_probe()
212 ip->chip.ops = &iproc_pwm_ops; in iproc_pwmc_probe()
213 ip->chip.base = -1; in iproc_pwmc_probe()
214 ip->chip.npwm = 4; in iproc_pwmc_probe()
215 ip->chip.of_xlate = of_pwm_xlate_with_flags; in iproc_pwmc_probe()
216 ip->chip.of_pwm_n_cells = 3; in iproc_pwmc_probe()
219 ip->base = devm_ioremap_resource(&pdev->dev, res); in iproc_pwmc_probe()
220 if (IS_ERR(ip->base)) in iproc_pwmc_probe()
221 return PTR_ERR(ip->base); in iproc_pwmc_probe()
223 ip->clk = devm_clk_get(&pdev->dev, NULL); in iproc_pwmc_probe()
224 if (IS_ERR(ip->clk)) { in iproc_pwmc_probe()
225 dev_err(&pdev->dev, "failed to get clock: %ld\n", in iproc_pwmc_probe()
226 PTR_ERR(ip->clk)); in iproc_pwmc_probe()
227 return PTR_ERR(ip->clk); in iproc_pwmc_probe()
230 ret = clk_prepare_enable(ip->clk); in iproc_pwmc_probe()
232 dev_err(&pdev->dev, "failed to enable clock: %d\n", ret); in iproc_pwmc_probe()
237 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_probe()
239 for (i = 0; i < ip->chip.npwm; i++) { in iproc_pwmc_probe()
244 writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); in iproc_pwmc_probe()
246 ret = pwmchip_add(&ip->chip); in iproc_pwmc_probe()
248 dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); in iproc_pwmc_probe()
249 clk_disable_unprepare(ip->clk); in iproc_pwmc_probe()
259 clk_disable_unprepare(ip->clk); in iproc_pwmc_remove()
261 return pwmchip_remove(&ip->chip); in iproc_pwmc_remove()
265 { .compatible = "brcm,iproc-pwm" },
272 .name = "bcm-iproc-pwm",