abx500.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (C) 2007-2009 ST-Ericsson AB
  3. * License terms: GNU General Public License (GPL) version 2
  4. *
  5. * ABX500 core access functions.
  6. * The abx500 interface is used for the Analog Baseband chips.
  7. *
  8. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  9. * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
  10. * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
  11. * Author: Rickard Andersson <rickard.andersson@stericsson.com>
  12. */
  13. #include <linux/regulator/machine.h>
  14. struct device;
  15. #ifndef MFD_ABX500_H
  16. #define MFD_ABX500_H
  17. /**
  18. * struct abx500_init_setting
  19. * Initial value of the registers for driver to use during setup.
  20. */
  21. struct abx500_init_settings {
  22. u8 bank;
  23. u8 reg;
  24. u8 setting;
  25. };
  26. /* Battery driver related data */
  27. /*
  28. * ADC for the battery thermistor.
  29. * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined
  30. * with a NTC resistor to both identify the battery and to measure its
  31. * temperature. Different phone manufactures uses different techniques to both
  32. * identify the battery and to read its temperature.
  33. */
  34. enum abx500_adc_therm {
  35. ABx500_ADC_THERM_BATCTRL,
  36. ABx500_ADC_THERM_BATTEMP,
  37. };
  38. /**
  39. * struct abx500_res_to_temp - defines one point in a temp to res curve. To
  40. * be used in battery packs that combines the identification resistor with a
  41. * NTC resistor.
  42. * @temp: battery pack temperature in Celcius
  43. * @resist: NTC resistor net total resistance
  44. */
  45. struct abx500_res_to_temp {
  46. int temp;
  47. int resist;
  48. };
  49. /**
  50. * struct abx500_v_to_cap - Table for translating voltage to capacity
  51. * @voltage: Voltage in mV
  52. * @capacity: Capacity in percent
  53. */
  54. struct abx500_v_to_cap {
  55. int voltage;
  56. int capacity;
  57. };
  58. /* Forward declaration */
  59. struct abx500_fg;
  60. /**
  61. * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
  62. * if not specified
  63. * @recovery_sleep_timer: Time between measurements while recovering
  64. * @recovery_total_time: Total recovery time
  65. * @init_timer: Measurement interval during startup
  66. * @init_discard_time: Time we discard voltage measurement at startup
  67. * @init_total_time: Total init time during startup
  68. * @high_curr_time: Time current has to be high to go to recovery
  69. * @accu_charging: FG accumulation time while charging
  70. * @accu_high_curr: FG accumulation time in high current mode
  71. * @high_curr_threshold: High current threshold, in mA
  72. * @lowbat_threshold: Low battery threshold, in mV
  73. * @overbat_threshold: Over battery threshold, in mV
  74. * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
  75. * Resolution in 50 mV step.
  76. * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
  77. * Resolution in 50 mV step.
  78. * @user_cap_limit Capacity reported from user must be within this
  79. * limit to be considered as sane, in percentage
  80. * points.
  81. * @maint_thres This is the threshold where we stop reporting
  82. * battery full while in maintenance, in per cent
  83. */
  84. struct abx500_fg_parameters {
  85. int recovery_sleep_timer;
  86. int recovery_total_time;
  87. int init_timer;
  88. int init_discard_time;
  89. int init_total_time;
  90. int high_curr_time;
  91. int accu_charging;
  92. int accu_high_curr;
  93. int high_curr_threshold;
  94. int lowbat_threshold;
  95. int overbat_threshold;
  96. int battok_falling_th_sel0;
  97. int battok_raising_th_sel1;
  98. int user_cap_limit;
  99. int maint_thres;
  100. };
  101. /**
  102. * struct abx500_charger_maximization - struct used by the board config.
  103. * @use_maxi: Enable maximization for this battery type
  104. * @maxi_chg_curr: Maximum charger current allowed
  105. * @maxi_wait_cycles: cycles to wait before setting charger current
  106. * @charger_curr_step delta between two charger current settings (mA)
  107. */
  108. struct abx500_maxim_parameters {
  109. bool ena_maxi;
  110. int chg_curr;
  111. int wait_cycles;
  112. int charger_curr_step;
  113. };
  114. /**
  115. * struct abx500_battery_type - different batteries supported
  116. * @name: battery technology
  117. * @resis_high: battery upper resistance limit
  118. * @resis_low: battery lower resistance limit
  119. * @charge_full_design: Maximum battery capacity in mAh
  120. * @nominal_voltage: Nominal voltage of the battery in mV
  121. * @termination_vol: max voltage upto which battery can be charged
  122. * @termination_curr battery charging termination current in mA
  123. * @recharge_cap battery capacity limit that will trigger a new
  124. * full charging cycle in the case where maintenan-
  125. * -ce charging has been disabled
  126. * @normal_cur_lvl: charger current in normal state in mA
  127. * @normal_vol_lvl: charger voltage in normal state in mV
  128. * @maint_a_cur_lvl: charger current in maintenance A state in mA
  129. * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
  130. * @maint_a_chg_timer_h: charge time in maintenance A state
  131. * @maint_b_cur_lvl: charger current in maintenance B state in mA
  132. * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
  133. * @maint_b_chg_timer_h: charge time in maintenance B state
  134. * @low_high_cur_lvl: charger current in temp low/high state in mA
  135. * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
  136. * @battery_resistance: battery inner resistance in mOhm.
  137. * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
  138. * @r_to_t_tbl: table containing resistance to temp points
  139. * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
  140. * @v_to_cap_tbl: Voltage to capacity (in %) table
  141. * @n_batres_tbl_elements number of elements in the batres_tbl
  142. * @batres_tbl battery internal resistance vs temperature table
  143. */
  144. struct abx500_battery_type {
  145. int name;
  146. int resis_high;
  147. int resis_low;
  148. int charge_full_design;
  149. int nominal_voltage;
  150. int termination_vol;
  151. int termination_curr;
  152. int recharge_cap;
  153. int normal_cur_lvl;
  154. int normal_vol_lvl;
  155. int maint_a_cur_lvl;
  156. int maint_a_vol_lvl;
  157. int maint_a_chg_timer_h;
  158. int maint_b_cur_lvl;
  159. int maint_b_vol_lvl;
  160. int maint_b_chg_timer_h;
  161. int low_high_cur_lvl;
  162. int low_high_vol_lvl;
  163. int battery_resistance;
  164. int n_temp_tbl_elements;
  165. struct abx500_res_to_temp *r_to_t_tbl;
  166. int n_v_cap_tbl_elements;
  167. struct abx500_v_to_cap *v_to_cap_tbl;
  168. int n_batres_tbl_elements;
  169. struct batres_vs_temp *batres_tbl;
  170. };
  171. /**
  172. * struct abx500_bm_capacity_levels - abx500 capacity level data
  173. * @critical: critical capacity level in percent
  174. * @low: low capacity level in percent
  175. * @normal: normal capacity level in percent
  176. * @high: high capacity level in percent
  177. * @full: full capacity level in percent
  178. */
  179. struct abx500_bm_capacity_levels {
  180. int critical;
  181. int low;
  182. int normal;
  183. int high;
  184. int full;
  185. };
  186. /**
  187. * struct abx500_bm_charger_parameters - Charger specific parameters
  188. * @usb_volt_max: maximum allowed USB charger voltage in mV
  189. * @usb_curr_max: maximum allowed USB charger current in mA
  190. * @ac_volt_max: maximum allowed AC charger voltage in mV
  191. * @ac_curr_max: maximum allowed AC charger current in mA
  192. */
  193. struct abx500_bm_charger_parameters {
  194. int usb_volt_max;
  195. int usb_curr_max;
  196. int ac_volt_max;
  197. int ac_curr_max;
  198. };
  199. /**
  200. * struct abx500_bm_data - abx500 battery management data
  201. * @temp_under under this temp, charging is stopped
  202. * @temp_low between this temp and temp_under charging is reduced
  203. * @temp_high between this temp and temp_over charging is reduced
  204. * @temp_over over this temp, charging is stopped
  205. * @temp_now present battery temperature
  206. * @temp_interval_chg temperature measurement interval in s when charging
  207. * @temp_interval_nochg temperature measurement interval in s when not charging
  208. * @main_safety_tmr_h safety timer for main charger
  209. * @usb_safety_tmr_h safety timer for usb charger
  210. * @bkup_bat_v voltage which we charge the backup battery with
  211. * @bkup_bat_i current which we charge the backup battery with
  212. * @no_maintenance indicates that maintenance charging is disabled
  213. * @capacity_scaling indicates whether capacity scaling is to be used
  214. * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
  215. * @chg_unknown_bat flag to enable charging of unknown batteries
  216. * @enable_overshoot flag to enable VBAT overshoot control
  217. * @auto_trig flag to enable auto adc trigger
  218. * @fg_res resistance of FG resistor in 0.1mOhm
  219. * @n_btypes number of elements in array bat_type
  220. * @batt_id index of the identified battery in array bat_type
  221. * @interval_charging charge alg cycle period time when charging (sec)
  222. * @interval_not_charging charge alg cycle period time when not charging (sec)
  223. * @temp_hysteresis temperature hysteresis
  224. * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
  225. * @maxi: maximization parameters
  226. * @cap_levels capacity in percent for the different capacity levels
  227. * @bat_type table of supported battery types
  228. * @chg_params charger parameters
  229. * @fg_params fuel gauge parameters
  230. */
  231. struct abx500_bm_data {
  232. int temp_under;
  233. int temp_low;
  234. int temp_high;
  235. int temp_over;
  236. int temp_now;
  237. int temp_interval_chg;
  238. int temp_interval_nochg;
  239. int main_safety_tmr_h;
  240. int usb_safety_tmr_h;
  241. int bkup_bat_v;
  242. int bkup_bat_i;
  243. bool autopower_cfg;
  244. bool ac_enabled;
  245. bool usb_enabled;
  246. bool no_maintenance;
  247. bool capacity_scaling;
  248. bool chg_unknown_bat;
  249. bool enable_overshoot;
  250. bool auto_trig;
  251. enum abx500_adc_therm adc_therm;
  252. int fg_res;
  253. int n_btypes;
  254. int batt_id;
  255. int interval_charging;
  256. int interval_not_charging;
  257. int temp_hysteresis;
  258. int gnd_lift_resistance;
  259. const struct abx500_maxim_parameters *maxi;
  260. const struct abx500_bm_capacity_levels *cap_levels;
  261. struct abx500_battery_type *bat_type;
  262. const struct abx500_bm_charger_parameters *chg_params;
  263. const struct abx500_fg_parameters *fg_params;
  264. };
  265. enum {
  266. NTC_EXTERNAL = 0,
  267. NTC_INTERNAL,
  268. };
  269. int ab8500_bm_of_probe(struct device *dev,
  270. struct device_node *np,
  271. struct abx500_bm_data *bm);
  272. int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
  273. u8 value);
  274. int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
  275. u8 *value);
  276. int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
  277. u8 first_reg, u8 *regvals, u8 numregs);
  278. int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
  279. u8 first_reg, u8 *regvals, u8 numregs);
  280. /**
  281. * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
  282. * target register
  283. *
  284. * @dev: The AB sub device.
  285. * @bank: The i2c bank number.
  286. * @bitmask: The bit mask to use.
  287. * @bitvalues: The new bit values.
  288. *
  289. * Updates the value of an AB register:
  290. * value -> ((value & ~bitmask) | (bitvalues & bitmask))
  291. */
  292. int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
  293. u8 reg, u8 bitmask, u8 bitvalues);
  294. int abx500_get_chip_id(struct device *dev);
  295. int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
  296. int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
  297. void abx500_dump_all_banks(void);
  298. struct abx500_ops {
  299. int (*get_chip_id) (struct device *);
  300. int (*get_register) (struct device *, u8, u8, u8 *);
  301. int (*set_register) (struct device *, u8, u8, u8);
  302. int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
  303. int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
  304. int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
  305. int (*event_registers_startup_state_get) (struct device *, u8 *);
  306. int (*startup_irq_enabled) (struct device *, unsigned int);
  307. void (*dump_all_banks) (struct device *);
  308. };
  309. int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
  310. void abx500_remove_ops(struct device *dev);
  311. #endif