devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] gpio: driver for the RPi3 GPIO expander
@ 2018-01-02 13:19 Baruch Siach
  2018-01-02 13:19 ` [PATCH 1/4] ARM: bcm2835: sync firmware properties with downstream Baruch Siach
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Baruch Siach @ 2018-01-02 13:19 UTC (permalink / raw)
  To: Dave Stevenson, Eric Anholt, Stefan Wahren, Linus Walleij
  Cc: linux-gpio, linux-arm-kernel, linux-rpi-kernel, devicetree, Baruch Siach

The Raspberry Pi 3 has a GPIO expander that controls, among others, the 
activity LED, and the camera connector GPIOs. The GPIO expander on an I2C bus 
that is not directly controlled from the ARM core. The VC4 firmware controls 
the I2C bus, and allows the ARM core to set/get GPIO settings over its mailbox 
interface.

This series adds support for the RPi3 expander.

The driver is ported from the downstream kernel at 
https://github.com/raspberrypi/linux/, branch rpi-4.9.y.

Baruch Siach (3):
  ARM: bcm2835: sync firmware properties with downstream
  dt-bindings: gpio: add raspberry pi GPIO expander binding
  ARM: dts: bcm2837-rpi-3-b: add GPIO expander

Dave Stevenson (1):
  bcm2835-gpio-exp: Driver for GPIO expander via mailbox service

 .../bindings/gpio/brcm,bcm2835-expgpio.txt         |  24 ++
 arch/arm/boot/dts/bcm2837-rpi-3-b.dts              |  10 +
 drivers/gpio/Kconfig                               |   7 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-bcm-exp.c                        | 254 +++++++++++++++++++++
 include/soc/bcm2835/raspberrypi-firmware.h         |  18 ++
 6 files changed, 314 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
 create mode 100644 drivers/gpio/gpio-bcm-exp.c

-- 
2.15.1


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

* [PATCH 1/4] ARM: bcm2835: sync firmware properties with downstream
  2018-01-02 13:19 [PATCH 0/4] gpio: driver for the RPi3 GPIO expander Baruch Siach
@ 2018-01-02 13:19 ` Baruch Siach
  2018-01-02 13:19 ` [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding Baruch Siach
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 18+ messages in thread
From: Baruch Siach @ 2018-01-02 13:19 UTC (permalink / raw)
  To: Dave Stevenson, Eric Anholt, Stefan Wahren, Linus Walleij
  Cc: linux-gpio, linux-arm-kernel, linux-rpi-kernel, devicetree, Baruch Siach

Add latest firmware property tags from the latest Raspberry Pi downstream
kernel. This is needed for the GPIO tags, so we can control the GPIO
multiplexor lines.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 include/soc/bcm2835/raspberrypi-firmware.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index cb979ad90401..50df5b28d2c9 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -63,6 +63,7 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_GET_MIN_VOLTAGE =                        0x00030008,
 	RPI_FIRMWARE_GET_TURBO =                              0x00030009,
 	RPI_FIRMWARE_GET_MAX_TEMPERATURE =                    0x0003000a,
+	RPI_FIRMWARE_GET_STC =                                0x0003000b,
 	RPI_FIRMWARE_ALLOCATE_MEMORY =                        0x0003000c,
 	RPI_FIRMWARE_LOCK_MEMORY =                            0x0003000d,
 	RPI_FIRMWARE_UNLOCK_MEMORY =                          0x0003000e,
@@ -72,12 +73,22 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_SET_ENABLE_QPU =                         0x00030012,
 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
+	RPI_FIRMWARE_GET_CUSTOMER_OTP =                       0x00030021,
 	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
 	RPI_FIRMWARE_SET_CLOCK_STATE =                        0x00038001,
 	RPI_FIRMWARE_SET_CLOCK_RATE =                         0x00038002,
 	RPI_FIRMWARE_SET_VOLTAGE =                            0x00038003,
 	RPI_FIRMWARE_SET_TURBO =                              0x00038009,
+	RPI_FIRMWARE_SET_CUSTOMER_OTP =                       0x00038021,
 	RPI_FIRMWARE_SET_DOMAIN_STATE =                       0x00038030,
+	RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
+	RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,
+	RPI_FIRMWARE_SET_SDHOST_CLOCK =                       0x00038042,
+	RPI_FIRMWARE_GET_GPIO_CONFIG =                        0x00030043,
+	RPI_FIRMWARE_SET_GPIO_CONFIG =                        0x00038043,
+	RPI_FIRMWARE_GET_PERIPH_REG =                         0x00030045,
+	RPI_FIRMWARE_SET_PERIPH_REG =                         0x00038045,
+
 
 	/* Dispmanx TAGS */
 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
@@ -91,6 +102,8 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_OFFSET =         0x00040009,
 	RPI_FIRMWARE_FRAMEBUFFER_GET_OVERSCAN =               0x0004000a,
 	RPI_FIRMWARE_FRAMEBUFFER_GET_PALETTE =                0x0004000b,
+	RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF =               0x0004000f,
+	RPI_FIRMWARE_FRAMEBUFFER_GET_GPIOVIRTBUF =            0x00040010,
 	RPI_FIRMWARE_FRAMEBUFFER_RELEASE =                    0x00048001,
 	RPI_FIRMWARE_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
 	RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT =  0x00044004,
@@ -100,6 +113,7 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_OFFSET =        0x00044009,
 	RPI_FIRMWARE_FRAMEBUFFER_TEST_OVERSCAN =              0x0004400a,
 	RPI_FIRMWARE_FRAMEBUFFER_TEST_PALETTE =               0x0004400b,
+	RPI_FIRMWARE_FRAMEBUFFER_TEST_VSYNC =                 0x0004400e,
 	RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT =  0x00048003,
 	RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT =   0x00048004,
 	RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH =                  0x00048005,
@@ -108,6 +122,10 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET =         0x00048009,
 	RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN =               0x0004800a,
 	RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE =                0x0004800b,
+	RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF =               0x0004801f,
+	RPI_FIRMWARE_FRAMEBUFFER_SET_GPIOVIRTBUF =            0x00048020,
+	RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC =                  0x0004800e,
+	RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT =              0x0004800f,
 
 	RPI_FIRMWARE_VCHIQ_INIT =                             0x00048010,
 
-- 
2.15.1


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

* [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding
  2018-01-02 13:19 [PATCH 0/4] gpio: driver for the RPi3 GPIO expander Baruch Siach
  2018-01-02 13:19 ` [PATCH 1/4] ARM: bcm2835: sync firmware properties with downstream Baruch Siach
