Lines Matching refs:lpc18xx_pwm

116 static inline void lpc18xx_pwm_writel(struct lpc18xx_pwm_chip *lpc18xx_pwm,  in lpc18xx_pwm_writel()  argument
119 writel(val, lpc18xx_pwm->base + reg); in lpc18xx_pwm_writel()
122 static inline u32 lpc18xx_pwm_readl(struct lpc18xx_pwm_chip *lpc18xx_pwm, in lpc18xx_pwm_readl() argument
125 return readl(lpc18xx_pwm->base + reg); in lpc18xx_pwm_readl()
128 static void lpc18xx_pwm_set_conflict_res(struct lpc18xx_pwm_chip *lpc18xx_pwm, in lpc18xx_pwm_set_conflict_res() argument
134 mutex_lock(&lpc18xx_pwm->res_lock); in lpc18xx_pwm_set_conflict_res()
141 val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_RES_BASE); in lpc18xx_pwm_set_conflict_res()
144 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_RES_BASE, val); in lpc18xx_pwm_set_conflict_res()
146 mutex_unlock(&lpc18xx_pwm->res_lock); in lpc18xx_pwm_set_conflict_res()
151 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_config_period() local
160 val = mul_u64_u64_div_u64(period_ns, lpc18xx_pwm->clk_rate, NSEC_PER_SEC); in lpc18xx_pwm_config_period()
162 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_config_period()
163 LPC18XX_PWM_MATCH(lpc18xx_pwm->period_event), in lpc18xx_pwm_config_period()
166 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_config_period()
167 LPC18XX_PWM_MATCHREL(lpc18xx_pwm->period_event), in lpc18xx_pwm_config_period()
174 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_config_duty() local
175 struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; in lpc18xx_pwm_config_duty()
182 val = mul_u64_u64_div_u64(duty_ns, lpc18xx_pwm->clk_rate, NSEC_PER_SEC); in lpc18xx_pwm_config_duty()
184 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_config_duty()
188 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_config_duty()
196 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_config() local
199 if (period_ns < lpc18xx_pwm->min_period_ns || in lpc18xx_pwm_config()
200 period_ns > lpc18xx_pwm->max_period_ns) { in lpc18xx_pwm_config()
205 mutex_lock(&lpc18xx_pwm->period_lock); in lpc18xx_pwm_config()
207 requested_events = bitmap_weight(&lpc18xx_pwm->event_map, in lpc18xx_pwm_config()
215 if (requested_events > 2 && lpc18xx_pwm->period_ns != period_ns && in lpc18xx_pwm_config()
216 lpc18xx_pwm->period_ns) { in lpc18xx_pwm_config()
219 mutex_unlock(&lpc18xx_pwm->period_lock); in lpc18xx_pwm_config()
223 if ((requested_events <= 2 && lpc18xx_pwm->period_ns != period_ns) || in lpc18xx_pwm_config()
224 !lpc18xx_pwm->period_ns) { in lpc18xx_pwm_config()
225 lpc18xx_pwm->period_ns = period_ns; in lpc18xx_pwm_config()
231 mutex_unlock(&lpc18xx_pwm->period_lock); in lpc18xx_pwm_config()
240 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_enable() local
241 struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; in lpc18xx_pwm_enable()
245 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_enable()
250 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_enable()
255 set_event = lpc18xx_pwm->period_event; in lpc18xx_pwm_enable()
260 clear_event = lpc18xx_pwm->period_event; in lpc18xx_pwm_enable()
264 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_OUTPUTSET(pwm->hwpwm), in lpc18xx_pwm_enable()
266 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_OUTPUTCL(pwm->hwpwm), in lpc18xx_pwm_enable()
268 lpc18xx_pwm_set_conflict_res(lpc18xx_pwm, pwm, res_action); in lpc18xx_pwm_enable()
275 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_disable() local
276 struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; in lpc18xx_pwm_disable()
278 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_disable()
280 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_OUTPUTSET(pwm->hwpwm), 0); in lpc18xx_pwm_disable()
281 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_OUTPUTCL(pwm->hwpwm), 0); in lpc18xx_pwm_disable()
286 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_request() local
287 struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; in lpc18xx_pwm_request()
290 event = find_first_zero_bit(&lpc18xx_pwm->event_map, in lpc18xx_pwm_request()
294 dev_err(lpc18xx_pwm->dev, in lpc18xx_pwm_request()
299 set_bit(event, &lpc18xx_pwm->event_map); in lpc18xx_pwm_request()
307 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); in lpc18xx_pwm_free() local
308 struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; in lpc18xx_pwm_free()
310 clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map); in lpc18xx_pwm_free()
355 struct lpc18xx_pwm_chip *lpc18xx_pwm; in lpc18xx_pwm_probe() local
359 lpc18xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*lpc18xx_pwm), in lpc18xx_pwm_probe()
361 if (!lpc18xx_pwm) in lpc18xx_pwm_probe()
364 lpc18xx_pwm->dev = &pdev->dev; in lpc18xx_pwm_probe()
366 lpc18xx_pwm->base = devm_platform_ioremap_resource(pdev, 0); in lpc18xx_pwm_probe()
367 if (IS_ERR(lpc18xx_pwm->base)) in lpc18xx_pwm_probe()
368 return PTR_ERR(lpc18xx_pwm->base); in lpc18xx_pwm_probe()
370 lpc18xx_pwm->pwm_clk = devm_clk_get_enabled(&pdev->dev, "pwm"); in lpc18xx_pwm_probe()
371 if (IS_ERR(lpc18xx_pwm->pwm_clk)) in lpc18xx_pwm_probe()
372 return dev_err_probe(&pdev->dev, PTR_ERR(lpc18xx_pwm->pwm_clk), in lpc18xx_pwm_probe()
375 lpc18xx_pwm->clk_rate = clk_get_rate(lpc18xx_pwm->pwm_clk); in lpc18xx_pwm_probe()
376 if (!lpc18xx_pwm->clk_rate) in lpc18xx_pwm_probe()
383 if (lpc18xx_pwm->clk_rate > NSEC_PER_SEC) in lpc18xx_pwm_probe()
386 mutex_init(&lpc18xx_pwm->res_lock); in lpc18xx_pwm_probe()
387 mutex_init(&lpc18xx_pwm->period_lock); in lpc18xx_pwm_probe()
389 lpc18xx_pwm->max_period_ns = in lpc18xx_pwm_probe()
390 mul_u64_u64_div_u64(NSEC_PER_SEC, LPC18XX_PWM_TIMER_MAX, lpc18xx_pwm->clk_rate); in lpc18xx_pwm_probe()
392 lpc18xx_pwm->min_period_ns = DIV_ROUND_UP(NSEC_PER_SEC, in lpc18xx_pwm_probe()
393 lpc18xx_pwm->clk_rate); in lpc18xx_pwm_probe()
395 lpc18xx_pwm->chip.dev = &pdev->dev; in lpc18xx_pwm_probe()
396 lpc18xx_pwm->chip.ops = &lpc18xx_pwm_ops; in lpc18xx_pwm_probe()
397 lpc18xx_pwm->chip.npwm = LPC18XX_NUM_PWMS; in lpc18xx_pwm_probe()
400 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CONFIG, in lpc18xx_pwm_probe()
407 set_bit(LPC18XX_PWM_EVENT_PERIOD, &lpc18xx_pwm->event_map); in lpc18xx_pwm_probe()
408 lpc18xx_pwm->period_event = LPC18XX_PWM_EVENT_PERIOD; in lpc18xx_pwm_probe()
410 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_probe()
411 LPC18XX_PWM_EVSTATEMSK(lpc18xx_pwm->period_event), in lpc18xx_pwm_probe()
414 val = LPC18XX_PWM_EVCTRL_MATCH(lpc18xx_pwm->period_event) | in lpc18xx_pwm_probe()
416 lpc18xx_pwm_writel(lpc18xx_pwm, in lpc18xx_pwm_probe()
417 LPC18XX_PWM_EVCTRL(lpc18xx_pwm->period_event), val); in lpc18xx_pwm_probe()
419 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT, in lpc18xx_pwm_probe()
420 BIT(lpc18xx_pwm->period_event)); in lpc18xx_pwm_probe()
422 val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL); in lpc18xx_pwm_probe()
427 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val); in lpc18xx_pwm_probe()
429 ret = pwmchip_add(&lpc18xx_pwm->chip); in lpc18xx_pwm_probe()
433 platform_set_drvdata(pdev, lpc18xx_pwm); in lpc18xx_pwm_probe()
440 struct lpc18xx_pwm_chip *lpc18xx_pwm = platform_get_drvdata(pdev); in lpc18xx_pwm_remove() local
443 pwmchip_remove(&lpc18xx_pwm->chip); in lpc18xx_pwm_remove()
445 val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL); in lpc18xx_pwm_remove()
446 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, in lpc18xx_pwm_remove()