Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2009 ST-Ericsson AB |
| 3 | * License terms: GNU General Public License (GPL) version 2 |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 4 | * |
| 5 | * ABX500 core access functions. |
Marcus Cooper | 0fd0013 | 2012-08-10 10:32:35 +0200 | [diff] [blame] | 6 | * The abx500 interface is used for the Analog Baseband chips. |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 7 | * |
| 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 Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
Linus Walleij | d619bc1 | 2009-09-09 11:31:00 +0200 | [diff] [blame] | 14 | #include <linux/regulator/machine.h> |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 15 | |
Paul Gortmaker | 313162d | 2012-01-30 11:46:54 -0500 | [diff] [blame] | 16 | struct device; |
| 17 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 18 | #ifndef MFD_ABX500_H |
| 19 | #define MFD_ABX500_H |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 20 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 21 | /** |
| 22 | * struct abx500_init_setting |
| 23 | * Initial value of the registers for driver to use during setup. |
| 24 | */ |
| 25 | struct abx500_init_settings { |
| 26 | u8 bank; |
| 27 | u8 reg; |
| 28 | u8 setting; |
| 29 | }; |
| 30 | |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 31 | /* 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 | */ |
| 39 | enum 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 | */ |
| 51 | struct 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 | */ |
| 61 | struct abx500_v_to_cap { |
| 62 | int voltage; |
| 63 | int capacity; |
| 64 | }; |
| 65 | |
| 66 | /* Forward declaration */ |
| 67 | struct 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 |
Lee Jones | 93ff722 | 2012-05-31 16:16:36 +0200 | [diff] [blame] | 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 |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 97 | */ |
| 98 | struct abx500_fg_parameters { |
| 99 | int recovery_sleep_timer; |
| 100 | int recovery_total_time; |
| 101 | int init_timer; |
| 102 | int init_discard_time; |
| 103 | int init_total_time; |
| 104 | int high_curr_time; |
| 105 | int accu_charging; |
| 106 | int accu_high_curr; |
| 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; |
| 112 | int user_cap_limit; |
| 113 | int maint_thres; |
Lee Jones | 93ff722 | 2012-05-31 16:16:36 +0200 | [diff] [blame] | 114 | bool pcut_enable; |
| 115 | u8 pcut_max_time; |
| 116 | u8 pcut_flag_time; |
| 117 | u8 pcut_max_restart; |
| 118 | u8 pcut_debounce_time; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | /** |
| 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) |
| 127 | */ |
| 128 | struct abx500_maxim_parameters { |
| 129 | bool ena_maxi; |
| 130 | int chg_curr; |
| 131 | int wait_cycles; |
| 132 | int charger_curr_step; |
| 133 | }; |
| 134 | |
| 135 | /** |
| 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 |
Marcus Cooper | ea40240 | 2013-01-11 13:12:54 +0000 | [diff] [blame] | 144 | * @recharge_cap battery capacity limit that will trigger a new |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 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 |
| 164 | */ |
| 165 | struct abx500_battery_type { |
| 166 | int name; |
| 167 | int resis_high; |
| 168 | int resis_low; |
| 169 | int charge_full_design; |
| 170 | int nominal_voltage; |
| 171 | int termination_vol; |
| 172 | int termination_curr; |
Marcus Cooper | ea40240 | 2013-01-11 13:12:54 +0000 | [diff] [blame] | 173 | int recharge_cap; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 174 | int normal_cur_lvl; |
| 175 | int normal_vol_lvl; |
| 176 | int maint_a_cur_lvl; |
| 177 | int maint_a_vol_lvl; |
| 178 | int maint_a_chg_timer_h; |
| 179 | int maint_b_cur_lvl; |
| 180 | int maint_b_vol_lvl; |
| 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; |
Hongbo Zhang | 2c89940 | 2013-04-03 20:18:10 +0800 | [diff] [blame] | 186 | const struct abx500_res_to_temp *r_to_t_tbl; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 187 | int n_v_cap_tbl_elements; |
Hongbo Zhang | 2c89940 | 2013-04-03 20:18:10 +0800 | [diff] [blame] | 188 | const struct abx500_v_to_cap *v_to_cap_tbl; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 189 | int n_batres_tbl_elements; |
Hongbo Zhang | 2c89940 | 2013-04-03 20:18:10 +0800 | [diff] [blame] | 190 | const struct batres_vs_temp *batres_tbl; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | /** |
| 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 |
| 200 | */ |
| 201 | struct abx500_bm_capacity_levels { |
| 202 | int critical; |
| 203 | int low; |
| 204 | int normal; |
| 205 | int high; |
| 206 | int full; |
| 207 | }; |
| 208 | |
| 209 | /** |
| 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 |
| 215 | */ |
| 216 | struct abx500_bm_charger_parameters { |
| 217 | int usb_volt_max; |
| 218 | int usb_curr_max; |
| 219 | int ac_volt_max; |
| 220 | int ac_curr_max; |
| 221 | }; |
| 222 | |
| 223 | /** |
| 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 |
Marcus Cooper | ea40240 | 2013-01-11 13:12:54 +0000 | [diff] [blame] | 237 | * @capacity_scaling indicates whether capacity scaling is to be used |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 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) |
Lee Jones | 861a30d | 2012-08-29 20:36:51 +0800 | [diff] [blame] | 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 |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 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 |
| 258 | */ |
| 259 | struct abx500_bm_data { |
| 260 | int temp_under; |
| 261 | int temp_low; |
| 262 | int temp_high; |
| 263 | int temp_over; |
| 264 | int temp_now; |
| 265 | int temp_interval_chg; |
| 266 | int temp_interval_nochg; |
| 267 | int main_safety_tmr_h; |
| 268 | int usb_safety_tmr_h; |
| 269 | int bkup_bat_v; |
| 270 | int bkup_bat_i; |
Lee Jones | 97034a1 | 2013-01-17 16:08:42 +0000 | [diff] [blame] | 271 | bool autopower_cfg; |
| 272 | bool ac_enabled; |
| 273 | bool usb_enabled; |
Lee Jones | db43e6c | 2013-02-14 12:39:15 +0000 | [diff] [blame] | 274 | bool usb_power_path; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 275 | bool no_maintenance; |
Marcus Cooper | ea40240 | 2013-01-11 13:12:54 +0000 | [diff] [blame] | 276 | bool capacity_scaling; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 277 | bool chg_unknown_bat; |
| 278 | bool enable_overshoot; |
| 279 | bool auto_trig; |
| 280 | enum abx500_adc_therm adc_therm; |
| 281 | int fg_res; |
| 282 | int n_btypes; |
| 283 | int batt_id; |
| 284 | int interval_charging; |
| 285 | int interval_not_charging; |
| 286 | int temp_hysteresis; |
| 287 | int gnd_lift_resistance; |
Lee Jones | 861a30d | 2012-08-29 20:36:51 +0800 | [diff] [blame] | 288 | int n_chg_out_curr; |
| 289 | int n_chg_in_curr; |
| 290 | int *chg_output_curr; |
| 291 | int *chg_input_curr; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 292 | const struct abx500_maxim_parameters *maxi; |
| 293 | const struct abx500_bm_capacity_levels *cap_levels; |
Rajanikanth H.V | e0f1abe | 2012-11-18 18:45:41 -0800 | [diff] [blame] | 294 | struct abx500_battery_type *bat_type; |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 295 | const struct abx500_bm_charger_parameters *chg_params; |
| 296 | const struct abx500_fg_parameters *fg_params; |
| 297 | }; |
| 298 | |
Rajanikanth H.V | e0f1abe | 2012-11-18 18:45:41 -0800 | [diff] [blame] | 299 | enum { |
| 300 | NTC_EXTERNAL = 0, |
| 301 | NTC_INTERNAL, |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 302 | }; |
| 303 | |
Lee Jones | b0284de | 2012-11-30 10:09:42 +0000 | [diff] [blame] | 304 | int ab8500_bm_of_probe(struct device *dev, |
| 305 | struct device_node *np, |
Lee Jones | 23a04f9 | 2012-11-29 15:08:41 +0000 | [diff] [blame] | 306 | struct abx500_bm_data *bm); |
Arun Murthy | 1668f81 | 2012-02-29 21:54:25 +0530 | [diff] [blame] | 307 | |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 308 | int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 309 | u8 value); |
| 310 | int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg, |
| 311 | u8 *value); |
| 312 | int abx500_get_register_page_interruptible(struct device *dev, u8 bank, |
| 313 | u8 first_reg, u8 *regvals, u8 numregs); |
| 314 | int abx500_set_register_page_interruptible(struct device *dev, u8 bank, |
| 315 | u8 first_reg, u8 *regvals, u8 numregs); |
| 316 | /** |
| 317 | * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a |
| 318 | * target register |
| 319 | * |
| 320 | * @dev: The AB sub device. |
| 321 | * @bank: The i2c bank number. |
| 322 | * @bitmask: The bit mask to use. |
| 323 | * @bitvalues: The new bit values. |
| 324 | * |
| 325 | * Updates the value of an AB register: |
| 326 | * value -> ((value & ~bitmask) | (bitvalues & bitmask)) |
| 327 | */ |
| 328 | int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank, |
| 329 | u8 reg, u8 bitmask, u8 bitvalues); |
| 330 | int abx500_get_chip_id(struct device *dev); |
| 331 | int abx500_event_registers_startup_state_get(struct device *dev, u8 *event); |
| 332 | int abx500_startup_irq_enabled(struct device *dev, unsigned int irq); |
Mian Yousaf Kaukab | e0f4fec | 2012-01-27 11:22:16 +0100 | [diff] [blame] | 333 | void abx500_dump_all_banks(void); |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 334 | |
| 335 | struct abx500_ops { |
| 336 | int (*get_chip_id) (struct device *); |
| 337 | int (*get_register) (struct device *, u8, u8, u8 *); |
| 338 | int (*set_register) (struct device *, u8, u8, u8); |
| 339 | int (*get_register_page) (struct device *, u8, u8, u8 *, u8); |
| 340 | int (*set_register_page) (struct device *, u8, u8, u8 *, u8); |
| 341 | int (*mask_and_set_register) (struct device *, u8, u8, u8, u8); |
| 342 | int (*event_registers_startup_state_get) (struct device *, u8 *); |
| 343 | int (*startup_irq_enabled) (struct device *, unsigned int); |
Mian Yousaf Kaukab | e0f4fec | 2012-01-27 11:22:16 +0100 | [diff] [blame] | 344 | void (*dump_all_banks) (struct device *); |
Mattias Wallin | fa66125 | 2010-05-01 18:26:20 +0200 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops); |
Mark Brown | c6252e9 | 2010-09-22 14:58:30 +0100 | [diff] [blame] | 348 | void abx500_remove_ops(struct device *dev); |
Linus Walleij | 14fa569 | 2009-05-21 23:17:06 +0200 | [diff] [blame] | 349 | #endif |