@ 2018-01-02 13:19 ` Baruch Siach
  2018-01-02 18:26   ` Stefan Wahren
  2018-01-02 13:19 ` [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service Baruch Siach
       [not found] ` <cover.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
  3 siblings, 1 reply; 18+ messages in thread
From: Baruch Siach @ 2018-01-02 13:19 UTC (permalink / raw)
  To: Dave Stevenson, Eric Anholt, Stefan Wahren, Linus Walleij
  Cc: linux-gpio, linux-arm-kernel, linux-rpi-kernel, devicetree, Baruch Siach

The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware over
I2C. The firmware mailbox interface allows the ARM core to control the
GPIO lines.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 .../bindings/gpio/brcm,bcm2835-expgpio.txt         | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt

diff --git a/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
new file mode 100644
index 000000000000..55257f31a9be
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
@@ -0,0 +1,24 @@
+Raspberry Pi GPIO expander
+
+The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware. The
+firmware exposes a mailbox interface that allows the ARM core to control the
+GPIO lines on the expander.
+
+Required properties:
+
+- compatible : Should be "brcm,bcm2835-expgpio"
+- gpio-controller : Marks the device node as a gpio controller
+- #gpio-cells : Should be two.  The first cell is the pin number, and
+  the second cell is used to specify the gpio polarity:
+  0 = active high
+  1 = active low
+- firmware : Reference to the RPi firmware device node
+
+Example:
+
+expgpio: expgpio {
+	compatible = "brcm,bcm2835-expgpio";
+	gpio-controller;
+	#gpio-cells = <2>;
+	firmware = <&firmware>;
+};
-- 
2.15.1


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

* [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-02 13:19 [PATCH 0/4] gpio: driver for the RPi3 GPIO expander Baruch Siach
  2018-01-02 13:19 ` [PATCH 1/4] ARM: bcm2835: sync firmware properties with downstream Baruch Siach
  2018-01-02 13:19 ` [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding Baruch Siach
@ 2018-01-02 13:19 ` Baruch Siach
  2018-01-02 18:49   ` Stefan Wahren
  2018-01-03 10:08   ` Linus Walleij
       [not found] ` <cover.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
  3 siblings, 2 replies; 18+ messages in thread
From: Baruch Siach @ 2018-01-02 13:19 UTC (permalink / raw)
  To: Dave Stevenson, Eric Anholt, Stefan Wahren, Linus Walleij
  Cc: linux-gpio, linux-arm-kernel, linux-rpi-kernel, devicetree, Baruch Siach

From: Dave Stevenson <dave.stevenson@raspberrypi.org>

Pi3 and Compute Module 3 have a GPIO expander that the
VPU communicates with.
There is a mailbox service that now allows control of this
expander, so add a kernel driver that can make use of it.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 drivers/gpio/Kconfig        |   7 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-bcm-exp.c | 254 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 262 insertions(+)
 create mode 100644 drivers/gpio/gpio-bcm-exp.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index d6a8e851ad13..e2aab64ea772 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -128,6 +128,13 @@ config GPIO_AXP209
 	help
 	  Say yes to enable GPIO support for the AXP209 PMIC
 
+config GPIO_BCM_EXP
+	bool "Broadcom Exp GPIO"
+	depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
+	help
+	  Turn on GPIO support for Broadcom chips using the firmware mailbox
+	  to communicate with VideoCore on BCM283x chips.
+
 config GPIO_BCM_KONA
 	bool "Broadcom Kona GPIO"
 	depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST)
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 4bc24febb889..c5f481b1d53c 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_GPIO_ARIZONA)	+= gpio-arizona.o
 obj-$(CONFIG_GPIO_ATH79)	+= gpio-ath79.o
 obj-$(CONFIG_GPIO_ASPEED)	+= gpio-aspeed.o
 obj-$(CONFIG_GPIO_AXP209)	+= gpio-axp209.o
+obj-$(CONFIG_GPIO_BCM_EXP)	+= gpio-bcm-exp.o
 obj-$(CONFIG_GPIO_BCM_KONA)	+= gpio-bcm-kona.o
 obj-$(CONFIG_GPIO_BD9571MWV)	+= gpio-bd9571mwv.o
 obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
diff --git a/drivers/gpio/gpio-bcm-exp.c b/drivers/gpio/gpio-bcm-exp.c
new file mode 100644
index 000000000000..d68adafaee4a
--- /dev/null
+++ b/drivers/gpio/gpio-bcm-exp.c
@@ -0,0 +1,254 @@
+/*
+ *  Broadcom expander GPIO driver
+ *
+ *  Uses the firmware mailbox service to communicate with the
+ *  GPIO expander on the VPU.
+ *
+ *  Copyright (C) 2017 Raspberry Pi Trading Ltd.
+ *
+ *  Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
+ *  Based on gpio-bcm-virt.c by Dom Cobley <popcornmix@gmail.com>
+ *
+ * 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.
+ */
+
+#include <linux/err.h>
+#include <linux/gpio.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+#define MODULE_NAME "brcmexp-gpio"
+#define NUM_GPIO 8
+
+struct brcmexp_gpio {
+	struct gpio_chip gc;
+	struct device *dev;
+	struct rpi_firmware *fw;
+};
+
+struct gpio_set_config {
+	u32 gpio, direction, polarity, term_en, term_pull_up, state;
+};
+
+struct gpio_get_config {
+	u32 gpio, direction, polarity, term_en, term_pull_up;
+};
+
+struct gpio_get_set_state {
+	u32 gpio, state;
+};
+
+static int brcmexp_gpio_get_polarity(struct gpio_chip *gc, unsigned int off)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_get_config get;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	get.gpio = off + gpio->gc.base;	/* GPIO to update */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
+				    &get, sizeof(get));
+	if (ret) {
+		dev_err(gpio->dev,
+			"Failed to get GPIO %u config (%d)\n", off, ret);
+		return ret;
+	}
+	return get.polarity;
+}
+
+static int brcmexp_gpio_dir_in(struct gpio_chip *gc, unsigned int off)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_set_config set_in;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	set_in.gpio = off + gpio->gc.base;	/* GPIO to update */
+	set_in.direction = 0;		/* Input */
+	set_in.polarity = brcmexp_gpio_get_polarity(gc, off);
+					/* Retain existing setting */
+	set_in.term_en = 0;		/* termination disabled */
+	set_in.term_pull_up = 0;	/* n/a as termination disabled */
+	set_in.state = 0;		/* n/a as configured as an input */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
+				    &set_in, sizeof(set_in));
+	if (ret) {
+		dev_err(gpio->dev,
+			"Failed to set GPIO %u to input (%d)\n",
+			off, ret);
+		return ret;
+	}
+	return 0;
+}
+
+static int brcmexp_gpio_dir_out(struct gpio_chip *gc, unsigned int off, int val)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_set_config set_out;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	set_out.gpio = off + gpio->gc.base;	/* GPIO to update */
+	set_out.direction = 1;		/* Output */
+	set_out.polarity = brcmexp_gpio_get_polarity(gc, off);
+					/* Retain existing setting */
+	set_out.term_en = 0;		/* n/a as an output */
+	set_out.term_pull_up = 0;	/* n/a as termination disabled */
+	set_out.state = val;		/* Output state */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_CONFIG,
+				    &set_out, sizeof(set_out));
+	if (ret) {
+		dev_err(gpio->dev,
+			"Failed to set GPIO %u to output (%d)\n", off, ret);
+		return ret;
+	}
+	return 0;
+}
+
+static int brcmexp_gpio_get_direction(struct gpio_chip *gc, unsigned int off)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_get_config get;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	get.gpio = off + gpio->gc.base;	/* GPIO to update */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
+				    &get, sizeof(get));
+	if (ret) {
+		dev_err(gpio->dev,
+			"Failed to get GPIO %u config (%d)\n", off, ret);
+		return ret;
+	}
+	return get.direction ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
+}
+
+static int brcmexp_gpio_get(struct gpio_chip *gc, unsigned int off)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_get_set_state get;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	get.gpio = off + gpio->gc.base;	/* GPIO to update */
+	get.state = 0;		/* storage for returned value */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_STATE,
+					 &get, sizeof(get));
+	if (ret) {
+		dev_err(gpio->dev,
+			"Failed to get GPIO %u state (%d)\n", off, ret);
+		return ret;
+	}
+	return !!get.state;
+}
+
+static void brcmexp_gpio_set(struct gpio_chip *gc, unsigned int off, int val)
+{
+	struct brcmexp_gpio *gpio;
+	struct gpio_get_set_state set;
+	int ret;
+
+	gpio = container_of(gc, struct brcmexp_gpio, gc);
+
+	set.gpio = off + gpio->gc.base;	/* GPIO to update */
+	set.state = val;	/* Output state */
+
+	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_SET_GPIO_STATE,
+					 &set, sizeof(set));
+	if (ret)
+		dev_err(gpio->dev,
+			"Failed to set GPIO %u state (%d)\n", off, ret);
+}
+
+static int brcmexp_gpio_probe(struct platform_device *pdev)
+{
+	int err = 0;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct device_node *fw_node;
+	struct rpi_firmware *fw;
+	struct brcmexp_gpio *ucb;
+
+	fw_node = of_parse_phandle(np, "firmware", 0);
+	if (!fw_node) {
+		dev_err(dev, "Missing firmware node\n");
+		return -ENOENT;
+	}
+
+	fw = rpi_firmware_get(fw_node);
+	if (!fw)
+		return -EPROBE_DEFER;
+
+	ucb = devm_kzalloc(dev, sizeof(*ucb), GFP_KERNEL);
+	if (!ucb)
+		return -EINVAL;
+
+	ucb->fw = fw;
+	ucb->dev = dev;
+	ucb->gc.label = MODULE_NAME;
+	ucb->gc.owner = THIS_MODULE;
+	ucb->gc.of_node = np;
+	ucb->gc.base = 128;
+	ucb->gc.ngpio = NUM_GPIO;
+
+	ucb->gc.direction_input = brcmexp_gpio_dir_in;
+	ucb->gc.direction_output = brcmexp_gpio_dir_out;
+	ucb->gc.get_direction = brcmexp_gpio_get_direction;
+	ucb->gc.get = brcmexp_gpio_get;
+	ucb->gc.set = brcmexp_gpio_set;
+	ucb->gc.can_sleep = true;
+
+	err = gpiochip_add(&ucb->gc);
+	if (err)
+		return err;
+
+	platform_set_drvdata(pdev, ucb);
+
+	return 0;
+}
+
+static int brcmexp_gpio_remove(struct platform_device *pdev)
+{
+	struct brcmexp_gpio *ucb = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&ucb->gc);
+
+	return 0;
+}
+
+static const struct of_device_id __maybe_unused brcmexp_gpio_ids[] = {
+	{ .compatible = "brcm,bcm2835-expgpio" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, brcmexp_gpio_ids);
+
+static struct platform_driver brcmexp_gpio_driver = {
+	.driver	= {
+		.name		= MODULE_NAME,
+		.owner		= THIS_MODULE,
+		.of_match_table	= of_match_ptr(brcmexp_gpio_ids),
+	},
+	.probe	= brcmexp_gpio_probe,
+	.remove	= brcmexp_gpio_remove,
+};
+module_platform_driver(brcmexp_gpio_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.org>");
+MODULE_DESCRIPTION("brcm-exp GPIO driver");
+MODULE_ALIAS("platform:brcmexp-gpio");
-- 
2.15.1


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

* [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander
       [not found] ` <cover.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
@ 2018-01-02 13:19   ` Baruch Siach
       [not found]     ` <a29df633ee568e150c150debde66c0783a57c70a.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
  2018-01-02 18:05   ` [PATCH 0/4] gpio: driver for the RPi3 " Stefan Wahren
  1 sibling, 1 reply; 18+ messages in thread
From: Baruch Siach @ 2018-01-02 13:19 UTC (permalink / raw)
  To: Dave Stevenson, Eric Anholt, Stefan Wahren, Linus Walleij
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Baruch Siach

Add a description of the RPi3 GPIO expander that the VC4 firmware controls.

Signed-off-by: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
---
 arch/arm/boot/dts/bcm2837-rpi-3-b.dts | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/bcm2837-rpi-3-b.dts b/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
index b44b3b5af00d..09dca48da2bd 100644
--- a/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
+++ b/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
@@ -23,6 +23,16 @@
 			gpios = <&gpio 47 0>;
 		};
 	};
+
+	soc {
+		expgpio: expgpio {
+			compatible = "brcm,bcm2835-expgpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+			firmware = <&firmware>;
+			status = "okay";
+		};
+	};
 };
 
 /* uart0 communicates with the BT module */
