mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff
@ 2014-06-23 21:21 Antony Pavlov
  2014-06-23 21:21 ` [PATCH 1/7] gpio: add Malta CBUS FPGA I2C driver Antony Pavlov
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Antony Pavlov (7):
  gpio: add Malta CBUS FPGA I2C driver
  MIPS: add <asm/gpio.h> header file
  MIPS: malta: enable gpiolib
  MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver
  i2c: i2c_gpio: add devicetree support
  MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C
    bus
  MIPS: qemu-malta_defconfig: enable gpio & i2c stuff

 .../devicetree/bindings/gpio/gpio_i2c.txt          |  32 ++++
 arch/mips/Kconfig                                  |   1 +
 arch/mips/configs/qemu-malta_defconfig             |  60 +++----
 arch/mips/dts/qemu-malta.dts                       |  23 +++
 arch/mips/include/asm/gpio.h                       |   6 +
 drivers/gpio/Kconfig                               |  10 ++
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-malta-fpga-i2c.c                 | 186 +++++++++++++++++++++
 drivers/i2c/busses/i2c-gpio.c                      |  54 +++++-
 include/of_gpio.h                                  |  55 ++++++
 10 files changed, 397 insertions(+), 31 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio_i2c.txt
 create mode 100644 arch/mips/include/asm/gpio.h
 create mode 100644 drivers/gpio/gpio-malta-fpga-i2c.c

-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/7] gpio: add Malta CBUS FPGA I2C driver
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-23 21:21 ` [PATCH 2/7] MIPS: add <asm/gpio.h> header file Antony Pavlov
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

This driver provides common support for accessing
the CBUS FPGA I2C lines through the gpio library.

Additional i2c bitbang driver must be enabled
in order to use the functionality of the i2c controller.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/gpio/Kconfig               |  10 ++
 drivers/gpio/Makefile              |   1 +
 drivers/gpio/gpio-malta-fpga-i2c.c | 186 +++++++++++++++++++++++++++++++++++++
 3 files changed, 197 insertions(+)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7302955..45b8c53 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -37,6 +37,16 @@ config GPIO_GENERIC_PLATFORM
 config GPIO_IMX
 	def_bool ARCH_IMX
 
+config GPIO_MALTA_FPGA_I2C
+	bool "Malta CBUS FPGA I2C GPIO"
+	depends on MACH_MIPS_MALTA
+	help
+	  Support access to the CBUS FPGA I2C lines through the gpio library.
+
+	  This driver provides common support for accessing the device,
+	  additional drivers must be enabled in order to use the
+	  functionality of the device.
+
 config GPIO_OMAP
 	def_bool ARCH_OMAP
 
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 68a76a3..add6ffc 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_GPIO_DAVINCI)	+= gpio-davinci.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
 obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 obj-$(CONFIG_GPIO_IMX)		+= gpio-imx.o
+obj-$(CONFIG_GPIO_MALTA_FPGA_I2C) += gpio-malta-fpga-i2c.o
 obj-$(CONFIG_GPIO_ORION)	+= gpio-orion.o
 obj-$(CONFIG_GPIO_OMAP)		+= gpio-omap.o
 obj-$(CONFIG_GPIO_PL061)	+= gpio-pl061.o
