abx500.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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_vol battery voltage 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_vol;
  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. * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
  214. * @chg_unknown_bat flag to enable charging of unknown batteries
  215. * @enable_overshoot flag to enable VBAT overshoot control
  216. * @auto_trig flag to enable auto adc trigger
  217. * @fg_res resistance of FG resistor in 0.1mOhm
  218. * @n_btypes number of elements in array bat_type
  219. * @batt_id index of the identified battery in array bat_type
  220. * @interval_charging charge alg cycle period time when charging (sec)
  221. * @interval_not_charging charge alg cycle period time when not charging (sec)
  222. * @temp_hysteresis temperature hysteresis
  223. * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
  224. * @maxi: maximization parameters
  225. * @cap_levels capacity in percent for the different capacity levels
  226. * @bat_type table of supported battery types
  227. * @chg_params charger parameters
  228. * @fg_params fuel gauge parameters
  229. */
  230. struct abx500_bm_data {
  231. int temp_under;
  232. int temp_low;
  233. int temp_high;
  234. int temp_over;
  235. int temp_now;
  236. int temp_interval_chg;
  237. int temp_interval_nochg;
  238. int main_safety_tmr_h;
  239. int usb_safety_tmr_h;
  240. int bkup_bat_v;
  241. int bkup_bat_i;
  242. bool no_maintenance;
  243. bool chg_unknown_bat;
  244. bool enable_overshoot;
  245. bool auto_trig;
  246. enum abx500_adc_therm adc_therm;
  247. int fg_res;
  248. int n_btypes;
  249. int batt_id;
  250. int interval_charging;
  251. int interval_not_charging;
  252. int temp_hysteresis;
  253. int gnd_lift_resistance;
  254. const struct abx500_maxim_parameters *maxi;
  255. const struct abx500_bm_capacity_levels *cap_levels;
  256. const struct abx500_battery_type *bat_type;
  257. const struct abx500_bm_charger_parameters *chg_params;
  258. const struct abx500_fg_parameters *fg_params;
  259. };
  260. struct abx500_chargalg_platform_data {
  261. char **supplied_to;
  262. size_t num_supplicants;
  263. };
  264. struct abx500_charger_platform_data {
  265. char **supplied_to;
  266. size_t num_supplicants;
  267. bool autopower_cfg;
  268. };
  269. struct abx500_btemp_platform_data {
  270. char **supplied_to;
  271. size_t num_supplicants;
  272. };
  273. struct abx500_fg_platform_data {
  274. char **supplied_to;
  275. size_t num_supplicants;
  276. };
  277. struct abx500_bm_plat_data {
  278. struct abx500_bm_data *battery;
  279. struct abx500_charger_platform_data *charger;
  280. struct abx500_btemp_platform_data *btemp;
  281. struct abx500_fg_platform_data *fg;
  282. struct abx500_chargalg_platform_data *chargalg;
  283. };
  284. int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
  285. u8 value);
  286. int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
  287. u8 *value);
  288. int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
  289. u8 first_reg, u8 *regvals, u8 numregs);
  290. int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
  291. u8 first_reg, u8 *regvals, u8 numregs);
  292. /**
  293. * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
  294. * target register
  295. *
  296. * @dev: The AB sub device.
  297. * @bank: The i2c bank number.
  298. * @bitmask: The bit mask to use.
  299. * @bitvalues: The new bit values.
  300. *
  301. * Updates the value of an AB register:
  302. * value -> ((value & ~bitmask) | (bitvalues & bitmask))
  303. */
  304. int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
  305. u8 reg, u8 bitmask, u8 bitvalues);
  306. int abx500_get_chip_id(struct device *dev);
  307. int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
  308. int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
  309. struct abx500_ops {
  310. int (*get_chip_id) (struct device *);
  311. int (*get_register) (struct device *, u8, u8, u8 *);
  312. int (*set_register) (struct device *, u8, u8, u8);
  313. int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
  314. int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
  315. int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
  316. int (*event_registers_startup_state_get) (struct device *, u8 *);
  317. int (*startup_irq_enabled) (struct device *, unsigned int);
  318. };
  319. int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
  320. void abx500_remove_ops(struct device *dev);
  321. #endif