From fe38bab96168effcce38090259f265d82e784aa1 Mon Sep 17 00:00:00 2001 From: Rong Chang Date: Sat, 16 Jun 2012 20:22:20 +0800 Subject: Set daisy and snow PB6 PB7 GPIO pinmux to I2C This change enables I2C1 host function. Signed-off-by: Rong Chang BUG=chrome-os-partner:10608,10607,9724 TEST=manual Change I2C_PORT_HOST to 0. Rebuild ec.bin. Swap I2C resistors on the daisy board, connect battery and charger to EC_I2C_HOST. Check I2C functions using uart console commands: i2c r 0x90 4 // read pmu control reg0 i2c r16 0x16 0x14 // read smart battery desired current Connect a battery and check console command 'battery'. Change-Id: Iaa5271e856f410f2d0d2250caf0de6bc5101c1d4 Reviewed-on: https://gerrit.chromium.org/gerrit/25498 Reviewed-by: Vincent Palatin Tested-by: Rong Chang Commit-Ready: Rong Chang --- board/daisy/board.c | 22 ++++++++++++++-------- board/daisy/board.h | 5 +++-- board/snow/board.c | 11 ++++++++--- chip/stm32/i2c.c | 12 ++++++++---- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/board/daisy/board.c b/board/daisy/board.c index de50e06886..1d5a57e66c 100644 --- a/board/daisy/board.c +++ b/board/daisy/board.c @@ -113,15 +113,21 @@ void configure_board(void) STM32_GPIO_OSPEEDR_OFF(GPIO_A) |= 0xff00; /* - * I2C SCL/SDA on PB10-11, bi-directional, no pull-up/down, initialized - * as hi-Z until alt. function is set + * I2C SCL/SDA on PB10-11 and PB6-7, bi-directional, no pull-up/down, + * initialized as hi-Z until alt. function is set */ - STM32_GPIO_PUPDR_OFF(GPIO_B) &= ~((3 << (11*2)) | (3 << (10*2))); - STM32_GPIO_MODER_OFF(GPIO_B) &= ~((3 << (11*2)) | (3 << (10*2))); - STM32_GPIO_MODER_OFF(GPIO_B) |= (1 << (11*2)) | (1 << (10*2)); - STM32_GPIO_OTYPER_OFF(GPIO_B) |= (1<<11) | (1<<10); - STM32_GPIO_BSRR_OFF(GPIO_B) |= (1<<11) | (1<<10); - gpio_set_alternate_function(GPIO_B, (1<<11) | (1<<10), GPIO_ALT_I2C); + STM32_GPIO_PUPDR_OFF(GPIO_B) &= ~((3 << (11*2)) | (3 << (10*2)) | + (3 << (7*2)) | (3 << (6*2))); + STM32_GPIO_MODER_OFF(GPIO_B) &= ~((3 << (11*2)) | (3 << (10*2)) | + (3 << (7*2)) | (3 << (6*2))); + STM32_GPIO_MODER_OFF(GPIO_B) |= (1 << (11*2)) | (1 << (10*2)) | + (1 << (7*2)) | (1 << (6*2)); + STM32_GPIO_OTYPER_OFF(GPIO_B) |= (1<<11) | (1<<10) | (1<<7) | (1<<6); + STM32_GPIO_BSRR_OFF(GPIO_B) |= (1<<11) | (1<<10) | (1<<7) | (1<<6); + gpio_set_alternate_function(GPIO_B, (1<<11) | + (1<<10) | + (1<<7) | + (1<<6), GPIO_ALT_I2C); /* Select Alternate function for USART1 on pins PA9/PA10 */ gpio_set_alternate_function(GPIO_A, (1<<9) | (1<<10), GPIO_ALT_USART); diff --git a/board/daisy/board.h b/board/daisy/board.h index b0a3df0963..e85e0b2dc3 100644 --- a/board/daisy/board.h +++ b/board/daisy/board.h @@ -35,8 +35,9 @@ /* Charging */ #define CONFIG_SMART_BATTERY #define CONFIG_PMU_TPS65090 -#define I2C_PORT_BATTERY 1 -#define I2C_PORT_CHARGER 1 +#define I2C_PORT_HOST 1 +#define I2C_PORT_BATTERY I2C_PORT_HOST +#define I2C_PORT_CHARGER I2C_PORT_HOST /* GPIO signal list */ enum gpio_signal { diff --git a/board/snow/board.c b/board/snow/board.c index 783303cb58..8c97c24790 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -86,13 +86,18 @@ void configure_board(void) STM32_GPIO_CRL_OFF(GPIO_A) = val; /* - * I2C SCL/SDA on PB10-11, bi-directional, no pull-up/down, initialized - * as hi-Z until alt. function is set + * I2C SCL/SDA on PB10-11 and PB6-7, bi-directional, no pull-up/down, + * initialized as hi-Z until alt. function is set */ val = STM32_GPIO_CRH_OFF(GPIO_B) & ~0x0000ff00; val |= 0x0000dd00; STM32_GPIO_CRH_OFF(GPIO_B) = val; - STM32_GPIO_BSRR_OFF(GPIO_B) |= (1<<11) | (1<<10); + + val = STM32_GPIO_CRL_OFF(GPIO_B) & ~0xff000000; + val |= 0xdd000000; + STM32_GPIO_CRL_OFF(GPIO_B) = val; + + STM32_GPIO_BSRR_OFF(GPIO_B) |= (1<<11) | (1<<10) | (1<<7) | (1<<6); /* Select Alternate function for USART1 on pins PA9/PA10 */ val = STM32_GPIO_CRH_OFF(GPIO_A) & ~0x00000ff0; diff --git a/chip/stm32/i2c.c b/chip/stm32/i2c.c index 2b06f6055d..c3fe00af2b 100644 --- a/chip/stm32/i2c.c +++ b/chip/stm32/i2c.c @@ -612,6 +612,8 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data, /*****************************************************************************/ /* Console commands */ +#ifdef I2C_PORT_HOST + static int command_i2c(int argc, char **argv) { int rw = 0; @@ -665,16 +667,16 @@ static int command_i2c(int argc, char **argv) switch (rw) { case 0: - rv = i2c_read8(I2C2, slave_addr, offset, &value); + rv = i2c_read8(I2C_PORT_HOST, slave_addr, offset, &value); break; case 1: - rv = i2c_read16(I2C2, slave_addr, offset, &value); + rv = i2c_read16(I2C_PORT_HOST, slave_addr, offset, &value); break; case 2: - rv = i2c_write8(I2C2, slave_addr, offset, value); + rv = i2c_write8(I2C_PORT_HOST, slave_addr, offset, value); break; case 3: - rv = i2c_write16(I2C2, slave_addr, offset, value); + rv = i2c_write16(I2C_PORT_HOST, slave_addr, offset, value); break; } @@ -698,3 +700,5 @@ DECLARE_CONSOLE_COMMAND(i2c, command_i2c, "Read write i2c", NULL); +#endif /* I2C_PORT_HOST */ + -- cgit v1.2.1