hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
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,9 +72,10 @@
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;
77
+ u32 oneshot_repeat;
78
+ u64 duty_offset;
8979 #endif /* CONFIG_PWM_ROCKCHIP_ONESHOT */
9080 bool enabled;
9181 };
....@@ -99,7 +89,8 @@
9989 * @chip: PWM chip providing this PWM device
10090 * @chip_data: chip-private data associated with the PWM device
10191 * @args: PWM arguments
102
- * @state: curent PWM channel state
92
+ * @state: last applied state
93
+ * @last: last implemented state (for PWM_DEBUG)
10394 */
10495 struct pwm_device {
10596 const char *label;
....@@ -111,6 +102,9 @@
111102
112103 struct pwm_args args;
113104 struct pwm_state state;
105
+ struct pwm_state last;
106
+
107
+ ANDROID_KABI_RESERVE(1);
114108 };
115109
116110 /**
....@@ -133,31 +127,13 @@
133127 return state.enabled;
134128 }
135129
136
-static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
130
+static inline void pwm_set_period(struct pwm_device *pwm, u64 period)
137131 {
138132 if (pwm)
139133 pwm->state.period = period;
140134 }
141135
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)
136
+static inline u64 pwm_get_period(const struct pwm_device *pwm)
161137 {
162138 struct pwm_state state;
163139
....@@ -172,25 +148,7 @@
172148 pwm->state.duty_cycle = duty;
173149 }
174150
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)
151
+static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm)
194152 {
195153 struct pwm_state state;
196154
....@@ -216,16 +174,6 @@
216174 pwm_get_state(pwm, &state);
217175
218176 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;
229177 }
230178
231179 static inline void pwm_get_args(const struct pwm_device *pwm,
....@@ -326,79 +274,68 @@
326274 * struct pwm_ops - PWM controller operations
327275 * @request: optional hook for requesting a PWM
328276 * @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
333277 * @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)
278
+ * @apply: atomically apply a new PWM config
343279 * @get_state: get the current PWM state. This function is only
344280 * called once per PWM device when the PWM chip is
345281 * registered.
346
- * @dbg_show: optional routine to show contents in debugfs
282
+ * @get_output_type_supported: get the supported output type of this PWM
347283 * @owner: helps prevent removal of modules exporting active PWMs
284
+ * @config: configure duty cycles and period length for this PWM
285
+ * @set_polarity: configure the polarity of this PWM
286
+ * @enable: enable PWM output toggling
287
+ * @disable: disable PWM output toggling
348288 */
349289 struct pwm_ops {
350290 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
351291 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);
358292 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
359293 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);
369294 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
370
- struct pwm_state *state);
295
+ const struct pwm_state *state);
371296 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
372297 struct pwm_state *state);
373
-#ifdef CONFIG_DEBUG_FS
374
- void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
375
-#endif
298
+ int (*get_output_type_supported)(struct pwm_chip *chip,
299
+ struct pwm_device *pwm);
376300 struct module *owner;
301
+
302
+ /* Only used by legacy drivers */
303
+ int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
304
+ int duty_ns, int period_ns);
305
+ int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
306
+ enum pwm_polarity polarity);
307
+ int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
308
+ void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
309
+
310
+ ANDROID_KABI_RESERVE(1);
377311 };
378312
379313 /**
380314 * struct pwm_chip - abstract a PWM controller
381315 * @dev: device providing the PWMs
382
- * @list: list node for internal use
383316 * @ops: callbacks for this PWM controller
384317 * @base: number of first PWM controlled by this chip
385318 * @npwm: number of PWMs controlled by this chip
386
- * @pwms: array of PWM devices allocated by the framework
387319 * @of_xlate: request a PWM device given a device tree PWM specifier
388320 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
321
+ * @list: list node for internal use
322
+ * @pwms: array of PWM devices allocated by the framework
389323 */
390324 struct pwm_chip {
391325 struct device *dev;
392
- struct list_head list;
393326 const struct pwm_ops *ops;
394327 int base;
395328 unsigned int npwm;
396329
397
- struct pwm_device *pwms;
398
-
399330 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
400331 const struct of_phandle_args *args);
401332 unsigned int of_pwm_n_cells;
333
+
334
+ /* only used internally by the PWM framework */
335
+ struct list_head list;
336
+ struct pwm_device *pwms;
337
+
338
+ ANDROID_KABI_RESERVE(1);
402339 };
403340
404341 /**
....@@ -407,30 +344,33 @@
407344 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
408345 */
409346 struct pwm_capture {
410
- u64 period;
411
- u64 duty_cycle;
347
+ unsigned int period;
348
+ unsigned int duty_cycle;
412349 };
413350
414351 #if IS_ENABLED(CONFIG_PWM)
415352 /* PWM user APIs */
416353 struct pwm_device *pwm_request(int pwm_id, const char *label);
417354 void pwm_free(struct pwm_device *pwm);
418
-int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state);
355
+int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
419356 int pwm_adjust_config(struct pwm_device *pwm);
420357
421358 /**
422
- * pwm_output_type_support()
359
+ * pwm_get_output_type_supported() - obtain output type of a PWM device.
423360 * @pwm: PWM device
424361 *
425
- * Returns: output types supported by the PWM device
362
+ * Returns: output type supported by the PWM device
426363 */
427364 static inline int pwm_get_output_type_supported(struct pwm_device *pwm)
428365 {
429
- if (pwm->chip->ops->get_output_type_supported != NULL)
366
+ if (!pwm)
367
+ return -EINVAL;
368
+
369
+ if (pwm->chip->ops->get_output_type_supported)
430370 return pwm->chip->ops->get_output_type_supported(pwm->chip,
431
- pwm);
432
- else
433
- return PWM_OUTPUT_FIXED;
371
+ pwm);
372
+
373
+ return PWM_OUTPUT_FIXED;
434374 }
435375
436376 /**
....@@ -458,67 +398,6 @@
458398
459399 state.duty_cycle = duty_ns;
460400 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;
522401 return pwm_apply_state(pwm, &state);
523402 }
524403
....@@ -580,12 +459,16 @@
580459 const struct of_phandle_args *args);
581460
582461 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);
462
+struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np,
463
+ const char *con_id);
584464 void pwm_put(struct pwm_device *pwm);
585465
586466 struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
587467 struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
588468 const char *con_id);
469
+struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
470
+ struct fwnode_handle *fwnode,
471
+ const char *con_id);
589472 void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
590473 #else
591474 static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
....@@ -608,6 +491,11 @@
608491 return -ENOTSUPP;
609492 }
610493
494
+static inline int pwm_get_output_type_supported(struct pwm_device *pwm)
495
+{
496
+ return -EINVAL;
497
+}
498
+
611499 static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
612500 int period_ns)
613501 {
....@@ -619,12 +507,6 @@
619507 unsigned long timeout)
620508 {
621509 return -EINVAL;
622
-}
623
-
624
-static inline int pwm_set_polarity(struct pwm_device *pwm,
625
- enum pwm_polarity polarity)
626
-{
627
- return -ENOTSUPP;
628510 }
629511
630512 static inline int pwm_enable(struct pwm_device *pwm)
....@@ -674,7 +556,8 @@
674556 return ERR_PTR(-ENODEV);
675557 }
676558
677
-static inline struct pwm_device *of_pwm_get(struct device_node *np,
559
+static inline struct pwm_device *of_pwm_get(struct device *dev,
560
+ struct device_node *np,
678561 const char *con_id)
679562 {
680563 return ERR_PTR(-ENODEV);
....@@ -697,6 +580,13 @@
697580 return ERR_PTR(-ENODEV);
698581 }
699582
583
+static inline struct pwm_device *
584
+devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode,
585
+ const char *con_id)
586
+{
587
+ return ERR_PTR(-ENODEV);
588
+}
589
+
700590 static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
701591 {
702592 }