Lines Matching refs:ddata
61 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); in pwm_sifive_request() local
63 mutex_lock(&ddata->lock); in pwm_sifive_request()
64 ddata->user_count++; in pwm_sifive_request()
65 mutex_unlock(&ddata->lock); in pwm_sifive_request()
72 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); in pwm_sifive_free() local
74 mutex_lock(&ddata->lock); in pwm_sifive_free()
75 ddata->user_count--; in pwm_sifive_free()
76 mutex_unlock(&ddata->lock); in pwm_sifive_free()
80 static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, in pwm_sifive_update_clock() argument
94 scale_pow = div64_ul(ddata->approx_period * (u64)rate, NSEC_PER_SEC); in pwm_sifive_update_clock()
99 writel(val, ddata->regs + PWM_SIFIVE_PWMCFG); in pwm_sifive_update_clock()
103 ddata->real_period = div64_ul(num, rate); in pwm_sifive_update_clock()
104 dev_dbg(ddata->chip.dev, in pwm_sifive_update_clock()
105 "New real_period = %u ns\n", ddata->real_period); in pwm_sifive_update_clock()
111 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); in pwm_sifive_get_state() local
114 duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); in pwm_sifive_get_state()
118 val = readl(ddata->regs + PWM_SIFIVE_PWMCFG); in pwm_sifive_get_state()
122 state->period = ddata->real_period; in pwm_sifive_get_state()
124 (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; in pwm_sifive_get_state()
131 struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); in pwm_sifive_apply() local
160 mutex_lock(&ddata->lock); in pwm_sifive_apply()
161 if (state->period != ddata->approx_period) { in pwm_sifive_apply()
162 if (ddata->user_count != 1) { in pwm_sifive_apply()
163 mutex_unlock(&ddata->lock); in pwm_sifive_apply()
166 ddata->approx_period = state->period; in pwm_sifive_apply()
167 pwm_sifive_update_clock(ddata, clk_get_rate(ddata->clk)); in pwm_sifive_apply()
169 mutex_unlock(&ddata->lock); in pwm_sifive_apply()
177 ret = clk_enable(ddata->clk); in pwm_sifive_apply()
179 dev_err(ddata->chip.dev, "Enable clk failed\n"); in pwm_sifive_apply()
184 writel(frac, ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); in pwm_sifive_apply()
187 clk_disable(ddata->clk); in pwm_sifive_apply()
204 struct pwm_sifive_ddata *ddata = in pwm_sifive_clock_notifier() local
208 mutex_lock(&ddata->lock); in pwm_sifive_clock_notifier()
209 pwm_sifive_update_clock(ddata, ndata->new_rate); in pwm_sifive_clock_notifier()
210 mutex_unlock(&ddata->lock); in pwm_sifive_clock_notifier()
219 struct pwm_sifive_ddata *ddata; in pwm_sifive_probe() local
225 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); in pwm_sifive_probe()
226 if (!ddata) in pwm_sifive_probe()
229 mutex_init(&ddata->lock); in pwm_sifive_probe()
230 chip = &ddata->chip; in pwm_sifive_probe()
235 ddata->regs = devm_platform_ioremap_resource(pdev, 0); in pwm_sifive_probe()
236 if (IS_ERR(ddata->regs)) in pwm_sifive_probe()
237 return PTR_ERR(ddata->regs); in pwm_sifive_probe()
239 ddata->clk = devm_clk_get(dev, NULL); in pwm_sifive_probe()
240 if (IS_ERR(ddata->clk)) in pwm_sifive_probe()
241 return dev_err_probe(dev, PTR_ERR(ddata->clk), in pwm_sifive_probe()
244 ret = clk_prepare_enable(ddata->clk); in pwm_sifive_probe()
250 val = readl(ddata->regs + PWM_SIFIVE_PWMCFG); in pwm_sifive_probe()
255 val = readl(ddata->regs + PWM_SIFIVE_PWMCMP(i)); in pwm_sifive_probe()
265 ret = clk_enable(ddata->clk); in pwm_sifive_probe()
273 clk_disable(ddata->clk); in pwm_sifive_probe()
278 ddata->notifier.notifier_call = pwm_sifive_clock_notifier; in pwm_sifive_probe()
279 ret = clk_notifier_register(ddata->clk, &ddata->notifier); in pwm_sifive_probe()
291 platform_set_drvdata(pdev, ddata); in pwm_sifive_probe()
297 clk_notifier_unregister(ddata->clk, &ddata->notifier); in pwm_sifive_probe()
300 clk_disable(ddata->clk); in pwm_sifive_probe()
303 clk_unprepare(ddata->clk); in pwm_sifive_probe()
310 struct pwm_sifive_ddata *ddata = platform_get_drvdata(dev); in pwm_sifive_remove() local
314 pwmchip_remove(&ddata->chip); in pwm_sifive_remove()
315 clk_notifier_unregister(ddata->clk, &ddata->notifier); in pwm_sifive_remove()
317 for (ch = 0; ch < ddata->chip.npwm; ch++) { in pwm_sifive_remove()
318 pwm = &ddata->chip.pwms[ch]; in pwm_sifive_remove()
320 clk_disable(ddata->clk); in pwm_sifive_remove()
323 clk_unprepare(ddata->clk); in pwm_sifive_remove()