diff --git a/drivers/gpio/gpio-malta-fpga-i2c.c b/drivers/gpio/gpio-malta-fpga-i2c.c
new file mode 100644
index 0000000..d6995aa
--- /dev/null
+++ b/drivers/gpio/gpio-malta-fpga-i2c.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2014 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <gpio.h>
+#include <linux/err.h>
+#include <malloc.h>
+
+struct malta_i2c_gpio {
+	void __iomem *base;
+	struct gpio_chip chip;
+};
+
+#define MALTA_I2CINP 0
+#define MALTA_I2COE  0x8
+#define MALTA_I2COUT 0x10
+#define MALTA_I2CSEL 0x18
+
+static inline struct malta_i2c_gpio *chip_to_malta_i2c_gpio(struct gpio_chip *c)
+{
+	return container_of(c, struct malta_i2c_gpio, chip);
+}
+
+static inline void malta_i2c_gpio_write(struct malta_i2c_gpio *sc,
+					u32 v, int reg)
+{
+	__raw_writel(v, sc->base + reg);
+}
+
+static inline u32 malta_i2c_gpio_read(struct malta_i2c_gpio *sc, int reg)
+{
+	return __raw_readl(sc->base + reg);
+}
+
+static inline int malta_i2c_gpio_get_bit(struct malta_i2c_gpio *sc,
+						int reg, int bit)
+{
+	return !!(malta_i2c_gpio_read(sc, reg) & BIT(bit));
+}
+
+static inline void malta_i2c_gpio_set_bit(struct malta_i2c_gpio *sc,
+						int reg, int bit, int v)
+{
+	u32 t;
+
+	t = malta_i2c_gpio_read(sc, reg);
+	if (v)
+		t |= BIT(bit);
+	else
+		t &= ~BIT(bit);
+
+	malta_i2c_gpio_write(sc, t, reg);
+}
+
+static int malta_i2c_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
+{
+	struct malta_i2c_gpio *sc = chip_to_malta_i2c_gpio(chip);
+
+	malta_i2c_gpio_set_bit(sc, MALTA_I2COE, gpio, 0);
+
+	return 0;
+}
+
+static int malta_i2c_gpio_direction_output(struct gpio_chip *chip,
+					unsigned gpio, int v)
+{
+	struct malta_i2c_gpio *sc = chip_to_malta_i2c_gpio(chip);
+
+	malta_i2c_gpio_set_bit(sc, MALTA_I2COUT, gpio, v);
+	malta_i2c_gpio_set_bit(sc, MALTA_I2COE, gpio, 1);
+
+	return 0;
+}
+
+static int malta_i2c_gpio_get_direction(struct gpio_chip *chip, unsigned gpio)
+{
+	struct malta_i2c_gpio *sc = chip_to_malta_i2c_gpio(chip);
+
+	if (malta_i2c_gpio_get_bit(sc, MALTA_I2COE, gpio))
+		return GPIOF_DIR_OUT;
+
+	return GPIOF_DIR_IN;
+}
+
+static int malta_i2c_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{
+	struct malta_i2c_gpio *sc = chip_to_malta_i2c_gpio(chip);
+	int v;
+
+	v = malta_i2c_gpio_get_bit(sc, MALTA_I2CINP, gpio);
+
+	pr_debug("%s: gpio_chip=%p gpio=%d value=%d\n",
+			__func__, chip, gpio, v);
+
+	return v;
+}
+
+static void malta_i2c_gpio_set_value(struct gpio_chip *chip,
+					unsigned gpio, int v)
+{
+	struct malta_i2c_gpio *sc = chip_to_malta_i2c_gpio(chip);
+
+	pr_debug("%s: gpio_chip=%p gpio=%d value=%d\n",
+			__func__, chip, gpio, v);
+
+	malta_i2c_gpio_set_bit(sc, MALTA_I2COUT, gpio, v);
+}
+
+static struct gpio_ops malta_i2c_gpio_ops = {
+	.direction_input = malta_i2c_gpio_direction_input,
+	.direction_output = malta_i2c_gpio_direction_output,
+	.get_direction = malta_i2c_gpio_get_direction,
+	.get = malta_i2c_gpio_get_value,
+	.set = malta_i2c_gpio_set_value,
+};
+
+static int malta_i2c_gpio_probe(struct device_d *dev)
+{
+	void __iomem *gpio_base;
+	struct malta_i2c_gpio *sc;
+	int ret;
+
+	gpio_base = dev_request_mem_region(dev, 0);
+	if (!gpio_base) {
+		dev_err(dev, "could not get memory region\n");
+		return -ENODEV;
+	}
+
+	sc = xzalloc(sizeof(*sc));
+	sc->base = gpio_base;
+	sc->chip.ops = &malta_i2c_gpio_ops;
+	sc->chip.base = -1;
+	sc->chip.ngpio = 2;
+	sc->chip.dev = dev;
+
+	ret = gpiochip_add(&sc->chip);
+	if (ret) {
+		dev_err(dev, "couldn't add gpiochip\n");
+		free(sc);
+		return ret;
+	}
+
+	malta_i2c_gpio_write(sc, 1, MALTA_I2CSEL);
+
+	dev_info(dev, "probed gpiochip%d with base %d\n",
+		dev->id, sc->chip.base);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id malta_i2c_gpio_dt_ids[] = {
+	{
+		.compatible = "mti,malta-fpga-i2c-gpio",
+	}, {
+		/* sentinel */
+	},
+};
+
+static struct driver_d malta_i2c_gpio_driver = {
+	.name  = "malta-fpga-i2c-gpio",
+	.probe = malta_i2c_gpio_probe,
+	.of_compatible	= DRV_OF_COMPAT(malta_i2c_gpio_dt_ids),
+};
+
+static int malta_i2c_gpio_driver_init(void)
+{
+	return platform_driver_register(&malta_i2c_gpio_driver);
+}
+coredevice_initcall(malta_i2c_gpio_driver_init);
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/7] MIPS: add <asm/gpio.h> header file
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
  2014-06-23 21:21 ` [PATCH 1/7] gpio: add Malta CBUS FPGA I2C driver Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-23 21:21 ` [PATCH 3/7] MIPS: malta: enable gpiolib Antony Pavlov
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/include/asm/gpio.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/mips/include/asm/gpio.h b/arch/mips/include/asm/gpio.h
new file mode 100644
index 0000000..41a9589
--- /dev/null
+++ b/arch/mips/include/asm/gpio.h
@@ -0,0 +1,6 @@
+#ifndef _ARCH_MIPS_GPIO_H
+#define _ARCH_MIPS_GPIO_H
+
+#include <asm-generic/gpio.h>
+
+#endif /* _ARCH_MIPS_GPIO_H */
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/7] MIPS: malta: enable gpiolib
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
  2014-06-23 21:21 ` [PATCH 1/7] gpio: add Malta CBUS FPGA I2C driver Antony Pavlov
  2014-06-23 21:21 ` [PATCH 2/7] MIPS: add <asm/gpio.h> header file Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-23 21:21 ` [PATCH 4/7] MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver Antony Pavlov
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 9a240b7..f6b9765 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -44,6 +44,7 @@ config MACH_MIPS_MALTA
 	select SYS_SUPPORTS_32BIT_KERNEL
 	select SYS_SUPPORTS_BIG_ENDIAN
 	select HAS_DEBUG_LL
+	select GPIOLIB
 
 config MACH_MIPS_AR231X
 	bool "Atheros ar231x-based boards"
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/7] MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
                   ` (2 preceding siblings ...)
  2014-06-23 21:21 ` [PATCH 3/7] MIPS: malta: enable gpiolib Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-23 21:21 ` [PATCH 5/7] i2c: i2c_gpio: add devicetree support Antony Pavlov
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/dts/qemu-malta.dts | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/mips/dts/qemu-malta.dts b/arch/mips/dts/qemu-malta.dts
index 67fe591..204007d 100644
--- a/arch/mips/dts/qemu-malta.dts
+++ b/arch/mips/dts/qemu-malta.dts
@@ -25,6 +25,13 @@
 		clock-frequency = <1843200>;
 	};
 
