Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 1 | #ifndef __LINUX_PWM_H |
| 2 | #define __LINUX_PWM_H |
| 3 | |
Thierry Reding | 7299ab7 | 2011-12-14 11:10:32 +0100 | [diff] [blame] | 4 | #include <linux/of.h> |
| 5 | |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 6 | struct pwm_device; |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 7 | struct seq_file; |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 8 | |
| 9 | /* |
| 10 | * pwm_request - request a PWM device |
| 11 | */ |
| 12 | struct pwm_device *pwm_request(int pwm_id, const char *label); |
| 13 | |
| 14 | /* |
| 15 | * pwm_free - free a PWM device |
| 16 | */ |
| 17 | void pwm_free(struct pwm_device *pwm); |
| 18 | |
| 19 | /* |
| 20 | * pwm_config - change a PWM device configuration |
| 21 | */ |
| 22 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); |
| 23 | |
| 24 | /* |
| 25 | * pwm_enable - start a PWM output toggling |
| 26 | */ |
| 27 | int pwm_enable(struct pwm_device *pwm); |
| 28 | |
| 29 | /* |
| 30 | * pwm_disable - stop a PWM output toggling |
| 31 | */ |
| 32 | void pwm_disable(struct pwm_device *pwm); |
| 33 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 34 | #ifdef CONFIG_PWM |
| 35 | struct pwm_chip; |
| 36 | |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 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 | */ |
| 46 | enum pwm_polarity { |
| 47 | PWM_POLARITY_NORMAL, |
| 48 | PWM_POLARITY_INVERSED, |
| 49 | }; |
| 50 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 51 | enum { |
| 52 | PWMF_REQUESTED = 1 << 0, |
| 53 | PWMF_ENABLED = 1 << 1, |
| 54 | }; |
| 55 | |
| 56 | struct 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 | |
| 67 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| 68 | { |
| 69 | if (pwm) |
| 70 | pwm->period = period; |
| 71 | } |
| 72 | |
| 73 | static inline unsigned int pwm_get_period(struct pwm_device *pwm) |
| 74 | { |
| 75 | return pwm ? pwm->period : 0; |
| 76 | } |
| 77 | |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 78 | /* |
| 79 | * pwm_set_polarity - configure the polarity of a PWM signal |
| 80 | */ |
| 81 | int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity); |
| 82 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 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 |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 88 | * @set_polarity: configure the polarity of this PWM |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 89 | * @enable: enable PWM output toggling |
| 90 | * @disable: disable PWM output toggling |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 91 | * @dbg_show: optional routine to show contents in debugfs |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 92 | * @owner: helps prevent removal of modules exporting active PWMs |
| 93 | */ |
| 94 | struct pwm_ops { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 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); |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 102 | int (*set_polarity)(struct pwm_chip *chip, |
| 103 | struct pwm_device *pwm, |
| 104 | enum pwm_polarity polarity); |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 105 | int (*enable)(struct pwm_chip *chip, |
| 106 | struct pwm_device *pwm); |
| 107 | void (*disable)(struct pwm_chip *chip, |
| 108 | struct pwm_device *pwm); |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 109 | #ifdef CONFIG_DEBUG_FS |
| 110 | void (*dbg_show)(struct pwm_chip *chip, |
| 111 | struct seq_file *s); |
| 112 | #endif |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 113 | struct module *owner; |
| 114 | }; |
| 115 | |
| 116 | /** |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 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 |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 124 | */ |
| 125 | struct pwm_chip { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 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; |
Thierry Reding | 7299ab7 | 2011-12-14 11:10:32 +0100 | [diff] [blame] | 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; |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 137 | }; |
| 138 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 139 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
| 140 | void *pwm_get_chip_data(struct pwm_device *pwm); |
| 141 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 142 | int pwmchip_add(struct pwm_chip *chip); |
| 143 | int pwmchip_remove(struct pwm_chip *chip); |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 144 | struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
| 145 | unsigned int index, |
| 146 | const char *label); |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 147 | |
| 148 | struct pwm_device *pwm_get(struct device *dev, const char *consumer); |
| 149 | void pwm_put(struct pwm_device *pwm); |
| 150 | |
Alexandre Courbot | 6354316 | 2012-08-01 19:20:58 +0900 | [diff] [blame^] | 151 | struct pwm_device *devm_pwm_get(struct device *dev, const char *consumer); |
| 152 | void devm_pwm_put(struct device *dev, struct pwm_device *pwm); |
| 153 | |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 154 | struct 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 | |
| 170 | void pwm_add_table(struct pwm_lookup *table, size_t num); |
| 171 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 172 | #endif |
| 173 | |
Mark Vels | 5243ef8 | 2009-01-18 18:42:45 +0100 | [diff] [blame] | 174 | #endif /* __LINUX_PWM_H */ |