-- 
2.15.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 0/4] gpio: driver for the RPi3 GPIO expander
       [not found] ` <cover.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
  2018-01-02 13:19   ` [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander Baruch Siach
@ 2018-01-02 18:05   ` Stefan Wahren
  1 sibling, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-01-02 18:05 UTC (permalink / raw)
  To: Baruch Siach
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Linus Walleij,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Dave Stevenson, devicetree-u79uwXL29TY76Z2rM5mHXA, Eric Anholt

Hi Baruch,

> Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> hat am 2. Januar 2018 um 14:19 geschrieben:
> 
> 
> The Raspberry Pi 3 has a GPIO expander that controls, among others, the 
> activity LED, and the camera connector GPIOs. The GPIO expander on an I2C bus 
> that is not directly controlled from the ARM core. The VC4 firmware controls 
> the I2C bus, and allows the ARM core to set/get GPIO settings over its mailbox 
> interface.
> 
> This series adds support for the RPi3 expander.
> 
> The driver is ported from the downstream kernel at 
> https://github.com/raspberrypi/linux/, branch rpi-4.9.y.
> 

thanks for trying to upstream this. There has been attemps by Eric Anholt (September 2016) and Michael Zoran (March 2017). Some problems like get_direction() has been fixed, but not all of them.

So please look at the followings links first:
https://patchwork.kernel.org/patch/9339859/
https://patchwork.kernel.org/patch/9339857/
http://lists.infradead.org/pipermail/linux-rpi-kernel/2017-March/005903.html

Stefan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding
  2018-01-02 13:19 ` [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding Baruch Siach
@ 2018-01-02 18:26   ` Stefan Wahren
       [not found]     ` <860502005.181510.1514917560724-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Wahren @ 2018-01-02 18:26 UTC (permalink / raw)
  To: Baruch Siach
  Cc: linux-gpio, linux-rpi-kernel, linux-arm-kernel, devicetree,
	Dave Stevenson, Linus Walleij, Eric Anholt

Hi Baruch,

> Baruch Siach <baruch@tkos.co.il> hat am 2. Januar 2018 um 14:19 geschrieben:
> 
> 
> The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware over
> I2C. The firmware mailbox interface allows the ARM core to control the
> GPIO lines.
> 
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>  .../bindings/gpio/brcm,bcm2835-expgpio.txt         | 24 ++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> 
> diff --git a/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> new file mode 100644
> index 000000000000..55257f31a9be
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> @@ -0,0 +1,24 @@
> +Raspberry Pi GPIO expander
> +
> +The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware. The
> +firmware exposes a mailbox interface that allows the ARM core to control the
> +GPIO lines on the expander.
> +
> +Required properties:
> +
> +- compatible : Should be "brcm,bcm2835-expgpio"

from my understand this driver is specific to the Raspberry Pi and it's vendor is the Raspberry Pi Foundation. So i prefer Eric's suggestion of "raspberrypi,firmware-gpio", which also applies to the filename.

> +- gpio-controller : Marks the device node as a gpio controller
> +- #gpio-cells : Should be two.  The first cell is the pin number, and
> +  the second cell is used to specify the gpio polarity:
> +  0 = active high
> +  1 = active low
> +- firmware : Reference to the RPi firmware device node
> +
> +Example:
> +
> +expgpio: expgpio {
> +	compatible = "brcm,bcm2835-expgpio";
> +	gpio-controller;
> +	#gpio-cells = <2>;
> +	firmware = <&firmware>;
> +};
> -- 
> 2.15.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-02 13:19 ` [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service Baruch Siach
@ 2018-01-02 18:49   ` Stefan Wahren
       [not found]     ` <2013811470.181895.1514918984637-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
  2018-01-03 10:08   ` Linus Walleij
  1 sibling, 1 reply; 18+ messages in thread
From: Stefan Wahren @ 2018-01-02 18:49 UTC (permalink / raw)
  To: Baruch Siach
  Cc: linux-gpio, linux-rpi-kernel, linux-arm-kernel, Dave Stevenson,
	devicetree, Linus Walleij, Eric Anholt

Hi Baruch,

additionally the my comments on Michael's patches in March 2017, some new below.

> Baruch Siach <baruch@tkos.co.il> hat am 2. Januar 2018 um 14:19 geschrieben:
> 
> 
> From: Dave Stevenson <dave.stevenson@raspberrypi.org>
> 
> Pi3 and Compute Module 3 have a GPIO expander that the
> VPU communicates with.
> There is a mailbox service that now allows control of this
> expander, so add a kernel driver that can make use of it.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
>  drivers/gpio/Kconfig        |   7 ++
>  drivers/gpio/Makefile       |   1 +
>  drivers/gpio/gpio-bcm-exp.c | 254 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 262 insertions(+)
>  create mode 100644 drivers/gpio/gpio-bcm-exp.c
> 
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index d6a8e851ad13..e2aab64ea772 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -128,6 +128,13 @@ config GPIO_AXP209
>  	help
>  	  Say yes to enable GPIO support for the AXP209 PMIC
>  
> +config GPIO_BCM_EXP
> +	bool "Broadcom Exp GPIO"

same as in the binding, i don't think this is specific to Broadcom.

> +	depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)

This is too long. Please split up.

> +	help
> +	  Turn on GPIO support for Broadcom chips using the firmware mailbox
> +	  to communicate with VideoCore on BCM283x chips.
> +
>  config GPIO_BCM_KONA
>  	bool "Broadcom Kona GPIO"
>  	depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST)
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 4bc24febb889..c5f481b1d53c 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -33,6 +33,7 @@ obj-$(CONFIG_GPIO_ARIZONA)	+= gpio-arizona.o
>  obj-$(CONFIG_GPIO_ATH79)	+= gpio-ath79.o
>  obj-$(CONFIG_GPIO_ASPEED)	+= gpio-aspeed.o
>  obj-$(CONFIG_GPIO_AXP209)	+= gpio-axp209.o
> +obj-$(CONFIG_GPIO_BCM_EXP)	+= gpio-bcm-exp.o
>  obj-$(CONFIG_GPIO_BCM_KONA)	+= gpio-bcm-kona.o
>  obj-$(CONFIG_GPIO_BD9571MWV)	+= gpio-bd9571mwv.o
>  obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
> diff --git a/drivers/gpio/gpio-bcm-exp.c b/drivers/gpio/gpio-bcm-exp.c
> new file mode 100644
> index 000000000000..d68adafaee4a
> --- /dev/null
> +++ b/drivers/gpio/gpio-bcm-exp.c
> @@ -0,0 +1,254 @@
> +/*
> + *  Broadcom expander GPIO driver
> + *
> + *  Uses the firmware mailbox service to communicate with the
> + *  GPIO expander on the VPU.
> + *
> + *  Copyright (C) 2017 Raspberry Pi Trading Ltd.
> + *
> + *  Author: Dave Stevenson <dave.stevenson@raspberrypi.org>
> + *  Based on gpio-bcm-virt.c by Dom Cobley <popcornmix@gmail.com>
> + *
> + * 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.
> + */

