Skip to contentSkip to conversation

dt-bindings: Add a binding for the RPi firmware GPIO driver.

PATCH In review Eric Anholt 5 participants 20 messages Sep 19, 2016 – Oct 6, 2016

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

PATCH 1/3 dt-bindings: Add a binding for the RPi firmware GPIO driver.

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

---
 .../bindings/gpio/gpio-raspberrypi-firmware.txt    | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +22 -0
new file mode 100644
index 000000000000..2b635c23a6f8
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,firmware-gpio"
+- gpio-controller:	Marks the device node as a gpio controller
+- #gpio-cells:		Should be <2> for GPIO number and flags
+- ngpios:		Number of GPIO lines to control.  See gpio.txt
+- firmware:		Reference to the RPi firmware device node
+- raspberrypi,firmware-gpio-offset:
+			Number the firmware uses for the first GPIO line
+			  controlled by this driver
+
+Example:
+fxl6408: firmware-gpio-128 {
+	compatible = "raspberrypi,firmware-gpio";
+	gpio-controller;
+	#gpio-cells = <2>;
+	firmware = <&firmware>;
+	ngpios = <8>;
+	raspberrypi,firmware-gpio-offset = <128>;
+};
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/3 gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

This driver will be used for accessing the FXL6408 GPIO exander on the Pi3. We can't drive it directly from Linux because the firmware is continuously polling one of the expander's lines to do its undervoltage detection.

---
 drivers/gpio/Kconfig                       |   8 ++
 drivers/gpio/Makefile                      |   1 +
 drivers/gpio/gpio-raspberrypi.c            | 159 +++++++++++++++++++++++++++++
 include/soc/bcm2835/raspberrypi-firmware.h |   2 +
 4 files changed, 170 insertions(+)
 create mode 100644 drivers/gpio/gpio-raspberrypi.c
drivers/gpio/Kconfig +8 -0
index fcbd8e318474..60cf38bb3a44 100644
@@ -136,6 +136,14 @@ config GPIO_BCM_KONA
 	help
 	  Turn on GPIO support for Broadcom "Kona" chips.
 
+config GPIO_RASPBERRYPI
+	tristate "Raspberry Pi firmware-based GPIO access"
+	depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
+	help
+	  Turns on support for using the Raspberry Pi firmware to
+	  control GPIO pins.  Used for access to the FXL6408 GPIO
+	  expander on the Pi 3.
+
 config GPIO_BRCMSTB
 	tristate "BRCMSTB GPIO support"
 	default y if (ARCH_BRCMSTB || BMIPS_GENERIC)
drivers/gpio/Makefile +1 -0
index b3e039c3ae8d..fa10cf4030ad 100644
@@ -31,6 +31,7 @@ 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_KONA)	+= gpio-bcm-kona.o
+obj-$(CONFIG_GPIO_RASPBERRYPI)	+= gpio-raspberrypi.o
 obj-$(CONFIG_GPIO_BRCMSTB)	+= gpio-brcmstb.o
 obj-$(CONFIG_GPIO_BT8XX)	+= gpio-bt8xx.o
 obj-$(CONFIG_GPIO_CLPS711X)	+= gpio-clps711x.o
drivers/gpio/gpio-raspberrypi.c new file +159 -0

159 lines not on this page · raw message

include/soc/bcm2835/raspberrypi-firmware.h +2 -0
index 3fb357193f09..671ccd00aea2 100644
@@ -73,11 +73,13 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
 	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
+	RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
 	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_DOMAIN_STATE =                       0x00038030,
+	RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,
 
 	/* Dispmanx TAGS */
 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

Quoted 6 lines · Eric Anholt

This driver will be used for accessing the FXL6408 GPIO exander on the Pi3. We can't drive it directly from Linux because the firmware is continuously polling one of the expander's lines to do its undervoltage detection.

(...)

drivers/gpio/Kconfig config GPIO_BCM_KONA · line 145

Quoted 7 lines
drivers/gpio/Kconfig +7 -0
+config GPIO_RASPBERRYPI
+       tristate "Raspberry Pi firmware-based GPIO access"
+       depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
+       help
+         Turns on support for using the Raspberry Pi firmware to
+         control GPIO pins.  Used for access to the FXL6408 GPIO
+         expander on the Pi 3.

Maybe it should be named GPIO_RPI_FXL6408 ?

(No strong opinion.)

drivers/gpio/gpio-raspberrypi.c line 18

Quoted 2 lines
drivers/gpio/gpio-raspberrypi.c new file +2 -0
+#include <linux/err.h>
+#include <linux/gpio.h>

No, only #include <linux/gpio/driver.h>

drivers/gpio/gpio-raspberrypi.c line 42

Quoted 11 lines
drivers/gpio/gpio-raspberrypi.c new file +11 -0
+static int rpi_gpio_dir_in(struct gpio_chip *gc, unsigned off)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}
+
+static int rpi_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}

IMO this should return OK if you try to set it to the direction that the line is hardwired for in that case, not just fail everything.

If you return errors here, any generic driver that tries to set the line as input or output will fail and then require a second workaround in that driver if it is used on rpi etc etc.

