[U-Boot] [PATCH v2 1/6] i2c: add slave mode support

Heiko Schocher hs at denx.de
Tue Apr 29 07:30:41 CEST 2014


Hello Andrey,

Am 27.04.2014 03:14, schrieb Andrey Danin:
> Signed-off-by: Andrey Danin<danindrey at mail.ru>
> CC: Stephen Warren<swarren at nvidia.com>
> CC: Marc Dietrich<marvin24 at gmx.de>
> CC: Julian Andres Klode<jak at jak-linux.org>
> CC: ac100 at lists.launchpad.net
> ---
>   drivers/i2c/i2c_core.c |   13 +++++++++++++
>   include/i2c.h          |   30 +++++++++++++++++++++++++++++-
>   2 files changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/i2c_core.c b/drivers/i2c/i2c_core.c
> index 18d6736..105aa0a 100644
> --- a/drivers/i2c/i2c_core.c
> +++ b/drivers/i2c/i2c_core.c
> @@ -395,6 +395,19 @@ void i2c_reg_write(uint8_t addr, uint8_t reg, uint8_t val)
>   	i2c_write(addr, reg, 1,&val, 1);
>   }
>
> +int i2c_slave_io(struct i2c_transaction *trans)
> +{
> +	struct i2c_adapter *cur = I2C_ADAP;
> +
> +	if (!cur->slave_io) {
> +		printf("Error: slave IO is not supported on adap %d\n",
> +		       cur->hwadapnr);
> +		return -1;
> +	}
> +
> +	return cur->slave_io(cur, trans);
> +}
> +
>   void __i2c_init(int speed, int slaveaddr)
>   {
>   	i2c_init_bus(i2c_get_bus_num(), speed, slaveaddr);
> diff --git a/include/i2c.h b/include/i2c.h
> index f93a183..165b919 100644
> --- a/include/i2c.h
> +++ b/include/i2c.h
> @@ -55,6 +55,20 @@
>   #define CONFIG_SYS_SPD_BUS_NUM		0
>   #endif
>
> +struct i2c_transaction {
> +	char rx_buf[34];
> +	int rx_pos;
> +
> +	char tx_buf[34];
> +	int tx_pos;
> +	int tx_size;
> +
> +	unsigned int start_timeout;
> +	unsigned int timeout;
> +
> +	int res;
> +};
> +
>   struct i2c_adapter {
>   	void		(*init)(struct i2c_adapter *adap, int speed,
>   				int slaveaddr);
> @@ -65,6 +79,8 @@ struct i2c_adapter {
>   	int		(*write)(struct i2c_adapter *adap, uint8_t chip,
>   				uint addr, int alen, uint8_t *buffer,
>   				int len);
> +	int		(*slave_io)(struct i2c_adapter *adap,
> +				struct i2c_transaction *trans);
>   	uint		(*set_bus_speed)(struct i2c_adapter *adap,
>   				uint speed);
>   	int		speed;
> @@ -81,12 +97,13 @@ struct i2c_adapter {
>   		.probe		=	_probe, \
>   		.read		=	_read, \
>   		.write		=	_write, \
> +		.slave_io	=	0, \
>   		.set_bus_speed	=	_set_speed, \
>   		.speed		=	_speed, \
>   		.slaveaddr	=	_slaveaddr, \
>   		.init_done	=	0, \
>   		.hwadapnr	=	_hwadapnr, \
> -		.name		=	#_name \
> +		.name		=	#_name, \
>   };
>
>   #define U_BOOT_I2C_ADAP_COMPLETE(_name, _init, _probe, _read, _write, \
> @@ -450,4 +467,15 @@ int i2c_get_bus_num_fdt(int node);
>    * @return 0 if port was reset, -1 if not found
>    */
>   int i2c_reset_port_fdt(const void *blob, int node);
> +
> +/**
> + * Perform I2C transaction with master device.
> + *
> + * @param trans  I2C transaction object
> + * @return 0 if succeeded, -1 if not supported,
> + *         1 if not ready, 2 if operation timed out,
> + *         3 if not our packet, other - unknown error.
> + */
> +int i2c_slave_io(struct i2c_transaction *trans);
> +
>   #endif	/* _I2C_H_ */

Hmm, why you use positiv error codes? Can we use negativ codes here
please? And maybe define somewhere this values as defines? Or can
you use:

include/asm-generic/errno.h

Beside of that, it looks Ok to me.

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