diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-14 13:45:11 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-14 13:45:11 -0500 |
commit | 5c43019f25977fb6119dff471d592321ed0d2333 (patch) | |
tree | 17589e88fe53f2492db4bbc133e324bbae701571 | |
parent | c25949d4cc22449414fe73bc930bdf650078e877 (diff) | |
parent | 265b60497a57da56a4be7d5c72983ae89dc0765e (diff) |
Merge tag 'for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply
Pull power supply and reset updates from Sebastian Reichel:
"I have mostly fixes in the power-supply tree for the 4.5 kernel. I
should mention, that the top-most commit has not been in next, but
it's a fix changing only a single register offset.
Summary:
- uncouple CONFIG_POWER_RESET from CONFIG_POWER_SUPPLY
- misc fixes"
* tag 'for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply:
power: bq27xxx_battery: Fix bq27541 AveragePower register address
power: test_power: correctly handle empty writes
power: generic-adc-battery: use to_delayed_work
power: isp1704_charger: Fix isp1704_write() definition
power: bq27xxx: fix register numbers of bq27500
power: bq27xxx: fix reading for bq27000 and bq27010
power: Fix unmet dependency on POWER_SUPPLY by POWER_RESET by uncoupling them
power: bq27xxx_battery: Reorganize I2C into a module
power: bq27xxx: don't fill system log by missing battery
power: max8903_charger: set IRQF_ONESHOT if no primary handler is specified
power/reset: at91-reset: add missing of_node_put
power: ds2782_battery: constify ds278x_battery_ops structure
power: bq2415x_charger: Delete unnecessary checks before the function call "of_node_put"
-rw-r--r-- | drivers/Makefile | 2 | ||||
-rw-r--r-- | drivers/power/Kconfig | 17 | ||||
-rw-r--r-- | drivers/power/Makefile | 1 | ||||
-rw-r--r-- | drivers/power/bq2415x_charger.c | 6 | ||||
-rw-r--r-- | drivers/power/bq27xxx_battery.c | 348 | ||||
-rw-r--r-- | drivers/power/bq27xxx_battery_i2c.c | 150 | ||||
-rw-r--r-- | drivers/power/ds2782_battery.c | 4 | ||||
-rw-r--r-- | drivers/power/generic-adc-battery.c | 2 | ||||
-rw-r--r-- | drivers/power/isp1704_charger.c | 2 | ||||
-rw-r--r-- | drivers/power/max8903_charger.c | 24 | ||||
-rw-r--r-- | drivers/power/reset/at91-reset.c | 1 | ||||
-rw-r--r-- | drivers/power/test_power.c | 2 | ||||
-rw-r--r-- | include/linux/power/bq27xxx_battery.h | 57 |
13 files changed, 264 insertions, 352 deletions
diff --git a/drivers/Makefile b/drivers/Makefile index 795d0ca714bf..8f5d076baeb0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -106,7 +106,7 @@ obj-y += i2c/ media/ | |||
106 | obj-$(CONFIG_PPS) += pps/ | 106 | obj-$(CONFIG_PPS) += pps/ |
107 | obj-$(CONFIG_PTP_1588_CLOCK) += ptp/ | 107 | obj-$(CONFIG_PTP_1588_CLOCK) += ptp/ |
108 | obj-$(CONFIG_W1) += w1/ | 108 | obj-$(CONFIG_W1) += w1/ |
109 | obj-$(CONFIG_POWER_SUPPLY) += power/ | 109 | obj-y += power/ |
110 | obj-$(CONFIG_HWMON) += hwmon/ | 110 | obj-$(CONFIG_HWMON) += hwmon/ |
111 | obj-$(CONFIG_THERMAL) += thermal/ | 111 | obj-$(CONFIG_THERMAL) += thermal/ |
112 | obj-$(CONFIG_WATCHDOG) += watchdog/ | 112 | obj-$(CONFIG_WATCHDOG) += watchdog/ |
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 237d7aa73e8c..1ddd13cc0c07 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig | |||
@@ -160,22 +160,16 @@ config BATTERY_SBS | |||
160 | config BATTERY_BQ27XXX | 160 | config BATTERY_BQ27XXX |
161 | tristate "BQ27xxx battery driver" | 161 | tristate "BQ27xxx battery driver" |
162 | help | 162 | help |
163 | Say Y here to enable support for batteries with BQ27xxx (I2C/HDQ) chips. | 163 | Say Y here to enable support for batteries with BQ27xxx chips. |
164 | 164 | ||
165 | config BATTERY_BQ27XXX_I2C | 165 | config BATTERY_BQ27XXX_I2C |
166 | bool "BQ27xxx I2C support" | 166 | tristate "BQ27xxx I2C support" |
167 | depends on BATTERY_BQ27XXX | 167 | depends on BATTERY_BQ27XXX |
168 | depends on I2C | 168 | depends on I2C |
169 | default y | 169 | default y |
170 | help | 170 | help |
171 | Say Y here to enable support for batteries with BQ27xxx (I2C) chips. | 171 | Say Y here to enable support for batteries with BQ27xxx chips |
172 | 172 | connected over an I2C bus. | |
173 | config BATTERY_BQ27XXX_PLATFORM | ||
174 | bool "BQ27xxx HDQ support" | ||
175 | depends on BATTERY_BQ27XXX | ||
176 | default y | ||
177 | help | ||
178 | Say Y here to enable support for batteries with BQ27xxx (HDQ) chips. | ||
179 | 173 | ||
180 | config BATTERY_DA9030 | 174 | config BATTERY_DA9030 |
181 | tristate "DA9030 battery driver" | 175 | tristate "DA9030 battery driver" |
@@ -508,8 +502,7 @@ config AXP20X_POWER | |||
508 | This driver provides support for the power supply features of | 502 | This driver provides support for the power supply features of |
509 | AXP20x PMIC. | 503 | AXP20x PMIC. |
510 | 504 | ||
511 | source "drivers/power/reset/Kconfig" | ||
512 | |||
513 | endif # POWER_SUPPLY | 505 | endif # POWER_SUPPLY |
514 | 506 | ||
507 | source "drivers/power/reset/Kconfig" | ||
515 | source "drivers/power/avs/Kconfig" | 508 | source "drivers/power/avs/Kconfig" |
diff --git a/drivers/power/Makefile b/drivers/power/Makefile index b656638f8b39..0e4eab55f8d7 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile | |||
@@ -31,6 +31,7 @@ obj-$(CONFIG_BATTERY_IPAQ_MICRO) += ipaq_micro_battery.o | |||
31 | obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o | 31 | obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o |
32 | obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o | 32 | obj-$(CONFIG_BATTERY_SBS) += sbs-battery.o |
33 | obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o | 33 | obj-$(CONFIG_BATTERY_BQ27XXX) += bq27xxx_battery.o |
34 | obj-$(CONFIG_BATTERY_BQ27XXX_I2C) += bq27xxx_battery_i2c.o | ||
34 | obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o | 35 | obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o |
35 | obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o | 36 | obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o |
36 | obj-$(CONFIG_CHARGER_DA9150) += da9150-charger.o | 37 | obj-$(CONFIG_CHARGER_DA9150) += da9150-charger.o |
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index 4afd76848bce..27e89536689a 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c | |||
@@ -1704,7 +1704,7 @@ error_4: | |||
1704 | error_3: | 1704 | error_3: |
1705 | bq2415x_power_supply_exit(bq); | 1705 | bq2415x_power_supply_exit(bq); |
1706 | error_2: | 1706 | error_2: |
1707 | if (bq && bq->notify_node) | 1707 | if (bq) |
1708 | of_node_put(bq->notify_node); | 1708 | of_node_put(bq->notify_node); |
1709 | kfree(name); | 1709 | kfree(name); |
1710 | error_1: | 1710 | error_1: |
@@ -1724,9 +1724,7 @@ static int bq2415x_remove(struct i2c_client *client) | |||
1724 | if (bq->nb.notifier_call) | 1724 | if (bq->nb.notifier_call) |
1725 | power_supply_unreg_notifier(&bq->nb); | 1725 | power_supply_unreg_notifier(&bq->nb); |
1726 | 1726 | ||
1727 | if (bq->notify_node) | 1727 | of_node_put(bq->notify_node); |
1728 | of_node_put(bq->notify_node); | ||
1729 | |||
1730 | bq2415x_sysfs_exit(bq); | 1728 | bq2415x_sysfs_exit(bq); |
1731 | bq2415x_power_supply_exit(bq); | 1729 | bq2415x_power_supply_exit(bq); |
1732 | 1730 | ||
diff --git a/drivers/power/bq27xxx_battery.c b/drivers/power/bq27xxx_battery.c index 880233ce9343..6b027a418943 100644 --- a/drivers/power/bq27xxx_battery.c +++ b/drivers/power/bq27xxx_battery.c | |||
@@ -45,11 +45,7 @@ | |||
45 | #include <linux/delay.h> | 45 | #include <linux/delay.h> |
46 | #include <linux/platform_device.h> | 46 | #include <linux/platform_device.h> |
47 | #include <linux/power_supply.h> | 47 | #include <linux/power_supply.h> |
48 | #include <linux/idr.h> | ||
49 | #include <linux/i2c.h> | ||
50 | #include <linux/slab.h> | 48 | #include <linux/slab.h> |
51 | #include <linux/interrupt.h> | ||
52 | #include <asm/unaligned.h> | ||
53 | 49 | ||
54 | #include <linux/power/bq27xxx_battery.h> | 50 | #include <linux/power/bq27xxx_battery.h> |
55 | 51 | ||
@@ -78,11 +74,6 @@ | |||
78 | #define BQ27XXX_POWER_CONSTANT (29200) /* 29.2 µV^2 * 1000 */ | 74 | #define BQ27XXX_POWER_CONSTANT (29200) /* 29.2 µV^2 * 1000 */ |
79 | #define BQ27XXX_CURRENT_CONSTANT (3570) /* 3.57 µV * 1000 */ | 75 | #define BQ27XXX_CURRENT_CONSTANT (3570) /* 3.57 µV * 1000 */ |
80 | 76 | ||
81 | struct bq27xxx_device_info; | ||
82 | struct bq27xxx_access_methods { | ||
83 | int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single); | ||
84 | }; | ||
85 | |||
86 | #define INVALID_REG_ADDR 0xff | 77 | #define INVALID_REG_ADDR 0xff |
87 | 78 | ||
88 | /* | 79 | /* |
@@ -110,40 +101,6 @@ enum bq27xxx_reg_index { | |||
110 | BQ27XXX_REG_AP, /* Average Power */ | 101 | BQ27XXX_REG_AP, /* Average Power */ |
111 | }; | 102 | }; |
112 | 103 | ||
113 | struct bq27xxx_reg_cache { | ||
114 | int temperature; | ||
115 | int time_to_empty; | ||
116 | int time_to_empty_avg; | ||
117 | int time_to_full; | ||
118 | int charge_full; | ||
119 | int cycle_count; | ||
120 | int capacity; | ||
121 | int energy; | ||
122 | int flags; | ||
123 | int power_avg; | ||
124 | int health; | ||
125 | }; | ||
126 | |||
127 | struct bq27xxx_device_info { | ||
128 | struct device *dev; | ||
129 | int id; | ||
130 | enum bq27xxx_chip chip; | ||
131 | |||
132 | struct bq27xxx_reg_cache cache; | ||
133 | int charge_design_full; | ||
134 | |||
135 | unsigned long last_update; | ||
136 | struct delayed_work work; | ||
137 | |||
138 | struct power_supply *bat; | ||
139 | |||
140 | struct bq27xxx_access_methods bus; | ||
141 | |||
142 | struct mutex lock; | ||
143 | |||
144 | u8 *regs; | ||
145 | }; | ||
146 | |||
147 | /* Register mappings */ | 104 | /* Register mappings */ |
148 | static u8 bq27000_regs[] = { | 105 | static u8 bq27000_regs[] = { |
149 | 0x00, /* CONTROL */ | 106 | 0x00, /* CONTROL */ |
@@ -198,10 +155,10 @@ static u8 bq27500_regs[] = { | |||
198 | INVALID_REG_ADDR, /* TTECP - NA */ | 155 | INVALID_REG_ADDR, /* TTECP - NA */ |
199 | 0x0c, /* NAC */ | 156 | 0x0c, /* NAC */ |
200 | 0x12, /* LMD(FCC) */ | 157 | 0x12, /* LMD(FCC) */ |
201 | 0x1e, /* CYCT */ | 158 | 0x2a, /* CYCT */ |
202 | INVALID_REG_ADDR, /* AE - NA */ | 159 | INVALID_REG_ADDR, /* AE - NA */ |
203 | 0x20, /* SOC(RSOC) */ | 160 | 0x2c, /* SOC(RSOC) */ |
204 | 0x2e, /* DCAP(ILMD) */ | 161 | 0x3c, /* DCAP(ILMD) */ |
205 | INVALID_REG_ADDR, /* AP - NA */ | 162 | INVALID_REG_ADDR, /* AP - NA */ |
206 | }; | 163 | }; |
207 | 164 | ||
@@ -242,7 +199,7 @@ static u8 bq27541_regs[] = { | |||
242 | INVALID_REG_ADDR, /* AE - NA */ | 199 | INVALID_REG_ADDR, /* AE - NA */ |
243 | 0x2c, /* SOC(RSOC) */ | 200 | 0x2c, /* SOC(RSOC) */ |
244 | 0x3c, /* DCAP */ | 201 | 0x3c, /* DCAP */ |
245 | 0x76, /* AP */ | 202 | 0x24, /* AP */ |
246 | }; | 203 | }; |
247 | 204 | ||
248 | static u8 bq27545_regs[] = { | 205 | static u8 bq27545_regs[] = { |
@@ -471,7 +428,10 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di) | |||
471 | { | 428 | { |
472 | int soc; | 429 | int soc; |
473 | 430 | ||
474 | soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false); | 431 | if (di->chip == BQ27000 || di->chip == BQ27010) |
432 | soc = bq27xxx_read(di, BQ27XXX_REG_SOC, true); | ||
433 | else | ||
434 | soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false); | ||
475 | 435 | ||
476 | if (soc < 0) | 436 | if (soc < 0) |
477 | dev_dbg(di->dev, "error reading State-of-Charge\n"); | 437 | dev_dbg(di->dev, "error reading State-of-Charge\n"); |
@@ -536,7 +496,10 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di) | |||
536 | { | 496 | { |
537 | int dcap; | 497 | int dcap; |
538 | 498 | ||
539 | dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); | 499 | if (di->chip == BQ27000 || di->chip == BQ27010) |
500 | dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, true); | ||
501 | else | ||
502 | dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false); | ||
540 | 503 | ||
541 | if (dcap < 0) { | 504 | if (dcap < 0) { |
542 | dev_dbg(di->dev, "error reading initial last measured discharge\n"); | 505 | dev_dbg(di->dev, "error reading initial last measured discharge\n"); |
@@ -544,7 +507,7 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di) | |||
544 | } | 507 | } |
545 | 508 | ||
546 | if (di->chip == BQ27000 || di->chip == BQ27010) | 509 | if (di->chip == BQ27000 || di->chip == BQ27010) |
547 | dcap *= BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; | 510 | dcap = (dcap << 8) * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; |
548 | else | 511 | else |
549 | dcap *= 1000; | 512 | dcap *= 1000; |
550 | 513 | ||
@@ -710,7 +673,7 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) | |||
710 | return POWER_SUPPLY_HEALTH_GOOD; | 673 | return POWER_SUPPLY_HEALTH_GOOD; |
711 | } | 674 | } |
712 | 675 | ||
713 | static void bq27xxx_battery_update(struct bq27xxx_device_info *di) | 676 | void bq27xxx_battery_update(struct bq27xxx_device_info *di) |
714 | { | 677 | { |
715 | struct bq27xxx_reg_cache cache = {0, }; | 678 | struct bq27xxx_reg_cache cache = {0, }; |
716 | bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010; | 679 | bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010; |
@@ -722,7 +685,7 @@ static void bq27xxx_battery_update(struct bq27xxx_device_info *di) | |||
722 | if (cache.flags >= 0) { | 685 | if (cache.flags >= 0) { |
723 | cache.temperature = bq27xxx_battery_read_temperature(di); | 686 | cache.temperature = bq27xxx_battery_read_temperature(di); |
724 | if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) { | 687 | if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) { |
725 | dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); | 688 | dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n"); |
726 | cache.capacity = -ENODATA; | 689 | cache.capacity = -ENODATA; |
727 | cache.energy = -ENODATA; | 690 | cache.energy = -ENODATA; |
728 | cache.time_to_empty = -ENODATA; | 691 | cache.time_to_empty = -ENODATA; |
@@ -761,6 +724,7 @@ static void bq27xxx_battery_update(struct bq27xxx_device_info *di) | |||
761 | 724 | ||
762 | di->last_update = jiffies; | 725 | di->last_update = jiffies; |
763 | } | 726 | } |
727 | EXPORT_SYMBOL_GPL(bq27xxx_battery_update); | ||
764 | 728 | ||
765 | static void bq27xxx_battery_poll(struct work_struct *work) | 729 | static void bq27xxx_battery_poll(struct work_struct *work) |
766 | { | 730 | { |
@@ -991,32 +955,30 @@ static void bq27xxx_external_power_changed(struct power_supply *psy) | |||
991 | schedule_delayed_work(&di->work, 0); | 955 | schedule_delayed_work(&di->work, 0); |
992 | } | 956 | } |
993 | 957 | ||
994 | static int bq27xxx_powersupply_init(struct bq27xxx_device_info *di, | 958 | int bq27xxx_battery_setup(struct bq27xxx_device_info *di) |
995 | const char *name) | ||
996 | { | 959 | { |
997 | int ret; | ||
998 | struct power_supply_desc *psy_desc; | 960 | struct power_supply_desc *psy_desc; |
999 | struct power_supply_config psy_cfg = { .drv_data = di, }; | 961 | struct power_supply_config psy_cfg = { .drv_data = di, }; |
1000 | 962 | ||
963 | INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); | ||
964 | mutex_init(&di->lock); | ||
965 | di->regs = bq27xxx_regs[di->chip]; | ||
966 | |||
1001 | psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL); | 967 | psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL); |
1002 | if (!psy_desc) | 968 | if (!psy_desc) |
1003 | return -ENOMEM; | 969 | return -ENOMEM; |
1004 | 970 | ||
1005 | psy_desc->name = name; | 971 | psy_desc->name = di->name; |
1006 | psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; | 972 | psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; |
1007 | psy_desc->properties = bq27xxx_battery_props[di->chip].props; | 973 | psy_desc->properties = bq27xxx_battery_props[di->chip].props; |
1008 | psy_desc->num_properties = bq27xxx_battery_props[di->chip].size; | 974 | psy_desc->num_properties = bq27xxx_battery_props[di->chip].size; |
1009 | psy_desc->get_property = bq27xxx_battery_get_property; | 975 | psy_desc->get_property = bq27xxx_battery_get_property; |
1010 | psy_desc->external_power_changed = bq27xxx_external_power_changed; | 976 | psy_desc->external_power_changed = bq27xxx_external_power_changed; |
1011 | 977 | ||
1012 | INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll); | ||
1013 | mutex_init(&di->lock); | ||
1014 | |||
1015 | di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg); | 978 | di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg); |
1016 | if (IS_ERR(di->bat)) { | 979 | if (IS_ERR(di->bat)) { |
1017 | ret = PTR_ERR(di->bat); | 980 | dev_err(di->dev, "failed to register battery\n"); |
1018 | dev_err(di->dev, "failed to register battery: %d\n", ret); | 981 | return PTR_ERR(di->bat); |
1019 | return ret; | ||
1020 | } | 982 | } |
1021 | 983 | ||
1022 | dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); | 984 | dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION); |
@@ -1025,8 +987,9 @@ static int bq27xxx_powersupply_init(struct bq27xxx_device_info *di, | |||
1025 | 987 | ||
1026 | return 0; | 988 | return 0; |
1027 | } | 989 | } |
990 | EXPORT_SYMBOL_GPL(bq27xxx_battery_setup); | ||
1028 | 991 | ||
1029 | static void bq27xxx_powersupply_unregister(struct bq27xxx_device_info *di) | 992 | void bq27xxx_battery_teardown(struct bq27xxx_device_info *di) |
1030 | { | 993 | { |
1031 | /* | 994 | /* |
1032 | * power_supply_unregister call bq27xxx_battery_get_property which | 995 | * power_supply_unregister call bq27xxx_battery_get_property which |
@@ -1042,192 +1005,7 @@ static void bq27xxx_powersupply_unregister(struct bq27xxx_device_info *di) | |||
1042 | 1005 | ||
1043 | mutex_destroy(&di->lock); | 1006 | mutex_destroy(&di->lock); |
1044 | } | 1007 | } |
1045 | 1008 | EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown); | |
1046 | /* i2c specific code */ | ||
1047 | #ifdef CONFIG_BATTERY_BQ27XXX_I2C | ||
1048 | |||
1049 | /* If the system has several batteries we need a different name for each | ||
1050 | * of them... | ||
1051 | */ | ||
1052 | static DEFINE_IDR(battery_id); | ||
1053 | static DEFINE_MUTEX(battery_mutex); | ||
1054 | |||
1055 | static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data) | ||
1056 | { | ||
1057 | struct bq27xxx_device_info *di = data; | ||
1058 | |||
1059 | bq27xxx_battery_update(di); | ||
1060 | |||
1061 | return IRQ_HANDLED; | ||
1062 | } | ||
1063 | |||
1064 | static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg, | ||
1065 | bool single) | ||
1066 | { | ||
1067 | struct i2c_client *client = to_i2c_client(di->dev); | ||
1068 | struct i2c_msg msg[2]; | ||
1069 | unsigned char data[2]; | ||
1070 | int ret; | ||
1071 | |||
1072 | if (!client->adapter) | ||
1073 | return -ENODEV; | ||
1074 | |||
1075 | msg[0].addr = client->addr; | ||
1076 | msg[0].flags = 0; | ||
1077 | msg[0].buf = ® | ||
1078 | msg[0].len = sizeof(reg); | ||
1079 | msg[1].addr = client->addr; | ||
1080 | msg[1].flags = I2C_M_RD; | ||
1081 | msg[1].buf = data; | ||
1082 | if (single) | ||
1083 | msg[1].len = 1; | ||
1084 | else | ||
1085 | msg[1].len = 2; | ||
1086 | |||
1087 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); | ||
1088 | if (ret < 0) | ||
1089 | return ret; | ||
1090 | |||
1091 | if (!single) | ||
1092 | ret = get_unaligned_le16(data); | ||
1093 | else | ||
1094 | ret = data[0]; | ||
1095 | |||
1096 | return ret; | ||
1097 | } | ||
1098 | |||
1099 | static int bq27xxx_battery_i2c_probe(struct i2c_client *client, | ||
1100 | const struct i2c_device_id *id) | ||
1101 | { | ||
1102 | char *name; | ||
1103 | struct bq27xxx_device_info *di; | ||
1104 | int num; | ||
1105 | int retval = 0; | ||
1106 | |||
1107 | /* Get new ID for the new battery device */ | ||
1108 | mutex_lock(&battery_mutex); | ||
1109 | num = idr_alloc(&battery_id, client, 0, 0, GFP_KERNEL); | ||
1110 | mutex_unlock(&battery_mutex); | ||
1111 | if (num < 0) | ||
1112 | return num; | ||
1113 | |||
1114 | name = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%d", id->name, num); | ||
1115 | if (!name) { | ||
1116 | retval = -ENOMEM; | ||
1117 | goto batt_failed; | ||
1118 | } | ||
1119 | |||
1120 | di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); | ||
1121 | if (!di) { | ||
1122 | retval = -ENOMEM; | ||
1123 | goto batt_failed; | ||
1124 | } | ||
1125 | |||
1126 | di->id = num; | ||
1127 | di->dev = &client->dev; | ||
1128 | di->chip = id->driver_data; | ||
1129 | di->bus.read = &bq27xxx_battery_i2c_read; | ||
1130 | di->regs = bq27xxx_regs[di->chip]; | ||
1131 | |||
1132 | retval = bq27xxx_powersupply_init(di, name); | ||
1133 | if (retval) | ||
1134 | goto batt_failed; | ||
1135 | |||
1136 | /* Schedule a polling after about 1 min */ | ||
1137 | schedule_delayed_work(&di->work, 60 * HZ); | ||
1138 | |||
1139 | i2c_set_clientdata(client, di); | ||
1140 | |||
1141 | if (client->irq) { | ||
1142 | retval = devm_request_threaded_irq(&client->dev, client->irq, | ||
1143 | NULL, bq27xxx_battery_irq_handler_thread, | ||
1144 | IRQF_ONESHOT, | ||
1145 | name, di); | ||
1146 | if (retval) { | ||
1147 | dev_err(&client->dev, | ||
1148 | "Unable to register IRQ %d error %d\n", | ||
1149 | client->irq, retval); | ||
1150 | return retval; | ||
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | return 0; | ||
1155 | |||
1156 | batt_failed: | ||
1157 | mutex_lock(&battery_mutex); | ||
1158 | idr_remove(&battery_id, num); | ||
1159 | mutex_unlock(&battery_mutex); | ||
1160 | |||
1161 | return retval; | ||
1162 | } | ||
1163 | |||
1164 | static int bq27xxx_battery_i2c_remove(struct i2c_client *client) | ||
1165 | { | ||
1166 | struct bq27xxx_device_info *di = i2c_get_clientdata(client); | ||
1167 | |||
1168 | bq27xxx_powersupply_unregister(di); | ||
1169 | |||
1170 | mutex_lock(&battery_mutex); | ||
1171 | idr_remove(&battery_id, di->id); | ||
1172 | mutex_unlock(&battery_mutex); | ||
1173 | |||
1174 | return 0; | ||
1175 | } | ||
1176 | |||
1177 | static const struct i2c_device_id bq27xxx_id[] = { | ||
1178 | { "bq27200", BQ27000 }, | ||
1179 | { "bq27210", BQ27010 }, | ||
1180 | { "bq27500", BQ27500 }, | ||
1181 | { "bq27510", BQ27500 }, | ||
1182 | { "bq27520", BQ27500 }, | ||
1183 | { "bq27530", BQ27530 }, | ||
1184 | { "bq27531", BQ27530 }, | ||
1185 | { "bq27541", BQ27541 }, | ||
1186 | { "bq27542", BQ27541 }, | ||
1187 | { "bq27546", BQ27541 }, | ||
1188 | { "bq27742", BQ27541 }, | ||
1189 | { "bq27545", BQ27545 }, | ||
1190 | { "bq27421", BQ27421 }, | ||
1191 | { "bq27425", BQ27421 }, | ||
1192 | { "bq27441", BQ27421 }, | ||
1193 | { "bq27621", BQ27421 }, | ||
1194 | {}, | ||
1195 | }; | ||
1196 | MODULE_DEVICE_TABLE(i2c, bq27xxx_id); | ||
1197 | |||
1198 | static struct i2c_driver bq27xxx_battery_i2c_driver = { | ||
1199 | .driver = { | ||
1200 | .name = "bq27xxx-battery", | ||
1201 | }, | ||
1202 | .probe = bq27xxx_battery_i2c_probe, | ||
1203 | .remove = bq27xxx_battery_i2c_remove, | ||
1204 | .id_table = bq27xxx_id, | ||
1205 | }; | ||
1206 | |||
1207 | static inline int bq27xxx_battery_i2c_init(void) | ||
1208 | { | ||
1209 | int ret = i2c_add_driver(&bq27xxx_battery_i2c_driver); | ||
1210 | |||
1211 | if (ret) | ||
1212 | pr_err("Unable to register BQ27xxx i2c driver\n"); | ||
1213 | |||
1214 | return ret; | ||
1215 | } | ||
1216 | |||
1217 | static inline void bq27xxx_battery_i2c_exit(void) | ||
1218 | { | ||
1219 | i2c_del_driver(&bq27xxx_battery_i2c_driver); | ||
1220 | } | ||
1221 | |||
1222 | #else | ||
1223 | |||
1224 | static inline int bq27xxx_battery_i2c_init(void) { return 0; } | ||
1225 | static inline void bq27xxx_battery_i2c_exit(void) {}; | ||
1226 | |||
1227 | #endif | ||
1228 | |||
1229 | /* platform specific code */ | ||
1230 | #ifdef CONFIG_BATTERY_BQ27XXX_PLATFORM | ||
1231 | 1009 | ||
1232 | static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg, | 1010 | static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg, |
1233 | bool single) | 1011 | bool single) |
@@ -1267,7 +1045,6 @@ static int bq27xxx_battery_platform_probe(struct platform_device *pdev) | |||
1267 | { | 1045 | { |
1268 | struct bq27xxx_device_info *di; | 1046 | struct bq27xxx_device_info *di; |
1269 | struct bq27xxx_platform_data *pdata = pdev->dev.platform_data; | 1047 | struct bq27xxx_platform_data *pdata = pdev->dev.platform_data; |
1270 | const char *name; | ||
1271 | 1048 | ||
1272 | if (!pdata) { | 1049 | if (!pdata) { |
1273 | dev_err(&pdev->dev, "no platform_data supplied\n"); | 1050 | dev_err(&pdev->dev, "no platform_data supplied\n"); |
@@ -1292,83 +1069,36 @@ static int bq27xxx_battery_platform_probe(struct platform_device *pdev) | |||
1292 | 1069 | ||
1293 | di->dev = &pdev->dev; | 1070 | di->dev = &pdev->dev; |
1294 | di->chip = pdata->chip; | 1071 | di->chip = pdata->chip; |
1295 | di->regs = bq27xxx_regs[di->chip]; | 1072 | di->name = pdata->name ?: dev_name(&pdev->dev); |
1296 | 1073 | di->bus.read = bq27xxx_battery_platform_read; | |
1297 | name = pdata->name ?: dev_name(&pdev->dev); | ||
1298 | di->bus.read = &bq27xxx_battery_platform_read; | ||
1299 | 1074 | ||
1300 | return bq27xxx_powersupply_init(di, name); | 1075 | return bq27xxx_battery_setup(di); |
1301 | } | 1076 | } |
1302 | 1077 | ||
1303 | static int bq27xxx_battery_platform_remove(struct platform_device *pdev) | 1078 | static int bq27xxx_battery_platform_remove(struct platform_device *pdev) |
1304 | { | 1079 | { |
1305 | struct bq27xxx_device_info *di = platform_get_drvdata(pdev); | 1080 | struct bq27xxx_device_info *di = platform_get_drvdata(pdev); |
1306 | 1081 | ||
1307 | bq27xxx_powersupply_unregister(di); | 1082 | bq27xxx_battery_teardown(di); |
1308 | 1083 | ||
1309 | return 0; | 1084 | return 0; |
1310 | } | 1085 | } |
1311 | 1086 | ||
1087 | static const struct platform_device_id bq27xxx_battery_platform_id_table[] = { | ||
1088 | { "bq27000-battery", }, | ||
1089 | { /* sentinel */ } | ||
1090 | }; | ||
1091 | MODULE_DEVICE_TABLE(platform, bq27xxx_battery_platform_id_table); | ||
1092 | |||
1312 | static struct platform_driver bq27xxx_battery_platform_driver = { | 1093 | static struct platform_driver bq27xxx_battery_platform_driver = { |
1313 | .probe = bq27xxx_battery_platform_probe, | 1094 | .probe = bq27xxx_battery_platform_probe, |
1314 | .remove = bq27xxx_battery_platform_remove, | 1095 | .remove = bq27xxx_battery_platform_remove, |
1315 | .driver = { | 1096 | .driver = { |
1316 | .name = "bq27000-battery", | 1097 | .name = "bq27000-battery", |
1317 | }, | 1098 | }, |
1099 | .id_table = bq27xxx_battery_platform_id_table, | ||
1318 | }; | 1100 | }; |
1319 | 1101 | module_platform_driver(bq27xxx_battery_platform_driver); | |
1320 | static inline int bq27xxx_battery_platform_init(void) | ||
1321 | { | ||
1322 | int ret = platform_driver_register(&bq27xxx_battery_platform_driver); | ||
1323 | |||
1324 | if (ret) | ||
1325 | pr_err("Unable to register BQ27xxx platform driver\n"); | ||
1326 | |||
1327 | return ret; | ||
1328 | } | ||
1329 | |||
1330 | static inline void bq27xxx_battery_platform_exit(void) | ||
1331 | { | ||
1332 | platform_driver_unregister(&bq27xxx_battery_platform_driver); | ||
1333 | } | ||
1334 | |||
1335 | #else | ||
1336 | |||
1337 | static inline int bq27xxx_battery_platform_init(void) { return 0; } | ||
1338 | static inline void bq27xxx_battery_platform_exit(void) {}; | ||
1339 | |||
1340 | #endif | ||
1341 | |||
1342 | /* | ||
1343 | * Module stuff | ||
1344 | */ | ||
1345 | |||
1346 | static int __init bq27xxx_battery_init(void) | ||
1347 | { | ||
1348 | int ret; | ||
1349 | |||
1350 | ret = bq27xxx_battery_i2c_init(); | ||
1351 | if (ret) | ||
1352 | return ret; | ||
1353 | |||
1354 | ret = bq27xxx_battery_platform_init(); | ||
1355 | if (ret) | ||
1356 | bq27xxx_battery_i2c_exit(); | ||
1357 | |||
1358 | return ret; | ||
1359 | } | ||
1360 | module_init(bq27xxx_battery_init); | ||
1361 | |||
1362 | static void __exit bq27xxx_battery_exit(void) | ||
1363 | { | ||
1364 | bq27xxx_battery_platform_exit(); | ||
1365 | bq27xxx_battery_i2c_exit(); | ||
1366 | } | ||
1367 | module_exit(bq27xxx_battery_exit); | ||
1368 | |||
1369 | #ifdef CONFIG_BATTERY_BQ27XXX_PLATFORM | ||
1370 | MODULE_ALIAS("platform:bq27000-battery"); | ||
1371 | #endif | ||
1372 | 1102 | ||
1373 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); | 1103 | MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>"); |
1374 | MODULE_DESCRIPTION("BQ27xxx battery monitor driver"); | 1104 | MODULE_DESCRIPTION("BQ27xxx battery monitor driver"); |
diff --git a/drivers/power/bq27xxx_battery_i2c.c b/drivers/power/bq27xxx_battery_i2c.c new file mode 100644 index 000000000000..9429e66be096 --- /dev/null +++ b/drivers/power/bq27xxx_battery_i2c.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /* | ||
2 | * SCI Reset driver for Keystone based devices | ||
3 | * | ||
4 | * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ | ||
5 | * Andrew F. Davis <afd@ti.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any | ||
12 | * kind, whether express or implied; without even the implied warranty | ||
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/interrupt.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <asm/unaligned.h> | ||
21 | |||
22 | #include <linux/power/bq27xxx_battery.h> | ||
23 | |||
24 | static irqreturn_t bq27xxx_battery_irq_handler_thread(int irq, void *data) | ||
25 | { | ||
26 | struct bq27xxx_device_info *di = data; | ||
27 | |||
28 | bq27xxx_battery_update(di); | ||
29 | |||
30 | return IRQ_HANDLED; | ||
31 | } | ||
32 | |||
33 | static int bq27xxx_battery_i2c_read(struct bq27xxx_device_info *di, u8 reg, | ||
34 | bool single) | ||
35 | { | ||
36 | struct i2c_client *client = to_i2c_client(di->dev); | ||
37 | struct i2c_msg msg[2]; | ||
38 | unsigned char data[2]; | ||
39 | int ret; | ||
40 | |||
41 | if (!client->adapter) | ||
42 | return -ENODEV; | ||
43 | |||
44 | msg[0].addr = client->addr; | ||
45 | msg[0].flags = 0; | ||
46 | msg[0].buf = ® | ||
47 | msg[0].len = sizeof(reg); | ||
48 | msg[1].addr = client->addr; | ||
49 | msg[1].flags = I2C_M_RD; | ||
50 | msg[1].buf = data; | ||
51 | if (single) | ||
52 | msg[1].len = 1; | ||
53 | else | ||
54 | msg[1].len = 2; | ||
55 | |||
56 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); | ||
57 | if (ret < 0) | ||
58 | return ret; | ||
59 | |||
60 | if (!single) | ||
61 | ret = get_unaligned_le16(data); | ||
62 | else | ||
63 | ret = data[0]; | ||
64 | |||
65 | return ret; | ||
66 | } | ||
67 | |||
68 | static int bq27xxx_battery_i2c_probe(struct i2c_client *client, | ||
69 | const struct i2c_device_id *id) | ||
70 | { | ||
71 | struct bq27xxx_device_info *di; | ||
72 | int ret; | ||
73 | |||
74 | di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL); | ||
75 | if (!di) | ||
76 | return -ENOMEM; | ||
77 | |||
78 | di->dev = &client->dev; | ||
79 | di->chip = id->driver_data; | ||
80 | di->name = id->name; | ||
81 | di->bus.read = bq27xxx_battery_i2c_read; | ||
82 | |||
83 | ret = bq27xxx_battery_setup(di); | ||
84 | if (ret) | ||
85 | return ret; | ||
86 | |||
87 | /* Schedule a polling after about 1 min */ | ||
88 | schedule_delayed_work(&di->work, 60 * HZ); | ||
89 | |||
90 | i2c_set_clientdata(client, di); | ||
91 | |||
92 | if (client->irq) { | ||
93 | ret = devm_request_threaded_irq(&client->dev, client->irq, | ||
94 | NULL, bq27xxx_battery_irq_handler_thread, | ||
95 | IRQF_ONESHOT, | ||
96 | di->name, di); | ||
97 | if (ret) { | ||
98 | dev_err(&client->dev, | ||
99 | "Unable to register IRQ %d error %d\n", | ||
100 | client->irq, ret); | ||
101 | return ret; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | static int bq27xxx_battery_i2c_remove(struct i2c_client *client) | ||
109 | { | ||
110 | struct bq27xxx_device_info *di = i2c_get_clientdata(client); | ||
111 | |||
112 | bq27xxx_battery_teardown(di); | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static const struct i2c_device_id bq27xxx_i2c_id_table[] = { | ||
118 | { "bq27200", BQ27000 }, | ||
119 | { "bq27210", BQ27010 }, | ||
120 | { "bq27500", BQ27500 }, | ||
121 | { "bq27510", BQ27500 }, | ||
122 | { "bq27520", BQ27500 }, | ||
123 | { "bq27530", BQ27530 }, | ||
124 | { "bq27531", BQ27530 }, | ||
125 | { "bq27541", BQ27541 }, | ||
126 | { "bq27542", BQ27541 }, | ||
127 | { "bq27546", BQ27541 }, | ||
128 | { "bq27742", BQ27541 }, | ||
129 | { "bq27545", BQ27545 }, | ||
130 | { "bq27421", BQ27421 }, | ||
131 | { "bq27425", BQ27421 }, | ||
132 | { "bq27441", BQ27421 }, | ||
133 | { "bq27621", BQ27421 }, | ||
134 | {}, | ||
135 | }; | ||
136 | MODULE_DEVICE_TABLE(i2c, bq27xxx_i2c_id_table); | ||
137 | |||
138 | static struct i2c_driver bq27xxx_battery_i2c_driver = { | ||
139 | .driver = { | ||
140 | .name = "bq27xxx-battery", | ||
141 | }, | ||
142 | .probe = bq27xxx_battery_i2c_probe, | ||
143 | .remove = bq27xxx_battery_i2c_remove, | ||
144 | .id_table = bq27xxx_i2c_id_table, | ||
145 | }; | ||
146 | module_i2c_driver(bq27xxx_battery_i2c_driver); | ||
147 | |||
148 | MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); | ||
149 | MODULE_DESCRIPTION("BQ27xxx battery monitor i2c driver"); | ||
150 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/power/ds2782_battery.c b/drivers/power/ds2782_battery.c index ed4d756d21e4..a1b7e0592245 100644 --- a/drivers/power/ds2782_battery.c +++ b/drivers/power/ds2782_battery.c | |||
@@ -59,7 +59,7 @@ struct ds278x_info { | |||
59 | struct i2c_client *client; | 59 | struct i2c_client *client; |
60 | struct power_supply *battery; | 60 | struct power_supply *battery; |
61 | struct power_supply_desc battery_desc; | 61 | struct power_supply_desc battery_desc; |
62 | struct ds278x_battery_ops *ops; | 62 | const struct ds278x_battery_ops *ops; |
63 | struct delayed_work bat_work; | 63 | struct delayed_work bat_work; |
64 | int id; | 64 | int id; |
65 | int rsns; | 65 | int rsns; |
@@ -361,7 +361,7 @@ enum ds278x_num_id { | |||
361 | DS2786, | 361 | DS2786, |
362 | }; | 362 | }; |
363 | 363 | ||
364 | static struct ds278x_battery_ops ds278x_ops[] = { | 364 | static const struct ds278x_battery_ops ds278x_ops[] = { |
365 | [DS2782] = { | 365 | [DS2782] = { |
366 | .get_battery_current = ds2782_get_current, | 366 | .get_battery_current = ds2782_get_current, |
367 | .get_battery_voltage = ds2782_get_voltage, | 367 | .get_battery_voltage = ds2782_get_voltage, |
diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c index fedc5818fab7..edb36bf781b0 100644 --- a/drivers/power/generic-adc-battery.c +++ b/drivers/power/generic-adc-battery.c | |||
@@ -206,7 +206,7 @@ static void gab_work(struct work_struct *work) | |||
206 | bool is_plugged; | 206 | bool is_plugged; |
207 | int status; | 207 | int status; |
208 | 208 | ||
209 | delayed_work = container_of(work, struct delayed_work, work); | 209 | delayed_work = to_delayed_work(work); |
210 | adc_bat = container_of(delayed_work, struct gab, bat_work); | 210 | adc_bat = container_of(delayed_work, struct gab, bat_work); |
211 | pdata = adc_bat->pdata; | 211 | pdata = adc_bat->pdata; |
212 | status = adc_bat->status; | 212 | status = adc_bat->status; |
diff --git a/drivers/power/isp1704_charger.c b/drivers/power/isp1704_charger.c index f2a7d970388f..46a292aa182d 100644 --- a/drivers/power/isp1704_charger.c +++ b/drivers/power/isp1704_charger.c | |||
@@ -76,7 +76,7 @@ static inline int isp1704_read(struct isp1704_charger *isp, u32 reg) | |||
76 | return usb_phy_io_read(isp->phy, reg); | 76 | return usb_phy_io_read(isp->phy, reg); |
77 | } | 77 | } |
78 | 78 | ||
79 | static inline int isp1704_write(struct isp1704_charger *isp, u32 val, u32 reg) | 79 | static inline int isp1704_write(struct isp1704_charger *isp, u32 reg, u32 val) |
80 | { | 80 | { |
81 | return usb_phy_io_write(isp->phy, val, reg); | 81 | return usb_phy_io_write(isp->phy, val, reg); |
82 | } | 82 | } |
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c index 6d39d52040d4..17876caf31e5 100644 --- a/drivers/power/max8903_charger.c +++ b/drivers/power/max8903_charger.c | |||
@@ -291,10 +291,10 @@ static int max8903_probe(struct platform_device *pdev) | |||
291 | 291 | ||
292 | if (pdata->dc_valid) { | 292 | if (pdata->dc_valid) { |
293 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->dok), | 293 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->dok), |
294 | NULL, max8903_dcin, | 294 | NULL, max8903_dcin, |
295 | IRQF_TRIGGER_FALLING | | 295 | IRQF_TRIGGER_FALLING | |
296 | IRQF_TRIGGER_RISING, | 296 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
297 | "MAX8903 DC IN", data); | 297 | "MAX8903 DC IN", data); |
298 | if (ret) { | 298 | if (ret) { |
299 | dev_err(dev, "Cannot request irq %d for DC (%d)\n", | 299 | dev_err(dev, "Cannot request irq %d for DC (%d)\n", |
300 | gpio_to_irq(pdata->dok), ret); | 300 | gpio_to_irq(pdata->dok), ret); |
@@ -304,10 +304,10 @@ static int max8903_probe(struct platform_device *pdev) | |||
304 | 304 | ||
305 | if (pdata->usb_valid) { | 305 | if (pdata->usb_valid) { |
306 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->uok), | 306 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->uok), |
307 | NULL, max8903_usbin, | 307 | NULL, max8903_usbin, |
308 | IRQF_TRIGGER_FALLING | | 308 | IRQF_TRIGGER_FALLING | |
309 | IRQF_TRIGGER_RISING, | 309 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
310 | "MAX8903 USB IN", data); | 310 | "MAX8903 USB IN", data); |
311 | if (ret) { | 311 | if (ret) { |
312 | dev_err(dev, "Cannot request irq %d for USB (%d)\n", | 312 | dev_err(dev, "Cannot request irq %d for USB (%d)\n", |
313 | gpio_to_irq(pdata->uok), ret); | 313 | gpio_to_irq(pdata->uok), ret); |
@@ -317,10 +317,10 @@ static int max8903_probe(struct platform_device *pdev) | |||
317 | 317 | ||
318 | if (pdata->flt) { | 318 | if (pdata->flt) { |
319 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->flt), | 319 | ret = devm_request_threaded_irq(dev, gpio_to_irq(pdata->flt), |
320 | NULL, max8903_fault, | 320 | NULL, max8903_fault, |
321 | IRQF_TRIGGER_FALLING | | 321 | IRQF_TRIGGER_FALLING | |
322 | IRQF_TRIGGER_RISING, | 322 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
323 | "MAX8903 Fault", data); | 323 | "MAX8903 Fault", data); |
324 | if (ret) { | 324 | if (ret) { |
325 | dev_err(dev, "Cannot request irq %d for Fault (%d)\n", | 325 | dev_err(dev, "Cannot request irq %d for Fault (%d)\n", |
326 | gpio_to_irq(pdata->flt), ret); | 326 | gpio_to_irq(pdata->flt), ret); |
diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c index 3f6b5dd7c3d4..1b5d450586d1 100644 --- a/drivers/power/reset/at91-reset.c +++ b/drivers/power/reset/at91-reset.c | |||
@@ -198,6 +198,7 @@ static int __init at91_reset_probe(struct platform_device *pdev) | |||
198 | at91_ramc_base[idx] = of_iomap(np, 0); | 198 | at91_ramc_base[idx] = of_iomap(np, 0); |
199 | if (!at91_ramc_base[idx]) { | 199 | if (!at91_ramc_base[idx]) { |
200 | dev_err(&pdev->dev, "Could not map ram controller address\n"); | 200 | dev_err(&pdev->dev, "Could not map ram controller address\n"); |
201 | of_node_put(np); | ||
201 | return -ENODEV; | 202 | return -ENODEV; |
202 | } | 203 | } |
203 | idx++; | 204 | idx++; |
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c index 83c42ea88f2b..57246cdbd042 100644 --- a/drivers/power/test_power.c +++ b/drivers/power/test_power.c | |||
@@ -301,6 +301,8 @@ static int map_get_value(struct battery_property_map *map, const char *key, | |||
301 | buf[MAX_KEYLENGTH-1] = '\0'; | 301 | buf[MAX_KEYLENGTH-1] = '\0'; |
302 | 302 | ||
303 | cr = strnlen(buf, MAX_KEYLENGTH) - 1; | 303 | cr = strnlen(buf, MAX_KEYLENGTH) - 1; |
304 | if (cr < 0) | ||
305 | return def_val; | ||
304 | if (buf[cr] == '\n') | 306 | if (buf[cr] == '\n') |
305 | buf[cr] = '\0'; | 307 | buf[cr] = '\0'; |
306 | 308 | ||
diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h index 45f6a7b5b3cb..998d8f1c3c91 100644 --- a/include/linux/power/bq27xxx_battery.h +++ b/include/linux/power/bq27xxx_battery.h | |||
@@ -1,6 +1,16 @@ | |||
1 | #ifndef __LINUX_BQ27X00_BATTERY_H__ | 1 | #ifndef __LINUX_BQ27X00_BATTERY_H__ |
2 | #define __LINUX_BQ27X00_BATTERY_H__ | 2 | #define __LINUX_BQ27X00_BATTERY_H__ |
3 | 3 | ||
4 | enum bq27xxx_chip { | ||
5 | BQ27000 = 1, /* bq27000, bq27200 */ | ||
6 | BQ27010, /* bq27010, bq27210 */ | ||
7 | BQ27500, /* bq27500, bq27510, bq27520 */ | ||
8 | BQ27530, /* bq27530, bq27531 */ | ||
9 | BQ27541, /* bq27541, bq27542, bq27546, bq27742 */ | ||
10 | BQ27545, /* bq27545 */ | ||
11 | BQ27421, /* bq27421, bq27425, bq27441, bq27621 */ | ||
12 | }; | ||
13 | |||
4 | /** | 14 | /** |
5 | * struct bq27xxx_plaform_data - Platform data for bq27xxx devices | 15 | * struct bq27xxx_plaform_data - Platform data for bq27xxx devices |
6 | * @name: Name of the battery. | 16 | * @name: Name of the battery. |
@@ -12,20 +22,47 @@ | |||
12 | * register to be read. The return value should either be the content of | 22 | * register to be read. The return value should either be the content of |
13 | * the passed register or an error value. | 23 | * the passed register or an error value. |
14 | */ | 24 | */ |
15 | enum bq27xxx_chip { | ||
16 | BQ27000 = 1, /* bq27000, bq27200 */ | ||
17 | BQ27010, /* bq27010, bq27210 */ | ||
18 | BQ27500, /* bq27500, bq27510, bq27520 */ | ||
19 | BQ27530, /* bq27530, bq27531 */ | ||
20 | BQ27541, /* bq27541, bq27542, bq27546, bq27742 */ | ||
21 | BQ27545, /* bq27545 */ | ||
22 | BQ27421, /* bq27421, bq27425, bq27441, bq27621 */ | ||
23 | }; | ||
24 | |||
25 | struct bq27xxx_platform_data { | 25 | struct bq27xxx_platform_data { |
26 | const char *name; | 26 | const char *name; |
27 | enum bq27xxx_chip chip; | 27 | enum bq27xxx_chip chip; |
28 | int (*read)(struct device *dev, unsigned int); | 28 | int (*read)(struct device *dev, unsigned int); |
29 | }; | 29 | }; |
30 | 30 | ||
31 | struct bq27xxx_device_info; | ||
32 | struct bq27xxx_access_methods { | ||
33 | int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single); | ||
34 | }; | ||
35 | |||
36 | struct bq27xxx_reg_cache { | ||
37 | int temperature; | ||
38 | int time_to_empty; | ||
39 | int time_to_empty_avg; | ||
40 | int time_to_full; | ||
41 | int charge_full; | ||
42 | int cycle_count; | ||
43 | int capacity; | ||
44 | int energy; | ||
45 | int flags; | ||
46 | int power_avg; | ||
47 | int health; | ||
48 | }; | ||
49 | |||
50 | struct bq27xxx_device_info { | ||
51 | struct device *dev; | ||
52 | enum bq27xxx_chip chip; | ||
53 | const char *name; | ||
54 | struct bq27xxx_access_methods bus; | ||
55 | struct bq27xxx_reg_cache cache; | ||
56 | int charge_design_full; | ||
57 | unsigned long last_update; | ||
58 | struct delayed_work work; | ||
59 | struct power_supply *bat; | ||
60 | struct mutex lock; | ||
61 | u8 *regs; | ||
62 | }; | ||
63 | |||
64 | void bq27xxx_battery_update(struct bq27xxx_device_info *di); | ||
65 | int bq27xxx_battery_setup(struct bq27xxx_device_info *di); | ||
66 | void bq27xxx_battery_teardown(struct bq27xxx_device_info *di); | ||
67 | |||
31 | #endif | 68 | #endif |