* 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.ro...@gmail.com>
---
 drivers/power/bq2415x_charger.c       |   25 ++++++++++++++++++-------
 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 ee842b3..293b70d 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -734,12 +734,10 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, 
enum bq2415x_mode mode)
        int charger = 0;
        int boost = 0;
 
-       if (mode == BQ2415X_MODE_HOST_CHARGER ||
-               mode == BQ2415X_MODE_DEDICATED_CHARGER)
-                       charger = 1;
-
        if (mode == BQ2415X_MODE_BOOST)
                boost = 1;
+       else if (mode != BQ2415X_MODE_OFF)
+               charger = 1;
 
        if (!charger)
                ret = bq2415x_exec_command(bq, BQ2415X_CHARGER_DISABLE);
@@ -751,6 +749,10 @@ static int bq2415x_set_mode(struct bq2415x_device *bq, 
enum bq2415x_mode mode)
                return ret;
 
        switch (mode) {
+       case BQ2415X_MODE_OFF:
+               dev_dbg(bq->dev, "changing mode to: Offline\n");
+               ret = bq2415x_set_current_limit(bq, 100);
+               break;
        case BQ2415X_MODE_NONE:
                dev_dbg(bq->dev, "changing mode to: N/A\n");
                ret = bq2415x_set_current_limit(bq, 100);
@@ -843,7 +845,7 @@ static void bq2415x_timer_error(struct bq2415x_device *bq, 
const char *msg)
        dev_err(bq->dev, "%s\n", msg);
        if (bq->automode > 0)
                bq->automode = 0;
-       bq2415x_set_mode(bq, BQ2415X_MODE_NONE);
+       bq2415x_set_mode(bq, BQ2415X_MODE_OFF);
        bq2415x_set_autotimer(bq, 0);
 }
 
@@ -1136,6 +1138,10 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
                        return -ENOSYS;
                bq->automode = 1;
                mode = bq->reported_mode;
+       } else if (strncmp(buf, "off", 3) == 0) {
+               if (bq->automode > 0)
+                       bq->automode = 0;
+               mode = BQ2415X_MODE_OFF;
        } else if (strncmp(buf, "none", 4) == 0) {
                if (bq->automode > 0)
                        bq->automode = 0;
@@ -1183,6 +1189,9 @@ static ssize_t bq2415x_sysfs_show_mode(struct device *dev,
                ret += sprintf(buf+ret, "auto (");
 
        switch (bq->mode) {
+       case BQ2415X_MODE_OFF:
+               ret += sprintf(buf+ret, "off");
+               break;
        case BQ2415X_MODE_NONE:
                ret += sprintf(buf+ret, "none");
                break;
@@ -1217,6 +1226,8 @@ static ssize_t bq2415x_sysfs_show_reported_mode(struct 
device *dev,
                return -EINVAL;
 
        switch (bq->reported_mode) {
+       case BQ2415X_MODE_OFF:
+               return sprintf(buf, "off\n");
        case BQ2415X_MODE_NONE:
                return sprintf(buf, "none\n");
        case BQ2415X_MODE_HOST_CHARGER:
@@ -1536,8 +1547,8 @@ static int bq2415x_probe(struct i2c_client *client,
        bq->dev = &client->dev;
        bq->chip = id->driver_data;
        bq->name = name;
-       bq->mode = BQ2415X_MODE_NONE;
-       bq->reported_mode = BQ2415X_MODE_NONE;
+       bq->mode = BQ2415X_MODE_OFF;
+       bq->reported_mode = BQ2415X_MODE_OFF;
        bq->autotimer = 0;
        bq->automode = 0;
 
diff --git a/include/linux/power/bq2415x_charger.h 
b/include/linux/power/bq2415x_charger.h
index 97a1665..8dcc0f4 100644
--- a/include/linux/power/bq2415x_charger.h
+++ b/include/linux/power/bq2415x_charger.h
@@ -75,7 +75,8 @@
 
 /* Supported modes with maximal current limit */
 enum bq2415x_mode {
-       BQ2415X_MODE_NONE,              /* unknown or no charger (100mA) */
+       BQ2415X_MODE_OFF,               /* offline mode (charger disabled) */
+       BQ2415X_MODE_NONE,              /* unknown charger (100mA) */
        BQ2415X_MODE_HOST_CHARGER,      /* usb host/hub charger (500mA) */
        BQ2415X_MODE_DEDICATED_CHARGER, /* dedicated charger (unlimited) */
        BQ2415X_MODE_BOOST,             /* boost mode (charging disabled) */
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to