Commit 240fbe23 authored by Anton Vorontsov's avatar Anton Vorontsov
parents 2fbb520d 215cf5c9
...@@ -1011,40 +1011,32 @@ static struct mfd_cell ab8500_bm_devs[] = { ...@@ -1011,40 +1011,32 @@ static struct mfd_cell ab8500_bm_devs[] = {
.of_compatible = "stericsson,ab8500-charger", .of_compatible = "stericsson,ab8500-charger",
.num_resources = ARRAY_SIZE(ab8500_charger_resources), .num_resources = ARRAY_SIZE(ab8500_charger_resources),
.resources = ab8500_charger_resources, .resources = ab8500_charger_resources,
#ifndef CONFIG_OF
.platform_data = &ab8500_bm_data, .platform_data = &ab8500_bm_data,
.pdata_size = sizeof(ab8500_bm_data), .pdata_size = sizeof(ab8500_bm_data),
#endif
}, },
{ {
.name = "ab8500-btemp", .name = "ab8500-btemp",
.of_compatible = "stericsson,ab8500-btemp", .of_compatible = "stericsson,ab8500-btemp",
.num_resources = ARRAY_SIZE(ab8500_btemp_resources), .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
.resources = ab8500_btemp_resources, .resources = ab8500_btemp_resources,
#ifndef CONFIG_OF
.platform_data = &ab8500_bm_data, .platform_data = &ab8500_bm_data,
.pdata_size = sizeof(ab8500_bm_data), .pdata_size = sizeof(ab8500_bm_data),
#endif
}, },
{ {
.name = "ab8500-fg", .name = "ab8500-fg",
.of_compatible = "stericsson,ab8500-fg", .of_compatible = "stericsson,ab8500-fg",
.num_resources = ARRAY_SIZE(ab8500_fg_resources), .num_resources = ARRAY_SIZE(ab8500_fg_resources),
.resources = ab8500_fg_resources, .resources = ab8500_fg_resources,
#ifndef CONFIG_OF
.platform_data = &ab8500_bm_data, .platform_data = &ab8500_bm_data,
.pdata_size = sizeof(ab8500_bm_data), .pdata_size = sizeof(ab8500_bm_data),
#endif
}, },
{ {
.name = "ab8500-chargalg", .name = "ab8500-chargalg",
.of_compatible = "stericsson,ab8500-chargalg", .of_compatible = "stericsson,ab8500-chargalg",
.num_resources = ARRAY_SIZE(ab8500_chargalg_resources), .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
.resources = ab8500_chargalg_resources, .resources = ab8500_chargalg_resources,
#ifndef CONFIG_OF
.platform_data = &ab8500_bm_data, .platform_data = &ab8500_bm_data,
.pdata_size = sizeof(ab8500_bm_data), .pdata_size = sizeof(ab8500_bm_data),
#endif
}, },
}; };
......
...@@ -38,7 +38,7 @@ obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o ...@@ -38,7 +38,7 @@ obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o
obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o
obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_btemp.o ab8500_fg.o abx500_chargalg.o obj-$(CONFIG_AB8500_BM) += ab8500_bmdata.o ab8500_charger.o ab8500_fg.o ab8500_btemp.o abx500_chargalg.o
obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
......
...@@ -182,7 +182,7 @@ static struct batres_vs_temp temp_to_batres_tbl_9100[] = { ...@@ -182,7 +182,7 @@ static struct batres_vs_temp temp_to_batres_tbl_9100[] = {
}; };
static struct abx500_battery_type bat_type_thermistor[] = { static struct abx500_battery_type bat_type_thermistor[] = {
[BATTERY_UNKNOWN] = { [BATTERY_UNKNOWN] = {
/* First element always represent the UNKNOWN battery */ /* First element always represent the UNKNOWN battery */
.name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN, .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
.resis_high = 0, .resis_high = 0,
...@@ -209,8 +209,8 @@ static struct abx500_battery_type bat_type_thermistor[] = { ...@@ -209,8 +209,8 @@ static struct abx500_battery_type bat_type_thermistor[] = {
.v_to_cap_tbl = cap_tbl, .v_to_cap_tbl = cap_tbl,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
{ {
.name = POWER_SUPPLY_TECHNOLOGY_LIPO, .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
.resis_high = 53407, .resis_high = 53407,
.resis_low = 12500, .resis_low = 12500,
...@@ -237,8 +237,8 @@ static struct abx500_battery_type bat_type_thermistor[] = { ...@@ -237,8 +237,8 @@ static struct abx500_battery_type bat_type_thermistor[] = {
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
{ {
.name = POWER_SUPPLY_TECHNOLOGY_LIPO, .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
.resis_high = 200000, .resis_high = 200000,
.resis_low = 82869, .resis_low = 82869,
...@@ -264,11 +264,11 @@ static struct abx500_battery_type bat_type_thermistor[] = { ...@@ -264,11 +264,11 @@ static struct abx500_battery_type bat_type_thermistor[] = {
.v_to_cap_tbl = cap_tbl_B_thermistor, .v_to_cap_tbl = cap_tbl_B_thermistor,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
}; };
static struct abx500_battery_type bat_type_ext_thermistor[] = { static struct abx500_battery_type bat_type_ext_thermistor[] = {
[BATTERY_UNKNOWN] = { [BATTERY_UNKNOWN] = {
/* First element always represent the UNKNOWN battery */ /* First element always represent the UNKNOWN battery */
.name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN, .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
.resis_high = 0, .resis_high = 0,
...@@ -295,13 +295,13 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { ...@@ -295,13 +295,13 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
.v_to_cap_tbl = cap_tbl, .v_to_cap_tbl = cap_tbl,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
/* /*
* These are the batteries that doesn't have an internal NTC resistor to measure * These are the batteries that doesn't have an internal NTC resistor to measure
* its temperature. The temperature in this case is measure with a NTC placed * its temperature. The temperature in this case is measure with a NTC placed
* near the battery but on the PCB. * near the battery but on the PCB.
*/ */
{ {
.name = POWER_SUPPLY_TECHNOLOGY_LIPO, .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
.resis_high = 76000, .resis_high = 76000,
.resis_low = 53000, .resis_low = 53000,
...@@ -327,8 +327,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { ...@@ -327,8 +327,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
.v_to_cap_tbl = cap_tbl, .v_to_cap_tbl = cap_tbl,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
{ {
.name = POWER_SUPPLY_TECHNOLOGY_LION, .name = POWER_SUPPLY_TECHNOLOGY_LION,
.resis_high = 30000, .resis_high = 30000,
.resis_low = 10000, .resis_low = 10000,
...@@ -354,8 +354,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { ...@@ -354,8 +354,8 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
.v_to_cap_tbl = cap_tbl, .v_to_cap_tbl = cap_tbl,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
{ {
.name = POWER_SUPPLY_TECHNOLOGY_LION, .name = POWER_SUPPLY_TECHNOLOGY_LION,
.resis_high = 95000, .resis_high = 95000,
.resis_low = 76001, .resis_low = 76001,
...@@ -381,7 +381,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { ...@@ -381,7 +381,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = {
.v_to_cap_tbl = cap_tbl, .v_to_cap_tbl = cap_tbl,
.n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
.batres_tbl = temp_to_batres_tbl_thermistor, .batres_tbl = temp_to_batres_tbl_thermistor,
}, },
}; };
static const struct abx500_bm_capacity_levels cap_levels = { static const struct abx500_bm_capacity_levels cap_levels = {
...@@ -452,70 +452,55 @@ struct abx500_bm_data ab8500_bm_data = { ...@@ -452,70 +452,55 @@ struct abx500_bm_data ab8500_bm_data = {
.fg_params = &fg, .fg_params = &fg,
}; };
int __devinit int __devinit ab8500_bm_of_probe(struct device *dev,
bmdevs_of_probe(struct device *dev,
struct device_node *np, struct device_node *np,
struct abx500_bm_data **battery) struct abx500_bm_data *bm)
{ {
struct abx500_battery_type *btype; struct batres_vs_temp *tmp_batres_tbl;
struct device_node *np_bat_supply; struct device_node *battery_node;
struct abx500_bm_data *bat;
const char *btech; const char *btech;
char bat_tech[8]; int i;
int i, thermistor;
*battery = &ab8500_bm_data;
/* get phandle to 'battery-info' node */ /* get phandle to 'battery-info' node */
np_bat_supply = of_parse_phandle(np, "battery", 0); battery_node = of_parse_phandle(np, "battery", 0);
if (!np_bat_supply) { if (!battery_node) {
dev_err(dev, "missing property battery\n"); dev_err(dev, "battery node or reference missing\n");
return -EINVAL; return -EINVAL;
} }
if (of_property_read_bool(np_bat_supply,
"thermistor-on-batctrl"))
thermistor = NTC_INTERNAL;
else
thermistor = NTC_EXTERNAL;
bat = *battery; btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
if (thermistor == NTC_EXTERNAL) {
bat->n_btypes = 4;
bat->bat_type = bat_type_ext_thermistor;
bat->adc_therm = ABx500_ADC_THERM_BATTEMP;
}
btech = of_get_property(np_bat_supply,
"stericsson,battery-type", NULL);
if (!btech) { if (!btech) {
dev_warn(dev, "missing property battery-name/type\n"); dev_warn(dev, "missing property battery-name/type\n");
strcpy(bat_tech, "UNKNOWN"); return -EINVAL;
} else {
strcpy(bat_tech, btech);
} }
if (strncmp(bat_tech, "LION", 4) == 0) { if (strncmp(btech, "LION", 4) == 0) {
bat->no_maintenance = true; bm->no_maintenance = true;
bat->chg_unknown_bat = true; bm->chg_unknown_bat = true;
bat->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600; bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
bat->bat_type[BATTERY_UNKNOWN].termination_vol = 4150; bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
bat->bat_type[BATTERY_UNKNOWN].recharge_vol = 4130; bm->bat_type[BATTERY_UNKNOWN].recharge_vol = 4130;
bat->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520; bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
bat->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200; bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
} }
/* select the battery resolution table */
for (i = 0; i < bat->n_btypes; ++i) { if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
btype = (bat->bat_type + i); if (strncmp(btech, "LION", 4) == 0)
if (thermistor == NTC_EXTERNAL) { tmp_batres_tbl = temp_to_batres_tbl_9100;
btype->batres_tbl = else
temp_to_batres_tbl_ext_thermistor; tmp_batres_tbl = temp_to_batres_tbl_thermistor;
} else if (strncmp(bat_tech, "LION", 4) == 0) {
btype->batres_tbl =
temp_to_batres_tbl_9100;
} else { } else {
btype->batres_tbl = bm->n_btypes = 4;
temp_to_batres_tbl_thermistor; bm->bat_type = bat_type_ext_thermistor;
} bm->adc_therm = ABx500_ADC_THERM_BATTEMP;
tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
} }
of_node_put(np_bat_supply);
/* select the battery resolution table */
for (i = 0; i < bm->n_btypes; ++i)
bm->bat_type[i].batres_tbl = tmp_batres_tbl;
of_node_put(battery_node);
return 0; return 0;
} }
...@@ -78,12 +78,13 @@ struct ab8500_btemp_ranges { ...@@ -78,12 +78,13 @@ struct ab8500_btemp_ranges {
* @parent: Pointer to the struct ab8500 * @parent: Pointer to the struct ab8500
* @gpadc: Pointer to the struct gpadc * @gpadc: Pointer to the struct gpadc
* @fg: Pointer to the struct fg * @fg: Pointer to the struct fg
* @bat: Pointer to the abx500_bm platform data * @bm: Platform specific battery management information
* @btemp_psy: Structure for BTEMP specific battery properties * @btemp_psy: Structure for BTEMP specific battery properties
* @events: Structure for information about events triggered * @events: Structure for information about events triggered
* @btemp_ranges: Battery temperature range structure * @btemp_ranges: Battery temperature range structure
* @btemp_wq: Work queue for measuring the temperature periodically * @btemp_wq: Work queue for measuring the temperature periodically
* @btemp_periodic_work: Work for measuring the temperature periodically * @btemp_periodic_work: Work for measuring the temperature periodically
* @initialized: True if battery id read.
*/ */
struct ab8500_btemp { struct ab8500_btemp {
struct device *dev; struct device *dev;
...@@ -94,12 +95,13 @@ struct ab8500_btemp { ...@@ -94,12 +95,13 @@ struct ab8500_btemp {
struct ab8500 *parent; struct ab8500 *parent;
struct ab8500_gpadc *gpadc; struct ab8500_gpadc *gpadc;
struct ab8500_fg *fg; struct ab8500_fg *fg;
struct abx500_bm_data *bat; struct abx500_bm_data *bm;
struct power_supply btemp_psy; struct power_supply btemp_psy;
struct ab8500_btemp_events events; struct ab8500_btemp_events events;
struct ab8500_btemp_ranges btemp_ranges; struct ab8500_btemp_ranges btemp_ranges;
struct workqueue_struct *btemp_wq; struct workqueue_struct *btemp_wq;
struct delayed_work btemp_periodic_work; struct delayed_work btemp_periodic_work;
bool initialized;
}; };
/* BTEMP power supply properties */ /* BTEMP power supply properties */
...@@ -147,13 +149,13 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di, ...@@ -147,13 +149,13 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
return (450000 * (v_batctrl)) / (1800 - v_batctrl); return (450000 * (v_batctrl)) / (1800 - v_batctrl);
} }
if (di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL) { if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL) {
/* /*
* If the battery has internal NTC, we use the current * If the battery has internal NTC, we use the current
* source to calculate the resistance, 7uA or 20uA * source to calculate the resistance, 7uA or 20uA
*/ */
rbs = (v_batctrl * 1000 rbs = (v_batctrl * 1000
- di->bat->gnd_lift_resistance * inst_curr) - di->bm->gnd_lift_resistance * inst_curr)
/ di->curr_source; / di->curr_source;
} else { } else {
/* /*
...@@ -209,7 +211,7 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di, ...@@ -209,7 +211,7 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
return 0; return 0;
/* Only do this for batteries with internal NTC */ /* Only do this for batteries with internal NTC */
if (di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL && enable) { if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && enable) {
if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_7UA) if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_7UA)
curr = BAT_CTRL_7U_ENA; curr = BAT_CTRL_7U_ENA;
else else
...@@ -241,7 +243,7 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di, ...@@ -241,7 +243,7 @@ static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
__func__); __func__);
goto disable_curr_source; goto disable_curr_source;
} }
} else if (di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL && !enable) { } else if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && !enable) {
dev_dbg(di->dev, "Disable BATCTRL curr source\n"); dev_dbg(di->dev, "Disable BATCTRL curr source\n");
/* Write 0 to the curr bits */ /* Write 0 to the curr bits */
...@@ -457,9 +459,9 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) ...@@ -457,9 +459,9 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
int rbat, rntc, vntc; int rbat, rntc, vntc;
u8 id; u8 id;
id = di->bat->batt_id; id = di->bm->batt_id;
if (di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL && if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL &&
id != BATTERY_UNKNOWN) { id != BATTERY_UNKNOWN) {
rbat = ab8500_btemp_get_batctrl_res(di); rbat = ab8500_btemp_get_batctrl_res(di);
...@@ -474,8 +476,8 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) ...@@ -474,8 +476,8 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
} }
temp = ab8500_btemp_res_to_temp(di, temp = ab8500_btemp_res_to_temp(di,
di->bat->bat_type[id].r_to_t_tbl, di->bm->bat_type[id].r_to_t_tbl,
di->bat->bat_type[id].n_temp_tbl_elements, rbat); di->bm->bat_type[id].n_temp_tbl_elements, rbat);
} else { } else {
vntc = ab8500_gpadc_convert(di->gpadc, BTEMP_BALL); vntc = ab8500_gpadc_convert(di->gpadc, BTEMP_BALL);
if (vntc < 0) { if (vntc < 0) {
...@@ -491,8 +493,8 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) ...@@ -491,8 +493,8 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
rntc = 230000 * vntc / (VTVOUT_V - vntc); rntc = 230000 * vntc / (VTVOUT_V - vntc);
temp = ab8500_btemp_res_to_temp(di, temp = ab8500_btemp_res_to_temp(di,
di->bat->bat_type[id].r_to_t_tbl, di->bm->bat_type[id].r_to_t_tbl,
di->bat->bat_type[id].n_temp_tbl_elements, rntc); di->bm->bat_type[id].n_temp_tbl_elements, rntc);
prev = temp; prev = temp;
} }
dev_dbg(di->dev, "Battery temperature is %d\n", temp); dev_dbg(di->dev, "Battery temperature is %d\n", temp);
...@@ -513,7 +515,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) ...@@ -513,7 +515,7 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
u8 i; u8 i;
di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA; di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA;
di->bat->batt_id = BATTERY_UNKNOWN; di->bm->batt_id = BATTERY_UNKNOWN;
res = ab8500_btemp_get_batctrl_res(di); res = ab8500_btemp_get_batctrl_res(di);
if (res < 0) { if (res < 0) {
...@@ -522,23 +524,23 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) ...@@ -522,23 +524,23 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
} }
/* BATTERY_UNKNOWN is defined on position 0, skip it! */ /* BATTERY_UNKNOWN is defined on position 0, skip it! */
for (i = BATTERY_UNKNOWN + 1; i < di->bat->n_btypes; i++) { for (i = BATTERY_UNKNOWN + 1; i < di->bm->n_btypes; i++) {
if ((res <= di->bat->bat_type[i].resis_high) && if ((res <= di->bm->bat_type[i].resis_high) &&
(res >= di->bat->bat_type[i].resis_low)) { (res >= di->bm->bat_type[i].resis_low)) {
dev_dbg(di->dev, "Battery detected on %s" dev_dbg(di->dev, "Battery detected on %s"
" low %d < res %d < high: %d" " low %d < res %d < high: %d"
" index: %d\n", " index: %d\n",
di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL ? di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL ?
"BATCTRL" : "BATTEMP", "BATCTRL" : "BATTEMP",
di->bat->bat_type[i].resis_low, res, di->bm->bat_type[i].resis_low, res,
di->bat->bat_type[i].resis_high, i); di->bm->bat_type[i].resis_high, i);
di->bat->batt_id = i; di->bm->batt_id = i;
break; break;
} }
} }
if (di->bat->batt_id == BATTERY_UNKNOWN) { if (di->bm->batt_id == BATTERY_UNKNOWN) {
dev_warn(di->dev, "Battery identified as unknown" dev_warn(di->dev, "Battery identified as unknown"
", resistance %d Ohm\n", res); ", resistance %d Ohm\n", res);
return -ENXIO; return -ENXIO;
...@@ -548,13 +550,13 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) ...@@ -548,13 +550,13 @@ static int ab8500_btemp_id(struct ab8500_btemp *di)
* We only have to change current source if the * We only have to change current source if the
* detected type is Type 1, else we use the 7uA source * detected type is Type 1, else we use the 7uA source
*/ */
if (di->bat->adc_therm == ABx500_ADC_THERM_BATCTRL && if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL &&
di->bat->batt_id == 1) { di->bm->batt_id == 1) {
dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n"); dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n");
di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA; di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA;
} }
return di->bat->batt_id; return di->bm->batt_id;
} }
/** /**
...@@ -569,6 +571,13 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) ...@@ -569,6 +571,13 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
struct ab8500_btemp *di = container_of(work, struct ab8500_btemp *di = container_of(work,
struct ab8500_btemp, btemp_periodic_work.work); struct ab8500_btemp, btemp_periodic_work.work);
if (!di->initialized) {
di->initialized = true;
/* Identify the battery */
if (ab8500_btemp_id(di) < 0)
dev_warn(di->dev, "failed to identify the battery\n");
}
di->bat_temp = ab8500_btemp_measure_temp(di); di->bat_temp = ab8500_btemp_measure_temp(di);
if (di->bat_temp != di->prev_bat_temp) { if (di->bat_temp != di->prev_bat_temp) {
...@@ -577,9 +586,9 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) ...@@ -577,9 +586,9 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)
} }
if (di->events.ac_conn || di->events.usb_conn) if (di->events.ac_conn || di->events.usb_conn)
interval = di->bat->temp_interval_chg; interval = di->bm->temp_interval_chg;
else else
interval = di->bat->temp_interval_nochg; interval = di->bm->temp_interval_nochg;
/* Schedule a new measurement */ /* Schedule a new measurement */
queue_delayed_work(di->btemp_wq, queue_delayed_work(di->btemp_wq,
...@@ -806,7 +815,7 @@ static int ab8500_btemp_get_property(struct power_supply *psy, ...@@ -806,7 +815,7 @@ static int ab8500_btemp_get_property(struct power_supply *psy,
val->intval = 1; val->intval = 1;
break; break;
case POWER_SUPPLY_PROP_TECHNOLOGY: case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = di->bat->bat_type[di->bat->batt_id].name; val->intval = di->bm->bat_type[di->bm->batt_id].name;
break; break;
case POWER_SUPPLY_PROP_TEMP: case POWER_SUPPLY_PROP_TEMP:
val->intval = ab8500_btemp_get_temp(di); val->intval = ab8500_btemp_get_temp(di);
...@@ -967,6 +976,7 @@ static char *supply_interface[] = { ...@@ -967,6 +976,7 @@ static char *supply_interface[] = {
static int ab8500_btemp_probe(struct platform_device *pdev) static int ab8500_btemp_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct abx500_bm_data *plat = pdev->dev.platform_data;
struct ab8500_btemp *di; struct ab8500_btemp *di;
int irq, i, ret = 0; int irq, i, ret = 0;
u8 val; u8 val;
...@@ -976,21 +986,19 @@ static int ab8500_btemp_probe(struct platform_device *pdev) ...@@ -976,21 +986,19 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "%s no mem for ab8500_btemp\n", __func__); dev_err(&pdev->dev, "%s no mem for ab8500_btemp\n", __func__);
return -ENOMEM; return -ENOMEM;
} }
di->bat = pdev->mfd_cell->platform_data;
if (!di->bat) { if (!plat) {
dev_err(&pdev->dev, "no battery management data supplied\n");
return -EINVAL;
}
di->bm = plat;
if (np) { if (np) {
ret = bmdevs_of_probe(&pdev->dev, np, &di->bat); ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm);
if (ret) { if (ret) {
dev_err(&pdev->dev, dev_err(&pdev->dev, "failed to get battery information\n");
"failed to get battery information\n");
return ret; return ret;
} }
} else {
dev_err(&pdev->dev, "missing dt node for ab8500_btemp\n");
return -EINVAL;
}
} else {
dev_info(&pdev->dev, "falling back to legacy platform data\n");
} }
/* get parent data */ /* get parent data */
...@@ -998,6 +1006,8 @@ static int ab8500_btemp_probe(struct platform_device *pdev) ...@@ -998,6 +1006,8 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
di->parent = dev_get_drvdata(pdev->dev.parent); di->parent = dev_get_drvdata(pdev->dev.parent);
di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
di->initialized = false;
/* BTEMP supply */ /* BTEMP supply */
di->btemp_psy.name = "ab8500_btemp"; di->btemp_psy.name = "ab8500_btemp";
di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY; di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY;
...@@ -1022,10 +1032,6 @@ static int ab8500_btemp_probe(struct platform_device *pdev) ...@@ -1022,10 +1032,6 @@ static int ab8500_btemp_probe(struct platform_device *pdev)
INIT_DEFERRABLE_WORK(&di->btemp_periodic_work, INIT_DEFERRABLE_WORK(&di->btemp_periodic_work,
ab8500_btemp_periodic_work); ab8500_btemp_periodic_work);
/* Identify the battery */
if (ab8500_btemp_id(di) < 0)
dev_warn(di->dev, "failed to identify the battery\n");
/* Set BTEMP thermal limits. Low and Med are fixed */ /* Set BTEMP thermal limits. Low and Med are fixed */
di->btemp_ranges.btemp_low_limit = BTEMP_THERMAL_LOW_LIMIT; di->btemp_ranges.btemp_low_limit = BTEMP_THERMAL_LOW_LIMIT;
di->btemp_ranges.btemp_med_limit = BTEMP_THERMAL_MED_LIMIT; di->btemp_ranges.btemp_med_limit = BTEMP_THERMAL_MED_LIMIT;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -279,9 +279,9 @@ enum { ...@@ -279,9 +279,9 @@ enum {
NTC_INTERNAL, NTC_INTERNAL,
}; };
int bmdevs_of_probe(struct device *dev, int ab8500_bm_of_probe(struct device *dev,
struct device_node *np, struct device_node *np,
struct abx500_bm_data **battery); struct abx500_bm_data *bm);
int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg, int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
u8 value); u8 value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment