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