88pm80x.h 10.0 KB

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