Skip to content

Commit 4b24ff7

Browse files
committed
Merge tag 'for-v3.6' of git://git.infradead.org/battery-2.6
Pull battery updates from Anton Vorontsov: "The tag contains just a few battery-related changes for v3.6. It's is all pretty straightforward, except one thing. One of our patches added thermal support for power supply class, but thermal/ subsystem changed under our feet. We (well, Stephen, that is) caught the issue and it was decided[1] that I'd just delay the battery pull request, and then will fix it up by merging upstream back into battery tree at the specific commit. That's not all though: another[2] small fixup for thermal subsystem was needed to get rid of a warning in power supply subsystem (the warning was not drivers/power's "fault", the thermal registration function just needed a proper const annotation, which is also done by a small commit on top of the merge. So, to sum this up: - The 'master' branch of the battery tree was in the -next tree for weeks, was never rebased, altered etc. It should be all OK; - Although, for-v3.6 tag contains the 'master' branch + merge + the warning fix. [1] http://lkml.org/lkml/2012/6/19/23 [2] http://lkml.org/lkml/2012/6/18/28" * tag 'for-v3.6' of git://git.infradead.org/battery-2.6: (23 commits) thermal: Constify 'type' argument for the registration routine olpc-battery: update CHARGE_FULL_DESIGN property for BYD LiFe batteries olpc-battery: Add VOLTAGE_MAX_DESIGN property charger-manager: Fix build break related to EXTCON lp8727_charger: Move header file into platform_data directory power_supply: Add min/max alert properties for CAPACITY, TEMP, TEMP_AMBIENT bq27x00_battery: Add support for BQ27425 chip charger-manager: Set current limit of regulator for over current protection charger-manager: Use EXTCON Subsystem to detect charger cables for charging test_power: Add VOLTAGE_NOW and BATTERY_TEMP properties test_power: Add support for USB AC source gpio-charger: Use cansleep version of gpio_set_value bq27x00_battery: Add support for power average and health properties sbs-battery: Don't trigger false supply_changed event twl4030_charger: Allow charger to control the regulator that feeds it twl4030_charger: Add backup-battery charging twl4030_charger: Fix some typos max17042_battery: Support CHARGE_COUNTER power supply attribute smb347-charger: Add constant charge and current properties power_supply: Add constant charge_current and charge_voltage properties ...
2 parents bca1a5c + 4b1bf58 commit 4b24ff7

23 files changed

Lines changed: 789 additions & 57 deletions

Documentation/power/power_supply_class.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,24 @@ CHARGE_COUNTER - the current charge counter (in µAh). This could easily
112112
be negative; there is no empty or full value. It is only useful for
113113
relative, time-based measurements.
114114

115+
CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
116+
117+
CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
118+
115119
ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
116120

117121
CAPACITY - capacity in percents.
122+
CAPACITY_ALERT_MIN - minimum capacity alert value in percents.
123+
CAPACITY_ALERT_MAX - maximum capacity alert value in percents.
118124
CAPACITY_LEVEL - capacity level. This corresponds to
119125
POWER_SUPPLY_CAPACITY_LEVEL_*.
120126

121127
TEMP - temperature of the power supply.
128+
TEMP_ALERT_MIN - minimum battery temperature alert value in milli centigrade.
129+
TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade.
122130
TEMP_AMBIENT - ambient temperature.
131+
TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade.
132+
TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade.
123133

124134
TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
125135
while battery powers a load)

