5 #include <linux/mutex.h>
11 #if IS_ENABLED(CONFIG_PWM)
13 * pwm_request - request a PWM device
15 struct pwm_device
*pwm_request(int pwm_id
, const char *label
);
18 * pwm_free - free a PWM device
20 void pwm_free(struct pwm_device
*pwm
);
23 * pwm_config - change a PWM device configuration
25 int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
);
28 * pwm_enable - start a PWM output toggling
30 int pwm_enable(struct pwm_device
*pwm
);
33 * pwm_disable - stop a PWM output toggling
35 void pwm_disable(struct pwm_device
*pwm
);
37 static inline struct pwm_device
*pwm_request(int pwm_id
, const char *label
)
39 return ERR_PTR(-ENODEV
);
42 static inline void pwm_free(struct pwm_device
*pwm
)
46 static inline int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
)
51 static inline int pwm_enable(struct pwm_device
*pwm
)
56 static inline void pwm_disable(struct pwm_device
*pwm
)
64 * enum pwm_polarity - polarity of a PWM signal
65 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
66 * cycle, followed by a low signal for the remainder of the pulse
68 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
69 * cycle, followed by a high signal for the remainder of the pulse
74 PWM_POLARITY_INVERSED
,
78 * struct pwm_args - board-dependent PWM arguments
79 * @period: reference period
80 * @polarity: reference polarity
82 * This structure describes board-dependent arguments attached to a PWM
83 * device. These arguments are usually retrieved from the PWM lookup table or
86 * Do not confuse this with the PWM state: PWM arguments represent the initial
87 * configuration that users want to use on this PWM device rather than the
88 * current PWM hardware state.
92 enum pwm_polarity polarity
;
96 PWMF_REQUESTED
= 1 << 0,
97 PWMF_ENABLED
= 1 << 1,
98 PWMF_EXPORTED
= 1 << 2,
102 * struct pwm_device - PWM channel object
103 * @label: name of the PWM device
104 * @flags: flags associated with the PWM device
105 * @hwpwm: per-chip relative index of the PWM device
106 * @pwm: global index of the PWM device
107 * @chip: PWM chip providing this PWM device
108 * @chip_data: chip-private data associated with the PWM device
109 * @lock: used to serialize accesses to the PWM device where necessary
110 * @period: period of the PWM signal (in nanoseconds)
111 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
112 * @polarity: polarity of the PWM signal
113 * @args: PWM arguments
120 struct pwm_chip
*chip
;
125 unsigned int duty_cycle
;
126 enum pwm_polarity polarity
;
128 struct pwm_args args
;
131 static inline bool pwm_is_enabled(const struct pwm_device
*pwm
)
133 return test_bit(PWMF_ENABLED
, &pwm
->flags
);
136 static inline void pwm_set_period(struct pwm_device
*pwm
, unsigned int period
)
139 pwm
->period
= period
;
142 static inline unsigned int pwm_get_period(const struct pwm_device
*pwm
)
144 return pwm
? pwm
->period
: 0;
147 static inline void pwm_set_duty_cycle(struct pwm_device
*pwm
, unsigned int duty
)
150 pwm
->duty_cycle
= duty
;
153 static inline unsigned int pwm_get_duty_cycle(const struct pwm_device
*pwm
)
155 return pwm
? pwm
->duty_cycle
: 0;
159 * pwm_set_polarity - configure the polarity of a PWM signal
161 int pwm_set_polarity(struct pwm_device
*pwm
, enum pwm_polarity polarity
);
163 static inline enum pwm_polarity
pwm_get_polarity(const struct pwm_device
*pwm
)
165 return pwm
? pwm
->polarity
: PWM_POLARITY_NORMAL
;
168 static inline void pwm_get_args(const struct pwm_device
*pwm
,
169 struct pwm_args
*args
)
174 static inline void pwm_apply_args(struct pwm_device
*pwm
)
176 pwm_set_period(pwm
, pwm
->args
.period
);
177 pwm_set_polarity(pwm
, pwm
->args
.polarity
);
181 * struct pwm_ops - PWM controller operations
182 * @request: optional hook for requesting a PWM
183 * @free: optional hook for freeing a PWM
184 * @config: configure duty cycles and period length for this PWM
185 * @set_polarity: configure the polarity of this PWM
186 * @enable: enable PWM output toggling
187 * @disable: disable PWM output toggling
188 * @dbg_show: optional routine to show contents in debugfs
189 * @owner: helps prevent removal of modules exporting active PWMs
192 int (*request
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
193 void (*free
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
194 int (*config
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
,
195 int duty_ns
, int period_ns
);
196 int (*set_polarity
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
,
197 enum pwm_polarity polarity
);
198 int (*enable
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
199 void (*disable
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
200 #ifdef CONFIG_DEBUG_FS
201 void (*dbg_show
)(struct pwm_chip
*chip
, struct seq_file
*s
);
203 struct module
*owner
;
207 * struct pwm_chip - abstract a PWM controller
208 * @dev: device providing the PWMs
209 * @list: list node for internal use
210 * @ops: callbacks for this PWM controller
211 * @base: number of first PWM controlled by this chip
212 * @npwm: number of PWMs controlled by this chip
213 * @pwms: array of PWM devices allocated by the framework
214 * @of_xlate: request a PWM device given a device tree PWM specifier
215 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
216 * @can_sleep: must be true if the .config(), .enable() or .disable()
217 * operations may sleep
221 struct list_head list
;
222 const struct pwm_ops
*ops
;
226 struct pwm_device
*pwms
;
228 struct pwm_device
* (*of_xlate
)(struct pwm_chip
*pc
,
229 const struct of_phandle_args
*args
);
230 unsigned int of_pwm_n_cells
;
234 #if IS_ENABLED(CONFIG_PWM)
235 int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
);
236 void *pwm_get_chip_data(struct pwm_device
*pwm
);
238 int pwmchip_add_with_polarity(struct pwm_chip
*chip
,
239 enum pwm_polarity polarity
);
240 int pwmchip_add(struct pwm_chip
*chip
);
241 int pwmchip_remove(struct pwm_chip
*chip
);
242 struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
246 struct pwm_device
*of_pwm_xlate_with_flags(struct pwm_chip
*pc
,
247 const struct of_phandle_args
*args
);
249 struct pwm_device
*pwm_get(struct device
*dev
, const char *con_id
);
250 struct pwm_device
*of_pwm_get(struct device_node
*np
, const char *con_id
);
251 void pwm_put(struct pwm_device
*pwm
);
253 struct pwm_device
*devm_pwm_get(struct device
*dev
, const char *con_id
);
254 struct pwm_device
*devm_of_pwm_get(struct device
*dev
, struct device_node
*np
,
256 void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
);
258 bool pwm_can_sleep(struct pwm_device
*pwm
);
260 static inline int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
)
265 static inline void *pwm_get_chip_data(struct pwm_device
*pwm
)
270 static inline int pwmchip_add(struct pwm_chip
*chip
)
275 static inline int pwmchip_add_inversed(struct pwm_chip
*chip
)
280 static inline int pwmchip_remove(struct pwm_chip
*chip
)
285 static inline struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
289 return ERR_PTR(-ENODEV
);
292 static inline struct pwm_device
*pwm_get(struct device
*dev
,
293 const char *consumer
)
295 return ERR_PTR(-ENODEV
);
298 static inline struct pwm_device
*of_pwm_get(struct device_node
*np
,
301 return ERR_PTR(-ENODEV
);
304 static inline void pwm_put(struct pwm_device
*pwm
)
308 static inline struct pwm_device
*devm_pwm_get(struct device
*dev
,
309 const char *consumer
)
311 return ERR_PTR(-ENODEV
);
314 static inline struct pwm_device
*devm_of_pwm_get(struct device
*dev
,
315 struct device_node
*np
,
318 return ERR_PTR(-ENODEV
);
321 static inline void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
)
325 static inline bool pwm_can_sleep(struct pwm_device
*pwm
)
332 struct list_head list
;
333 const char *provider
;
338 enum pwm_polarity polarity
;
341 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
343 .provider = _provider, \
348 .polarity = _polarity \
351 #if IS_ENABLED(CONFIG_PWM)
352 void pwm_add_table(struct pwm_lookup
*table
, size_t num
);
353 void pwm_remove_table(struct pwm_lookup
*table
, size_t num
);
355 static inline void pwm_add_table(struct pwm_lookup
*table
, size_t num
)
359 static inline void pwm_remove_table(struct pwm_lookup
*table
, size_t num
)
364 #ifdef CONFIG_PWM_SYSFS
365 void pwmchip_sysfs_export(struct pwm_chip
*chip
);
366 void pwmchip_sysfs_unexport(struct pwm_chip
*chip
);
368 static inline void pwmchip_sysfs_export(struct pwm_chip
*chip
)
372 static inline void pwmchip_sysfs_unexport(struct pwm_chip
*chip
)
375 #endif /* CONFIG_PWM_SYSFS */
377 #endif /* __LINUX_PWM_H */
This page took 0.047711 seconds and 6 git commands to generate.