gpio: driver for the RPi3 GPIO expander
Subsystems (4)
v4 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 e237f98a9c.
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 | 29 +++ arch/arm/boot/dts/bcm2835-rpi.dtsi | 4 +- arch/arm/boot/dts/bcm2837-rpi-3-b.dts | 18 ++ 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.15.1
PATCH v4 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.15.1
PATCH v4 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.
---
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 | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +29 -0
@@ -0,0 +1,29 @@ +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 "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 +- firmware : Reference to the RPi firmware device node + +Example: + +firmware: firmware { + compatible = "raspberrypi,bcm2835-firmware"; + mboxes = <&mailbox>; + + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + firmware = <&firmware>; + }; +};
Signature · 1 line
2.15.1
Rob Herring
maintainerPATCH v4 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
Quoted 31 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]>---
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 | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txtDocumentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +5
-0@@ -0,0 +1,29 @@ +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.
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 15
Quoted 10 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +10
-0+ +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 +- firmware : Reference to the RPi firmware device node
This is the parent node. You don't need it.
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 21
Quoted 6 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +6
-0+ +Example: + +firmware: firmware { + compatible = "raspberrypi,bcm2835-firmware"; + mboxes = <&mailbox>;
No, sorry. /firmware is the container of firmware nodes. So something like this:
firmware {
rpi-firmware {
compatible = "raspberrypi,bcm2835-firmware";
mboxes = <&mailbox>;
gpio {
compatible = "raspberrypi,firmware-gpio";
};
};
};Quoted 11 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +8
-0+ + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + firmware = <&firmware>; + }; +};Signature · 1 line
2.15.1
PATCH v4 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
Hi Rob,
Thanks again for reviewing.
Quoted 10 lines · Rob Herring
Quoted 9 lines · Baruch Siach
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +9
-0+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 "raspberrypi,firmware-gpio"
Quoted 8 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 15
Quoted 6 lines
+- gpio-controller : Marks the device node as a gpio controller +- #gpio-cells : Should be two. The first cell is the pin number, andDocumentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +4
-0+ the second cell is used to specify the gpio polarity: + 0 = active high + 1 = active low +- firmware : Reference to the RPi firmware device nodeThis is the parent node. You don't need it.
OK. I guess of_get_parent() will do the trick.
Quoted 9 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +5
-0+Example: + +firmware: firmware { + compatible = "raspberrypi,bcm2835-firmware"; + mboxes = <&mailbox>;No, sorry. /firmware is the container of firmware nodes. So something like this:
Quoted 10 lines
firmware {
rpi-firmware {
compatible = "raspberrypi,bcm2835-firmware";
mboxes = <&mailbox>;
gpio {
compatible = "raspberrypi,firmware-gpio";
};
};
};This is the hierarchy we currently have at arch/arm/boot/dts/bcm2835-rpi.dtsi:
/ {
soc {
firmware: firmware {
compatible = "raspberrypi,bcm2835-firmware";
mboxes = <&mailbox>;
};
};
};Are you suggesting to add another container between 'soc' and 'firmware'? Or is it the 'firmware' node name that we need to change to 'rpi-firmware'?
Quoted 8 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 29
Quoted 8 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +8
-0+ + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + firmware = <&firmware>; + }; +};
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -Rob Herring
maintainerPATCH v4 2/5 dt-bindings: gpio: add raspberry pi GPIO expander binding
Quoted 57 lines · Baruch Siach
Hi Rob,
Thanks again for reviewing.
Quoted 10 lines · Rob Herring
Quoted 9 lines · Baruch Siach
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +9
-0+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 "raspberrypi,firmware-gpio"Quoted 8 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 15
Quoted 6 lines
+- gpio-controller : Marks the device node as a gpio controller +- #gpio-cells : Should be two. The first cell is the pin number, andDocumentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +4
-0+ the second cell is used to specify the gpio polarity: + 0 = active high + 1 = active low +- firmware : Reference to the RPi firmware device nodeThis is the parent node. You don't need it.
OK. I guess
of_get_parent()will do the trick.Quoted 9 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt line 21
Quoted 5 lines
Documentation/devicetree/bindings/gpio/raspberrypi,firmware-gpio.txt new file +5
-0+Example: + +firmware: firmware { + compatible = "raspberrypi,bcm2835-firmware"; + mboxes = <&mailbox>;No, sorry. /firmware is the container of firmware nodes. So something like this:
Quoted 10 lines
firmware { rpi-firmware { compatible = "raspberrypi,bcm2835-firmware"; mboxes = <&mailbox>; gpio { compatible = "raspberrypi,firmware-gpio"; }; }; };This is the hierarchy we currently have at
arch/arm/boot/dts/bcm2835-rpi.dtsi:/ { soc { firmware: firmware { compatible = "raspberrypi,bcm2835-firmware"; mboxes = <&mailbox>; }; }; };
Quoted 2 lines
Are you suggesting to add another container between 'soc' and 'firmware'? Or is it the 'firmware' node name that we need to change to 'rpi-firmware'?
Ah, I guess RPi missed following putting its firmware node under a /firmware node rather than under /soc. We try to put all firmware interfaces (you can have more than one) under /firmware. So just as I wrote out. But you don't need to change that for this.
Just noting this is a child of "raspberrypi,bcm2835-firmware" is enough.
Rob
PATCH v4 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.
---
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.15.1
PATCH v4 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.15.1
PATCH v4 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.
---
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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm/boot/dts/bcm2837-rpi-3-b.dts +18 -0
@@ -25,6 +25,24 @@ }; }; +&firmware { + expgpio: gpio { + compatible = "raspberrypi,firmware-gpio"; + gpio-controller; + #gpio-cells = <2>; + firmware = <&firmware>; + 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.15.1