summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2016-11-03 12:19:20 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-11-04 18:31:56 -0700
commit4555fe63f5db4eb6674c93623e4499e6859eac62 (patch)
treebc785413e0caec3626fc3dcd67d6232d186721af
parent72d72ea0089ab27fadc7b9bf81829c1646e20847 (diff)
downloadchrome-ec-4555fe63f5db4eb6674c93623e4499e6859eac62.tar.gz
anx74xx: Modifed tcpm_get_cc function to fix check for 3.0 A type
When attaching a dump (not PD protocol) TypeC charger, the incorrect charger type was being selected and therefore it was not enabling 3A charging. I tracked this issue down to the anx74xx_tcpm_get_cc() function returning a incorrect value. The expected value was TYPEC_CC_VOLT_SNK_3_0, but instead it was returning TYPEC_CC_VOLT_SNK_DEF. The reason the incorrect cc type was being returned is because the if, else if, construct didn't work properly for the 3A case where the upper 2 bits are set. Modified this routine to use a case statement and consolidated the checks for both cc1 and cc2 into one helper function. BRANCH=none BUG=chrome-os-partner:58738 TEST=manual Connected zinger and guppy chargers and verified correct cc type was being returned. In addition tested hoho/dingdong adapters as well as suzyq. Tested both cable orientations to verify that cc1 and cc2 returned the correct values. With guppy connected, now see this output on ec console: C0 HARD RST TX C0 st5 C0 st36 C0 st37 C0 HARD RST TX C0 st5 [1921.980074 AC on] [1922.008140 charge_request(8688mV, 9280mA)] C0 st6 [1922.910539 Ramp p0 st5 3000mA 3000mA] Change-Id: I8b31c7ce366f383dfcc2f6e850b76a83340a02a1 Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/406642 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Kevin K Wong <kevin.k.wong@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--driver/tcpm/anx74xx.c70
-rw-r--r--driver/tcpm/anx74xx.h17
2 files changed, 50 insertions, 37 deletions
diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c
index 5e3681e643..e22e1a49dd 100644
--- a/driver/tcpm/anx74xx.c
+++ b/driver/tcpm/anx74xx.c
@@ -398,37 +398,54 @@ static int anx74xx_read_pd_obj(int port,
return rv;
}
+static int anx74xx_check_cc_type(int cc_reg)
+{
+ int cc;
+
+ switch (cc_reg & ANX74XX_REG_CC_STATUS_MASK) {
+ case BIT_VALUE_OF_SRC_CC_RD:
+ cc = TYPEC_CC_VOLT_RD;
+ break;
+
+ case BIT_VALUE_OF_SRC_CC_RA:
+ cc = TYPEC_CC_VOLT_RD;
+ break;
+
+ case BIT_VALUE_OF_SNK_CC_DEFAULT:
+ cc = TYPEC_CC_VOLT_SNK_DEF;
+ break;
+
+ case BIT_VALUE_OF_SNK_CC_1_P_5:
+ cc = TYPEC_CC_VOLT_SNK_1_5;
+ break;
+
+ case BIT_VALUE_OF_SNK_CC_3_P_0:
+ cc = TYPEC_CC_VOLT_SNK_3_0;
+ break;
+
+ default:
+ /* If no bits are set, then nothing is attached */
+ cc = TYPEC_CC_VOLT_OPEN;
+ }
+
+ return cc;
+}
+
static int anx74xx_tcpm_get_cc(int port, int *cc1, int *cc2)
{
int rv = EC_SUCCESS;
int reg = 0;
+
+ /* Read tcpc cc status register */
rv |= tcpc_read(port, ANX74XX_REG_CC_STATUS, &reg);
- /* CC1 */
- if (reg & BIT_VALUE_OF_SNK_CC1_DEFAULT)
- *cc1 = TYPEC_CC_VOLT_SNK_DEF;
- else if (reg & BIT_VALUE_OF_SNK_CC1_1_P_5)
- *cc1 = TYPEC_CC_VOLT_SNK_1_5;
- else if (reg & BIT_VALUE_OF_SNK_CC1_3_P_0)
- *cc1 = TYPEC_CC_VOLT_SNK_3_0;
- else if (reg & BIT_VALUE_OF_SRC_CC1_RA)
- *cc1 = TYPEC_CC_VOLT_RA;
- else if (reg & BIT_VALUE_OF_SRC_CC1_RD)
- *cc1 = TYPEC_CC_VOLT_RD;
- else
- *cc1 = TYPEC_CC_VOLT_OPEN;
- /* CC2 */
- if (reg & BIT_VALUE_OF_SNK_CC2_DEFAULT)
- *cc2 = TYPEC_CC_VOLT_SNK_DEF;
- else if (reg & BIT_VALUE_OF_SNK_CC2_1_P_5)
- *cc2 = TYPEC_CC_VOLT_SNK_1_5;
- else if (reg & BIT_VALUE_OF_SNK_CC2_3_P_0)
- *cc2 = TYPEC_CC_VOLT_SNK_3_0;
- else if (reg & BIT_VALUE_OF_SRC_CC2_RA)
- *cc2 = TYPEC_CC_VOLT_RA;
- else if (reg & BIT_VALUE_OF_SRC_CC2_RD)
- *cc2 = TYPEC_CC_VOLT_RD;
- else
- *cc2 = TYPEC_CC_VOLT_OPEN;
+ /* Check for cc1 type */
+ *cc1 = anx74xx_check_cc_type(reg);
+ /*
+ * Check for cc2 type (note cc2 bits are upper 4 of cc status
+ * register.
+ */
+ *cc2 = anx74xx_check_cc_type(reg >> 4);
+
/* clear HPD status*/
if (!(*cc1) && !(*cc2)) {
anx74xx_tcpc_clear_hpd_status(port);
@@ -439,6 +456,7 @@ static int anx74xx_tcpm_get_cc(int port, int *cc1, int *cc2)
return EC_SUCCESS;
}
+
static int anx74xx_rp_control(int port, int rp)
{
int reg;
diff --git a/driver/tcpm/anx74xx.h b/driver/tcpm/anx74xx.h
index 6e31dbdf7d..5f0995725d 100644
--- a/driver/tcpm/anx74xx.h
+++ b/driver/tcpm/anx74xx.h
@@ -165,17 +165,12 @@
#define ANX74XX_REG_STATUS_CC2_VRD_3P0 (1 << 2)
/* defined in the inter-bock Spec: 4.2.10 CC Detect Status */
-
-#define BIT_VALUE_OF_SRC_CC1_RD 0x01
-#define BIT_VALUE_OF_SRC_CC1_RA 0x02
-#define BIT_VALUE_OF_SNK_CC1_DEFAULT 0x04
-#define BIT_VALUE_OF_SNK_CC1_1_P_5 0x08
-#define BIT_VALUE_OF_SNK_CC1_3_P_0 0x0C
-#define BIT_VALUE_OF_SRC_CC2_RD 0x10
-#define BIT_VALUE_OF_SRC_CC2_RA 0x20
-#define BIT_VALUE_OF_SNK_CC2_DEFAULT 0x40
-#define BIT_VALUE_OF_SNK_CC2_1_P_5 0x80
-#define BIT_VALUE_OF_SNK_CC2_3_P_0 0xC0
+#define ANX74XX_REG_CC_STATUS_MASK 0xf
+#define BIT_VALUE_OF_SRC_CC_RD 0x01
+#define BIT_VALUE_OF_SRC_CC_RA 0x02
+#define BIT_VALUE_OF_SNK_CC_DEFAULT 0x04
+#define BIT_VALUE_OF_SNK_CC_1_P_5 0x08
+#define BIT_VALUE_OF_SNK_CC_3_P_0 0x0C
extern const struct tcpm_drv anx74xx_tcpm_drv;
extern const struct usb_mux_driver anx74xx_tcpm_usb_mux_driver;