From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Schocher Date: Mon, 10 Nov 2014 07:33:06 +0100 Subject: [U-Boot] [RFC PATCH 03/12] dm: i2c: Add a uclass for I2C In-Reply-To: <1413178778-30846-4-git-send-email-sjg@chromium.org> References: <1413178778-30846-1-git-send-email-sjg@chromium.org> <1413178778-30846-4-git-send-email-sjg@chromium.org> Message-ID: <54605C22.7030308@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Simon, Am 13.10.2014 07:39, schrieb Simon Glass: > The uclass implements the same operations as the current I2C framework but > makes some changes to make it fit driver model better: > > - Remove the chip address from API calls > - Remove the address length from API calls > - Remove concept of 'current' I2C bus > - Drop all existing init functions > > Signed-off-by: Simon Glass > --- > > drivers/i2c/Makefile | 1 + > drivers/i2c/i2c-uclass.c | 177 +++++++++++++++++++++++++++++++ > include/config_fallbacks.h | 6 ++ > include/dm/uclass-id.h | 1 + > include/i2c.h | 252 +++++++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 437 insertions(+) > create mode 100644 drivers/i2c/i2c-uclass.c only nitpick ... [...] > diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c > new file mode 100644 > index 0000000..6bdce8c > --- /dev/null > +++ b/drivers/i2c/i2c-uclass.c > @@ -0,0 +1,177 @@ > +/* > + * Copyright (c) 2014 Google, Inc > + * > + * SPDX-License-Identifier: GPL-2.0+ > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +DECLARE_GLOBAL_DATA_PTR; > + > +int i2c_read(struct udevice *dev, uint addr, uint8_t *buffer, int len) > +{ > + struct dm_i2c_chip *chip = dev_get_parentdata(dev); > + struct udevice *bus = dev_get_parent(dev); > + struct dm_i2c_ops *ops = i2c_get_ops(bus); > + > + if (!ops->read) > + return -ENOSYS; > + > + return ops->read(bus, chip->chip_addr, addr, chip->addr_len, buffer, > + len); > +} > + > +int i2c_write(struct udevice *dev, uint addr, const uint8_t *buffer, int len) > +{ > + struct dm_i2c_chip *chip = dev_get_parentdata(dev); > + struct udevice *bus = dev_get_parent(dev); > + struct dm_i2c_ops *ops = i2c_get_ops(bus); > + > + if (!ops->write) > + return -ENOSYS; > + > + return ops->write(bus, chip->chip_addr, addr, chip->addr_len, buffer, > + len); > +} > + > +int i2c_get_chip(struct udevice *bus, uint chip_addr, struct udevice **devp) > +{ > + struct udevice *dev; > + > + for (device_find_first_child(bus, &dev); dev; > + device_find_next_child(&dev)) { > + struct dm_i2c_chip store; > + struct dm_i2c_chip *chip = dev_get_parentdata(dev); > + int ret; > + > + if (!chip) { > + chip = &store; > + i2c_chip_ofdata_to_platdata(gd->fdt_blob, > + dev->of_offset, chip); > + } > + if (chip->chip_addr == chip_addr) { > + ret = device_probe(dev); > + if (ret) > + return ret; > + *devp = dev; > + return 0; > + } > + } > + > + return -ENODEV; > +} > + > +int i2c_probe(struct udevice *bus, uint chip) > +{ > + struct dm_i2c_ops *ops = i2c_get_ops(bus); > + struct udevice *dev; > + int ret; > + > + if (!ops->probe) > + return -ENODEV; > + > + /* First probe that chip */ > + ret = ops->probe(bus, chip); > + if (ret) > + return ret; > + > + /* The cihp was found, see if we have a driver, and probe it */ s/cihp/chip [...] bye, Heiko -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany