Skip to content

Commit f0d15c9

Browse files
committed
Merge git://git.infradead.org/battery-2.6
* 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
2 parents 4d8a93c + f8c6391 commit f0d15c9

18 files changed

Lines changed: 806 additions & 103 deletions

‎drivers/mfd/max8998.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static struct mfd_cell max8998_devs[] = {
3939
.name = "max8998-pmic",
4040
}, {
4141
.name = "max8998-rtc",
42+
}, {
43+
.name = "max8998-battery",
4244
},
4345
};
4446

‎drivers/power/Kconfig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,18 @@ config CHARGER_GPIO
235235
This driver can be build as a module. If so, the module will be
236236
called gpio-charger.
237237

238+
config CHARGER_MAX8997
239+
tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver"
240+
depends on MFD_MAX8997 && REGULATOR_MAX8997
241+
help
242+
Say Y to enable support for the battery charger control sysfs and
243+
platform data of MAX8997/LP3974 PMICs.
244+
245+
config CHARGER_MAX8998
246+
tristate "Maxim MAX8998/LP3974 PMIC battery charger driver"
247+
depends on MFD_MAX8998 && REGULATOR_MAX8998
248+
help
249+
Say Y to enable support for the battery charger control sysfs and
250+
platform data of MAX8998/LP3974 PMICs.
251+
238252
endif # POWER_SUPPLY

‎drivers/power/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
3636
obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
3737
obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
3838
obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
39+
obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o
40+
obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o

‎drivers/power/apm_power.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#include <linux/apm-emulation.h>
1515

1616

17-
#define PSY_PROP(psy, prop, val) psy->get_property(psy, \
18-
POWER_SUPPLY_PROP_##prop, val)
17+
#define PSY_PROP(psy, prop, val) (psy->get_property(psy, \
18+
POWER_SUPPLY_PROP_##prop, val))
1919

20-
#define _MPSY_PROP(prop, val) main_battery->get_property(main_battery, \
21-
prop, val)
20+
#define _MPSY_PROP(prop, val) (main_battery->get_property(main_battery, \
21+
prop, val))
2222

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

‎drivers/power/bq20z75.c‎

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ struct bq20z75_info {
152152
bool gpio_detect;
153153
bool enable_detection;
154154
int irq;
155+
int last_state;
156+
int poll_time;
157+
struct delayed_work work;
158+
int ignore_changes;
155159
};
156160