+	gpio: gpio@1f000b00 {
+		compatible = "mti,malta-fpga-i2c-gpio";
+		gpio-controller;
+		reg = <0xbf000b00 0x20>;
+		#gpio-cells = <2>;
+	};
+
 	uart2: serial@bf000900 {
 		compatible = "ns16550a";
 		reg = <0xbf000900 0x40>;
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/7] i2c: i2c_gpio: add devicetree support
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
                   ` (3 preceding siblings ...)
  2014-06-23 21:21 ` [PATCH 4/7] MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-24  7:03   ` Sascha Hauer
  2014-06-23 21:21 ` [PATCH 6/7] MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C bus Antony Pavlov
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 .../devicetree/bindings/gpio/gpio_i2c.txt          | 32 +++++++++++++
 drivers/i2c/busses/i2c-gpio.c                      | 54 +++++++++++++++++++--
 include/of_gpio.h                                  | 55 ++++++++++++++++++++++
 3 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/gpio/gpio_i2c.txt b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
new file mode 100644
index 0000000..4f8ec94
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
@@ -0,0 +1,32 @@
+Device-Tree bindings for i2c gpio driver
+
+Required properties:
+	- compatible = "i2c-gpio";
+	- gpios: sda and scl gpio
+
+
+Optional properties:
+	- i2c-gpio,sda-open-drain: sda as open drain
+	- i2c-gpio,scl-open-drain: scl as open drain
+	- i2c-gpio,scl-output-only: scl as output only
+	- i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform)
+	- i2c-gpio,timeout-ms: timeout to get data
+
+Example nodes:
+
+i2c@0 {
+	compatible = "i2c-gpio";
+	gpios = <&pioA 23 0 /* sda */
+		 &pioA 24 0 /* scl */
+		>;
+	i2c-gpio,sda-open-drain;
+	i2c-gpio,scl-open-drain;
+	i2c-gpio,delay-us = <2>;	/* ~100 kHz */
+	#address-cells = <1>;
+	#size-cells = <0>;
+
+	rv3029c2@56 {
+		compatible = "rv3029c2";
+		reg = <0x56>;
+	};
+};
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 8b49c2c..29dc3d2 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -15,6 +15,7 @@
 #include <i2c/i2c-gpio.h>
 #include <init.h>
 #include <gpio.h>
