pwm.h 2.3 KB

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