summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott <scollyer@chromium.org>2017-03-08 18:56:32 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-03-26 02:15:54 -0700
commit850e9e4ac0f84217b7fbc182b23821047e203307 (patch)
treea4834dedbba38f33b7f1038148d590a782b5d942
parent577fb7faa0fd8479921dfdf344a4d8bd44022e82 (diff)
downloadchrome-ec-850e9e4ac0f84217b7fbc182b23821047e203307.tar.gz
servo_v4: pd: Updated CC_NC and CC_RA macros
Previous boards that implemented tcpc layer on chip didn't support variable Rp values. However, servo_v4 can present any of the 3 possible Rp values and therefore the voltage thresholds that are used to determine a no-connect or Ra attach status need a way to be set based on the Rp value that's current attached to a given CC line. - Added port and cc line selection to both the CC_NC and CC_RA macros and now check if they are already defined before being defined in usb_pd_tcpc.c. - Defined each of these macros in board.h to use a function that's able to select the threshold based on the current Rp configuration. BUG=b:35586526 BRANCH=servo TEST=Tested with servo_v4 against Electro and verified that it connects when a charger is and is not connected to CHG port which exercises the differnt Rp combinations that servo_v4 presents. Change-Id: I1a31e430c0f290486f0fa8a50bdafdddf20d23ca Signed-off-by: Scott <scollyer@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/451962 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/servo_v4/board.h34
-rw-r--r--board/servo_v4/usb_pd_policy.c45
-rw-r--r--common/usb_pd_tcpc.c19
3 files changed, 88 insertions, 10 deletions
diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h
index eb5de84dbd..dad2c8642b 100644
--- a/board/servo_v4/board.h
+++ b/board/servo_v4/board.h
@@ -91,9 +91,9 @@
/* Override PD_ROLE_DEFAULT in usb_pd.h */
#define PD_ROLE_DEFAULT(port) ((port) ? PD_ROLE_SOURCE : PD_ROLE_SINK)
-/* 3.0A Standard-current Rp */
-#define PD_SRC_VNC PD_SRC_3_0_VNC_MV
-#define PD_SRC_RD_THRESHOLD PD_SRC_DEF_RD_THRESH_MV
+/* Variable-current Rp no connect and Ra attach macros */
+#define CC_NC(port, cc, sel) (pd_tcpc_cc_nc(port, cc, sel))
+#define CC_RA(port, cc, sel) (pd_tcpc_cc_ra(port, cc, sel))
/*
* TODO(crosbug.com/p/60792): The delay values are currently just place holders
@@ -153,5 +153,33 @@ enum adc_channel {
ADC_CH_COUNT
};
+/**
+ * Compare cc_voltage to disconnect threshold
+ *
+ * This function can be used for boards that support variable Rp settings and
+ * require a different voltage threshold based on the Rp value attached to a
+ * given cc line.
+ *
+ * @param port USB-C port number
+ * @param cc_volt voltage measured in mV of the CC line
+ * @param cc_sel cc1 or cc2 selection
+ * @return 1 if voltage is >= threshold value for disconnect
+ */
+int pd_tcpc_cc_nc(int port, int cc_volt, int cc_sel);
+
+/**
+ * Compare cc_voltage to Ra threshold
+ *
+ * This function can be used for boards that support variable Rp settings and
+ * require a different voltage threshold based on the Rp value attached to a
+ * given cc line.
+ *
+ * @param port USB-C port number
+ * @param cc_volt voltage measured in mV of the CC line
+ * @param cc_sel cc1 or cc2 selection
+ * @return 1 if voltage is < threshold value for Ra attach
+ */
+int pd_tcpc_cc_ra(int port, int cc_volt, int cc_sel);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
index 9ba5356791..b6c395a860 100644
--- a/board/servo_v4/usb_pd_policy.c
+++ b/board/servo_v4/usb_pd_policy.c
@@ -58,6 +58,19 @@ static struct vbus_prop vbus[CONFIG_USB_PD_PORT_COUNT];
static struct vbus_prop vbus_pend;
static uint8_t vbus_rp = TYPEC_RP_RESERVED;
+/* Voltage thresholds for no connect */
+static int pd_src_vnc[TYPEC_RP_RESERVED][2] = {
+ {PD_SRC_3_0_VNC_MV, PD_SRC_1_5_VNC_MV},
+ {PD_SRC_1_5_VNC_MV, PD_SRC_DEF_VNC_MV},
+ {PD_SRC_3_0_VNC_MV, PD_SRC_DEF_VNC_MV},
+};
+/* Voltage thresholds for Ra attach */
+static int pd_src_rd_threshold[TYPEC_RP_RESERVED][2] = {
+ {PD_SRC_3_0_RD_THRESH_MV, PD_SRC_1_5_RD_THRESH_MV},
+ {PD_SRC_1_5_RD_THRESH_MV, PD_SRC_DEF_RD_THRESH_MV},
+ {PD_SRC_3_0_RD_THRESH_MV, PD_SRC_DEF_RD_THRESH_MV},
+};
+
static void board_manage_dut_port(void)
{
int rp;
@@ -165,6 +178,38 @@ static void board_update_chg_vbus(int max_ma, int vbus_mv)
hook_call_deferred(&board_manage_chg_port_data, 0);
}
+int pd_tcpc_cc_nc(int port, int cc_volt, int cc_sel)
+{
+ int rp_index;
+
+ /* Can never be called from CHG port as it's sink only */
+ if (port == CHG)
+ return 0;
+
+ rp_index = vbus_rp;
+ /* Ensure that rp_index doens't exceed the array size */
+ if (rp_index >= TYPEC_RP_RESERVED)
+ rp_index = 0;
+
+ return cc_volt >= pd_src_vnc[rp_index][cc_sel];
+}
+
+int pd_tcpc_cc_ra(int port, int cc_volt, int cc_sel)
+{
+ int rp_index;
+
+ /* Can never be called from CHG port as it's sink only */
+ if (port == CHG)
+ return 0;
+
+ rp_index = vbus_rp;
+ /* Ensure that rp_index doens't exceed the array size */
+ if (rp_index >= TYPEC_RP_RESERVED)
+ rp_index = 0;
+
+ return cc_volt < pd_src_rd_threshold[rp_index][cc_sel];
+}
+
int board_select_rp_value(int port, int rp)
{
return pd_set_rp_rd(port, TYPEC_CC_RP, rp);
diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c
index 491b471e22..0c620f7207 100644
--- a/common/usb_pd_tcpc.c
+++ b/common/usb_pd_tcpc.c
@@ -158,9 +158,13 @@ static const uint8_t dec4b5b[] = {
#define PD_SRC_VNC PD_SRC_DEF_VNC_MV
#endif
-#define CC_RA(cc) (cc < PD_SRC_RD_THRESHOLD)
+#ifndef CC_RA
+#define CC_RA(port, cc, sel) (cc < PD_SRC_RD_THRESHOLD)
+#endif
#define CC_RD(cc) ((cc >= PD_SRC_RD_THRESHOLD) && (cc < PD_SRC_VNC))
-#define CC_NC(cc) (cc >= PD_SRC_VNC)
+#ifndef CC_NC
+#define CC_NC(port, cc, sel) (cc >= PD_SRC_VNC)
+#endif
/*
* Polarity based on 'UFP Perspective'.
@@ -715,13 +719,13 @@ static void handle_request(int port, uint16_t head)
}
/* Convert CC voltage to CC status */
-static int cc_voltage_to_status(int port, int cc_volt)
+static int cc_voltage_to_status(int port, int cc_volt, int cc_sel)
{
/* If we have a pull-up, then we are source, check for Rd. */
if (pd[port].cc_pull == TYPEC_CC_RP) {
- if (CC_NC(cc_volt))
+ if (CC_NC(port, cc_volt, cc_sel))
return TYPEC_CC_VOLT_OPEN;
- else if (CC_RA(cc_volt))
+ else if (CC_RA(port, cc_volt, cc_sel))
return TYPEC_CC_VOLT_RA;
else
return TYPEC_CC_VOLT_RD;
@@ -824,7 +828,7 @@ int tcpc_run(int port, int evt)
cc = pd_adc_read(port, i);
/* convert voltage to status, and check status change */
- cc = cc_voltage_to_status(port, cc);
+ cc = cc_voltage_to_status(port, cc, i);
if (pd[port].cc_status[i] != cc) {
pd[port].cc_status[i] = cc;
alert(port, TCPC_REG_ALERT_CC_STATUS);
@@ -1109,7 +1113,8 @@ void tcpc_init(int port)
/* make initial readings of CC voltages */
for (i = 0; i < 2; i++) {
pd[port].cc_status[i] = cc_voltage_to_status(port,
- pd_adc_read(port, i));
+ pd_adc_read(port, i),
+ i);
}
#ifdef CONFIG_USB_PD_TCPC_TRACK_VBUS