Skip to contentSkip to conversation

MIPS: malta: enable gpio & i2c stuff

PATCH In review Antony Pavlov 2 participants 10 messages Jun 23, 2014 – Jun 24, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover MIPS: malta: enable gpio & i2c stuff

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
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/7 gpio: add Malta CBUS FPGA I2C driver

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.

---
 drivers/gpio/Kconfig               |  10 ++
 drivers/gpio/Makefile              |   1 +
 drivers/gpio/gpio-malta-fpga-i2c.c | 186 +++++++++++++++++++++++++++++++++++++
 3 files changed, 197 insertions(+)
drivers/gpio/Kconfig +10 -0
index 7302955..45b8c53 100644
@@ -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
 
drivers/gpio/Makefile +1 -0
index 68a76a3..add6ffc 100644
@@ -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
drivers/gpio/gpio-malta-fpga-i2c.c new file +186 -0

186 lines not on this page · raw message

Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 2/7 MIPS: add <asm/gpio.h> header file

In reply to Antony Pavlov
---
 arch/mips/include/asm/gpio.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/mips/include/asm/gpio.h new file +6 -0
new file mode 100644
index 0000000..41a9589
@@ -0,0 +1,6 @@
+#ifndef _ARCH_MIPS_GPIO_H
+#define _ARCH_MIPS_GPIO_H
+
+#include <asm-generic/gpio.h>
+
+#endif /* _ARCH_MIPS_GPIO_H */
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH 3/7 MIPS: malta: enable gpiolib

In reply to Antony Pavlov
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/mips/Kconfig +1 -0
index 9a240b7..f6b9765 100644
@@ -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"
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 6/7 MIPS: dts: qemu-malta.dts: use i2c-gpio for accessing CBUS FPGA I2C bus

In reply to Antony Pavlov

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
---
 arch/mips/dts/qemu-malta.dts | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/mips/dts/qemu-malta.dts +16 -0
index 204007d..cc1c960 100644
@@ -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";
+};
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH 4/7 MIPS: dts: qemu-malta.dts: enable CBUS FPGA I2C gpio driver

In reply to Antony Pavlov
---
 arch/mips/dts/qemu-malta.dts | 7 +++++++
 1 file changed, 7 insertions(+)
arch/mips/dts/qemu-malta.dts +7 -0
index 67fe591..204007d 100644
@@ -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>;
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 5/7 i2c: i2c_gpio: add devicetree support

In reply to Antony Pavlov
---
 .../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(-)
Documentation/devicetree/bindings/gpio/gpio_i2c.txt new file +32 -0
new file mode 100644
index 0000000..4f8ec94
@@ -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>;
+	};
+};
drivers/i2c/busses/i2c-gpio.c +51 -3

86 lines not on this page · raw message

include/of_gpio.h +55 -0

65 lines not on this page · raw message

Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 7/7 MIPS: qemu-malta_defconfig: enable gpio & i2c stuff

In reply to Antony Pavlov
---
 arch/mips/configs/qemu-malta_defconfig | 60 ++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 28 deletions(-)
arch/mips/configs/qemu-malta_defconfig +32 -28
index ba5fa96..78f175d 100644
@@ -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
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [PATCH 5/7] i2c: i2c_gpio: add devicetree support

In reply to Antony Pavlov

Documentation/devicetree/bindings/gpio/gpio_i2c.txt

Quoted 12 lines · Antony Pavlov
---
 .../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(-)
Documentation/devicetree/bindings/gpio/gpio_i2c.txt new file +0 -0
new file mode 100644
index 0000000..4f8ec94

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.

Quoted 46 lines
Documentation/devicetree/bindings/gpio/gpio_i2c.txt new file +32 -0
@@ -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>;
+	};
+};
drivers/i2c/busses/i2c-gpio.c +1 -0
index 8b49c2c..29dc3d2 100644
@@ -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;

drivers/i2c/busses/i2c-gpio.c static int i2c_gpio_getscl(void *data) · line 91

Quoted 8 lines
drivers/i2c/busses/i2c-gpio.c +5 -0
@@ -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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw
In reply to Antony Pavlov
Quoted 9 lines · Antony Pavlov

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

Quoted 25 lines
 .../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
Signature · 7 lines
1.9.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox