[U-Boot] PATCH 2/8 Multi-adapter multi-bus I2C

Heiko Schocher hs at denx.de
Mon Feb 9 12:45:30 CET 2009


Hello ksi,

ksi at koi8.net wrote:
[...]
> diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
> index ce646fd..f7998e3 100644
> --- a/drivers/i2c/fsl_i2c.c
> +++ b/drivers/i2c/fsl_i2c.c
> @@ -1,4 +1,8 @@
>  /*
> + * Copyright (c) 2009 Sergey Kubushyn <ksi at koi8.net>
> + *
> + * Changes for multibus/multiadapter I2C support.
> + *
>   * Copyright 2006 Freescale Semiconductor, Inc.
>   *
>   * This program is free software; you can redistribute it and/or
> @@ -18,7 +22,7 @@
>  
>  #include <common.h>
>  
> -#ifdef CONFIG_HARD_I2C
> +#ifdef CONFIG_FSL_I2C
>  
>  #include <command.h>
>  #include <i2c.h>		/* Functional interface */
> @@ -31,24 +35,15 @@
>  #define I2C_READ_BIT  1
>  #define I2C_WRITE_BIT 0
>  
> -DECLARE_GLOBAL_DATA_PTR;
> -
> -/* Initialize the bus pointer to whatever one the SPD EEPROM is on.
> - * Default is bus 0.  This is necessary because the DDR initialization
> - * runs from ROM, and we can't switch buses because we can't modify
> - * the global variables.
> - */
> -#ifndef CONFIG_SYS_SPD_BUS_NUM
> -#define CONFIG_SYS_SPD_BUS_NUM 0
> -#endif
> -static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = CONFIG_SYS_SPD_BUS_NUM;
> +#define FSL_NAME(arg)	"fsl_i2c@" MK_NAME(arg)
> +#define MK_NAME(arg)	#arg
>  
> -static unsigned int i2c_bus_speed[2] = {CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SPEED};
> +DECLARE_GLOBAL_DATA_PTR;
>  
>  static const struct fsl_i2c *i2c_dev[2] = {
> -	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET),
> -#ifdef CONFIG_SYS_I2C2_OFFSET
> -	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C2_OFFSET)
> +	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_I2C_OFFSET),
> +#ifdef CONFIG_SYS_FSL_I2C2_OFFSET
> +	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_I2C2_OFFSET)
>  #endif
>  };
>  
> @@ -126,6 +121,8 @@ static const struct {
>  #endif
>  };
>  
> +i2c_adap_t	fsl_i2c_adap[];
> +
>  /**
>   * Set the I2C bus speed for a given I2C device
>   *
> @@ -169,43 +166,29 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c *dev,
>  	return speed;
>  }
>  
> -void
> -i2c_init(int speed, int slaveadd)
> +
> +static void __i2c_init(int adap_no, int speed, int slaveadd)
>  {
> -	struct fsl_i2c *dev;
>  	unsigned int temp;
>  
> -	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
> -
> -	writeb(0, &dev->cr);			/* stop I2C controller */
> +	writeb(0, &i2c_dev[adap_no]->cr);	/* stop I2C controller */
>   

Why do you here substitute a "dev->" with "&i2c_dev[adap_no]"?
Why not dev =  &i2c_dev[adap_no] and you can let the dev-> unchanged.

>  	udelay(5);				/* let it shutdown in peace */
> -	temp = set_i2c_bus_speed(dev, gd->i2c1_clk, speed);
> -	if (gd->flags & GD_FLG_RELOC)
> -		i2c_bus_speed[0] = temp;
> -	writeb(slaveadd << 1, &dev->adr);	/* write slave address */
> -	writeb(0x0, &dev->sr);			/* clear status register */
> -	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
> -
> -#ifdef	CONFIG_SYS_I2C2_OFFSET
> -	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C2_OFFSET);
> -
> -	writeb(0, &dev->cr);			/* stop I2C controller */
> -	udelay(5);				/* let it shutdown in peace */
> -	temp = set_i2c_bus_speed(dev, gd->i2c2_clk, speed);
> -	if (gd->flags & GD_FLG_RELOC)
> -		i2c_bus_speed[1] = temp;
> -	writeb(slaveadd << 1, &dev->adr);	/* write slave address */
> -	writeb(0x0, &dev->sr);			/* clear status register */
> -	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
> -#endif
> +	temp = set_i2c_bus_speed(i2c_dev[adap_no], gd->i2c1_clk, speed);
> +	if (gd->flags & GD_FLG_RELOC) {
> +		fsl_i2c_adap[adap_no].speed = temp;
> +		fsl_i2c_adap[adap_no].slaveaddr = slaveadd;
> +	}
> +	writeb(slaveadd << 1, &i2c_dev[adap_no]->adr);	/* write slave address */
> +	writeb(0x0, &i2c_dev[adap_no]->sr);			/* clear status register */
> +	writeb(I2C_CR_MEN, &i2c_dev[adap_no]->cr);		/* start I2C controller */
>  }
>  
bye
Heiko

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany 



More information about the U-Boot mailing list