s2dos05.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * s2dos05.h
  3. *
  4. * Copyright (c) 2016 Samsung Electronics Co., Ltd
  5. * http://www.samsung.com
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #ifndef __LINUX_MFD_S2DOS05_H
  14. #define __LINUX_MFD_S2DOS05_H
  15. #include <linux/platform_device.h>
  16. #include <linux/regmap.h>
  17. #define MFD_DEV_NAME "s2dos05"
  18. /**
  19. * sec_regulator_data - regulator data
  20. * @id: regulator id
  21. * @initdata: regulator init data (contraints, supplies, ...)
  22. */
  23. struct s2dos05_dev {
  24. struct device *dev;
  25. struct i2c_client *i2c; /* 0xB2; PMIC, Flash LED */
  26. struct mutex i2c_lock;
  27. int type;
  28. u8 rev_num; /* pmic Rev */
  29. bool wakeup;
  30. int dp_pmic_irq;
  31. int adc_mode;
  32. int adc_sync_mode;
  33. u8 adc_en_val;
  34. struct s2dos05_platform_data *pdata;
  35. #if IS_ENABLED(CONFIG_DRV_SAMSUNG_PMIC)
  36. struct device *powermeter_dev;
  37. #endif
  38. struct adc_info *adc_meter;
  39. #if IS_ENABLED(CONFIG_SEC_PM)
  40. struct device *sec_disp_pmic_dev;
  41. bool is_sm3080;
  42. #endif /* CONFIG_SEC_PM */
  43. };
  44. struct s2dos05_regulator_data {
  45. int id;
  46. struct regulator_init_data *initdata;
  47. struct device_node *reg_node;
  48. };
  49. struct s2dos05_platform_data {
  50. bool wakeup;
  51. int num_regulators;
  52. int num_rdata;
  53. struct s2dos05_regulator_data *regulators;
  54. int device_type;
  55. int dp_pmic_irq;
  56. /* adc_mode
  57. * 0 : not use
  58. * 1 : current meter
  59. * 2 : power meter
  60. */
  61. int adc_mode;
  62. /* 1 : sync mode, 2 : async mode */
  63. int adc_sync_mode;
  64. #if IS_ENABLED(CONFIG_SEC_PM)
  65. const char *sec_disp_pmic_name;
  66. /* OCL_ELVSS
  67. * 0: 1.3A
  68. * 1: 1.5A
  69. * 2: 1.7A (default)
  70. * 3: 1.9A
  71. */
  72. int ocl_elvss;
  73. unsigned int enable_fd_delay_ms;
  74. #endif /* CONFIG_SEC_PM */
  75. };
  76. struct s2dos05 {
  77. struct regmap *regmap;
  78. };
  79. /* S2DOS05 registers */
  80. /* Slave Addr : 0xC0 */
  81. enum S2DOS05_reg {
  82. S2DOS05_REG_DEV_ID,
  83. S2DOS05_REG_TOPSYS_STAT,
  84. S2DOS05_REG_STAT,
  85. S2DOS05_REG_EN,
  86. S2DOS05_REG_LDO1_CFG,
  87. S2DOS05_REG_LDO2_CFG,
  88. S2DOS05_REG_LDO3_CFG,
  89. S2DOS05_REG_LDO4_CFG,
  90. S2DOS05_REG_BUCK_CFG,
  91. S2DOS05_REG_BUCK_VOUT,
  92. S2DOS05_REG_IRQ_MASK = 0x0D,
  93. #if IS_ENABLED(CONFIG_SEC_PM)
  94. S2DOS05_REG_SSD_TSD = 0x0E,
  95. S2DOS05_REG_UVLO_FD = 0x0F,
  96. S2DOS05_REG_OCL = 0x10,
  97. #endif /* CONFIG_SEC_PM */
  98. S2DOS05_REG_IRQ = 0x11,
  99. #if IS_ENABLED(CONFIG_SEC_PM)
  100. S2DOS05_REG_DEVICE_ID_PGM = 0x61,
  101. #endif /* CONFIG_SEC_PM */
  102. };
  103. /* S2DOS05 regulator ids */
  104. enum S2DOS05_regulators {
  105. S2DOS05_LDO1,
  106. S2DOS05_LDO2,
  107. S2DOS05_LDO3,
  108. S2DOS05_LDO4,
  109. S2DOS05_BUCK1,
  110. #if IS_ENABLED(CONFIG_SEC_PM)
  111. S2DOS05_ELVSS_SSD,
  112. S2DOS05_ELVSS_FD,
  113. #endif /* CONFIG_SEC_PM */
  114. S2DOS05_REG_MAX,
  115. };
  116. #define S2DOS05_IRQ_PWRMT_MASK (1 << 5)
  117. #define S2DOS05_IRQ_TSD_MASK (1 << 4)
  118. #define S2DOS05_IRQ_SSD_MASK (1 << 3)
  119. #define S2DOS05_IRQ_SCP_MASK (1 << 2)
  120. #define S2DOS05_IRQ_UVLO_MASK (1 << 1)
  121. #define S2DOS05_IRQ_OCD_MASK (1 << 0)
  122. #define S2DOS05_BUCK_MIN1 506250
  123. #define S2DOS05_LDO_MIN1 1500000
  124. #define S2DOS05_LDO_MIN2 2700000
  125. #define S2DOS05_BUCK_STEP1 6250
  126. #define S2DOS05_LDO_STEP1 25000
  127. #define S2DOS05_LDO_VSEL_MASK 0x7F
  128. #define S2DOS05_BUCK_VSEL_MASK 0xFF
  129. #if IS_ENABLED(CONFIG_SEC_PM)
  130. #define S2DOS05_ELVSS_SEL_SSD_MASK (3 << 5)
  131. #define S2DOS05_ELVSS_SSD_EN_MASK (3 << 3)
  132. #endif /* CONFIG_SEC_PM */
  133. #define S2DOS05_ENABLE_MASK_L1 (1 << 0)
  134. #define S2DOS05_ENABLE_MASK_L2 (1 << 1)
  135. #define S2DOS05_ENABLE_MASK_L3 (1 << 2)
  136. #define S2DOS05_ENABLE_MASK_L4 (1 << 3)
  137. #define S2DOS05_ENABLE_MASK_B1 (1 << 4)
  138. #define S2DOS05_OCL_ELVSS_MASK (3 << 0)
  139. /* hidden for SM3080 only */
  140. #define SM3080_AVDD 5
  141. #define SM3080_ELVSS 6
  142. #define SM3080_ELVDD 7
  143. #define SM3080_ENABLE_MASK_AVDD (1 << SM3080_AVDD)
  144. #define SM3080_ENABLE_MASK_ELVSS (1 << SM3080_ELVSS)
  145. #define SM3080_ENABLE_MASK_ELVDD (1 << SM3080_ELVDD)
  146. #define S2DOS05_RAMP_DELAY 12000
  147. #define S2DOS05_ENABLE_TIME_LDO 50
  148. #define S2DOS05_ENABLE_TIME_BUCK 350
  149. #define S2DOS05_ENABLE_SHIFT 0x06
  150. #define S2DOS05_LDO_N_VOLTAGES (S2DOS05_LDO_VSEL_MASK + 1)
  151. #define S2DOS05_BUCK_N_VOLTAGES (S2DOS05_BUCK_VSEL_MASK + 1)
  152. #define S2DOS05_PMIC_EN_SHIFT 6
  153. #define S2DOS05_REGULATOR_MAX (S2DOS05_REG_MAX)
  154. /* ----------power meter ----------*/
  155. #define S2DOS05_REG_PWRMT_CTRL1 0x0A
  156. #define S2DOS05_REG_PWRMT_CTRL2 0x0B
  157. #define S2DOS05_REG_PWRMT_DATA 0x0C
  158. #define S2DOS05_REG_IRQ_MASK 0x0D
  159. #define CURRENT_ELVDD 2450
  160. #define CURRENT_ELVSS 2450
  161. #define CURRENT_AVDD 612
  162. #define CURRENT_BUCK 1220
  163. #define CURRENT_L1 2000
  164. #define CURRENT_L2 2000
  165. #define CURRENT_L3 2000
  166. #define CURRENT_L4 2000
  167. #define POWER_ELVDD 24500
  168. #define POWER_ELVSS 24500
  169. #define POWER_AVDD 3060
  170. #define POWER_BUCK 1525
  171. #define POWER_L1 5000
  172. #define POWER_L2 5000
  173. #define POWER_L3 5000
  174. #define POWER_L4 5000
  175. #define ADC_EN_MASK 0x80
  176. #define ADC_ASYNCRD_MASK 0x80
  177. #define ADC_PTR_MASK 0x0F
  178. #define ADC_PGEN_MASK 0x30
  179. #define CURRENT_MODE 0x00
  180. #define POWER_MODE 0x10
  181. #define RAWCURRENT_MODE 0x20
  182. #define FAULT_STATUS1 0x67 /* S2DOS05 SCP */
  183. #define FAULT_STATUS2 0x68
  184. #define INT_STATUS1 0xB8 /* SM3080 SCP */
  185. #define SMPNUM_MASK 0x0F
  186. #define S2DOS05_MAX_ADC_CHANNEL 8
  187. extern void s2dos05_powermeter_init(struct s2dos05_dev *s2dos05);
  188. extern void s2dos05_powermeter_deinit(struct s2dos05_dev *s2dos05);
  189. /* S2DOS05 shared i2c API function */
  190. extern int s2dos05_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest);
  191. extern int s2dos05_write_reg(struct i2c_client *i2c, u8 reg, u8 value);
  192. extern int s2dos05_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask);
  193. #endif /* __LINUX_MFD_S2DOS05_H */