Commit 4b24ff71 authored by Linus Torvalds's avatar Linus Torvalds

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
  ...
parents bca1a5c0 4b1bf587
......@@ -112,14 +112,24 @@ CHARGE_COUNTER - the current charge counter (in µAh). This could easily
be negative; there is no empty or full value. It is only useful for
relative, time-based measurements.
CONSTANT_CHARGE_CURRENT - constant charge current programmed by charger.
CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger.
ENERGY_FULL, ENERGY_EMPTY - same as above but for energy.
CAPACITY - capacity in percents.
CAPACITY_ALERT_MIN - minimum capacity alert value in percents.
CAPACITY_ALERT_MAX - maximum capacity alert value in percents.
CAPACITY_LEVEL - capacity level. This corresponds to
POWER_SUPPLY_CAPACITY_LEVEL_*.
TEMP - temperature of the power supply.
TEMP_ALERT_MIN - minimum battery temperature alert value in milli centigrade.
TEMP_ALERT_MAX - maximum battery temperature alert value in milli centigrade.
TEMP_AMBIENT - ambient temperature.
TEMP_AMBIENT_ALERT_MIN - minimum ambient temperature alert value in milli centigrade.
TEMP_AMBIENT_ALERT_MAX - maximum ambient temperature alert value in milli centigrade.
TIME_TO_EMPTY - seconds left for battery to be considered empty (i.e.
while battery powers a load)
......
......@@ -717,8 +717,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
static struct regulator_consumer_supply usb1v8 = {
.supply = "usb1v8",
};
static struct regulator_consumer_supply usb3v1 = {
.supply = "usb3v1",
static struct regulator_consumer_supply usb3v1[] = {
{ .supply = "usb3v1" },
{ .supply = "bci3v1" },
};
/* 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,
return PTR_ERR(child);
child = add_regulator_linked(TWL4030_REG_VUSB3V1,
&usb_fixed, &usb3v1, 1,
&usb_fixed, usb3v1, 2,
features);
if (IS_ERR(child))
return PTR_ERR(child);
......@@ -767,7 +768,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
if (twl_has_regulator() && child) {
usb1v5.dev_name = dev_name(child);
usb1v8.dev_name = dev_name(child);
usb3v1.dev_name = dev_name(child);
usb3v1[0].dev_name = dev_name(child);
}
}
if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
......
......@@ -268,6 +268,7 @@ config CHARGER_GPIO
config CHARGER_MANAGER
bool "Battery charger manager for multiple chargers"
depends on REGULATOR && RTC_CLASS
select EXTCON
help
Say Y to enable charger-manager support, which allows multiple
chargers attached to a battery and multiple batteries attached to a
......
......@@ -22,6 +22,7 @@
* Datasheets:
* http://focus.ti.com/docs/prod/folders/print/bq27000.html
* http://focus.ti.com/docs/prod/folders/print/bq27500.html
* http://www.ti.com/product/bq27425-g1
*/
#include <linux/module.h>
......@@ -51,6 +52,7 @@
#define BQ27x00_REG_LMD 0x12 /* Last measured discharge */
#define BQ27x00_REG_CYCT 0x2A /* Cycle count total */
#define BQ27x00_REG_AE 0x22 /* Available energy */
#define BQ27x00_POWER_AVG 0x24
#define BQ27000_REG_RSOC 0x0B /* Relative State-of-Charge */
#define BQ27000_REG_ILMD 0x76 /* Initial last measured discharge */
......@@ -66,15 +68,21 @@
#define BQ27500_FLAG_SOCF BIT(1) /* State-of-Charge threshold final */
#define BQ27500_FLAG_SOC1 BIT(2) /* State-of-Charge threshold 1 */
#define BQ27500_FLAG_FC BIT(9)
#define BQ27500_FLAG_OTC BIT(15)
/* bq27425 register addresses are same as bq27x00 addresses minus 4 */
#define BQ27425_REG_OFFSET 0x04
#define BQ27425_REG_SOC 0x18 /* Register address plus offset */
#define BQ27000_RS 20 /* Resistor sense */
#define BQ27x00_POWER_CONSTANT (256 * 29200 / 1000)
struct bq27x00_device_info;
struct bq27x00_access_methods {
int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
};
enum bq27x00_chip { BQ27000, BQ27500 };
enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
struct bq27x00_reg_cache {
int temperature;
......@@ -86,6 +94,8 @@ struct bq27x00_reg_cache {
int capacity;
int energy;
int flags;
int power_avg;
int health;
};
struct bq27x00_device_info {
......@@ -123,6 +133,22 @@ static enum power_supply_property bq27x00_battery_props[] = {
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CYCLE_COUNT,
POWER_SUPPLY_PROP_ENERGY_NOW,
POWER_SUPPLY_PROP_POWER_AVG,
POWER_SUPPLY_PROP_HEALTH,
};
static enum power_supply_property bq27425_battery_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
};
static unsigned int poll_interval = 360;
......@@ -137,9 +163,23 @@ MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \
static inline int bq27x00_read(struct bq27x00_device_info *di, u8 reg,
bool single)
{
if (di->chip == BQ27425)
return di->bus.read(di, reg - BQ27425_REG_OFFSET, single);
return di->bus.read(di, reg, single);
}
/*
* Higher versions of the chip like BQ27425 and BQ27500
* differ from BQ27000 and BQ27200 in calculation of certain
* parameters. Hence we need to check for the chip type.
*/
static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di)
{
if (di->chip == BQ27425 || di->chip == BQ27500)
return true;
return false;
}
/*
* Return the battery Relative State-of-Charge
* Or < 0 if something fails.
......@@ -150,6 +190,8 @@ static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
if (di->chip == BQ27500)
rsoc = bq27x00_read(di, BQ27500_REG_SOC, false);
else if (di->chip == BQ27425)
rsoc = bq27x00_read(di, BQ27425_REG_SOC, false);
else
rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
......@@ -174,7 +216,7 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
return charge;
}
if (di->chip == BQ27500)
if (bq27xxx_is_chip_version_higher(di))
charge *= 1000;
else
charge = charge * 3570 / BQ27000_RS;
......@@ -208,7 +250,7 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
{
int ilmd;
if (di->chip == BQ27500)
if (bq27xxx_is_chip_version_higher(di))
ilmd = bq27x00_read(di, BQ27500_REG_DCAP, false);
else
ilmd = bq27x00_read(di, BQ27000_REG_ILMD, true);
......@@ -218,7 +260,7 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
return ilmd;
}
if (di->chip == BQ27500)
if (bq27xxx_is_chip_version_higher(di))
ilmd *= 1000;
else
ilmd = ilmd * 256 * 3570 / BQ27000_RS;
......@@ -262,7 +304,7 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
return temp;
}
if (di->chip == BQ27500)
if (bq27xxx_is_chip_version_higher(di))
temp -= 2731;
else
temp = ((temp * 5) - 5463) / 2;
......@@ -306,14 +348,70 @@ static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
return tval * 60;
}
/*
* Read a power avg register.
* Return < 0 if something fails.
*/
static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg)
{
int tval;
tval = bq27x00_read(di, reg, false);
if (tval < 0) {
dev_err(di->dev, "error reading power avg rgister %02x: %d\n",
reg, tval);
return tval;
}
if (di->chip == BQ27500)
return tval;
else
return (tval * BQ27x00_POWER_CONSTANT) / BQ27000_RS;
}
/*
* Read flag register.
* Return < 0 if something fails.
*/
static int bq27x00_battery_read_health(struct bq27x00_device_info *di)
{
int tval;
tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false);
if (tval < 0) {
dev_err(di->dev, "error reading flag register:%d\n", tval);
return tval;
}
if ((di->chip == BQ27500)) {
if (tval & BQ27500_FLAG_SOCF)
tval = POWER_SUPPLY_HEALTH_DEAD;
else if (tval & BQ27500_FLAG_OTC)
tval = POWER_SUPPLY_HEALTH_OVERHEAT;
else
tval = POWER_SUPPLY_HEALTH_GOOD;
return tval;
} else {
if (tval & BQ27000_FLAG_EDV1)
tval = POWER_SUPPLY_HEALTH_DEAD;
else
tval = POWER_SUPPLY_HEALTH_GOOD;
return tval;
}
return -1;
}
static void bq27x00_update(struct bq27x00_device_info *di)
{
struct bq27x00_reg_cache cache = {0, };
bool is_bq27500 = di->chip == BQ27500;
bool is_bq27425 = di->chip == BQ27425;
cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
if (cache.flags >= 0) {
if (!is_bq27500 && (cache.flags & BQ27000_FLAG_CI)) {
if (!is_bq27500 && !is_bq27425
&& (cache.flags & BQ27000_FLAG_CI)) {
dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n");
cache.capacity = -ENODATA;
cache.energy = -ENODATA;
......@@ -321,16 +419,30 @@ static void bq27x00_update(struct bq27x00_device_info *di)
cache.time_to_empty_avg = -ENODATA;
cache.time_to_full = -ENODATA;
cache.charge_full = -ENODATA;
cache.health = -ENODATA;
} else {
cache.capacity = bq27x00_battery_read_rsoc(di);
cache.energy = bq27x00_battery_read_energy(di);
cache.time_to_empty = bq27x00_battery_read_time(di, BQ27x00_REG_TTE);
cache.time_to_empty_avg = bq27x00_battery_read_time(di, BQ27x00_REG_TTECP);
cache.time_to_full = bq27x00_battery_read_time(di, BQ27x00_REG_TTF);
if (!is_bq27425) {
cache.energy = bq27x00_battery_read_energy(di);
cache.time_to_empty =
bq27x00_battery_read_time(di,
BQ27x00_REG_TTE);
cache.time_to_empty_avg =
bq27x00_battery_read_time(di,
BQ27x00_REG_TTECP);
cache.time_to_full =
bq27x00_battery_read_time(di,
BQ27x00_REG_TTF);
}
cache.charge_full = bq27x00_battery_read_lmd(di);
cache.health = bq27x00_battery_read_health(di);
}
cache.temperature = bq27x00_battery_read_temperature(di);
if (!is_bq27425)
cache.cycle_count = bq27x00_battery_read_cyct(di);
cache.cycle_count = bq27x00_battery_read_cyct(di);
cache.power_avg =
bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG);
/* We only have to read charge design full once */
if (di->charge_design_full <= 0)
......@@ -376,7 +488,7 @@ static int bq27x00_battery_current(struct bq27x00_device_info *di,
return curr;
}
if (di->chip == BQ27500) {
if (bq27xxx_is_chip_version_higher(di)) {
/* bq27500 returns signed value */
val->intval = (int)((s16)curr) * 1000;
} else {
......@@ -397,7 +509,7 @@ static int bq27x00_battery_status(struct bq27x00_device_info *di,
{
int status;
if (di->chip == BQ27500) {
if (bq27xxx_is_chip_version_higher(di)) {
if (di->cache.flags & BQ27500_FLAG_FC)
status = POWER_SUPPLY_STATUS_FULL;
else if (di->cache.flags & BQ27500_FLAG_DSC)
......@@ -425,7 +537,7 @@ static int bq27x00_battery_capacity_level(struct bq27x00_device_info *di,
{
int level;
if (di->chip == BQ27500) {
if (bq27xxx_is_chip_version_higher(di)) {
if (di->cache.flags & BQ27500_FLAG_FC)
level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
else if (di->cache.flags & BQ27500_FLAG_SOC1)
......@@ -550,6 +662,12 @@ static int bq27x00_battery_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_ENERGY_NOW:
ret = bq27x00_simple_value(di->cache.energy, val);
break;
case POWER_SUPPLY_PROP_POWER_AVG:
ret = bq27x00_simple_value(di->cache.power_avg, val);
break;
case POWER_SUPPLY_PROP_HEALTH:
ret = bq27x00_simple_value(di->cache.health, val);
break;
default:
return -EINVAL;
}
......@@ -570,8 +688,14 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
int ret;
di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
di->bat.properties = bq27x00_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
di->chip = BQ27425;
if (di->chip == BQ27425) {
di->bat.properties = bq27425_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props);
} else {
di->bat.properties = bq27x00_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
}
di->bat.get_property = bq27x00_battery_get_property;
di->bat.external_power_changed = bq27x00_external_power_changed;
......@@ -729,6 +853,7 @@ static int bq27x00_battery_remove(struct i2c_client *client)
static const struct i2c_device_id bq27x00_id[] = {
{ "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */
{ "bq27500", BQ27500 },
{ "bq27425", BQ27425 },
{},
};
MODULE_DEVICE_TABLE(i2c, bq27x00_id);
......
......@@ -271,16 +271,13 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)
if (enable) {
if (cm->emergency_stop)
return -EAGAIN;
err = regulator_bulk_enable(desc->num_charger_regulators,
desc->charger_regulators);
for (i = 0 ; i < desc->num_charger_regulators ; i++)
regulator_enable(desc->charger_regulators[i].consumer);
} else {
/*
* Abnormal battery state - Stop charging forcibly,
* even if charger was enabled at the other places
*/
err = regulator_bulk_disable(desc->num_charger_regulators,
desc->charger_regulators);
for (i = 0; i < desc->num_charger_regulators; i++) {
if (regulator_is_enabled(
desc->charger_regulators[i].consumer)) {
......@@ -288,7 +285,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)
desc->charger_regulators[i].consumer);
dev_warn(cm->dev,
"Disable regulator(%s) forcibly.\n",
desc->charger_regulators[i].supply);
desc->charger_regulators[i].regulator_name);
}
}
}
......@@ -994,11 +991,92 @@ int setup_charger_manager(struct charger_global_desc *gd)
}
EXPORT_SYMBOL_GPL(setup_charger_manager);
/**
* charger_extcon_work - enable/diable charger according to the state
* of charger cable
*
* @work: work_struct of the function charger_extcon_work.
*/
static void charger_extcon_work(struct work_struct *work)
{
struct charger_cable *cable =
container_of(work, struct charger_cable, wq);
int ret;
if (cable->attached && cable->min_uA != 0 && cable->max_uA != 0) {
ret = regulator_set_current_limit(cable->charger->consumer,
cable->min_uA, cable->max_uA);
if (ret < 0) {
pr_err("Cannot set current limit of %s (%s)\n",
cable->charger->regulator_name, cable->name);
return;
}
pr_info("Set current limit of %s : %duA ~ %duA\n",
cable->charger->regulator_name,
cable->min_uA, cable->max_uA);
}
try_charger_enable(cable->cm, cable->attached);
}
/**
* charger_extcon_notifier - receive the state of charger cable
* when registered cable is attached or detached.
*
* @self: the notifier block of the charger_extcon_notifier.
* @event: the cable state.
* @ptr: the data pointer of notifier block.
*/
static int charger_extcon_notifier(struct notifier_block *self,
unsigned long event, void *ptr)
{
struct charger_cable *cable =
container_of(self, struct charger_cable, nb);
cable->attached = event;
schedule_work(&cable->wq);
return NOTIFY_DONE;
}
/**
* charger_extcon_init - register external connector to use it
* as the charger cable
*
* @cm: the Charger Manager representing the battery.
* @cable: the Charger cable representing the external connector.
*/
static int charger_extcon_init(struct charger_manager *cm,
struct charger_cable *cable)
{
int ret = 0;
/*
* Charger manager use Extcon framework to identify
* the charger cable among various external connector
* cable (e.g., TA, USB, MHL, Dock).
*/
INIT_WORK(&cable->wq, charger_extcon_work);
cable->nb.notifier_call = charger_extcon_notifier;
ret = extcon_register_interest(&cable->extcon_dev,
cable->extcon_name, cable->name, &cable->nb);
if (ret < 0) {
pr_info("Cannot register extcon_dev for %s(cable: %s).\n",
cable->extcon_name,
cable->name);
ret = -EINVAL;
}
return ret;
}
static int charger_manager_probe(struct platform_device *pdev)
{
struct charger_desc *desc = dev_get_platdata(&pdev->dev);
struct charger_manager *cm;
int ret = 0, i = 0;
int j = 0;
union power_supply_propval val;
if (g_desc && !rtc_dev && g_desc->rtc_name) {
......@@ -1167,11 +1245,31 @@ static int charger_manager_probe(struct platform_device *pdev)
goto err_register;
}
ret = regulator_bulk_get(&pdev->dev, desc->num_charger_regulators,
desc->charger_regulators);
if (ret) {
dev_err(&pdev->dev, "Cannot get charger regulators.\n");
goto err_bulk_get;
for (i = 0 ; i < desc->num_charger_regulators ; i++) {
struct charger_regulator *charger
= &desc->charger_regulators[i];
charger->consumer = regulator_get(&pdev->dev,
charger->regulator_name);
if (charger->consumer == NULL) {
dev_err(&pdev->dev, "Cannot find charger(%s)n",
charger->regulator_name);
ret = -EINVAL;
goto err_chg_get;
}
for (j = 0 ; j < charger->num_cables ; j++) {
struct charger_cable *cable = &charger->cables[j];
ret = charger_extcon_init(cm, cable);
if (ret < 0) {
dev_err(&pdev->dev, "Cannot find charger(%s)n",
charger->regulator_name);
goto err_extcon;
}
cable->charger = charger;
cable->cm = cm;
}
}
ret = try_charger_enable(cm, true);
......@@ -1197,9 +1295,19 @@ static int charger_manager_probe(struct platform_device *pdev)
return 0;
err_chg_enable:
regulator_bulk_free(desc->num_charger_regulators,
desc->charger_regulators);
err_bulk_get:
err_extcon:
for (i = 0 ; i < desc->num_charger_regulators ; i++) {
struct charger_regulator *charger
= &desc->charger_regulators[i];
for (j = 0 ; j < charger->num_cables ; j++) {
struct charger_cable *cable = &charger->cables[j];
extcon_unregister_interest(&cable->extcon_dev);
}
}
err_chg_get:
for (i = 0 ; i < desc->num_charger_regulators ; i++)
regulator_put(desc->charger_regulators[i].consumer);
power_supply_unregister(&cm->charger_psy);
err_register:
kfree(cm->charger_psy.properties);
......@@ -1218,6 +1326,8 @@ static int __devexit charger_manager_remove(struct platform_device *pdev)
{
struct charger_manager *cm = platform_get_drvdata(pdev);
struct charger_desc *desc = cm->desc;
int i = 0;
int j = 0;
/* Remove from the list */
mutex_lock(&cm_list_mtx);
......@@ -1229,8 +1339,18 @@ static int __devexit charger_manager_remove(struct platform_device *pdev)
if (delayed_work_pending(&cm_monitor_work))
cancel_delayed_work_sync(&cm_monitor_work);
regulator_bulk_free(desc->num_charger_regulators,
desc->charger_regulators);
for (i = 0 ; i < desc->num_charger_regulators ; i++) {
struct charger_regulator *charger
= &desc->charger_regulators[i];
for (j = 0 ; j < charger->num_cables ; j++) {
struct charger_cable *cable = &charger->cables[j];
extcon_unregister_interest(&cable->extcon_dev);
}
}
for (i = 0 ; i < desc->num_charger_regulators ; i++)
regulator_put(desc->charger_regulators[i].consumer);
power_supply_unregister(&cm->charger_psy);
try_charger_enable(cm, false);
......
......@@ -64,7 +64,7 @@ static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
return w1_ds2781_io(dev_info->w1_dev, buf, addr, count, io);
}
int w1_ds2781_read(struct ds2781_device_info *dev_info, char *buf,
static int w1_ds2781_read(struct ds2781_device_info *dev_info, char *buf,
int addr, size_t count)
{
return ds2781_battery_io(dev_info, buf, addr, count, 0);
......
......@@ -54,7 +54,7 @@ static int gpio_charger_get_property(struct power_supply *psy,
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
val->intval = gpio_get_value(pdata->gpio);
val->intval = gpio_get_value_cansleep(pdata->gpio);
val->intval ^= pdata->gpio_active_low;
break;
default:
......
......@@ -15,7 +15,7 @@
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/power_supply.h>
#include <linux/lp8727.h>
#include <linux/platform_data/lp8727.h>
#define DEBOUNCE_MSEC 270
......
......@@ -113,6 +113,7 @@ static enum power_supply_property max17042_battery_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_OCV,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CURRENT_AVG,
......@@ -199,6 +200,13 @@ static int max17042_get_property(struct power_supply *psy,
if (ret < 0)
return ret;
val->intval = ret * 1000 / 2;
break;
case POWER_SUPPLY_PROP_CHARGE_COUNTER:
ret = max17042_read_reg(chip->client, MAX17042_QH);
if (ret < 0)
return ret;
val->intval = ret * 1000 / 2;
break;
case POWER_SUPPLY_PROP_TEMP:
......
......@@ -231,11 +231,9 @@ static int olpc_bat_get_charge_full_design(union power_supply_propval *val)
case POWER_SUPPLY_TECHNOLOGY_LiFe:
switch (mfr) {
case 1: /* Gold Peak */
val->intval = 2800000;
break;
case 1: /* Gold Peak, fall through */
case 2: /* BYD */
val->intval = 3100000;
val->intval = 2800000;
break;
default:
return -EIO;
......@@ -267,6 +265,55 @@ static int olpc_bat_get_charge_now(union power_supply_propval *val)
return 0;
}
static int olpc_bat_get_voltage_max_design(union power_supply_propval *val)
{
uint8_t ec_byte;
union power_supply_propval tech;
int mfr;
int ret;
ret = olpc_bat_get_tech(&tech);
if (ret)
return ret;
ec_byte = BAT_ADDR_MFR_TYPE;
ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &ec_byte, 1);
if (ret)
return ret;
mfr = ec_byte >> 4;
switch (tech.intval) {
case POWER_SUPPLY_TECHNOLOGY_NiMH:
switch (mfr) {
case 1: /* Gold Peak */
val->intval = 6000000;
break;
default:
return -EIO;
}
break;
case POWER_SUPPLY_TECHNOLOGY_LiFe:
switch (mfr) {
case 1: /* Gold Peak */
val->intval = 6400000;
break;
case 2: /* BYD */
val->intval = 6500000;
break;
default:
return -EIO;
}
break;
default:
return -EIO;
}
return ret;
}
/*********************************************************************
* Battery properties
*********************************************************************/
......@@ -401,6 +448,11 @@ static int olpc_bat_get_property(struct power_supply *psy,
sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
val->strval = bat_serial;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
ret = olpc_bat_get_voltage_max_design(val);
if (ret)
return ret;
break;
default:
ret = -EINVAL;
break;
......@@ -428,6 +480,7 @@ static enum power_supply_property olpc_xo1_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
};
/* XO-1.5 does not have ambient temperature property */
......@@ -449,6 +502,7 @@ static enum power_supply_property olpc_xo15_bat_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
POWER_SUPPLY_PROP_CHARGE_COUNTER,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
};
/* EEPROM reading goes completely around the power_supply API, sadly */
......