+#include <of_gpio.h>
 
 struct i2c_gpio_private_data {
 	struct i2c_adapter adap;
@@ -83,6 +84,38 @@ static int i2c_gpio_getscl(void *data)
 	return gpio_get_value(pdata->scl_pin);
 }
 
+static int of_i2c_gpio_probe(struct device_node *np,
+			     struct i2c_gpio_platform_data *pdata)
+{
+	u32 reg;
+
+	if (of_gpio_count(np) < 2)
+		return -ENODEV;
+
+	pdata->sda_pin = of_get_gpio(np, 0);
+	pdata->scl_pin = of_get_gpio(np, 1);
+
+	if (!gpio_is_valid(pdata->sda_pin) || !gpio_is_valid(pdata->scl_pin)) {
+		pr_err("%s: invalid GPIO pins, sda=%d/scl=%d\n",
+		       np->full_name, pdata->sda_pin, pdata->scl_pin);
+		return -ENODEV;
+	}
+
+	of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
+
+	if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", &reg))
+		pdata->timeout_ms = reg;
+
+	pdata->sda_is_open_drain =
+		of_property_read_bool(np, "i2c-gpio,sda-open-drain");
+	pdata->scl_is_open_drain =
+		of_property_read_bool(np, "i2c-gpio,scl-open-drain");
+	pdata->scl_is_output_only =
+		of_property_read_bool(np, "i2c-gpio,scl-output-only");
+
+	return 0;
+}
+
 static int i2c_gpio_probe(struct device_d *dev)
 {
 	struct i2c_gpio_private_data *priv;
@@ -97,9 +130,15 @@ static int i2c_gpio_probe(struct device_d *dev)
 	bit_data = &priv->bit_data;
 	pdata = &priv->pdata;
 
-	if (!dev->platform_data)
-		return -ENXIO;
-	memcpy(pdata, dev->platform_data, sizeof(*pdata));
+	if (dev->device_node) {
+		ret = of_i2c_gpio_probe(dev->device_node, pdata);
+		if (ret)
+			return ret;
+	} else {
+		if (!dev->platform_data)
+			return -ENXIO;
+		memcpy(pdata, dev->platform_data, sizeof(*pdata));
+	}
 
 	ret = gpio_request(pdata->sda_pin, "sda");
 	if (ret)
@@ -144,6 +183,7 @@ static int i2c_gpio_probe(struct device_d *dev)
 
 	adap->algo_data = bit_data;
 	adap->dev.parent = dev;
+	adap->dev.device_node = dev->device_node;
 
 	adap->nr = dev->id;
 	ret = i2c_bit_add_numbered_bus(adap);
@@ -165,8 +205,16 @@ err_request_sda:
 	return ret;
 }
 