Try to return zero if the consumer asks for the direction that the line is set to.

Also implement .get_direction(). Doing so will show how to do the above two calls in the right way.

Quoted 22 lines
drivers/gpio/gpio-raspberrypi.c new file +22 -0
+static void rpi_gpio_set(struct gpio_chip *gc, unsigned off, int val)
+{
+       struct rpi_gpio *rpi = container_of(gc, struct rpi_gpio, gc);
+       u32 packet[2] = { rpi->offset + off, val };
+       int ret;
+
+       ret = rpi_firmware_property(rpi->firmware,
+                                   RPI_FIRMWARE_SET_GPIO_STATE,
+                                   &packet, sizeof(packet));
+       if (ret)
+               dev_err(rpi->dev, "Error setting GPIO %d state: %d\n", off, ret);
+}
+
+static int rpi_gpio_get(struct gpio_chip *gc, unsigned off)
+{
+       struct rpi_gpio *rpi = container_of(gc, struct rpi_gpio, gc);
+       u32 packet[2] = { rpi->offset + off, 0 };
+       int ret;
+
+       ret = rpi_firmware_property(rpi->firmware,
+                                   RPI_FIRMWARE_GET_GPIO_STATE,
+                                   &packet, sizeof(packet));

drivers/gpio/gpio-raspberrypi.c line 75

Quoted 10 lines
drivers/gpio/gpio-raspberrypi.c new file +10 -0
+       if (ret) {
+               dev_err(rpi->dev, "Error getting GPIO state: %d\n", ret);
+               return ret;
+       } else if (packet[0]) {
+               dev_err(rpi->dev, "Firmware error getting GPIO state: %d\n",
+                       packet[0]);
+               return -EINVAL;
+       } else {
+               return packet[1];
+       }

You can just remove the last } else { } clause and return on a single line.

Please do it like this though:

return !!packet[1];

So you clamp the returned value to a boolean.

Quoted 18 lines
drivers/gpio/gpio-raspberrypi.c new file +18 -0
+static int rpi_gpio_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct device_node *fw_node;
+       struct rpi_gpio *rpi;
+       u32 ngpio;
+       int ret;
+
+       rpi = devm_kzalloc(dev, sizeof *rpi, GFP_KERNEL);
+       if (!rpi)
+               return -ENOMEM;
+       rpi->dev = dev;
+
+       fw_node = of_parse_phandle(np, "firmware", 0);
+       if (!fw_node) {
+               dev_err(dev, "Missing firmware node\n");
+               return -ENOENT;

drivers/gpio/gpio-raspberrypi.c line 105

Quoted 10 lines
drivers/gpio/gpio-raspberrypi.c new file +10 -0
+       }
+
+       rpi->firmware = rpi_firmware_get(fw_node);
+       if (!rpi->firmware)
+               return -EPROBE_DEFER;
+
+       if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpio)) {
+               dev_err(dev, "Missing ngpios");
+               return -ENOENT;
+       }

This is suspect you could skip and just hardcode to 8.

drivers/gpio/gpio-raspberrypi.c line 111

Quoted 6 lines
drivers/gpio/gpio-raspberrypi.c new file +6 -0
+       if (of_property_read_u32(pdev->dev.of_node,
+                                "raspberrypi,firmware-gpio-offset",
+                                &rpi->offset)) {
+               dev_err(dev, "Missing raspberrypi,firmware-gpio-offset");
+               return -ENOENT;
+       }

Can't you just hardcode this into the driver as well?

drivers/gpio/gpio-raspberrypi.c line 118

Quoted 6 lines
drivers/gpio/gpio-raspberrypi.c new file +6 -0
+       rpi->gc.label = np->full_name;
+       rpi->gc.owner = THIS_MODULE;
+       rpi->gc.of_node = np;
+       rpi->gc.ngpio = ngpio;
+       rpi->gc.direction_input = rpi_gpio_dir_in;
+       rpi->gc.direction_output = rpi_gpio_dir_out;

Implement .get_direction()

drivers/gpio/gpio-raspberrypi.c line 125

Quoted 7 lines
drivers/gpio/gpio-raspberrypi.c new file +7 -0
+       rpi->gc.get = rpi_gpio_get;
+       rpi->gc.set = rpi_gpio_set;
+       rpi->gc.can_sleep = true;
+
+       ret = gpiochip_add(&rpi->gc);
+       if (ret)
+               return ret;

Use devm_gpiochip_add_data() and pass NULL as data so you can still use the devm* function.

Quoted 1 line

+ platform_set_drvdata(pdev, rpi);

Should not be needed after that.

drivers/gpio/gpio-raspberrypi.c line 139

Quoted 11 lines
drivers/gpio/gpio-raspberrypi.c new file +11 -0
+       return 0;
+}
+
+static int rpi_gpio_remove(struct platform_device *pdev)
+{
+       struct rpi_gpio *rpi = platform_get_drvdata(pdev);
+
+       gpiochip_remove(&rpi->gc);
+
+       return 0;
+}

Should be possible to drop after using devm_gpiochip_add_data()

