apm821xx: switch to pending xhci-pci-renesas solution
[openwrt/staging/chunkeey.git] / target / linux / apm821xx / patches-5.4 / 104-usb-xhci-provide-a-debugfs-hook-for-erasing-rom.patch
1 From d6e220fb600a6b1f73155b541aa9826ec75d4559 Mon Sep 17 00:00:00 2001
2 From: Vinod Koul <vkoul@kernel.org>
3 Date: Mon, 13 Jan 2020 14:10:05 +0530
4 Subject: [PATCH 104/104] usb: xhci: provide a debugfs hook for erasing rom
5
6 run "echo 1 > /sys/kernel/debug/renesas-usb/rom_erase" to erase firmware
7 when driver is loaded.
8
9 Subsequent init of driver shall reload the firmware
10
11 Signed-off-by: Vinod Koul <vkoul@kernel.org>
12 Signed-off-by: Christian Lamparter <chunkeey@gmail.com> [5.4 backport]
13 ---
14 drivers/usb/host/xhci-pci-renesas.c | 35 +++++++++++++++++++++++++++++
15 1 file changed, 35 insertions(+)
16
17 --- a/drivers/usb/host/xhci-pci-renesas.c
18 +++ b/drivers/usb/host/xhci-pci-renesas.c
19 @@ -2,6 +2,7 @@
20 /* Copyright (C) 2019-2020 Linaro Limited */
21
22 #include <linux/acpi.h>
23 +#include <linux/debugfs.h>
24 #include <linux/firmware.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 @@ -229,6 +230,9 @@ static int renesas_fw_verify(struct pci_
28
29 return 0;
30 }
31 +
32 +static void debugfs_init(struct pci_dev *pdev);
33 +
34 static int renesas_check_rom_state(struct pci_dev *pdev)
35 {
36 const struct renesas_fw_entry *entry;
37 @@ -252,6 +256,7 @@ static int renesas_check_rom_state(struc
38 if (version == entry->expected_version) {
39 dev_dbg(&pdev->dev, "Detected valid ROM version..\n");
40 valid_version = true;
41 + debugfs_init(pdev);
42 }
43 }
44 if (valid_version == false)
45 @@ -536,6 +541,34 @@ static void renesas_rom_erase(struct pci
46 dev_dbg(&pdev->dev, "ROM Erase... Done success\n");
47 }
48
49 +static int debugfs_rom_erase(void *data, u64 value)
50 +{
51 + struct pci_dev *pdev = data;
52 +
53 + if (value == 1) {
54 + dev_dbg(&pdev->dev, "Userspace requested ROM erase\n");
55 + renesas_rom_erase(pdev);
56 + return 0;
57 + }
58 + return -EINVAL;
59 +}
60 +DEFINE_DEBUGFS_ATTRIBUTE(rom_erase_ops, NULL, debugfs_rom_erase, "%llu\n");
61 +
62 +static struct dentry *debugfs_root;
63 +
64 +static void debugfs_init(struct pci_dev *pdev)
65 +{
66 + debugfs_root = debugfs_create_dir("renesas-usb", NULL);
67 +
68 + debugfs_create_file("rom_erase", 0200, debugfs_root,
69 + pdev, &rom_erase_ops);
70 +}
71 +
72 +static void debugfs_exit(void)
73 +{
74 + debugfs_remove_recursive(debugfs_root);
75 +}
76 +
77 static bool renesas_download_rom(struct pci_dev *pdev,
78 const u32 *fw, size_t step)
79 {
80 @@ -889,6 +922,8 @@ static int renesas_xhci_pci_probe(struct
81
82 static void renesas_xhci_pci_remove(struct pci_dev *dev)
83 {
84 + debugfs_exit();
85 +
86 if (renesas_fw_alive_check(dev)) {
87 /*
88 * bail out early, if this was a renesas device w/o FW.