drivers/mfd/twl-core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
717717
static struct regulator_consumer_supply usb1v8 = {
718718
.supply = "usb1v8",
719719
};
720-
static struct regulator_consumer_supply usb3v1 = {
721-
.supply = "usb3v1",
720+
static struct regulator_consumer_supply usb3v1[] = {
721+
{ .supply = "usb3v1" },
722+
{ .supply = "bci3v1" },
722723
};
723724

724725
/* First add the regulators so that they can be used by transceiver */
@@ -746,7 +747,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
746747
return PTR_ERR(child);
747748

748749
child = add_regulator_linked(TWL4030_REG_VUSB3V1,
749-
&usb_fixed, &usb3v1, 1,
750+
&usb_fixed, usb3v1, 2,
750751
features);
751752
if (IS_ERR(child))
752753
return PTR_ERR(child);
@@ -767,7 +768,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
767768
if (twl_has_regulator() && child) {
768769
usb1v5.dev_name = dev_name(child);
769770
usb1v8.dev_name = dev_name(child);
770-
usb3v1.dev_name = dev_name(child);
771+
usb3v1[0].dev_name = dev_name(child);
771772
}
772773
}
773774
if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {

drivers/power/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ config CHARGER_GPIO
268268
config CHARGER_MANAGER
269269
bool "Battery charger manager for multiple chargers"
270270
depends on REGULATOR && RTC_CLASS
271+
select EXTCON
271272
help
272273
Say Y to enable charger-manager support, which allows multiple
273274
chargers attached to a battery and multiple batteries attached to a

drivers/power/bq27x00_battery.c

Lines changed: 140 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Datasheets:
2323
* http://focus.ti.com/docs/prod/folders/print/bq27000.html
2424
* http://focus.ti.com/docs/prod/folders/print/bq27500.html
25+
* http://www.ti.com/product/bq27425-g1
2526
*/
2627

2728
#include <linux/module.h>
@@ -51,6 +52,7 @@
5152
#define BQ27x00_REG_LMD 0x12 /* Last measured discharge */
5253
#define BQ27x00_REG_CYCT 0x2A /* Cycle count total */
5354
#define BQ27x00_REG_AE 0x22 /* Available energy */
55+
#define BQ27x00_POWER_AVG 0x24
5456

5557
#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
5658
#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
@@ -66,15 +68,21 @@
6668
#define BQ27500_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */
6769
#define BQ27500_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */
6870
#define BQ27500_FLAG_FC BIT(9)
71+
#define BQ27500_FLAG_OTC BIT(15)
72+
73+
/* bq27425 register addresses are same as bq27x00 addresses minus 4 */
74+
#define BQ27425_REG_OFFSET 0x04
75+
#define BQ27425_REG_SOC 0x18 /* Register address plus offset */
6976

7077
#define BQ27000_RS 20 /* Resistor sense */
78+
#define BQ27x00_POWER_CONSTANT (256 * 29200 / 1000)
7179

7280
struct bq27x00_device_info;
7381
struct bq27x00_access_methods {
7482
int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
7583
};
7684

77-
enum bq27x00_chip { BQ27000, BQ27500 };
85+
enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
7886

7987
struct bq27x00_reg_cache {
8088
int temperature;
@@ -86,6 +94,8 @@ struct bq27x00_reg_cache {
8694
int capacity;
8795
int energy;
8896
int flags;
97+
int power_avg;
98+
int health;
8999
};
90100

91101
struct bq27x00_device_info {
@@ -123,6 +133,22 @@ static enum power_supply_property bq27x00_battery_props[] = {
123133
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
124134
POWER_SUPPLY_PROP_CYCLE_COUNT,
125135
POWER_SUPPLY_PROP_ENERGY_NOW,
136+
POWER_SUPPLY_PROP_POWER_AVG,
137+
POWER_SUPPLY_PROP_HEALTH,
138+
};
139+
140+
static enum power_supply_property bq27425_battery_props[] = {
141+
POWER_SUPPLY_PROP_STATUS,
142+
POWER_SUPPLY_PROP_PRESENT,
143+
POWER_SUPPLY_PROP_VOLTAGE_NOW,
144+
POWER_SUPPLY_PROP_CURRENT_NOW,
145+
POWER_SUPPLY_PROP_CAPACITY,
146+
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
147+
POWER_SUPPLY_PROP_TEMP,
148+
POWER_SUPPLY_PROP_TECHNOLOGY,
149+
POWER_SUPPLY_PROP_CHARGE_FULL,
150+
POWER_SUPPLY_PROP_CHARGE_NOW,
151+
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
126152
};
127153

128154
static unsigned int poll_interval = 360;
@@ -137,9 +163,23 @@ MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \
137163
static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
138164
bool single)
139165
{
166+
if (di->chip == BQ27425)
167+
return di->bus.read(di, reg - BQ27425_REG_OFFSET, single);
140168
return di->bus.read(di, reg, single);
141169
}
142170

171+
/*
172+
* Higher versions of the chip like BQ27425 and BQ27500
173+
* differ from BQ27000 and BQ27200 in calculation of certain
174+
* parameters. Hence we need to check for the chip type.
175+
*/
176+
static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di)
177+
{
178+
if (di->chip == BQ27425 || di->chip == BQ27500)
179+
return true;
180+
return false;
181+
}
182+
143183
/*
144184
* Return the battery Relative State-of-Charge
145185
* Or < 0 if something fails.
@@ -150,6 +190,8 @@ static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
150190

151191
if (di->chip == BQ27500)
152192
rsoc = bq27x00_read(di, BQ27500_REG_SOC, false);
193+
else if (di->chip == BQ27425)
194+
rsoc = bq27x00_read(di, BQ27425_REG_SOC, false);
153195
else
154196
rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
155197

@@ -174,7 +216,7 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
174216
return charge;
175217
}
176218

177-
if (di->chip == BQ27500)
219+
if (bq27xxx_is_chip_version_higher(di))
178220
charge *= 1000;
179221
else
180222
charge = charge * 3570 / BQ27000_RS;
@@ -208,7 +250,7 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
208250
{
209251
int ilmd;
210252

211-
if (di->chip == BQ27500)
253+
if (bq27xxx_is_chip_version_higher(di))
212254
ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false);
213255
else
214256
ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true);
@@ -218,7 +260,7 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
218260
return ilmd;
219261
}
220262

221-
if (di->chip == BQ27500)
263+
if (bq27xxx_is_chip_version_higher(di))
222264
ilmd *= 1000;
223265
else
224266
ilmd = ilmd * 256 * 3570 / BQ27000_RS;
@@ -262,7 +304,7 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
262304
return temp;
263305
}
264306

265-
if (di->chip == BQ27500)
307+
if (bq27xxx_is_chip_version_higher(di))
266308
temp -= 2731;
267309
else
268310
temp = ((temp * 5) - 5463) / 2;
@@ -306,31 +348,101 @@ static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
306348
return tval * 60;
307349
}
308350

351+
/*
352+
* Read a power avg register.
353+
* Return < 0 if something fails.
354+
*/
355+
static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg)
356+
{
357+
int tval;
358+
359+
tval = bq27x00_read(di, reg, false);
360+
if (tval < 0) {
361+
dev_err(di->dev, "error reading power avg rgister %02x: %d\n",
362+
reg, tval);
363+
return tval;
364+
}
365+
366+
if (di->chip == BQ27500)
367+
return tval;
368+
else
369+
return (tval * BQ27x00_POWER_CONSTANT) / BQ27000_RS;
370+
}
371+
372+
/*
373+
* Read flag register.
374+
* Return < 0 if something fails.
375+
*/
376+
static int bq27x00_battery_read_health(struct bq27x00_device_info *di)
377+
{
378+
int tval;
379+
380+
tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false);
381+
if (tval < 0) {
382+
dev_err(di->dev, "error reading flag register:%d\n", tval);
383+
return tval;
384+
}
385+
386+
if ((di->chip == BQ27500)) {
387+
if (tval & BQ27500_FLAG_SOCF)
388+
tval = POWER_SUPPLY_HEALTH_DEAD;
389+
else if (tval & BQ27500_FLAG_OTC)
390+
tval = POWER_SUPPLY_HEALTH_OVERHEAT;
391+
else
392+
tval = POWER_SUPPLY_HEALTH_GOOD;
393+
return tval;
394+
} else {
395+
if (tval & BQ27000_FLAG_EDV1)
396+
tval = POWER_SUPPLY_HEALTH_DEAD;
397+
else
398+
tval = POWER_SUPPLY_HEALTH_GOOD;
399+
return tval;
400+
}
401+
402+
return -1;
403+
}
404+
309405
static void bq27x00_update(struct bq27x00_device_info *di)
310406
{
311407
struct bq27x00_reg_cache cache = {0, };
312408
bool is_bq27500 = di->chip == BQ27500;
409+
bool is_bq27425 = di->chip == BQ27425;
313410

314411
cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
315412
if (cache.flags >= 0) {
316-
if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) {
413+
if (!is_bq27500 && !is_bq27425
414+
&& (cache.flags & BQ27000_FLAG_CI)) {
317415
dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n");
318416
cache.capacity = -ENODATA;
319417
cache.energy = -ENODATA;
320418
cache.time_to_empty = -ENODATA;
321419
cache.time_to_empty_avg = -ENODATA;
322420
cache.time_to_full = -ENODATA;
323421
cache.charge_full = -ENODATA;
422+
cache.health = -ENODATA;
324423
} else {
325424
cache.capacity = bq27x00_battery_read_rsoc(di);
326-
cache.energy = bq27x00_battery_read_energy(di);
327-
cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
328-
cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
329-
cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
425+
if (!is_bq27425) {
426+
cache.energy = bq27x00_battery_read_energy(di);
427+
cache.time_to_empty =
428+
bq27x00_battery_read_time(di,
429+
BQ27x00_REG_TTE);
430+
cache.time_to_empty_avg =
431+
bq27x00_battery_read_time(di,
432+
BQ27x00_REG_TTECP);
433+
cache.time_to_full =
434+
bq27x00_battery_read_time(di,
435+
BQ27x00_REG_TTF);
436+
}
330437
cache.charge_full = bq27x00_battery_read_lmd(di);
438+
cache.health = bq27x00_battery_read_health(di);
331439
}
332440
cache.temperature = bq27x00_battery_read_temperature(di);
441+
if (!is_bq27425)
442+
cache.cycle_count = bq27x00_battery_read_cyct(di);
333443
cache.cycle_count = bq27x00_battery_read_cyct(di);
444+
cache.power_avg =
445+
bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG);
334446

335447
/* We only have to read charge design full once */
336448
if (di->charge_design_full <= 0)
@@ -376,7 +488,7 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di,
376488
return curr;
377489
}
378490

