1 // SPDX-License-Identifier: GPL-2.0
3 * Raspberry Pi 4 firmware reset driver
5 * Copyright (C) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
7 #include <linux/delay.h>
8 #include <linux/device.h>
9 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/reset-controller.h>
13 #include <soc/bcm2835/raspberrypi-firmware.h>
14 #include <dt-bindings/reset/raspberrypi,firmware-reset.h>
17 struct reset_controller_dev rcdev;
18 struct rpi_firmware *fw;
21 static inline struct rpi_reset *to_rpi(struct reset_controller_dev *rcdev)
23 return container_of(rcdev, struct rpi_reset, rcdev);
26 static int rpi_reset_reset(struct reset_controller_dev *rcdev, unsigned long id)
28 struct rpi_reset *priv = to_rpi(rcdev);
33 case RASPBERRYPI_FIRMWARE_RESET_ID_USB:
35 * The Raspberry Pi 4 gets its USB functionality from VL805, a
36 * PCIe chip that implements xHCI. After a PCI reset, VL805's
37 * firmware may either be loaded directly from an EEPROM or, if
38 * not present, by the SoC's co-processor, VideoCore. rpi's
39 * VideoCore OS contains both the non public firmware load
40 * logic and the VL805 firmware blob. This triggers the
41 * aforementioned process.
43 * The pci device address is expected is expected by the
44 * firmware encoded like this:
46 * PCI_BUS << 20 | PCI_SLOT << 15 | PCI_FUNC << 12
48 * But since rpi's PCIe is hardwired, we know the address in
52 ret = rpi_firmware_property(priv->fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET,
53 &dev_addr, sizeof(dev_addr));
57 /* Wait for vl805 to startup */
58 usleep_range(200, 1000);
68 static const struct reset_control_ops rpi_reset_ops = {
69 .reset = rpi_reset_reset,
72 static int rpi_reset_probe(struct platform_device *pdev)
74 struct device *dev = &pdev->dev;
75 struct rpi_firmware *fw;
76 struct device_node *np;
77 struct rpi_reset *priv;
79 np = of_get_parent(dev->of_node);
81 dev_err(dev, "Missing firmware node\n");
85 fw = devm_rpi_firmware_get(&pdev->dev, np);
90 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
94 dev_set_drvdata(dev, priv);
97 priv->rcdev.owner = THIS_MODULE;
98 priv->rcdev.nr_resets = RASPBERRYPI_FIRMWARE_RESET_NUM_IDS;
99 priv->rcdev.ops = &rpi_reset_ops;
100 priv->rcdev.of_node = dev->of_node;
102 return devm_reset_controller_register(dev, &priv->rcdev);
105 static const struct of_device_id rpi_reset_of_match[] = {
106 { .compatible = "raspberrypi,firmware-reset" },
109 MODULE_DEVICE_TABLE(of, rpi_reset_of_match);
111 static struct platform_driver rpi_reset_driver = {
112 .probe = rpi_reset_probe,
114 .name = "raspberrypi-reset",
115 .of_match_table = rpi_reset_of_match,
118 module_platform_driver(rpi_reset_driver);
120 MODULE_AUTHOR("Nicolas Saenz Julienne <nsaenzjulienne@suse.de>");
121 MODULE_DESCRIPTION("Raspberry Pi 4 firmware reset driver");
122 MODULE_LICENSE("GPL");