twl6030.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2010
  4. * Texas Instruments, <www.ti.com>
  5. */
  6. #ifndef TWL6030_H
  7. #define TWL6030_H
  8. #include <common.h>
  9. #include <i2c.h>
  10. /* I2C chip addresses */
  11. #define TWL6030_CHIP_PM 0x48
  12. #define TWL6030_CHIP_USB 0x49
  13. #define TWL6030_CHIP_ADC 0x49
  14. #define TWL6030_CHIP_CHARGER 0x49
  15. #define TWL6030_CHIP_PWM 0x49
  16. /* Slave Address 0x48 */
  17. #define TWL6030_STS_HW_CONDITIONS 0x21
  18. #define TWL6030_STS_HW_CONDITIONS_PWRON (1 << 0)
  19. #define TWL6030_PHOENIX_DEV_ON 0x25
  20. #define TWL6030_PHOENIX_APP_DEVOFF (1 << 0)
  21. #define TWL6030_PHOENIX_CON_DEVOFF (1 << 1)
  22. #define TWL6030_PHOENIX_MOD_DEVOFF (1 << 2)
  23. #define TWL6030_PH_STS_BOOT 0x29
  24. #define TWL6030_PH_STS_BOOT0 (1 << 0)
  25. #define TWL6030_PH_STS_BOOT1 (1 << 1)
  26. #define TWL6030_PH_STS_BOOT2 (1 << 2)
  27. #define TWL6030_PH_STS_BOOT3 (1 << 3)
  28. #define TWL6030_VAUX1_CFG_STATE 0x86
  29. #define TWL6030_VAUX1_CFG_VOLTAGE 0x87
  30. #define TWL6030_VMMC_CFG_STATE 0x9A
  31. #define TWL6030_VMMC_CFG_VOLTAGE 0x9B
  32. #define TWL6030_VUSB_CFG_STATE 0xA2
  33. #define TWL6030_VUSB_CFG_VOLTAGE 0xA3
  34. #define TWL6030_CFG_GRP_P1 (1 << 0)
  35. #define TWL6030_CFG_STATE_ON (1 << 0)
  36. #define TWL6030_CFG_STATE_P1 (TWL6030_CFG_GRP_P1 << 5)
  37. #define TWL6030_CFG_VOLTAGE_18 0x09
  38. #define TWL6030_CFG_VOLTAGE_28 0x13
  39. #define TWL6030_CFG_VOLTAGE_30 0x15
  40. #define TWL6030_CFG_VOLTAGE_33 0x18
  41. #define MISC1 0xE4
  42. #define VAC_MEAS (1 << 2)
  43. #define VBAT_MEAS (1 << 1)
  44. #define BB_MEAS (1 << 0)
  45. #define TWL6030_MISC2 0xE5
  46. #define TWL6030_MISC2_VUSB_IN_PMID (1 << 3)
  47. #define TWL6030_MISC2_VUSB_IN_VSYS (1 << 4)
  48. /* Slave Address 0x49 */
  49. #define TWL6030_CONTROLLER_STAT1 0xE3
  50. #define TWL6030_CONTROLLER_STAT1_VAC_DET (1 << 3)
  51. #define TWL6030_CONTROLLER_STAT1_VBUS_DET (1 << 2)
  52. /* Battery CHARGER REGISTERS */
  53. #define CONTROLLER_INT_MASK 0xE0
  54. #define CONTROLLER_CTRL1 0xE1
  55. #define CONTROLLER_WDG 0xE2
  56. #define CONTROLLER_STAT1 0xE3
  57. #define CHARGERUSB_INT_STATUS 0xE4
  58. #define CHARGERUSB_INT_MASK 0xE5
  59. #define CHARGERUSB_STATUS_INT1 0xE6
  60. #define CHARGERUSB_STATUS_INT2 0xE7
  61. #define CHARGERUSB_CTRL1 0xE8
  62. #define CHARGERUSB_CTRL2 0xE9
  63. #define CHARGERUSB_CTRL3 0xEA
  64. #define CHARGERUSB_STAT1 0xEB
  65. #define CHARGERUSB_VOREG 0xEC
  66. #define CHARGERUSB_VICHRG 0xED
  67. #define CHARGERUSB_CINLIMIT 0xEE
  68. #define CHARGERUSB_CTRLLIMIT1 0xEF
  69. /* CHARGERUSB_VICHRG */
  70. #define CHARGERUSB_VICHRG_500 0x4
  71. #define CHARGERUSB_VICHRG_1500 0xE
  72. /* CHARGERUSB_CINLIMIT */
  73. #define CHARGERUSB_CIN_LIMIT_100 0x1
  74. #define CHARGERUSB_CIN_LIMIT_300 0x5
  75. #define CHARGERUSB_CIN_LIMIT_500 0x9
  76. #define CHARGERUSB_CIN_LIMIT_NONE 0xF
  77. /* CONTROLLER_INT_MASK */
  78. #define MVAC_FAULT (1 << 6)
  79. #define MAC_EOC (1 << 5)
  80. #define MBAT_REMOVED (1 << 4)
  81. #define MFAULT_WDG (1 << 3)
  82. #define MBAT_TEMP (1 << 2)
  83. #define MVBUS_DET (1 << 1)
  84. #define MVAC_DET (1 << 0)
  85. /* CHARGERUSB_INT_MASK */
  86. #define MASK_MCURRENT_TERM (1 << 3)
  87. #define MASK_MCHARGERUSB_STAT (1 << 2)
  88. #define MASK_MCHARGERUSB_THMREG (1 << 1)
  89. #define MASK_MCHARGERUSB_FAULT (1 << 0)
  90. /* CHARGERUSB_VOREG */
  91. #define CHARGERUSB_VOREG_3P52 0x01
  92. #define CHARGERUSB_VOREG_4P0 0x19
  93. #define CHARGERUSB_VOREG_4P2 0x23
  94. #define CHARGERUSB_VOREG_4P76 0x3F
  95. /* CHARGERUSB_CTRL1 */
  96. #define SUSPEND_BOOT (1 << 7)
  97. #define OPA_MODE (1 << 6)
  98. #define HZ_MODE (1 << 5)
  99. #define TERM (1 << 4)
  100. /* CHARGERUSB_CTRL2 */
  101. #define CHARGERUSB_CTRL2_VITERM_50 (0 << 5)
  102. #define CHARGERUSB_CTRL2_VITERM_100 (1 << 5)
  103. #define CHARGERUSB_CTRL2_VITERM_150 (2 << 5)
  104. #define CHARGERUSB_CTRL2_VITERM_400 (7 << 5)
  105. /* CONTROLLER_CTRL1 */
  106. #define CONTROLLER_CTRL1_EN_CHARGER (1 << 4)
  107. #define CONTROLLER_CTRL1_SEL_CHARGER (1 << 3)
  108. /* CONTROLLER_STAT1 */
  109. #define CHRG_EXTCHRG_STATZ (1 << 7)
  110. #define CHRG_DET_N (1 << 5)
  111. #define VAC_DET (1 << 3)
  112. #define VBUS_DET (1 << 2)
  113. #define FG_REG_10 0xCA
  114. #define FG_REG_11 0xCB
  115. #define TOGGLE1 0x90
  116. #define FGS (1 << 5)
  117. #define FGR (1 << 4)
  118. #define GPADCS (1 << 1)
  119. #define GPADCR (1 << 0)
  120. #define CTRL_P2 0x34
  121. #define CTRL_P2_SP2 (1 << 2)
  122. #define CTRL_P2_EOCP2 (1 << 1)
  123. #define CTRL_P2_BUSY (1 << 0)
  124. #define TWL6032_CTRL_P1 0x36
  125. #define CTRL_P1_SP1 (1 << 3)
  126. #define GPCH0_LSB 0x57
  127. #define GPCH0_MSB 0x58
  128. #define TWL6032_GPCH0_LSB 0x3b
  129. #define TWL6032_GPSELECT_ISB 0x35
  130. #define USB_PRODUCT_ID_LSB 0x02
  131. #define TWL6030_GPADC_VBAT_CHNL 0x07
  132. #define TWL6032_GPADC_VBAT_CHNL 0x12
  133. #define TWL6030_GPADC_CTRL 0x2e
  134. #define TWL6032_GPADC_CTRL2 0x2f
  135. #define GPADC_CTRL2_CH18_SCALER_EN (1 << 2)
  136. #define GPADC_CTRL_SCALER_DIV4 (1 << 3)
  137. #define TWL6030_VBAT_MULT 40 * 1000
  138. #define TWL6032_VBAT_MULT 25 * 1000
  139. #define TWL6030_VBAT_SHIFT (10 + 3)
  140. #define TWL6032_VBAT_SHIFT (12 + 2)
  141. enum twl603x_chip_type{
  142. chip_TWL6030,
  143. chip_TWL6032,
  144. chip_TWL603X_cnt
  145. };
  146. struct twl6030_data{
  147. u8 chip_type;
  148. u8 adc_rbase;
  149. u8 adc_ctrl;
  150. u8 adc_enable;
  151. int vbat_mult;
  152. int vbat_shift;
  153. };
  154. /* Functions to read and write from TWL6030 */
  155. #ifndef CONFIG_DM_I2C
  156. static inline int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val)
  157. {
  158. return i2c_write(chip_no, reg, 1, &val, 1);
  159. }
  160. static inline int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val)
  161. {
  162. return i2c_read(chip_no, reg, 1, val, 1);
  163. }
  164. #else
  165. int twl6030_i2c_write_u8(u8 chip_no, u8 reg, u8 val);
  166. int twl6030_i2c_read_u8(u8 chip_no, u8 reg, u8 *val);
  167. #endif
  168. /*
  169. * Power
  170. */
  171. void twl6030_power_off(void);
  172. void twl6030_init_battery_charging(void);
  173. void twl6030_usb_device_settings(void);
  174. void twl6030_start_usb_charging(void);
  175. void twl6030_stop_usb_charging(void);
  176. int twl6030_get_battery_voltage(void);
  177. int twl6030_get_battery_current(void);
  178. void twl6030_power_mmc_init(int dev_index);
  179. /*
  180. * Input
  181. */
  182. int twl6030_input_power_button(void);
  183. int twl6030_input_charger(void);
  184. int twl6030_input_usb(void);
  185. #endif /* TWL6030_H */