0001
0002 #include <linux/export.h>
0003 #include <linux/power_supply.h>
0004 #include <linux/of.h>
0005
0006 #include "ab8500-bm.h"
0007
0008
0009 #define AB8500_TEMP_UNDER 3
0010
0011 #define AB8500_TEMP_LOW 8
0012
0013 #define AB8500_TEMP_HIGH 43
0014
0015 #define AB8500_TEMP_OVER 48
0016
0017 #define AB8500_TEMP_HYSTERESIS 3
0018
0019 static struct power_supply_battery_ocv_table ocv_cap_tbl[] = {
0020 { .ocv = 4186000, .capacity = 100},
0021 { .ocv = 4163000, .capacity = 99},
0022 { .ocv = 4114000, .capacity = 95},
0023 { .ocv = 4068000, .capacity = 90},
0024 { .ocv = 3990000, .capacity = 80},
0025 { .ocv = 3926000, .capacity = 70},
0026 { .ocv = 3898000, .capacity = 65},
0027 { .ocv = 3866000, .capacity = 60},
0028 { .ocv = 3833000, .capacity = 55},
0029 { .ocv = 3812000, .capacity = 50},
0030 { .ocv = 3787000, .capacity = 40},
0031 { .ocv = 3768000, .capacity = 30},
0032 { .ocv = 3747000, .capacity = 25},
0033 { .ocv = 3730000, .capacity = 20},
0034 { .ocv = 3705000, .capacity = 15},
0035 { .ocv = 3699000, .capacity = 14},
0036 { .ocv = 3684000, .capacity = 12},
0037 { .ocv = 3672000, .capacity = 9},
0038 { .ocv = 3657000, .capacity = 7},
0039 { .ocv = 3638000, .capacity = 6},
0040 { .ocv = 3556000, .capacity = 4},
0041 { .ocv = 3424000, .capacity = 2},
0042 { .ocv = 3317000, .capacity = 1},
0043 { .ocv = 3094000, .capacity = 0},
0044 };
0045
0046
0047
0048
0049
0050
0051 static struct power_supply_resistance_temp_table temp_to_batres_tbl_thermistor[] = {
0052 { .temp = 40, .resistance = 40 },
0053 { .temp = 30, .resistance = 45 },
0054 { .temp = 20, .resistance = 55 },
0055 { .temp = 10, .resistance = 77 },
0056 { .temp = 00, .resistance = 108 },
0057 { .temp = -10, .resistance = 158 },
0058 { .temp = -20, .resistance = 198 },
0059 };
0060
0061 static struct power_supply_maintenance_charge_table ab8500_maint_charg_table[] = {
0062 {
0063
0064 .charge_current_max_ua = 400000,
0065 .charge_voltage_max_uv = 4050000,
0066 .charge_safety_timer_minutes = 60*60,
0067 },
0068 {
0069
0070 .charge_current_max_ua = 400000,
0071 .charge_voltage_max_uv = 4000000,
0072 .charge_safety_timer_minutes = 200*60,
0073 }
0074 };
0075
0076 static const struct ab8500_bm_capacity_levels cap_levels = {
0077 .critical = 2,
0078 .low = 10,
0079 .normal = 70,
0080 .high = 95,
0081 .full = 100,
0082 };
0083
0084 static const struct ab8500_fg_parameters fg = {
0085 .recovery_sleep_timer = 10,
0086 .recovery_total_time = 100,
0087 .init_timer = 1,
0088 .init_discard_time = 5,
0089 .init_total_time = 40,
0090 .high_curr_time = 60,
0091 .accu_charging = 30,
0092 .accu_high_curr = 30,
0093 .high_curr_threshold_ua = 50000,
0094 .lowbat_threshold_uv = 3100000,
0095 .battok_falling_th_sel0 = 2860,
0096 .battok_raising_th_sel1 = 2860,
0097 .maint_thres = 95,
0098 .user_cap_limit = 15,
0099 .pcut_enable = 1,
0100 .pcut_max_time = 127,
0101 .pcut_flag_time = 112,
0102 .pcut_max_restart = 15,
0103 .pcut_debounce_time = 2,
0104 };
0105
0106 static const struct ab8500_maxim_parameters ab8500_maxi_params = {
0107 .ena_maxi = true,
0108 .chg_curr_ua = 910000,
0109 .wait_cycles = 10,
0110 .charger_curr_step_ua = 100000,
0111 };
0112
0113 static const struct ab8500_bm_charger_parameters chg = {
0114 .usb_volt_max_uv = 5500000,
0115 .usb_curr_max_ua = 1500000,
0116 .ac_volt_max_uv = 7500000,
0117 .ac_curr_max_ua = 1500000,
0118 };
0119
0120
0121 struct ab8500_bm_data ab8500_bm_data = {
0122 .main_safety_tmr_h = 4,
0123 .temp_interval_chg = 20,
0124 .temp_interval_nochg = 120,
0125 .usb_safety_tmr_h = 4,
0126 .bkup_bat_v = BUP_VCH_SEL_2P6V,
0127 .bkup_bat_i = BUP_ICH_SEL_150UA,
0128 .capacity_scaling = false,
0129 .chg_unknown_bat = false,
0130 .enable_overshoot = false,
0131 .fg_res = 100,
0132 .cap_levels = &cap_levels,
0133 .interval_charging = 5,
0134 .interval_not_charging = 120,
0135 .maxi = &ab8500_maxi_params,
0136 .chg_params = &chg,
0137 .fg_params = &fg,
0138 };
0139
0140 int ab8500_bm_of_probe(struct power_supply *psy,
0141 struct ab8500_bm_data *bm)
0142 {
0143 struct power_supply_battery_info *bi;
0144 struct device *dev = &psy->dev;
0145 int ret;
0146
0147 ret = power_supply_get_battery_info(psy, &bm->bi);
0148 if (ret) {
0149 dev_err(dev, "cannot retrieve battery info\n");
0150 return ret;
0151 }
0152 bi = bm->bi;
0153
0154
0155 if (bi->charge_full_design_uah < 0)
0156
0157 bi->charge_full_design_uah = 612000;
0158
0159
0160
0161
0162
0163 if ((bi->voltage_min_design_uv < 0) ||
0164 (bi->voltage_max_design_uv < 0)) {
0165
0166 bi->voltage_min_design_uv = 3700000;
0167
0168 bi->voltage_max_design_uv = 4050000;
0169 }
0170
0171 if (bi->constant_charge_current_max_ua < 0)
0172 bi->constant_charge_current_max_ua = 400000;
0173
0174 if (bi->constant_charge_voltage_max_uv < 0)
0175 bi->constant_charge_voltage_max_uv = 4100000;
0176
0177 if (bi->charge_term_current_ua)
0178
0179 bi->charge_term_current_ua = 200000;
0180
0181 if (!bi->maintenance_charge || !bi->maintenance_charge_size) {
0182 bi->maintenance_charge = ab8500_maint_charg_table;
0183 bi->maintenance_charge_size = ARRAY_SIZE(ab8500_maint_charg_table);
0184 }
0185
0186 if (bi->alert_low_temp_charge_current_ua < 0 ||
0187 bi->alert_low_temp_charge_voltage_uv < 0)
0188 {
0189 bi->alert_low_temp_charge_current_ua = 300000;
0190 bi->alert_low_temp_charge_voltage_uv = 4000000;
0191 }
0192 if (bi->alert_high_temp_charge_current_ua < 0 ||
0193 bi->alert_high_temp_charge_voltage_uv < 0)
0194 {
0195 bi->alert_high_temp_charge_current_ua = 300000;
0196 bi->alert_high_temp_charge_voltage_uv = 4000000;
0197 }
0198
0199
0200
0201
0202
0203 if ((bi->factory_internal_resistance_uohm < 0) ||
0204 !bi->resist_table) {
0205 bi->factory_internal_resistance_uohm = 300000;
0206 bi->resist_table = temp_to_batres_tbl_thermistor;
0207 bi->resist_table_size = ARRAY_SIZE(temp_to_batres_tbl_thermistor);
0208 }
0209
0210
0211 if (bi->bti_resistance_ohm < 0 ||
0212 bi->bti_resistance_tolerance < 0) {
0213 bi->bti_resistance_ohm = 7000;
0214 bi->bti_resistance_tolerance = 20;
0215 }
0216
0217 if (!bi->ocv_table[0]) {
0218
0219 bi->ocv_temp[0] = 25;
0220 bi->ocv_table[0] = ocv_cap_tbl;
0221 bi->ocv_table_size[0] = ARRAY_SIZE(ocv_cap_tbl);
0222 }
0223
0224 if (bi->temp_min == INT_MIN)
0225 bi->temp_min = AB8500_TEMP_UNDER;
0226 if (bi->temp_max == INT_MAX)
0227 bi->temp_max = AB8500_TEMP_OVER;
0228 if (bi->temp_alert_min == INT_MIN)
0229 bi->temp_alert_min = AB8500_TEMP_LOW;
0230 if (bi->temp_alert_max == INT_MAX)
0231 bi->temp_alert_max = AB8500_TEMP_HIGH;
0232 bm->temp_hysteresis = AB8500_TEMP_HYSTERESIS;
0233
0234 return 0;
0235 }
0236
0237 void ab8500_bm_of_remove(struct power_supply *psy,
0238 struct ab8500_bm_data *bm)
0239 {
0240 power_supply_put_battery_info(psy, bm->bi);
0241 }