pwm.h 2.6 KB

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