[U-Boot] [PATCH] OMAP2/3: I2C: Add support for second and third bus

Tom Tom.Rix at windriver.com
Mon Nov 2 16:50:04 CET 2009


Dirk Behme wrote:
> Add support to use second and third I2C bus, too.
> 
> Bus 0 is still the default, but by calling i2c_set_bus_num(1/2) before doing
> I2C accesses, code can switch to bus 1 and 2, too. Don't forget to switch
> back afterwards, then. 
> 
> Signed-off-by: Dirk Behme <dirk.behme at googlemail.com>
> ---
> 
> Based on Hugo Vincent's patch
> 
> http://lists.denx.de/pipermail/u-boot/2009-June/055029.html
> 
> (this patch only contains the multibus support)
> 
> Compile tested with omap2_beagle and omap2420h4_config.
> 
> Boot tested with Zippy (I2C bus 1).
> 
>  drivers/i2c/omap24xx_i2c.c          |  170 +++++++++++++++++++++---------------
>  include/asm-arm/arch-omap24xx/i2c.h |   53 +++++++----
>  include/asm-arm/arch-omap3/i2c.h    |   50 +++++++---
>  3 files changed, 175 insertions(+), 98 deletions(-)
> 
> Index: u-boot-main/drivers/i2c/omap24xx_i2c.c
> ===================================================================
> --- u-boot-main.orig/drivers/i2c/omap24xx_i2c.c
> +++ u-boot-main/drivers/i2c/omap24xx_i2c.c
> @@ -29,6 +29,15 @@ static void wait_for_bb (void);
>  static u16 wait_for_pin (void);
>  static void flush_fifo(void);
>  
> +static struct i2c *i2c_base = (struct i2c *)I2C_DEFAULT_BASE;
> +
> +static unsigned int bus_initialized[I2C_BUS_MAX] = {0,
> +#if I2C_BUS_MAX==3
> +						    0,
> +#endif
> +						    0};
> +static unsigned int current_bus = 0;
> +

You can save this if-def if you do not initialize.
Since this is a static, it is not necessary if initializing with 0's

<snip>
>  void i2c_init (int speed, int slaveadd)
>  {
>  	int psc, fsscll, fssclh;

> --- u-boot-main.orig/include/asm-arm/arch-omap3/i2c.h
> +++ u-boot-main/include/asm-arm/arch-omap3/i2c.h
> @@ -25,21 +25,39 @@
>  
>  #define I2C_DEFAULT_BASE	I2C_BASE1
>  
> -#define I2C_REV		(I2C_DEFAULT_BASE + 0x00)
> -#define I2C_IE 		(I2C_DEFAULT_BASE + 0x04)
> -#define I2C_STAT	(I2C_DEFAULT_BASE + 0x08)
> -#define I2C_IV 		(I2C_DEFAULT_BASE + 0x0c)
> -#define I2C_BUF		(I2C_DEFAULT_BASE + 0x14)
> -#define I2C_CNT		(I2C_DEFAULT_BASE + 0x18)
> -#define I2C_DATA	(I2C_DEFAULT_BASE + 0x1c)
> -#define I2C_SYSC	(I2C_DEFAULT_BASE + 0x20)
> -#define I2C_CON		(I2C_DEFAULT_BASE + 0x24)
> -#define I2C_OA 		(I2C_DEFAULT_BASE + 0x28)
> -#define I2C_SA 		(I2C_DEFAULT_BASE + 0x2c)
> -#define I2C_PSC		(I2C_DEFAULT_BASE + 0x30)
> -#define I2C_SCLL	(I2C_DEFAULT_BASE + 0x34)
> -#define I2C_SCLH	(I2C_DEFAULT_BASE + 0x38)
> -#define I2C_SYSTEST	(I2C_DEFAULT_BASE + 0x3c)
> +struct i2c {
> +	unsigned short rev;	/* 0x00 */
> +	unsigned short res1;
> +	unsigned short ie;	/* 0x04 */
> +	unsigned short res2;
> +	unsigned short stat;	/* 0x08 */
> +	unsigned short res3;
> +	unsigned short iv;	/* 0x0C */
> +	unsigned short res4[3];
> +	unsigned short buf;	/* 0x14 */
> +	unsigned short res5;
> +	unsigned short cnt;	/* 0x18 */
> +	unsigned short res6;
> +	unsigned short data;	/* 0x1C */
> +	unsigned short res7;
> +	unsigned short sysc;	/* 0x20 */
> +	unsigned short res8;
> +	unsigned short con;	/* 0x24 */
> +	unsigned short res9;
> +	unsigned short oa;	/* 0x28 */
> +	unsigned short res10;
> +	unsigned short sa;	/* 0x2C */
> +	unsigned short res11;
> +	unsigned short psc;	/* 0x30 */
> +	unsigned short res12;
> +	unsigned short scll;	/* 0x34 */
> +	unsigned short res13;
> +	unsigned short sclh;	/* 0x38 */
> +	unsigned short res14;
> +	unsigned short systest;	/* 0x3c */

Please add a short to the end.
So the sizeof struct i2c will be divisible by 4.

Same for omap2.

Tom



More information about the U-Boot mailing list