blob: 0e6e90badfcaaa203d0b45f8a98b645dd1b5985f [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
92 */
93struct abx500_fg_parameters {
94 int recovery_sleep_timer;
95 int recovery_total_time;
96 int init_timer;
97 int init_discard_time;
98 int init_total_time;
99 int high_curr_time;
100 int accu_charging;
101 int accu_high_curr;
102 int high_curr_threshold;
103 int lowbat_threshold;
104 int overbat_threshold;
105 int battok_falling_th_sel0;
106 int battok_raising_th_sel1;
107 int user_cap_limit;
108 int maint_thres;
109};
110
111/**
112 * struct abx500_charger_maximization - struct used by the board config.
113 * @use_maxi: Enable maximization for this battery type
114 * @maxi_chg_curr: Maximum charger current allowed
115 * @maxi_wait_cycles: cycles to wait before setting charger current
116 * @charger_curr_step delta between two charger current settings (mA)
117 */
118struct abx500_maxim_parameters {
119 bool ena_maxi;
120 int chg_curr;
121 int wait_cycles;
122 int charger_curr_step;
123};
124
125/**
126 * struct abx500_battery_type - different batteries supported
127 * @name: battery technology
128 * @resis_high: battery upper resistance limit
129 * @resis_low: battery lower resistance limit
130 * @charge_full_design: Maximum battery capacity in mAh
131 * @nominal_voltage: Nominal voltage of the battery in mV
132 * @termination_vol: max voltage upto which battery can be charged
133 * @termination_curr battery charging termination current in mA
Marcus Cooperea402402013-01-11 13:12:54 +0000134 * @recharge_cap battery capacity limit that will trigger a new
Arun Murthy1668f812012-02-29 21:54:25 +0530135 * full charging cycle in the case where maintenan-
136 * -ce charging has been disabled
137 * @normal_cur_lvl: charger current in normal state in mA
138 * @normal_vol_lvl: charger voltage in normal state in mV
139 * @maint_a_cur_lvl: charger current in maintenance A state in mA
140 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
141 * @maint_a_chg_timer_h: charge time in maintenance A state
142 * @maint_b_cur_lvl: charger current in maintenance B state in mA
143 * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
144 * @maint_b_chg_timer_h: charge time in maintenance B state
145 * @low_high_cur_lvl: charger current in temp low/high state in mA
146 * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
147 * @battery_resistance: battery inner resistance in mOhm.
148 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
149 * @r_to_t_tbl: table containing resistance to temp points
150 * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
151 * @v_to_cap_tbl: Voltage to capacity (in %) table
152 * @n_batres_tbl_elements number of elements in the batres_tbl
153 * @batres_tbl battery internal resistance vs temperature table
154 */
155struct abx500_battery_type {
156 int name;
157 int resis_high;
158 int resis_low;
159 int charge_full_design;
160 int nominal_voltage;
161 int termination_vol;
162 int termination_curr;
Marcus Cooperea402402013-01-11 13:12:54 +0000163 int recharge_cap;
Arun Murthy1668f812012-02-29 21:54:25 +0530164 int normal_cur_lvl;
165 int normal_vol_lvl;
166 int maint_a_cur_lvl;
167 int maint_a_vol_lvl;
168 int maint_a_chg_timer_h;
169 int maint_b_cur_lvl;
170 int maint_b_vol_lvl;
171 int maint_b_chg_timer_h;
172 int low_high_cur_lvl;
173 int low_high_vol_lvl;
174 int battery_resistance;
175 int n_temp_tbl_elements;
176 struct abx500_res_to_temp *r_to_t_tbl;
177 int n_v_cap_tbl_elements;
178 struct abx500_v_to_cap *v_to_cap_tbl;
179 int n_batres_tbl_elements;
180 struct batres_vs_temp *batres_tbl;
181};
182
183/**
184 * struct abx500_bm_capacity_levels - abx500 capacity level data
185 * @critical: critical capacity level in percent
186 * @low: low capacity level in percent
187 * @normal: normal capacity level in percent
188 * @high: high capacity level in percent
189 * @full: full capacity level in percent
190 */
191struct abx500_bm_capacity_levels {
192 int critical;
193 int low;
194 int normal;
195 int high;
196 int full;
197};
198
199/**
200 * struct abx500_bm_charger_parameters - Charger specific parameters
201 * @usb_volt_max: maximum allowed USB charger voltage in mV
202 * @usb_curr_max: maximum allowed USB charger current in mA
203 * @ac_volt_max: maximum allowed AC charger voltage in mV
204 * @ac_curr_max: maximum allowed AC charger current in mA
205 */
206struct abx500_bm_charger_parameters {
207 int usb_volt_max;
208 int usb_curr_max;
209 int ac_volt_max;
210 int ac_curr_max;
211};
212
213/**
214 * struct abx500_bm_data - abx500 battery management data
215 * @temp_under under this temp, charging is stopped
216 * @temp_low between this temp and temp_under charging is reduced
217 * @temp_high between this temp and temp_over charging is reduced
218 * @temp_over over this temp, charging is stopped
219 * @temp_now present battery temperature
220 * @temp_interval_chg temperature measurement interval in s when charging
221 * @temp_interval_nochg temperature measurement interval in s when not charging
222 * @main_safety_tmr_h safety timer for main charger
223 * @usb_safety_tmr_h safety timer for usb charger
224 * @bkup_bat_v voltage which we charge the backup battery with
225 * @bkup_bat_i current which we charge the backup battery with
226 * @no_maintenance indicates that maintenance charging is disabled
Marcus Cooperea402402013-01-11 13:12:54 +0000227 * @capacity_scaling indicates whether capacity scaling is to be used
Arun Murthy1668f812012-02-29 21:54:25 +0530228 * @abx500_adc_therm placement of thermistor, batctrl or battemp adc
229 * @chg_unknown_bat flag to enable charging of unknown batteries
230 * @enable_overshoot flag to enable VBAT overshoot control
231 * @auto_trig flag to enable auto adc trigger
232 * @fg_res resistance of FG resistor in 0.1mOhm
233 * @n_btypes number of elements in array bat_type
234 * @batt_id index of the identified battery in array bat_type
235 * @interval_charging charge alg cycle period time when charging (sec)
236 * @interval_not_charging charge alg cycle period time when not charging (sec)
237 * @temp_hysteresis temperature hysteresis
238 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
239 * @maxi: maximization parameters
240 * @cap_levels capacity in percent for the different capacity levels
241 * @bat_type table of supported battery types
242 * @chg_params charger parameters
243 * @fg_params fuel gauge parameters
244 */
245struct abx500_bm_data {
246 int temp_under;
247 int temp_low;
248 int temp_high;
249 int temp_over;
250 int temp_now;
251 int temp_interval_chg;
252 int temp_interval_nochg;
253 int main_safety_tmr_h;
254 int usb_safety_tmr_h;
255 int bkup_bat_v;
256 int bkup_bat_i;
257 bool no_maintenance;
Marcus Cooperea402402013-01-11 13:12:54 +0000258 bool capacity_scaling;
Arun Murthy1668f812012-02-29 21:54:25 +0530259 bool chg_unknown_bat;
260 bool enable_overshoot;
261 bool auto_trig;
262 enum abx500_adc_therm adc_therm;
263 int fg_res;
264 int n_btypes;
265 int batt_id;
266 int interval_charging;
267 int interval_not_charging;
268 int temp_hysteresis;
269 int gnd_lift_resistance;
270 const struct abx500_maxim_parameters *maxi;
271 const struct abx500_bm_capacity_levels *cap_levels;
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800272 struct abx500_battery_type *bat_type;
Arun Murthy1668f812012-02-29 21:54:25 +0530273 const struct abx500_bm_charger_parameters *chg_params;
274 const struct abx500_fg_parameters *fg_params;
275};
276
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800277extern struct abx500_bm_data ab8500_bm_data;
278
Rajanikanth H.Ve0f1abe2012-11-18 18:45:41 -0800279enum {
280 NTC_EXTERNAL = 0,
281 NTC_INTERNAL,
Arun Murthy1668f812012-02-29 21:54:25 +0530282};
283
Lee Jonesb0284de2012-11-30 10:09:42 +0000284int ab8500_bm_of_probe(struct device *dev,
285 struct device_node *np,
Lee Jones23a04f92012-11-29 15:08:41 +0000286 struct abx500_bm_data *bm);
Arun Murthy1668f812012-02-29 21:54:25 +0530287
Mattias Wallinfa661252010-05-01 18:26:20 +0200288int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
289 u8 value);
290int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
291 u8 *value);
292int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
293 u8 first_reg, u8 *regvals, u8 numregs);
294int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
295 u8 first_reg, u8 *regvals, u8 numregs);
296/**
297 * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
298 * target register
299 *
300 * @dev: The AB sub device.
301 * @bank: The i2c bank number.
302 * @bitmask: The bit mask to use.
303 * @bitvalues: The new bit values.
304 *
305 * Updates the value of an AB register:
306 * value -> ((value & ~bitmask) | (bitvalues & bitmask))
307 */
308int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
309 u8 reg, u8 bitmask, u8 bitvalues);
310int abx500_get_chip_id(struct device *dev);
311int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
312int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
313
314struct abx500_ops {
315 int (*get_chip_id) (struct device *);
316 int (*get_register) (struct device *, u8, u8, u8 *);
317 int (*set_register) (struct device *, u8, u8, u8);
318 int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
319 int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
320 int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
321 int (*event_registers_startup_state_get) (struct device *, u8 *);
322 int (*startup_irq_enabled) (struct device *, unsigned int);
323};
324
325int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
Mark Brownc6252e92010-09-22 14:58:30 +0100326void abx500_remove_ops(struct device *dev);
Linus Walleij14fa5692009-05-21 23:17:06 +0200327#endif