[U-Boot] [PATCH 1/2] i2c:soft:multi: Support for multiple soft I2C buses

Heiko Schocher
2012-08-28T09:00:55Z

Hello Lukasz,

On 28.08.2012 10:33, Lukasz Majewski wrote:
> Support for multiple soft I2C buses at soft_i2c.c
>
> This approach defines get_multi_{sda|scl}_pin functions to switch
> between multiple "soft" I2C buses.
>
> Up to CONFIG_SYS_MAX_I2C_BUS devices can be utilized.
> Common definition of I2C_X I2C buses is provided.
>
> TEST HW:
> Samsung's Exynos4210 evt.0.1 - Trats development board
>
> Signed-off-by: Lukasz Majewski<l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park<kyungmin.park@samsung.com>
> ---
> drivers/i2c/soft_i2c.c | 41 +++++++++++++++++++++++++++++++++++++++++
> include/i2c.h | 17 +++++++++++++++++
> 2 files changed, 58 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/i2c/soft_i2c.c b/drivers/i2c/soft_i2c.c
> index 36c6114..7901f04 100644
> --- a/drivers/i2c/soft_i2c.c
> +++ b/drivers/i2c/soft_i2c.c
> @@ -127,6 +127,15 @@ DECLARE_GLOBAL_DATA_PTR;
>
> #if defined(CONFIG_I2C_MULTI_BUS)
> static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = 0;
> +const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS] = {
> + NULL,
> + NULL,
> + NULL,
> + NULL,
> + "soft_i2c_4",
> + "soft_i2c_5",
> + NULL,
> +};

For what do you need "soft_i2c_name"? I see no usage of this in your patchset?
Also why the "NULL" for 0-3 and 6 positions?

And what is, if CONFIG_SYS_MAX_I2C_BUS is < 7 ?

> #endif /* CONFIG_I2C_MULTI_BUS */
>
> /*-----------------------------------------------------------------------
> @@ -482,3 +491,35 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
> send_stop();
> return(failures);
> }
> +
> +#if defined(CONFIG_I2C_MULTI_BUS)
> +/* Handle multiple I2C buses instances */
> +int get_multi_scl_pin(void)
> +{
> + switch (I2C_GET_BUS()) {
> + case I2C_4:
> + return CONFIG_SOFT_I2C_I2C4_SCL;
> + case I2C_5:
> + return CONFIG_SOFT_I2C_I2C5_SCL;
> + };
> +
> + return 0;
> +}
> +
> +int get_multi_sda_pin(void)
> +{
> + switch (I2C_GET_BUS()) {
> + case I2C_4:
> + return CONFIG_SOFT_I2C_I2C4_SDA;
> + case I2C_5:
> + return CONFIG_SOFT_I2C_I2C5_SDA;
> + };
> +
> + return 0;
> +}
> +
> +int multi_i2c_init(void)
> +{
> + return 0;
> +}
> +#endif /* CONFIG_I2C_MULTI_BUS */

Again, what is with busnr = 0-3 or 6?

This is not needed in the i2c soft file. You can define this functions
board specific ... so, no change in the driver is needed ... please
move this to board specific code.

> diff --git a/include/i2c.h b/include/i2c.h
> index 1f35acf..d563d62 100644
> --- a/include/i2c.h
> +++ b/include/i2c.h
> @@ -250,4 +250,21 @@ static inline void I2C_SET_BUS(unsigned int bus)
> i2c_set_bus_num(bus);
> }
>
> +/* Multi I2C busses handling */
> +#if (defined(CONFIG_SOFT_I2C)&& defined(CONFIG_I2C_MULTI_BUS))
> +enum {
> + I2C_0,
> + I2C_1,
> + I2C_2,
> + I2C_3,
> + I2C_4,
> + I2C_5,
> + I2C_6
> +};
> +
> +extern const char *soft_i2c_name[CONFIG_SYS_MAX_I2C_BUS];
> +extern int get_multi_scl_pin(void);
> +extern int get_multi_sda_pin(void);
> +extern int multi_i2c_init(void);
> +#endif
> #endif /* _I2C_H_ */

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