]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/power/supply/cpcap-charger.c
power: supply: cpcap-charger: Update charge current table and add comments
[mirror_ubuntu-bionic-kernel.git] / drivers / power / supply / cpcap-charger.c
index 543a1bd21ab9c74ab15a2a16898fa477ed021818..adb9767adc8ab39410fc49f0954a50b946a77f19 100644 (file)
 #include <linux/iio/consumer.h>
 #include <linux/mfd/motorola-cpcap.h>
 
-/* CPCAP_REG_CRM register bits */
+/*
+ * CPCAP_REG_CRM register bits. For documentation of somewhat similar hardware,
+ * see NXP "MC13783 Power Management and Audio Circuit Users's Guide"
+ * MC13783UG.pdf chapter "8.5 Battery Interface Register Summary". The registers
+ * and values for CPCAP are different, but some of the internal components seem
+ * similar. Also see the Motorola Linux kernel cpcap-regbits.h. CPCAP_REG_CHRGR_1
+ * bits that seem to describe the CRM register.
+ */
 #define CPCAP_REG_CRM_UNUSED_641_15    BIT(15) /* 641 = register number */
 #define CPCAP_REG_CRM_UNUSED_641_14    BIT(14) /* 641 = register number */
-#define CPCAP_REG_CRM_CHRG_LED_EN      BIT(13)
-#define CPCAP_REG_CRM_RVRSMODE         BIT(12)
-#define CPCAP_REG_CRM_ICHRG_TR1                BIT(11)
+#define CPCAP_REG_CRM_CHRG_LED_EN      BIT(13) /* Charger LED */
+#define CPCAP_REG_CRM_RVRSMODE         BIT(12) /* USB VBUS output enable */
+#define CPCAP_REG_CRM_ICHRG_TR1                BIT(11) /* Trickle charge current */
 #define CPCAP_REG_CRM_ICHRG_TR0                BIT(10)
-#define CPCAP_REG_CRM_FET_OVRD         BIT(9)
-#define CPCAP_REG_CRM_FET_CTRL         BIT(8)
-#define CPCAP_REG_CRM_VCHRG3           BIT(7)
+#define CPCAP_REG_CRM_FET_OVRD         BIT(9)  /* 0 = hardware, 1 = FET_CTRL */
+#define CPCAP_REG_CRM_FET_CTRL         BIT(8)  /* BPFET 1 if FET_OVRD set */
+#define CPCAP_REG_CRM_VCHRG3           BIT(7)  /* Charge voltage bits */
 #define CPCAP_REG_CRM_VCHRG2           BIT(6)
 #define CPCAP_REG_CRM_VCHRG1           BIT(5)
 #define CPCAP_REG_CRM_VCHRG0           BIT(4)
-#define CPCAP_REG_CRM_ICHRG3           BIT(3)
+#define CPCAP_REG_CRM_ICHRG3           BIT(3)  /* Charge current bits */
 #define CPCAP_REG_CRM_ICHRG2           BIT(2)
 #define CPCAP_REG_CRM_ICHRG1           BIT(1)
 #define CPCAP_REG_CRM_ICHRG0           BIT(0)
 #define CPCAP_REG_CRM_VCHRG_4V30       CPCAP_REG_CRM_VCHRG(0x8)
 #define CPCAP_REG_CRM_VCHRG_4V32       CPCAP_REG_CRM_VCHRG(0x9)
 #define CPCAP_REG_CRM_VCHRG_4V34       CPCAP_REG_CRM_VCHRG(0xa)
-#define CPCAP_REG_CRM_VCHRG_4V36       CPCAP_REG_CRM_VCHRG(0xb)
+#define CPCAP_REG_CRM_VCHRG_4V35       CPCAP_REG_CRM_VCHRG(0xb)
 #define CPCAP_REG_CRM_VCHRG_4V38       CPCAP_REG_CRM_VCHRG(0xc)
 #define CPCAP_REG_CRM_VCHRG_4V40       CPCAP_REG_CRM_VCHRG(0xd)
 #define CPCAP_REG_CRM_VCHRG_4V42       CPCAP_REG_CRM_VCHRG(0xe)
 #define CPCAP_REG_CRM_VCHRG_4V44       CPCAP_REG_CRM_VCHRG(0xf)
 
-/* CPCAP_REG_CRM charge currents */
+/*
+ * CPCAP_REG_CRM charge currents. These seem to match MC13783UG.pdf
+ * values in "Table 8-3. Charge Path Regulator Current Limit
+ * Characteristics" for the nominal values.
+ */
 #define CPCAP_REG_CRM_ICHRG(val)       (((val) & 0xf) << 0)
 #define CPCAP_REG_CRM_ICHRG_0A000      CPCAP_REG_CRM_ICHRG(0x0)
 #define CPCAP_REG_CRM_ICHRG_0A070      CPCAP_REG_CRM_ICHRG(0x1)
