pmic8058-pwm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Copyright (c) 2010, 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. */
  13. #ifndef __PMIC8058_PWM_H__
  14. #define __PMIC8058_PWM_H__
  15. /* The MAX value is computation limit. Hardware limit is 393 seconds. */
  16. #define PM_PWM_PERIOD_MAX (274 * USEC_PER_SEC)
  17. /* The MIN value is hardware limit. */
  18. #define PM_PWM_PERIOD_MIN 7 /* micro seconds */
  19. struct pm8058_pwm_pdata {
  20. int (*config)(struct pwm_device *pwm, int ch, int on);
  21. int (*enable)(struct pwm_device *pwm, int ch, int on);
  22. };
  23. #define PM_PWM_LUT_SIZE 64
  24. #define PM_PWM_LUT_DUTY_TIME_MAX 512 /* ms */
  25. #define PM_PWM_LUT_PAUSE_MAX (7000 * PM_PWM_LUT_DUTY_TIME_MAX)
  26. /* Flags for Look Up Table */
  27. #define PM_PWM_LUT_LOOP 0x01
  28. #define PM_PWM_LUT_RAMP_UP 0x02
  29. #define PM_PWM_LUT_REVERSE 0x04
  30. #define PM_PWM_LUT_PAUSE_HI_EN 0x10
  31. #define PM_PWM_LUT_PAUSE_LO_EN 0x20
  32. #define PM_PWM_LUT_NO_TABLE 0x100
  33. /* PWM LED ID */
  34. #define PM_PWM_LED_0 0
  35. #define PM_PWM_LED_1 1
  36. #define PM_PWM_LED_2 2
  37. #define PM_PWM_LED_KPD 3
  38. #define PM_PWM_LED_FLASH 4
  39. #define PM_PWM_LED_FLASH1 5
  40. /* PWM LED configuration mode */
  41. #define PM_PWM_CONF_NONE 0x0
  42. #define PM_PWM_CONF_PWM1 0x1
  43. #define PM_PWM_CONF_PWM2 0x2
  44. #define PM_PWM_CONF_PWM3 0x3
  45. #define PM_PWM_CONF_DTEST1 0x4
  46. #define PM_PWM_CONF_DTEST2 0x5
  47. #define PM_PWM_CONF_DTEST3 0x6
  48. #define PM_PWM_CONF_DTEST4 0x7
  49. /**
  50. * PWM frequency/period control
  51. *
  52. * PWM Frequency = ClockFrequency / (N * T)
  53. * or
  54. * PWM Period = Clock Period * (N * T)
  55. * where
  56. * N = 2^9 or 2^6 for 9-bit or 6-bit PWM size
  57. * T = Pre-divide * 2^m, m = 0..7 (exponent)
  58. *
  59. */
  60. enum pm_pwm_size {
  61. PM_PWM_SIZE_6BIT = 6,
  62. PM_PWM_SIZE_9BIT = 9,
  63. };
  64. enum pm_pwm_clk {
  65. PM_PWM_CLK_1KHZ,
  66. PM_PWM_CLK_32KHZ,
  67. PM_PWM_CLK_19P2MHZ,
  68. };
  69. enum pm_pwm_pre_div {
  70. PM_PWM_PDIV_2,
  71. PM_PWM_PDIV_3,
  72. PM_PWM_PDIV_5,
  73. PM_PWM_PDIV_6,
  74. };
  75. /**
  76. * struct pm8058_pwm_period - PWM period structure
  77. * @pwm_size: enum pm_pwm_size
  78. * @clk: enum pm_pwm_clk
  79. * @pre_div: enum pm_pwm_pre_div
  80. * @pre_div_exp: exponent of 2 as part of pre-divider: 0..7
  81. */
  82. struct pm8058_pwm_period {
  83. enum pm_pwm_size pwm_size;
  84. enum pm_pwm_clk clk;
  85. enum pm_pwm_pre_div pre_div;
  86. int pre_div_exp;
  87. };
  88. /**
  89. * pm8058_pwm_config_period - change PWM period
  90. *
  91. * @pwm: the PWM device
  92. * @pwm_p: period in struct pm8058_pwm_period
  93. */
  94. int pm8058_pwm_config_period(struct pwm_device *pwm,
  95. struct pm8058_pwm_period *pwm_p);
  96. /**
  97. * pm8058_pwm_config_duty_cycle - change PWM duty cycle
  98. *
  99. * @pwm: the PWM device
  100. * @pwm_value: the duty cycle in raw PWM value (< 2^pwm_size)
  101. */
  102. int pm8058_pwm_config_duty_cycle(struct pwm_device *pwm, int pwm_value);
  103. /**
  104. * pm8058_pwm_lut_config - change a PWM device configuration to use LUT
  105. *
  106. * @pwm: the PWM device
  107. * @period_us: period in micro second
  108. * @duty_pct: arrary of duty cycles in percent, like 20, 50.
  109. * @duty_time_ms: time for each duty cycle in millisecond
  110. * @start_idx: start index in lookup table from 0 to MAX-1
  111. * @idx_len: number of index
  112. * @pause_lo: pause time in millisecond at low index
  113. * @pause_hi: pause time in millisecond at high index
  114. * @flags: control flags
  115. */
  116. int pm8058_pwm_lut_config(struct pwm_device *pwm, int period_us,
  117. int duty_pct[], int duty_time_ms, int start_idx,
  118. int len, int pause_lo, int pause_hi, int flags);
  119. /**
  120. * pm8058_pwm_lut_enable - control a PWM device to start/stop LUT ramp
  121. *
  122. * @pwm: the PWM device
  123. * @start: to start (1), or stop (0)
  124. */
  125. int pm8058_pwm_lut_enable(struct pwm_device *pwm, int start);
  126. int pm8058_pwm_set_dtest(struct pwm_device *pwm, int enable);
  127. int pm8058_pwm_config_led(struct pwm_device *pwm, int id,
  128. int mode, int max_current);
  129. #endif /* __PMIC8058_PWM_H__ */