+#if defined(CONFIG_OFDEVICE)
+static struct of_device_id i2c_gpio_dt_ids[] = {
+	{ .compatible = "i2c-gpio", },
+	{ /* sentinel */ }
+};
+#endif
+
 static struct driver_d i2c_gpio_driver = {
 	.name	= "i2c-gpio",
 	.probe	= i2c_gpio_probe,
+	.of_compatible = DRV_OF_COMPAT(i2c_gpio_dt_ids),
 };
 device_platform_driver(i2c_gpio_driver);
diff --git a/include/of_gpio.h b/include/of_gpio.h
index d42b18e..95a454c 100644
--- a/include/of_gpio.h
+++ b/include/of_gpio.h
@@ -35,10 +35,65 @@ static inline int of_get_named_gpio_flags(struct device_node *np,
 
 #endif /* CONFIG_OF_GPIO */
 
+/**
+ * of_gpio_named_count() - Count GPIOs for a device
+ * @np:		device node to count GPIOs for
+ * @propname:	property name containing gpio specifier(s)
+ *
+ * The function returns the count of GPIOs specified for a node.
+ * Note that the empty GPIO specifiers count too. Returns either
+ *   Number of gpios defined in property,
+ *   -EINVAL for an incorrectly formed gpios property, or
+ *   -ENOENT for a missing gpios property
+ *
+ * Example:
+ * gpios = <0
+ *          &gpio1 1 2
+ *          0
+ *          &gpio2 3 4>;
+ *
+ * The above example defines four GPIOs, two of which are not specified.
+ * This function will return '4'
+ */
+static inline int of_gpio_named_count(struct device_node *np, const char* propname)
+{
+	return of_count_phandle_with_args(np, propname, "#gpio-cells");
+}
+
+/**
+ * of_gpio_count() - Count GPIOs for a device
+ * @np:		device node to count GPIOs for
+ *
+ * Same as of_gpio_named_count, but hard coded to use the 'gpios' property
+ */
+static inline int of_gpio_count(struct device_node *np)
+{
+	return of_gpio_named_count(np, "gpios");
+}
+
+static inline int of_get_gpio_flags(struct device_node *np, int index,
+		      enum of_gpio_flags *flags)
+{
+	return of_get_named_gpio_flags(np, "gpios", index, flags);
+}
+
 static inline int of_get_named_gpio(struct device_node *np,
 				const char *list_name, int index)
 {
 	return of_get_named_gpio_flags(np, list_name, index, NULL);
 }
 
+/**
+ * of_get_gpio() - Get a GPIO number to use with GPIO API
+ * @np:		device node to get GPIO from
+ * @index:	index of the GPIO
+ *
+ * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
+ * value on the error condition.
+ */
+static inline int of_get_gpio(struct device_node *np, int index)
+{
+	return of_get_gpio_flags(np, index, NULL);
+}
+
 #endif
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/7] MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C bus
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
                   ` (4 preceding siblings ...)
  2014-06-23 21:21 ` [PATCH 5/7] i2c: i2c_gpio: add devicetree support Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-23 21:21 ` [PATCH 7/7] MIPS: qemu-malta_defconfig: enable gpio & i2c stuff Antony Pavlov
  2014-06-24  7:09 ` [PATCH 0/7] MIPS: malta: " Sascha Hauer
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Also we can enable m24c02 eeprom chip in dts-file e.g.

    &i2c0 {
            status = "okay";

            eeprom: m24c02@50 {
                    compatible = "spd";
                    reg = <0x50>;
            };
    };

Alas! qemu mips malta spd m24c02 eeprom chip emulation is not perfect:
the block read operation does not work properly.

Here is an example.

