diff options
-rw-r--r-- | board/cr50/build.mk | 1 | ||||
-rw-r--r-- | board/cr50/gpio.inc | 16 | ||||
-rw-r--r-- | board/cr50/rdd.c | 64 | ||||
-rw-r--r-- | chip/g/rdd.c | 36 | ||||
-rw-r--r-- | chip/g/rdd.h | 14 |
5 files changed, 102 insertions, 29 deletions
diff --git a/board/cr50/build.mk b/board/cr50/build.mk index 09dd749239..7232785edf 100644 --- a/board/cr50/build.mk +++ b/board/cr50/build.mk @@ -30,6 +30,7 @@ dirs-y += $(BDIR)/tpm2 # Objects that we need to build board-y = board.o +board-${CONFIG_RDD} += rdd.o board-y += tpm2/NVMem.o board-y += tpm2/aes.o board-y += tpm2/ecc.o diff --git a/board/cr50/gpio.inc b/board/cr50/gpio.inc index 1c6d04f4b9..ef4b5eb21b 100644 --- a/board/cr50/gpio.inc +++ b/board/cr50/gpio.inc @@ -54,14 +54,14 @@ PINMUX(GPIO(BATT_PRES), M2, 0) /* UARTs */ PINMUX(FUNC(UART0_TX), A0, DIO_OUTPUT) /* Cr50 console */ PINMUX(FUNC(UART0_RX), A1, DIO_INPUT | DIO_WAKE_LOW) -/* AP console */ -/* TODO(crosbug.com/p/52281, crosbug.com/p/50700). Don't fight servo */ -/* PINMUX(FUNC(UART1_TX), A7, DIO_OUTPUT) */ -PINMUX(FUNC(UART1_RX), A3, DIO_INPUT) -/* EC console */ -/* TODO(crosbug.com/p/52281, crosbug.com/p/50700). Don't fight servo */ -/* PINMUX(FUNC(UART2_TX), B5, DIO_OUTPUT) */ -PINMUX(FUNC(UART2_RX), B6, DIO_INPUT) +/* UART1_TX and UART2_TX are configured in usart.c. They are not set as outputs + * here in order to avoid interfering with servo. They can be controlled using + * the 'uart' console command. + * UART1_TX = DIOA7 AP console + * UART2_TX = DIOB5 EC console + */ +PINMUX(FUNC(UART1_RX), A3, DIO_INPUT) /* AP console */ +PINMUX(FUNC(UART2_RX), B6, DIO_INPUT) /* EC console */ /* I2C pins are bi-directional */ PINMUX(FUNC(I2C0_SCL), B0, DIO_INPUT) diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c new file mode 100644 index 0000000000..66f6c8c313 --- /dev/null +++ b/board/cr50/rdd.c @@ -0,0 +1,64 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "console.h" +#include "rdd.h" +#include "registers.h" +#include "usb_api.h" + +static void usart_tx_connect(void) +{ + GWRITE(PINMUX, DIOA7_SEL, GC_PINMUX_UART1_TX_SEL); + GWRITE(PINMUX, DIOB5_SEL, GC_PINMUX_UART2_TX_SEL); +} + +static void usart_tx_disconnect(void) +{ + GWRITE(PINMUX, DIOA7_SEL, GC_PINMUX_DIOA3_SEL_DEFAULT); + GWRITE(PINMUX, DIOB5_SEL, GC_PINMUX_DIOB5_SEL_DEFAULT); +} + +void rdd_attached(void) +{ + /* Select the CCD PHY */ + usb_select_phy(USB_SEL_PHY1); + + /* Connect to selected phy */ + usb_init(); +} + +void rdd_detached(void) +{ + /* Disconnect from AP and EC UART TX */ + usart_tx_disconnect(); + + /* Select the AP PHY */ + usb_select_phy(USB_SEL_PHY0); + + /* Connect to selected phy */ + usb_init(); +} + +static int command_uart(int argc, char **argv) +{ + static int enabled; + + if (argc > 1) { + if (!strcasecmp("enable", argv[1])) { + enabled = 1; + usart_tx_connect(); + } else if (!strcasecmp("disable", argv[1])) { + enabled = 0; + usart_tx_disconnect(); + } + } + + ccprintf("UART %s\n", enabled ? "enabled" : "disabled"); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(uart, command_uart, + "[enable|disable]", + "Get/set the UART TX connection state", + NULL); diff --git a/chip/g/rdd.c b/chip/g/rdd.c index 63df750484..59a27ee475 100644 --- a/chip/g/rdd.c +++ b/chip/g/rdd.c @@ -7,16 +7,14 @@ #include "console.h" #include "gpio.h" #include "hooks.h" +#include "rdd.h" #include "registers.h" #include "task.h" #include "usb_api.h" -#define CCD_PHY USB_SEL_PHY1 -#define AP_PHY USB_SEL_PHY0 +static uint16_t debug_detect; -uint16_t ccd_detect; - -static int debug_cable_is_detected(void) +int debug_cable_is_attached(void) { uint8_t cc1 = GREAD_FIELD(RDD, INPUT_PIN_VALUES, CC1); uint8_t cc2 = GREAD_FIELD(RDD, INPUT_PIN_VALUES, CC2); @@ -26,25 +24,18 @@ static int debug_cable_is_detected(void) void rdd_interrupt(void) { - if (debug_cable_is_detected()) { + if (debug_cable_is_attached()) { ccprintf("Debug Accessory connected\n"); /* Detect when debug cable is disconnected */ - GWRITE(RDD, PROG_DEBUG_STATE_MAP, ~ccd_detect); - - /* Select the CCD PHY */ - usb_select_phy(CCD_PHY); + GWRITE(RDD, PROG_DEBUG_STATE_MAP, ~debug_detect); + rdd_attached(); } else { ccprintf("Debug Accessory disconnected\n"); /* Detect when debug cable is connected */ - GWRITE(RDD, PROG_DEBUG_STATE_MAP, ccd_detect); - - /* Select the AP PHY */ - usb_select_phy(AP_PHY); + GWRITE(RDD, PROG_DEBUG_STATE_MAP, debug_detect); + rdd_detached(); } - /* Connect to selected phy */ - usb_init(); - /* Clear interrupt */ GWRITE_FIELD(RDD, INT_STATE, INTR_DEBUG_STATE_DETECTED, 1); } @@ -56,10 +47,13 @@ void rdd_init(void) clock_enable_module(MODULE_RDD, 1); GWRITE(RDD, POWER_DOWN_B, 1); - ccd_detect = GREAD(RDD, PROG_DEBUG_STATE_MAP); - /* Detect cable disconnect if CCD is enabled */ - if (usb_get_phy() == CCD_PHY) - GWRITE(RDD, PROG_DEBUG_STATE_MAP, ~ccd_detect); + debug_detect = GREAD(RDD, PROG_DEBUG_STATE_MAP); + + /* If cable is attached, detect when it is disconnected */ + if (debug_cable_is_attached()) { + GWRITE(RDD, PROG_DEBUG_STATE_MAP, ~debug_detect); + rdd_attached(); + } /* Enable RDD interrupts */ task_enable_irq(GC_IRQNUM_RDD0_INTR_DEBUG_STATE_DETECTED_INT); diff --git a/chip/g/rdd.h b/chip/g/rdd.h new file mode 100644 index 0000000000..53dd687a16 --- /dev/null +++ b/chip/g/rdd.h @@ -0,0 +1,14 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_RDD_H +#define __CROS_RDD_H + +/* Detach from debug cable */ +void rdd_detached(void); + +/* Attach to debug cable */ +void rdd_attached(void); +#endif /* __CROS_RDD_H */ |