lp8788.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * TI LP8788 MFD Device
  4. *
  5. * Copyright 2012 Texas Instruments
  6. *
  7. * Author: Milo(Woogyom) Kim <[email protected]>
  8. */
  9. #ifndef __MFD_LP8788_H__
  10. #define __MFD_LP8788_H__
  11. #include <linux/gpio.h>
  12. #include <linux/irqdomain.h>
  13. #include <linux/pwm.h>
  14. #include <linux/regmap.h>
  15. #define LP8788_DEV_BUCK "lp8788-buck"
  16. #define LP8788_DEV_DLDO "lp8788-dldo"
  17. #define LP8788_DEV_ALDO "lp8788-aldo"
  18. #define LP8788_DEV_CHARGER "lp8788-charger"
  19. #define LP8788_DEV_RTC "lp8788-rtc"
  20. #define LP8788_DEV_BACKLIGHT "lp8788-backlight"
  21. #define LP8788_DEV_VIBRATOR "lp8788-vibrator"
  22. #define LP8788_DEV_KEYLED "lp8788-keyled"
  23. #define LP8788_DEV_ADC "lp8788-adc"
  24. #define LP8788_NUM_BUCKS 4
  25. #define LP8788_NUM_DLDOS 12
  26. #define LP8788_NUM_ALDOS 10
  27. #define LP8788_NUM_BUCK2_DVS 2
  28. #define LP8788_CHG_IRQ "CHG_IRQ"
  29. #define LP8788_PRSW_IRQ "PRSW_IRQ"
  30. #define LP8788_BATT_IRQ "BATT_IRQ"
  31. #define LP8788_ALM_IRQ "ALARM_IRQ"
  32. enum lp8788_int_id {
  33. /* interrup register 1 : Addr 00h */
  34. LP8788_INT_TSDL,
  35. LP8788_INT_TSDH,
  36. LP8788_INT_UVLO,
  37. LP8788_INT_FLAGMON,
  38. LP8788_INT_PWRON_TIME,
  39. LP8788_INT_PWRON,
  40. LP8788_INT_COMP1,
  41. LP8788_INT_COMP2,
  42. /* interrupt register 2 : Addr 01h */
  43. LP8788_INT_CHG_INPUT_STATE,
  44. LP8788_INT_CHG_STATE,
  45. LP8788_INT_EOC,
  46. LP8788_INT_CHG_RESTART,
  47. LP8788_INT_RESTART_TIMEOUT,
  48. LP8788_INT_FULLCHG_TIMEOUT,
  49. LP8788_INT_PRECHG_TIMEOUT,
  50. /* interrupt register 3 : Addr 02h */
  51. LP8788_INT_RTC_ALARM1 = 17,
  52. LP8788_INT_RTC_ALARM2,
  53. LP8788_INT_ENTER_SYS_SUPPORT,
  54. LP8788_INT_EXIT_SYS_SUPPORT,
  55. LP8788_INT_BATT_LOW,
  56. LP8788_INT_NO_BATT,
  57. LP8788_INT_MAX = 24,
  58. };
  59. enum lp8788_dvs_sel {
  60. DVS_SEL_V0,
  61. DVS_SEL_V1,
  62. DVS_SEL_V2,
  63. DVS_SEL_V3,
  64. };
  65. enum lp8788_ext_ldo_en_id {
  66. EN_ALDO1,
  67. EN_ALDO234,
  68. EN_ALDO5,
  69. EN_ALDO7,
  70. EN_DLDO7,
  71. EN_DLDO911,
  72. EN_LDOS_MAX,
  73. };
  74. enum lp8788_charger_event {
  75. NO_CHARGER,
  76. CHARGER_DETECTED,
  77. };
  78. enum lp8788_bl_ctrl_mode {
  79. LP8788_BL_REGISTER_ONLY,
  80. LP8788_BL_COMB_PWM_BASED, /* PWM + I2C, changed by PWM input */
  81. LP8788_BL_COMB_REGISTER_BASED, /* PWM + I2C, changed by I2C */
  82. };
  83. enum lp8788_bl_dim_mode {
  84. LP8788_DIM_EXPONENTIAL,
  85. LP8788_DIM_LINEAR,
  86. };
  87. enum lp8788_bl_full_scale_current {
  88. LP8788_FULLSCALE_5000uA,
  89. LP8788_FULLSCALE_8500uA,
  90. LP8788_FULLSCALE_1200uA,
  91. LP8788_FULLSCALE_1550uA,
  92. LP8788_FULLSCALE_1900uA,
  93. LP8788_FULLSCALE_2250uA,
  94. LP8788_FULLSCALE_2600uA,
  95. LP8788_FULLSCALE_2950uA,
  96. };
  97. enum lp8788_bl_ramp_step {
  98. LP8788_RAMP_8us,
  99. LP8788_RAMP_1024us,
  100. LP8788_RAMP_2048us,
  101. LP8788_RAMP_4096us,
  102. LP8788_RAMP_8192us,
  103. LP8788_RAMP_16384us,
  104. LP8788_RAMP_32768us,
  105. LP8788_RAMP_65538us,
  106. };
  107. enum lp8788_isink_scale {
  108. LP8788_ISINK_SCALE_100mA,
  109. LP8788_ISINK_SCALE_120mA,
  110. };
  111. enum lp8788_isink_number {
  112. LP8788_ISINK_1,
  113. LP8788_ISINK_2,
  114. LP8788_ISINK_3,
  115. };
  116. enum lp8788_alarm_sel {
  117. LP8788_ALARM_1,
  118. LP8788_ALARM_2,
  119. LP8788_ALARM_MAX,
  120. };
  121. enum lp8788_adc_id {
  122. LPADC_VBATT_5P5,
  123. LPADC_VIN_CHG,
  124. LPADC_IBATT,
  125. LPADC_IC_TEMP,
  126. LPADC_VBATT_6P0,
  127. LPADC_VBATT_5P0,
  128. LPADC_ADC1,
  129. LPADC_ADC2,
  130. LPADC_VDD,
  131. LPADC_VCOIN,
  132. LPADC_VDD_LDO,
  133. LPADC_ADC3,
  134. LPADC_ADC4,
  135. LPADC_MAX,
  136. };
  137. struct lp8788;
  138. /*
  139. * lp8788_buck1_dvs
  140. * @gpio : gpio pin number for dvs control
  141. * @vsel : dvs selector for buck v1 register
  142. */
  143. struct lp8788_buck1_dvs {
  144. int gpio;
  145. enum lp8788_dvs_sel vsel;
  146. };
  147. /*
  148. * lp8788_buck2_dvs
  149. * @gpio : two gpio pin numbers are used for dvs
  150. * @vsel : dvs selector for buck v2 register
  151. */
  152. struct lp8788_buck2_dvs {
  153. int gpio[LP8788_NUM_BUCK2_DVS];
  154. enum lp8788_dvs_sel vsel;
  155. };
  156. /*
  157. * struct lp8788_chg_param
  158. * @addr : charging control register address (range : 0x11 ~ 0x1C)
  159. * @val : charging parameter value
  160. */
  161. struct lp8788_chg_param {
  162. u8 addr;
  163. u8 val;
  164. };
  165. /*
  166. * struct lp8788_charger_platform_data
  167. * @adc_vbatt : adc channel name for battery voltage
  168. * @adc_batt_temp : adc channel name for battery temperature
  169. * @max_vbatt_mv : used for calculating battery capacity
  170. * @chg_params : initial charging parameters
  171. * @num_chg_params : numbers of charging parameters
  172. * @charger_event : the charger event can be reported to the platform side
  173. */
  174. struct lp8788_charger_platform_data {
  175. const char *adc_vbatt;
  176. const char *adc_batt_temp;
  177. unsigned int max_vbatt_mv;
  178. struct lp8788_chg_param *chg_params;
  179. int num_chg_params;
  180. void (*charger_event) (struct lp8788 *lp,
  181. enum lp8788_charger_event event);
  182. };
  183. /*
  184. * struct lp8788_backlight_platform_data
  185. * @name : backlight driver name. (default: "lcd-backlight")
  186. * @initial_brightness : initial value of backlight brightness
  187. * @bl_mode : brightness control by pwm or lp8788 register
  188. * @dim_mode : dimming mode selection
  189. * @full_scale : full scale current setting
  190. * @rise_time : brightness ramp up step time
  191. * @fall_time : brightness ramp down step time
  192. * @pwm_pol : pwm polarity setting when bl_mode is pwm based
  193. * @period_ns : platform specific pwm period value. unit is nano.
  194. Only valid when bl_mode is LP8788_BL_COMB_PWM_BASED
  195. */
  196. struct lp8788_backlight_platform_data {
  197. char *name;
  198. int initial_brightness;
  199. enum lp8788_bl_ctrl_mode bl_mode;
  200. enum lp8788_bl_dim_mode dim_mode;
  201. enum lp8788_bl_full_scale_current full_scale;
  202. enum lp8788_bl_ramp_step rise_time;
  203. enum lp8788_bl_ramp_step fall_time;
  204. enum pwm_polarity pwm_pol;
  205. unsigned int period_ns;
  206. };
  207. /*
  208. * struct lp8788_led_platform_data
  209. * @name : led driver name. (default: "keyboard-backlight")
  210. * @scale : current scale
  211. * @num : current sink number
  212. * @iout_code : current output value (Addr 9Ah ~ 9Bh)
  213. */
  214. struct lp8788_led_platform_data {
  215. char *name;
  216. enum lp8788_isink_scale scale;
  217. enum lp8788_isink_number num;
  218. int iout_code;
  219. };
  220. /*
  221. * struct lp8788_vib_platform_data
  222. * @name : vibrator driver name
  223. * @scale : current scale
  224. * @num : current sink number
  225. * @iout_code : current output value (Addr 9Ah ~ 9Bh)
  226. * @pwm_code : PWM code value (Addr 9Ch ~ 9Eh)
  227. */
  228. struct lp8788_vib_platform_data {
  229. char *name;
  230. enum lp8788_isink_scale scale;
  231. enum lp8788_isink_number num;
  232. int iout_code;
  233. int pwm_code;
  234. };
  235. /*
  236. * struct lp8788_platform_data
  237. * @init_func : used for initializing registers
  238. * before mfd driver is registered
  239. * @buck_data : regulator initial data for buck
  240. * @dldo_data : regulator initial data for digital ldo
  241. * @aldo_data : regulator initial data for analog ldo
  242. * @buck1_dvs : gpio configurations for buck1 dvs
  243. * @buck2_dvs : gpio configurations for buck2 dvs
  244. * @chg_pdata : platform data for charger driver
  245. * @alarm_sel : rtc alarm selection (1 or 2)
  246. * @bl_pdata : configurable data for backlight driver
  247. * @led_pdata : configurable data for led driver
  248. * @vib_pdata : configurable data for vibrator driver
  249. * @adc_pdata : iio map data for adc driver
  250. */
  251. struct lp8788_platform_data {
  252. /* general system information */
  253. int (*init_func) (struct lp8788 *lp);
  254. /* regulators */
  255. struct regulator_init_data *buck_data[LP8788_NUM_BUCKS];
  256. struct regulator_init_data *dldo_data[LP8788_NUM_DLDOS];
  257. struct regulator_init_data *aldo_data[LP8788_NUM_ALDOS];
  258. struct lp8788_buck1_dvs *buck1_dvs;
  259. struct lp8788_buck2_dvs *buck2_dvs;
  260. /* charger */
  261. struct lp8788_charger_platform_data *chg_pdata;
  262. /* rtc alarm */
  263. enum lp8788_alarm_sel alarm_sel;
  264. /* backlight */
  265. struct lp8788_backlight_platform_data *bl_pdata;
  266. /* current sinks */
  267. struct lp8788_led_platform_data *led_pdata;
  268. struct lp8788_vib_platform_data *vib_pdata;
  269. /* adc iio map data */
  270. struct iio_map *adc_pdata;
  271. };
  272. /*
  273. * struct lp8788
  274. * @dev : parent device pointer
  275. * @regmap : used for i2c communcation on accessing registers
  276. * @irqdm : interrupt domain for handling nested interrupt
  277. * @irq : pin number of IRQ_N
  278. * @pdata : lp8788 platform specific data
  279. */
  280. struct lp8788 {
  281. struct device *dev;
  282. struct regmap *regmap;
  283. struct irq_domain *irqdm;
  284. int irq;
  285. struct lp8788_platform_data *pdata;
  286. };
  287. int lp8788_irq_init(struct lp8788 *lp, int chip_irq);
  288. void lp8788_irq_exit(struct lp8788 *lp);
  289. int lp8788_read_byte(struct lp8788 *lp, u8 reg, u8 *data);
  290. int lp8788_read_multi_bytes(struct lp8788 *lp, u8 reg, u8 *data, size_t count);
  291. int lp8788_write_byte(struct lp8788 *lp, u8 reg, u8 data);
  292. int lp8788_update_bits(struct lp8788 *lp, u8 reg, u8 mask, u8 data);
  293. #endif