Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: raspberrypi: Introduce vl805 init routine

The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip
that implements xHCI. After a PCI reset, VL805's firmware may either be
loaded directly from an EEPROM or, if not present, by the SoC's
co-processor, VideoCore. RPi4's VideoCore OS contains both the non public
firmware load logic and the VL805 firmware blob. The function this patch
introduces triggers the aforementioned process.

Link: https://lore.kernel.org/r/20200505161318.26200-3-nsaenzjulienne@suse.de
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Rob Herring <robh@kernel.org>

authored by

Nicolas Saenz Julienne and committed by
Lorenzo Pieralisi
fbbc5ff3 ca91ddef

+68
+61
drivers/firmware/raspberrypi.c
··· 12 12 #include <linux/of_platform.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/slab.h> 15 + #include <linux/pci.h> 16 + #include <linux/delay.h> 15 17 #include <soc/bcm2835/raspberrypi-firmware.h> 16 18 17 19 #define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf)) 18 20 #define MBOX_CHAN(msg) ((msg) & 0xf) 19 21 #define MBOX_DATA28(msg) ((msg) & ~0xf) 20 22 #define MBOX_CHAN_PROPERTY 8 23 + 24 + #define VL805_PCI_CONFIG_VERSION_OFFSET 0x50 21 25 22 26 static struct platform_device *rpi_hwmon; 23 27 static struct platform_device *rpi_clk; ··· 289 285 return platform_get_drvdata(pdev); 290 286 } 291 287 EXPORT_SYMBOL_GPL(rpi_firmware_get); 288 + 289 + /* 290 + * The Raspberry Pi 4 gets its USB functionality from VL805, a PCIe chip that 291 + * implements xHCI. After a PCI reset, VL805's firmware may either be loaded 292 + * directly from an EEPROM or, if not present, by the SoC's co-processor, 293 + * VideoCore. RPi4's VideoCore OS contains both the non public firmware load 294 + * logic and the VL805 firmware blob. This function triggers the aforementioned 295 + * process. 296 + */ 297 + int rpi_firmware_init_vl805(struct pci_dev *pdev) 298 + { 299 + struct device_node *fw_np; 300 + struct rpi_firmware *fw; 301 + u32 dev_addr, version; 302 + int ret; 303 + 304 + fw_np = of_find_compatible_node(NULL, NULL, 305 + "raspberrypi,bcm2835-firmware"); 306 + if (!fw_np) 307 + return 0; 308 + 309 + fw = rpi_firmware_get(fw_np); 310 + of_node_put(fw_np); 311 + if (!fw) 312 + return -ENODEV; 313 + 314 + /* 315 + * Make sure we don't trigger a firmware load unnecessarily. 316 + * 317 + * If something went wrong with PCI, this whole exercise would be 318 + * futile as VideoCore expects from us a configured PCI bus. Just take 319 + * the faulty version (likely ~0) and let xHCI's registration fail 320 + * further down the line. 321 + */ 322 + pci_read_config_dword(pdev, VL805_PCI_CONFIG_VERSION_OFFSET, &version); 323 + if (version) 324 + goto exit; 325 + 326 + dev_addr = pdev->bus->number << 20 | PCI_SLOT(pdev->devfn) << 15 | 327 + PCI_FUNC(pdev->devfn) << 12; 328 + 329 + ret = rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_XHCI_RESET, 330 + &dev_addr, sizeof(dev_addr)); 331 + if (ret) 332 + return ret; 333 + 334 + /* Wait for vl805 to startup */ 335 + usleep_range(200, 1000); 336 + 337 + pci_read_config_dword(pdev, VL805_PCI_CONFIG_VERSION_OFFSET, 338 + &version); 339 + exit: 340 + pci_info(pdev, "VL805 firmware version %08x\n", version); 341 + 342 + return 0; 343 + } 344 + EXPORT_SYMBOL_GPL(rpi_firmware_init_vl805); 292 345 293 346 static const struct of_device_id rpi_firmware_of_match[] = { 294 347 { .compatible = "raspberrypi,bcm2835-firmware", },
+7
include/soc/bcm2835/raspberrypi-firmware.h
··· 10 10 #include <linux/of_device.h> 11 11 12 12 struct rpi_firmware; 13 + struct pci_dev; 13 14 14 15 enum rpi_firmware_property_status { 15 16 RPI_FIRMWARE_STATUS_REQUEST = 0, ··· 142 141 int rpi_firmware_property_list(struct rpi_firmware *fw, 143 142 void *data, size_t tag_size); 144 143 struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node); 144 + int rpi_firmware_init_vl805(struct pci_dev *pdev); 145 145 #else 146 146 static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag, 147 147 void *data, size_t len) ··· 159 157 static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node) 160 158 { 161 159 return NULL; 160 + } 161 + 162 + static inline int rpi_firmware_init_vl805(struct pci_dev *pdev) 163 + { 164 + return 0; 162 165 } 163 166 #endif 164 167