Set daisy and snow PB6 PB7 GPIO pinmux to I2C

This change enables I2C1 host function.

Signed-off-by: Rong Chang <rongchang@chromium.org>
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 <vpalatin@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
This commit is contained in:
Rong Chang
2012-06-16 20:22:20 +08:00
committed by Gerrit
parent 4aa13dbef9
commit fe38bab961
4 changed files with 33 additions and 17 deletions

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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 */