diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-07-25 10:22:12 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-08-01 02:51:14 +0000 |
commit | ddc7145e082099693b60b291ab45230193d99f92 (patch) | |
tree | de20717b736af4bcfc95438a0bcf5873406b8b4a | |
parent | c9832e04f15288ea9d617dba13ba606aa667def5 (diff) | |
download | chrome-ec-ddc7145e082099693b60b291ab45230193d99f92.tar.gz |
ryu: dynamic switch between SPI and I2C sensors configuration
boards version 6 / 7 / 8 have an I2C bus to sensors.
board version 0+ has a SPI bus to sensors
On board v0, enable 3rd SPI port and use it to accel the accelerometer.
BRANCH=smaug
BUG=chrome-os-partner:42304
TEST=Check accel on SPI enabled Ryu board,
on v7 and v0 boards, check closed case debugging and type-C features
Change-Id: Ic8de2bb0f9d8a15f86a2c1ea98ef27613f090b22
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/289960
-rw-r--r-- | board/ryu/board.c | 57 | ||||
-rw-r--r-- | board/ryu/board.h | 9 | ||||
-rw-r--r-- | board/ryu/gpio.inc | 7 |
3 files changed, 52 insertions, 21 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c index c9104a2fe4..fa9cf8967c 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -186,6 +186,7 @@ BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) == /* Initialize board. */ static void board_init(void) { + int i; struct charge_port_info charge_none, charge_vbus; /* Initialize all pericom charge suppliers to 0 */ @@ -235,24 +236,36 @@ static void board_init(void) /* Enable interrupts from BMI160 sensor. */ gpio_enable_interrupt(GPIO_ACC_IRQ1); - /* Enable SPI for BMI160 */ - gpio_config_module(MODULE_SPI_MASTER, 1); + if (board_has_spi_sensors()) { + for (i = MOTIONSENSE_TYPE_ACCEL; + i <= MOTIONSENSE_TYPE_MAG; i++) { + motion_sensors[i].addr = BMI160_SET_SPI_ADDRESS(1); + } + /* SPI sensors: put back the GPIO in its expected state */ + gpio_set_level(GPIO_SPI3_NSS, 1); - /* Set all four SPI3 pins to high speed */ - /* pins C10/C11/C12 */ - STM32_GPIO_OSPEEDR(GPIO_C) |= 0x03f00000; + /* Enable SPI for BMI160 */ + gpio_config_module(MODULE_SPI_MASTER, 1); - /* pin A4 */ - STM32_GPIO_OSPEEDR(GPIO_A) |= 0x00000300; + /* Set all four SPI3 pins to high speed */ + /* pins C10/C11/C12 */ + STM32_GPIO_OSPEEDR(GPIO_C) |= 0x03f00000; - /* Enable clocks to SPI3 module */ - STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI3; + /* pin A4 */ + STM32_GPIO_OSPEEDR(GPIO_A) |= 0x00000300; - /* Reset SPI3 */ - STM32_RCC_APB1RSTR |= STM32_RCC_PB1_SPI3; - STM32_RCC_APB1RSTR &= ~STM32_RCC_PB1_SPI3; + /* Enable clocks to SPI3 module */ + STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI3; - spi_enable(CONFIG_SPI_ACCEL_PORT, 1); + /* Reset SPI3 */ + STM32_RCC_APB1RSTR |= STM32_RCC_PB1_SPI3; + STM32_RCC_APB1RSTR &= ~STM32_RCC_PB1_SPI3; + + spi_enable(CONFIG_SPI_ACCEL_PORT, 1); + CPRINTS("Board using SPI sensors"); + } else { /* I2C sensors on rev v6/7/8 */ + CPRINTS("Board using I2C sensors"); + } } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); @@ -347,7 +360,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, - .addr = 1, + .addr = BMI160_ADDR0, .rot_standard_ref = &accelgyro_standard_ref, .default_config = { .odr = 100000, @@ -364,7 +377,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, - .addr = 1, + .addr = BMI160_ADDR0, .rot_standard_ref = &accelgyro_standard_ref, .default_config = { .odr = 0, @@ -381,7 +394,7 @@ struct motion_sensor_t motion_sensors[] = { .drv = &bmi160_drv, .mutex = &g_mutex, .drv_data = &g_bmi160_data, - .addr = 1, + .addr = BMI160_ADDR0, .rot_standard_ref = &mag_standard_ref, .default_config = { .odr = 0, @@ -570,12 +583,22 @@ int board_get_version(void) gpio_set_flags(GPIO_BOARD_ID0, GPIO_INPUT); gpio_set_flags(GPIO_BOARD_ID1, GPIO_INPUT); ver = id1 * 3 + id0; - CPRINTS("Board ID = %d\n", ver); + CPRINTS("Board ID = %d", ver); } return ver; } +int board_has_spi_sensors(void) +{ + /* + * boards version 6 / 7 / 8 have an I2C bus to sensors. + * board version 0+ has a SPI bus to sensors + */ + int ver = board_get_version(); + return (ver < 6); +} + /****************************************************************************/ /* Host commands */ diff --git a/board/ryu/board.h b/board/ryu/board.h index 1347902b7a..aaee26b661 100644 --- a/board/ryu/board.h +++ b/board/ryu/board.h @@ -95,8 +95,8 @@ #define I2C_PORT_CHARGER I2C_PORT_MASTER #define I2C_PORT_BATTERY I2C_PORT_MASTER #define I2C_PORT_LIGHTBAR I2C_PORT_MASTER +#define I2C_PORT_ACCEL I2C_PORT_MASTER #define I2C_PORT_PERICOM I2C_PORT_MASTER - #define BMM150_I2C_ADDRESS BMM150_ADDR0 /* slave address for host commands */ @@ -170,6 +170,13 @@ #ifndef __ASSEMBLER__ int board_get_version(void); +int board_has_spi_sensors(void); + +/* GPIOs depending on board version */ +#define GPIO_VDDSPI_EN (board_has_spi_sensors() ? GPIO_VDDSPI_EN_0 \ + : GPIO_VDDSPI_EN_OLD) +#define GPIO_USBC_CC_EN (board_has_spi_sensors() ? GPIO_USBC_CC_EN_0 \ + : GPIO_SPI3_NSS) /* Timer selection */ #define TIM_CLOCK32 5 diff --git a/board/ryu/gpio.inc b/board/ryu/gpio.inc index 34569b90b5..e8c670ea18 100644 --- a/board/ryu/gpio.inc +++ b/board/ryu/gpio.inc @@ -31,11 +31,11 @@ GPIO(BTN_VOLU_L, PIN(A, 2), GPIO_INPUT | GPIO_PULL_UP) /* PD RX/TX */ GPIO(USBC_CC1_PD, PIN(A, 1), GPIO_ANALOG) GPIO(USBC_CC2_PD, PIN(A, 3), GPIO_ANALOG) -GPIO(USBC_CC_EN, PIN(E, 7), GPIO_OUT_LOW) +GPIO(USBC_CC_EN_0, PIN(E, 7), GPIO_OUT_LOW) /* on rev v0+ */ GPIO(USBC_CC_TX_DATA, PIN(A, 6), GPIO_OUT_LOW) GPIO(USBC_CC_TX_EN, PIN(D, 7), GPIO_OUT_LOW) -GPIO(SPI3_NSS, PIN(A, 4), GPIO_OUT_HIGH) +GPIO(SPI3_NSS, PIN(A, 4), GPIO_OUT_LOW) /* USB_CC_EN on v6/7/8 */ #if 0 /* Alternate functions */ GPIO(USBC_TX_CLKOUT, PIN(B, 1), GPIO_OUT_LOW) @@ -110,7 +110,8 @@ GPIO(PERICOM_CLK_EN, PIN(C, 15), GPIO_OUT_HIGH) GPIO(USB_PU_EN_L, PIN(C, 2), GPIO_OUT_HIGH) GPIO(PD_DISABLE_DEBUG, PIN(C, 6), GPIO_OUT_LOW) GPIO(SPI_FLASH_NSS, PIN(B, 9), GPIO_INPUT) -GPIO(VDDSPI_EN, PIN(C, 15), GPIO_OUT_LOW) +GPIO(VDDSPI_EN_0, PIN(C, 15), GPIO_OUT_LOW) /* on rev v0+ */ +GPIO(VDDSPI_EN_OLD, PIN(C, 12), GPIO_OUT_LOW) /* on rev v6/7/8 */ GPIO(SH_RESET, PIN(C, 4), GPIO_ODR_HIGH) GPIO(SH_BOOT, PIN(C, 9), GPIO_ODR_HIGH) GPIO(EC_INT_L, PIN(F, 2), GPIO_ODR_HIGH) |