aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/bq2415x_charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/bq2415x_charger.c')
-rw-r--r--drivers/power/bq2415x_charger.c147
1 files changed, 69 insertions, 78 deletions
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 1f49986fc605..6c534dcbc19c 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -13,12 +13,6 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/*
22 * Datasheets: 16 * Datasheets:
23 * http://www.ti.com/product/bq24150 17 * http://www.ti.com/product/bq24150
24 * http://www.ti.com/product/bq24150a 18 * http://www.ti.com/product/bq24150a
@@ -26,6 +20,8 @@
26 * http://www.ti.com/product/bq24153 20 * http://www.ti.com/product/bq24153
27 * http://www.ti.com/product/bq24153a 21 * http://www.ti.com/product/bq24153a
28 * http://www.ti.com/product/bq24155 22 * http://www.ti.com/product/bq24155
23 * http://www.ti.com/product/bq24157s
24 * http://www.ti.com/product/bq24158
29 */ 25 */
30 26
31#include <linux/kernel.h> 27#include <linux/kernel.h>
@@ -147,6 +143,7 @@ enum bq2415x_chip {
147 BQ24155, 143 BQ24155,
148 BQ24156, 144 BQ24156,
149 BQ24156A, 145 BQ24156A,
146 BQ24157S,
150 BQ24158, 147 BQ24158,
151}; 148};
152 149
@@ -162,18 +159,20 @@ static char *bq2415x_chip_name[] = {
162 "bq24155", 159 "bq24155",
163 "bq24156", 160 "bq24156",
164 "bq24156a", 161 "bq24156a",
162 "bq24157s",
165 "bq24158", 163 "bq24158",
166}; 164};
167 165
168struct bq2415x_device { 166struct bq2415x_device {
169 struct device *dev; 167 struct device *dev;
170 struct bq2415x_platform_data init_data; 168 struct bq2415x_platform_data init_data;
171 struct power_supply charger; 169 struct power_supply *charger;
170 struct power_supply_desc charger_desc;
172 struct delayed_work work; 171 struct delayed_work work;
173 struct power_supply *notify_psy; 172 struct power_supply *notify_psy;
174 struct notifier_block nb; 173 struct notifier_block nb;
175 enum bq2415x_mode reported_mode;/* mode reported by hook function */ 174 enum bq2415x_mode reported_mode;/* mode reported by hook function */
176 enum bq2415x_mode mode; /* current configured mode */ 175 enum bq2415x_mode mode; /* currently configured mode */
177 enum bq2415x_chip chip; 176 enum bq2415x_chip chip;
178 const char *timer_error; 177 const char *timer_error;
179 char *model; 178 char *model;
@@ -352,8 +351,7 @@ static int bq2415x_exec_command(struct bq2415x_device *bq,
352 BQ2415X_BIT_CE); 351 BQ2415X_BIT_CE);
353 if (ret < 0) 352 if (ret < 0)
354 return ret; 353 return ret;
355 else 354 return ret > 0 ? 0 : 1;
356 return ret > 0 ? 0 : 1;
357 case BQ2415X_CHARGER_ENABLE: 355 case BQ2415X_CHARGER_ENABLE:
358 return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, 356 return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL,
359 0, BQ2415X_BIT_CE); 357 0, BQ2415X_BIT_CE);
@@ -426,20 +424,17 @@ static enum bq2415x_chip bq2415x_detect_chip(struct bq2415x_device *bq)
426 case 0: 424 case 0:
427 if (bq->chip == BQ24151A) 425 if (bq->chip == BQ24151A)
428 return bq->chip; 426 return bq->chip;
429 else 427 return BQ24151;
430 return BQ24151;
431 case 1: 428 case 1:
432 if (bq->chip == BQ24150A || 429 if (bq->chip == BQ24150A ||
433 bq->chip == BQ24152 || 430 bq->chip == BQ24152 ||
434 bq->chip == BQ24155) 431 bq->chip == BQ24155)
435 return bq->chip; 432 return bq->chip;
436 else 433 return BQ24150;
437 return BQ24150;
438 case 2: 434 case 2:
439 if (bq->chip == BQ24153A) 435 if (bq->chip == BQ24153A)
440 return bq->chip; 436 return bq->chip;
441 else 437 return BQ24153;
442 return BQ24153;
443 default: 438 default:
444 return BQUNKNOWN; 439 return BQUNKNOWN;
445 } 440 }
@@ -450,9 +445,10 @@ static enum bq2415x_chip bq2415x_detect_chip(struct bq2415x_device *bq)
450 case 0: 445 case 0:
451 if (bq->chip == BQ24156A) 446 if (bq->chip == BQ24156A)
452 return bq->chip; 447 return bq->chip;
453 else 448 return BQ24156;
454 return BQ24156;
455 case 2: 449 case 2:
450 if (bq->chip == BQ24157S)
451 return bq->chip;
456 return BQ24158; 452 return BQ24158;
457 default: 453 default:
458 return BQUNKNOWN; 454 return BQUNKNOWN;
@@ -480,24 +476,22 @@ static int bq2415x_detect_revision(struct bq2415x_device *bq)
480 case BQ24152: 476 case BQ24152:
481 if (ret >= 0 && ret <= 3) 477 if (ret >= 0 && ret <= 3)
482 return ret; 478 return ret;
483 else 479 return -1;
484 return -1;
485 case BQ24153: 480 case BQ24153:
486 case BQ24153A: 481 case BQ24153A:
487 case BQ24156: 482 case BQ24156:
488 case BQ24156A: 483 case BQ24156A:
484 case BQ24157S:
489 case BQ24158: 485 case BQ24158:
490 if (ret == 3) 486 if (ret == 3)
491 return 0; 487 return 0;
492 else if (ret == 1) 488 else if (ret == 1)
493 return 1; 489 return 1;
494 else 490 return -1;
495 return -1;
496 case BQ24155: 491 case BQ24155:
497 if (ret == 3) 492 if (ret == 3)
498 return 3; 493 return 3;
499 else 494 return -1;
500 return -1;
501 case BQUNKNOWN: 495 case BQUNKNOWN:
502 return -1; 496 return -1;
503 } 497 }
@@ -791,7 +785,7 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode)
791 bq2415x_set_default_value(bq, battery_regulation_voltage); 785 bq2415x_set_default_value(bq, battery_regulation_voltage);
792 786
793 bq->mode = mode; 787 bq->mode = mode;
794 sysfs_notify(&bq->charger.dev->kobj, NULL, "mode"); 788 sysfs_notify(&bq->charger->dev.kobj, NULL, "mode");
795 789
796 return 0; 790 return 0;
797 791
@@ -816,7 +810,8 @@ static int bq2415x_notifier_call(struct notifier_block *nb,
816 810
817 dev_dbg(bq->dev, "notifier call was called\n"); 811 dev_dbg(bq->dev, "notifier call was called\n");
818 812
819 ret = psy->get_property(psy, POWER_SUPPLY_PROP_CURRENT_MAX, &prop); 813 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_CURRENT_MAX,
814 &prop);
820 if (ret != 0) 815 if (ret != 0)
821 return NOTIFY_OK; 816 return NOTIFY_OK;
822 817
@@ -874,7 +869,7 @@ static void bq2415x_set_autotimer(struct bq2415x_device *bq, int state)
874static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg) 869static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg)
875{ 870{
876 bq->timer_error = msg; 871 bq->timer_error = msg;
877 sysfs_notify(&bq->charger.dev->kobj, NULL, "timer"); 872 sysfs_notify(&bq->charger->dev.kobj, NULL, "timer");
878 dev_err(bq->dev, "%s\n", msg); 873 dev_err(bq->dev, "%s\n", msg);
879 if (bq->automode > 0) 874 if (bq->automode > 0)
880 bq->automode = 0; 875 bq->automode = 0;
@@ -892,7 +887,7 @@ static void bq2415x_timer_work(struct work_struct *work)
892 int boost; 887 int boost;
893 888
894 if (bq->automode > 0 && (bq->reported_mode != bq->mode)) { 889 if (bq->automode > 0 && (bq->reported_mode != bq->mode)) {
895 sysfs_notify(&bq->charger.dev->kobj, NULL, "reported_mode"); 890 sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode");
896 bq2415x_set_mode(bq, bq->reported_mode); 891 bq2415x_set_mode(bq, bq->reported_mode);
897 } 892 }
898 893
@@ -998,8 +993,7 @@ static int bq2415x_power_supply_get_property(struct power_supply *psy,
998 enum power_supply_property psp, 993 enum power_supply_property psp,
999 union power_supply_propval *val) 994 union power_supply_propval *val)
1000{ 995{
1001 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 996 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1002 charger);
1003 int ret; 997 int ret;
1004 998
1005 switch (psp) { 999 switch (psp) {
@@ -1030,12 +1024,14 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
1030 int ret; 1024 int ret;
1031 int chip; 1025 int chip;
1032 char revstr[8]; 1026 char revstr[8];
1027 struct power_supply_config psy_cfg = { .drv_data = bq, };
1033 1028
1034 bq->charger.name = bq->name; 1029 bq->charger_desc.name = bq->name;
1035 bq->charger.type = POWER_SUPPLY_TYPE_USB; 1030 bq->charger_desc.type = POWER_SUPPLY_TYPE_USB;
1036 bq->charger.properties = bq2415x_power_supply_props; 1031 bq->charger_desc.properties = bq2415x_power_supply_props;
1037 bq->charger.num_properties = ARRAY_SIZE(bq2415x_power_supply_props); 1032 bq->charger_desc.num_properties =
1038 bq->charger.get_property = bq2415x_power_supply_get_property; 1033 ARRAY_SIZE(bq2415x_power_supply_props);
1034 bq->charger_desc.get_property = bq2415x_power_supply_get_property;
1039 1035
1040 ret = bq2415x_detect_chip(bq); 1036 ret = bq2415x_detect_chip(bq);
1041 if (ret < 0) 1037 if (ret < 0)
@@ -1058,10 +1054,11 @@ static int bq2415x_power_supply_init(struct bq2415x_device *bq)
1058 return -ENOMEM; 1054 return -ENOMEM;
1059 } 1055 }
1060 1056
1061 ret = power_supply_register(bq->dev, &bq->charger); 1057 bq->charger = power_supply_register(bq->dev, &bq->charger_desc,
1062 if (ret) { 1058 &psy_cfg);
1059 if (IS_ERR(bq->charger)) {
1063 kfree(bq->model); 1060 kfree(bq->model);
1064 return ret; 1061 return PTR_ERR(bq->charger);
1065 } 1062 }
1066 1063
1067 return 0; 1064 return 0;
@@ -1073,7 +1070,7 @@ static void bq2415x_power_supply_exit(struct bq2415x_device *bq)
1073 if (bq->automode > 0) 1070 if (bq->automode > 0)
1074 bq->automode = 0; 1071 bq->automode = 0;
1075 cancel_delayed_work_sync(&bq->work); 1072 cancel_delayed_work_sync(&bq->work);
1076 power_supply_unregister(&bq->charger); 1073 power_supply_unregister(bq->charger);
1077 kfree(bq->model); 1074 kfree(bq->model);
1078} 1075}
1079 1076
@@ -1085,8 +1082,7 @@ static ssize_t bq2415x_sysfs_show_status(struct device *dev,
1085 char *buf) 1082 char *buf)
1086{ 1083{
1087 struct power_supply *psy = dev_get_drvdata(dev); 1084 struct power_supply *psy = dev_get_drvdata(dev);
1088 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1085 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1089 charger);
1090 enum bq2415x_command command; 1086 enum bq2415x_command command;
1091 int ret; 1087 int ret;
1092 1088
@@ -1119,8 +1115,7 @@ static ssize_t bq2415x_sysfs_set_timer(struct device *dev,
1119 size_t count) 1115 size_t count)
1120{ 1116{
1121 struct power_supply *psy = dev_get_drvdata(dev); 1117 struct power_supply *psy = dev_get_drvdata(dev);
1122 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1118 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1123 charger);
1124 int ret = 0; 1119 int ret = 0;
1125 1120
1126 if (strncmp(buf, "auto", 4) == 0) 1121 if (strncmp(buf, "auto", 4) == 0)
@@ -1141,8 +1136,7 @@ static ssize_t bq2415x_sysfs_show_timer(struct device *dev,
1141 char *buf) 1136 char *buf)
1142{ 1137{
1143 struct power_supply *psy = dev_get_drvdata(dev); 1138 struct power_supply *psy = dev_get_drvdata(dev);
1144 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1139 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1145 charger);
1146 1140
1147 if (bq->timer_error) 1141 if (bq->timer_error)
1148 return sprintf(buf, "%s\n", bq->timer_error); 1142 return sprintf(buf, "%s\n", bq->timer_error);
@@ -1166,8 +1160,7 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
1166 size_t count) 1160 size_t count)
1167{ 1161{
1168 struct power_supply *psy = dev_get_drvdata(dev); 1162 struct power_supply *psy = dev_get_drvdata(dev);
1169 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1163 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1170 charger);
1171 enum bq2415x_mode mode; 1164 enum bq2415x_mode mode;
1172 int ret = 0; 1165 int ret = 0;
1173 1166
@@ -1219,8 +1212,7 @@ static ssize_t bq2415x_sysfs_show_mode(struct device *dev,
1219 char *buf) 1212 char *buf)
1220{ 1213{
1221 struct power_supply *psy = dev_get_drvdata(dev); 1214 struct power_supply *psy = dev_get_drvdata(dev);
1222 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1215 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1223 charger);
1224 ssize_t ret = 0; 1216 ssize_t ret = 0;
1225 1217
1226 if (bq->automode > 0) 1218 if (bq->automode > 0)
@@ -1257,8 +1249,7 @@ static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev,
1257 char *buf) 1249 char *buf)
1258{ 1250{
1259 struct power_supply *psy = dev_get_drvdata(dev); 1251 struct power_supply *psy = dev_get_drvdata(dev);
1260 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1252 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1261 charger);
1262 1253
1263 if (bq->automode < 0) 1254 if (bq->automode < 0)
1264 return -EINVAL; 1255 return -EINVAL;
@@ -1286,8 +1277,7 @@ static ssize_t bq2415x_sysfs_set_registers(struct device *dev,
1286 size_t count) 1277 size_t count)
1287{ 1278{
1288 struct power_supply *psy = dev_get_drvdata(dev); 1279 struct power_supply *psy = dev_get_drvdata(dev);
1289 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1280 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1290 charger);
1291 ssize_t ret = 0; 1281 ssize_t ret = 0;
1292 unsigned int reg; 1282 unsigned int reg;
1293 unsigned int val; 1283 unsigned int val;
@@ -1322,8 +1312,7 @@ static ssize_t bq2415x_sysfs_show_registers(struct device *dev,
1322 char *buf) 1312 char *buf)
1323{ 1313{
1324 struct power_supply *psy = dev_get_drvdata(dev); 1314 struct power_supply *psy = dev_get_drvdata(dev);
1325 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1315 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1326 charger);
1327 ssize_t ret = 0; 1316 ssize_t ret = 0;
1328 1317
1329 ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_STATUS, buf+ret); 1318 ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_STATUS, buf+ret);
@@ -1341,8 +1330,7 @@ static ssize_t bq2415x_sysfs_set_limit(struct device *dev,
1341 size_t count) 1330 size_t count)
1342{ 1331{
1343 struct power_supply *psy = dev_get_drvdata(dev); 1332 struct power_supply *psy = dev_get_drvdata(dev);
1344 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1333 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1345 charger);
1346 long val; 1334 long val;
1347 int ret; 1335 int ret;
1348 1336
@@ -1373,8 +1361,7 @@ static ssize_t bq2415x_sysfs_show_limit(struct device *dev,
1373 char *buf) 1361 char *buf)
1374{ 1362{
1375 struct power_supply *psy = dev_get_drvdata(dev); 1363 struct power_supply *psy = dev_get_drvdata(dev);
1376 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1364 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1377 charger);
1378 int ret; 1365 int ret;
1379 1366
1380 if (strcmp(attr->attr.name, "current_limit") == 0) 1367 if (strcmp(attr->attr.name, "current_limit") == 0)
@@ -1402,8 +1389,7 @@ static ssize_t bq2415x_sysfs_set_enable(struct device *dev,
1402 size_t count) 1389 size_t count)
1403{ 1390{
1404 struct power_supply *psy = dev_get_drvdata(dev); 1391 struct power_supply *psy = dev_get_drvdata(dev);
1405 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1392 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1406 charger);
1407 enum bq2415x_command command; 1393 enum bq2415x_command command;
1408 long val; 1394 long val;
1409 int ret; 1395 int ret;
@@ -1438,8 +1424,7 @@ static ssize_t bq2415x_sysfs_show_enable(struct device *dev,
1438 char *buf) 1424 char *buf)
1439{ 1425{
1440 struct power_supply *psy = dev_get_drvdata(dev); 1426 struct power_supply *psy = dev_get_drvdata(dev);
1441 struct bq2415x_device *bq = container_of(psy, struct bq2415x_device, 1427 struct bq2415x_device *bq = power_supply_get_drvdata(psy);
1442 charger);
1443 enum bq2415x_command command; 1428 enum bq2415x_command command;
1444 int ret; 1429 int ret;
1445 1430
@@ -1530,13 +1515,13 @@ static const struct attribute_group bq2415x_sysfs_attr_group = {
1530 1515
1531static int bq2415x_sysfs_init(struct bq2415x_device *bq) 1516static int bq2415x_sysfs_init(struct bq2415x_device *bq)
1532{ 1517{
1533 return sysfs_create_group(&bq->charger.dev->kobj, 1518 return sysfs_create_group(&bq->charger->dev.kobj,
1534 &bq2415x_sysfs_attr_group); 1519 &bq2415x_sysfs_attr_group);
1535} 1520}
1536 1521
1537static void bq2415x_sysfs_exit(struct bq2415x_device *bq) 1522static void bq2415x_sysfs_exit(struct bq2415x_device *bq)
1538{ 1523{
1539 sysfs_remove_group(&bq->charger.dev->kobj, &bq2415x_sysfs_attr_group); 1524 sysfs_remove_group(&bq->charger->dev.kobj, &bq2415x_sysfs_attr_group);
1540} 1525}
1541 1526
1542/* main bq2415x probe function */ 1527/* main bq2415x probe function */
@@ -1609,27 +1594,27 @@ static int bq2415x_probe(struct i2c_client *client,
1609 ret = of_property_read_u32(np, "ti,current-limit", 1594 ret = of_property_read_u32(np, "ti,current-limit",
1610 &bq->init_data.current_limit); 1595 &bq->init_data.current_limit);
1611 if (ret) 1596 if (ret)
1612 goto error_2; 1597 goto error_3;
1613 ret = of_property_read_u32(np, "ti,weak-battery-voltage", 1598 ret = of_property_read_u32(np, "ti,weak-battery-voltage",
1614 &bq->init_data.weak_battery_voltage); 1599 &bq->init_data.weak_battery_voltage);
1615 if (ret) 1600 if (ret)
1616 goto error_2; 1601 goto error_3;
1617 ret = of_property_read_u32(np, "ti,battery-regulation-voltage", 1602 ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
1618 &bq->init_data.battery_regulation_voltage); 1603 &bq->init_data.battery_regulation_voltage);
1619 if (ret) 1604 if (ret)
1620 goto error_2; 1605 goto error_3;
1621 ret = of_property_read_u32(np, "ti,charge-current", 1606 ret = of_property_read_u32(np, "ti,charge-current",
1622 &bq->init_data.charge_current); 1607 &bq->init_data.charge_current);
1623 if (ret) 1608 if (ret)
1624 goto error_2; 1609 goto error_3;
1625 ret = of_property_read_u32(np, "ti,termination-current", 1610 ret = of_property_read_u32(np, "ti,termination-current",
1626 &bq->init_data.termination_current); 1611 &bq->init_data.termination_current);
1627 if (ret) 1612 if (ret)
1628 goto error_2; 1613 goto error_3;
1629 ret = of_property_read_u32(np, "ti,resistor-sense", 1614 ret = of_property_read_u32(np, "ti,resistor-sense",
1630 &bq->init_data.resistor_sense); 1615 &bq->init_data.resistor_sense);
1631 if (ret) 1616 if (ret)
1632 goto error_2; 1617 goto error_3;
1633 } else { 1618 } else {
1634 memcpy(&bq->init_data, pdata, sizeof(bq->init_data)); 1619 memcpy(&bq->init_data, pdata, sizeof(bq->init_data));
1635 } 1620 }
@@ -1639,19 +1624,19 @@ static int bq2415x_probe(struct i2c_client *client,
1639 ret = bq2415x_power_supply_init(bq); 1624 ret = bq2415x_power_supply_init(bq);
1640 if (ret) { 1625 if (ret) {
1641 dev_err(bq->dev, "failed to register power supply: %d\n", ret); 1626 dev_err(bq->dev, "failed to register power supply: %d\n", ret);
1642 goto error_2; 1627 goto error_3;
1643 } 1628 }
1644 1629
1645 ret = bq2415x_sysfs_init(bq); 1630 ret = bq2415x_sysfs_init(bq);
1646 if (ret) { 1631 if (ret) {
1647 dev_err(bq->dev, "failed to create sysfs entries: %d\n", ret); 1632 dev_err(bq->dev, "failed to create sysfs entries: %d\n", ret);
1648 goto error_3; 1633 goto error_4;
1649 } 1634 }
1650 1635
1651 ret = bq2415x_set_defaults(bq); 1636 ret = bq2415x_set_defaults(bq);
1652 if (ret) { 1637 if (ret) {
1653 dev_err(bq->dev, "failed to set default values: %d\n", ret); 1638 dev_err(bq->dev, "failed to set default values: %d\n", ret);
1654 goto error_4; 1639 goto error_5;
1655 } 1640 }
1656 1641
1657 if (bq->notify_psy) { 1642 if (bq->notify_psy) {
@@ -1659,7 +1644,7 @@ static int bq2415x_probe(struct i2c_client *client,
1659 ret = power_supply_reg_notifier(&bq->nb); 1644 ret = power_supply_reg_notifier(&bq->nb);
1660 if (ret) { 1645 if (ret) {
1661 dev_err(bq->dev, "failed to reg notifier: %d\n", ret); 1646 dev_err(bq->dev, "failed to reg notifier: %d\n", ret);
1662 goto error_5; 1647 goto error_6;
1663 } 1648 }
1664 1649
1665 /* Query for initial reported_mode and set it */ 1650 /* Query for initial reported_mode and set it */
@@ -1679,11 +1664,14 @@ static int bq2415x_probe(struct i2c_client *client,
1679 dev_info(bq->dev, "driver registered\n"); 1664 dev_info(bq->dev, "driver registered\n");
1680 return 0; 1665 return 0;
1681 1666
1667error_6:
1682error_5: 1668error_5:
1683error_4:
1684 bq2415x_sysfs_exit(bq); 1669 bq2415x_sysfs_exit(bq);
1685error_3: 1670error_4:
1686 bq2415x_power_supply_exit(bq); 1671 bq2415x_power_supply_exit(bq);
1672error_3:
1673 if (bq->notify_psy)
1674 power_supply_put(bq->notify_psy);
1687error_2: 1675error_2:
1688 kfree(name); 1676 kfree(name);
1689error_1: 1677error_1:
@@ -1700,8 +1688,10 @@ static int bq2415x_remove(struct i2c_client *client)
1700{ 1688{
1701 struct bq2415x_device *bq = i2c_get_clientdata(client); 1689 struct bq2415x_device *bq = i2c_get_clientdata(client);
1702 1690
1703 if (bq->notify_psy) 1691 if (bq->notify_psy) {
1704 power_supply_unreg_notifier(&bq->nb); 1692 power_supply_unreg_notifier(&bq->nb);
1693 power_supply_put(bq->notify_psy);
1694 }
1705 1695
1706 bq2415x_sysfs_exit(bq); 1696 bq2415x_sysfs_exit(bq);
1707 bq2415x_power_supply_exit(bq); 1697 bq2415x_power_supply_exit(bq);
@@ -1731,6 +1721,7 @@ static const struct i2c_device_id bq2415x_i2c_id_table[] = {
1731 { "bq24155", BQ24155 }, 1721 { "bq24155", BQ24155 },
1732 { "bq24156", BQ24156 }, 1722 { "bq24156", BQ24156 },
1733 { "bq24156a", BQ24156A }, 1723 { "bq24156a", BQ24156A },
1724 { "bq24157s", BQ24157S },
1734 { "bq24158", BQ24158 }, 1725 { "bq24158", BQ24158 },
1735 {}, 1726 {},
1736}; 1727};