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