pwm: Allow chips to support multiple PWMs
[linux-block.git] / include / linux / pwm.h
CommitLineData
1a189b97
RK
1#ifndef __LINUX_PWM_H
2#define __LINUX_PWM_H
3
4struct pwm_device;
5
6/*
7 * pwm_request - request a PWM device
8 */
9struct pwm_device *pwm_request(int pwm_id, const char *label);
10
11/*
12 * pwm_free - free a PWM device
13 */
14void pwm_free(struct pwm_device *pwm);
15
16/*
17 * pwm_config - change a PWM device configuration
18 */
19int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
20
21/*
22 * pwm_enable - start a PWM output toggling
23 */
24int pwm_enable(struct pwm_device *pwm);
25
26/*
27 * pwm_disable - stop a PWM output toggling
28 */
29void pwm_disable(struct pwm_device *pwm);
30
0c2498f1
SH
31#ifdef CONFIG_PWM
32struct pwm_chip;
33
f051c466
TR
34enum {
35 PWMF_REQUESTED = 1 << 0,
36 PWMF_ENABLED = 1 << 1,
37};
38
39struct pwm_device {
40 const char *label;
41 unsigned long flags;
42 unsigned int hwpwm;
43 unsigned int pwm;
44 struct pwm_chip *chip;
45 void *chip_data;
46
47 unsigned int period; /* in nanoseconds */
48};
49
50static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
51{
52 if (pwm)
53 pwm->period = period;
54}
55
56static inline unsigned int pwm_get_period(struct pwm_device *pwm)
57{
58 return pwm ? pwm->period : 0;
59}
60
0c2498f1
SH
61/**
62 * struct pwm_ops - PWM controller operations
63 * @request: optional hook for requesting a PWM
64 * @free: optional hook for freeing a PWM
65 * @config: configure duty cycles and period length for this PWM
66 * @enable: enable PWM output toggling
67 * @disable: disable PWM output toggling
68 * @owner: helps prevent removal of modules exporting active PWMs
69 */
70struct pwm_ops {
f051c466
TR
71 int (*request)(struct pwm_chip *chip,
72 struct pwm_device *pwm);
73 void (*free)(struct pwm_chip *chip,
74 struct pwm_device *pwm);
75 int (*config)(struct pwm_chip *chip,
76 struct pwm_device *pwm,
77 int duty_ns, int period_ns);
78 int (*enable)(struct pwm_chip *chip,
79 struct pwm_device *pwm);
80 void (*disable)(struct pwm_chip *chip,
81 struct pwm_device *pwm);
0c2498f1
SH
82 struct module *owner;
83};
84
85/**
f051c466
TR
86 * struct pwm_chip - abstract a PWM controller
87 * @dev: device providing the PWMs
88 * @list: list node for internal use
89 * @ops: callbacks for this PWM controller
90 * @base: number of first PWM controlled by this chip
91 * @npwm: number of PWMs controlled by this chip
92 * @pwms: array of PWM devices allocated by the framework
0c2498f1
SH
93 */
94struct pwm_chip {
f051c466
TR
95 struct device *dev;
96 struct list_head list;
97 const struct pwm_ops *ops;
98 int base;
99 unsigned int npwm;
100
101 struct pwm_device *pwms;
0c2498f1
SH
102};
103
f051c466
TR
104int pwm_set_chip_data(struct pwm_device *pwm, void *data);
105void *pwm_get_chip_data(struct pwm_device *pwm);
106
0c2498f1
SH
107int pwmchip_add(struct pwm_chip *chip);
108int pwmchip_remove(struct pwm_chip *chip);
f051c466
TR
109struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
110 unsigned int index,
111 const char *label);
0c2498f1
SH
112#endif
113
5243ef8b 114#endif /* __LINUX_PWM_H */