157161
static int bq20z75_read_word_data(struct i2c_client *client, u8 address)
@@ -279,6 +283,7 @@ static int bq20z75_get_battery_property(struct i2c_client *client,
279283
int reg_offset, enum power_supply_property psp,
280284
union power_supply_propval *val)
281285
{
286+
struct bq20z75_info *bq20z75_device = i2c_get_clientdata(client);
282287
s32 ret;
283288

284289
ret = bq20z75_read_word_data(client,
@@ -293,15 +298,24 @@ static int bq20z75_get_battery_property(struct i2c_client *client,
293298
if (ret >= bq20z75_data[reg_offset].min_value &&
294299
ret <= bq20z75_data[reg_offset].max_value) {
295300
val->intval = ret;
296-
if (psp == POWER_SUPPLY_PROP_STATUS) {
297-
if (ret & BATTERY_FULL_CHARGED)
298-
val->intval = POWER_SUPPLY_STATUS_FULL;
299-
else if (ret & BATTERY_FULL_DISCHARGED)
300-
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
301-
else if (ret & BATTERY_DISCHARGING)
302-
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
303-
else
304-
val->intval = POWER_SUPPLY_STATUS_CHARGING;
301+
if (psp != POWER_SUPPLY_PROP_STATUS)
302+
return 0;
303+
304+
if (ret & BATTERY_FULL_CHARGED)
305+
val->intval = POWER_SUPPLY_STATUS_FULL;
306+
else if (ret & BATTERY_FULL_DISCHARGED)
307+
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
308+
else if (ret & BATTERY_DISCHARGING)
309+
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
310+
else
311+
val->intval = POWER_SUPPLY_STATUS_CHARGING;
312+
313+
if (bq20z75_device->poll_time == 0)
314+
bq20z75_device->last_state = val->intval;
315+
else if (bq20z75_device->last_state != val->intval) {
316+
cancel_delayed_work_sync(&bq20z75_device->work);
317+
power_supply_changed(&bq20z75_device->power_supply);
318+
bq20z75_device->poll_time = 0;
305319
}
306320
} else {
307321
if (psp == POWER_SUPPLY_PROP_STATUS)
@@ -545,6 +559,60 @@ static irqreturn_t bq20z75_irq(int irq, void *devid)
545559
return IRQ_HANDLED;
546560
}
547561

562+
static void bq20z75_external_power_changed(struct power_supply *psy)
563+
{
564+
struct bq20z75_info *bq20z75_device;
565+
566+
bq20z75_device = container_of(psy, struct bq20z75_info, power_supply);
567+
568+
if (bq20z75_device->ignore_changes > 0) {
569+
bq20z75_device->ignore_changes--;
570+
return;
571+
}
572+
573+
/* cancel outstanding work */
574+
cancel_delayed_work_sync(&bq20z75_device->work);
575+
576+
schedule_delayed_work(&bq20z75_device->work, HZ);
577+
bq20z75_device->poll_time = bq20z75_device->pdata->poll_retry_count;
578+
}
579+
580+
static void bq20z75_delayed_work(struct work_struct *work)
581+
{
582+
struct bq20z75_info *bq20z75_device;
583+
s32 ret;
584+
585+
bq20z75_device = container_of(work, struct bq20z75_info, work.work);
586+
587+
ret = bq20z75_read_word_data(bq20z75_device->client,
588+
bq20z75_data[REG_STATUS].addr);
589+
/* if the read failed, give up on this work */
590+
if (ret < 0) {
591+
bq20z75_device->poll_time = 0;
592+
return;
593+
}
594+
595+
if (ret & BATTERY_FULL_CHARGED)
596+
ret = POWER_SUPPLY_STATUS_FULL;
597+
else if (ret & BATTERY_FULL_DISCHARGED)
598+
ret = POWER_SUPPLY_STATUS_NOT_CHARGING;
599+
else if (ret & BATTERY_DISCHARGING)
600+
ret = POWER_SUPPLY_STATUS_DISCHARGING;
601+
else
602+
ret = POWER_SUPPLY_STATUS_CHARGING;
603+
604+
if (bq20z75_device->last_state != ret) {
605+
bq20z75_device->poll_time = 0;
606+
power_supply_changed(&bq20z75_device->power_supply);
607+
return;
608+
}
609+
if (bq20z75_device->poll_time > 0) {
610+
schedule_delayed_work(&bq20z75_device->work, HZ);
611+
bq20z75_device->poll_time--;
612+
return;
613+
}
614+
}
615+
548616
static int __devinit bq20z75_probe(struct i2c_client *client,
549617
const struct i2c_device_id *id)
550618
{
@@ -566,6 +634,13 @@ static int __devinit bq20z75_probe(struct i2c_client *client,
566634
bq20z75_device->power_supply.num_properties =
567635
ARRAY_SIZE(bq20z75_properties);
568636
bq20z75_device->power_supply.get_property = bq20z75_get_property;
637+
/* ignore first notification of external change, it is generated
638+
* from the power_supply_register call back
639+
*/
640+
bq20z75_device->ignore_changes = 1;
641+
bq20z75_device->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
642+
bq20z75_device->power_supply.external_power_changed =
643+
bq20z75_external_power_changed;
569644

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

703+
INIT_DELAYED_WORK(&bq20z75_device->work, bq20z75_delayed_work);
704+
705+
bq20z75_device->enable_detection = true;
706+
628707
return 0;
629708

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

650729
power_supply_unregister(&bq20z75_device->power_supply);
730+
731+
cancel_delayed_work_sync(&bq20z75_device->work);
732+
651733
kfree(bq20z75_device);
652734
bq20z75_device = NULL;
653735

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

746+
if (bq20z75_device->poll_time > 0)
747+
cancel_delayed_work_sync(&bq20z75_device->work);
748+
664749
/* write to manufacturer access with sleep command */
665750
ret = bq20z75_write_word_data(client,
666751
bq20z75_data[REG_MANUFACTURER_DATA].addr,

‎drivers/power/gpio-charger.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int __devinit gpio_charger_probe(struct platform_device *pdev)
127127
ret = request_any_context_irq(irq, gpio_charger_irq,
128128
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
129129
dev_name(&pdev->dev), charger);
130-
if (ret)
130+
if (ret < 0)
131131
dev_warn(&pdev->dev, "Failed to request irq: %d\n", ret);
132132
else
133133
gpio_charger->irq = irq;

0 commit comments

Comments
 (0)