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>
7 * ABX500 core access functions.
8 * The abx500 interface is used for the Analog Baseband chip
9 * ab3100, ab5500, and ab8500.
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>
17 #include <linux/device.h>
18 #include <linux/regulator/machine.h>
23 #define AB3100_P1A 0xc0
24 #define AB3100_P1B 0xc1
25 #define AB3100_P1C 0xc2
26 #define AB3100_P1D 0xc3
27 #define AB3100_P1E 0xc4
28 #define AB3100_P1F 0xc5
29 #define AB3100_P1G 0xc6
30 #define AB3100_R2A 0xc7
31 #define AB3100_R2B 0xc8
32 #define AB5500_1_0 0x20
33 #define AB5500_1_1 0x21
34 #define AB5500_2_0 0x24
37 #define AB8500_CUT1P0 0x10
38 #define AB8500_CUT1P1 0x11
39 #define AB8500_CUT2P0 0x20
40 #define AB8500_CUT3P0 0x30
41 #define AB8500_CUT3P3 0x33
44 * AB3100, EVENTA1, A2 and A3 event register flags
45 * these are catenated into a single 32-bit flag in the code
46 * for event notification broadcasts.
48 #define AB3100_EVENTA1_ONSWA (0x01<<16)
49 #define AB3100_EVENTA1_ONSWB (0x02<<16)
50 #define AB3100_EVENTA1_ONSWC (0x04<<16)
51 #define AB3100_EVENTA1_DCIO (0x08<<16)
52 #define AB3100_EVENTA1_OVER_TEMP (0x10<<16)
53 #define AB3100_EVENTA1_SIM_OFF (0x20<<16)
54 #define AB3100_EVENTA1_VBUS (0x40<<16)
55 #define AB3100_EVENTA1_VSET_USB (0x80<<16)
57 #define AB3100_EVENTA2_READY_TX (0x01<<8)
58 #define AB3100_EVENTA2_READY_RX (0x02<<8)
59 #define AB3100_EVENTA2_OVERRUN_ERROR (0x04<<8)
60 #define AB3100_EVENTA2_FRAMING_ERROR (0x08<<8)
61 #define AB3100_EVENTA2_CHARG_OVERCURRENT (0x10<<8)
62 #define AB3100_EVENTA2_MIDR (0x20<<8)
63 #define AB3100_EVENTA2_BATTERY_REM (0x40<<8)
64 #define AB3100_EVENTA2_ALARM (0x80<<8)
66 #define AB3100_EVENTA3_ADC_TRIG5 (0x01)
67 #define AB3100_EVENTA3_ADC_TRIG4 (0x02)
68 #define AB3100_EVENTA3_ADC_TRIG3 (0x04)
69 #define AB3100_EVENTA3_ADC_TRIG2 (0x08)
70 #define AB3100_EVENTA3_ADC_TRIGVBAT (0x10)
71 #define AB3100_EVENTA3_ADC_TRIGVTX (0x20)
72 #define AB3100_EVENTA3_ADC_TRIG1 (0x40)
73 #define AB3100_EVENTA3_ADC_TRIG0 (0x80)
75 /* AB3100, STR register flags */
76 #define AB3100_STR_ONSWA (0x01)
77 #define AB3100_STR_ONSWB (0x02)
78 #define AB3100_STR_ONSWC (0x04)
79 #define AB3100_STR_DCIO (0x08)
80 #define AB3100_STR_BOOT_MODE (0x10)
81 #define AB3100_STR_SIM_OFF (0x20)
82 #define AB3100_STR_BATT_REMOVAL (0x40)
83 #define AB3100_STR_VBUS (0x80)
86 * AB3100 contains 8 regulators, one external regulator controller
87 * and a buck converter, further the LDO E and buck converter can
88 * have separate settings if they are in sleep mode, this is
89 * modeled as a separate regulator.
91 #define AB3100_NUM_REGULATORS 10
95 * @access_mutex: lock out concurrent accesses to the AB3100 registers
96 * @dev: pointer to the containing device
97 * @i2c_client: I2C client for this chip
98 * @testreg_client: secondary client for test registers
99 * @chip_name: name of this chip variant
100 * @chip_id: 8 bit chip ID for this chip variant
101 * @event_subscribers: event subscribers are listed here
102 * @startup_events: a copy of the first reading of the event registers
103 * @startup_events_read: whether the first events have been read
105 * This struct is PRIVATE and devices using it should NOT
106 * access ANY fields. It is used as a token for calling the
110 struct mutex access_mutex;
112 struct i2c_client *i2c_client;
113 struct i2c_client *testreg_client;
116 struct blocking_notifier_head event_subscribers;
117 u8 startup_events[3];
118 bool startup_events_read;
122 * struct ab3100_platform_data
123 * Data supplied to initialize board connections to the AB3100
124 * @reg_constraints: regulator constraints for target board
125 * the order of these constraints are: LDO A, C, D, E,
126 * F, G, H, K, EXT and BUCK.
127 * @reg_initvals: initial values for the regulator registers
128 * plus two sleep settings for LDO E and the BUCK converter.
129 * exactly AB3100_NUM_REGULATORS+2 values must be sent in.
130 * Order: LDO A, C, E, E sleep, F, G, H, K, EXT, BUCK,
131 * BUCK sleep, LDO D. (LDO D need to be initialized last.)
132 * @external_voltage: voltage level of the external regulator.
134 struct ab3100_platform_data {
135 struct regulator_init_data reg_constraints[AB3100_NUM_REGULATORS];
136 u8 reg_initvals[AB3100_NUM_REGULATORS+2];
137 int external_voltage;
140 int ab3100_event_register(struct ab3100 *ab3100,
141 struct notifier_block *nb);
142 int ab3100_event_unregister(struct ab3100 *ab3100,
143 struct notifier_block *nb);
146 * struct abx500_init_setting
147 * Initial value of the registers for driver to use during setup.
149 struct abx500_init_settings {
155 /* Battery driver related data */
157 * ADC for the battery thermistor.
158 * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined
159 * with a NTC resistor to both identify the battery and to measure its
160 * temperature. Different phone manufactures uses different techniques to both
161 * identify the battery and to read its temperature.
163 enum abx500_adc_therm {
164 ABx500_ADC_THERM_BATCTRL,
165 ABx500_ADC_THERM_BATTEMP,
169 * struct abx500_res_to_temp - defines one point in a temp to res curve. To
170 * be used in battery packs that combines the identification resistor with a
172 * @temp: battery pack temperature in Celcius
173 * @resist: NTC resistor net total resistance
175 struct abx500_res_to_temp {
181 * struct abx500_v_to_cap - Table for translating voltage to capacity
182 * @voltage: Voltage in mV
183 * @capacity: Capacity in percent
185 struct abx500_v_to_cap {
190 /* Forward declaration */
194 * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
196 * @recovery_sleep_timer: Time between measurements while recovering
197 * @recovery_total_time: Total recovery time
198 * @init_timer: Measurement interval during startup
199 * @init_discard_time: Time we discard voltage measurement at startup
200 * @init_total_time: Total init time during startup
201 * @high_curr_time: Time current has to be high to go to recovery
202 * @accu_charging: FG accumulation time while charging
203 * @accu_high_curr: FG accumulation time in high current mode
204 * @high_curr_threshold: High current threshold, in mA
205 * @lowbat_threshold: Low battery threshold, in mV
206 * @overbat_threshold: Over battery threshold, in mV
207 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
208 * Resolution in 50 mV step.
209 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
210 * Resolution in 50 mV step.
211 * @user_cap_limit Capacity reported from user must be within this
212 * limit to be considered as sane, in percentage
214 * @maint_thres This is the threshold where we stop reporting
215 * battery full while in maintenance, in per cent
217 struct abx500_fg_parameters {
218 int recovery_sleep_timer;
219 int recovery_total_time;
221 int init_discard_time;
226 int high_curr_threshold;
227 int lowbat_threshold;
228 int overbat_threshold;
229 int battok_falling_th_sel0;
230 int battok_raising_th_sel1;
236 * struct abx500_charger_maximization - struct used by the board config.
237 * @use_maxi: Enable maximization for this battery type
238 * @maxi_chg_curr: Maximum charger current allowed
239 * @maxi_wait_cycles: cycles to wait before setting charger current
240 * @charger_curr_step delta between two charger current settings (mA)
242 struct abx500_maxim_parameters {
246 int charger_curr_step;
250 * struct abx500_battery_type - different batteries supported
251 * @name: battery technology
252 * @resis_high: battery upper resistance limit
253 * @resis_low: battery lower resistance limit
254 * @charge_full_design: Maximum battery capacity in mAh
255 * @nominal_voltage: Nominal voltage of the battery in mV
256 * @termination_vol: max voltage upto which battery can be charged
257 * @termination_curr battery charging termination current in mA
258 * @recharge_vol battery voltage limit that will trigger a new
259 * full charging cycle in the case where maintenan-
260 * -ce charging has been disabled
261 * @normal_cur_lvl: charger current in normal state in mA
262 * @normal_vol_lvl: charger voltage in normal state in mV
263 * @maint_a_cur_lvl: charger current in maintenance A state in mA
264 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
265 * @maint_a_chg_timer_h: charge time in maintenance A state
266 * @maint_b_cur_lvl: charger current in maintenance B state in mA
267 * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
268 * @maint_b_chg_timer_h: charge time in maintenance B state
269 * @low_high_cur_lvl: charger current in temp low/high state in mA
270 * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
271 * @battery_resistance: battery inner resistance in mOhm.
272 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
273 * @r_to_t_tbl: table containing resistance to temp points
274 * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
275 * @v_to_cap_tbl: Voltage to capacity (in %) table
276 * @n_batres_tbl_elements number of elements in the batres_tbl
277 * @batres_tbl battery internal resistance vs temperature table
279 struct abx500_battery_type {
283 int charge_full_design;
286 int termination_curr;
292 int maint_a_chg_timer_h;
295 int maint_b_chg_timer_h;
296 int low_high_cur_lvl;
297 int low_high_vol_lvl;
298 int battery_resistance;
299 int n_temp_tbl_elements;
300 struct abx500_res_to_temp *r_to_t_tbl;
301 int n_v_cap_tbl_elements;
302 struct abx500_v_to_cap *v_to_cap_tbl;
303 int n_batres_tbl_elements;
304 struct batres_vs_temp *batres_tbl;
308 * struct abx500_bm_capacity_levels - abx500 capacity level data
309 * @critical: critical capacity level in percent
310 * @low: low capacity level in percent
311 * @normal: normal capacity level in percent
312 * @high: high capacity level in percent
313 * @full: full capacity level in percent
315 struct abx500_bm_capacity_levels {
324 * struct abx500_bm_charger_parameters - Charger specific parameters
325 * @usb_volt_max: maximum allowed USB charger voltage in mV
326 * @usb_curr_max: maximum allowed USB charger current in mA
327 * @ac_volt_max: maximum allowed AC charger voltage in mV
328 * @ac_curr_max: maximum allowed AC charger current in mA
330 struct abx500_bm_charger_parameters {
338 * struct abx500_bm_data - abx500 battery management data
339 * @temp_under under this temp, charging is stopped
340 * @temp_low between this temp and temp_under charging is reduced
341 * @temp_high between this temp and temp_over charging is reduced
342 * @temp_over over this temp, charging is stopped
343 * @temp_now present battery temperature
344 * @temp_interval_chg temperature measurement interval in s when charging
345 * @temp_interval_nochg temperature measurement interval in s when not charging
346 * @main_safety_tmr_h safety timer for main charger
347 * @usb_safety_tmr_h safety timer for usb charger
348 * @bkup_bat_v voltage which we charge the backup battery with
349 * @bkup_bat_i current which we charge the backup battery with
350 * @no_maintenance indicates that maintenance charging is disabled
351 * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
352 * @chg_unknown_bat flag to enable charging of unknown batteries
353 * @enable_overshoot flag to enable VBAT overshoot control
354 * @auto_trig flag to enable auto adc trigger
355 * @fg_res resistance of FG resistor in 0.1mOhm
356 * @n_btypes number of elements in array bat_type
357 * @batt_id index of the identified battery in array bat_type
358 * @interval_charging charge alg cycle period time when charging (sec)
359 * @interval_not_charging charge alg cycle period time when not charging (sec)
360 * @temp_hysteresis temperature hysteresis
361 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
362 * @maxi: maximization parameters
363 * @cap_levels capacity in percent for the different capacity levels
364 * @bat_type table of supported battery types
365 * @chg_params charger parameters
366 * @fg_params fuel gauge parameters
368 struct abx500_bm_data {
374 int temp_interval_chg;
375 int temp_interval_nochg;
376 int main_safety_tmr_h;
377 int usb_safety_tmr_h;
381 bool chg_unknown_bat;
382 bool enable_overshoot;
384 enum abx500_adc_therm adc_therm;
388 int interval_charging;
389 int interval_not_charging;
391 int gnd_lift_resistance;
392 const struct abx500_maxim_parameters *maxi;
393 const struct abx500_bm_capacity_levels *cap_levels;
394 const struct abx500_battery_type *bat_type;
395 const struct abx500_bm_charger_parameters *chg_params;
396 const struct abx500_fg_parameters *fg_params;
399 struct abx500_chargalg_platform_data {
401 size_t num_supplicants;
404 struct abx500_charger_platform_data {
406 size_t num_supplicants;
410 struct abx500_btemp_platform_data {
412 size_t num_supplicants;
415 struct abx500_fg_platform_data {
417 size_t num_supplicants;
420 struct abx500_bm_plat_data {
421 struct abx500_bm_data *battery;
422 struct abx500_charger_platform_data *charger;
423 struct abx500_btemp_platform_data *btemp;
424 struct abx500_fg_platform_data *fg;
425 struct abx500_chargalg_platform_data *chargalg;
428 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
430 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
432 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
433 u8 first_reg, u8 *regvals, u8 numregs);
434 int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
435 u8 first_reg, u8 *regvals, u8 numregs);
437 * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
440 * @dev: The AB sub device.
441 * @bank: The i2c bank number.
442 * @bitmask: The bit mask to use.
443 * @bitvalues: The new bit values.
445 * Updates the value of an AB register:
446 * value -> ((value & ~bitmask) | (bitvalues & bitmask))
448 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
449 u8 reg, u8 bitmask, u8 bitvalues);
450 int abx500_get_chip_id(struct device *dev);
451 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
452 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
455 int (*get_chip_id) (struct device *);
456 int (*get_register) (struct device *, u8, u8, u8 *);
457 int (*set_register) (struct device *, u8, u8, u8);
458 int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
459 int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
460 int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
461 int (*event_registers_startup_state_get) (struct device *, u8 *);
462 int (*startup_irq_enabled) (struct device *, unsigned int);
465 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
466 void abx500_remove_ops(struct device *dev);