4 * Copyright (C) 2008 Bill Gatliff < bgat@billgatliff.com>
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.
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.
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
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),
30 PWM_CONFIG_HANDLER = BIT(5),
32 PWM_CONFIG_DUTY_NS = BIT(6),
33 PWM_CONFIG_DUTY_PERCENT = BIT(7),
34 PWM_CONFIG_PERIOD_NS = BIT(8),
40 typedef int (*pwm_handler_t)(struct pwm_channel *p, void *data);
41 typedef void (*pwm_callback_t)(struct pwm_channel *p);
43 struct pwm_channel_config {
45 unsigned long duty_ticks;
46 unsigned long period_ticks;
49 pwm_handler_t handler;
51 unsigned long duty_ns;
52 unsigned long period_ns;
57 struct list_head list;
61 struct pwm_channel *channels;
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);
80 int pwm_register(struct pwm_device *pwm);
81 int pwm_unregister(struct pwm_device *pwm);
89 struct list_head list;
90 struct pwm_device *pwm;
91 const char *requester;
95 unsigned long tick_hz;
98 struct completion complete;
100 pwm_callback_t callback;
102 struct work_struct handler_work;
103 pwm_handler_t handler;
107 unsigned long period_ticks;
108 unsigned long duty_ticks;
111 struct gpio_pwm_platform_data {
116 pwm_request(const char *bus_id, int chan,
117 const char *requester);
119 void pwm_free(struct pwm_channel *pwm);
121 int pwm_config_nosleep(struct pwm_channel *pwm,
122 struct pwm_channel_config *c);
124 int pwm_config(struct pwm_channel *pwm,
125 struct pwm_channel_config *c);
127 unsigned long pwm_ns_to_ticks(struct pwm_channel *pwm,
128 unsigned long nsecs);
130 unsigned long pwm_ticks_to_ns(struct pwm_channel *pwm,
131 unsigned long ticks);
133 int pwm_set_period_ns(struct pwm_channel *pwm,
134 unsigned long period_ns);
136 unsigned long int pwm_get_period_ns(struct pwm_channel *pwm);
138 int pwm_set_duty_ns(struct pwm_channel *pwm,
139 unsigned long duty_ns);
141 int pwm_set_duty_percent(struct pwm_channel *pwm,
144 unsigned long pwm_get_duty_ns(struct pwm_channel *pwm);
146 int pwm_set_polarity(struct pwm_channel *pwm,
149 int pwm_start(struct pwm_channel *pwm);
151 int pwm_stop(struct pwm_channel *pwm);
153 int pwm_set_handler(struct pwm_channel *pwm,
154 pwm_handler_t handler,
157 int pwm_synchronize(struct pwm_channel *p,
158 struct pwm_channel *to_p);
161 int pwm_unsynchronize(struct pwm_channel *p,
162 struct pwm_channel *from_p);
165 #endif /* __LINUX_PWM_H */