abx500.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. * @pcut_enable: Enable power cut feature in ab8505
  84. * @pcut_max_time: Max time threshold
  85. * @pcut_flag_time: Flagtime threshold
  86. * @pcut_max_restart: Max number of restarts
  87. * @pcut_debounce_time: Sets battery debounce time
  88. */
  89. struct abx500_fg_parameters {
  90. int recovery_sleep_timer;
  91. int recovery_total_time;
  92. int init_timer;
  93. int init_discard_time;
  94. int init_total_time;
  95. int high_curr_time;
  96. int accu_charging;
  97. int accu_high_curr;
  98. int high_curr_threshold;
  99. int lowbat_threshold;
  100. int overbat_threshold;
  101. int battok_falling_th_sel0;
  102. int battok_raising_th_sel1;
  103. int user_cap_limit;
  104. int maint_thres;
  105. bool pcut_enable;
  106. u8 pcut_max_time;
  107. u8 pcut_flag_time;
  108. u8 pcut_max_restart;
  109. u8 pcut_debounce_time;
  110. };
  111. /**
  112. * struct abx500_charger_maximization - struct used by the board config.
  113. * @use_maxi: Enable maximization for this battery type
  114. * @maxi_chg_curr: Maximum charger current allowed
  115. * @maxi_wait_cycles: cycles to wait before setting charger current
  116. * @charger_curr_step delta between two charger current settings (mA)
  117. */
  118. struct abx500_maxim_parameters {
  119. bool ena_maxi;
  120. int chg_curr;
  121. int wait_cycles;
  122. int charger_curr_step;
  123. };
  124. /**
  125. * struct abx500_battery_type - different batteries supported
  126. * @name: battery technology
  127. * @resis_high: battery upper resistance limit
  128. * @resis_low: battery lower resistance limit
  129. * @charge_full_design: Maximum battery capacity in mAh
  130. * @nominal_voltage: Nominal voltage of the battery in mV
  131. * @termination_vol: max voltage upto which battery can be charged
  132. * @termination_curr battery charging termination current in mA
  133. * @recharge_cap battery capacity limit that will trigger a new
  134. * full charging cycle in the case where maintenan-
  135. * -ce charging has been disabled
  136. * @normal_cur_lvl: charger current in normal state in mA
  137. * @normal_vol_lvl: charger voltage in normal state in mV
  138. * @maint_a_cur_lvl: charger current in maintenance A state in mA
  139. * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
  140. * @maint_a_chg_timer_h: charge time in maintenance A state
  141. * @maint_b_cur_lvl: charger current in maintenance B state in mA
  142. * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
  143. * @maint_b_chg_timer_h: charge time in maintenance B state
  144. * @low_high_cur_lvl: charger current in temp low/high state in mA
  145. * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
  146. * @battery_resistance: battery inner resistance in mOhm.
  147. * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
  148. * @r_to_t_tbl: table containing resistance to temp points
  149. * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
  150. * @v_to_cap_tbl: Voltage to capacity (in %) table
  151. * @n_batres_tbl_elements number of elements in the batres_tbl
  152. * @batres_tbl battery internal resistance vs temperature table
  153. */
  154. struct abx500_battery_type {
  155. int name;
  156. int resis_high;
  157. int resis_low;
  158. int charge_full_design;
  159. int nominal_voltage;
  160. int termination_vol;
  161. int termination_curr;
  162. int recharge_cap;
  163. int normal_cur_lvl;
  164. int normal_vol_lvl;
  165. int maint_a_cur_lvl;
  166. int maint_a_vol_lvl;
  167. int maint_a_chg_timer_h;
  168. int maint_b_cur_lvl;
  169. int maint_b_vol_lvl;
  170. int maint_b_chg_timer_h;
  171. int low_high_cur_lvl;
  172. int low_high_vol_lvl;
  173. int battery_resistance;
  174. int n_temp_tbl_elements;
  175. const struct abx500_res_to_temp *r_to_t_tbl;
  176. int n_v_cap_tbl_elements;
  177. const struct abx500_v_to_cap *v_to_cap_tbl;
  178. int n_batres_tbl_elements;
  179. const struct batres_vs_temp *batres_tbl;
  180. };
  181. /**
  182. * struct abx500_bm_capacity_levels - abx500 capacity level data
  183. * @critical: critical capacity level in percent
  184. * @low: low capacity level in percent
  185. * @normal: normal capacity level in percent
  186. * @high: high capacity level in percent
  187. * @full: full capacity level in percent
  188. */
  189. struct abx500_bm_capacity_levels {
  190. int critical;
  191. int low;
  192. int normal;
  193. int high;
  194. int full;
  195. };
  196. /**
  197. * struct abx500_bm_charger_parameters - Charger specific parameters
  198. * @usb_volt_max: maximum allowed USB charger voltage in mV
  199. * @usb_curr_max: maximum allowed USB charger current in mA
  200. * @ac_volt_max: maximum allowed AC charger voltage in mV
  201. * @ac_curr_max: maximum allowed AC charger current in mA
  202. */
  203. struct abx500_bm_charger_parameters {
  204. int usb_volt_max;
  205. int usb_curr_max;
  206. int ac_volt_max;
  207. int ac_curr_max;
  208. };
  209. /**
  210. * struct abx500_bm_data - abx500 battery management data
  211. * @temp_under under this temp, charging is stopped
  212. * @temp_low between this temp and temp_under charging is reduced
  213. * @temp_high between this temp and temp_over charging is reduced
  214. * @temp_over over this temp, charging is stopped
  215. * @temp_now present battery temperature
  216. * @temp_interval_chg temperature measurement interval in s when charging
  217. * @temp_interval_nochg temperature measurement interval in s when not charging
  218. * @main_safety_tmr_h safety timer for main charger
  219. * @usb_safety_tmr_h safety timer for usb charger
  220. * @bkup_bat_v voltage which we charge the backup battery with
  221. * @bkup_bat_i current which we charge the backup battery with
  222. * @no_maintenance indicates that maintenance charging is disabled
  223. * @capacity_scaling indicates whether capacity scaling is to be used
  224. * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
  225. * @chg_unknown_bat flag to enable charging of unknown batteries
  226. * @enable_overshoot flag to enable VBAT overshoot control
  227. * @auto_trig flag to enable auto adc trigger
  228. * @fg_res resistance of FG resistor in 0.1mOhm
  229. * @n_btypes number of elements in array bat_type
  230. * @batt_id index of the identified battery in array bat_type
  231. * @interval_charging charge alg cycle period time when charging (sec)
  232. * @interval_not_charging charge alg cycle period time when not charging (sec)
  233. * @temp_hysteresis temperature hysteresis
  234. * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
  235. * @n_chg_out_curr number of elements in array chg_output_curr
  236. * @n_chg_in_curr number of elements in array chg_input_curr
  237. * @chg_output_curr charger output current level map
  238. * @chg_input_curr charger input current level map
  239. * @maxi maximization parameters
  240. * @cap_levels capacity in percent for the different capacity levels
  241. * @bat_type table of supported battery types
  242. * @chg_params charger parameters
  243. * @fg_params fuel gauge parameters
  244. */
  245. struct abx500_bm_data {
  246. int temp_under;
  247. int temp_low;
  248. int temp_high;
  249. int temp_over;
  250. int temp_now;
  251. int temp_interval_chg;
  252. int temp_interval_nochg;
  253. int main_safety_tmr_h;
  254. int usb_safety_tmr_h;
  255. int bkup_bat_v;
  256. int bkup_bat_i;
  257. bool autopower_cfg;
  258. bool ac_enabled;
  259. bool usb_enabled;
  260. bool usb_power_path;
  261. bool no_maintenance;
  262. bool capacity_scaling;
  263. bool chg_unknown_bat;
  264. bool enable_overshoot;
  265. bool auto_trig;
  266. enum abx500_adc_therm adc_therm;
  267. int fg_res;
  268. int n_btypes;
  269. int batt_id;
  270. int interval_charging;
  271. int interval_not_charging;
  272. int temp_hysteresis;
  273. int gnd_lift_resistance;
  274. int n_chg_out_curr;
  275. int n_chg_in_curr;
  276. int *chg_output_curr;
  277. int *chg_input_curr;
  278. const struct abx500_maxim_parameters *maxi;
  279. const struct abx500_bm_capacity_levels *cap_levels;
  280. struct abx500_battery_type *bat_type;
  281. const struct abx500_bm_charger_parameters *chg_params;
  282. const struct abx500_fg_parameters *fg_params;
  283. };
  284. enum {
  285. NTC_EXTERNAL = 0,
  286. NTC_INTERNAL,
  287. };
  288. int ab8500_bm_of_probe(struct device *dev,
  289. struct device_node *np,
  290. struct abx500_bm_data *bm);
  291. int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
  292. u8 value);
  293. int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
  294. u8 *value);
  295. int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
  296. u8 first_reg, u8 *regvals, u8 numregs);
  297. int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
  298. u8 first_reg, u8 *regvals, u8 numregs);
  299. /**
  300. * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
  301. * target register
  302. *
  303. * @dev: The AB sub device.
  304. * @bank: The i2c bank number.
  305. * @bitmask: The bit mask to use.
  306. * @bitvalues: The new bit values.
  307. *
  308. * Updates the value of an AB register:
  309. * value -> ((value & ~bitmask) | (bitvalues & bitmask))
  310. */
  311. int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
  312. u8 reg, u8 bitmask, u8 bitvalues);
  313. int abx500_get_chip_id(struct device *dev);
  314. int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
  315. int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
  316. struct abx500_ops {
  317. int (*get_chip_id) (struct device *);
  318. int (*get_register) (struct device *, u8, u8, u8 *);
  319. int (*set_register) (struct device *, u8, u8, u8);
  320. int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
  321. int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
  322. int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
  323. int (*event_registers_startup_state_get) (struct device *, u8 *);
  324. int (*startup_irq_enabled) (struct device *, unsigned int);
  325. void (*dump_all_banks) (struct device *);
  326. };
  327. int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
  328. void abx500_remove_ops(struct device *dev);
  329. #endif