From 910bd284c39cb52eefcd61651a8278b329be5e5a Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 28 Jun 2016 08:45:29 +0200 Subject: [PATCH] i2c: Enable i2c and perform bus clear procedure Help the boot loader and perform a bus clear. U-Boot will try to read the MAC from the EEPROM and barebox has the complex boot state stored in it. In the past we have seen U-boot failing to read from the EEPROM and let's have one place to initialize it. --- board.h | 2 +- davinci.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/board.h b/board.h index d7f896c..84a4bec 100644 --- a/board.h +++ b/board.h @@ -39,7 +39,7 @@ #if defined(board_sysmobts_v2) # define PINMUX0_DEFAULT 0x0000000F -# define PINMUX1_DEFAULT PINMUX1_UART0 | PINMUX1_UART1 +# define PINMUX1_DEFAULT PINMUX1_UART0 | PINMUX1_UART1 | PINMUX1_I2C # define NAND_nWP_GPIO 33 #endif diff --git a/davinci.c b/davinci.c index e7ed279..d3ea368 100644 --- a/davinci.c +++ b/davinci.c @@ -217,6 +217,39 @@ lpsc_tansition(uint8_t module, uint8_t domain, uint8_t state) ; } +static void +i2c_init(void) +{ + int i; + + // Perform a bus clear. That is the best we can do to + // unlock I2C devices that do not have reset signal + SYSTEM->PINMUX[1] &= ~PINMUX1_I2C; + + gpio_direction_in(43); // SCL High + waitloop(450); + gpio_direction_in(44); // SDA High + waitloop(450); + + gpio_direction_out(43, 0); // SCL Low + waitloop(450); + gpio_direction_out(44, 0); // SDA Low + waitloop(450); + + for (i=0; i<9; i++) { + gpio_direction_in(43); // SCL High + waitloop(450); + gpio_direction_out(43, 0); // SCL Low + waitloop(450); + } + + gpio_direction_in(43); // SCL High + waitloop(450); + gpio_direction_in(44); // SDA High + + SYSTEM->PINMUX[1] |= PINMUX1_I2C; +} + static void ivt_init(void) { @@ -716,6 +749,12 @@ davinci_platform_init(char *version, int *nwp_nand) gpio_direction_out(HDD_ENA, 1); #endif + /* Init/Reset I2C */ +#ifdef PINMUX1_DEFAULT + if ((PINMUX1_DEFAULT) & PINMUX1_I2C) + i2c_init(); +#endif + /* IRQ Vector Table Setup */ ivt_init();