pwm.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @dev: PWM device to update
  18. * @channel: PWM channel to update
  19. * @period_ns: PWM period in nanoseconds
  20. * @duty_ns: PWM duty period in nanoseconds
  21. * @return 0 if OK, -ve on error
  22. */
  23. int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
  24. uint duty_ns);
  25. /**
  26. * set_enable() - Enable or disable the PWM
  27. *
  28. * @dev: PWM device to update
  29. * @channel: PWM channel to update
  30. * @enable: true to enable, false to disable
  31. * @return 0 if OK, -ve on error
  32. */
  33. int (*set_enable)(struct udevice *dev, uint channel, bool enable);
  34. /**
  35. * set_invert() - Set the PWM invert
  36. *
  37. * @dev: PWM device to update
  38. * @channel: PWM channel to update
  39. * @polarity: true to invert, false to keep normal polarity
  40. * @return 0 if OK, -ve on error
  41. */
  42. int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
  43. };
  44. #define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops)
  45. /**
  46. * pwm_set_config() - Set the PWM configuration
  47. *
  48. * @dev: PWM device to update
  49. * @channel: PWM channel to update
  50. * @period_ns: PWM period in nanoseconds
  51. * @duty_ns: PWM duty period in nanoseconds
  52. * @return 0 if OK, -ve on error
  53. */
  54. int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
  55. uint duty_ns);
  56. /**
  57. * pwm_set_enable() - Enable or disable the PWM
  58. *
  59. * @dev: PWM device to update
  60. * @channel: PWM channel to update
  61. * @enable: true to enable, false to disable
  62. * @return 0 if OK, -ve on error
  63. */
  64. int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
  65. /**
  66. * pwm_set_invert() - Set pwm default polarity
  67. *
  68. * @dev: PWM device to update
  69. * @channel: PWM channel to update
  70. * @polarity: true to invert, false to keep normal polarity
  71. * @return 0 if OK, -ve on error
  72. */
  73. int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
  74. /* Legacy interface */
  75. #ifndef CONFIG_DM_PWM
  76. int pwm_init (int pwm_id, int div, int invert);
  77. int pwm_config (int pwm_id, int duty_ns, int period_ns);
  78. int pwm_enable (int pwm_id);
  79. void pwm_disable (int pwm_id);
  80. #endif
  81. #endif /* _pwm_h_ */