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