[U-Boot] [PATCH u-boot sunxi 07/12] sunxi: Add i2c support

Heiko Schocher hs at denx.de
Tue Mar 18 08:54:41 CET 2014


Hello Hans,

Am 18.03.2014 00:00, schrieb Hans de Goede:
> From: Henrik Nordstrom<henrik at henriknordstrom.net>
>
> Based linux-sunxi#sunxi commit d854c4de2f57 "arm: Handle .gnu.hash section in
> ldscripts" vs v2014.01.
>
> As well as the following signed-off-by the sunxi branch shows commits to
> the sunxi_i2c.c file by:
>
> Stefan Roese<sr at denx.de>
>
> Signed-off-by: Henrik Nordstrom<henrik at henriknordstrom.net>
> Signed-off-by: Oliver Schinagl<oliver at schinagl.nl>
> Signed-off-by: Hans de Goede<hdegoede at redhat.com>
> ---
>   arch/arm/cpu/armv7/sunxi/board.c      |   6 +
>   arch/arm/include/asm/arch-sunxi/i2c.h | 169 ++++++++++++++++++++++
>   drivers/i2c/Makefile                  |   1 +
>   drivers/i2c/sunxi_i2c.c               | 260 ++++++++++++++++++++++++++++++++++
>   include/configs/sunxi-common.h        |   8 ++
>   5 files changed, 444 insertions(+)
>   create mode 100644 arch/arm/include/asm/arch-sunxi/i2c.h
>   create mode 100644 drivers/i2c/sunxi_i2c.c
>
[...]
> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
> index fa3a875..2a44db4 100644
> --- a/drivers/i2c/Makefile
> +++ b/drivers/i2c/Makefile
> @@ -15,6 +15,7 @@ obj-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o
>   obj-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
>   obj-$(CONFIG_U8500_I2C) += u8500_i2c.o
>   obj-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o
> +obj-$(CONFIG_SUNXI_I2C) += sunxi_i2c.o

please use:

CONFIG_SYS_I2C_SUNXI

>   obj-$(CONFIG_SYS_I2C) += i2c_core.o
>   obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
>   obj-$(CONFIG_SYS_I2C_FTI2C010) += fti2c010.o
> diff --git a/drivers/i2c/sunxi_i2c.c b/drivers/i2c/sunxi_i2c.c
> new file mode 100644
> index 0000000..9a542f6
> --- /dev/null
> +++ b/drivers/i2c/sunxi_i2c.c
> @@ -0,0 +1,260 @@
> +/*
> + * (C) Copyright 2012 Henrik Nordstrom<henrik at henriknordstrom.net>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include<common.h>
> +#include<i2c.h>
> +#include<asm/io.h>
> +#include<asm/arch/clock.h>
> +#include<asm/arch/cpu.h>
> +#include<asm/arch/gpio.h>
> +#include<asm/arch/i2c.h>
> +
> +static struct i2c __attribute__ ((section(".data"))) *i2c_base =
> +	(struct i2c *)0x1c2ac00;

Please no magic numbers, use a define instead.

> +void i2c_init(int speed, int slaveaddr)
[...]
> +int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
> +{
> +	int rc = i2c_do_write(chip, addr, alen, buffer, len);
> +
> +	i2c_stop();
> +
> +	return rc;
> +}

Please update to the new i2c multibus/multiadpater framework

Dummy question, there is another "twi" driver in drivers/i2c

bfin-twi_i2c.c

are they compatible?

> diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
> index fe41b89..1f2bcb5 100644
> --- a/include/configs/sunxi-common.h
> +++ b/include/configs/sunxi-common.h
> @@ -176,6 +176,14 @@
>   #undef CONFIG_CMD_NET
>   #undef CONFIG_CMD_NFS
>
> +/* I2C */
> +#define CONFIG_SPL_I2C_SUPPORT
> +#define CONFIG_SYS_I2C_SPEED		400000
> +#define CONFIG_HARD_I2C

NACK, please use no longer HARD_I2C, switch instead to
CONFIG_SYS_I2C

> +#define CONFIG_SUNXI_I2C
> +#define CONFIG_SYS_I2C_SLAVE		0x7f
> +#define CONFIG_CMD_I2C
> +
>   #ifndef CONFIG_CONS_INDEX
>   #define CONFIG_CONS_INDEX              1       /* UART0 */
>   #endif

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