1*af873fceSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2812f9e9dSLinus Walleij /* 3812f9e9dSLinus Walleij * Copyright (C) 2007-2009 ST-Ericsson AB 4fa661258SMattias Wallin * 5fa661258SMattias Wallin * ABX500 core access functions. 60fd0013cSMarcus Cooper * The abx500 interface is used for the Analog Baseband chips. 7fa661258SMattias Wallin * 8fa661258SMattias Wallin * Author: Mattias Wallin <mattias.wallin@stericsson.com> 9fa661258SMattias Wallin * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> 10fa661258SMattias Wallin * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com> 11fa661258SMattias Wallin * Author: Rickard Andersson <rickard.andersson@stericsson.com> 12812f9e9dSLinus Walleij */ 13812f9e9dSLinus Walleij 14812f9e9dSLinus Walleij #include <linux/regulator/machine.h> 15812f9e9dSLinus Walleij 16313162d0SPaul Gortmaker struct device; 17313162d0SPaul Gortmaker 18fa661258SMattias Wallin #ifndef MFD_ABX500_H 19fa661258SMattias Wallin #define MFD_ABX500_H 20812f9e9dSLinus Walleij 21fa661258SMattias Wallin /** 22fa661258SMattias Wallin * struct abx500_init_setting 23fa661258SMattias Wallin * Initial value of the registers for driver to use during setup. 24fa661258SMattias Wallin */ 25fa661258SMattias Wallin struct abx500_init_settings { 26fa661258SMattias Wallin u8 bank; 27fa661258SMattias Wallin u8 reg; 28fa661258SMattias Wallin u8 setting; 29fa661258SMattias Wallin }; 30fa661258SMattias Wallin 311668f811SArun Murthy /* Battery driver related data */ 321668f811SArun Murthy /* 331668f811SArun Murthy * ADC for the battery thermistor. 341668f811SArun Murthy * When using the ABx500_ADC_THERM_BATCTRL the battery ID resistor is combined 351668f811SArun Murthy * with a NTC resistor to both identify the battery and to measure its 361668f811SArun Murthy * temperature. Different phone manufactures uses different techniques to both 371668f811SArun Murthy * identify the battery and to read its temperature. 381668f811SArun Murthy */ 391668f811SArun Murthy enum abx500_adc_therm { 401668f811SArun Murthy ABx500_ADC_THERM_BATCTRL, 411668f811SArun Murthy ABx500_ADC_THERM_BATTEMP, 421668f811SArun Murthy }; 431668f811SArun Murthy 441668f811SArun Murthy /** 451668f811SArun Murthy * struct abx500_res_to_temp - defines one point in a temp to res curve. To 461668f811SArun Murthy * be used in battery packs that combines the identification resistor with a 471668f811SArun Murthy * NTC resistor. 48a042a7a4SColin Ian King * @temp: battery pack temperature in Celsius 491668f811SArun Murthy * @resist: NTC resistor net total resistance 501668f811SArun Murthy */ 511668f811SArun Murthy struct abx500_res_to_temp { 521668f811SArun Murthy int temp; 531668f811SArun Murthy int resist; 541668f811SArun Murthy }; 551668f811SArun Murthy 561668f811SArun Murthy /** 571668f811SArun Murthy * struct abx500_v_to_cap - Table for translating voltage to capacity 581668f811SArun Murthy * @voltage: Voltage in mV 591668f811SArun Murthy * @capacity: Capacity in percent 601668f811SArun Murthy */ 611668f811SArun Murthy struct abx500_v_to_cap { 621668f811SArun Murthy int voltage; 631668f811SArun Murthy int capacity; 641668f811SArun Murthy }; 651668f811SArun Murthy 661668f811SArun Murthy /* Forward declaration */ 671668f811SArun Murthy struct abx500_fg; 681668f811SArun Murthy 691668f811SArun Murthy /** 701668f811SArun Murthy * struct abx500_fg_parameters - Fuel gauge algorithm parameters, in seconds 711668f811SArun Murthy * if not specified 721668f811SArun Murthy * @recovery_sleep_timer: Time between measurements while recovering 731668f811SArun Murthy * @recovery_total_time: Total recovery time 741668f811SArun Murthy * @init_timer: Measurement interval during startup 751668f811SArun Murthy * @init_discard_time: Time we discard voltage measurement at startup 761668f811SArun Murthy * @init_total_time: Total init time during startup 771668f811SArun Murthy * @high_curr_time: Time current has to be high to go to recovery 781668f811SArun Murthy * @accu_charging: FG accumulation time while charging 791668f811SArun Murthy * @accu_high_curr: FG accumulation time in high current mode 801668f811SArun Murthy * @high_curr_threshold: High current threshold, in mA 811668f811SArun Murthy * @lowbat_threshold: Low battery threshold, in mV 821668f811SArun Murthy * @overbat_threshold: Over battery threshold, in mV 831668f811SArun Murthy * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0 841668f811SArun Murthy * Resolution in 50 mV step. 851668f811SArun Murthy * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1 861668f811SArun Murthy * Resolution in 50 mV step. 871668f811SArun Murthy * @user_cap_limit Capacity reported from user must be within this 881668f811SArun Murthy * limit to be considered as sane, in percentage 891668f811SArun Murthy * points. 901668f811SArun Murthy * @maint_thres This is the threshold where we stop reporting 911668f811SArun Murthy * battery full while in maintenance, in per cent 9293ff722eSLee Jones * @pcut_enable: Enable power cut feature in ab8505 9393ff722eSLee Jones * @pcut_max_time: Max time threshold 9493ff722eSLee Jones * @pcut_flag_time: Flagtime threshold 9593ff722eSLee Jones * @pcut_max_restart: Max number of restarts 9693ff722eSLee Jones * @pcut_debounce_time: Sets battery debounce time 971668f811SArun Murthy */ 981668f811SArun Murthy struct abx500_fg_parameters { 991668f811SArun Murthy int recovery_sleep_timer; 1001668f811SArun Murthy int recovery_total_time; 1011668f811SArun Murthy int init_timer; 1021668f811SArun Murthy int init_discard_time; 1031668f811SArun Murthy int init_total_time; 1041668f811SArun Murthy int high_curr_time; 1051668f811SArun Murthy int accu_charging; 1061668f811SArun Murthy int accu_high_curr; 1071668f811SArun Murthy int high_curr_threshold; 1081668f811SArun Murthy int lowbat_threshold; 1091668f811SArun Murthy int overbat_threshold; 1101668f811SArun Murthy int battok_falling_th_sel0; 1111668f811SArun Murthy int battok_raising_th_sel1; 1121668f811SArun Murthy int user_cap_limit; 1131668f811SArun Murthy int maint_thres; 11493ff722eSLee Jones bool pcut_enable; 11593ff722eSLee Jones u8 pcut_max_time; 11693ff722eSLee Jones u8 pcut_flag_time; 11793ff722eSLee Jones u8 pcut_max_restart; 11893ff722eSLee Jones u8 pcut_debounce_time; 1191668f811SArun Murthy }; 1201668f811SArun Murthy 1211668f811SArun Murthy /** 1221668f811SArun Murthy * struct abx500_charger_maximization - struct used by the board config. 1231668f811SArun Murthy * @use_maxi: Enable maximization for this battery type 1241668f811SArun Murthy * @maxi_chg_curr: Maximum charger current allowed 1251668f811SArun Murthy * @maxi_wait_cycles: cycles to wait before setting charger current 1261668f811SArun Murthy * @charger_curr_step delta between two charger current settings (mA) 1271668f811SArun Murthy */ 1281668f811SArun Murthy struct abx500_maxim_parameters { 1291668f811SArun Murthy bool ena_maxi; 1301668f811SArun Murthy int chg_curr; 1311668f811SArun Murthy int wait_cycles; 1321668f811SArun Murthy int charger_curr_step; 1331668f811SArun Murthy }; 1341668f811SArun Murthy 1351668f811SArun Murthy /** 1361668f811SArun Murthy * struct abx500_battery_type - different batteries supported 1371668f811SArun Murthy * @name: battery technology 1381668f811SArun Murthy * @resis_high: battery upper resistance limit 1391668f811SArun Murthy * @resis_low: battery lower resistance limit 1401668f811SArun Murthy * @charge_full_design: Maximum battery capacity in mAh 1411668f811SArun Murthy * @nominal_voltage: Nominal voltage of the battery in mV 1421668f811SArun Murthy * @termination_vol: max voltage upto which battery can be charged 1431668f811SArun Murthy * @termination_curr battery charging termination current in mA 144ea402401SMarcus Cooper * @recharge_cap battery capacity limit that will trigger a new 1451668f811SArun Murthy * full charging cycle in the case where maintenan- 1461668f811SArun Murthy * -ce charging has been disabled 1471668f811SArun Murthy * @normal_cur_lvl: charger current in normal state in mA 1481668f811SArun Murthy * @normal_vol_lvl: charger voltage in normal state in mV 1491668f811SArun Murthy * @maint_a_cur_lvl: charger current in maintenance A state in mA 1501668f811SArun Murthy * @maint_a_vol_lvl: charger voltage in maintenance A state in mV 1511668f811SArun Murthy * @maint_a_chg_timer_h: charge time in maintenance A state 1521668f811SArun Murthy * @maint_b_cur_lvl: charger current in maintenance B state in mA 1531668f811SArun Murthy * @maint_b_vol_lvl: charger voltage in maintenance B state in mV 1541668f811SArun Murthy * @maint_b_chg_timer_h: charge time in maintenance B state 1551668f811SArun Murthy * @low_high_cur_lvl: charger current in temp low/high state in mA 1561668f811SArun Murthy * @low_high_vol_lvl: charger voltage in temp low/high state in mV' 1571668f811SArun Murthy * @battery_resistance: battery inner resistance in mOhm. 1581668f811SArun Murthy * @n_r_t_tbl_elements: number of elements in r_to_t_tbl 1591668f811SArun Murthy * @r_to_t_tbl: table containing resistance to temp points 1601668f811SArun Murthy * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl 1611668f811SArun Murthy * @v_to_cap_tbl: Voltage to capacity (in %) table 1621668f811SArun Murthy * @n_batres_tbl_elements number of elements in the batres_tbl 1631668f811SArun Murthy * @batres_tbl battery internal resistance vs temperature table 1641668f811SArun Murthy */ 1651668f811SArun Murthy struct abx500_battery_type { 1661668f811SArun Murthy int name; 1671668f811SArun Murthy int resis_high; 1681668f811SArun Murthy int resis_low; 1691668f811SArun Murthy int charge_full_design; 1701668f811SArun Murthy int nominal_voltage; 1711668f811SArun Murthy int termination_vol; 1721668f811SArun Murthy int termination_curr; 173ea402401SMarcus Cooper int recharge_cap; 1741668f811SArun Murthy int normal_cur_lvl; 1751668f811SArun Murthy int normal_vol_lvl; 1761668f811SArun Murthy int maint_a_cur_lvl; 1771668f811SArun Murthy int maint_a_vol_lvl; 1781668f811SArun Murthy int maint_a_chg_timer_h; 1791668f811SArun Murthy int maint_b_cur_lvl; 1801668f811SArun Murthy int maint_b_vol_lvl; 1811668f811SArun Murthy int maint_b_chg_timer_h; 1821668f811SArun Murthy int low_high_cur_lvl; 1831668f811SArun Murthy int low_high_vol_lvl; 1841668f811SArun Murthy int battery_resistance; 1851668f811SArun Murthy int n_temp_tbl_elements; 1862c899407SHongbo Zhang const struct abx500_res_to_temp *r_to_t_tbl; 1871668f811SArun Murthy int n_v_cap_tbl_elements; 1882c899407SHongbo Zhang const struct abx500_v_to_cap *v_to_cap_tbl; 1891668f811SArun Murthy int n_batres_tbl_elements; 1902c899407SHongbo Zhang const struct batres_vs_temp *batres_tbl; 1911668f811SArun Murthy }; 1921668f811SArun Murthy 1931668f811SArun Murthy /** 1941668f811SArun Murthy * struct abx500_bm_capacity_levels - abx500 capacity level data 1951668f811SArun Murthy * @critical: critical capacity level in percent 1961668f811SArun Murthy * @low: low capacity level in percent 1971668f811SArun Murthy * @normal: normal capacity level in percent 1981668f811SArun Murthy * @high: high capacity level in percent 1991668f811SArun Murthy * @full: full capacity level in percent 2001668f811SArun Murthy */ 2011668f811SArun Murthy struct abx500_bm_capacity_levels { 2021668f811SArun Murthy int critical; 2031668f811SArun Murthy int low; 2041668f811SArun Murthy int normal; 2051668f811SArun Murthy int high; 2061668f811SArun Murthy int full; 2071668f811SArun Murthy }; 2081668f811SArun Murthy 2091668f811SArun Murthy /** 2101668f811SArun Murthy * struct abx500_bm_charger_parameters - Charger specific parameters 2111668f811SArun Murthy * @usb_volt_max: maximum allowed USB charger voltage in mV 2121668f811SArun Murthy * @usb_curr_max: maximum allowed USB charger current in mA 2131668f811SArun Murthy * @ac_volt_max: maximum allowed AC charger voltage in mV 2141668f811SArun Murthy * @ac_curr_max: maximum allowed AC charger current in mA 2151668f811SArun Murthy */ 2161668f811SArun Murthy struct abx500_bm_charger_parameters { 2171668f811SArun Murthy int usb_volt_max; 2181668f811SArun Murthy int usb_curr_max; 2191668f811SArun Murthy int ac_volt_max; 2201668f811SArun Murthy int ac_curr_max; 2211668f811SArun Murthy }; 2221668f811SArun Murthy 2231668f811SArun Murthy /** 2241668f811SArun Murthy * struct abx500_bm_data - abx500 battery management data 2251668f811SArun Murthy * @temp_under under this temp, charging is stopped 2261668f811SArun Murthy * @temp_low between this temp and temp_under charging is reduced 2271668f811SArun Murthy * @temp_high between this temp and temp_over charging is reduced 2281668f811SArun Murthy * @temp_over over this temp, charging is stopped 2291668f811SArun Murthy * @temp_now present battery temperature 2301668f811SArun Murthy * @temp_interval_chg temperature measurement interval in s when charging 2311668f811SArun Murthy * @temp_interval_nochg temperature measurement interval in s when not charging 2321668f811SArun Murthy * @main_safety_tmr_h safety timer for main charger 2331668f811SArun Murthy * @usb_safety_tmr_h safety timer for usb charger 2341668f811SArun Murthy * @bkup_bat_v voltage which we charge the backup battery with 2351668f811SArun Murthy * @bkup_bat_i current which we charge the backup battery with 2361668f811SArun Murthy * @no_maintenance indicates that maintenance charging is disabled 237ea402401SMarcus Cooper * @capacity_scaling indicates whether capacity scaling is to be used 2381668f811SArun Murthy * @abx500_adc_therm placement of thermistor, batctrl or battemp adc 2391668f811SArun Murthy * @chg_unknown_bat flag to enable charging of unknown batteries 2401668f811SArun Murthy * @enable_overshoot flag to enable VBAT overshoot control 2411668f811SArun Murthy * @auto_trig flag to enable auto adc trigger 2421668f811SArun Murthy * @fg_res resistance of FG resistor in 0.1mOhm 2431668f811SArun Murthy * @n_btypes number of elements in array bat_type 2441668f811SArun Murthy * @batt_id index of the identified battery in array bat_type 2451668f811SArun Murthy * @interval_charging charge alg cycle period time when charging (sec) 2461668f811SArun Murthy * @interval_not_charging charge alg cycle period time when not charging (sec) 2471668f811SArun Murthy * @temp_hysteresis temperature hysteresis 2481668f811SArun Murthy * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm) 249861a30daSLee Jones * @n_chg_out_curr number of elements in array chg_output_curr 250861a30daSLee Jones * @n_chg_in_curr number of elements in array chg_input_curr 251861a30daSLee Jones * @chg_output_curr charger output current level map 252861a30daSLee Jones * @chg_input_curr charger input current level map 253861a30daSLee Jones * @maxi maximization parameters 2541668f811SArun Murthy * @cap_levels capacity in percent for the different capacity levels 2551668f811SArun Murthy * @bat_type table of supported battery types 2561668f811SArun Murthy * @chg_params charger parameters 2571668f811SArun Murthy * @fg_params fuel gauge parameters 2581668f811SArun Murthy */ 2591668f811SArun Murthy struct abx500_bm_data { 2601668f811SArun Murthy int temp_under; 2611668f811SArun Murthy int temp_low; 2621668f811SArun Murthy int temp_high; 2631668f811SArun Murthy int temp_over; 2641668f811SArun Murthy int temp_now; 2651668f811SArun Murthy int temp_interval_chg; 2661668f811SArun Murthy int temp_interval_nochg; 2671668f811SArun Murthy int main_safety_tmr_h; 2681668f811SArun Murthy int usb_safety_tmr_h; 2691668f811SArun Murthy int bkup_bat_v; 2701668f811SArun Murthy int bkup_bat_i; 27197034a1eSLee Jones bool autopower_cfg; 27297034a1eSLee Jones bool ac_enabled; 27397034a1eSLee Jones bool usb_enabled; 2741668f811SArun Murthy bool no_maintenance; 275ea402401SMarcus Cooper bool capacity_scaling; 2761668f811SArun Murthy bool chg_unknown_bat; 2771668f811SArun Murthy bool enable_overshoot; 2781668f811SArun Murthy bool auto_trig; 2791668f811SArun Murthy enum abx500_adc_therm adc_therm; 2801668f811SArun Murthy int fg_res; 2811668f811SArun Murthy int n_btypes; 2821668f811SArun Murthy int batt_id; 2831668f811SArun Murthy int interval_charging; 2841668f811SArun Murthy int interval_not_charging; 2851668f811SArun Murthy int temp_hysteresis; 2861668f811SArun Murthy int gnd_lift_resistance; 287861a30daSLee Jones int n_chg_out_curr; 288861a30daSLee Jones int n_chg_in_curr; 289861a30daSLee Jones int *chg_output_curr; 290861a30daSLee Jones int *chg_input_curr; 2911668f811SArun Murthy const struct abx500_maxim_parameters *maxi; 2921668f811SArun Murthy const struct abx500_bm_capacity_levels *cap_levels; 293e0f1abebSRajanikanth H.V struct abx500_battery_type *bat_type; 2941668f811SArun Murthy const struct abx500_bm_charger_parameters *chg_params; 2951668f811SArun Murthy const struct abx500_fg_parameters *fg_params; 2961668f811SArun Murthy }; 2971668f811SArun Murthy 298e0f1abebSRajanikanth H.V enum { 299e0f1abebSRajanikanth H.V NTC_EXTERNAL = 0, 300e0f1abebSRajanikanth H.V NTC_INTERNAL, 3011668f811SArun Murthy }; 3021668f811SArun Murthy 303b0284de0SLee Jones int ab8500_bm_of_probe(struct device *dev, 304e0f1abebSRajanikanth H.V struct device_node *np, 30523a04f9fSLee Jones struct abx500_bm_data *bm); 3061668f811SArun Murthy 307fa661258SMattias Wallin int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, 308fa661258SMattias Wallin u8 value); 309fa661258SMattias Wallin int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg, 310fa661258SMattias Wallin u8 *value); 311fa661258SMattias Wallin int abx500_get_register_page_interruptible(struct device *dev, u8 bank, 312fa661258SMattias Wallin u8 first_reg, u8 *regvals, u8 numregs); 313fa661258SMattias Wallin int abx500_set_register_page_interruptible(struct device *dev, u8 bank, 314fa661258SMattias Wallin u8 first_reg, u8 *regvals, u8 numregs); 315fa661258SMattias Wallin /** 316fa661258SMattias Wallin * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a 317fa661258SMattias Wallin * target register 318fa661258SMattias Wallin * 319fa661258SMattias Wallin * @dev: The AB sub device. 320fa661258SMattias Wallin * @bank: The i2c bank number. 321fa661258SMattias Wallin * @bitmask: The bit mask to use. 322fa661258SMattias Wallin * @bitvalues: The new bit values. 323fa661258SMattias Wallin * 324fa661258SMattias Wallin * Updates the value of an AB register: 325fa661258SMattias Wallin * value -> ((value & ~bitmask) | (bitvalues & bitmask)) 326fa661258SMattias Wallin */ 327fa661258SMattias Wallin int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank, 328fa661258SMattias Wallin u8 reg, u8 bitmask, u8 bitvalues); 329fa661258SMattias Wallin int abx500_get_chip_id(struct device *dev); 330fa661258SMattias Wallin int abx500_event_registers_startup_state_get(struct device *dev, u8 *event); 331fa661258SMattias Wallin int abx500_startup_irq_enabled(struct device *dev, unsigned int irq); 332fa661258SMattias Wallin 333fa661258SMattias Wallin struct abx500_ops { 334fa661258SMattias Wallin int (*get_chip_id) (struct device *); 335fa661258SMattias Wallin int (*get_register) (struct device *, u8, u8, u8 *); 336fa661258SMattias Wallin int (*set_register) (struct device *, u8, u8, u8); 337fa661258SMattias Wallin int (*get_register_page) (struct device *, u8, u8, u8 *, u8); 338fa661258SMattias Wallin int (*set_register_page) (struct device *, u8, u8, u8 *, u8); 339fa661258SMattias Wallin int (*mask_and_set_register) (struct device *, u8, u8, u8, u8); 340fa661258SMattias Wallin int (*event_registers_startup_state_get) (struct device *, u8 *); 341fa661258SMattias Wallin int (*startup_irq_enabled) (struct device *, unsigned int); 342e0f4fec0SMian Yousaf Kaukab void (*dump_all_banks) (struct device *); 343fa661258SMattias Wallin }; 344fa661258SMattias Wallin 345fa661258SMattias Wallin int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops); 346c6252e9cSMark Brown void abx500_remove_ops(struct device *dev); 347812f9e9dSLinus Walleij #endif 348