diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2014-04-18 08:01:39 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-30 09:45:54 +0000 |
commit | ac4238c29986a3a0ec587432712bd21c99731e16 (patch) | |
tree | efcc3ab4253ebae53beff1844551db91559ec8d1 | |
parent | bc72ea3e17007577cfdb87d068bbc1883a591ad2 (diff) | |
download | chrome-ec-ac4238c29986a3a0ec587432712bd21c99731e16.tar.gz |
Add support for the Firefly board
Firefly is the test/burn-in board for Zinger production.
It's acting a Power Delivery sink.
The plug polarity is not managed correctly yet.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=none
TEST=none
Change-Id: I57f525ad04c519f2fa458635a1c6cc45a503e5ac
Reviewed-on: https://chromium-review.googlesource.com/195586
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/firefly/board.c | 164 | ||||
-rw-r--r-- | board/firefly/board.h | 110 | ||||
-rw-r--r-- | board/firefly/build.mk | 14 | ||||
-rw-r--r-- | board/firefly/ec.tasklist | 22 | ||||
-rw-r--r-- | board/firefly/usb_pd_config.h | 103 | ||||
-rw-r--r-- | board/firefly/usb_pd_policy.c | 125 | ||||
-rwxr-xr-x | util/flash_ec | 2 |
7 files changed, 539 insertions, 1 deletions
diff --git a/board/firefly/board.c b/board/firefly/board.c new file mode 100644 index 0000000000..c48e27c7c7 --- /dev/null +++ b/board/firefly/board.c @@ -0,0 +1,164 @@ +/* Copyright (c) 2014 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. + */ +/* Firefly board configuration */ + +#include "adc.h" +#include "adc_chip.h" +#include "common.h" +#include "console.h" +#include "gpio.h" +#include "hooks.h" +#include "i2c.h" +#include "registers.h" +#include "task.h" +#include "usb_pd.h" +#include "util.h" + +void button_event(enum gpio_signal signal) +{ + int mv; + switch (signal) { + case GPIO_SW_PP20000: + mv = 20000; + break; + case GPIO_SW_PP12000: + mv = 12000; + break; + case GPIO_SW_PP5000: + mv = 5000; + break; + default: + mv = -1; + } + pd_request_source_voltage(mv); + ccprintf("Button %d = %d => Vout=%d mV\n", + signal, gpio_get_level(signal), mv); +} + +void vbus_event(enum gpio_signal signal) +{ + ccprintf("VBUS! =%d\n", gpio_get_level(signal)); +} + +void board_config_pre_init(void) +{ + /* enable SYSCFG clock */ + STM32_RCC_APB2ENR |= 1 << 0; + /* Remap USART DMA to match the USART driver */ + /* + * the DMA mapping is : + * Chan 2 : TIM1_CH1 (PD RX) + * Chan 3 : SPI1_TX (PD TX) + * Chan 4 : USART1_TX + * Chan 5 : USART1_RX + */ + STM32_SYSCFG_CFGR1 |= (1 << 9) | (1 << 10);/* Remap USART1 RX/TX DMA */ +} + +/* GPIO signal list. Must match order from enum gpio_signal. */ +const struct gpio_info gpio_list[] = { + {"VBUS_WAKE", GPIO_C, (1<<13), GPIO_INT_BOTH, vbus_event}, + /* Buttons */ + {"SW_PP20000", GPIO_B, (1<<10), GPIO_INT_FALLING, button_event}, + {"SW_PP12000", GPIO_B, (1<<11), GPIO_INT_FALLING, button_event}, + {"SW_PP5000", GPIO_B, (1<<12), GPIO_INT_FALLING, button_event}, + + /* PD RX/TX */ + {"USB_CC1_PD", GPIO_A, (1<<0), GPIO_ANALOG, NULL}, + {"PD_REF1", GPIO_A, (1<<1), GPIO_ANALOG, NULL}, + {"USB_CC2_PD", GPIO_A, (1<<2), GPIO_ANALOG, NULL}, + {"PD_REF2", GPIO_A, (1<<3), GPIO_ANALOG, NULL}, + {"PD_CC1_TX_EN", GPIO_A, (1<<4), GPIO_ODR_HIGH, NULL}, + {"PD_CC2_TX_EN", GPIO_A, (1<<15), GPIO_ODR_HIGH, NULL}, + {"PD_CLK_OUT", GPIO_B, (1<<9), GPIO_OUT_LOW, NULL}, + {"PD_CC1_TX_DATA", GPIO_A, (1<<6), GPIO_INPUT, NULL}, + {"PD_CC2_TX_DATA", GPIO_B, (1<<4), GPIO_INPUT, NULL}, + {"PD_CLK_IN", GPIO_B, (1<<3), GPIO_INPUT, NULL}, + + /* CCx device pull-downs */ + {"PD_CC1_DEVICE", GPIO_B, (1<<13), GPIO_ODR_LOW, NULL}, + {"PD_CC2_DEVICE", GPIO_B, (1<<14), GPIO_ODR_LOW, NULL}, + + /* ADC */ + {"VBUS_SENSE", GPIO_A, (1<<5), GPIO_ANALOG, NULL}, + + /* LEDs control */ + {"LED_PP20000", GPIO_B, (1<<0), GPIO_OUT_LOW, NULL}, + {"LED_PP12000", GPIO_B, (1<<1), GPIO_OUT_LOW, NULL}, + {"LED_PP5000", GPIO_B, (1<<2), GPIO_OUT_LOW, NULL}, + + /* Slave I2C port */ + {"I2C_INT_L", GPIO_B, (1<<8), GPIO_ODR_HIGH, NULL}, + /* + * I2C pins should be configured as inputs until I2C module is + * initialized. This will avoid driving the lines unintentionally. + */ + {"I2C_SCL", GPIO_B, (1<<6), GPIO_INPUT, NULL}, + {"I2C_SDA", GPIO_B, (1<<7), GPIO_INPUT, NULL}, + + /* Test points */ + {"TP_A8", GPIO_A, (1<<8), GPIO_ODR_HIGH, NULL}, + {"TP_A13", GPIO_A, (1<<13), GPIO_ODR_HIGH, NULL}, + {"TP_A14", GPIO_A, (1<<14), GPIO_ODR_HIGH, NULL}, + {"TP_B15", GPIO_B, (1<<15), GPIO_ODR_HIGH, NULL}, + {"TP_C14", GPIO_C, (1<<14), GPIO_ODR_HIGH, NULL}, + {"TP_C15", GPIO_C, (1<<15), GPIO_ODR_HIGH, NULL}, + {"TP_F0", GPIO_F, (1<<0), GPIO_ODR_HIGH, NULL}, + {"TP_F1", GPIO_F, (1<<1), GPIO_ODR_HIGH, NULL}, + + /* Unimplemented signals which we need to emulate for now */ + GPIO_SIGNAL_NOT_IMPLEMENTED("ENTERING_RW"), + GPIO_SIGNAL_NOT_IMPLEMENTED("WP_L"), +}; +BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT); + +/* Pins with alternate functions */ +const struct gpio_alt_func gpio_alt_funcs[] = { + {GPIO_B, 0x0008, 0, MODULE_USB_PD},/* SPI1: SCK(PB3) */ + {GPIO_B, 0x0200, 2, MODULE_USB_PD},/* TIM17_CH1: PB9) */ + {GPIO_A, 0x0600, 1, MODULE_UART, GPIO_PULL_UP},/* USART1: PA9/PA10 */ + {GPIO_B, 0x00c0, 1, MODULE_I2C}, /* I2C SLAVE:PB6/7 */ +}; +const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); + +/* ADC channels */ +const struct adc_t adc_channels[] = { + /* USB PD CC lines sensing. Converted to mV (3300mV/4096). */ + [ADC_CH_CC1_PD] = {"CC1_PD", 3300, 4096, 0, STM32_AIN(0)}, + [ADC_CH_CC2_PD] = {"CC2_PD", 3300, 4096, 0, STM32_AIN(2)}, + /* VBUS voltage sensing is behind a 14.3K/100K voltage divider */ + [ADC_CH_VBUS_SENSE] = {"VBUS", 26377, 4096, 0, STM32_AIN(5)}, +}; +BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); + +/* I2C ports */ +const struct i2c_port_t i2c_ports[] = { +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +static void board_init(void) +{ + gpio_enable_interrupt(GPIO_SW_PP20000); + gpio_enable_interrupt(GPIO_SW_PP12000); + gpio_enable_interrupt(GPIO_SW_PP5000); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + +static int command_volt(int argc, char **argv) +{ + int millivolt = -1; + if (argc >= 2) { + char *e; + millivolt = strtoi(argv[1], &e, 10) * 1000; + } + ccprintf("Request Vout=%d mV\n", millivolt); + pd_request_source_voltage(millivolt); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(volt, command_volt, + "[5|12|20]", + "set voltage through USB PD", + NULL); diff --git a/board/firefly/board.h b/board/firefly/board.h new file mode 100644 index 0000000000..5388ac411b --- /dev/null +++ b/board/firefly/board.h @@ -0,0 +1,110 @@ +/* Copyright (c) 2014 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. + */ + +/* Firefly board configuration */ + +#ifndef __BOARD_H +#define __BOARD_H + +/* 48 MHz SYSCLK clock frequency */ +#define CPU_CLOCK 48000000 + +/* the UART console is on USART1 (PA9/PA10) */ +#define CONFIG_UART_CONSOLE 1 + +/* Optional features */ +#define CONFIG_STM_HWTIMER32 +#define CONFIG_USB_POWER_DELIVERY +#define CONFIG_USB_PD_DUAL_ROLE +#define CONFIG_USB_PD_INTERNAL_COMP +#define CONFIG_ADC +#define CONFIG_HW_CRC +#define CONFIG_I2C +#define CONFIG_BOARD_PRE_INIT +#undef CONFIG_WATCHDOG_HELP +#undef CONFIG_LID_SWITCH +#undef CONFIG_TASK_PROFILING + +/* I2C ports configuration */ +#define I2C_PORT_SLAVE 0 + +/* + * 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 + +/* GPIO signal list */ +enum gpio_signal { + /* Inputs with interrupt handlers are first for efficiency */ + GPIO_VBUS_WAKE = 0, + GPIO_SW_PP20000, + GPIO_SW_PP12000, + GPIO_SW_PP5000, + + /* PD RX/TX */ + GPIO_USB_CC1_PD, + GPIO_PD_REF1, + GPIO_USB_CC2_PD, + GPIO_PD_REF2, + GPIO_PD_CC1_TX_EN, + GPIO_PD_CC2_TX_EN, + GPIO_PD_CLK_OUT, + GPIO_PD_CC1_TX_DATA, + GPIO_PD_CC2_TX_DATA, + GPIO_PD_CLK_IN, + + /* CCx device pull-downs */ + GPIO_PD_CC1_DEVICE, + GPIO_PD_CC2_DEVICE, + + /* ADCs */ + GPIO_VBUS_SENSE, + + /* LEDs control */ + GPIO_LED_PP20000, + GPIO_LED_PP12000, + GPIO_LED_PP5000, + + /* Slave I2C */ + GPIO_I2C_INT_L, + GPIO_I2C_SCL, + GPIO_I2C_SDA, + + /* Test points */ + GPIO_TP_A8, + GPIO_TP_A13, + GPIO_TP_A14, + GPIO_TP_B15, + GPIO_TP_C14, + GPIO_TP_C15, + GPIO_TP_F0, + GPIO_TP_F1, + + /* Unimplemented signals we emulate */ + GPIO_ENTERING_RW, + GPIO_WP_L, + /* Number of GPIOs; not an actual GPIO */ + GPIO_COUNT +}; + +/* ADC signal */ +enum adc_channel { + ADC_CH_CC1_PD = 0, + ADC_CH_CC2_PD, + ADC_CH_VBUS_SENSE, + /* Number of ADC channels */ + ADC_CH_COUNT +}; + +#endif /* !__ASSEMBLER__ */ + +#endif /* __BOARD_H */ diff --git a/board/firefly/build.mk b/board/firefly/build.mk new file mode 100644 index 0000000000..3d6b7a4688 --- /dev/null +++ b/board/firefly/build.mk @@ -0,0 +1,14 @@ +# -*- makefile -*- +# Copyright (c) 2014 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 STM32F072CBU6 +CHIP:=stm32 +CHIP_FAMILY:=stm32f0 +CHIP_VARIANT:=stm32f07x + +board-y=board.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/board/firefly/ec.tasklist b/board/firefly/ec.tasklist new file mode 100644 index 0000000000..e9c8c1cc1f --- /dev/null +++ b/board/firefly/ec.tasklist @@ -0,0 +1,22 @@ +/* Copyright (c) 2014 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) \ + TASK_ALWAYS(PD, pd_task, NULL, TASK_STACK_SIZE) diff --git a/board/firefly/usb_pd_config.h b/board/firefly/usb_pd_config.h new file mode 100644 index 0000000000..b6558bd878 --- /dev/null +++ b/board/firefly/usb_pd_config.h @@ -0,0 +1,103 @@ +/* Copyright (c) 2014 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. + */ + +/* USB Power delivery board configuration */ + +#ifndef __USB_PD_CONFIG_H +#define __USB_PD_CONFIG_H + +/* Timer selection for baseband PD communication */ +#define TIM_CLOCK_PD_TX 17 +#define TIM_CLOCK_PD_RX 1 + +/* use the hardware accelerator for CRC */ +#define CONFIG_HW_CRC + +/* TX is using SPI2 on PB3/PB4 or PA6 */ +#define SPI_REGS STM32_SPI1_REGS +#define DMAC_SPI_TX STM32_DMAC_CH3 + +static inline void spi_enable_clock(void) +{ + STM32_RCC_APB2ENR |= STM32_RCC_PB2_SPI1; +} + +/* RX is using COMP1 triggering TIM1 CH1 */ +#define DMAC_TIM_RX STM32_DMAC_CH2 +#define TIM_CCR_IDX 1 +#define TIM_CCR_CS 1 +#define EXTI_COMP_MASK ((1 << 21) | (1 << 22)) +#define IRQ_COMP STM32_IRQ_COMP +/* triggers packet detection on comparator falling edge */ +#define EXTI_XTSR STM32_EXTI_FTSR + +/* the pins used for communication need to be hi-speed */ +static inline void pd_set_pins_speed(void) +{ + /* 40 MHz pin speed on SPI1 PA4/6/7 */ + STM32_GPIO_OSPEEDR(GPIO_B) |= 0x0000F300; + /* 40 MHz pin speed on SPI1 PB3/4/5 */ + STM32_GPIO_OSPEEDR(GPIO_B) |= 0x00000FC0; + /* 40 MHz pin speed on TIM17_CH1 (PB9) */ + STM32_GPIO_OSPEEDR(GPIO_B) |= 0x000C0000; +} + +/* Drive the CC line from the TX block */ +static inline void pd_tx_enable(int polarity) +{ + /* set the low level reference */ + gpio_set_level(polarity ? GPIO_PD_CC2_TX_EN : GPIO_PD_CC1_TX_EN, 0); + /* put SPI function on TX pin */ + if (polarity) /* PB4 is SPI1 MISO */ + gpio_set_alternate_function(GPIO_B, 0x0010, 0); + else /* PA6 is SPI1 MISO */ + gpio_set_alternate_function(GPIO_A, 0x0040, 0); +} + +/* Put the TX driver in Hi-Z state */ +static inline void pd_tx_disable(int polarity) +{ + /* put SPI TX in Hi-Z */ + if (polarity) + gpio_set_alternate_function(GPIO_B, 0x0010, -1); + else + gpio_set_alternate_function(GPIO_A, 0x0040, -1); + /* put the low level reference in Hi-Z */ + gpio_set_level(polarity ? GPIO_PD_CC2_TX_EN : GPIO_PD_CC1_TX_EN, 1); +} + +/* we know the plug polarity, do the right configuration */ +static inline void pd_select_polarity(int polarity) +{ + /* use the right comparator */ + STM32_COMP_CSR = + (STM32_COMP_CSR & ~(STM32_COMP_CMP1EN | STM32_COMP_CMP2EN)) + | (polarity ? STM32_COMP_CMP2EN : STM32_COMP_CMP1EN); +} + +/* Initialize pins used for TX and put them in Hi-Z */ +static inline void pd_tx_init(void) +{ + /* Configure SCK pin */ + gpio_config_module(MODULE_USB_PD, 1); +} + +static inline void pd_set_host_mode(int enable) +{ +} + +/* Standard-current DFP : no-connect voltage is 1.55V */ +#define PD_SRC_VNC 1550 /* mV */ + +/* UFP-side : threshold for DFP connection detection */ +#define PD_SNK_VA 250 /* mV */ + +/* we are acting only as a sink */ +#define PD_DEFAULT_STATE PD_STATE_SNK_DISCONNECTED + +/* we are never a source : don't care about power supply */ +#define PD_POWER_SUPPLY_TRANSITION_DELAY 0 + +#endif /* __USB_PD_CONFIG_H */ diff --git a/board/firefly/usb_pd_policy.c b/board/firefly/usb_pd_policy.c new file mode 100644 index 0000000000..4a6d9da103 --- /dev/null +++ b/board/firefly/usb_pd_policy.c @@ -0,0 +1,125 @@ +/* Copyright (c) 2014 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 "adc.h" +#include "board.h" +#include "common.h" +#include "console.h" +#include "gpio.h" +#include "hooks.h" +#include "registers.h" +#include "task.h" +#include "timer.h" +#include "util.h" +#include "usb_pd.h" + +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) + +/* Acceptable margin between requested VBUS and measured value */ +#define MARGIN_MV 400 /* mV */ + +/* we are not acting as a source */ +const uint32_t pd_src_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_EXTERNAL), +}; +const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo); + +/* Fake PDOs : we just want our pre-defined voltages */ +const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, 0), + PDO_FIXED(12000, 500, 0), + PDO_FIXED(20000, 500, 0), +}; +const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + +/* Desired voltage requested as a sink (in millivolts) */ +static unsigned select_mv = -1; /* no valid selection */ + +int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo) +{ + int i; + int ma; + int set_mv = select_mv; + + /* Default to 5V */ + if (set_mv <= 0) + set_mv = 5000; + + /* Get the selected voltage */ + for (i = cnt; i >= 0; i--) { + int mv = ((src_caps[i] >> 10) & 0x3FF) * 50; + int type = src_caps[i] & PDO_TYPE_MASK; + if ((mv == set_mv) && (type == PDO_TYPE_FIXED)) + break; + } + if (i < 0) + return -EC_ERROR_UNKNOWN; + + /* request all the power ... */ + ma = 10 * (src_caps[i] & 0x3FF); + *rdo = RDO_FIXED(i + 1, ma, ma, 0); + ccprintf("Request [%d] %d V %d mA\n", i, set_mv/1000, ma); + return EC_SUCCESS; +} + +void pd_set_max_voltage(unsigned mv) +{ + select_mv = mv; +} + +int pd_request_voltage(uint32_t rdo) +{ + /* Never acting as a source */ + return EC_ERROR_INVAL; +} + +int pd_set_power_supply_ready(void) +{ + /* Never acting as a source */ + return EC_ERROR_INVAL; +} + +void pd_power_supply_reset(void) +{ +} + +void pd_board_checks(void) +{ + static int blinking; + int vbus; + int led5 = 0, led12 = 0, led20 = 0; + + /* LED blinking state for the default indicator */ + blinking = (blinking + 1) & 3; + + vbus = adc_read_channel(ADC_CH_VBUS_SENSE); + + if (select_mv > 0) { + /* is current VBUS voltage matching the request ? */ + int diff = vbus - select_mv; + int correct = (diff < MARGIN_MV) && (diff > -MARGIN_MV); + /* + * turn on the LED if the voltage is correct + * or we are in on-period of the duty cycle. + */ + int led_value = correct || !blinking; + /* decide which LED is used */ + switch (select_mv) { + case 5000: + led5 = led_value; + break; + case 12000: + led12 = led_value; + break; + case 20000: + led20 = led_value; + break; + } + } + /* switch LEDs */ + gpio_set_level(GPIO_LED_PP5000, led5); + gpio_set_level(GPIO_LED_PP12000, led12); + gpio_set_level(GPIO_LED_PP20000, led20); +} diff --git a/util/flash_ec b/util/flash_ec index aa33fb82a2..341bef6c5e 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -245,7 +245,7 @@ save="$(servo_save)" case "${BOARD}" in big | blaze | discovery | nyan | pit | snow | spring ) flash_stm32 ;; - fruitpie | zinger) flash_stm32 ;; + fruitpie | zinger | firefly) flash_stm32 ;; falco | peppy | rambi | samus | squawks ) flash_lm4 ;; link ) flash_link ;; *) die "board ${BOARD} not supported" ;; |