FruitPie board configuration

Add all the pins configuration to use the real FruitPie board
and the USB Power Delivery configuration.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=none
TEST=make BOARD=fruitpie

Change-Id: I8c20118400cb6a2e26b541a9ee2da5b706299fcf
Reviewed-on: https://chromium-review.googlesource.com/189862
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vincent Palatin
2014-03-12 15:38:22 -07:00
committed by chrome-internal-fetch
parent 828c1a384a
commit 6c6276fd45
8 changed files with 455 additions and 16 deletions

View File

@@ -4,24 +4,91 @@
*/
/* Fruitpie 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 "util.h"
void button_event(enum gpio_signal signal)
void rohm_event(enum gpio_signal signal)
{
ccprintf("ROHM!\n");
}
void vbus_event(enum gpio_signal signal)
{
ccprintf("VBUS!\n");
}
void tsu_event(enum gpio_signal signal)
{
ccprintf("TSU!\n");
}
/* GPIO signal list. Must match order from enum gpio_signal. */
const struct gpio_info gpio_list[] = {
/* Inputs with interrupt handlers are first for efficiency */
{"USER_BUTTON", GPIO_A, (1<<0), GPIO_INT_BOTH, button_event},
/* Outputs */
{"LED_BLUE", GPIO_B, (1<<6), GPIO_OUT_LOW, NULL},
{"LED_GREEN", GPIO_B, (1<<7), GPIO_OUT_LOW, NULL},
{"VBUS_WAKE", GPIO_B, (1<<5), GPIO_INT_BOTH, vbus_event},
{"MASTER_I2C_INT_L", GPIO_C, (1<<13), GPIO_INT_FALLING, tsu_event},
/* PD RX/TX */
{"USB_CC1_PD", GPIO_A, (1<<0), GPIO_ANALOG, NULL},
{"PD_REF1", GPIO_A, (1<<1), GPIO_ANALOG, NULL},
{"PD_REF2", GPIO_A, (1<<3), GPIO_ANALOG, NULL},
{"USB_CC2_PD", GPIO_A, (1<<4), GPIO_ANALOG, NULL},
{"PD_CLK_OUT", GPIO_B, (1<<9), GPIO_OUT_LOW, NULL},
{"PD_TX_EN", GPIO_B, (1<<12), GPIO_OUT_LOW, NULL},
#if 0
{"PD_CLK_IN", GPIO_B, (1<<13), GPIO_OUT_LOW, NULL},
{"PD_TX_DATA", GPIO_B, (1<<14), GPIO_OUT_LOW, NULL},
#endif
/* Power and muxes control */
{"PP5000_EN", GPIO_A, (1<<5), GPIO_OUT_HIGH, NULL},
{"CC_HOST", GPIO_A, (1<<6), GPIO_OUT_LOW, NULL},
{"CHARGE_EN_L", GPIO_A, (1<<8), GPIO_OUT_HIGH, NULL},
{"USB_C_5V_EN", GPIO_A, (1<<10), GPIO_OUT_LOW, NULL},
{"VCONN1_EN", GPIO_B, (1<<15), GPIO_OUT_LOW, NULL},
{"VCONN2_EN", GPIO_C, (1<<14), GPIO_OUT_LOW, NULL},
{"SS1_EN_L", GPIO_A, (1<<9), GPIO_OUT_HIGH, NULL},
{"SS2_EN_L", GPIO_B, (1<<4), GPIO_OUT_HIGH, NULL},
{"SS2_USB_MODE_L", GPIO_B, (1<<3), GPIO_OUT_HIGH, NULL},
{"SS1_USB_MODE_L", GPIO_B, (1<<8), GPIO_OUT_HIGH, NULL},
{"DP_MODE", GPIO_C, (1<<15), GPIO_OUT_LOW, NULL},
{"DP_POLARITY_L", GPIO_A, (1<<7), GPIO_OUT_HIGH, NULL},
/* Not used : no host on that bus */
{"SLAVE_I2C_INT_L", GPIO_B, (1<<2), GPIO_ODR_HIGH, NULL},
/* Alternate functions */
#if 0
{"USB_DM", GPIO_A, (1<<11), GPIO_ANALOG, NULL},
{"USB_DP", GPIO_A, (1<<12), GPIO_ANALOG, NULL},
{"UART_TX", GPIO_A, (1<<14), GPIO_OUT_LOW, NULL},
{"UART_RX", GPIO_A, (1<<15), GPIO_OUT_LOW, NULL},
#endif
/*
* I2C pins should be configured as inputs until I2C module is
* initialized. This will avoid driving the lines unintentionally.
*/
{"SLAVE_I2C_SCL", GPIO_B, (1<<6), GPIO_INPUT, NULL},
{"SLAVE_I2C_SDA", GPIO_B, (1<<7), GPIO_INPUT, NULL},
{"MASTER_I2C_SCL", GPIO_B, (1<<10), GPIO_INPUT, NULL},
{"MASTER_I2C_SDA", GPIO_B, (1<<11), GPIO_INPUT, NULL},
/* Rohm BD92104 connections */
{"ALERT_L", GPIO_A, (1<<2), GPIO_INT_FALLING, rohm_event},
{"USBPD_RST", GPIO_B, (1<<0), GPIO_OUT_LOW, NULL},
{"USBPD_FORCE_OTG", GPIO_B, (1<<1), GPIO_OUT_LOW, NULL},
{"USBPD_VIN_EN_L", GPIO_F, (1<<0), GPIO_OUT_HIGH, NULL},
/* Test points */
{"TP9", GPIO_A, (1<<13), GPIO_ODR_HIGH, NULL},
{"TP11", GPIO_F, (1<<1), GPIO_ODR_HIGH, NULL},
/* Unimplemented signals which we need to emulate for now */
GPIO_SIGNAL_NOT_IMPLEMENTED("ENTERING_RW"),
@@ -32,12 +99,102 @@ BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT);
/* Initialize board. */
static void board_init(void)
{
gpio_enable_interrupt(GPIO_USER_BUTTON);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
/* Pins with alternate functions */
const struct gpio_alt_func gpio_alt_funcs[] = {
{GPIO_A, 0xC000, 1, MODULE_UART}, /* USART2: PA14/PA15 */
{GPIO_B, 0x6000, 0, MODULE_USB_PD},/* SPI2: MISO(PB14) SCK(PB13) */
{GPIO_B, 0x0200, 2, MODULE_USB_PD},/* TIM17_CH1: PB9) */
{GPIO_A, 0xC000, 1, MODULE_UART}, /* USART2: PA14/PA15 */
{GPIO_B, 0x0cc0, 1, MODULE_I2C}, /* I2C SLAVE:PB6/7 MASTER:PB10/11 */
};
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(4)},
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
/* 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);
void board_set_usb_mux(enum typec_mux mux)
{
/* reset everything */
gpio_set_level(GPIO_SS1_EN_L, 1);
gpio_set_level(GPIO_SS2_EN_L, 1);
gpio_set_level(GPIO_DP_MODE, 0);
gpio_set_level(GPIO_SS1_USB_MODE_L, 1);
gpio_set_level(GPIO_SS2_USB_MODE_L, 1);
switch (mux) {
case TYPEC_MUX_NONE:
/* everything is already disabled, we can return */
return;
case TYPEC_MUX_USB1:
gpio_set_level(GPIO_SS1_USB_MODE_L, 0);
break;
case TYPEC_MUX_USB2:
gpio_set_level(GPIO_SS2_USB_MODE_L, 0);
break;
case TYPEC_MUX_DP1:
gpio_set_level(GPIO_DP_POLARITY_L, 1);
gpio_set_level(GPIO_DP_MODE, 1);
break;
case TYPEC_MUX_DP2:
gpio_set_level(GPIO_DP_POLARITY_L, 0);
gpio_set_level(GPIO_DP_MODE, 1);
break;
}
gpio_set_level(GPIO_SS1_EN_L, 0);
gpio_set_level(GPIO_SS2_EN_L, 0);
}
static int command_typec(int argc, char **argv)
{
const char * const mux_name[] = {"none", "usb1", "usb2", "dp1", "dp2"};
if (argc < 2) {
/* dump current state */
ccprintf("CC1 %d mV CC2 %d mV\n",
adc_read_channel(ADC_CH_CC1_PD),
adc_read_channel(ADC_CH_CC2_PD));
ccprintf("DP %d Polarity %d\n", gpio_get_level(GPIO_DP_MODE),
!!gpio_get_level(GPIO_DP_POLARITY_L) + 1);
ccprintf("Superspeed %s\n",
gpio_get_level(GPIO_SS1_EN_L) ? "None" :
(gpio_get_level(GPIO_DP_MODE) ? "DP" :
(!gpio_get_level(GPIO_SS1_USB_MODE_L) ? "USB1" : "USB2")
));
return EC_SUCCESS;
}
if (!strcasecmp(argv[1], "mux")) {
enum typec_mux mux = TYPEC_MUX_NONE;
int i;
if (argc < 3)
return EC_ERROR_PARAM2;
for (i = 0; i < ARRAY_SIZE(mux_name); i++)
if (!strcasecmp(argv[2], mux_name[i]))
mux = i;
board_set_usb_mux(mux);
return EC_SUCCESS;
} else {
return EC_ERROR_PARAM1;
}
return EC_ERROR_UNKNOWN;
}
DECLARE_CONSOLE_COMMAND(typec, command_typec,
"[mux none|usb1|usb2|dp1|d2]",
"Control type-C connector",
NULL);