379-
if (di->chip == BQ27500) {
491+
if (bq27xxx_is_chip_version_higher(di)) {
380492
/* bq27500 returns signed value */
381493
val->intval = (int)((s16)curr) * 1000;
382494
} else {
@@ -397,7 +509,7 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,
397509
{
398510
int status;
399511

400-
if (di->chip == BQ27500) {
512+
if (bq27xxx_is_chip_version_higher(di)) {
401513
if (di->cache.flags & BQ27500_FLAG_FC)
402514
status = POWER_SUPPLY_STATUS_FULL;
403515
else if (di->cache.flags & BQ27500_FLAG_DSC)
@@ -425,7 +537,7 @@ static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di,
425537
{
426538
int level;
427539

428-
if (di->chip == BQ27500) {
540+
if (bq27xxx_is_chip_version_higher(di)) {
429541
if (di->cache.flags & BQ27500_FLAG_FC)
430542
level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
431543
else if (di->cache.flags & BQ27500_FLAG_SOC1)
@@ -550,6 +662,12 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
550662
case POWER_SUPPLY_PROP_ENERGY_NOW:
551663
ret = bq27x00_simple_value(di->cache.energy, val);
552664
break;
665+
case POWER_SUPPLY_PROP_POWER_AVG:
666+
ret = bq27x00_simple_value(di->cache.power_avg, val);
667+
break;
668+
case POWER_SUPPLY_PROP_HEALTH:
669+
ret = bq27x00_simple_value(di->cache.health, val);
670+
break;
553671
default:
554672
return -EINVAL;
555673
}
@@ -570,8 +688,14 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
570688
int ret;
571689

572690
di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
573-
di->bat.properties = bq27x00_battery_props;
574-
di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
691+
di->chip = BQ27425;
692+
if (di->chip == BQ27425) {
693+
di->bat.properties = bq27425_battery_props;
694+
di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props);
695+
} else {
696+
di->bat.properties = bq27x00_battery_props;
697+
di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
698+
}
575699
di->bat.get_property = bq27x00_battery_get_property;
576700
di->bat.external_power_changed = bq27x00_external_power_changed;
577701

@@ -729,6 +853,7 @@ static int bq27x00_battery_remove(struct i2c_client *client)
729853
static const struct i2c_device_id bq27x00_id[] = {
730854
{ "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
731855
{ "bq27500", BQ27500 },
856+
{ "bq27425", BQ27425 },
732857
{},
733858
};
734859
MODULE_DEVICE_TABLE(i2c, bq27x00_id);

0 commit comments

Comments
 (0)