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