File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,9 @@ int pwm_round_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *
242
242
243
243
BUG_ON (WFHWSIZE < ops -> sizeof_wfhw );
244
244
245
+ if (!pwmchip_supports_waveform (chip ))
246
+ return - EOPNOTSUPP ;
247
+
245
248
if (!pwm_wf_valid (wf ))
246
249
return - EINVAL ;
247
250
@@ -294,6 +297,9 @@ int pwm_get_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf
294
297
295
298
BUG_ON (WFHWSIZE < ops -> sizeof_wfhw );
296
299
300
+ if (!pwmchip_supports_waveform (chip ) || !ops -> read_waveform )
301
+ return - EOPNOTSUPP ;
302
+
297
303
guard (pwmchip )(chip );
298
304
299
305
if (!chip -> operational )
@@ -320,6 +326,9 @@ static int __pwm_set_waveform(struct pwm_device *pwm,
320
326
321
327
BUG_ON (WFHWSIZE < ops -> sizeof_wfhw );
322
328
329
+ if (!pwmchip_supports_waveform (chip ))
330
+ return - EOPNOTSUPP ;
331
+
323
332
if (!pwm_wf_valid (wf ))
324
333
return - EINVAL ;
325
334
@@ -592,7 +601,7 @@ static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state)
592
601
state -> usage_power == pwm -> state .usage_power )
593
602
return 0 ;
594
603
595
- if (ops -> write_waveform ) {
604
+ if (pwmchip_supports_waveform ( chip ) ) {
596
605
struct pwm_waveform wf ;
597
606
char wfhw [WFHWSIZE ];
598
607
@@ -746,7 +755,7 @@ int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state)
746
755
if (!chip -> operational )
747
756
return - ENODEV ;
748
757
749
- if (ops -> read_waveform ) {
758
+ if (pwmchip_supports_waveform ( chip ) && ops -> read_waveform ) {
750
759
char wfhw [WFHWSIZE ];
751
760
struct pwm_waveform wf ;
752
761
Original file line number Diff line number Diff line change @@ -347,6 +347,23 @@ struct pwm_chip {
347
347
struct pwm_device pwms [] __counted_by (npwm );
348
348
};
349
349
350
+ /**
351
+ * pwmchip_supports_waveform() - checks if the given chip supports waveform callbacks
352
+ * @chip: The pwm_chip to test
353
+ *
354
+ * Returns true iff the pwm chip support the waveform functions like
355
+ * pwm_set_waveform_might_sleep() and pwm_round_waveform_might_sleep()
356
+ */
357
+ static inline bool pwmchip_supports_waveform (struct pwm_chip * chip )
358
+ {
359
+ /*
360
+ * only check for .write_waveform(). If that is available,
361
+ * .round_waveform_tohw() and .round_waveform_fromhw() asserted to be
362
+ * available, too, in pwmchip_add().
363
+ */
364
+ return chip -> ops -> write_waveform != NULL ;
365
+ }
366
+
350
367
static inline struct device * pwmchip_parent (const struct pwm_chip * chip )
351
368
{
352
369
return chip -> dev .parent ;
You can’t perform that action at this time.
0 commit comments