hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/pwm.h
....@@ -5,6 +5,7 @@
55 #include <linux/err.h>
66 #include <linux/mutex.h>
77 #include <linux/of.h>
8
+#include <linux/android_kabi.h>
89
910 struct pwm_capture;
1011 struct seq_file;
....@@ -59,18 +60,6 @@
5960 PWM_OUTPUT_MODULATED = 1 << 1,
6061 };
6162
62
-/**
63
- * struct pwm_output_pattern - PWM duty pattern for MODULATED duty type
64
- * @duty_pattern: PWM duty cycles in the pattern for duty modulation
65
- * @num_entries: number of entries in the pattern
66
- * @cycles_per_duty: number of PWM period cycles an entry stays at
67
- */
68
-struct pwm_output_pattern {
69
- u64 *duty_pattern;
70
- unsigned int num_entries;
71
- u64 cycles_per_duty;
72
-};
73
-
7463 /*
7564 * struct pwm_state - state of a PWM channel
7665 * @period: PWM period (in nanoseconds)
....@@ -83,7 +72,6 @@
8372 u64 duty_cycle;
8473 enum pwm_polarity polarity;
8574 enum pwm_output_type output_type;
86
- struct pwm_output_pattern *output_pattern;
8775 #ifdef CONFIG_PWM_ROCKCHIP_ONESHOT
8876 u64 oneshot_count;
8977 #endif /* CONFIG_PWM_ROCKCHIP_ONESHOT */
....@@ -99,7 +87,8 @@
9987 * @chip: PWM chip providing this PWM device
10088 * @chip_data: chip-private data associated with the PWM device
10189 * @args: PWM arguments
102
- * @state: curent PWM channel state
90
+ * @state: last applied state
91
+ * @last: last implemented state (for PWM_DEBUG)
10392 */
10493 struct pwm_device {
10594 const char *label;
....@@ -111,6 +100,9 @@
111100
112101 struct pwm_args args;
113102 struct pwm_state state;
103
+ struct pwm_state last;
104
+
105
+ ANDROID_KABI_RESERVE(1);
114106 };
115107
116108 /**
....@@ -133,31 +125,13 @@
133125 return state.enabled;
134126 }
135127
136
-static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
128
+static inline void pwm_set_period(struct pwm_device *pwm, u64 period)
137129 {
138130 if (pwm)
139131 pwm->state.period = period;
140132 }
141133
142
-static inline void pwm_set_period_extend(struct pwm_device *pwm, u64 period)
143
-{
144
- if (pwm)
145
- pwm->state.period = period;
146
-}
147
-
148
-static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
149
-{
150
- struct pwm_state state;
151
-
152
- pwm_get_state(pwm, &state);
153
-
154
- if (state.period > UINT_MAX)
155
- pr_warn("PWM period %llu is truncated\n", state.period);
156
-
157
- return (unsigned int)state.period;
158
-}
159
-
160
-static inline u64 pwm_get_period_extend(const struct pwm_device *pwm)
134
+static inline u64 pwm_get_period(const struct pwm_device *pwm)
161135 {
162136 struct pwm_state state;
163137
....@@ -172,25 +146,7 @@
172146 pwm->state.duty_cycle = duty;
173147 }
174148
175
-static inline void pwm_set_duty_cycle_extend(struct pwm_device *pwm, u64 duty)
176
-{
177
- if (pwm)
178
- pwm->state.duty_cycle = duty;
179
-}
180
-
181
-static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
182
-{
183
- struct pwm_state state;
184
-
185
- pwm_get_state(pwm, &state);
186
-
187
- if (state.duty_cycle > UINT_MAX)
188
- pr_warn("PWM duty cycle %llu is truncated\n", state.duty_cycle);
189
-
190
- return (unsigned int)state.duty_cycle;
191
-}
192
-
193
-static inline u64 pwm_get_duty_cycle_extend(const struct pwm_device *pwm)
149
+static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm)
194150 {
195151 struct pwm_state state;
196152
....@@ -216,16 +172,6 @@
216172 pwm_get_state(pwm, &state);
217173
218174 return state.output_type;
219
-}
220
-
221
-static inline struct pwm_output_pattern *pwm_get_output_pattern(
222
- struct pwm_device *pwm)
223
-{
224
- struct pwm_state state;
225
-
226
- pwm_get_state(pwm, &state);
227
-
228
- return pwm->state.output_pattern ?: NULL;
229175 }
230176
231177 static inline void pwm_get_args(const struct pwm_device *pwm,
....@@ -326,79 +272,68 @@
326272 * struct pwm_ops - PWM controller operations
327273 * @request: optional hook for requesting a PWM
328274 * @free: optional hook for freeing a PWM
329
- * @config: configure duty cycles and period length for this PWM
330
- * @config_extend: configure duty cycles and period length for this
331
- * PWM with u64 data type
332
- * @set_polarity: configure the polarity of this PWM
333275 * @capture: capture and report PWM signal
334
- * @enable: enable PWM output toggling
335
- * @disable: disable PWM output toggling
336
- * @get_output_type_supported: get the supported output type
337
- * @set_output_type: set PWM output type
338
- * @set_output_pattern: set the pattern for the modulated output
339
- * @apply: atomically apply a new PWM config. The state argument
340
- * should be adjusted with the real hardware config (if the
341
- * approximate the period or duty_cycle value, state should
342
- * reflect it)
276
+ * @apply: atomically apply a new PWM config
343277 * @get_state: get the current PWM state. This function is only
344278 * called once per PWM device when the PWM chip is
345279 * registered.
346
- * @dbg_show: optional routine to show contents in debugfs
280
+ * @get_output_type_supported: get the supported output type of this PWM
347281 * @owner: helps prevent removal of modules exporting active PWMs
282
+ * @config: configure duty cycles and period length for this PWM
283
+ * @set_polarity: configure the polarity of this PWM
284
+ * @enable: enable PWM output toggling
285
+ * @disable: disable PWM output toggling
348286 */
349287 struct pwm_ops {
350288 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
351289 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
352
- int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
353
- int duty_ns, int period_ns);
354
- int (*config_extend)(struct pwm_chip *chip, struct pwm_device *pwm,
355
- u64 duty_ns, u64 period_ns);
356
- int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
357
- enum pwm_polarity polarity);
358290 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
359291 struct pwm_capture *result, unsigned long timeout);
360
- int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
361
- void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
362
- int (*get_output_type_supported)(struct pwm_chip *chip,
363
- struct pwm_device *pwm);
364
- int (*set_output_type)(struct pwm_chip *chip, struct pwm_device *pwm,
365
- enum pwm_output_type output_type);
366
- int (*set_output_pattern)(struct pwm_chip *chip,
367
- struct pwm_device *pwm,
368
- struct pwm_output_pattern *output_pattern);
369292 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
370
- struct pwm_state *state);
293
+ const struct pwm_state *state);
371294 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
372295 struct pwm_state *state);
373
-#ifdef CONFIG_DEBUG_FS
374
- void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
375
-#endif
296
+ int (*get_output_type_supported)(struct pwm_chip *chip,
297
+ struct pwm_device *pwm);
376298 struct module *owner;
299
+
300
+ /* Only used by legacy drivers */
301
+ int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
302
+ int duty_ns, int period_ns);
303
+ int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
304
+ enum pwm_polarity polarity);
305
+ int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
306
+ void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
307
+
308
+ ANDROID_KABI_RESERVE(1);
377309 };
378310
379311 /**
380312 * struct pwm_chip - abstract a PWM controller
381313 * @dev: device providing the PWMs
382
- * @list: list node for internal use
383314 * @ops: callbacks for this PWM controller
384315 * @base: number of first PWM controlled by this chip
385316 * @npwm: number of PWMs controlled by this chip
386
- * @pwms: array of PWM devices allocated by the framework
387317 * @of_xlate: request a PWM device given a device tree PWM specifier
388318 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
319
+ * @list: list node for internal use
320
+ * @pwms: array of PWM devices allocated by the framework
389321 */
390322 struct pwm_chip {
391323 struct device *dev;
392
- struct list_head list;
393324 const struct pwm_ops *ops;
394325 int base;
395326 unsigned int npwm;
396327
397
- struct pwm_device *pwms;
398
-
399328 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
400329 const struct of_phandle_args *args);
401330 unsigned int of_pwm_n_cells;
331
+
332
+ /* only used internally by the PWM framework */
333
+ struct list_head list;
334
+ struct pwm_device *pwms;
335
+
336
+ ANDROID_KABI_RESERVE(1);
402337 };
403338
404339 /**
....@@ -407,30 +342,33 @@
407342 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
408343 */
409344 struct pwm_capture {
410
- u64 period;
411
- u64 duty_cycle;
345
+ unsigned int period;
346
+ unsigned int duty_cycle;
412347 };
413348
414349 #if IS_ENABLED(CONFIG_PWM)
415350 /* PWM user APIs */
416351 struct pwm_device *pwm_request(int pwm_id, const char *label);
417352 void pwm_free(struct pwm_device *pwm);
418
-int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state);
353
+int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
419354 int pwm_adjust_config(struct pwm_device *pwm);
420355
421356 /**
422
- * pwm_output_type_support()
357
+ * pwm_get_output_type_supported() - obtain output type of a PWM device.
423358 * @pwm: PWM device
424359 *
425
- * Returns: output types supported by the PWM device
360
+ * Returns: output type supported by the PWM device
426361 */
427362 static inline int pwm_get_output_type_supported(struct pwm_device *pwm)
428363 {
429
- if (pwm->chip->ops->get_output_type_supported != NULL)
364
+ if (!pwm)
365
+ return -EINVAL;
366
+
367
+ if (pwm->chip->ops->get_output_type_supported)
430368 return pwm->chip->ops->get_output_type_supported(pwm->chip,
431
- pwm);
432
- else
433
- return PWM_OUTPUT_FIXED;
369
+ pwm);
370
+
371
+ return PWM_OUTPUT_FIXED;
434372 }
435373
436374 /**
....@@ -458,67 +396,6 @@
458396
459397 state.duty_cycle = duty_ns;
460398 state.period = period_ns;
461
- return pwm_apply_state(pwm, &state);
462
-}
463
-
464
-/**
465
- * pwm_config_extend() - change PWM period and duty length with u64 data type
466
- * @pwm: PWM device
467
- * @duty_ns: "on" time (in nanoseconds)
468
- * @period_ns: duration (in nanoseconds) of one cycle
469
- *
470
- * Returns: 0 on success or a negative error code on failure.
471
- */
472
-static inline int pwm_config_extend(struct pwm_device *pwm, u64 duty_ns,
473
- u64 period_ns)
474
-{
475
- struct pwm_state state;
476
-
477
- if (!pwm)
478
- return -EINVAL;
479
-
480
- pwm_get_state(pwm, &state);
481
- if (state.duty_cycle == duty_ns && state.period == period_ns)
482
- return 0;
483
-
484
- state.duty_cycle = duty_ns;
485
- state.period = period_ns;
486
- return pwm_apply_state(pwm, &state);
487
-}
488
-
489
-/**
490
- * pwm_set_polarity() - configure the polarity of a PWM signal
491
- * @pwm: PWM device
492
- * @polarity: new polarity of the PWM signal
493
- *
494
- * Note that the polarity cannot be configured while the PWM device is
495
- * enabled.
496
- *
497
- * Returns: 0 on success or a negative error code on failure.
498
- */
499
-static inline int pwm_set_polarity(struct pwm_device *pwm,
500
- enum pwm_polarity polarity)
501
-{
502
- struct pwm_state state;
503
-
504
- if (!pwm)
505
- return -EINVAL;
506
-
507
- pwm_get_state(pwm, &state);
508
- if (state.polarity == polarity)
509
- return 0;
510
-
511
- /*
512
- * Changing the polarity of a running PWM without adjusting the
513
- * dutycycle/period value is a bit risky (can introduce glitches).
514
- * Return -EBUSY in this case.
515
- * Note that this is allowed when using pwm_apply_state() because
516
- * the user specifies all the parameters.
517
- */
518
- if (state.enabled)
519
- return -EBUSY;
520
-
521
- state.polarity = polarity;
522399 return pwm_apply_state(pwm, &state);
523400 }
524401
....@@ -580,12 +457,16 @@
580457 const struct of_phandle_args *args);
581458
582459 struct pwm_device *pwm_get(struct device *dev, const char *con_id);
583
-struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id);
460
+struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,
461
+ const char *con_id);
584462 void pwm_put(struct pwm_device *pwm);
585463
586464 struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
587465 struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
588466 const char *con_id);
467
+struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
468
+ struct fwnode_handle *fwnode,
469
+ const char *con_id);
589470 void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
590471 #else
591472 static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
....@@ -608,6 +489,11 @@
608489 return -ENOTSUPP;
609490 }
610491
492
+static inline int pwm_get_output_type_supported(struct pwm_device *pwm)
493
+{
494
+ return -EINVAL;
495
+}
496
+
611497 static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
612498 int period_ns)
613499 {
....@@ -619,12 +505,6 @@
619505 unsigned long timeout)
620506 {
621507 return -EINVAL;
622
-}
623
-
624
-static inline int pwm_set_polarity(struct pwm_device *pwm,
625
- enum pwm_polarity polarity)
626
-{
627
- return -ENOTSUPP;
628508 }
629509
630510 static inline int pwm_enable(struct pwm_device *pwm)
....@@ -674,7 +554,8 @@
674554 return ERR_PTR(-ENODEV);
675555 }
676556
677
-static inline struct pwm_device *of_pwm_get(struct device_node *np,
557
+static inline struct pwm_device *of_pwm_get(struct device *dev,
558
+ struct device_node *np,
678559 const char *con_id)
679560 {
680561 return ERR_PTR(-ENODEV);
....@@ -697,6 +578,13 @@
697578 return ERR_PTR(-ENODEV);
698579 }
699580
581
+static inline struct pwm_device *
582
+devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode,
583
+ const char *con_id)
584
+{
585
+ return ERR_PTR(-ENODEV);
586
+}
587
+
700588 static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
701589 {
702590 }