bat_sbi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. *********************************************************************
  3. * File : bat_sbi.h
  4. * Description : This file implement the Smart battery interface.
  5. * Note : it depends on bat_i2c driver.
  6. * Author : Shoufu Zhao <shoufu.zhao@amlogic.com> 2010/11/24
  7. *********************************************************************
  8. */
  9. #ifndef __BAT_SBI_H__
  10. #define __BAT_SBI_H__
  11. /**
  12. * BatteryMode.
  13. *
  14. * Description : This function reports the battery system's operational modes and
  15. * capabilities, and flags minor conditions requiring attention.
  16. * Purpose : To allow the Host Device to determine the presence of Fule Cell system
  17. * and the particular data reporting formats.
  18. * SMBus Protocol: Read or Write Word
  19. * TODO: what is this doing?
  20. */
  21. #define SBI_BATTERY_MODE 0x30
  22. /**
  23. * Temperature(0x08).
  24. * Description :This read-word function returns a unsigned integer value of the
  25. * temperature in units of 0.1K as measured by the bq20z70. It has a range
  26. * of 0~6553.5K.
  27. * SMBus protocol : read word
  28. * Out: unsigned 16-bit.
  29. */
  30. #define SBI_TEMPERATURE 0x08
  31. /**
  32. * Voltage (0x09)
  33. * Description : Value of the sum of individual of cell voltage measures in mV with
  34. * a range of 0~20000mV.
  35. * SMBus Protocol : read word.
  36. * Out : unsigned 16-bit.
  37. */
  38. #define SBI_VOLTAGE 0x09
  39. /**
  40. * Current (0x0A).
  41. *
  42. * SMBus protocol : Read Word.
  43. * Out : signed 16-bit integar.
  44. */
  45. #define SBI_CURRENT 0x0A
  46. /**
  47. * RelativeStateOfCharge(0Dh).
  48. *
  49. * Description : Returns the predicated remaining battery capacity or Fule Cell system fule
  50. * cartridge expressed as a precentage of the DesignCapacity(%)
  51. * Purpose : The RelativeStateOfCharge function is used to estimate the amount of charge
  52. * remaining in the battery or fule in the Fule Cell system fule cartridge(s).
  53. * SMBus Protocol : Read Word
  54. * Output : unsigned int - percent of remaining capacity
  55. * Unitis: %
  56. * Range: 0 to 100%
  57. * Granularity: 2%
  58. * Accuracy : 10%
  59. *
  60. * BQ20Z70: This value is expressed in either charge(mAh) or energy(10mWh), depending
  61. * on the setting of [CAPACITY_MODE] flag.
  62. */
  63. #define SBI_RELATIVE_STATE_OF_CHARGE 0x0D
  64. /**
  65. * RemaningCapacity (0Fh)
  66. * Description : Returns the predicated remaining battery capacity of Fule Cell
  67. * system internal battery capacity in milli-Amp-hour(mAh)
  68. * SMBus protocol : Read Word
  69. * Output : Units : mAh
  70. * Range : 0-65535mAh
  71. */
  72. #define SBI_REMAINING_CAPACITY 0x0F
  73. /**
  74. * FullChargeCapacity(10h)
  75. *
  76. * Description : Returns the predicated pack capacity or Fuel Cell system internal * battery capacity when it is fully charged in milli-Amp-Hours(mAh)
  77. * SMBus Protocal : Read Word
  78. * Output : unsigned int - estimated full charge capacity in mAh.
  79. * Units: mAh
  80. * Range: 0 ~ 65535
  81. *
  82. * BQ20Z70: This value is expressed in either charge(mAh) or power(mWh) depending on
  83. * the setting of [CAPACITY_MODE] flag.
  84. */
  85. #define SBI_FULL_CHARGE_CAPACITY 0x10
  86. /**
  87. * AverageTimeToEmpty(0x12h)
  88. * Description: Returns a rolling average of the predicated remaining battery life
  89. * or Fule Cell system fule cartridge remaining runtime in minutes.
  90. * SMBus protocol : Read Word
  91. * Output : unsigned int - minute of operation left.
  92. * Unit: minutes
  93. *
  94. * BQ20Z70: A range of 0~65534. A value of 65535 indicates that the battery is not
  95. * being discharged.
  96. * 0~05535 = predicted remaining battery life, based on AverageCurrent
  97. * 65535 = battery is not being discharged.
  98. */
  99. #define SBI_AVERAGE_TIME_TO_EMPTY 0x12
  100. /**
  101. * BatteryStatus (16h).
  102. * Description : Returns the status word which contains alarm and status bit flags
  103. * which indicate end-of-discharge, over temperature, and other conditions.
  104. * Purpose: The BatteryStatus() function is used by the Host Device to get alram
  105. * and status bits, as well as error code from the Smart Battery.
  106. * SMBus Protocol : Read Word.
  107. * Out : unsigned 16-bit.
  108. *
  109. * --------------Alarm Bits--------------
  110. * 0x8000 OVER_CHARGED_ALARM
  111. * 0x4000 TERMINATE_CHARGE_ALARM
  112. * 0x2000 reserved
  113. * 0x1000 OVER_TEMP_ALARM
  114. * 0x0800 TERMINATE_DISCHARGE_ALARM
  115. * 0x0400 reserved
  116. * 0x0200 REMAINING_CAPACITY_ALARM
  117. * 0x0100 REMAINING_TIME_ALARM
  118. *
  119. * -------------Status Bits--------------
  120. * 0x0080 INITIALIZED
  121. * 0x0040 DISCHARGING
  122. * 0x0020 FULLY_CHARGED
  123. * 0x0010 FULLY_DISCHARGED
  124. */
  125. #define SBI_BATTERY_STATUS 0x16
  126. #define SBI_BS_OVER_CHARGED_ALARM 0x8000
  127. #define SBI_BS_TERMINATE_CHARGE_ALARM 0x4000
  128. #define SBI_BS_OVER_TEMP_ALARM 0x1000
  129. #define SBI_BS_TERMINATE_DISCHARGE_ALARM 0x0800
  130. #define SBI_BS_REMAINING_CAPACITY_ALARM 0x0200
  131. #define SBI_BS_REMAINING_TIME_ALARM 0x0100
  132. #define SBI_BS_ALL_ALARM (0x8000 | 0x4000 | 0x1000 | 0x0800 | 0x0200 | 0x0100)
  133. #define SBI_BS_INITILIZED 0x0080
  134. #define SBI_BS_DISCHARGING 0x0040
  135. #define SBI_BS_FULLY_CHARGED 0x0020
  136. #define SBI_BS_FULLY_DISCHARGED 0x0010
  137. /**
  138. * ChargingCurrent (14h)
  139. * Description : Returns the Smart Battery's desired charging rate in milli-Amps(mA)
  140. * Purpose : The Charging Current function returns the maximum current that a Smart
  141. * Battery Charger may deliver to the Smart Battery. In combination with the
  142. * ChargingVoltage these functions permit a Smart Battery Charger to dynamically
  143. * adjust its charging profile(current/voltage) for optimal charge. The battery
  144. * can effectively trun off the Smart Battery Charger by returning a value of 0
  145. * for this function. Smart Battery Chargers may be operated as a constant
  146. * voltage source above their maximum regulated current by returning a
  147. * ChargingCurrent value of 65535.
  148. * Note : The Smart Battery Charger is expected to respond in one of three ways:
  149. * 1. Supply the current requested.
  150. * 2. Supply its maximum current if the request is greater than its maxmum and less
  151. * than 65535.
  152. * 3. Supply its maximum safe current if the request is 65535.
  153. * Protocol : Read Word
  154. * Output: unsigned int -- maximum charger output current in mA(0~65535)
  155. */
  156. #define SBI_CHARGING_CURRENT 0x14
  157. #define SBI_CC_CONSTATN_VOLTAGE_CHARGING 65535
  158. /**
  159. * ChargingVoltage(15h)
  160. * Description : Returns the SmartBattery's desired charging voltage in milli-Volts(mV)
  161. * This represents the maximum voltage which may be provided by the Smart Battery
  162. * Charger during charging.
  163. * SMBus protocol : Read Word
  164. * Output : unsigned int - charger output voltage in mV
  165. */
  166. #define SBI_CHARGING_VOLTAGE 0x15
  167. #define SBI_CV_CONSTANT_CURRENT_CHARGING 65535
  168. /**
  169. * DesignCapacity(18h).
  170. * Description : Returns the full capacity of a new battery pack or Fule Cell system
  171. * fule cartidge(s) in milli-Amp-hours(mAh).
  172. * SMBus Protocol : Read Word
  173. * Output : unsigned int - the battery or Fule Cell system fule cartridge capacity in mAh
  174. * Units: mAh
  175. *
  176. * BQ20Z70: The DesignCapacity value is expressed in either current(mAh) or power,
  177. * depending on the setting of [CAPACITY_MODE] bit.
  178. */
  179. #define SBI_DESIGN_CAPACITY 0x18
  180. /**
  181. * DesignVoltage(19h).
  182. * Description : Returns the design voltage of a new battery pack or Fule Cell system in
  183. * milli-Volts(mV).
  184. * SMBus Protocol : Read Word
  185. */
  186. #define SBI_DESIGN_VOLTAGE 0x19
  187. /**
  188. * ManufactureDate(1Bh).
  189. * Description : This function returns the date the cell pack was manufactured in a packed
  190. * integer. The date is packed in the following fashion: (Year-1980)*512 + Moth*32 +Day
  191. * SMBus Protocol : Read Word
  192. */
  193. #define SBI_MANUFACTURE_DATE 0x1B
  194. /**
  195. * SerialNumber(1Ch).
  196. * Description: This function is used to return a serial number. The number when combined
  197. * with the ManufactureName, the DeviceName, and the ManufactureDate will uniquely
  198. * indentify the battery.
  199. * SMBus Protocol : Read Word
  200. * Output : unsigned int (0~65535)
  201. */
  202. #define SBI_SERIAL_NUMBER 0x1C
  203. /**
  204. * ManufactureName(20h).
  205. * Desciption : This function returns a character array containing the battery or Fule
  206. * Cell manufacture's name. For example, "BestBatt" would identify the battery
  207. * or Fule Cell's manufacture as BestBatt.
  208. * SMBus Protocol : Read Block
  209. * Ouput : string - limited to 8 characters.
  210. */
  211. #define SBI_MANUFACTURE_NAME 0x20
  212. /**
  213. * DeviceName(21h)
  214. * Description : This function returns a character string that contains the batterh or
  215. * Fuel Cell's name. For example, a DeviceName of "SmartB" would indicate that the
  216. * battery is a modle SmartB.
  217. * SMBus Protocol : Read Block
  218. * Output : string -- limited to 8 characters.
  219. */
  220. #define SBI_DEVICE_NAME 0x21
  221. /**
  222. * Device Chemistry(22h)
  223. * Description : This function returns a character string that contains the battery or
  224. * Fule Cell's chemistry. For example, if the DeviceChemistry function returns
  225. * "LS02", the battery pack would comtain primary lithium cells.
  226. * SMBus protocol : Read Block
  227. * Ouput string - limited to 4 characters
  228. */
  229. #define SBI_DEVICE_CHEMISTRY 0x22
  230. /**
  231. * AverageVoltage(0x5d).
  232. * Description: Returns a signed integer value that appromixates a one-munite rolling
  233. * average of the sume of cell voltages in mV, with a range of 0~65535.
  234. * SMBus Protocol: Read Word
  235. */
  236. #define SBI_AVERAGE_VOLTAGE 0x5d
  237. /**
  238. * AverageCurrent(0x0b).
  239. * Description: This function returns a signed integer value approximates a one-minute
  240. * average of the current being suppied (or accepted) thorogh the battery
  241. * terminals in mA, with a range of -32768~32767.
  242. * SMBus protocol: Read Word.
  243. */
  244. #define SBI_AVERAGE_CURRENT 0x0b
  245. /**
  246. * RunTimeToEmpty(0x11)
  247. * Description: This function returns a unsigned integer value of oredicted remaining
  248. * battery life at the present rate of discharge, in minutes, with a range of
  249. * 0~65535min. A value of 65535 indicates battery is not being discharged.
  250. * SMBus protocol: Read Word.
  251. * Out: 16-bit unsigned short int.
  252. */
  253. #define SBI_RUN_TIME_TO_EMPTY 0x11
  254. /**
  255. * StateOfHealth(0x4f)
  256. * Description : This read word function returns the state of health of the battery in
  257. * %. The caculation formula depends on the CAPACITY_MODE flag.
  258. * CAPACITY_MO StateOfHeath
  259. * DE
  260. * 0 = FullChargeCapacity/Design Capacity
  261. * 1 = FullChargeCapacity/Design Energy
  262. * Return value : 16 bit unsigned integer, range : 0~100.
  263. */
  264. #define SBI_STATE_OF_HEALTH 0x4f
  265. /**
  266. * DataFlashSubClassID(0x77).
  267. * Description : This write word function set the bq27z20 dataflash subclass, where
  268. * data can be accessed by following DataFlashSubClass1..8 commands. A NAK is
  269. * returned to this command if the value of the class is outside of the allowed
  270. * range.
  271. * SMBus protocol: Write-word.
  272. */
  273. #define SBI_DATA_FLASH_SUBCLASS_ID 0x77
  274. /**
  275. * DataFlashSubClassPage1..8(0x78...0x7f)
  276. * Description: These comamnds are used to access the consecutive 32-byte pages of
  277. * of each subclass. DataFlashSubClassPage1 get byte 0 to 31 of the subclass,
  278. * DataFlashSubClassPage2 get bytes 32 to 63 and so on.
  279. */
  280. #define SBI_DATA_FLASH_SUBCLASS_PAGE1 0x78
  281. #define SBI_DATA_FLASH_SUBCLASS_PAGE2 0x79
  282. #define SBI_DATA_FLASH_SUBCLASS_PAGE3 0x7a
  283. #define SBI_DATA_FLASH_SUBCLASS_PAGE4 0x7b
  284. #define SBI_DATA_FLASH_SUBCLASS_PAGE5 0x7c
  285. #define SBI_DATA_FLASH_SUBCLASS_PAGE6 0x7d
  286. #define SBI_DATA_FLASH_SUBCLASS_PAGE7 0x7e
  287. #define SBI_DATA_FLASH_SUBCLASS_PAGE8 0x7f
  288. /*
  289. * Method declare
  290. */
  291. extern int Temperature(unsigned short *temperature);
  292. extern int Voltage(unsigned short *voltage);
  293. extern int Current(unsigned short *tmp_current);
  294. extern int RelativeStateOfCharge(unsigned short *rsoc);
  295. extern int RemainingCapacity(unsigned short *capacity);
  296. extern int FullChargeCapacity(unsigned short *capacity);
  297. extern int AverageTimeToEmpty(unsigned short *time);
  298. extern int BatteryStatus(unsigned short *status);
  299. extern int ChargingCurrent(unsigned short *tmp_current);
  300. extern int ChargingVoltage(unsigned short *voltage);
  301. extern int DesignCapacity(unsigned short *capacity);
  302. extern int DesignVoltage(unsigned short *voltage);
  303. extern int ManufactureDate(unsigned short *date);
  304. extern int SerialNumber(unsigned short *number);
  305. extern int ManufactureName(unsigned char *name);
  306. extern int DeviceName(unsigned char *name);
  307. extern int DeviceChemistry(unsigned char *chemistry);
  308. extern int AverageVoltage(unsigned short *voltage);
  309. extern int AverageCurrent(short *tmp_current);
  310. extern int RunTimeToEmpty(unsigned short *minute);
  311. extern int StateOfHealth(unsigned short *health);
  312. #endif