diff mbox

[U-Boot,v4,1/4] dm: i2c: dts: Support an offset-len device tree property

Message ID 1422329380-3408-2-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Jan. 27, 2015, 3:29 a.m. UTC
Since U-Boot can support different offset lengths (0-4 bytes), add a device
tree property to specify this. This avoids hard-coding it in the driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v4: None

 doc/device-tree-bindings/i2c/i2c.txt | 28 ++++++++++++++++++++++++++++
 drivers/i2c/i2c-uclass.c             |  3 ++-
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 doc/device-tree-bindings/i2c/i2c.txt

Comments

Simon Glass Jan. 29, 2015, 5:35 p.m. UTC | #1
On 26 January 2015 at 20:29, Simon Glass <sjg@chromium.org> wrote:
> Since U-Boot can support different offset lengths (0-4 bytes), add a device
> tree property to specify this. This avoids hard-coding it in the driver.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v4: None
>
>  doc/device-tree-bindings/i2c/i2c.txt | 28 ++++++++++++++++++++++++++++
>  drivers/i2c/i2c-uclass.c             |  3 ++-
>  2 files changed, 30 insertions(+), 1 deletion(-)
>  create mode 100644 doc/device-tree-bindings/i2c/i2c.txt

Applied to u-boot-dm.
diff mbox

Patch

diff --git a/doc/device-tree-bindings/i2c/i2c.txt b/doc/device-tree-bindings/i2c/i2c.txt
new file mode 100644
index 0000000..ea918dd
--- /dev/null
+++ b/doc/device-tree-bindings/i2c/i2c.txt
@@ -0,0 +1,28 @@ 
+U-Boot I2C
+----------
+
+U-Boot's I2C model has the concept of an offset within a chip (I2C target
+device). The offset can be up to 4 bytes long, but is normally 1 byte,
+meaning that offsets from 0 to 255 are supported by the chip. This often
+corresponds to register numbers.
+
+Apart from the controller-specific I2C bindings, U-Boot supports a special
+property which allows the chip offset length to be selected.
+
+Optional properties:
+- u-boot,i2c-offset-len - length of chip offset in bytes. If omitted the
+    default value of 1 is used.
+
+
+Example
+-------
+
+i2c4: i2c@12ca0000 {
+	cros-ec@1e {
+		reg = <0x1e>;
+		compatible = "google,cros-ec";
+		i2c-max-frequency = <100000>;
+		u-boot,i2c-offset-len = <0>;
+		ec-interrupt = <&gpx1 6 GPIO_ACTIVE_LOW>;
+	};
+};
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index 393cd6f..eafa457 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -420,7 +420,8 @@  int i2c_deblock(struct udevice *bus)
 int i2c_chip_ofdata_to_platdata(const void *blob, int node,
 				struct dm_i2c_chip *chip)
 {
-	chip->offset_len = 1;	/* default */
+	chip->offset_len = fdtdec_get_int(gd->fdt_blob, node,
+					  "u-boot,i2c-offset-len", 1);
 	chip->flags = 0;
 	chip->chip_addr = fdtdec_get_int(gd->fdt_blob, node, "reg", -1);
 	if (chip->chip_addr == -1) {