-#define CPCAP_REG_CRM_ICHRG_0A176      CPCAP_REG_CRM_ICHRG(0x2)
-#define CPCAP_REG_CRM_ICHRG_0A264      CPCAP_REG_CRM_ICHRG(0x3)
-#define CPCAP_REG_CRM_ICHRG_0A352      CPCAP_REG_CRM_ICHRG(0x4)
-#define CPCAP_REG_CRM_ICHRG_0A440      CPCAP_REG_CRM_ICHRG(0x5)
-#define CPCAP_REG_CRM_ICHRG_0A528      CPCAP_REG_CRM_ICHRG(0x6)
-#define CPCAP_REG_CRM_ICHRG_0A616      CPCAP_REG_CRM_ICHRG(0x7)
-#define CPCAP_REG_CRM_ICHRG_0A704      CPCAP_REG_CRM_ICHRG(0x8)
-#define CPCAP_REG_CRM_ICHRG_0A792      CPCAP_REG_CRM_ICHRG(0x9)
-#define CPCAP_REG_CRM_ICHRG_0A880      CPCAP_REG_CRM_ICHRG(0xa)
-#define CPCAP_REG_CRM_ICHRG_0A968      CPCAP_REG_CRM_ICHRG(0xb)
-#define CPCAP_REG_CRM_ICHRG_1A056      CPCAP_REG_CRM_ICHRG(0xc)
-#define CPCAP_REG_CRM_ICHRG_1A144      CPCAP_REG_CRM_ICHRG(0xd)
-#define CPCAP_REG_CRM_ICHRG_1A584      CPCAP_REG_CRM_ICHRG(0xe)
+#define CPCAP_REG_CRM_ICHRG_0A177      CPCAP_REG_CRM_ICHRG(0x2)
+#define CPCAP_REG_CRM_ICHRG_0A266      CPCAP_REG_CRM_ICHRG(0x3)
+#define CPCAP_REG_CRM_ICHRG_0A355      CPCAP_REG_CRM_ICHRG(0x4)
+#define CPCAP_REG_CRM_ICHRG_0A443      CPCAP_REG_CRM_ICHRG(0x5)
+#define CPCAP_REG_CRM_ICHRG_0A532      CPCAP_REG_CRM_ICHRG(0x6)
+#define CPCAP_REG_CRM_ICHRG_0A621      CPCAP_REG_CRM_ICHRG(0x7)
+#define CPCAP_REG_CRM_ICHRG_0A709      CPCAP_REG_CRM_ICHRG(0x8)
+#define CPCAP_REG_CRM_ICHRG_0A798      CPCAP_REG_CRM_ICHRG(0x9)
+#define CPCAP_REG_CRM_ICHRG_0A886      CPCAP_REG_CRM_ICHRG(0xa)
+#define CPCAP_REG_CRM_ICHRG_0A975      CPCAP_REG_CRM_ICHRG(0xb)
+#define CPCAP_REG_CRM_ICHRG_1A064      CPCAP_REG_CRM_ICHRG(0xc)
+#define CPCAP_REG_CRM_ICHRG_1A152      CPCAP_REG_CRM_ICHRG(0xd)
+#define CPCAP_REG_CRM_ICHRG_1A596      CPCAP_REG_CRM_ICHRG(0xe)
 #define CPCAP_REG_CRM_ICHRG_NO_LIMIT   CPCAP_REG_CRM_ICHRG(0xf)
 
 enum {
@@ -262,7 +273,7 @@ static int cpcap_charger_set_state(struct cpcap_charger_ddata *ddata,
        bool enable;
        int error;
 
-       enable = max_voltage && (charge_current || trickle_current);
+       enable = (charge_current || trickle_current);
        dev_dbg(ddata->dev, "%s enable: %i\n", __func__, enable);
 
        if (!enable) {
@@ -428,14 +439,13 @@ static void cpcap_usb_detect(struct work_struct *work)
                int max_current;
 
                if (cpcap_charger_battery_found(ddata))
-                       max_current = CPCAP_REG_CRM_ICHRG_1A584;
+                       max_current = CPCAP_REG_CRM_ICHRG_1A596;
                else
-                       max_current = CPCAP_REG_CRM_ICHRG_0A528;
+                       max_current = CPCAP_REG_CRM_ICHRG_0A532;
 
                error = cpcap_charger_set_state(ddata,
-                                               CPCAP_REG_CRM_VCHRG_4V20,
-                                               max_current,
-                                               CPCAP_REG_CRM_TR_0A72);
+                                               CPCAP_REG_CRM_VCHRG_4V35,
+                                               max_current, 0);
                if (error)
                        goto out_err;
        } else {
@@ -566,7 +576,7 @@ out_err:
 }
 
 static const struct power_supply_desc cpcap_charger_usb_desc = {
-       .name           = "cpcap_usb",
+       .name           = "usb",
        .type           = POWER_SUPPLY_TYPE_USB,
        .properties     = cpcap_charger_props,
        .num_properties = ARRAY_SIZE(cpcap_charger_props),