Lines Matching refs:sun4ichip
97 static inline u32 sun4i_pwm_readl(struct sun4i_pwm_chip *sun4ichip, in sun4i_pwm_readl() argument
100 return readl(sun4ichip->base + offset); in sun4i_pwm_readl()
103 static inline void sun4i_pwm_writel(struct sun4i_pwm_chip *sun4ichip, in sun4i_pwm_writel() argument
106 writel(val, sun4ichip->base + offset); in sun4i_pwm_writel()
113 struct sun4i_pwm_chip *sun4ichip = to_sun4i_pwm_chip(chip); in sun4i_pwm_get_state() local
118 clk_rate = clk_get_rate(sun4ichip->clk); in sun4i_pwm_get_state()
122 val = sun4i_pwm_readl(sun4ichip, PWM_CTRL_REG); in sun4i_pwm_get_state()
130 sun4ichip->data->has_direct_mod_clk_output) { in sun4i_pwm_get_state()
139 sun4ichip->data->has_prescaler_bypass) in sun4i_pwm_get_state()
158 val = sun4i_pwm_readl(sun4ichip, PWM_CH_PRD(pwm->hwpwm)); in sun4i_pwm_get_state()
169 static int sun4i_pwm_calculate(struct sun4i_pwm_chip *sun4ichip, in sun4i_pwm_calculate() argument
177 clk_rate = clk_get_rate(sun4ichip->clk); in sun4i_pwm_calculate()
179 *bypass = sun4ichip->data->has_direct_mod_clk_output && in sun4i_pwm_calculate()
189 if (sun4ichip->data->has_prescaler_bypass) { in sun4i_pwm_calculate()
235 struct sun4i_pwm_chip *sun4ichip = to_sun4i_pwm_chip(chip); in sun4i_pwm_apply() local
245 ret = clk_prepare_enable(sun4ichip->clk); in sun4i_pwm_apply()
252 ret = sun4i_pwm_calculate(sun4ichip, state, &duty, &period, &prescaler, in sun4i_pwm_apply()
257 clk_disable_unprepare(sun4ichip->clk); in sun4i_pwm_apply()
261 spin_lock(&sun4ichip->ctrl_lock); in sun4i_pwm_apply()
262 ctrl = sun4i_pwm_readl(sun4ichip, PWM_CTRL_REG); in sun4i_pwm_apply()
264 if (sun4ichip->data->has_direct_mod_clk_output) { in sun4i_pwm_apply()
268 sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG); in sun4i_pwm_apply()
269 spin_unlock(&sun4ichip->ctrl_lock); in sun4i_pwm_apply()
279 sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG); in sun4i_pwm_apply()
286 sun4i_pwm_writel(sun4ichip, val, PWM_CH_PRD(pwm->hwpwm)); in sun4i_pwm_apply()
298 sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG); in sun4i_pwm_apply()
300 spin_unlock(&sun4ichip->ctrl_lock); in sun4i_pwm_apply()
312 spin_lock(&sun4ichip->ctrl_lock); in sun4i_pwm_apply()
313 ctrl = sun4i_pwm_readl(sun4ichip, PWM_CTRL_REG); in sun4i_pwm_apply()
316 sun4i_pwm_writel(sun4ichip, ctrl, PWM_CTRL_REG); in sun4i_pwm_apply()
317 spin_unlock(&sun4ichip->ctrl_lock); in sun4i_pwm_apply()
319 clk_disable_unprepare(sun4ichip->clk); in sun4i_pwm_apply()
388 struct sun4i_pwm_chip *sun4ichip; in sun4i_pwm_probe() local
395 chip = devm_pwmchip_alloc(&pdev->dev, data->npwm, sizeof(*sun4ichip)); in sun4i_pwm_probe()
398 sun4ichip = to_sun4i_pwm_chip(chip); in sun4i_pwm_probe()
400 sun4ichip->data = data; in sun4i_pwm_probe()
401 sun4ichip->base = devm_platform_ioremap_resource(pdev, 0); in sun4i_pwm_probe()
402 if (IS_ERR(sun4ichip->base)) in sun4i_pwm_probe()
403 return PTR_ERR(sun4ichip->base); in sun4i_pwm_probe()
416 sun4ichip->clk = devm_clk_get_optional(&pdev->dev, "mod"); in sun4i_pwm_probe()
417 if (IS_ERR(sun4ichip->clk)) in sun4i_pwm_probe()
418 return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->clk), in sun4i_pwm_probe()
421 if (!sun4ichip->clk) { in sun4i_pwm_probe()
422 sun4ichip->clk = devm_clk_get(&pdev->dev, NULL); in sun4i_pwm_probe()
423 if (IS_ERR(sun4ichip->clk)) in sun4i_pwm_probe()
424 return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->clk), in sun4i_pwm_probe()
428 sun4ichip->bus_clk = devm_clk_get_optional(&pdev->dev, "bus"); in sun4i_pwm_probe()
429 if (IS_ERR(sun4ichip->bus_clk)) in sun4i_pwm_probe()
430 return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->bus_clk), in sun4i_pwm_probe()
433 sun4ichip->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL); in sun4i_pwm_probe()
434 if (IS_ERR(sun4ichip->rst)) in sun4i_pwm_probe()
435 return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->rst), in sun4i_pwm_probe()
439 ret = reset_control_deassert(sun4ichip->rst); in sun4i_pwm_probe()
450 ret = clk_prepare_enable(sun4ichip->bus_clk); in sun4i_pwm_probe()
459 spin_lock_init(&sun4ichip->ctrl_lock); in sun4i_pwm_probe()
472 clk_disable_unprepare(sun4ichip->bus_clk); in sun4i_pwm_probe()
474 reset_control_assert(sun4ichip->rst); in sun4i_pwm_probe()
482 struct sun4i_pwm_chip *sun4ichip = to_sun4i_pwm_chip(chip); in sun4i_pwm_remove() local
486 clk_disable_unprepare(sun4ichip->bus_clk); in sun4i_pwm_remove()
487 reset_control_assert(sun4ichip->rst); in sun4i_pwm_remove()