88pm80x.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /*
  2. * Marvell 88PM80x Interface
  3. *
  4. * Copyright (C) 2012 Marvell International Ltd.
  5. * Qiao Zhou <zhouqiao@marvell.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_MFD_88PM80X_H
  12. #define __LINUX_MFD_88PM80X_H
  13. #include <linux/platform_device.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/regmap.h>
  16. #include <linux/atomic.h>
  17. enum {
  18. CHIP_INVALID = 0,
  19. CHIP_PM800,
  20. CHIP_PM805,
  21. CHIP_MAX,
  22. };
  23. enum {
  24. PM800_ID_BUCK1 = 0,
  25. PM800_ID_BUCK2,
  26. PM800_ID_BUCK3,
  27. PM800_ID_BUCK4,
  28. PM800_ID_BUCK5,
  29. PM800_ID_LDO1,
  30. PM800_ID_LDO2,
  31. PM800_ID_LDO3,
  32. PM800_ID_LDO4,
  33. PM800_ID_LDO5,
  34. PM800_ID_LDO6,
  35. PM800_ID_LDO7,
  36. PM800_ID_LDO8,
  37. PM800_ID_LDO9,
  38. PM800_ID_LDO10,
  39. PM800_ID_LDO11,
  40. PM800_ID_LDO12,
  41. PM800_ID_LDO13,
  42. PM800_ID_LDO14,
  43. PM800_ID_LDO15,
  44. PM800_ID_LDO16,
  45. PM800_ID_LDO17,
  46. PM800_ID_LDO18,
  47. PM800_ID_LDO19,
  48. PM800_ID_RG_MAX,
  49. };
  50. #define PM800_MAX_REGULATOR PM800_ID_RG_MAX /* 5 Bucks, 19 LDOs */
  51. #define PM800_NUM_BUCK (5) /*5 Bucks */
  52. #define PM800_NUM_LDO (19) /*19 Bucks */
  53. /* page 0 basic: slave adder 0x60 */
  54. #define PM800_STATUS_1 (0x01)
  55. #define PM800_ONKEY_STS1 (1 << 0)
  56. #define PM800_EXTON_STS1 (1 << 1)
  57. #define PM800_CHG_STS1 (1 << 2)
  58. #define PM800_BAT_STS1 (1 << 3)
  59. #define PM800_VBUS_STS1 (1 << 4)
  60. #define PM800_LDO_PGOOD_STS1 (1 << 5)
  61. #define PM800_BUCK_PGOOD_STS1 (1 << 6)
  62. #define PM800_STATUS_2 (0x02)
  63. #define PM800_RTC_ALARM_STS2 (1 << 0)
  64. /* Wakeup Registers */
  65. #define PM800_WAKEUP1 (0x0D)
  66. #define PM800_WAKEUP2 (0x0E)
  67. #define PM800_WAKEUP2_INV_INT (1 << 0)
  68. #define PM800_WAKEUP2_INT_CLEAR (1 << 1)
  69. #define PM800_WAKEUP2_INT_MASK (1 << 2)
  70. #define PM800_POWER_UP_LOG (0x10)
  71. /* Referance and low power registers */
  72. #define PM800_LOW_POWER1 (0x20)
  73. #define PM800_LOW_POWER2 (0x21)
  74. #define PM800_LOW_POWER_CONFIG3 (0x22)
  75. #define PM800_LOW_POWER_CONFIG4 (0x23)
  76. /* GPIO register */
  77. #define PM800_GPIO_0_1_CNTRL (0x30)
  78. #define PM800_GPIO0_VAL (1 << 0)
  79. #define PM800_GPIO0_GPIO_MODE(x) (x << 1)
  80. #define PM800_GPIO1_VAL (1 << 4)
  81. #define PM800_GPIO1_GPIO_MODE(x) (x << 5)
  82. #define PM800_GPIO_2_3_CNTRL (0x31)
  83. #define PM800_GPIO2_VAL (1 << 0)
  84. #define PM800_GPIO2_GPIO_MODE(x) (x << 1)
  85. #define PM800_GPIO3_VAL (1 << 4)
  86. #define PM800_GPIO3_GPIO_MODE(x) (x << 5)
  87. #define PM800_GPIO3_MODE_MASK 0x1F
  88. #define PM800_GPIO3_HEADSET_MODE PM800_GPIO3_GPIO_MODE(6)
  89. #define PM800_GPIO_4_CNTRL (0x32)
  90. #define PM800_GPIO4_VAL (1 << 0)
  91. #define PM800_GPIO4_GPIO_MODE(x) (x << 1)
  92. #define PM800_HEADSET_CNTRL (0x38)
  93. #define PM800_HEADSET_DET_EN (1 << 7)
  94. #define PM800_HSDET_SLP (1 << 1)
  95. /* PWM register */
  96. #define PM800_PWM1 (0x40)
  97. #define PM800_PWM2 (0x41)
  98. #define PM800_PWM3 (0x42)
  99. #define PM800_PWM4 (0x43)
  100. /* RTC Registers */
  101. #define PM800_RTC_CONTROL (0xD0)
  102. #define PM800_RTC_MISC1 (0xE1)
  103. #define PM800_RTC_MISC2 (0xE2)
  104. #define PM800_RTC_MISC3 (0xE3)
  105. #define PM800_RTC_MISC4 (0xE4)
  106. #define PM800_RTC_MISC5 (0xE7)
  107. /* bit definitions of RTC Register 1 (0xD0) */
  108. #define PM800_ALARM1_EN (1 << 0)
  109. #define PM800_ALARM_WAKEUP (1 << 4)
  110. #define PM800_ALARM (1 << 5)
  111. #define PM800_RTC1_USE_XO (1 << 7)
  112. /* Regulator Control Registers: BUCK1,BUCK5,LDO1 have DVC */
  113. /* buck registers */
  114. #define PM800_SLEEP_BUCK1 (0x30)
  115. /* BUCK Sleep Mode Register 1: BUCK[1..4] */
  116. #define PM800_BUCK_SLP1 (0x5A)
  117. #define PM800_BUCK1_SLP1_SHIFT 0
  118. #define PM800_BUCK1_SLP1_MASK (0x3 << PM800_BUCK1_SLP1_SHIFT)
  119. /* page 2 GPADC: slave adder 0x02 */
  120. #define PM800_GPADC_MEAS_EN1 (0x01)
  121. #define PM800_MEAS_EN1_VBAT (1 << 2)
  122. #define PM800_GPADC_MEAS_EN2 (0x02)
  123. #define PM800_MEAS_EN2_RFTMP (1 << 0)
  124. #define PM800_MEAS_GP0_EN (1 << 2)
  125. #define PM800_MEAS_GP1_EN (1 << 3)
  126. #define PM800_MEAS_GP2_EN (1 << 4)
  127. #define PM800_MEAS_GP3_EN (1 << 5)
  128. #define PM800_MEAS_GP4_EN (1 << 6)
  129. #define PM800_GPADC_MISC_CONFIG1 (0x05)
  130. #define PM800_GPADC_MISC_CONFIG2 (0x06)
  131. #define PM800_GPADC_MISC_GPFSM_EN (1 << 0)
  132. #define PM800_GPADC_SLOW_MODE(x) (x << 3)
  133. #define PM800_GPADC_MISC_CONFIG3 (0x09)
  134. #define PM800_GPADC_MISC_CONFIG4 (0x0A)
  135. #define PM800_GPADC_PREBIAS1 (0x0F)
  136. #define PM800_GPADC0_GP_PREBIAS_TIME(x) (x << 0)
  137. #define PM800_GPADC_PREBIAS2 (0x10)
  138. #define PM800_GP_BIAS_ENA1 (0x14)
  139. #define PM800_GPADC_GP_BIAS_EN0 (1 << 0)
  140. #define PM800_GPADC_GP_BIAS_EN1 (1 << 1)
  141. #define PM800_GPADC_GP_BIAS_EN2 (1 << 2)
  142. #define PM800_GPADC_GP_BIAS_EN3 (1 << 3)
  143. #define PM800_GP_BIAS_OUT1 (0x15)
  144. #define PM800_BIAS_OUT_GP0 (1 << 0)
  145. #define PM800_BIAS_OUT_GP1 (1 << 1)
  146. #define PM800_BIAS_OUT_GP2 (1 << 2)
  147. #define PM800_BIAS_OUT_GP3 (1 << 3)
  148. #define PM800_GPADC0_LOW_TH 0x20
  149. #define PM800_GPADC1_LOW_TH 0x21
  150. #define PM800_GPADC2_LOW_TH 0x22
  151. #define PM800_GPADC3_LOW_TH 0x23
  152. #define PM800_GPADC4_LOW_TH 0x24
  153. #define PM800_GPADC0_UPP_TH 0x30
  154. #define PM800_GPADC1_UPP_TH 0x31
  155. #define PM800_GPADC2_UPP_TH 0x32
  156. #define PM800_GPADC3_UPP_TH 0x33
  157. #define PM800_GPADC4_UPP_TH 0x34
  158. #define PM800_VBBAT_MEAS1 0x40
  159. #define PM800_VBBAT_MEAS2 0x41
  160. #define PM800_VBAT_MEAS1 0x42
  161. #define PM800_VBAT_MEAS2 0x43
  162. #define PM800_VSYS_MEAS1 0x44
  163. #define PM800_VSYS_MEAS2 0x45
  164. #define PM800_VCHG_MEAS1 0x46
  165. #define PM800_VCHG_MEAS2 0x47
  166. #define PM800_TINT_MEAS1 0x50
  167. #define PM800_TINT_MEAS2 0x51
  168. #define PM800_PMOD_MEAS1 0x52
  169. #define PM800_PMOD_MEAS2 0x53
  170. #define PM800_GPADC0_MEAS1 0x54
  171. #define PM800_GPADC0_MEAS2 0x55
  172. #define PM800_GPADC1_MEAS1 0x56
  173. #define PM800_GPADC1_MEAS2 0x57
  174. #define PM800_GPADC2_MEAS1 0x58
  175. #define PM800_GPADC2_MEAS2 0x59
  176. #define PM800_GPADC3_MEAS1 0x5A
  177. #define PM800_GPADC3_MEAS2 0x5B
  178. #define PM800_GPADC4_MEAS1 0x5C
  179. #define PM800_GPADC4_MEAS2 0x5D
  180. #define PM800_GPADC4_AVG1 0xA8
  181. #define PM800_GPADC4_AVG2 0xA9
  182. /* 88PM805 Registers */
  183. #define PM805_MAIN_POWERUP (0x01)
  184. #define PM805_INT_STATUS0 (0x02) /* for ena/dis all interrupts */
  185. #define PM805_STATUS0_INT_CLEAR (1 << 0)
  186. #define PM805_STATUS0_INV_INT (1 << 1)
  187. #define PM800_STATUS0_INT_MASK (1 << 2)
  188. #define PM805_INT_STATUS1 (0x03)
  189. #define PM805_INT1_HP1_SHRT (1 << 0)
  190. #define PM805_INT1_HP2_SHRT (1 << 1)
  191. #define PM805_INT1_MIC_CONFLICT (1 << 2)
  192. #define PM805_INT1_CLIP_FAULT (1 << 3)
  193. #define PM805_INT1_LDO_OFF (1 << 4)
  194. #define PM805_INT1_SRC_DPLL_LOCK (1 << 5)
  195. #define PM805_INT_STATUS2 (0x04)
  196. #define PM805_INT2_MIC_DET (1 << 0)
  197. #define PM805_INT2_SHRT_BTN_DET (1 << 1)
  198. #define PM805_INT2_VOLM_BTN_DET (1 << 2)
  199. #define PM805_INT2_VOLP_BTN_DET (1 << 3)
  200. #define PM805_INT2_RAW_PLL_FAULT (1 << 4)
  201. #define PM805_INT2_FINE_PLL_FAULT (1 << 5)
  202. #define PM805_INT_MASK1 (0x05)
  203. #define PM805_INT_MASK2 (0x06)
  204. #define PM805_SHRT_BTN_DET (1 << 1)
  205. /* number of status and int reg in a row */
  206. #define PM805_INT_REG_NUM (2)
  207. #define PM805_MIC_DET1 (0x07)
  208. #define PM805_MIC_DET_EN_MIC_DET (1 << 0)
  209. #define PM805_MIC_DET2 (0x08)
  210. #define PM805_MIC_DET_STATUS1 (0x09)
  211. #define PM805_MIC_DET_STATUS3 (0x0A)
  212. #define PM805_AUTO_SEQ_STATUS1 (0x0B)
  213. #define PM805_AUTO_SEQ_STATUS2 (0x0C)
  214. #define PM805_ADC_SETTING1 (0x10)
  215. #define PM805_ADC_SETTING2 (0x11)
  216. #define PM805_ADC_SETTING3 (0x11)
  217. #define PM805_ADC_GAIN1 (0x12)
  218. #define PM805_ADC_GAIN2 (0x13)
  219. #define PM805_DMIC_SETTING (0x15)
  220. #define PM805_DWS_SETTING (0x16)
  221. #define PM805_MIC_CONFLICT_STS (0x17)
  222. #define PM805_PDM_SETTING1 (0x20)
  223. #define PM805_PDM_SETTING2 (0x21)
  224. #define PM805_PDM_SETTING3 (0x22)
  225. #define PM805_PDM_CONTROL1 (0x23)
  226. #define PM805_PDM_CONTROL2 (0x24)
  227. #define PM805_PDM_CONTROL3 (0x25)
  228. #define PM805_HEADPHONE_SETTING (0x26)
  229. #define PM805_HEADPHONE_GAIN_A2A (0x27)
  230. #define PM805_HEADPHONE_SHORT_STATE (0x28)
  231. #define PM805_EARPHONE_SETTING (0x29)
  232. #define PM805_AUTO_SEQ_SETTING (0x2A)
  233. struct pm80x_rtc_pdata {
  234. int vrtc;
  235. int rtc_wakeup;
  236. };
  237. struct pm80x_subchip {
  238. struct i2c_client *power_page; /* chip client for power page */
  239. struct i2c_client *gpadc_page; /* chip client for gpadc page */
  240. struct regmap *regmap_power;
  241. struct regmap *regmap_gpadc;
  242. unsigned short power_page_addr; /* power page I2C address */
  243. unsigned short gpadc_page_addr; /* gpadc page I2C address */
  244. };
  245. struct pm80x_chip {
  246. struct pm80x_subchip *subchip;
  247. struct device *dev;
  248. struct i2c_client *client;
  249. struct i2c_client *companion;
  250. struct regmap *regmap;
  251. struct regmap_irq_chip *regmap_irq_chip;
  252. struct regmap_irq_chip_data *irq_data;
  253. int type;
  254. int irq;
  255. int irq_mode;
  256. unsigned long wu_flag;
  257. spinlock_t lock;
  258. };
  259. struct pm80x_platform_data {
  260. struct pm80x_rtc_pdata *rtc;
  261. int irq_mode; /* Clear interrupt by read/write(0/1) */
  262. int batt_det; /* enable/disable */
  263. int (*plat_config)(struct pm80x_chip *chip,
  264. struct pm80x_platform_data *pdata);
  265. };
  266. extern const struct dev_pm_ops pm80x_pm_ops;
  267. extern const struct regmap_config pm80x_regmap_config;
  268. static inline int pm80x_request_irq(struct pm80x_chip *pm80x, int irq,
  269. irq_handler_t handler, unsigned long flags,
  270. const char *name, void *data)
  271. {
  272. if (!pm80x->irq_data)
  273. return -EINVAL;
  274. return request_threaded_irq(regmap_irq_get_virq(pm80x->irq_data, irq),
  275. NULL, handler, flags, name, data);
  276. }
  277. static inline void pm80x_free_irq(struct pm80x_chip *pm80x, int irq, void *data)
  278. {
  279. if (!pm80x->irq_data)
  280. return;
  281. free_irq(regmap_irq_get_virq(pm80x->irq_data, irq), data);
  282. }
  283. #ifdef CONFIG_PM
  284. static inline int pm80x_dev_suspend(struct device *dev)
  285. {
  286. struct platform_device *pdev = to_platform_device(dev);
  287. struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  288. int irq = platform_get_irq(pdev, 0);
  289. if (device_may_wakeup(dev))
  290. set_bit((1 << irq), &chip->wu_flag);
  291. return 0;
  292. }
  293. static inline int pm80x_dev_resume(struct device *dev)
  294. {
  295. struct platform_device *pdev = to_platform_device(dev);
  296. struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  297. int irq = platform_get_irq(pdev, 0);
  298. if (device_may_wakeup(dev))
  299. clear_bit((1 << irq), &chip->wu_flag);
  300. return 0;
  301. }
  302. #endif
  303. extern int pm80x_init(struct i2c_client *client);
  304. extern int pm80x_deinit(void);
  305. #endif /* __LINUX_MFD_88PM80X_H */