Root/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
23enum {
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
37struct pwm_channel;
38struct work_struct;
39
40typedef int (*pwm_handler_t)(struct pwm_channel *p, void *data);
41typedef void (*pwm_callback_t)(struct pwm_channel *p);
42
43struct 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
56struct 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
80int pwm_register(struct pwm_device *pwm);
81int pwm_unregister(struct pwm_device *pwm);
82
83enum {
84    FLAG_REQUESTED = 0,
85    FLAG_STOP = 1,
86};
87
88struct 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
111struct gpio_pwm_platform_data {
112    int gpio;
113};
114
115struct pwm_channel *
116pwm_request(const char *bus_id, int chan,
117        const char *requester);
118
119void pwm_free(struct pwm_channel *pwm);
120
121int pwm_config_nosleep(struct pwm_channel *pwm,
122               struct pwm_channel_config *c);
123
124int pwm_config(struct pwm_channel *pwm,
125           struct pwm_channel_config *c);
126
127unsigned long pwm_ns_to_ticks(struct pwm_channel *pwm,
128                  unsigned long nsecs);
129
130unsigned long pwm_ticks_to_ns(struct pwm_channel *pwm,
131                  unsigned long ticks);
132
133int pwm_set_period_ns(struct pwm_channel *pwm,
134              unsigned long period_ns);
135
136unsigned long int pwm_get_period_ns(struct pwm_channel *pwm);
137
138int pwm_set_duty_ns(struct pwm_channel *pwm,
139            unsigned long duty_ns);
140
141int pwm_set_duty_percent(struct pwm_channel *pwm,
142             int percent);
143
144unsigned long pwm_get_duty_ns(struct pwm_channel *pwm);
145
146int pwm_set_polarity(struct pwm_channel *pwm,
147             int active_high);
148
149int pwm_start(struct pwm_channel *pwm);
150
151int pwm_stop(struct pwm_channel *pwm);
152
153int pwm_set_handler(struct pwm_channel *pwm,
154            pwm_handler_t handler,
155            void *data);
156
157int pwm_synchronize(struct pwm_channel *p,
158            struct pwm_channel *to_p);
159
160
161int pwm_unsynchronize(struct pwm_channel *p,
162              struct pwm_channel *from_p);
163
164
165#endif /* __LINUX_PWM_H */
166

Archive Download this file



interactive