pwm: i.MX: fix clock lookup
[deliverable/linux.git] / include / linux / pwm.h
CommitLineData
1a189b97
RK
1#ifndef __LINUX_PWM_H
2#define __LINUX_PWM_H
3
7299ab70
TR
4#include <linux/of.h>
5
1a189b97 6struct pwm_device;
62099abf 7struct seq_file;
1a189b97
RK
8
9/*
10 * pwm_request - request a PWM device
11 */
12struct pwm_device *pwm_request(int pwm_id, const char *label);
13
14/*
15 * pwm_free - free a PWM device
16 */
17void pwm_free(struct pwm_device *pwm);
18
19/*
20 * pwm_config - change a PWM device configuration
21 */
22int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);
23
24/*
25 * pwm_enable - start a PWM output toggling
26 */
27int pwm_enable(struct pwm_device *pwm);
28
29/*
30 * pwm_disable - stop a PWM output toggling
31 */
32void pwm_disable(struct pwm_device *pwm);
33
0c2498f1
SH
34#ifdef CONFIG_PWM
35struct pwm_chip;
36
0aa0869c
PA
37/**
38 * enum pwm_polarity - polarity of a PWM signal
39 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
40 * cycle, followed by a low signal for the remainder of the pulse
41 * period
42 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
43 * cycle, followed by a high signal for the remainder of the pulse
44 * period
45 */
46enum pwm_polarity {
47 PWM_POLARITY_NORMAL,
48 PWM_POLARITY_INVERSED,
49};
50
f051c466
TR
51enum {
52 PWMF_REQUESTED = 1 << 0,
53 PWMF_ENABLED = 1 << 1,
54};
55
56struct pwm_device {
57 const char *label;
58 unsigned long flags;
59 unsigned int hwpwm;
60 unsigned int pwm;
61 struct pwm_chip *chip;
62 void *chip_data;
63
64 unsigned int period; /* in nanoseconds */
65};
66
67static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
68{
69 if (pwm)
70 pwm->period = period;
71}
72
73static inline unsigned int pwm_get_period(struct pwm_device *pwm)
74{
75 return pwm ? pwm->period : 0;
76}
77
0aa0869c
PA
78/*
79 * pwm_set_polarity - configure the polarity of a PWM signal
80 */
81int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
82
0c2498f1
SH
83/**
84 * struct pwm_ops - PWM controller operations
85 * @request: optional hook for requesting a PWM
86 * @free: optional hook for freeing a PWM
87 * @config: configure duty cycles and period length for this PWM
0aa0869c 88 * @set_polarity: configure the polarity of this PWM
0c2498f1
SH
89 * @enable: enable PWM output toggling
90 * @disable: disable PWM output toggling
62099abf 91 * @dbg_show: optional routine to show contents in debugfs
0c2498f1
SH
92 * @owner: helps prevent removal of modules exporting active PWMs
93 */
94struct pwm_ops {
f051c466
TR
95 int (*request)(struct pwm_chip *chip,
96 struct pwm_device *pwm);
97 void (*free)(struct pwm_chip *chip,
98 struct pwm_device *pwm);
99 int (*config)(struct pwm_chip *chip,
100 struct pwm_device *pwm,
101 int duty_ns, int period_ns);
0aa0869c
PA
102 int (*set_polarity)(struct pwm_chip *chip,
103 struct pwm_device *pwm,
104 enum pwm_polarity polarity);
f051c466
TR
105 int (*enable)(struct pwm_chip *chip,
106 struct pwm_device *pwm);
107 void (*disable)(struct pwm_chip *chip,
108 struct pwm_device *pwm);
62099abf
TR
109#ifdef CONFIG_DEBUG_FS
110 void (*dbg_show)(struct pwm_chip *chip,
111 struct seq_file *s);
112#endif
0c2498f1
SH
113 struct module *owner;
114};
115
116/**
f051c466
TR
117 * struct pwm_chip - abstract a PWM controller
118 * @dev: device providing the PWMs
119 * @list: list node for internal use
120 * @ops: callbacks for this PWM controller
121 * @base: number of first PWM controlled by this chip
122 * @npwm: number of PWMs controlled by this chip
123 * @pwms: array of PWM devices allocated by the framework
0c2498f1
SH
124 */
125struct pwm_chip {
f051c466
TR
126 struct device *dev;
127 struct list_head list;
128 const struct pwm_ops *ops;
129 int base;
130 unsigned int npwm;
131
132 struct pwm_device *pwms;
7299ab70
TR
133
134 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
135 const struct of_phandle_args *args);
136 unsigned int of_pwm_n_cells;
0c2498f1
SH
137};
138
f051c466
TR
139int pwm_set_chip_data(struct pwm_device *pwm, void *data);
140void *pwm_get_chip_data(struct pwm_device *pwm);
141
0c2498f1
SH
142int pwmchip_add(struct pwm_chip *chip);
143int pwmchip_remove(struct pwm_chip *chip);
f051c466
TR
144struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
145 unsigned int index,
146 const char *label);
8138d2dd
TR
147
148struct pwm_device *pwm_get(struct device *dev, const char *consumer);
149void pwm_put(struct pwm_device *pwm);
150
6354316d
AC
151struct pwm_device *devm_pwm_get(struct device *dev, const char *consumer);
152void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
153
8138d2dd
TR
154struct pwm_lookup {
155 struct list_head list;
156 const char *provider;
157 unsigned int index;
158 const char *dev_id;
159 const char *con_id;
160};
161
162#define PWM_LOOKUP(_provider, _index, _dev_id, _con_id) \
163 { \
164 .provider = _provider, \
165 .index = _index, \
166 .dev_id = _dev_id, \
167 .con_id = _con_id, \
168 }
169
170void pwm_add_table(struct pwm_lookup *table, size_t num);
171
0c2498f1
SH
172#endif
173
5243ef8b 174#endif /* __LINUX_PWM_H */
This page took 0.510145 seconds and 5 git commands to generate.