abx500.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * Copyright (C) 2007-2009 ST-Ericsson AB
  3. * License terms: GNU General Public License (GPL) version 2
  4. * AB3100 core access functions
  5. * Author: Linus Walleij <linus.walleij@stericsson.com>
  6. *
  7. * ABX500 core access functions.
  8. * The abx500 interface is used for the Analog Baseband chip
  9. * ab3100, ab5500, and ab8500.
  10. *
  11. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  12. * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
  13. * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
  14. * Author: Rickard Andersson <rickard.andersson@stericsson.com>
  15. */
  16. #include <linux/regulator/machine.h>
  17. struct device;
  18. #ifndef MFD_ABX500_H
  19. #define MFD_ABX500_H
  20. #define AB3100_P1A 0xc0
  21. #define AB3100_P1B 0xc1
  22. #define AB3100_P1C 0xc2
  23. #define AB3100_P1D 0xc3
  24. #define AB3100_P1E 0xc4
  25. #define AB3100_P1F 0xc5
  26. #define AB3100_P1G 0xc6
  27. #define AB3100_R2A 0xc7
  28. #define AB3100_R2B 0xc8
  29. #define AB5500_1_0 0x20
  30. #define AB5500_1_1 0x21
  31. #define AB5500_2_0 0x24
  32. /*
  33. * AB3100, EVENTA1, A2 and A3 event register flags
  34. * these are catenated into a single 32-bit flag in the code
  35. * for event notification broadcasts.
  36. */
  37. #define AB3100_EVENTA1_ONSWA (0x01<<16)
  38. #define AB3100_EVENTA1_ONSWB (0x02<<16)
  39. #define AB3100_EVENTA1_ONSWC (0x04<<16)
  40. #define AB3100_EVENTA1_DCIO (0x08<<16)
  41. #define AB3100_EVENTA1_OVER_TEMP (0x10<<16)
  42. #define AB3100_EVENTA1_SIM_OFF (0x20<<16)
  43. #define AB3100_EVENTA1_VBUS (0x40<<16)
  44. #define AB3100_EVENTA1_VSET_USB (0x80<<16)
  45. #define AB3100_EVENTA2_READY_TX (0x01<<8)
  46. #define AB3100_EVENTA2_READY_RX (0x02<<8)
  47. #define AB3100_EVENTA2_OVERRUN_ERROR (0x04<<8)
  48. #define AB3100_EVENTA2_FRAMING_ERROR (0x08<<8)
  49. #define AB3100_EVENTA2_CHARG_OVERCURRENT (0x10<<8)
  50. #define AB3100_EVENTA2_MIDR (0x20<<8)
  51. #define AB3100_EVENTA2_BATTERY_REM (0x40<<8)
  52. #define AB3100_EVENTA2_ALARM (0x80<<8)
  53. #define AB3100_EVENTA3_ADC_TRIG5 (0x01)
  54. #define AB3100_EVENTA3_ADC_TRIG4 (0x02)
  55. #define AB3100_EVENTA3_ADC_TRIG3 (0x04)
  56. #define AB3100_EVENTA3_ADC_TRIG2 (0x08)
  57. #define AB3100_EVENTA3_ADC_TRIGVBAT (0x10)
  58. #define AB3100_EVENTA3_ADC_TRIGVTX (0x20)
  59. #define AB3100_EVENTA3_ADC_TRIG1 (0x40)
  60. #define AB3100_EVENTA3_ADC_TRIG0 (0x80)
  61. /* AB3100, STR register flags */
  62. #define AB3100_STR_ONSWA (0x01)
  63. #define AB3100_STR_ONSWB (0x02)
  64. #define AB3100_STR_ONSWC (0x04)
  65. #define AB3100_STR_DCIO (0x08)
  66. #define AB3100_STR_BOOT_MODE (0x10)
  67. #define AB3100_STR_SIM_OFF (0x20)
  68. #define AB3100_STR_BATT_REMOVAL (0x40)
  69. #define AB3100_STR_VBUS (0x80)
  70. /*
  71. * AB3100 contains 8 regulators, one external regulator controller
  72. * and a buck converter, further the LDO E and buck converter can
  73. * have separate settings if they are in sleep mode, this is
  74. * modeled as a separate regulator.
  75. */
  76. #define AB3100_NUM_REGULATORS 10
  77. /**
  78. * struct ab3100
  79. * @access_mutex: lock out concurrent accesses to the AB3100 registers
  80. * @dev: pointer to the containing device
  81. * @i2c_client: I2C client for this chip
  82. * @testreg_client: secondary client for test registers
  83. * @chip_name: name of this chip variant
  84. * @chip_id: 8 bit chip ID for this chip variant
  85. * @event_subscribers: event subscribers are listed here
  86. * @startup_events: a copy of the first reading of the event registers
  87. * @startup_events_read: whether the first events have been read
  88. *
  89. * This struct is PRIVATE and devices using it should NOT
  90. * access ANY fields. It is used as a token for calling the
  91. * AB3100 functions.
  92. */
  93. struct ab3100 {
  94. struct mutex access_mutex;
  95. struct device *dev;
  96. struct i2c_client *i2c_client;
  97. struct i2c_client *testreg_client;
  98. char chip_name[32];
  99. u8 chip_id;
  100. struct blocking_notifier_head event_subscribers;
  101. u8 startup_events[3];
  102. bool startup_events_read;
  103. };
  104. /**
  105. * struct ab3100_platform_data
  106. * Data supplied to initialize board connections to the AB3100
  107. * @reg_constraints: regulator constraints for target board
  108. * the order of these constraints are: LDO A, C, D, E,
  109. * F, G, H, K, EXT and BUCK.
  110. * @reg_initvals: initial values for the regulator registers
  111. * plus two sleep settings for LDO E and the BUCK converter.
  112. * exactly AB3100_NUM_REGULATORS+2 values must be sent in.
  113. * Order: LDO A, C, E, E sleep, F, G, H, K, EXT, BUCK,
  114. * BUCK sleep, LDO D. (LDO D need to be initialized last.)
  115. * @external_voltage: voltage level of the external regulator.
  116. */
  117. struct ab3100_platform_data {
  118. struct regulator_init_data reg_constraints[AB3100_NUM_REGULATORS];
  119. u8 reg_initvals[AB3100_NUM_REGULATORS+2];
  120. int external_voltage;
  121. };
  122. int ab3100_event_register(struct ab3100 *ab3100,
  123. struct notifier_block *nb);
  124. int ab3100_event_unregister(struct ab3100 *ab3100,
  125. struct notifier_block *nb);
  126. /**
  127. * struct abx500_init_setting
  128. * Initial value of the registers for driver to use during setup.
  129. */
  130. struct abx500_init_settings {
  131. u8 bank;
  132. u8 reg;
  133. u8 setting;
  134. };
  135. /* Battery driver related data */
  136. /*
  137. * ADC for the battery thermistor.
  138. * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined
  139. * with a NTC resistor to both identify the battery and to measure its
  140. * temperature. Different phone manufactures uses different techniques to both
  141. * identify the battery and to read its temperature.
  142. */
  143. enum abx500_adc_therm {
  144. ABx500_ADC_THERM_BATCTRL,
  145. ABx500_ADC_THERM_BATTEMP,
  146. };
  147. /**
  148. * struct abx500_res_to_temp - defines one point in a temp to res curve. To
  149. * be used in battery packs that combines the identification resistor with a
  150. * NTC resistor.
  151. * @temp: battery pack temperature in Celcius
  152. * @resist: NTC resistor net total resistance
  153. */
  154. struct abx500_res_to_temp {
  155. int temp;
  156. int resist;
  157. };
  158. /**
  159. * struct abx500_v_to_cap - Table for translating voltage to capacity
  160. * @voltage: Voltage in mV
  161. * @capacity: Capacity in percent
  162. */
  163. struct abx500_v_to_cap {
  164. int voltage;
  165. int capacity;
  166. };
  167. /* Forward declaration */
  168. struct abx500_fg;
  169. /**
  170. * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
  171. * if not specified
  172. * @recovery_sleep_timer: Time between measurements while recovering
  173. * @recovery_total_time: Total recovery time
  174. * @init_timer: Measurement interval during startup
  175. * @init_discard_time: Time we discard voltage measurement at startup
  176. * @init_total_time: Total init time during startup
  177. * @high_curr_time: Time current has to be high to go to recovery
  178. * @accu_charging: FG accumulation time while charging
  179. * @accu_high_curr: FG accumulation time in high current mode
  180. * @high_curr_threshold: High current threshold, in mA
  181. * @lowbat_threshold: Low battery threshold, in mV
  182. * @overbat_threshold: Over battery threshold, in mV
  183. * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
  184. * Resolution in 50 mV step.
  185. * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
  186. * Resolution in 50 mV step.
  187. * @user_cap_limit Capacity reported from user must be within this
  188. * limit to be considered as sane, in percentage
  189. * points.
  190. * @maint_thres This is the threshold where we stop reporting
  191. * battery full while in maintenance, in per cent
  192. */
  193. struct abx500_fg_parameters {
  194. int recovery_sleep_timer;
  195. int recovery_total_time;
  196. int init_timer;
  197. int init_discard_time;
  198. int init_total_time;
  199. int high_curr_time;
  200. int accu_charging;
  201. int accu_high_curr;
  202. int high_curr_threshold;
  203. int lowbat_threshold;
  204. int overbat_threshold;
  205. int battok_falling_th_sel0;
  206. int battok_raising_th_sel1;
  207. int user_cap_limit;
  208. int maint_thres;
  209. };
  210. /**
  211. * struct abx500_charger_maximization - struct used by the board config.
  212. * @use_maxi: Enable maximization for this battery type
  213. * @maxi_chg_curr: Maximum charger current allowed
  214. * @maxi_wait_cycles: cycles to wait before setting charger current
  215. * @charger_curr_step delta between two charger current settings (mA)
  216. */
  217. struct abx500_maxim_parameters {
  218. bool ena_maxi;
  219. int chg_curr;
  220. int wait_cycles;
  221. int charger_curr_step;
  222. };
  223. /**
  224. * struct abx500_battery_type - different batteries supported
  225. * @name: battery technology
  226. * @resis_high: battery upper resistance limit
  227. * @resis_low: battery lower resistance limit
  228. * @charge_full_design: Maximum battery capacity in mAh
  229. * @nominal_voltage: Nominal voltage of the battery in mV
  230. * @termination_vol: max voltage upto which battery can be charged
  231. * @termination_curr battery charging termination current in mA
  232. * @recharge_vol battery voltage limit that will trigger a new
  233. * full charging cycle in the case where maintenan-
  234. * -ce charging has been disabled
  235. * @normal_cur_lvl: charger current in normal state in mA
  236. * @normal_vol_lvl: charger voltage in normal state in mV
  237. * @maint_a_cur_lvl: charger current in maintenance A state in mA
  238. * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
  239. * @maint_a_chg_timer_h: charge time in maintenance A state
  240. * @maint_b_cur_lvl: charger current in maintenance B state in mA
  241. * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
  242. * @maint_b_chg_timer_h: charge time in maintenance B state
  243. * @low_high_cur_lvl: charger current in temp low/high state in mA
  244. * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
  245. * @battery_resistance: battery inner resistance in mOhm.
  246. * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
  247. * @r_to_t_tbl: table containing resistance to temp points
  248. * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
  249. * @v_to_cap_tbl: Voltage to capacity (in %) table
  250. * @n_batres_tbl_elements number of elements in the batres_tbl
  251. * @batres_tbl battery internal resistance vs temperature table
  252. */
  253. struct abx500_battery_type {
  254. int name;
  255. int resis_high;
  256. int resis_low;
  257. int charge_full_design;
  258. int nominal_voltage;
  259. int termination_vol;
  260. int termination_curr;
  261. int recharge_vol;
  262. int normal_cur_lvl;
  263. int normal_vol_lvl;
  264. int maint_a_cur_lvl;
  265. int maint_a_vol_lvl;
  266. int maint_a_chg_timer_h;
  267. int maint_b_cur_lvl;
  268. int maint_b_vol_lvl;
  269. int maint_b_chg_timer_h;
  270. int low_high_cur_lvl;
  271. int low_high_vol_lvl;
  272. int battery_resistance;
  273. int n_temp_tbl_elements;
  274. struct abx500_res_to_temp *r_to_t_tbl;
  275. int n_v_cap_tbl_elements;
  276. struct abx500_v_to_cap *v_to_cap_tbl;
  277. int n_batres_tbl_elements;
  278. struct batres_vs_temp *batres_tbl;
  279. };
  280. /**
  281. * struct abx500_bm_capacity_levels - abx500 capacity level data
  282. * @critical: critical capacity level in percent
  283. * @low: low capacity level in percent
  284. * @normal: normal capacity level in percent
  285. * @high: high capacity level in percent
  286. * @full: full capacity level in percent
  287. */
  288. struct abx500_bm_capacity_levels {
  289. int critical;
  290. int low;
  291. int normal;
  292. int high;
  293. int full;
  294. };
  295. /**
  296. * struct abx500_bm_charger_parameters - Charger specific parameters
  297. * @usb_volt_max: maximum allowed USB charger voltage in mV
  298. * @usb_curr_max: maximum allowed USB charger current in mA
  299. * @ac_volt_max: maximum allowed AC charger voltage in mV
  300. * @ac_curr_max: maximum allowed AC charger current in mA
  301. */
  302. struct abx500_bm_charger_parameters {
  303. int usb_volt_max;
  304. int usb_curr_max;
  305. int ac_volt_max;
  306. int ac_curr_max;
  307. };
  308. /**
  309. * struct abx500_bm_data - abx500 battery management data
  310. * @temp_under under this temp, charging is stopped
  311. * @temp_low between this temp and temp_under charging is reduced
  312. * @temp_high between this temp and temp_over charging is reduced
  313. * @temp_over over this temp, charging is stopped
  314. * @temp_now present battery temperature
  315. * @temp_interval_chg temperature measurement interval in s when charging
  316. * @temp_interval_nochg temperature measurement interval in s when not charging
  317. * @main_safety_tmr_h safety timer for main charger
  318. * @usb_safety_tmr_h safety timer for usb charger
  319. * @bkup_bat_v voltage which we charge the backup battery with
  320. * @bkup_bat_i current which we charge the backup battery with
  321. * @no_maintenance indicates that maintenance charging is disabled
  322. * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
  323. * @chg_unknown_bat flag to enable charging of unknown batteries
  324. * @enable_overshoot flag to enable VBAT overshoot control
  325. * @auto_trig flag to enable auto adc trigger
  326. * @fg_res resistance of FG resistor in 0.1mOhm
  327. * @n_btypes number of elements in array bat_type
  328. * @batt_id index of the identified battery in array bat_type
  329. * @interval_charging charge alg cycle period time when charging (sec)
  330. * @interval_not_charging charge alg cycle period time when not charging (sec)
  331. * @temp_hysteresis temperature hysteresis
  332. * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
  333. * @maxi: maximization parameters
  334. * @cap_levels capacity in percent for the different capacity levels
  335. * @bat_type table of supported battery types
  336. * @chg_params charger parameters
  337. * @fg_params fuel gauge parameters
  338. */
  339. struct abx500_bm_data {
  340. int temp_under;
  341. int temp_low;
  342. int temp_high;
  343. int temp_over;
  344. int temp_now;
  345. int temp_interval_chg;
  346. int temp_interval_nochg;
  347. int main_safety_tmr_h;
  348. int usb_safety_tmr_h;
  349. int bkup_bat_v;
  350. int bkup_bat_i;
  351. bool no_maintenance;
  352. bool chg_unknown_bat;
  353. bool enable_overshoot;
  354. bool auto_trig;
  355. enum abx500_adc_therm adc_therm;
  356. int fg_res;
  357. int n_btypes;
  358. int batt_id;
  359. int interval_charging;
  360. int interval_not_charging;
  361. int temp_hysteresis;
  362. int gnd_lift_resistance;
  363. const struct abx500_maxim_parameters *maxi;
  364. const struct abx500_bm_capacity_levels *cap_levels;
  365. const struct abx500_battery_type *bat_type;
  366. const struct abx500_bm_charger_parameters *chg_params;
  367. const struct abx500_fg_parameters *fg_params;
  368. };
  369. struct abx500_chargalg_platform_data {
  370. char **supplied_to;
  371. size_t num_supplicants;
  372. };
  373. struct abx500_charger_platform_data {
  374. char **supplied_to;
  375. size_t num_supplicants;
  376. bool autopower_cfg;
  377. };
  378. struct abx500_btemp_platform_data {
  379. char **supplied_to;
  380. size_t num_supplicants;
  381. };
  382. struct abx500_fg_platform_data {
  383. char **supplied_to;
  384. size_t num_supplicants;
  385. };
  386. struct abx500_bm_plat_data {
  387. struct abx500_bm_data *battery;
  388. struct abx500_charger_platform_data *charger;
  389. struct abx500_btemp_platform_data *btemp;
  390. struct abx500_fg_platform_data *fg;
  391. struct abx500_chargalg_platform_data *chargalg;
  392. };
  393. int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
  394. u8 value);
  395. int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
  396. u8 *value);
  397. int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
  398. u8 first_reg, u8 *regvals, u8 numregs);
  399. int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
  400. u8 first_reg, u8 *regvals, u8 numregs);
  401. /**
  402. * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
  403. * target register
  404. *
  405. * @dev: The AB sub device.
  406. * @bank: The i2c bank number.
  407. * @bitmask: The bit mask to use.
  408. * @bitvalues: The new bit values.
  409. *
  410. * Updates the value of an AB register:
  411. * value -> ((value & ~bitmask) | (bitvalues & bitmask))
  412. */
  413. int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
  414. u8 reg, u8 bitmask, u8 bitvalues);
  415. int abx500_get_chip_id(struct device *dev);
  416. int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
  417. int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
  418. struct abx500_ops {
  419. int (*get_chip_id) (struct device *);
  420. int (*get_register) (struct device *, u8, u8, u8 *);
  421. int (*set_register) (struct device *, u8, u8, u8);
  422. int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
  423. int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
  424. int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
  425. int (*event_registers_startup_state_get) (struct device *, u8 *);
  426. int (*startup_irq_enabled) (struct device *, unsigned int);
  427. };
  428. int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
  429. void abx500_remove_ops(struct device *dev);
  430. #endif