blob: 3301b2031c8d03b5900bf9364901a76763585bb7 [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
Mattias Wallinfa661252010-05-01 18:26:20 +02004 *
5 * ABX500 core access functions.
Marcus Cooper0fd00132012-08-10 10:32:35 +02006 * The abx500 interface is used for the Analog Baseband chips.
Mattias Wallinfa661252010-05-01 18:26:20 +02007 *
8 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
9 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
10 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
11 * Author: Rickard Andersson <rickard.andersson@stericsson.com>
Linus Walleij14fa5692009-05-21 23:17:06 +020012 */
13
Linus Walleijd619bc12009-09-09 11:31:00 +020014#include <linux/regulator/machine.h>
Linus Walleij14fa5692009-05-21 23:17:06 +020015
Paul Gortmaker313162d2012-01-30 11:46:54 -050016struct device;
17
Mattias Wallinfa661252010-05-01 18:26:20 +020018#ifndef MFD_ABX500_H
19#define MFD_ABX500_H
Linus Walleij14fa5692009-05-21 23:17:06 +020020
Mattias Wallinfa661252010-05-01 18:26:20 +020021/**
22 * struct abx500_init_setting
23 * Initial value of the registers for driver to use during setup.
24 */
25struct abx500_init_settings {
26 u8 bank;
27 u8 reg;
28 u8 setting;
29};
30
Arun Murthy1668f812012-02-29 21:54:25 +053031/* Battery driver related data */
32/*
33 * ADC for the battery thermistor.
34 * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined
35 * with a NTC resistor to both identify the battery and to measure its
36 * temperature. Different phone manufactures uses different techniques to both
37 * identify the battery and to read its temperature.
38 */
39enum abx500_adc_therm {
40 ABx500_ADC_THERM_BATCTRL,
41 ABx500_ADC_THERM_BATTEMP,
42};
43
44/**
45 * struct abx500_res_to_temp - defines one point in a temp to res curve. To
46 * be used in battery packs that combines the identification resistor with a
47 * NTC resistor.
48 * @temp: battery pack temperature in Celcius
49 * @resist: NTC resistor net total resistance
50 */
51struct abx500_res_to_temp {
52 int temp;
53 int resist;
54};
55
56/**
57 * struct abx500_v_to_cap - Table for translating voltage to capacity
58 * @voltage: Voltage in mV
59 * @capacity: Capacity in percent
60 */
61struct abx500_v_to_cap {
62 int voltage;
63 int capacity;
64};
65
66/* Forward declaration */
67struct abx500_fg;
68
69/**
70 * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
71 * if not specified
72 * @recovery_sleep_timer: Time between measurements while recovering
73 * @recovery_total_time: Total recovery time
74 * @init_timer: Measurement interval during startup
75 * @init_discard_time: Time we discard voltage measurement at startup
76 * @init_total_time: Total init time during startup
77 * @high_curr_time: Time current has to be high to go to recovery
78 * @accu_charging: FG accumulation time while charging
79 * @accu_high_curr: FG accumulation time in high current mode
80 * @high_curr_threshold: High current threshold, in mA
81 * @lowbat_threshold: Low battery threshold, in mV
82 * @overbat_threshold: Over battery threshold, in mV
83 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
84 * Resolution in 50 mV step.
85 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
86 * Resolution in 50 mV step.
87 * @user_cap_limit Capacity reported from user must be within this
88 * limit to be considered as sane, in percentage
89 * points.
90 * @maint_thres This is the threshold where we stop reporting
91 * battery full while in maintenance, in per cent
Lee Jones93ff7222012-05-31 16:16:36 +020092 * @pcut_enable: Enable power cut feature in ab8505
93 * @pcut_max_time: Max time threshold
94 * @pcut_flag_time: Flagtime threshold
95 * @pcut_max_restart: Max number of restarts
96 * @pcut_debounce_time: Sets battery debounce time
Arun Murthy1668f812012-02-29 21:54:25 +053097 */
98struct abx500_fg_parameters {
99 int recovery_sleep_timer;
100 int recovery_total_time;
101 int init_timer;
102 int init_discard_time;
103 int init_total_time;
104 int high_curr_time;
105 int accu_charging;
106 int accu_high_curr;
107 int high_curr_threshold;
108 int lowbat_threshold;
109 int overbat_threshold;
110 int battok_falling_th_sel0;
111 int battok_raising_th_sel1;
112 int user_cap_limit;
113 int maint_thres;
Lee Jones93ff7222012-05-31 16:16:36 +0200114 bool pcut_enable;
115 u8 pcut_max_time;
116 u8 pcut_flag_time;
117 u8 pcut_max_restart;
118 u8 pcut_debounce_time;
Arun Murthy1668f812012-02-29 21:54:25 +0530119};
120
121/**
122 * struct abx500_charger_maximization - struct used by the board config.
123 * @use_maxi: Enable maximization for this battery type
124 * @maxi_chg_curr: Maximum charger current allowed
125 * @maxi_wait_cycles: cycles to wait before setting charger current
126 * @charger_curr_step delta between two charger current settings (mA)
127 */
128struct abx500_maxim_parameters {
129 bool ena_maxi;
130 int chg_curr;
131 int wait_cycles;
132 int charger_curr_step;
133};
134
135/**
136 * struct abx500_battery_type - different batteries supported
137 * @name: battery technology
138 * @resis_high: battery upper resistance limit
139 * @resis_low: battery lower resistance limit
140 * @charge_full_design: Maximum battery capacity in mAh
141 * @nominal_voltage: Nominal voltage of the battery in mV
142 * @termination_vol: max voltage upto which battery can be charged
143 * @termination_curr battery charging termination current in mA
Marcus Cooperea402402013-01-11 13:12:54 +0000144 * @recharge_cap battery capacity limit that will trigger a new
Arun Murthy1668f812012-02-29 21:54:25 +0530145 * full charging cycle in the case where maintenan-
146 * -ce charging has been disabled
147 * @normal_cur_lvl: charger current in normal state in mA
148 * @normal_vol_lvl: charger voltage in normal state in mV
149 * @maint_a_cur_lvl: charger current in maintenance A state in mA
150 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
151 * @maint_a_chg_timer_h: charge time in maintenance A state
152 * @maint_b_cur_lvl: charger current in maintenance B state in mA
153 * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
154 * @maint_b_chg_timer_h: charge time in maintenance B state
155 * @low_high_cur_lvl: charger current in temp low/high state in mA
156 * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
157 * @battery_resistance: battery inner resistance in mOhm.
158 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
159 * @r_to_t_tbl: table containing resistance to temp points
160 * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
161 * @v_to_cap_tbl: Voltage to capacity (in %) table
162 * @n_batres_tbl_elements number of elements in the batres_tbl
163 * @batres_tbl battery internal resistance vs temperature table
164 */
165struct abx500_battery_type {
166 int name;
167 int resis_high;
168 int resis_low;
169 int charge_full_design;
170 int nominal_voltage;
171 int termination_vol;
172 int termination_curr;
Marcus Cooperea402402013-01-11 13:12:54 +0000173 int recharge_cap;
Arun Murthy1668f812012-02-29 21:54:25 +0530174 int normal_cur_lvl;
175 int normal_vol_lvl;
176 int maint_a_cur_lvl;
177 int maint_a_vol_lvl;
178 int maint_a_chg_timer_h;
179 int maint_b_cur_lvl;
180 int maint_b_vol_lvl;
181 int maint_b_chg_timer_h;
182 int low_high_cur_lvl;
183 int low_high_vol_lvl;
184 int battery_resistance;
185 int n_temp_tbl_elements;
Hongbo Zhang2c899402013-04-03 20:18:10 +0800186 const struct abx500_res_to_temp *r_to_t_tbl;
Arun Murthy1668f812012-02-29 21:54:25 +0530187 int n_v_cap_tbl_elements;
Hongbo Zhang2c899402013-04-03 20:18:10 +0800188 const struct abx500_v_to_cap *v_to_cap_tbl;
Arun Murthy1668f812012-02-29 21:54:25 +0530189 int n_batres_tbl_elements;
Hongbo Zhang2c899402013-04-03 20:18:10 +0800190 const struct batres_vs_temp *batres_tbl;
Arun Murthy1668f812012-02-29 21:54:25 +0530191};
192
193/**
194 * struct abx500_bm_capacity_levels - abx500 capacity level data
195 * @critical: critical capacity level in percent
196 * @low: low capacity level in percent
197 * @normal: normal capacity level in percent
198 * @high: high capacity level in percent
199 * @full: full capacity level in percent
200 */
201struct abx500_bm_capacity_levels {
202 int critical;
203 int low;
204 int normal;
205 int high;
206 int full;
207};
208
209/**
210 * struct abx500_bm_charger_parameters - Charger specific parameters
211 * @usb_volt_max: maximum allowed USB charger voltage in mV
212 * @usb_curr_max: maximum allowed USB charger current in mA
213 * @ac_volt_max: maximum allowed AC charger voltage in mV
214 * @ac_curr_max: maximum allowed AC charger current in mA
215 */
216struct abx500_bm_charger_parameters {
217 int usb_volt_max;
218 int usb_curr_max;
219 int ac_volt_max;
220 int ac_curr_max;
221};
222
223/**
224 * struct abx500_bm_data - abx500 battery management data
225 * @temp_under under this temp, charging is stopped
226 * @temp_low between this temp and temp_under charging is reduced
227 * @temp_high between this temp and temp_over charging is reduced
228 * @temp_over over this temp, charging is stopped
229 * @temp_now present battery temperature
230 * @temp_interval_chg temperature measurement interval in s when charging
231 * @temp_interval_nochg temperature measurement interval in s when not charging
232 * @main_safety_tmr_h safety timer for main charger
233 * @usb_safety_tmr_h safety timer for usb charger
234 * @bkup_bat_v voltage which we charge the backup battery with
235 * @bkup_bat_i current which we charge the backup battery with
236 * @no_maintenance indicates that maintenance charging is disabled
Marcus Cooperea402402013-01-11 13:12:54 +0000237 * @capacity_scaling indicates whether capacity scaling is to be used
Arun Murthy1668f812012-02-29 21:54:25 +0530238 * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
239 * @chg_unknown_bat flag to enable charging of unknown batteries
240 * @enable_overshoot flag to enable VBAT overshoot control
241 * @auto_trig flag to enable auto adc trigger
242 * @fg_res resistance of FG resistor in 0.1mOhm
243 * @n_btypes number of elements in array bat_type
244 * @batt_id index of the identified battery in array bat_type
245 * @interval_charging charge alg cycle period time when charging (sec)
246 * @interval_not_charging charge alg cycle period time when not charging (sec)
247 * @temp_hysteresis temperature hysteresis
248 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
Lee Jones861a30d2012-08-29 20:36:51 +0800249 * @n_chg_out_curr number of elements in array chg_output_curr
250 * @n_chg_in_curr number of elements in array chg_input_curr
251 * @chg_output_curr charger output current level map
252 * @chg_input_curr charger input current level map
253 * @maxi maximization parameters
Arun Murthy1668f812012-02-29 21:54:25 +0530254 * @cap_levels capacity in percent for the different capacity levels
255 * @bat_type table of supported battery types
256 * @chg_params charger parameters
257 * @fg_params fuel gauge parameters
258 */
259struct abx500_bm_data {
260 int temp_under;
261 int temp_low;
262 int temp_high;
263 int temp_over;
264 int temp_now;
265 int temp_interval_chg;
266 int temp_interval_nochg;
267 int main_safety_tmr_h;
268 int usb_safety_tmr_h;
269 int bkup_bat_v;
270 int bkup_bat_i;
Lee Jones97034a12013-01-17 16:08:42 +0000271 bool autopower_cfg;
272 bool ac_enabled;
273 bool usb_enabled;
Lee Jonesdb43e6c2013-02-14 12:39:15 +0000274 bool usb_power_path;
Arun Murthy1668f812012-02-29 21:54:25 +0530275 bool no_maintenance;
Marcus Cooperea402402013-01-11 13:12:54 +0000276 bool capacity_scaling;
Arun Murthy1668f812012-02-29 21:54:25 +0530277 bool chg_unknown_bat;
278 bool enable_overshoot;
279 bool auto_trig;
280 enum abx500_adc_therm adc_therm;
281 int fg_res;
282 int n_btypes;
283 int batt_id;
284 int interval_charging;
285 int interval_not_charging;
286 int temp_hysteresis;
287 int gnd_lift_resistance;
Lee Jones861a30d2012-08-29 20:36:51 +0800288 int n_chg_out_curr;
289 int n_chg_in_curr;
290 int *chg_output_curr;
291 int *chg_input_curr;
Arun Murthy1668f812012-02-29 21:54:25 +0530292 const struct abx500_maxim_parameters *maxi;
293 const struct abx500_bm_capacity_levels *cap_levels;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800294 struct abx500_battery_type *bat_type;
Arun Murthy1668f812012-02-29 21:54:25 +0530295 const struct abx500_bm_charger_parameters *chg_params;
296 const struct abx500_fg_parameters *fg_params;
297};
298
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800299enum {
300 NTC_EXTERNAL = 0,
301 NTC_INTERNAL,
Arun Murthy1668f812012-02-29 21:54:25 +0530302};
303
Lee Jonesb0284de2012-11-30 10:09:42 +0000304int ab8500_bm_of_probe(struct device *dev,
305 struct device_node *np,
Lee Jones23a04f92012-11-29 15:08:41 +0000306 struct abx500_bm_data *bm);
Arun Murthy1668f812012-02-29 21:54:25 +0530307
Mattias Wallinfa661252010-05-01 18:26:20 +0200308int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
309 u8 value);
310int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
311 u8 *value);
312int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
313 u8 first_reg, u8 *regvals, u8 numregs);
314int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
315 u8 first_reg, u8 *regvals, u8 numregs);
316/**
317 * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
318 * target register
319 *
320 * @dev: The AB sub device.
321 * @bank: The i2c bank number.
322 * @bitmask: The bit mask to use.
323 * @bitvalues: The new bit values.
324 *
325 * Updates the value of an AB register:
326 * value -> ((value & ~bitmask) | (bitvalues & bitmask))
327 */
328int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
329 u8 reg, u8 bitmask, u8 bitvalues);
330int abx500_get_chip_id(struct device *dev);
331int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
332int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
Mian Yousaf Kaukabe0f4fec2012-01-27 11:22:16 +0100333void abx500_dump_all_banks(void);
Mattias Wallinfa661252010-05-01 18:26:20 +0200334
335struct abx500_ops {
336 int (*get_chip_id) (struct device *);
337 int (*get_register) (struct device *, u8, u8, u8 *);
338 int (*set_register) (struct device *, u8, u8, u8);
339 int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
340 int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
341 int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
342 int (*event_registers_startup_state_get) (struct device *, u8 *);
343 int (*startup_irq_enabled) (struct device *, unsigned int);
Mian Yousaf Kaukabe0f4fec2012-01-27 11:22:16 +0100344 void (*dump_all_banks) (struct device *);
Mattias Wallinfa661252010-05-01 18:26:20 +0200345};
346
347int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
Mark Brownc6252e92010-09-22 14:58:30 +0100348void abx500_remove_ops(struct device *dev);
Linus Walleij14fa5692009-05-21 23:17:06 +0200349#endif