blob: cdeeacaff15c5e3e309dde54232e24931a6e904d [file] [log] [blame]
developer00bd07d2021-06-24 09:20:42 +08001From 5ca0fcdea508f0d55153baed58d1fb88d7bf0678 Mon Sep 17 00:00:00 2001
2From: Zhanyong Wang <zhanyong.wang@mediatek.com>
3Date: Thu, 17 Jun 2021 16:09:04 +0800
4Subject: [PATCH] [PATCH][PATCH 1/1] usb: add embedded Host feature support
5
6add EH(Embedded Host) feature for PET authentication
71. need CONFIG_USB_OTG_WHITELIST enable
8 CONFIG_USB_OTG_WHITELIST=y
9
102. host device tree node need include "tpl-support" keyword
11 &xhci {
12 tpl-support;
13 }
14
15Signed-off-by: Zhanyong Wang <zhanyong.wang@mediatek.com>
16---
17 drivers/usb/core/hub.c | 9 +++++---
18 drivers/usb/core/otg_whitelist.h | 39 ++++++++++++++++++++++++++++++++
19 drivers/usb/host/xhci-mtk.c | 3 +++
20 3 files changed, 48 insertions(+), 3 deletions(-)
21
22diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
23index cd61860cada5..aa0131aae89c 100644
24--- a/drivers/usb/core/hub.c
25+++ b/drivers/usb/core/hub.c
26@@ -2413,6 +2413,8 @@ static int usb_enumerate_device(struct usb_device *udev)
27 if (err < 0)
28 dev_dbg(&udev->dev, "HNP fail, %d\n", err);
29 }
30+
31+ dev_info(&udev->dev, "Unsupported Device!\n");
32 return -ENOTSUPP;
33 }
34
35@@ -4728,9 +4730,10 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
36 goto fail;
37 }
38 if (r) {
39- if (r != -ENODEV)
40- dev_err(&udev->dev, "device descriptor read/64, error %d\n",
41- r);
42+ if (r != -ENODEV) {
43+ dev_err(&udev->dev, "device descriptor read/64, error %d\n", r);
44+ dev_info(&udev->dev, "Device No Respond\n");
45+ }
46 retval = -EMSGSIZE;
47 continue;
48 }
49diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h
50index 2ae90158ded7..a8dd221334c1 100644
51--- a/drivers/usb/core/otg_whitelist.h
52+++ b/drivers/usb/core/otg_whitelist.h
53@@ -39,9 +39,44 @@ static struct usb_device_id whitelist_table[] = {
54 { USB_DEVICE(0x0525, 0xa4a0), },
55 #endif
56
57+/* xhci-mtk usb3 root-hub */
58+{ USB_DEVICE(0x1d6b, 0x0003), },
59+
60+/* xhci-mtk usb2 root-hub */
61+{ USB_DEVICE(0x1d6b, 0x0002), },
62+
63+/* */
64+{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, 0, 0) },
65+
66 { } /* Terminating entry */
67 };
68
69+static bool usb_match_any_interface(struct usb_device *udev,
70+ const struct usb_device_id *id)
71+{
72+ unsigned int i;
73+
74+ for (i = 0; i < udev->descriptor.bNumConfigurations; ++i) {
75+ struct usb_host_config *cfg = &udev->config[i];
76+ unsigned int j;
77+
78+ for (j = 0; j < cfg->desc.bNumInterfaces; ++j) {
79+ struct usb_interface_cache *cache;
80+ struct usb_host_interface *intf;
81+
82+ cache = cfg->intf_cache[j];
83+ if (cache->num_altsetting == 0)
84+ continue;
85+
86+ intf = &cache->altsetting[0];
87+ if (id->bInterfaceClass == intf->desc.bInterfaceClass)
88+ return true;
89+ }
90+ }
91+
92+ return false;
93+}
94+
95 static int is_targeted(struct usb_device *dev)
96 {
97 struct usb_device_id *id = whitelist_table;
98@@ -90,6 +125,10 @@ static int is_targeted(struct usb_device *dev)
99 (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
100 continue;
101
102+ if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_INFO) &&
103+ !usb_match_any_interface(dev, id))
104+ continue;
105+
106 return 1;
107 }
108
109diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
110index 5c0eb35cd007..5714103fd3b9 100644
111--- a/drivers/usb/host/xhci-mtk.c
112+++ b/drivers/usb/host/xhci-mtk.c
113@@ -18,6 +18,7 @@
114 #include <linux/pm_runtime.h>
115 #include <linux/regmap.h>
116 #include <linux/regulator/consumer.h>
117+#include <linux/usb/of.h>
118
119 #include "xhci.h"
120 #include "xhci-mtk.h"
121@@ -559,6 +560,8 @@ static int xhci_mtk_probe(struct platform_device *pdev)
122 goto disable_device_wakeup;
123 }
124
125+ hcd->tpl_support = of_usb_host_tpl_support(node);
126+ xhci->shared_hcd->tpl_support = hcd->tpl_support;
127 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
128 if (ret)
129 goto put_usb3_hcd;
130--
1312.18.0
132