hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/pwm/pwm-rockchip.c
....@@ -169,7 +169,7 @@
169169 const struct pwm_state *state)
170170 {
171171 struct rockchip_pwm_chip *pc = to_rockchip_pwm_chip(chip);
172
- unsigned long period, duty;
172
+ unsigned long period, duty, delay_ns;
173173 unsigned long flags;
174174 u64 div;
175175 u32 ctrl;
....@@ -191,11 +191,13 @@
191191 div = (u64)pc->clk_rate * state->duty_cycle;
192192 duty = DIV_ROUND_CLOSEST_ULL(div, dclk_div * pc->data->prescaler * NSEC_PER_SEC);
193193
194
+ if (pc->data->supports_lock) {
195
+ div = (u64)10 * NSEC_PER_SEC * dclk_div * pc->data->prescaler;
196
+ delay_ns = DIV_ROUND_UP_ULL(div, pc->clk_rate);
197
+ }
198
+
194199 local_irq_save(flags);
195
- /*
196
- * Lock the period and duty of previous configuration, then
197
- * change the duty and period, that would not be effective.
198
- */
200
+
199201 ctrl = readl_relaxed(pc->base + pc->data->regs.ctrl);
200202 if (pc->data->vop_pwm) {
201203 if (pc->vop_pwm_en)
....@@ -253,6 +255,10 @@
253255 }
254256 #endif
255257
258
+ /*
259
+ * Lock the period and duty of previous configuration, then
260
+ * change the duty and period, that would not be effective.
261
+ */
256262 if (pc->data->supports_lock) {
257263 ctrl |= PWM_LOCK_EN;
258264 writel_relaxed(ctrl, pc->base + pc->data->regs.ctrl);
....@@ -270,12 +276,14 @@
270276 }
271277
272278 /*
273
- * Unlock and set polarity at the same time,
274
- * the configuration of duty, period and polarity
275
- * would be effective together at next period.
279
+ * Unlock and set polarity at the same time, the configuration of duty,
280
+ * period and polarity would be effective together at next period. It
281
+ * takes 10 dclk cycles to make sure lock works before unlocking.
276282 */
277
- if (pc->data->supports_lock)
283
+ if (pc->data->supports_lock) {
278284 ctrl &= ~PWM_LOCK_EN;
285
+ ndelay(delay_ns);
286
+ }
279287
280288 writel(ctrl, pc->base + pc->data->regs.ctrl);
281289 local_irq_restore(flags);