88pm860x.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Marvell 88PM860x Interface
  4. *
  5. * Copyright (C) 2009 Marvell International Ltd.
  6. * Haojian Zhuang <[email protected]>
  7. */
  8. #ifndef __LINUX_MFD_88PM860X_H
  9. #define __LINUX_MFD_88PM860X_H
  10. #include <linux/interrupt.h>
  11. #define MFD_NAME_SIZE (40)
  12. enum {
  13. CHIP_INVALID = 0,
  14. CHIP_PM8606,
  15. CHIP_PM8607,
  16. CHIP_MAX,
  17. };
  18. enum {
  19. PM8606_ID_INVALID,
  20. PM8606_ID_BACKLIGHT,
  21. PM8606_ID_LED,
  22. PM8606_ID_VIBRATOR,
  23. PM8606_ID_TOUCH,
  24. PM8606_ID_SOUND,
  25. PM8606_ID_CHARGER,
  26. PM8606_ID_MAX,
  27. };
  28. /* 8606 Registers */
  29. #define PM8606_DCM_BOOST (0x00)
  30. #define PM8606_PWM (0x01)
  31. #define PM8607_MISC2 (0x42)
  32. /* Power Up Log Register */
  33. #define PM8607_POWER_UP_LOG (0x3F)
  34. /* Charger Control Registers */
  35. #define PM8607_CCNT (0x47)
  36. #define PM8607_CHG_CTRL1 (0x48)
  37. #define PM8607_CHG_CTRL2 (0x49)
  38. #define PM8607_CHG_CTRL3 (0x4A)
  39. #define PM8607_CHG_CTRL4 (0x4B)
  40. #define PM8607_CHG_CTRL5 (0x4C)
  41. #define PM8607_CHG_CTRL6 (0x4D)
  42. #define PM8607_CHG_CTRL7 (0x4E)
  43. /* Backlight Registers */
  44. #define PM8606_WLED1A (0x02)
  45. #define PM8606_WLED1B (0x03)
  46. #define PM8606_WLED2A (0x04)
  47. #define PM8606_WLED2B (0x05)
  48. #define PM8606_WLED3A (0x06)
  49. #define PM8606_WLED3B (0x07)
  50. /* LED Registers */
  51. #define PM8606_RGB2A (0x08)
  52. #define PM8606_RGB2B (0x09)
  53. #define PM8606_RGB2C (0x0A)
  54. #define PM8606_RGB2D (0x0B)
  55. #define PM8606_RGB1A (0x0C)
  56. #define PM8606_RGB1B (0x0D)
  57. #define PM8606_RGB1C (0x0E)
  58. #define PM8606_RGB1D (0x0F)
  59. #define PM8606_PREREGULATORA (0x10)
  60. #define PM8606_PREREGULATORB (0x11)
  61. #define PM8606_VIBRATORA (0x12)
  62. #define PM8606_VIBRATORB (0x13)
  63. #define PM8606_VCHG (0x14)
  64. #define PM8606_VSYS (0x15)
  65. #define PM8606_MISC (0x16)
  66. #define PM8606_CHIP_ID (0x17)
  67. #define PM8606_STATUS (0x18)
  68. #define PM8606_FLAGS (0x19)
  69. #define PM8606_PROTECTA (0x1A)
  70. #define PM8606_PROTECTB (0x1B)
  71. #define PM8606_PROTECTC (0x1C)
  72. /* Bit definitions of PM8606 registers */
  73. #define PM8606_DCM_500MA (0x0) /* current limit */
  74. #define PM8606_DCM_750MA (0x1)
  75. #define PM8606_DCM_1000MA (0x2)
  76. #define PM8606_DCM_1250MA (0x3)
  77. #define PM8606_DCM_250MV (0x0 << 2)
  78. #define PM8606_DCM_300MV (0x1 << 2)
  79. #define PM8606_DCM_350MV (0x2 << 2)
  80. #define PM8606_DCM_400MV (0x3 << 2)
  81. #define PM8606_PWM_31200HZ (0x0)
  82. #define PM8606_PWM_15600HZ (0x1)
  83. #define PM8606_PWM_7800HZ (0x2)
  84. #define PM8606_PWM_3900HZ (0x3)
  85. #define PM8606_PWM_1950HZ (0x4)
  86. #define PM8606_PWM_976HZ (0x5)
  87. #define PM8606_PWM_488HZ (0x6)
  88. #define PM8606_PWM_244HZ (0x7)
  89. #define PM8606_PWM_FREQ_MASK (0x7)
  90. #define PM8606_WLED_ON (1 << 0)
  91. #define PM8606_WLED_CURRENT(x) ((x & 0x1F) << 1)
  92. #define PM8606_LED_CURRENT(x) (((x >> 2) & 0x07) << 5)
  93. #define PM8606_VSYS_EN (1 << 1)
  94. #define PM8606_MISC_OSC_EN (1 << 4)
  95. enum {
  96. PM8607_ID_BUCK1 = 0,
  97. PM8607_ID_BUCK2,
  98. PM8607_ID_BUCK3,
  99. PM8607_ID_LDO1,
  100. PM8607_ID_LDO2,
  101. PM8607_ID_LDO3,
  102. PM8607_ID_LDO4,
  103. PM8607_ID_LDO5,
  104. PM8607_ID_LDO6,
  105. PM8607_ID_LDO7,
  106. PM8607_ID_LDO8,
  107. PM8607_ID_LDO9,
  108. PM8607_ID_LDO10,
  109. PM8607_ID_LDO11,
  110. PM8607_ID_LDO12,
  111. PM8607_ID_LDO13,
  112. PM8607_ID_LDO14,
  113. PM8607_ID_LDO15,
  114. PM8606_ID_PREG,
  115. PM8607_ID_RG_MAX,
  116. };
  117. /* 8607 chip ID is 0x40 or 0x50 */
  118. #define PM8607_VERSION_MASK (0xF0) /* 8607 chip ID mask */
  119. /* Interrupt Registers */
  120. #define PM8607_STATUS_1 (0x01)
  121. #define PM8607_STATUS_2 (0x02)
  122. #define PM8607_INT_STATUS1 (0x03)
  123. #define PM8607_INT_STATUS2 (0x04)
  124. #define PM8607_INT_STATUS3 (0x05)
  125. #define PM8607_INT_MASK_1 (0x06)
  126. #define PM8607_INT_MASK_2 (0x07)
  127. #define PM8607_INT_MASK_3 (0x08)
  128. /* Regulator Control Registers */
  129. #define PM8607_LDO1 (0x10)
  130. #define PM8607_LDO2 (0x11)
  131. #define PM8607_LDO3 (0x12)
  132. #define PM8607_LDO4 (0x13)
  133. #define PM8607_LDO5 (0x14)
  134. #define PM8607_LDO6 (0x15)
  135. #define PM8607_LDO7 (0x16)
  136. #define PM8607_LDO8 (0x17)
  137. #define PM8607_LDO9 (0x18)
  138. #define PM8607_LDO10 (0x19)
  139. #define PM8607_LDO12 (0x1A)
  140. #define PM8607_LDO14 (0x1B)
  141. #define PM8607_SLEEP_MODE1 (0x1C)
  142. #define PM8607_SLEEP_MODE2 (0x1D)
  143. #define PM8607_SLEEP_MODE3 (0x1E)
  144. #define PM8607_SLEEP_MODE4 (0x1F)
  145. #define PM8607_GO (0x20)
  146. #define PM8607_SLEEP_BUCK1 (0x21)
  147. #define PM8607_SLEEP_BUCK2 (0x22)
  148. #define PM8607_SLEEP_BUCK3 (0x23)
  149. #define PM8607_BUCK1 (0x24)
  150. #define PM8607_BUCK2 (0x25)
  151. #define PM8607_BUCK3 (0x26)
  152. #define PM8607_BUCK_CONTROLS (0x27)
  153. #define PM8607_SUPPLIES_EN11 (0x2B)
  154. #define PM8607_SUPPLIES_EN12 (0x2C)
  155. #define PM8607_GROUP1 (0x2D)
  156. #define PM8607_GROUP2 (0x2E)
  157. #define PM8607_GROUP3 (0x2F)
  158. #define PM8607_GROUP4 (0x30)
  159. #define PM8607_GROUP5 (0x31)
  160. #define PM8607_GROUP6 (0x32)
  161. #define PM8607_SUPPLIES_EN21 (0x33)
  162. #define PM8607_SUPPLIES_EN22 (0x34)
  163. /* Vibrator Control Registers */
  164. #define PM8607_VIBRATOR_SET (0x28)
  165. #define PM8607_VIBRATOR_PWM (0x29)
  166. /* GPADC Registers */
  167. #define PM8607_GP_BIAS1 (0x4F)
  168. #define PM8607_MEAS_EN1 (0x50)
  169. #define PM8607_MEAS_EN2 (0x51)
  170. #define PM8607_MEAS_EN3 (0x52)
  171. #define PM8607_MEAS_OFF_TIME1 (0x53)
  172. #define PM8607_MEAS_OFF_TIME2 (0x54)
  173. #define PM8607_TSI_PREBIAS (0x55) /* prebias time */
  174. #define PM8607_PD_PREBIAS (0x56) /* prebias time */
  175. #define PM8607_GPADC_MISC1 (0x57)
  176. /* bit definitions of MEAS_EN1*/
  177. #define PM8607_MEAS_EN1_VBAT (1 << 0)
  178. #define PM8607_MEAS_EN1_VCHG (1 << 1)
  179. #define PM8607_MEAS_EN1_VSYS (1 << 2)
  180. #define PM8607_MEAS_EN1_TINT (1 << 3)
  181. #define PM8607_MEAS_EN1_RFTMP (1 << 4)
  182. #define PM8607_MEAS_EN1_TBAT (1 << 5)
  183. #define PM8607_MEAS_EN1_GPADC2 (1 << 6)
  184. #define PM8607_MEAS_EN1_GPADC3 (1 << 7)
  185. /* Battery Monitor Registers */
  186. #define PM8607_GP_BIAS2 (0x5A)
  187. #define PM8607_VBAT_LOWTH (0x5B)
  188. #define PM8607_VCHG_LOWTH (0x5C)
  189. #define PM8607_VSYS_LOWTH (0x5D)
  190. #define PM8607_TINT_LOWTH (0x5E)
  191. #define PM8607_GPADC0_LOWTH (0x5F)
  192. #define PM8607_GPADC1_LOWTH (0x60)
  193. #define PM8607_GPADC2_LOWTH (0x61)
  194. #define PM8607_GPADC3_LOWTH (0x62)
  195. #define PM8607_VBAT_HIGHTH (0x63)
  196. #define PM8607_VCHG_HIGHTH (0x64)
  197. #define PM8607_VSYS_HIGHTH (0x65)
  198. #define PM8607_TINT_HIGHTH (0x66)
  199. #define PM8607_GPADC0_HIGHTH (0x67)
  200. #define PM8607_GPADC1_HIGHTH (0x68)
  201. #define PM8607_GPADC2_HIGHTH (0x69)
  202. #define PM8607_GPADC3_HIGHTH (0x6A)
  203. #define PM8607_IBAT_MEAS1 (0x6B)
  204. #define PM8607_IBAT_MEAS2 (0x6C)
  205. #define PM8607_VBAT_MEAS1 (0x6D)
  206. #define PM8607_VBAT_MEAS2 (0x6E)
  207. #define PM8607_VCHG_MEAS1 (0x6F)
  208. #define PM8607_VCHG_MEAS2 (0x70)
  209. #define PM8607_VSYS_MEAS1 (0x71)
  210. #define PM8607_VSYS_MEAS2 (0x72)
  211. #define PM8607_TINT_MEAS1 (0x73)
  212. #define PM8607_TINT_MEAS2 (0x74)
  213. #define PM8607_GPADC0_MEAS1 (0x75)
  214. #define PM8607_GPADC0_MEAS2 (0x76)
  215. #define PM8607_GPADC1_MEAS1 (0x77)
  216. #define PM8607_GPADC1_MEAS2 (0x78)
  217. #define PM8607_GPADC2_MEAS1 (0x79)
  218. #define PM8607_GPADC2_MEAS2 (0x7A)
  219. #define PM8607_GPADC3_MEAS1 (0x7B)
  220. #define PM8607_GPADC3_MEAS2 (0x7C)
  221. #define PM8607_CCNT_MEAS1 (0x95)
  222. #define PM8607_CCNT_MEAS2 (0x96)
  223. #define PM8607_VBAT_AVG (0x97)
  224. #define PM8607_VCHG_AVG (0x98)
  225. #define PM8607_VSYS_AVG (0x99)
  226. #define PM8607_VBAT_MIN (0x9A)
  227. #define PM8607_VCHG_MIN (0x9B)
  228. #define PM8607_VSYS_MIN (0x9C)
  229. #define PM8607_VBAT_MAX (0x9D)
  230. #define PM8607_VCHG_MAX (0x9E)
  231. #define PM8607_VSYS_MAX (0x9F)
  232. #define PM8607_GPADC_MISC2 (0x59)
  233. #define PM8607_GPADC0_GP_BIAS_A0 (1 << 0)
  234. #define PM8607_GPADC1_GP_BIAS_A1 (1 << 1)
  235. #define PM8607_GPADC2_GP_BIAS_A2 (1 << 2)
  236. #define PM8607_GPADC3_GP_BIAS_A3 (1 << 3)
  237. #define PM8607_GPADC2_GP_BIAS_OUT2 (1 << 6)
  238. /* RTC Control Registers */
  239. #define PM8607_RTC1 (0xA0)
  240. #define PM8607_RTC_COUNTER1 (0xA1)
  241. #define PM8607_RTC_COUNTER2 (0xA2)
  242. #define PM8607_RTC_COUNTER3 (0xA3)
  243. #define PM8607_RTC_COUNTER4 (0xA4)
  244. #define PM8607_RTC_EXPIRE1 (0xA5)
  245. #define PM8607_RTC_EXPIRE2 (0xA6)
  246. #define PM8607_RTC_EXPIRE3 (0xA7)
  247. #define PM8607_RTC_EXPIRE4 (0xA8)
  248. #define PM8607_RTC_TRIM1 (0xA9)
  249. #define PM8607_RTC_TRIM2 (0xAA)
  250. #define PM8607_RTC_TRIM3 (0xAB)
  251. #define PM8607_RTC_TRIM4 (0xAC)
  252. #define PM8607_RTC_MISC1 (0xAD)
  253. #define PM8607_RTC_MISC2 (0xAE)
  254. #define PM8607_RTC_MISC3 (0xAF)
  255. /* Misc Registers */
  256. #define PM8607_CHIP_ID (0x00)
  257. #define PM8607_B0_MISC1 (0x0C)
  258. #define PM8607_LDO1 (0x10)
  259. #define PM8607_DVC3 (0x26)
  260. #define PM8607_A1_MISC1 (0x40)
  261. /* bit definitions of Status Query Interface */
  262. #define PM8607_STATUS_CC (1 << 3)
  263. #define PM8607_STATUS_PEN (1 << 4)
  264. #define PM8607_STATUS_HEADSET (1 << 5)
  265. #define PM8607_STATUS_HOOK (1 << 6)
  266. #define PM8607_STATUS_MICIN (1 << 7)
  267. #define PM8607_STATUS_ONKEY (1 << 8)
  268. #define PM8607_STATUS_EXTON (1 << 9)
  269. #define PM8607_STATUS_CHG (1 << 10)
  270. #define PM8607_STATUS_BAT (1 << 11)
  271. #define PM8607_STATUS_VBUS (1 << 12)
  272. #define PM8607_STATUS_OV (1 << 13)
  273. /* bit definitions of BUCK3 */
  274. #define PM8607_BUCK3_DOUBLE (1 << 6)
  275. /* bit definitions of Misc1 */
  276. #define PM8607_A1_MISC1_PI2C (1 << 0)
  277. #define PM8607_B0_MISC1_INV_INT (1 << 0)
  278. #define PM8607_B0_MISC1_INT_CLEAR (1 << 1)
  279. #define PM8607_B0_MISC1_INT_MASK (1 << 2)
  280. #define PM8607_B0_MISC1_PI2C (1 << 3)
  281. #define PM8607_B0_MISC1_RESET (1 << 6)
  282. /* bits definitions of GPADC */
  283. #define PM8607_GPADC_EN (1 << 0)
  284. #define PM8607_GPADC_PREBIAS_MASK (3 << 1)
  285. #define PM8607_GPADC_SLOT_CYCLE_MASK (3 << 3) /* slow mode */
  286. #define PM8607_GPADC_OFF_SCALE_MASK (3 << 5) /* GP sleep mode */
  287. #define PM8607_GPADC_SW_CAL_MASK (1 << 7)
  288. #define PM8607_PD_PREBIAS_MASK (0x1F << 0)
  289. #define PM8607_PD_PRECHG_MASK (7 << 5)
  290. #define PM8606_REF_GP_OSC_OFF 0
  291. #define PM8606_REF_GP_OSC_ON 1
  292. #define PM8606_REF_GP_OSC_UNKNOWN 2
  293. /* Clients of reference group and 8MHz oscillator in 88PM8606 */
  294. enum pm8606_ref_gp_and_osc_clients {
  295. REF_GP_NO_CLIENTS = 0,
  296. WLED1_DUTY = (1<<0), /*PF 0x02.7:0*/
  297. WLED2_DUTY = (1<<1), /*PF 0x04.7:0*/
  298. WLED3_DUTY = (1<<2), /*PF 0x06.7:0*/
  299. RGB1_ENABLE = (1<<3), /*PF 0x07.1*/
  300. RGB2_ENABLE = (1<<4), /*PF 0x07.2*/
  301. LDO_VBR_EN = (1<<5), /*PF 0x12.0*/
  302. REF_GP_MAX_CLIENT = 0xFFFF
  303. };
  304. /* Interrupt Number in 88PM8607 */
  305. enum {
  306. PM8607_IRQ_ONKEY,
  307. PM8607_IRQ_EXTON,
  308. PM8607_IRQ_CHG,
  309. PM8607_IRQ_BAT,
  310. PM8607_IRQ_RTC,
  311. PM8607_IRQ_CC,
  312. PM8607_IRQ_VBAT,
  313. PM8607_IRQ_VCHG,
  314. PM8607_IRQ_VSYS,
  315. PM8607_IRQ_TINT,
  316. PM8607_IRQ_GPADC0,
  317. PM8607_IRQ_GPADC1,
  318. PM8607_IRQ_GPADC2,
  319. PM8607_IRQ_GPADC3,
  320. PM8607_IRQ_AUDIO_SHORT,
  321. PM8607_IRQ_PEN,
  322. PM8607_IRQ_HEADSET,
  323. PM8607_IRQ_HOOK,
  324. PM8607_IRQ_MICIN,
  325. PM8607_IRQ_CHG_FAIL,
  326. PM8607_IRQ_CHG_DONE,
  327. PM8607_IRQ_CHG_FAULT,
  328. };
  329. enum {
  330. PM8607_CHIP_A0 = 0x40,
  331. PM8607_CHIP_A1 = 0x41,
  332. PM8607_CHIP_B0 = 0x48,
  333. };
  334. struct pm860x_chip {
  335. struct device *dev;
  336. struct mutex irq_lock;
  337. struct mutex osc_lock;
  338. struct i2c_client *client;
  339. struct i2c_client *companion; /* companion chip client */
  340. struct regmap *regmap;
  341. struct regmap *regmap_companion;
  342. int buck3_double; /* DVC ramp slope double */
  343. int companion_addr;
  344. unsigned short osc_vote;
  345. int id;
  346. int irq_mode;
  347. int irq_base;
  348. int core_irq;
  349. unsigned char chip_version;
  350. unsigned char osc_status;
  351. unsigned int wakeup_flag;
  352. };
  353. enum {
  354. GI2C_PORT = 0,
  355. PI2C_PORT,
  356. };
  357. struct pm860x_backlight_pdata {
  358. int pwm;
  359. int iset;
  360. };
  361. struct pm860x_led_pdata {
  362. int iset;
  363. };
  364. struct pm860x_rtc_pdata {
  365. int (*sync)(unsigned int ticks);
  366. int vrtc;
  367. };
  368. struct pm860x_touch_pdata {
  369. int gpadc_prebias;
  370. int slot_cycle;
  371. int off_scale;
  372. int sw_cal;
  373. int tsi_prebias; /* time, slot */
  374. int pen_prebias; /* time, slot */
  375. int pen_prechg; /* time, slot */
  376. int res_x; /* resistor of Xplate */
  377. unsigned long flags;
  378. };
  379. struct pm860x_power_pdata {
  380. int max_capacity;
  381. int resistor;
  382. };
  383. struct pm860x_platform_data {
  384. struct pm860x_backlight_pdata *backlight;
  385. struct pm860x_led_pdata *led;
  386. struct pm860x_rtc_pdata *rtc;
  387. struct pm860x_touch_pdata *touch;
  388. struct pm860x_power_pdata *power;
  389. struct regulator_init_data *buck1;
  390. struct regulator_init_data *buck2;
  391. struct regulator_init_data *buck3;
  392. struct regulator_init_data *ldo1;
  393. struct regulator_init_data *ldo2;
  394. struct regulator_init_data *ldo3;
  395. struct regulator_init_data *ldo4;
  396. struct regulator_init_data *ldo5;
  397. struct regulator_init_data *ldo6;
  398. struct regulator_init_data *ldo7;
  399. struct regulator_init_data *ldo8;
  400. struct regulator_init_data *ldo9;
  401. struct regulator_init_data *ldo10;
  402. struct regulator_init_data *ldo12;
  403. struct regulator_init_data *ldo_vibrator;
  404. struct regulator_init_data *ldo14;
  405. struct charger_desc *chg_desc;
  406. int companion_addr; /* I2C address of companion chip */
  407. int i2c_port; /* Controlled by GI2C or PI2C */
  408. int irq_mode; /* Clear interrupt by read/write(0/1) */
  409. int irq_base; /* IRQ base number of 88pm860x */
  410. int num_leds;
  411. int num_backlights;
  412. };
  413. extern int pm8606_osc_enable(struct pm860x_chip *, unsigned short);
  414. extern int pm8606_osc_disable(struct pm860x_chip *, unsigned short);
  415. extern int pm860x_reg_read(struct i2c_client *, int);
  416. extern int pm860x_reg_write(struct i2c_client *, int, unsigned char);
  417. extern int pm860x_bulk_read(struct i2c_client *, int, int, unsigned char *);
  418. extern int pm860x_bulk_write(struct i2c_client *, int, int, unsigned char *);
  419. extern int pm860x_set_bits(struct i2c_client *, int, unsigned char,
  420. unsigned char);
  421. extern int pm860x_page_reg_read(struct i2c_client *, int);
  422. extern int pm860x_page_reg_write(struct i2c_client *, int, unsigned char);
  423. extern int pm860x_page_bulk_read(struct i2c_client *, int, int,
  424. unsigned char *);
  425. extern int pm860x_page_bulk_write(struct i2c_client *, int, int,
  426. unsigned char *);
  427. extern int pm860x_page_set_bits(struct i2c_client *, int, unsigned char,
  428. unsigned char);
  429. #endif /* __LINUX_MFD_88PM860X_H */