summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
l---------board/servo_v4/Makefile1
-rw-r--r--board/servo_v4/board.c220
-rw-r--r--board/servo_v4/board.h105
-rw-r--r--board/servo_v4/build.mk13
-rw-r--r--board/servo_v4/ec.tasklist21
-rw-r--r--board/servo_v4/gpio.inc81
6 files changed, 441 insertions, 0 deletions
diff --git a/board/servo_v4/Makefile b/board/servo_v4/Makefile
new file mode 120000
index 0000000000..94aaae2c4d
--- /dev/null
+++ b/board/servo_v4/Makefile
@@ -0,0 +1 @@
+../../Makefile \ No newline at end of file
diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c
new file mode 100644
index 0000000000..400ada3f83
--- /dev/null
+++ b/board/servo_v4/board.c
@@ -0,0 +1,220 @@
+/* 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.
+ */
+/* Servo V4 configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "common.h"
+#include "console.h"
+#include "ec_version.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "queue_policies.h"
+#include "registers.h"
+#include "spi.h"
+#include "task.h"
+#include "timer.h"
+#include "usart-stm32f0.h"
+#include "usart_tx_dma.h"
+#include "usart_rx_dma.h"
+#include "usb_gpio.h"
+#include "usb_i2c.h"
+#include "usb_spi.h"
+#include "usb-stream.h"
+#include "util.h"
+
+
+/******************************************************************************
+ * Build GPIO tables and expose a subset of the GPIOs over USB.
+ */
+
+#include "gpio_list.h"
+
+static enum gpio_signal const usb_gpio_list[] = {
+/* Outputs */
+GPIO_DUT_CHG_EN,
+GPIO_HOST_OR_CHG_CTL,
+GPIO_DP_HPD,
+GPIO_SBU_UART_SEL,
+GPIO_HOST_USB_HUB_RESET_L,
+GPIO_FASTBOOT_DUTHUB_MUX_SEL,
+GPIO_SBU_MUX_EN,
+GPIO_FASTBOOT_DUTHUB_MUX_EN_L,
+GPIO_DUT_HUB_USB_RESET_L,
+GPIO_ATMEL_HWB_L,
+GPIO_ATMEL_RESET_L,
+GPIO_EMMC_MUX_SEL,
+GPIO_CMUX_EN,
+GPIO_EMMC_MUX_EN_L,
+GPIO_EMMC_PWR_EN,
+
+
+/* Inputs */
+GPIO_USERVO_FAULT_L,
+GPIO_USB_FAULT_L,
+GPIO_USB_DUT_CC2_RPUSB,
+GPIO_USB_DUT_CC2_RD,
+GPIO_USB_DUT_CC2_RA,
+GPIO_TP17,
+GPIO_USB_DUT_CC1_PR3A0,
+GPIO_USB_DUT_CC1_RP1A5,
+GPIO_USB_DUT_CC1_RPUSB,
+GPIO_USB_DUT_CC1_RD,
+GPIO_USB_DUT_CC1_RA,
+GPIO_USB_DUT_CC2_PR3A0,
+GPIO_USB_DUT_CC2_RP1A5,
+
+};
+
+/*
+ * This instantiates struct usb_gpio_config const usb_gpio, plus several other
+ * variables, all named something beginning with usb_gpio_
+ */
+USB_GPIO_CONFIG(usb_gpio,
+ usb_gpio_list,
+ USB_IFACE_GPIO,
+ USB_EP_GPIO);
+
+
+/******************************************************************************
+ * Set up USB PD
+ */
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ /* USB PD CC lines sensing. Converted to mV (3300mV/4096). */
+ [ADC_DUT_CC1_PD] = {"DUT_CC1_PD", 3300, 4096, 0, STM32_AIN(0)},
+ [ADC_CHG_CC1_PD] = {"CHG_CC1_PD", 3300, 4096, 0, STM32_AIN(2)},
+ [ADC_CHG_CC2_PD] = {"CHG_CC2_PD", 3300, 4096, 0, STM32_AIN(4)},
+ [ADC_DUT_CC2_PD] = {"DUT_CC2_PD", 3300, 4096, 0, STM32_AIN(5)},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+
+/******************************************************************************
+ * Forward UARTs as a USB serial interface.
+ */
+
+#define USB_STREAM_RX_SIZE 16
+#define USB_STREAM_TX_SIZE 16
+
+/******************************************************************************
+ * Forward USART3 as a simple USB serial interface.
+ */
+
+static struct usart_config const usart3;
+struct usb_stream_config const usart3_usb;
+
+static struct queue const usart3_to_usb = QUEUE_DIRECT(64, uint8_t,
+ usart3.producer, usart3_usb.consumer);
+static struct queue const usb_to_usart3 = QUEUE_DIRECT(64, uint8_t,
+ usart3_usb.producer, usart3.consumer);
+
+static struct usart_config const usart3 =
+ USART_CONFIG(usart3_hw,
+ usart_rx_interrupt,
+ usart_tx_interrupt,
+ 115200,
+ usart3_to_usb,
+ usb_to_usart3);
+
+USB_STREAM_CONFIG(usart3_usb,
+ USB_IFACE_USART3_STREAM,
+ USB_STR_USART3_STREAM_NAME,
+ USB_EP_USART3_STREAM,
+ USB_STREAM_RX_SIZE,
+ USB_STREAM_TX_SIZE,
+ usb_to_usart3,
+ usart3_to_usb)
+
+
+/******************************************************************************
+ * Forward USART4 as a simple USB serial interface.
+ */
+
+static struct usart_config const usart4;
+struct usb_stream_config const usart4_usb;
+
+static struct queue const usart4_to_usb = QUEUE_DIRECT(64, uint8_t,
+ usart4.producer, usart4_usb.consumer);
+static struct queue const usb_to_usart4 = QUEUE_DIRECT(64, uint8_t,
+ usart4_usb.producer, usart4.consumer);
+
+static struct usart_config const usart4 =
+ USART_CONFIG(usart4_hw,
+ usart_rx_interrupt,
+ usart_tx_interrupt,
+ 9600,
+ usart4_to_usb,
+ usb_to_usart4);
+
+USB_STREAM_CONFIG(usart4_usb,
+ USB_IFACE_USART4_STREAM,
+ USB_STR_USART4_STREAM_NAME,
+ USB_EP_USART4_STREAM,
+ USB_STREAM_RX_SIZE,
+ USB_STREAM_TX_SIZE,
+ usb_to_usart4,
+ usart4_to_usb)
+
+
+/******************************************************************************
+ * Define the strings used in our USB descriptors.
+ */
+
+const void *const usb_strings[] = {
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("Servo V4"),
+ [USB_STR_SERIALNO] = USB_STRING_DESC("1234-a"),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_CONSOLE_NAME] = USB_STRING_DESC("Servo EC Shell"),
+ [USB_STR_USART3_STREAM_NAME] = USB_STRING_DESC("DUT UART"),
+ [USB_STR_USART4_STREAM_NAME] = USB_STRING_DESC("Atmega UART"),
+};
+
+BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
+
+
+
+/******************************************************************************
+ * Support I2C bridging over USB, this requires usb_i2c_board_enable and
+ * usb_i2c_board_disable to be defined to enable and disable the SPI bridge.
+ */
+
+/* I2C ports */
+const struct i2c_port_t i2c_ports[] = {
+ {"master", I2C_PORT_MASTER, 100,
+ GPIO_MASTER_I2C_SCL, GPIO_MASTER_I2C_SDA},
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+USB_I2C_CONFIG(usb_i2c, USB_IFACE_I2C, USB_EP_I2C);
+
+
+/******************************************************************************
+ * Initialize board.
+ */
+static void board_init(void)
+{
+ /* USB to serial queues */
+ queue_init(&usart3_to_usb);
+ queue_init(&usb_to_usart3);
+ queue_init(&usart4_to_usb);
+ queue_init(&usb_to_usart4);
+
+ /* UART init */
+ usart_init(&usart3);
+ usart_init(&usart4);
+
+ /* Delay DUT hub to avoid brownout. */
+ usleep(1000);
+ gpio_set_flags(GPIO_DUT_HUB_USB_RESET_L, GPIO_INPUT);
+
+ /* Write USB3 Mode Enable to PS8742 USB/DP Mux. */
+ i2c_write8(1, 0x20, 0x0, 0x20);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h
new file mode 100644
index 0000000000..f9f303b558
--- /dev/null
+++ b/board/servo_v4/board.h
@@ -0,0 +1,105 @@
+/* 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.
+ */
+
+/* Servo V4 configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+/* 48 MHz SYSCLK clock frequency */
+#define CPU_CLOCK 48000000
+
+/* Enable USART1,3,4 and USB streams */
+#define CONFIG_STREAM_USART
+
+#define CONFIG_STREAM_USART3
+#define CONFIG_STREAM_USART4
+#define CONFIG_STREAM_USB
+#define CONFIG_CMD_USART_INFO
+
+/* Optional features */
+#define CONFIG_STM_HWTIMER32
+#define CONFIG_HW_CRC
+
+/* USB Configuration */
+#define CONFIG_USB
+#define CONFIG_USB_PID 0x501b
+#define CONFIG_USB_CONSOLE
+
+/* USB interface indexes (use define rather than enum to expand them) */
+#define USB_IFACE_CONSOLE 0
+#define USB_IFACE_GPIO 1
+#define USB_IFACE_I2C 2
+#define USB_IFACE_USART3_STREAM 3
+#define USB_IFACE_USART4_STREAM 4
+#define USB_IFACE_COUNT 5
+
+/* USB endpoint indexes (use define rather than enum to expand them) */
+#define USB_EP_CONTROL 0
+#define USB_EP_CONSOLE 1
+#define USB_EP_GPIO 2
+#define USB_EP_I2C 3
+#define USB_EP_USART3_STREAM 4
+#define USB_EP_USART4_STREAM 5
+#define USB_EP_COUNT 6
+
+/* Enable control of GPIOs over USB */
+#define CONFIG_USB_GPIO
+
+/* This is not actually an EC so disable some features. */
+#undef CONFIG_WATCHDOG_HELP
+#undef CONFIG_LID_SWITCH
+
+/* Enable control of I2C over USB */
+#define CONFIG_USB_I2C
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
+#define I2C_PORT_MASTER 1
+
+/* PD features */
+#define CONFIG_ADC
+
+/*
+ * Allow dangerous commands all the time, since we don't have a write protect
+ * switch.
+ */
+#define CONFIG_SYSTEM_UNLOCKED
+
+#ifndef __ASSEMBLER__
+
+/* Timer selection */
+#define TIM_CLOCK32 2
+#define TIM_ADC 3
+
+
+#include "gpio_signal.h"
+
+/* USB string indexes */
+enum usb_strings {
+ USB_STR_DESC = 0,
+ USB_STR_VENDOR,
+ USB_STR_PRODUCT,
+ USB_STR_SERIALNO,
+ USB_STR_VERSION,
+ USB_STR_CONSOLE_NAME,
+ USB_STR_USART3_STREAM_NAME,
+ USB_STR_USART4_STREAM_NAME,
+
+ USB_STR_COUNT
+};
+
+
+/* ADC signal */
+enum adc_channel {
+ ADC_DUT_CC1_PD = 0,
+ ADC_CHG_CC1_PD,
+ ADC_CHG_CC2_PD,
+ ADC_DUT_CC2_PD,
+ /* Number of ADC channels */
+ ADC_CH_COUNT
+};
+
+#endif /* !__ASSEMBLER__ */
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/servo_v4/build.mk b/board/servo_v4/build.mk
new file mode 100644
index 0000000000..0e069a31ad
--- /dev/null
+++ b/board/servo_v4/build.mk
@@ -0,0 +1,13 @@
+# -*- makefile -*-
+# 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.
+#
+# Board specific files build
+
+# the IC is STmicro STM32F072RBT6
+CHIP:=stm32
+CHIP_FAMILY:=stm32f0
+CHIP_VARIANT:=stm32f07x
+
+board-y=board.o
diff --git a/board/servo_v4/ec.tasklist b/board/servo_v4/ec.tasklist
new file mode 100644
index 0000000000..1944ef3874
--- /dev/null
+++ b/board/servo_v4/ec.tasklist
@@ -0,0 +1,21 @@
+/* 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.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and
+ * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries,
+ * where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TASK_LIST \
+ TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
diff --git a/board/servo_v4/gpio.inc b/board/servo_v4/gpio.inc
new file mode 100644
index 0000000000..373e7f8f31
--- /dev/null
+++ b/board/servo_v4/gpio.inc
@@ -0,0 +1,81 @@
+/* -*- mode:c -*-
+ *
+ * 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.
+ */
+
+/* Outputs */
+GPIO(DUT_CHG_EN, PIN(A, 10), GPIO_OUT_LOW)
+GPIO(HOST_OR_CHG_CTL, PIN(A, 13), GPIO_OUT_HIGH)
+GPIO(SBU_UART_SEL, PIN(A, 15), GPIO_OUT_LOW)
+GPIO(HOST_USB_HUB_RESET_L, PIN(D, 2), GPIO_OUT_HIGH)
+GPIO(FASTBOOT_DUTHUB_MUX_SEL, PIN(B, 5), GPIO_OUT_HIGH)
+GPIO(SBU_MUX_EN, PIN(B, 6), GPIO_OUT_LOW)
+GPIO(FASTBOOT_DUTHUB_MUX_EN_L, PIN(B, 7), GPIO_OUT_LOW)
+GPIO(DUT_HUB_USB_RESET_L, PIN(B, 9), GPIO_OUT_LOW)
+GPIO(ATMEL_HWB_L, PIN(B, 12), GPIO_OUT_HIGH)
+GPIO(ATMEL_RESET_L, PIN(C, 12), GPIO_OUT_LOW)
+GPIO(EMMC_MUX_SEL, PIN(C, 13), GPIO_OUT_LOW)
+GPIO(CMUX_EN, PIN(C, 14), GPIO_OUT_HIGH)
+GPIO(EMMC_MUX_EN_L, PIN(F, 0), GPIO_OUT_HIGH)
+GPIO(EMMC_PWR_EN, PIN(F, 1), GPIO_OUT_LOW)
+
+
+/* Inputs */
+GPIO(DP_HPD, PIN(A, 14), GPIO_INPUT)
+GPIO(USERVO_FAULT_L, PIN(A, 8), GPIO_INPUT)
+GPIO(USB_FAULT_L, PIN(A, 9), GPIO_INPUT)
+
+GPIO(TP17, PIN(C, 15), GPIO_INPUT)
+
+/* Type-C */
+/* PD RX/TX */
+GPIO(USB_C_REF, PIN(A, 1), GPIO_ANALOG)
+GPIO(USB_CHG_CC1_PD, PIN(A, 2), GPIO_ANALOG)
+GPIO(USB_CHG_CC2_PD, PIN(A, 4), GPIO_ANALOG)
+GPIO(USB_DUT_CC1_PD, PIN(A, 0), GPIO_ANALOG)
+GPIO(USB_DUT_CC2_PD, PIN(A, 5), GPIO_ANALOG)
+
+GPIO(USB_CHG_CC1_TX_DATA, PIN(B, 4), GPIO_INPUT)
+GPIO(USB_CHG_CC2_TX_DATA, PIN(A, 6), GPIO_INPUT)
+GPIO(USB_DUT_CC1_TX_DATA, PIN(B, 14), GPIO_INPUT)
+GPIO(USB_DUT_CC2_TX_DATA, PIN(C, 2), GPIO_INPUT)
+
+GPIO(USB_DUT_CC1_PR3A0, PIN(C, 0), GPIO_INPUT)
+GPIO(USB_DUT_CC1_RP1A5, PIN(C, 1), GPIO_INPUT)
+GPIO(USB_DUT_CC1_RPUSB, PIN(C, 3), GPIO_INPUT)
+GPIO(USB_DUT_CC1_RD, PIN(C, 6), GPIO_INPUT)
+GPIO(USB_DUT_CC1_RA, PIN(C, 7), GPIO_INPUT)
+
+GPIO(USB_DUT_CC2_PR3A0, PIN(C, 8), GPIO_INPUT)
+GPIO(USB_DUT_CC2_RP1A5, PIN(C, 9), GPIO_INPUT)
+GPIO(USB_DUT_CC2_RPUSB, PIN(B, 0), GPIO_INPUT)
+GPIO(USB_DUT_CC2_RD, PIN(B, 1), GPIO_INPUT)
+GPIO(USB_DUT_CC2_RA, PIN(B, 2), GPIO_INPUT)
+
+/* Alternate PD functions */
+GPIO(USB_CHG_TX_CLKOUT, PIN(B, 8), GPIO_INPUT)
+GPIO(USB_CHG_TX_CLKIN, PIN(B, 3), GPIO_INPUT)
+GPIO(USB_DUT_TX_CLKOUT, PIN(B, 15), GPIO_INPUT)
+GPIO(USB_DUT_TX_CLKIN, PIN(B, 13), GPIO_INPUT)
+
+
+/* I2C pins should be configured as inputs until I2C module is */
+/* initialized. This will avoid driving the lines unintentionally.*/
+GPIO(MASTER_I2C_SCL, PIN(B, 10), GPIO_INPUT)
+GPIO(MASTER_I2C_SDA, PIN(B, 11), GPIO_INPUT)
+
+/* Unimplemented signals since we are not an EC */
+UNIMPLEMENTED(ENTERING_RW)
+UNIMPLEMENTED(WP_L)
+
+ALTERNATE(PIN_MASK(C, 0x0030), 1, MODULE_USART, 0) /* USART3: PC4/PC5 - Servo DUT UART */
+ALTERNATE(PIN_MASK(C, 0x0C00), 0, MODULE_USART, 0) /* USART4: PC10/PC11 - Servo UART3 */
+ALTERNATE(PIN_MASK(B, 0x0C00), 1, MODULE_I2C, 0) /* I2C MASTER:PB8/9 GPIO_ODR_HIGH */
+
+ALTERNATE(PIN_MASK(B, 0x0008), 0, MODULE_USB_PD, 0) /* SPI1_SCK: PB3 */
+ALTERNATE(PIN_MASK(B, 0x2000), 0, MODULE_USB_PD, 0) /* SPI2_SCK: PB13 */
+ALTERNATE(PIN_MASK(B, 0x0100), 2, MODULE_USB_PD, 0) /* TIM16_CH1: PB8 */
+ALTERNATE(PIN_MASK(B, 0x8000), 1, MODULE_USB_PD, 0) /* TIM15_CH2: PB15 */
+