Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / reset / reset-raspberrypi.c
blob02f59c06f69bb7edffc442a10e8114aefe57457e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Raspberry Pi 4 firmware reset driver
5 * Copyright (C) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
6 */
7 #include <linux/delay.h>
8 #include <linux/device.h>
9 #include <linux/module.h>
10 #include <linux/of.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>
16 struct rpi_reset {
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);
29 u32 dev_addr;
30 int ret;
32 switch (id) {
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
49 * advance.
51 dev_addr = 0x100000;
52 ret = rpi_firmware_property(priv->fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET,
53 &dev_addr, sizeof(dev_addr));
54 if (ret)
55 return ret;
57 /* Wait for vl805 to startup */
58 usleep_range(200, 1000);
59 break;
61 default:
62 return -EINVAL;
65 return 0;
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);
80 if (!np) {
81 dev_err(dev, "Missing firmware node\n");
82 return -ENOENT;
85 fw = rpi_firmware_get(np);
86 of_node_put(np);
87 if (!fw)
88 return -EPROBE_DEFER;
90 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
91 if (!priv)
92 return -ENOMEM;
94 dev_set_drvdata(dev, priv);
96 priv->fw = fw;
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" },
107 { /* sentinel */ }
109 MODULE_DEVICE_TABLE(of, rpi_reset_of_match);
111 static struct platform_driver rpi_reset_driver = {
112 .probe = rpi_reset_probe,
113 .driver = {
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");