
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 sjg@chromium.org
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 <common.h> +#include <dm.h> +#include <errno.h> +#include <fdtdec.h> +#include <i2c.h> +#include <dm/device-internal.h> +#include <dm/root.h>
+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