Skip to content

Commit

Permalink
Merge git://git.infradead.org/battery-2.6
Browse files Browse the repository at this point in the history
* git://git.infradead.org/battery-2.6:
  gpio-charger: Fix checking return value of request_any_context_irq
  power_supply: MAX17042: Support additional properties
  max8903_charger: Allow platform data to be __initdata
  power_supply: Add charger driver for MAX8998/LP3974
  power_supply: Add charger driver for MAX8997/8966
  max17042_battery: Remove obsolete cleanup for clientdata
  twl4030_charger: Fix warnings
  wm831x_power: Support multiple instances
  wm831x_backup: Support multiple instances
  apm_power: Fix style error in macros
  s3c_adc_battery: Fix annotation for s3c_adc_battery_probe()
  bq20z75: Enable detection after registering
  bq20z75: Add support for external notification
  • Loading branch information
Linus Torvalds committed Jul 31, 2011
2 parents 4d8a93c + f8c6391 commit f0d15c9
Show file tree
Hide file tree
Showing 18 changed files with 806 additions and 103 deletions.
2 changes: 2 additions & 0 deletions drivers/mfd/max8998.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static struct mfd_cell max8998_devs[] = {
.name = "max8998-pmic",
}, {
.name = "max8998-rtc",
}, {
.name = "max8998-battery",
},
};

Expand Down
14 changes: 14 additions & 0 deletions drivers/power/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,18 @@ config CHARGER_GPIO
This driver can be build as a module. If so, the module will be
called gpio-charger.

config CHARGER_MAX8997
tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver"
depends on MFD_MAX8997 && REGULATOR_MAX8997
help
Say Y to enable support for the battery charger control sysfs and
platform data of MAX8997/LP3974 PMICs.

config CHARGER_MAX8998
tristate "Maxim MAX8998/LP3974 PMIC battery charger driver"
depends on MFD_MAX8998 && REGULATOR_MAX8998
help
Say Y to enable support for the battery charger control sysfs and
platform data of MAX8998/LP3974 PMICs.

endif # POWER_SUPPLY
2 changes: 2 additions & 0 deletions drivers/power/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o
8 changes: 4 additions & 4 deletions drivers/power/apm_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include <linux/apm-emulation.h>


#define PSY_PROP(psy, prop, val) psy->get_property(psy, \
POWER_SUPPLY_PROP_##prop, val)
#define PSY_PROP(psy, prop, val) (psy->get_property(psy, \
POWER_SUPPLY_PROP_##prop, val))

#define _MPSY_PROP(prop, val) main_battery->get_property(main_battery, \
prop, val)
#define _MPSY_PROP(prop, val) (main_battery->get_property(main_battery, \
prop, val))

#define MPSY_PROP(prop, val) _MPSY_PROP(POWER_SUPPLY_PROP_##prop, val)

Expand Down
103 changes: 94 additions & 9 deletions drivers/power/bq20z75.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ struct bq20z75_info {
bool gpio_detect;
bool enable_detection;
int irq;
int last_state;
int poll_time;
struct delayed_work work;
int ignore_changes;
};

static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
Expand Down Expand Up @@ -279,6 +283,7 @@ static int bq20z75_get_battery_property(struct i2c_client *client,
int reg_offset, enum power_supply_property psp,
union power_supply_propval *val)
{
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
s32 ret;

ret = bq20z75_read_word_data(client,
Expand All @@ -293,15 +298,24 @@ static int bq20z75_get_battery_property(struct i2c_client *client,
if (ret >= bq20z75_data[reg_offset].min_value &&
ret <= bq20z75_data[reg_offset].max_value) {
val->intval = ret;
if (psp == POWER_SUPPLY_PROP_STATUS) {
if (ret & BATTERY_FULL_CHARGED)
val->intval = POWER_SUPPLY_STATUS_FULL;
else if (ret & BATTERY_FULL_DISCHARGED)
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
else if (ret & BATTERY_DISCHARGING)
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
else
val->intval = POWER_SUPPLY_STATUS_CHARGING;
if (psp != POWER_SUPPLY_PROP_STATUS)
return 0;

if (ret & BATTERY_FULL_CHARGED)
val->intval = POWER_SUPPLY_STATUS_FULL;
else if (ret & BATTERY_FULL_DISCHARGED)
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
else if (ret & BATTERY_DISCHARGING)
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
else
val->intval = POWER_SUPPLY_STATUS_CHARGING;

if (bq20z75_device->poll_time == 0)
bq20z75_device->last_state = val->intval;
else if (bq20z75_device->last_state != val->intval) {
cancel_delayed_work_sync(&bq20z75_device->work);
power_supply_changed(&bq20z75_device->power_supply);
bq20z75_device->poll_time = 0;
}
} else {
if (psp == POWER_SUPPLY_PROP_STATUS)
Expand Down Expand Up @@ -545,6 +559,60 @@ static irqreturn_t bq20z75_irq(int irq, void *devid)
return IRQ_HANDLED;
}

static void bq20z75_external_power_changed(struct power_supply *psy)
{
struct bq20z75_info *bq20z75_device;

bq20z75_device = container_of(psy, struct bq20z75_info, power_supply);

if (bq20z75_device->ignore_changes > 0) {
bq20z75_device->ignore_changes--;
return;
}

/* cancel outstanding work */
cancel_delayed_work_sync(&bq20z75_device->work);

schedule_delayed_work(&bq20z75_device->work, HZ);
bq20z75_device->poll_time = bq20z75_device->pdata->poll_retry_count;
}

static void bq20z75_delayed_work(struct work_struct *work)
{
struct bq20z75_info *bq20z75_device;
s32 ret;

bq20z75_device = container_of(work, struct bq20z75_info, work.work);

ret = bq20z75_read_word_data(bq20z75_device->client,
bq20z75_data[REG_STATUS].addr);
/* if the read failed, give up on this work */
if (ret < 0) {
bq20z75_device->poll_time = 0;
return;
}

if (ret & BATTERY_FULL_CHARGED)
ret = POWER_SUPPLY_STATUS_FULL;
else if (ret & BATTERY_FULL_DISCHARGED)
ret = POWER_SUPPLY_STATUS_NOT_CHARGING;
else if (ret & BATTERY_DISCHARGING)
ret = POWER_SUPPLY_STATUS_DISCHARGING;
else
ret = POWER_SUPPLY_STATUS_CHARGING;

if (bq20z75_device->last_state != ret) {
bq20z75_device->poll_time = 0;
power_supply_changed(&bq20z75_device->power_supply);
return;
}
if (bq20z75_device->poll_time > 0) {
schedule_delayed_work(&bq20z75_device->work, HZ);
bq20z75_device->poll_time--;
return;
}
}

static int __devinit bq20z75_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
Expand All @@ -566,6 +634,13 @@ static int __devinit bq20z75_probe(struct i2c_client *client,
bq20z75_device->power_supply.num_properties =
ARRAY_SIZE(bq20z75_properties);
bq20z75_device->power_supply.get_property = bq20z75_get_property;
/* ignore first notification of external change, it is generated
* from the power_supply_register call back
*/
bq20z75_device->ignore_changes = 1;
bq20z75_device->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
bq20z75_device->power_supply.external_power_changed =
bq20z75_external_power_changed;

if (pdata) {
bq20z75_device->gpio_detect =
Expand Down Expand Up @@ -625,6 +700,10 @@ static int __devinit bq20z75_probe(struct i2c_client *client,
dev_info(&client->dev,
"%s: battery gas gauge device registered\n", client->name);

INIT_DELAYED_WORK(&bq20z75_device->work, bq20z75_delayed_work);

bq20z75_device->enable_detection = true;

return 0;

exit_psupply:
Expand All @@ -648,6 +727,9 @@ static int __devexit bq20z75_remove(struct i2c_client *client)
gpio_free(bq20z75_device->pdata->battery_detect);

power_supply_unregister(&bq20z75_device->power_supply);

cancel_delayed_work_sync(&bq20z75_device->work);

kfree(bq20z75_device);
bq20z75_device = NULL;

Expand All @@ -661,6 +743,9 @@ static int bq20z75_suspend(struct i2c_client *client,
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
s32 ret;

if (bq20z75_device->poll_time > 0)
cancel_delayed_work_sync(&bq20z75_device->work);

/* write to manufacturer access with sleep command */
ret = bq20z75_write_word_data(client,
bq20z75_data[REG_MANUFACTURER_DATA].addr,
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/gpio-charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
ret = request_any_context_irq(irq, gpio_charger_irq,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
dev_name(&pdev->dev), charger);
if (ret)
if (ret < 0)
dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret);
else
gpio_charger->irq = irq;
Expand Down
Loading

0 comments on commit f0d15c9

Please sign in to comment.