Quoted 5 lines
include/soc/bcm2835/raspberrypi-firmware.h +0 -0
index 3fb357193f09..671ccd00aea2 100644

include/soc/bcm2835/raspberrypi-firmware.h enum rpi_firmware_property_tag { · line 82

Quoted 10 lines
include/soc/bcm2835/raspberrypi-firmware.h +2 -0
@@ -73,11 +73,13 @@ enum rpi_firmware_property_tag {
        RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
        RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
        RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
+       RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
        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_DOMAIN_STATE =                       0x00038030,
+       RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,

Can you please merge this orthogonally into the rpi tree to ARM SoC?

Yours,
Linus Walleij

#3 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

Quoted 18 lines · Linus Walleij
Quoted 6 lines · Eric Anholt

This driver will be used for accessing the FXL6408 GPIO exander on the Pi3. We can't drive it directly from Linux because the firmware is continuously polling one of the expander's lines to do its undervoltage detection.

(...)

drivers/gpio/Kconfig config GPIO_BCM_KONA · line 145

Quoted 7 lines
drivers/gpio/Kconfig +7 -0
+config GPIO_RASPBERRYPI
+       tristate "Raspberry Pi firmware-based GPIO access"
+       depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
+       help
+         Turns on support for using the Raspberry Pi firmware to
+         control GPIO pins.  Used for access to the FXL6408 GPIO
+         expander on the Pi 3.
Quoted 3 lines

Maybe it should be named GPIO_RPI_FXL6408 ?

(No strong opinion.)

See DT binding comment -- I think since this driver has no dependency on being to the 6408 on the pi3, we shouldn't needlessly bind it to the FXL6408. (the help comment was just context for why you would want the driver today).

Quoted 19 lines

drivers/gpio/gpio-raspberrypi.c line 42

Quoted 11 lines
drivers/gpio/gpio-raspberrypi.c new file +11 -0
+static int rpi_gpio_dir_in(struct gpio_chip *gc, unsigned off)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}
+
+static int rpi_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}

IMO this should return OK if you try to set it to the direction that the line is hardwired for in that case, not just fail everything.

If you return errors here, any generic driver that tries to set the line as input or output will fail and then require a second workaround in that driver if it is used on rpi etc etc.

Quoted 5 lines

Try to return zero if the consumer asks for the direction that the line is set to.

Also implement .get_direction(). Doing so will show how to do the above two calls in the right way.

I was worried about the lack of direction support. The firmware interface doesn't give me anything for direction, and a get or set of the value doesn't try to set direction.

I can try to bother them to give me support for that, but if they cooperate on that it means that users will only get HDMI detection once they update firmware.

The alternative to new firmware interface would be to provide a bunch of DT saying which of these should be in/out at boot time and refuse to change them after that. That seems like a mess, though.

Quoted 36 lines
Quoted 22 lines
drivers/gpio/gpio-raspberrypi.c new file +22 -0
+static void rpi_gpio_set(struct gpio_chip *gc, unsigned off, int val)
+{
+       struct rpi_gpio *rpi = container_of(gc, struct rpi_gpio, gc);
+       u32 packet[2] = { rpi->offset + off, val };
+       int ret;
+
+       ret = rpi_firmware_property(rpi->firmware,
+                                   RPI_FIRMWARE_SET_GPIO_STATE,
+                                   &packet, sizeof(packet));
+       if (ret)
+               dev_err(rpi->dev, "Error setting GPIO %d state: %d\n", off, ret);
+}
+
+static int rpi_gpio_get(struct gpio_chip *gc, unsigned off)
+{
+       struct rpi_gpio *rpi = container_of(gc, struct rpi_gpio, gc);
+       u32 packet[2] = { rpi->offset + off, 0 };
+       int ret;
+
+       ret = rpi_firmware_property(rpi->firmware,
+                                   RPI_FIRMWARE_GET_GPIO_STATE,
+                                   &packet, sizeof(packet));

drivers/gpio/gpio-raspberrypi.c line 75

Quoted 10 lines
drivers/gpio/gpio-raspberrypi.c new file +10 -0
+       if (ret) {
+               dev_err(rpi->dev, "Error getting GPIO state: %d\n", ret);
+               return ret;
+       } else if (packet[0]) {
+               dev_err(rpi->dev, "Firmware error getting GPIO state: %d\n",
+                       packet[0]);
+               return -EINVAL;
+       } else {
+               return packet[1];
+       }

You can just remove the last } else { } clause and return on a single line.

Quoted 5 lines

Please do it like this though:

return !!packet[1];

So you clamp the returned value to a boolean.

Will do.

Quoted 10 lines

drivers/gpio/gpio-raspberrypi.c line 125

Quoted 7 lines
drivers/gpio/gpio-raspberrypi.c new file +7 -0
+       rpi->gc.get = rpi_gpio_get;
+       rpi->gc.set = rpi_gpio_set;
+       rpi->gc.can_sleep = true;
+
+       ret = gpiochip_add(&rpi->gc);
+       if (ret)
+               return ret;

Use devm_gpiochip_add_data() and pass NULL as data so you can still use the devm* function.

Oh, nice.

