blob: 8344196b0004da66bf988e7811a14e778f83666e [file] [log] [blame]
Linus Walleij14fa5692009-05-21 23:17:06 +02001/*
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>
Mattias Wallinfa661252010-05-01 18:26:20 +02006 *
7 * ABX500 core access functions.
8 * The abx500 interface is used for the Analog Baseband chip
Linus Walleij8959e742011-09-26 11:45:30 +02009 * ab3100, ab5500, and ab8500.
Mattias Wallinfa661252010-05-01 18:26:20 +020010 *
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>
Linus Walleij14fa5692009-05-21 23:17:06 +020015 */
16
17#include <linux/device.h>
Linus Walleijd619bc12009-09-09 11:31:00 +020018#include <linux/regulator/machine.h>
Linus Walleij14fa5692009-05-21 23:17:06 +020019
Mattias Wallinfa661252010-05-01 18:26:20 +020020#ifndef MFD_ABX500_H
21#define MFD_ABX500_H
Linus Walleij14fa5692009-05-21 23:17:06 +020022
Mattias Wallinfa661252010-05-01 18:26:20 +020023#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
Mattias Wallinfa661252010-05-01 18:26:20 +020032#define AB5500_1_0 0x20
Mattias Wallin3d5e2ca2011-09-22 08:22:18 +020033#define AB5500_1_1 0x21
34#define AB5500_2_0 0x24
Linus Walleij14fa5692009-05-21 23:17:06 +020035
Linus Walleij863dde52011-05-08 00:54:45 +020036/* AB8500 CIDs*/
Linus Walleij863dde52011-05-08 00:54:45 +020037#define AB8500_CUT1P0 0x10
38#define AB8500_CUT1P1 0x11
39#define AB8500_CUT2P0 0x20
40#define AB8500_CUT3P0 0x30
Linus Walleijb958f7a2011-10-30 23:50:36 +010041#define AB8500_CUT3P3 0x33
Linus Walleij863dde52011-05-08 00:54:45 +020042
Linus Walleij14fa5692009-05-21 23:17:06 +020043/*
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.
47 */
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)
56
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)
65
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)
74
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)
84
Linus Walleijd619bc12009-09-09 11:31:00 +020085/*
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.
90 */
91#define AB3100_NUM_REGULATORS 10
92
Linus Walleij14fa5692009-05-21 23:17:06 +020093/**
94 * struct ab3100
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
Linus Walleij14fa5692009-05-21 23:17:06 +0200101 * @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
104 *
105 * This struct is PRIVATE and devices using it should NOT
106 * access ANY fields. It is used as a token for calling the
107 * AB3100 functions.
108 */
109struct ab3100 {
110 struct mutex access_mutex;
111 struct device *dev;
112 struct i2c_client *i2c_client;
113 struct i2c_client *testreg_client;
114 char chip_name[32];
115 u8 chip_id;
Linus Walleij14fa5692009-05-21 23:17:06 +0200116 struct blocking_notifier_head event_subscribers;
Mattias Wallinfa661252010-05-01 18:26:20 +0200117 u8 startup_events[3];
Linus Walleij14fa5692009-05-21 23:17:06 +0200118 bool startup_events_read;
119};
120
Linus Walleijd619bc12009-09-09 11:31:00 +0200121/**
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.
133 */
134struct 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;
138};
139
Linus Walleij14fa5692009-05-21 23:17:06 +0200140int ab3100_event_register(struct ab3100 *ab3100,
141 struct notifier_block *nb);
142int ab3100_event_unregister(struct ab3100 *ab3100,
143 struct notifier_block *nb);
Linus Walleij14fa5692009-05-21 23:17:06 +0200144
Mattias Wallinfa661252010-05-01 18:26:20 +0200145/**
146 * struct abx500_init_setting
147 * Initial value of the registers for driver to use during setup.
148 */
149struct abx500_init_settings {
150 u8 bank;
151 u8 reg;
152 u8 setting;
153};
154
Arun Murthy1668f81152012-02-29 21:54:25 +0530155/* Battery driver related data */
156/*
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.
162 */
163enum abx500_adc_therm {
164 ABx500_ADC_THERM_BATCTRL,
165 ABx500_ADC_THERM_BATTEMP,
166};
167
168/**
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
171 * NTC resistor.
172 * @temp: battery pack temperature in Celcius
173 * @resist: NTC resistor net total resistance
174 */
175struct abx500_res_to_temp {
176 int temp;
177 int resist;
178};
179
180/**
181 * struct abx500_v_to_cap - Table for translating voltage to capacity
182 * @voltage: Voltage in mV
183 * @capacity: Capacity in percent
184 */
185struct abx500_v_to_cap {
186 int voltage;
187 int capacity;
188};
189
190/* Forward declaration */
191struct abx500_fg;
192
193/**
194 * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
195 * if not specified
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
213 * points.
214 * @maint_thres This is the threshold where we stop reporting
215 * battery full while in maintenance, in per cent
216 */
217struct abx500_fg_parameters {
218 int recovery_sleep_timer;
219 int recovery_total_time;
220 int init_timer;
221 int init_discard_time;
222 int init_total_time;
223 int high_curr_time;
224 int accu_charging;
225 int accu_high_curr;
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;
231 int user_cap_limit;
232 int maint_thres;
233};
234
235/**
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)
241 */
242struct abx500_maxim_parameters {
243 bool ena_maxi;
244 int chg_curr;
245 int wait_cycles;
246 int charger_curr_step;
247};
248
249/**
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
278 */
279struct abx500_battery_type {
280 int name;
281 int resis_high;
282 int resis_low;
283 int charge_full_design;
284 int nominal_voltage;
285 int termination_vol;
286 int termination_curr;
287 int recharge_vol;
288 int normal_cur_lvl;
289 int normal_vol_lvl;
290 int maint_a_cur_lvl;
291 int maint_a_vol_lvl;
292 int maint_a_chg_timer_h;
293 int maint_b_cur_lvl;
294 int maint_b_vol_lvl;
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;
305};
306
307/**
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
314 */
315struct abx500_bm_capacity_levels {
316 int critical;
317 int low;
318 int normal;
319 int high;
320 int full;
321};
322
323/**
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
329 */
330struct abx500_bm_charger_parameters {
331 int usb_volt_max;
332 int usb_curr_max;
333 int ac_volt_max;
334 int ac_curr_max;
335};
336
337/**
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
367 */
368struct abx500_bm_data {
369 int temp_under;
370 int temp_low;
371 int temp_high;
372 int temp_over;
373 int temp_now;
374 int temp_interval_chg;
375 int temp_interval_nochg;
376 int main_safety_tmr_h;
377 int usb_safety_tmr_h;
378 int bkup_bat_v;
379 int bkup_bat_i;
380 bool no_maintenance;
381 bool chg_unknown_bat;
382 bool enable_overshoot;
383 bool auto_trig;
384 enum abx500_adc_therm adc_therm;
385 int fg_res;
386 int n_btypes;
387 int batt_id;
388 int interval_charging;
389 int interval_not_charging;
390 int temp_hysteresis;
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;
397};
398
399struct abx500_chargalg_platform_data {
400 char **supplied_to;
401 size_t num_supplicants;
402};
403
404struct abx500_charger_platform_data {
405 char **supplied_to;
406 size_t num_supplicants;
407 bool autopower_cfg;
408};
409
410struct abx500_btemp_platform_data {
411 char **supplied_to;
412 size_t num_supplicants;
413};
414
415struct abx500_fg_platform_data {
416 char **supplied_to;
417 size_t num_supplicants;
418};
419
420struct 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;
426};
427
Mattias Wallinfa661252010-05-01 18:26:20 +0200428int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
429 u8 value);
430int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
431 u8 *value);
432int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
433 u8 first_reg, u8 *regvals, u8 numregs);
434int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
435 u8 first_reg, u8 *regvals, u8 numregs);
436/**
437 * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
438 * target register
439 *
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.
444 *
445 * Updates the value of an AB register:
446 * value -> ((value & ~bitmask) | (bitvalues & bitmask))
447 */
448int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
449 u8 reg, u8 bitmask, u8 bitvalues);
450int abx500_get_chip_id(struct device *dev);
451int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
452int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
453
454struct abx500_ops {
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);
463};
464
465int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
Mark Brownc6252e92010-09-22 14:58:30 +0100466void abx500_remove_ops(struct device *dev);
Linus Walleij14fa5692009-05-21 23:17:06 +0200467#endif