max17042_battery.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Fuel gauge driver for Maxim 17042 / 8966 / 8997
  3. * Note that Maxim 8966 and 8997 are mfd and this is its subdevice.
  4. *
  5. * Copyright (C) 2011 Samsung Electronics
  6. * MyungJoo Ham <myungjoo.ham@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef __MAX17042_BATTERY_H_
  23. #define __MAX17042_BATTERY_H_
  24. #define MAX17042_STATUS_BattAbsent (1 << 3)
  25. #define MAX17042_BATTERY_FULL (100)
  26. #define MAX17042_DEFAULT_SNS_RESISTOR (10000)
  27. #define MAX17042_CHARACTERIZATION_DATA_SIZE 48
  28. enum max17042_register {
  29. MAX17042_STATUS = 0x00,
  30. MAX17042_VALRT_Th = 0x01,
  31. MAX17042_TALRT_Th = 0x02,
  32. MAX17042_SALRT_Th = 0x03,
  33. MAX17042_AtRate = 0x04,
  34. MAX17042_RepCap = 0x05,
  35. MAX17042_RepSOC = 0x06,
  36. MAX17042_Age = 0x07,
  37. MAX17042_TEMP = 0x08,
  38. MAX17042_VCELL = 0x09,
  39. MAX17042_Current = 0x0A,
  40. MAX17042_AvgCurrent = 0x0B,
  41. MAX17042_SOC = 0x0D,
  42. MAX17042_AvSOC = 0x0E,
  43. MAX17042_RemCap = 0x0F,
  44. MAX17042_FullCAP = 0x10,
  45. MAX17042_TTE = 0x11,
  46. MAX17042_V_empty = 0x12,
  47. MAX17042_RSLOW = 0x14,
  48. MAX17042_AvgTA = 0x16,
  49. MAX17042_Cycles = 0x17,
  50. MAX17042_DesignCap = 0x18,
  51. MAX17042_AvgVCELL = 0x19,
  52. MAX17042_MinMaxTemp = 0x1A,
  53. MAX17042_MinMaxVolt = 0x1B,
  54. MAX17042_MinMaxCurr = 0x1C,
  55. MAX17042_CONFIG = 0x1D,
  56. MAX17042_ICHGTerm = 0x1E,
  57. MAX17042_AvCap = 0x1F,
  58. MAX17042_ManName = 0x20,
  59. MAX17042_DevName = 0x21,
  60. MAX17042_FullCAPNom = 0x23,
  61. MAX17042_TempNom = 0x24,
  62. MAX17042_TempLim = 0x25,
  63. MAX17042_TempHot = 0x26,
  64. MAX17042_AIN = 0x27,
  65. MAX17042_LearnCFG = 0x28,
  66. MAX17042_FilterCFG = 0x29,
  67. MAX17042_RelaxCFG = 0x2A,
  68. MAX17042_MiscCFG = 0x2B,
  69. MAX17042_TGAIN = 0x2C,
  70. MAx17042_TOFF = 0x2D,
  71. MAX17042_CGAIN = 0x2E,
  72. MAX17042_COFF = 0x2F,
  73. MAX17042_MaskSOC = 0x32,
  74. MAX17042_SOC_empty = 0x33,
  75. MAX17042_T_empty = 0x34,
  76. MAX17042_FullCAP0 = 0x35,
  77. MAX17042_LAvg_empty = 0x36,
  78. MAX17042_FCTC = 0x37,
  79. MAX17042_RCOMP0 = 0x38,
  80. MAX17042_TempCo = 0x39,
  81. MAX17042_EmptyTempCo = 0x3A,
  82. MAX17042_K_empty0 = 0x3B,
  83. MAX17042_TaskPeriod = 0x3C,
  84. MAX17042_FSTAT = 0x3D,
  85. MAX17042_SHDNTIMER = 0x3F,
  86. MAX17042_dQacc = 0x45,
  87. MAX17042_dPacc = 0x46,
  88. MAX17042_VFSOC0 = 0x48,
  89. MAX17042_QH = 0x4D,
  90. MAX17042_QL = 0x4E,
  91. MAX17042_VFSOC0Enable = 0x60,
  92. MAX17042_MLOCKReg1 = 0x62,
  93. MAX17042_MLOCKReg2 = 0x63,
  94. MAX17042_MODELChrTbl = 0x80,
  95. MAX17042_OCV = 0xEE,
  96. MAX17042_OCVInternal = 0xFB,
  97. MAX17042_VFSOC = 0xFF,
  98. };
  99. /* Registers specific to max17047/50 */
  100. enum max17047_register {
  101. MAX17047_QRTbl00 = 0x12,
  102. MAX17047_FullSOCThr = 0x13,
  103. MAX17047_QRTbl10 = 0x22,
  104. MAX17047_QRTbl20 = 0x32,
  105. MAX17047_V_empty = 0x3A,
  106. MAX17047_QRTbl30 = 0x42,
  107. };
  108. enum max170xx_chip_type {
  109. MAXIM_DEVICE_TYPE_UNKNOWN = 0,
  110. MAXIM_DEVICE_TYPE_MAX17042,
  111. MAXIM_DEVICE_TYPE_MAX17047,
  112. MAXIM_DEVICE_TYPE_MAX17050,
  113. MAXIM_DEVICE_TYPE_NUM
  114. };
  115. /*
  116. * used for setting a register to a desired value
  117. * addr : address for a register
  118. * data : setting value for the register
  119. */
  120. struct max17042_reg_data {
  121. u8 addr;
  122. u16 data;
  123. };
  124. struct max17042_config_data {
  125. /* External current sense resistor value in milli-ohms */
  126. u32 cur_sense_val;
  127. /* A/D measurement */
  128. u16 tgain; /* 0x2C */
  129. u16 toff; /* 0x2D */
  130. u16 cgain; /* 0x2E */
  131. u16 coff; /* 0x2F */
  132. /* Alert / Status */
  133. u16 valrt_thresh; /* 0x01 */
  134. u16 talrt_thresh; /* 0x02 */
  135. u16 soc_alrt_thresh; /* 0x03 */
  136. u16 config; /* 0x01D */
  137. u16 shdntimer; /* 0x03F */
  138. /* App data */
  139. u16 full_soc_thresh; /* 0x13 */
  140. u16 design_cap; /* 0x18 */
  141. u16 ichgt_term; /* 0x1E */
  142. /* MG3 config */
  143. u16 at_rate; /* 0x04 */
  144. u16 learn_cfg; /* 0x28 */
  145. u16 filter_cfg; /* 0x29 */
  146. u16 relax_cfg; /* 0x2A */
  147. u16 misc_cfg; /* 0x2B */
  148. u16 masksoc; /* 0x32 */
  149. /* MG3 save and restore */
  150. u16 fullcap; /* 0x10 */
  151. u16 fullcapnom; /* 0x23 */
  152. u16 socempty; /* 0x33 */
  153. u16 lavg_empty; /* 0x36 */
  154. u16 dqacc; /* 0x45 */
  155. u16 dpacc; /* 0x46 */
  156. u16 qrtbl00; /* 0x12 */
  157. u16 qrtbl10; /* 0x22 */
  158. u16 qrtbl20; /* 0x32 */
  159. u16 qrtbl30; /* 0x42 */
  160. /* Cell technology from power_supply.h */
  161. u16 cell_technology;
  162. /* Cell Data */
  163. u16 vempty; /* 0x12 */
  164. u16 temp_nom; /* 0x24 */
  165. u16 temp_lim; /* 0x25 */
  166. u16 fctc; /* 0x37 */
  167. u16 rcomp0; /* 0x38 */
  168. u16 tcompc0; /* 0x39 */
  169. u16 empty_tempco; /* 0x3A */
  170. u16 kempty0; /* 0x3B */
  171. u16 cell_char_tbl[MAX17042_CHARACTERIZATION_DATA_SIZE];
  172. } __packed;
  173. struct max17042_platform_data {
  174. struct max17042_reg_data *init_data;
  175. struct max17042_config_data *config_data;
  176. int num_init_data; /* Number of enties in init_data array */
  177. bool enable_current_sense;
  178. bool enable_por_init; /* Use POR init from Maxim appnote */
  179. /*
  180. * R_sns in micro-ohms.
  181. * default 10000 (if r_sns = 0) as it is the recommended value by
  182. * the datasheet although it can be changed by board designers.
  183. */
  184. unsigned int r_sns;
  185. int vmin; /* in millivolts */
  186. int vmax; /* in millivolts */
  187. int temp_min; /* in tenths of degree Celsius */
  188. int temp_max; /* in tenths of degree Celsius */
  189. };
  190. #endif /* __MAX17042_BATTERY_H_ */