1812f9e9dSLinus Walleij /* 2812f9e9dSLinus Walleij * Copyright (C) 2007-2009 ST-Ericsson AB 3812f9e9dSLinus Walleij * License terms: GNU General Public License (GPL) version 2 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. 481668f811SArun Murthy * @temp: battery pack temperature in Celcius 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 921668f811SArun Murthy */ 931668f811SArun Murthy struct abx500_fg_parameters { 941668f811SArun Murthy int recovery_sleep_timer; 951668f811SArun Murthy int recovery_total_time; 961668f811SArun Murthy int init_timer; 971668f811SArun Murthy int init_discard_time; 981668f811SArun Murthy int init_total_time; 991668f811SArun Murthy int high_curr_time; 1001668f811SArun Murthy int accu_charging; 1011668f811SArun Murthy int accu_high_curr; 1021668f811SArun Murthy int high_curr_threshold; 1031668f811SArun Murthy int lowbat_threshold; 1041668f811SArun Murthy int overbat_threshold; 1051668f811SArun Murthy int battok_falling_th_sel0; 1061668f811SArun Murthy int battok_raising_th_sel1; 1071668f811SArun Murthy int user_cap_limit; 1081668f811SArun Murthy int maint_thres; 1091668f811SArun Murthy }; 1101668f811SArun Murthy 1111668f811SArun Murthy /** 1121668f811SArun Murthy * struct abx500_charger_maximization - struct used by the board config. 1131668f811SArun Murthy * @use_maxi: Enable maximization for this battery type 1141668f811SArun Murthy * @maxi_chg_curr: Maximum charger current allowed 1151668f811SArun Murthy * @maxi_wait_cycles: cycles to wait before setting charger current 1161668f811SArun Murthy * @charger_curr_step delta between two charger current settings (mA) 1171668f811SArun Murthy */ 1181668f811SArun Murthy struct abx500_maxim_parameters { 1191668f811SArun Murthy bool ena_maxi; 1201668f811SArun Murthy int chg_curr; 1211668f811SArun Murthy int wait_cycles; 1221668f811SArun Murthy int charger_curr_step; 1231668f811SArun Murthy }; 1241668f811SArun Murthy 1251668f811SArun Murthy /** 1261668f811SArun Murthy * struct abx500_battery_type - different batteries supported 1271668f811SArun Murthy * @name: battery technology 1281668f811SArun Murthy * @resis_high: battery upper resistance limit 1291668f811SArun Murthy * @resis_low: battery lower resistance limit 1301668f811SArun Murthy * @charge_full_design: Maximum battery capacity in mAh 1311668f811SArun Murthy * @nominal_voltage: Nominal voltage of the battery in mV 1321668f811SArun Murthy * @termination_vol: max voltage upto which battery can be charged 1331668f811SArun Murthy * @termination_curr battery charging termination current in mA 1341668f811SArun Murthy * @recharge_vol battery voltage limit that will trigger a new 1351668f811SArun Murthy * full charging cycle in the case where maintenan- 1361668f811SArun Murthy * -ce charging has been disabled 1371668f811SArun Murthy * @normal_cur_lvl: charger current in normal state in mA 1381668f811SArun Murthy * @normal_vol_lvl: charger voltage in normal state in mV 1391668f811SArun Murthy * @maint_a_cur_lvl: charger current in maintenance A state in mA 1401668f811SArun Murthy * @maint_a_vol_lvl: charger voltage in maintenance A state in mV 1411668f811SArun Murthy * @maint_a_chg_timer_h: charge time in maintenance A state 1421668f811SArun Murthy * @maint_b_cur_lvl: charger current in maintenance B state in mA 1431668f811SArun Murthy * @maint_b_vol_lvl: charger voltage in maintenance B state in mV 1441668f811SArun Murthy * @maint_b_chg_timer_h: charge time in maintenance B state 1451668f811SArun Murthy * @low_high_cur_lvl: charger current in temp low/high state in mA 1461668f811SArun Murthy * @low_high_vol_lvl: charger voltage in temp low/high state in mV' 1471668f811SArun Murthy * @battery_resistance: battery inner resistance in mOhm. 1481668f811SArun Murthy * @n_r_t_tbl_elements: number of elements in r_to_t_tbl 1491668f811SArun Murthy * @r_to_t_tbl: table containing resistance to temp points 1501668f811SArun Murthy * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl 1511668f811SArun Murthy * @v_to_cap_tbl: Voltage to capacity (in %) table 1521668f811SArun Murthy * @n_batres_tbl_elements number of elements in the batres_tbl 1531668f811SArun Murthy * @batres_tbl battery internal resistance vs temperature table 1541668f811SArun Murthy */ 1551668f811SArun Murthy struct abx500_battery_type { 1561668f811SArun Murthy int name; 1571668f811SArun Murthy int resis_high; 1581668f811SArun Murthy int resis_low; 1591668f811SArun Murthy int charge_full_design; 1601668f811SArun Murthy int nominal_voltage; 1611668f811SArun Murthy int termination_vol; 1621668f811SArun Murthy int termination_curr; 1631668f811SArun Murthy int recharge_vol; 1641668f811SArun Murthy int normal_cur_lvl; 1651668f811SArun Murthy int normal_vol_lvl; 1661668f811SArun Murthy int maint_a_cur_lvl; 1671668f811SArun Murthy int maint_a_vol_lvl; 1681668f811SArun Murthy int maint_a_chg_timer_h; 1691668f811SArun Murthy int maint_b_cur_lvl; 1701668f811SArun Murthy int maint_b_vol_lvl; 1711668f811SArun Murthy int maint_b_chg_timer_h; 1721668f811SArun Murthy int low_high_cur_lvl; 1731668f811SArun Murthy int low_high_vol_lvl; 1741668f811SArun Murthy int battery_resistance; 1751668f811SArun Murthy int n_temp_tbl_elements; 1761668f811SArun Murthy struct abx500_res_to_temp *r_to_t_tbl; 1771668f811SArun Murthy int n_v_cap_tbl_elements; 1781668f811SArun Murthy struct abx500_v_to_cap *v_to_cap_tbl; 1791668f811SArun Murthy int n_batres_tbl_elements; 1801668f811SArun Murthy struct batres_vs_temp *batres_tbl; 1811668f811SArun Murthy }; 1821668f811SArun Murthy 1831668f811SArun Murthy /** 1841668f811SArun Murthy * struct abx500_bm_capacity_levels - abx500 capacity level data 1851668f811SArun Murthy * @critical: critical capacity level in percent 1861668f811SArun Murthy * @low: low capacity level in percent 1871668f811SArun Murthy * @normal: normal capacity level in percent 1881668f811SArun Murthy * @high: high capacity level in percent 1891668f811SArun Murthy * @full: full capacity level in percent 1901668f811SArun Murthy */ 1911668f811SArun Murthy struct abx500_bm_capacity_levels { 1921668f811SArun Murthy int critical; 1931668f811SArun Murthy int low; 1941668f811SArun Murthy int normal; 1951668f811SArun Murthy int high; 1961668f811SArun Murthy int full; 1971668f811SArun Murthy }; 1981668f811SArun Murthy 1991668f811SArun Murthy /** 2001668f811SArun Murthy * struct abx500_bm_charger_parameters - Charger specific parameters 2011668f811SArun Murthy * @usb_volt_max: maximum allowed USB charger voltage in mV 2021668f811SArun Murthy * @usb_curr_max: maximum allowed USB charger current in mA 2031668f811SArun Murthy * @ac_volt_max: maximum allowed AC charger voltage in mV 2041668f811SArun Murthy * @ac_curr_max: maximum allowed AC charger current in mA 2051668f811SArun Murthy */ 2061668f811SArun Murthy struct abx500_bm_charger_parameters { 2071668f811SArun Murthy int usb_volt_max; 2081668f811SArun Murthy int usb_curr_max; 2091668f811SArun Murthy int ac_volt_max; 2101668f811SArun Murthy int ac_curr_max; 2111668f811SArun Murthy }; 2121668f811SArun Murthy 2131668f811SArun Murthy /** 2141668f811SArun Murthy * struct abx500_bm_data - abx500 battery management data 2151668f811SArun Murthy * @temp_under under this temp, charging is stopped 2161668f811SArun Murthy * @temp_low between this temp and temp_under charging is reduced 2171668f811SArun Murthy * @temp_high between this temp and temp_over charging is reduced 2181668f811SArun Murthy * @temp_over over this temp, charging is stopped 2191668f811SArun Murthy * @temp_now present battery temperature 2201668f811SArun Murthy * @temp_interval_chg temperature measurement interval in s when charging 2211668f811SArun Murthy * @temp_interval_nochg temperature measurement interval in s when not charging 2221668f811SArun Murthy * @main_safety_tmr_h safety timer for main charger 2231668f811SArun Murthy * @usb_safety_tmr_h safety timer for usb charger 2241668f811SArun Murthy * @bkup_bat_v voltage which we charge the backup battery with 2251668f811SArun Murthy * @bkup_bat_i current which we charge the backup battery with 2261668f811SArun Murthy * @no_maintenance indicates that maintenance charging is disabled 2271668f811SArun Murthy * @abx500_adc_therm placement of thermistor, batctrl or battemp adc 2281668f811SArun Murthy * @chg_unknown_bat flag to enable charging of unknown batteries 2291668f811SArun Murthy * @enable_overshoot flag to enable VBAT overshoot control 2301668f811SArun Murthy * @auto_trig flag to enable auto adc trigger 2311668f811SArun Murthy * @fg_res resistance of FG resistor in 0.1mOhm 2321668f811SArun Murthy * @n_btypes number of elements in array bat_type 2331668f811SArun Murthy * @batt_id index of the identified battery in array bat_type 2341668f811SArun Murthy * @interval_charging charge alg cycle period time when charging (sec) 2351668f811SArun Murthy * @interval_not_charging charge alg cycle period time when not charging (sec) 2361668f811SArun Murthy * @temp_hysteresis temperature hysteresis 2371668f811SArun Murthy * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm) 2381668f811SArun Murthy * @maxi: maximization parameters 2391668f811SArun Murthy * @cap_levels capacity in percent for the different capacity levels 2401668f811SArun Murthy * @bat_type table of supported battery types 2411668f811SArun Murthy * @chg_params charger parameters 2421668f811SArun Murthy * @fg_params fuel gauge parameters 2431668f811SArun Murthy */ 2441668f811SArun Murthy struct abx500_bm_data { 2451668f811SArun Murthy int temp_under; 2461668f811SArun Murthy int temp_low; 2471668f811SArun Murthy int temp_high; 2481668f811SArun Murthy int temp_over; 2491668f811SArun Murthy int temp_now; 2501668f811SArun Murthy int temp_interval_chg; 2511668f811SArun Murthy int temp_interval_nochg; 2521668f811SArun Murthy int main_safety_tmr_h; 2531668f811SArun Murthy int usb_safety_tmr_h; 2541668f811SArun Murthy int bkup_bat_v; 2551668f811SArun Murthy int bkup_bat_i; 2561668f811SArun Murthy bool no_maintenance; 2571668f811SArun Murthy bool chg_unknown_bat; 2581668f811SArun Murthy bool enable_overshoot; 2591668f811SArun Murthy bool auto_trig; 2601668f811SArun Murthy enum abx500_adc_therm adc_therm; 2611668f811SArun Murthy int fg_res; 2621668f811SArun Murthy int n_btypes; 2631668f811SArun Murthy int batt_id; 2641668f811SArun Murthy int interval_charging; 2651668f811SArun Murthy int interval_not_charging; 2661668f811SArun Murthy int temp_hysteresis; 2671668f811SArun Murthy int gnd_lift_resistance; 2681668f811SArun Murthy const struct abx500_maxim_parameters *maxi; 2691668f811SArun Murthy const struct abx500_bm_capacity_levels *cap_levels; 270e0f1abebSRajanikanth H.V struct abx500_battery_type *bat_type; 2711668f811SArun Murthy const struct abx500_bm_charger_parameters *chg_params; 2721668f811SArun Murthy const struct abx500_fg_parameters *fg_params; 2731668f811SArun Murthy }; 2741668f811SArun Murthy 275e0f1abebSRajanikanth H.V extern struct abx500_bm_data ab8500_bm_data; 2761668f811SArun Murthy 277e0f1abebSRajanikanth H.V struct abx500_bmdevs_plat_data { 2781668f811SArun Murthy char **supplied_to; 2791668f811SArun Murthy size_t num_supplicants; 2801668f811SArun Murthy bool autopower_cfg; 2811668f811SArun Murthy }; 2821668f811SArun Murthy 283e0f1abebSRajanikanth H.V enum { 284e0f1abebSRajanikanth H.V NTC_EXTERNAL = 0, 285e0f1abebSRajanikanth H.V NTC_INTERNAL, 2861668f811SArun Murthy }; 2871668f811SArun Murthy 288e0f1abebSRajanikanth H.V int bmdevs_of_probe(struct device *dev, 289e0f1abebSRajanikanth H.V struct device_node *np, 290e0f1abebSRajanikanth H.V struct abx500_bm_data **battery); 2911668f811SArun Murthy 292fa661258SMattias Wallin int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, 293fa661258SMattias Wallin u8 value); 294fa661258SMattias Wallin int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg, 295fa661258SMattias Wallin u8 *value); 296fa661258SMattias Wallin int abx500_get_register_page_interruptible(struct device *dev, u8 bank, 297fa661258SMattias Wallin u8 first_reg, u8 *regvals, u8 numregs); 298fa661258SMattias Wallin int abx500_set_register_page_interruptible(struct device *dev, u8 bank, 299fa661258SMattias Wallin u8 first_reg, u8 *regvals, u8 numregs); 300fa661258SMattias Wallin /** 301fa661258SMattias Wallin * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a 302fa661258SMattias Wallin * target register 303fa661258SMattias Wallin * 304fa661258SMattias Wallin * @dev: The AB sub device. 305fa661258SMattias Wallin * @bank: The i2c bank number. 306fa661258SMattias Wallin * @bitmask: The bit mask to use. 307fa661258SMattias Wallin * @bitvalues: The new bit values. 308fa661258SMattias Wallin * 309fa661258SMattias Wallin * Updates the value of an AB register: 310fa661258SMattias Wallin * value -> ((value & ~bitmask) | (bitvalues & bitmask)) 311fa661258SMattias Wallin */ 312fa661258SMattias Wallin int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank, 313fa661258SMattias Wallin u8 reg, u8 bitmask, u8 bitvalues); 314fa661258SMattias Wallin int abx500_get_chip_id(struct device *dev); 315fa661258SMattias Wallin int abx500_event_registers_startup_state_get(struct device *dev, u8 *event); 316fa661258SMattias Wallin int abx500_startup_irq_enabled(struct device *dev, unsigned int irq); 317fa661258SMattias Wallin 318fa661258SMattias Wallin struct abx500_ops { 319fa661258SMattias Wallin int (*get_chip_id) (struct device *); 320fa661258SMattias Wallin int (*get_register) (struct device *, u8, u8, u8 *); 321fa661258SMattias Wallin int (*set_register) (struct device *, u8, u8, u8); 322fa661258SMattias Wallin int (*get_register_page) (struct device *, u8, u8, u8 *, u8); 323fa661258SMattias Wallin int (*set_register_page) (struct device *, u8, u8, u8 *, u8); 324fa661258SMattias Wallin int (*mask_and_set_register) (struct device *, u8, u8, u8, u8); 325fa661258SMattias Wallin int (*event_registers_startup_state_get) (struct device *, u8 *); 326fa661258SMattias Wallin int (*startup_irq_enabled) (struct device *, unsigned int); 327fa661258SMattias Wallin }; 328fa661258SMattias Wallin 329fa661258SMattias Wallin int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops); 330c6252e9cSMark Brown void abx500_remove_ops(struct device *dev); 331812f9e9dSLinus Walleij #endif 332