Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 1 | #ifndef __LINUX_PWM_H |
| 2 | #define __LINUX_PWM_H |
| 3 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 4 | #include <linux/err.h> |
Jonathan Richardson | d1cd214 | 2015-10-16 17:40:58 -0700 | [diff] [blame] | 5 | #include <linux/mutex.h> |
Thierry Reding | 7299ab7 | 2011-12-14 11:10:32 +0100 | [diff] [blame] | 6 | #include <linux/of.h> |
| 7 | |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 8 | struct pwm_device; |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 9 | struct seq_file; |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 10 | |
Sascha Hauer | 557fe99 | 2014-01-24 08:54:16 +0100 | [diff] [blame] | 11 | #if IS_ENABLED(CONFIG_PWM) |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 12 | /* |
| 13 | * pwm_request - request a PWM device |
| 14 | */ |
| 15 | struct pwm_device *pwm_request(int pwm_id, const char *label); |
| 16 | |
| 17 | /* |
| 18 | * pwm_free - free a PWM device |
| 19 | */ |
| 20 | void pwm_free(struct pwm_device *pwm); |
| 21 | |
| 22 | /* |
| 23 | * pwm_config - change a PWM device configuration |
| 24 | */ |
| 25 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); |
| 26 | |
| 27 | /* |
| 28 | * pwm_enable - start a PWM output toggling |
| 29 | */ |
| 30 | int pwm_enable(struct pwm_device *pwm); |
| 31 | |
| 32 | /* |
| 33 | * pwm_disable - stop a PWM output toggling |
| 34 | */ |
| 35 | void pwm_disable(struct pwm_device *pwm); |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 36 | #else |
| 37 | static inline struct pwm_device *pwm_request(int pwm_id, const char *label) |
| 38 | { |
| 39 | return ERR_PTR(-ENODEV); |
| 40 | } |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 41 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 42 | static inline void pwm_free(struct pwm_device *pwm) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | static inline int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns) |
| 47 | { |
| 48 | return -EINVAL; |
| 49 | } |
| 50 | |
| 51 | static inline int pwm_enable(struct pwm_device *pwm) |
| 52 | { |
| 53 | return -EINVAL; |
| 54 | } |
| 55 | |
| 56 | static inline void pwm_disable(struct pwm_device *pwm) |
| 57 | { |
| 58 | } |
| 59 | #endif |
| 60 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 61 | struct pwm_chip; |
| 62 | |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 63 | /** |
| 64 | * enum pwm_polarity - polarity of a PWM signal |
| 65 | * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty- |
| 66 | * cycle, followed by a low signal for the remainder of the pulse |
| 67 | * period |
| 68 | * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty- |
| 69 | * cycle, followed by a high signal for the remainder of the pulse |
| 70 | * period |
| 71 | */ |
| 72 | enum pwm_polarity { |
| 73 | PWM_POLARITY_NORMAL, |
| 74 | PWM_POLARITY_INVERSED, |
| 75 | }; |
| 76 | |
Boris Brezillon | e39c0df | 2016-04-14 21:17:21 +0200 | [diff] [blame] | 77 | /** |
| 78 | * struct pwm_args - board-dependent PWM arguments |
| 79 | * @period: reference period |
| 80 | * @polarity: reference polarity |
| 81 | * |
| 82 | * This structure describes board-dependent arguments attached to a PWM |
| 83 | * device. These arguments are usually retrieved from the PWM lookup table or |
| 84 | * device tree. |
| 85 | * |
| 86 | * Do not confuse this with the PWM state: PWM arguments represent the initial |
| 87 | * configuration that users want to use on this PWM device rather than the |
| 88 | * current PWM hardware state. |
| 89 | */ |
| 90 | struct pwm_args { |
| 91 | unsigned int period; |
| 92 | enum pwm_polarity polarity; |
| 93 | }; |
| 94 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 95 | enum { |
| 96 | PWMF_REQUESTED = 1 << 0, |
| 97 | PWMF_ENABLED = 1 << 1, |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 98 | PWMF_EXPORTED = 1 << 2, |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 101 | /* |
| 102 | * struct pwm_state - state of a PWM channel |
| 103 | * @period: PWM period (in nanoseconds) |
| 104 | * @duty_cycle: PWM duty cycle (in nanoseconds) |
| 105 | * @polarity: PWM polarity |
| 106 | */ |
| 107 | struct pwm_state { |
| 108 | unsigned int period; |
| 109 | unsigned int duty_cycle; |
| 110 | enum pwm_polarity polarity; |
| 111 | }; |
| 112 | |
Thierry Reding | 0488380 | 2015-07-27 11:58:32 +0200 | [diff] [blame] | 113 | /** |
| 114 | * struct pwm_device - PWM channel object |
| 115 | * @label: name of the PWM device |
| 116 | * @flags: flags associated with the PWM device |
| 117 | * @hwpwm: per-chip relative index of the PWM device |
| 118 | * @pwm: global index of the PWM device |
| 119 | * @chip: PWM chip providing this PWM device |
| 120 | * @chip_data: chip-private data associated with the PWM device |
Boris Brezillon | e39c0df | 2016-04-14 21:17:21 +0200 | [diff] [blame] | 121 | * @args: PWM arguments |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 122 | * @state: curent PWM channel state |
Thierry Reding | 0488380 | 2015-07-27 11:58:32 +0200 | [diff] [blame] | 123 | */ |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 124 | struct pwm_device { |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 125 | const char *label; |
| 126 | unsigned long flags; |
| 127 | unsigned int hwpwm; |
| 128 | unsigned int pwm; |
| 129 | struct pwm_chip *chip; |
| 130 | void *chip_data; |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 131 | |
Boris Brezillon | e39c0df | 2016-04-14 21:17:21 +0200 | [diff] [blame] | 132 | struct pwm_args args; |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 133 | struct pwm_state state; |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 134 | }; |
| 135 | |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 136 | /** |
| 137 | * pwm_get_state() - retrieve the current PWM state |
| 138 | * @pwm: PWM device |
| 139 | * @state: state to fill with the current PWM state |
| 140 | */ |
| 141 | static inline void pwm_get_state(const struct pwm_device *pwm, |
| 142 | struct pwm_state *state) |
| 143 | { |
| 144 | *state = pwm->state; |
| 145 | } |
| 146 | |
Boris Brezillon | 5c31252 | 2015-07-01 10:21:47 +0200 | [diff] [blame] | 147 | static inline bool pwm_is_enabled(const struct pwm_device *pwm) |
| 148 | { |
| 149 | return test_bit(PWMF_ENABLED, &pwm->flags); |
| 150 | } |
| 151 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 152 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| 153 | { |
| 154 | if (pwm) |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 155 | pwm->state.period = period; |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Boris Brezillon | a1cf421 | 2015-07-01 10:21:48 +0200 | [diff] [blame] | 158 | static inline unsigned int pwm_get_period(const struct pwm_device *pwm) |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 159 | { |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 160 | struct pwm_state state; |
| 161 | |
| 162 | pwm_get_state(pwm, &state); |
| 163 | |
| 164 | return state.period; |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 165 | } |
| 166 | |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 167 | static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty) |
| 168 | { |
| 169 | if (pwm) |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 170 | pwm->state.duty_cycle = duty; |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Boris Brezillon | a1cf421 | 2015-07-01 10:21:48 +0200 | [diff] [blame] | 173 | static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm) |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 174 | { |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 175 | struct pwm_state state; |
| 176 | |
| 177 | pwm_get_state(pwm, &state); |
| 178 | |
| 179 | return state.duty_cycle; |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 182 | /* |
| 183 | * pwm_set_polarity - configure the polarity of a PWM signal |
| 184 | */ |
| 185 | int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity); |
| 186 | |
Boris Brezillon | 011e763 | 2015-07-01 10:21:49 +0200 | [diff] [blame] | 187 | static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) |
| 188 | { |
Boris Brezillon | 43a276b | 2016-04-14 21:17:38 +0200 | [diff] [blame^] | 189 | struct pwm_state state; |
| 190 | |
| 191 | pwm_get_state(pwm, &state); |
| 192 | |
| 193 | return state.polarity; |
Boris Brezillon | 011e763 | 2015-07-01 10:21:49 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Boris Brezillon | e39c0df | 2016-04-14 21:17:21 +0200 | [diff] [blame] | 196 | static inline void pwm_get_args(const struct pwm_device *pwm, |
| 197 | struct pwm_args *args) |
| 198 | { |
| 199 | *args = pwm->args; |
| 200 | } |
| 201 | |
| 202 | static inline void pwm_apply_args(struct pwm_device *pwm) |
| 203 | { |
Boris Brezillon | e39c0df | 2016-04-14 21:17:21 +0200 | [diff] [blame] | 204 | pwm_set_polarity(pwm, pwm->args.polarity); |
| 205 | } |
| 206 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 207 | /** |
| 208 | * struct pwm_ops - PWM controller operations |
| 209 | * @request: optional hook for requesting a PWM |
| 210 | * @free: optional hook for freeing a PWM |
| 211 | * @config: configure duty cycles and period length for this PWM |
Philip, Avinash | 0aa0869 | 2012-07-24 19:35:32 +0530 | [diff] [blame] | 212 | * @set_polarity: configure the polarity of this PWM |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 213 | * @enable: enable PWM output toggling |
| 214 | * @disable: disable PWM output toggling |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 215 | * @dbg_show: optional routine to show contents in debugfs |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 216 | * @owner: helps prevent removal of modules exporting active PWMs |
| 217 | */ |
| 218 | struct pwm_ops { |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 219 | int (*request)(struct pwm_chip *chip, struct pwm_device *pwm); |
| 220 | void (*free)(struct pwm_chip *chip, struct pwm_device *pwm); |
| 221 | int (*config)(struct pwm_chip *chip, struct pwm_device *pwm, |
| 222 | int duty_ns, int period_ns); |
| 223 | int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm, |
| 224 | enum pwm_polarity polarity); |
| 225 | int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); |
| 226 | void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 227 | #ifdef CONFIG_DEBUG_FS |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 228 | void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s); |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 229 | #endif |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 230 | struct module *owner; |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | /** |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 234 | * struct pwm_chip - abstract a PWM controller |
| 235 | * @dev: device providing the PWMs |
| 236 | * @list: list node for internal use |
| 237 | * @ops: callbacks for this PWM controller |
| 238 | * @base: number of first PWM controlled by this chip |
| 239 | * @npwm: number of PWMs controlled by this chip |
| 240 | * @pwms: array of PWM devices allocated by the framework |
Thierry Reding | 0488380 | 2015-07-27 11:58:32 +0200 | [diff] [blame] | 241 | * @of_xlate: request a PWM device given a device tree PWM specifier |
| 242 | * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier |
Florian Vaussard | 6e69ab1 | 2013-01-28 15:00:57 +0100 | [diff] [blame] | 243 | * @can_sleep: must be true if the .config(), .enable() or .disable() |
| 244 | * operations may sleep |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 245 | */ |
| 246 | struct pwm_chip { |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 247 | struct device *dev; |
| 248 | struct list_head list; |
| 249 | const struct pwm_ops *ops; |
| 250 | int base; |
| 251 | unsigned int npwm; |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 252 | |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 253 | struct pwm_device *pwms; |
Thierry Reding | 7299ab7 | 2011-12-14 11:10:32 +0100 | [diff] [blame] | 254 | |
Thierry Reding | 6bc7064 | 2015-07-27 11:57:28 +0200 | [diff] [blame] | 255 | struct pwm_device * (*of_xlate)(struct pwm_chip *pc, |
| 256 | const struct of_phandle_args *args); |
| 257 | unsigned int of_pwm_n_cells; |
| 258 | bool can_sleep; |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 259 | }; |
| 260 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 261 | #if IS_ENABLED(CONFIG_PWM) |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 262 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
| 263 | void *pwm_get_chip_data(struct pwm_device *pwm); |
| 264 | |
Tim Kryger | b6a00fa | 2015-05-26 13:08:16 -0700 | [diff] [blame] | 265 | int pwmchip_add_with_polarity(struct pwm_chip *chip, |
| 266 | enum pwm_polarity polarity); |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 267 | int pwmchip_add(struct pwm_chip *chip); |
| 268 | int pwmchip_remove(struct pwm_chip *chip); |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 269 | struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
| 270 | unsigned int index, |
| 271 | const char *label); |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 272 | |
Philip, Avinash | 83af240 | 2012-11-21 13:10:44 +0530 | [diff] [blame] | 273 | struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc, |
| 274 | const struct of_phandle_args *args); |
| 275 | |
Peter Ujfalusi | d4c0c47 | 2012-12-21 01:43:57 -0800 | [diff] [blame] | 276 | struct pwm_device *pwm_get(struct device *dev, const char *con_id); |
Peter Ujfalusi | 8eb9612 | 2012-12-21 01:43:58 -0800 | [diff] [blame] | 277 | struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id); |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 278 | void pwm_put(struct pwm_device *pwm); |
| 279 | |
Peter Ujfalusi | d4c0c47 | 2012-12-21 01:43:57 -0800 | [diff] [blame] | 280 | struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id); |
Peter Ujfalusi | 261a5ed | 2012-12-21 01:43:59 -0800 | [diff] [blame] | 281 | struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, |
| 282 | const char *con_id); |
Alexandre Courbot | 6354316 | 2012-08-01 19:20:58 +0900 | [diff] [blame] | 283 | void devm_pwm_put(struct device *dev, struct pwm_device *pwm); |
Florian Vaussard | 6e69ab1 | 2013-01-28 15:00:57 +0100 | [diff] [blame] | 284 | |
| 285 | bool pwm_can_sleep(struct pwm_device *pwm); |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 286 | #else |
| 287 | static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data) |
| 288 | { |
| 289 | return -EINVAL; |
| 290 | } |
| 291 | |
| 292 | static inline void *pwm_get_chip_data(struct pwm_device *pwm) |
| 293 | { |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | static inline int pwmchip_add(struct pwm_chip *chip) |
| 298 | { |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | |
Tim Kryger | b6a00fa | 2015-05-26 13:08:16 -0700 | [diff] [blame] | 302 | static inline int pwmchip_add_inversed(struct pwm_chip *chip) |
| 303 | { |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 307 | static inline int pwmchip_remove(struct pwm_chip *chip) |
| 308 | { |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
| 313 | unsigned int index, |
| 314 | const char *label) |
| 315 | { |
| 316 | return ERR_PTR(-ENODEV); |
| 317 | } |
| 318 | |
| 319 | static inline struct pwm_device *pwm_get(struct device *dev, |
| 320 | const char *consumer) |
| 321 | { |
| 322 | return ERR_PTR(-ENODEV); |
| 323 | } |
| 324 | |
Peter Ujfalusi | 8eb9612 | 2012-12-21 01:43:58 -0800 | [diff] [blame] | 325 | static inline struct pwm_device *of_pwm_get(struct device_node *np, |
| 326 | const char *con_id) |
| 327 | { |
| 328 | return ERR_PTR(-ENODEV); |
| 329 | } |
| 330 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 331 | static inline void pwm_put(struct pwm_device *pwm) |
| 332 | { |
| 333 | } |
| 334 | |
| 335 | static inline struct pwm_device *devm_pwm_get(struct device *dev, |
| 336 | const char *consumer) |
| 337 | { |
| 338 | return ERR_PTR(-ENODEV); |
| 339 | } |
| 340 | |
Peter Ujfalusi | 261a5ed | 2012-12-21 01:43:59 -0800 | [diff] [blame] | 341 | static inline struct pwm_device *devm_of_pwm_get(struct device *dev, |
| 342 | struct device_node *np, |
| 343 | const char *con_id) |
| 344 | { |
| 345 | return ERR_PTR(-ENODEV); |
| 346 | } |
| 347 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 348 | static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm) |
| 349 | { |
| 350 | } |
Florian Vaussard | 6e69ab1 | 2013-01-28 15:00:57 +0100 | [diff] [blame] | 351 | |
| 352 | static inline bool pwm_can_sleep(struct pwm_device *pwm) |
| 353 | { |
| 354 | return false; |
| 355 | } |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 356 | #endif |
Alexandre Courbot | 6354316 | 2012-08-01 19:20:58 +0900 | [diff] [blame] | 357 | |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 358 | struct pwm_lookup { |
| 359 | struct list_head list; |
| 360 | const char *provider; |
| 361 | unsigned int index; |
| 362 | const char *dev_id; |
| 363 | const char *con_id; |
Alexandre Belloni | 3796ce1 | 2014-05-19 22:42:32 +0200 | [diff] [blame] | 364 | unsigned int period; |
| 365 | enum pwm_polarity polarity; |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 366 | }; |
| 367 | |
Alexandre Belloni | 4284402 | 2014-05-19 22:42:37 +0200 | [diff] [blame] | 368 | #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \ |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 369 | { \ |
| 370 | .provider = _provider, \ |
| 371 | .index = _index, \ |
| 372 | .dev_id = _dev_id, \ |
| 373 | .con_id = _con_id, \ |
Alexandre Belloni | 4284402 | 2014-05-19 22:42:37 +0200 | [diff] [blame] | 374 | .period = _period, \ |
| 375 | .polarity = _polarity \ |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 378 | #if IS_ENABLED(CONFIG_PWM) |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 379 | void pwm_add_table(struct pwm_lookup *table, size_t num); |
Shobhit Kumar | efb0de5 | 2015-05-05 15:04:18 +0530 | [diff] [blame] | 380 | void pwm_remove_table(struct pwm_lookup *table, size_t num); |
Tushar Behera | 0bcf168 | 2012-09-12 15:31:46 +0530 | [diff] [blame] | 381 | #else |
| 382 | static inline void pwm_add_table(struct pwm_lookup *table, size_t num) |
| 383 | { |
| 384 | } |
Shobhit Kumar | efb0de5 | 2015-05-05 15:04:18 +0530 | [diff] [blame] | 385 | |
| 386 | static inline void pwm_remove_table(struct pwm_lookup *table, size_t num) |
| 387 | { |
| 388 | } |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 389 | #endif |
| 390 | |
H Hartley Sweeten | 76abbdde | 2013-06-11 10:38:59 -0700 | [diff] [blame] | 391 | #ifdef CONFIG_PWM_SYSFS |
| 392 | void pwmchip_sysfs_export(struct pwm_chip *chip); |
| 393 | void pwmchip_sysfs_unexport(struct pwm_chip *chip); |
| 394 | #else |
| 395 | static inline void pwmchip_sysfs_export(struct pwm_chip *chip) |
| 396 | { |
| 397 | } |
| 398 | |
| 399 | static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip) |
| 400 | { |
| 401 | } |
| 402 | #endif /* CONFIG_PWM_SYSFS */ |
| 403 | |
Mark Vels | 5243ef8 | 2009-01-18 18:42:45 +0100 | [diff] [blame] | 404 | #endif /* __LINUX_PWM_H */ |