[U-Boot] [PATCH v3 08/10] dm: Add a simple EEPROM driver

Masahiro Yamada yamada.m at jp.panasonic.com
Mon Dec 1 12:48:35 CET 2014


Hi Simon,





On Mon, 24 Nov 2014 11:57:22 -0700
Simon Glass <sjg at chromium.org> wrote:

> --- /dev/null
> +++ b/drivers/misc/i2c_eeprom.c
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright (c) 2014 Google, Inc
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <i2c.h>
> +#include <i2c_eeprom.h>
> +
> +static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
> +			   int size)
> +{
> +	return -ENODEV;
> +}
> +
> +static int i2c_eeprom_write(struct udevice *dev, int offset,
> +			    const uint8_t *buf, int size)
> +{
> +	return -ENODEV;
> +}


Isn't there any possibility to reach i2c_eeprom_read/i2c_eeprom_write
handler?

Maybe, is it better to fallback to i2c_read()/i2c_write() like this?


static int i2c_eeprom_read(struct udevice *dev, int offset, uint8_t *buf,
			   int size)
{
	return i2c_read(dev, offset, buf, size);
}

static int i2c_eeprom_write(struct udevice *dev, int offset, const uint8_t *buf,
			   int size)
{
	return i2c_write(dev, offset, buf, size);
}



Moreover, can we read data from EEPROM
without knowing if its parent is I2C bus or SPI bus ?


My rough image is like this:

int eeprom_read(struct udevice *dev, int offset, uint8_t buf, int size)
{
	struct udevice *bus = dev->parent;
	struct generic_bus_operation *ops = bus->uclass->uc_drv->ops;

	return ops->read(dev, bus, offset, buf, size);
}

I am not sure, but if this approach is possible,
we do not need to have both of "i2c_eeprom uclass" and "spi_eeprom uclass".

struct generic_bus_operation is the operaton some uclasses have.

We can move i2c_read() and i2c_write()
to struct generic_bus_operation of i2c uclass.

Likewise, we can move spi_read() and spi_write()
to struct generic_bus_operation of spi uclass.




Best Regards
Masahiro Yamada



More information about the U-Boot mailing list