abx500.h 15 KB

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