SPDX identifier?

> +
> +#include <linux/err.h>
> +#include <linux/gpio.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> +#include <soc/bcm2835/raspberrypi-firmware.h>
> +
> +#define MODULE_NAME "brcmexp-gpio"
> +#define NUM_GPIO 8
> +
> +struct brcmexp_gpio {
> +	struct gpio_chip gc;
> +	struct device *dev;
> +	struct rpi_firmware *fw;
> +};
> +
> +struct gpio_set_config {
> +	u32 gpio, direction, polarity, term_en, term_pull_up, state;
> +};
> +
> +struct gpio_get_config {
> +	u32 gpio, direction, polarity, term_en, term_pull_up;
> +};
> +
> +struct gpio_get_set_state {
> +	u32 gpio, state;
> +};
> +
> +static int brcmexp_gpio_get_polarity(struct gpio_chip *gc, unsigned int off)
> +{
> +	struct brcmexp_gpio *gpio;
> +	struct gpio_get_config get;
> +	int ret;
> +
> +	gpio = container_of(gc, struct brcmexp_gpio, gc);
> +
> +	get.gpio = off + gpio->gc.base;	/* GPIO to update */

Please don't misuse the gpiochip base to communicate with the firmware. AFAIK the gc.base should be -1 (dynamic), so better use a define for the base.

> +
> +	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
> +				    &get, sizeof(get));
> +	if (ret) {
> +		dev_err(gpio->dev,
> +			"Failed to get GPIO %u config (%d)\n", off, ret);
> +		return ret;
> +	}

Shouldn't we also check the in-bound status at get.gpio?
And in all the other gpio ops?