View File

@@ -16,10 +16,33 @@
#define CONFIG_UART_CONSOLE 2
/* 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_BATTERY_SMART
#define CONFIG_USB_SWITCH_TSU6721
#undef CONFIG_WATCHDOG_HELP
#undef CONFIG_LID_SWITCH
#undef CONFIG_TASK_PROFILING
/* I2C ports configuration */
#define I2C_PORT_MASTER 1
#define I2C_PORT_BATTERY I2C_PORT_MASTER
#define I2C_PORT_CHARGER I2C_PORT_MASTER
#define I2C_PORT_SLAVE 0
/* Charger configuration */
#define CONFIG_CHARGER
#undef CONFIG_CHARGER_V1
#define CONFIG_CHARGER_BQ24773
#define CONFIG_CHARGER_SENSE_RESISTOR 5 /* milliOhms */
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 /* milliOhms */
#define CONFIG_CHARGER_INPUT_CURRENT 512 /* mA */
/*
* Allow dangerous commands all the time, since we don't have a write protect
* switch.
@@ -29,16 +52,60 @@
#ifndef __ASSEMBLER__
/* Timer selection */
#define TIM_CLOCK_MSB 3
#define TIM_CLOCK_LSB 15
#define TIM_CLOCK32 2
#define TIM_ADC 3
/* GPIO signal list */
enum gpio_signal {
/* Inputs with interrupt handlers are first for efficiency */
GPIO_USER_BUTTON = 0,
/* Outputs */
GPIO_LED_BLUE,
GPIO_LED_GREEN,
GPIO_VBUS_WAKE = 0,
GPIO_MASTER_I2C_INT_L,
/* PD RX/TX */
GPIO_USB_CC1_PD,
GPIO_PD_REF1,
GPIO_PD_REF2,
GPIO_USB_CC2_PD,
GPIO_PD_CLK_OUT,
GPIO_PD_TX_EN,
#if 0
GPIO_PD_CLK_IN,
GPIO_PD_TX_DATA,
#endif
/* Power and muxes control */
GPIO_PP5000_EN,
GPIO_CC_HOST,
GPIO_CHARGE_EN_L,
GPIO_USB_C_5V_EN,
GPIO_VCONN1_EN,
GPIO_VCONN2_EN,
GPIO_SS1_EN_L,
GPIO_SS2_EN_L,
GPIO_SS2_USB_MODE_L,
GPIO_SS1_USB_MODE_L,
GPIO_DP_MODE,
GPIO_DP_POLARITY_L,
/* Not used : no host on that bus */
GPIO_SLAVE_I2C_INT_L,
/* I2C busses */
GPIO_SLAVE_I2C_SCL,
GPIO_SLAVE_I2C_SDA,
GPIO_MASTER_I2C_SCL,
GPIO_MASTER_I2C_SDA,
/* Rohm BD92104 connections */
GPIO_ALERT_L,
GPIO_USBPD_RST,
GPIO_USBPD_FORCE_OTG,
GPIO_USBPD_VIN_EN_L,
/* Test points */
GPIO_TP9,
GPIO_TP11,
/* Unimplemented signals we emulate */
GPIO_ENTERING_RW,
GPIO_WP_L,
@@ -46,6 +113,23 @@ enum gpio_signal {
GPIO_COUNT
};
/* ADC signal */
enum adc_channel {
ADC_CH_CC1_PD = 0,
ADC_CH_CC2_PD,
/* Number of ADC channels */
ADC_CH_COUNT
};
/* Muxing for the USB type C */
enum typec_mux {
TYPEC_MUX_NONE,
TYPEC_MUX_USB1,
TYPEC_MUX_USB2,
TYPEC_MUX_DP1,
TYPEC_MUX_DP2,
};
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */

View File

@@ -11,3 +11,4 @@ CHIP_FAMILY:=stm32f0
CHIP_VARIANT:=stm32f07x
board-y=board.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o

View File

@@ -18,4 +18,5 @@
*/
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE)
TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(PD, pd_task, NULL, TASK_STACK_SIZE)

