pwm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * header file for pwm driver.
  4. *
  5. * Copyright 2016 Google Inc.
  6. * Copyright (c) 2011 samsung electronics
  7. * Donghwa Lee <dh09.lee@samsung.com>
  8. */
  9. #ifndef _pwm_h_
  10. #define _pwm_h_
  11. struct udevice;
  12. /* struct pwm_ops: Operations for the PWM uclass */
  13. struct pwm_ops {
  14. /**
  15. * set_config() - Set the PWM configuration
  16. *
  17. * Change both the PWM device's period and it's duty period if
  18. * possible. Otherwise, set an appropriate duty period that best
  19. * matches the given period_ns / duty_ns ratio for the device.
  20. *
  21. * @dev: PWM device to update
  22. * @channel: PWM channel to update
  23. * @period_ns: PWM period in nanoseconds
  24. * @duty_ns: PWM duty period in nanoseconds
  25. * @return 0 if OK, -ve on error
  26. */
  27. int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
  28. uint duty_ns);
  29. /**
  30. * set_enable() - Enable or disable the PWM
  31. *
  32. * @dev: PWM device to update
  33. * @channel: PWM channel to update
  34. * @enable: true to enable, false to disable
  35. * @return 0 if OK, -ve on error
  36. */
  37. int (*set_enable)(struct udevice *dev, uint channel, bool enable);
  38. /**
  39. * set_invert() - Set the PWM invert
  40. *
  41. * @dev: PWM device to update
  42. * @channel: PWM channel to update
  43. * @polarity: true to invert, false to keep normal polarity
  44. * @return 0 if OK, -ve on error
  45. */
  46. int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
  47. };
  48. #define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops)
  49. /**
  50. * pwm_set_config() - Set the PWM configuration
  51. *
  52. * Change both the PWM device's period and it's duty period if
  53. * possible. Otherwise, set an appropriate duty period that best
  54. * matches the given period_ns / duty_ns ratio for the device.
  55. *
  56. * @dev: PWM device to update
  57. * @channel: PWM channel to update
  58. * @period_ns: PWM period in nanoseconds
  59. * @duty_ns: PWM duty period in nanoseconds
  60. * Return: 0 if OK, -ve on error
  61. */
  62. int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
  63. uint duty_ns);
  64. /**
  65. * pwm_set_enable() - Enable or disable the PWM
  66. *
  67. * @dev: PWM device to update
  68. * @channel: PWM channel to update
  69. * @enable: true to enable, false to disable
  70. * Return: 0 if OK, -ve on error
  71. */
  72. int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
  73. /**
  74. * pwm_set_invert() - Set pwm default polarity
  75. *
  76. * @dev: PWM device to update
  77. * @channel: PWM channel to update
  78. * @polarity: true to invert, false to keep normal polarity
  79. * Return: 0 if OK, -ve on error
  80. */
  81. int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
  82. /* Legacy interface */
  83. #ifndef CONFIG_DM_PWM
  84. int pwm_init (int pwm_id, int div, int invert);
  85. int pwm_config (int pwm_id, int duty_ns, int period_ns);
  86. int pwm_enable (int pwm_id);
  87. void pwm_disable (int pwm_id);
  88. #endif
  89. #endif /* _pwm_h_ */