All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 1/2] eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS
Date: Tue, 23 Apr 2019 21:59:32 +0200	[thread overview]
Message-ID: <20190423215932.314c9544@jawa> (raw)
In-Reply-To: <20190423191814.24718-1-simon.k.r.goldschmidt@gmail.com>

Hi Simon,

> The current device model enabled eeprom code only works if
> CONFIG_SYS_I2C_EEPROM_BUS is set.
> 
> This patch makes it work without that define so that the bus
> number passed to 'eeprom_init' is used.

Reviewed-by: Lukasz Majewski <lukma@denx.de>

> 
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> Reviewed-by: Heiko Schocher <hs@denx.de>
> ---
> 
> Changes in v3:
> - use eeprom_init() to set CONFIG_SYS_I2C_EEPROM_BUS, not
>   i2c_set_bus_num to make things work with CONFIG_DM_I2C
> 
> Changes in v2: None
> 
>  cmd/eeprom.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/cmd/eeprom.c b/cmd/eeprom.c
> index 6c29b33ba3..7b1f81477f 100644
> --- a/cmd/eeprom.c
> +++ b/cmd/eeprom.c
> @@ -59,6 +59,10 @@
>  #endif
>  #endif
>  
> +#if defined(CONFIG_DM_I2C)
> +int eeprom_i2c_bus;
> +#endif
> +
>  __weak int eeprom_write_enable(unsigned dev_addr, int state)
>  {
>  	return 0;
> @@ -67,7 +71,9 @@ __weak int eeprom_write_enable(unsigned dev_addr,
> int state) void eeprom_init(int bus)
>  {
>  	/* I2C EEPROM */
> -#if defined(CONFIG_SYS_I2C)
> +#if defined(CONFIG_DM_I2C)
> +	eeprom_i2c_bus = bus;
> +#elif defined(CONFIG_SYS_I2C)
>  	if (bus >= 0)
>  		i2c_set_bus_num(bus);
>  	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
> @@ -124,14 +130,14 @@ static int eeprom_rw_block(unsigned offset,
> uchar *addr, unsigned alen, {
>  	int ret = 0;
>  
> -#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
> +#if defined(CONFIG_DM_I2C)
>  	struct udevice *dev;
>  
> -	ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS,
> addr[0],
> +	ret = i2c_get_chip_for_busnum(eeprom_i2c_bus, addr[0],
>  				      alen - 1, &dev);
>  	if (ret) {
>  		printf("%s: Cannot find udev for a bus %d\n",
> __func__,
> -		       CONFIG_SYS_I2C_EEPROM_BUS);
> +		       eeprom_i2c_bus);
>  		return CMD_RET_FAILURE;
>  	}
>  
> @@ -141,15 +147,12 @@ static int eeprom_rw_block(unsigned offset,
> uchar *addr, unsigned alen, ret = dm_i2c_write(dev, offset, buffer,
> len); 
>  #else /* Non DM I2C support - will be removed */
> -#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
> -	i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
> -#endif
>  
>  	if (read)
>  		ret = i2c_read(addr[0], offset, alen - 1, buffer,
> len); else
>  		ret = i2c_write(addr[0], offset, alen - 1, buffer,
> len); -#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */
> +#endif /* CONFIG_DM_I2C */
>  	if (ret)
>  		ret = CMD_RET_FAILURE;
>  
> @@ -164,6 +167,10 @@ static int eeprom_rw(unsigned dev_addr, unsigned
> offset, uchar *buffer, int rcode = 0;
>  	uchar addr[3];
>  
> +#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
> +	eeprom_init(CONFIG_SYS_I2C_EEPROM_BUS);
> +#endif
> +
>  	while (offset < end) {
>  		alen = eeprom_addr(dev_addr, offset, addr);
>  




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190423/5a8676a2/attachment.sig>

  parent reply	other threads:[~2019-04-23 19:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 19:18 [U-Boot] [PATCH v3 1/2] eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS Simon Goldschmidt
2019-04-23 19:18 ` [U-Boot] [PATCH v3 2/2] Revert "cmd: Kconfig: Do not include EEPROM if DM_I2C is used without DM_I2C_COMPAT" Simon Goldschmidt
2019-04-23 19:59 ` Lukasz Majewski [this message]
2019-04-24 17:51 ` [U-Boot] [PATCH v3 1/2] eeprom: fix DM_I2C support without CONFIG_SYS_I2C_EEPROM_BUS Simon Goldschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190423215932.314c9544@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.