@@ -95,7 +95,7 @@ static inline struct brcmstb_pwm *to_brcmstb_pwm(struct pwm_chip *chip)
9595 * "on" time, so this translates directly into our HW programming here.
9696 */
9797static int brcmstb_pwm_config (struct pwm_chip * chip , struct pwm_device * pwm ,
98- int duty_ns , int period_ns )
98+ u64 duty_ns , u64 period_ns )
9999{
100100 struct brcmstb_pwm * p = to_brcmstb_pwm (chip );
101101 unsigned long pc , dc , cword = CONST_VAR_F_MAX ;
@@ -114,22 +114,17 @@ static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
114114 }
115115
116116 while (1 ) {
117- u64 rate , tmp ;
117+ u64 rate ;
118118
119119 /*
120120 * Calculate the base rate from base frequency and current
121121 * cword
122122 */
123123 rate = (u64 )clk_get_rate (p -> clk ) * (u64 )cword ;
124- do_div ( rate , 1 << CWORD_BIT_SIZE ) ;
124+ rate >>= CWORD_BIT_SIZE ;
125125
126- tmp = period_ns * rate ;
127- do_div (tmp , NSEC_PER_SEC );
128- pc = tmp ;
129-
130- tmp = (duty_ns + 1 ) * rate ;
131- do_div (tmp , NSEC_PER_SEC );
132- dc = tmp ;
126+ pc = mul_u64_u64_div_u64 (period_ns , rate , NSEC_PER_SEC );
127+ dc = mul_u64_u64_div_u64 (duty_ns + 1 , rate , NSEC_PER_SEC );
133128
134129 /*
135130 * We can be called with separate duty and period updates,
@@ -202,26 +197,34 @@ static inline void brcmstb_pwm_enable_set(struct brcmstb_pwm *p,
202197 spin_unlock (& p -> lock );
203198}
204199
205- static int brcmstb_pwm_enable (struct pwm_chip * chip , struct pwm_device * pwm )
200+ static int brcmstb_pwm_apply (struct pwm_chip * chip , struct pwm_device * pwm ,
201+ const struct pwm_state * state )
206202{
207203 struct brcmstb_pwm * p = to_brcmstb_pwm (chip );
204+ int err ;
208205
209- brcmstb_pwm_enable_set (p , pwm -> hwpwm , true);
206+ if (state -> polarity != PWM_POLARITY_NORMAL )
207+ return - EINVAL ;
210208
211- return 0 ;
212- }
209+ if (!state -> enabled ) {
210+ if (pwm -> state .enabled )
211+ brcmstb_pwm_enable_set (p , pwm -> hwpwm , false);
213212
214- static void brcmstb_pwm_disable (struct pwm_chip * chip , struct pwm_device * pwm )
215- {
216- struct brcmstb_pwm * p = to_brcmstb_pwm (chip );
213+ return 0 ;
214+ }
215+
216+ err = brcmstb_pwm_config (chip , pwm , state -> duty_cycle , state -> period );
217+ if (err )
218+ return err ;
217219
218- brcmstb_pwm_enable_set (p , pwm -> hwpwm , false);
220+ if (!pwm -> state .enabled )
221+ brcmstb_pwm_enable_set (p , pwm -> hwpwm , true);
222+
223+ return 0 ;
219224}
220225
221226static const struct pwm_ops brcmstb_pwm_ops = {
222- .config = brcmstb_pwm_config ,
223- .enable = brcmstb_pwm_enable ,
224- .disable = brcmstb_pwm_disable ,
227+ .apply = brcmstb_pwm_apply ,
225228 .owner = THIS_MODULE ,
226229};
227230
0 commit comments