@@ -137,6 +137,45 @@ static void twl4030_pwmled_disable(struct pwm_chip *chip,
137
137
mutex_unlock (& twl -> mutex );
138
138
}
139
139
140
+ static int twl4030_pwmled_apply (struct pwm_chip * chip , struct pwm_device * pwm ,
141
+ const struct pwm_state * state )
142
+ {
143
+ int ret ;
144
+
145
+ if (state -> polarity != PWM_POLARITY_NORMAL )
146
+ return - EINVAL ;
147
+
148
+ if (!state -> enabled ) {
149
+ if (pwm -> state .enabled )
150
+ twl4030_pwmled_disable (chip , pwm );
151
+
152
+ return 0 ;
153
+ }
154
+
155
+ /*
156
+ * We cannot skip calling ->config even if state->period ==
157
+ * pwm->state.period && state->duty_cycle == pwm->state.duty_cycle
158
+ * because we might have exited early in the last call to
159
+ * pwm_apply_state because of !state->enabled and so the two values in
160
+ * pwm->state might not be configured in hardware.
161
+ */
162
+ ret = twl4030_pwmled_config (pwm -> chip , pwm ,
163
+ state -> duty_cycle , state -> period );
164
+ if (ret )
165
+ return ret ;
166
+
167
+ if (!pwm -> state .enabled )
168
+ ret = twl4030_pwmled_enable (chip , pwm );
169
+
170
+ return ret ;
171
+ }
172
+
173
+
174
+ static const struct pwm_ops twl4030_pwmled_ops = {
175
+ .apply = twl4030_pwmled_apply ,
176
+ .owner = THIS_MODULE ,
177
+ };
178
+
140
179
static int twl6030_pwmled_config (struct pwm_chip * chip , struct pwm_device * pwm ,
141
180
int duty_ns , int period_ns )
142
181
{
@@ -206,6 +245,32 @@ static void twl6030_pwmled_disable(struct pwm_chip *chip,
206
245
mutex_unlock (& twl -> mutex );
207
246
}
208
247
248
+ static int twl6030_pwmled_apply (struct pwm_chip * chip , struct pwm_device * pwm ,
249
+ const struct pwm_state * state )
250
+ {
251
+ int err ;
252
+
253
+ if (state -> polarity != pwm -> state .polarity )
254
+ return - EINVAL ;
255
+
256
+ if (!state -> enabled ) {
257
+ if (pwm -> state .enabled )
258
+ twl6030_pwmled_disable (chip , pwm );
259
+
260
+ return 0 ;
261
+ }
262
+
263
+ err = twl6030_pwmled_config (pwm -> chip , pwm ,
264
+ state -> duty_cycle , state -> period );
265
+ if (err )
266
+ return err ;
267
+
268
+ if (!pwm -> state .enabled )
269
+ err = twl6030_pwmled_enable (chip , pwm );
270
+
271
+ return err ;
272
+ }
273
+
209
274
static int twl6030_pwmled_request (struct pwm_chip * chip , struct pwm_device * pwm )
210
275
{
211
276
struct twl_pwmled_chip * twl = to_twl (chip );
@@ -257,17 +322,8 @@ static void twl6030_pwmled_free(struct pwm_chip *chip, struct pwm_device *pwm)
257
322
mutex_unlock (& twl -> mutex );
258
323
}
259
324
260
- static const struct pwm_ops twl4030_pwmled_ops = {
261
- .enable = twl4030_pwmled_enable ,
262
- .disable = twl4030_pwmled_disable ,
263
- .config = twl4030_pwmled_config ,
264
- .owner = THIS_MODULE ,
265
- };
266
-
267
325
static const struct pwm_ops twl6030_pwmled_ops = {
268
- .enable = twl6030_pwmled_enable ,
269
- .disable = twl6030_pwmled_disable ,
270
- .config = twl6030_pwmled_config ,
326
+ .apply = twl6030_pwmled_apply ,
271
327
.request = twl6030_pwmled_request ,
272
328
.free = twl6030_pwmled_free ,
273
329
.owner = THIS_MODULE ,
0 commit comments