kernel: drop dead glamo code
[openwrt/svn-archive/archive.git] / target / linux / generic / files / include / linux / pwm / pwm.h
1 /*
2 * include/linux/pwm.h
3 *
4 * Copyright (C) 2008 Bill Gatliff < bgat@billgatliff.com>
5 *
6 * This program is free software; you may redistribute and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20 #ifndef __LINUX_PWM_H
21 #define __LINUX_PWM_H
22
23 enum {
24 PWM_CONFIG_DUTY_TICKS = BIT(0),
25 PWM_CONFIG_PERIOD_TICKS = BIT(1),
26 PWM_CONFIG_POLARITY = BIT(2),
27 PWM_CONFIG_START = BIT(3),
28 PWM_CONFIG_STOP = BIT(4),
29
30 PWM_CONFIG_HANDLER = BIT(5),
31
32 PWM_CONFIG_DUTY_NS = BIT(6),
33 PWM_CONFIG_DUTY_PERCENT = BIT(7),
34 PWM_CONFIG_PERIOD_NS = BIT(8),
35 };
36
37 struct pwm_channel;
38 struct work_struct;
39
40 typedef int (*pwm_handler_t)(struct pwm_channel *p, void *data);
41 typedef void (*pwm_callback_t)(struct pwm_channel *p);
42
43 struct pwm_channel_config {
44 int config_mask;
45 unsigned long duty_ticks;
46 unsigned long period_ticks;
47 int polarity;
48
49 pwm_handler_t handler;
50
51 unsigned long duty_ns;
52 unsigned long period_ns;
53 int duty_percent;
54 };
55
56 struct pwm_device {
57 struct list_head list;
58 spinlock_t list_lock;
59 struct device *dev;
60 struct module *owner;
61 struct pwm_channel *channels;
62
63 const char *bus_id;
64 int nchan;
65
66 int (*request) (struct pwm_channel *p);
67 void (*free) (struct pwm_channel *p);
68 int (*config) (struct pwm_channel *p,
69 struct pwm_channel_config *c);
70 int (*config_nosleep)(struct pwm_channel *p,
71 struct pwm_channel_config *c);
72 int (*synchronize) (struct pwm_channel *p,
73 struct pwm_channel *to_p);
74 int (*unsynchronize)(struct pwm_channel *p,
75 struct pwm_channel *from_p);
76 int (*set_callback) (struct pwm_channel *p,
77 pwm_callback_t callback);
78 };
79
80 int pwm_register(struct pwm_device *pwm);
81 int pwm_unregister(struct pwm_device *pwm);
82
83 enum {
84 FLAG_REQUESTED = 0,
85 FLAG_STOP = 1,
86 };
87
88 struct pwm_channel {
89 struct list_head list;
90 struct pwm_device *pwm;
91 const char *requester;
92 pid_t pid;
93 int chan;
94 unsigned long flags;
95 unsigned long tick_hz;
96
97 spinlock_t lock;
98 struct completion complete;
99
100 pwm_callback_t callback;
101
102 struct work_struct handler_work;
103 pwm_handler_t handler;
104 void *handler_data;
105
106 int active_high;
107 unsigned long period_ticks;
108 unsigned long duty_ticks;
109 };
110
111 struct gpio_pwm_platform_data {
112 int gpio;
113 };
114
115 struct pwm_channel *
116 pwm_request(const char *bus_id, int chan,
117 const char *requester);
118
119 void pwm_free(struct pwm_channel *pwm);
120
121 int pwm_config_nosleep(struct pwm_channel *pwm,
122 struct pwm_channel_config *c);
123
124 int pwm_config(struct pwm_channel *pwm,
125 struct pwm_channel_config *c);
126
127 unsigned long pwm_ns_to_ticks(struct pwm_channel *pwm,
128 unsigned long nsecs);
129
130 unsigned long pwm_ticks_to_ns(struct pwm_channel *pwm,
131 unsigned long ticks);
132
133 int pwm_set_period_ns(struct pwm_channel *pwm,
134 unsigned long period_ns);
135
136 unsigned long int pwm_get_period_ns(struct pwm_channel *pwm);
137
138 int pwm_set_duty_ns(struct pwm_channel *pwm,
139 unsigned long duty_ns);
140
141 int pwm_set_duty_percent(struct pwm_channel *pwm,
142 int percent);
143
144 unsigned long pwm_get_duty_ns(struct pwm_channel *pwm);
145
146 int pwm_set_polarity(struct pwm_channel *pwm,
147 int active_high);
148
149 int pwm_start(struct pwm_channel *pwm);
150
151 int pwm_stop(struct pwm_channel *pwm);
152
153 int pwm_set_handler(struct pwm_channel *pwm,
154 pwm_handler_t handler,
155 void *data);
156
157 int pwm_synchronize(struct pwm_channel *p,
158 struct pwm_channel *to_p);
159
160
161 int pwm_unsynchronize(struct pwm_channel *p,
162 struct pwm_channel *from_p);
163
164
165 #endif /* __LINUX_PWM_H */