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.
Signed-off-by: Eric Anholt <eric@xxxxxxxxxx>
---
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.
Note that I don't think I've done what srwarren wanted for
-EPROBE_DEFER, because I'm not clear what he wants. I think he might
just be asking for a function that does:
/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)
{
struct platform_device *pdev = of_find_device_by_node(of_node);
if (!platform_get_drvdata(pdev))
return -EPROBE_DEFER;
return 0;
}
EXPORT_SYMBOL(rpi_firmware_get)
If that's all, I'm happy to add it.
Note that a client could currently do this:
ret = rpi_firmware_property_list(firmware_node, NULL, 0);
in exchange for a bit of overhead in the case that it's actually probed already.
diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c[...]
+int rpi_firmware_property_list(struct device_node *of_node,[...]
+ void *data, size_t tag_size)
+{
+ struct platform_device *pdev = of_find_device_by_node(of_node);
+ struct rpi_firmware *fw = platform_get_drvdata(pdev);
+ size_t size = tag_size + 12;
+ u32 *buf;
+ dma_addr_t bus_addr;
+ int ret = 0;
+
+ if (!fw)
+ return -EPROBE_DEFER;
+
+ /* Packets are processed a dword at a time. */
+ if (size & 3)
+ return -EINVAL;
+
+ buf = dma_alloc_coherent(fw->cl.dev, PAGE_ALIGN(size), &bus_addr,
+ dma_free_coherent(NULL, PAGE_ALIGN(size), buf, bus_addr);
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ int ret = 0;
+ struct rpi_firmware *fw;
+
+ fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+ if (!fw)
+ return -ENOMEM;
+
+ fw->cl.dev = dev;
+ fw->cl.rx_callback = response_callback;
+ fw->cl.tx_block = true;
+
+ fw->chan = mbox_request_channel(&fw->cl, 0);
+ if (IS_ERR(fw->chan)) {
+ ret = PTR_ERR(fw->chan);
+ /* An -EBUSY from the core means it couldn't find our
+ * channel, because the mailbox driver hadn't
+ * registered yet.
+ */
+ if (ret != -EPROBE_DEFER)
+ dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+ return ret;
+ }