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 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 37 | enum { |
| 38 | PWMF_REQUESTED = 1 << 0, |
| 39 | PWMF_ENABLED = 1 << 1, |
| 40 | }; |
| 41 | |
| 42 | struct pwm_device { |
| 43 | const char *label; |
| 44 | unsigned long flags; |
| 45 | unsigned int hwpwm; |
| 46 | unsigned int pwm; |
| 47 | struct pwm_chip *chip; |
| 48 | void *chip_data; |
| 49 | |
| 50 | unsigned int period; /* in nanoseconds */ |
| 51 | }; |
| 52 | |
| 53 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| 54 | { |
| 55 | if (pwm) |
| 56 | pwm->period = period; |
| 57 | } |
| 58 | |
| 59 | static inline unsigned int pwm_get_period(struct pwm_device *pwm) |
| 60 | { |
| 61 | return pwm ? pwm->period : 0; |
| 62 | } |
| 63 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 64 | /** |
| 65 | * struct pwm_ops - PWM controller operations |
| 66 | * @request: optional hook for requesting a PWM |
| 67 | * @free: optional hook for freeing a PWM |
| 68 | * @config: configure duty cycles and period length for this PWM |
| 69 | * @enable: enable PWM output toggling |
| 70 | * @disable: disable PWM output toggling |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 71 | * @dbg_show: optional routine to show contents in debugfs |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 72 | * @owner: helps prevent removal of modules exporting active PWMs |
| 73 | */ |
| 74 | struct pwm_ops { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 75 | int (*request)(struct pwm_chip *chip, |
| 76 | struct pwm_device *pwm); |
| 77 | void (*free)(struct pwm_chip *chip, |
| 78 | struct pwm_device *pwm); |
| 79 | int (*config)(struct pwm_chip *chip, |
| 80 | struct pwm_device *pwm, |
| 81 | int duty_ns, int period_ns); |
| 82 | int (*enable)(struct pwm_chip *chip, |
| 83 | struct pwm_device *pwm); |
| 84 | void (*disable)(struct pwm_chip *chip, |
| 85 | struct pwm_device *pwm); |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_DEBUG_FS |
| 87 | void (*dbg_show)(struct pwm_chip *chip, |
| 88 | struct seq_file *s); |
| 89 | #endif |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 90 | struct module *owner; |
| 91 | }; |
| 92 | |
| 93 | /** |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 94 | * struct pwm_chip - abstract a PWM controller |
| 95 | * @dev: device providing the PWMs |
| 96 | * @list: list node for internal use |
| 97 | * @ops: callbacks for this PWM controller |
| 98 | * @base: number of first PWM controlled by this chip |
| 99 | * @npwm: number of PWMs controlled by this chip |
| 100 | * @pwms: array of PWM devices allocated by the framework |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 101 | */ |
| 102 | struct pwm_chip { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 103 | struct device *dev; |
| 104 | struct list_head list; |
| 105 | const struct pwm_ops *ops; |
| 106 | int base; |
| 107 | unsigned int npwm; |
| 108 | |
| 109 | struct pwm_device *pwms; |
Thierry Reding | 7299ab7 | 2011-12-14 11:10:32 +0100 | [diff] [blame] | 110 | |
| 111 | struct pwm_device * (*of_xlate)(struct pwm_chip *pc, |
| 112 | const struct of_phandle_args *args); |
| 113 | unsigned int of_pwm_n_cells; |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 116 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
| 117 | void *pwm_get_chip_data(struct pwm_device *pwm); |
| 118 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 119 | int pwmchip_add(struct pwm_chip *chip); |
| 120 | int pwmchip_remove(struct pwm_chip *chip); |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 121 | struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
| 122 | unsigned int index, |
| 123 | const char *label); |
Thierry Reding | 8138d2d | 2012-03-26 08:42:48 +0200 | [diff] [blame] | 124 | |
| 125 | struct pwm_device *pwm_get(struct device *dev, const char *consumer); |
| 126 | void pwm_put(struct pwm_device *pwm); |
| 127 | |
| 128 | struct pwm_lookup { |
| 129 | struct list_head list; |
| 130 | const char *provider; |
| 131 | unsigned int index; |
| 132 | const char *dev_id; |
| 133 | const char *con_id; |
| 134 | }; |
| 135 | |
| 136 | #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id) \ |
| 137 | { \ |
| 138 | .provider = _provider, \ |
| 139 | .index = _index, \ |
| 140 | .dev_id = _dev_id, \ |
| 141 | .con_id = _con_id, \ |
| 142 | } |
| 143 | |
| 144 | void pwm_add_table(struct pwm_lookup *table, size_t num); |
| 145 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 146 | #endif |
| 147 | |
Mark Vels | 5243ef8 | 2009-01-18 18:42:45 +0100 | [diff] [blame] | 148 | #endif /* __LINUX_PWM_H */ |