If we read eeprom content byte-by-byte then there is no problem:

    barebox:/ for i in 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f ;
    > do i2c_read -b 0 -a 0x50 -r $i -c 1 ; done
    0x01
    0x75
    0x54
    0x00
    0x82
    0x08
    0x00
    0x01

Compare this output with content of qemu.git/hw/mips/mips_malta.c:

    static eeprom24c0x_t spd_eeprom = {
        .contents = {
            ...
            /* 00000008: */ 0x01,0x75,0x54,0x00,0x82,0x08,0x00,0x01,

But if we read several bytes at once the we have data corruption:

    barebox:/ i2c_read -b 0 -a 0x50 -r 0x8 -c 8
    0x01 0xff 0xff 0xff 0xff 0xff 0xff 0xff

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/dts/qemu-malta.dts | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/mips/dts/qemu-malta.dts b/arch/mips/dts/qemu-malta.dts
index 204007d..cc1c960 100644
--- a/arch/mips/dts/qemu-malta.dts
+++ b/arch/mips/dts/qemu-malta.dts
@@ -32,6 +32,18 @@
 		#gpio-cells = <2>;
 	};
 
+	i2c0: i2c0 {
+		compatible = "i2c-gpio";
+		gpios = <&gpio 0 0 /* sda */
+			&gpio 1 0 /* scl */
+			>;
+		i2c-gpio,sda-open-drain;
+		i2c-gpio,scl-open-drain;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
 	uart2: serial@bf000900 {
 		compatible = "ns16550a";
 		reg = <0xbf000900 0x40>;
@@ -58,3 +70,7 @@
 		};
 	};
 };
+
+&i2c0 {
+	status = "okay";
+};
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 7/7] MIPS: qemu-malta_defconfig: enable gpio & i2c stuff
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
                   ` (5 preceding siblings ...)
  2014-06-23 21:21 ` [PATCH 6/7] MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C bus Antony Pavlov
@ 2014-06-23 21:21 ` Antony Pavlov
  2014-06-24  7:09 ` [PATCH 0/7] MIPS: malta: " Sascha Hauer
  7 siblings, 0 replies; 10+ messages in thread
From: Antony Pavlov @ 2014-06-23 21:21 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/configs/qemu-malta_defconfig | 60 ++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/arch/mips/configs/qemu-malta_defconfig b/arch/mips/configs/qemu-malta_defconfig
index ba5fa96..78f175d 100644
--- a/arch/mips/configs/qemu-malta_defconfig
+++ b/arch/mips/configs/qemu-malta_defconfig
@@ -4,9 +4,7 @@ CONFIG_PBL_IMAGE=y
 CONFIG_STACK_SIZE=0x7000
 CONFIG_BROKEN=y
 CONFIG_EXPERIMENTAL=y
-CONFIG_LONGHELP=y
 CONFIG_HUSH_FANCY_PROMPT=y
-CONFIG_CMD_GETOPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
@@ -14,54 +12,60 @@ CONFIG_PARTITION=y
 # CONFIG_DEFAULT_ENVIRONMENT is not set
 CONFIG_POLLER=y
 CONFIG_DEBUG_INFO=y
-CONFIG_CMD_EDIT=y
-CONFIG_CMD_SLEEP=y
-CONFIG_CMD_SAVEENV=y
-CONFIG_CMD_LOADENV=y
+CONFIG_LONGHELP=y
+CONFIG_CMD_IOMEM=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_LOADB=y
+CONFIG_CMD_LOADY=y
+CONFIG_CMD_RESET=y
+CONFIG_CMD_PARTITION=y
 CONFIG_CMD_EXPORT=y
+CONFIG_CMD_LOADENV=y
 CONFIG_CMD_PRINTENV=y
-CONFIG_CMD_READLINE=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_MD5SUM=y
+CONFIG_CMD_SHA1SUM=y
+CONFIG_CMD_SHA256SUM=y
+CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_GETOPT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_TFTP=y
+CONFIG_CMD_ECHO_E=y
+CONFIG_CMD_EDIT=y
 CONFIG_CMD_MENU=y
 CONFIG_CMD_MENU_MANAGEMENT=y
 CONFIG_CMD_PASSWD=y