> ...
> +
> +static int brcmexp_gpio_probe(struct platform_device *pdev)
> +{
> +	int err = 0;
> +	struct device *dev = &pdev->dev;
> +	struct device_node *np = dev->of_node;
> +	struct device_node *fw_node;
> +	struct rpi_firmware *fw;
> +	struct brcmexp_gpio *ucb;
> +
> +	fw_node = of_parse_phandle(np, "firmware", 0);
> +	if (!fw_node) {
> +		dev_err(dev, "Missing firmware node\n");
> +		return -ENOENT;
> +	}
> +
> +	fw = rpi_firmware_get(fw_node);
> +	if (!fw)
> +		return -EPROBE_DEFER;
> +
> +	ucb = devm_kzalloc(dev, sizeof(*ucb), GFP_KERNEL);
> +	if (!ucb)
> +		return -EINVAL;
> +
> +	ucb->fw = fw;
> +	ucb->dev = dev;
> +	ucb->gc.label = MODULE_NAME;
> +	ucb->gc.owner = THIS_MODULE;
> +	ucb->gc.of_node = np;
> +	ucb->gc.base = 128;

As said above this should be -1

Stefan

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

* Re: [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander
       [not found]     ` <a29df633ee568e150c150debde66c0783a57c70a.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
@ 2018-01-02 19:03       ` Stefan Wahren
       [not found]         ` <1524381852.182115.1514919793281-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Wahren @ 2018-01-02 19:03 UTC (permalink / raw)
  To: Baruch Siach
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA, Linus Walleij,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Dave Stevenson, devicetree-u79uwXL29TY76Z2rM5mHXA, Eric Anholt

Hi Baruch,

> Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> hat am 2. Januar 2018 um 14:19 geschrieben:
> 
> 
> Add a description of the RPi3 GPIO expander that the VC4 firmware controls.
> 
> Signed-off-by: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
> ---
>  arch/arm/boot/dts/bcm2837-rpi-3-b.dts | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/bcm2837-rpi-3-b.dts b/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
> index b44b3b5af00d..09dca48da2bd 100644
> --- a/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
> +++ b/arch/arm/boot/dts/bcm2837-rpi-3-b.dts
> @@ -23,6 +23,16 @@
>  			gpios = <&gpio 47 0>;
>  		};
>  	};
> +
> +	soc {

unfortunately this is a common issue of the RPi firmware drivers. These nodes shouldn't be child of the soc, because it's only bound for memory mapped IO. So please move it to the same level as soc. Otherwise we get more warnings with W=1 and Rob Herring gets unhappy.

> +		expgpio: expgpio {
> +			compatible = "brcm,bcm2835-expgpio";
> +			gpio-controller;
> +			#gpio-cells = <2>;
> +			firmware = <&firmware>;

Please add the gpio-line-names from Eric's patch [1].

Thanks
Stefan

[1] - https://patchwork.kernel.org/patch/9339857/

> +			status = "okay";
> +		};
> +	};
>  };
>  
>  /* uart0 communicates with the BT module */
> -- 
> 2.15.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-02 13:19 ` [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service Baruch Siach
  2018-01-02 18:49   ` Stefan Wahren
@ 2018-01-03 10:08   ` Linus Walleij
  2018-01-10  3:45     ` Baruch Siach
  1 sibling, 1 reply; 18+ messages in thread
From: Linus Walleij @ 2018-01-03 10:08 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Dave Stevenson, Eric Anholt, Stefan Wahren, linux-gpio,
	Linux ARM, linux-rpi-kernel,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Tue, Jan 2, 2018 at 2:19 PM, Baruch Siach <baruch@tkos.co.il> wrote:

> +config GPIO_BCM_EXP
> +       bool "Broadcom Exp GPIO"
> +       depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
> +       help
> +         Turn on GPIO support for Broadcom chips using the firmware mailbox
> +         to communicate with VideoCore on BCM283x chips.

Should this be

default RASPBERRYPI_FIRMWARE

So it is always available if the firmware interface is there?

> +#include <linux/err.h>
> +#include <linux/gpio.h>

Just use

#include <linux/driver.h>

> +#define MODULE_NAME "brcmexp-gpio"
> +#define NUM_GPIO 8
> +
> +struct brcmexp_gpio {
> +       struct gpio_chip gc;
> +       struct device *dev;
> +       struct rpi_firmware *fw;
> +};
> +
> +struct gpio_set_config {
> +       u32 gpio, direction, polarity, term_en, term_pull_up, state;
> +};
> +
> +struct gpio_get_config {
> +       u32 gpio, direction, polarity, term_en, term_pull_up;
> +};

Seems to support some pin control stuff, hm?

The pull ups seems unused though so OK.

Yours,
Linus Walleij

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

* Re: [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander
       [not found]         ` <1524381852.182115.1514919793281-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
@ 2018-01-03 20:17           ` Stefan Wahren
  2018-01-03 20:29             ` Phil Elwell
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Wahren @ 2018-01-03 20:17 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Linus Walleij, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi Baruch,

> Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> hat am 2. Januar 2018 um 20:03 geschrieben:
> 
> 
> Hi Baruch,
> 
> > Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> hat am 2. Januar 2018 um 14:19 geschrieben:
> 
> > +		expgpio: expgpio {
> > +			compatible = "brcm,bcm2835-expgpio";
> > +			gpio-controller;
> > +			#gpio-cells = <2>;
> > +			firmware = <&firmware>;
> 
> Please add the gpio-line-names from Eric's patch [1].
> 
> Thanks
> Stefan
> 
> [1] - https://patchwork.kernel.org/patch/9339857/
> 

sorry i missed the fact that the same GPIO expander is on the CM3. So please move the exgpio node to bcm2837.dtsi and only define the gpio-line-names in this file.

Thanks
Stefan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander
  2018-01-03 20:17           ` Stefan Wahren
@ 2018-01-03 20:29             ` Phil Elwell
       [not found]               ` <3993684b-5b99-6c38-6247-999f7564762b-FnsA7b+Nu9XbIbC87yuRow@public.gmane.org>
  0 siblings, 1 reply; 18+ messages in thread
From: Phil Elwell @ 2018-01-03 20:29 UTC (permalink / raw)
  To: Stefan Wahren, Baruch Siach
  Cc: linux-gpio, Linus Walleij, linux-rpi-kernel, linux-arm-kernel,
	devicetree

Hi Stefan,

On 03/01/2018 20:17, Stefan Wahren wrote:
> Hi Baruch,
> 
>> Stefan Wahren <stefan.wahren@i2se.com> hat am 2. Januar 2018 um 20:03 geschrieben:
>>
>>
>> Hi Baruch,
>>
>>> Baruch Siach <baruch@tkos.co.il> hat am 2. Januar 2018 um 14:19 geschrieben:
>>
>>> +		expgpio: expgpio {
>>> +			compatible = "brcm,bcm2835-expgpio";
>>> +			gpio-controller;
>>> +			#gpio-cells = <2>;
>>> +			firmware = <&firmware>;
>>
>> Please add the gpio-line-names from Eric's patch [1].
>>
>> Thanks
>> Stefan
>>
>> [1] - https://patchwork.kernel.org/patch/9339857/
>>
> 
> sorry i missed the fact that the same GPIO expander is on the CM3. So please move the exgpio node to bcm2837.dtsi and only define the gpio-line-names in this file.

The GPIO expander is not a part of the BCM2837 SoC, and not all BCM2837-based Pis have a GPIO expander - see the Pi 2+.

Phil

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

* Re: [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander
       [not found]               ` <3993684b-5b99-6c38-6247-999f7564762b-FnsA7b+Nu9XbIbC87yuRow@public.gmane.org>
@ 2018-01-04  3:06                 ` Peter Robinson
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Robinson @ 2018-01-04  3:06 UTC (permalink / raw)
  To: Phil Elwell
  Cc: Stefan Wahren, Baruch Siach, linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	Linus Walleij, linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA

>>> Stefan Wahren <stefan.wahren-eS4NqCHxEME@public.gmane.org> hat am 2. Januar 2018 um 20:03
>>> geschrieben:
>>>
>>>
>>> Hi Baruch,
>>>
>>>> Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> hat am 2. Januar 2018 um 14:19
>>>> geschrieben:
>>>
>>>
>>>> +               expgpio: expgpio {
>>>> +                       compatible = "brcm,bcm2835-expgpio";
>>>> +                       gpio-controller;
>>>> +                       #gpio-cells = <2>;
>>>> +                       firmware = <&firmware>;
>>>
>>>
>>> Please add the gpio-line-names from Eric's patch [1].
>>>
>>> Thanks
>>> Stefan
>>>
>>> [1] - https://patchwork.kernel.org/patch/9339857/
>>>
>>
>> sorry i missed the fact that the same GPIO expander is on the CM3. So
>> please move the exgpio node to bcm2837.dtsi and only define the
>> gpio-line-names in this file.
>
>
> The GPIO expander is not a part of the BCM2837 SoC, and not all
> BCM2837-based Pis have a GPIO expander - see the Pi 2+.

There's two ways that's generally handled upstream, either just
duplicate across the two .dts files or to put it in a separate .dtsi
and include it in the relevant .dts files, see arch/arm/boot/dts/axp*
as relevant examples.

Peter
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding
       [not found]     ` <860502005.181510.1514917560724-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
@ 2018-01-04 19:35       ` Baruch Siach
  0 siblings, 0 replies; 18+ messages in thread
From: Baruch Siach @ 2018-01-04 19:35 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Dave Stevenson, Linus Walleij,
	Eric Anholt

Hi Stefan,

On Tue, Jan 02, 2018 at 07:26:00PM +0100, Stefan Wahren wrote: 
> > Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> hat am 2. Januar 2018 um 14:19 geschrieben:
> > 
> > 
> > The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware over
> > I2C. The firmware mailbox interface allows the ARM core to control the
> > GPIO lines.
> > 
> > Signed-off-by: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
> > ---
> >  .../bindings/gpio/brcm,bcm2835-expgpio.txt         | 24 ++++++++++++++++++++++
> >  1 file changed, 24 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> > new file mode 100644
> > index 000000000000..55257f31a9be
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/gpio/brcm,bcm2835-expgpio.txt
> > @@ -0,0 +1,24 @@
> > +Raspberry Pi GPIO expander
> > +
> > +The Raspberry Pi 3 GPIO expander is controlled by the VC4 firmware. The
> > +firmware exposes a mailbox interface that allows the ARM core to control the
> > +GPIO lines on the expander.
> > +
> > +Required properties:
> > +
> > +- compatible : Should be "brcm,bcm2835-expgpio"
> 
> from my understand this driver is specific to the Raspberry Pi and it's 
> vendor is the Raspberry Pi Foundation. So i prefer Eric's suggestion of 
> "raspberrypi,firmware-gpio", which also applies to the filename.

That was my inclination as well. But I thought that keeping DT compatibility 
with downstream is desirable.

I'll change compatible/file/driver names to raspberry something.

baruch

> > +- gpio-controller : Marks the device node as a gpio controller
> > +- #gpio-cells : Should be two.  The first cell is the pin number, and
> > +  the second cell is used to specify the gpio polarity:
> > +  0 = active high
> > +  1 = active low
> > +- firmware : Reference to the RPi firmware device node
> > +
> > +Example:
> > +
> > +expgpio: expgpio {
> > +	compatible = "brcm,bcm2835-expgpio";
> > +	gpio-controller;
> > +	#gpio-cells = <2>;
> > +	firmware = <&firmware>;
> > +};

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org - tel: +972.52.368.4656, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
       [not found]     ` <2013811470.181895.1514918984637-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
@ 2018-01-09 13:41       ` Baruch Siach
  2018-01-09 20:15         ` Stefan Wahren
  0 siblings, 1 reply; 18+ messages in thread
From: Baruch Siach @ 2018-01-09 13:41 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: linux-gpio-u79uwXL29TY76Z2rM5mHXA,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Dave Stevenson, devicetree-u79uwXL29TY76Z2rM5mHXA, Linus Walleij,
	Eric Anholt

Hi Stefan,

On Tue, Jan 02, 2018 at 07:49:44PM +0100, Stefan Wahren wrote:

[...]

> > +	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
> > +				    &get, sizeof(get));
> > +	if (ret) {
> > +		dev_err(gpio->dev,
> > +			"Failed to get GPIO %u config (%d)\n", off, ret);
> > +		return ret;
> > +	}
> 
> Shouldn't we also check the in-bound status at get.gpio?

What is the in-bound status value? May you refer me to the documentation?

> And in all the other gpio ops?

Thanks,
baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org - tel: +972.52.368.4656, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-09 13:41       ` Baruch Siach
@ 2018-01-09 20:15         ` Stefan Wahren
  0 siblings, 0 replies; 18+ messages in thread
From: Stefan Wahren @ 2018-01-09 20:15 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Linus Walleij, Eric Anholt, Dave Stevenson, linux-gpio,
	linux-rpi-kernel, linux-arm-kernel, devicetree, phil

Hi Baruch,

> Baruch Siach <baruch@tkos.co.il> hat am 9. Januar 2018 um 14:41 geschrieben:
> 
> 
> Hi Stefan,
> 
> On Tue, Jan 02, 2018 at 07:49:44PM +0100, Stefan Wahren wrote:
> 
> [...]
> 
> > > +	ret = rpi_firmware_property(gpio->fw, RPI_FIRMWARE_GET_GPIO_CONFIG,
> > > +				    &get, sizeof(get));
> > > +	if (ret) {
> > > +		dev_err(gpio->dev,
> > > +			"Failed to get GPIO %u config (%d)\n", off, ret);
> > > +		return ret;
> > > +	}
> > 
> > Shouldn't we also check the in-bound status at get.gpio?
> 
> What is the in-bound status value? May you refer me to the documentation?

unfortunately this mailbox property isn't documented here [1]. So please refer to Phil's explanation [2].

I assume gpio_get_config.gpio of the response would be 0x80000000 in case of an invalid request. But i didn't test it yet.

This was my solution [3] for the RPI_FIRMWARE_GET_CUSTOMER_OTP. But it hadn't been reviewed yet.

Stefan

[1] - https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
[2] - http://lists.infradead.org/pipermail/linux-rpi-kernel/2018-January/007237.html
[3] - https://github.com/lategoodbye/rpi-zero/blob/bcm2835-otp/drivers/nvmem/raspberrypi-otp.c#L61

> 
> > And in all the other gpio ops?
> 
> Thanks,
> baruch
> 
> -- 
>      http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
> =}------------------------------------------------ooO--U--Ooo------------{=
>    - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-03 10:08   ` Linus Walleij
@ 2018-01-10  3:45     ` Baruch Siach
  2018-01-11  9:39       ` Linus Walleij
  0 siblings, 1 reply; 18+ messages in thread
From: Baruch Siach @ 2018-01-10  3:45 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dave Stevenson, Eric Anholt, Stefan Wahren, linux-gpio,
	Linux ARM, linux-rpi-kernel,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

Hi Linus,

On Wed, Jan 03, 2018 at 11:08:15AM +0100, Linus Walleij wrote:
> On Tue, Jan 2, 2018 at 2:19 PM, Baruch Siach <baruch@tkos.co.il> wrote:
> > +#include <linux/err.h>
> > +#include <linux/gpio.h>
> 
> Just use
> 
> #include <linux/driver.h>

You mean linux/gpio/driver.h, right?

I still need linux/gpio.h for GPIOF_DIR_*.

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

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

* Re: [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service
  2018-01-10  3:45     ` Baruch Siach
@ 2018-01-11  9:39       ` Linus Walleij
  0 siblings, 0 replies; 18+ messages in thread
From: Linus Walleij @ 2018-01-11  9:39 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Dave Stevenson, Eric Anholt, Stefan Wahren, linux-gpio,
	Linux ARM, linux-rpi-kernel,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Wed, Jan 10, 2018 at 4:45 AM, Baruch Siach <baruch@tkos.co.il> wrote:
> Hi Linus,
>
> On Wed, Jan 03, 2018 at 11:08:15AM +0100, Linus Walleij wrote:
>> On Tue, Jan 2, 2018 at 2:19 PM, Baruch Siach <baruch@tkos.co.il> wrote:
>> > +#include <linux/err.h>
>> > +#include <linux/gpio.h>
>>
>> Just use
>>
>> #include <linux/driver.h>
>
> You mean linux/gpio/driver.h, right?

Yes.

> I still need linux/gpio.h for GPIOF_DIR_*.

Don't use these, just use 0 and 1 open coded for the
moment (if you check my devel branch, the references to
these flags are gone).

We need to make new defines for the new API.

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-01-11  9:39 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-02 13:19 [PATCH 0/4] gpio: driver for the RPi3 GPIO expander Baruch Siach
2018-01-02 13:19 ` [PATCH 1/4] ARM: bcm2835: sync firmware properties with downstream Baruch Siach
2018-01-02 13:19 ` [PATCH 2/4] dt-bindings: gpio: add raspberry pi GPIO expander binding Baruch Siach
2018-01-02 18:26   ` Stefan Wahren
     [not found]     ` <860502005.181510.1514917560724-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2018-01-04 19:35       ` Baruch Siach
2018-01-02 13:19 ` [PATCH 3/4] bcm2835-gpio-exp: Driver for GPIO expander via mailbox service Baruch Siach
2018-01-02 18:49   ` Stefan Wahren
     [not found]     ` <2013811470.181895.1514918984637-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2018-01-09 13:41       ` Baruch Siach
2018-01-09 20:15         ` Stefan Wahren
2018-01-03 10:08   ` Linus Walleij
2018-01-10  3:45     ` Baruch Siach
2018-01-11  9:39       ` Linus Walleij
     [not found] ` <cover.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
2018-01-02 13:19   ` [PATCH 4/4] ARM: dts: bcm2837-rpi-3-b: add GPIO expander Baruch Siach
     [not found]     ` <a29df633ee568e150c150debde66c0783a57c70a.1514898134.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
2018-01-02 19:03       ` Stefan Wahren
     [not found]         ` <1524381852.182115.1514919793281-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2018-01-03 20:17           ` Stefan Wahren
2018-01-03 20:29             ` Phil Elwell
     [not found]               ` <3993684b-5b99-6c38-6247-999f7564762b-FnsA7b+Nu9XbIbC87yuRow@public.gmane.org>
2018-01-04  3:06                 ` Peter Robinson
2018-01-02 18:05   ` [PATCH 0/4] gpio: driver for the RPi3 " Stefan Wahren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).