1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2007-2009 ST-Ericsson AB
5 * ABX500 core access functions.
6 * The abx500 interface is used for the Analog Baseband chips.
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>
14 #include <linux/regulator/machine.h>
22 * struct abx500_init_setting
23 * Initial value of the registers for driver to use during setup.
25 struct abx500_init_settings {
31 /* Battery driver related data */
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.
39 enum abx500_adc_therm {
40 ABx500_ADC_THERM_BATCTRL,
41 ABx500_ADC_THERM_BATTEMP,
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
48 * @temp: battery pack temperature in Celsius
49 * @resist: NTC resistor net total resistance
51 struct abx500_res_to_temp {
57 * struct abx500_v_to_cap - Table for translating voltage to capacity
58 * @voltage: Voltage in mV
59 * @capacity: Capacity in percent
61 struct abx500_v_to_cap {
66 /* Forward declaration */
70 * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds
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
90 * @maint_thres This is the threshold where we stop reporting
91 * battery full while in maintenance, in per cent
92 * @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
98 struct abx500_fg_parameters {
99 int recovery_sleep_timer;
100 int recovery_total_time;
102 int init_discard_time;
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;
118 u8 pcut_debounce_time;
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)
128 struct abx500_maxim_parameters {
132 int charger_curr_step;
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
144 * @recharge_cap battery capacity limit that will trigger a new
145 * 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
165 struct abx500_battery_type {
169 int charge_full_design;
172 int termination_curr;
178 int maint_a_chg_timer_h;
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;
186 const struct abx500_res_to_temp *r_to_t_tbl;
187 int n_v_cap_tbl_elements;
188 const struct abx500_v_to_cap *v_to_cap_tbl;
189 int n_batres_tbl_elements;
190 const struct batres_vs_temp *batres_tbl;
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
201 struct abx500_bm_capacity_levels {
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
216 struct abx500_bm_charger_parameters {
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
237 * @capacity_scaling indicates whether capacity scaling is to be used
238 * @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)
249 * @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
254 * @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
259 struct abx500_bm_data {
265 int temp_interval_chg;
266 int temp_interval_nochg;
267 int main_safety_tmr_h;
268 int usb_safety_tmr_h;
275 bool capacity_scaling;
276 bool chg_unknown_bat;
277 bool enable_overshoot;
279 enum abx500_adc_therm adc_therm;
283 int interval_charging;
284 int interval_not_charging;
286 int gnd_lift_resistance;
289 int *chg_output_curr;
291 const struct abx500_maxim_parameters *maxi;
292 const struct abx500_bm_capacity_levels *cap_levels;
293 struct abx500_battery_type *bat_type;
294 const struct abx500_bm_charger_parameters *chg_params;
295 const struct abx500_fg_parameters *fg_params;
303 int ab8500_bm_of_probe(struct device *dev,
304 struct device_node *np,
305 struct abx500_bm_data *bm);
307 int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
309 int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
311 int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
312 u8 first_reg, u8 *regvals, u8 numregs);
313 int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
314 u8 first_reg, u8 *regvals, u8 numregs);
316 * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
319 * @dev: The AB sub device.
320 * @bank: The i2c bank number.
321 * @bitmask: The bit mask to use.
322 * @bitvalues: The new bit values.
324 * Updates the value of an AB register:
325 * value -> ((value & ~bitmask) | (bitvalues & bitmask))
327 int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
328 u8 reg, u8 bitmask, u8 bitvalues);
329 int abx500_get_chip_id(struct device *dev);
330 int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
331 int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
334 int (*get_chip_id) (struct device *);
335 int (*get_register) (struct device *, u8, u8, u8 *);
336 int (*set_register) (struct device *, u8, u8, u8);
337 int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
338 int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
339 int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
340 int (*event_registers_startup_state_get) (struct device *, u8 *);
341 int (*startup_irq_enabled) (struct device *, unsigned int);
342 void (*dump_all_banks) (struct device *);
345 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
346 void abx500_remove_ops(struct device *dev);