-CONFIG_CMD_TIME=y
-CONFIG_CMD_TFTP=y
-CONFIG_CMD_ECHO_E=y
-CONFIG_CMD_LOADB=y
-CONFIG_CMD_LOADY=y
-CONFIG_CMD_MEMINFO=y
-CONFIG_CMD_IOMEM=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_CRC=y
 CONFIG_CMD_CRC_CMP=y
-CONFIG_CMD_MD5SUM=y
-CONFIG_CMD_SHA1SUM=y
-CONFIG_CMD_SHA256SUM=y
 CONFIG_CMD_FLASH=y
-CONFIG_CMD_BOOTM_SHOW_TYPE=y
-CONFIG_CMD_RESET=y
-CONFIG_CMD_GO=y
-CONFIG_CMD_OFTREE=y
-CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_I2C=y
 CONFIG_CMD_OF_NODE=y
-CONFIG_CMD_MTEST=y
-CONFIG_CMD_TIMEOUT=y
-CONFIG_CMD_PARTITION=y
-CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_OFTREE=y
+CONFIG_CMD_TIME=y
 CONFIG_NET=y
-CONFIG_CMD_DHCP=y
 CONFIG_NET_NFS=y
-CONFIG_CMD_PING=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
 CONFIG_OFDEVICE=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 # CONFIG_SPI is not set
+CONFIG_I2C=y
+CONFIG_I2C_GPIO=y
 CONFIG_MTD=y
 CONFIG_DRIVER_CFI=y
 # CONFIG_DRIVER_CFI_AMD is not set
 # CONFIG_DRIVER_CFI_BANK_WIDTH_1 is not set
 # CONFIG_DRIVER_CFI_BANK_WIDTH_2 is not set
 CONFIG_CFI_BUFFER_WRITE=y
+CONFIG_GPIO_MALTA_FPGA_I2C=y
 CONFIG_FS_CRAMFS=y
 CONFIG_FS_TFTP=y
 CONFIG_FS_FAT=y
-- 
1.9.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/7] i2c: i2c_gpio: add devicetree support
  2014-06-23 21:21 ` [PATCH 5/7] i2c: i2c_gpio: add devicetree support Antony Pavlov
@ 2014-06-24  7:03   ` Sascha Hauer
  0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2014-06-24  7:03 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Tue, Jun 24, 2014 at 01:21:11AM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  .../devicetree/bindings/gpio/gpio_i2c.txt          | 32 +++++++++++++
>  drivers/i2c/busses/i2c-gpio.c                      | 54 +++++++++++++++++++--
>  include/of_gpio.h                                  | 55 ++++++++++++++++++++++
>  3 files changed, 138 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio_i2c.txt b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
> new file mode 100644
> index 0000000..4f8ec94
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/gpio_i2c.txt

We already have this binding in dts/Bindings/i2c/i2c-gpio.txt, no need
to duplicate it here. Documentation/devicetree is only for barebox
specific bindings.


