Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 1 | #ifndef __LINUX_PWM_H |
| 2 | #define __LINUX_PWM_H |
| 3 | |
| 4 | struct pwm_device; |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame^] | 5 | struct seq_file; |
Russell King | 1a189b9 | 2008-04-13 21:41:55 +0100 | [diff] [blame] | 6 | |
| 7 | /* |
| 8 | * pwm_request - request a PWM device |
| 9 | */ |
| 10 | struct pwm_device *pwm_request(int pwm_id, const char *label); |
| 11 | |
| 12 | /* |
| 13 | * pwm_free - free a PWM device |
| 14 | */ |
| 15 | void pwm_free(struct pwm_device *pwm); |
| 16 | |
| 17 | /* |
| 18 | * pwm_config - change a PWM device configuration |
| 19 | */ |
| 20 | int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns); |
| 21 | |
| 22 | /* |
| 23 | * pwm_enable - start a PWM output toggling |
| 24 | */ |
| 25 | int pwm_enable(struct pwm_device *pwm); |
| 26 | |
| 27 | /* |
| 28 | * pwm_disable - stop a PWM output toggling |
| 29 | */ |
| 30 | void pwm_disable(struct pwm_device *pwm); |
| 31 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 32 | #ifdef CONFIG_PWM |
| 33 | struct pwm_chip; |
| 34 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 35 | enum { |
| 36 | PWMF_REQUESTED = 1 << 0, |
| 37 | PWMF_ENABLED = 1 << 1, |
| 38 | }; |
| 39 | |
| 40 | struct pwm_device { |
| 41 | const char *label; |
| 42 | unsigned long flags; |
| 43 | unsigned int hwpwm; |
| 44 | unsigned int pwm; |
| 45 | struct pwm_chip *chip; |
| 46 | void *chip_data; |
| 47 | |
| 48 | unsigned int period; /* in nanoseconds */ |
| 49 | }; |
| 50 | |
| 51 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| 52 | { |
| 53 | if (pwm) |
| 54 | pwm->period = period; |
| 55 | } |
| 56 | |
| 57 | static inline unsigned int pwm_get_period(struct pwm_device *pwm) |
| 58 | { |
| 59 | return pwm ? pwm->period : 0; |
| 60 | } |
| 61 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 62 | /** |
| 63 | * struct pwm_ops - PWM controller operations |
| 64 | * @request: optional hook for requesting a PWM |
| 65 | * @free: optional hook for freeing a PWM |
| 66 | * @config: configure duty cycles and period length for this PWM |
| 67 | * @enable: enable PWM output toggling |
| 68 | * @disable: disable PWM output toggling |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame^] | 69 | * @dbg_show: optional routine to show contents in debugfs |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 70 | * @owner: helps prevent removal of modules exporting active PWMs |
| 71 | */ |
| 72 | struct pwm_ops { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 73 | int (*request)(struct pwm_chip *chip, |
| 74 | struct pwm_device *pwm); |
| 75 | void (*free)(struct pwm_chip *chip, |
| 76 | struct pwm_device *pwm); |
| 77 | int (*config)(struct pwm_chip *chip, |
| 78 | struct pwm_device *pwm, |
| 79 | int duty_ns, int period_ns); |
| 80 | int (*enable)(struct pwm_chip *chip, |
| 81 | struct pwm_device *pwm); |
| 82 | void (*disable)(struct pwm_chip *chip, |
| 83 | struct pwm_device *pwm); |
Thierry Reding | 62099ab | 2012-03-26 09:31:48 +0200 | [diff] [blame^] | 84 | #ifdef CONFIG_DEBUG_FS |
| 85 | void (*dbg_show)(struct pwm_chip *chip, |
| 86 | struct seq_file *s); |
| 87 | #endif |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 88 | struct module *owner; |
| 89 | }; |
| 90 | |
| 91 | /** |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 92 | * struct pwm_chip - abstract a PWM controller |
| 93 | * @dev: device providing the PWMs |
| 94 | * @list: list node for internal use |
| 95 | * @ops: callbacks for this PWM controller |
| 96 | * @base: number of first PWM controlled by this chip |
| 97 | * @npwm: number of PWMs controlled by this chip |
| 98 | * @pwms: array of PWM devices allocated by the framework |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 99 | */ |
| 100 | struct pwm_chip { |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 101 | struct device *dev; |
| 102 | struct list_head list; |
| 103 | const struct pwm_ops *ops; |
| 104 | int base; |
| 105 | unsigned int npwm; |
| 106 | |
| 107 | struct pwm_device *pwms; |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 108 | }; |
| 109 | |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 110 | int pwm_set_chip_data(struct pwm_device *pwm, void *data); |
| 111 | void *pwm_get_chip_data(struct pwm_device *pwm); |
| 112 | |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 113 | int pwmchip_add(struct pwm_chip *chip); |
| 114 | int pwmchip_remove(struct pwm_chip *chip); |
Thierry Reding | f051c46 | 2011-12-14 11:12:23 +0100 | [diff] [blame] | 115 | struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, |
| 116 | unsigned int index, |
| 117 | const char *label); |
Sascha Hauer | 0c2498f | 2011-01-28 09:40:40 +0100 | [diff] [blame] | 118 | #endif |
| 119 | |
Mark Vels | 5243ef8 | 2009-01-18 18:42:45 +0100 | [diff] [blame] | 120 | #endif /* __LINUX_PWM_H */ |