[U-Boot] [PATCH 2/2] WIP: tegra: i2c: Enable new CONFIG_SYS_I2C framework

Heiko Schocher hs at denx.de
Wed Oct 31 06:53:08 CET 2012


Hello Simon,

On 30.10.2012 18:28, Simon Glass wrote:
> (just for illustration, please don't merge)
>
> This enables CONFIG_SYS_I2C on Tegra, updating existing boards and the Tegra
> i2c driver to support this.
>
> Signed-off-by: Simon Glass<sjg at chromium.org>
> ---
>   drivers/i2c/i2c_core.c      |    3 ++
>   drivers/i2c/tegra_i2c.c     |   64 +++++++++++++++++--------------------------
>   include/configs/seaboard.h  |    4 ++-
>   include/configs/trimslice.h |    4 ++-
>   include/configs/whistler.h  |    4 ++-
>   5 files changed, 37 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/i2c/i2c_core.c b/drivers/i2c/i2c_core.c
> index 5a738d5..44f1297 100644
> --- a/drivers/i2c/i2c_core.c
> +++ b/drivers/i2c/i2c_core.c
> @@ -9,6 +9,9 @@
>   #ifdef CONFIG_SYS_I2C_SOFT
>   extern struct i2c_adapter soft_i2c_adap[];
>   #endif
> +#ifdef CONFIG_TEGRA_I2C
> +extern struct i2c_adapter tegra_i2c_adap[];
> +#endif
>
>   struct i2c_adapter *i2c_adap[CONFIG_SYS_NUM_I2C_ADAPTERS] =
>   			CONFIG_SYS_I2C_ADAPTERS;
> diff --git a/drivers/i2c/tegra_i2c.c b/drivers/i2c/tegra_i2c.c
> index 3e157f4..b92bcf1 100644
> --- a/drivers/i2c/tegra_i2c.c
> +++ b/drivers/i2c/tegra_i2c.c
> @@ -35,8 +35,6 @@
>
>   DECLARE_GLOBAL_DATA_PTR;
>
> -static unsigned int i2c_bus_num;
> -
>   /* Information about i2c controller */
>   struct i2c_bus {
>   	int			id;
> @@ -327,21 +325,11 @@ static struct i2c_bus *tegra_i2c_get_bus(unsigned int bus_num)
>   	return bus;
>   }
>
> -unsigned int i2c_get_bus_speed(void)
> +static unsigned int tegra_i2c_set_bus_speed(unsigned int speed)
>   {
>   	struct i2c_bus *bus;
>
> -	bus = tegra_i2c_get_bus(i2c_bus_num);
> -	if (!bus)
> -		return 0;
> -	return bus->speed;
> -}
> -
> -int i2c_set_bus_speed(unsigned int speed)
> -{
> -	struct i2c_bus *bus;
> -
> -	bus = tegra_i2c_get_bus(i2c_bus_num);
> +	bus = tegra_i2c_get_bus(i2c_get_bus_num());
>   	if (!bus)
>   		return 0;
>   	bus->speed = speed;
> @@ -450,7 +438,7 @@ void i2c_init_board(void)
>   		return;
>   }
>
> -void i2c_init(int speed, int slaveaddr)
> +static void tegra_i2c_init(int speed, int slaveaddr)
>   {
>   	/* This will override the speed selected in the fdt for that port */
>   	debug("i2c_init(speed=%u, slaveaddr=0x%x)\n", speed, slaveaddr);
> @@ -500,7 +488,7 @@ int i2c_read_data(struct i2c_bus *bus, uchar chip, uchar *buffer, int len)
>   }
>
>   /* Probe to see if a chip is present. */
> -int i2c_probe(uchar chip)
> +static int tegra_i2c_probe(uchar chip)
>   {
>   	struct i2c_bus *bus;
>   	int rc;
> @@ -526,7 +514,8 @@ static int i2c_addr_ok(const uint addr, const int alen)
>   }
>
>   /* Read bytes */
> -int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
> +static int tegra_i2c_read(uchar chip, uint addr, int alen, uchar *buffer,
> +			  int len)
>   {
>   	struct i2c_bus *bus;
>   	uint offset;
> @@ -534,7 +523,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
>
>   	debug("i2c_read: chip=0x%x, addr=0x%x, len=0x%x\n",
>   				chip, addr, len);
> -	bus = tegra_i2c_get_bus(i2c_bus_num);
> +	bus = tegra_i2c_get_bus(i2c_get_bus_num());
>   	if (!bus)
>   		return 1;
>   	if (!i2c_addr_ok(addr, alen)) {
> @@ -564,7 +553,8 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
>   }
>
>   /* Write bytes */
> -int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
> +static int tegra_i2c_write(uchar chip, uint addr, int alen, uchar *buffer,
> +			   int len)
>   {
>   	struct i2c_bus *bus;
>   	uint offset;
> @@ -572,7 +562,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
>
>   	debug("i2c_write: chip=0x%x, addr=0x%x, len=0x%x\n",
>   				chip, addr, len);
> -	bus = tegra_i2c_get_bus(i2c_bus_num);
> +	bus = tegra_i2c_get_bus(i2c_get_bus_num());
>   	if (!bus)
>   		return 1;
>   	if (!i2c_addr_ok(addr, alen)) {
> @@ -593,25 +583,6 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
>   	return 0;
>   }
>
> -#if defined(CONFIG_I2C_MULTI_BUS)
> -/*
> - * Functions for multiple I2C bus handling
> - */
> -unsigned int i2c_get_bus_num(void)
> -{
> -	return i2c_bus_num;
> -}
> -
> -int i2c_set_bus_num(unsigned int bus)
> -{
> -	if (bus>= TEGRA_I2C_NUM_CONTROLLERS || !i2c_controllers[bus].inited)
> -		return -1;
> -	i2c_bus_num = bus;
> -
> -	return 0;
> -}
> -#endif
> -
>   int tegra_i2c_get_dvc_bus_num(void)
>   {
>   	int i;
> @@ -625,3 +596,18 @@ int tegra_i2c_get_dvc_bus_num(void)
>
>   	return -1;
>   }
> +
> +struct i2c_adapter tegra_i2c_adap[] = {
> +	{
> +		.init		= tegra_i2c_init,
> +		.probe		= tegra_i2c_probe,
> +		.read		= tegra_i2c_read,
> +		.write		= tegra_i2c_write,
> +		.set_bus_speed	= tegra_i2c_set_bus_speed,
> +		.speed		= 100000,
> +		.slaveaddr	= 0,

speed and slaveaddr always fix?

> +		.name		= "tegra-i2c",
> +		.init_done	= 0,
> +		.hwadapnr	= 0,
> +	}
> +};
> diff --git a/include/configs/seaboard.h b/include/configs/seaboard.h
> index 0727a4c..61aca66 100644
> --- a/include/configs/seaboard.h
> +++ b/include/configs/seaboard.h
> @@ -58,10 +58,12 @@
>   /* I2C */
>   #define CONFIG_TEGRA_I2C
>   #define CONFIG_SYS_I2C_INIT_BOARD
> -#define CONFIG_I2C_MULTI_BUS
>   #define CONFIG_SYS_MAX_I2C_BUS		4
>   #define CONFIG_SYS_I2C_SPEED		100000
>   #define CONFIG_CMD_I2C
> +#define CONFIG_SYS_I2C
> +#define CONFIG_SYS_I2C_ADAPTERS	{&tegra_i2c_adap[0]}
> +#define CONFIG_SYS_NUM_I2C_ADAPTERS	TEGRA_I2C_NUM_CONTROLLERS

TEGRA_I2C_NUM_CONTROLLERS is defined with a value of 4, so we need
4 entries in tegra_i2c_adap[] ...

 > +struct i2c_adapter tegra_i2c_adap[] = {
 > +	{
 > +		.init		= tegra_i2c_init,
 > +		.probe		= tegra_i2c_probe,
 > +		.read		= tegra_i2c_read,
 > +		.write		= tegra_i2c_write,
 > +		.set_bus_speed	= tegra_i2c_set_bus_speed,
 > +		.speed		= 100000,
 > +		.slaveaddr	= 0,
 > +		.name		= "tegra-i2c",
 > +		.init_done	= 0,
 > +		.hwadapnr	= 0,
 > +	},
 > +     {
 > +		.init		= tegra_i2c_init,
 > +		.probe		= tegra_i2c_probe,
 > +		.read		= tegra_i2c_read,
 > +		.write		= tegra_i2c_write,
 > +		.set_bus_speed	= tegra_i2c_set_bus_speed,
 > +		.speed		= 100000,
 > +		.slaveaddr	= 0,

 > +		.name		= "tegra-i2c-2",
 > +		.init_done	= 0,
 > +		.hwadapnr	= 1,
 > +      },
[...]

 > +};

[...]

Just pushed my v2 patches to:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=shortlog;h=refs/heads/multibus_v2_20121030

there I added the fsl driver to the new framework, see:

http://git.denx.de/?p=u-boot/u-boot-i2c.git;a=blobdiff;f=drivers/i2c/fsl_i2c.c;h=aa12d87a94937cf2f850ce74af244543336f7699;hp=3cb232fdd110c44ab391e38252b707a89c565fa2;hb=ec77e97e9750c4e9cde7f2e5c646d7cf5bda6c29;hpb=48cf290f61518a4c26a163c823c570fea3660b66

maybe it helps to look in it for you? But if you agree, I rework your
two patches and add it to my v2 serie (post it to you in provate EMail
for testing) and if tests are OK, post the v2 serie with it?

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