pwm.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __PM8XXX_PWM_H__
  13. #define __PM8XXX_PWM_H__
  14. #include <linux/pwm.h>
  15. #define PM8XXX_PWM_DEV_NAME "pm8xxx-pwm"
  16. #define PM8XXX_PWM_PERIOD_MIN 7 /* usec: 19.2M, n=6, m=0, pre=2 */
  17. #define PM8XXX_PWM_PERIOD_MAX (384 * USEC_PER_SEC) /* 1K, n=9, m=7, pre=6 */
  18. #define PM_PWM_LUT_SIZE 64
  19. #define PM_PWM_LUT_DUTY_TIME_MAX 512 /* ms */
  20. #define PM_PWM_LUT_PAUSE_MAX (7000 * PM_PWM_LUT_DUTY_TIME_MAX)
  21. /* Flags for Look Up Table */
  22. #define PM_PWM_LUT_LOOP 0x01
  23. #define PM_PWM_LUT_RAMP_UP 0x02
  24. #define PM_PWM_LUT_REVERSE 0x04
  25. #define PM_PWM_LUT_PAUSE_HI_EN 0x10
  26. #define PM_PWM_LUT_PAUSE_LO_EN 0x20
  27. #define PM_PWM_LUT_NO_TABLE 0x100
  28. #define PM_PWM_BANK_LO 0x1000
  29. #define PM_PWM_BANK_HI 0x2000
  30. /**
  31. * PWM frequency/period control
  32. *
  33. * PWM Frequency = ClockFrequency / (N * T)
  34. * or
  35. * PWM Period = Clock Period * (N * T)
  36. * where
  37. * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size
  38. * T = Pre-divide * 2^m, m = 0..7 (exponent)
  39. *
  40. */
  41. enum pm_pwm_size {
  42. PM_PWM_SIZE_6BIT = 6,
  43. PM_PWM_SIZE_9BIT = 9,
  44. };
  45. enum pm_pwm_clk {
  46. PM_PWM_CLK_1KHZ,
  47. PM_PWM_CLK_32KHZ,
  48. PM_PWM_CLK_19P2MHZ,
  49. };
  50. enum pm_pwm_pre_div {
  51. PM_PWM_PDIV_2,
  52. PM_PWM_PDIV_3,
  53. PM_PWM_PDIV_5,
  54. PM_PWM_PDIV_6,
  55. };
  56. /**
  57. * struct pm8xxx_pwm_period - PWM period structure
  58. * @pwm_size: enum pm_pwm_size
  59. * @clk: enum pm_pwm_clk
  60. * @pre_div: enum pm_pwm_pre_div
  61. * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7
  62. */
  63. struct pm8xxx_pwm_period {
  64. enum pm_pwm_size pwm_size;
  65. enum pm_pwm_clk clk;
  66. enum pm_pwm_pre_div pre_div;
  67. int pre_div_exp;
  68. };
  69. /**
  70. * struct pm8xxx_pwm_duty_cycles - PWM duty cycle info
  71. * duty_pcts - pointer to an array of duty percentage for a pwm period
  72. * num_duty_pcts - total entries in duty_pcts array
  73. * duty_ms - duty cycle time in ms
  74. * start_idx - index in the LUT
  75. */
  76. struct pm8xxx_pwm_duty_cycles {
  77. int *duty_pcts;
  78. int num_duty_pcts;
  79. int duty_ms;
  80. int start_idx;
  81. };
  82. /**
  83. * struct pm8xxx_pwm_platform_data - PWM platform data
  84. * dtest_channel - Enable LPG DTEST mode for this LPG channel
  85. */
  86. struct pm8xxx_pwm_platform_data {
  87. int dtest_channel;
  88. };
  89. /**
  90. * pm8xxx_pwm_config_period - change PWM period
  91. *
  92. * @pwm: the PWM device
  93. * @pwm_p: period in struct pm8xxx_pwm_period
  94. */
  95. int pm8xxx_pwm_config_period(struct pwm_device *pwm,
  96. struct pm8xxx_pwm_period *pwm_p);
  97. /**
  98. * pm8xxx_pwm_config_pwm_value - change a PWM device configuration
  99. * @pwm: the PWM device
  100. * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size)
  101. */
  102. int pm8xxx_pwm_config_pwm_value(struct pwm_device *pwm, int pwm_value);
  103. /**
  104. * pm8xxx_pwm_lut_config - change a PWM device configuration to use LUT
  105. * @pwm: the PWM device
  106. * @period_us: period in micro second
  107. * @duty_pct: arrary of duty cycles in percent, like 20, 50.
  108. * @duty_time_ms: time for each duty cycle in millisecond
  109. * @start_idx: start index in lookup table from 0 to MAX-1
  110. * @idx_len: number of index
  111. * @pause_lo: pause time in millisecond at low index
  112. * @pause_hi: pause time in millisecond at high index
  113. * @flags: control flags
  114. */
  115. int pm8xxx_pwm_lut_config(struct pwm_device *pwm, int period_us,
  116. int duty_pct[], int duty_time_ms, int start_idx,
  117. int len, int pause_lo, int pause_hi, int flags);
  118. /**
  119. * pm8xxx_pwm_lut_enable - control a PWM device to start/stop LUT ramp
  120. * @pwm: the PWM device
  121. * @start: to start (1), or stop (0)
  122. */
  123. int pm8xxx_pwm_lut_enable(struct pwm_device *pwm, int start);
  124. /* Standard APIs supported */
  125. /**
  126. * pwm_request - request a PWM device
  127. * @pwm_id: PWM id or channel
  128. * @label: the label to identify the user
  129. */
  130. /**
  131. * pwm_free - free a PWM device
  132. * @pwm: the PWM device
  133. */
  134. /**
  135. * pwm_config - change a PWM device configuration
  136. * @pwm: the PWM device
  137. * @period_us: period in microsecond
  138. * @duty_us: duty cycle in microsecond
  139. */
  140. /**
  141. * pwm_enable - start a PWM output toggling
  142. * @pwm: the PWM device
  143. */
  144. /**
  145. * pwm_disable - stop a PWM output toggling
  146. * @pwm: the PWM device
  147. */
  148. #endif /* __PM8XXX_PWM_H__ */