Quoted 9 lines
Quoted 9 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
index 3fb357193f09..671ccd00aea2 100644
@@ -73,11 +73,13 @@ enum rpi_firmware_property_tag {
        RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
        RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
        RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
+       RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
Quoted 8 lines

include/soc/bcm2835/raspberrypi-firmware.h enum rpi_firmware_property_tag { · line 82

Quoted 6 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
        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_DOMAIN_STATE =                       0x00038030,
+       RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,

Can you please merge this orthogonally into the rpi tree to ARM SoC?

This driver would appear in the rpi downstream tree once we settle the
driver here. Or are you asking me to delay this series until I can get
them to pull just a patch extending the set of packets?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160923/83848ae6/attachment.sig>

#4 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

Quoted 10 lines · Eric Anholt
Quoted 3 lines · Linus Walleij

Maybe it should be named GPIO_RPI_FXL6408 ?

(No strong opinion.)

See DT binding comment -- I think since this driver has no dependency on being to the 6408 on the pi3, we shouldn't needlessly bind it to the FXL6408. (the help comment was just context for why you would want the driver today).

OK

Quoted 29 lines
Quoted 19 lines

drivers/gpio/gpio-raspberrypi.c line 42

Quoted 11 lines
drivers/gpio/gpio-raspberrypi.c new file +11 -0
+static int rpi_gpio_dir_in(struct gpio_chip *gc, unsigned off)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}
+
+static int rpi_gpio_dir_out(struct gpio_chip *gc, unsigned off, int val)
+{
+       /* We don't have direction control. */
+       return -EINVAL;
+}

IMO this should return OK if you try to set it to the direction that the line is hardwired for in that case, not just fail everything.

If you return errors here, any generic driver that tries to set the line as input or output will fail and then require a second workaround in that driver if it is used on rpi etc etc.

Quoted 5 lines

Try to return zero if the consumer asks for the direction that the line is set to.

Also implement .get_direction(). Doing so will show how to do the above two calls in the right way.

I was worried about the lack of direction support. The firmware interface doesn't give me anything for direction, and a get or set of the value doesn't try to set direction.

Quoted 7 lines

I can try to bother them to give me support for that, but if they cooperate on that it means that users will only get HDMI detection once they update firmware.

The alternative to new firmware interface would be to provide a bunch of DT saying which of these should be in/out at boot time and refuse to change them after that. That seems like a mess, though.

It has to be resolved one way or another I'm afraid.

Do you have an API in place to ask for the firmware version? RPI_FIRMWARE_GET_FIRMWARE_REVISION seems to
exist at least?

In that case try to make some compromise, e.g. if lines 0 and 1 are output and the rest input in a certain firmware version:

struct rpi_gpio {
    (...)
    u8 dirs;
};

if (fw_version <= a)

     rpi->dirs = 0x03;
else if (fw_version > a && fw_version <= b)
    rpi->dirs = 0x07;
else
     /* Ask firmware */

Then in e.g.

static int rpi_gpio_dir_in(struct gpio_chip *gc, unsigned off)

{
     struct rpi_gpio *rpi = gpiochip_get_data(gc);

     if (!(rpi->dirs & BIT(off)))
            return 0;
     return -EINVAL;
}

I think this should be managed by code in the driver like this and not by any DT properties. I suspect also the ngpio number is better to determine from looking at the fw version number.

Quoted 4 lines
Quoted 2 lines

Use devm_gpiochip_add_data() and pass NULL as data so you can still use the devm* function.

Oh, nice.

I forgot this: with devm_gpiochip_add_data() pass struct rpi_gpio * as data then you can just:

static void rpi_gpio_set(struct gpio_chip *gc, unsigned off, int val) {
- struct rpi_gpio *rpi = container_of(gc, struct rpi_gpio, gc);
+ struct rpi_gpio *rpi = gpiochip_get_data(gc);

Applies everywhere.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
index 3fb357193f09..671ccd00aea2 100644
@@ -73,11 +73,13 @@ enum rpi_firmware_property_tag {
        RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
        RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
        RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
+       RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
Quoted 8 lines

include/soc/bcm2835/raspberrypi-firmware.h enum rpi_firmware_property_tag { · line 82

Quoted 6 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
        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_DOMAIN_STATE =                       0x00038030,
+       RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,

Can you please merge this orthogonally into the rpi tree to ARM SoC?

Quoted 3 lines

This driver would appear in the rpi downstream tree once we settle the driver here. Or are you asking me to delay this series until I can get them to pull just a patch extending the set of packets?

Sorry I am not familiar with your development model. I don't know about any RPI downstream tree... What I mean is that the patch to include/soc/bcm2835/raspberrypi-firmware.h should be merged by whoever is maintaining that file, it is not a GPIO file.

If I get an ACK from the maintainer I can take it into the GPIO tree.

Yours,
Linus Walleij

#5 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

Quoted 24 lines · Linus Walleij
Quoted 19 lines · Eric Anholt
Quoted 9 lines · Linus Walleij
Quoted 9 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
index 3fb357193f09..671ccd00aea2 100644
@@ -73,11 +73,13 @@ enum rpi_firmware_property_tag {
        RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
        RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
        RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
+       RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
Quoted 8 lines

include/soc/bcm2835/raspberrypi-firmware.h enum rpi_firmware_property_tag { · line 82

Quoted 6 lines
include/soc/bcm2835/raspberrypi-firmware.h +1 -0
        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_DOMAIN_STATE =                       0x00038030,
+       RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,

Can you please merge this orthogonally into the rpi tree to ARM SoC?

Quoted 3 lines

This driver would appear in the rpi downstream tree once we settle the driver here. Or are you asking me to delay this series until I can get them to pull just a patch extending the set of packets?

Quoted 7 lines

Sorry I am not familiar with your development model. I don't know about any RPI downstream tree... What I mean is that the patch to include/soc/bcm2835/raspberrypi-firmware.h should be merged by whoever is maintaining that file, it is not a GPIO file.

If I get an ACK from the maintainer I can take it into the GPIO tree.

Oh, people often say "the rpi tree" to mean downstream (currently 4.4).
The maintainer of that file upstream is me, and I was hoping you could
merge through your tree.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160924/7d45838e/attachment.sig>

#6 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

Quoted 7 lines · Eric Anholt
Quoted 5 lines · Linus Walleij

Sorry I am not familiar with your development model. I don't know about any RPI downstream tree... What I mean is that the patch to include/soc/bcm2835/raspberrypi-firmware.h should be merged by whoever is maintaining that file, it is not a GPIO file.

Quoted 6 lines
Quoted 2 lines

If I get an ACK from the maintainer I can take it into the GPIO tree.

Oh, people often say "the rpi tree" to mean downstream (currently 4.4). The maintainer of that file upstream is me, and I was hoping you could merge through your tree.

OK no problem, I can merge it once we agree on the mechanics :)

Yours,
Linus Walleij

#7 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

In reply to Eric Anholt
Quoted 20 lines · Eric Anholt
Quoted 18 lines · Linus Walleij
Quoted 6 lines · Eric Anholt

This driver will be used for accessing the FXL6408 GPIO exander on the Pi3. We can't drive it directly from Linux because the firmware is continuously polling one of the expander's lines to do its undervoltage detection.

(...)

Quoted 7 lines
drivers/gpio/Kconfig +7 -0
+config GPIO_RASPBERRYPI
+       tristate "Raspberry Pi firmware-based GPIO access"
+       depends on OF_GPIO && RASPBERRYPI_FIRMWARE && (ARCH_BCM2835 || COMPILE_TEST)
+       help
+         Turns on support for using the Raspberry Pi firmware to
+         control GPIO pins.  Used for access to the FXL6408 GPIO
+         expander on the Pi 3.
Quoted 8 lines
Quoted 3 lines

Maybe it should be named GPIO_RPI_FXL6408 ?

(No strong opinion.)

See DT binding comment -- I think since this driver has no dependency on being to the 6408 on the pi3, we shouldn't needlessly bind it to the FXL6408. (the help comment was just context for why you would want the driver today).

I'd suggest including "FW" or "FIRMWARE" in the Kconfig option too; the Raspberry Pi has multiple GPIO drivers; one accessing the BCM283x HW directly and the other going through the FW. It'd be good if each Kconfig name was pretty explicit re: which one it represented.

#8 lore raw

Re: [PATCH 2/3] gpio: Add a driver for the Raspberry Pi's firmware GPIO calls.

In reply to Eric Anholt

Hi Eric,

Quoted 17 lines

Eric Anholt <[email protected]> hat am 19. September 2016 um 18:13 geschrieben:

This driver will be used for accessing the FXL6408 GPIO exander on the Pi3. We can't drive it directly from Linux because the firmware is continuously polling one of the expander's lines to do its undervoltage detection.

---
...

drivers/gpio/gpio-raspberrypi.c new file +6 -0
+
+static int rpi_gpio_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
+	struct device_node *fw_node;

drivers/gpio/gpio-raspberrypi.c line 92

Quoted 10 lines
drivers/gpio/gpio-raspberrypi.c new file +10 -0
+	struct rpi_gpio *rpi;
+	u32 ngpio;
+	int ret;
+
+	rpi = devm_kzalloc(dev, sizeof *rpi, GFP_KERNEL);
+	if (!rpi)
+		return -ENOMEM;
+	rpi->dev = dev;
+
+	fw_node = of_parse_phandle(np, "firmware", 0);

AFAIK fw_node must be freed with of_node_put() after usage

Quoted 19 lines
drivers/gpio/gpio-raspberrypi.c new file +19 -0
+	if (!fw_node) {
+		dev_err(dev, "Missing firmware node\n");
+		return -ENOENT;
+	}
+
+	rpi->firmware = rpi_firmware_get(fw_node);
+	if (!rpi->firmware)
+		return -EPROBE_DEFER;
+
+	if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpio)) {
+		dev_err(dev, "Missing ngpios");
+		return -ENOENT;
+	}
+	if (of_property_read_u32(pdev->dev.of_node,
+				 "raspberrypi,firmware-gpio-offset",
+				 &rpi->offset)) {
+		dev_err(dev, "Missing raspberrypi,firmware-gpio-offset");
+		return -ENOENT;
+	}

drivers/gpio/gpio-raspberrypi.c line 121

Quoted 10 lines
drivers/gpio/gpio-raspberrypi.c new file +10 -0
+
+	rpi->gc.label = np->full_name;
+	rpi->gc.owner = THIS_MODULE;
+	rpi->gc.of_node = np;
+	rpi->gc.ngpio = ngpio;
+	rpi->gc.direction_input = rpi_gpio_dir_in;
+	rpi->gc.direction_output = rpi_gpio_dir_out;
+	rpi->gc.get = rpi_gpio_get;
+	rpi->gc.set = rpi_gpio_set;
+	rpi->gc.can_sleep = true;

i think it's better to assign rpi->gc.base explicit.

Stefan

#9 lore raw

PATCH 3/3 arm64: Add the Raspberry Pi firmware's interface to the FXL6408.

In reply to Eric Anholt

This gets us hotplug detection of HDMI, so that graphics now works at boot. Tested with watching the output of xrandr while plugging and unplugging the HDMI cable.

---
 arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts +17 -0
index 7841b724e340..2460b47737e9 100644
@@ -23,8 +23,25 @@
 			linux,default-trigger = "default-on";
 		};
 	};
+
+	soc {
+		fxl6408: firmware-gpio-128 {
+			compatible = "raspberrypi,firmware-gpio";
+			gpio-controller;
+			#gpio-cells = <2>;
+			firmware = <&firmware>;
+			ngpios = <8>;
+			gpio-line-names = "BT_ON", "WL_ON", "", "LAN_RUN", "HPD_N", "CAM_GPIO0", "CAM_GPIO1", "PWR_LOW_N";
+
+			raspberrypi,firmware-gpio-offset = <128>;
+		};
+	};
 };
 
 &uart1 {
 	status = "okay";
 };
+
+&hdmi {
+	hpd-gpios = <&fxl6408 4 GPIO_ACTIVE_HIGH>;
+};
Signature · 1 line
2.9.3
Tested-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] arm64: Add the Raspberry Pi firmware's interface to the FXL6408.

Quoted 3 lines · Eric Anholt

This gets us hotplug detection of HDMI, so that graphics now works at boot. Tested with watching the output of xrandr while plugging and unplugging the HDMI cable.

Very nice. Whole patch series:

/me hopes this lands in the 4.9 merge window.

cheers,
Gerd

#11 lore raw

Re: [PATCH 3/3] arm64: Add the Raspberry Pi firmware's interface to the FXL6408.

Quoted 10 lines · Gerd Hoffmann
Quoted 3 lines · Eric Anholt

This gets us hotplug detection of HDMI, so that graphics now works at boot. Tested with watching the output of xrandr while plugging and unplugging the HDMI cable.

Very nice. Whole patch series:

/me hopes this lands in the 4.9 merge window.

Sorry no way. I have comments on the driver and
bindings.

Yours,
Linus Walleij

#12 lore raw
In reply to Eric Anholt
Quoted 6 lines · Eric Anholt

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

Aha

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 1

Quoted 3 lines

+++ b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver

Really? :)

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+Required properties:
+
+- compatible:          Should be "raspberrypi,firmware-gpio"

Usually this is vendor,compat, is the vendors name "raspberrypi"?

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 8

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- gpio-controller:     Marks the device node as a gpio controller
+- #gpio-cells:         Should be <2> for GPIO number and flags
+- ngpios:              Number of GPIO lines to control.  See gpio.txt

Is this ever anything else than 8? Else omit it and hardcode 8 in the driver instead.

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 9

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
+- firmware:            Reference to the RPi firmware device node

Reference the DT binding for this.

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 12

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- raspberrypi,firmware-gpio-offset:
+                       Number the firmware uses for the first GPIO line
+                         controlled by this driver

Does this differ between different instances of this hardware or can it just be open coded in the driver instead?

Yours,
Linus Walleij

#13 lore raw
Quoted 9 lines · Linus Walleij
Quoted 6 lines · Eric Anholt

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

Quoted 7 lines

Aha

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 1

Quoted 3 lines

+++ b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver

Really? :)

Thanks.

Quoted 5 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+Required properties:
+
+- compatible:          Should be "raspberrypi,firmware-gpio"

Usually this is vendor,compat, is the vendors name "raspberrypi"?

Yes, this driver is for part of the Raspberry Pi Foundation's firmware code (you can find the same pattern in the firmware and firmware power domain drivers).

Quoted 6 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 8

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- gpio-controller:     Marks the device node as a gpio controller
+- #gpio-cells:         Should be <2> for GPIO number and flags
+- ngpios:              Number of GPIO lines to control.  See gpio.txt

Is this ever anything else than 8? Else omit it and hardcode 8 in the driver instead.

(see below)

Quoted 10 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 9

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
+- firmware:            Reference to the RPi firmware device node

Reference the DT binding for this.

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 12

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- raspberrypi,firmware-gpio-offset:
+                       Number the firmware uses for the first GPIO line
+                         controlled by this driver

Does this differ between different instances of this hardware or can it just be open coded in the driver instead?

This is which range (128-135) of the firmware's GPIOs we're controlling. If another GPIO expander appears later (quite believable, I think they're down to 1 spare line on this expander), then we would just make another node with a new offset and ngpios for that expander.

Sort of related: I also worry that we have races with the firmware for
the platform GPIO bits, since both ARM and firmware are doing RMWs (or,
even worse, maybe just Ws?) of the registers controlled by the pinctrl
driver. Hopefully I can get the firmware to pass control of devices
like this over to Linux, with firmware making requests to us, but I
don't know if that will happen and we may need to access other GPIOs
using this interface :(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160923/2ef4c585/attachment.sig>

#14 lore raw
Quoted 7 lines · Eric Anholt

Sort of related: I also worry that we have races with the firmware for the platform GPIO bits, since both ARM and firmware are doing RMWs (or, even worse, maybe just Ws?) of the registers controlled by the pinctrl driver. Hopefully I can get the firmware to pass control of devices like this over to Linux, with firmware making requests to us, but I don't know if that will happen and we may need to access other GPIOs using this interface :(

For the race with firmware I have no good solutions, it's just one of those things I guess :(

When two kernel drivers compete about registers, say for example one driver needs to RMW bits 0-5 and another driver needs to RMW bits 7-11, the right solution is usually to use syscon and then regmap-mmio will deal with the concurrency as part of regmap_update_bits() etc.

Yours,
Linus Walleij

#15 lore raw
In reply to Eric Anholt
Quoted 48 lines · Eric Anholt
Quoted 9 lines · Linus Walleij
Quoted 6 lines · Eric Anholt

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

Quoted 7 lines

Aha

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 1

Quoted 3 lines

+++ b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver

Really? :)

Thanks.

Quoted 5 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+Required properties:
+
+- compatible:          Should be "raspberrypi,firmware-gpio"

Usually this is vendor,compat, is the vendors name "raspberrypi"?

Yes, this driver is for part of the Raspberry Pi Foundation's firmware code (you can find the same pattern in the firmware and firmware power domain drivers).

Quoted 6 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 8

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- gpio-controller:     Marks the device node as a gpio controller
+- #gpio-cells:         Should be <2> for GPIO number and flags
+- ngpios:              Number of GPIO lines to control.  See gpio.txt

Is this ever anything else than 8? Else omit it and hardcode 8 in the driver instead.

(see below)

Quoted 8 lines

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 9

Quoted 1 line
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +1 -0
+- firmware:            Reference to the RPi firmware device node

Reference the DT binding for this.

Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +3 -0
+- raspberrypi,firmware-gpio-offset:
+                       Number the firmware uses for the first GPIO line
+                         controlled by this driver
Quoted 7 lines
Quoted 2 lines

Does this differ between different instances of this hardware or can it just be open coded in the driver instead?

This is which range (128-135) of the firmware's GPIOs we're controlling. If another GPIO expander appears later (quite believable, I think they're down to 1 spare line on this expander), then we would just make another node with a new offset and ngpios for that expander.

Why would we make another node for that? Wouldn't we always have a single node to represent the FW's control over GPIOs, and have that node expose all GPIOs that the FW supports. Which GPIO IDs clients actually use will simply be determined by the HW schematic, and kernel-side SW would just act as a conduit to pass those IDs between clients and the FW.

Quoted 7 lines

Sort of related: I also worry that we have races with the firmware for the platform GPIO bits, since both ARM and firmware are doing RMWs (or, even worse, maybe just Ws?) of the registers controlled by the pinctrl driver. Hopefully I can get the firmware to pass control of devices like this over to Linux, with firmware making requests to us, but I don't know if that will happen and we may need to access other GPIOs using this interface :(

Aren't there write-to-set/write-to-clear registers? If not, then either FW owns everything in a particular register or Linux does; the HW won't allow sharing.

#16 lore raw
In reply to Eric Anholt

Hi Eric,

Quoted 24 lines

Eric Anholt <[email protected]> hat am 19. September 2016 um 18:13 geschrieben:

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

---
 .../bindings/gpio/gpio-raspberrypi-firmware.txt    | 22
++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file mode 100644
index 000000000000..2b635c23a6f8

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +5 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,firmware-gpio"

i think the compatible should be more specific like

raspberrypi,rpi3-firmware-gpio

and all information which aren't requestable from the firmware should be stored in a info structure. This makes the driver easier to extend in the future by adding new compatibles and their info structures.

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 12

Quoted 7 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +7 -0
+- gpio-controller:	Marks the device node as a gpio controller
+- #gpio-cells:		Should be <2> for GPIO number and flags
+- ngpios:		Number of GPIO lines to control.  See gpio.txt
+- firmware:		Reference to the RPi firmware device node
+- raspberrypi,firmware-gpio-offset:
+			Number the firmware uses for the first GPIO line
+			  controlled by this driver

We should avoid such properties because they don't really describe the hardware.

Stefan

#17 lore raw
Quoted 34 lines · Stefan Wahren

Hi Eric,

Quoted 24 lines

Eric Anholt <[email protected]> hat am 19. September 2016 um 18:13 geschrieben:

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

---
 .../bindings/gpio/gpio-raspberrypi-firmware.txt    | 22
++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file mode 100644
index 000000000000..2b635c23a6f8

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +5 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,firmware-gpio"

i think the compatible should be more specific like

Quoted 5 lines

raspberrypi,rpi3-firmware-gpio

and all information which aren't requestable from the firmware should be stored in a info structure. This makes the driver easier to extend in the future by adding new compatibles and their info structures.

Is this actually specific to the Pi3 at all? Isn't the FW the same across all Pis; the part that's specific to the Pi3 is whether it's useful to use that API?

As such, I'd suggest just raspberrypi,firmware-gpio as the compatible value.

#18 lore raw
Quoted 41 lines

Stephen Warren <[email protected]> hat am 26. September 2016 um 18:38 geschrieben:

Quoted 35 lines · Stefan Wahren

Hi Eric,

Quoted 25 lines

Eric Anholt <[email protected]> hat am 19. September 2016 um 18:13 geschrieben:

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

---
 .../bindings/gpio/gpio-raspberrypi-firmware.txt    | 22
++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file mode 100644
index 000000000000..2b635c23a6f8

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +5 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,firmware-gpio"

i think the compatible should be more specific like

Quoted 8 lines
Quoted 6 lines

raspberrypi,rpi3-firmware-gpio

and all information which aren't requestable from the firmware should be stored
in a info structure. This makes the driver easier to extend in the future by adding new compatibles and their info structures.

Is this actually specific to the Pi3 at all?

AFAIK only the Raspberry Pi 3 has a GPIO expander which is accessible via the common FW. My suggestion tries to follow the basic guideline "A precise compatible string is better than a vague one" from Device Tree for Dummies [1]. So in case the next Raspberry Pi would have a different GPIO expander with different parameters we could add a new compatible.

But you are right the word order in "rpi3-firmware-gpio" suggests that there are different FW which is wrong. At the end it's only a compatible string. So no strong opinion about the naming.

[1] -
https://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf

Quoted 6 lines

Isn't the FW the same
across all Pis; the part that's specific to the Pi3 is whether it's useful to use that API?

As such, I'd suggest just raspberrypi,firmware-gpio as the compatible value.

#19 lore raw
Quoted 56 lines · Stefan Wahren
Quoted 41 lines

Stephen Warren <[email protected]> hat am 26. September 2016 um 18:38 geschrieben:

Quoted 35 lines · Stefan Wahren

Hi Eric,

Quoted 25 lines

Eric Anholt <[email protected]> hat am 19. September 2016 um 18:13 geschrieben:

The RPi firmware exposes all of the board's GPIO lines through property calls. Linux chooses to control most lines directly through the pinctrl driver, but for the FXL6408 GPIO expander on the Pi3, we need to access them through the firmware.

---
 .../bindings/gpio/gpio-raspberrypi-firmware.txt    | 22
++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt b/Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file mode 100644
index 000000000000..2b635c23a6f8

Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-raspberrypi-firmware.txt new file +5 -0
@@ -0,0 +1,22 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,firmware-gpio"

i think the compatible should be more specific like

Quoted 8 lines
Quoted 6 lines

raspberrypi,rpi3-firmware-gpio

and all information which aren't requestable from the firmware should be stored
in a info structure. This makes the driver easier to extend in the future by adding new compatibles and their info structures.

Is this actually specific to the Pi3 at all?

AFAIK only the Raspberry Pi 3 has a GPIO expander which is accessible via the common FW. My suggestion tries to follow the basic guideline "A precise compatible string is better than a vague one" from Device Tree for Dummies [1]. So in case the next Raspberry Pi would have a different GPIO expander with different parameters we could add a new compatible.

Quoted 6 lines

But you are right the word order in "rpi3-firmware-gpio" suggests that there are different FW which is wrong. At the end it's only a compatible string. So no strong opinion about the naming.

[1] -
https://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf

To deal with that requirement, what you'd want is the following:

RPi 1:
"raspberrypi,firmware-gpio"

RPi 2:
"raspberrypi,rpi2-firmware-gpio", "raspberrypi,firmware-gpio"

RPi 3:
"raspberrypi,rpi3-firmware-gpio", "raspberrypi,firmware-gpio"

Compatible values should always list both the most specific value and the baseline value that it's 100% backwards compatible with.

However, I don't think this argument applies in this case. It isn't the case that there's a separate Pi1 FW, Pi2 FW, Pi3 FW. Rather, there is a single FW image that runs on all (currently existing) Pis. As such, I believe that using solely "raspberrypi,firmware-gpio" is appropriate everywhere, since the thing being described is always the exact same thing with no variance.

This contrasts with HW modules in the SoC, since the different Pis really do have a different SoC, and hence potentially different HW modules, so e.g. compatible = "brcm,bcm2837-i2c", "brcm,bcm2835-i2c" could actually be useful.

Quoted 5 lines
Quoted 5 lines

Isn't the FW the same
across all Pis; the part that's specific to the Pi3 is whether it's useful to use that API?

As such, I'd suggest just raspberrypi,firmware-gpio as the compatible value.