diff options
author | Pali Rohár <pali.rohar@gmail.com> | 2013-02-10 12:32:18 -0500 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-02-16 16:34:10 -0500 |
commit | ac6324e7021dfa917ce4f9a836318c3e46fbb84e (patch) | |
tree | 74dcd582e083fbf8c82e3146e89b84bb6e8d1295 | |
parent | 64d26f225fefe06c870634e7bfe026a063e7f776 (diff) |
bq2415x_charger: Add support for offline and 100mA mode
* Renamed mode BQ2415X_MODE_NONE to BQ2415X_MODE_OFF because this mode
turning chaging completly off
* Added new mode BQ2415X_MODE_NONE which enable charging with maximal
current limit 100mA (this is minimal safe value for bq2415x chips)
Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
-rw-r--r-- | drivers/power/bq2415x_charger.c | 25 | ||||
-rw-r--r-- | include/linux/power/bq2415x_charger.h | 3 |
2 files changed, 20 insertions, 8 deletions
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c index ca70365e9410..ca91396fc48e 100644 --- a/drivers/power/bq2415x_charger.c +++ b/drivers/power/bq2415x_charger.c | |||
@@ -733,12 +733,10 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode) | |||
733 | int charger = 0; | 733 | int charger = 0; |
734 | int boost = 0; | 734 | int boost = 0; |
735 | 735 | ||
736 | if (mode == BQ2415X_MODE_HOST_CHARGER || | ||
737 | mode == BQ2415X_MODE_DEDICATED_CHARGER) | ||
738 | charger = 1; | ||
739 | |||
740 | if (mode == BQ2415X_MODE_BOOST) | 736 | if (mode == BQ2415X_MODE_BOOST) |
741 | boost = 1; | 737 | boost = 1; |
738 | else if (mode != BQ2415X_MODE_OFF) | ||
739 | charger = 1; | ||
742 | 740 | ||
743 | if (!charger) | 741 | if (!charger) |
744 | ret = bq2415x_exec_command(bq, BQ2415X_CHARGER_DISABLE); | 742 | ret = bq2415x_exec_command(bq, BQ2415X_CHARGER_DISABLE); |
@@ -750,6 +748,10 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode) | |||
750 | return ret; | 748 | return ret; |
751 | 749 | ||
752 | switch (mode) { | 750 | switch (mode) { |
751 | case BQ2415X_MODE_OFF: | ||
752 | dev_dbg(bq->dev, "changing mode to: Offline\n"); | ||
753 | ret = bq2415x_set_current_limit(bq, 100); | ||
754 | break; | ||
753 | case BQ2415X_MODE_NONE: | 755 | case BQ2415X_MODE_NONE: |
754 | dev_dbg(bq->dev, "changing mode to: N/A\n"); | 756 | dev_dbg(bq->dev, "changing mode to: N/A\n"); |
755 | ret = bq2415x_set_current_limit(bq, 100); | 757 | ret = bq2415x_set_current_limit(bq, 100); |
@@ -842,7 +844,7 @@ static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg) | |||
842 | dev_err(bq->dev, "%s\n", msg); | 844 | dev_err(bq->dev, "%s\n", msg); |
843 | if (bq->automode > 0) | 845 | if (bq->automode > 0) |
844 | bq->automode = 0; | 846 | bq->automode = 0; |
845 | bq2415x_set_mode(bq, BQ2415X_MODE_NONE); | 847 | bq2415x_set_mode(bq, BQ2415X_MODE_OFF); |
846 | bq2415x_set_autotimer(bq, 0); | 848 | bq2415x_set_autotimer(bq, 0); |
847 | } | 849 | } |
848 | 850 | ||
@@ -1135,6 +1137,10 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev, | |||
1135 | return -ENOSYS; | 1137 | return -ENOSYS; |
1136 | bq->automode = 1; | 1138 | bq->automode = 1; |
1137 | mode = bq->reported_mode; | 1139 | mode = bq->reported_mode; |
1140 | } else if (strncmp(buf, "off", 3) == 0) { | ||
1141 | if (bq->automode > 0) | ||
1142 | bq->automode = 0; | ||
1143 | mode = BQ2415X_MODE_OFF; | ||
1138 | } else if (strncmp(buf, "none", 4) == 0) { | 1144 | } else if (strncmp(buf, "none", 4) == 0) { |
1139 | if (bq->automode > 0) | 1145 | if (bq->automode > 0) |
1140 | bq->automode = 0; | 1146 | bq->automode = 0; |
@@ -1182,6 +1188,9 @@ static ssize_t bq2415x_sysfs_show_mode(struct device *dev, | |||
1182 | ret += sprintf(buf+ret, "auto ("); | 1188 | ret += sprintf(buf+ret, "auto ("); |
1183 | 1189 | ||
1184 | switch (bq->mode) { | 1190 | switch (bq->mode) { |
1191 | case BQ2415X_MODE_OFF: | ||
1192 | ret += sprintf(buf+ret, "off"); | ||
1193 | break; | ||
1185 | case BQ2415X_MODE_NONE: | 1194 | case BQ2415X_MODE_NONE: |
1186 | ret += sprintf(buf+ret, "none"); | 1195 | ret += sprintf(buf+ret, "none"); |
1187 | break; | 1196 | break; |
@@ -1216,6 +1225,8 @@ static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev, | |||
1216 | return -EINVAL; | 1225 | return -EINVAL; |
1217 | 1226 | ||
1218 | switch (bq->reported_mode) { | 1227 | switch (bq->reported_mode) { |
1228 | case BQ2415X_MODE_OFF: | ||
1229 | return sprintf(buf, "off\n"); | ||
1219 | case BQ2415X_MODE_NONE: | 1230 | case BQ2415X_MODE_NONE: |
1220 | return sprintf(buf, "none\n"); | 1231 | return sprintf(buf, "none\n"); |
1221 | case BQ2415X_MODE_HOST_CHARGER: | 1232 | case BQ2415X_MODE_HOST_CHARGER: |
@@ -1535,8 +1546,8 @@ static int bq2415x_probe(struct i2c_client *client, | |||
1535 | bq->dev = &client->dev; | 1546 | bq->dev = &client->dev; |
1536 | bq->chip = id->driver_data; | 1547 | bq->chip = id->driver_data; |
1537 | bq->name = name; | 1548 | bq->name = name; |
1538 | bq->mode = BQ2415X_MODE_NONE; | 1549 | bq->mode = BQ2415X_MODE_OFF; |
1539 | bq->reported_mode = BQ2415X_MODE_NONE; | 1550 | bq->reported_mode = BQ2415X_MODE_OFF; |
1540 | bq->autotimer = 0; | 1551 | bq->autotimer = 0; |
1541 | bq->automode = 0; | 1552 | bq->automode = 0; |
1542 | 1553 | ||
diff --git a/include/linux/power/bq2415x_charger.h b/include/linux/power/bq2415x_charger.h index 97a1665eaeaf..8dcc0f46fc0a 100644 --- a/include/linux/power/bq2415x_charger.h +++ b/include/linux/power/bq2415x_charger.h | |||
@@ -75,7 +75,8 @@ | |||
75 | 75 | ||
76 | /* Supported modes with maximal current limit */ | 76 | /* Supported modes with maximal current limit */ |
77 | enum bq2415x_mode { | 77 | enum bq2415x_mode { |
78 | BQ2415X_MODE_NONE, /* unknown or no charger (100mA) */ | 78 | BQ2415X_MODE_OFF, /* offline mode (charger disabled) */ |
79 | BQ2415X_MODE_NONE, /* unknown charger (100mA) */ | ||
79 | BQ2415X_MODE_HOST_CHARGER, /* usb host/hub charger (500mA) */ | 80 | BQ2415X_MODE_HOST_CHARGER, /* usb host/hub charger (500mA) */ |
80 | BQ2415X_MODE_DEDICATED_CHARGER, /* dedicated charger (unlimited) */ | 81 | BQ2415X_MODE_DEDICATED_CHARGER, /* dedicated charger (unlimited) */ |
81 | BQ2415X_MODE_BOOST, /* boost mode (charging disabled) */ | 82 | BQ2415X_MODE_BOOST, /* boost mode (charging disabled) */ |