> @@ -0,0 +1,32 @@
> +Device-Tree bindings for i2c gpio driver
> +
> +Required properties:
> +	- compatible = "i2c-gpio";
> +	- gpios: sda and scl gpio
> +
> +
> +Optional properties:
> +	- i2c-gpio,sda-open-drain: sda as open drain
> +	- i2c-gpio,scl-open-drain: scl as open drain
> +	- i2c-gpio,scl-output-only: scl as output only
> +	- i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform)
> +	- i2c-gpio,timeout-ms: timeout to get data
> +
> +Example nodes:
> +
> +i2c@0 {
> +	compatible = "i2c-gpio";
> +	gpios = <&pioA 23 0 /* sda */
> +		 &pioA 24 0 /* scl */
> +		>;
> +	i2c-gpio,sda-open-drain;
> +	i2c-gpio,scl-open-drain;
> +	i2c-gpio,delay-us = <2>;	/* ~100 kHz */
> +	#address-cells = <1>;
> +	#size-cells = <0>;
> +
> +	rv3029c2@56 {
> +		compatible = "rv3029c2";
> +		reg = <0x56>;
> +	};
> +};
> diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
> index 8b49c2c..29dc3d2 100644
> --- a/drivers/i2c/busses/i2c-gpio.c
> +++ b/drivers/i2c/busses/i2c-gpio.c
> @@ -15,6 +15,7 @@
>  #include <i2c/i2c-gpio.h>
>  #include <init.h>
>  #include <gpio.h>
> +#include <of_gpio.h>
>  
>  struct i2c_gpio_private_data {
>  	struct i2c_adapter adap;
> @@ -83,6 +84,38 @@ static int i2c_gpio_getscl(void *data)
>  	return gpio_get_value(pdata->scl_pin);
>  }
>  
> +static int of_i2c_gpio_probe(struct device_node *np,
> +			     struct i2c_gpio_platform_data *pdata)
> +{
> +	u32 reg;
> +

Consider adding a

	is (!IS_ENABLED(CONFIG_OFDEVICE))
		return -ENODEV;

to allow the compiler to throw away the rest of this function.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff
  2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
                   ` (6 preceding siblings ...)
  2014-06-23 21:21 ` [PATCH 7/7] MIPS: qemu-malta_defconfig: enable gpio & i2c stuff Antony Pavlov
@ 2014-06-24  7:09 ` Sascha Hauer
  7 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2014-06-24  7:09 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Tue, Jun 24, 2014 at 01:21:06AM +0400, Antony Pavlov wrote:
> Antony Pavlov (7):
>   gpio: add Malta CBUS FPGA I2C driver
>   MIPS: add <asm/gpio.h> header file
>   MIPS: malta: enable gpiolib
>   MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver
>   i2c: i2c_gpio: add devicetree support
>   MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C
>     bus
>   MIPS: qemu-malta_defconfig: enable gpio & i2c stuff

Just fixed up the patches myself and applied the series.

Sascha

> 
>  .../devicetree/bindings/gpio/gpio_i2c.txt          |  32 ++++
>  arch/mips/Kconfig                                  |   1 +
>  arch/mips/configs/qemu-malta_defconfig             |  60 +++----
>  arch/mips/dts/qemu-malta.dts                       |  23 +++
>  arch/mips/include/asm/gpio.h                       |   6 +
>  drivers/gpio/Kconfig                               |  10 ++
>  drivers/gpio/Makefile                              |   1 +
>  drivers/gpio/gpio-malta-fpga-i2c.c                 | 186 +++++++++++++++++++++
>  drivers/i2c/busses/i2c-gpio.c                      |  54 +++++-
>  include/of_gpio.h                                  |  55 ++++++
>  10 files changed, 397 insertions(+), 31 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/gpio/gpio_i2c.txt
>  create mode 100644 arch/mips/include/asm/gpio.h
>  create mode 100644 drivers/gpio/gpio-malta-fpga-i2c.c
> 
> -- 
> 1.9.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-06-24  7:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23 21:21 [PATCH 0/7] MIPS: malta: enable gpio & i2c stuff Antony Pavlov
2014-06-23 21:21 ` [PATCH 1/7] gpio: add Malta CBUS FPGA I2C driver Antony Pavlov
2014-06-23 21:21 ` [PATCH 2/7] MIPS: add <asm/gpio.h> header file Antony Pavlov
2014-06-23 21:21 ` [PATCH 3/7] MIPS: malta: enable gpiolib Antony Pavlov
2014-06-23 21:21 ` [PATCH 4/7] MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver Antony Pavlov
2014-06-23 21:21 ` [PATCH 5/7] i2c: i2c_gpio: add devicetree support Antony Pavlov
2014-06-24  7:03   ` Sascha Hauer
2014-06-23 21:21 ` [PATCH 6/7] MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C bus Antony Pavlov
2014-06-23 21:21 ` [PATCH 7/7] MIPS: qemu-malta_defconfig: enable gpio & i2c stuff Antony Pavlov
2014-06-24  7:09 ` [PATCH 0/7] MIPS: malta: " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox