gpio: driver for the RPi3 GPIO expander
Subsystems (4)
v5 cover gpio: driver for the RPi3 GPIO expander
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.
This series is based on commit v4.16-rc2.
Changes in v5:
* Remove the 'firmware' property from the binding as suggested by Rob Herring. The firmware node is the parent of the gpio node, so use of_get_parent() instead of a phandle.
Changes in v4:
* Move the gpio expander node under the firmware node; this requires an addtional patch that makes the firmware node into a bus
* Rename the gpio node to just 'gpio'
* Drop the platform driver .owner set
Changes in v3:
* Kconfig tweaks
* Check rpi_exp_gpio_get_polarity() return value
* Redundant header removal
* Redundant platform_set_drvdata() call removal
* Small coding style changes
Changes in v2:
* Driver renamed to gpio-raspberrypi-exp
* Compatible string renamed to "raspberrypi,firmware-gpio"
* Firmware error check
* Smaller tweaks listed in individual patches
Baruch Siach (4):
ARM: bcm2835: sync firmware properties with downstream
dt-bindings: gpio: add raspberry pi GPIO expander binding
ARM: dts: bcm2835: make the firmware node into a bus
ARM: dts: bcm2837-rpi-3-b: add GPIO expander
Dave Stevenson (1):
gpio: raspberrypi-exp: Driver for RPi3 GPIO expander via mailbox
service
.../bindings/gpio/raspberrypi,firmware-gpio.txt | 30 +++ arch/arm/boot/dts/bcm2835-rpi.dtsi | 4 +- arch/arm/boot/dts/bcm2837-rpi-3-b.dts | 17 ++ drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-raspberrypi-exp.c | 252 +++++++++++++++++++++ include/soc/bcm2835/raspberrypi-firmware.h | 18 ++ 7 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt create mode 100644 drivers/gpio/gpio-raspberrypi-exp.c
Signature · 1 line
2.16.1
PATCH v5 1/5 ARM: bcm2835: sync firmware properties with downstream
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.
---
v4: No change
v3: Add Stefan's ack
v2: No change
--- include/soc/bcm2835/raspberrypi-firmware.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/soc/bcm2835/raspberrypi-firmware.h +18 -0
@@ -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,
Signature · 1 line
2.16.1
PATCH v5 1/5 ARM: bcm2835: sync firmware properties with downstream
Quoted 8 lines · 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.
Acked-by Stefan Wahren <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v4: No change
Patch applied to the GPIO tree for v4.17.
But I changed the subject from ARM: to soc:
Yours,
Linus Walleij
PATCH v5 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
In reply to Baruch SiachThe 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.
---
v5:
* Remove the 'firmware' property
* Note that the gpio node is a child of the firmware node
v4:
* Move the example gpio node under the firmware node
* Rename gpio node name to plain 'gpio'
v3:
* Rename node name.
v2:
* Rename compatible string to raspberrypi,firmware-gpio
--- .../bindings/gpio/raspberrypi,firmware-gpio.txt | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +30 -0
@@ -0,0 +1,30 @@ +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. + +The Raspberry Pi GPIO expander node must be a child node of the Raspberry Pi +firmware node. + +Required properties: + +- compatible : Should be "raspberrypi,firmware-gpio" +- 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 + +Example: + +firmware: firmware-rpi { + compatible = "raspberrypi,bcm2835-firmware"; + mboxes = <&mailbox>; + + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; +};
Signature · 1 line
2.16.1
PATCH v5 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
Quoted 17 lines · 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 <[email protected]>---
v5:
* Remove the 'firmware' property
* Note that the gpio node is a child of the firmware nodev4:
* Move the example gpio node under the firmware node
* Rename gpio node name to plain 'gpio'v3:
* Rename node name.
Quoted 6 lines
v2:
* Rename compatible string to raspberrypi,firmware-gpio--- .../bindings/gpio/raspberrypi,firmware-gpio.txt | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt
PATCH v5 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
In reply to Baruch SiachQuoted 9 lines · 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 <[email protected]>---
v5:
* Remove the 'firmware' property
* Note that the gpio node is a child of the firmware node
This v5 patch applied to the GPIO tree for v4.17 with Rob's ACK.
Yours,
Linus Walleij
PATCH v5 3/5 gpio: raspberrypi-exp: Driver for RPi3 GPIO expander via mailbox service
In reply to Baruch SiachFrom: Dave Stevenson <[email protected]>
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.
---
v5:
* Use the parent node to find the firmware
v4:
* Don't set the .owner driver field
* Add Stefan's review tag
v3:
* Tweak Kconfig driver prompt
* Make GPIO_RASPBERRYPI_EXP tristate
* Make COMPILE_TEST independent of RASPBERRYPI_FIRMWARE
* Remove redundant DMA header
* Use less code lines for dev_err()
* Check rpi_exp_gpio_get_polarity() return value
* Remove redundant platform_set_drvdata() call
v2:
* Rename driver to gpio-raspberrypi-exp
* Populate the gpiochip parent device pointer
* Use macro for the mailbox base GPIO number
* Drop linux/gpio.h and GPIOF_DIR_*
* Check and print firmware error value
* Use devm_gpiochip_add_data(); drop .remove
* A few more minor tweaks
--- drivers/gpio/Kconfig | 9 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-raspberrypi-exp.c | 252 ++++++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 drivers/gpio/gpio-raspberrypi-exp.c
drivers/gpio/Kconfig +9 -0
@@ -122,6 +122,15 @@ config GPIO_ATH79 Select this option to enable GPIO driver for Atheros AR71XX/AR724X/AR913X SoC devices. +config GPIO_RASPBERRYPI_EXP + tristate "Raspberry Pi 3 GPIO Expander" + default RASPBERRYPI_FIRMWARE + depends on OF_GPIO + depends on (ARCH_BCM2835 && RASPBERRYPI_FIRMWARE) || COMPILE_TEST + help + Turn on GPIO support for the expander on Raspberry Pi 3 boards, 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)
drivers/gpio/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o +obj-$(CONFIG_GPIO_RASPBERRYPI_EXP) += gpio-raspberrypi-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
drivers/gpio/gpio-raspberrypi-exp.c new file +252 -0
252 lines not on this page · raw message
Signature · 1 line
2.16.1
PATCH v5 3/5 gpio: raspberrypi-exp: Driver for RPi3 GPIO expander via mailbox service
Quoted 7 lines · Baruch Siach
From: Dave Stevenson <[email protected]>
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.
Quoted 6 lines
Reviewed-by Stefan Wahren <[email protected]>Signed-off-by Dave Stevenson <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v5:
* Use the parent node to find the firmware
This v5 version applied to the GPIO tree for v4.17.
Yours,
Linus Walleij
PATCH v5 4/5 ARM: dts: bcm2835: make the firmware node into a bus
In reply to Baruch SiachThis allows adding devices for which the firmware exposes control interface via the mailbox. An example of such device is the GPIO expander.
---
v4: New patch in this series
--- arch/arm/boot/dts/bcm2835-rpi.dtsi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/boot/dts/bcm2835-rpi.dtsi +3 -1
@@ -18,7 +18,9 @@ soc { firmware: firmware { - compatible = "raspberrypi,bcm2835-firmware"; + compatible = "raspberrypi,bcm2835-firmware", "simple-bus"; + #address-cells = <0>; + #size-cells = <0>; mboxes = <&mailbox>; };
Signature · 1 line
2.16.1
PATCH v5 4/5 ARM: dts: bcm2835: make the firmware node into a bus
Quoted 6 lines · Baruch Siach
This allows adding devices for which the firmware exposes control interface via the mailbox. An example of such device is the GPIO expander.
Signed-off-by Baruch Siach <[email protected]>---
v4: New patch in this series
Please funnel this patch through the ARM SoC tree.
Yours,
Linus Walleij
PATCH v5 5/5 ARM: dts: bcm2837-rpi-3-b: add GPIO expander
In reply to Baruch SiachAdd a description of the RPi3 GPIO expander that the VC4 firmware controls.
---
v5:
* Drop the 'firmware' property
v4:
* Move the gpio node under the firmware node
* Rename the gpio node to plain 'gpio'
* Add Stefan's ack
v3:
* List GPIO names one per line.
v2:
* Move GPIO expander node out of the soc container
* Rename compatible string
* Add gpio-line-names property
--- arch/arm/boot/dts/bcm2837-rpi-3-b.dts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm/boot/dts/bcm2837-rpi-3-b.dts +17 -0
@@ -25,6 +25,23 @@ }; }; +&firmware { + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + gpio-line-names = "BT_ON", + "WL_ON", + "STATUS_LED", + "LAN_RUN", + "HPD_N", + "CAM_GPIO0", + "CAM_GPIO1", + "PWR_LOW_N"; + status = "okay"; + }; +}; + /* uart0 communicates with the BT module */ &uart0 { pinctrl-names = "default";
Signature · 1 line
2.16.1
PATCH v5 5/5 ARM: dts: bcm2837-rpi-3-b: add GPIO expander
Quoted 7 lines · Baruch Siach
Add a description of the RPi3 GPIO expander that the VC4 firmware controls.
Acked-by Stefan Wahren <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v5:
* Drop the 'firmware' property
Please funnel this patch through the ARM SoC tree.
Yours,
Linus Walleij
PATCH v5 5/5 ARM: dts: bcm2837-rpi-3-b: add GPIO expander
Quoted 10 lines · Linus Walleij
Quoted 7 lines · Baruch Siach
Add a description of the RPi3 GPIO expander that the VC4 firmware controls.
Acked-by Stefan Wahren <[email protected]>Signed-off-by Baruch Siach <[email protected]>---
v5:
* Drop the 'firmware' property
Quoted 3 lines
Reviewed-by Linus Walleij <[email protected]>Please funnel this patch through the ARM SoC tree.
Picked up the reviews and applied these last 2 to bcm2835-dt-next. I didn't see the gpio tree's for-next updated, so I didn't integration test it personally, but hopefully our branches can come together in -next soon.
(FWIW, I was looking atgit://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for gpio)
Thanks for pushing this to completion, Baruch!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180222/f4ec0701/attachment.sig>