View File

@@ -0,0 +1,80 @@
/* 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 PB12-14 */
#define SPI_REGS STM32_SPI2_REGS
#define DMAC_SPI_TX STM32_DMAC_CH7
static inline void spi_enable_clock(void)
{
STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI2;
STM32_SYSCFG_CFGR1 |= 1 << 24; /* Remap SPI2 DMA */
}
/* 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 21
#define IRQ_COMP STM32_IRQ_COMP
/* triggers packet detection on comparator falling edge */
#define EXTI_XTSR STM32_EXTI_FTSR
/* Clock divider for RX edges timings (2.4Mhz counter from 48Mhz clock) */
#define RX_CLOCK_DIV (20 - 1)
/* the pins used for communication need to be hi-speed */
static inline void pd_set_pins_speed(void)
{
/* 40 MHz pin speed on SPI PB12/13/14 */
STM32_GPIO_OSPEEDR(GPIO_B) |= 0x7f000000;
/* 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(void)
{
gpio_set_level(GPIO_PD_TX_EN, 1);
}
/* Put the TX driver in Hi-Z state */
static inline void pd_tx_disable(void)
{
gpio_set_level(GPIO_PD_TX_EN, 0);
}
/* Initialize pins used for TX and put them in Hi-Z */
static inline void pd_tx_init(void)
{
gpio_config_module(MODULE_USB_PD, 1);
}
/* 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 200 /* mV */
/* we are a dev board, wait for the user to tell us what we should do */
#define PD_DEFAULT_STATE PD_STATE_DISABLED
/* delay necessary for the voltage transition on the power supply */
#define PD_POWER_SUPPLY_TRANSITION_DELAY 50000 /* us */
#endif /* __USB_PD_CONFIG_H */

View File

@@ -0,0 +1,114 @@
/* 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 "board.h"
#include "common.h"
#include "console.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)
const uint32_t pd_src_pdo[] = {
PDO_FIXED(5000, 500, PDO_FIXED_EXTERNAL),
PDO_FIXED(5000, 3000, 0),
PDO_FIXED(12000, 3000, 0),
PDO_FIXED(20000, 2000, 0),
};
const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
const uint32_t pd_snk_pdo[] = {
PDO_BATT(4500, 5500, 15000),
PDO_BATT(11500, 12500, 36000),
};
const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
/* Cap on the max voltage requested as a sink (in millivolts) */
static unsigned max_mv = -1; /* no cap */
int pd_choose_voltage(int cnt, uint32_t *src_caps, uint32_t *rdo)
{
int i;
int sel_mv;
int max_uw = 0;
int max_i = -1;
/* Get max power */
for (i = 0; i < cnt; i++) {
int uw;
int mv = ((src_caps[i] >> 10) & 0x3FF) * 50;
if ((src_caps[i] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
uw = 250000 * (src_caps[i] & 0x3FF);
} else {
int ma = (src_caps[i] & 0x3FF) * 10;
uw = ma * mv;
}
if ((uw > max_uw) && (mv <= max_mv)) {
max_i = i;
max_uw = uw;
sel_mv = mv;
}
}
if (max_i < 0)
return -EC_ERROR_UNKNOWN;
/* request all the power ... */
if ((src_caps[max_i] & PDO_TYPE_MASK) == PDO_TYPE_BATTERY) {
int uw = 250000 * (src_caps[i] & 0x3FF);
*rdo = RDO_BATT(max_i + 1, uw/2, uw, 0);
ccprintf("Request [%d] %dV %d/%d mW\n",
max_i, sel_mv/1000, uw/1000, uw/1000);
} else {
int ma = 10 * (src_caps[max_i] & 0x3FF);
*rdo = RDO_FIXED(max_i + 1, ma / 2, ma, 0);
ccprintf("Request [%d] %dV %d/%d mA\n",
max_i, sel_mv/1000, max_i, ma/2, ma);
}
return EC_SUCCESS;
}
void pd_set_max_voltage(unsigned mv)
{
max_mv = mv;
}
int pd_request_voltage(uint32_t rdo)
{
int op_ma = rdo & 0x3FF;
int max_ma = (rdo >> 10) & 0x3FF;
int idx = rdo >> 28;
uint32_t pdo;
uint32_t pdo_ma;
if (!idx || idx > pd_src_pdo_cnt)
return EC_ERROR_INVAL; /* Invalid index */
/* check current ... */
pdo = pd_src_pdo[idx - 1];
pdo_ma = (pdo & 0x3ff);
if (op_ma > pdo_ma)
return EC_ERROR_INVAL; /* too much op current */
if (max_ma > pdo_ma)
return EC_ERROR_INVAL; /* too much max current */
ccprintf("Switch to %d V %d mA (for %d/%d mA)\n",
((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
((rdo >> 10) & 0x3ff) * 10, (rdo & 0x3ff) * 10);
return EC_SUCCESS;
}
int pd_set_power_supply_ready(void)
{
return EC_SUCCESS; /* we are ready */
}
void pd_power_supply_reset(void)
{
}

View File

@@ -40,6 +40,7 @@ enum module_id {
MODULE_TASK,
MODULE_THERMAL,
MODULE_UART,
MODULE_USB_PD,
MODULE_USB_PORT_POWER,
MODULE_USB_SWITCH,
MODULE_VBOOT,

View File

@@ -231,7 +231,7 @@ info "Using EC image : ${IMG}"
EC_UART="$(ec_uart)"
info "EC UART pty : ${EC_UART}"
if dut_control uart_mux 2>/dev/null ; then
if dut_control boot_mode 2>/dev/null ; then
SERVO_TYPE=toad
info "Using a TOAD cable"
fi
@@ -240,6 +240,7 @@ save="$(servo_save)"
case "${BOARD}" in
big | blaze | discovery | nyan | pit | snow | spring ) flash_stm32 ;;
fruitpie ) flash_stm32 ;;
falco | peppy | rambi | samus | squawks ) flash_lm4 ;;
link ) flash_link ;;
*) die "board ${BOARD} not supported" ;;