power: bq2419X: Support BQ24193 version
Hyongbin Kim [Thu, 10 Oct 2013 04:03:37 +0000 (13:03 +0900)]
BQ24193 support JEITA spec.
Set ISET=1 for charging 0.2C at T1~T2.
Set VSET=4.2V for 4.2V charging at T3~T5.

Bug 1324720

Change-Id: I17d144658706140bee1298edfa9792b2eb0f5605
Signed-off-by: Hyongbin Kim <hyongbink@nvidia.com>
Reviewed-on: http://git-master/r/289135
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Gabby Lee <galee@nvidia.com>

drivers/power/bq2419x-charger.c
include/linux/power/bq2419x-charger.h

index 46edd3d..831be32 100644 (file)
 #include <linux/alarmtimer.h>
 #include <generated/mach-types.h>
 
+enum bq2419x_version {
+       BQ24190_IC = 0,
+       BQ24192_IC,
+       BQ24193_IC,
+       BQ24192i_IC,
+};
+
 /* input current limit */
 static const unsigned int iinlim[] = {
        100, 150, 500, 900, 1200, 1500, 2000, 3000,
@@ -89,6 +96,7 @@ struct bq2419x_chip {
        int                             chg_restart_timeout;
        int                             chg_restart_time;
        int                             chg_enable;
+       int                             chip_version;
 };
 
 static int current_to_reg(const unsigned int *tbl,
@@ -257,6 +265,27 @@ static int bq2419x_charger_init(struct bq2419x_chip *bq2419x)
                }
        }
 
+       if (bq2419x->chip_version == BQ24193_IC) {
+               /* JEITA_ISET=20%*/
+               ret = regmap_update_bits(bq2419x->regmap,
+                       BQ2419X_TIME_CTRL_REG, BQ2419X_JEITA_ISET_MASK,
+                       BQ2419X_JEITA_ISET_20);
+               if (ret < 0) {
+                       dev_err(bq2419x->dev,
+                       "TIME_CTRL_REG update failed %d\n", ret);
+                       return ret;
+               }
+               /* JEITA_VSET=4.2V*/
+               ret = regmap_update_bits(bq2419x->regmap,
+                       BQ2419X_MISC_OPER_REG, BQ2419X_JEITA_VSET_MASK,
+                       BQ2419X_JEITA_VSET_4_20V);
+               if (ret < 0) {
+                       dev_err(bq2419x->dev,
+                       "MISC_OPER_REG update failed %d\n", ret);
+                       return ret;
+               }
+       }
+
        /*
         * Configure Input voltage limit reset to OTP value,
         * and charging current to 500mA.
@@ -749,12 +778,21 @@ static int bq2419x_show_chip_version(struct bq2419x_chip *bq2419x)
                return ret;
        }
 
-       if ((val & BQ24190_IC_VER) == BQ24190_IC_VER)
+       val &= BQ2419X_IC_VER_MASK;
+
+       if (val == BQ24190_IC_VER) {
+               bq2419x->chip_version = BQ24190_IC;
                dev_info(bq2419x->dev, "chip type BQ24190 detected\n");
-       else if ((val & BQ24192_IC_VER) == BQ24192_IC_VER)
-               dev_info(bq2419x->dev, "chip type BQ2419X/3 detected\n");
-       else if ((val & BQ24192i_IC_VER) == BQ24192i_IC_VER)
+       } else if (val == BQ24192_IC_VER) {
+               bq2419x->chip_version = BQ24192_IC;
+               dev_info(bq2419x->dev, "chip type BQ24192 detected\n");
+       } else if (val == BQ24193_IC_VER) {
+               bq2419x->chip_version = BQ24193_IC;
+               dev_info(bq2419x->dev, "chip type BQ24193 detected\n");
+       } else if (val == BQ24192i_IC_VER) {
+               bq2419x->chip_version = BQ24192i_IC;
                dev_info(bq2419x->dev, "chip type BQ2419Xi detected\n");
+       }
        return 0;
 }
 
index 5f61243..65516ba 100644 (file)
 #define BQ2419X_FAULT_REG              0x09
 #define BQ2419X_REVISION_REG           0x0a
 
-#define BQ24190_IC_VER                 0x40
+#define BQ2419X_IC_VER_MASK            0x3C
+#define BQ24190_IC_VER                 0x20
 #define BQ24192_IC_VER                 0x28
+#define BQ24193_IC_VER                 0x2C
 #define BQ24192i_IC_VER                        0x18
 
 #define BQ2419X_ENABLE_CHARGE_MASK     0x30
 #define BQ2419X_WD_80ms                        0x20
 #define BQ2419X_WD_160ms               0x30
 
+#define BQ2419X_JEITA_ISET_MASK                0x1
+#define BQ2419X_JEITA_ISET_20          0x1
+#define BQ2419X_JEITA_ISET_50          0x0
+
+#define BQ2419X_JEITA_VSET_MASK                0x10
+#define BQ2419X_JEITA_VSET_4_20V       0x10
+#define BQ2419X_JEITA_VSET_4_05V       0x00
+
 #define BQ2419x_VBUS_STAT              0xc0
 #define BQ2419x_VBUS_UNKNOWN           0x00
 #define BQ2419x_VBUS_USB               0x40