Skip to contentSkip to conversation

dt/bindings: Add binding for the Raspberry Pi firmware driver

PATCH Superseded Eric Anholt 2 participants 4 messages May 29, 2015

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/3 dt/bindings: Add binding for the Raspberry Pi firmware driver

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

v2: Improve commit message, point to mailbox.txt for how mboxes work.
v3: Use Lee's suggestion for mailbox phandle docs, fix spelling of
"raspberry".
v4: Change the compatible string to "raspberrypi,bcm2835-firmware"
(requested by Lee, agreed by Stephen)

---
 .../bindings/arm/bcm/raspberrypi,bcm2835-firmware.txt      | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.txt
Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-firmware.txt new file +14 -0
new file mode 100644
index 0000000..5fb1868
@@ -0,0 +1,14 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+
+- compatible:		Should be "rasbperrypi,bcm2835-firmware"
+- mboxes:		Phandle to the firmware device's Mailbox.
+			  (See: ../mailbox/mailbox.txt for more information)
+
+Example:
+
+firmware {
+	compatible = "raspberrypi,bcm2835-firmware";
+	mboxes = <&mailbox>;
+};
Signature · 1 line
2.1.4
#1 lore raw

PATCH v5 2/3 ARM: bcm2835: Add the Raspberry Pi firmware driver

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

v3: Use kernel-doc style for big comments (from Noralf), drop stale
comment, use "dev" when freeing DMA as well.

v4: Move description comment into copyright comment, drop a dead
initialization of "ret", and print the firmware revision at probe time.

v5: Rename the compatible to "raspberrypi,bcm2835-firmware", move
include to not say "property", add functions to get struct rpi_firmware from the device_node and put when done, make property functions take the rpi_firmware instead and never return -EPROBE_DEFER, put the driver under its own RASPBERRYPI_FIRMWARE Kconfig.

---
 drivers/firmware/Kconfig                   |   7 +
 drivers/firmware/Makefile                  |   1 +
 drivers/firmware/raspberrypi.c             | 272 +++++++++++++++++++++++++++++
 include/soc/bcm2835/raspberrypi-firmware.h | 116 ++++++++++++
 4 files changed, 396 insertions(+)
 create mode 100644 drivers/firmware/raspberrypi.c
 create mode 100644 include/soc/bcm2835/raspberrypi-firmware.h
drivers/firmware/Kconfig +7 -0
index 6517132..564aa5b 100644
@@ -136,6 +136,13 @@ config QCOM_SCM
 	bool
 	depends on ARM || ARM64
 
+config RASPBERRYPI_FIRMWARE
+	tristate "Raspberry Pi Firmware Driver"
+	depends on BCM2835_MBOX
+	help
+	  This option enables support for communicating with the firmware on the
+	  Raspberry Pi.
+
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
 
drivers/firmware/Makefile +1 -0
index 3fdd391..ee101a2 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o
 CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
+obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
 
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
drivers/firmware/raspberrypi.c new file +272 -0

272 lines not on this page · raw message

include/soc/bcm2835/raspberrypi-firmware.h new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH v5 2/3] ARM: bcm2835: Add the Raspberry Pi firmware driver

Den 29.05.2015 02:07, skrev Eric Anholt:

Quoted 3 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 3 lines

+/**
+ * rpi_firmware_property_list - Submit firmware property list
+ * @of_node: Pointer to the firmware Device Tree node.

Update kdoc to reflect change:
* @fw: Pointer to firmware structure

Quoted 14 lines

+ * @data: Buffer holding tags.
+ * @tag_size: Size of tags buffer.
+ *
+ * Submits a set of concatenated tags to the VPU firmware through the
+ * mailbox property interface.
+ *
+ * The buffer header and the ending tag are added by this function and
+ * don't need to be supplied, just the actual tags for your operation.
+ * See struct rpi_firmware_property_tag_header for the per-tag
+ * structure.
+ */

drivers/firmware/raspberrypi.c new file +3 -0
+int rpi_firmware_property_list(struct rpi_firmware *fw,
+			       void *data, size_t tag_size)
+{

...

Quoted 3 lines

+/**
+ * rpi_firmware_property - Submit single firmware property
+ * @of_node: Pointer to the firmware Device Tree node.

Same:
* @fw: Pointer to firmware structure

Quoted 14 lines

+ * @tag: One of enum_mbox_property_tag.
+ * @tag_data: Tag data buffer.
+ * @buf_size: Buffer size.
+ *
+ * Submits a single tag to the VPU firmware through the mailbox
+ * property interface.
+ *
+ * This is a convenience wrapper around
+ * rpi_firmware_property_list() to avoid some of the
+ * boilerplate in property calls.
+ */

drivers/firmware/raspberrypi.c new file +3 -0
+int rpi_firmware_property(struct rpi_firmware *fw,
+			  u32 tag, void *tag_data, size_t buf_size)
+{

...

Quoted 4 lines

+/*
+ * Returns the struct rpi_firmware if the firmware device is probed
+ * and available, otherwise NULL.
+ */

kdoc:
/**
* rpi_firmware_get - Get pointer to rpi_firmware structure.
* @of_node: Pointer to the firmware Device Tree node.
*
* Returns NULL is the firmware device is not ready. */

drivers/firmware/raspberrypi.c line 241

Quoted 13 lines
drivers/firmware/raspberrypi.c new file +13 -0
+struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
+{
+	struct platform_device *pdev = of_find_device_by_node(firmware_node);
+
+	if (!pdev)
+		return NULL;
+
+	if (!pdev->dev.driver)
+		return NULL;
+
+	if (!try_module_get(pdev->dev.driver->owner))
+		return NULL;
+

Sigh, I think I was wrong about suggesting try_module_get here. A module can't be
unloaded if another loaded module depends on one it's exported symbols. So this firmware module can't be unloaded if a client module is loaded. So it shouldn't be necessary.

drivers/firmware/raspberrypi.c line 252

Quoted 11 lines
drivers/firmware/raspberrypi.c new file +11 -0
+	return platform_get_drvdata(pdev);
+}
+EXPORT_SYMBOL_GPL(rpi_firmware_get);
+
+void rpi_firmware_put(struct rpi_firmware *fw)
+{
+	struct device *dev = fw->cl.dev;
+
+	module_put(dev->driver->owner);
+}
+EXPORT_SYMBOL_GPL(rpi_firmware_put);

So rpi_firmware_put() won't be needed then, sorry.

However the API feels much better now with this change.

#3 lore raw

PATCH v5 3/3 ARM: bcm2835: Add the firmware driver information to the RPi DT

In reply to Eric Anholt

v2: Drop pm-domains stuff since I've dropped it from the firmware
driver for now, until we get drivers/base fixed.

v3: Rename the compatible to "raspberrypi,bcm2835-firmware"

---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +7 -0
index 46780bb..ab5474e 100644
@@ -14,6 +14,13 @@
 			linux,default-trigger = "heartbeat";
 		};
 	};
+
+	soc {
+		firmware: firmware {
+			compatible = "raspberrypi,bcm2835-firmware";
+			mboxes = <&mailbox>;
+		};
+	};
 };
 
 &gpio {
Signature · 1 line
2.1.4