@@ -156,13 +156,48 @@ static void ep93xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
156
156
clk_disable (ep93xx_pwm -> clk );
157
157
}
158
158
159
+ static int ep93xx_pwm_apply (struct pwm_chip * chip , struct pwm_device * pwm ,
160
+ const struct pwm_state * state )
161
+ {
162
+ int ret ;
163
+ bool enabled = state -> enabled ;
164
+
165
+ if (state -> polarity != pwm -> state .polarity ) {
166
+ if (enabled ) {
167
+ ep93xx_pwm_disable (chip , pwm );
168
+ enabled = false;
169
+ }
170
+
171
+ ret = ep93xx_pwm_polarity (chip , pwm , state -> polarity );
172
+ if (ret )
173
+ return ret ;
174
+ }
175
+
176
+ if (!state -> enabled ) {
177
+ if (enabled )
178
+ ep93xx_pwm_disable (chip , pwm );
179
+
180
+ return 0 ;
181
+ }
182
+
183
+ if (state -> period != pwm -> state .period ||
184
+ state -> duty_cycle != pwm -> state .duty_cycle ) {
185
+ ret = ep93xx_pwm_config (chip , pwm , (int )state -> duty_cycle ,
186
+ (int )state -> period );
187
+ if (ret )
188
+ return ret ;
189
+ }
190
+
191
+ if (!enabled )
192
+ return ep93xx_pwm_enable (chip , pwm );
193
+
194
+ return 0 ;
195
+ }
196
+
159
197
static const struct pwm_ops ep93xx_pwm_ops = {
160
198
.request = ep93xx_pwm_request ,
161
199
.free = ep93xx_pwm_free ,
162
- .config = ep93xx_pwm_config ,
163
- .set_polarity = ep93xx_pwm_polarity ,
164
- .enable = ep93xx_pwm_enable ,
165
- .disable = ep93xx_pwm_disable ,
200
+ .apply = ep93xx_pwm_apply ,
166
201
.owner = THIS_MODULE ,
167
202
};
168
203
0 commit comments