From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 03/12] dm: i2c: Add a uclass for I2C
Date: Mon, 10 Nov 2014 07:33:06 +0100 [thread overview]
Message-ID: <54605C22.7030308@denx.de> (raw)
In-Reply-To: <1413178778-30846-4-git-send-email-sjg@chromium.org>
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
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next prev parent reply other threads:[~2014-11-10 6:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 5:39 [U-Boot] [RFC PATCH 0/12] RFC: dm: Add I2C support Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 01/12] dm: core: Allow access to the device's driver_id data Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 02/12] dm: core: Add functions to find parent and OF data Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 03/12] dm: i2c: Add a uclass for I2C Simon Glass
2014-11-10 6:33 ` Heiko Schocher [this message]
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 04/12] dm: i2c: Implement driver model support in the i2c command Simon Glass
2014-11-10 7:01 ` Heiko Schocher
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 05/12] dm: i2c: Add I2C emulation driver for sandbox Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 06/12] dm: i2c: Add a sandbox I2C driver Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 07/12] dm: i2c: Add an I2C EEPROM simulator Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 08/12] dm: i2c: config: Enable I2C for sandbox using driver model Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 09/12] dm: i2c: dts: Add an I2C bus for sandbox Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 10/12] dm: WIP: EEPROM driver Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 11/12] dm: i2c: Add tests for I2C Simon Glass
2014-10-13 5:39 ` [U-Boot] [RFC PATCH 12/12] dm: i2c: tegra: Convert to driver model for I2C for seaboard Simon Glass
2014-10-24 15:03 ` [U-Boot] [RFC PATCH 0/12] RFC: dm: Add I2C support Tom Rini
2014-10-29 7:31 ` Heiko Schocher
2014-11-10 7:16 ` Heiko Schocher
2014-11-11 15:44 ` Simon Glass
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=54605C22.7030308@denx.de \
--to=hs@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox