diff options
Diffstat (limited to 'drivers/usb')
194 files changed, 7875 insertions, 4307 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index cf1b19bca306..ae481c37a208 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig | |||
@@ -149,4 +149,14 @@ source "drivers/usb/phy/Kconfig" | |||
149 | 149 | ||
150 | source "drivers/usb/gadget/Kconfig" | 150 | source "drivers/usb/gadget/Kconfig" |
151 | 151 | ||
152 | config USB_LED_TRIG | ||
153 | bool "USB LED Triggers" | ||
154 | depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS | ||
155 | help | ||
156 | This option adds LED triggers for USB host and/or gadget activity. | ||
157 | |||
158 | Say Y here if you are working on a system with led-class supported | ||
159 | LEDs and you want to use them as activity indicators for USB host or | ||
160 | gadget. | ||
161 | |||
152 | endif # USB_SUPPORT | 162 | endif # USB_SUPPORT |
diff --git a/drivers/usb/README b/drivers/usb/README index 284f46b3e1cc..2144e7dbfa41 100644 --- a/drivers/usb/README +++ b/drivers/usb/README | |||
@@ -24,7 +24,7 @@ Here is a list of what each subdirectory here is, and what is contained in | |||
24 | them. | 24 | them. |
25 | 25 | ||
26 | core/ - This is for the core USB host code, including the | 26 | core/ - This is for the core USB host code, including the |
27 | usbfs files and the hub class driver ("khubd"). | 27 | usbfs files and the hub class driver ("hub_wq"). |
28 | 28 | ||
29 | host/ - This is for USB host controller drivers. This | 29 | host/ - This is for USB host controller drivers. This |
30 | includes UHCI, OHCI, EHCI, and others that might | 30 | includes UHCI, OHCI, EHCI, and others that might |
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 9563cb56d564..ea40626e0246 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h | |||
@@ -99,10 +99,10 @@ enum ci_role { | |||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * struct ci_role_driver - host/gadget role driver | 101 | * struct ci_role_driver - host/gadget role driver |
102 | * start: start this role | 102 | * @start: start this role |
103 | * stop: stop this role | 103 | * @stop: stop this role |
104 | * irq: irq handler for this role | 104 | * @irq: irq handler for this role |
105 | * name: role name string (host/gadget) | 105 | * @name: role name string (host/gadget) |
106 | */ | 106 | */ |
107 | struct ci_role_driver { | 107 | struct ci_role_driver { |
108 | int (*start)(struct ci_hdrc *); | 108 | int (*start)(struct ci_hdrc *); |
@@ -245,6 +245,7 @@ static inline void ci_role_stop(struct ci_hdrc *ci) | |||
245 | 245 | ||
246 | /** | 246 | /** |
247 | * hw_read: reads from a hw register | 247 | * hw_read: reads from a hw register |
248 | * @ci: the controller | ||
248 | * @reg: register index | 249 | * @reg: register index |
249 | * @mask: bitfield mask | 250 | * @mask: bitfield mask |
250 | * | 251 | * |
@@ -277,6 +278,7 @@ static inline void __hw_write(struct ci_hdrc *ci, u32 val, | |||
277 | 278 | ||
278 | /** | 279 | /** |
279 | * hw_write: writes to a hw register | 280 | * hw_write: writes to a hw register |
281 | * @ci: the controller | ||
280 | * @reg: register index | 282 | * @reg: register index |
281 | * @mask: bitfield mask | 283 | * @mask: bitfield mask |
282 | * @data: new value | 284 | * @data: new value |
@@ -293,6 +295,7 @@ static inline void hw_write(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
293 | 295 | ||
294 | /** | 296 | /** |
295 | * hw_test_and_clear: tests & clears a hw register | 297 | * hw_test_and_clear: tests & clears a hw register |
298 | * @ci: the controller | ||
296 | * @reg: register index | 299 | * @reg: register index |
297 | * @mask: bitfield mask | 300 | * @mask: bitfield mask |
298 | * | 301 | * |
@@ -309,6 +312,7 @@ static inline u32 hw_test_and_clear(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
309 | 312 | ||
310 | /** | 313 | /** |
311 | * hw_test_and_write: tests & writes a hw register | 314 | * hw_test_and_write: tests & writes a hw register |
315 | * @ci: the controller | ||
312 | * @reg: register index | 316 | * @reg: register index |
313 | * @mask: bitfield mask | 317 | * @mask: bitfield mask |
314 | * @data: new value | 318 | * @data: new value |
@@ -327,6 +331,8 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
327 | /** | 331 | /** |
328 | * ci_otg_is_fsm_mode: runtime check if otg controller | 332 | * ci_otg_is_fsm_mode: runtime check if otg controller |
329 | * is in otg fsm mode. | 333 | * is in otg fsm mode. |
334 | * | ||
335 | * @ci: chipidea device | ||
330 | */ | 336 | */ |
331 | static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci) | 337 | static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci) |
332 | { | 338 | { |
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index 65444b02bd68..a7ab0f15926e 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c | |||
@@ -54,6 +54,7 @@ struct ci_hdrc_imx_data { | |||
54 | 54 | ||
55 | static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) | 55 | static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) |
56 | { | 56 | { |
57 | struct platform_device *misc_pdev; | ||
57 | struct device_node *np = dev->of_node; | 58 | struct device_node *np = dev->of_node; |
58 | struct of_phandle_args args; | 59 | struct of_phandle_args args; |
59 | struct imx_usbmisc_data *data; | 60 | struct imx_usbmisc_data *data; |
@@ -79,8 +80,15 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) | |||
79 | } | 80 | } |
80 | 81 | ||
81 | data->index = args.args[0]; | 82 | data->index = args.args[0]; |
83 | |||
84 | misc_pdev = of_find_device_by_node(args.np); | ||
82 | of_node_put(args.np); | 85 | of_node_put(args.np); |
83 | 86 | ||
87 | if (!misc_pdev) | ||
88 | return ERR_PTR(-EPROBE_DEFER); | ||
89 | |||
90 | data->dev = &misc_pdev->dev; | ||
91 | |||
84 | if (of_find_property(np, "disable-over-current", NULL)) | 92 | if (of_find_property(np, "disable-over-current", NULL)) |
85 | data->disable_oc = 1; | 93 | data->disable_oc = 1; |
86 | 94 | ||
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.h b/drivers/usb/chipidea/ci_hdrc_imx.h index 996ec93467b2..4ed828f75a1e 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.h +++ b/drivers/usb/chipidea/ci_hdrc_imx.h | |||
@@ -13,6 +13,7 @@ | |||
13 | #define __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H | 13 | #define __DRIVER_USB_CHIPIDEA_CI_HDRC_IMX_H |
14 | 14 | ||
15 | struct imx_usbmisc_data { | 15 | struct imx_usbmisc_data { |
16 | struct device *dev; | ||
16 | int index; | 17 | int index; |
17 | 18 | ||
18 | unsigned int disable_oc:1; /* over current detect disabled */ | 19 | unsigned int disable_oc:1; /* over current detect disabled */ |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 619d13e29995..3df5005c554d 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -139,6 +139,8 @@ static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) | |||
139 | /** | 139 | /** |
140 | * hw_read_intr_enable: returns interrupt enable register | 140 | * hw_read_intr_enable: returns interrupt enable register |
141 | * | 141 | * |
142 | * @ci: the controller | ||
143 | * | ||
142 | * This function returns register data | 144 | * This function returns register data |
143 | */ | 145 | */ |
144 | u32 hw_read_intr_enable(struct ci_hdrc *ci) | 146 | u32 hw_read_intr_enable(struct ci_hdrc *ci) |
@@ -149,6 +151,8 @@ u32 hw_read_intr_enable(struct ci_hdrc *ci) | |||
149 | /** | 151 | /** |
150 | * hw_read_intr_status: returns interrupt status register | 152 | * hw_read_intr_status: returns interrupt status register |
151 | * | 153 | * |
154 | * @ci: the controller | ||
155 | * | ||
152 | * This function returns register data | 156 | * This function returns register data |
153 | */ | 157 | */ |
154 | u32 hw_read_intr_status(struct ci_hdrc *ci) | 158 | u32 hw_read_intr_status(struct ci_hdrc *ci) |
@@ -176,6 +180,8 @@ int hw_port_test_set(struct ci_hdrc *ci, u8 mode) | |||
176 | /** | 180 | /** |
177 | * hw_port_test_get: reads port test mode value | 181 | * hw_port_test_get: reads port test mode value |
178 | * | 182 | * |
183 | * @ci: the controller | ||
184 | * | ||
179 | * This function returns port test mode value | 185 | * This function returns port test mode value |
180 | */ | 186 | */ |
181 | u8 hw_port_test_get(struct ci_hdrc *ci) | 187 | u8 hw_port_test_get(struct ci_hdrc *ci) |
@@ -295,7 +301,7 @@ static void hw_phymode_configure(struct ci_hdrc *ci) | |||
295 | /** | 301 | /** |
296 | * ci_usb_phy_init: initialize phy according to different phy type | 302 | * ci_usb_phy_init: initialize phy according to different phy type |
297 | * @ci: the controller | 303 | * @ci: the controller |
298 | * | 304 | * |
299 | * This function returns an error code if usb_phy_init has failed | 305 | * This function returns an error code if usb_phy_init has failed |
300 | */ | 306 | */ |
301 | static int ci_usb_phy_init(struct ci_hdrc *ci) | 307 | static int ci_usb_phy_init(struct ci_hdrc *ci) |
@@ -473,6 +479,10 @@ static int ci_get_platdata(struct device *dev, | |||
473 | PTR_ERR(platdata->reg_vbus)); | 479 | PTR_ERR(platdata->reg_vbus)); |
474 | return PTR_ERR(platdata->reg_vbus); | 480 | return PTR_ERR(platdata->reg_vbus); |
475 | } | 481 | } |
482 | /* Get TPL support */ | ||
483 | if (!platdata->tpl_support) | ||
484 | platdata->tpl_support = | ||
485 | of_usb_host_tpl_support(dev->of_node); | ||
476 | } | 486 | } |
477 | 487 | ||
478 | if (of_usb_get_maximum_speed(dev->of_node) == USB_SPEED_FULL) | 488 | if (of_usb_get_maximum_speed(dev->of_node) == USB_SPEED_FULL) |
@@ -658,7 +668,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
658 | goto deinit_phy; | 668 | goto deinit_phy; |
659 | } | 669 | } |
660 | 670 | ||
661 | if (ci->is_otg) { | 671 | if (ci->is_otg && ci->roles[CI_ROLE_GADGET]) { |
662 | /* Disable and clear all OTG irq */ | 672 | /* Disable and clear all OTG irq */ |
663 | hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, | 673 | hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, |
664 | OTGSC_INT_STATUS_BITS); | 674 | OTGSC_INT_STATUS_BITS); |
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index a93d950e9468..ebde7b6ce687 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c | |||
@@ -59,7 +59,8 @@ static int host_start(struct ci_hdrc *ci) | |||
59 | hcd->has_tt = 1; | 59 | hcd->has_tt = 1; |
60 | 60 | ||
61 | hcd->power_budget = ci->platdata->power_budget; | 61 | hcd->power_budget = ci->platdata->power_budget; |
62 | hcd->phy = ci->transceiver; | 62 | hcd->usb_phy = ci->transceiver; |
63 | hcd->tpl_support = ci->platdata->tpl_support; | ||
63 | 64 | ||
64 | ehci = hcd_to_ehci(hcd); | 65 | ehci = hcd_to_ehci(hcd); |
65 | ehci->caps = ci->hw_bank.cap; | 66 | ehci->caps = ci->hw_bank.cap; |
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index b8125aa64ad8..0444d3f8971a 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -627,7 +627,7 @@ __acquires(hwep->lock) | |||
627 | 627 | ||
628 | if (hwreq->req.complete != NULL) { | 628 | if (hwreq->req.complete != NULL) { |
629 | spin_unlock(hwep->lock); | 629 | spin_unlock(hwep->lock); |
630 | hwreq->req.complete(&hwep->ep, &hwreq->req); | 630 | usb_gadget_giveback_request(&hwep->ep, &hwreq->req); |
631 | spin_lock(hwep->lock); | 631 | spin_lock(hwep->lock); |
632 | } | 632 | } |
633 | } | 633 | } |
@@ -922,7 +922,7 @@ __acquires(hwep->lock) | |||
922 | if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && | 922 | if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && |
923 | hwreq->req.length) | 923 | hwreq->req.length) |
924 | hweptemp = hwep->ci->ep0in; | 924 | hweptemp = hwep->ci->ep0in; |
925 | hwreq->req.complete(&hweptemp->ep, &hwreq->req); | 925 | usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req); |
926 | spin_lock(hwep->lock); | 926 | spin_lock(hwep->lock); |
927 | } | 927 | } |
928 | } | 928 | } |
@@ -1347,7 +1347,7 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
1347 | 1347 | ||
1348 | if (hwreq->req.complete != NULL) { | 1348 | if (hwreq->req.complete != NULL) { |
1349 | spin_unlock(hwep->lock); | 1349 | spin_unlock(hwep->lock); |
1350 | hwreq->req.complete(&hwep->ep, &hwreq->req); | 1350 | usb_gadget_giveback_request(&hwep->ep, &hwreq->req); |
1351 | spin_lock(hwep->lock); | 1351 | spin_lock(hwep->lock); |
1352 | } | 1352 | } |
1353 | 1353 | ||
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index 85293b8b1df9..926c997ef310 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c | |||
@@ -57,6 +57,8 @@ | |||
57 | 57 | ||
58 | #define MX6_BM_OVER_CUR_DIS BIT(7) | 58 | #define MX6_BM_OVER_CUR_DIS BIT(7) |
59 | 59 | ||
60 | #define VF610_OVER_CUR_DIS BIT(7) | ||
61 | |||
60 | struct usbmisc_ops { | 62 | struct usbmisc_ops { |
61 | /* It's called once when probe a usb device */ | 63 | /* It's called once when probe a usb device */ |
62 | int (*init)(struct imx_usbmisc_data *data); | 64 | int (*init)(struct imx_usbmisc_data *data); |
@@ -71,10 +73,9 @@ struct imx_usbmisc { | |||
71 | const struct usbmisc_ops *ops; | 73 | const struct usbmisc_ops *ops; |
72 | }; | 74 | }; |
73 | 75 | ||
74 | static struct imx_usbmisc *usbmisc; | ||
75 | |||
76 | static int usbmisc_imx25_init(struct imx_usbmisc_data *data) | 76 | static int usbmisc_imx25_init(struct imx_usbmisc_data *data) |
77 | { | 77 | { |
78 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
78 | unsigned long flags; | 79 | unsigned long flags; |
79 | u32 val = 0; | 80 | u32 val = 0; |
80 | 81 | ||
@@ -108,6 +109,7 @@ static int usbmisc_imx25_init(struct imx_usbmisc_data *data) | |||
108 | 109 | ||
109 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) | 110 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) |
110 | { | 111 | { |
112 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
111 | void __iomem *reg; | 113 | void __iomem *reg; |
112 | unsigned long flags; | 114 | unsigned long flags; |
113 | u32 val; | 115 | u32 val; |
@@ -130,6 +132,7 @@ static int usbmisc_imx25_post(struct imx_usbmisc_data *data) | |||
130 | 132 | ||
131 | static int usbmisc_imx27_init(struct imx_usbmisc_data *data) | 133 | static int usbmisc_imx27_init(struct imx_usbmisc_data *data) |
132 | { | 134 | { |
135 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
133 | unsigned long flags; | 136 | unsigned long flags; |
134 | u32 val; | 137 | u32 val; |
135 | 138 | ||
@@ -160,6 +163,7 @@ static int usbmisc_imx27_init(struct imx_usbmisc_data *data) | |||
160 | 163 | ||
161 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) | 164 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) |
162 | { | 165 | { |
166 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
163 | void __iomem *reg = NULL; | 167 | void __iomem *reg = NULL; |
164 | unsigned long flags; | 168 | unsigned long flags; |
165 | u32 val = 0; | 169 | u32 val = 0; |
@@ -204,6 +208,7 @@ static int usbmisc_imx53_init(struct imx_usbmisc_data *data) | |||
204 | 208 | ||
205 | static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) | 209 | static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) |
206 | { | 210 | { |
211 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
207 | unsigned long flags; | 212 | unsigned long flags; |
208 | u32 reg; | 213 | u32 reg; |
209 | 214 | ||
@@ -221,6 +226,26 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) | |||
221 | return 0; | 226 | return 0; |
222 | } | 227 | } |
223 | 228 | ||
229 | static int usbmisc_vf610_init(struct imx_usbmisc_data *data) | ||
230 | { | ||
231 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); | ||
232 | u32 reg; | ||
233 | |||
234 | /* | ||
235 | * Vybrid only has one misc register set, but in two different | ||
236 | * areas. These is reflected in two instances of this driver. | ||
237 | */ | ||
238 | if (data->index >= 1) | ||
239 | return -EINVAL; | ||
240 | |||
241 | if (data->disable_oc) { | ||
242 | reg = readl(usbmisc->base); | ||
243 | writel(reg | VF610_OVER_CUR_DIS, usbmisc->base); | ||
244 | } | ||
245 | |||
246 | return 0; | ||
247 | } | ||
248 | |||
224 | static const struct usbmisc_ops imx25_usbmisc_ops = { | 249 | static const struct usbmisc_ops imx25_usbmisc_ops = { |
225 | .init = usbmisc_imx25_init, | 250 | .init = usbmisc_imx25_init, |
226 | .post = usbmisc_imx25_post, | 251 | .post = usbmisc_imx25_post, |
@@ -238,10 +263,14 @@ static const struct usbmisc_ops imx6q_usbmisc_ops = { | |||
238 | .init = usbmisc_imx6q_init, | 263 | .init = usbmisc_imx6q_init, |
239 | }; | 264 | }; |
240 | 265 | ||
266 | static const struct usbmisc_ops vf610_usbmisc_ops = { | ||
267 | .init = usbmisc_vf610_init, | ||
268 | }; | ||
269 | |||
241 | int imx_usbmisc_init(struct imx_usbmisc_data *data) | 270 | int imx_usbmisc_init(struct imx_usbmisc_data *data) |
242 | { | 271 | { |
243 | if (!usbmisc) | 272 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
244 | return -EPROBE_DEFER; | 273 | |
245 | if (!usbmisc->ops->init) | 274 | if (!usbmisc->ops->init) |
246 | return 0; | 275 | return 0; |
247 | return usbmisc->ops->init(data); | 276 | return usbmisc->ops->init(data); |
@@ -250,8 +279,8 @@ EXPORT_SYMBOL_GPL(imx_usbmisc_init); | |||
250 | 279 | ||
251 | int imx_usbmisc_init_post(struct imx_usbmisc_data *data) | 280 | int imx_usbmisc_init_post(struct imx_usbmisc_data *data) |
252 | { | 281 | { |
253 | if (!usbmisc) | 282 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
254 | return -EPROBE_DEFER; | 283 | |
255 | if (!usbmisc->ops->post) | 284 | if (!usbmisc->ops->post) |
256 | return 0; | 285 | return 0; |
257 | return usbmisc->ops->post(data); | 286 | return usbmisc->ops->post(data); |
@@ -283,6 +312,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { | |||
283 | .compatible = "fsl,imx6q-usbmisc", | 312 | .compatible = "fsl,imx6q-usbmisc", |
284 | .data = &imx6q_usbmisc_ops, | 313 | .data = &imx6q_usbmisc_ops, |
285 | }, | 314 | }, |
315 | { | ||
316 | .compatible = "fsl,vf610-usbmisc", | ||
317 | .data = &vf610_usbmisc_ops, | ||
318 | }, | ||
286 | { /* sentinel */ } | 319 | { /* sentinel */ } |
287 | }; | 320 | }; |
288 | MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); | 321 | MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); |
@@ -294,9 +327,6 @@ static int usbmisc_imx_probe(struct platform_device *pdev) | |||
294 | int ret; | 327 | int ret; |
295 | struct of_device_id *tmp_dev; | 328 | struct of_device_id *tmp_dev; |
296 | 329 | ||
297 | if (usbmisc) | ||
298 | return -EBUSY; | ||
299 | |||
300 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | 330 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
301 | if (!data) | 331 | if (!data) |
302 | return -ENOMEM; | 332 | return -ENOMEM; |
@@ -325,15 +355,15 @@ static int usbmisc_imx_probe(struct platform_device *pdev) | |||
325 | tmp_dev = (struct of_device_id *) | 355 | tmp_dev = (struct of_device_id *) |
326 | of_match_device(usbmisc_imx_dt_ids, &pdev->dev); | 356 | of_match_device(usbmisc_imx_dt_ids, &pdev->dev); |
327 | data->ops = (const struct usbmisc_ops *)tmp_dev->data; | 357 | data->ops = (const struct usbmisc_ops *)tmp_dev->data; |
328 | usbmisc = data; | 358 | platform_set_drvdata(pdev, data); |
329 | 359 | ||
330 | return 0; | 360 | return 0; |
331 | } | 361 | } |
332 | 362 | ||
333 | static int usbmisc_imx_remove(struct platform_device *pdev) | 363 | static int usbmisc_imx_remove(struct platform_device *pdev) |
334 | { | 364 | { |
365 | struct imx_usbmisc *usbmisc = dev_get_drvdata(&pdev->dev); | ||
335 | clk_disable_unprepare(usbmisc->clk); | 366 | clk_disable_unprepare(usbmisc->clk); |
336 | usbmisc = NULL; | ||
337 | return 0; | 367 | return 0; |
338 | } | 368 | } |
339 | 369 | ||
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index 752646167e1e..ca2f8bd0e431 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile | |||
@@ -2,5 +2,8 @@ | |||
2 | # Makefile for the usb common parts. | 2 | # Makefile for the usb common parts. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_USB_COMMON) += usb-common.o | 5 | obj-$(CONFIG_USB_COMMON) += usb-common.o |
6 | usb-common-y += common.o | ||
7 | usb-common-$(CONFIG_USB_LED_TRIG) += led.o | ||
8 | |||
6 | obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o | 9 | obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o |
diff --git a/drivers/usb/common/usb-common.c b/drivers/usb/common/common.c index 6dfd30a863c7..b530fd403ffb 100644 --- a/drivers/usb/common/usb-common.c +++ b/drivers/usb/common/common.c | |||
@@ -139,6 +139,21 @@ enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np) | |||
139 | } | 139 | } |
140 | EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed); | 140 | EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed); |
141 | 141 | ||
142 | /** | ||
143 | * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported | ||
144 | * for given targeted hosts (non-PC hosts) | ||
145 | * @np: Pointer to the given device_node | ||
146 | * | ||
147 | * The function gets if the targeted hosts support TPL or not | ||
148 | */ | ||
149 | bool of_usb_host_tpl_support(struct device_node *np) | ||
150 | { | ||
151 | if (of_find_property(np, "tpl-support", NULL)) | ||
152 | return true; | ||
153 | |||
154 | return false; | ||
155 | } | ||
156 | EXPORT_SYMBOL_GPL(of_usb_host_tpl_support); | ||
142 | #endif | 157 | #endif |
143 | 158 | ||
144 | MODULE_LICENSE("GPL"); | 159 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/common/led.c b/drivers/usb/common/led.c new file mode 100644 index 000000000000..df23da00a901 --- /dev/null +++ b/drivers/usb/common/led.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * LED Triggers for USB Activity | ||
3 | * | ||
4 | * Copyright 2014 Michal Sojka <sojka@merica.cz> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/leds.h> | ||
16 | #include <linux/usb.h> | ||
17 | |||
18 | #define BLINK_DELAY 30 | ||
19 | |||
20 | static unsigned long usb_blink_delay = BLINK_DELAY; | ||
21 | |||
22 | DEFINE_LED_TRIGGER(ledtrig_usb_gadget); | ||
23 | DEFINE_LED_TRIGGER(ledtrig_usb_host); | ||
24 | |||
25 | void usb_led_activity(enum usb_led_event ev) | ||
26 | { | ||
27 | struct led_trigger *trig = NULL; | ||
28 | |||
29 | switch (ev) { | ||
30 | case USB_LED_EVENT_GADGET: | ||
31 | trig = ledtrig_usb_gadget; | ||
32 | break; | ||
33 | case USB_LED_EVENT_HOST: | ||
34 | trig = ledtrig_usb_host; | ||
35 | break; | ||
36 | } | ||
37 | /* led_trigger_blink_oneshot() handles trig == NULL gracefully */ | ||
38 | led_trigger_blink_oneshot(trig, &usb_blink_delay, &usb_blink_delay, 0); | ||
39 | } | ||
40 | EXPORT_SYMBOL_GPL(usb_led_activity); | ||
41 | |||
42 | |||
43 | static int __init ledtrig_usb_init(void) | ||
44 | { | ||
45 | led_trigger_register_simple("usb-gadget", &ledtrig_usb_gadget); | ||
46 | led_trigger_register_simple("usb-host", &ledtrig_usb_host); | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static void __exit ledtrig_usb_exit(void) | ||
51 | { | ||
52 | led_trigger_unregister_simple(ledtrig_usb_gadget); | ||
53 | led_trigger_unregister_simple(ledtrig_usb_host); | ||
54 | } | ||
55 | |||
56 | module_init(ledtrig_usb_init); | ||
57 | module_exit(ledtrig_usb_exit); | ||
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index 1060657ca1b0..9cfda6a72194 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -56,22 +56,16 @@ config USB_OTG | |||
56 | connector. | 56 | connector. |
57 | 57 | ||
58 | config USB_OTG_WHITELIST | 58 | config USB_OTG_WHITELIST |
59 | bool "Rely on OTG Targeted Peripherals List" | 59 | bool "Rely on OTG and EH Targeted Peripherals List" |
60 | depends on USB_OTG || EXPERT | 60 | depends on USB |
61 | default y if USB_OTG | ||
62 | help | 61 | help |
63 | If you say Y here, the "otg_whitelist.h" file will be used as a | 62 | If you say Y here, the "otg_whitelist.h" file will be used as a |
64 | product whitelist, so USB peripherals not listed there will be | 63 | product whitelist, so USB peripherals not listed there will be |
65 | rejected during enumeration. This behavior is required by the | 64 | rejected during enumeration. This behavior is required by the |
66 | USB OTG specification for all devices not on your product's | 65 | USB OTG and EH specification for all devices not on your product's |
67 | "Targeted Peripherals List". "Embedded Hosts" are likewise | 66 | "Targeted Peripherals List". "Embedded Hosts" are likewise |
68 | allowed to support only a limited number of peripherals. | 67 | allowed to support only a limited number of peripherals. |
69 | 68 | ||
70 | Otherwise, peripherals not listed there will only generate a | ||
71 | warning and enumeration will continue. That's more like what | ||
72 | normal Linux-USB hosts do (other than the warning), and is | ||
73 | convenient for many stages of product development. | ||
74 | |||
75 | config USB_OTG_BLACKLIST_HUB | 69 | config USB_OTG_BLACKLIST_HUB |
76 | bool "Disable external hubs" | 70 | bool "Disable external hubs" |
77 | depends on USB_OTG || EXPERT | 71 | depends on USB_OTG || EXPERT |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 487abcfcccd8..b84fb141e122 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include <linux/pm_runtime.h> | 42 | #include <linux/pm_runtime.h> |
43 | #include <linux/types.h> | 43 | #include <linux/types.h> |
44 | 44 | ||
45 | #include <linux/phy/phy.h> | ||
45 | #include <linux/usb.h> | 46 | #include <linux/usb.h> |
46 | #include <linux/usb/hcd.h> | 47 | #include <linux/usb/hcd.h> |
47 | #include <linux/usb/phy.h> | 48 | #include <linux/usb/phy.h> |
@@ -1272,7 +1273,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep); | |||
1272 | * The usb core itself is however optimized for host controllers that can dma | 1273 | * The usb core itself is however optimized for host controllers that can dma |
1273 | * using regular system memory - like pci devices doing bus mastering. | 1274 | * using regular system memory - like pci devices doing bus mastering. |
1274 | * | 1275 | * |
1275 | * To support host controllers with limited dma capabilites we provide dma | 1276 | * To support host controllers with limited dma capabilities we provide dma |
1276 | * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag. | 1277 | * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag. |
1277 | * For this to work properly the host controller code must first use the | 1278 | * For this to work properly the host controller code must first use the |
1278 | * function dma_declare_coherent_memory() to point out which memory area | 1279 | * function dma_declare_coherent_memory() to point out which memory area |
@@ -1664,6 +1665,8 @@ static void __usb_hcd_giveback_urb(struct urb *urb) | |||
1664 | usbmon_urb_complete(&hcd->self, urb, status); | 1665 | usbmon_urb_complete(&hcd->self, urb, status); |
1665 | usb_anchor_suspend_wakeups(anchor); | 1666 | usb_anchor_suspend_wakeups(anchor); |
1666 | usb_unanchor_urb(urb); | 1667 | usb_unanchor_urb(urb); |
1668 | if (likely(status == 0)) | ||
1669 | usb_led_activity(USB_LED_EVENT_HOST); | ||
1667 | 1670 | ||
1668 | /* pass ownership to the completion handler */ | 1671 | /* pass ownership to the completion handler */ |
1669 | urb->status = status; | 1672 | urb->status = status; |
@@ -2301,7 +2304,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); | |||
2301 | * Context: in_interrupt() | 2304 | * Context: in_interrupt() |
2302 | * | 2305 | * |
2303 | * Starts enumeration, with an immediate reset followed later by | 2306 | * Starts enumeration, with an immediate reset followed later by |
2304 | * khubd identifying and possibly configuring the device. | 2307 | * hub_wq identifying and possibly configuring the device. |
2305 | * This is needed by OTG controller drivers, where it helps meet | 2308 | * This is needed by OTG controller drivers, where it helps meet |
2306 | * HNP protocol timing requirements for starting a port reset. | 2309 | * HNP protocol timing requirements for starting a port reset. |
2307 | * | 2310 | * |
@@ -2320,7 +2323,7 @@ int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num) | |||
2320 | if (port_num && hcd->driver->start_port_reset) | 2323 | if (port_num && hcd->driver->start_port_reset) |
2321 | status = hcd->driver->start_port_reset(hcd, port_num); | 2324 | status = hcd->driver->start_port_reset(hcd, port_num); |
2322 | 2325 | ||
2323 | /* run khubd shortly after (first) root port reset finishes; | 2326 | /* allocate hub_wq shortly after (first) root port reset finishes; |
2324 | * it may issue others, until at least 50 msecs have passed. | 2327 | * it may issue others, until at least 50 msecs have passed. |
2325 | */ | 2328 | */ |
2326 | if (status == 0) | 2329 | if (status == 0) |
@@ -2383,20 +2386,20 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2383 | if (hcd->rh_registered) { | 2386 | if (hcd->rh_registered) { |
2384 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2387 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2385 | 2388 | ||
2386 | /* make khubd clean up old urbs and devices */ | 2389 | /* make hub_wq clean up old urbs and devices */ |
2387 | usb_set_device_state (hcd->self.root_hub, | 2390 | usb_set_device_state (hcd->self.root_hub, |
2388 | USB_STATE_NOTATTACHED); | 2391 | USB_STATE_NOTATTACHED); |
2389 | usb_kick_khubd (hcd->self.root_hub); | 2392 | usb_kick_hub_wq(hcd->self.root_hub); |
2390 | } | 2393 | } |
2391 | if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { | 2394 | if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { |
2392 | hcd = hcd->shared_hcd; | 2395 | hcd = hcd->shared_hcd; |
2393 | if (hcd->rh_registered) { | 2396 | if (hcd->rh_registered) { |
2394 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2397 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2395 | 2398 | ||
2396 | /* make khubd clean up old urbs and devices */ | 2399 | /* make hub_wq clean up old urbs and devices */ |
2397 | usb_set_device_state(hcd->self.root_hub, | 2400 | usb_set_device_state(hcd->self.root_hub, |
2398 | USB_STATE_NOTATTACHED); | 2401 | USB_STATE_NOTATTACHED); |
2399 | usb_kick_khubd(hcd->self.root_hub); | 2402 | usb_kick_hub_wq(hcd->self.root_hub); |
2400 | } | 2403 | } |
2401 | } | 2404 | } |
2402 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 2405 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
@@ -2627,7 +2630,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2627 | int retval; | 2630 | int retval; |
2628 | struct usb_device *rhdev; | 2631 | struct usb_device *rhdev; |
2629 | 2632 | ||
2630 | if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->phy) { | 2633 | if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->usb_phy) { |
2631 | struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0); | 2634 | struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0); |
2632 | 2635 | ||
2633 | if (IS_ERR(phy)) { | 2636 | if (IS_ERR(phy)) { |
@@ -2640,11 +2643,34 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2640 | usb_put_phy(phy); | 2643 | usb_put_phy(phy); |
2641 | return retval; | 2644 | return retval; |
2642 | } | 2645 | } |
2643 | hcd->phy = phy; | 2646 | hcd->usb_phy = phy; |
2644 | hcd->remove_phy = 1; | 2647 | hcd->remove_phy = 1; |
2645 | } | 2648 | } |
2646 | } | 2649 | } |
2647 | 2650 | ||
2651 | if (IS_ENABLED(CONFIG_GENERIC_PHY)) { | ||
2652 | struct phy *phy = phy_get(hcd->self.controller, "usb"); | ||
2653 | |||
2654 | if (IS_ERR(phy)) { | ||
2655 | retval = PTR_ERR(phy); | ||
2656 | if (retval == -EPROBE_DEFER) | ||
2657 | goto err_phy; | ||
2658 | } else { | ||
2659 | retval = phy_init(phy); | ||
2660 | if (retval) { | ||
2661 | phy_put(phy); | ||
2662 | goto err_phy; | ||
2663 | } | ||
2664 | retval = phy_power_on(phy); | ||
2665 | if (retval) { | ||
2666 | phy_exit(phy); | ||
2667 | phy_put(phy); | ||
2668 | goto err_phy; | ||
2669 | } | ||
2670 | hcd->phy = phy; | ||
2671 | } | ||
2672 | } | ||
2673 | |||
2648 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); | 2674 | dev_info(hcd->self.controller, "%s\n", hcd->product_desc); |
2649 | 2675 | ||
2650 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ | 2676 | /* Keep old behaviour if authorized_default is not in [0, 1]. */ |
@@ -2655,12 +2681,12 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2655 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 2681 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
2656 | 2682 | ||
2657 | /* HC is in reset state, but accessible. Now do the one-time init, | 2683 | /* HC is in reset state, but accessible. Now do the one-time init, |
2658 | * bottom up so that hcds can customize the root hubs before khubd | 2684 | * bottom up so that hcds can customize the root hubs before hub_wq |
2659 | * starts talking to them. (Note, bus id is assigned early too.) | 2685 | * starts talking to them. (Note, bus id is assigned early too.) |
2660 | */ | 2686 | */ |
2661 | if ((retval = hcd_buffer_create(hcd)) != 0) { | 2687 | if ((retval = hcd_buffer_create(hcd)) != 0) { |
2662 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); | 2688 | dev_dbg(hcd->self.controller, "pool alloc failed\n"); |
2663 | goto err_remove_phy; | 2689 | goto err_create_buf; |
2664 | } | 2690 | } |
2665 | 2691 | ||
2666 | if ((retval = usb_register_bus(&hcd->self)) < 0) | 2692 | if ((retval = usb_register_bus(&hcd->self)) < 0) |
@@ -2787,12 +2813,19 @@ err_allocate_root_hub: | |||
2787 | usb_deregister_bus(&hcd->self); | 2813 | usb_deregister_bus(&hcd->self); |
2788 | err_register_bus: | 2814 | err_register_bus: |
2789 | hcd_buffer_destroy(hcd); | 2815 | hcd_buffer_destroy(hcd); |
2790 | err_remove_phy: | 2816 | err_create_buf: |
2791 | if (hcd->remove_phy && hcd->phy) { | 2817 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) { |
2792 | usb_phy_shutdown(hcd->phy); | 2818 | phy_power_off(hcd->phy); |
2793 | usb_put_phy(hcd->phy); | 2819 | phy_exit(hcd->phy); |
2820 | phy_put(hcd->phy); | ||
2794 | hcd->phy = NULL; | 2821 | hcd->phy = NULL; |
2795 | } | 2822 | } |
2823 | err_phy: | ||
2824 | if (hcd->remove_phy && hcd->usb_phy) { | ||
2825 | usb_phy_shutdown(hcd->usb_phy); | ||
2826 | usb_put_phy(hcd->usb_phy); | ||
2827 | hcd->usb_phy = NULL; | ||
2828 | } | ||
2796 | return retval; | 2829 | return retval; |
2797 | } | 2830 | } |
2798 | EXPORT_SYMBOL_GPL(usb_add_hcd); | 2831 | EXPORT_SYMBOL_GPL(usb_add_hcd); |
@@ -2864,11 +2897,18 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2864 | 2897 | ||
2865 | usb_deregister_bus(&hcd->self); | 2898 | usb_deregister_bus(&hcd->self); |
2866 | hcd_buffer_destroy(hcd); | 2899 | hcd_buffer_destroy(hcd); |
2867 | if (hcd->remove_phy && hcd->phy) { | 2900 | |
2868 | usb_phy_shutdown(hcd->phy); | 2901 | if (IS_ENABLED(CONFIG_GENERIC_PHY) && hcd->phy) { |
2869 | usb_put_phy(hcd->phy); | 2902 | phy_power_off(hcd->phy); |
2903 | phy_exit(hcd->phy); | ||
2904 | phy_put(hcd->phy); | ||
2870 | hcd->phy = NULL; | 2905 | hcd->phy = NULL; |
2871 | } | 2906 | } |
2907 | if (hcd->remove_phy && hcd->usb_phy) { | ||
2908 | usb_phy_shutdown(hcd->usb_phy); | ||
2909 | usb_put_phy(hcd->usb_phy); | ||
2910 | hcd->usb_phy = NULL; | ||
2911 | } | ||
2872 | 2912 | ||
2873 | usb_put_invalidate_rhdev(hcd); | 2913 | usb_put_invalidate_rhdev(hcd); |
2874 | } | 2914 | } |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index d481c99a20d7..11e80ac31324 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -22,9 +22,8 @@ | |||
22 | #include <linux/usb/hcd.h> | 22 | #include <linux/usb/hcd.h> |
23 | #include <linux/usb/otg.h> | 23 | #include <linux/usb/otg.h> |
24 | #include <linux/usb/quirks.h> | 24 | #include <linux/usb/quirks.h> |
25 | #include <linux/kthread.h> | 25 | #include <linux/workqueue.h> |
26 | #include <linux/mutex.h> | 26 | #include <linux/mutex.h> |
27 | #include <linux/freezer.h> | ||
28 | #include <linux/random.h> | 27 | #include <linux/random.h> |
29 | #include <linux/pm_qos.h> | 28 | #include <linux/pm_qos.h> |
30 | 29 | ||
@@ -32,6 +31,7 @@ | |||
32 | #include <asm/byteorder.h> | 31 | #include <asm/byteorder.h> |
33 | 32 | ||
34 | #include "hub.h" | 33 | #include "hub.h" |
34 | #include "otg_whitelist.h" | ||
35 | 35 | ||
36 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 | 36 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 |
37 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 | 37 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 |
@@ -41,14 +41,9 @@ | |||
41 | * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */ | 41 | * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */ |
42 | static DEFINE_SPINLOCK(device_state_lock); | 42 | static DEFINE_SPINLOCK(device_state_lock); |
43 | 43 | ||
44 | /* khubd's worklist and its lock */ | 44 | /* workqueue to process hub events */ |
45 | static DEFINE_SPINLOCK(hub_event_lock); | 45 | static struct workqueue_struct *hub_wq; |
46 | static LIST_HEAD(hub_event_list); /* List of hubs needing servicing */ | 46 | static void hub_event(struct work_struct *work); |
47 | |||
48 | /* Wakes up khubd */ | ||
49 | static DECLARE_WAIT_QUEUE_HEAD(khubd_wait); | ||
50 | |||
51 | static struct task_struct *khubd_task; | ||
52 | 47 | ||
53 | /* synchronize hub-port add/remove and peering operations */ | 48 | /* synchronize hub-port add/remove and peering operations */ |
54 | DEFINE_MUTEX(usb_port_peer_mutex); | 49 | DEFINE_MUTEX(usb_port_peer_mutex); |
@@ -104,6 +99,7 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); | |||
104 | #define HUB_DEBOUNCE_STEP 25 | 99 | #define HUB_DEBOUNCE_STEP 25 |
105 | #define HUB_DEBOUNCE_STABLE 100 | 100 | #define HUB_DEBOUNCE_STABLE 100 |
106 | 101 | ||
102 | static void hub_release(struct kref *kref); | ||
107 | static int usb_reset_and_verify_device(struct usb_device *udev); | 103 | static int usb_reset_and_verify_device(struct usb_device *udev); |
108 | 104 | ||
109 | static inline char *portspeed(struct usb_hub *hub, int portstatus) | 105 | static inline char *portspeed(struct usb_hub *hub, int portstatus) |
@@ -575,28 +571,39 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
575 | return ret; | 571 | return ret; |
576 | } | 572 | } |
577 | 573 | ||
578 | static void kick_khubd(struct usb_hub *hub) | 574 | static void kick_hub_wq(struct usb_hub *hub) |
579 | { | 575 | { |
580 | unsigned long flags; | 576 | struct usb_interface *intf; |
581 | 577 | ||
582 | spin_lock_irqsave(&hub_event_lock, flags); | 578 | if (hub->disconnected || work_pending(&hub->events)) |
583 | if (!hub->disconnected && list_empty(&hub->event_list)) { | 579 | return; |
584 | list_add_tail(&hub->event_list, &hub_event_list); | ||
585 | 580 | ||
586 | /* Suppress autosuspend until khubd runs */ | 581 | /* |
587 | usb_autopm_get_interface_no_resume( | 582 | * Suppress autosuspend until the event is proceed. |
588 | to_usb_interface(hub->intfdev)); | 583 | * |
589 | wake_up(&khubd_wait); | 584 | * Be careful and make sure that the symmetric operation is |
590 | } | 585 | * always called. We are here only when there is no pending |
591 | spin_unlock_irqrestore(&hub_event_lock, flags); | 586 | * work for this hub. Therefore put the interface either when |
587 | * the new work is called or when it is canceled. | ||
588 | */ | ||
589 | intf = to_usb_interface(hub->intfdev); | ||
590 | usb_autopm_get_interface_no_resume(intf); | ||
591 | kref_get(&hub->kref); | ||
592 | |||
593 | if (queue_work(hub_wq, &hub->events)) | ||
594 | return; | ||
595 | |||
596 | /* the work has already been scheduled */ | ||
597 | usb_autopm_put_interface_async(intf); | ||
598 | kref_put(&hub->kref, hub_release); | ||
592 | } | 599 | } |
593 | 600 | ||
594 | void usb_kick_khubd(struct usb_device *hdev) | 601 | void usb_kick_hub_wq(struct usb_device *hdev) |
595 | { | 602 | { |
596 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | 603 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); |
597 | 604 | ||
598 | if (hub) | 605 | if (hub) |
599 | kick_khubd(hub); | 606 | kick_hub_wq(hub); |
600 | } | 607 | } |
601 | 608 | ||
602 | /* | 609 | /* |
@@ -618,7 +625,7 @@ void usb_wakeup_notification(struct usb_device *hdev, | |||
618 | hub = usb_hub_to_struct_hub(hdev); | 625 | hub = usb_hub_to_struct_hub(hdev); |
619 | if (hub) { | 626 | if (hub) { |
620 | set_bit(portnum, hub->wakeup_bits); | 627 | set_bit(portnum, hub->wakeup_bits); |
621 | kick_khubd(hub); | 628 | kick_hub_wq(hub); |
622 | } | 629 | } |
623 | } | 630 | } |
624 | EXPORT_SYMBOL_GPL(usb_wakeup_notification); | 631 | EXPORT_SYMBOL_GPL(usb_wakeup_notification); |
@@ -645,7 +652,7 @@ static void hub_irq(struct urb *urb) | |||
645 | hub->error = status; | 652 | hub->error = status; |
646 | /* FALL THROUGH */ | 653 | /* FALL THROUGH */ |
647 | 654 | ||
648 | /* let khubd handle things */ | 655 | /* let hub_wq handle things */ |
649 | case 0: /* we got data: port status changed */ | 656 | case 0: /* we got data: port status changed */ |
650 | bits = 0; | 657 | bits = 0; |
651 | for (i = 0; i < urb->actual_length; ++i) | 658 | for (i = 0; i < urb->actual_length; ++i) |
@@ -657,8 +664,8 @@ static void hub_irq(struct urb *urb) | |||
657 | 664 | ||
658 | hub->nerrors = 0; | 665 | hub->nerrors = 0; |
659 | 666 | ||
660 | /* Something happened, let khubd figure it out */ | 667 | /* Something happened, let hub_wq figure it out */ |
661 | kick_khubd(hub); | 668 | kick_hub_wq(hub); |
662 | 669 | ||
663 | resubmit: | 670 | resubmit: |
664 | if (hub->quiescing) | 671 | if (hub->quiescing) |
@@ -688,7 +695,7 @@ hub_clear_tt_buffer (struct usb_device *hdev, u16 devinfo, u16 tt) | |||
688 | } | 695 | } |
689 | 696 | ||
690 | /* | 697 | /* |
691 | * enumeration blocks khubd for a long time. we use keventd instead, since | 698 | * enumeration blocks hub_wq for a long time. we use keventd instead, since |
692 | * long blocking there is the exception, not the rule. accordingly, HCDs | 699 | * long blocking there is the exception, not the rule. accordingly, HCDs |
693 | * talking to TTs must queue control transfers (not just bulk and iso), so | 700 | * talking to TTs must queue control transfers (not just bulk and iso), so |
694 | * both can talk to the same hub concurrently. | 701 | * both can talk to the same hub concurrently. |
@@ -954,7 +961,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
954 | 961 | ||
955 | /* | 962 | /* |
956 | * Disable a port and mark a logical connect-change event, so that some | 963 | * Disable a port and mark a logical connect-change event, so that some |
957 | * time later khubd will disconnect() any existing usb_device on the port | 964 | * time later hub_wq will disconnect() any existing usb_device on the port |
958 | * and will re-enumerate if there actually is a device attached. | 965 | * and will re-enumerate if there actually is a device attached. |
959 | */ | 966 | */ |
960 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | 967 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) |
@@ -967,12 +974,12 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | |||
967 | * - SRP saves power that way | 974 | * - SRP saves power that way |
968 | * - ... new call, TBD ... | 975 | * - ... new call, TBD ... |
969 | * That's easy if this hub can switch power per-port, and | 976 | * That's easy if this hub can switch power per-port, and |
970 | * khubd reactivates the port later (timer, SRP, etc). | 977 | * hub_wq reactivates the port later (timer, SRP, etc). |
971 | * Powerdown must be optional, because of reset/DFU. | 978 | * Powerdown must be optional, because of reset/DFU. |
972 | */ | 979 | */ |
973 | 980 | ||
974 | set_bit(port1, hub->change_bits); | 981 | set_bit(port1, hub->change_bits); |
975 | kick_khubd(hub); | 982 | kick_hub_wq(hub); |
976 | } | 983 | } |
977 | 984 | ||
978 | /** | 985 | /** |
@@ -980,7 +987,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | |||
980 | * @udev: device to be disabled and removed | 987 | * @udev: device to be disabled and removed |
981 | * Context: @udev locked, must be able to sleep. | 988 | * Context: @udev locked, must be able to sleep. |
982 | * | 989 | * |
983 | * After @udev's port has been disabled, khubd is notified and it will | 990 | * After @udev's port has been disabled, hub_wq is notified and it will |
984 | * see that the device has been disconnected. When the device is | 991 | * see that the device has been disconnected. When the device is |
985 | * physically unplugged and something is plugged in, the events will | 992 | * physically unplugged and something is plugged in, the events will |
986 | * be received and processed normally. | 993 | * be received and processed normally. |
@@ -1100,7 +1107,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1100 | init2: | 1107 | init2: |
1101 | 1108 | ||
1102 | /* | 1109 | /* |
1103 | * Check each port and set hub->change_bits to let khubd know | 1110 | * Check each port and set hub->change_bits to let hub_wq know |
1104 | * which ports need attention. | 1111 | * which ports need attention. |
1105 | */ | 1112 | */ |
1106 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | 1113 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { |
@@ -1167,7 +1174,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1167 | clear_bit(port1, hub->removed_bits); | 1174 | clear_bit(port1, hub->removed_bits); |
1168 | 1175 | ||
1169 | if (!udev || udev->state == USB_STATE_NOTATTACHED) { | 1176 | if (!udev || udev->state == USB_STATE_NOTATTACHED) { |
1170 | /* Tell khubd to disconnect the device or | 1177 | /* Tell hub_wq to disconnect the device or |
1171 | * check for a new connection | 1178 | * check for a new connection |
1172 | */ | 1179 | */ |
1173 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION) || | 1180 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION) || |
@@ -1180,7 +1187,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1180 | USB_SS_PORT_LS_U0; | 1187 | USB_SS_PORT_LS_U0; |
1181 | /* The power session apparently survived the resume. | 1188 | /* The power session apparently survived the resume. |
1182 | * If there was an overcurrent or suspend change | 1189 | * If there was an overcurrent or suspend change |
1183 | * (i.e., remote wakeup request), have khubd | 1190 | * (i.e., remote wakeup request), have hub_wq |
1184 | * take care of it. Look at the port link state | 1191 | * take care of it. Look at the port link state |
1185 | * for USB 3.0 hubs, since they don't have a suspend | 1192 | * for USB 3.0 hubs, since they don't have a suspend |
1186 | * change bit, and they don't set the port link change | 1193 | * change bit, and they don't set the port link change |
@@ -1201,7 +1208,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1201 | set_bit(port1, hub->change_bits); | 1208 | set_bit(port1, hub->change_bits); |
1202 | 1209 | ||
1203 | } else { | 1210 | } else { |
1204 | /* The power session is gone; tell khubd */ | 1211 | /* The power session is gone; tell hub_wq */ |
1205 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1212 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1206 | set_bit(port1, hub->change_bits); | 1213 | set_bit(port1, hub->change_bits); |
1207 | } | 1214 | } |
@@ -1209,10 +1216,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1209 | 1216 | ||
1210 | /* If no port-status-change flags were set, we don't need any | 1217 | /* If no port-status-change flags were set, we don't need any |
1211 | * debouncing. If flags were set we can try to debounce the | 1218 | * debouncing. If flags were set we can try to debounce the |
1212 | * ports all at once right now, instead of letting khubd do them | 1219 | * ports all at once right now, instead of letting hub_wq do them |
1213 | * one at a time later on. | 1220 | * one at a time later on. |
1214 | * | 1221 | * |
1215 | * If any port-status changes do occur during this delay, khubd | 1222 | * If any port-status changes do occur during this delay, hub_wq |
1216 | * will see them later and handle them normally. | 1223 | * will see them later and handle them normally. |
1217 | */ | 1224 | */ |
1218 | if (need_debounce_delay) { | 1225 | if (need_debounce_delay) { |
@@ -1240,7 +1247,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1240 | &hub->leds, LED_CYCLE_PERIOD); | 1247 | &hub->leds, LED_CYCLE_PERIOD); |
1241 | 1248 | ||
1242 | /* Scan all ports that need attention */ | 1249 | /* Scan all ports that need attention */ |
1243 | kick_khubd(hub); | 1250 | kick_hub_wq(hub); |
1244 | 1251 | ||
1245 | /* Allow autosuspend if it was suppressed */ | 1252 | /* Allow autosuspend if it was suppressed */ |
1246 | if (type <= HUB_INIT3) | 1253 | if (type <= HUB_INIT3) |
@@ -1273,7 +1280,7 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) | |||
1273 | 1280 | ||
1274 | cancel_delayed_work_sync(&hub->init_work); | 1281 | cancel_delayed_work_sync(&hub->init_work); |
1275 | 1282 | ||
1276 | /* khubd and related activity won't re-trigger */ | 1283 | /* hub_wq and related activity won't re-trigger */ |
1277 | hub->quiescing = 1; | 1284 | hub->quiescing = 1; |
1278 | 1285 | ||
1279 | if (type != HUB_SUSPEND) { | 1286 | if (type != HUB_SUSPEND) { |
@@ -1284,7 +1291,7 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) | |||
1284 | } | 1291 | } |
1285 | } | 1292 | } |
1286 | 1293 | ||
1287 | /* Stop khubd and related activity */ | 1294 | /* Stop hub_wq and related activity */ |
1288 | usb_kill_urb(hub->urb); | 1295 | usb_kill_urb(hub->urb); |
1289 | if (hub->has_indicators) | 1296 | if (hub->has_indicators) |
1290 | cancel_delayed_work_sync(&hub->leds); | 1297 | cancel_delayed_work_sync(&hub->leds); |
@@ -1606,7 +1613,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1606 | if (ret < 0) | 1613 | if (ret < 0) |
1607 | goto fail; | 1614 | goto fail; |
1608 | 1615 | ||
1609 | /* Update the HCD's internal representation of this hub before khubd | 1616 | /* Update the HCD's internal representation of this hub before hub_wq |
1610 | * starts getting port status changes for devices under the hub. | 1617 | * starts getting port status changes for devices under the hub. |
1611 | */ | 1618 | */ |
1612 | if (hcd->driver->update_hub_device) { | 1619 | if (hcd->driver->update_hub_device) { |
@@ -1634,6 +1641,7 @@ static void hub_release(struct kref *kref) | |||
1634 | { | 1641 | { |
1635 | struct usb_hub *hub = container_of(kref, struct usb_hub, kref); | 1642 | struct usb_hub *hub = container_of(kref, struct usb_hub, kref); |
1636 | 1643 | ||
1644 | usb_put_dev(hub->hdev); | ||
1637 | usb_put_intf(to_usb_interface(hub->intfdev)); | 1645 | usb_put_intf(to_usb_interface(hub->intfdev)); |
1638 | kfree(hub); | 1646 | kfree(hub); |
1639 | } | 1647 | } |
@@ -1646,14 +1654,11 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1646 | struct usb_device *hdev = interface_to_usbdev(intf); | 1654 | struct usb_device *hdev = interface_to_usbdev(intf); |
1647 | int port1; | 1655 | int port1; |
1648 | 1656 | ||
1649 | /* Take the hub off the event list and don't let it be added again */ | 1657 | /* |
1650 | spin_lock_irq(&hub_event_lock); | 1658 | * Stop adding new hub events. We do not want to block here and thus |
1651 | if (!list_empty(&hub->event_list)) { | 1659 | * will not try to remove any pending work item. |
1652 | list_del_init(&hub->event_list); | 1660 | */ |
1653 | usb_autopm_put_interface_no_suspend(intf); | ||
1654 | } | ||
1655 | hub->disconnected = 1; | 1661 | hub->disconnected = 1; |
1656 | spin_unlock_irq(&hub_event_lock); | ||
1657 | 1662 | ||
1658 | /* Disconnect all children and quiesce the hub */ | 1663 | /* Disconnect all children and quiesce the hub */ |
1659 | hub->error = 0; | 1664 | hub->error = 0; |
@@ -1793,12 +1798,13 @@ descriptor_error: | |||
1793 | } | 1798 | } |
1794 | 1799 | ||
1795 | kref_init(&hub->kref); | 1800 | kref_init(&hub->kref); |
1796 | INIT_LIST_HEAD(&hub->event_list); | ||
1797 | hub->intfdev = &intf->dev; | 1801 | hub->intfdev = &intf->dev; |
1798 | hub->hdev = hdev; | 1802 | hub->hdev = hdev; |
1799 | INIT_DELAYED_WORK(&hub->leds, led_work); | 1803 | INIT_DELAYED_WORK(&hub->leds, led_work); |
1800 | INIT_DELAYED_WORK(&hub->init_work, NULL); | 1804 | INIT_DELAYED_WORK(&hub->init_work, NULL); |
1805 | INIT_WORK(&hub->events, hub_event); | ||
1801 | usb_get_intf(intf); | 1806 | usb_get_intf(intf); |
1807 | usb_get_dev(hdev); | ||
1802 | 1808 | ||
1803 | usb_set_intfdata (intf, hub); | 1809 | usb_set_intfdata (intf, hub); |
1804 | intf->needs_remote_wakeup = 1; | 1810 | intf->needs_remote_wakeup = 1; |
@@ -1983,8 +1989,10 @@ void usb_set_device_state(struct usb_device *udev, | |||
1983 | || new_state == USB_STATE_SUSPENDED) | 1989 | || new_state == USB_STATE_SUSPENDED) |
1984 | ; /* No change to wakeup settings */ | 1990 | ; /* No change to wakeup settings */ |
1985 | else if (new_state == USB_STATE_CONFIGURED) | 1991 | else if (new_state == USB_STATE_CONFIGURED) |
1986 | wakeup = udev->actconfig->desc.bmAttributes | 1992 | wakeup = (udev->quirks & |
1987 | & USB_CONFIG_ATT_WAKEUP; | 1993 | USB_QUIRK_IGNORE_REMOTE_WAKEUP) ? 0 : |
1994 | udev->actconfig->desc.bmAttributes & | ||
1995 | USB_CONFIG_ATT_WAKEUP; | ||
1988 | else | 1996 | else |
1989 | wakeup = 0; | 1997 | wakeup = 0; |
1990 | } | 1998 | } |
@@ -2037,7 +2045,8 @@ static void choose_devnum(struct usb_device *udev) | |||
2037 | int devnum; | 2045 | int devnum; |
2038 | struct usb_bus *bus = udev->bus; | 2046 | struct usb_bus *bus = udev->bus; |
2039 | 2047 | ||
2040 | /* If khubd ever becomes multithreaded, this will need a lock */ | 2048 | /* be safe when more hub events are proceed in parallel */ |
2049 | mutex_lock(&bus->usb_address0_mutex); | ||
2041 | if (udev->wusb) { | 2050 | if (udev->wusb) { |
2042 | devnum = udev->portnum + 1; | 2051 | devnum = udev->portnum + 1; |
2043 | BUG_ON(test_bit(devnum, bus->devmap.devicemap)); | 2052 | BUG_ON(test_bit(devnum, bus->devmap.devicemap)); |
@@ -2055,6 +2064,7 @@ static void choose_devnum(struct usb_device *udev) | |||
2055 | set_bit(devnum, bus->devmap.devicemap); | 2064 | set_bit(devnum, bus->devmap.devicemap); |
2056 | udev->devnum = devnum; | 2065 | udev->devnum = devnum; |
2057 | } | 2066 | } |
2067 | mutex_unlock(&bus->usb_address0_mutex); | ||
2058 | } | 2068 | } |
2059 | 2069 | ||
2060 | static void release_devnum(struct usb_device *udev) | 2070 | static void release_devnum(struct usb_device *udev) |
@@ -2205,9 +2215,6 @@ static void announce_device(struct usb_device *udev) | |||
2205 | static inline void announce_device(struct usb_device *udev) { } | 2215 | static inline void announce_device(struct usb_device *udev) { } |
2206 | #endif | 2216 | #endif |
2207 | 2217 | ||
2208 | #ifdef CONFIG_USB_OTG | ||
2209 | #include "otg_whitelist.h" | ||
2210 | #endif | ||
2211 | 2218 | ||
2212 | /** | 2219 | /** |
2213 | * usb_enumerate_device_otg - FIXME (usbcore-internal) | 2220 | * usb_enumerate_device_otg - FIXME (usbcore-internal) |
@@ -2267,21 +2274,6 @@ static int usb_enumerate_device_otg(struct usb_device *udev) | |||
2267 | } | 2274 | } |
2268 | } | 2275 | } |
2269 | } | 2276 | } |
2270 | |||
2271 | if (!is_targeted(udev)) { | ||
2272 | |||
2273 | /* Maybe it can talk to us, though we can't talk to it. | ||
2274 | * (Includes HNP test device.) | ||
2275 | */ | ||
2276 | if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { | ||
2277 | err = usb_port_suspend(udev, PMSG_SUSPEND); | ||
2278 | if (err < 0) | ||
2279 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); | ||
2280 | } | ||
2281 | err = -ENOTSUPP; | ||
2282 | goto fail; | ||
2283 | } | ||
2284 | fail: | ||
2285 | #endif | 2277 | #endif |
2286 | return err; | 2278 | return err; |
2287 | } | 2279 | } |
@@ -2304,6 +2296,7 @@ fail: | |||
2304 | static int usb_enumerate_device(struct usb_device *udev) | 2296 | static int usb_enumerate_device(struct usb_device *udev) |
2305 | { | 2297 | { |
2306 | int err; | 2298 | int err; |
2299 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
2307 | 2300 | ||
2308 | if (udev->config == NULL) { | 2301 | if (udev->config == NULL) { |
2309 | err = usb_get_configuration(udev); | 2302 | err = usb_get_configuration(udev); |
@@ -2325,6 +2318,20 @@ static int usb_enumerate_device(struct usb_device *udev) | |||
2325 | if (err < 0) | 2318 | if (err < 0) |
2326 | return err; | 2319 | return err; |
2327 | 2320 | ||
2321 | if (IS_ENABLED(CONFIG_USB_OTG_WHITELIST) && hcd->tpl_support && | ||
2322 | !is_targeted(udev)) { | ||
2323 | /* Maybe it can talk to us, though we can't talk to it. | ||
2324 | * (Includes HNP test device.) | ||
2325 | */ | ||
2326 | if (IS_ENABLED(CONFIG_USB_OTG) && (udev->bus->b_hnp_enable | ||
2327 | || udev->bus->is_b_host)) { | ||
2328 | err = usb_port_suspend(udev, PMSG_AUTO_SUSPEND); | ||
2329 | if (err < 0) | ||
2330 | dev_dbg(&udev->dev, "HNP fail, %d\n", err); | ||
2331 | } | ||
2332 | return -ENOTSUPP; | ||
2333 | } | ||
2334 | |||
2328 | usb_detect_interface_quirks(udev); | 2335 | usb_detect_interface_quirks(udev); |
2329 | 2336 | ||
2330 | return 0; | 2337 | return 0; |
@@ -3070,7 +3077,7 @@ static unsigned wakeup_enabled_descendants(struct usb_device *udev) | |||
3070 | * Once VBUS drop breaks the circuit, the port it's using has to go through | 3077 | * Once VBUS drop breaks the circuit, the port it's using has to go through |
3071 | * normal re-enumeration procedures, starting with enabling VBUS power. | 3078 | * normal re-enumeration procedures, starting with enabling VBUS power. |
3072 | * Other than re-initializing the hub (plug/unplug, except for root hubs), | 3079 | * Other than re-initializing the hub (plug/unplug, except for root hubs), |
3073 | * Linux (2.6) currently has NO mechanisms to initiate that: no khubd | 3080 | * Linux (2.6) currently has NO mechanisms to initiate that: no hub_wq |
3074 | * timer, no SRP, no requests through sysfs. | 3081 | * timer, no SRP, no requests through sysfs. |
3075 | * | 3082 | * |
3076 | * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get | 3083 | * If Runtime PM isn't enabled or used, non-SuperSpeed devices may not get |
@@ -3212,7 +3219,7 @@ static int finish_port_resume(struct usb_device *udev) | |||
3212 | /* usb ch9 identifies four variants of SUSPENDED, based on what | 3219 | /* usb ch9 identifies four variants of SUSPENDED, based on what |
3213 | * state the device resumes to. Linux currently won't see the | 3220 | * state the device resumes to. Linux currently won't see the |
3214 | * first two on the host side; they'd be inside hub_port_init() | 3221 | * first two on the host side; they'd be inside hub_port_init() |
3215 | * during many timeouts, but khubd can't suspend until later. | 3222 | * during many timeouts, but hub_wq can't suspend until later. |
3216 | */ | 3223 | */ |
3217 | usb_set_device_state(udev, udev->actconfig | 3224 | usb_set_device_state(udev, udev->actconfig |
3218 | ? USB_STATE_CONFIGURED | 3225 | ? USB_STATE_CONFIGURED |
@@ -3577,7 +3584,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
3577 | 3584 | ||
3578 | dev_dbg(&intf->dev, "%s\n", __func__); | 3585 | dev_dbg(&intf->dev, "%s\n", __func__); |
3579 | 3586 | ||
3580 | /* stop khubd and related activity */ | 3587 | /* stop hub_wq and related activity */ |
3581 | hub_quiesce(hub, HUB_SUSPEND); | 3588 | hub_quiesce(hub, HUB_SUSPEND); |
3582 | return 0; | 3589 | return 0; |
3583 | } | 3590 | } |
@@ -4461,8 +4468,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4461 | if (retval) | 4468 | if (retval) |
4462 | goto fail; | 4469 | goto fail; |
4463 | 4470 | ||
4464 | if (hcd->phy && !hdev->parent) | 4471 | if (hcd->usb_phy && !hdev->parent) |
4465 | usb_phy_notify_connect(hcd->phy, udev->speed); | 4472 | usb_phy_notify_connect(hcd->usb_phy, udev->speed); |
4466 | 4473 | ||
4467 | /* | 4474 | /* |
4468 | * Some superspeed devices have finished the link training process | 4475 | * Some superspeed devices have finished the link training process |
@@ -4538,6 +4545,9 @@ check_highspeed (struct usb_hub *hub, struct usb_device *udev, int port1) | |||
4538 | struct usb_qualifier_descriptor *qual; | 4545 | struct usb_qualifier_descriptor *qual; |
4539 | int status; | 4546 | int status; |
4540 | 4547 | ||
4548 | if (udev->quirks & USB_QUIRK_DEVICE_QUALIFIER) | ||
4549 | return; | ||
4550 | |||
4541 | qual = kmalloc (sizeof *qual, GFP_KERNEL); | 4551 | qual = kmalloc (sizeof *qual, GFP_KERNEL); |
4542 | if (qual == NULL) | 4552 | if (qual == NULL) |
4543 | return; | 4553 | return; |
@@ -4617,9 +4627,9 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, | |||
4617 | 4627 | ||
4618 | /* Disconnect any existing devices under this port */ | 4628 | /* Disconnect any existing devices under this port */ |
4619 | if (udev) { | 4629 | if (udev) { |
4620 | if (hcd->phy && !hdev->parent && | 4630 | if (hcd->usb_phy && !hdev->parent && |
4621 | !(portstatus & USB_PORT_STAT_CONNECTION)) | 4631 | !(portstatus & USB_PORT_STAT_CONNECTION)) |
4622 | usb_phy_notify_disconnect(hcd->phy, udev->speed); | 4632 | usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); |
4623 | usb_disconnect(&port_dev->child); | 4633 | usb_disconnect(&port_dev->child); |
4624 | } | 4634 | } |
4625 | 4635 | ||
@@ -4970,10 +4980,10 @@ static void port_event(struct usb_hub *hub, int port1) | |||
4970 | * On disconnect USB3 protocol ports transit from U0 to | 4980 | * On disconnect USB3 protocol ports transit from U0 to |
4971 | * SS.Inactive to Rx.Detect. If this happens a warm- | 4981 | * SS.Inactive to Rx.Detect. If this happens a warm- |
4972 | * reset is not needed, but a (re)connect may happen | 4982 | * reset is not needed, but a (re)connect may happen |
4973 | * before khubd runs and sees the disconnect, and the | 4983 | * before hub_wq runs and sees the disconnect, and the |
4974 | * device may be an unknown state. | 4984 | * device may be an unknown state. |
4975 | * | 4985 | * |
4976 | * If the port went through SS.Inactive without khubd | 4986 | * If the port went through SS.Inactive without hub_wq |
4977 | * seeing it the C_LINK_STATE change flag will be set, | 4987 | * seeing it the C_LINK_STATE change flag will be set, |
4978 | * and we reset the dev to put it in a known state. | 4988 | * and we reset the dev to put it in a known state. |
4979 | */ | 4989 | */ |
@@ -4992,10 +5002,8 @@ static void port_event(struct usb_hub *hub, int port1) | |||
4992 | hub_port_connect_change(hub, port1, portstatus, portchange); | 5002 | hub_port_connect_change(hub, port1, portstatus, portchange); |
4993 | } | 5003 | } |
4994 | 5004 | ||
4995 | 5005 | static void hub_event(struct work_struct *work) | |
4996 | static void hub_events(void) | ||
4997 | { | 5006 | { |
4998 | struct list_head *tmp; | ||
4999 | struct usb_device *hdev; | 5007 | struct usb_device *hdev; |
5000 | struct usb_interface *intf; | 5008 | struct usb_interface *intf; |
5001 | struct usb_hub *hub; | 5009 | struct usb_hub *hub; |
@@ -5004,166 +5012,117 @@ static void hub_events(void) | |||
5004 | u16 hubchange; | 5012 | u16 hubchange; |
5005 | int i, ret; | 5013 | int i, ret; |
5006 | 5014 | ||
5007 | /* | 5015 | hub = container_of(work, struct usb_hub, events); |
5008 | * We restart the list every time to avoid a deadlock with | 5016 | hdev = hub->hdev; |
5009 | * deleting hubs downstream from this one. This should be | 5017 | hub_dev = hub->intfdev; |
5010 | * safe since we delete the hub from the event list. | 5018 | intf = to_usb_interface(hub_dev); |
5011 | * Not the most efficient, but avoids deadlocks. | 5019 | |
5012 | */ | 5020 | dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n", |
5013 | while (1) { | 5021 | hdev->state, hdev->maxchild, |
5022 | /* NOTE: expects max 15 ports... */ | ||
5023 | (u16) hub->change_bits[0], | ||
5024 | (u16) hub->event_bits[0]); | ||
5025 | |||
5026 | /* Lock the device, then check to see if we were | ||
5027 | * disconnected while waiting for the lock to succeed. */ | ||
5028 | usb_lock_device(hdev); | ||
5029 | if (unlikely(hub->disconnected)) | ||
5030 | goto out_hdev_lock; | ||
5031 | |||
5032 | /* If the hub has died, clean up after it */ | ||
5033 | if (hdev->state == USB_STATE_NOTATTACHED) { | ||
5034 | hub->error = -ENODEV; | ||
5035 | hub_quiesce(hub, HUB_DISCONNECT); | ||
5036 | goto out_hdev_lock; | ||
5037 | } | ||
5038 | |||
5039 | /* Autoresume */ | ||
5040 | ret = usb_autopm_get_interface(intf); | ||
5041 | if (ret) { | ||
5042 | dev_dbg(hub_dev, "Can't autoresume: %d\n", ret); | ||
5043 | goto out_hdev_lock; | ||
5044 | } | ||
5014 | 5045 | ||
5015 | /* Grab the first entry at the beginning of the list */ | 5046 | /* If this is an inactive hub, do nothing */ |
5016 | spin_lock_irq(&hub_event_lock); | 5047 | if (hub->quiescing) |
5017 | if (list_empty(&hub_event_list)) { | 5048 | goto out_autopm; |
5018 | spin_unlock_irq(&hub_event_lock); | ||
5019 | break; | ||
5020 | } | ||
5021 | 5049 | ||
5022 | tmp = hub_event_list.next; | 5050 | if (hub->error) { |
5023 | list_del_init(tmp); | 5051 | dev_dbg(hub_dev, "resetting for error %d\n", hub->error); |
5024 | |||
5025 | hub = list_entry(tmp, struct usb_hub, event_list); | ||
5026 | kref_get(&hub->kref); | ||
5027 | hdev = hub->hdev; | ||
5028 | usb_get_dev(hdev); | ||
5029 | spin_unlock_irq(&hub_event_lock); | ||
5030 | |||
5031 | hub_dev = hub->intfdev; | ||
5032 | intf = to_usb_interface(hub_dev); | ||
5033 | dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n", | ||
5034 | hdev->state, hdev->maxchild, | ||
5035 | /* NOTE: expects max 15 ports... */ | ||
5036 | (u16) hub->change_bits[0], | ||
5037 | (u16) hub->event_bits[0]); | ||
5038 | |||
5039 | /* Lock the device, then check to see if we were | ||
5040 | * disconnected while waiting for the lock to succeed. */ | ||
5041 | usb_lock_device(hdev); | ||
5042 | if (unlikely(hub->disconnected)) | ||
5043 | goto loop_disconnected; | ||
5044 | |||
5045 | /* If the hub has died, clean up after it */ | ||
5046 | if (hdev->state == USB_STATE_NOTATTACHED) { | ||
5047 | hub->error = -ENODEV; | ||
5048 | hub_quiesce(hub, HUB_DISCONNECT); | ||
5049 | goto loop; | ||
5050 | } | ||
5051 | 5052 | ||
5052 | /* Autoresume */ | 5053 | ret = usb_reset_device(hdev); |
5053 | ret = usb_autopm_get_interface(intf); | ||
5054 | if (ret) { | 5054 | if (ret) { |
5055 | dev_dbg(hub_dev, "Can't autoresume: %d\n", ret); | 5055 | dev_dbg(hub_dev, "error resetting hub: %d\n", ret); |
5056 | goto loop; | 5056 | goto out_autopm; |
5057 | } | 5057 | } |
5058 | 5058 | ||
5059 | /* If this is an inactive hub, do nothing */ | 5059 | hub->nerrors = 0; |
5060 | if (hub->quiescing) | 5060 | hub->error = 0; |
5061 | goto loop_autopm; | 5061 | } |
5062 | |||
5063 | if (hub->error) { | ||
5064 | dev_dbg (hub_dev, "resetting for error %d\n", | ||
5065 | hub->error); | ||
5066 | 5062 | ||
5067 | ret = usb_reset_device(hdev); | 5063 | /* deal with port status changes */ |
5068 | if (ret) { | 5064 | for (i = 1; i <= hdev->maxchild; i++) { |
5069 | dev_dbg (hub_dev, | 5065 | struct usb_port *port_dev = hub->ports[i - 1]; |
5070 | "error resetting hub: %d\n", ret); | ||
5071 | goto loop_autopm; | ||
5072 | } | ||
5073 | 5066 | ||
5074 | hub->nerrors = 0; | 5067 | if (test_bit(i, hub->event_bits) |
5075 | hub->error = 0; | 5068 | || test_bit(i, hub->change_bits) |
5069 | || test_bit(i, hub->wakeup_bits)) { | ||
5070 | /* | ||
5071 | * The get_noresume and barrier ensure that if | ||
5072 | * the port was in the process of resuming, we | ||
5073 | * flush that work and keep the port active for | ||
5074 | * the duration of the port_event(). However, | ||
5075 | * if the port is runtime pm suspended | ||
5076 | * (powered-off), we leave it in that state, run | ||
5077 | * an abbreviated port_event(), and move on. | ||
5078 | */ | ||
5079 | pm_runtime_get_noresume(&port_dev->dev); | ||
5080 | pm_runtime_barrier(&port_dev->dev); | ||
5081 | usb_lock_port(port_dev); | ||
5082 | port_event(hub, i); | ||
5083 | usb_unlock_port(port_dev); | ||
5084 | pm_runtime_put_sync(&port_dev->dev); | ||
5076 | } | 5085 | } |
5086 | } | ||
5077 | 5087 | ||
5078 | /* deal with port status changes */ | 5088 | /* deal with hub status changes */ |
5079 | for (i = 1; i <= hdev->maxchild; i++) { | 5089 | if (test_and_clear_bit(0, hub->event_bits) == 0) |
5080 | struct usb_port *port_dev = hub->ports[i - 1]; | 5090 | ; /* do nothing */ |
5081 | 5091 | else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) | |
5082 | if (test_bit(i, hub->event_bits) | 5092 | dev_err(hub_dev, "get_hub_status failed\n"); |
5083 | || test_bit(i, hub->change_bits) | 5093 | else { |
5084 | || test_bit(i, hub->wakeup_bits)) { | 5094 | if (hubchange & HUB_CHANGE_LOCAL_POWER) { |
5085 | /* | 5095 | dev_dbg(hub_dev, "power change\n"); |
5086 | * The get_noresume and barrier ensure that if | 5096 | clear_hub_feature(hdev, C_HUB_LOCAL_POWER); |
5087 | * the port was in the process of resuming, we | 5097 | if (hubstatus & HUB_STATUS_LOCAL_POWER) |
5088 | * flush that work and keep the port active for | 5098 | /* FIXME: Is this always true? */ |
5089 | * the duration of the port_event(). However, | 5099 | hub->limited_power = 1; |
5090 | * if the port is runtime pm suspended | 5100 | else |
5091 | * (powered-off), we leave it in that state, run | 5101 | hub->limited_power = 0; |
5092 | * an abbreviated port_event(), and move on. | ||
5093 | */ | ||
5094 | pm_runtime_get_noresume(&port_dev->dev); | ||
5095 | pm_runtime_barrier(&port_dev->dev); | ||
5096 | usb_lock_port(port_dev); | ||
5097 | port_event(hub, i); | ||
5098 | usb_unlock_port(port_dev); | ||
5099 | pm_runtime_put_sync(&port_dev->dev); | ||
5100 | } | ||
5101 | } | 5102 | } |
5103 | if (hubchange & HUB_CHANGE_OVERCURRENT) { | ||
5104 | u16 status = 0; | ||
5105 | u16 unused; | ||
5102 | 5106 | ||
5103 | /* deal with hub status changes */ | 5107 | dev_dbg(hub_dev, "over-current change\n"); |
5104 | if (test_and_clear_bit(0, hub->event_bits) == 0) | 5108 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); |
5105 | ; /* do nothing */ | 5109 | msleep(500); /* Cool down */ |
5106 | else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) | 5110 | hub_power_on(hub, true); |
5107 | dev_err (hub_dev, "get_hub_status failed\n"); | 5111 | hub_hub_status(hub, &status, &unused); |
5108 | else { | 5112 | if (status & HUB_STATUS_OVERCURRENT) |
5109 | if (hubchange & HUB_CHANGE_LOCAL_POWER) { | 5113 | dev_err(hub_dev, "over-current condition\n"); |
5110 | dev_dbg (hub_dev, "power change\n"); | ||
5111 | clear_hub_feature(hdev, C_HUB_LOCAL_POWER); | ||
5112 | if (hubstatus & HUB_STATUS_LOCAL_POWER) | ||
5113 | /* FIXME: Is this always true? */ | ||
5114 | hub->limited_power = 1; | ||
5115 | else | ||
5116 | hub->limited_power = 0; | ||
5117 | } | ||
5118 | if (hubchange & HUB_CHANGE_OVERCURRENT) { | ||
5119 | u16 status = 0; | ||
5120 | u16 unused; | ||
5121 | |||
5122 | dev_dbg(hub_dev, "over-current change\n"); | ||
5123 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); | ||
5124 | msleep(500); /* Cool down */ | ||
5125 | hub_power_on(hub, true); | ||
5126 | hub_hub_status(hub, &status, &unused); | ||
5127 | if (status & HUB_STATUS_OVERCURRENT) | ||
5128 | dev_err(hub_dev, "over-current " | ||
5129 | "condition\n"); | ||
5130 | } | ||
5131 | } | 5114 | } |
5115 | } | ||
5132 | 5116 | ||
5133 | loop_autopm: | 5117 | out_autopm: |
5134 | /* Balance the usb_autopm_get_interface() above */ | 5118 | /* Balance the usb_autopm_get_interface() above */ |
5135 | usb_autopm_put_interface_no_suspend(intf); | 5119 | usb_autopm_put_interface_no_suspend(intf); |
5136 | loop: | 5120 | out_hdev_lock: |
5137 | /* Balance the usb_autopm_get_interface_no_resume() in | 5121 | usb_unlock_device(hdev); |
5138 | * kick_khubd() and allow autosuspend. | ||
5139 | */ | ||
5140 | usb_autopm_put_interface(intf); | ||
5141 | loop_disconnected: | ||
5142 | usb_unlock_device(hdev); | ||
5143 | usb_put_dev(hdev); | ||
5144 | kref_put(&hub->kref, hub_release); | ||
5145 | |||
5146 | } /* end while (1) */ | ||
5147 | } | ||
5148 | |||
5149 | static int hub_thread(void *__unused) | ||
5150 | { | ||
5151 | /* khubd needs to be freezable to avoid interfering with USB-PERSIST | ||
5152 | * port handover. Otherwise it might see that a full-speed device | ||
5153 | * was gone before the EHCI controller had handed its port over to | ||
5154 | * the companion full-speed controller. | ||
5155 | */ | ||
5156 | set_freezable(); | ||
5157 | |||
5158 | do { | ||
5159 | hub_events(); | ||
5160 | wait_event_freezable(khubd_wait, | ||
5161 | !list_empty(&hub_event_list) || | ||
5162 | kthread_should_stop()); | ||
5163 | } while (!kthread_should_stop() || !list_empty(&hub_event_list)); | ||
5164 | 5122 | ||
5165 | pr_debug("%s: khubd exiting\n", usbcore_name); | 5123 | /* Balance the stuff in kick_hub_wq() and allow autosuspend */ |
5166 | return 0; | 5124 | usb_autopm_put_interface(intf); |
5125 | kref_put(&hub->kref, hub_release); | ||
5167 | } | 5126 | } |
5168 | 5127 | ||
5169 | static const struct usb_device_id hub_id_table[] = { | 5128 | static const struct usb_device_id hub_id_table[] = { |
@@ -5203,20 +5162,26 @@ int usb_hub_init(void) | |||
5203 | return -1; | 5162 | return -1; |
5204 | } | 5163 | } |
5205 | 5164 | ||
5206 | khubd_task = kthread_run(hub_thread, NULL, "khubd"); | 5165 | /* |
5207 | if (!IS_ERR(khubd_task)) | 5166 | * The workqueue needs to be freezable to avoid interfering with |
5167 | * USB-PERSIST port handover. Otherwise it might see that a full-speed | ||
5168 | * device was gone before the EHCI controller had handed its port | ||
5169 | * over to the companion full-speed controller. | ||
5170 | */ | ||
5171 | hub_wq = alloc_workqueue("usb_hub_wq", WQ_FREEZABLE, 0); | ||
5172 | if (hub_wq) | ||
5208 | return 0; | 5173 | return 0; |
5209 | 5174 | ||
5210 | /* Fall through if kernel_thread failed */ | 5175 | /* Fall through if kernel_thread failed */ |
5211 | usb_deregister(&hub_driver); | 5176 | usb_deregister(&hub_driver); |
5212 | printk(KERN_ERR "%s: can't start khubd\n", usbcore_name); | 5177 | pr_err("%s: can't allocate workqueue for usb hub\n", usbcore_name); |
5213 | 5178 | ||
5214 | return -1; | 5179 | return -1; |
5215 | } | 5180 | } |
5216 | 5181 | ||
5217 | void usb_hub_cleanup(void) | 5182 | void usb_hub_cleanup(void) |
5218 | { | 5183 | { |
5219 | kthread_stop(khubd_task); | 5184 | destroy_workqueue(hub_wq); |
5220 | 5185 | ||
5221 | /* | 5186 | /* |
5222 | * Hub resources are freed for us by usb_deregister. It calls | 5187 | * Hub resources are freed for us by usb_deregister. It calls |
@@ -5325,7 +5290,7 @@ static int descriptors_changed(struct usb_device *udev, | |||
5325 | * former operating configuration. If the reset fails, or the device's | 5290 | * former operating configuration. If the reset fails, or the device's |
5326 | * descriptors change from their values before the reset, or the original | 5291 | * descriptors change from their values before the reset, or the original |
5327 | * configuration and altsettings cannot be restored, a flag will be set | 5292 | * configuration and altsettings cannot be restored, a flag will be set |
5328 | * telling khubd to pretend the device has been disconnected and then | 5293 | * telling hub_wq to pretend the device has been disconnected and then |
5329 | * re-connected. All drivers will be unbound, and the device will be | 5294 | * re-connected. All drivers will be unbound, and the device will be |
5330 | * re-enumerated and probed all over again. | 5295 | * re-enumerated and probed all over again. |
5331 | * | 5296 | * |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index c77d8778af4b..688817fb3246 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -41,7 +41,6 @@ struct usb_hub { | |||
41 | int error; /* last reported error */ | 41 | int error; /* last reported error */ |
42 | int nerrors; /* track consecutive errors */ | 42 | int nerrors; /* track consecutive errors */ |
43 | 43 | ||
44 | struct list_head event_list; /* hubs w/data or errs ready */ | ||
45 | unsigned long event_bits[1]; /* status change bitmask */ | 44 | unsigned long event_bits[1]; /* status change bitmask */ |
46 | unsigned long change_bits[1]; /* ports with logical connect | 45 | unsigned long change_bits[1]; /* ports with logical connect |
47 | status change */ | 46 | status change */ |
@@ -77,6 +76,7 @@ struct usb_hub { | |||
77 | u8 indicator[USB_MAXCHILDREN]; | 76 | u8 indicator[USB_MAXCHILDREN]; |
78 | struct delayed_work leds; | 77 | struct delayed_work leds; |
79 | struct delayed_work init_work; | 78 | struct delayed_work init_work; |
79 | struct work_struct events; | ||
80 | struct usb_port **ports; | 80 | struct usb_port **ports; |
81 | }; | 81 | }; |
82 | 82 | ||
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 0c8a7fc4dad8..f7b7713cfb2a 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -770,9 +770,7 @@ static int usb_get_langid(struct usb_device *dev, unsigned char *tbuf) | |||
770 | dev->string_langid = 0x0409; | 770 | dev->string_langid = 0x0409; |
771 | dev->have_langid = 1; | 771 | dev->have_langid = 1; |
772 | dev_err(&dev->dev, | 772 | dev_err(&dev->dev, |
773 | "string descriptor 0 malformed (err = %d), " | 773 | "language id specifier not provided by device, defaulting to English\n"); |
774 | "defaulting to 0x%04x\n", | ||
775 | err, dev->string_langid); | ||
776 | return 0; | 774 | return 0; |
777 | } | 775 | } |
778 | 776 | ||
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h index e8cdce571bb1..de0c9c9d7091 100644 --- a/drivers/usb/core/otg_whitelist.h +++ b/drivers/usb/core/otg_whitelist.h | |||
@@ -10,8 +10,8 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * This OTG Whitelist is the OTG "Targeted Peripheral List". It should | 13 | * This OTG and Embedded Host Whitelist is "Targeted Peripheral List". |
14 | * mostly use of USB_DEVICE() or USB_DEVICE_VER() entries.. | 14 | * It should mostly use of USB_DEVICE() or USB_DEVICE_VER() entries.. |
15 | * | 15 | * |
16 | * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING! | 16 | * YOU _SHOULD_ CHANGE THIS LIST TO MATCH YOUR PRODUCT AND ITS TESTING! |
17 | */ | 17 | */ |
@@ -50,10 +50,6 @@ static int is_targeted(struct usb_device *dev) | |||
50 | { | 50 | { |
51 | struct usb_device_id *id = whitelist_table; | 51 | struct usb_device_id *id = whitelist_table; |
52 | 52 | ||
53 | /* possible in developer configs only! */ | ||
54 | if (!dev->bus->otg_port) | ||
55 | return 1; | ||
56 | |||
57 | /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */ | 53 | /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */ |
58 | if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && | 54 | if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a && |
59 | le16_to_cpu(dev->descriptor.idProduct) == 0xbadd)) | 55 | le16_to_cpu(dev->descriptor.idProduct) == 0xbadd)) |
@@ -103,10 +99,7 @@ static int is_targeted(struct usb_device *dev) | |||
103 | dev_err(&dev->dev, "device v%04x p%04x is not supported\n", | 99 | dev_err(&dev->dev, "device v%04x p%04x is not supported\n", |
104 | le16_to_cpu(dev->descriptor.idVendor), | 100 | le16_to_cpu(dev->descriptor.idVendor), |
105 | le16_to_cpu(dev->descriptor.idProduct)); | 101 | le16_to_cpu(dev->descriptor.idProduct)); |
106 | #ifdef CONFIG_USB_OTG_WHITELIST | 102 | |
107 | return 0; | 103 | return 0; |
108 | #else | ||
109 | return 1; | ||
110 | #endif | ||
111 | } | 104 | } |
112 | 105 | ||
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index bae636e2a1a3..5ae883dc21f5 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c | |||
@@ -93,6 +93,10 @@ static const struct usb_device_id usb_quirk_list[] = { | |||
93 | { USB_DEVICE(0x04e8, 0x6601), .driver_info = | 93 | { USB_DEVICE(0x04e8, 0x6601), .driver_info = |
94 | USB_QUIRK_CONFIG_INTF_STRINGS }, | 94 | USB_QUIRK_CONFIG_INTF_STRINGS }, |
95 | 95 | ||
96 | /* Elan Touchscreen */ | ||
97 | { USB_DEVICE(0x04f3, 0x0089), .driver_info = | ||
98 | USB_QUIRK_DEVICE_QUALIFIER }, | ||
99 | |||
96 | /* Roland SC-8820 */ | 100 | /* Roland SC-8820 */ |
97 | { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, | 101 | { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, |
98 | 102 | ||
@@ -159,6 +163,10 @@ static const struct usb_device_id usb_quirk_list[] = { | |||
159 | /* USB3503 */ | 163 | /* USB3503 */ |
160 | { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME }, | 164 | { USB_DEVICE(0x0424, 0x3503), .driver_info = USB_QUIRK_RESET_RESUME }, |
161 | 165 | ||
166 | /* ASUS Base Station(T100) */ | ||
167 | { USB_DEVICE(0x0b05, 0x17e0), .driver_info = | ||
168 | USB_QUIRK_IGNORE_REMOTE_WAKEUP }, | ||
169 | |||
162 | { } /* terminating entry must be last */ | 170 | { } /* terminating entry must be last */ |
163 | }; | 171 | }; |
164 | 172 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index d9d08720c386..b1b34d0557c9 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -48,7 +48,7 @@ static inline unsigned usb_get_max_power(struct usb_device *udev, | |||
48 | return c->desc.bMaxPower * mul; | 48 | return c->desc.bMaxPower * mul; |
49 | } | 49 | } |
50 | 50 | ||
51 | extern void usb_kick_khubd(struct usb_device *dev); | 51 | extern void usb_kick_hub_wq(struct usb_device *dev); |
52 | extern int usb_match_one_id_intf(struct usb_device *dev, | 52 | extern int usb_match_one_id_intf(struct usb_device *dev, |
53 | struct usb_host_interface *intf, | 53 | struct usb_host_interface *intf, |
54 | const struct usb_device_id *id); | 54 | const struct usb_device_id *id); |
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 27d2c9b8a034..d9269459d481 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c | |||
@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) | |||
118 | { | 118 | { |
119 | u32 greset; | 119 | u32 greset; |
120 | int count = 0; | 120 | int count = 0; |
121 | u32 gusbcfg; | ||
121 | 122 | ||
122 | dev_vdbg(hsotg->dev, "%s()\n", __func__); | 123 | dev_vdbg(hsotg->dev, "%s()\n", __func__); |
123 | 124 | ||
@@ -148,6 +149,23 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg) | |||
148 | } | 149 | } |
149 | } while (greset & GRSTCTL_CSFTRST); | 150 | } while (greset & GRSTCTL_CSFTRST); |
150 | 151 | ||
152 | if (hsotg->dr_mode == USB_DR_MODE_HOST) { | ||
153 | gusbcfg = readl(hsotg->regs + GUSBCFG); | ||
154 | gusbcfg &= ~GUSBCFG_FORCEDEVMODE; | ||
155 | gusbcfg |= GUSBCFG_FORCEHOSTMODE; | ||
156 | writel(gusbcfg, hsotg->regs + GUSBCFG); | ||
157 | } else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { | ||
158 | gusbcfg = readl(hsotg->regs + GUSBCFG); | ||
159 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; | ||
160 | gusbcfg |= GUSBCFG_FORCEDEVMODE; | ||
161 | writel(gusbcfg, hsotg->regs + GUSBCFG); | ||
162 | } else if (hsotg->dr_mode == USB_DR_MODE_OTG) { | ||
163 | gusbcfg = readl(hsotg->regs + GUSBCFG); | ||
164 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; | ||
165 | gusbcfg &= ~GUSBCFG_FORCEDEVMODE; | ||
166 | writel(gusbcfg, hsotg->regs + GUSBCFG); | ||
167 | } | ||
168 | |||
151 | /* | 169 | /* |
152 | * NOTE: This long sleep is _very_ important, otherwise the core will | 170 | * NOTE: This long sleep is _very_ important, otherwise the core will |
153 | * not stay in host mode after a connector ID change! | 171 | * not stay in host mode after a connector ID change! |
@@ -2674,23 +2692,23 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) | |||
2674 | hwcfg2 = readl(hsotg->regs + GHWCFG2); | 2692 | hwcfg2 = readl(hsotg->regs + GHWCFG2); |
2675 | hwcfg3 = readl(hsotg->regs + GHWCFG3); | 2693 | hwcfg3 = readl(hsotg->regs + GHWCFG3); |
2676 | hwcfg4 = readl(hsotg->regs + GHWCFG4); | 2694 | hwcfg4 = readl(hsotg->regs + GHWCFG4); |
2677 | gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ); | ||
2678 | grxfsiz = readl(hsotg->regs + GRXFSIZ); | 2695 | grxfsiz = readl(hsotg->regs + GRXFSIZ); |
2679 | 2696 | ||
2680 | dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); | 2697 | dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); |
2681 | dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); | 2698 | dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); |
2682 | dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); | 2699 | dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); |
2683 | dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); | 2700 | dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); |
2684 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); | ||
2685 | dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); | 2701 | dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); |
2686 | 2702 | ||
2687 | /* Force host mode to get HPTXFSIZ exact power on value */ | 2703 | /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */ |
2688 | gusbcfg = readl(hsotg->regs + GUSBCFG); | 2704 | gusbcfg = readl(hsotg->regs + GUSBCFG); |
2689 | gusbcfg |= GUSBCFG_FORCEHOSTMODE; | 2705 | gusbcfg |= GUSBCFG_FORCEHOSTMODE; |
2690 | writel(gusbcfg, hsotg->regs + GUSBCFG); | 2706 | writel(gusbcfg, hsotg->regs + GUSBCFG); |
2691 | usleep_range(100000, 150000); | 2707 | usleep_range(100000, 150000); |
2692 | 2708 | ||
2709 | gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ); | ||
2693 | hptxfsiz = readl(hsotg->regs + HPTXFSIZ); | 2710 | hptxfsiz = readl(hsotg->regs + HPTXFSIZ); |
2711 | dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); | ||
2694 | dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); | 2712 | dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); |
2695 | gusbcfg = readl(hsotg->regs + GUSBCFG); | 2713 | gusbcfg = readl(hsotg->regs + GUSBCFG); |
2696 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; | 2714 | gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; |
@@ -2725,6 +2743,13 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) | |||
2725 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> | 2743 | width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> |
2726 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; | 2744 | GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; |
2727 | hw->max_transfer_size = (1 << (width + 11)) - 1; | 2745 | hw->max_transfer_size = (1 << (width + 11)) - 1; |
2746 | /* | ||
2747 | * Clip max_transfer_size to 65535. dwc2_hc_setup_align_buf() allocates | ||
2748 | * coherent buffers with this size, and if it's too large we can | ||
2749 | * exhaust the coherent DMA pool. | ||
2750 | */ | ||
2751 | if (hw->max_transfer_size > 65535) | ||
2752 | hw->max_transfer_size = 65535; | ||
2728 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> | 2753 | width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> |
2729 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; | 2754 | GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; |
2730 | hw->max_packet_count = (1 << (width + 4)) - 1; | 2755 | hw->max_packet_count = (1 << (width + 4)) - 1; |
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 1efd10cc9629..bf015ab3b44c 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h | |||
@@ -139,6 +139,7 @@ struct s3c_hsotg_ep { | |||
139 | unsigned int last_load; | 139 | unsigned int last_load; |
140 | unsigned int fifo_load; | 140 | unsigned int fifo_load; |
141 | unsigned short fifo_size; | 141 | unsigned short fifo_size; |
142 | unsigned short fifo_index; | ||
142 | 143 | ||
143 | unsigned char dir_in; | 144 | unsigned char dir_in; |
144 | unsigned char index; | 145 | unsigned char index; |
@@ -194,8 +195,10 @@ struct s3c_hsotg { | |||
194 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | 195 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; |
195 | 196 | ||
196 | u32 phyif; | 197 | u32 phyif; |
198 | int fifo_mem; | ||
197 | unsigned int dedicated_fifos:1; | 199 | unsigned int dedicated_fifos:1; |
198 | unsigned char num_of_eps; | 200 | unsigned char num_of_eps; |
201 | u32 fifo_map; | ||
199 | 202 | ||
200 | struct dentry *debug_root; | 203 | struct dentry *debug_root; |
201 | struct dentry *debug_file; | 204 | struct dentry *debug_file; |
@@ -501,6 +504,10 @@ struct dwc2_hw_params { | |||
501 | * a_peripheral and b_device=>b_host) this may not match | 504 | * a_peripheral and b_device=>b_host) this may not match |
502 | * the core, but allows the software to determine | 505 | * the core, but allows the software to determine |
503 | * transitions | 506 | * transitions |
507 | * @dr_mode: Requested mode of operation, one of following: | ||
508 | * - USB_DR_MODE_PERIPHERAL | ||
509 | * - USB_DR_MODE_HOST | ||
510 | * - USB_DR_MODE_OTG | ||
504 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth | 511 | * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth |
505 | * transfer are in process of being queued | 512 | * transfer are in process of being queued |
506 | * @srp_success: Stores status of SRP request in the case of a FS PHY | 513 | * @srp_success: Stores status of SRP request in the case of a FS PHY |
@@ -592,6 +599,7 @@ struct dwc2_hsotg { | |||
592 | /** Params to actually use */ | 599 | /** Params to actually use */ |
593 | struct dwc2_core_params *core_params; | 600 | struct dwc2_core_params *core_params; |
594 | enum usb_otg_state op_state; | 601 | enum usb_otg_state op_state; |
602 | enum usb_dr_mode dr_mode; | ||
595 | 603 | ||
596 | unsigned int queuing_high_bandwidth:1; | 604 | unsigned int queuing_high_bandwidth:1; |
597 | unsigned int srp_success:1; | 605 | unsigned int srp_success:1; |
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index ce6071d65d51..7b5856fadd93 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c | |||
@@ -182,16 +182,33 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
182 | 182 | ||
183 | /* start at the end of the GNPTXFSIZ, rounded up */ | 183 | /* start at the end of the GNPTXFSIZ, rounded up */ |
184 | addr = 2048 + 1024; | 184 | addr = 2048 + 1024; |
185 | size = 768; | ||
186 | 185 | ||
187 | /* | 186 | /* |
188 | * currently we allocate TX FIFOs for all possible endpoints, | 187 | * Because we have not enough memory to have each TX FIFO of size at |
189 | * and assume that they are all the same size. | 188 | * least 3072 bytes (the maximum single packet size), we create four |
189 | * FIFOs of lenght 1024, and four of length 3072 bytes, and assing | ||
190 | * them to endpoints dynamically according to maxpacket size value of | ||
191 | * given endpoint. | ||
190 | */ | 192 | */ |
191 | 193 | ||
192 | for (ep = 1; ep <= 15; ep++) { | 194 | /* 256*4=1024 bytes FIFO length */ |
195 | size = 256; | ||
196 | for (ep = 1; ep <= 4; ep++) { | ||
193 | val = addr; | 197 | val = addr; |
194 | val |= size << FIFOSIZE_DEPTH_SHIFT; | 198 | val |= size << FIFOSIZE_DEPTH_SHIFT; |
199 | WARN_ONCE(addr + size > hsotg->fifo_mem, | ||
200 | "insufficient fifo memory"); | ||
201 | addr += size; | ||
202 | |||
203 | writel(val, hsotg->regs + DPTXFSIZN(ep)); | ||
204 | } | ||
205 | /* 768*4=3072 bytes FIFO length */ | ||
206 | size = 768; | ||
207 | for (ep = 5; ep <= 8; ep++) { | ||
208 | val = addr; | ||
209 | val |= size << FIFOSIZE_DEPTH_SHIFT; | ||
210 | WARN_ONCE(addr + size > hsotg->fifo_mem, | ||
211 | "insufficient fifo memory"); | ||
195 | addr += size; | 212 | addr += size; |
196 | 213 | ||
197 | writel(val, hsotg->regs + DPTXFSIZN(ep)); | 214 | writel(val, hsotg->regs + DPTXFSIZN(ep)); |
@@ -987,8 +1004,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, | |||
987 | hs_req = ep->req; | 1004 | hs_req = ep->req; |
988 | ep->req = NULL; | 1005 | ep->req = NULL; |
989 | list_del_init(&hs_req->queue); | 1006 | list_del_init(&hs_req->queue); |
990 | hs_req->req.complete(&ep->ep, | 1007 | usb_gadget_giveback_request(&ep->ep, |
991 | &hs_req->req); | 1008 | &hs_req->req); |
992 | } | 1009 | } |
993 | 1010 | ||
994 | /* If we have pending request, then start it */ | 1011 | /* If we have pending request, then start it */ |
@@ -1245,7 +1262,7 @@ static void s3c_hsotg_complete_request(struct s3c_hsotg *hsotg, | |||
1245 | 1262 | ||
1246 | if (hs_req->req.complete) { | 1263 | if (hs_req->req.complete) { |
1247 | spin_unlock(&hsotg->lock); | 1264 | spin_unlock(&hsotg->lock); |
1248 | hs_req->req.complete(&hs_ep->ep, &hs_req->req); | 1265 | usb_gadget_giveback_request(&hs_ep->ep, &hs_req->req); |
1249 | spin_lock(&hsotg->lock); | 1266 | spin_lock(&hsotg->lock); |
1250 | } | 1267 | } |
1251 | 1268 | ||
@@ -1832,7 +1849,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1832 | if (dir_in) { | 1849 | if (dir_in) { |
1833 | int epctl = readl(hsotg->regs + epctl_reg); | 1850 | int epctl = readl(hsotg->regs + epctl_reg); |
1834 | 1851 | ||
1835 | s3c_hsotg_txfifo_flush(hsotg, idx); | 1852 | s3c_hsotg_txfifo_flush(hsotg, hs_ep->fifo_index); |
1836 | 1853 | ||
1837 | if ((epctl & DXEPCTL_STALL) && | 1854 | if ((epctl & DXEPCTL_STALL) && |
1838 | (epctl & DXEPCTL_EPTYPE_BULK)) { | 1855 | (epctl & DXEPCTL_EPTYPE_BULK)) { |
@@ -1981,6 +1998,7 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
1981 | int result, bool force) | 1998 | int result, bool force) |
1982 | { | 1999 | { |
1983 | struct s3c_hsotg_req *req, *treq; | 2000 | struct s3c_hsotg_req *req, *treq; |
2001 | unsigned size; | ||
1984 | 2002 | ||
1985 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { | 2003 | list_for_each_entry_safe(req, treq, &ep->queue, queue) { |
1986 | /* | 2004 | /* |
@@ -1994,9 +2012,11 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
1994 | s3c_hsotg_complete_request(hsotg, ep, req, | 2012 | s3c_hsotg_complete_request(hsotg, ep, req, |
1995 | result); | 2013 | result); |
1996 | } | 2014 | } |
1997 | if (hsotg->dedicated_fifos) | 2015 | if (!hsotg->dedicated_fifos) |
1998 | if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) | 2016 | return; |
1999 | s3c_hsotg_txfifo_flush(hsotg, ep->index); | 2017 | size = (readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4; |
2018 | if (size < ep->fifo_size) | ||
2019 | s3c_hsotg_txfifo_flush(hsotg, ep->fifo_index); | ||
2000 | } | 2020 | } |
2001 | 2021 | ||
2002 | /** | 2022 | /** |
@@ -2437,6 +2457,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2437 | u32 epctrl; | 2457 | u32 epctrl; |
2438 | u32 mps; | 2458 | u32 mps; |
2439 | int dir_in; | 2459 | int dir_in; |
2460 | int i, val, size; | ||
2440 | int ret = 0; | 2461 | int ret = 0; |
2441 | 2462 | ||
2442 | dev_dbg(hsotg->dev, | 2463 | dev_dbg(hsotg->dev, |
@@ -2509,17 +2530,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2509 | break; | 2530 | break; |
2510 | 2531 | ||
2511 | case USB_ENDPOINT_XFER_INT: | 2532 | case USB_ENDPOINT_XFER_INT: |
2512 | if (dir_in) { | 2533 | if (dir_in) |
2513 | /* | ||
2514 | * Allocate our TxFNum by simply using the index | ||
2515 | * of the endpoint for the moment. We could do | ||
2516 | * something better if the host indicates how | ||
2517 | * many FIFOs we are expecting to use. | ||
2518 | */ | ||
2519 | |||
2520 | hs_ep->periodic = 1; | 2534 | hs_ep->periodic = 1; |
2521 | epctrl |= DXEPCTL_TXFNUM(index); | ||
2522 | } | ||
2523 | 2535 | ||
2524 | epctrl |= DXEPCTL_EPTYPE_INTERRUPT; | 2536 | epctrl |= DXEPCTL_EPTYPE_INTERRUPT; |
2525 | break; | 2537 | break; |
@@ -2533,8 +2545,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2533 | * if the hardware has dedicated fifos, we must give each IN EP | 2545 | * if the hardware has dedicated fifos, we must give each IN EP |
2534 | * a unique tx-fifo even if it is non-periodic. | 2546 | * a unique tx-fifo even if it is non-periodic. |
2535 | */ | 2547 | */ |
2536 | if (dir_in && hsotg->dedicated_fifos) | 2548 | if (dir_in && hsotg->dedicated_fifos) { |
2537 | epctrl |= DXEPCTL_TXFNUM(index); | 2549 | size = hs_ep->ep.maxpacket*hs_ep->mc; |
2550 | for (i = 1; i <= 8; ++i) { | ||
2551 | if (hsotg->fifo_map & (1<<i)) | ||
2552 | continue; | ||
2553 | val = readl(hsotg->regs + DPTXFSIZN(i)); | ||
2554 | val = (val >> FIFOSIZE_DEPTH_SHIFT)*4; | ||
2555 | if (val < size) | ||
2556 | continue; | ||
2557 | hsotg->fifo_map |= 1<<i; | ||
2558 | |||
2559 | epctrl |= DXEPCTL_TXFNUM(i); | ||
2560 | hs_ep->fifo_index = i; | ||
2561 | hs_ep->fifo_size = val; | ||
2562 | break; | ||
2563 | } | ||
2564 | if (i == 8) | ||
2565 | return -ENOMEM; | ||
2566 | } | ||
2538 | 2567 | ||
2539 | /* for non control endpoints, set PID to D0 */ | 2568 | /* for non control endpoints, set PID to D0 */ |
2540 | if (index) | 2569 | if (index) |
@@ -2568,7 +2597,7 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2568 | u32 epctrl_reg; | 2597 | u32 epctrl_reg; |
2569 | u32 ctrl; | 2598 | u32 ctrl; |
2570 | 2599 | ||
2571 | dev_info(hsotg->dev, "%s(ep %p)\n", __func__, ep); | 2600 | dev_dbg(hsotg->dev, "%s(ep %p)\n", __func__, ep); |
2572 | 2601 | ||
2573 | if (ep == &hsotg->eps[0].ep) { | 2602 | if (ep == &hsotg->eps[0].ep) { |
2574 | dev_err(hsotg->dev, "%s: called for ep0\n", __func__); | 2603 | dev_err(hsotg->dev, "%s: called for ep0\n", __func__); |
@@ -2581,6 +2610,9 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2581 | /* terminate all requests with shutdown */ | 2610 | /* terminate all requests with shutdown */ |
2582 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); | 2611 | kill_all_requests(hsotg, hs_ep, -ESHUTDOWN, false); |
2583 | 2612 | ||
2613 | hsotg->fifo_map &= ~(1<<hs_ep->fifo_index); | ||
2614 | hs_ep->fifo_index = 0; | ||
2615 | hs_ep->fifo_size = 0; | ||
2584 | 2616 | ||
2585 | ctrl = readl(hsotg->regs + epctrl_reg); | 2617 | ctrl = readl(hsotg->regs + epctrl_reg); |
2586 | ctrl &= ~DXEPCTL_EPENA; | 2618 | ctrl &= ~DXEPCTL_EPENA; |
@@ -2626,7 +2658,7 @@ static int s3c_hsotg_ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2626 | struct s3c_hsotg *hs = hs_ep->parent; | 2658 | struct s3c_hsotg *hs = hs_ep->parent; |
2627 | unsigned long flags; | 2659 | unsigned long flags; |
2628 | 2660 | ||
2629 | dev_info(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); | 2661 | dev_dbg(hs->dev, "ep_dequeue(%p,%p)\n", ep, req); |
2630 | 2662 | ||
2631 | spin_lock_irqsave(&hs->lock, flags); | 2663 | spin_lock_irqsave(&hs->lock, flags); |
2632 | 2664 | ||
@@ -2861,6 +2893,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, | |||
2861 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; | 2893 | hsotg->gadget.dev.of_node = hsotg->dev->of_node; |
2862 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; | 2894 | hsotg->gadget.speed = USB_SPEED_UNKNOWN; |
2863 | 2895 | ||
2896 | clk_enable(hsotg->clk); | ||
2897 | |||
2864 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), | 2898 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
2865 | hsotg->supplies); | 2899 | hsotg->supplies); |
2866 | if (ret) { | 2900 | if (ret) { |
@@ -2909,6 +2943,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, | |||
2909 | 2943 | ||
2910 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); | 2944 | regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); |
2911 | 2945 | ||
2946 | clk_disable(hsotg->clk); | ||
2947 | |||
2912 | return 0; | 2948 | return 0; |
2913 | } | 2949 | } |
2914 | 2950 | ||
@@ -2935,13 +2971,15 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) | |||
2935 | struct s3c_hsotg *hsotg = to_hsotg(gadget); | 2971 | struct s3c_hsotg *hsotg = to_hsotg(gadget); |
2936 | unsigned long flags = 0; | 2972 | unsigned long flags = 0; |
2937 | 2973 | ||
2938 | dev_dbg(hsotg->dev, "%s: is_in: %d\n", __func__, is_on); | 2974 | dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); |
2939 | 2975 | ||
2940 | spin_lock_irqsave(&hsotg->lock, flags); | 2976 | spin_lock_irqsave(&hsotg->lock, flags); |
2941 | if (is_on) { | 2977 | if (is_on) { |
2942 | s3c_hsotg_phy_enable(hsotg); | 2978 | s3c_hsotg_phy_enable(hsotg); |
2979 | clk_enable(hsotg->clk); | ||
2943 | s3c_hsotg_core_init(hsotg); | 2980 | s3c_hsotg_core_init(hsotg); |
2944 | } else { | 2981 | } else { |
2982 | clk_disable(hsotg->clk); | ||
2945 | s3c_hsotg_phy_disable(hsotg); | 2983 | s3c_hsotg_phy_disable(hsotg); |
2946 | } | 2984 | } |
2947 | 2985 | ||
@@ -2972,7 +3010,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
2972 | struct s3c_hsotg_ep *hs_ep, | 3010 | struct s3c_hsotg_ep *hs_ep, |
2973 | int epnum) | 3011 | int epnum) |
2974 | { | 3012 | { |
2975 | u32 ptxfifo; | ||
2976 | char *dir; | 3013 | char *dir; |
2977 | 3014 | ||
2978 | if (epnum == 0) | 3015 | if (epnum == 0) |
@@ -3001,15 +3038,6 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3001 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; | 3038 | hs_ep->ep.ops = &s3c_hsotg_ep_ops; |
3002 | 3039 | ||
3003 | /* | 3040 | /* |
3004 | * Read the FIFO size for the Periodic TX FIFO, even if we're | ||
3005 | * an OUT endpoint, we may as well do this if in future the | ||
3006 | * code is changed to make each endpoint's direction changeable. | ||
3007 | */ | ||
3008 | |||
3009 | ptxfifo = readl(hsotg->regs + DPTXFSIZN(epnum)); | ||
3010 | hs_ep->fifo_size = FIFOSIZE_DEPTH_GET(ptxfifo) * 4; | ||
3011 | |||
3012 | /* | ||
3013 | * if we're using dma, we need to set the next-endpoint pointer | 3041 | * if we're using dma, we need to set the next-endpoint pointer |
3014 | * to be something valid. | 3042 | * to be something valid. |
3015 | */ | 3043 | */ |
@@ -3029,19 +3057,22 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3029 | */ | 3057 | */ |
3030 | static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) | 3058 | static void s3c_hsotg_hw_cfg(struct s3c_hsotg *hsotg) |
3031 | { | 3059 | { |
3032 | u32 cfg2, cfg4; | 3060 | u32 cfg2, cfg3, cfg4; |
3033 | /* check hardware configuration */ | 3061 | /* check hardware configuration */ |
3034 | 3062 | ||
3035 | cfg2 = readl(hsotg->regs + 0x48); | 3063 | cfg2 = readl(hsotg->regs + 0x48); |
3036 | hsotg->num_of_eps = (cfg2 >> 10) & 0xF; | 3064 | hsotg->num_of_eps = (cfg2 >> 10) & 0xF; |
3037 | 3065 | ||
3038 | dev_info(hsotg->dev, "EPs:%d\n", hsotg->num_of_eps); | 3066 | cfg3 = readl(hsotg->regs + 0x4C); |
3067 | hsotg->fifo_mem = (cfg3 >> 16); | ||
3039 | 3068 | ||
3040 | cfg4 = readl(hsotg->regs + 0x50); | 3069 | cfg4 = readl(hsotg->regs + 0x50); |
3041 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; | 3070 | hsotg->dedicated_fifos = (cfg4 >> 25) & 1; |
3042 | 3071 | ||
3043 | dev_info(hsotg->dev, "%s fifos\n", | 3072 | dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", |
3044 | hsotg->dedicated_fifos ? "dedicated" : "shared"); | 3073 | hsotg->num_of_eps, |
3074 | hsotg->dedicated_fifos ? "dedicated" : "shared", | ||
3075 | hsotg->fifo_mem); | ||
3045 | } | 3076 | } |
3046 | 3077 | ||
3047 | /** | 3078 | /** |
@@ -3392,6 +3423,9 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3392 | if (!hsotg) | 3423 | if (!hsotg) |
3393 | return -ENOMEM; | 3424 | return -ENOMEM; |
3394 | 3425 | ||
3426 | /* Set default UTMI width */ | ||
3427 | hsotg->phyif = GUSBCFG_PHYIF16; | ||
3428 | |||
3395 | /* | 3429 | /* |
3396 | * Attempt to find a generic PHY, then look for an old style | 3430 | * Attempt to find a generic PHY, then look for an old style |
3397 | * USB PHY, finally fall back to pdata | 3431 | * USB PHY, finally fall back to pdata |
@@ -3410,8 +3444,15 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3410 | hsotg->plat = plat; | 3444 | hsotg->plat = plat; |
3411 | } else | 3445 | } else |
3412 | hsotg->uphy = uphy; | 3446 | hsotg->uphy = uphy; |
3413 | } else | 3447 | } else { |
3414 | hsotg->phy = phy; | 3448 | hsotg->phy = phy; |
3449 | /* | ||
3450 | * If using the generic PHY framework, check if the PHY bus | ||
3451 | * width is 8-bit and set the phyif appropriately. | ||
3452 | */ | ||
3453 | if (phy_get_bus_width(phy) == 8) | ||
3454 | hsotg->phyif = GUSBCFG_PHYIF8; | ||
3455 | } | ||
3415 | 3456 | ||
3416 | hsotg->dev = dev; | 3457 | hsotg->dev = dev; |
3417 | 3458 | ||
@@ -3471,22 +3512,12 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3471 | goto err_supplies; | 3512 | goto err_supplies; |
3472 | } | 3513 | } |
3473 | 3514 | ||
3474 | /* Set default UTMI width */ | ||
3475 | hsotg->phyif = GUSBCFG_PHYIF16; | ||
3476 | |||
3477 | /* | ||
3478 | * If using the generic PHY framework, check if the PHY bus | ||
3479 | * width is 8-bit and set the phyif appropriately. | ||
3480 | */ | ||
3481 | if (hsotg->phy && (phy_get_bus_width(phy) == 8)) | ||
3482 | hsotg->phyif = GUSBCFG_PHYIF8; | ||
3483 | |||
3484 | /* usb phy enable */ | 3515 | /* usb phy enable */ |
3485 | s3c_hsotg_phy_enable(hsotg); | 3516 | s3c_hsotg_phy_enable(hsotg); |
3486 | 3517 | ||
3487 | s3c_hsotg_corereset(hsotg); | 3518 | s3c_hsotg_corereset(hsotg); |
3488 | s3c_hsotg_init(hsotg); | ||
3489 | s3c_hsotg_hw_cfg(hsotg); | 3519 | s3c_hsotg_hw_cfg(hsotg); |
3520 | s3c_hsotg_init(hsotg); | ||
3490 | 3521 | ||
3491 | ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0, | 3522 | ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0, |
3492 | dev_name(dev), hsotg); | 3523 | dev_name(dev), hsotg); |
@@ -3611,6 +3642,7 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) | |||
3611 | 3642 | ||
3612 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), | 3643 | ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), |
3613 | hsotg->supplies); | 3644 | hsotg->supplies); |
3645 | clk_disable(hsotg->clk); | ||
3614 | } | 3646 | } |
3615 | 3647 | ||
3616 | return ret; | 3648 | return ret; |
@@ -3625,6 +3657,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev) | |||
3625 | if (hsotg->driver) { | 3657 | if (hsotg->driver) { |
3626 | dev_info(hsotg->dev, "resuming usb gadget %s\n", | 3658 | dev_info(hsotg->dev, "resuming usb gadget %s\n", |
3627 | hsotg->driver->driver.name); | 3659 | hsotg->driver->driver.name); |
3660 | |||
3661 | clk_enable(hsotg->clk); | ||
3628 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), | 3662 | ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), |
3629 | hsotg->supplies); | 3663 | hsotg->supplies); |
3630 | } | 3664 | } |
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 4d918ed8d343..0a0e6f0ad15f 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c | |||
@@ -697,29 +697,45 @@ static void *dwc2_hc_init_xfer(struct dwc2_hsotg *hsotg, | |||
697 | } | 697 | } |
698 | 698 | ||
699 | static int dwc2_hc_setup_align_buf(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, | 699 | static int dwc2_hc_setup_align_buf(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, |
700 | struct dwc2_host_chan *chan, void *bufptr) | 700 | struct dwc2_host_chan *chan, |
701 | struct dwc2_hcd_urb *urb, void *bufptr) | ||
701 | { | 702 | { |
702 | u32 buf_size; | 703 | u32 buf_size; |
703 | 704 | struct urb *usb_urb; | |
704 | if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) | 705 | struct usb_hcd *hcd; |
705 | buf_size = hsotg->core_params->max_transfer_size; | ||
706 | else | ||
707 | buf_size = 4096; | ||
708 | 706 | ||
709 | if (!qh->dw_align_buf) { | 707 | if (!qh->dw_align_buf) { |
708 | if (chan->ep_type != USB_ENDPOINT_XFER_ISOC) | ||
709 | buf_size = hsotg->core_params->max_transfer_size; | ||
710 | else | ||
711 | /* 3072 = 3 max-size Isoc packets */ | ||
712 | buf_size = 3072; | ||
713 | |||
710 | qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size, | 714 | qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size, |
711 | &qh->dw_align_buf_dma, | 715 | &qh->dw_align_buf_dma, |
712 | GFP_ATOMIC); | 716 | GFP_ATOMIC); |
713 | if (!qh->dw_align_buf) | 717 | if (!qh->dw_align_buf) |
714 | return -ENOMEM; | 718 | return -ENOMEM; |
719 | qh->dw_align_buf_size = buf_size; | ||
715 | } | 720 | } |
716 | 721 | ||
717 | if (!chan->ep_is_in && chan->xfer_len) { | 722 | if (chan->xfer_len) { |
718 | dma_sync_single_for_cpu(hsotg->dev, chan->xfer_dma, buf_size, | 723 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); |
719 | DMA_TO_DEVICE); | 724 | usb_urb = urb->priv; |
720 | memcpy(qh->dw_align_buf, bufptr, chan->xfer_len); | 725 | |
721 | dma_sync_single_for_device(hsotg->dev, chan->xfer_dma, buf_size, | 726 | if (usb_urb) { |
722 | DMA_TO_DEVICE); | 727 | if (usb_urb->transfer_flags & |
728 | (URB_SETUP_MAP_SINGLE | URB_DMA_MAP_SG | | ||
729 | URB_DMA_MAP_PAGE | URB_DMA_MAP_SINGLE)) { | ||
730 | hcd = dwc2_hsotg_to_hcd(hsotg); | ||
731 | usb_hcd_unmap_urb_for_dma(hcd, usb_urb); | ||
732 | } | ||
733 | if (!chan->ep_is_in) | ||
734 | memcpy(qh->dw_align_buf, bufptr, | ||
735 | chan->xfer_len); | ||
736 | } else { | ||
737 | dev_warn(hsotg->dev, "no URB in dwc2_urb\n"); | ||
738 | } | ||
723 | } | 739 | } |
724 | 740 | ||
725 | chan->align_buf = qh->dw_align_buf_dma; | 741 | chan->align_buf = qh->dw_align_buf_dma; |
@@ -828,7 +844,7 @@ static int dwc2_assign_and_init_hc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | |||
828 | /* Non DWORD-aligned buffer case */ | 844 | /* Non DWORD-aligned buffer case */ |
829 | if (bufptr) { | 845 | if (bufptr) { |
830 | dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); | 846 | dev_vdbg(hsotg->dev, "Non-aligned buffer\n"); |
831 | if (dwc2_hc_setup_align_buf(hsotg, qh, chan, bufptr)) { | 847 | if (dwc2_hc_setup_align_buf(hsotg, qh, chan, urb, bufptr)) { |
832 | dev_err(hsotg->dev, | 848 | dev_err(hsotg->dev, |
833 | "%s: Failed to allocate memory to handle non-dword aligned buffer\n", | 849 | "%s: Failed to allocate memory to handle non-dword aligned buffer\n", |
834 | __func__); | 850 | __func__); |
diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h index fdc6d489084a..a12bb1538666 100644 --- a/drivers/usb/dwc2/hcd.h +++ b/drivers/usb/dwc2/hcd.h | |||
@@ -243,7 +243,8 @@ enum dwc2_transaction_type { | |||
243 | * @ntd: Actual number of transfer descriptors in a list | 243 | * @ntd: Actual number of transfer descriptors in a list |
244 | * @dw_align_buf: Used instead of original buffer if its physical address | 244 | * @dw_align_buf: Used instead of original buffer if its physical address |
245 | * is not dword-aligned | 245 | * is not dword-aligned |
246 | * @dw_align_buf_dma: DMA address for align_buf | 246 | * @dw_align_buf_size: Size of dw_align_buf |
247 | * @dw_align_buf_dma: DMA address for dw_align_buf | ||
247 | * @qtd_list: List of QTDs for this QH | 248 | * @qtd_list: List of QTDs for this QH |
248 | * @channel: Host channel currently processing transfers for this QH | 249 | * @channel: Host channel currently processing transfers for this QH |
249 | * @qh_list_entry: Entry for QH in either the periodic or non-periodic | 250 | * @qh_list_entry: Entry for QH in either the periodic or non-periodic |
@@ -276,6 +277,7 @@ struct dwc2_qh { | |||
276 | u16 start_split_frame; | 277 | u16 start_split_frame; |
277 | u16 ntd; | 278 | u16 ntd; |
278 | u8 *dw_align_buf; | 279 | u8 *dw_align_buf; |
280 | int dw_align_buf_size; | ||
279 | dma_addr_t dw_align_buf_dma; | 281 | dma_addr_t dw_align_buf_dma; |
280 | struct list_head qtd_list; | 282 | struct list_head qtd_list; |
281 | struct dwc2_host_chan *channel; | 283 | struct dwc2_host_chan *channel; |
diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c index 47b9eb5389b4..551ba878b003 100644 --- a/drivers/usb/dwc2/hcd_intr.c +++ b/drivers/usb/dwc2/hcd_intr.c | |||
@@ -465,12 +465,8 @@ static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg, | |||
465 | /* Non DWORD-aligned buffer case handling */ | 465 | /* Non DWORD-aligned buffer case handling */ |
466 | if (chan->align_buf && xfer_length && chan->ep_is_in) { | 466 | if (chan->align_buf && xfer_length && chan->ep_is_in) { |
467 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | 467 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); |
468 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length, | ||
469 | DMA_FROM_DEVICE); | ||
470 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, | 468 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, |
471 | xfer_length); | 469 | xfer_length); |
472 | dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length, | ||
473 | DMA_FROM_DEVICE); | ||
474 | } | 470 | } |
475 | 471 | ||
476 | dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n", | 472 | dev_vdbg(hsotg->dev, "urb->actual_length=%d xfer_length=%d\n", |
@@ -560,14 +556,9 @@ static enum dwc2_halt_status dwc2_update_isoc_urb_state( | |||
560 | chan->ep_is_in) { | 556 | chan->ep_is_in) { |
561 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", | 557 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", |
562 | __func__); | 558 | __func__); |
563 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, | ||
564 | urb->length, DMA_FROM_DEVICE); | ||
565 | memcpy(urb->buf + frame_desc->offset + | 559 | memcpy(urb->buf + frame_desc->offset + |
566 | qtd->isoc_split_offset, chan->qh->dw_align_buf, | 560 | qtd->isoc_split_offset, chan->qh->dw_align_buf, |
567 | frame_desc->actual_length); | 561 | frame_desc->actual_length); |
568 | dma_sync_single_for_device(hsotg->dev, urb->dma, | ||
569 | urb->length, | ||
570 | DMA_FROM_DEVICE); | ||
571 | } | 562 | } |
572 | break; | 563 | break; |
573 | case DWC2_HC_XFER_FRAME_OVERRUN: | 564 | case DWC2_HC_XFER_FRAME_OVERRUN: |
@@ -594,14 +585,9 @@ static enum dwc2_halt_status dwc2_update_isoc_urb_state( | |||
594 | chan->ep_is_in) { | 585 | chan->ep_is_in) { |
595 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", | 586 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", |
596 | __func__); | 587 | __func__); |
597 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, | ||
598 | urb->length, DMA_FROM_DEVICE); | ||
599 | memcpy(urb->buf + frame_desc->offset + | 588 | memcpy(urb->buf + frame_desc->offset + |
600 | qtd->isoc_split_offset, chan->qh->dw_align_buf, | 589 | qtd->isoc_split_offset, chan->qh->dw_align_buf, |
601 | frame_desc->actual_length); | 590 | frame_desc->actual_length); |
602 | dma_sync_single_for_device(hsotg->dev, urb->dma, | ||
603 | urb->length, | ||
604 | DMA_FROM_DEVICE); | ||
605 | } | 591 | } |
606 | 592 | ||
607 | /* Skip whole frame */ | 593 | /* Skip whole frame */ |
@@ -937,12 +923,8 @@ static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg *hsotg, | |||
937 | 923 | ||
938 | if (chan->align_buf) { | 924 | if (chan->align_buf) { |
939 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | 925 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); |
940 | dma_sync_single_for_cpu(hsotg->dev, qtd->urb->dma, | ||
941 | qtd->urb->length, DMA_FROM_DEVICE); | ||
942 | memcpy(qtd->urb->buf + frame_desc->offset + | 926 | memcpy(qtd->urb->buf + frame_desc->offset + |
943 | qtd->isoc_split_offset, chan->qh->dw_align_buf, len); | 927 | qtd->isoc_split_offset, chan->qh->dw_align_buf, len); |
944 | dma_sync_single_for_device(hsotg->dev, qtd->urb->dma, | ||
945 | qtd->urb->length, DMA_FROM_DEVICE); | ||
946 | } | 928 | } |
947 | 929 | ||
948 | qtd->isoc_split_offset += len; | 930 | qtd->isoc_split_offset += len; |
@@ -1170,12 +1152,8 @@ static void dwc2_update_urb_state_abn(struct dwc2_hsotg *hsotg, | |||
1170 | /* Non DWORD-aligned buffer case handling */ | 1152 | /* Non DWORD-aligned buffer case handling */ |
1171 | if (chan->align_buf && xfer_length && chan->ep_is_in) { | 1153 | if (chan->align_buf && xfer_length && chan->ep_is_in) { |
1172 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); | 1154 | dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__); |
1173 | dma_sync_single_for_cpu(hsotg->dev, urb->dma, urb->length, | ||
1174 | DMA_FROM_DEVICE); | ||
1175 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, | 1155 | memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf, |
1176 | xfer_length); | 1156 | xfer_length); |
1177 | dma_sync_single_for_device(hsotg->dev, urb->dma, urb->length, | ||
1178 | DMA_FROM_DEVICE); | ||
1179 | } | 1157 | } |
1180 | 1158 | ||
1181 | urb->actual_length += xfer_length; | 1159 | urb->actual_length += xfer_length; |
@@ -1890,12 +1868,20 @@ static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg, | |||
1890 | "hcint 0x%08x, intsts 0x%08x\n", | 1868 | "hcint 0x%08x, intsts 0x%08x\n", |
1891 | chan->hcint, | 1869 | chan->hcint, |
1892 | readl(hsotg->regs + GINTSTS)); | 1870 | readl(hsotg->regs + GINTSTS)); |
1871 | goto error; | ||
1893 | } | 1872 | } |
1894 | } | 1873 | } |
1895 | } else { | 1874 | } else { |
1896 | dev_info(hsotg->dev, | 1875 | dev_info(hsotg->dev, |
1897 | "NYET/NAK/ACK/other in non-error case, 0x%08x\n", | 1876 | "NYET/NAK/ACK/other in non-error case, 0x%08x\n", |
1898 | chan->hcint); | 1877 | chan->hcint); |
1878 | error: | ||
1879 | /* Failthrough: use 3-strikes rule */ | ||
1880 | qtd->error_count++; | ||
1881 | dwc2_update_urb_state_abn(hsotg, chan, chnum, qtd->urb, | ||
1882 | qtd, DWC2_HC_XFER_XACT_ERR); | ||
1883 | dwc2_hcd_save_data_toggle(hsotg, chan, chnum, qtd); | ||
1884 | dwc2_halt_channel(hsotg, chan, qtd, DWC2_HC_XFER_XACT_ERR); | ||
1899 | } | 1885 | } |
1900 | } | 1886 | } |
1901 | 1887 | ||
diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c index 9540f7e1e20e..bb97838bc6c0 100644 --- a/drivers/usb/dwc2/hcd_queue.c +++ b/drivers/usb/dwc2/hcd_queue.c | |||
@@ -229,19 +229,11 @@ static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg, | |||
229 | */ | 229 | */ |
230 | void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) | 230 | void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
231 | { | 231 | { |
232 | u32 buf_size; | 232 | if (hsotg->core_params->dma_desc_enable > 0) |
233 | |||
234 | if (hsotg->core_params->dma_desc_enable > 0) { | ||
235 | dwc2_hcd_qh_free_ddma(hsotg, qh); | 233 | dwc2_hcd_qh_free_ddma(hsotg, qh); |
236 | } else if (qh->dw_align_buf) { | 234 | else if (qh->dw_align_buf) |
237 | if (qh->ep_type == USB_ENDPOINT_XFER_ISOC) | 235 | dma_free_coherent(hsotg->dev, qh->dw_align_buf_size, |
238 | buf_size = 4096; | 236 | qh->dw_align_buf, qh->dw_align_buf_dma); |
239 | else | ||
240 | buf_size = hsotg->core_params->max_transfer_size; | ||
241 | dma_free_coherent(hsotg->dev, buf_size, qh->dw_align_buf, | ||
242 | qh->dw_align_buf_dma); | ||
243 | } | ||
244 | |||
245 | kfree(qh); | 237 | kfree(qh); |
246 | } | 238 | } |
247 | 239 | ||
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index a10e7a353576..121dbdafc06b 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c | |||
@@ -42,6 +42,8 @@ | |||
42 | #include <linux/of_device.h> | 42 | #include <linux/of_device.h> |
43 | #include <linux/platform_device.h> | 43 | #include <linux/platform_device.h> |
44 | 44 | ||
45 | #include <linux/usb/of.h> | ||
46 | |||
45 | #include "core.h" | 47 | #include "core.h" |
46 | #include "hcd.h" | 48 | #include "hcd.h" |
47 | 49 | ||
@@ -75,6 +77,34 @@ static const struct dwc2_core_params params_bcm2835 = { | |||
75 | .uframe_sched = 0, | 77 | .uframe_sched = 0, |
76 | }; | 78 | }; |
77 | 79 | ||
80 | static const struct dwc2_core_params params_rk3066 = { | ||
81 | .otg_cap = 2, /* non-HNP/non-SRP */ | ||
82 | .otg_ver = -1, | ||
83 | .dma_enable = -1, | ||
84 | .dma_desc_enable = 0, | ||
85 | .speed = -1, | ||
86 | .enable_dynamic_fifo = 1, | ||
87 | .en_multiple_tx_fifo = -1, | ||
88 | .host_rx_fifo_size = 520, /* 520 DWORDs */ | ||
89 | .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ | ||
90 | .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ | ||
91 | .max_transfer_size = 65535, | ||
92 | .max_packet_count = -1, | ||
93 | .host_channels = -1, | ||
94 | .phy_type = -1, | ||
95 | .phy_utmi_width = -1, | ||
96 | .phy_ulpi_ddr = -1, | ||
97 | .phy_ulpi_ext_vbus = -1, | ||
98 | .i2c_enable = -1, | ||
99 | .ulpi_fs_ls = -1, | ||
100 | .host_support_fs_ls_low_power = -1, | ||
101 | .host_ls_low_power_phy_clk = -1, | ||
102 | .ts_dline = -1, | ||
103 | .reload_ctl = -1, | ||
104 | .ahbcfg = 0x7, /* INCR16 */ | ||
105 | .uframe_sched = -1, | ||
106 | }; | ||
107 | |||
78 | /** | 108 | /** |
79 | * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the | 109 | * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the |
80 | * DWC_otg driver | 110 | * DWC_otg driver |
@@ -97,6 +127,7 @@ static int dwc2_driver_remove(struct platform_device *dev) | |||
97 | 127 | ||
98 | static const struct of_device_id dwc2_of_match_table[] = { | 128 | static const struct of_device_id dwc2_of_match_table[] = { |
99 | { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, | 129 | { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, |
130 | { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, | ||
100 | { .compatible = "snps,dwc2", .data = NULL }, | 131 | { .compatible = "snps,dwc2", .data = NULL }, |
101 | {}, | 132 | {}, |
102 | }; | 133 | }; |
@@ -171,6 +202,8 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
171 | dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", | 202 | dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", |
172 | (unsigned long)res->start, hsotg->regs); | 203 | (unsigned long)res->start, hsotg->regs); |
173 | 204 | ||
205 | hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); | ||
206 | |||
174 | retval = dwc2_hcd_init(hsotg, irq, params); | 207 | retval = dwc2_hcd_init(hsotg, irq, params); |
175 | if (retval) | 208 | if (retval) |
176 | return retval; | 209 | return retval; |
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 785510a0a0c3..f4e5cc60db0b 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -80,6 +80,23 @@ config USB_DWC3_KEYSTONE | |||
80 | Support of USB2/3 functionality in TI Keystone2 platforms. | 80 | Support of USB2/3 functionality in TI Keystone2 platforms. |
81 | Say 'Y' or 'M' here if you have one such device | 81 | Say 'Y' or 'M' here if you have one such device |
82 | 82 | ||
83 | config USB_DWC3_ST | ||
84 | tristate "STMicroelectronics Platforms" | ||
85 | depends on ARCH_STI && OF | ||
86 | default USB_DWC3 | ||
87 | help | ||
88 | STMicroelectronics SoCs with one DesignWare Core USB3 IP | ||
89 | inside (i.e. STiH407). | ||
90 | Say 'Y' or 'M' if you have one such device. | ||
91 | |||
92 | config USB_DWC3_QCOM | ||
93 | tristate "Qualcomm Platforms" | ||
94 | depends on ARCH_QCOM || COMPILE_TEST | ||
95 | default USB_DWC3 | ||
96 | help | ||
97 | Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside, | ||
98 | say 'Y' or 'M' if you have one such device. | ||
99 | |||
83 | comment "Debugging features" | 100 | comment "Debugging features" |
84 | 101 | ||
85 | config USB_DWC3_DEBUG | 102 | config USB_DWC3_DEBUG |
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile index 10ac3e72482e..bb34fbcfeab3 100644 --- a/drivers/usb/dwc3/Makefile +++ b/drivers/usb/dwc3/Makefile | |||
@@ -1,9 +1,12 @@ | |||
1 | # define_trace.h needs to know how to find our header | ||
2 | CFLAGS_trace.o := -I$(src) | ||
3 | |||
1 | ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG | 4 | ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG |
2 | ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG | 5 | ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG |
3 | 6 | ||
4 | obj-$(CONFIG_USB_DWC3) += dwc3.o | 7 | obj-$(CONFIG_USB_DWC3) += dwc3.o |
5 | 8 | ||
6 | dwc3-y := core.o | 9 | dwc3-y := core.o debug.o trace.o |
7 | 10 | ||
8 | ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),) | 11 | ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),) |
9 | dwc3-y += host.o | 12 | dwc3-y += host.o |
@@ -33,3 +36,5 @@ obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o | |||
33 | obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o | 36 | obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o |
34 | obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o | 37 | obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o |
35 | obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o | 38 | obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o |
39 | obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o | ||
40 | obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o | ||
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 9069984fe5cf..b0f4d52b7f04 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -186,10 +186,8 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) | |||
186 | 186 | ||
187 | dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, | 187 | dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, |
188 | GFP_KERNEL); | 188 | GFP_KERNEL); |
189 | if (!dwc->ev_buffs) { | 189 | if (!dwc->ev_buffs) |
190 | dev_err(dwc->dev, "can't allocate event buffers array\n"); | ||
191 | return -ENOMEM; | 190 | return -ENOMEM; |
192 | } | ||
193 | 191 | ||
194 | for (i = 0; i < num; i++) { | 192 | for (i = 0; i < num; i++) { |
195 | struct dwc3_event_buffer *evt; | 193 | struct dwc3_event_buffer *evt; |
@@ -639,10 +637,9 @@ static int dwc3_probe(struct platform_device *pdev) | |||
639 | void *mem; | 637 | void *mem; |
640 | 638 | ||
641 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); | 639 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); |
642 | if (!mem) { | 640 | if (!mem) |
643 | dev_err(dev, "not enough memory\n"); | ||
644 | return -ENOMEM; | 641 | return -ENOMEM; |
645 | } | 642 | |
646 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); | 643 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); |
647 | dwc->mem = mem; | 644 | dwc->mem = mem; |
648 | dwc->dev = dev; | 645 | dwc->dev = dev; |
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 48fb264065db..66f62563bcf9 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h | |||
@@ -33,6 +33,8 @@ | |||
33 | 33 | ||
34 | #include <linux/phy/phy.h> | 34 | #include <linux/phy/phy.h> |
35 | 35 | ||
36 | #define DWC3_MSG_MAX 500 | ||
37 | |||
36 | /* Global constants */ | 38 | /* Global constants */ |
37 | #define DWC3_EP0_BOUNCE_SIZE 512 | 39 | #define DWC3_EP0_BOUNCE_SIZE 512 |
38 | #define DWC3_ENDPOINTS_NUM 32 | 40 | #define DWC3_ENDPOINTS_NUM 32 |
@@ -938,7 +940,7 @@ int dwc3_gadget_get_link_state(struct dwc3 *dwc); | |||
938 | int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); | 940 | int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); |
939 | int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, | 941 | int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, |
940 | unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); | 942 | unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); |
941 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param); | 943 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param); |
942 | #else | 944 | #else |
943 | static inline int dwc3_gadget_init(struct dwc3 *dwc) | 945 | static inline int dwc3_gadget_init(struct dwc3 *dwc) |
944 | { return 0; } | 946 | { return 0; } |
diff --git a/drivers/usb/dwc3/debug.c b/drivers/usb/dwc3/debug.c new file mode 100644 index 000000000000..0be6885bc370 --- /dev/null +++ b/drivers/usb/dwc3/debug.c | |||
@@ -0,0 +1,32 @@ | |||
1 | /** | ||
2 | * debug.c - DesignWare USB3 DRD Controller Debug/Trace Support | ||
3 | * | ||
4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: Felipe Balbi <balbi@ti.com> | ||
7 | * | ||
8 | * This program is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 of | ||
10 | * the License as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | |||
18 | #include "debug.h" | ||
19 | |||
20 | void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...) | ||
21 | { | ||
22 | struct va_format vaf; | ||
23 | va_list args; | ||
24 | |||
25 | va_start(args, fmt); | ||
26 | vaf.fmt = fmt; | ||
27 | vaf.va = &args; | ||
28 | |||
29 | trace(&vaf); | ||
30 | |||
31 | va_end(args); | ||
32 | } | ||
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index fceb39dc4bba..07fbc2d94fd4 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h | |||
@@ -16,8 +16,206 @@ | |||
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef __DWC3_DEBUG_H | ||
20 | #define __DWC3_DEBUG_H | ||
21 | |||
19 | #include "core.h" | 22 | #include "core.h" |
20 | 23 | ||
24 | /** | ||
25 | * dwc3_gadget_ep_cmd_string - returns endpoint command string | ||
26 | * @cmd: command code | ||
27 | */ | ||
28 | static inline const char * | ||
29 | dwc3_gadget_ep_cmd_string(u8 cmd) | ||
30 | { | ||
31 | switch (cmd) { | ||
32 | case DWC3_DEPCMD_DEPSTARTCFG: | ||
33 | return "Start New Configuration"; | ||
34 | case DWC3_DEPCMD_ENDTRANSFER: | ||
35 | return "End Transfer"; | ||
36 | case DWC3_DEPCMD_UPDATETRANSFER: | ||
37 | return "Update Transfer"; | ||
38 | case DWC3_DEPCMD_STARTTRANSFER: | ||
39 | return "Start Transfer"; | ||
40 | case DWC3_DEPCMD_CLEARSTALL: | ||
41 | return "Clear Stall"; | ||
42 | case DWC3_DEPCMD_SETSTALL: | ||
43 | return "Set Stall"; | ||
44 | case DWC3_DEPCMD_GETEPSTATE: | ||
45 | return "Get Endpoint State"; | ||
46 | case DWC3_DEPCMD_SETTRANSFRESOURCE: | ||
47 | return "Set Endpoint Transfer Resource"; | ||
48 | case DWC3_DEPCMD_SETEPCONFIG: | ||
49 | return "Set Endpoint Configuration"; | ||
50 | default: | ||
51 | return "UNKNOWN command"; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * dwc3_gadget_generic_cmd_string - returns generic command string | ||
57 | * @cmd: command code | ||
58 | */ | ||
59 | static inline const char * | ||
60 | dwc3_gadget_generic_cmd_string(u8 cmd) | ||
61 | { | ||
62 | switch (cmd) { | ||
63 | case DWC3_DGCMD_SET_LMP: | ||
64 | return "Set LMP"; | ||
65 | case DWC3_DGCMD_SET_PERIODIC_PAR: | ||
66 | return "Set Periodic Parameters"; | ||
67 | case DWC3_DGCMD_XMIT_FUNCTION: | ||
68 | return "Transmit Function Wake Device Notification"; | ||
69 | case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO: | ||
70 | return "Set Scratchpad Buffer Array Address Lo"; | ||
71 | case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI: | ||
72 | return "Set Scratchpad Buffer Array Address Hi"; | ||
73 | case DWC3_DGCMD_SELECTED_FIFO_FLUSH: | ||
74 | return "Selected FIFO Flush"; | ||
75 | case DWC3_DGCMD_ALL_FIFO_FLUSH: | ||
76 | return "All FIFO Flush"; | ||
77 | case DWC3_DGCMD_SET_ENDPOINT_NRDY: | ||
78 | return "Set Endpoint NRDY"; | ||
79 | case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: | ||
80 | return "Run SoC Bus Loopback Test"; | ||
81 | default: | ||
82 | return "UNKNOWN"; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * dwc3_gadget_link_string - returns link name | ||
88 | * @link_state: link state code | ||
89 | */ | ||
90 | static inline const char * | ||
91 | dwc3_gadget_link_string(enum dwc3_link_state link_state) | ||
92 | { | ||
93 | switch (link_state) { | ||
94 | case DWC3_LINK_STATE_U0: | ||
95 | return "U0"; | ||
96 | case DWC3_LINK_STATE_U1: | ||
97 | return "U1"; | ||
98 | case DWC3_LINK_STATE_U2: | ||
99 | return "U2"; | ||
100 | case DWC3_LINK_STATE_U3: | ||
101 | return "U3"; | ||
102 | case DWC3_LINK_STATE_SS_DIS: | ||
103 | return "SS.Disabled"; | ||
104 | case DWC3_LINK_STATE_RX_DET: | ||
105 | return "RX.Detect"; | ||
106 | case DWC3_LINK_STATE_SS_INACT: | ||
107 | return "SS.Inactive"; | ||
108 | case DWC3_LINK_STATE_POLL: | ||
109 | return "Polling"; | ||
110 | case DWC3_LINK_STATE_RECOV: | ||
111 | return "Recovery"; | ||
112 | case DWC3_LINK_STATE_HRESET: | ||
113 | return "Hot Reset"; | ||
114 | case DWC3_LINK_STATE_CMPLY: | ||
115 | return "Compliance"; | ||
116 | case DWC3_LINK_STATE_LPBK: | ||
117 | return "Loopback"; | ||
118 | case DWC3_LINK_STATE_RESET: | ||
119 | return "Reset"; | ||
120 | case DWC3_LINK_STATE_RESUME: | ||
121 | return "Resume"; | ||
122 | default: | ||
123 | return "UNKNOWN link state\n"; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * dwc3_gadget_event_string - returns event name | ||
129 | * @event: the event code | ||
130 | */ | ||
131 | static inline const char *dwc3_gadget_event_string(u8 event) | ||
132 | { | ||
133 | switch (event) { | ||
134 | case DWC3_DEVICE_EVENT_DISCONNECT: | ||
135 | return "Disconnect"; | ||
136 | case DWC3_DEVICE_EVENT_RESET: | ||
137 | return "Reset"; | ||
138 | case DWC3_DEVICE_EVENT_CONNECT_DONE: | ||
139 | return "Connection Done"; | ||
140 | case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: | ||
141 | return "Link Status Change"; | ||
142 | case DWC3_DEVICE_EVENT_WAKEUP: | ||
143 | return "WakeUp"; | ||
144 | case DWC3_DEVICE_EVENT_EOPF: | ||
145 | return "End-Of-Frame"; | ||
146 | case DWC3_DEVICE_EVENT_SOF: | ||
147 | return "Start-Of-Frame"; | ||
148 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: | ||
149 | return "Erratic Error"; | ||
150 | case DWC3_DEVICE_EVENT_CMD_CMPL: | ||
151 | return "Command Complete"; | ||
152 | case DWC3_DEVICE_EVENT_OVERFLOW: | ||
153 | return "Overflow"; | ||
154 | } | ||
155 | |||
156 | return "UNKNOWN"; | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * dwc3_ep_event_string - returns event name | ||
161 | * @event: then event code | ||
162 | */ | ||
163 | static inline const char *dwc3_ep_event_string(u8 event) | ||
164 | { | ||
165 | switch (event) { | ||
166 | case DWC3_DEPEVT_XFERCOMPLETE: | ||
167 | return "Transfer Complete"; | ||
168 | case DWC3_DEPEVT_XFERINPROGRESS: | ||
169 | return "Transfer In-Progress"; | ||
170 | case DWC3_DEPEVT_XFERNOTREADY: | ||
171 | return "Transfer Not Ready"; | ||
172 | case DWC3_DEPEVT_RXTXFIFOEVT: | ||
173 | return "FIFO"; | ||
174 | case DWC3_DEPEVT_STREAMEVT: | ||
175 | return "Stream"; | ||
176 | case DWC3_DEPEVT_EPCMDCMPLT: | ||
177 | return "Endpoint Command Complete"; | ||
178 | } | ||
179 | |||
180 | return "UNKNOWN"; | ||
181 | } | ||
182 | |||
183 | /** | ||
184 | * dwc3_gadget_event_type_string - return event name | ||
185 | * @event: the event code | ||
186 | */ | ||
187 | static inline const char *dwc3_gadget_event_type_string(u8 event) | ||
188 | { | ||
189 | switch (event) { | ||
190 | case DWC3_DEVICE_EVENT_DISCONNECT: | ||
191 | return "Disconnect"; | ||
192 | case DWC3_DEVICE_EVENT_RESET: | ||
193 | return "Reset"; | ||
194 | case DWC3_DEVICE_EVENT_CONNECT_DONE: | ||
195 | return "Connect Done"; | ||
196 | case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: | ||
197 | return "Link Status Change"; | ||
198 | case DWC3_DEVICE_EVENT_WAKEUP: | ||
199 | return "Wake-Up"; | ||
200 | case DWC3_DEVICE_EVENT_HIBER_REQ: | ||
201 | return "Hibernation"; | ||
202 | case DWC3_DEVICE_EVENT_EOPF: | ||
203 | return "End of Periodic Frame"; | ||
204 | case DWC3_DEVICE_EVENT_SOF: | ||
205 | return "Start of Frame"; | ||
206 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: | ||
207 | return "Erratic Error"; | ||
208 | case DWC3_DEVICE_EVENT_CMD_CMPL: | ||
209 | return "Command Complete"; | ||
210 | case DWC3_DEVICE_EVENT_OVERFLOW: | ||
211 | return "Overflow"; | ||
212 | default: | ||
213 | return "UNKNOWN"; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...); | ||
218 | |||
21 | #ifdef CONFIG_DEBUG_FS | 219 | #ifdef CONFIG_DEBUG_FS |
22 | extern int dwc3_debugfs_init(struct dwc3 *); | 220 | extern int dwc3_debugfs_init(struct dwc3 *); |
23 | extern void dwc3_debugfs_exit(struct dwc3 *); | 221 | extern void dwc3_debugfs_exit(struct dwc3 *); |
@@ -27,4 +225,4 @@ static inline int dwc3_debugfs_init(struct dwc3 *d) | |||
27 | static inline void dwc3_debugfs_exit(struct dwc3 *d) | 225 | static inline void dwc3_debugfs_exit(struct dwc3 *d) |
28 | { } | 226 | { } |
29 | #endif | 227 | #endif |
30 | 228 | #endif /* __DWC3_DEBUG_H */ | |
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index f9fb8adb785b..3951a65fea04 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -113,10 +113,8 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
113 | int ret; | 113 | int ret; |
114 | 114 | ||
115 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); | 115 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
116 | if (!exynos) { | 116 | if (!exynos) |
117 | dev_err(dev, "not enough memory\n"); | ||
118 | return -ENOMEM; | 117 | return -ENOMEM; |
119 | } | ||
120 | 118 | ||
121 | /* | 119 | /* |
122 | * Right now device-tree probed devices don't get dma_mask set. | 120 | * Right now device-tree probed devices don't get dma_mask set. |
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c index 1fad1618df6e..7ec8495f4523 100644 --- a/drivers/usb/dwc3/dwc3-keystone.c +++ b/drivers/usb/dwc3/dwc3-keystone.c | |||
@@ -189,7 +189,6 @@ static struct platform_driver kdwc3_driver = { | |||
189 | .remove = kdwc3_remove, | 189 | .remove = kdwc3_remove, |
190 | .driver = { | 190 | .driver = { |
191 | .name = "keystone-dwc3", | 191 | .name = "keystone-dwc3", |
192 | .owner = THIS_MODULE, | ||
193 | .of_match_table = kdwc3_of_match, | 192 | .of_match_table = kdwc3_of_match, |
194 | }, | 193 | }, |
195 | }; | 194 | }; |
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index fc0de3753648..2f537d588225 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -481,10 +481,8 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
481 | } | 481 | } |
482 | 482 | ||
483 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); | 483 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
484 | if (!omap) { | 484 | if (!omap) |
485 | dev_err(dev, "not enough memory\n"); | ||
486 | return -ENOMEM; | 485 | return -ENOMEM; |
487 | } | ||
488 | 486 | ||
489 | platform_set_drvdata(pdev, omap); | 487 | platform_set_drvdata(pdev, omap); |
490 | 488 | ||
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index a60bab7dfa0a..436fb08c40b8 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -103,10 +103,8 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
103 | struct device *dev = &pci->dev; | 103 | struct device *dev = &pci->dev; |
104 | 104 | ||
105 | glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); | 105 | glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); |
106 | if (!glue) { | 106 | if (!glue) |
107 | dev_err(dev, "not enough memory\n"); | ||
108 | return -ENOMEM; | 107 | return -ENOMEM; |
109 | } | ||
110 | 108 | ||
111 | glue->dev = dev; | 109 | glue->dev = dev; |
112 | 110 | ||
diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c new file mode 100644 index 000000000000..8c2e8eec80c2 --- /dev/null +++ b/drivers/usb/dwc3/dwc3-qcom.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | */ | ||
12 | |||
13 | #include <linux/clk.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/of.h> | ||
18 | #include <linux/of_platform.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | |||
21 | struct dwc3_qcom { | ||
22 | struct device *dev; | ||
23 | |||
24 | struct clk *core_clk; | ||
25 | struct clk *iface_clk; | ||
26 | struct clk *sleep_clk; | ||
27 | }; | ||
28 | |||
29 | static int dwc3_qcom_probe(struct platform_device *pdev) | ||
30 | { | ||
31 | struct device_node *node = pdev->dev.of_node; | ||
32 | struct dwc3_qcom *qdwc; | ||
33 | int ret; | ||
34 | |||
35 | qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL); | ||
36 | if (!qdwc) | ||
37 | return -ENOMEM; | ||
38 | |||
39 | platform_set_drvdata(pdev, qdwc); | ||
40 | |||
41 | qdwc->dev = &pdev->dev; | ||
42 | |||
43 | qdwc->core_clk = devm_clk_get(qdwc->dev, "core"); | ||
44 | if (IS_ERR(qdwc->core_clk)) { | ||
45 | dev_err(qdwc->dev, "failed to get core clock\n"); | ||
46 | return PTR_ERR(qdwc->core_clk); | ||
47 | } | ||
48 | |||
49 | qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface"); | ||
50 | if (IS_ERR(qdwc->iface_clk)) { | ||
51 | dev_dbg(qdwc->dev, "failed to get optional iface clock\n"); | ||
52 | qdwc->iface_clk = NULL; | ||
53 | } | ||
54 | |||
55 | qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep"); | ||
56 | if (IS_ERR(qdwc->sleep_clk)) { | ||
57 | dev_dbg(qdwc->dev, "failed to get optional sleep clock\n"); | ||
58 | qdwc->sleep_clk = NULL; | ||
59 | } | ||
60 | |||
61 | ret = clk_prepare_enable(qdwc->core_clk); | ||
62 | if (ret) { | ||
63 | dev_err(qdwc->dev, "failed to enable core clock\n"); | ||
64 | goto err_core; | ||
65 | } | ||
66 | |||
67 | ret = clk_prepare_enable(qdwc->iface_clk); | ||
68 | if (ret) { | ||
69 | dev_err(qdwc->dev, "failed to enable optional iface clock\n"); | ||
70 | goto err_iface; | ||
71 | } | ||
72 | |||
73 | ret = clk_prepare_enable(qdwc->sleep_clk); | ||
74 | if (ret) { | ||
75 | dev_err(qdwc->dev, "failed to enable optional sleep clock\n"); | ||
76 | goto err_sleep; | ||
77 | } | ||
78 | |||
79 | ret = of_platform_populate(node, NULL, NULL, qdwc->dev); | ||
80 | if (ret) { | ||
81 | dev_err(qdwc->dev, "failed to register core - %d\n", ret); | ||
82 | goto err_clks; | ||
83 | } | ||
84 | |||
85 | return 0; | ||
86 | |||
87 | err_clks: | ||
88 | clk_disable_unprepare(qdwc->sleep_clk); | ||
89 | err_sleep: | ||
90 | clk_disable_unprepare(qdwc->iface_clk); | ||
91 | err_iface: | ||
92 | clk_disable_unprepare(qdwc->core_clk); | ||
93 | err_core: | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | static int dwc3_qcom_remove(struct platform_device *pdev) | ||
98 | { | ||
99 | struct dwc3_qcom *qdwc = platform_get_drvdata(pdev); | ||
100 | |||
101 | of_platform_depopulate(&pdev->dev); | ||
102 | |||
103 | clk_disable_unprepare(qdwc->sleep_clk); | ||
104 | clk_disable_unprepare(qdwc->iface_clk); | ||
105 | clk_disable_unprepare(qdwc->core_clk); | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static const struct of_device_id of_dwc3_match[] = { | ||
111 | { .compatible = "qcom,dwc3" }, | ||
112 | { /* Sentinel */ } | ||
113 | }; | ||
114 | MODULE_DEVICE_TABLE(of, of_dwc3_match); | ||
115 | |||
116 | static struct platform_driver dwc3_qcom_driver = { | ||
117 | .probe = dwc3_qcom_probe, | ||
118 | .remove = dwc3_qcom_remove, | ||
119 | .driver = { | ||
120 | .name = "qcom-dwc3", | ||
121 | .of_match_table = of_dwc3_match, | ||
122 | }, | ||
123 | }; | ||
124 | |||
125 | module_platform_driver(dwc3_qcom_driver); | ||
126 | |||
127 | MODULE_ALIAS("platform:qcom-dwc3"); | ||
128 | MODULE_LICENSE("GPL v2"); | ||
129 | MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer"); | ||
130 | MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>"); | ||
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c new file mode 100644 index 000000000000..c7602b5362ad --- /dev/null +++ b/drivers/usb/dwc3/dwc3-st.c | |||
@@ -0,0 +1,367 @@ | |||
1 | /** | ||
2 | * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms | ||
3 | * | ||
4 | * This is a small driver for the dwc3 to provide the glue logic | ||
5 | * to configure the controller. Tested on STi platforms. | ||
6 | * | ||
7 | * Copyright (C) 2014 Stmicroelectronics | ||
8 | * | ||
9 | * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> | ||
10 | * Contributors: Aymen Bouattay <aymen.bouattay@st.com> | ||
11 | * Peter Griffin <peter.griffin@linaro.org> | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * Inspired by dwc3-omap.c and dwc3-exynos.c. | ||
19 | */ | ||
20 | |||
21 | #include <linux/delay.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/mfd/syscon.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/of_platform.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/slab.h> | ||
32 | #include <linux/regmap.h> | ||
33 | #include <linux/reset.h> | ||
34 | #include <linux/usb/of.h> | ||
35 | |||
36 | #include "core.h" | ||
37 | #include "io.h" | ||
38 | |||
39 | /* glue registers */ | ||
40 | #define CLKRST_CTRL 0x00 | ||
41 | #define AUX_CLK_EN BIT(0) | ||
42 | #define SW_PIPEW_RESET_N BIT(4) | ||
43 | #define EXT_CFG_RESET_N BIT(8) | ||
44 | /* | ||
45 | * 1'b0 : The host controller complies with the xHCI revision 0.96 | ||
46 | * 1'b1 : The host controller complies with the xHCI revision 1.0 | ||
47 | */ | ||
48 | #define XHCI_REVISION BIT(12) | ||
49 | |||
50 | #define USB2_VBUS_MNGMNT_SEL1 0x2C | ||
51 | /* | ||
52 | * For all fields in USB2_VBUS_MNGMNT_SEL1 | ||
53 | * 2’b00 : Override value from Reg 0x30 is selected | ||
54 | * 2’b01 : utmiotg_<signal_name> from usb3_top is selected | ||
55 | * 2’b10 : pipew_<signal_name> from PIPEW instance is selected | ||
56 | * 2’b11 : value is 1'b0 | ||
57 | */ | ||
58 | #define USB2_VBUS_REG30 0x0 | ||
59 | #define USB2_VBUS_UTMIOTG 0x1 | ||
60 | #define USB2_VBUS_PIPEW 0x2 | ||
61 | #define USB2_VBUS_ZERO 0x3 | ||
62 | |||
63 | #define SEL_OVERRIDE_VBUSVALID(n) (n << 0) | ||
64 | #define SEL_OVERRIDE_POWERPRESENT(n) (n << 4) | ||
65 | #define SEL_OVERRIDE_BVALID(n) (n << 8) | ||
66 | |||
67 | /* Static DRD configuration */ | ||
68 | #define USB3_CONTROL_MASK 0xf77 | ||
69 | |||
70 | #define USB3_DEVICE_NOT_HOST BIT(0) | ||
71 | #define USB3_FORCE_VBUSVALID BIT(1) | ||
72 | #define USB3_DELAY_VBUSVALID BIT(2) | ||
73 | #define USB3_SEL_FORCE_OPMODE BIT(4) | ||
74 | #define USB3_FORCE_OPMODE(n) (n << 5) | ||
75 | #define USB3_SEL_FORCE_DPPULLDOWN2 BIT(8) | ||
76 | #define USB3_FORCE_DPPULLDOWN2 BIT(9) | ||
77 | #define USB3_SEL_FORCE_DMPULLDOWN2 BIT(10) | ||
78 | #define USB3_FORCE_DMPULLDOWN2 BIT(11) | ||
79 | |||
80 | /** | ||
81 | * struct st_dwc3 - dwc3-st driver private structure | ||
82 | * @dev: device pointer | ||
83 | * @glue_base: ioaddr for the glue registers | ||
84 | * @regmap: regmap pointer for getting syscfg | ||
85 | * @syscfg_reg_off: usb syscfg control offset | ||
86 | * @dr_mode: drd static host/device config | ||
87 | * @rstc_pwrdn: rest controller for powerdown signal | ||
88 | * @rstc_rst: reset controller for softreset signal | ||
89 | */ | ||
90 | |||
91 | struct st_dwc3 { | ||
92 | struct device *dev; | ||
93 | void __iomem *glue_base; | ||
94 | struct regmap *regmap; | ||
95 | int syscfg_reg_off; | ||
96 | enum usb_dr_mode dr_mode; | ||
97 | struct reset_control *rstc_pwrdn; | ||
98 | struct reset_control *rstc_rst; | ||
99 | }; | ||
100 | |||
101 | static inline u32 st_dwc3_readl(void __iomem *base, u32 offset) | ||
102 | { | ||
103 | return readl_relaxed(base + offset); | ||
104 | } | ||
105 | |||
106 | static inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value) | ||
107 | { | ||
108 | writel_relaxed(value, base + offset); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * st_dwc3_drd_init: program the port | ||
113 | * @dwc3_data: driver private structure | ||
114 | * Description: this function is to program the port as either host or device | ||
115 | * according to the static configuration passed from devicetree. | ||
116 | * OTG and dual role are not yet supported! | ||
117 | */ | ||
118 | static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data) | ||
119 | { | ||
120 | u32 val; | ||
121 | int err; | ||
122 | |||
123 | err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val); | ||
124 | if (err) | ||
125 | return err; | ||
126 | |||
127 | val &= USB3_CONTROL_MASK; | ||
128 | |||
129 | switch (dwc3_data->dr_mode) { | ||
130 | case USB_DR_MODE_PERIPHERAL: | ||
131 | |||
132 | val &= ~(USB3_FORCE_VBUSVALID | USB3_DELAY_VBUSVALID | ||
133 | | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) | ||
134 | | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 | ||
135 | | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); | ||
136 | |||
137 | val |= USB3_DEVICE_NOT_HOST; | ||
138 | |||
139 | dev_dbg(dwc3_data->dev, "Configuring as Device\n"); | ||
140 | break; | ||
141 | |||
142 | case USB_DR_MODE_HOST: | ||
143 | |||
144 | val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID | ||
145 | | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) | ||
146 | | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 | ||
147 | | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); | ||
148 | |||
149 | /* | ||
150 | * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus, | ||
151 | * when set to ‘0‘, it can delay the arrival of VBUSVALID | ||
152 | * information to VBUSVLDEXT2 input of the pico PHY. | ||
153 | * We don't want to do that so we set the bit to '1'. | ||
154 | */ | ||
155 | |||
156 | val |= USB3_DELAY_VBUSVALID; | ||
157 | |||
158 | dev_dbg(dwc3_data->dev, "Configuring as Host\n"); | ||
159 | break; | ||
160 | |||
161 | default: | ||
162 | dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n", | ||
163 | dwc3_data->dr_mode); | ||
164 | return -EINVAL; | ||
165 | } | ||
166 | |||
167 | return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val); | ||
168 | } | ||
169 | |||
170 | /** | ||
171 | * st_dwc3_init: init the controller via glue logic | ||
172 | * @dwc3_data: driver private structure | ||
173 | */ | ||
174 | static void st_dwc3_init(struct st_dwc3 *dwc3_data) | ||
175 | { | ||
176 | u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL); | ||
177 | |||
178 | reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION; | ||
179 | reg &= ~SW_PIPEW_RESET_N; | ||
180 | st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg); | ||
181 | |||
182 | /* configure mux for vbus, powerpresent and bvalid signals */ | ||
183 | reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1); | ||
184 | |||
185 | reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | | ||
186 | SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | | ||
187 | SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG); | ||
188 | |||
189 | st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg); | ||
190 | |||
191 | reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL); | ||
192 | reg |= SW_PIPEW_RESET_N; | ||
193 | st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg); | ||
194 | } | ||
195 | |||
196 | static int st_dwc3_probe(struct platform_device *pdev) | ||
197 | { | ||
198 | struct st_dwc3 *dwc3_data; | ||
199 | struct resource *res; | ||
200 | struct device *dev = &pdev->dev; | ||
201 | struct device_node *node = dev->of_node, *child; | ||
202 | struct regmap *regmap; | ||
203 | int ret; | ||
204 | |||
205 | dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL); | ||
206 | if (!dwc3_data) | ||
207 | return -ENOMEM; | ||
208 | |||
209 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg-glue"); | ||
210 | dwc3_data->glue_base = devm_ioremap_resource(dev, res); | ||
211 | if (IS_ERR(dwc3_data->glue_base)) | ||
212 | return PTR_ERR(dwc3_data->glue_base); | ||
213 | |||
214 | regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg"); | ||
215 | if (IS_ERR(regmap)) | ||
216 | return PTR_ERR(regmap); | ||
217 | |||
218 | dma_set_coherent_mask(dev, dev->coherent_dma_mask); | ||
219 | dwc3_data->dev = dev; | ||
220 | dwc3_data->regmap = regmap; | ||
221 | |||
222 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg"); | ||
223 | if (!res) { | ||
224 | ret = -ENXIO; | ||
225 | goto undo_platform_dev_alloc; | ||
226 | } | ||
227 | |||
228 | dwc3_data->syscfg_reg_off = res->start; | ||
229 | |||
230 | dev_vdbg(&pdev->dev, "glue-logic addr 0x%p, syscfg-reg offset 0x%x\n", | ||
231 | dwc3_data->glue_base, dwc3_data->syscfg_reg_off); | ||
232 | |||
233 | dwc3_data->rstc_pwrdn = devm_reset_control_get(dev, "powerdown"); | ||
234 | if (IS_ERR(dwc3_data->rstc_pwrdn)) { | ||
235 | dev_err(&pdev->dev, "could not get power controller\n"); | ||
236 | ret = PTR_ERR(dwc3_data->rstc_pwrdn); | ||
237 | goto undo_platform_dev_alloc; | ||
238 | } | ||
239 | |||
240 | /* Manage PowerDown */ | ||
241 | reset_control_deassert(dwc3_data->rstc_pwrdn); | ||
242 | |||
243 | dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset"); | ||
244 | if (IS_ERR(dwc3_data->rstc_rst)) { | ||
245 | dev_err(&pdev->dev, "could not get reset controller\n"); | ||
246 | ret = PTR_ERR(dwc3_data->rstc_pwrdn); | ||
247 | goto undo_powerdown; | ||
248 | } | ||
249 | |||
250 | /* Manage SoftReset */ | ||
251 | reset_control_deassert(dwc3_data->rstc_rst); | ||
252 | |||
253 | child = of_get_child_by_name(node, "dwc3"); | ||
254 | if (!child) { | ||
255 | dev_err(&pdev->dev, "failed to find dwc3 core node\n"); | ||
256 | ret = -ENODEV; | ||
257 | goto undo_softreset; | ||
258 | } | ||
259 | |||
260 | dwc3_data->dr_mode = of_usb_get_dr_mode(child); | ||
261 | |||
262 | /* Allocate and initialize the core */ | ||
263 | ret = of_platform_populate(node, NULL, NULL, dev); | ||
264 | if (ret) { | ||
265 | dev_err(dev, "failed to add dwc3 core\n"); | ||
266 | goto undo_softreset; | ||
267 | } | ||
268 | |||
269 | /* | ||
270 | * Configure the USB port as device or host according to the static | ||
271 | * configuration passed from DT. | ||
272 | * DRD is the only mode currently supported so this will be enhanced | ||
273 | * as soon as OTG is available. | ||
274 | */ | ||
275 | ret = st_dwc3_drd_init(dwc3_data); | ||
276 | if (ret) { | ||
277 | dev_err(dev, "drd initialisation failed\n"); | ||
278 | goto undo_softreset; | ||
279 | } | ||
280 | |||
281 | /* ST glue logic init */ | ||
282 | st_dwc3_init(dwc3_data); | ||
283 | |||
284 | platform_set_drvdata(pdev, dwc3_data); | ||
285 | return 0; | ||
286 | |||
287 | undo_softreset: | ||
288 | reset_control_assert(dwc3_data->rstc_rst); | ||
289 | undo_powerdown: | ||
290 | reset_control_assert(dwc3_data->rstc_pwrdn); | ||
291 | undo_platform_dev_alloc: | ||
292 | platform_device_put(pdev); | ||
293 | return ret; | ||
294 | } | ||
295 | |||
296 | static int st_dwc3_remove(struct platform_device *pdev) | ||
297 | { | ||
298 | struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev); | ||
299 | |||
300 | of_platform_depopulate(&pdev->dev); | ||
301 | |||
302 | reset_control_assert(dwc3_data->rstc_pwrdn); | ||
303 | reset_control_assert(dwc3_data->rstc_rst); | ||
304 | |||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | #ifdef CONFIG_PM_SLEEP | ||
309 | static int st_dwc3_suspend(struct device *dev) | ||
310 | { | ||
311 | struct st_dwc3 *dwc3_data = dev_get_drvdata(dev); | ||
312 | |||
313 | reset_control_assert(dwc3_data->rstc_pwrdn); | ||
314 | reset_control_assert(dwc3_data->rstc_rst); | ||
315 | |||
316 | pinctrl_pm_select_sleep_state(dev); | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | static int st_dwc3_resume(struct device *dev) | ||
322 | { | ||
323 | struct st_dwc3 *dwc3_data = dev_get_drvdata(dev); | ||
324 | int ret; | ||
325 | |||
326 | pinctrl_pm_select_default_state(dev); | ||
327 | |||
328 | reset_control_deassert(dwc3_data->rstc_pwrdn); | ||
329 | reset_control_deassert(dwc3_data->rstc_rst); | ||
330 | |||
331 | ret = st_dwc3_drd_init(dwc3_data); | ||
332 | if (ret) { | ||
333 | dev_err(dev, "drd initialisation failed\n"); | ||
334 | return ret; | ||
335 | } | ||
336 | |||
337 | /* ST glue logic init */ | ||
338 | st_dwc3_init(dwc3_data); | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | #endif /* CONFIG_PM_SLEEP */ | ||
343 | |||
344 | static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume); | ||
345 | |||
346 | static const struct of_device_id st_dwc3_match[] = { | ||
347 | { .compatible = "st,stih407-dwc3" }, | ||
348 | { /* sentinel */ }, | ||
349 | }; | ||
350 | |||
351 | MODULE_DEVICE_TABLE(of, st_dwc3_match); | ||
352 | |||
353 | static struct platform_driver st_dwc3_driver = { | ||
354 | .probe = st_dwc3_probe, | ||
355 | .remove = st_dwc3_remove, | ||
356 | .driver = { | ||
357 | .name = "usb-st-dwc3", | ||
358 | .of_match_table = st_dwc3_match, | ||
359 | .pm = &st_dwc3_dev_pm_ops, | ||
360 | }, | ||
361 | }; | ||
362 | |||
363 | module_platform_driver(st_dwc3_driver); | ||
364 | |||
365 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); | ||
366 | MODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer"); | ||
367 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 21a352079bc2..b35938777dde 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/usb/composite.h> | 31 | #include <linux/usb/composite.h> |
32 | 32 | ||
33 | #include "core.h" | 33 | #include "core.h" |
34 | #include "debug.h" | ||
34 | #include "gadget.h" | 35 | #include "gadget.h" |
35 | #include "io.h" | 36 | #include "io.h" |
36 | 37 | ||
@@ -65,7 +66,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, | |||
65 | 66 | ||
66 | dep = dwc->eps[epnum]; | 67 | dep = dwc->eps[epnum]; |
67 | if (dep->flags & DWC3_EP_BUSY) { | 68 | if (dep->flags & DWC3_EP_BUSY) { |
68 | dev_vdbg(dwc->dev, "%s: still busy\n", dep->name); | 69 | dwc3_trace(trace_dwc3_ep0, "%s still busy", dep->name); |
69 | return 0; | 70 | return 0; |
70 | } | 71 | } |
71 | 72 | ||
@@ -88,7 +89,8 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, | |||
88 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, | 89 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, |
89 | DWC3_DEPCMD_STARTTRANSFER, ¶ms); | 90 | DWC3_DEPCMD_STARTTRANSFER, ¶ms); |
90 | if (ret < 0) { | 91 | if (ret < 0) { |
91 | dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); | 92 | dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed", |
93 | dep->name); | ||
92 | return ret; | 94 | return ret; |
93 | } | 95 | } |
94 | 96 | ||
@@ -153,7 +155,8 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, | |||
153 | if (dwc->ep0state == EP0_STATUS_PHASE) | 155 | if (dwc->ep0state == EP0_STATUS_PHASE) |
154 | __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); | 156 | __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); |
155 | else | 157 | else |
156 | dev_dbg(dwc->dev, "too early for delayed status\n"); | 158 | dwc3_trace(trace_dwc3_ep0, |
159 | "too early for delayed status"); | ||
157 | 160 | ||
158 | return 0; | 161 | return 0; |
159 | } | 162 | } |
@@ -217,7 +220,8 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, | |||
217 | 220 | ||
218 | spin_lock_irqsave(&dwc->lock, flags); | 221 | spin_lock_irqsave(&dwc->lock, flags); |
219 | if (!dep->endpoint.desc) { | 222 | if (!dep->endpoint.desc) { |
220 | dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", | 223 | dwc3_trace(trace_dwc3_ep0, |
224 | "trying to queue request %p to disabled %s", | ||
221 | request, dep->name); | 225 | request, dep->name); |
222 | ret = -ESHUTDOWN; | 226 | ret = -ESHUTDOWN; |
223 | goto out; | 227 | goto out; |
@@ -229,7 +233,8 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, | |||
229 | goto out; | 233 | goto out; |
230 | } | 234 | } |
231 | 235 | ||
232 | dev_vdbg(dwc->dev, "queueing request %p to %s length %d, state '%s'\n", | 236 | dwc3_trace(trace_dwc3_ep0, |
237 | "queueing request %p to %s length %d state '%s'", | ||
233 | request, dep->name, request->length, | 238 | request, dep->name, request->length, |
234 | dwc3_ep0_state_string(dwc->ep0state)); | 239 | dwc3_ep0_state_string(dwc->ep0state)); |
235 | 240 | ||
@@ -485,12 +490,13 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
485 | 490 | ||
486 | addr = le16_to_cpu(ctrl->wValue); | 491 | addr = le16_to_cpu(ctrl->wValue); |
487 | if (addr > 127) { | 492 | if (addr > 127) { |
488 | dev_dbg(dwc->dev, "invalid device address %d\n", addr); | 493 | dwc3_trace(trace_dwc3_ep0, "invalid device address %d", addr); |
489 | return -EINVAL; | 494 | return -EINVAL; |
490 | } | 495 | } |
491 | 496 | ||
492 | if (state == USB_STATE_CONFIGURED) { | 497 | if (state == USB_STATE_CONFIGURED) { |
493 | dev_dbg(dwc->dev, "trying to set address when configured\n"); | 498 | dwc3_trace(trace_dwc3_ep0, |
499 | "trying to set address when configured"); | ||
494 | return -EINVAL; | 500 | return -EINVAL; |
495 | } | 501 | } |
496 | 502 | ||
@@ -556,7 +562,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
556 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); | 562 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
557 | 563 | ||
558 | dwc->resize_fifos = true; | 564 | dwc->resize_fifos = true; |
559 | dev_dbg(dwc->dev, "resize fifos flag SET\n"); | 565 | dwc3_trace(trace_dwc3_ep0, "resize FIFOs flag SET"); |
560 | } | 566 | } |
561 | break; | 567 | break; |
562 | 568 | ||
@@ -680,35 +686,35 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) | |||
680 | 686 | ||
681 | switch (ctrl->bRequest) { | 687 | switch (ctrl->bRequest) { |
682 | case USB_REQ_GET_STATUS: | 688 | case USB_REQ_GET_STATUS: |
683 | dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS\n"); | 689 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS\n"); |
684 | ret = dwc3_ep0_handle_status(dwc, ctrl); | 690 | ret = dwc3_ep0_handle_status(dwc, ctrl); |
685 | break; | 691 | break; |
686 | case USB_REQ_CLEAR_FEATURE: | 692 | case USB_REQ_CLEAR_FEATURE: |
687 | dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE\n"); | 693 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE\n"); |
688 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); | 694 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); |
689 | break; | 695 | break; |
690 | case USB_REQ_SET_FEATURE: | 696 | case USB_REQ_SET_FEATURE: |
691 | dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE\n"); | 697 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE\n"); |
692 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); | 698 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); |
693 | break; | 699 | break; |
694 | case USB_REQ_SET_ADDRESS: | 700 | case USB_REQ_SET_ADDRESS: |
695 | dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS\n"); | 701 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS\n"); |
696 | ret = dwc3_ep0_set_address(dwc, ctrl); | 702 | ret = dwc3_ep0_set_address(dwc, ctrl); |
697 | break; | 703 | break; |
698 | case USB_REQ_SET_CONFIGURATION: | 704 | case USB_REQ_SET_CONFIGURATION: |
699 | dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); | 705 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION\n"); |
700 | ret = dwc3_ep0_set_config(dwc, ctrl); | 706 | ret = dwc3_ep0_set_config(dwc, ctrl); |
701 | break; | 707 | break; |
702 | case USB_REQ_SET_SEL: | 708 | case USB_REQ_SET_SEL: |
703 | dev_vdbg(dwc->dev, "USB_REQ_SET_SEL\n"); | 709 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL\n"); |
704 | ret = dwc3_ep0_set_sel(dwc, ctrl); | 710 | ret = dwc3_ep0_set_sel(dwc, ctrl); |
705 | break; | 711 | break; |
706 | case USB_REQ_SET_ISOCH_DELAY: | 712 | case USB_REQ_SET_ISOCH_DELAY: |
707 | dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); | 713 | dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY\n"); |
708 | ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); | 714 | ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); |
709 | break; | 715 | break; |
710 | default: | 716 | default: |
711 | dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); | 717 | dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver\n"); |
712 | ret = dwc3_ep0_delegate_req(dwc, ctrl); | 718 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
713 | break; | 719 | break; |
714 | } | 720 | } |
@@ -726,6 +732,8 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, | |||
726 | if (!dwc->gadget_driver) | 732 | if (!dwc->gadget_driver) |
727 | goto out; | 733 | goto out; |
728 | 734 | ||
735 | trace_dwc3_ctrl_req(ctrl); | ||
736 | |||
729 | len = le16_to_cpu(ctrl->wLength); | 737 | len = le16_to_cpu(ctrl->wLength); |
730 | if (!len) { | 738 | if (!len) { |
731 | dwc->three_stage_setup = false; | 739 | dwc->three_stage_setup = false; |
@@ -774,7 +782,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc, | |||
774 | 782 | ||
775 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); | 783 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
776 | if (status == DWC3_TRBSTS_SETUP_PENDING) { | 784 | if (status == DWC3_TRBSTS_SETUP_PENDING) { |
777 | dev_dbg(dwc->dev, "Setup Pending received\n"); | 785 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); |
778 | 786 | ||
779 | if (r) | 787 | if (r) |
780 | dwc3_gadget_giveback(ep0, r, -ECONNRESET); | 788 | dwc3_gadget_giveback(ep0, r, -ECONNRESET); |
@@ -834,7 +842,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc, | |||
834 | 842 | ||
835 | ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); | 843 | ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); |
836 | if (ret < 0) { | 844 | if (ret < 0) { |
837 | dev_dbg(dwc->dev, "Invalid Test #%d\n", | 845 | dwc3_trace(trace_dwc3_ep0, "Invalid Test #%d", |
838 | dwc->test_mode_nr); | 846 | dwc->test_mode_nr); |
839 | dwc3_ep0_stall_and_restart(dwc); | 847 | dwc3_ep0_stall_and_restart(dwc); |
840 | return; | 848 | return; |
@@ -843,7 +851,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc, | |||
843 | 851 | ||
844 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); | 852 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
845 | if (status == DWC3_TRBSTS_SETUP_PENDING) | 853 | if (status == DWC3_TRBSTS_SETUP_PENDING) |
846 | dev_dbg(dwc->dev, "Setup Pending received\n"); | 854 | dwc3_trace(trace_dwc3_ep0, "Setup Pending received\n"); |
847 | 855 | ||
848 | dwc->ep0state = EP0_SETUP_PHASE; | 856 | dwc->ep0state = EP0_SETUP_PHASE; |
849 | dwc3_ep0_out_start(dwc); | 857 | dwc3_ep0_out_start(dwc); |
@@ -860,17 +868,17 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, | |||
860 | 868 | ||
861 | switch (dwc->ep0state) { | 869 | switch (dwc->ep0state) { |
862 | case EP0_SETUP_PHASE: | 870 | case EP0_SETUP_PHASE: |
863 | dev_vdbg(dwc->dev, "Inspecting Setup Bytes\n"); | 871 | dwc3_trace(trace_dwc3_ep0, "Setup Phase"); |
864 | dwc3_ep0_inspect_setup(dwc, event); | 872 | dwc3_ep0_inspect_setup(dwc, event); |
865 | break; | 873 | break; |
866 | 874 | ||
867 | case EP0_DATA_PHASE: | 875 | case EP0_DATA_PHASE: |
868 | dev_vdbg(dwc->dev, "Data Phase\n"); | 876 | dwc3_trace(trace_dwc3_ep0, "Data Phase"); |
869 | dwc3_ep0_complete_data(dwc, event); | 877 | dwc3_ep0_complete_data(dwc, event); |
870 | break; | 878 | break; |
871 | 879 | ||
872 | case EP0_STATUS_PHASE: | 880 | case EP0_STATUS_PHASE: |
873 | dev_vdbg(dwc->dev, "Status Phase\n"); | 881 | dwc3_trace(trace_dwc3_ep0, "Status Phase"); |
874 | dwc3_ep0_complete_status(dwc, event); | 882 | dwc3_ep0_complete_status(dwc, event); |
875 | break; | 883 | break; |
876 | default: | 884 | default: |
@@ -946,7 +954,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep) | |||
946 | static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) | 954 | static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) |
947 | { | 955 | { |
948 | if (dwc->resize_fifos) { | 956 | if (dwc->resize_fifos) { |
949 | dev_dbg(dwc->dev, "starting to resize fifos\n"); | 957 | dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs"); |
950 | dwc3_gadget_resize_tx_fifos(dwc); | 958 | dwc3_gadget_resize_tx_fifos(dwc); |
951 | dwc->resize_fifos = 0; | 959 | dwc->resize_fifos = 0; |
952 | } | 960 | } |
@@ -987,7 +995,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc, | |||
987 | 995 | ||
988 | switch (event->status) { | 996 | switch (event->status) { |
989 | case DEPEVT_STATUS_CONTROL_DATA: | 997 | case DEPEVT_STATUS_CONTROL_DATA: |
990 | dev_vdbg(dwc->dev, "Control Data\n"); | 998 | dwc3_trace(trace_dwc3_ep0, "Control Data"); |
991 | 999 | ||
992 | /* | 1000 | /* |
993 | * We already have a DATA transfer in the controller's cache, | 1001 | * We already have a DATA transfer in the controller's cache, |
@@ -1001,7 +1009,8 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc, | |||
1001 | if (dwc->ep0_expect_in != event->endpoint_number) { | 1009 | if (dwc->ep0_expect_in != event->endpoint_number) { |
1002 | struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; | 1010 | struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; |
1003 | 1011 | ||
1004 | dev_vdbg(dwc->dev, "Wrong direction for Data phase\n"); | 1012 | dwc3_trace(trace_dwc3_ep0, |
1013 | "Wrong direction for Data phase"); | ||
1005 | dwc3_ep0_end_control_data(dwc, dep); | 1014 | dwc3_ep0_end_control_data(dwc, dep); |
1006 | dwc3_ep0_stall_and_restart(dwc); | 1015 | dwc3_ep0_stall_and_restart(dwc); |
1007 | return; | 1016 | return; |
@@ -1013,13 +1022,13 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc, | |||
1013 | if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) | 1022 | if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) |
1014 | return; | 1023 | return; |
1015 | 1024 | ||
1016 | dev_vdbg(dwc->dev, "Control Status\n"); | 1025 | dwc3_trace(trace_dwc3_ep0, "Control Status"); |
1017 | 1026 | ||
1018 | dwc->ep0state = EP0_STATUS_PHASE; | 1027 | dwc->ep0state = EP0_STATUS_PHASE; |
1019 | 1028 | ||
1020 | if (dwc->delayed_status) { | 1029 | if (dwc->delayed_status) { |
1021 | WARN_ON_ONCE(event->endpoint_number != 1); | 1030 | WARN_ON_ONCE(event->endpoint_number != 1); |
1022 | dev_vdbg(dwc->dev, "Mass Storage delayed status\n"); | 1031 | dwc3_trace(trace_dwc3_ep0, "Delayed Status"); |
1023 | return; | 1032 | return; |
1024 | } | 1033 | } |
1025 | 1034 | ||
@@ -1032,7 +1041,7 @@ void dwc3_ep0_interrupt(struct dwc3 *dwc, | |||
1032 | { | 1041 | { |
1033 | u8 epnum = event->endpoint_number; | 1042 | u8 epnum = event->endpoint_number; |
1034 | 1043 | ||
1035 | dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'\n", | 1044 | dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'", |
1036 | dwc3_ep_event_string(event->endpoint_event), | 1045 | dwc3_ep_event_string(event->endpoint_event), |
1037 | epnum >> 1, (epnum & 1) ? "in" : "out", | 1046 | epnum >> 1, (epnum & 1) ? "in" : "out", |
1038 | dwc3_ep0_state_string(dwc->ep0state)); | 1047 | dwc3_ep0_state_string(dwc->ep0state)); |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 490a6ca00733..3818b26bfc05 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/usb/ch9.h> | 30 | #include <linux/usb/ch9.h> |
31 | #include <linux/usb/gadget.h> | 31 | #include <linux/usb/gadget.h> |
32 | 32 | ||
33 | #include "debug.h" | ||
33 | #include "core.h" | 34 | #include "core.h" |
34 | #include "gadget.h" | 35 | #include "gadget.h" |
35 | #include "io.h" | 36 | #include "io.h" |
@@ -266,107 +267,19 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, | |||
266 | dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", | 267 | dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", |
267 | req, dep->name, req->request.actual, | 268 | req, dep->name, req->request.actual, |
268 | req->request.length, status); | 269 | req->request.length, status); |
270 | trace_dwc3_gadget_giveback(req); | ||
269 | 271 | ||
270 | spin_unlock(&dwc->lock); | 272 | spin_unlock(&dwc->lock); |
271 | req->request.complete(&dep->endpoint, &req->request); | 273 | usb_gadget_giveback_request(&dep->endpoint, &req->request); |
272 | spin_lock(&dwc->lock); | 274 | spin_lock(&dwc->lock); |
273 | } | 275 | } |
274 | 276 | ||
275 | static const char *dwc3_gadget_ep_cmd_string(u8 cmd) | 277 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param) |
276 | { | ||
277 | switch (cmd) { | ||
278 | case DWC3_DEPCMD_DEPSTARTCFG: | ||
279 | return "Start New Configuration"; | ||
280 | case DWC3_DEPCMD_ENDTRANSFER: | ||
281 | return "End Transfer"; | ||
282 | case DWC3_DEPCMD_UPDATETRANSFER: | ||
283 | return "Update Transfer"; | ||
284 | case DWC3_DEPCMD_STARTTRANSFER: | ||
285 | return "Start Transfer"; | ||
286 | case DWC3_DEPCMD_CLEARSTALL: | ||
287 | return "Clear Stall"; | ||
288 | case DWC3_DEPCMD_SETSTALL: | ||
289 | return "Set Stall"; | ||
290 | case DWC3_DEPCMD_GETEPSTATE: | ||
291 | return "Get Endpoint State"; | ||
292 | case DWC3_DEPCMD_SETTRANSFRESOURCE: | ||
293 | return "Set Endpoint Transfer Resource"; | ||
294 | case DWC3_DEPCMD_SETEPCONFIG: | ||
295 | return "Set Endpoint Configuration"; | ||
296 | default: | ||
297 | return "UNKNOWN command"; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | static const char *dwc3_gadget_generic_cmd_string(u8 cmd) | ||
302 | { | ||
303 | switch (cmd) { | ||
304 | case DWC3_DGCMD_SET_LMP: | ||
305 | return "Set LMP"; | ||
306 | case DWC3_DGCMD_SET_PERIODIC_PAR: | ||
307 | return "Set Periodic Parameters"; | ||
308 | case DWC3_DGCMD_XMIT_FUNCTION: | ||
309 | return "Transmit Function Wake Device Notification"; | ||
310 | case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO: | ||
311 | return "Set Scratchpad Buffer Array Address Lo"; | ||
312 | case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI: | ||
313 | return "Set Scratchpad Buffer Array Address Hi"; | ||
314 | case DWC3_DGCMD_SELECTED_FIFO_FLUSH: | ||
315 | return "Selected FIFO Flush"; | ||
316 | case DWC3_DGCMD_ALL_FIFO_FLUSH: | ||
317 | return "All FIFO Flush"; | ||
318 | case DWC3_DGCMD_SET_ENDPOINT_NRDY: | ||
319 | return "Set Endpoint NRDY"; | ||
320 | case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: | ||
321 | return "Run SoC Bus Loopback Test"; | ||
322 | default: | ||
323 | return "UNKNOWN"; | ||
324 | } | ||
325 | } | ||
326 | |||
327 | static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state) | ||
328 | { | ||
329 | switch (link_state) { | ||
330 | case DWC3_LINK_STATE_U0: | ||
331 | return "U0"; | ||
332 | case DWC3_LINK_STATE_U1: | ||
333 | return "U1"; | ||
334 | case DWC3_LINK_STATE_U2: | ||
335 | return "U2"; | ||
336 | case DWC3_LINK_STATE_U3: | ||
337 | return "U3"; | ||
338 | case DWC3_LINK_STATE_SS_DIS: | ||
339 | return "SS.Disabled"; | ||
340 | case DWC3_LINK_STATE_RX_DET: | ||
341 | return "RX.Detect"; | ||
342 | case DWC3_LINK_STATE_SS_INACT: | ||
343 | return "SS.Inactive"; | ||
344 | case DWC3_LINK_STATE_POLL: | ||
345 | return "Polling"; | ||
346 | case DWC3_LINK_STATE_RECOV: | ||
347 | return "Recovery"; | ||
348 | case DWC3_LINK_STATE_HRESET: | ||
349 | return "Hot Reset"; | ||
350 | case DWC3_LINK_STATE_CMPLY: | ||
351 | return "Compliance"; | ||
352 | case DWC3_LINK_STATE_LPBK: | ||
353 | return "Loopback"; | ||
354 | case DWC3_LINK_STATE_RESET: | ||
355 | return "Reset"; | ||
356 | case DWC3_LINK_STATE_RESUME: | ||
357 | return "Resume"; | ||
358 | default: | ||
359 | return "UNKNOWN link state\n"; | ||
360 | } | ||
361 | } | ||
362 | |||
363 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) | ||
364 | { | 278 | { |
365 | u32 timeout = 500; | 279 | u32 timeout = 500; |
366 | u32 reg; | 280 | u32 reg; |
367 | 281 | ||
368 | dev_vdbg(dwc->dev, "generic cmd '%s' [%d] param %08x\n", | 282 | trace_dwc3_gadget_generic_cmd(cmd, param); |
369 | dwc3_gadget_generic_cmd_string(cmd), cmd, param); | ||
370 | 283 | ||
371 | dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); | 284 | dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); |
372 | dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); | 285 | dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); |
@@ -397,10 +310,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, | |||
397 | u32 timeout = 500; | 310 | u32 timeout = 500; |
398 | u32 reg; | 311 | u32 reg; |
399 | 312 | ||
400 | dev_vdbg(dwc->dev, "%s: cmd '%s' [%d] params %08x %08x %08x\n", | 313 | trace_dwc3_gadget_ep_cmd(dep, cmd, params); |
401 | dep->name, | ||
402 | dwc3_gadget_ep_cmd_string(cmd), cmd, params->param0, | ||
403 | params->param1, params->param2); | ||
404 | 314 | ||
405 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); | 315 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); |
406 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1); | 316 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1); |
@@ -789,17 +699,16 @@ static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep, | |||
789 | { | 699 | { |
790 | struct dwc3_request *req; | 700 | struct dwc3_request *req; |
791 | struct dwc3_ep *dep = to_dwc3_ep(ep); | 701 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
792 | struct dwc3 *dwc = dep->dwc; | ||
793 | 702 | ||
794 | req = kzalloc(sizeof(*req), gfp_flags); | 703 | req = kzalloc(sizeof(*req), gfp_flags); |
795 | if (!req) { | 704 | if (!req) |
796 | dev_err(dwc->dev, "not enough memory\n"); | ||
797 | return NULL; | 705 | return NULL; |
798 | } | ||
799 | 706 | ||
800 | req->epnum = dep->number; | 707 | req->epnum = dep->number; |
801 | req->dep = dep; | 708 | req->dep = dep; |
802 | 709 | ||
710 | trace_dwc3_alloc_request(req); | ||
711 | |||
803 | return &req->request; | 712 | return &req->request; |
804 | } | 713 | } |
805 | 714 | ||
@@ -808,6 +717,7 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep, | |||
808 | { | 717 | { |
809 | struct dwc3_request *req = to_dwc3_request(request); | 718 | struct dwc3_request *req = to_dwc3_request(request); |
810 | 719 | ||
720 | trace_dwc3_free_request(req); | ||
811 | kfree(req); | 721 | kfree(req); |
812 | } | 722 | } |
813 | 723 | ||
@@ -889,6 +799,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep, | |||
889 | trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id); | 799 | trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id); |
890 | 800 | ||
891 | trb->ctrl |= DWC3_TRB_CTRL_HWO; | 801 | trb->ctrl |= DWC3_TRB_CTRL_HWO; |
802 | |||
803 | trace_dwc3_prepare_trb(dep, trb); | ||
892 | } | 804 | } |
893 | 805 | ||
894 | /* | 806 | /* |
@@ -1235,6 +1147,7 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, | |||
1235 | 1147 | ||
1236 | dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", | 1148 | dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", |
1237 | request, ep->name, request->length); | 1149 | request, ep->name, request->length); |
1150 | trace_dwc3_ep_queue(req); | ||
1238 | 1151 | ||
1239 | ret = __dwc3_gadget_ep_queue(dep, req); | 1152 | ret = __dwc3_gadget_ep_queue(dep, req); |
1240 | spin_unlock_irqrestore(&dwc->lock, flags); | 1153 | spin_unlock_irqrestore(&dwc->lock, flags); |
@@ -1254,6 +1167,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, | |||
1254 | unsigned long flags; | 1167 | unsigned long flags; |
1255 | int ret = 0; | 1168 | int ret = 0; |
1256 | 1169 | ||
1170 | trace_dwc3_ep_dequeue(req); | ||
1171 | |||
1257 | spin_lock_irqsave(&dwc->lock, flags); | 1172 | spin_lock_irqsave(&dwc->lock, flags); |
1258 | 1173 | ||
1259 | list_for_each_entry(r, &dep->request_list, list) { | 1174 | list_for_each_entry(r, &dep->request_list, list) { |
@@ -1744,11 +1659,8 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc, | |||
1744 | u8 epnum = (i << 1) | (!!direction); | 1659 | u8 epnum = (i << 1) | (!!direction); |
1745 | 1660 | ||
1746 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); | 1661 | dep = kzalloc(sizeof(*dep), GFP_KERNEL); |
1747 | if (!dep) { | 1662 | if (!dep) |
1748 | dev_err(dwc->dev, "can't allocate endpoint %d\n", | ||
1749 | epnum); | ||
1750 | return -ENOMEM; | 1663 | return -ENOMEM; |
1751 | } | ||
1752 | 1664 | ||
1753 | dep->dwc = dwc; | 1665 | dep->dwc = dwc; |
1754 | dep->number = epnum; | 1666 | dep->number = epnum; |
@@ -1847,6 +1759,8 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, | |||
1847 | unsigned int s_pkt = 0; | 1759 | unsigned int s_pkt = 0; |
1848 | unsigned int trb_status; | 1760 | unsigned int trb_status; |
1849 | 1761 | ||
1762 | trace_dwc3_complete_trb(dep, trb); | ||
1763 | |||
1850 | if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) | 1764 | if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) |
1851 | /* | 1765 | /* |
1852 | * We continue despite the error. There is not much we | 1766 | * We continue despite the error. There is not much we |
@@ -2021,9 +1935,6 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, | |||
2021 | if (!(dep->flags & DWC3_EP_ENABLED)) | 1935 | if (!(dep->flags & DWC3_EP_ENABLED)) |
2022 | return; | 1936 | return; |
2023 | 1937 | ||
2024 | dev_vdbg(dwc->dev, "%s: %s\n", dep->name, | ||
2025 | dwc3_ep_event_string(event->endpoint_event)); | ||
2026 | |||
2027 | if (epnum == 0 || epnum == 1) { | 1938 | if (epnum == 0 || epnum == 1) { |
2028 | dwc3_ep0_interrupt(dwc, event); | 1939 | dwc3_ep0_interrupt(dwc, event); |
2029 | return; | 1940 | return; |
@@ -2210,8 +2121,6 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) | |||
2210 | { | 2121 | { |
2211 | int reg; | 2122 | int reg; |
2212 | 2123 | ||
2213 | dev_vdbg(dwc->dev, "%s\n", __func__); | ||
2214 | |||
2215 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); | 2124 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
2216 | reg &= ~DWC3_DCTL_INITU1ENA; | 2125 | reg &= ~DWC3_DCTL_INITU1ENA; |
2217 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); | 2126 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
@@ -2230,8 +2139,6 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) | |||
2230 | { | 2139 | { |
2231 | u32 reg; | 2140 | u32 reg; |
2232 | 2141 | ||
2233 | dev_vdbg(dwc->dev, "%s\n", __func__); | ||
2234 | |||
2235 | /* | 2142 | /* |
2236 | * WORKAROUND: DWC3 revisions <1.88a have an issue which | 2143 | * WORKAROUND: DWC3 revisions <1.88a have an issue which |
2237 | * would cause a missing Disconnect Event if there's a | 2144 | * would cause a missing Disconnect Event if there's a |
@@ -2316,8 +2223,6 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) | |||
2316 | u32 reg; | 2223 | u32 reg; |
2317 | u8 speed; | 2224 | u8 speed; |
2318 | 2225 | ||
2319 | dev_vdbg(dwc->dev, "%s\n", __func__); | ||
2320 | |||
2321 | reg = dwc3_readl(dwc->regs, DWC3_DSTS); | 2226 | reg = dwc3_readl(dwc->regs, DWC3_DSTS); |
2322 | speed = reg & DWC3_DSTS_CONNECTSPD; | 2227 | speed = reg & DWC3_DSTS_CONNECTSPD; |
2323 | dwc->speed = speed; | 2228 | dwc->speed = speed; |
@@ -2415,8 +2320,6 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) | |||
2415 | 2320 | ||
2416 | static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) | 2321 | static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) |
2417 | { | 2322 | { |
2418 | dev_vdbg(dwc->dev, "%s\n", __func__); | ||
2419 | |||
2420 | /* | 2323 | /* |
2421 | * TODO take core out of low power mode when that's | 2324 | * TODO take core out of low power mode when that's |
2422 | * implemented. | 2325 | * implemented. |
@@ -2521,10 +2424,6 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, | |||
2521 | break; | 2424 | break; |
2522 | } | 2425 | } |
2523 | 2426 | ||
2524 | dev_vdbg(dwc->dev, "link change: %s [%d] -> %s [%d]\n", | ||
2525 | dwc3_gadget_link_string(dwc->link_state), | ||
2526 | dwc->link_state, dwc3_gadget_link_string(next), next); | ||
2527 | |||
2528 | dwc->link_state = next; | 2427 | dwc->link_state = next; |
2529 | } | 2428 | } |
2530 | 2429 | ||
@@ -2601,6 +2500,8 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, | |||
2601 | static void dwc3_process_event_entry(struct dwc3 *dwc, | 2500 | static void dwc3_process_event_entry(struct dwc3 *dwc, |
2602 | const union dwc3_event *event) | 2501 | const union dwc3_event *event) |
2603 | { | 2502 | { |
2503 | trace_dwc3_event(event->raw); | ||
2504 | |||
2604 | /* Endpoint IRQ, handle it and return early */ | 2505 | /* Endpoint IRQ, handle it and return early */ |
2605 | if (event->type.is_devspec == 0) { | 2506 | if (event->type.is_devspec == 0) { |
2606 | /* depevt */ | 2507 | /* depevt */ |
@@ -2754,7 +2655,6 @@ int dwc3_gadget_init(struct dwc3 *dwc) | |||
2754 | 2655 | ||
2755 | dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL); | 2656 | dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL); |
2756 | if (!dwc->setup_buf) { | 2657 | if (!dwc->setup_buf) { |
2757 | dev_err(dwc->dev, "failed to allocate setup buffer\n"); | ||
2758 | ret = -ENOMEM; | 2658 | ret = -ENOMEM; |
2759 | goto err2; | 2659 | goto err2; |
2760 | } | 2660 | } |
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index a0ee75b68a80..178ad8982206 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h | |||
@@ -103,60 +103,4 @@ static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number) | |||
103 | return DWC3_DEPCMD_GET_RSC_IDX(res_id); | 103 | return DWC3_DEPCMD_GET_RSC_IDX(res_id); |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | ||
107 | * dwc3_gadget_event_string - returns event name | ||
108 | * @event: the event code | ||
109 | */ | ||
110 | static inline const char *dwc3_gadget_event_string(u8 event) | ||
111 | { | ||
112 | switch (event) { | ||
113 | case DWC3_DEVICE_EVENT_DISCONNECT: | ||
114 | return "Disconnect"; | ||
115 | case DWC3_DEVICE_EVENT_RESET: | ||
116 | return "Reset"; | ||
117 | case DWC3_DEVICE_EVENT_CONNECT_DONE: | ||
118 | return "Connection Done"; | ||
119 | case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: | ||
120 | return "Link Status Change"; | ||
121 | case DWC3_DEVICE_EVENT_WAKEUP: | ||
122 | return "WakeUp"; | ||
123 | case DWC3_DEVICE_EVENT_EOPF: | ||
124 | return "End-Of-Frame"; | ||
125 | case DWC3_DEVICE_EVENT_SOF: | ||
126 | return "Start-Of-Frame"; | ||
127 | case DWC3_DEVICE_EVENT_ERRATIC_ERROR: | ||
128 | return "Erratic Error"; | ||
129 | case DWC3_DEVICE_EVENT_CMD_CMPL: | ||
130 | return "Command Complete"; | ||
131 | case DWC3_DEVICE_EVENT_OVERFLOW: | ||
132 | return "Overflow"; | ||
133 | } | ||
134 | |||
135 | return "UNKNOWN"; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * dwc3_ep_event_string - returns event name | ||
140 | * @event: then event code | ||
141 | */ | ||
142 | static inline const char *dwc3_ep_event_string(u8 event) | ||
143 | { | ||
144 | switch (event) { | ||
145 | case DWC3_DEPEVT_XFERCOMPLETE: | ||
146 | return "Transfer Complete"; | ||
147 | case DWC3_DEPEVT_XFERINPROGRESS: | ||
148 | return "Transfer In-Progress"; | ||
149 | case DWC3_DEPEVT_XFERNOTREADY: | ||
150 | return "Transfer Not Ready"; | ||
151 | case DWC3_DEPEVT_RXTXFIFOEVT: | ||
152 | return "FIFO"; | ||
153 | case DWC3_DEPEVT_STREAMEVT: | ||
154 | return "Stream"; | ||
155 | case DWC3_DEPEVT_EPCMDCMPLT: | ||
156 | return "Endpoint Command Complete"; | ||
157 | } | ||
158 | |||
159 | return "UNKNOWN"; | ||
160 | } | ||
161 | |||
162 | #endif /* __DRIVERS_USB_DWC3_GADGET_H */ | 106 | #endif /* __DRIVERS_USB_DWC3_GADGET_H */ |
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h index d94441c14d8c..6a79c8e66bbc 100644 --- a/drivers/usb/dwc3/io.h +++ b/drivers/usb/dwc3/io.h | |||
@@ -20,27 +20,51 @@ | |||
20 | #define __DRIVERS_USB_DWC3_IO_H | 20 | #define __DRIVERS_USB_DWC3_IO_H |
21 | 21 | ||
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | 23 | #include "trace.h" | |
24 | #include "debug.h" | ||
24 | #include "core.h" | 25 | #include "core.h" |
25 | 26 | ||
26 | static inline u32 dwc3_readl(void __iomem *base, u32 offset) | 27 | static inline u32 dwc3_readl(void __iomem *base, u32 offset) |
27 | { | 28 | { |
29 | u32 offs = offset - DWC3_GLOBALS_REGS_START; | ||
30 | u32 value; | ||
31 | |||
28 | /* | 32 | /* |
29 | * We requested the mem region starting from the Globals address | 33 | * We requested the mem region starting from the Globals address |
30 | * space, see dwc3_probe in core.c. | 34 | * space, see dwc3_probe in core.c. |
31 | * However, the offsets are given starting from xHCI address space. | 35 | * However, the offsets are given starting from xHCI address space. |
32 | */ | 36 | */ |
33 | return readl(base + (offset - DWC3_GLOBALS_REGS_START)); | 37 | value = readl(base + offs); |
38 | |||
39 | /* | ||
40 | * When tracing we want to make it easy to find the correct address on | ||
41 | * documentation, so we revert it back to the proper addresses, the | ||
42 | * same way they are described on SNPS documentation | ||
43 | */ | ||
44 | dwc3_trace(trace_dwc3_readl, "addr %p value %08x", | ||
45 | base - DWC3_GLOBALS_REGS_START + offset, value); | ||
46 | |||
47 | return value; | ||
34 | } | 48 | } |
35 | 49 | ||
36 | static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) | 50 | static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) |
37 | { | 51 | { |
52 | u32 offs = offset - DWC3_GLOBALS_REGS_START; | ||
53 | |||
38 | /* | 54 | /* |
39 | * We requested the mem region starting from the Globals address | 55 | * We requested the mem region starting from the Globals address |
40 | * space, see dwc3_probe in core.c. | 56 | * space, see dwc3_probe in core.c. |
41 | * However, the offsets are given starting from xHCI address space. | 57 | * However, the offsets are given starting from xHCI address space. |
42 | */ | 58 | */ |
43 | writel(value, base + (offset - DWC3_GLOBALS_REGS_START)); | 59 | writel(value, base + offs); |
60 | |||
61 | /* | ||
62 | * When tracing we want to make it easy to find the correct address on | ||
63 | * documentation, so we revert it back to the proper addresses, the | ||
64 | * same way they are described on SNPS documentation | ||
65 | */ | ||
66 | dwc3_trace(trace_dwc3_writel, "addr %p value %08x", | ||
67 | base - DWC3_GLOBALS_REGS_START + offset, value); | ||
44 | } | 68 | } |
45 | 69 | ||
46 | #endif /* __DRIVERS_USB_DWC3_IO_H */ | 70 | #endif /* __DRIVERS_USB_DWC3_IO_H */ |
diff --git a/drivers/usb/dwc3/trace.c b/drivers/usb/dwc3/trace.c new file mode 100644 index 000000000000..6cd166412ad0 --- /dev/null +++ b/drivers/usb/dwc3/trace.c | |||
@@ -0,0 +1,19 @@ | |||
1 | /** | ||
2 | * trace.c - DesignWare USB3 DRD Controller Trace Support | ||
3 | * | ||
4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: Felipe Balbi <balbi@ti.com> | ||
7 | * | ||
8 | * This program is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 of | ||
10 | * the License as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | |||
18 | #define CREATE_TRACE_POINTS | ||
19 | #include "trace.h" | ||
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h new file mode 100644 index 000000000000..78aff1da089a --- /dev/null +++ b/drivers/usb/dwc3/trace.h | |||
@@ -0,0 +1,220 @@ | |||
1 | /** | ||
2 | * trace.h - DesignWare USB3 DRD Controller Trace Support | ||
3 | * | ||
4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * | ||
6 | * Author: Felipe Balbi <balbi@ti.com> | ||
7 | * | ||
8 | * This program is free software: you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 of | ||
10 | * the License as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | */ | ||
17 | |||
18 | #undef TRACE_SYSTEM | ||
19 | #define TRACE_SYSTEM dwc3 | ||
20 | |||
21 | #if !defined(__DWC3_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) | ||
22 | #define __DWC3_TRACE_H | ||
23 | |||
24 | #include <linux/types.h> | ||
25 | #include <linux/tracepoint.h> | ||
26 | #include <asm/byteorder.h> | ||
27 | #include "core.h" | ||
28 | #include "debug.h" | ||
29 | |||
30 | DECLARE_EVENT_CLASS(dwc3_log_msg, | ||
31 | TP_PROTO(struct va_format *vaf), | ||
32 | TP_ARGS(vaf), | ||
33 | TP_STRUCT__entry(__dynamic_array(char, msg, DWC3_MSG_MAX)), | ||
34 | TP_fast_assign( | ||
35 | vsnprintf(__get_str(msg), DWC3_MSG_MAX, vaf->fmt, *vaf->va); | ||
36 | ), | ||
37 | TP_printk("%s", __get_str(msg)) | ||
38 | ); | ||
39 | |||
40 | DEFINE_EVENT(dwc3_log_msg, dwc3_readl, | ||
41 | TP_PROTO(struct va_format *vaf), | ||
42 | TP_ARGS(vaf) | ||
43 | ); | ||
44 | |||
45 | DEFINE_EVENT(dwc3_log_msg, dwc3_writel, | ||
46 | TP_PROTO(struct va_format *vaf), | ||
47 | TP_ARGS(vaf) | ||
48 | ); | ||
49 | |||
50 | DEFINE_EVENT(dwc3_log_msg, dwc3_ep0, | ||
51 | TP_PROTO(struct va_format *vaf), | ||
52 | TP_ARGS(vaf) | ||
53 | ); | ||
54 | |||
55 | DECLARE_EVENT_CLASS(dwc3_log_event, | ||
56 | TP_PROTO(u32 event), | ||
57 | TP_ARGS(event), | ||
58 | TP_STRUCT__entry( | ||
59 | __field(u32, event) | ||
60 | ), | ||
61 | TP_fast_assign( | ||
62 | __entry->event = event; | ||
63 | ), | ||
64 | TP_printk("event %08x\n", __entry->event) | ||
65 | ); | ||
66 | |||
67 | DEFINE_EVENT(dwc3_log_event, dwc3_event, | ||
68 | TP_PROTO(u32 event), | ||
69 | TP_ARGS(event) | ||
70 | ); | ||
71 | |||
72 | DECLARE_EVENT_CLASS(dwc3_log_ctrl, | ||
73 | TP_PROTO(struct usb_ctrlrequest *ctrl), | ||
74 | TP_ARGS(ctrl), | ||
75 | TP_STRUCT__entry( | ||
76 | __field(struct usb_ctrlrequest *, ctrl) | ||
77 | ), | ||
78 | TP_fast_assign( | ||
79 | __entry->ctrl = ctrl; | ||
80 | ), | ||
81 | TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d", | ||
82 | __entry->ctrl->bRequestType, __entry->ctrl->bRequest, | ||
83 | le16_to_cpu(__entry->ctrl->wValue), le16_to_cpu(__entry->ctrl->wIndex), | ||
84 | le16_to_cpu(__entry->ctrl->wLength) | ||
85 | ) | ||
86 | ); | ||
87 | |||
88 | DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req, | ||
89 | TP_PROTO(struct usb_ctrlrequest *ctrl), | ||
90 | TP_ARGS(ctrl) | ||
91 | ); | ||
92 | |||
93 | DECLARE_EVENT_CLASS(dwc3_log_request, | ||
94 | TP_PROTO(struct dwc3_request *req), | ||
95 | TP_ARGS(req), | ||
96 | TP_STRUCT__entry( | ||
97 | __field(struct dwc3_request *, req) | ||
98 | ), | ||
99 | TP_fast_assign( | ||
100 | __entry->req = req; | ||
101 | ), | ||
102 | TP_printk("%s: req %p length %u/%u ==> %d", | ||
103 | __entry->req->dep->name, __entry->req, | ||
104 | __entry->req->request.actual, __entry->req->request.length, | ||
105 | __entry->req->request.status | ||
106 | ) | ||
107 | ); | ||
108 | |||
109 | DEFINE_EVENT(dwc3_log_request, dwc3_alloc_request, | ||
110 | TP_PROTO(struct dwc3_request *req), | ||
111 | TP_ARGS(req) | ||
112 | ); | ||
113 | |||
114 | DEFINE_EVENT(dwc3_log_request, dwc3_free_request, | ||
115 | TP_PROTO(struct dwc3_request *req), | ||
116 | TP_ARGS(req) | ||
117 | ); | ||
118 | |||
119 | DEFINE_EVENT(dwc3_log_request, dwc3_ep_queue, | ||
120 | TP_PROTO(struct dwc3_request *req), | ||
121 | TP_ARGS(req) | ||
122 | ); | ||
123 | |||
124 | DEFINE_EVENT(dwc3_log_request, dwc3_ep_dequeue, | ||
125 | TP_PROTO(struct dwc3_request *req), | ||
126 | TP_ARGS(req) | ||
127 | ); | ||
128 | |||
129 | DEFINE_EVENT(dwc3_log_request, dwc3_gadget_giveback, | ||
130 | TP_PROTO(struct dwc3_request *req), | ||
131 | TP_ARGS(req) | ||
132 | ); | ||
133 | |||
134 | DECLARE_EVENT_CLASS(dwc3_log_generic_cmd, | ||
135 | TP_PROTO(unsigned int cmd, u32 param), | ||
136 | TP_ARGS(cmd, param), | ||
137 | TP_STRUCT__entry( | ||
138 | __field(unsigned int, cmd) | ||
139 | __field(u32, param) | ||
140 | ), | ||
141 | TP_fast_assign( | ||
142 | __entry->cmd = cmd; | ||
143 | __entry->param = param; | ||
144 | ), | ||
145 | TP_printk("cmd '%s' [%d] param %08x\n", | ||
146 | dwc3_gadget_generic_cmd_string(__entry->cmd), | ||
147 | __entry->cmd, __entry->param | ||
148 | ) | ||
149 | ); | ||
150 | |||
151 | DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd, | ||
152 | TP_PROTO(unsigned int cmd, u32 param), | ||
153 | TP_ARGS(cmd, param) | ||
154 | ); | ||
155 | |||
156 | DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd, | ||
157 | TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, | ||
158 | struct dwc3_gadget_ep_cmd_params *params), | ||
159 | TP_ARGS(dep, cmd, params), | ||
160 | TP_STRUCT__entry( | ||
161 | __field(struct dwc3_ep *, dep) | ||
162 | __field(unsigned int, cmd) | ||
163 | __field(struct dwc3_gadget_ep_cmd_params *, params) | ||
164 | ), | ||
165 | TP_fast_assign( | ||
166 | __entry->dep = dep; | ||
167 | __entry->cmd = cmd; | ||
168 | __entry->params = params; | ||
169 | ), | ||
170 | TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x\n", | ||
171 | __entry->dep->name, dwc3_gadget_ep_cmd_string(__entry->cmd), | ||
172 | __entry->cmd, __entry->params->param0, | ||
173 | __entry->params->param1, __entry->params->param2 | ||
174 | ) | ||
175 | ); | ||
176 | |||
177 | DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd, | ||
178 | TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, | ||
179 | struct dwc3_gadget_ep_cmd_params *params), | ||
180 | TP_ARGS(dep, cmd, params) | ||
181 | ); | ||
182 | |||
183 | DECLARE_EVENT_CLASS(dwc3_log_trb, | ||
184 | TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), | ||
185 | TP_ARGS(dep, trb), | ||
186 | TP_STRUCT__entry( | ||
187 | __field(struct dwc3_ep *, dep) | ||
188 | __field(struct dwc3_trb *, trb) | ||
189 | ), | ||
190 | TP_fast_assign( | ||
191 | __entry->dep = dep; | ||
192 | __entry->trb = trb; | ||
193 | ), | ||
194 | TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x\n", | ||
195 | __entry->dep->name, __entry->trb, __entry->trb->bph, | ||
196 | __entry->trb->bpl, __entry->trb->size, __entry->trb->ctrl | ||
197 | ) | ||
198 | ); | ||
199 | |||
200 | DEFINE_EVENT(dwc3_log_trb, dwc3_prepare_trb, | ||
201 | TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), | ||
202 | TP_ARGS(dep, trb) | ||
203 | ); | ||
204 | |||
205 | DEFINE_EVENT(dwc3_log_trb, dwc3_complete_trb, | ||
206 | TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), | ||
207 | TP_ARGS(dep, trb) | ||
208 | ); | ||
209 | |||
210 | #endif /* __DWC3_TRACE_H */ | ||
211 | |||
212 | /* this part has to be here */ | ||
213 | |||
214 | #undef TRACE_INCLUDE_PATH | ||
215 | #define TRACE_INCLUDE_PATH . | ||
216 | |||
217 | #undef TRACE_INCLUDE_FILE | ||
218 | #define TRACE_INCLUDE_FILE trace | ||
219 | |||
220 | #include <trace/define_trace.h> | ||
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 5c822afb6d70..c4880fc0d86e 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -181,6 +181,15 @@ config USB_F_MASS_STORAGE | |||
181 | config USB_F_FS | 181 | config USB_F_FS |
182 | tristate | 182 | tristate |
183 | 183 | ||
184 | config USB_F_UAC1 | ||
185 | tristate | ||
186 | |||
187 | config USB_F_UAC2 | ||
188 | tristate | ||
189 | |||
190 | config USB_F_UVC | ||
191 | tristate | ||
192 | |||
184 | choice | 193 | choice |
185 | tristate "USB Gadget Drivers" | 194 | tristate "USB Gadget Drivers" |
186 | default USB_ETH | 195 | default USB_ETH |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 9add915d41f7..598a67d6ba05 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -3,7 +3,7 @@ | |||
3 | # | 3 | # |
4 | subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG | 4 | subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG |
5 | subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG | 5 | subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG |
6 | ccflags-y += -Idrivers/usb/gadget/udc | 6 | ccflags-y += -I$(srctree)/drivers/usb/gadget/udc |
7 | 7 | ||
8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o | 8 | obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o |
9 | libcomposite-y := usbstring.o config.o epautoconf.o | 9 | libcomposite-y := usbstring.o config.o epautoconf.o |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 6935a822ce2b..a8c18df171c3 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -1956,7 +1956,6 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) | |||
1956 | } | 1956 | } |
1957 | if (cdev->req) { | 1957 | if (cdev->req) { |
1958 | kfree(cdev->req->buf); | 1958 | kfree(cdev->req->buf); |
1959 | usb_ep_dequeue(cdev->gadget->ep0, cdev->req); | ||
1960 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); | 1959 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); |
1961 | } | 1960 | } |
1962 | cdev->next_string_id = 0; | 1961 | cdev->next_string_id = 0; |
@@ -2073,6 +2072,7 @@ static const struct usb_gadget_driver composite_driver_template = { | |||
2073 | .unbind = composite_unbind, | 2072 | .unbind = composite_unbind, |
2074 | 2073 | ||
2075 | .setup = composite_setup, | 2074 | .setup = composite_setup, |
2075 | .reset = composite_disconnect, | ||
2076 | .disconnect = composite_disconnect, | 2076 | .disconnect = composite_disconnect, |
2077 | 2077 | ||
2078 | .suspend = composite_suspend, | 2078 | .suspend = composite_suspend, |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 811c2c7cc269..34034333f7f6 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -1450,6 +1450,7 @@ static const struct usb_gadget_driver configfs_driver_template = { | |||
1450 | .unbind = configfs_composite_unbind, | 1450 | .unbind = configfs_composite_unbind, |
1451 | 1451 | ||
1452 | .setup = composite_setup, | 1452 | .setup = composite_setup, |
1453 | .reset = composite_disconnect, | ||
1453 | .disconnect = composite_disconnect, | 1454 | .disconnect = composite_disconnect, |
1454 | 1455 | ||
1455 | .max_speed = USB_SPEED_SUPER, | 1456 | .max_speed = USB_SPEED_SUPER, |
diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile index 83ae1065149d..90701aa5a826 100644 --- a/drivers/usb/gadget/function/Makefile +++ b/drivers/usb/gadget/function/Makefile | |||
@@ -2,8 +2,8 @@ | |||
2 | # USB peripheral controller drivers | 2 | # USB peripheral controller drivers |
3 | # | 3 | # |
4 | 4 | ||
5 | ccflags-y := -Idrivers/usb/gadget/ | 5 | ccflags-y := -I$(srctree)/drivers/usb/gadget/ |
6 | ccflags-y += -Idrivers/usb/gadget/udc/ | 6 | ccflags-y += -I$(srctree)/drivers/usb/gadget/udc/ |
7 | 7 | ||
8 | # USB Functions | 8 | # USB Functions |
9 | usb_f_acm-y := f_acm.o | 9 | usb_f_acm-y := f_acm.o |
@@ -32,3 +32,9 @@ usb_f_mass_storage-y := f_mass_storage.o storage_common.o | |||
32 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | 32 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o |
33 | usb_f_fs-y := f_fs.o | 33 | usb_f_fs-y := f_fs.o |
34 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | 34 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o |
35 | usb_f_uac1-y := f_uac1.o u_uac1.o | ||
36 | obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o | ||
37 | usb_f_uac2-y := f_uac2.o | ||
38 | obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o | ||
39 | usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o | ||
40 | obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o | ||
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c index ab1065afbbd0..6da4685490ef 100644 --- a/drivers/usb/gadget/function/f_acm.c +++ b/drivers/usb/gadget/function/f_acm.c | |||
@@ -313,15 +313,15 @@ static void acm_complete_set_line_coding(struct usb_ep *ep, | |||
313 | struct usb_composite_dev *cdev = acm->port.func.config->cdev; | 313 | struct usb_composite_dev *cdev = acm->port.func.config->cdev; |
314 | 314 | ||
315 | if (req->status != 0) { | 315 | if (req->status != 0) { |
316 | DBG(cdev, "acm ttyGS%d completion, err %d\n", | 316 | dev_dbg(&cdev->gadget->dev, "acm ttyGS%d completion, err %d\n", |
317 | acm->port_num, req->status); | 317 | acm->port_num, req->status); |
318 | return; | 318 | return; |
319 | } | 319 | } |
320 | 320 | ||
321 | /* normal completion */ | 321 | /* normal completion */ |
322 | if (req->actual != sizeof(acm->port_line_coding)) { | 322 | if (req->actual != sizeof(acm->port_line_coding)) { |
323 | DBG(cdev, "acm ttyGS%d short resp, len %d\n", | 323 | dev_dbg(&cdev->gadget->dev, "acm ttyGS%d short resp, len %d\n", |
324 | acm->port_num, req->actual); | 324 | acm->port_num, req->actual); |
325 | usb_ep_set_halt(ep); | 325 | usb_ep_set_halt(ep); |
326 | } else { | 326 | } else { |
327 | struct usb_cdc_line_coding *value = req->buf; | 327 | struct usb_cdc_line_coding *value = req->buf; |
@@ -397,14 +397,16 @@ static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
397 | 397 | ||
398 | default: | 398 | default: |
399 | invalid: | 399 | invalid: |
400 | VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", | 400 | dev_vdbg(&cdev->gadget->dev, |
401 | ctrl->bRequestType, ctrl->bRequest, | 401 | "invalid control req%02x.%02x v%04x i%04x l%d\n", |
402 | w_value, w_index, w_length); | 402 | ctrl->bRequestType, ctrl->bRequest, |
403 | w_value, w_index, w_length); | ||
403 | } | 404 | } |
404 | 405 | ||
405 | /* respond with data transfer or status phase? */ | 406 | /* respond with data transfer or status phase? */ |
406 | if (value >= 0) { | 407 | if (value >= 0) { |
407 | DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n", | 408 | dev_dbg(&cdev->gadget->dev, |
409 | "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n", | ||
408 | acm->port_num, ctrl->bRequestType, ctrl->bRequest, | 410 | acm->port_num, ctrl->bRequestType, ctrl->bRequest, |
409 | w_value, w_index, w_length); | 411 | w_value, w_index, w_length); |
410 | req->zero = 0; | 412 | req->zero = 0; |
@@ -428,10 +430,12 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
428 | 430 | ||
429 | if (intf == acm->ctrl_id) { | 431 | if (intf == acm->ctrl_id) { |
430 | if (acm->notify->driver_data) { | 432 | if (acm->notify->driver_data) { |
431 | VDBG(cdev, "reset acm control interface %d\n", intf); | 433 | dev_vdbg(&cdev->gadget->dev, |
434 | "reset acm control interface %d\n", intf); | ||
432 | usb_ep_disable(acm->notify); | 435 | usb_ep_disable(acm->notify); |
433 | } else { | 436 | } else { |
434 | VDBG(cdev, "init acm ctrl interface %d\n", intf); | 437 | dev_vdbg(&cdev->gadget->dev, |
438 | "init acm ctrl interface %d\n", intf); | ||
435 | if (config_ep_by_speed(cdev->gadget, f, acm->notify)) | 439 | if (config_ep_by_speed(cdev->gadget, f, acm->notify)) |
436 | return -EINVAL; | 440 | return -EINVAL; |
437 | } | 441 | } |
@@ -440,11 +444,13 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
440 | 444 | ||
441 | } else if (intf == acm->data_id) { | 445 | } else if (intf == acm->data_id) { |
442 | if (acm->port.in->driver_data) { | 446 | if (acm->port.in->driver_data) { |
443 | DBG(cdev, "reset acm ttyGS%d\n", acm->port_num); | 447 | dev_dbg(&cdev->gadget->dev, |
448 | "reset acm ttyGS%d\n", acm->port_num); | ||
444 | gserial_disconnect(&acm->port); | 449 | gserial_disconnect(&acm->port); |
445 | } | 450 | } |
446 | if (!acm->port.in->desc || !acm->port.out->desc) { | 451 | if (!acm->port.in->desc || !acm->port.out->desc) { |
447 | DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); | 452 | dev_dbg(&cdev->gadget->dev, |
453 | "activate acm ttyGS%d\n", acm->port_num); | ||
448 | if (config_ep_by_speed(cdev->gadget, f, | 454 | if (config_ep_by_speed(cdev->gadget, f, |
449 | acm->port.in) || | 455 | acm->port.in) || |
450 | config_ep_by_speed(cdev->gadget, f, | 456 | config_ep_by_speed(cdev->gadget, f, |
@@ -467,7 +473,7 @@ static void acm_disable(struct usb_function *f) | |||
467 | struct f_acm *acm = func_to_acm(f); | 473 | struct f_acm *acm = func_to_acm(f); |
468 | struct usb_composite_dev *cdev = f->config->cdev; | 474 | struct usb_composite_dev *cdev = f->config->cdev; |
469 | 475 | ||
470 | DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num); | 476 | dev_dbg(&cdev->gadget->dev, "acm ttyGS%d deactivated\n", acm->port_num); |
471 | gserial_disconnect(&acm->port); | 477 | gserial_disconnect(&acm->port); |
472 | usb_ep_disable(acm->notify); | 478 | usb_ep_disable(acm->notify); |
473 | acm->notify->driver_data = NULL; | 479 | acm->notify->driver_data = NULL; |
@@ -537,8 +543,8 @@ static int acm_notify_serial_state(struct f_acm *acm) | |||
537 | 543 | ||
538 | spin_lock(&acm->lock); | 544 | spin_lock(&acm->lock); |
539 | if (acm->notify_req) { | 545 | if (acm->notify_req) { |
540 | DBG(cdev, "acm ttyGS%d serial state %04x\n", | 546 | dev_dbg(&cdev->gadget->dev, "acm ttyGS%d serial state %04x\n", |
541 | acm->port_num, acm->serial_state); | 547 | acm->port_num, acm->serial_state); |
542 | status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE, | 548 | status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE, |
543 | 0, &acm->serial_state, sizeof(acm->serial_state)); | 549 | 0, &acm->serial_state, sizeof(acm->serial_state)); |
544 | } else { | 550 | } else { |
@@ -691,12 +697,13 @@ acm_bind(struct usb_configuration *c, struct usb_function *f) | |||
691 | if (status) | 697 | if (status) |
692 | goto fail; | 698 | goto fail; |
693 | 699 | ||
694 | DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", | 700 | dev_dbg(&cdev->gadget->dev, |
695 | acm->port_num, | 701 | "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", |
696 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | 702 | acm->port_num, |
697 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 703 | gadget_is_superspeed(c->cdev->gadget) ? "super" : |
698 | acm->port.in->name, acm->port.out->name, | 704 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
699 | acm->notify->name); | 705 | acm->port.in->name, acm->port.out->name, |
706 | acm->notify->name); | ||
700 | return 0; | 707 | return 0; |
701 | 708 | ||
702 | fail: | 709 | fail: |
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 0dc3552d1360..4ad11e03cf54 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c | |||
@@ -1032,6 +1032,29 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code, | |||
1032 | case FUNCTIONFS_ENDPOINT_REVMAP: | 1032 | case FUNCTIONFS_ENDPOINT_REVMAP: |
1033 | ret = epfile->ep->num; | 1033 | ret = epfile->ep->num; |
1034 | break; | 1034 | break; |
1035 | case FUNCTIONFS_ENDPOINT_DESC: | ||
1036 | { | ||
1037 | int desc_idx; | ||
1038 | struct usb_endpoint_descriptor *desc; | ||
1039 | |||
1040 | switch (epfile->ffs->gadget->speed) { | ||
1041 | case USB_SPEED_SUPER: | ||
1042 | desc_idx = 2; | ||
1043 | break; | ||
1044 | case USB_SPEED_HIGH: | ||
1045 | desc_idx = 1; | ||
1046 | break; | ||
1047 | default: | ||
1048 | desc_idx = 0; | ||
1049 | } | ||
1050 | desc = epfile->ep->descs[desc_idx]; | ||
1051 | |||
1052 | spin_unlock_irq(&epfile->ffs->eps_lock); | ||
1053 | ret = copy_to_user((void *)value, desc, sizeof(*desc)); | ||
1054 | if (ret) | ||
1055 | ret = -EFAULT; | ||
1056 | return ret; | ||
1057 | } | ||
1035 | default: | 1058 | default: |
1036 | ret = -ENOTTY; | 1059 | ret = -ENOTTY; |
1037 | } | 1060 | } |
@@ -1534,7 +1557,10 @@ static int ffs_epfiles_create(struct ffs_data *ffs) | |||
1534 | epfile->ffs = ffs; | 1557 | epfile->ffs = ffs; |
1535 | mutex_init(&epfile->mutex); | 1558 | mutex_init(&epfile->mutex); |
1536 | init_waitqueue_head(&epfile->wait); | 1559 | init_waitqueue_head(&epfile->wait); |
1537 | sprintf(epfiles->name, "ep%u", i); | 1560 | if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) |
1561 | sprintf(epfiles->name, "ep%02x", ffs->eps_addrmap[i]); | ||
1562 | else | ||
1563 | sprintf(epfiles->name, "ep%u", i); | ||
1538 | if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile, | 1564 | if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile, |
1539 | &ffs_epfile_operations, | 1565 | &ffs_epfile_operations, |
1540 | &epfile->dentry))) { | 1566 | &epfile->dentry))) { |
@@ -2083,10 +2109,12 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, | |||
2083 | break; | 2109 | break; |
2084 | case FUNCTIONFS_DESCRIPTORS_MAGIC_V2: | 2110 | case FUNCTIONFS_DESCRIPTORS_MAGIC_V2: |
2085 | flags = get_unaligned_le32(data + 8); | 2111 | flags = get_unaligned_le32(data + 8); |
2112 | ffs->user_flags = flags; | ||
2086 | if (flags & ~(FUNCTIONFS_HAS_FS_DESC | | 2113 | if (flags & ~(FUNCTIONFS_HAS_FS_DESC | |
2087 | FUNCTIONFS_HAS_HS_DESC | | 2114 | FUNCTIONFS_HAS_HS_DESC | |
2088 | FUNCTIONFS_HAS_SS_DESC | | 2115 | FUNCTIONFS_HAS_SS_DESC | |
2089 | FUNCTIONFS_HAS_MS_OS_DESC)) { | 2116 | FUNCTIONFS_HAS_MS_OS_DESC | |
2117 | FUNCTIONFS_VIRTUAL_ADDR)) { | ||
2090 | ret = -ENOSYS; | 2118 | ret = -ENOSYS; |
2091 | goto error; | 2119 | goto error; |
2092 | } | 2120 | } |
@@ -2346,7 +2374,8 @@ static void __ffs_event_add(struct ffs_data *ffs, | |||
2346 | break; | 2374 | break; |
2347 | 2375 | ||
2348 | default: | 2376 | default: |
2349 | BUG(); | 2377 | WARN(1, "%d: unknown event, this should not happen\n", type); |
2378 | return; | ||
2350 | } | 2379 | } |
2351 | 2380 | ||
2352 | { | 2381 | { |
@@ -2393,7 +2422,8 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2393 | struct usb_endpoint_descriptor *ds = (void *)desc; | 2422 | struct usb_endpoint_descriptor *ds = (void *)desc; |
2394 | struct ffs_function *func = priv; | 2423 | struct ffs_function *func = priv; |
2395 | struct ffs_ep *ffs_ep; | 2424 | struct ffs_ep *ffs_ep; |
2396 | unsigned ep_desc_id, idx; | 2425 | unsigned ep_desc_id; |
2426 | int idx; | ||
2397 | static const char *speed_names[] = { "full", "high", "super" }; | 2427 | static const char *speed_names[] = { "full", "high", "super" }; |
2398 | 2428 | ||
2399 | if (type != FFS_DESCRIPTOR) | 2429 | if (type != FFS_DESCRIPTOR) |
@@ -2441,7 +2471,13 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2441 | } else { | 2471 | } else { |
2442 | struct usb_request *req; | 2472 | struct usb_request *req; |
2443 | struct usb_ep *ep; | 2473 | struct usb_ep *ep; |
2474 | u8 bEndpointAddress; | ||
2444 | 2475 | ||
2476 | /* | ||
2477 | * We back up bEndpointAddress because autoconfig overwrites | ||
2478 | * it with physical endpoint address. | ||
2479 | */ | ||
2480 | bEndpointAddress = ds->bEndpointAddress; | ||
2445 | pr_vdebug("autoconfig\n"); | 2481 | pr_vdebug("autoconfig\n"); |
2446 | ep = usb_ep_autoconfig(func->gadget, ds); | 2482 | ep = usb_ep_autoconfig(func->gadget, ds); |
2447 | if (unlikely(!ep)) | 2483 | if (unlikely(!ep)) |
@@ -2456,6 +2492,12 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, | |||
2456 | ffs_ep->req = req; | 2492 | ffs_ep->req = req; |
2457 | func->eps_revmap[ds->bEndpointAddress & | 2493 | func->eps_revmap[ds->bEndpointAddress & |
2458 | USB_ENDPOINT_NUMBER_MASK] = idx + 1; | 2494 | USB_ENDPOINT_NUMBER_MASK] = idx + 1; |
2495 | /* | ||
2496 | * If we use virtual address mapping, we restore | ||
2497 | * original bEndpointAddress value. | ||
2498 | */ | ||
2499 | if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) | ||
2500 | ds->bEndpointAddress = bEndpointAddress; | ||
2459 | } | 2501 | } |
2460 | ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); | 2502 | ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); |
2461 | 2503 | ||
@@ -2900,6 +2942,8 @@ static int ffs_func_setup(struct usb_function *f, | |||
2900 | ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); | 2942 | ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); |
2901 | if (unlikely(ret < 0)) | 2943 | if (unlikely(ret < 0)) |
2902 | return ret; | 2944 | return ret; |
2945 | if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) | ||
2946 | ret = func->ffs->eps_addrmap[ret]; | ||
2903 | break; | 2947 | break; |
2904 | 2948 | ||
2905 | default: | 2949 | default: |
diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c index 4557cd03f0b1..bf04389137e6 100644 --- a/drivers/usb/gadget/function/f_loopback.c +++ b/drivers/usb/gadget/function/f_loopback.c | |||
@@ -298,7 +298,8 @@ static void disable_loopback(struct f_loopback *loop) | |||
298 | struct usb_composite_dev *cdev; | 298 | struct usb_composite_dev *cdev; |
299 | 299 | ||
300 | cdev = loop->function.config->cdev; | 300 | cdev = loop->function.config->cdev; |
301 | disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL); | 301 | disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL, NULL, |
302 | NULL); | ||
302 | VDBG(cdev, "%s disabled\n", loop->function.name); | 303 | VDBG(cdev, "%s disabled\n", loop->function.name); |
303 | } | 304 | } |
304 | 305 | ||
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index b96393908860..811929cd4c9e 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c | |||
@@ -566,22 +566,22 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep, | |||
566 | *pbusy = 1; | 566 | *pbusy = 1; |
567 | *state = BUF_STATE_BUSY; | 567 | *state = BUF_STATE_BUSY; |
568 | spin_unlock_irq(&fsg->common->lock); | 568 | spin_unlock_irq(&fsg->common->lock); |
569 | |||
569 | rc = usb_ep_queue(ep, req, GFP_KERNEL); | 570 | rc = usb_ep_queue(ep, req, GFP_KERNEL); |
570 | if (rc != 0) { | 571 | if (rc == 0) |
571 | *pbusy = 0; | 572 | return; /* All good, we're done */ |
572 | *state = BUF_STATE_EMPTY; | ||
573 | 573 | ||
574 | /* We can't do much more than wait for a reset */ | 574 | *pbusy = 0; |
575 | *state = BUF_STATE_EMPTY; | ||
575 | 576 | ||
576 | /* | 577 | /* We can't do much more than wait for a reset */ |
577 | * Note: currently the net2280 driver fails zero-length | 578 | |
578 | * submissions if DMA is enabled. | 579 | /* |
579 | */ | 580 | * Note: currently the net2280 driver fails zero-length |
580 | if (rc != -ESHUTDOWN && | 581 | * submissions if DMA is enabled. |
581 | !(rc == -EOPNOTSUPP && req->length == 0)) | 582 | */ |
582 | WARNING(fsg, "error in submission: %s --> %d\n", | 583 | if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP && req->length == 0)) |
583 | ep->name, rc); | 584 | WARNING(fsg, "error in submission: %s --> %d\n", ep->name, rc); |
584 | } | ||
585 | } | 585 | } |
586 | 586 | ||
587 | static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh) | 587 | static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh) |
@@ -3665,4 +3665,3 @@ void fsg_config_from_params(struct fsg_config *cfg, | |||
3665 | cfg->fsg_num_buffers = fsg_num_buffers; | 3665 | cfg->fsg_num_buffers = fsg_num_buffers; |
3666 | } | 3666 | } |
3667 | EXPORT_SYMBOL_GPL(fsg_config_from_params); | 3667 | EXPORT_SYMBOL_GPL(fsg_config_from_params); |
3668 | |||
diff --git a/drivers/usb/gadget/function/f_obex.c b/drivers/usb/gadget/function/f_obex.c index aebae1853bce..5f40080c92cc 100644 --- a/drivers/usb/gadget/function/f_obex.c +++ b/drivers/usb/gadget/function/f_obex.c | |||
@@ -200,19 +200,22 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
200 | if (alt != 0) | 200 | if (alt != 0) |
201 | goto fail; | 201 | goto fail; |
202 | /* NOP */ | 202 | /* NOP */ |
203 | DBG(cdev, "reset obex ttyGS%d control\n", obex->port_num); | 203 | dev_dbg(&cdev->gadget->dev, |
204 | "reset obex ttyGS%d control\n", obex->port_num); | ||
204 | 205 | ||
205 | } else if (intf == obex->data_id) { | 206 | } else if (intf == obex->data_id) { |
206 | if (alt > 1) | 207 | if (alt > 1) |
207 | goto fail; | 208 | goto fail; |
208 | 209 | ||
209 | if (obex->port.in->driver_data) { | 210 | if (obex->port.in->driver_data) { |
210 | DBG(cdev, "reset obex ttyGS%d\n", obex->port_num); | 211 | dev_dbg(&cdev->gadget->dev, |
212 | "reset obex ttyGS%d\n", obex->port_num); | ||
211 | gserial_disconnect(&obex->port); | 213 | gserial_disconnect(&obex->port); |
212 | } | 214 | } |
213 | 215 | ||
214 | if (!obex->port.in->desc || !obex->port.out->desc) { | 216 | if (!obex->port.in->desc || !obex->port.out->desc) { |
215 | DBG(cdev, "init obex ttyGS%d\n", obex->port_num); | 217 | dev_dbg(&cdev->gadget->dev, |
218 | "init obex ttyGS%d\n", obex->port_num); | ||
216 | if (config_ep_by_speed(cdev->gadget, f, | 219 | if (config_ep_by_speed(cdev->gadget, f, |
217 | obex->port.in) || | 220 | obex->port.in) || |
218 | config_ep_by_speed(cdev->gadget, f, | 221 | config_ep_by_speed(cdev->gadget, f, |
@@ -224,7 +227,8 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
224 | } | 227 | } |
225 | 228 | ||
226 | if (alt == 1) { | 229 | if (alt == 1) { |
227 | DBG(cdev, "activate obex ttyGS%d\n", obex->port_num); | 230 | dev_dbg(&cdev->gadget->dev, |
231 | "activate obex ttyGS%d\n", obex->port_num); | ||
228 | gserial_connect(&obex->port, obex->port_num); | 232 | gserial_connect(&obex->port, obex->port_num); |
229 | } | 233 | } |
230 | 234 | ||
@@ -252,7 +256,7 @@ static void obex_disable(struct usb_function *f) | |||
252 | struct f_obex *obex = func_to_obex(f); | 256 | struct f_obex *obex = func_to_obex(f); |
253 | struct usb_composite_dev *cdev = f->config->cdev; | 257 | struct usb_composite_dev *cdev = f->config->cdev; |
254 | 258 | ||
255 | DBG(cdev, "obex ttyGS%d disable\n", obex->port_num); | 259 | dev_dbg(&cdev->gadget->dev, "obex ttyGS%d disable\n", obex->port_num); |
256 | gserial_disconnect(&obex->port); | 260 | gserial_disconnect(&obex->port); |
257 | } | 261 | } |
258 | 262 | ||
@@ -269,7 +273,8 @@ static void obex_connect(struct gserial *g) | |||
269 | 273 | ||
270 | status = usb_function_activate(&g->func); | 274 | status = usb_function_activate(&g->func); |
271 | if (status) | 275 | if (status) |
272 | DBG(cdev, "obex ttyGS%d function activate --> %d\n", | 276 | dev_dbg(&cdev->gadget->dev, |
277 | "obex ttyGS%d function activate --> %d\n", | ||
273 | obex->port_num, status); | 278 | obex->port_num, status); |
274 | } | 279 | } |
275 | 280 | ||
@@ -284,7 +289,8 @@ static void obex_disconnect(struct gserial *g) | |||
284 | 289 | ||
285 | status = usb_function_deactivate(&g->func); | 290 | status = usb_function_deactivate(&g->func); |
286 | if (status) | 291 | if (status) |
287 | DBG(cdev, "obex ttyGS%d function deactivate --> %d\n", | 292 | dev_dbg(&cdev->gadget->dev, |
293 | "obex ttyGS%d function deactivate --> %d\n", | ||
288 | obex->port_num, status); | 294 | obex->port_num, status); |
289 | } | 295 | } |
290 | 296 | ||
@@ -383,10 +389,10 @@ static int obex_bind(struct usb_configuration *c, struct usb_function *f) | |||
383 | obex->can_activate = true; | 389 | obex->can_activate = true; |
384 | 390 | ||
385 | 391 | ||
386 | DBG(cdev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", | 392 | dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", |
387 | obex->port_num, | 393 | obex->port_num, |
388 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 394 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
389 | obex->port.in->name, obex->port.out->name); | 395 | obex->port.in->name, obex->port.out->name); |
390 | 396 | ||
391 | return 0; | 397 | return 0; |
392 | 398 | ||
diff --git a/drivers/usb/gadget/function/f_serial.c b/drivers/usb/gadget/function/f_serial.c index 9ecbcbf36a45..2e02dfabc7ae 100644 --- a/drivers/usb/gadget/function/f_serial.c +++ b/drivers/usb/gadget/function/f_serial.c | |||
@@ -155,11 +155,13 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
155 | /* we know alt == 0, so this is an activation or a reset */ | 155 | /* we know alt == 0, so this is an activation or a reset */ |
156 | 156 | ||
157 | if (gser->port.in->driver_data) { | 157 | if (gser->port.in->driver_data) { |
158 | DBG(cdev, "reset generic ttyGS%d\n", gser->port_num); | 158 | dev_dbg(&cdev->gadget->dev, |
159 | "reset generic ttyGS%d\n", gser->port_num); | ||
159 | gserial_disconnect(&gser->port); | 160 | gserial_disconnect(&gser->port); |
160 | } | 161 | } |
161 | if (!gser->port.in->desc || !gser->port.out->desc) { | 162 | if (!gser->port.in->desc || !gser->port.out->desc) { |
162 | DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); | 163 | dev_dbg(&cdev->gadget->dev, |
164 | "activate generic ttyGS%d\n", gser->port_num); | ||
163 | if (config_ep_by_speed(cdev->gadget, f, gser->port.in) || | 165 | if (config_ep_by_speed(cdev->gadget, f, gser->port.in) || |
164 | config_ep_by_speed(cdev->gadget, f, gser->port.out)) { | 166 | config_ep_by_speed(cdev->gadget, f, gser->port.out)) { |
165 | gser->port.in->desc = NULL; | 167 | gser->port.in->desc = NULL; |
@@ -176,7 +178,8 @@ static void gser_disable(struct usb_function *f) | |||
176 | struct f_gser *gser = func_to_gser(f); | 178 | struct f_gser *gser = func_to_gser(f); |
177 | struct usb_composite_dev *cdev = f->config->cdev; | 179 | struct usb_composite_dev *cdev = f->config->cdev; |
178 | 180 | ||
179 | DBG(cdev, "generic ttyGS%d deactivated\n", gser->port_num); | 181 | dev_dbg(&cdev->gadget->dev, |
182 | "generic ttyGS%d deactivated\n", gser->port_num); | ||
180 | gserial_disconnect(&gser->port); | 183 | gserial_disconnect(&gser->port); |
181 | } | 184 | } |
182 | 185 | ||
@@ -239,11 +242,11 @@ static int gser_bind(struct usb_configuration *c, struct usb_function *f) | |||
239 | gser_ss_function); | 242 | gser_ss_function); |
240 | if (status) | 243 | if (status) |
241 | goto fail; | 244 | goto fail; |
242 | DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", | 245 | dev_dbg(&cdev->gadget->dev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", |
243 | gser->port_num, | 246 | gser->port_num, |
244 | gadget_is_superspeed(c->cdev->gadget) ? "super" : | 247 | gadget_is_superspeed(c->cdev->gadget) ? "super" : |
245 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", | 248 | gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", |
246 | gser->port.in->name, gser->port.out->name); | 249 | gser->port.in->name, gser->port.out->name); |
247 | return 0; | 250 | return 0; |
248 | 251 | ||
249 | fail: | 252 | fail: |
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c index d3cd52db78fe..80be25b32cd7 100644 --- a/drivers/usb/gadget/function/f_sourcesink.c +++ b/drivers/usb/gadget/function/f_sourcesink.c | |||
@@ -23,6 +23,15 @@ | |||
23 | #include "gadget_chips.h" | 23 | #include "gadget_chips.h" |
24 | #include "u_f.h" | 24 | #include "u_f.h" |
25 | 25 | ||
26 | #define USB_MS_TO_SS_INTERVAL(x) USB_MS_TO_HS_INTERVAL(x) | ||
27 | |||
28 | enum eptype { | ||
29 | EP_CONTROL = 0, | ||
30 | EP_BULK, | ||
31 | EP_ISOC, | ||
32 | EP_INTERRUPT, | ||
33 | }; | ||
34 | |||
26 | /* | 35 | /* |
27 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral | 36 | * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral |
28 | * controller drivers. | 37 | * controller drivers. |
@@ -55,6 +64,8 @@ struct f_sourcesink { | |||
55 | struct usb_ep *out_ep; | 64 | struct usb_ep *out_ep; |
56 | struct usb_ep *iso_in_ep; | 65 | struct usb_ep *iso_in_ep; |
57 | struct usb_ep *iso_out_ep; | 66 | struct usb_ep *iso_out_ep; |
67 | struct usb_ep *int_in_ep; | ||
68 | struct usb_ep *int_out_ep; | ||
58 | int cur_alt; | 69 | int cur_alt; |
59 | }; | 70 | }; |
60 | 71 | ||
@@ -68,6 +79,10 @@ static unsigned isoc_interval; | |||
68 | static unsigned isoc_maxpacket; | 79 | static unsigned isoc_maxpacket; |
69 | static unsigned isoc_mult; | 80 | static unsigned isoc_mult; |
70 | static unsigned isoc_maxburst; | 81 | static unsigned isoc_maxburst; |
82 | static unsigned int_interval; /* In ms */ | ||
83 | static unsigned int_maxpacket; | ||
84 | static unsigned int_mult; | ||
85 | static unsigned int_maxburst; | ||
71 | static unsigned buflen; | 86 | static unsigned buflen; |
72 | 87 | ||
73 | /*-------------------------------------------------------------------------*/ | 88 | /*-------------------------------------------------------------------------*/ |
@@ -92,6 +107,16 @@ static struct usb_interface_descriptor source_sink_intf_alt1 = { | |||
92 | /* .iInterface = DYNAMIC */ | 107 | /* .iInterface = DYNAMIC */ |
93 | }; | 108 | }; |
94 | 109 | ||
110 | static struct usb_interface_descriptor source_sink_intf_alt2 = { | ||
111 | .bLength = USB_DT_INTERFACE_SIZE, | ||
112 | .bDescriptorType = USB_DT_INTERFACE, | ||
113 | |||
114 | .bAlternateSetting = 2, | ||
115 | .bNumEndpoints = 2, | ||
116 | .bInterfaceClass = USB_CLASS_VENDOR_SPEC, | ||
117 | /* .iInterface = DYNAMIC */ | ||
118 | }; | ||
119 | |||
95 | /* full speed support: */ | 120 | /* full speed support: */ |
96 | 121 | ||
97 | static struct usb_endpoint_descriptor fs_source_desc = { | 122 | static struct usb_endpoint_descriptor fs_source_desc = { |
@@ -130,6 +155,26 @@ static struct usb_endpoint_descriptor fs_iso_sink_desc = { | |||
130 | .bInterval = 4, | 155 | .bInterval = 4, |
131 | }; | 156 | }; |
132 | 157 | ||
158 | static struct usb_endpoint_descriptor fs_int_source_desc = { | ||
159 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
160 | .bDescriptorType = USB_DT_ENDPOINT, | ||
161 | |||
162 | .bEndpointAddress = USB_DIR_IN, | ||
163 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
164 | .wMaxPacketSize = cpu_to_le16(64), | ||
165 | .bInterval = GZERO_INT_INTERVAL, | ||
166 | }; | ||
167 | |||
168 | static struct usb_endpoint_descriptor fs_int_sink_desc = { | ||
169 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
170 | .bDescriptorType = USB_DT_ENDPOINT, | ||
171 | |||
172 | .bEndpointAddress = USB_DIR_OUT, | ||
173 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
174 | .wMaxPacketSize = cpu_to_le16(64), | ||
175 | .bInterval = GZERO_INT_INTERVAL, | ||
176 | }; | ||
177 | |||
133 | static struct usb_descriptor_header *fs_source_sink_descs[] = { | 178 | static struct usb_descriptor_header *fs_source_sink_descs[] = { |
134 | (struct usb_descriptor_header *) &source_sink_intf_alt0, | 179 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
135 | (struct usb_descriptor_header *) &fs_sink_desc, | 180 | (struct usb_descriptor_header *) &fs_sink_desc, |
@@ -140,6 +185,10 @@ static struct usb_descriptor_header *fs_source_sink_descs[] = { | |||
140 | (struct usb_descriptor_header *) &fs_source_desc, | 185 | (struct usb_descriptor_header *) &fs_source_desc, |
141 | (struct usb_descriptor_header *) &fs_iso_sink_desc, | 186 | (struct usb_descriptor_header *) &fs_iso_sink_desc, |
142 | (struct usb_descriptor_header *) &fs_iso_source_desc, | 187 | (struct usb_descriptor_header *) &fs_iso_source_desc, |
188 | (struct usb_descriptor_header *) &source_sink_intf_alt2, | ||
189 | #define FS_ALT_IFC_2_OFFSET 8 | ||
190 | (struct usb_descriptor_header *) &fs_int_sink_desc, | ||
191 | (struct usb_descriptor_header *) &fs_int_source_desc, | ||
143 | NULL, | 192 | NULL, |
144 | }; | 193 | }; |
145 | 194 | ||
@@ -179,6 +228,24 @@ static struct usb_endpoint_descriptor hs_iso_sink_desc = { | |||
179 | .bInterval = 4, | 228 | .bInterval = 4, |
180 | }; | 229 | }; |
181 | 230 | ||
231 | static struct usb_endpoint_descriptor hs_int_source_desc = { | ||
232 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
233 | .bDescriptorType = USB_DT_ENDPOINT, | ||
234 | |||
235 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
236 | .wMaxPacketSize = cpu_to_le16(1024), | ||
237 | .bInterval = USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL), | ||
238 | }; | ||
239 | |||
240 | static struct usb_endpoint_descriptor hs_int_sink_desc = { | ||
241 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
242 | .bDescriptorType = USB_DT_ENDPOINT, | ||
243 | |||
244 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
245 | .wMaxPacketSize = cpu_to_le16(1024), | ||
246 | .bInterval = USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL), | ||
247 | }; | ||
248 | |||
182 | static struct usb_descriptor_header *hs_source_sink_descs[] = { | 249 | static struct usb_descriptor_header *hs_source_sink_descs[] = { |
183 | (struct usb_descriptor_header *) &source_sink_intf_alt0, | 250 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
184 | (struct usb_descriptor_header *) &hs_source_desc, | 251 | (struct usb_descriptor_header *) &hs_source_desc, |
@@ -189,6 +256,10 @@ static struct usb_descriptor_header *hs_source_sink_descs[] = { | |||
189 | (struct usb_descriptor_header *) &hs_sink_desc, | 256 | (struct usb_descriptor_header *) &hs_sink_desc, |
190 | (struct usb_descriptor_header *) &hs_iso_source_desc, | 257 | (struct usb_descriptor_header *) &hs_iso_source_desc, |
191 | (struct usb_descriptor_header *) &hs_iso_sink_desc, | 258 | (struct usb_descriptor_header *) &hs_iso_sink_desc, |
259 | (struct usb_descriptor_header *) &source_sink_intf_alt2, | ||
260 | #define HS_ALT_IFC_2_OFFSET 8 | ||
261 | (struct usb_descriptor_header *) &hs_int_source_desc, | ||
262 | (struct usb_descriptor_header *) &hs_int_sink_desc, | ||
192 | NULL, | 263 | NULL, |
193 | }; | 264 | }; |
194 | 265 | ||
@@ -264,6 +335,42 @@ static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = { | |||
264 | .wBytesPerInterval = cpu_to_le16(1024), | 335 | .wBytesPerInterval = cpu_to_le16(1024), |
265 | }; | 336 | }; |
266 | 337 | ||
338 | static struct usb_endpoint_descriptor ss_int_source_desc = { | ||
339 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
340 | .bDescriptorType = USB_DT_ENDPOINT, | ||
341 | |||
342 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
343 | .wMaxPacketSize = cpu_to_le16(1024), | ||
344 | .bInterval = USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL), | ||
345 | }; | ||
346 | |||
347 | struct usb_ss_ep_comp_descriptor ss_int_source_comp_desc = { | ||
348 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
349 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
350 | |||
351 | .bMaxBurst = 0, | ||
352 | .bmAttributes = 0, | ||
353 | .wBytesPerInterval = cpu_to_le16(1024), | ||
354 | }; | ||
355 | |||
356 | static struct usb_endpoint_descriptor ss_int_sink_desc = { | ||
357 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
358 | .bDescriptorType = USB_DT_ENDPOINT, | ||
359 | |||
360 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
361 | .wMaxPacketSize = cpu_to_le16(1024), | ||
362 | .bInterval = USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL), | ||
363 | }; | ||
364 | |||
365 | struct usb_ss_ep_comp_descriptor ss_int_sink_comp_desc = { | ||
366 | .bLength = USB_DT_SS_EP_COMP_SIZE, | ||
367 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
368 | |||
369 | .bMaxBurst = 0, | ||
370 | .bmAttributes = 0, | ||
371 | .wBytesPerInterval = cpu_to_le16(1024), | ||
372 | }; | ||
373 | |||
267 | static struct usb_descriptor_header *ss_source_sink_descs[] = { | 374 | static struct usb_descriptor_header *ss_source_sink_descs[] = { |
268 | (struct usb_descriptor_header *) &source_sink_intf_alt0, | 375 | (struct usb_descriptor_header *) &source_sink_intf_alt0, |
269 | (struct usb_descriptor_header *) &ss_source_desc, | 376 | (struct usb_descriptor_header *) &ss_source_desc, |
@@ -280,6 +387,12 @@ static struct usb_descriptor_header *ss_source_sink_descs[] = { | |||
280 | (struct usb_descriptor_header *) &ss_iso_source_comp_desc, | 387 | (struct usb_descriptor_header *) &ss_iso_source_comp_desc, |
281 | (struct usb_descriptor_header *) &ss_iso_sink_desc, | 388 | (struct usb_descriptor_header *) &ss_iso_sink_desc, |
282 | (struct usb_descriptor_header *) &ss_iso_sink_comp_desc, | 389 | (struct usb_descriptor_header *) &ss_iso_sink_comp_desc, |
390 | (struct usb_descriptor_header *) &source_sink_intf_alt2, | ||
391 | #define SS_ALT_IFC_2_OFFSET 14 | ||
392 | (struct usb_descriptor_header *) &ss_int_source_desc, | ||
393 | (struct usb_descriptor_header *) &ss_int_source_comp_desc, | ||
394 | (struct usb_descriptor_header *) &ss_int_sink_desc, | ||
395 | (struct usb_descriptor_header *) &ss_int_sink_comp_desc, | ||
283 | NULL, | 396 | NULL, |
284 | }; | 397 | }; |
285 | 398 | ||
@@ -301,6 +414,21 @@ static struct usb_gadget_strings *sourcesink_strings[] = { | |||
301 | }; | 414 | }; |
302 | 415 | ||
303 | /*-------------------------------------------------------------------------*/ | 416 | /*-------------------------------------------------------------------------*/ |
417 | static const char *get_ep_string(enum eptype ep_type) | ||
418 | { | ||
419 | switch (ep_type) { | ||
420 | case EP_ISOC: | ||
421 | return "ISOC-"; | ||
422 | case EP_INTERRUPT: | ||
423 | return "INTERRUPT-"; | ||
424 | case EP_CONTROL: | ||
425 | return "CTRL-"; | ||
426 | case EP_BULK: | ||
427 | return "BULK-"; | ||
428 | default: | ||
429 | return "UNKNOWN-"; | ||
430 | } | ||
431 | } | ||
304 | 432 | ||
305 | static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) | 433 | static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) |
306 | { | 434 | { |
@@ -328,7 +456,8 @@ static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) | |||
328 | 456 | ||
329 | void disable_endpoints(struct usb_composite_dev *cdev, | 457 | void disable_endpoints(struct usb_composite_dev *cdev, |
330 | struct usb_ep *in, struct usb_ep *out, | 458 | struct usb_ep *in, struct usb_ep *out, |
331 | struct usb_ep *iso_in, struct usb_ep *iso_out) | 459 | struct usb_ep *iso_in, struct usb_ep *iso_out, |
460 | struct usb_ep *int_in, struct usb_ep *int_out) | ||
332 | { | 461 | { |
333 | disable_ep(cdev, in); | 462 | disable_ep(cdev, in); |
334 | disable_ep(cdev, out); | 463 | disable_ep(cdev, out); |
@@ -336,6 +465,10 @@ void disable_endpoints(struct usb_composite_dev *cdev, | |||
336 | disable_ep(cdev, iso_in); | 465 | disable_ep(cdev, iso_in); |
337 | if (iso_out) | 466 | if (iso_out) |
338 | disable_ep(cdev, iso_out); | 467 | disable_ep(cdev, iso_out); |
468 | if (int_in) | ||
469 | disable_ep(cdev, int_in); | ||
470 | if (int_out) | ||
471 | disable_ep(cdev, int_out); | ||
339 | } | 472 | } |
340 | 473 | ||
341 | static int | 474 | static int |
@@ -352,6 +485,7 @@ sourcesink_bind(struct usb_configuration *c, struct usb_function *f) | |||
352 | return id; | 485 | return id; |
353 | source_sink_intf_alt0.bInterfaceNumber = id; | 486 | source_sink_intf_alt0.bInterfaceNumber = id; |
354 | source_sink_intf_alt1.bInterfaceNumber = id; | 487 | source_sink_intf_alt1.bInterfaceNumber = id; |
488 | source_sink_intf_alt2.bInterfaceNumber = id; | ||
355 | 489 | ||
356 | /* allocate bulk endpoints */ | 490 | /* allocate bulk endpoints */ |
357 | ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); | 491 | ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); |
@@ -412,14 +546,55 @@ no_iso: | |||
412 | if (isoc_maxpacket > 1024) | 546 | if (isoc_maxpacket > 1024) |
413 | isoc_maxpacket = 1024; | 547 | isoc_maxpacket = 1024; |
414 | 548 | ||
549 | /* sanity check the interrupt module parameters */ | ||
550 | if (int_interval < 1) | ||
551 | int_interval = 1; | ||
552 | if (int_interval > 4096) | ||
553 | int_interval = 4096; | ||
554 | if (int_mult > 2) | ||
555 | int_mult = 2; | ||
556 | if (int_maxburst > 15) | ||
557 | int_maxburst = 15; | ||
558 | |||
559 | /* fill in the FS interrupt descriptors from the module parameters */ | ||
560 | fs_int_source_desc.wMaxPacketSize = int_maxpacket > 64 ? | ||
561 | 64 : int_maxpacket; | ||
562 | fs_int_source_desc.bInterval = int_interval > 255 ? | ||
563 | 255 : int_interval; | ||
564 | fs_int_sink_desc.wMaxPacketSize = int_maxpacket > 64 ? | ||
565 | 64 : int_maxpacket; | ||
566 | fs_int_sink_desc.bInterval = int_interval > 255 ? | ||
567 | 255 : int_interval; | ||
568 | |||
569 | /* allocate int endpoints */ | ||
570 | ss->int_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_int_source_desc); | ||
571 | if (!ss->int_in_ep) | ||
572 | goto no_int; | ||
573 | ss->int_in_ep->driver_data = cdev; /* claim */ | ||
574 | |||
575 | ss->int_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_int_sink_desc); | ||
576 | if (ss->int_out_ep) { | ||
577 | ss->int_out_ep->driver_data = cdev; /* claim */ | ||
578 | } else { | ||
579 | ss->int_in_ep->driver_data = NULL; | ||
580 | ss->int_in_ep = NULL; | ||
581 | no_int: | ||
582 | fs_source_sink_descs[FS_ALT_IFC_2_OFFSET] = NULL; | ||
583 | hs_source_sink_descs[HS_ALT_IFC_2_OFFSET] = NULL; | ||
584 | ss_source_sink_descs[SS_ALT_IFC_2_OFFSET] = NULL; | ||
585 | } | ||
586 | |||
587 | if (int_maxpacket > 1024) | ||
588 | int_maxpacket = 1024; | ||
589 | |||
415 | /* support high speed hardware */ | 590 | /* support high speed hardware */ |
416 | hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; | 591 | hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; |
417 | hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; | 592 | hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; |
418 | 593 | ||
419 | /* | 594 | /* |
420 | * Fill in the HS isoc descriptors from the module parameters. | 595 | * Fill in the HS isoc and interrupt descriptors from the module |
421 | * We assume that the user knows what they are doing and won't | 596 | * parameters. We assume that the user knows what they are doing and |
422 | * give parameters that their UDC doesn't support. | 597 | * won't give parameters that their UDC doesn't support. |
423 | */ | 598 | */ |
424 | hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket; | 599 | hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket; |
425 | hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11; | 600 | hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11; |
@@ -432,6 +607,17 @@ no_iso: | |||
432 | hs_iso_sink_desc.bInterval = isoc_interval; | 607 | hs_iso_sink_desc.bInterval = isoc_interval; |
433 | hs_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; | 608 | hs_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; |
434 | 609 | ||
610 | hs_int_source_desc.wMaxPacketSize = int_maxpacket; | ||
611 | hs_int_source_desc.wMaxPacketSize |= int_mult << 11; | ||
612 | hs_int_source_desc.bInterval = USB_MS_TO_HS_INTERVAL(int_interval); | ||
613 | hs_int_source_desc.bEndpointAddress = | ||
614 | fs_int_source_desc.bEndpointAddress; | ||
615 | |||
616 | hs_int_sink_desc.wMaxPacketSize = int_maxpacket; | ||
617 | hs_int_sink_desc.wMaxPacketSize |= int_mult << 11; | ||
618 | hs_int_sink_desc.bInterval = USB_MS_TO_HS_INTERVAL(int_interval); | ||
619 | hs_int_sink_desc.bEndpointAddress = fs_int_sink_desc.bEndpointAddress; | ||
620 | |||
435 | /* support super speed hardware */ | 621 | /* support super speed hardware */ |
436 | ss_source_desc.bEndpointAddress = | 622 | ss_source_desc.bEndpointAddress = |
437 | fs_source_desc.bEndpointAddress; | 623 | fs_source_desc.bEndpointAddress; |
@@ -439,9 +625,9 @@ no_iso: | |||
439 | fs_sink_desc.bEndpointAddress; | 625 | fs_sink_desc.bEndpointAddress; |
440 | 626 | ||
441 | /* | 627 | /* |
442 | * Fill in the SS isoc descriptors from the module parameters. | 628 | * Fill in the SS isoc and interrupt descriptors from the module |
443 | * We assume that the user knows what they are doing and won't | 629 | * parameters. We assume that the user knows what they are doing and |
444 | * give parameters that their UDC doesn't support. | 630 | * won't give parameters that their UDC doesn't support. |
445 | */ | 631 | */ |
446 | ss_iso_source_desc.wMaxPacketSize = isoc_maxpacket; | 632 | ss_iso_source_desc.wMaxPacketSize = isoc_maxpacket; |
447 | ss_iso_source_desc.bInterval = isoc_interval; | 633 | ss_iso_source_desc.bInterval = isoc_interval; |
@@ -460,17 +646,37 @@ no_iso: | |||
460 | isoc_maxpacket * (isoc_mult + 1) * (isoc_maxburst + 1); | 646 | isoc_maxpacket * (isoc_mult + 1) * (isoc_maxburst + 1); |
461 | ss_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; | 647 | ss_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; |
462 | 648 | ||
649 | ss_int_source_desc.wMaxPacketSize = int_maxpacket; | ||
650 | ss_int_source_desc.bInterval = USB_MS_TO_SS_INTERVAL(int_interval); | ||
651 | ss_int_source_comp_desc.bmAttributes = int_mult; | ||
652 | ss_int_source_comp_desc.bMaxBurst = int_maxburst; | ||
653 | ss_int_source_comp_desc.wBytesPerInterval = | ||
654 | int_maxpacket * (int_mult + 1) * (int_maxburst + 1); | ||
655 | ss_int_source_desc.bEndpointAddress = | ||
656 | fs_int_source_desc.bEndpointAddress; | ||
657 | |||
658 | ss_int_sink_desc.wMaxPacketSize = int_maxpacket; | ||
659 | ss_int_sink_desc.bInterval = USB_MS_TO_SS_INTERVAL(int_interval); | ||
660 | ss_int_sink_comp_desc.bmAttributes = int_mult; | ||
661 | ss_int_sink_comp_desc.bMaxBurst = int_maxburst; | ||
662 | ss_int_sink_comp_desc.wBytesPerInterval = | ||
663 | int_maxpacket * (int_mult + 1) * (int_maxburst + 1); | ||
664 | ss_int_sink_desc.bEndpointAddress = fs_int_sink_desc.bEndpointAddress; | ||
665 | |||
463 | ret = usb_assign_descriptors(f, fs_source_sink_descs, | 666 | ret = usb_assign_descriptors(f, fs_source_sink_descs, |
464 | hs_source_sink_descs, ss_source_sink_descs); | 667 | hs_source_sink_descs, ss_source_sink_descs); |
465 | if (ret) | 668 | if (ret) |
466 | return ret; | 669 | return ret; |
467 | 670 | ||
468 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n", | 671 | DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s, " |
672 | "INT-IN/%s, INT-OUT/%s\n", | ||
469 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : | 673 | (gadget_is_superspeed(c->cdev->gadget) ? "super" : |
470 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), | 674 | (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), |
471 | f->name, ss->in_ep->name, ss->out_ep->name, | 675 | f->name, ss->in_ep->name, ss->out_ep->name, |
472 | ss->iso_in_ep ? ss->iso_in_ep->name : "<none>", | 676 | ss->iso_in_ep ? ss->iso_in_ep->name : "<none>", |
473 | ss->iso_out_ep ? ss->iso_out_ep->name : "<none>"); | 677 | ss->iso_out_ep ? ss->iso_out_ep->name : "<none>", |
678 | ss->int_in_ep ? ss->int_in_ep->name : "<none>", | ||
679 | ss->int_out_ep ? ss->int_out_ep->name : "<none>"); | ||
474 | return 0; | 680 | return 0; |
475 | } | 681 | } |
476 | 682 | ||
@@ -601,14 +807,15 @@ static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) | |||
601 | } | 807 | } |
602 | 808 | ||
603 | static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, | 809 | static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, |
604 | bool is_iso, int speed) | 810 | enum eptype ep_type, int speed) |
605 | { | 811 | { |
606 | struct usb_ep *ep; | 812 | struct usb_ep *ep; |
607 | struct usb_request *req; | 813 | struct usb_request *req; |
608 | int i, size, status; | 814 | int i, size, status; |
609 | 815 | ||
610 | for (i = 0; i < 8; i++) { | 816 | for (i = 0; i < 8; i++) { |
611 | if (is_iso) { | 817 | switch (ep_type) { |
818 | case EP_ISOC: | ||
612 | switch (speed) { | 819 | switch (speed) { |
613 | case USB_SPEED_SUPER: | 820 | case USB_SPEED_SUPER: |
614 | size = isoc_maxpacket * (isoc_mult + 1) * | 821 | size = isoc_maxpacket * (isoc_mult + 1) * |
@@ -624,9 +831,28 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, | |||
624 | } | 831 | } |
625 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; | 832 | ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; |
626 | req = ss_alloc_ep_req(ep, size); | 833 | req = ss_alloc_ep_req(ep, size); |
627 | } else { | 834 | break; |
835 | case EP_INTERRUPT: | ||
836 | switch (speed) { | ||
837 | case USB_SPEED_SUPER: | ||
838 | size = int_maxpacket * (int_mult + 1) * | ||
839 | (int_maxburst + 1); | ||
840 | break; | ||
841 | case USB_SPEED_HIGH: | ||
842 | size = int_maxpacket * (int_mult + 1); | ||
843 | break; | ||
844 | default: | ||
845 | size = int_maxpacket > 1023 ? | ||
846 | 1023 : int_maxpacket; | ||
847 | break; | ||
848 | } | ||
849 | ep = is_in ? ss->int_in_ep : ss->int_out_ep; | ||
850 | req = ss_alloc_ep_req(ep, size); | ||
851 | break; | ||
852 | default: | ||
628 | ep = is_in ? ss->in_ep : ss->out_ep; | 853 | ep = is_in ? ss->in_ep : ss->out_ep; |
629 | req = ss_alloc_ep_req(ep, 0); | 854 | req = ss_alloc_ep_req(ep, 0); |
855 | break; | ||
630 | } | 856 | } |
631 | 857 | ||
632 | if (!req) | 858 | if (!req) |
@@ -644,12 +870,12 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, | |||
644 | 870 | ||
645 | cdev = ss->function.config->cdev; | 871 | cdev = ss->function.config->cdev; |
646 | ERROR(cdev, "start %s%s %s --> %d\n", | 872 | ERROR(cdev, "start %s%s %s --> %d\n", |
647 | is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", | 873 | get_ep_string(ep_type), is_in ? "IN" : "OUT", |
648 | ep->name, status); | 874 | ep->name, status); |
649 | free_ep_req(ep, req); | 875 | free_ep_req(ep, req); |
650 | } | 876 | } |
651 | 877 | ||
652 | if (!is_iso) | 878 | if (!(ep_type == EP_ISOC)) |
653 | break; | 879 | break; |
654 | } | 880 | } |
655 | 881 | ||
@@ -662,7 +888,7 @@ static void disable_source_sink(struct f_sourcesink *ss) | |||
662 | 888 | ||
663 | cdev = ss->function.config->cdev; | 889 | cdev = ss->function.config->cdev; |
664 | disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep, | 890 | disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep, |
665 | ss->iso_out_ep); | 891 | ss->iso_out_ep, ss->int_in_ep, ss->int_out_ep); |
666 | VDBG(cdev, "%s disabled\n", ss->function.name); | 892 | VDBG(cdev, "%s disabled\n", ss->function.name); |
667 | } | 893 | } |
668 | 894 | ||
@@ -674,6 +900,62 @@ enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss, | |||
674 | int speed = cdev->gadget->speed; | 900 | int speed = cdev->gadget->speed; |
675 | struct usb_ep *ep; | 901 | struct usb_ep *ep; |
676 | 902 | ||
903 | if (alt == 2) { | ||
904 | /* Configure for periodic interrupt endpoint */ | ||
905 | ep = ss->int_in_ep; | ||
906 | if (ep) { | ||
907 | result = config_ep_by_speed(cdev->gadget, | ||
908 | &(ss->function), ep); | ||
909 | if (result) | ||
910 | return result; | ||
911 | |||
912 | result = usb_ep_enable(ep); | ||
913 | if (result < 0) | ||
914 | return result; | ||
915 | |||
916 | ep->driver_data = ss; | ||
917 | result = source_sink_start_ep(ss, true, EP_INTERRUPT, | ||
918 | speed); | ||
919 | if (result < 0) { | ||
920 | fail1: | ||
921 | ep = ss->int_in_ep; | ||
922 | if (ep) { | ||
923 | usb_ep_disable(ep); | ||
924 | ep->driver_data = NULL; | ||
925 | } | ||
926 | return result; | ||
927 | } | ||
928 | } | ||
929 | |||
930 | /* | ||
931 | * one interrupt endpoint reads (sinks) anything OUT (from the | ||
932 | * host) | ||
933 | */ | ||
934 | ep = ss->int_out_ep; | ||
935 | if (ep) { | ||
936 | result = config_ep_by_speed(cdev->gadget, | ||
937 | &(ss->function), ep); | ||
938 | if (result) | ||
939 | goto fail1; | ||
940 | |||
941 | result = usb_ep_enable(ep); | ||
942 | if (result < 0) | ||
943 | goto fail1; | ||
944 | |||
945 | ep->driver_data = ss; | ||
946 | result = source_sink_start_ep(ss, false, EP_INTERRUPT, | ||
947 | speed); | ||
948 | if (result < 0) { | ||
949 | ep = ss->int_out_ep; | ||
950 | usb_ep_disable(ep); | ||
951 | ep->driver_data = NULL; | ||
952 | goto fail1; | ||
953 | } | ||
954 | } | ||
955 | |||
956 | goto out; | ||
957 | } | ||
958 | |||
677 | /* one bulk endpoint writes (sources) zeroes IN (to the host) */ | 959 | /* one bulk endpoint writes (sources) zeroes IN (to the host) */ |
678 | ep = ss->in_ep; | 960 | ep = ss->in_ep; |
679 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); | 961 | result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); |
@@ -684,7 +966,7 @@ enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss, | |||
684 | return result; | 966 | return result; |
685 | ep->driver_data = ss; | 967 | ep->driver_data = ss; |
686 | 968 | ||
687 | result = source_sink_start_ep(ss, true, false, speed); | 969 | result = source_sink_start_ep(ss, true, EP_BULK, speed); |
688 | if (result < 0) { | 970 | if (result < 0) { |
689 | fail: | 971 | fail: |
690 | ep = ss->in_ep; | 972 | ep = ss->in_ep; |
@@ -703,7 +985,7 @@ fail: | |||
703 | goto fail; | 985 | goto fail; |
704 | ep->driver_data = ss; | 986 | ep->driver_data = ss; |
705 | 987 | ||
706 | result = source_sink_start_ep(ss, false, false, speed); | 988 | result = source_sink_start_ep(ss, false, EP_BULK, speed); |
707 | if (result < 0) { | 989 | if (result < 0) { |
708 | fail2: | 990 | fail2: |
709 | ep = ss->out_ep; | 991 | ep = ss->out_ep; |
@@ -726,7 +1008,7 @@ fail2: | |||
726 | goto fail2; | 1008 | goto fail2; |
727 | ep->driver_data = ss; | 1009 | ep->driver_data = ss; |
728 | 1010 | ||
729 | result = source_sink_start_ep(ss, true, true, speed); | 1011 | result = source_sink_start_ep(ss, true, EP_ISOC, speed); |
730 | if (result < 0) { | 1012 | if (result < 0) { |
731 | fail3: | 1013 | fail3: |
732 | ep = ss->iso_in_ep; | 1014 | ep = ss->iso_in_ep; |
@@ -749,13 +1031,14 @@ fail3: | |||
749 | goto fail3; | 1031 | goto fail3; |
750 | ep->driver_data = ss; | 1032 | ep->driver_data = ss; |
751 | 1033 | ||
752 | result = source_sink_start_ep(ss, false, true, speed); | 1034 | result = source_sink_start_ep(ss, false, EP_ISOC, speed); |
753 | if (result < 0) { | 1035 | if (result < 0) { |
754 | usb_ep_disable(ep); | 1036 | usb_ep_disable(ep); |
755 | ep->driver_data = NULL; | 1037 | ep->driver_data = NULL; |
756 | goto fail3; | 1038 | goto fail3; |
757 | } | 1039 | } |
758 | } | 1040 | } |
1041 | |||
759 | out: | 1042 | out: |
760 | ss->cur_alt = alt; | 1043 | ss->cur_alt = alt; |
761 | 1044 | ||
@@ -771,6 +1054,8 @@ static int sourcesink_set_alt(struct usb_function *f, | |||
771 | 1054 | ||
772 | if (ss->in_ep->driver_data) | 1055 | if (ss->in_ep->driver_data) |
773 | disable_source_sink(ss); | 1056 | disable_source_sink(ss); |
1057 | else if (alt == 2 && ss->int_in_ep->driver_data) | ||
1058 | disable_source_sink(ss); | ||
774 | return enable_source_sink(cdev, ss, alt); | 1059 | return enable_source_sink(cdev, ss, alt); |
775 | } | 1060 | } |
776 | 1061 | ||
@@ -883,6 +1168,10 @@ static struct usb_function *source_sink_alloc_func( | |||
883 | isoc_maxpacket = ss_opts->isoc_maxpacket; | 1168 | isoc_maxpacket = ss_opts->isoc_maxpacket; |
884 | isoc_mult = ss_opts->isoc_mult; | 1169 | isoc_mult = ss_opts->isoc_mult; |
885 | isoc_maxburst = ss_opts->isoc_maxburst; | 1170 | isoc_maxburst = ss_opts->isoc_maxburst; |
1171 | int_interval = ss_opts->int_interval; | ||
1172 | int_maxpacket = ss_opts->int_maxpacket; | ||
1173 | int_mult = ss_opts->int_mult; | ||
1174 | int_maxburst = ss_opts->int_maxburst; | ||
886 | buflen = ss_opts->bulk_buflen; | 1175 | buflen = ss_opts->bulk_buflen; |
887 | 1176 | ||
888 | ss->function.name = "source/sink"; | 1177 | ss->function.name = "source/sink"; |
@@ -1179,6 +1468,182 @@ static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = | |||
1179 | f_ss_opts_bulk_buflen_show, | 1468 | f_ss_opts_bulk_buflen_show, |
1180 | f_ss_opts_bulk_buflen_store); | 1469 | f_ss_opts_bulk_buflen_store); |
1181 | 1470 | ||
1471 | static ssize_t f_ss_opts_int_interval_show(struct f_ss_opts *opts, char *page) | ||
1472 | { | ||
1473 | int result; | ||
1474 | |||
1475 | mutex_lock(&opts->lock); | ||
1476 | result = sprintf(page, "%d", opts->int_interval); | ||
1477 | mutex_unlock(&opts->lock); | ||
1478 | |||
1479 | return result; | ||
1480 | } | ||
1481 | |||
1482 | static ssize_t f_ss_opts_int_interval_store(struct f_ss_opts *opts, | ||
1483 | const char *page, size_t len) | ||
1484 | { | ||
1485 | int ret; | ||
1486 | u32 num; | ||
1487 | |||
1488 | mutex_lock(&opts->lock); | ||
1489 | if (opts->refcnt) { | ||
1490 | ret = -EBUSY; | ||
1491 | goto end; | ||
1492 | } | ||
1493 | |||
1494 | ret = kstrtou32(page, 0, &num); | ||
1495 | if (ret) | ||
1496 | goto end; | ||
1497 | |||
1498 | if (num > 4096) { | ||
1499 | ret = -EINVAL; | ||
1500 | goto end; | ||
1501 | } | ||
1502 | |||
1503 | opts->int_interval = num; | ||
1504 | ret = len; | ||
1505 | end: | ||
1506 | mutex_unlock(&opts->lock); | ||
1507 | return ret; | ||
1508 | } | ||
1509 | |||
1510 | static struct f_ss_opts_attribute f_ss_opts_int_interval = | ||
1511 | __CONFIGFS_ATTR(int_interval, S_IRUGO | S_IWUSR, | ||
1512 | f_ss_opts_int_interval_show, | ||
1513 | f_ss_opts_int_interval_store); | ||
1514 | |||
1515 | static ssize_t f_ss_opts_int_maxpacket_show(struct f_ss_opts *opts, char *page) | ||
1516 | { | ||
1517 | int result; | ||
1518 | |||
1519 | mutex_lock(&opts->lock); | ||
1520 | result = sprintf(page, "%d", opts->int_maxpacket); | ||
1521 | mutex_unlock(&opts->lock); | ||
1522 | |||
1523 | return result; | ||
1524 | } | ||
1525 | |||
1526 | static ssize_t f_ss_opts_int_maxpacket_store(struct f_ss_opts *opts, | ||
1527 | const char *page, size_t len) | ||
1528 | { | ||
1529 | int ret; | ||
1530 | u16 num; | ||
1531 | |||
1532 | mutex_lock(&opts->lock); | ||
1533 | if (opts->refcnt) { | ||
1534 | ret = -EBUSY; | ||
1535 | goto end; | ||
1536 | } | ||
1537 | |||
1538 | ret = kstrtou16(page, 0, &num); | ||
1539 | if (ret) | ||
1540 | goto end; | ||
1541 | |||
1542 | if (num > 1024) { | ||
1543 | ret = -EINVAL; | ||
1544 | goto end; | ||
1545 | } | ||
1546 | |||
1547 | opts->int_maxpacket = num; | ||
1548 | ret = len; | ||
1549 | end: | ||
1550 | mutex_unlock(&opts->lock); | ||
1551 | return ret; | ||
1552 | } | ||
1553 | |||
1554 | static struct f_ss_opts_attribute f_ss_opts_int_maxpacket = | ||
1555 | __CONFIGFS_ATTR(int_maxpacket, S_IRUGO | S_IWUSR, | ||
1556 | f_ss_opts_int_maxpacket_show, | ||
1557 | f_ss_opts_int_maxpacket_store); | ||
1558 | |||
1559 | static ssize_t f_ss_opts_int_mult_show(struct f_ss_opts *opts, char *page) | ||
1560 | { | ||
1561 | int result; | ||
1562 | |||
1563 | mutex_lock(&opts->lock); | ||
1564 | result = sprintf(page, "%d", opts->int_mult); | ||
1565 | mutex_unlock(&opts->lock); | ||
1566 | |||
1567 | return result; | ||
1568 | } | ||
1569 | |||
1570 | static ssize_t f_ss_opts_int_mult_store(struct f_ss_opts *opts, | ||
1571 | const char *page, size_t len) | ||
1572 | { | ||
1573 | int ret; | ||
1574 | u8 num; | ||
1575 | |||
1576 | mutex_lock(&opts->lock); | ||
1577 | if (opts->refcnt) { | ||
1578 | ret = -EBUSY; | ||
1579 | goto end; | ||
1580 | } | ||
1581 | |||
1582 | ret = kstrtou8(page, 0, &num); | ||
1583 | if (ret) | ||
1584 | goto end; | ||
1585 | |||
1586 | if (num > 2) { | ||
1587 | ret = -EINVAL; | ||
1588 | goto end; | ||
1589 | } | ||
1590 | |||
1591 | opts->int_mult = num; | ||
1592 | ret = len; | ||
1593 | end: | ||
1594 | mutex_unlock(&opts->lock); | ||
1595 | return ret; | ||
1596 | } | ||
1597 | |||
1598 | static struct f_ss_opts_attribute f_ss_opts_int_mult = | ||
1599 | __CONFIGFS_ATTR(int_mult, S_IRUGO | S_IWUSR, | ||
1600 | f_ss_opts_int_mult_show, | ||
1601 | f_ss_opts_int_mult_store); | ||
1602 | |||
1603 | static ssize_t f_ss_opts_int_maxburst_show(struct f_ss_opts *opts, char *page) | ||
1604 | { | ||
1605 | int result; | ||
1606 | |||
1607 | mutex_lock(&opts->lock); | ||
1608 | result = sprintf(page, "%d", opts->int_maxburst); | ||
1609 | mutex_unlock(&opts->lock); | ||
1610 | |||
1611 | return result; | ||
1612 | } | ||
1613 | |||
1614 | static ssize_t f_ss_opts_int_maxburst_store(struct f_ss_opts *opts, | ||
1615 | const char *page, size_t len) | ||
1616 | { | ||
1617 | int ret; | ||
1618 | u8 num; | ||
1619 | |||
1620 | mutex_lock(&opts->lock); | ||
1621 | if (opts->refcnt) { | ||
1622 | ret = -EBUSY; | ||
1623 | goto end; | ||
1624 | } | ||
1625 | |||
1626 | ret = kstrtou8(page, 0, &num); | ||
1627 | if (ret) | ||
1628 | goto end; | ||
1629 | |||
1630 | if (num > 15) { | ||
1631 | ret = -EINVAL; | ||
1632 | goto end; | ||
1633 | } | ||
1634 | |||
1635 | opts->int_maxburst = num; | ||
1636 | ret = len; | ||
1637 | end: | ||
1638 | mutex_unlock(&opts->lock); | ||
1639 | return ret; | ||
1640 | } | ||
1641 | |||
1642 | static struct f_ss_opts_attribute f_ss_opts_int_maxburst = | ||
1643 | __CONFIGFS_ATTR(int_maxburst, S_IRUGO | S_IWUSR, | ||
1644 | f_ss_opts_int_maxburst_show, | ||
1645 | f_ss_opts_int_maxburst_store); | ||
1646 | |||
1182 | static struct configfs_attribute *ss_attrs[] = { | 1647 | static struct configfs_attribute *ss_attrs[] = { |
1183 | &f_ss_opts_pattern.attr, | 1648 | &f_ss_opts_pattern.attr, |
1184 | &f_ss_opts_isoc_interval.attr, | 1649 | &f_ss_opts_isoc_interval.attr, |
@@ -1186,6 +1651,10 @@ static struct configfs_attribute *ss_attrs[] = { | |||
1186 | &f_ss_opts_isoc_mult.attr, | 1651 | &f_ss_opts_isoc_mult.attr, |
1187 | &f_ss_opts_isoc_maxburst.attr, | 1652 | &f_ss_opts_isoc_maxburst.attr, |
1188 | &f_ss_opts_bulk_buflen.attr, | 1653 | &f_ss_opts_bulk_buflen.attr, |
1654 | &f_ss_opts_int_interval.attr, | ||
1655 | &f_ss_opts_int_maxpacket.attr, | ||
1656 | &f_ss_opts_int_mult.attr, | ||
1657 | &f_ss_opts_int_maxburst.attr, | ||
1189 | NULL, | 1658 | NULL, |
1190 | }; | 1659 | }; |
1191 | 1660 | ||
@@ -1215,6 +1684,8 @@ static struct usb_function_instance *source_sink_alloc_inst(void) | |||
1215 | ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; | 1684 | ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; |
1216 | ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; | 1685 | ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; |
1217 | ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; | 1686 | ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; |
1687 | ss_opts->int_interval = GZERO_INT_INTERVAL; | ||
1688 | ss_opts->int_maxpacket = GZERO_INT_MAXPACKET; | ||
1218 | 1689 | ||
1219 | config_group_init_type_name(&ss_opts->func_inst.group, "", | 1690 | config_group_init_type_name(&ss_opts->func_inst.group, "", |
1220 | &ss_func_type); | 1691 | &ss_func_type); |
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 2b4c82d84bfc..f7b203293205 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c | |||
@@ -11,24 +11,12 @@ | |||
11 | 11 | ||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/atomic.h> | 16 | #include <linux/atomic.h> |
16 | 17 | ||
17 | #include "u_uac1.h" | 18 | #include "u_uac1.h" |
18 | 19 | ||
19 | #define OUT_EP_MAX_PACKET_SIZE 200 | ||
20 | static int req_buf_size = OUT_EP_MAX_PACKET_SIZE; | ||
21 | module_param(req_buf_size, int, S_IRUGO); | ||
22 | MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); | ||
23 | |||
24 | static int req_count = 256; | ||
25 | module_param(req_count, int, S_IRUGO); | ||
26 | MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); | ||
27 | |||
28 | static int audio_buf_size = 48000; | ||
29 | module_param(audio_buf_size, int, S_IRUGO); | ||
30 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | ||
31 | |||
32 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); | 20 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); |
33 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | 21 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); |
34 | 22 | ||
@@ -46,7 +34,7 @@ static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | |||
46 | #define F_AUDIO_NUM_INTERFACES 2 | 34 | #define F_AUDIO_NUM_INTERFACES 2 |
47 | 35 | ||
48 | /* B.3.1 Standard AC Interface Descriptor */ | 36 | /* B.3.1 Standard AC Interface Descriptor */ |
49 | static struct usb_interface_descriptor ac_interface_desc __initdata = { | 37 | static struct usb_interface_descriptor ac_interface_desc = { |
50 | .bLength = USB_DT_INTERFACE_SIZE, | 38 | .bLength = USB_DT_INTERFACE_SIZE, |
51 | .bDescriptorType = USB_DT_INTERFACE, | 39 | .bDescriptorType = USB_DT_INTERFACE, |
52 | .bNumEndpoints = 0, | 40 | .bNumEndpoints = 0, |
@@ -183,12 +171,12 @@ static struct usb_endpoint_descriptor as_out_ep_desc = { | |||
183 | .bEndpointAddress = USB_DIR_OUT, | 171 | .bEndpointAddress = USB_DIR_OUT, |
184 | .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE | 172 | .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE |
185 | | USB_ENDPOINT_XFER_ISOC, | 173 | | USB_ENDPOINT_XFER_ISOC, |
186 | .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), | 174 | .wMaxPacketSize = cpu_to_le16(UAC1_OUT_EP_MAX_PACKET_SIZE), |
187 | .bInterval = 4, | 175 | .bInterval = 4, |
188 | }; | 176 | }; |
189 | 177 | ||
190 | /* Class-specific AS ISO OUT Endpoint Descriptor */ | 178 | /* Class-specific AS ISO OUT Endpoint Descriptor */ |
191 | static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { | 179 | static struct uac_iso_endpoint_descriptor as_iso_out_desc = { |
192 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, | 180 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, |
193 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 181 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
194 | .bDescriptorSubtype = UAC_EP_GENERAL, | 182 | .bDescriptorSubtype = UAC_EP_GENERAL, |
@@ -197,7 +185,7 @@ static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { | |||
197 | .wLockDelay = __constant_cpu_to_le16(1), | 185 | .wLockDelay = __constant_cpu_to_le16(1), |
198 | }; | 186 | }; |
199 | 187 | ||
200 | static struct usb_descriptor_header *f_audio_desc[] __initdata = { | 188 | static struct usb_descriptor_header *f_audio_desc[] = { |
201 | (struct usb_descriptor_header *)&ac_interface_desc, | 189 | (struct usb_descriptor_header *)&ac_interface_desc, |
202 | (struct usb_descriptor_header *)&ac_header_desc, | 190 | (struct usb_descriptor_header *)&ac_header_desc, |
203 | 191 | ||
@@ -216,6 +204,37 @@ static struct usb_descriptor_header *f_audio_desc[] __initdata = { | |||
216 | NULL, | 204 | NULL, |
217 | }; | 205 | }; |
218 | 206 | ||
207 | enum { | ||
208 | STR_AC_IF, | ||
209 | STR_INPUT_TERMINAL, | ||
210 | STR_INPUT_TERMINAL_CH_NAMES, | ||
211 | STR_FEAT_DESC_0, | ||
212 | STR_OUTPUT_TERMINAL, | ||
213 | STR_AS_IF_ALT0, | ||
214 | STR_AS_IF_ALT1, | ||
215 | }; | ||
216 | |||
217 | static struct usb_string strings_uac1[] = { | ||
218 | [STR_AC_IF].s = "AC Interface", | ||
219 | [STR_INPUT_TERMINAL].s = "Input terminal", | ||
220 | [STR_INPUT_TERMINAL_CH_NAMES].s = "Channels", | ||
221 | [STR_FEAT_DESC_0].s = "Volume control & mute", | ||
222 | [STR_OUTPUT_TERMINAL].s = "Output terminal", | ||
223 | [STR_AS_IF_ALT0].s = "AS Interface", | ||
224 | [STR_AS_IF_ALT1].s = "AS Interface", | ||
225 | { }, | ||
226 | }; | ||
227 | |||
228 | static struct usb_gadget_strings str_uac1 = { | ||
229 | .language = 0x0409, /* en-us */ | ||
230 | .strings = strings_uac1, | ||
231 | }; | ||
232 | |||
233 | static struct usb_gadget_strings *uac1_strings[] = { | ||
234 | &str_uac1, | ||
235 | NULL, | ||
236 | }; | ||
237 | |||
219 | /* | 238 | /* |
220 | * This function is an ALSA sound card following USB Audio Class Spec 1.0. | 239 | * This function is an ALSA sound card following USB Audio Class Spec 1.0. |
221 | */ | 240 | */ |
@@ -300,8 +319,14 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req) | |||
300 | struct f_audio *audio = req->context; | 319 | struct f_audio *audio = req->context; |
301 | struct usb_composite_dev *cdev = audio->card.func.config->cdev; | 320 | struct usb_composite_dev *cdev = audio->card.func.config->cdev; |
302 | struct f_audio_buf *copy_buf = audio->copy_buf; | 321 | struct f_audio_buf *copy_buf = audio->copy_buf; |
322 | struct f_uac1_opts *opts; | ||
323 | int audio_buf_size; | ||
303 | int err; | 324 | int err; |
304 | 325 | ||
326 | opts = container_of(audio->card.func.fi, struct f_uac1_opts, | ||
327 | func_inst); | ||
328 | audio_buf_size = opts->audio_buf_size; | ||
329 | |||
305 | if (!copy_buf) | 330 | if (!copy_buf) |
306 | return -EINVAL; | 331 | return -EINVAL; |
307 | 332 | ||
@@ -546,10 +571,17 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
546 | struct usb_composite_dev *cdev = f->config->cdev; | 571 | struct usb_composite_dev *cdev = f->config->cdev; |
547 | struct usb_ep *out_ep = audio->out_ep; | 572 | struct usb_ep *out_ep = audio->out_ep; |
548 | struct usb_request *req; | 573 | struct usb_request *req; |
574 | struct f_uac1_opts *opts; | ||
575 | int req_buf_size, req_count, audio_buf_size; | ||
549 | int i = 0, err = 0; | 576 | int i = 0, err = 0; |
550 | 577 | ||
551 | DBG(cdev, "intf %d, alt %d\n", intf, alt); | 578 | DBG(cdev, "intf %d, alt %d\n", intf, alt); |
552 | 579 | ||
580 | opts = container_of(f->fi, struct f_uac1_opts, func_inst); | ||
581 | req_buf_size = opts->req_buf_size; | ||
582 | req_count = opts->req_count; | ||
583 | audio_buf_size = opts->audio_buf_size; | ||
584 | |||
553 | if (intf == 1) { | 585 | if (intf == 1) { |
554 | if (alt == 1) { | 586 | if (alt == 1) { |
555 | usb_ep_enable(out_ep); | 587 | usb_ep_enable(out_ep); |
@@ -625,13 +657,37 @@ static void f_audio_build_desc(struct f_audio *audio) | |||
625 | } | 657 | } |
626 | 658 | ||
627 | /* audio function driver setup/binding */ | 659 | /* audio function driver setup/binding */ |
628 | static int __init | 660 | static int |
629 | f_audio_bind(struct usb_configuration *c, struct usb_function *f) | 661 | f_audio_bind(struct usb_configuration *c, struct usb_function *f) |
630 | { | 662 | { |
631 | struct usb_composite_dev *cdev = c->cdev; | 663 | struct usb_composite_dev *cdev = c->cdev; |
632 | struct f_audio *audio = func_to_audio(f); | 664 | struct f_audio *audio = func_to_audio(f); |
665 | struct usb_string *us; | ||
633 | int status; | 666 | int status; |
634 | struct usb_ep *ep = NULL; | 667 | struct usb_ep *ep = NULL; |
668 | struct f_uac1_opts *audio_opts; | ||
669 | |||
670 | audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); | ||
671 | audio->card.gadget = c->cdev->gadget; | ||
672 | audio_opts->card = &audio->card; | ||
673 | /* set up ASLA audio devices */ | ||
674 | if (!audio_opts->bound) { | ||
675 | status = gaudio_setup(&audio->card); | ||
676 | if (status < 0) | ||
677 | return status; | ||
678 | audio_opts->bound = true; | ||
679 | } | ||
680 | us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); | ||
681 | if (IS_ERR(us)) | ||
682 | return PTR_ERR(us); | ||
683 | ac_interface_desc.iInterface = us[STR_AC_IF].id; | ||
684 | input_terminal_desc.iTerminal = us[STR_INPUT_TERMINAL].id; | ||
685 | input_terminal_desc.iChannelNames = us[STR_INPUT_TERMINAL_CH_NAMES].id; | ||
686 | feature_unit_desc.iFeature = us[STR_FEAT_DESC_0].id; | ||
687 | output_terminal_desc.iTerminal = us[STR_OUTPUT_TERMINAL].id; | ||
688 | as_interface_alt_0_desc.iInterface = us[STR_AS_IF_ALT0].id; | ||
689 | as_interface_alt_1_desc.iInterface = us[STR_AS_IF_ALT1].id; | ||
690 | |||
635 | 691 | ||
636 | f_audio_build_desc(audio); | 692 | f_audio_build_desc(audio); |
637 | 693 | ||
@@ -666,20 +722,12 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) | |||
666 | return 0; | 722 | return 0; |
667 | 723 | ||
668 | fail: | 724 | fail: |
725 | gaudio_cleanup(&audio->card); | ||
669 | if (ep) | 726 | if (ep) |
670 | ep->driver_data = NULL; | 727 | ep->driver_data = NULL; |
671 | return status; | 728 | return status; |
672 | } | 729 | } |
673 | 730 | ||
674 | static void | ||
675 | f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | ||
676 | { | ||
677 | struct f_audio *audio = func_to_audio(f); | ||
678 | |||
679 | usb_free_all_descriptors(f); | ||
680 | kfree(audio); | ||
681 | } | ||
682 | |||
683 | /*-------------------------------------------------------------------------*/ | 731 | /*-------------------------------------------------------------------------*/ |
684 | 732 | ||
685 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) | 733 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value) |
@@ -695,7 +743,7 @@ static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) | |||
695 | } | 743 | } |
696 | 744 | ||
697 | /* Todo: add more control selecotor dynamically */ | 745 | /* Todo: add more control selecotor dynamically */ |
698 | static int __init control_selector_init(struct f_audio *audio) | 746 | static int control_selector_init(struct f_audio *audio) |
699 | { | 747 | { |
700 | INIT_LIST_HEAD(&audio->cs); | 748 | INIT_LIST_HEAD(&audio->cs); |
701 | list_add(&feature_unit.list, &audio->cs); | 749 | list_add(&feature_unit.list, &audio->cs); |
@@ -712,57 +760,226 @@ static int __init control_selector_init(struct f_audio *audio) | |||
712 | return 0; | 760 | return 0; |
713 | } | 761 | } |
714 | 762 | ||
715 | /** | 763 | static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) |
716 | * audio_bind_config - add USB audio function to a configuration | 764 | { |
717 | * @c: the configuration to supcard the USB audio function | 765 | return container_of(to_config_group(item), struct f_uac1_opts, |
718 | * Context: single threaded during gadget setup | 766 | func_inst.group); |
719 | * | 767 | } |
720 | * Returns zero on success, else negative errno. | 768 | |
721 | */ | 769 | CONFIGFS_ATTR_STRUCT(f_uac1_opts); |
722 | static int __init audio_bind_config(struct usb_configuration *c) | 770 | CONFIGFS_ATTR_OPS(f_uac1_opts); |
771 | |||
772 | static void f_uac1_attr_release(struct config_item *item) | ||
773 | { | ||
774 | struct f_uac1_opts *opts = to_f_uac1_opts(item); | ||
775 | |||
776 | usb_put_function_instance(&opts->func_inst); | ||
777 | } | ||
778 | |||
779 | static struct configfs_item_operations f_uac1_item_ops = { | ||
780 | .release = f_uac1_attr_release, | ||
781 | .show_attribute = f_uac1_opts_attr_show, | ||
782 | .store_attribute = f_uac1_opts_attr_store, | ||
783 | }; | ||
784 | |||
785 | #define UAC1_INT_ATTRIBUTE(name) \ | ||
786 | static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ | ||
787 | char *page) \ | ||
788 | { \ | ||
789 | int result; \ | ||
790 | \ | ||
791 | mutex_lock(&opts->lock); \ | ||
792 | result = sprintf(page, "%u\n", opts->name); \ | ||
793 | mutex_unlock(&opts->lock); \ | ||
794 | \ | ||
795 | return result; \ | ||
796 | } \ | ||
797 | \ | ||
798 | static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ | ||
799 | const char *page, size_t len) \ | ||
800 | { \ | ||
801 | int ret; \ | ||
802 | u32 num; \ | ||
803 | \ | ||
804 | mutex_lock(&opts->lock); \ | ||
805 | if (opts->refcnt) { \ | ||
806 | ret = -EBUSY; \ | ||
807 | goto end; \ | ||
808 | } \ | ||
809 | \ | ||
810 | ret = kstrtou32(page, 0, &num); \ | ||
811 | if (ret) \ | ||
812 | goto end; \ | ||
813 | \ | ||
814 | opts->name = num; \ | ||
815 | ret = len; \ | ||
816 | \ | ||
817 | end: \ | ||
818 | mutex_unlock(&opts->lock); \ | ||
819 | return ret; \ | ||
820 | } \ | ||
821 | \ | ||
822 | static struct f_uac1_opts_attribute f_uac1_opts_##name = \ | ||
823 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ | ||
824 | f_uac1_opts_##name##_show, \ | ||
825 | f_uac1_opts_##name##_store) | ||
826 | |||
827 | UAC1_INT_ATTRIBUTE(req_buf_size); | ||
828 | UAC1_INT_ATTRIBUTE(req_count); | ||
829 | UAC1_INT_ATTRIBUTE(audio_buf_size); | ||
830 | |||
831 | #define UAC1_STR_ATTRIBUTE(name) \ | ||
832 | static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ | ||
833 | char *page) \ | ||
834 | { \ | ||
835 | int result; \ | ||
836 | \ | ||
837 | mutex_lock(&opts->lock); \ | ||
838 | result = sprintf(page, "%s\n", opts->name); \ | ||
839 | mutex_unlock(&opts->lock); \ | ||
840 | \ | ||
841 | return result; \ | ||
842 | } \ | ||
843 | \ | ||
844 | static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ | ||
845 | const char *page, size_t len) \ | ||
846 | { \ | ||
847 | int ret = -EBUSY; \ | ||
848 | char *tmp; \ | ||
849 | \ | ||
850 | mutex_lock(&opts->lock); \ | ||
851 | if (opts->refcnt) \ | ||
852 | goto end; \ | ||
853 | \ | ||
854 | tmp = kstrndup(page, len, GFP_KERNEL); \ | ||
855 | if (tmp) { \ | ||
856 | ret = -ENOMEM; \ | ||
857 | goto end; \ | ||
858 | } \ | ||
859 | if (opts->name##_alloc) \ | ||
860 | kfree(opts->name); \ | ||
861 | opts->name##_alloc = true; \ | ||
862 | opts->name = tmp; \ | ||
863 | ret = len; \ | ||
864 | \ | ||
865 | end: \ | ||
866 | mutex_unlock(&opts->lock); \ | ||
867 | return ret; \ | ||
868 | } \ | ||
869 | \ | ||
870 | static struct f_uac1_opts_attribute f_uac1_opts_##name = \ | ||
871 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ | ||
872 | f_uac1_opts_##name##_show, \ | ||
873 | f_uac1_opts_##name##_store) | ||
874 | |||
875 | UAC1_STR_ATTRIBUTE(fn_play); | ||
876 | UAC1_STR_ATTRIBUTE(fn_cap); | ||
877 | UAC1_STR_ATTRIBUTE(fn_cntl); | ||
878 | |||
879 | static struct configfs_attribute *f_uac1_attrs[] = { | ||
880 | &f_uac1_opts_req_buf_size.attr, | ||
881 | &f_uac1_opts_req_count.attr, | ||
882 | &f_uac1_opts_audio_buf_size.attr, | ||
883 | &f_uac1_opts_fn_play.attr, | ||
884 | &f_uac1_opts_fn_cap.attr, | ||
885 | &f_uac1_opts_fn_cntl.attr, | ||
886 | NULL, | ||
887 | }; | ||
888 | |||
889 | static struct config_item_type f_uac1_func_type = { | ||
890 | .ct_item_ops = &f_uac1_item_ops, | ||
891 | .ct_attrs = f_uac1_attrs, | ||
892 | .ct_owner = THIS_MODULE, | ||
893 | }; | ||
894 | |||
895 | static void f_audio_free_inst(struct usb_function_instance *f) | ||
896 | { | ||
897 | struct f_uac1_opts *opts; | ||
898 | |||
899 | opts = container_of(f, struct f_uac1_opts, func_inst); | ||
900 | gaudio_cleanup(opts->card); | ||
901 | if (opts->fn_play_alloc) | ||
902 | kfree(opts->fn_play); | ||
903 | if (opts->fn_cap_alloc) | ||
904 | kfree(opts->fn_cap); | ||
905 | if (opts->fn_cntl_alloc) | ||
906 | kfree(opts->fn_cntl); | ||
907 | kfree(opts); | ||
908 | } | ||
909 | |||
910 | static struct usb_function_instance *f_audio_alloc_inst(void) | ||
911 | { | ||
912 | struct f_uac1_opts *opts; | ||
913 | |||
914 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
915 | if (!opts) | ||
916 | return ERR_PTR(-ENOMEM); | ||
917 | |||
918 | mutex_init(&opts->lock); | ||
919 | opts->func_inst.free_func_inst = f_audio_free_inst; | ||
920 | |||
921 | config_group_init_type_name(&opts->func_inst.group, "", | ||
922 | &f_uac1_func_type); | ||
923 | |||
924 | opts->req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; | ||
925 | opts->req_count = UAC1_REQ_COUNT; | ||
926 | opts->audio_buf_size = UAC1_AUDIO_BUF_SIZE; | ||
927 | opts->fn_play = FILE_PCM_PLAYBACK; | ||
928 | opts->fn_cap = FILE_PCM_CAPTURE; | ||
929 | opts->fn_cntl = FILE_CONTROL; | ||
930 | return &opts->func_inst; | ||
931 | } | ||
932 | |||
933 | static void f_audio_free(struct usb_function *f) | ||
934 | { | ||
935 | struct f_audio *audio = func_to_audio(f); | ||
936 | struct f_uac1_opts *opts; | ||
937 | |||
938 | opts = container_of(f->fi, struct f_uac1_opts, func_inst); | ||
939 | kfree(audio); | ||
940 | mutex_lock(&opts->lock); | ||
941 | --opts->refcnt; | ||
942 | mutex_unlock(&opts->lock); | ||
943 | } | ||
944 | |||
945 | static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | ||
946 | { | ||
947 | usb_free_all_descriptors(f); | ||
948 | } | ||
949 | |||
950 | static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) | ||
723 | { | 951 | { |
724 | struct f_audio *audio; | 952 | struct f_audio *audio; |
725 | int status; | 953 | struct f_uac1_opts *opts; |
726 | 954 | ||
727 | /* allocate and initialize one new instance */ | 955 | /* allocate and initialize one new instance */ |
728 | audio = kzalloc(sizeof *audio, GFP_KERNEL); | 956 | audio = kzalloc(sizeof(*audio), GFP_KERNEL); |
729 | if (!audio) | 957 | if (!audio) |
730 | return -ENOMEM; | 958 | return ERR_PTR(-ENOMEM); |
731 | 959 | ||
732 | audio->card.func.name = "g_audio"; | 960 | audio->card.func.name = "g_audio"; |
733 | audio->card.gadget = c->cdev->gadget; | ||
734 | 961 | ||
962 | opts = container_of(fi, struct f_uac1_opts, func_inst); | ||
963 | mutex_lock(&opts->lock); | ||
964 | ++opts->refcnt; | ||
965 | mutex_unlock(&opts->lock); | ||
735 | INIT_LIST_HEAD(&audio->play_queue); | 966 | INIT_LIST_HEAD(&audio->play_queue); |
736 | spin_lock_init(&audio->lock); | 967 | spin_lock_init(&audio->lock); |
737 | 968 | ||
738 | /* set up ASLA audio devices */ | ||
739 | status = gaudio_setup(&audio->card); | ||
740 | if (status < 0) | ||
741 | goto setup_fail; | ||
742 | |||
743 | audio->card.func.strings = audio_strings; | ||
744 | audio->card.func.bind = f_audio_bind; | 969 | audio->card.func.bind = f_audio_bind; |
745 | audio->card.func.unbind = f_audio_unbind; | 970 | audio->card.func.unbind = f_audio_unbind; |
746 | audio->card.func.set_alt = f_audio_set_alt; | 971 | audio->card.func.set_alt = f_audio_set_alt; |
747 | audio->card.func.setup = f_audio_setup; | 972 | audio->card.func.setup = f_audio_setup; |
748 | audio->card.func.disable = f_audio_disable; | 973 | audio->card.func.disable = f_audio_disable; |
974 | audio->card.func.free_func = f_audio_free; | ||
749 | 975 | ||
750 | control_selector_init(audio); | 976 | control_selector_init(audio); |
751 | 977 | ||
752 | INIT_WORK(&audio->playback_work, f_audio_playback_work); | 978 | INIT_WORK(&audio->playback_work, f_audio_playback_work); |
753 | 979 | ||
754 | status = usb_add_function(c, &audio->card.func); | 980 | return &audio->card.func; |
755 | if (status) | ||
756 | goto add_fail; | ||
757 | |||
758 | INFO(c->cdev, "audio_buf_size %d, req_buf_size %d, req_count %d\n", | ||
759 | audio_buf_size, req_buf_size, req_count); | ||
760 | |||
761 | return status; | ||
762 | |||
763 | add_fail: | ||
764 | gaudio_cleanup(); | ||
765 | setup_fail: | ||
766 | kfree(audio); | ||
767 | return status; | ||
768 | } | 981 | } |
982 | |||
983 | DECLARE_USB_FUNCTION_INIT(uac1, f_audio_alloc_inst, f_audio_alloc); | ||
984 | MODULE_LICENSE("GPL"); | ||
985 | MODULE_AUTHOR("Bryan Wu"); | ||
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 3ed89ecc8d6d..a5a27a504d67 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c | |||
@@ -20,35 +20,7 @@ | |||
20 | #include <sound/pcm.h> | 20 | #include <sound/pcm.h> |
21 | #include <sound/pcm_params.h> | 21 | #include <sound/pcm_params.h> |
22 | 22 | ||
23 | /* Playback(USB-IN) Default Stereo - Fl/Fr */ | 23 | #include "u_uac2.h" |
24 | static int p_chmask = 0x3; | ||
25 | module_param(p_chmask, uint, S_IRUGO); | ||
26 | MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); | ||
27 | |||
28 | /* Playback Default 48 KHz */ | ||
29 | static int p_srate = 48000; | ||
30 | module_param(p_srate, uint, S_IRUGO); | ||
31 | MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); | ||
32 | |||
33 | /* Playback Default 16bits/sample */ | ||
34 | static int p_ssize = 2; | ||
35 | module_param(p_ssize, uint, S_IRUGO); | ||
36 | MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); | ||
37 | |||
38 | /* Capture(USB-OUT) Default Stereo - Fl/Fr */ | ||
39 | static int c_chmask = 0x3; | ||
40 | module_param(c_chmask, uint, S_IRUGO); | ||
41 | MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); | ||
42 | |||
43 | /* Capture Default 64 KHz */ | ||
44 | static int c_srate = 64000; | ||
45 | module_param(c_srate, uint, S_IRUGO); | ||
46 | MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); | ||
47 | |||
48 | /* Capture Default 16bits/sample */ | ||
49 | static int c_ssize = 2; | ||
50 | module_param(c_ssize, uint, S_IRUGO); | ||
51 | MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); | ||
52 | 24 | ||
53 | /* Keep everyone on toes */ | 25 | /* Keep everyone on toes */ |
54 | #define USB_XFERS 2 | 26 | #define USB_XFERS 2 |
@@ -120,6 +92,15 @@ struct snd_uac2_chip { | |||
120 | 92 | ||
121 | struct snd_card *card; | 93 | struct snd_card *card; |
122 | struct snd_pcm *pcm; | 94 | struct snd_pcm *pcm; |
95 | |||
96 | /* timekeeping for the playback endpoint */ | ||
97 | unsigned int p_interval; | ||
98 | unsigned int p_residue; | ||
99 | |||
100 | /* pre-calculated values for playback iso completion */ | ||
101 | unsigned int p_pktsize; | ||
102 | unsigned int p_pktsize_residue; | ||
103 | unsigned int p_framesize; | ||
123 | }; | 104 | }; |
124 | 105 | ||
125 | #define BUFF_SIZE_MAX (PAGE_SIZE * 16) | 106 | #define BUFF_SIZE_MAX (PAGE_SIZE * 16) |
@@ -149,8 +130,6 @@ struct audio_dev { | |||
149 | struct snd_uac2_chip uac2; | 130 | struct snd_uac2_chip uac2; |
150 | }; | 131 | }; |
151 | 132 | ||
152 | static struct audio_dev *agdev_g; | ||
153 | |||
154 | static inline | 133 | static inline |
155 | struct audio_dev *func_to_agdev(struct usb_function *f) | 134 | struct audio_dev *func_to_agdev(struct usb_function *f) |
156 | { | 135 | { |
@@ -170,6 +149,12 @@ struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p) | |||
170 | } | 149 | } |
171 | 150 | ||
172 | static inline | 151 | static inline |
152 | struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev) | ||
153 | { | ||
154 | return container_of(agdev->func.fi, struct f_uac2_opts, func_inst); | ||
155 | } | ||
156 | |||
157 | static inline | ||
173 | uint num_channels(uint chanmask) | 158 | uint num_channels(uint chanmask) |
174 | { | 159 | { |
175 | uint num = 0; | 160 | uint num = 0; |
@@ -187,8 +172,8 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) | |||
187 | { | 172 | { |
188 | unsigned pending; | 173 | unsigned pending; |
189 | unsigned long flags; | 174 | unsigned long flags; |
175 | unsigned int hw_ptr; | ||
190 | bool update_alsa = false; | 176 | bool update_alsa = false; |
191 | unsigned char *src, *dst; | ||
192 | int status = req->status; | 177 | int status = req->status; |
193 | struct uac2_req *ur = req->context; | 178 | struct uac2_req *ur = req->context; |
194 | struct snd_pcm_substream *substream; | 179 | struct snd_pcm_substream *substream; |
@@ -216,12 +201,27 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) | |||
216 | spin_lock_irqsave(&prm->lock, flags); | 201 | spin_lock_irqsave(&prm->lock, flags); |
217 | 202 | ||
218 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | 203 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
219 | src = prm->dma_area + prm->hw_ptr; | 204 | /* |
205 | * For each IN packet, take the quotient of the current data | ||
206 | * rate and the endpoint's interval as the base packet size. | ||
207 | * If there is a residue from this division, add it to the | ||
208 | * residue accumulator. | ||
209 | */ | ||
210 | req->length = uac2->p_pktsize; | ||
211 | uac2->p_residue += uac2->p_pktsize_residue; | ||
212 | |||
213 | /* | ||
214 | * Whenever there are more bytes in the accumulator than we | ||
215 | * need to add one more sample frame, increase this packet's | ||
216 | * size and decrease the accumulator. | ||
217 | */ | ||
218 | if (uac2->p_residue / uac2->p_interval >= uac2->p_framesize) { | ||
219 | req->length += uac2->p_framesize; | ||
220 | uac2->p_residue -= uac2->p_framesize * | ||
221 | uac2->p_interval; | ||
222 | } | ||
223 | |||
220 | req->actual = req->length; | 224 | req->actual = req->length; |
221 | dst = req->buf; | ||
222 | } else { | ||
223 | dst = prm->dma_area + prm->hw_ptr; | ||
224 | src = req->buf; | ||
225 | } | 225 | } |
226 | 226 | ||
227 | pending = prm->hw_ptr % prm->period_size; | 227 | pending = prm->hw_ptr % prm->period_size; |
@@ -229,12 +229,32 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) | |||
229 | if (pending >= prm->period_size) | 229 | if (pending >= prm->period_size) |
230 | update_alsa = true; | 230 | update_alsa = true; |
231 | 231 | ||
232 | hw_ptr = prm->hw_ptr; | ||
232 | prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes; | 233 | prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes; |
233 | 234 | ||
234 | spin_unlock_irqrestore(&prm->lock, flags); | 235 | spin_unlock_irqrestore(&prm->lock, flags); |
235 | 236 | ||
236 | /* Pack USB load in ALSA ring buffer */ | 237 | /* Pack USB load in ALSA ring buffer */ |
237 | memcpy(dst, src, req->actual); | 238 | pending = prm->dma_bytes - hw_ptr; |
239 | |||
240 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
241 | if (unlikely(pending < req->actual)) { | ||
242 | memcpy(req->buf, prm->dma_area + hw_ptr, pending); | ||
243 | memcpy(req->buf + pending, prm->dma_area, | ||
244 | req->actual - pending); | ||
245 | } else { | ||
246 | memcpy(req->buf, prm->dma_area + hw_ptr, req->actual); | ||
247 | } | ||
248 | } else { | ||
249 | if (unlikely(pending < req->actual)) { | ||
250 | memcpy(prm->dma_area + hw_ptr, req->buf, pending); | ||
251 | memcpy(prm->dma_area, req->buf + pending, | ||
252 | req->actual - pending); | ||
253 | } else { | ||
254 | memcpy(prm->dma_area + hw_ptr, req->buf, req->actual); | ||
255 | } | ||
256 | } | ||
257 | |||
238 | exit: | 258 | exit: |
239 | if (usb_ep_queue(ep, req, GFP_ATOMIC)) | 259 | if (usb_ep_queue(ep, req, GFP_ATOMIC)) |
240 | dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); | 260 | dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); |
@@ -342,6 +362,21 @@ static int uac2_pcm_open(struct snd_pcm_substream *substream) | |||
342 | { | 362 | { |
343 | struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream); | 363 | struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream); |
344 | struct snd_pcm_runtime *runtime = substream->runtime; | 364 | struct snd_pcm_runtime *runtime = substream->runtime; |
365 | struct audio_dev *audio_dev; | ||
366 | struct f_uac2_opts *opts; | ||
367 | int p_ssize, c_ssize; | ||
368 | int p_srate, c_srate; | ||
369 | int p_chmask, c_chmask; | ||
370 | |||
371 | audio_dev = uac2_to_agdev(uac2); | ||
372 | opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); | ||
373 | p_ssize = opts->p_ssize; | ||
374 | c_ssize = opts->c_ssize; | ||
375 | p_srate = opts->p_srate; | ||
376 | c_srate = opts->c_srate; | ||
377 | p_chmask = opts->p_chmask; | ||
378 | c_chmask = opts->c_chmask; | ||
379 | uac2->p_residue = 0; | ||
345 | 380 | ||
346 | runtime->hw = uac2_pcm_hardware; | 381 | runtime->hw = uac2_pcm_hardware; |
347 | 382 | ||
@@ -411,7 +446,15 @@ static int snd_uac2_probe(struct platform_device *pdev) | |||
411 | struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev); | 446 | struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev); |
412 | struct snd_card *card; | 447 | struct snd_card *card; |
413 | struct snd_pcm *pcm; | 448 | struct snd_pcm *pcm; |
449 | struct audio_dev *audio_dev; | ||
450 | struct f_uac2_opts *opts; | ||
414 | int err; | 451 | int err; |
452 | int p_chmask, c_chmask; | ||
453 | |||
454 | audio_dev = uac2_to_agdev(uac2); | ||
455 | opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); | ||
456 | p_chmask = opts->p_chmask; | ||
457 | c_chmask = opts->c_chmask; | ||
415 | 458 | ||
416 | /* Choose any slot, with no id */ | 459 | /* Choose any slot, with no id */ |
417 | err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card); | 460 | err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card); |
@@ -919,20 +962,58 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep) | |||
919 | "%s:%d Error!\n", __func__, __LINE__); | 962 | "%s:%d Error!\n", __func__, __LINE__); |
920 | } | 963 | } |
921 | 964 | ||
922 | static int __init | 965 | static int |
923 | afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | 966 | afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) |
924 | { | 967 | { |
925 | struct audio_dev *agdev = func_to_agdev(fn); | 968 | struct audio_dev *agdev = func_to_agdev(fn); |
926 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 969 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
927 | struct usb_composite_dev *cdev = cfg->cdev; | 970 | struct usb_composite_dev *cdev = cfg->cdev; |
928 | struct usb_gadget *gadget = cdev->gadget; | 971 | struct usb_gadget *gadget = cdev->gadget; |
972 | struct device *dev = &uac2->pdev.dev; | ||
929 | struct uac2_rtd_params *prm; | 973 | struct uac2_rtd_params *prm; |
974 | struct f_uac2_opts *uac2_opts; | ||
975 | struct usb_string *us; | ||
930 | int ret; | 976 | int ret; |
931 | 977 | ||
978 | uac2_opts = container_of(fn->fi, struct f_uac2_opts, func_inst); | ||
979 | |||
980 | us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); | ||
981 | if (IS_ERR(us)) | ||
982 | return PTR_ERR(us); | ||
983 | iad_desc.iFunction = us[STR_ASSOC].id; | ||
984 | std_ac_if_desc.iInterface = us[STR_IF_CTRL].id; | ||
985 | in_clk_src_desc.iClockSource = us[STR_CLKSRC_IN].id; | ||
986 | out_clk_src_desc.iClockSource = us[STR_CLKSRC_OUT].id; | ||
987 | usb_out_it_desc.iTerminal = us[STR_USB_IT].id; | ||
988 | io_in_it_desc.iTerminal = us[STR_IO_IT].id; | ||
989 | usb_in_ot_desc.iTerminal = us[STR_USB_OT].id; | ||
990 | io_out_ot_desc.iTerminal = us[STR_IO_OT].id; | ||
991 | std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id; | ||
992 | std_as_out_if1_desc.iInterface = us[STR_AS_OUT_ALT1].id; | ||
993 | std_as_in_if0_desc.iInterface = us[STR_AS_IN_ALT0].id; | ||
994 | std_as_in_if1_desc.iInterface = us[STR_AS_IN_ALT1].id; | ||
995 | |||
996 | |||
997 | /* Initialize the configurable parameters */ | ||
998 | usb_out_it_desc.bNrChannels = num_channels(uac2_opts->c_chmask); | ||
999 | usb_out_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); | ||
1000 | io_in_it_desc.bNrChannels = num_channels(uac2_opts->p_chmask); | ||
1001 | io_in_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); | ||
1002 | as_out_hdr_desc.bNrChannels = num_channels(uac2_opts->c_chmask); | ||
1003 | as_out_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); | ||
1004 | as_in_hdr_desc.bNrChannels = num_channels(uac2_opts->p_chmask); | ||
1005 | as_in_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); | ||
1006 | as_out_fmt1_desc.bSubslotSize = uac2_opts->c_ssize; | ||
1007 | as_out_fmt1_desc.bBitResolution = uac2_opts->c_ssize * 8; | ||
1008 | as_in_fmt1_desc.bSubslotSize = uac2_opts->p_ssize; | ||
1009 | as_in_fmt1_desc.bBitResolution = uac2_opts->p_ssize * 8; | ||
1010 | |||
1011 | snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", uac2_opts->p_srate); | ||
1012 | snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", uac2_opts->c_srate); | ||
1013 | |||
932 | ret = usb_interface_id(cfg, fn); | 1014 | ret = usb_interface_id(cfg, fn); |
933 | if (ret < 0) { | 1015 | if (ret < 0) { |
934 | dev_err(&uac2->pdev.dev, | 1016 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
935 | "%s:%d Error!\n", __func__, __LINE__); | ||
936 | return ret; | 1017 | return ret; |
937 | } | 1018 | } |
938 | std_ac_if_desc.bInterfaceNumber = ret; | 1019 | std_ac_if_desc.bInterfaceNumber = ret; |
@@ -941,8 +1022,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
941 | 1022 | ||
942 | ret = usb_interface_id(cfg, fn); | 1023 | ret = usb_interface_id(cfg, fn); |
943 | if (ret < 0) { | 1024 | if (ret < 0) { |
944 | dev_err(&uac2->pdev.dev, | 1025 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
945 | "%s:%d Error!\n", __func__, __LINE__); | ||
946 | return ret; | 1026 | return ret; |
947 | } | 1027 | } |
948 | std_as_out_if0_desc.bInterfaceNumber = ret; | 1028 | std_as_out_if0_desc.bInterfaceNumber = ret; |
@@ -952,8 +1032,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
952 | 1032 | ||
953 | ret = usb_interface_id(cfg, fn); | 1033 | ret = usb_interface_id(cfg, fn); |
954 | if (ret < 0) { | 1034 | if (ret < 0) { |
955 | dev_err(&uac2->pdev.dev, | 1035 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
956 | "%s:%d Error!\n", __func__, __LINE__); | ||
957 | return ret; | 1036 | return ret; |
958 | } | 1037 | } |
959 | std_as_in_if0_desc.bInterfaceNumber = ret; | 1038 | std_as_in_if0_desc.bInterfaceNumber = ret; |
@@ -963,16 +1042,14 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
963 | 1042 | ||
964 | agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); | 1043 | agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); |
965 | if (!agdev->out_ep) { | 1044 | if (!agdev->out_ep) { |
966 | dev_err(&uac2->pdev.dev, | 1045 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
967 | "%s:%d Error!\n", __func__, __LINE__); | ||
968 | goto err; | 1046 | goto err; |
969 | } | 1047 | } |
970 | agdev->out_ep->driver_data = agdev; | 1048 | agdev->out_ep->driver_data = agdev; |
971 | 1049 | ||
972 | agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc); | 1050 | agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc); |
973 | if (!agdev->in_ep) { | 1051 | if (!agdev->in_ep) { |
974 | dev_err(&uac2->pdev.dev, | 1052 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
975 | "%s:%d Error!\n", __func__, __LINE__); | ||
976 | goto err; | 1053 | goto err; |
977 | } | 1054 | } |
978 | agdev->in_ep->driver_data = agdev; | 1055 | agdev->in_ep->driver_data = agdev; |
@@ -1020,27 +1097,6 @@ err: | |||
1020 | return -EINVAL; | 1097 | return -EINVAL; |
1021 | } | 1098 | } |
1022 | 1099 | ||
1023 | static void | ||
1024 | afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn) | ||
1025 | { | ||
1026 | struct audio_dev *agdev = func_to_agdev(fn); | ||
1027 | struct uac2_rtd_params *prm; | ||
1028 | |||
1029 | alsa_uac2_exit(agdev); | ||
1030 | |||
1031 | prm = &agdev->uac2.p_prm; | ||
1032 | kfree(prm->rbuf); | ||
1033 | |||
1034 | prm = &agdev->uac2.c_prm; | ||
1035 | kfree(prm->rbuf); | ||
1036 | usb_free_all_descriptors(fn); | ||
1037 | |||
1038 | if (agdev->in_ep) | ||
1039 | agdev->in_ep->driver_data = NULL; | ||
1040 | if (agdev->out_ep) | ||
1041 | agdev->out_ep->driver_data = NULL; | ||
1042 | } | ||
1043 | |||
1044 | static int | 1100 | static int |
1045 | afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | 1101 | afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) |
1046 | { | 1102 | { |
@@ -1048,23 +1104,22 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | |||
1048 | struct audio_dev *agdev = func_to_agdev(fn); | 1104 | struct audio_dev *agdev = func_to_agdev(fn); |
1049 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 1105 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
1050 | struct usb_gadget *gadget = cdev->gadget; | 1106 | struct usb_gadget *gadget = cdev->gadget; |
1107 | struct device *dev = &uac2->pdev.dev; | ||
1051 | struct usb_request *req; | 1108 | struct usb_request *req; |
1052 | struct usb_ep *ep; | 1109 | struct usb_ep *ep; |
1053 | struct uac2_rtd_params *prm; | 1110 | struct uac2_rtd_params *prm; |
1054 | int i; | 1111 | int req_len, i; |
1055 | 1112 | ||
1056 | /* No i/f has more than 2 alt settings */ | 1113 | /* No i/f has more than 2 alt settings */ |
1057 | if (alt > 1) { | 1114 | if (alt > 1) { |
1058 | dev_err(&uac2->pdev.dev, | 1115 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
1059 | "%s:%d Error!\n", __func__, __LINE__); | ||
1060 | return -EINVAL; | 1116 | return -EINVAL; |
1061 | } | 1117 | } |
1062 | 1118 | ||
1063 | if (intf == agdev->ac_intf) { | 1119 | if (intf == agdev->ac_intf) { |
1064 | /* Control I/f has only 1 AltSetting - 0 */ | 1120 | /* Control I/f has only 1 AltSetting - 0 */ |
1065 | if (alt) { | 1121 | if (alt) { |
1066 | dev_err(&uac2->pdev.dev, | 1122 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
1067 | "%s:%d Error!\n", __func__, __LINE__); | ||
1068 | return -EINVAL; | 1123 | return -EINVAL; |
1069 | } | 1124 | } |
1070 | return 0; | 1125 | return 0; |
@@ -1075,14 +1130,43 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | |||
1075 | prm = &uac2->c_prm; | 1130 | prm = &uac2->c_prm; |
1076 | config_ep_by_speed(gadget, fn, ep); | 1131 | config_ep_by_speed(gadget, fn, ep); |
1077 | agdev->as_out_alt = alt; | 1132 | agdev->as_out_alt = alt; |
1133 | req_len = prm->max_psize; | ||
1078 | } else if (intf == agdev->as_in_intf) { | 1134 | } else if (intf == agdev->as_in_intf) { |
1135 | struct f_uac2_opts *opts = agdev_to_uac2_opts(agdev); | ||
1136 | unsigned int factor, rate; | ||
1137 | struct usb_endpoint_descriptor *ep_desc; | ||
1138 | |||
1079 | ep = agdev->in_ep; | 1139 | ep = agdev->in_ep; |
1080 | prm = &uac2->p_prm; | 1140 | prm = &uac2->p_prm; |
1081 | config_ep_by_speed(gadget, fn, ep); | 1141 | config_ep_by_speed(gadget, fn, ep); |
1082 | agdev->as_in_alt = alt; | 1142 | agdev->as_in_alt = alt; |
1143 | |||
1144 | /* pre-calculate the playback endpoint's interval */ | ||
1145 | if (gadget->speed == USB_SPEED_FULL) { | ||
1146 | ep_desc = &fs_epin_desc; | ||
1147 | factor = 1000; | ||
1148 | } else { | ||
1149 | ep_desc = &hs_epin_desc; | ||
1150 | factor = 125; | ||
1151 | } | ||
1152 | |||
1153 | /* pre-compute some values for iso_complete() */ | ||
1154 | uac2->p_framesize = opts->p_ssize * | ||
1155 | num_channels(opts->p_chmask); | ||
1156 | rate = opts->p_srate * uac2->p_framesize; | ||
1157 | uac2->p_interval = (1 << (ep_desc->bInterval - 1)) * factor; | ||
1158 | uac2->p_pktsize = min_t(unsigned int, rate / uac2->p_interval, | ||
1159 | prm->max_psize); | ||
1160 | |||
1161 | if (uac2->p_pktsize < prm->max_psize) | ||
1162 | uac2->p_pktsize_residue = rate % uac2->p_interval; | ||
1163 | else | ||
1164 | uac2->p_pktsize_residue = 0; | ||
1165 | |||
1166 | req_len = uac2->p_pktsize; | ||
1167 | uac2->p_residue = 0; | ||
1083 | } else { | 1168 | } else { |
1084 | dev_err(&uac2->pdev.dev, | 1169 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
1085 | "%s:%d Error!\n", __func__, __LINE__); | ||
1086 | return -EINVAL; | 1170 | return -EINVAL; |
1087 | } | 1171 | } |
1088 | 1172 | ||
@@ -1095,31 +1179,23 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) | |||
1095 | usb_ep_enable(ep); | 1179 | usb_ep_enable(ep); |
1096 | 1180 | ||
1097 | for (i = 0; i < USB_XFERS; i++) { | 1181 | for (i = 0; i < USB_XFERS; i++) { |
1098 | if (prm->ureq[i].req) { | 1182 | if (!prm->ureq[i].req) { |
1099 | if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) | 1183 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); |
1100 | dev_err(&uac2->pdev.dev, "%d Error!\n", | 1184 | if (req == NULL) |
1101 | __LINE__); | 1185 | return -ENOMEM; |
1102 | continue; | 1186 | |
1103 | } | 1187 | prm->ureq[i].req = req; |
1104 | 1188 | prm->ureq[i].pp = prm; | |
1105 | req = usb_ep_alloc_request(ep, GFP_ATOMIC); | 1189 | |
1106 | if (req == NULL) { | 1190 | req->zero = 0; |
1107 | dev_err(&uac2->pdev.dev, | 1191 | req->context = &prm->ureq[i]; |
1108 | "%s:%d Error!\n", __func__, __LINE__); | 1192 | req->length = req_len; |
1109 | return -EINVAL; | 1193 | req->complete = agdev_iso_complete; |
1194 | req->buf = prm->rbuf + i * prm->max_psize; | ||
1110 | } | 1195 | } |
1111 | 1196 | ||
1112 | prm->ureq[i].req = req; | 1197 | if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) |
1113 | prm->ureq[i].pp = prm; | 1198 | dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); |
1114 | |||
1115 | req->zero = 0; | ||
1116 | req->context = &prm->ureq[i]; | ||
1117 | req->length = prm->max_psize; | ||
1118 | req->complete = agdev_iso_complete; | ||
1119 | req->buf = prm->rbuf + i * req->length; | ||
1120 | |||
1121 | if (usb_ep_queue(ep, req, GFP_ATOMIC)) | ||
1122 | dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); | ||
1123 | } | 1199 | } |
1124 | 1200 | ||
1125 | return 0; | 1201 | return 0; |
@@ -1164,12 +1240,18 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) | |||
1164 | struct usb_request *req = fn->config->cdev->req; | 1240 | struct usb_request *req = fn->config->cdev->req; |
1165 | struct audio_dev *agdev = func_to_agdev(fn); | 1241 | struct audio_dev *agdev = func_to_agdev(fn); |
1166 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 1242 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
1243 | struct f_uac2_opts *opts; | ||
1167 | u16 w_length = le16_to_cpu(cr->wLength); | 1244 | u16 w_length = le16_to_cpu(cr->wLength); |
1168 | u16 w_index = le16_to_cpu(cr->wIndex); | 1245 | u16 w_index = le16_to_cpu(cr->wIndex); |
1169 | u16 w_value = le16_to_cpu(cr->wValue); | 1246 | u16 w_value = le16_to_cpu(cr->wValue); |
1170 | u8 entity_id = (w_index >> 8) & 0xff; | 1247 | u8 entity_id = (w_index >> 8) & 0xff; |
1171 | u8 control_selector = w_value >> 8; | 1248 | u8 control_selector = w_value >> 8; |
1172 | int value = -EOPNOTSUPP; | 1249 | int value = -EOPNOTSUPP; |
1250 | int p_srate, c_srate; | ||
1251 | |||
1252 | opts = agdev_to_uac2_opts(agdev); | ||
1253 | p_srate = opts->p_srate; | ||
1254 | c_srate = opts->c_srate; | ||
1173 | 1255 | ||
1174 | if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { | 1256 | if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { |
1175 | struct cntrl_cur_lay3 c; | 1257 | struct cntrl_cur_lay3 c; |
@@ -1199,6 +1281,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) | |||
1199 | struct usb_request *req = fn->config->cdev->req; | 1281 | struct usb_request *req = fn->config->cdev->req; |
1200 | struct audio_dev *agdev = func_to_agdev(fn); | 1282 | struct audio_dev *agdev = func_to_agdev(fn); |
1201 | struct snd_uac2_chip *uac2 = &agdev->uac2; | 1283 | struct snd_uac2_chip *uac2 = &agdev->uac2; |
1284 | struct f_uac2_opts *opts; | ||
1202 | u16 w_length = le16_to_cpu(cr->wLength); | 1285 | u16 w_length = le16_to_cpu(cr->wLength); |
1203 | u16 w_index = le16_to_cpu(cr->wIndex); | 1286 | u16 w_index = le16_to_cpu(cr->wIndex); |
1204 | u16 w_value = le16_to_cpu(cr->wValue); | 1287 | u16 w_value = le16_to_cpu(cr->wValue); |
@@ -1206,6 +1289,11 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) | |||
1206 | u8 control_selector = w_value >> 8; | 1289 | u8 control_selector = w_value >> 8; |
1207 | struct cntrl_range_lay3 r; | 1290 | struct cntrl_range_lay3 r; |
1208 | int value = -EOPNOTSUPP; | 1291 | int value = -EOPNOTSUPP; |
1292 | int p_srate, c_srate; | ||
1293 | |||
1294 | opts = agdev_to_uac2_opts(agdev); | ||
1295 | p_srate = opts->p_srate; | ||
1296 | c_srate = opts->c_srate; | ||
1209 | 1297 | ||
1210 | if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { | 1298 | if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { |
1211 | if (entity_id == USB_IN_CLK_ID) | 1299 | if (entity_id == USB_IN_CLK_ID) |
@@ -1309,66 +1397,184 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr) | |||
1309 | return value; | 1397 | return value; |
1310 | } | 1398 | } |
1311 | 1399 | ||
1312 | static int audio_bind_config(struct usb_configuration *cfg) | 1400 | static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item) |
1313 | { | 1401 | { |
1314 | int res; | 1402 | return container_of(to_config_group(item), struct f_uac2_opts, |
1315 | 1403 | func_inst.group); | |
1316 | agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL); | 1404 | } |
1317 | if (agdev_g == NULL) | ||
1318 | return -ENOMEM; | ||
1319 | |||
1320 | res = usb_string_ids_tab(cfg->cdev, strings_fn); | ||
1321 | if (res) | ||
1322 | return res; | ||
1323 | iad_desc.iFunction = strings_fn[STR_ASSOC].id; | ||
1324 | std_ac_if_desc.iInterface = strings_fn[STR_IF_CTRL].id; | ||
1325 | in_clk_src_desc.iClockSource = strings_fn[STR_CLKSRC_IN].id; | ||
1326 | out_clk_src_desc.iClockSource = strings_fn[STR_CLKSRC_OUT].id; | ||
1327 | usb_out_it_desc.iTerminal = strings_fn[STR_USB_IT].id; | ||
1328 | io_in_it_desc.iTerminal = strings_fn[STR_IO_IT].id; | ||
1329 | usb_in_ot_desc.iTerminal = strings_fn[STR_USB_OT].id; | ||
1330 | io_out_ot_desc.iTerminal = strings_fn[STR_IO_OT].id; | ||
1331 | std_as_out_if0_desc.iInterface = strings_fn[STR_AS_OUT_ALT0].id; | ||
1332 | std_as_out_if1_desc.iInterface = strings_fn[STR_AS_OUT_ALT1].id; | ||
1333 | std_as_in_if0_desc.iInterface = strings_fn[STR_AS_IN_ALT0].id; | ||
1334 | std_as_in_if1_desc.iInterface = strings_fn[STR_AS_IN_ALT1].id; | ||
1335 | |||
1336 | agdev_g->func.name = "uac2_func"; | ||
1337 | agdev_g->func.strings = fn_strings; | ||
1338 | agdev_g->func.bind = afunc_bind; | ||
1339 | agdev_g->func.unbind = afunc_unbind; | ||
1340 | agdev_g->func.set_alt = afunc_set_alt; | ||
1341 | agdev_g->func.get_alt = afunc_get_alt; | ||
1342 | agdev_g->func.disable = afunc_disable; | ||
1343 | agdev_g->func.setup = afunc_setup; | ||
1344 | 1405 | ||
1345 | /* Initialize the configurable parameters */ | 1406 | CONFIGFS_ATTR_STRUCT(f_uac2_opts); |
1346 | usb_out_it_desc.bNrChannels = num_channels(c_chmask); | 1407 | CONFIGFS_ATTR_OPS(f_uac2_opts); |
1347 | usb_out_it_desc.bmChannelConfig = cpu_to_le32(c_chmask); | 1408 | |
1348 | io_in_it_desc.bNrChannels = num_channels(p_chmask); | 1409 | static void f_uac2_attr_release(struct config_item *item) |
1349 | io_in_it_desc.bmChannelConfig = cpu_to_le32(p_chmask); | 1410 | { |
1350 | as_out_hdr_desc.bNrChannels = num_channels(c_chmask); | 1411 | struct f_uac2_opts *opts = to_f_uac2_opts(item); |
1351 | as_out_hdr_desc.bmChannelConfig = cpu_to_le32(c_chmask); | 1412 | |
1352 | as_in_hdr_desc.bNrChannels = num_channels(p_chmask); | 1413 | usb_put_function_instance(&opts->func_inst); |
1353 | as_in_hdr_desc.bmChannelConfig = cpu_to_le32(p_chmask); | ||
1354 | as_out_fmt1_desc.bSubslotSize = c_ssize; | ||
1355 | as_out_fmt1_desc.bBitResolution = c_ssize * 8; | ||
1356 | as_in_fmt1_desc.bSubslotSize = p_ssize; | ||
1357 | as_in_fmt1_desc.bBitResolution = p_ssize * 8; | ||
1358 | |||
1359 | snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", p_srate); | ||
1360 | snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", c_srate); | ||
1361 | |||
1362 | res = usb_add_function(cfg, &agdev_g->func); | ||
1363 | if (res < 0) | ||
1364 | kfree(agdev_g); | ||
1365 | |||
1366 | return res; | ||
1367 | } | 1414 | } |
1368 | 1415 | ||
1369 | static void | 1416 | static struct configfs_item_operations f_uac2_item_ops = { |
1370 | uac2_unbind_config(struct usb_configuration *cfg) | 1417 | .release = f_uac2_attr_release, |
1418 | .show_attribute = f_uac2_opts_attr_show, | ||
1419 | .store_attribute = f_uac2_opts_attr_store, | ||
1420 | }; | ||
1421 | |||
1422 | #define UAC2_ATTRIBUTE(name) \ | ||
1423 | static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \ | ||
1424 | char *page) \ | ||
1425 | { \ | ||
1426 | int result; \ | ||
1427 | \ | ||
1428 | mutex_lock(&opts->lock); \ | ||
1429 | result = sprintf(page, "%u\n", opts->name); \ | ||
1430 | mutex_unlock(&opts->lock); \ | ||
1431 | \ | ||
1432 | return result; \ | ||
1433 | } \ | ||
1434 | \ | ||
1435 | static ssize_t f_uac2_opts_##name##_store(struct f_uac2_opts *opts, \ | ||
1436 | const char *page, size_t len) \ | ||
1437 | { \ | ||
1438 | int ret; \ | ||
1439 | u32 num; \ | ||
1440 | \ | ||
1441 | mutex_lock(&opts->lock); \ | ||
1442 | if (opts->refcnt) { \ | ||
1443 | ret = -EBUSY; \ | ||
1444 | goto end; \ | ||
1445 | } \ | ||
1446 | \ | ||
1447 | ret = kstrtou32(page, 0, &num); \ | ||
1448 | if (ret) \ | ||
1449 | goto end; \ | ||
1450 | \ | ||
1451 | opts->name = num; \ | ||
1452 | ret = len; \ | ||
1453 | \ | ||
1454 | end: \ | ||
1455 | mutex_unlock(&opts->lock); \ | ||
1456 | return ret; \ | ||
1457 | } \ | ||
1458 | \ | ||
1459 | static struct f_uac2_opts_attribute f_uac2_opts_##name = \ | ||
1460 | __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ | ||
1461 | f_uac2_opts_##name##_show, \ | ||
1462 | f_uac2_opts_##name##_store) | ||
1463 | |||
1464 | UAC2_ATTRIBUTE(p_chmask); | ||
1465 | UAC2_ATTRIBUTE(p_srate); | ||
1466 | UAC2_ATTRIBUTE(p_ssize); | ||
1467 | UAC2_ATTRIBUTE(c_chmask); | ||
1468 | UAC2_ATTRIBUTE(c_srate); | ||
1469 | UAC2_ATTRIBUTE(c_ssize); | ||
1470 | |||
1471 | static struct configfs_attribute *f_uac2_attrs[] = { | ||
1472 | &f_uac2_opts_p_chmask.attr, | ||
1473 | &f_uac2_opts_p_srate.attr, | ||
1474 | &f_uac2_opts_p_ssize.attr, | ||
1475 | &f_uac2_opts_c_chmask.attr, | ||
1476 | &f_uac2_opts_c_srate.attr, | ||
1477 | &f_uac2_opts_c_ssize.attr, | ||
1478 | NULL, | ||
1479 | }; | ||
1480 | |||
1481 | static struct config_item_type f_uac2_func_type = { | ||
1482 | .ct_item_ops = &f_uac2_item_ops, | ||
1483 | .ct_attrs = f_uac2_attrs, | ||
1484 | .ct_owner = THIS_MODULE, | ||
1485 | }; | ||
1486 | |||
1487 | static void afunc_free_inst(struct usb_function_instance *f) | ||
1371 | { | 1488 | { |
1372 | kfree(agdev_g); | 1489 | struct f_uac2_opts *opts; |
1373 | agdev_g = NULL; | 1490 | |
1491 | opts = container_of(f, struct f_uac2_opts, func_inst); | ||
1492 | kfree(opts); | ||
1374 | } | 1493 | } |
1494 | |||
1495 | static struct usb_function_instance *afunc_alloc_inst(void) | ||
1496 | { | ||
1497 | struct f_uac2_opts *opts; | ||
1498 | |||
1499 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
1500 | if (!opts) | ||
1501 | return ERR_PTR(-ENOMEM); | ||
1502 | |||
1503 | mutex_init(&opts->lock); | ||
1504 | opts->func_inst.free_func_inst = afunc_free_inst; | ||
1505 | |||
1506 | config_group_init_type_name(&opts->func_inst.group, "", | ||
1507 | &f_uac2_func_type); | ||
1508 | |||
1509 | opts->p_chmask = UAC2_DEF_PCHMASK; | ||
1510 | opts->p_srate = UAC2_DEF_PSRATE; | ||
1511 | opts->p_ssize = UAC2_DEF_PSSIZE; | ||
1512 | opts->c_chmask = UAC2_DEF_CCHMASK; | ||
1513 | opts->c_srate = UAC2_DEF_CSRATE; | ||
1514 | opts->c_ssize = UAC2_DEF_CSSIZE; | ||
1515 | return &opts->func_inst; | ||
1516 | } | ||
1517 | |||
1518 | static void afunc_free(struct usb_function *f) | ||
1519 | { | ||
1520 | struct audio_dev *agdev; | ||
1521 | struct f_uac2_opts *opts; | ||
1522 | |||
1523 | agdev = func_to_agdev(f); | ||
1524 | opts = container_of(f->fi, struct f_uac2_opts, func_inst); | ||
1525 | kfree(agdev); | ||
1526 | mutex_lock(&opts->lock); | ||
1527 | --opts->refcnt; | ||
1528 | mutex_unlock(&opts->lock); | ||
1529 | } | ||
1530 | |||
1531 | static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) | ||
1532 | { | ||
1533 | struct audio_dev *agdev = func_to_agdev(f); | ||
1534 | struct uac2_rtd_params *prm; | ||
1535 | |||
1536 | alsa_uac2_exit(agdev); | ||
1537 | |||
1538 | prm = &agdev->uac2.p_prm; | ||
1539 | kfree(prm->rbuf); | ||
1540 | |||
1541 | prm = &agdev->uac2.c_prm; | ||
1542 | kfree(prm->rbuf); | ||
1543 | usb_free_all_descriptors(f); | ||
1544 | |||
1545 | if (agdev->in_ep) | ||
1546 | agdev->in_ep->driver_data = NULL; | ||
1547 | if (agdev->out_ep) | ||
1548 | agdev->out_ep->driver_data = NULL; | ||
1549 | } | ||
1550 | |||
1551 | struct usb_function *afunc_alloc(struct usb_function_instance *fi) | ||
1552 | { | ||
1553 | struct audio_dev *agdev; | ||
1554 | struct f_uac2_opts *opts; | ||
1555 | |||
1556 | agdev = kzalloc(sizeof(*agdev), GFP_KERNEL); | ||
1557 | if (agdev == NULL) | ||
1558 | return ERR_PTR(-ENOMEM); | ||
1559 | |||
1560 | opts = container_of(fi, struct f_uac2_opts, func_inst); | ||
1561 | mutex_lock(&opts->lock); | ||
1562 | ++opts->refcnt; | ||
1563 | mutex_unlock(&opts->lock); | ||
1564 | |||
1565 | agdev->func.name = "uac2_func"; | ||
1566 | agdev->func.bind = afunc_bind; | ||
1567 | agdev->func.unbind = afunc_unbind; | ||
1568 | agdev->func.set_alt = afunc_set_alt; | ||
1569 | agdev->func.get_alt = afunc_get_alt; | ||
1570 | agdev->func.disable = afunc_disable; | ||
1571 | agdev->func.setup = afunc_setup; | ||
1572 | agdev->func.free_func = afunc_free; | ||
1573 | |||
1574 | return &agdev->func; | ||
1575 | } | ||
1576 | |||
1577 | DECLARE_USB_FUNCTION_INIT(uac2, afunc_alloc_inst, afunc_alloc); | ||
1578 | MODULE_LICENSE("GPL"); | ||
1579 | MODULE_AUTHOR("Yadwinder Singh"); | ||
1580 | MODULE_AUTHOR("Jaswinder Singh"); | ||
diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index e2a1f50bd93c..e126439e4b65 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
16 | #include <linux/fs.h> | 17 | #include <linux/fs.h> |
@@ -27,24 +28,12 @@ | |||
27 | #include <media/v4l2-event.h> | 28 | #include <media/v4l2-event.h> |
28 | 29 | ||
29 | #include "uvc.h" | 30 | #include "uvc.h" |
31 | #include "uvc_v4l2.h" | ||
32 | #include "uvc_video.h" | ||
33 | #include "u_uvc.h" | ||
30 | 34 | ||
31 | unsigned int uvc_gadget_trace_param; | 35 | unsigned int uvc_gadget_trace_param; |
32 | 36 | ||
33 | /*-------------------------------------------------------------------------*/ | ||
34 | |||
35 | /* module parameters specific to the Video streaming endpoint */ | ||
36 | static unsigned int streaming_interval = 1; | ||
37 | module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); | ||
38 | MODULE_PARM_DESC(streaming_interval, "1 - 16"); | ||
39 | |||
40 | static unsigned int streaming_maxpacket = 1024; | ||
41 | module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); | ||
42 | MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)"); | ||
43 | |||
44 | static unsigned int streaming_maxburst; | ||
45 | module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); | ||
46 | MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); | ||
47 | |||
48 | /* -------------------------------------------------------------------------- | 37 | /* -------------------------------------------------------------------------- |
49 | * Function descriptors | 38 | * Function descriptors |
50 | */ | 39 | */ |
@@ -75,7 +64,7 @@ static struct usb_gadget_strings *uvc_function_strings[] = { | |||
75 | 64 | ||
76 | #define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */ | 65 | #define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */ |
77 | 66 | ||
78 | static struct usb_interface_assoc_descriptor uvc_iad __initdata = { | 67 | static struct usb_interface_assoc_descriptor uvc_iad = { |
79 | .bLength = sizeof(uvc_iad), | 68 | .bLength = sizeof(uvc_iad), |
80 | .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, | 69 | .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, |
81 | .bFirstInterface = 0, | 70 | .bFirstInterface = 0, |
@@ -86,7 +75,7 @@ static struct usb_interface_assoc_descriptor uvc_iad __initdata = { | |||
86 | .iFunction = 0, | 75 | .iFunction = 0, |
87 | }; | 76 | }; |
88 | 77 | ||
89 | static struct usb_interface_descriptor uvc_control_intf __initdata = { | 78 | static struct usb_interface_descriptor uvc_control_intf = { |
90 | .bLength = USB_DT_INTERFACE_SIZE, | 79 | .bLength = USB_DT_INTERFACE_SIZE, |
91 | .bDescriptorType = USB_DT_INTERFACE, | 80 | .bDescriptorType = USB_DT_INTERFACE, |
92 | .bInterfaceNumber = UVC_INTF_VIDEO_CONTROL, | 81 | .bInterfaceNumber = UVC_INTF_VIDEO_CONTROL, |
@@ -98,7 +87,7 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = { | |||
98 | .iInterface = 0, | 87 | .iInterface = 0, |
99 | }; | 88 | }; |
100 | 89 | ||
101 | static struct usb_endpoint_descriptor uvc_control_ep __initdata = { | 90 | static struct usb_endpoint_descriptor uvc_control_ep = { |
102 | .bLength = USB_DT_ENDPOINT_SIZE, | 91 | .bLength = USB_DT_ENDPOINT_SIZE, |
103 | .bDescriptorType = USB_DT_ENDPOINT, | 92 | .bDescriptorType = USB_DT_ENDPOINT, |
104 | .bEndpointAddress = USB_DIR_IN, | 93 | .bEndpointAddress = USB_DIR_IN, |
@@ -107,7 +96,7 @@ static struct usb_endpoint_descriptor uvc_control_ep __initdata = { | |||
107 | .bInterval = 8, | 96 | .bInterval = 8, |
108 | }; | 97 | }; |
109 | 98 | ||
110 | static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = { | 99 | static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp = { |
111 | .bLength = sizeof(uvc_ss_control_comp), | 100 | .bLength = sizeof(uvc_ss_control_comp), |
112 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 101 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
113 | /* The following 3 values can be tweaked if necessary. */ | 102 | /* The following 3 values can be tweaked if necessary. */ |
@@ -116,14 +105,14 @@ static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = { | |||
116 | .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), | 105 | .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), |
117 | }; | 106 | }; |
118 | 107 | ||
119 | static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { | 108 | static struct uvc_control_endpoint_descriptor uvc_control_cs_ep = { |
120 | .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, | 109 | .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, |
121 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 110 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
122 | .bDescriptorSubType = UVC_EP_INTERRUPT, | 111 | .bDescriptorSubType = UVC_EP_INTERRUPT, |
123 | .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), | 112 | .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), |
124 | }; | 113 | }; |
125 | 114 | ||
126 | static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { | 115 | static struct usb_interface_descriptor uvc_streaming_intf_alt0 = { |
127 | .bLength = USB_DT_INTERFACE_SIZE, | 116 | .bLength = USB_DT_INTERFACE_SIZE, |
128 | .bDescriptorType = USB_DT_INTERFACE, | 117 | .bDescriptorType = USB_DT_INTERFACE, |
129 | .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, | 118 | .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, |
@@ -135,7 +124,7 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { | |||
135 | .iInterface = 0, | 124 | .iInterface = 0, |
136 | }; | 125 | }; |
137 | 126 | ||
138 | static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = { | 127 | static struct usb_interface_descriptor uvc_streaming_intf_alt1 = { |
139 | .bLength = USB_DT_INTERFACE_SIZE, | 128 | .bLength = USB_DT_INTERFACE_SIZE, |
140 | .bDescriptorType = USB_DT_INTERFACE, | 129 | .bDescriptorType = USB_DT_INTERFACE, |
141 | .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, | 130 | .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, |
@@ -147,7 +136,7 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = { | |||
147 | .iInterface = 0, | 136 | .iInterface = 0, |
148 | }; | 137 | }; |
149 | 138 | ||
150 | static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = { | 139 | static struct usb_endpoint_descriptor uvc_fs_streaming_ep = { |
151 | .bLength = USB_DT_ENDPOINT_SIZE, | 140 | .bLength = USB_DT_ENDPOINT_SIZE, |
152 | .bDescriptorType = USB_DT_ENDPOINT, | 141 | .bDescriptorType = USB_DT_ENDPOINT, |
153 | .bEndpointAddress = USB_DIR_IN, | 142 | .bEndpointAddress = USB_DIR_IN, |
@@ -158,7 +147,7 @@ static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = { | |||
158 | */ | 147 | */ |
159 | }; | 148 | }; |
160 | 149 | ||
161 | static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = { | 150 | static struct usb_endpoint_descriptor uvc_hs_streaming_ep = { |
162 | .bLength = USB_DT_ENDPOINT_SIZE, | 151 | .bLength = USB_DT_ENDPOINT_SIZE, |
163 | .bDescriptorType = USB_DT_ENDPOINT, | 152 | .bDescriptorType = USB_DT_ENDPOINT, |
164 | .bEndpointAddress = USB_DIR_IN, | 153 | .bEndpointAddress = USB_DIR_IN, |
@@ -169,7 +158,7 @@ static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = { | |||
169 | */ | 158 | */ |
170 | }; | 159 | }; |
171 | 160 | ||
172 | static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { | 161 | static struct usb_endpoint_descriptor uvc_ss_streaming_ep = { |
173 | .bLength = USB_DT_ENDPOINT_SIZE, | 162 | .bLength = USB_DT_ENDPOINT_SIZE, |
174 | .bDescriptorType = USB_DT_ENDPOINT, | 163 | .bDescriptorType = USB_DT_ENDPOINT, |
175 | 164 | ||
@@ -181,7 +170,7 @@ static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { | |||
181 | */ | 170 | */ |
182 | }; | 171 | }; |
183 | 172 | ||
184 | static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = { | 173 | static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { |
185 | .bLength = sizeof(uvc_ss_streaming_comp), | 174 | .bLength = sizeof(uvc_ss_streaming_comp), |
186 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | 175 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, |
187 | /* The bMaxBurst, bmAttributes and wBytesPerInterval values will be | 176 | /* The bMaxBurst, bmAttributes and wBytesPerInterval values will be |
@@ -208,6 +197,12 @@ static const struct usb_descriptor_header * const uvc_ss_streaming[] = { | |||
208 | NULL, | 197 | NULL, |
209 | }; | 198 | }; |
210 | 199 | ||
200 | void uvc_set_trace_param(unsigned int trace) | ||
201 | { | ||
202 | uvc_gadget_trace_param = trace; | ||
203 | } | ||
204 | EXPORT_SYMBOL(uvc_set_trace_param); | ||
205 | |||
211 | /* -------------------------------------------------------------------------- | 206 | /* -------------------------------------------------------------------------- |
212 | * Control requests | 207 | * Control requests |
213 | */ | 208 | */ |
@@ -251,6 +246,12 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) | |||
251 | if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE) | 246 | if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE) |
252 | return -EINVAL; | 247 | return -EINVAL; |
253 | 248 | ||
249 | /* Tell the complete callback to generate an event for the next request | ||
250 | * that will be enqueued by UVCIOC_SEND_RESPONSE. | ||
251 | */ | ||
252 | uvc->event_setup_out = !(ctrl->bRequestType & USB_DIR_IN); | ||
253 | uvc->event_length = le16_to_cpu(ctrl->wLength); | ||
254 | |||
254 | memset(&v4l2_event, 0, sizeof(v4l2_event)); | 255 | memset(&v4l2_event, 0, sizeof(v4l2_event)); |
255 | v4l2_event.type = UVC_EVENT_SETUP; | 256 | v4l2_event.type = UVC_EVENT_SETUP; |
256 | memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); | 257 | memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req)); |
@@ -408,7 +409,9 @@ uvc_register_video(struct uvc_device *uvc) | |||
408 | 409 | ||
409 | video->v4l2_dev = &uvc->v4l2_dev; | 410 | video->v4l2_dev = &uvc->v4l2_dev; |
410 | video->fops = &uvc_v4l2_fops; | 411 | video->fops = &uvc_v4l2_fops; |
412 | video->ioctl_ops = &uvc_v4l2_ioctl_ops; | ||
411 | video->release = video_device_release; | 413 | video->release = video_device_release; |
414 | video->vfl_dir = VFL_DIR_TX; | ||
412 | strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); | 415 | strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); |
413 | 416 | ||
414 | uvc->vdev = video; | 417 | uvc->vdev = video; |
@@ -434,7 +437,7 @@ uvc_register_video(struct uvc_device *uvc) | |||
434 | } \ | 437 | } \ |
435 | } while (0) | 438 | } while (0) |
436 | 439 | ||
437 | static struct usb_descriptor_header ** __init | 440 | static struct usb_descriptor_header ** |
438 | uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | 441 | uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) |
439 | { | 442 | { |
440 | struct uvc_input_header_descriptor *uvc_streaming_header; | 443 | struct uvc_input_header_descriptor *uvc_streaming_header; |
@@ -554,45 +557,26 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) | |||
554 | return hdr; | 557 | return hdr; |
555 | } | 558 | } |
556 | 559 | ||
557 | static void | 560 | static int |
558 | uvc_function_unbind(struct usb_configuration *c, struct usb_function *f) | ||
559 | { | ||
560 | struct usb_composite_dev *cdev = c->cdev; | ||
561 | struct uvc_device *uvc = to_uvc(f); | ||
562 | |||
563 | INFO(cdev, "uvc_function_unbind\n"); | ||
564 | |||
565 | video_unregister_device(uvc->vdev); | ||
566 | v4l2_device_unregister(&uvc->v4l2_dev); | ||
567 | uvc->control_ep->driver_data = NULL; | ||
568 | uvc->video.ep->driver_data = NULL; | ||
569 | |||
570 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = 0; | ||
571 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); | ||
572 | kfree(uvc->control_buf); | ||
573 | |||
574 | usb_free_all_descriptors(f); | ||
575 | |||
576 | kfree(uvc); | ||
577 | } | ||
578 | |||
579 | static int __init | ||
580 | uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | 561 | uvc_function_bind(struct usb_configuration *c, struct usb_function *f) |
581 | { | 562 | { |
582 | struct usb_composite_dev *cdev = c->cdev; | 563 | struct usb_composite_dev *cdev = c->cdev; |
583 | struct uvc_device *uvc = to_uvc(f); | 564 | struct uvc_device *uvc = to_uvc(f); |
565 | struct usb_string *us; | ||
584 | unsigned int max_packet_mult; | 566 | unsigned int max_packet_mult; |
585 | unsigned int max_packet_size; | 567 | unsigned int max_packet_size; |
586 | struct usb_ep *ep; | 568 | struct usb_ep *ep; |
569 | struct f_uvc_opts *opts; | ||
587 | int ret = -EINVAL; | 570 | int ret = -EINVAL; |
588 | 571 | ||
589 | INFO(cdev, "uvc_function_bind\n"); | 572 | INFO(cdev, "uvc_function_bind\n"); |
590 | 573 | ||
574 | opts = to_f_uvc_opts(f->fi); | ||
591 | /* Sanity check the streaming endpoint module parameters. | 575 | /* Sanity check the streaming endpoint module parameters. |
592 | */ | 576 | */ |
593 | streaming_interval = clamp(streaming_interval, 1U, 16U); | 577 | opts->streaming_interval = clamp(opts->streaming_interval, 1U, 16U); |
594 | streaming_maxpacket = clamp(streaming_maxpacket, 1U, 3072U); | 578 | opts->streaming_maxpacket = clamp(opts->streaming_maxpacket, 1U, 3072U); |
595 | streaming_maxburst = min(streaming_maxburst, 15U); | 579 | opts->streaming_maxburst = min(opts->streaming_maxburst, 15U); |
596 | 580 | ||
597 | /* Fill in the FS/HS/SS Video Streaming specific descriptors from the | 581 | /* Fill in the FS/HS/SS Video Streaming specific descriptors from the |
598 | * module parameters. | 582 | * module parameters. |
@@ -600,30 +584,32 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
600 | * NOTE: We assume that the user knows what they are doing and won't | 584 | * NOTE: We assume that the user knows what they are doing and won't |
601 | * give parameters that their UDC doesn't support. | 585 | * give parameters that their UDC doesn't support. |
602 | */ | 586 | */ |
603 | if (streaming_maxpacket <= 1024) { | 587 | if (opts->streaming_maxpacket <= 1024) { |
604 | max_packet_mult = 1; | 588 | max_packet_mult = 1; |
605 | max_packet_size = streaming_maxpacket; | 589 | max_packet_size = opts->streaming_maxpacket; |
606 | } else if (streaming_maxpacket <= 2048) { | 590 | } else if (opts->streaming_maxpacket <= 2048) { |
607 | max_packet_mult = 2; | 591 | max_packet_mult = 2; |
608 | max_packet_size = streaming_maxpacket / 2; | 592 | max_packet_size = opts->streaming_maxpacket / 2; |
609 | } else { | 593 | } else { |
610 | max_packet_mult = 3; | 594 | max_packet_mult = 3; |
611 | max_packet_size = streaming_maxpacket / 3; | 595 | max_packet_size = opts->streaming_maxpacket / 3; |
612 | } | 596 | } |
613 | 597 | ||
614 | uvc_fs_streaming_ep.wMaxPacketSize = min(streaming_maxpacket, 1023U); | 598 | uvc_fs_streaming_ep.wMaxPacketSize = |
615 | uvc_fs_streaming_ep.bInterval = streaming_interval; | 599 | cpu_to_le16(min(opts->streaming_maxpacket, 1023U)); |
600 | uvc_fs_streaming_ep.bInterval = opts->streaming_interval; | ||
616 | 601 | ||
617 | uvc_hs_streaming_ep.wMaxPacketSize = max_packet_size; | 602 | uvc_hs_streaming_ep.wMaxPacketSize = |
618 | uvc_hs_streaming_ep.wMaxPacketSize |= ((max_packet_mult - 1) << 11); | 603 | cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11)); |
619 | uvc_hs_streaming_ep.bInterval = streaming_interval; | 604 | uvc_hs_streaming_ep.bInterval = opts->streaming_interval; |
620 | 605 | ||
621 | uvc_ss_streaming_ep.wMaxPacketSize = max_packet_size; | 606 | uvc_ss_streaming_ep.wMaxPacketSize = cpu_to_le16(max_packet_size); |
622 | uvc_ss_streaming_ep.bInterval = streaming_interval; | 607 | uvc_ss_streaming_ep.bInterval = opts->streaming_interval; |
623 | uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1; | 608 | uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1; |
624 | uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst; | 609 | uvc_ss_streaming_comp.bMaxBurst = opts->streaming_maxburst; |
625 | uvc_ss_streaming_comp.wBytesPerInterval = | 610 | uvc_ss_streaming_comp.wBytesPerInterval = |
626 | max_packet_size * max_packet_mult * streaming_maxburst; | 611 | cpu_to_le16(max_packet_size * max_packet_mult * |
612 | opts->streaming_maxburst); | ||
627 | 613 | ||
628 | /* Allocate endpoints. */ | 614 | /* Allocate endpoints. */ |
629 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep); | 615 | ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep); |
@@ -653,6 +639,18 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
653 | uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; | 639 | uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; |
654 | uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address; | 640 | uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address; |
655 | 641 | ||
642 | us = usb_gstrings_attach(cdev, uvc_function_strings, | ||
643 | ARRAY_SIZE(uvc_en_us_strings)); | ||
644 | if (IS_ERR(us)) { | ||
645 | ret = PTR_ERR(us); | ||
646 | goto error; | ||
647 | } | ||
648 | uvc_iad.iFunction = us[UVC_STRING_CONTROL_IDX].id; | ||
649 | uvc_control_intf.iInterface = us[UVC_STRING_CONTROL_IDX].id; | ||
650 | ret = us[UVC_STRING_STREAMING_IDX].id; | ||
651 | uvc_streaming_intf_alt0.iInterface = ret; | ||
652 | uvc_streaming_intf_alt1.iInterface = ret; | ||
653 | |||
656 | /* Allocate interface IDs. */ | 654 | /* Allocate interface IDs. */ |
657 | if ((ret = usb_interface_id(c, f)) < 0) | 655 | if ((ret = usb_interface_id(c, f)) < 0) |
658 | goto error; | 656 | goto error; |
@@ -697,7 +695,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) | |||
697 | } | 695 | } |
698 | 696 | ||
699 | /* Initialise video. */ | 697 | /* Initialise video. */ |
700 | ret = uvc_video_init(&uvc->video); | 698 | ret = uvcg_video_init(&uvc->video); |
701 | if (ret < 0) | 699 | if (ret < 0) |
702 | goto error; | 700 | goto error; |
703 | 701 | ||
@@ -720,10 +718,9 @@ error: | |||
720 | if (uvc->video.ep) | 718 | if (uvc->video.ep) |
721 | uvc->video.ep->driver_data = NULL; | 719 | uvc->video.ep->driver_data = NULL; |
722 | 720 | ||
723 | if (uvc->control_req) { | 721 | if (uvc->control_req) |
724 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); | 722 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); |
725 | kfree(uvc->control_buf); | 723 | kfree(uvc->control_buf); |
726 | } | ||
727 | 724 | ||
728 | usb_free_all_descriptors(f); | 725 | usb_free_all_descriptors(f); |
729 | return ret; | 726 | return ret; |
@@ -733,104 +730,81 @@ error: | |||
733 | * USB gadget function | 730 | * USB gadget function |
734 | */ | 731 | */ |
735 | 732 | ||
736 | /** | 733 | static void uvc_free_inst(struct usb_function_instance *f) |
737 | * uvc_bind_config - add a UVC function to a configuration | ||
738 | * @c: the configuration to support the UVC instance | ||
739 | * Context: single threaded during gadget setup | ||
740 | * | ||
741 | * Returns zero on success, else negative errno. | ||
742 | * | ||
743 | * Caller must have called @uvc_setup(). Caller is also responsible for | ||
744 | * calling @uvc_cleanup() before module unload. | ||
745 | */ | ||
746 | int __init | ||
747 | uvc_bind_config(struct usb_configuration *c, | ||
748 | const struct uvc_descriptor_header * const *fs_control, | ||
749 | const struct uvc_descriptor_header * const *ss_control, | ||
750 | const struct uvc_descriptor_header * const *fs_streaming, | ||
751 | const struct uvc_descriptor_header * const *hs_streaming, | ||
752 | const struct uvc_descriptor_header * const *ss_streaming) | ||
753 | { | 734 | { |
754 | struct uvc_device *uvc; | 735 | struct f_uvc_opts *opts = to_f_uvc_opts(f); |
755 | int ret = 0; | ||
756 | 736 | ||
757 | /* TODO Check if the USB device controller supports the required | 737 | kfree(opts); |
758 | * features. | 738 | } |
759 | */ | ||
760 | if (!gadget_is_dualspeed(c->cdev->gadget)) | ||
761 | return -EINVAL; | ||
762 | 739 | ||
763 | uvc = kzalloc(sizeof(*uvc), GFP_KERNEL); | 740 | static struct usb_function_instance *uvc_alloc_inst(void) |
764 | if (uvc == NULL) | 741 | { |
765 | return -ENOMEM; | 742 | struct f_uvc_opts *opts; |
766 | 743 | ||
767 | uvc->state = UVC_STATE_DISCONNECTED; | 744 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); |
745 | if (!opts) | ||
746 | return ERR_PTR(-ENOMEM); | ||
747 | opts->func_inst.free_func_inst = uvc_free_inst; | ||
768 | 748 | ||
769 | /* Validate the descriptors. */ | 749 | return &opts->func_inst; |
770 | if (fs_control == NULL || fs_control[0] == NULL || | 750 | } |
771 | fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) | ||
772 | goto error; | ||
773 | 751 | ||
774 | if (ss_control == NULL || ss_control[0] == NULL || | 752 | static void uvc_free(struct usb_function *f) |
775 | ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) | 753 | { |
776 | goto error; | 754 | struct uvc_device *uvc = to_uvc(f); |
777 | 755 | ||
778 | if (fs_streaming == NULL || fs_streaming[0] == NULL || | 756 | kfree(uvc); |
779 | fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | 757 | } |
780 | goto error; | ||
781 | 758 | ||
782 | if (hs_streaming == NULL || hs_streaming[0] == NULL || | 759 | static void uvc_unbind(struct usb_configuration *c, struct usb_function *f) |
783 | hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | 760 | { |
784 | goto error; | 761 | struct usb_composite_dev *cdev = c->cdev; |
762 | struct uvc_device *uvc = to_uvc(f); | ||
785 | 763 | ||
786 | if (ss_streaming == NULL || ss_streaming[0] == NULL || | 764 | INFO(cdev, "%s\n", __func__); |
787 | ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) | ||
788 | goto error; | ||
789 | 765 | ||
790 | uvc->desc.fs_control = fs_control; | 766 | video_unregister_device(uvc->vdev); |
791 | uvc->desc.ss_control = ss_control; | 767 | v4l2_device_unregister(&uvc->v4l2_dev); |
792 | uvc->desc.fs_streaming = fs_streaming; | 768 | uvc->control_ep->driver_data = NULL; |
793 | uvc->desc.hs_streaming = hs_streaming; | 769 | uvc->video.ep->driver_data = NULL; |
794 | uvc->desc.ss_streaming = ss_streaming; | ||
795 | 770 | ||
796 | /* String descriptors are global, we only need to allocate string IDs | 771 | usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); |
797 | * for the first UVC function. UVC functions beyond the first (if any) | 772 | kfree(uvc->control_buf); |
798 | * will reuse the same IDs. | 773 | |
799 | */ | 774 | usb_free_all_descriptors(f); |
800 | if (uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id == 0) { | 775 | } |
801 | ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); | 776 | |
802 | if (ret) | 777 | static struct usb_function *uvc_alloc(struct usb_function_instance *fi) |
803 | goto error; | 778 | { |
804 | uvc_iad.iFunction = | 779 | struct uvc_device *uvc; |
805 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; | 780 | struct f_uvc_opts *opts; |
806 | uvc_control_intf.iInterface = | 781 | |
807 | uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; | 782 | uvc = kzalloc(sizeof(*uvc), GFP_KERNEL); |
808 | ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; | 783 | if (uvc == NULL) |
809 | uvc_streaming_intf_alt0.iInterface = ret; | 784 | return ERR_PTR(-ENOMEM); |
810 | uvc_streaming_intf_alt1.iInterface = ret; | 785 | |
811 | } | 786 | uvc->state = UVC_STATE_DISCONNECTED; |
787 | opts = to_f_uvc_opts(fi); | ||
788 | |||
789 | uvc->desc.fs_control = opts->fs_control; | ||
790 | uvc->desc.ss_control = opts->ss_control; | ||
791 | uvc->desc.fs_streaming = opts->fs_streaming; | ||
792 | uvc->desc.hs_streaming = opts->hs_streaming; | ||
793 | uvc->desc.ss_streaming = opts->ss_streaming; | ||
812 | 794 | ||
813 | /* Register the function. */ | 795 | /* Register the function. */ |
814 | uvc->func.name = "uvc"; | 796 | uvc->func.name = "uvc"; |
815 | uvc->func.strings = uvc_function_strings; | ||
816 | uvc->func.bind = uvc_function_bind; | 797 | uvc->func.bind = uvc_function_bind; |
817 | uvc->func.unbind = uvc_function_unbind; | 798 | uvc->func.unbind = uvc_unbind; |
818 | uvc->func.get_alt = uvc_function_get_alt; | 799 | uvc->func.get_alt = uvc_function_get_alt; |
819 | uvc->func.set_alt = uvc_function_set_alt; | 800 | uvc->func.set_alt = uvc_function_set_alt; |
820 | uvc->func.disable = uvc_function_disable; | 801 | uvc->func.disable = uvc_function_disable; |
821 | uvc->func.setup = uvc_function_setup; | 802 | uvc->func.setup = uvc_function_setup; |
803 | uvc->func.free_func = uvc_free; | ||
822 | 804 | ||
823 | ret = usb_add_function(c, &uvc->func); | 805 | return &uvc->func; |
824 | if (ret) | ||
825 | kfree(uvc); | ||
826 | |||
827 | return ret; | ||
828 | |||
829 | error: | ||
830 | kfree(uvc); | ||
831 | return ret; | ||
832 | } | 806 | } |
833 | 807 | ||
834 | module_param_named(trace, uvc_gadget_trace_param, uint, S_IRUGO|S_IWUSR); | 808 | DECLARE_USB_FUNCTION_INIT(uvc, uvc_alloc_inst, uvc_alloc); |
835 | MODULE_PARM_DESC(trace, "Trace level bitmask"); | 809 | MODULE_LICENSE("GPL"); |
836 | 810 | MODULE_AUTHOR("Laurent Pinchart"); | |
diff --git a/drivers/usb/gadget/function/f_uvc.h b/drivers/usb/gadget/function/f_uvc.h index ec52752f7326..d0a73bdcbba1 100644 --- a/drivers/usb/gadget/function/f_uvc.h +++ b/drivers/usb/gadget/function/f_uvc.h | |||
@@ -16,12 +16,13 @@ | |||
16 | #include <linux/usb/composite.h> | 16 | #include <linux/usb/composite.h> |
17 | #include <linux/usb/video.h> | 17 | #include <linux/usb/video.h> |
18 | 18 | ||
19 | int uvc_bind_config(struct usb_configuration *c, | 19 | #include "uvc.h" |
20 | const struct uvc_descriptor_header * const *fs_control, | 20 | |
21 | const struct uvc_descriptor_header * const *hs_control, | 21 | void uvc_function_setup_continue(struct uvc_device *uvc); |
22 | const struct uvc_descriptor_header * const *fs_streaming, | 22 | |
23 | const struct uvc_descriptor_header * const *hs_streaming, | 23 | void uvc_function_connect(struct uvc_device *uvc); |
24 | const struct uvc_descriptor_header * const *ss_streaming); | 24 | |
25 | void uvc_function_disconnect(struct uvc_device *uvc); | ||
25 | 26 | ||
26 | #endif /* _F_UVC_H_ */ | 27 | #endif /* _F_UVC_H_ */ |
27 | 28 | ||
diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h index 15f180904f8a..2ce28b9d97cc 100644 --- a/drivers/usb/gadget/function/g_zero.h +++ b/drivers/usb/gadget/function/g_zero.h | |||
@@ -10,6 +10,8 @@ | |||
10 | #define GZERO_QLEN 32 | 10 | #define GZERO_QLEN 32 |
11 | #define GZERO_ISOC_INTERVAL 4 | 11 | #define GZERO_ISOC_INTERVAL 4 |
12 | #define GZERO_ISOC_MAXPACKET 1024 | 12 | #define GZERO_ISOC_MAXPACKET 1024 |
13 | #define GZERO_INT_INTERVAL 1 /* Default interrupt interval = 1 ms */ | ||
14 | #define GZERO_INT_MAXPACKET 1024 | ||
13 | 15 | ||
14 | struct usb_zero_options { | 16 | struct usb_zero_options { |
15 | unsigned pattern; | 17 | unsigned pattern; |
@@ -17,6 +19,10 @@ struct usb_zero_options { | |||
17 | unsigned isoc_maxpacket; | 19 | unsigned isoc_maxpacket; |
18 | unsigned isoc_mult; | 20 | unsigned isoc_mult; |
19 | unsigned isoc_maxburst; | 21 | unsigned isoc_maxburst; |
22 | unsigned int_interval; /* In ms */ | ||
23 | unsigned int_maxpacket; | ||
24 | unsigned int_mult; | ||
25 | unsigned int_maxburst; | ||
20 | unsigned bulk_buflen; | 26 | unsigned bulk_buflen; |
21 | unsigned qlen; | 27 | unsigned qlen; |
22 | }; | 28 | }; |
@@ -28,6 +34,10 @@ struct f_ss_opts { | |||
28 | unsigned isoc_maxpacket; | 34 | unsigned isoc_maxpacket; |
29 | unsigned isoc_mult; | 35 | unsigned isoc_mult; |
30 | unsigned isoc_maxburst; | 36 | unsigned isoc_maxburst; |
37 | unsigned int_interval; /* In ms */ | ||
38 | unsigned int_maxpacket; | ||
39 | unsigned int_mult; | ||
40 | unsigned int_maxburst; | ||
31 | unsigned bulk_buflen; | 41 | unsigned bulk_buflen; |
32 | 42 | ||
33 | /* | 43 | /* |
@@ -62,6 +72,7 @@ int lb_modinit(void); | |||
62 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); | 72 | void free_ep_req(struct usb_ep *ep, struct usb_request *req); |
63 | void disable_endpoints(struct usb_composite_dev *cdev, | 73 | void disable_endpoints(struct usb_composite_dev *cdev, |
64 | struct usb_ep *in, struct usb_ep *out, | 74 | struct usb_ep *in, struct usb_ep *out, |
65 | struct usb_ep *iso_in, struct usb_ep *iso_out); | 75 | struct usb_ep *iso_in, struct usb_ep *iso_out, |
76 | struct usb_ep *int_in, struct usb_ep *int_out); | ||
66 | 77 | ||
67 | #endif /* __G_ZERO_H */ | 78 | #endif /* __G_ZERO_H */ |
diff --git a/drivers/usb/gadget/function/u_fs.h b/drivers/usb/gadget/function/u_fs.h index d48897e8ffeb..cd128e31f808 100644 --- a/drivers/usb/gadget/function/u_fs.h +++ b/drivers/usb/gadget/function/u_fs.h | |||
@@ -224,6 +224,8 @@ struct ffs_data { | |||
224 | void *ms_os_descs_ext_prop_name_avail; | 224 | void *ms_os_descs_ext_prop_name_avail; |
225 | void *ms_os_descs_ext_prop_data_avail; | 225 | void *ms_os_descs_ext_prop_data_avail; |
226 | 226 | ||
227 | unsigned user_flags; | ||
228 | |||
227 | u8 eps_addrmap[15]; | 229 | u8 eps_addrmap[15]; |
228 | 230 | ||
229 | unsigned short strings_count; | 231 | unsigned short strings_count; |
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index ad0aca812002..491082aaf103 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c | |||
@@ -55,11 +55,8 @@ | |||
55 | * for a telephone or fax link. And ttyGS2 might be something that just | 55 | * for a telephone or fax link. And ttyGS2 might be something that just |
56 | * needs a simple byte stream interface for some messaging protocol that | 56 | * needs a simple byte stream interface for some messaging protocol that |
57 | * is managed in userspace ... OBEX, PTP, and MTP have been mentioned. | 57 | * is managed in userspace ... OBEX, PTP, and MTP have been mentioned. |
58 | */ | 58 | * |
59 | 59 | * | |
60 | #define PREFIX "ttyGS" | ||
61 | |||
62 | /* | ||
63 | * gserial is the lifecycle interface, used by USB functions | 60 | * gserial is the lifecycle interface, used by USB functions |
64 | * gs_port is the I/O nexus, used by the tty driver | 61 | * gs_port is the I/O nexus, used by the tty driver |
65 | * tty_struct links to the tty/filesystem framework | 62 | * tty_struct links to the tty/filesystem framework |
@@ -385,9 +382,9 @@ __acquires(&port->port_lock) | |||
385 | list_del(&req->list); | 382 | list_del(&req->list); |
386 | req->zero = (gs_buf_data_avail(&port->port_write_buf) == 0); | 383 | req->zero = (gs_buf_data_avail(&port->port_write_buf) == 0); |
387 | 384 | ||
388 | pr_vdebug(PREFIX "%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n", | 385 | pr_vdebug("ttyGS%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n", |
389 | port->port_num, len, *((u8 *)req->buf), | 386 | port->port_num, len, *((u8 *)req->buf), |
390 | *((u8 *)req->buf+1), *((u8 *)req->buf+2)); | 387 | *((u8 *)req->buf+1), *((u8 *)req->buf+2)); |
391 | 388 | ||
392 | /* Drop lock while we call out of driver; completions | 389 | /* Drop lock while we call out of driver; completions |
393 | * could be issued while we do so. Disconnection may | 390 | * could be issued while we do so. Disconnection may |
@@ -503,13 +500,13 @@ static void gs_rx_push(unsigned long _port) | |||
503 | switch (req->status) { | 500 | switch (req->status) { |
504 | case -ESHUTDOWN: | 501 | case -ESHUTDOWN: |
505 | disconnect = true; | 502 | disconnect = true; |
506 | pr_vdebug(PREFIX "%d: shutdown\n", port->port_num); | 503 | pr_vdebug("ttyGS%d: shutdown\n", port->port_num); |
507 | break; | 504 | break; |
508 | 505 | ||
509 | default: | 506 | default: |
510 | /* presumably a transient fault */ | 507 | /* presumably a transient fault */ |
511 | pr_warning(PREFIX "%d: unexpected RX status %d\n", | 508 | pr_warn("ttyGS%d: unexpected RX status %d\n", |
512 | port->port_num, req->status); | 509 | port->port_num, req->status); |
513 | /* FALLTHROUGH */ | 510 | /* FALLTHROUGH */ |
514 | case 0: | 511 | case 0: |
515 | /* normal completion */ | 512 | /* normal completion */ |
@@ -537,9 +534,8 @@ static void gs_rx_push(unsigned long _port) | |||
537 | if (count != size) { | 534 | if (count != size) { |
538 | /* stop pushing; TTY layer can't handle more */ | 535 | /* stop pushing; TTY layer can't handle more */ |
539 | port->n_read += count; | 536 | port->n_read += count; |
540 | pr_vdebug(PREFIX "%d: rx block %d/%d\n", | 537 | pr_vdebug("ttyGS%d: rx block %d/%d\n", |
541 | port->port_num, | 538 | port->port_num, count, req->actual); |
542 | count, req->actual); | ||
543 | break; | 539 | break; |
544 | } | 540 | } |
545 | port->n_read = 0; | 541 | port->n_read = 0; |
@@ -569,7 +565,7 @@ static void gs_rx_push(unsigned long _port) | |||
569 | if (do_push) | 565 | if (do_push) |
570 | tasklet_schedule(&port->push); | 566 | tasklet_schedule(&port->push); |
571 | else | 567 | else |
572 | pr_warning(PREFIX "%d: RX not scheduled?\n", | 568 | pr_warn("ttyGS%d: RX not scheduled?\n", |
573 | port->port_num); | 569 | port->port_num); |
574 | } | 570 | } |
575 | } | 571 | } |
@@ -985,7 +981,7 @@ static void gs_unthrottle(struct tty_struct *tty) | |||
985 | * read queue backs up enough we'll be NAKing OUT packets. | 981 | * read queue backs up enough we'll be NAKing OUT packets. |
986 | */ | 982 | */ |
987 | tasklet_schedule(&port->push); | 983 | tasklet_schedule(&port->push); |
988 | pr_vdebug(PREFIX "%d: unthrottle\n", port->port_num); | 984 | pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); |
989 | } | 985 | } |
990 | spin_unlock_irqrestore(&port->port_lock, flags); | 986 | spin_unlock_irqrestore(&port->port_lock, flags); |
991 | } | 987 | } |
@@ -1295,7 +1291,7 @@ static int userial_init(void) | |||
1295 | return -ENOMEM; | 1291 | return -ENOMEM; |
1296 | 1292 | ||
1297 | gs_tty_driver->driver_name = "g_serial"; | 1293 | gs_tty_driver->driver_name = "g_serial"; |
1298 | gs_tty_driver->name = PREFIX; | 1294 | gs_tty_driver->name = "ttyGS"; |
1299 | /* uses dynamically assigned dev_t values */ | 1295 | /* uses dynamically assigned dev_t values */ |
1300 | 1296 | ||
1301 | gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; | 1297 | gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c index 7a55fea43430..a44a07f30281 100644 --- a/drivers/usb/gadget/function/u_uac1.c +++ b/drivers/usb/gadget/function/u_uac1.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | ||
13 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
@@ -23,22 +24,6 @@ | |||
23 | * This component encapsulates the ALSA devices for USB audio gadget | 24 | * This component encapsulates the ALSA devices for USB audio gadget |
24 | */ | 25 | */ |
25 | 26 | ||
26 | #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" | ||
27 | #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" | ||
28 | #define FILE_CONTROL "/dev/snd/controlC0" | ||
29 | |||
30 | static char *fn_play = FILE_PCM_PLAYBACK; | ||
31 | module_param(fn_play, charp, S_IRUGO); | ||
32 | MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); | ||
33 | |||
34 | static char *fn_cap = FILE_PCM_CAPTURE; | ||
35 | module_param(fn_cap, charp, S_IRUGO); | ||
36 | MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); | ||
37 | |||
38 | static char *fn_cntl = FILE_CONTROL; | ||
39 | module_param(fn_cntl, charp, S_IRUGO); | ||
40 | MODULE_PARM_DESC(fn_cntl, "Control device file name"); | ||
41 | |||
42 | /*-------------------------------------------------------------------------*/ | 27 | /*-------------------------------------------------------------------------*/ |
43 | 28 | ||
44 | /** | 29 | /** |
@@ -167,7 +152,7 @@ static int playback_default_hw_params(struct gaudio_snd_dev *snd) | |||
167 | /** | 152 | /** |
168 | * Playback audio buffer data by ALSA PCM device | 153 | * Playback audio buffer data by ALSA PCM device |
169 | */ | 154 | */ |
170 | static size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) | 155 | size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) |
171 | { | 156 | { |
172 | struct gaudio_snd_dev *snd = &card->playback; | 157 | struct gaudio_snd_dev *snd = &card->playback; |
173 | struct snd_pcm_substream *substream = snd->substream; | 158 | struct snd_pcm_substream *substream = snd->substream; |
@@ -202,12 +187,12 @@ try_again: | |||
202 | return 0; | 187 | return 0; |
203 | } | 188 | } |
204 | 189 | ||
205 | static int u_audio_get_playback_channels(struct gaudio *card) | 190 | int u_audio_get_playback_channels(struct gaudio *card) |
206 | { | 191 | { |
207 | return card->playback.channels; | 192 | return card->playback.channels; |
208 | } | 193 | } |
209 | 194 | ||
210 | static int u_audio_get_playback_rate(struct gaudio *card) | 195 | int u_audio_get_playback_rate(struct gaudio *card) |
211 | { | 196 | { |
212 | return card->playback.rate; | 197 | return card->playback.rate; |
213 | } | 198 | } |
@@ -220,6 +205,13 @@ static int gaudio_open_snd_dev(struct gaudio *card) | |||
220 | { | 205 | { |
221 | struct snd_pcm_file *pcm_file; | 206 | struct snd_pcm_file *pcm_file; |
222 | struct gaudio_snd_dev *snd; | 207 | struct gaudio_snd_dev *snd; |
208 | struct f_uac1_opts *opts; | ||
209 | char *fn_play, *fn_cap, *fn_cntl; | ||
210 | |||
211 | opts = container_of(card->func.fi, struct f_uac1_opts, func_inst); | ||
212 | fn_play = opts->fn_play; | ||
213 | fn_cap = opts->fn_cap; | ||
214 | fn_cntl = opts->fn_cntl; | ||
223 | 215 | ||
224 | if (!card) | 216 | if (!card) |
225 | return -ENODEV; | 217 | return -ENODEV; |
@@ -293,7 +285,6 @@ static int gaudio_close_snd_dev(struct gaudio *gau) | |||
293 | return 0; | 285 | return 0; |
294 | } | 286 | } |
295 | 287 | ||
296 | static struct gaudio *the_card; | ||
297 | /** | 288 | /** |
298 | * gaudio_setup - setup ALSA interface and preparing for USB transfer | 289 | * gaudio_setup - setup ALSA interface and preparing for USB transfer |
299 | * | 290 | * |
@@ -301,15 +292,13 @@ static struct gaudio *the_card; | |||
301 | * | 292 | * |
302 | * Returns negative errno, or zero on success | 293 | * Returns negative errno, or zero on success |
303 | */ | 294 | */ |
304 | int __init gaudio_setup(struct gaudio *card) | 295 | int gaudio_setup(struct gaudio *card) |
305 | { | 296 | { |
306 | int ret; | 297 | int ret; |
307 | 298 | ||
308 | ret = gaudio_open_snd_dev(card); | 299 | ret = gaudio_open_snd_dev(card); |
309 | if (ret) | 300 | if (ret) |
310 | ERROR(card, "we need at least one control device\n"); | 301 | ERROR(card, "we need at least one control device\n"); |
311 | else if (!the_card) | ||
312 | the_card = card; | ||
313 | 302 | ||
314 | return ret; | 303 | return ret; |
315 | 304 | ||
@@ -320,11 +309,10 @@ int __init gaudio_setup(struct gaudio *card) | |||
320 | * | 309 | * |
321 | * This is called to free all resources allocated by @gaudio_setup(). | 310 | * This is called to free all resources allocated by @gaudio_setup(). |
322 | */ | 311 | */ |
323 | void gaudio_cleanup(void) | 312 | void gaudio_cleanup(struct gaudio *the_card) |
324 | { | 313 | { |
325 | if (the_card) { | 314 | if (the_card) { |
326 | gaudio_close_snd_dev(the_card); | 315 | gaudio_close_snd_dev(the_card); |
327 | the_card = NULL; | ||
328 | } | 316 | } |
329 | } | 317 | } |
330 | 318 | ||
diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1.h index 18c2e729faf6..f8b17fe82efe 100644 --- a/drivers/usb/gadget/function/u_uac1.h +++ b/drivers/usb/gadget/function/u_uac1.h | |||
@@ -23,6 +23,14 @@ | |||
23 | 23 | ||
24 | #include "gadget_chips.h" | 24 | #include "gadget_chips.h" |
25 | 25 | ||
26 | #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" | ||
27 | #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" | ||
28 | #define FILE_CONTROL "/dev/snd/controlC0" | ||
29 | |||
30 | #define UAC1_OUT_EP_MAX_PACKET_SIZE 200 | ||
31 | #define UAC1_REQ_COUNT 256 | ||
32 | #define UAC1_AUDIO_BUF_SIZE 48000 | ||
33 | |||
26 | /* | 34 | /* |
27 | * This represents the USB side of an audio card device, managed by a USB | 35 | * This represents the USB side of an audio card device, managed by a USB |
28 | * function which provides control and stream interfaces. | 36 | * function which provides control and stream interfaces. |
@@ -50,7 +58,28 @@ struct gaudio { | |||
50 | /* TODO */ | 58 | /* TODO */ |
51 | }; | 59 | }; |
52 | 60 | ||
61 | struct f_uac1_opts { | ||
62 | struct usb_function_instance func_inst; | ||
63 | int req_buf_size; | ||
64 | int req_count; | ||
65 | int audio_buf_size; | ||
66 | char *fn_play; | ||
67 | char *fn_cap; | ||
68 | char *fn_cntl; | ||
69 | unsigned bound:1; | ||
70 | unsigned fn_play_alloc:1; | ||
71 | unsigned fn_cap_alloc:1; | ||
72 | unsigned fn_cntl_alloc:1; | ||
73 | struct gaudio *card; | ||
74 | struct mutex lock; | ||
75 | int refcnt; | ||
76 | }; | ||
77 | |||
53 | int gaudio_setup(struct gaudio *card); | 78 | int gaudio_setup(struct gaudio *card); |
54 | void gaudio_cleanup(void); | 79 | void gaudio_cleanup(struct gaudio *the_card); |
80 | |||
81 | size_t u_audio_playback(struct gaudio *card, void *buf, size_t count); | ||
82 | int u_audio_get_playback_channels(struct gaudio *card); | ||
83 | int u_audio_get_playback_rate(struct gaudio *card); | ||
55 | 84 | ||
56 | #endif /* __U_AUDIO_H */ | 85 | #endif /* __U_AUDIO_H */ |
diff --git a/drivers/usb/gadget/function/u_uac2.h b/drivers/usb/gadget/function/u_uac2.h new file mode 100644 index 000000000000..78dd37279bd4 --- /dev/null +++ b/drivers/usb/gadget/function/u_uac2.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * u_uac2.h | ||
3 | * | ||
4 | * Utility definitions for UAC2 function | ||
5 | * | ||
6 | * Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef U_UAC2_H | ||
17 | #define U_UAC2_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | |||
21 | #define UAC2_DEF_PCHMASK 0x3 | ||
22 | #define UAC2_DEF_PSRATE 48000 | ||
23 | #define UAC2_DEF_PSSIZE 2 | ||
24 | #define UAC2_DEF_CCHMASK 0x3 | ||
25 | #define UAC2_DEF_CSRATE 64000 | ||
26 | #define UAC2_DEF_CSSIZE 2 | ||
27 | |||
28 | struct f_uac2_opts { | ||
29 | struct usb_function_instance func_inst; | ||
30 | int p_chmask; | ||
31 | int p_srate; | ||
32 | int p_ssize; | ||
33 | int c_chmask; | ||
34 | int c_srate; | ||
35 | int c_ssize; | ||
36 | bool bound; | ||
37 | |||
38 | struct mutex lock; | ||
39 | int refcnt; | ||
40 | }; | ||
41 | |||
42 | #endif | ||
diff --git a/drivers/usb/gadget/function/u_uvc.h b/drivers/usb/gadget/function/u_uvc.h new file mode 100644 index 000000000000..2a8dfdff0332 --- /dev/null +++ b/drivers/usb/gadget/function/u_uvc.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * u_uvc.h | ||
3 | * | ||
4 | * Utility definitions for the uvc function | ||
5 | * | ||
6 | * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd. | ||
7 | * http://www.samsung.com | ||
8 | * | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef U_UVC_H | ||
17 | #define U_UVC_H | ||
18 | |||
19 | #include <linux/usb/composite.h> | ||
20 | |||
21 | #define to_f_uvc_opts(f) container_of(f, struct f_uvc_opts, func_inst) | ||
22 | |||
23 | struct f_uvc_opts { | ||
24 | struct usb_function_instance func_inst; | ||
25 | unsigned int uvc_gadget_trace_param; | ||
26 | unsigned int streaming_interval; | ||
27 | unsigned int streaming_maxpacket; | ||
28 | unsigned int streaming_maxburst; | ||
29 | const struct uvc_descriptor_header * const *fs_control; | ||
30 | const struct uvc_descriptor_header * const *ss_control; | ||
31 | const struct uvc_descriptor_header * const *fs_streaming; | ||
32 | const struct uvc_descriptor_header * const *hs_streaming; | ||
33 | const struct uvc_descriptor_header * const *ss_streaming; | ||
34 | }; | ||
35 | |||
36 | void uvc_set_trace_param(unsigned int trace); | ||
37 | |||
38 | #endif /* U_UVC_H */ | ||
39 | |||
diff --git a/drivers/usb/gadget/function/uvc.h b/drivers/usb/gadget/function/uvc.h index 7a9111de8054..f67695cb28f8 100644 --- a/drivers/usb/gadget/function/uvc.h +++ b/drivers/usb/gadget/function/uvc.h | |||
@@ -53,6 +53,7 @@ struct uvc_event | |||
53 | #ifdef __KERNEL__ | 53 | #ifdef __KERNEL__ |
54 | 54 | ||
55 | #include <linux/usb.h> /* For usb_endpoint_* */ | 55 | #include <linux/usb.h> /* For usb_endpoint_* */ |
56 | #include <linux/usb/composite.h> | ||
56 | #include <linux/usb/gadget.h> | 57 | #include <linux/usb/gadget.h> |
57 | #include <linux/videodev2.h> | 58 | #include <linux/videodev2.h> |
58 | #include <linux/version.h> | 59 | #include <linux/version.h> |
@@ -96,9 +97,6 @@ extern unsigned int uvc_gadget_trace_param; | |||
96 | * Driver specific constants | 97 | * Driver specific constants |
97 | */ | 98 | */ |
98 | 99 | ||
99 | #define DRIVER_VERSION "0.1.0" | ||
100 | #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) | ||
101 | |||
102 | #define UVC_NUM_REQUESTS 4 | 100 | #define UVC_NUM_REQUESTS 4 |
103 | #define UVC_MAX_REQUEST_SIZE 64 | 101 | #define UVC_MAX_REQUEST_SIZE 64 |
104 | #define UVC_MAX_EVENTS 4 | 102 | #define UVC_MAX_EVENTS 4 |
diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c index 1c29bc954db9..8ea8b3b227b4 100644 --- a/drivers/usb/gadget/function/uvc_queue.c +++ b/drivers/usb/gadget/function/uvc_queue.c | |||
@@ -28,7 +28,7 @@ | |||
28 | /* ------------------------------------------------------------------------ | 28 | /* ------------------------------------------------------------------------ |
29 | * Video buffers queue management. | 29 | * Video buffers queue management. |
30 | * | 30 | * |
31 | * Video queues is initialized by uvc_queue_init(). The function performs | 31 | * Video queues is initialized by uvcg_queue_init(). The function performs |
32 | * basic initialization of the uvc_video_queue struct and never fails. | 32 | * basic initialization of the uvc_video_queue struct and never fails. |
33 | * | 33 | * |
34 | * Video buffers are managed by videobuf2. The driver uses a mutex to protect | 34 | * Video buffers are managed by videobuf2. The driver uses a mutex to protect |
@@ -126,13 +126,12 @@ static struct vb2_ops uvc_queue_qops = { | |||
126 | .wait_finish = uvc_wait_finish, | 126 | .wait_finish = uvc_wait_finish, |
127 | }; | 127 | }; |
128 | 128 | ||
129 | static int uvc_queue_init(struct uvc_video_queue *queue, | 129 | int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) |
130 | enum v4l2_buf_type type) | ||
131 | { | 130 | { |
132 | int ret; | 131 | int ret; |
133 | 132 | ||
134 | queue->queue.type = type; | 133 | queue->queue.type = type; |
135 | queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; | 134 | queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; |
136 | queue->queue.drv_priv = queue; | 135 | queue->queue.drv_priv = queue; |
137 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); | 136 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); |
138 | queue->queue.ops = &uvc_queue_qops; | 137 | queue->queue.ops = &uvc_queue_qops; |
@@ -154,7 +153,7 @@ static int uvc_queue_init(struct uvc_video_queue *queue, | |||
154 | /* | 153 | /* |
155 | * Free the video buffers. | 154 | * Free the video buffers. |
156 | */ | 155 | */ |
157 | static void uvc_free_buffers(struct uvc_video_queue *queue) | 156 | void uvcg_free_buffers(struct uvc_video_queue *queue) |
158 | { | 157 | { |
159 | mutex_lock(&queue->mutex); | 158 | mutex_lock(&queue->mutex); |
160 | vb2_queue_release(&queue->queue); | 159 | vb2_queue_release(&queue->queue); |
@@ -164,8 +163,8 @@ static void uvc_free_buffers(struct uvc_video_queue *queue) | |||
164 | /* | 163 | /* |
165 | * Allocate the video buffers. | 164 | * Allocate the video buffers. |
166 | */ | 165 | */ |
167 | static int uvc_alloc_buffers(struct uvc_video_queue *queue, | 166 | int uvcg_alloc_buffers(struct uvc_video_queue *queue, |
168 | struct v4l2_requestbuffers *rb) | 167 | struct v4l2_requestbuffers *rb) |
169 | { | 168 | { |
170 | int ret; | 169 | int ret; |
171 | 170 | ||
@@ -176,8 +175,7 @@ static int uvc_alloc_buffers(struct uvc_video_queue *queue, | |||
176 | return ret ? ret : rb->count; | 175 | return ret ? ret : rb->count; |
177 | } | 176 | } |
178 | 177 | ||
179 | static int uvc_query_buffer(struct uvc_video_queue *queue, | 178 | int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) |
180 | struct v4l2_buffer *buf) | ||
181 | { | 179 | { |
182 | int ret; | 180 | int ret; |
183 | 181 | ||
@@ -188,8 +186,7 @@ static int uvc_query_buffer(struct uvc_video_queue *queue, | |||
188 | return ret; | 186 | return ret; |
189 | } | 187 | } |
190 | 188 | ||
191 | static int uvc_queue_buffer(struct uvc_video_queue *queue, | 189 | int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) |
192 | struct v4l2_buffer *buf) | ||
193 | { | 190 | { |
194 | unsigned long flags; | 191 | unsigned long flags; |
195 | int ret; | 192 | int ret; |
@@ -213,8 +210,8 @@ done: | |||
213 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is | 210 | * Dequeue a video buffer. If nonblocking is false, block until a buffer is |
214 | * available. | 211 | * available. |
215 | */ | 212 | */ |
216 | static int uvc_dequeue_buffer(struct uvc_video_queue *queue, | 213 | int uvcg_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, |
217 | struct v4l2_buffer *buf, int nonblocking) | 214 | int nonblocking) |
218 | { | 215 | { |
219 | int ret; | 216 | int ret; |
220 | 217 | ||
@@ -231,8 +228,8 @@ static int uvc_dequeue_buffer(struct uvc_video_queue *queue, | |||
231 | * This function implements video queue polling and is intended to be used by | 228 | * This function implements video queue polling and is intended to be used by |
232 | * the device poll handler. | 229 | * the device poll handler. |
233 | */ | 230 | */ |
234 | static unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | 231 | unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, struct file *file, |
235 | struct file *file, poll_table *wait) | 232 | poll_table *wait) |
236 | { | 233 | { |
237 | unsigned int ret; | 234 | unsigned int ret; |
238 | 235 | ||
@@ -243,8 +240,7 @@ static unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | |||
243 | return ret; | 240 | return ret; |
244 | } | 241 | } |
245 | 242 | ||
246 | static int uvc_queue_mmap(struct uvc_video_queue *queue, | 243 | int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) |
247 | struct vm_area_struct *vma) | ||
248 | { | 244 | { |
249 | int ret; | 245 | int ret; |
250 | 246 | ||
@@ -261,8 +257,8 @@ static int uvc_queue_mmap(struct uvc_video_queue *queue, | |||
261 | * | 257 | * |
262 | * NO-MMU arch need this function to make mmap() work correctly. | 258 | * NO-MMU arch need this function to make mmap() work correctly. |
263 | */ | 259 | */ |
264 | static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, | 260 | unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, |
265 | unsigned long pgoff) | 261 | unsigned long pgoff) |
266 | { | 262 | { |
267 | unsigned long ret; | 263 | unsigned long ret; |
268 | 264 | ||
@@ -285,7 +281,7 @@ static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, | |||
285 | * This function acquires the irq spinlock and can be called from interrupt | 281 | * This function acquires the irq spinlock and can be called from interrupt |
286 | * context. | 282 | * context. |
287 | */ | 283 | */ |
288 | static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | 284 | void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect) |
289 | { | 285 | { |
290 | struct uvc_buffer *buf; | 286 | struct uvc_buffer *buf; |
291 | unsigned long flags; | 287 | unsigned long flags; |
@@ -324,9 +320,9 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) | |||
324 | * the main queue. | 320 | * the main queue. |
325 | * | 321 | * |
326 | * This function can't be called from interrupt context. Use | 322 | * This function can't be called from interrupt context. Use |
327 | * uvc_queue_cancel() instead. | 323 | * uvcg_queue_cancel() instead. |
328 | */ | 324 | */ |
329 | static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) | 325 | int uvcg_queue_enable(struct uvc_video_queue *queue, int enable) |
330 | { | 326 | { |
331 | unsigned long flags; | 327 | unsigned long flags; |
332 | int ret = 0; | 328 | int ret = 0; |
@@ -363,8 +359,8 @@ done: | |||
363 | } | 359 | } |
364 | 360 | ||
365 | /* called with &queue_irqlock held.. */ | 361 | /* called with &queue_irqlock held.. */ |
366 | static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | 362 | struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, |
367 | struct uvc_buffer *buf) | 363 | struct uvc_buffer *buf) |
368 | { | 364 | { |
369 | struct uvc_buffer *nextbuf; | 365 | struct uvc_buffer *nextbuf; |
370 | 366 | ||
@@ -392,7 +388,7 @@ static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |||
392 | return nextbuf; | 388 | return nextbuf; |
393 | } | 389 | } |
394 | 390 | ||
395 | static struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) | 391 | struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue) |
396 | { | 392 | { |
397 | struct uvc_buffer *buf = NULL; | 393 | struct uvc_buffer *buf = NULL; |
398 | 394 | ||
diff --git a/drivers/usb/gadget/function/uvc_queue.h b/drivers/usb/gadget/function/uvc_queue.h index 8e76ce982f1e..03919c724961 100644 --- a/drivers/usb/gadget/function/uvc_queue.h +++ b/drivers/usb/gadget/function/uvc_queue.h | |||
@@ -57,6 +57,39 @@ static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | |||
57 | return vb2_is_streaming(&queue->queue); | 57 | return vb2_is_streaming(&queue->queue); |
58 | } | 58 | } |
59 | 59 | ||
60 | int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type); | ||
61 | |||
62 | void uvcg_free_buffers(struct uvc_video_queue *queue); | ||
63 | |||
64 | int uvcg_alloc_buffers(struct uvc_video_queue *queue, | ||
65 | struct v4l2_requestbuffers *rb); | ||
66 | |||
67 | int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); | ||
68 | |||
69 | int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); | ||
70 | |||
71 | int uvcg_dequeue_buffer(struct uvc_video_queue *queue, | ||
72 | struct v4l2_buffer *buf, int nonblocking); | ||
73 | |||
74 | unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, | ||
75 | struct file *file, poll_table *wait); | ||
76 | |||
77 | int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma); | ||
78 | |||
79 | #ifndef CONFIG_MMU | ||
80 | unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, | ||
81 | unsigned long pgoff); | ||
82 | #endif /* CONFIG_MMU */ | ||
83 | |||
84 | void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect); | ||
85 | |||
86 | int uvcg_queue_enable(struct uvc_video_queue *queue, int enable); | ||
87 | |||
88 | struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, | ||
89 | struct uvc_buffer *buf); | ||
90 | |||
91 | struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue); | ||
92 | |||
60 | #endif /* __KERNEL__ */ | 93 | #endif /* __KERNEL__ */ |
61 | 94 | ||
62 | #endif /* _UVC_QUEUE_H_ */ | 95 | #endif /* _UVC_QUEUE_H_ */ |
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index ad48e81155e2..5aad7fededa5 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c | |||
@@ -23,8 +23,10 @@ | |||
23 | #include <media/v4l2-event.h> | 23 | #include <media/v4l2-event.h> |
24 | #include <media/v4l2-ioctl.h> | 24 | #include <media/v4l2-ioctl.h> |
25 | 25 | ||
26 | #include "f_uvc.h" | ||
26 | #include "uvc.h" | 27 | #include "uvc.h" |
27 | #include "uvc_queue.h" | 28 | #include "uvc_queue.h" |
29 | #include "uvc_video.h" | ||
28 | 30 | ||
29 | /* -------------------------------------------------------------------------- | 31 | /* -------------------------------------------------------------------------- |
30 | * Requests handling | 32 | * Requests handling |
@@ -48,7 +50,7 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data) | |||
48 | } | 50 | } |
49 | 51 | ||
50 | /* -------------------------------------------------------------------------- | 52 | /* -------------------------------------------------------------------------- |
51 | * V4L2 | 53 | * V4L2 ioctls |
52 | */ | 54 | */ |
53 | 55 | ||
54 | struct uvc_format | 56 | struct uvc_format |
@@ -63,8 +65,29 @@ static struct uvc_format uvc_formats[] = { | |||
63 | }; | 65 | }; |
64 | 66 | ||
65 | static int | 67 | static int |
66 | uvc_v4l2_get_format(struct uvc_video *video, struct v4l2_format *fmt) | 68 | uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap) |
67 | { | 69 | { |
70 | struct video_device *vdev = video_devdata(file); | ||
71 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
72 | struct usb_composite_dev *cdev = uvc->func.config->cdev; | ||
73 | |||
74 | strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); | ||
75 | strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); | ||
76 | strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), | ||
77 | sizeof(cap->bus_info)); | ||
78 | |||
79 | cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static int | ||
85 | uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt) | ||
86 | { | ||
87 | struct video_device *vdev = video_devdata(file); | ||
88 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
89 | struct uvc_video *video = &uvc->video; | ||
90 | |||
68 | fmt->fmt.pix.pixelformat = video->fcc; | 91 | fmt->fmt.pix.pixelformat = video->fcc; |
69 | fmt->fmt.pix.width = video->width; | 92 | fmt->fmt.pix.width = video->width; |
70 | fmt->fmt.pix.height = video->height; | 93 | fmt->fmt.pix.height = video->height; |
@@ -78,8 +101,11 @@ uvc_v4l2_get_format(struct uvc_video *video, struct v4l2_format *fmt) | |||
78 | } | 101 | } |
79 | 102 | ||
80 | static int | 103 | static int |
81 | uvc_v4l2_set_format(struct uvc_video *video, struct v4l2_format *fmt) | 104 | uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt) |
82 | { | 105 | { |
106 | struct video_device *vdev = video_devdata(file); | ||
107 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
108 | struct uvc_video *video = &uvc->video; | ||
83 | struct uvc_format *format; | 109 | struct uvc_format *format; |
84 | unsigned int imagesize; | 110 | unsigned int imagesize; |
85 | unsigned int bpl; | 111 | unsigned int bpl; |
@@ -116,209 +142,184 @@ uvc_v4l2_set_format(struct uvc_video *video, struct v4l2_format *fmt) | |||
116 | } | 142 | } |
117 | 143 | ||
118 | static int | 144 | static int |
119 | uvc_v4l2_open(struct file *file) | 145 | uvc_v4l2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *b) |
120 | { | 146 | { |
121 | struct video_device *vdev = video_devdata(file); | 147 | struct video_device *vdev = video_devdata(file); |
122 | struct uvc_device *uvc = video_get_drvdata(vdev); | 148 | struct uvc_device *uvc = video_get_drvdata(vdev); |
123 | struct uvc_file_handle *handle; | 149 | struct uvc_video *video = &uvc->video; |
124 | |||
125 | handle = kzalloc(sizeof(*handle), GFP_KERNEL); | ||
126 | if (handle == NULL) | ||
127 | return -ENOMEM; | ||
128 | |||
129 | v4l2_fh_init(&handle->vfh, vdev); | ||
130 | v4l2_fh_add(&handle->vfh); | ||
131 | 150 | ||
132 | handle->device = &uvc->video; | 151 | if (b->type != video->queue.queue.type) |
133 | file->private_data = &handle->vfh; | 152 | return -EINVAL; |
134 | 153 | ||
135 | uvc_function_connect(uvc); | 154 | return uvcg_alloc_buffers(&video->queue, b); |
136 | return 0; | ||
137 | } | 155 | } |
138 | 156 | ||
139 | static int | 157 | static int |
140 | uvc_v4l2_release(struct file *file) | 158 | uvc_v4l2_querybuf(struct file *file, void *fh, struct v4l2_buffer *b) |
141 | { | 159 | { |
142 | struct video_device *vdev = video_devdata(file); | 160 | struct video_device *vdev = video_devdata(file); |
143 | struct uvc_device *uvc = video_get_drvdata(vdev); | 161 | struct uvc_device *uvc = video_get_drvdata(vdev); |
144 | struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); | 162 | struct uvc_video *video = &uvc->video; |
145 | struct uvc_video *video = handle->device; | ||
146 | |||
147 | uvc_function_disconnect(uvc); | ||
148 | |||
149 | uvc_video_enable(video, 0); | ||
150 | uvc_free_buffers(&video->queue); | ||
151 | |||
152 | file->private_data = NULL; | ||
153 | v4l2_fh_del(&handle->vfh); | ||
154 | v4l2_fh_exit(&handle->vfh); | ||
155 | kfree(handle); | ||
156 | 163 | ||
157 | return 0; | 164 | return uvcg_query_buffer(&video->queue, b); |
158 | } | 165 | } |
159 | 166 | ||
160 | static long | 167 | static int |
161 | uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) | 168 | uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b) |
162 | { | 169 | { |
163 | struct video_device *vdev = video_devdata(file); | 170 | struct video_device *vdev = video_devdata(file); |
164 | struct uvc_device *uvc = video_get_drvdata(vdev); | 171 | struct uvc_device *uvc = video_get_drvdata(vdev); |
165 | struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); | ||
166 | struct usb_composite_dev *cdev = uvc->func.config->cdev; | ||
167 | struct uvc_video *video = &uvc->video; | 172 | struct uvc_video *video = &uvc->video; |
168 | int ret = 0; | 173 | int ret; |
169 | |||
170 | switch (cmd) { | ||
171 | /* Query capabilities */ | ||
172 | case VIDIOC_QUERYCAP: | ||
173 | { | ||
174 | struct v4l2_capability *cap = arg; | ||
175 | |||
176 | memset(cap, 0, sizeof *cap); | ||
177 | strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); | ||
178 | strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); | ||
179 | strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), | ||
180 | sizeof cap->bus_info); | ||
181 | cap->version = DRIVER_VERSION_NUMBER; | ||
182 | cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; | ||
183 | break; | ||
184 | } | ||
185 | |||
186 | /* Get & Set format */ | ||
187 | case VIDIOC_G_FMT: | ||
188 | { | ||
189 | struct v4l2_format *fmt = arg; | ||
190 | 174 | ||
191 | if (fmt->type != video->queue.queue.type) | 175 | ret = uvcg_queue_buffer(&video->queue, b); |
192 | return -EINVAL; | 176 | if (ret < 0) |
177 | return ret; | ||
193 | 178 | ||
194 | return uvc_v4l2_get_format(video, fmt); | 179 | return uvcg_video_pump(video); |
195 | } | 180 | } |
196 | 181 | ||
197 | case VIDIOC_S_FMT: | 182 | static int |
198 | { | 183 | uvc_v4l2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b) |
199 | struct v4l2_format *fmt = arg; | 184 | { |
185 | struct video_device *vdev = video_devdata(file); | ||
186 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
187 | struct uvc_video *video = &uvc->video; | ||
200 | 188 | ||
201 | if (fmt->type != video->queue.queue.type) | 189 | return uvcg_dequeue_buffer(&video->queue, b, file->f_flags & O_NONBLOCK); |
202 | return -EINVAL; | 190 | } |
203 | 191 | ||
204 | return uvc_v4l2_set_format(video, fmt); | 192 | static int |
205 | } | 193 | uvc_v4l2_streamon(struct file *file, void *fh, enum v4l2_buf_type type) |
194 | { | ||
195 | struct video_device *vdev = video_devdata(file); | ||
196 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
197 | struct uvc_video *video = &uvc->video; | ||
198 | int ret; | ||
206 | 199 | ||
207 | /* Buffers & streaming */ | 200 | if (type != video->queue.queue.type) |
208 | case VIDIOC_REQBUFS: | 201 | return -EINVAL; |
209 | { | ||
210 | struct v4l2_requestbuffers *rb = arg; | ||
211 | 202 | ||
212 | if (rb->type != video->queue.queue.type) | 203 | /* Enable UVC video. */ |
213 | return -EINVAL; | 204 | ret = uvcg_video_enable(video, 1); |
205 | if (ret < 0) | ||
206 | return ret; | ||
214 | 207 | ||
215 | ret = uvc_alloc_buffers(&video->queue, rb); | 208 | /* |
216 | if (ret < 0) | 209 | * Complete the alternate setting selection setup phase now that |
217 | return ret; | 210 | * userspace is ready to provide video frames. |
211 | */ | ||
212 | uvc_function_setup_continue(uvc); | ||
213 | uvc->state = UVC_STATE_STREAMING; | ||
218 | 214 | ||
219 | ret = 0; | 215 | return 0; |
220 | break; | 216 | } |
221 | } | ||
222 | |||
223 | case VIDIOC_QUERYBUF: | ||
224 | { | ||
225 | struct v4l2_buffer *buf = arg; | ||
226 | 217 | ||
227 | return uvc_query_buffer(&video->queue, buf); | 218 | static int |
228 | } | 219 | uvc_v4l2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type) |
220 | { | ||
221 | struct video_device *vdev = video_devdata(file); | ||
222 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
223 | struct uvc_video *video = &uvc->video; | ||
229 | 224 | ||
230 | case VIDIOC_QBUF: | 225 | if (type != video->queue.queue.type) |
231 | if ((ret = uvc_queue_buffer(&video->queue, arg)) < 0) | 226 | return -EINVAL; |
232 | return ret; | ||
233 | 227 | ||
234 | return uvc_video_pump(video); | 228 | return uvcg_video_enable(video, 0); |
229 | } | ||
235 | 230 | ||
236 | case VIDIOC_DQBUF: | 231 | static int |
237 | return uvc_dequeue_buffer(&video->queue, arg, | 232 | uvc_v4l2_subscribe_event(struct v4l2_fh *fh, |
238 | file->f_flags & O_NONBLOCK); | 233 | const struct v4l2_event_subscription *sub) |
234 | { | ||
235 | if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST) | ||
236 | return -EINVAL; | ||
239 | 237 | ||
240 | case VIDIOC_STREAMON: | 238 | return v4l2_event_subscribe(fh, sub, 2, NULL); |
241 | { | 239 | } |
242 | int *type = arg; | ||
243 | 240 | ||
244 | if (*type != video->queue.queue.type) | 241 | static int |
245 | return -EINVAL; | 242 | uvc_v4l2_unsubscribe_event(struct v4l2_fh *fh, |
243 | const struct v4l2_event_subscription *sub) | ||
244 | { | ||
245 | return v4l2_event_unsubscribe(fh, sub); | ||
246 | } | ||
246 | 247 | ||
247 | /* Enable UVC video. */ | 248 | static long |
248 | ret = uvc_video_enable(video, 1); | 249 | uvc_v4l2_ioctl_default(struct file *file, void *fh, bool valid_prio, |
249 | if (ret < 0) | 250 | unsigned int cmd, void *arg) |
250 | return ret; | 251 | { |
252 | struct video_device *vdev = video_devdata(file); | ||
253 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
251 | 254 | ||
252 | /* | 255 | switch (cmd) { |
253 | * Complete the alternate setting selection setup phase now that | 256 | case UVCIOC_SEND_RESPONSE: |
254 | * userspace is ready to provide video frames. | 257 | return uvc_send_response(uvc, arg); |
255 | */ | ||
256 | uvc_function_setup_continue(uvc); | ||
257 | uvc->state = UVC_STATE_STREAMING; | ||
258 | 258 | ||
259 | return 0; | 259 | default: |
260 | return -ENOIOCTLCMD; | ||
260 | } | 261 | } |
262 | } | ||
261 | 263 | ||
262 | case VIDIOC_STREAMOFF: | 264 | const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops = { |
263 | { | 265 | .vidioc_querycap = uvc_v4l2_querycap, |
264 | int *type = arg; | 266 | .vidioc_g_fmt_vid_out = uvc_v4l2_get_format, |
265 | 267 | .vidioc_s_fmt_vid_out = uvc_v4l2_set_format, | |
266 | if (*type != video->queue.queue.type) | 268 | .vidioc_reqbufs = uvc_v4l2_reqbufs, |
267 | return -EINVAL; | 269 | .vidioc_querybuf = uvc_v4l2_querybuf, |
270 | .vidioc_qbuf = uvc_v4l2_qbuf, | ||
271 | .vidioc_dqbuf = uvc_v4l2_dqbuf, | ||
272 | .vidioc_streamon = uvc_v4l2_streamon, | ||
273 | .vidioc_streamoff = uvc_v4l2_streamoff, | ||
274 | .vidioc_subscribe_event = uvc_v4l2_subscribe_event, | ||
275 | .vidioc_unsubscribe_event = uvc_v4l2_unsubscribe_event, | ||
276 | .vidioc_default = uvc_v4l2_ioctl_default, | ||
277 | }; | ||
268 | 278 | ||
269 | return uvc_video_enable(video, 0); | 279 | /* -------------------------------------------------------------------------- |
270 | } | 280 | * V4L2 |
281 | */ | ||
271 | 282 | ||
272 | /* Events */ | 283 | static int |
273 | case VIDIOC_DQEVENT: | 284 | uvc_v4l2_open(struct file *file) |
274 | { | 285 | { |
275 | struct v4l2_event *event = arg; | 286 | struct video_device *vdev = video_devdata(file); |
276 | 287 | struct uvc_device *uvc = video_get_drvdata(vdev); | |
277 | ret = v4l2_event_dequeue(&handle->vfh, event, | 288 | struct uvc_file_handle *handle; |
278 | file->f_flags & O_NONBLOCK); | ||
279 | if (ret == 0 && event->type == UVC_EVENT_SETUP) { | ||
280 | struct uvc_event *uvc_event = (void *)&event->u.data; | ||
281 | |||
282 | /* Tell the complete callback to generate an event for | ||
283 | * the next request that will be enqueued by | ||
284 | * uvc_event_write. | ||
285 | */ | ||
286 | uvc->event_setup_out = | ||
287 | !(uvc_event->req.bRequestType & USB_DIR_IN); | ||
288 | uvc->event_length = uvc_event->req.wLength; | ||
289 | } | ||
290 | 289 | ||
291 | return ret; | 290 | handle = kzalloc(sizeof(*handle), GFP_KERNEL); |
292 | } | 291 | if (handle == NULL) |
292 | return -ENOMEM; | ||
293 | 293 | ||
294 | case VIDIOC_SUBSCRIBE_EVENT: | 294 | v4l2_fh_init(&handle->vfh, vdev); |
295 | { | 295 | v4l2_fh_add(&handle->vfh); |
296 | struct v4l2_event_subscription *sub = arg; | ||
297 | 296 | ||
298 | if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST) | 297 | handle->device = &uvc->video; |
299 | return -EINVAL; | 298 | file->private_data = &handle->vfh; |
300 | 299 | ||
301 | return v4l2_event_subscribe(&handle->vfh, arg, 2, NULL); | 300 | uvc_function_connect(uvc); |
302 | } | 301 | return 0; |
302 | } | ||
303 | 303 | ||
304 | case VIDIOC_UNSUBSCRIBE_EVENT: | 304 | static int |
305 | return v4l2_event_unsubscribe(&handle->vfh, arg); | 305 | uvc_v4l2_release(struct file *file) |
306 | { | ||
307 | struct video_device *vdev = video_devdata(file); | ||
308 | struct uvc_device *uvc = video_get_drvdata(vdev); | ||
309 | struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); | ||
310 | struct uvc_video *video = handle->device; | ||
306 | 311 | ||
307 | case UVCIOC_SEND_RESPONSE: | 312 | uvc_function_disconnect(uvc); |
308 | ret = uvc_send_response(uvc, arg); | ||
309 | break; | ||
310 | 313 | ||
311 | default: | 314 | uvcg_video_enable(video, 0); |
312 | return -ENOIOCTLCMD; | 315 | uvcg_free_buffers(&video->queue); |
313 | } | ||
314 | 316 | ||
315 | return ret; | 317 | file->private_data = NULL; |
316 | } | 318 | v4l2_fh_del(&handle->vfh); |
319 | v4l2_fh_exit(&handle->vfh); | ||
320 | kfree(handle); | ||
317 | 321 | ||
318 | static long | 322 | return 0; |
319 | uvc_v4l2_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
320 | { | ||
321 | return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl); | ||
322 | } | 323 | } |
323 | 324 | ||
324 | static int | 325 | static int |
@@ -327,7 +328,7 @@ uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) | |||
327 | struct video_device *vdev = video_devdata(file); | 328 | struct video_device *vdev = video_devdata(file); |
328 | struct uvc_device *uvc = video_get_drvdata(vdev); | 329 | struct uvc_device *uvc = video_get_drvdata(vdev); |
329 | 330 | ||
330 | return uvc_queue_mmap(&uvc->video.queue, vma); | 331 | return uvcg_queue_mmap(&uvc->video.queue, vma); |
331 | } | 332 | } |
332 | 333 | ||
333 | static unsigned int | 334 | static unsigned int |
@@ -336,30 +337,30 @@ uvc_v4l2_poll(struct file *file, poll_table *wait) | |||
336 | struct video_device *vdev = video_devdata(file); | 337 | struct video_device *vdev = video_devdata(file); |
337 | struct uvc_device *uvc = video_get_drvdata(vdev); | 338 | struct uvc_device *uvc = video_get_drvdata(vdev); |
338 | 339 | ||
339 | return uvc_queue_poll(&uvc->video.queue, file, wait); | 340 | return uvcg_queue_poll(&uvc->video.queue, file, wait); |
340 | } | 341 | } |
341 | 342 | ||
342 | #ifndef CONFIG_MMU | 343 | #ifndef CONFIG_MMU |
343 | static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, | 344 | static unsigned long uvcg_v4l2_get_unmapped_area(struct file *file, |
344 | unsigned long addr, unsigned long len, unsigned long pgoff, | 345 | unsigned long addr, unsigned long len, unsigned long pgoff, |
345 | unsigned long flags) | 346 | unsigned long flags) |
346 | { | 347 | { |
347 | struct video_device *vdev = video_devdata(file); | 348 | struct video_device *vdev = video_devdata(file); |
348 | struct uvc_device *uvc = video_get_drvdata(vdev); | 349 | struct uvc_device *uvc = video_get_drvdata(vdev); |
349 | 350 | ||
350 | return uvc_queue_get_unmapped_area(&uvc->video.queue, pgoff); | 351 | return uvcg_queue_get_unmapped_area(&uvc->video.queue, pgoff); |
351 | } | 352 | } |
352 | #endif | 353 | #endif |
353 | 354 | ||
354 | static struct v4l2_file_operations uvc_v4l2_fops = { | 355 | struct v4l2_file_operations uvc_v4l2_fops = { |
355 | .owner = THIS_MODULE, | 356 | .owner = THIS_MODULE, |
356 | .open = uvc_v4l2_open, | 357 | .open = uvc_v4l2_open, |
357 | .release = uvc_v4l2_release, | 358 | .release = uvc_v4l2_release, |
358 | .ioctl = uvc_v4l2_ioctl, | 359 | .ioctl = video_ioctl2, |
359 | .mmap = uvc_v4l2_mmap, | 360 | .mmap = uvc_v4l2_mmap, |
360 | .poll = uvc_v4l2_poll, | 361 | .poll = uvc_v4l2_poll, |
361 | #ifndef CONFIG_MMU | 362 | #ifndef CONFIG_MMU |
362 | .get_unmapped_area = uvc_v4l2_get_unmapped_area, | 363 | .get_unmapped_area = uvcg_v4l2_get_unmapped_area, |
363 | #endif | 364 | #endif |
364 | }; | 365 | }; |
365 | 366 | ||
diff --git a/drivers/usb/gadget/function/uvc_v4l2.h b/drivers/usb/gadget/function/uvc_v4l2.h new file mode 100644 index 000000000000..2683b92fda65 --- /dev/null +++ b/drivers/usb/gadget/function/uvc_v4l2.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* | ||
2 | * uvc_v4l2.h -- USB Video Class Gadget driver | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 | ||
5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) | ||
6 | * | ||
7 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
8 | * http://www.samsung.com | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef __UVC_V4L2_H__ | ||
17 | #define __UVC_V4L2_H__ | ||
18 | |||
19 | extern const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops; | ||
20 | extern struct v4l2_file_operations uvc_v4l2_fops; | ||
21 | |||
22 | #endif /* __UVC_V4L2_H__ */ | ||
diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index a5eb9a3fbb7a..c3e1f27dbbef 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
16 | #include <linux/usb/ch9.h> | 16 | #include <linux/usb/ch9.h> |
17 | #include <linux/usb/gadget.h> | 17 | #include <linux/usb/gadget.h> |
18 | #include <linux/usb/video.h> | ||
18 | 19 | ||
19 | #include <media/v4l2-dev.h> | 20 | #include <media/v4l2-dev.h> |
20 | 21 | ||
@@ -85,7 +86,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video, | |||
85 | if (buf->bytesused == video->queue.buf_used) { | 86 | if (buf->bytesused == video->queue.buf_used) { |
86 | video->queue.buf_used = 0; | 87 | video->queue.buf_used = 0; |
87 | buf->state = UVC_BUF_STATE_DONE; | 88 | buf->state = UVC_BUF_STATE_DONE; |
88 | uvc_queue_next_buffer(&video->queue, buf); | 89 | uvcg_queue_next_buffer(&video->queue, buf); |
89 | video->fid ^= UVC_STREAM_FID; | 90 | video->fid ^= UVC_STREAM_FID; |
90 | 91 | ||
91 | video->payload_size = 0; | 92 | video->payload_size = 0; |
@@ -118,7 +119,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video, | |||
118 | if (buf->bytesused == video->queue.buf_used) { | 119 | if (buf->bytesused == video->queue.buf_used) { |
119 | video->queue.buf_used = 0; | 120 | video->queue.buf_used = 0; |
120 | buf->state = UVC_BUF_STATE_DONE; | 121 | buf->state = UVC_BUF_STATE_DONE; |
121 | uvc_queue_next_buffer(&video->queue, buf); | 122 | uvcg_queue_next_buffer(&video->queue, buf); |
122 | video->fid ^= UVC_STREAM_FID; | 123 | video->fid ^= UVC_STREAM_FID; |
123 | } | 124 | } |
124 | } | 125 | } |
@@ -171,19 +172,19 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) | |||
171 | break; | 172 | break; |
172 | 173 | ||
173 | case -ESHUTDOWN: /* disconnect from host. */ | 174 | case -ESHUTDOWN: /* disconnect from host. */ |
174 | printk(KERN_INFO "VS request cancelled.\n"); | 175 | printk(KERN_DEBUG "VS request cancelled.\n"); |
175 | uvc_queue_cancel(queue, 1); | 176 | uvcg_queue_cancel(queue, 1); |
176 | goto requeue; | 177 | goto requeue; |
177 | 178 | ||
178 | default: | 179 | default: |
179 | printk(KERN_INFO "VS request completed with status %d.\n", | 180 | printk(KERN_INFO "VS request completed with status %d.\n", |
180 | req->status); | 181 | req->status); |
181 | uvc_queue_cancel(queue, 0); | 182 | uvcg_queue_cancel(queue, 0); |
182 | goto requeue; | 183 | goto requeue; |
183 | } | 184 | } |
184 | 185 | ||
185 | spin_lock_irqsave(&video->queue.irqlock, flags); | 186 | spin_lock_irqsave(&video->queue.irqlock, flags); |
186 | buf = uvc_queue_head(&video->queue); | 187 | buf = uvcg_queue_head(&video->queue); |
187 | if (buf == NULL) { | 188 | if (buf == NULL) { |
188 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 189 | spin_unlock_irqrestore(&video->queue.irqlock, flags); |
189 | goto requeue; | 190 | goto requeue; |
@@ -195,7 +196,7 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) | |||
195 | printk(KERN_INFO "Failed to queue request (%d).\n", ret); | 196 | printk(KERN_INFO "Failed to queue request (%d).\n", ret); |
196 | usb_ep_set_halt(ep); | 197 | usb_ep_set_halt(ep); |
197 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 198 | spin_unlock_irqrestore(&video->queue.irqlock, flags); |
198 | uvc_queue_cancel(queue, 0); | 199 | uvcg_queue_cancel(queue, 0); |
199 | goto requeue; | 200 | goto requeue; |
200 | } | 201 | } |
201 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 202 | spin_unlock_irqrestore(&video->queue.irqlock, flags); |
@@ -274,13 +275,12 @@ error: | |||
274 | */ | 275 | */ |
275 | 276 | ||
276 | /* | 277 | /* |
277 | * uvc_video_pump - Pump video data into the USB requests | 278 | * uvcg_video_pump - Pump video data into the USB requests |
278 | * | 279 | * |
279 | * This function fills the available USB requests (listed in req_free) with | 280 | * This function fills the available USB requests (listed in req_free) with |
280 | * video data from the queued buffers. | 281 | * video data from the queued buffers. |
281 | */ | 282 | */ |
282 | static int | 283 | int uvcg_video_pump(struct uvc_video *video) |
283 | uvc_video_pump(struct uvc_video *video) | ||
284 | { | 284 | { |
285 | struct uvc_video_queue *queue = &video->queue; | 285 | struct uvc_video_queue *queue = &video->queue; |
286 | struct usb_request *req; | 286 | struct usb_request *req; |
@@ -288,7 +288,7 @@ uvc_video_pump(struct uvc_video *video) | |||
288 | unsigned long flags; | 288 | unsigned long flags; |
289 | int ret; | 289 | int ret; |
290 | 290 | ||
291 | /* FIXME TODO Race between uvc_video_pump and requests completion | 291 | /* FIXME TODO Race between uvcg_video_pump and requests completion |
292 | * handler ??? | 292 | * handler ??? |
293 | */ | 293 | */ |
294 | 294 | ||
@@ -309,10 +309,10 @@ uvc_video_pump(struct uvc_video *video) | |||
309 | /* Retrieve the first available video buffer and fill the | 309 | /* Retrieve the first available video buffer and fill the |
310 | * request, protected by the video queue irqlock. | 310 | * request, protected by the video queue irqlock. |
311 | */ | 311 | */ |
312 | spin_lock_irqsave(&video->queue.irqlock, flags); | 312 | spin_lock_irqsave(&queue->irqlock, flags); |
313 | buf = uvc_queue_head(&video->queue); | 313 | buf = uvcg_queue_head(queue); |
314 | if (buf == NULL) { | 314 | if (buf == NULL) { |
315 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 315 | spin_unlock_irqrestore(&queue->irqlock, flags); |
316 | break; | 316 | break; |
317 | } | 317 | } |
318 | 318 | ||
@@ -323,11 +323,11 @@ uvc_video_pump(struct uvc_video *video) | |||
323 | if (ret < 0) { | 323 | if (ret < 0) { |
324 | printk(KERN_INFO "Failed to queue request (%d)\n", ret); | 324 | printk(KERN_INFO "Failed to queue request (%d)\n", ret); |
325 | usb_ep_set_halt(video->ep); | 325 | usb_ep_set_halt(video->ep); |
326 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 326 | spin_unlock_irqrestore(&queue->irqlock, flags); |
327 | uvc_queue_cancel(queue, 0); | 327 | uvcg_queue_cancel(queue, 0); |
328 | break; | 328 | break; |
329 | } | 329 | } |
330 | spin_unlock_irqrestore(&video->queue.irqlock, flags); | 330 | spin_unlock_irqrestore(&queue->irqlock, flags); |
331 | } | 331 | } |
332 | 332 | ||
333 | spin_lock_irqsave(&video->req_lock, flags); | 333 | spin_lock_irqsave(&video->req_lock, flags); |
@@ -339,8 +339,7 @@ uvc_video_pump(struct uvc_video *video) | |||
339 | /* | 339 | /* |
340 | * Enable or disable the video stream. | 340 | * Enable or disable the video stream. |
341 | */ | 341 | */ |
342 | static int | 342 | int uvcg_video_enable(struct uvc_video *video, int enable) |
343 | uvc_video_enable(struct uvc_video *video, int enable) | ||
344 | { | 343 | { |
345 | unsigned int i; | 344 | unsigned int i; |
346 | int ret; | 345 | int ret; |
@@ -356,11 +355,11 @@ uvc_video_enable(struct uvc_video *video, int enable) | |||
356 | usb_ep_dequeue(video->ep, video->req[i]); | 355 | usb_ep_dequeue(video->ep, video->req[i]); |
357 | 356 | ||
358 | uvc_video_free_requests(video); | 357 | uvc_video_free_requests(video); |
359 | uvc_queue_enable(&video->queue, 0); | 358 | uvcg_queue_enable(&video->queue, 0); |
360 | return 0; | 359 | return 0; |
361 | } | 360 | } |
362 | 361 | ||
363 | if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) | 362 | if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) |
364 | return ret; | 363 | return ret; |
365 | 364 | ||
366 | if ((ret = uvc_video_alloc_requests(video)) < 0) | 365 | if ((ret = uvc_video_alloc_requests(video)) < 0) |
@@ -372,14 +371,13 @@ uvc_video_enable(struct uvc_video *video, int enable) | |||
372 | } else | 371 | } else |
373 | video->encode = uvc_video_encode_isoc; | 372 | video->encode = uvc_video_encode_isoc; |
374 | 373 | ||
375 | return uvc_video_pump(video); | 374 | return uvcg_video_pump(video); |
376 | } | 375 | } |
377 | 376 | ||
378 | /* | 377 | /* |
379 | * Initialize the UVC video stream. | 378 | * Initialize the UVC video stream. |
380 | */ | 379 | */ |
381 | static int | 380 | int uvcg_video_init(struct uvc_video *video) |
382 | uvc_video_init(struct uvc_video *video) | ||
383 | { | 381 | { |
384 | INIT_LIST_HEAD(&video->req_free); | 382 | INIT_LIST_HEAD(&video->req_free); |
385 | spin_lock_init(&video->req_lock); | 383 | spin_lock_init(&video->req_lock); |
@@ -391,7 +389,7 @@ uvc_video_init(struct uvc_video *video) | |||
391 | video->imagesize = 320 * 240 * 2; | 389 | video->imagesize = 320 * 240 * 2; |
392 | 390 | ||
393 | /* Initialize the video buffers queue. */ | 391 | /* Initialize the video buffers queue. */ |
394 | uvc_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT); | 392 | uvcg_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT); |
395 | return 0; | 393 | return 0; |
396 | } | 394 | } |
397 | 395 | ||
diff --git a/drivers/usb/gadget/function/uvc_video.h b/drivers/usb/gadget/function/uvc_video.h new file mode 100644 index 000000000000..ef00f06fa00b --- /dev/null +++ b/drivers/usb/gadget/function/uvc_video.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * uvc_video.h -- USB Video Class Gadget driver | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 | ||
5 | * Laurent Pinchart (laurent.pinchart@ideasonboard.com) | ||
6 | * | ||
7 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
8 | * http://www.samsung.com | ||
9 | * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | #ifndef __UVC_VIDEO_H__ | ||
16 | #define __UVC_VIDEO_H__ | ||
17 | |||
18 | int uvcg_video_pump(struct uvc_video *video); | ||
19 | |||
20 | int uvcg_video_enable(struct uvc_video *video, int enable); | ||
21 | |||
22 | int uvcg_video_init(struct uvc_video *video); | ||
23 | |||
24 | #endif /* __UVC_VIDEO_H__ */ | ||
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig index aa376f006333..24392d269709 100644 --- a/drivers/usb/gadget/legacy/Kconfig +++ b/drivers/usb/gadget/legacy/Kconfig | |||
@@ -54,6 +54,8 @@ config USB_AUDIO | |||
54 | depends on SND | 54 | depends on SND |
55 | select USB_LIBCOMPOSITE | 55 | select USB_LIBCOMPOSITE |
56 | select SND_PCM | 56 | select SND_PCM |
57 | select USB_F_UAC1 if GADGET_UAC1 | ||
58 | select USB_F_UAC2 if !GADGET_UAC1 | ||
57 | help | 59 | help |
58 | This Gadget Audio driver is compatible with USB Audio Class | 60 | This Gadget Audio driver is compatible with USB Audio Class |
59 | specification 2.0. It implements 1 AudioControl interface, | 61 | specification 2.0. It implements 1 AudioControl interface, |
@@ -466,6 +468,7 @@ config USB_G_WEBCAM | |||
466 | depends on VIDEO_DEV | 468 | depends on VIDEO_DEV |
467 | select USB_LIBCOMPOSITE | 469 | select USB_LIBCOMPOSITE |
468 | select VIDEOBUF2_VMALLOC | 470 | select VIDEOBUF2_VMALLOC |
471 | select USB_F_UVC | ||
469 | help | 472 | help |
470 | The Webcam Gadget acts as a composite USB Audio and Video Class | 473 | The Webcam Gadget acts as a composite USB Audio and Video Class |
471 | device. It provides a userspace API to process UVC control requests | 474 | device. It provides a userspace API to process UVC control requests |
diff --git a/drivers/usb/gadget/legacy/Makefile b/drivers/usb/gadget/legacy/Makefile index edba2d1ee0f3..7f485f25705e 100644 --- a/drivers/usb/gadget/legacy/Makefile +++ b/drivers/usb/gadget/legacy/Makefile | |||
@@ -2,9 +2,9 @@ | |||
2 | # USB gadget drivers | 2 | # USB gadget drivers |
3 | # | 3 | # |
4 | 4 | ||
5 | ccflags-y := -Idrivers/usb/gadget/ | 5 | ccflags-y := -I$(srctree)/drivers/usb/gadget/ |
6 | ccflags-y += -Idrivers/usb/gadget/udc/ | 6 | ccflags-y += -I$(srctree)/drivers/usb/gadget/udc/ |
7 | ccflags-y += -Idrivers/usb/gadget/function/ | 7 | ccflags-y += -I$(srctree)/drivers/usb/gadget/function/ |
8 | 8 | ||
9 | g_zero-y := zero.o | 9 | g_zero-y := zero.o |
10 | g_audio-y := audio.o | 10 | g_audio-y := audio.o |
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c index 6eb695e5e43a..f46a3956e43d 100644 --- a/drivers/usb/gadget/legacy/audio.c +++ b/drivers/usb/gadget/legacy/audio.c | |||
@@ -21,6 +21,66 @@ | |||
21 | 21 | ||
22 | USB_GADGET_COMPOSITE_OPTIONS(); | 22 | USB_GADGET_COMPOSITE_OPTIONS(); |
23 | 23 | ||
24 | #ifndef CONFIG_GADGET_UAC1 | ||
25 | #include "u_uac2.h" | ||
26 | |||
27 | /* Playback(USB-IN) Default Stereo - Fl/Fr */ | ||
28 | static int p_chmask = UAC2_DEF_PCHMASK; | ||
29 | module_param(p_chmask, uint, S_IRUGO); | ||
30 | MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); | ||
31 | |||
32 | /* Playback Default 48 KHz */ | ||
33 | static int p_srate = UAC2_DEF_PSRATE; | ||
34 | module_param(p_srate, uint, S_IRUGO); | ||
35 | MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); | ||
36 | |||
37 | /* Playback Default 16bits/sample */ | ||
38 | static int p_ssize = UAC2_DEF_PSSIZE; | ||
39 | module_param(p_ssize, uint, S_IRUGO); | ||
40 | MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); | ||
41 | |||
42 | /* Capture(USB-OUT) Default Stereo - Fl/Fr */ | ||
43 | static int c_chmask = UAC2_DEF_CCHMASK; | ||
44 | module_param(c_chmask, uint, S_IRUGO); | ||
45 | MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); | ||
46 | |||
47 | /* Capture Default 64 KHz */ | ||
48 | static int c_srate = UAC2_DEF_CSRATE; | ||
49 | module_param(c_srate, uint, S_IRUGO); | ||
50 | MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); | ||
51 | |||
52 | /* Capture Default 16bits/sample */ | ||
53 | static int c_ssize = UAC2_DEF_CSSIZE; | ||
54 | module_param(c_ssize, uint, S_IRUGO); | ||
55 | MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); | ||
56 | #else | ||
57 | #include "u_uac1.h" | ||
58 | |||
59 | static char *fn_play = FILE_PCM_PLAYBACK; | ||
60 | module_param(fn_play, charp, S_IRUGO); | ||
61 | MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); | ||
62 | |||
63 | static char *fn_cap = FILE_PCM_CAPTURE; | ||
64 | module_param(fn_cap, charp, S_IRUGO); | ||
65 | MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); | ||
66 | |||
67 | static char *fn_cntl = FILE_CONTROL; | ||
68 | module_param(fn_cntl, charp, S_IRUGO); | ||
69 | MODULE_PARM_DESC(fn_cntl, "Control device file name"); | ||
70 | |||
71 | static int req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; | ||
72 | module_param(req_buf_size, int, S_IRUGO); | ||
73 | MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); | ||
74 | |||
75 | static int req_count = UAC1_REQ_COUNT; | ||
76 | module_param(req_count, int, S_IRUGO); | ||
77 | MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); | ||
78 | |||
79 | static int audio_buf_size = UAC1_AUDIO_BUF_SIZE; | ||
80 | module_param(audio_buf_size, int, S_IRUGO); | ||
81 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | ||
82 | #endif | ||
83 | |||
24 | /* string IDs are assigned dynamically */ | 84 | /* string IDs are assigned dynamically */ |
25 | 85 | ||
26 | static struct usb_string strings_dev[] = { | 86 | static struct usb_string strings_dev[] = { |
@@ -40,12 +100,12 @@ static struct usb_gadget_strings *audio_strings[] = { | |||
40 | NULL, | 100 | NULL, |
41 | }; | 101 | }; |
42 | 102 | ||
43 | #ifdef CONFIG_GADGET_UAC1 | 103 | #ifndef CONFIG_GADGET_UAC1 |
44 | #include "u_uac1.h" | 104 | static struct usb_function_instance *fi_uac2; |
45 | #include "u_uac1.c" | 105 | static struct usb_function *f_uac2; |
46 | #include "f_uac1.c" | ||
47 | #else | 106 | #else |
48 | #include "f_uac2.c" | 107 | static struct usb_function_instance *fi_uac1; |
108 | static struct usb_function *f_uac1; | ||
49 | #endif | 109 | #endif |
50 | 110 | ||
51 | /*-------------------------------------------------------------------------*/ | 111 | /*-------------------------------------------------------------------------*/ |
@@ -109,6 +169,8 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
109 | 169 | ||
110 | static int __init audio_do_config(struct usb_configuration *c) | 170 | static int __init audio_do_config(struct usb_configuration *c) |
111 | { | 171 | { |
172 | int status; | ||
173 | |||
112 | /* FIXME alloc iConfiguration string, set it in c->strings */ | 174 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
113 | 175 | ||
114 | if (gadget_is_otg(c->cdev->gadget)) { | 176 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -116,7 +178,31 @@ static int __init audio_do_config(struct usb_configuration *c) | |||
116 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 178 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
117 | } | 179 | } |
118 | 180 | ||
119 | audio_bind_config(c); | 181 | #ifdef CONFIG_GADGET_UAC1 |
182 | f_uac1 = usb_get_function(fi_uac1); | ||
183 | if (IS_ERR(f_uac1)) { | ||
184 | status = PTR_ERR(f_uac1); | ||
185 | return status; | ||
186 | } | ||
187 | |||
188 | status = usb_add_function(c, f_uac1); | ||
189 | if (status < 0) { | ||
190 | usb_put_function(f_uac1); | ||
191 | return status; | ||
192 | } | ||
193 | #else | ||
194 | f_uac2 = usb_get_function(fi_uac2); | ||
195 | if (IS_ERR(f_uac2)) { | ||
196 | status = PTR_ERR(f_uac2); | ||
197 | return status; | ||
198 | } | ||
199 | |||
200 | status = usb_add_function(c, f_uac2); | ||
201 | if (status < 0) { | ||
202 | usb_put_function(f_uac2); | ||
203 | return status; | ||
204 | } | ||
205 | #endif | ||
120 | 206 | ||
121 | return 0; | 207 | return 0; |
122 | } | 208 | } |
@@ -126,17 +212,47 @@ static struct usb_configuration audio_config_driver = { | |||
126 | .bConfigurationValue = 1, | 212 | .bConfigurationValue = 1, |
127 | /* .iConfiguration = DYNAMIC */ | 213 | /* .iConfiguration = DYNAMIC */ |
128 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 214 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
129 | #ifndef CONFIG_GADGET_UAC1 | ||
130 | .unbind = uac2_unbind_config, | ||
131 | #endif | ||
132 | }; | 215 | }; |
133 | 216 | ||
134 | /*-------------------------------------------------------------------------*/ | 217 | /*-------------------------------------------------------------------------*/ |
135 | 218 | ||
136 | static int __init audio_bind(struct usb_composite_dev *cdev) | 219 | static int __init audio_bind(struct usb_composite_dev *cdev) |
137 | { | 220 | { |
221 | #ifndef CONFIG_GADGET_UAC1 | ||
222 | struct f_uac2_opts *uac2_opts; | ||
223 | #else | ||
224 | struct f_uac1_opts *uac1_opts; | ||
225 | #endif | ||
138 | int status; | 226 | int status; |
139 | 227 | ||
228 | #ifndef CONFIG_GADGET_UAC1 | ||
229 | fi_uac2 = usb_get_function_instance("uac2"); | ||
230 | if (IS_ERR(fi_uac2)) | ||
231 | return PTR_ERR(fi_uac2); | ||
232 | #else | ||
233 | fi_uac1 = usb_get_function_instance("uac1"); | ||
234 | if (IS_ERR(fi_uac1)) | ||
235 | return PTR_ERR(fi_uac1); | ||
236 | #endif | ||
237 | |||
238 | #ifndef CONFIG_GADGET_UAC1 | ||
239 | uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst); | ||
240 | uac2_opts->p_chmask = p_chmask; | ||
241 | uac2_opts->p_srate = p_srate; | ||
242 | uac2_opts->p_ssize = p_ssize; | ||
243 | uac2_opts->c_chmask = c_chmask; | ||
244 | uac2_opts->c_srate = c_srate; | ||
245 | uac2_opts->c_ssize = c_ssize; | ||
246 | #else | ||
247 | uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); | ||
248 | uac1_opts->fn_play = fn_play; | ||
249 | uac1_opts->fn_cap = fn_cap; | ||
250 | uac1_opts->fn_cntl = fn_cntl; | ||
251 | uac1_opts->req_buf_size = req_buf_size; | ||
252 | uac1_opts->req_count = req_count; | ||
253 | uac1_opts->audio_buf_size = audio_buf_size; | ||
254 | #endif | ||
255 | |||
140 | status = usb_string_ids_tab(cdev, strings_dev); | 256 | status = usb_string_ids_tab(cdev, strings_dev); |
141 | if (status < 0) | 257 | if (status < 0) |
142 | goto fail; | 258 | goto fail; |
@@ -152,13 +268,26 @@ static int __init audio_bind(struct usb_composite_dev *cdev) | |||
152 | return 0; | 268 | return 0; |
153 | 269 | ||
154 | fail: | 270 | fail: |
271 | #ifndef CONFIG_GADGET_UAC1 | ||
272 | usb_put_function_instance(fi_uac2); | ||
273 | #else | ||
274 | usb_put_function_instance(fi_uac1); | ||
275 | #endif | ||
155 | return status; | 276 | return status; |
156 | } | 277 | } |
157 | 278 | ||
158 | static int __exit audio_unbind(struct usb_composite_dev *cdev) | 279 | static int __exit audio_unbind(struct usb_composite_dev *cdev) |
159 | { | 280 | { |
160 | #ifdef CONFIG_GADGET_UAC1 | 281 | #ifdef CONFIG_GADGET_UAC1 |
161 | gaudio_cleanup(); | 282 | if (!IS_ERR_OR_NULL(f_uac1)) |
283 | usb_put_function(f_uac1); | ||
284 | if (!IS_ERR_OR_NULL(fi_uac1)) | ||
285 | usb_put_function_instance(fi_uac1); | ||
286 | #else | ||
287 | if (!IS_ERR_OR_NULL(f_uac2)) | ||
288 | usb_put_function(f_uac2); | ||
289 | if (!IS_ERR_OR_NULL(fi_uac2)) | ||
290 | usb_put_function_instance(fi_uac2); | ||
162 | #endif | 291 | #endif |
163 | return 0; | 292 | return 0; |
164 | } | 293 | } |
diff --git a/drivers/usb/gadget/legacy/dbgp.c b/drivers/usb/gadget/legacy/dbgp.c index 225e385a6160..1b075132f8f1 100644 --- a/drivers/usb/gadget/legacy/dbgp.c +++ b/drivers/usb/gadget/legacy/dbgp.c | |||
@@ -410,6 +410,7 @@ static __refdata struct usb_gadget_driver dbgp_driver = { | |||
410 | .bind = dbgp_bind, | 410 | .bind = dbgp_bind, |
411 | .unbind = dbgp_unbind, | 411 | .unbind = dbgp_unbind, |
412 | .setup = dbgp_setup, | 412 | .setup = dbgp_setup, |
413 | .reset = dbgp_disconnect, | ||
413 | .disconnect = dbgp_disconnect, | 414 | .disconnect = dbgp_disconnect, |
414 | .driver = { | 415 | .driver = { |
415 | .owner = THIS_MODULE, | 416 | .owner = THIS_MODULE, |
diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index e96077b8bf79..edefec2cc584 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c | |||
@@ -1775,6 +1775,7 @@ static struct usb_gadget_driver gadgetfs_driver = { | |||
1775 | .bind = gadgetfs_bind, | 1775 | .bind = gadgetfs_bind, |
1776 | .unbind = gadgetfs_unbind, | 1776 | .unbind = gadgetfs_unbind, |
1777 | .setup = gadgetfs_setup, | 1777 | .setup = gadgetfs_setup, |
1778 | .reset = gadgetfs_disconnect, | ||
1778 | .disconnect = gadgetfs_disconnect, | 1779 | .disconnect = gadgetfs_disconnect, |
1779 | .suspend = gadgetfs_suspend, | 1780 | .suspend = gadgetfs_suspend, |
1780 | 1781 | ||
diff --git a/drivers/usb/gadget/legacy/webcam.c b/drivers/usb/gadget/legacy/webcam.c index a11d8e420bfe..04a3da20f742 100644 --- a/drivers/usb/gadget/legacy/webcam.c +++ b/drivers/usb/gadget/legacy/webcam.c | |||
@@ -12,23 +12,31 @@ | |||
12 | 12 | ||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/device.h> | 14 | #include <linux/device.h> |
15 | #include <linux/module.h> | ||
15 | #include <linux/usb/video.h> | 16 | #include <linux/usb/video.h> |
16 | 17 | ||
17 | #include "f_uvc.h" | 18 | #include "u_uvc.h" |
18 | |||
19 | /* | ||
20 | * Kbuild is not very cooperative with respect to linking separately | ||
21 | * compiled library objects into one module. So for now we won't use | ||
22 | * separate compilation ... ensuring init/exit sections work to shrink | ||
23 | * the runtime footprint, and giving us at least some parts of what | ||
24 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. | ||
25 | */ | ||
26 | #include "uvc_queue.c" | ||
27 | #include "uvc_video.c" | ||
28 | #include "uvc_v4l2.c" | ||
29 | #include "f_uvc.c" | ||
30 | 19 | ||
31 | USB_GADGET_COMPOSITE_OPTIONS(); | 20 | USB_GADGET_COMPOSITE_OPTIONS(); |
21 | |||
22 | /*-------------------------------------------------------------------------*/ | ||
23 | |||
24 | /* module parameters specific to the Video streaming endpoint */ | ||
25 | static unsigned int streaming_interval = 1; | ||
26 | module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); | ||
27 | MODULE_PARM_DESC(streaming_interval, "1 - 16"); | ||
28 | |||
29 | static unsigned int streaming_maxpacket = 1024; | ||
30 | module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); | ||
31 | MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)"); | ||
32 | |||
33 | static unsigned int streaming_maxburst; | ||
34 | module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); | ||
35 | MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); | ||
36 | |||
37 | static unsigned int trace; | ||
38 | module_param(trace, uint, S_IRUGO|S_IWUSR); | ||
39 | MODULE_PARM_DESC(trace, "Trace level bitmask"); | ||
32 | /* -------------------------------------------------------------------------- | 40 | /* -------------------------------------------------------------------------- |
33 | * Device descriptor | 41 | * Device descriptor |
34 | */ | 42 | */ |
@@ -63,6 +71,9 @@ static struct usb_gadget_strings *webcam_device_strings[] = { | |||
63 | NULL, | 71 | NULL, |
64 | }; | 72 | }; |
65 | 73 | ||
74 | static struct usb_function_instance *fi_uvc; | ||
75 | static struct usb_function *f_uvc; | ||
76 | |||
66 | static struct usb_device_descriptor webcam_device_descriptor = { | 77 | static struct usb_device_descriptor webcam_device_descriptor = { |
67 | .bLength = USB_DT_DEVICE_SIZE, | 78 | .bLength = USB_DT_DEVICE_SIZE, |
68 | .bDescriptorType = USB_DT_DEVICE, | 79 | .bDescriptorType = USB_DT_DEVICE, |
@@ -326,9 +337,17 @@ static const struct uvc_descriptor_header * const uvc_ss_streaming_cls[] = { | |||
326 | static int __init | 337 | static int __init |
327 | webcam_config_bind(struct usb_configuration *c) | 338 | webcam_config_bind(struct usb_configuration *c) |
328 | { | 339 | { |
329 | return uvc_bind_config(c, uvc_fs_control_cls, uvc_ss_control_cls, | 340 | int status = 0; |
330 | uvc_fs_streaming_cls, uvc_hs_streaming_cls, | 341 | |
331 | uvc_ss_streaming_cls); | 342 | f_uvc = usb_get_function(fi_uvc); |
343 | if (IS_ERR(f_uvc)) | ||
344 | return PTR_ERR(f_uvc); | ||
345 | |||
346 | status = usb_add_function(c, f_uvc); | ||
347 | if (status < 0) | ||
348 | usb_put_function(f_uvc); | ||
349 | |||
350 | return status; | ||
332 | } | 351 | } |
333 | 352 | ||
334 | static struct usb_configuration webcam_config_driver = { | 353 | static struct usb_configuration webcam_config_driver = { |
@@ -342,14 +361,36 @@ static struct usb_configuration webcam_config_driver = { | |||
342 | static int /* __init_or_exit */ | 361 | static int /* __init_or_exit */ |
343 | webcam_unbind(struct usb_composite_dev *cdev) | 362 | webcam_unbind(struct usb_composite_dev *cdev) |
344 | { | 363 | { |
364 | if (!IS_ERR_OR_NULL(f_uvc)) | ||
365 | usb_put_function(f_uvc); | ||
366 | if (!IS_ERR_OR_NULL(fi_uvc)) | ||
367 | usb_put_function_instance(fi_uvc); | ||
345 | return 0; | 368 | return 0; |
346 | } | 369 | } |
347 | 370 | ||
348 | static int __init | 371 | static int __init |
349 | webcam_bind(struct usb_composite_dev *cdev) | 372 | webcam_bind(struct usb_composite_dev *cdev) |
350 | { | 373 | { |
374 | struct f_uvc_opts *uvc_opts; | ||
351 | int ret; | 375 | int ret; |
352 | 376 | ||
377 | fi_uvc = usb_get_function_instance("uvc"); | ||
378 | if (IS_ERR(fi_uvc)) | ||
379 | return PTR_ERR(fi_uvc); | ||
380 | |||
381 | uvc_opts = container_of(fi_uvc, struct f_uvc_opts, func_inst); | ||
382 | |||
383 | uvc_opts->streaming_interval = streaming_interval; | ||
384 | uvc_opts->streaming_maxpacket = streaming_maxpacket; | ||
385 | uvc_opts->streaming_maxburst = streaming_maxburst; | ||
386 | uvc_set_trace_param(trace); | ||
387 | |||
388 | uvc_opts->fs_control = uvc_fs_control_cls; | ||
389 | uvc_opts->ss_control = uvc_ss_control_cls; | ||
390 | uvc_opts->fs_streaming = uvc_fs_streaming_cls; | ||
391 | uvc_opts->hs_streaming = uvc_hs_streaming_cls; | ||
392 | uvc_opts->ss_streaming = uvc_ss_streaming_cls; | ||
393 | |||
353 | /* Allocate string descriptor numbers ... note that string contents | 394 | /* Allocate string descriptor numbers ... note that string contents |
354 | * can be overridden by the composite_dev glue. | 395 | * can be overridden by the composite_dev glue. |
355 | */ | 396 | */ |
@@ -373,7 +414,7 @@ webcam_bind(struct usb_composite_dev *cdev) | |||
373 | return 0; | 414 | return 0; |
374 | 415 | ||
375 | error: | 416 | error: |
376 | webcam_unbind(cdev); | 417 | usb_put_function_instance(fi_uvc); |
377 | return ret; | 418 | return ret; |
378 | } | 419 | } |
379 | 420 | ||
diff --git a/drivers/usb/gadget/legacy/zero.c b/drivers/usb/gadget/legacy/zero.c index c3d496828b74..ebf09f439f3a 100644 --- a/drivers/usb/gadget/legacy/zero.c +++ b/drivers/usb/gadget/legacy/zero.c | |||
@@ -68,6 +68,8 @@ static struct usb_zero_options gzero_options = { | |||
68 | .isoc_maxpacket = GZERO_ISOC_MAXPACKET, | 68 | .isoc_maxpacket = GZERO_ISOC_MAXPACKET, |
69 | .bulk_buflen = GZERO_BULK_BUFLEN, | 69 | .bulk_buflen = GZERO_BULK_BUFLEN, |
70 | .qlen = GZERO_QLEN, | 70 | .qlen = GZERO_QLEN, |
71 | .int_interval = GZERO_INT_INTERVAL, | ||
72 | .int_maxpacket = GZERO_INT_MAXPACKET, | ||
71 | }; | 73 | }; |
72 | 74 | ||
73 | /*-------------------------------------------------------------------------*/ | 75 | /*-------------------------------------------------------------------------*/ |
@@ -266,6 +268,21 @@ module_param_named(isoc_maxburst, gzero_options.isoc_maxburst, uint, | |||
266 | S_IRUGO|S_IWUSR); | 268 | S_IRUGO|S_IWUSR); |
267 | MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); | 269 | MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); |
268 | 270 | ||
271 | module_param_named(int_interval, gzero_options.int_interval, uint, | ||
272 | S_IRUGO|S_IWUSR); | ||
273 | MODULE_PARM_DESC(int_interval, "1 - 16"); | ||
274 | |||
275 | module_param_named(int_maxpacket, gzero_options.int_maxpacket, uint, | ||
276 | S_IRUGO|S_IWUSR); | ||
277 | MODULE_PARM_DESC(int_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); | ||
278 | |||
279 | module_param_named(int_mult, gzero_options.int_mult, uint, S_IRUGO|S_IWUSR); | ||
280 | MODULE_PARM_DESC(int_mult, "0 - 2 (hs/ss only)"); | ||
281 | |||
282 | module_param_named(int_maxburst, gzero_options.int_maxburst, uint, | ||
283 | S_IRUGO|S_IWUSR); | ||
284 | MODULE_PARM_DESC(int_maxburst, "0 - 15 (ss only)"); | ||
285 | |||
269 | static struct usb_function *func_lb; | 286 | static struct usb_function *func_lb; |
270 | static struct usb_function_instance *func_inst_lb; | 287 | static struct usb_function_instance *func_inst_lb; |
271 | 288 | ||
@@ -301,6 +318,10 @@ static int __init zero_bind(struct usb_composite_dev *cdev) | |||
301 | ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket; | 318 | ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket; |
302 | ss_opts->isoc_mult = gzero_options.isoc_mult; | 319 | ss_opts->isoc_mult = gzero_options.isoc_mult; |
303 | ss_opts->isoc_maxburst = gzero_options.isoc_maxburst; | 320 | ss_opts->isoc_maxburst = gzero_options.isoc_maxburst; |
321 | ss_opts->int_interval = gzero_options.int_interval; | ||
322 | ss_opts->int_maxpacket = gzero_options.int_maxpacket; | ||
323 | ss_opts->int_mult = gzero_options.int_mult; | ||
324 | ss_opts->int_maxburst = gzero_options.int_maxburst; | ||
304 | ss_opts->bulk_buflen = gzero_options.bulk_buflen; | 325 | ss_opts->bulk_buflen = gzero_options.bulk_buflen; |
305 | 326 | ||
306 | func_ss = usb_get_function(func_inst_ss); | 327 | func_ss = usb_get_function(func_inst_ss); |
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig index 34ebaa68504c..3ea287b0e448 100644 --- a/drivers/usb/gadget/udc/Kconfig +++ b/drivers/usb/gadget/udc/Kconfig | |||
@@ -163,7 +163,7 @@ config USB_R8A66597 | |||
163 | 163 | ||
164 | config USB_RENESAS_USBHS_UDC | 164 | config USB_RENESAS_USBHS_UDC |
165 | tristate 'Renesas USBHS controller' | 165 | tristate 'Renesas USBHS controller' |
166 | depends on USB_RENESAS_USBHS | 166 | depends on USB_RENESAS_USBHS && HAS_DMA |
167 | help | 167 | help |
168 | Renesas USBHS is a discrete USB host and peripheral controller chip | 168 | Renesas USBHS is a discrete USB host and peripheral controller chip |
169 | that supports both full and high speed USB 2.0 data transfers. | 169 | that supports both full and high speed USB 2.0 data transfers. |
@@ -354,6 +354,21 @@ config USB_EG20T | |||
354 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. | 354 | ML7213/ML7831 is completely compatible for Intel EG20T PCH. |
355 | 355 | ||
356 | This driver can be used with Intel's Quark X1000 SOC platform | 356 | This driver can be used with Intel's Quark X1000 SOC platform |
357 | |||
358 | config USB_GADGET_XILINX | ||
359 | tristate "Xilinx USB Driver" | ||
360 | depends on OF || COMPILE_TEST | ||
361 | help | ||
362 | USB peripheral controller driver for Xilinx USB2 device. | ||
363 | Xilinx USB2 device is a soft IP which supports both full | ||
364 | and high speed USB 2.0 data transfers. It has seven configurable | ||
365 | endpoints(bulk or interrupt or isochronous), as well as | ||
366 | endpoint zero(for control transfers). | ||
367 | |||
368 | Say "y" to link the driver statically, or "m" to build a | ||
369 | dynamically linked module called "udc-xilinx" and force all | ||
370 | gadget drivers to also be dynamically linked. | ||
371 | |||
357 | # | 372 | # |
358 | # LAST -- dummy/emulated controller | 373 | # LAST -- dummy/emulated controller |
359 | # | 374 | # |
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile index 4096122bb283..a7f4491593f1 100644 --- a/drivers/usb/gadget/udc/Makefile +++ b/drivers/usb/gadget/udc/Makefile | |||
@@ -29,3 +29,4 @@ obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | |||
29 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o | 29 | obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o |
30 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o | 30 | obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o |
31 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o | 31 | obj-$(CONFIG_USB_GR_UDC) += gr_udc.o |
32 | obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o | ||
diff --git a/drivers/usb/gadget/udc/amd5536udc.c b/drivers/usb/gadget/udc/amd5536udc.c index 41b062eb4de0..3b9d13848a4f 100644 --- a/drivers/usb/gadget/udc/amd5536udc.c +++ b/drivers/usb/gadget/udc/amd5536udc.c | |||
@@ -841,7 +841,7 @@ __acquires(ep->dev->lock) | |||
841 | &req->req, req->req.length, ep->ep.name, sts); | 841 | &req->req, req->req.length, ep->ep.name, sts); |
842 | 842 | ||
843 | spin_unlock(&dev->lock); | 843 | spin_unlock(&dev->lock); |
844 | req->req.complete(&ep->ep, &req->req); | 844 | usb_gadget_giveback_request(&ep->ep, &req->req); |
845 | spin_lock(&dev->lock); | 845 | spin_lock(&dev->lock); |
846 | ep->halted = halted; | 846 | ep->halted = halted; |
847 | } | 847 | } |
diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index cfd18bcca723..9968f5331fe4 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c | |||
@@ -267,7 +267,7 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status) | |||
267 | 267 | ||
268 | ep->stopped = 1; | 268 | ep->stopped = 1; |
269 | spin_unlock(&udc->lock); | 269 | spin_unlock(&udc->lock); |
270 | req->req.complete(&ep->ep, &req->req); | 270 | usb_gadget_giveback_request(&ep->ep, &req->req); |
271 | spin_lock(&udc->lock); | 271 | spin_lock(&udc->lock); |
272 | ep->stopped = stopped; | 272 | ep->stopped = stopped; |
273 | 273 | ||
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index c9fe67e29d35..1529926e20a0 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c | |||
@@ -463,7 +463,7 @@ static void receive_data(struct usba_ep *ep) | |||
463 | list_del_init(&req->queue); | 463 | list_del_init(&req->queue); |
464 | usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY); | 464 | usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY); |
465 | spin_unlock(&udc->lock); | 465 | spin_unlock(&udc->lock); |
466 | req->req.complete(&ep->ep, &req->req); | 466 | usb_gadget_giveback_request(&ep->ep, &req->req); |
467 | spin_lock(&udc->lock); | 467 | spin_lock(&udc->lock); |
468 | } | 468 | } |
469 | 469 | ||
@@ -495,7 +495,7 @@ request_complete(struct usba_ep *ep, struct usba_request *req, int status) | |||
495 | ep->ep.name, req, req->req.status, req->req.actual); | 495 | ep->ep.name, req, req->req.status, req->req.actual); |
496 | 496 | ||
497 | spin_unlock(&udc->lock); | 497 | spin_unlock(&udc->lock); |
498 | req->req.complete(&ep->ep, &req->req); | 498 | usb_gadget_giveback_request(&ep->ep, &req->req); |
499 | spin_lock(&udc->lock); | 499 | spin_lock(&udc->lock); |
500 | } | 500 | } |
501 | 501 | ||
diff --git a/drivers/usb/gadget/udc/bcm63xx_udc.c b/drivers/usb/gadget/udc/bcm63xx_udc.c index e969eb809a85..2235b8808700 100644 --- a/drivers/usb/gadget/udc/bcm63xx_udc.c +++ b/drivers/usb/gadget/udc/bcm63xx_udc.c | |||
@@ -1088,7 +1088,7 @@ static int bcm63xx_ep_disable(struct usb_ep *ep) | |||
1088 | breq->req.status = -ESHUTDOWN; | 1088 | breq->req.status = -ESHUTDOWN; |
1089 | 1089 | ||
1090 | spin_unlock_irqrestore(&udc->lock, flags); | 1090 | spin_unlock_irqrestore(&udc->lock, flags); |
1091 | breq->req.complete(&iudma->bep->ep, &breq->req); | 1091 | usb_gadget_giveback_request(&iudma->bep->ep, &breq->req); |
1092 | spin_lock_irqsave(&udc->lock, flags); | 1092 | spin_lock_irqsave(&udc->lock, flags); |
1093 | } | 1093 | } |
1094 | } | 1094 | } |
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index 2b54955d3166..81dc5959e36b 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c | |||
@@ -258,7 +258,7 @@ static void nuke(struct dummy *dum, struct dummy_ep *ep) | |||
258 | req->req.status = -ESHUTDOWN; | 258 | req->req.status = -ESHUTDOWN; |
259 | 259 | ||
260 | spin_unlock(&dum->lock); | 260 | spin_unlock(&dum->lock); |
261 | req->req.complete(&ep->ep, &req->req); | 261 | usb_gadget_giveback_request(&ep->ep, &req->req); |
262 | spin_lock(&dum->lock); | 262 | spin_lock(&dum->lock); |
263 | } | 263 | } |
264 | } | 264 | } |
@@ -658,7 +658,7 @@ static int dummy_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
658 | spin_unlock(&dum->lock); | 658 | spin_unlock(&dum->lock); |
659 | _req->actual = _req->length; | 659 | _req->actual = _req->length; |
660 | _req->status = 0; | 660 | _req->status = 0; |
661 | _req->complete(_ep, _req); | 661 | usb_gadget_giveback_request(_ep, _req); |
662 | spin_lock(&dum->lock); | 662 | spin_lock(&dum->lock); |
663 | } else | 663 | } else |
664 | list_add_tail(&req->queue, &ep->queue); | 664 | list_add_tail(&req->queue, &ep->queue); |
@@ -702,7 +702,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req) | |||
702 | dev_dbg(udc_dev(dum), | 702 | dev_dbg(udc_dev(dum), |
703 | "dequeued req %p from %s, len %d buf %p\n", | 703 | "dequeued req %p from %s, len %d buf %p\n", |
704 | req, _ep->name, _req->length, _req->buf); | 704 | req, _ep->name, _req->length, _req->buf); |
705 | _req->complete(_ep, _req); | 705 | usb_gadget_giveback_request(_ep, _req); |
706 | } | 706 | } |
707 | local_irq_restore(flags); | 707 | local_irq_restore(flags); |
708 | return retval; | 708 | return retval; |
@@ -1385,7 +1385,7 @@ top: | |||
1385 | list_del_init(&req->queue); | 1385 | list_del_init(&req->queue); |
1386 | 1386 | ||
1387 | spin_unlock(&dum->lock); | 1387 | spin_unlock(&dum->lock); |
1388 | req->req.complete(&ep->ep, &req->req); | 1388 | usb_gadget_giveback_request(&ep->ep, &req->req); |
1389 | spin_lock(&dum->lock); | 1389 | spin_lock(&dum->lock); |
1390 | 1390 | ||
1391 | /* requests might have been unlinked... */ | 1391 | /* requests might have been unlinked... */ |
@@ -1761,7 +1761,7 @@ restart: | |||
1761 | req); | 1761 | req); |
1762 | 1762 | ||
1763 | spin_unlock(&dum->lock); | 1763 | spin_unlock(&dum->lock); |
1764 | req->req.complete(&ep->ep, &req->req); | 1764 | usb_gadget_giveback_request(&ep->ep, &req->req); |
1765 | spin_lock(&dum->lock); | 1765 | spin_lock(&dum->lock); |
1766 | ep->already_seen = 0; | 1766 | ep->already_seen = 0; |
1767 | goto restart; | 1767 | goto restart; |
diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index e143d69f6017..1d315921bf34 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c | |||
@@ -70,7 +70,7 @@ static void fotg210_done(struct fotg210_ep *ep, struct fotg210_request *req, | |||
70 | req->req.status = status; | 70 | req->req.status = status; |
71 | 71 | ||
72 | spin_unlock(&ep->fotg210->lock); | 72 | spin_unlock(&ep->fotg210->lock); |
73 | req->req.complete(&ep->ep, &req->req); | 73 | usb_gadget_giveback_request(&ep->ep, &req->req); |
74 | spin_lock(&ep->fotg210->lock); | 74 | spin_lock(&ep->fotg210->lock); |
75 | 75 | ||
76 | if (ep->epnum) { | 76 | if (ep->epnum) { |
diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c index 732430804841..dd18ea38e391 100644 --- a/drivers/usb/gadget/udc/fsl_qe_udc.c +++ b/drivers/usb/gadget/udc/fsl_qe_udc.c | |||
@@ -118,10 +118,7 @@ static void done(struct qe_ep *ep, struct qe_req *req, int status) | |||
118 | ep->stopped = 1; | 118 | ep->stopped = 1; |
119 | spin_unlock(&udc->lock); | 119 | spin_unlock(&udc->lock); |
120 | 120 | ||
121 | /* this complete() should a func implemented by gadget layer, | 121 | usb_gadget_giveback_request(&ep->ep, &req->req); |
122 | * eg fsg->bulk_in_complete() */ | ||
123 | if (req->req.complete) | ||
124 | req->req.complete(&ep->ep, &req->req); | ||
125 | 122 | ||
126 | spin_lock(&udc->lock); | 123 | spin_lock(&udc->lock); |
127 | 124 | ||
@@ -2728,4 +2725,3 @@ module_platform_driver(udc_driver); | |||
2728 | MODULE_DESCRIPTION(DRIVER_DESC); | 2725 | MODULE_DESCRIPTION(DRIVER_DESC); |
2729 | MODULE_AUTHOR(DRIVER_AUTHOR); | 2726 | MODULE_AUTHOR(DRIVER_AUTHOR); |
2730 | MODULE_LICENSE("GPL"); | 2727 | MODULE_LICENSE("GPL"); |
2731 | |||
diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c index 75b23ea077a7..c3620791a315 100644 --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c | |||
@@ -197,10 +197,8 @@ __acquires(ep->udc->lock) | |||
197 | ep->stopped = 1; | 197 | ep->stopped = 1; |
198 | 198 | ||
199 | spin_unlock(&ep->udc->lock); | 199 | spin_unlock(&ep->udc->lock); |
200 | /* complete() is from gadget layer, | 200 | |
201 | * eg fsg->bulk_in_complete() */ | 201 | usb_gadget_giveback_request(&ep->ep, &req->req); |
202 | if (req->req.complete) | ||
203 | req->req.complete(&ep->ep, &req->req); | ||
204 | 202 | ||
205 | spin_lock(&ep->udc->lock); | 203 | spin_lock(&ep->udc->lock); |
206 | ep->stopped = stopped; | 204 | ep->stopped = stopped; |
diff --git a/drivers/usb/gadget/udc/fusb300_udc.c b/drivers/usb/gadget/udc/fusb300_udc.c index 5c5d1adda7eb..8286df72add4 100644 --- a/drivers/usb/gadget/udc/fusb300_udc.c +++ b/drivers/usb/gadget/udc/fusb300_udc.c | |||
@@ -876,7 +876,7 @@ static void done(struct fusb300_ep *ep, struct fusb300_request *req, | |||
876 | req->req.status = status; | 876 | req->req.status = status; |
877 | 877 | ||
878 | spin_unlock(&ep->fusb300->lock); | 878 | spin_unlock(&ep->fusb300->lock); |
879 | req->req.complete(&ep->ep, &req->req); | 879 | usb_gadget_giveback_request(&ep->ep, &req->req); |
880 | spin_lock(&ep->fusb300->lock); | 880 | spin_lock(&ep->fusb300->lock); |
881 | 881 | ||
882 | if (ep->epnum) { | 882 | if (ep->epnum) { |
diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 6c85839e15ad..bf9c5ef8b56b 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c | |||
@@ -320,7 +320,7 @@ done(struct goku_ep *ep, struct goku_request *req, int status) | |||
320 | /* don't modify queue heads during completion callback */ | 320 | /* don't modify queue heads during completion callback */ |
321 | ep->stopped = 1; | 321 | ep->stopped = 1; |
322 | spin_unlock(&dev->lock); | 322 | spin_unlock(&dev->lock); |
323 | req->req.complete(&ep->ep, &req->req); | 323 | usb_gadget_giveback_request(&ep->ep, &req->req); |
324 | spin_lock(&dev->lock); | 324 | spin_lock(&dev->lock); |
325 | ep->stopped = stopped; | 325 | ep->stopped = stopped; |
326 | } | 326 | } |
diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 08df5c4f46ce..1b3048a6a2a3 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c | |||
@@ -318,8 +318,26 @@ static void gr_finish_request(struct gr_ep *ep, struct gr_request *req, | |||
318 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); | 318 | usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); |
319 | gr_free_dma_desc_chain(dev, req); | 319 | gr_free_dma_desc_chain(dev, req); |
320 | 320 | ||
321 | if (ep->is_in) /* For OUT, actual gets updated bit by bit */ | 321 | if (ep->is_in) { /* For OUT, req->req.actual gets updated bit by bit */ |
322 | req->req.actual = req->req.length; | 322 | req->req.actual = req->req.length; |
323 | } else if (req->oddlen && req->req.actual > req->evenlen) { | ||
324 | /* | ||
325 | * Copy to user buffer in this case where length was not evenly | ||
326 | * divisible by ep->ep.maxpacket and the last descriptor was | ||
327 | * actually used. | ||
328 | */ | ||
329 | char *buftail = ((char *)req->req.buf + req->evenlen); | ||
330 | |||
331 | memcpy(buftail, ep->tailbuf, req->oddlen); | ||
332 | |||
333 | if (req->req.actual > req->req.length) { | ||
334 | /* We got more data than was requested */ | ||
335 | dev_dbg(ep->dev->dev, "Overflow for ep %s\n", | ||
336 | ep->ep.name); | ||
337 | gr_dbgprint_request("OVFL", ep, req); | ||
338 | req->req.status = -EOVERFLOW; | ||
339 | } | ||
340 | } | ||
323 | 341 | ||
324 | if (!status) { | 342 | if (!status) { |
325 | if (ep->is_in) | 343 | if (ep->is_in) |
@@ -339,7 +357,7 @@ static void gr_finish_request(struct gr_ep *ep, struct gr_request *req, | |||
339 | } else if (req->req.complete) { | 357 | } else if (req->req.complete) { |
340 | spin_unlock(&dev->lock); | 358 | spin_unlock(&dev->lock); |
341 | 359 | ||
342 | req->req.complete(&ep->ep, &req->req); | 360 | usb_gadget_giveback_request(&ep->ep, &req->req); |
343 | 361 | ||
344 | spin_lock(&dev->lock); | 362 | spin_lock(&dev->lock); |
345 | } | 363 | } |
@@ -379,6 +397,15 @@ static void gr_start_dma(struct gr_ep *ep) | |||
379 | /* A descriptor should already have been allocated */ | 397 | /* A descriptor should already have been allocated */ |
380 | BUG_ON(!req->curr_desc); | 398 | BUG_ON(!req->curr_desc); |
381 | 399 | ||
400 | /* | ||
401 | * The DMA controller can not handle smaller OUT buffers than | ||
402 | * ep->ep.maxpacket. It could lead to buffer overruns if an unexpectedly | ||
403 | * long packet are received. Therefore an internal bounce buffer gets | ||
404 | * used when such a request gets enabled. | ||
405 | */ | ||
406 | if (!ep->is_in && req->oddlen) | ||
407 | req->last_desc->data = ep->tailbuf_paddr; | ||
408 | |||
382 | wmb(); /* Make sure all is settled before handing it over to DMA */ | 409 | wmb(); /* Make sure all is settled before handing it over to DMA */ |
383 | 410 | ||
384 | /* Set the descriptor pointer in the hardware */ | 411 | /* Set the descriptor pointer in the hardware */ |
@@ -480,11 +507,11 @@ static int gr_setup_out_desc_list(struct gr_ep *ep, struct gr_request *req, | |||
480 | dma_addr_t start = req->req.dma + bytes_used; | 507 | dma_addr_t start = req->req.dma + bytes_used; |
481 | u16 size = min(bytes_left, ep->bytes_per_buffer); | 508 | u16 size = min(bytes_left, ep->bytes_per_buffer); |
482 | 509 | ||
483 | /* Should not happen however - gr_queue stops such lengths */ | 510 | if (size < ep->bytes_per_buffer) { |
484 | if (size < ep->bytes_per_buffer) | 511 | /* Prepare using bounce buffer */ |
485 | dev_warn(ep->dev->dev, | 512 | req->evenlen = req->req.length - bytes_left; |
486 | "Buffer overrun risk: %u < %u bytes/buffer\n", | 513 | req->oddlen = size; |
487 | size, ep->bytes_per_buffer); | 514 | } |
488 | 515 | ||
489 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); | 516 | ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); |
490 | if (ret) | 517 | if (ret) |
@@ -584,18 +611,6 @@ static int gr_queue(struct gr_ep *ep, struct gr_request *req, gfp_t gfp_flags) | |||
584 | return -EINVAL; | 611 | return -EINVAL; |
585 | } | 612 | } |
586 | 613 | ||
587 | /* | ||
588 | * The DMA controller can not handle smaller OUT buffers than | ||
589 | * maxpacket. It could lead to buffer overruns if unexpectedly long | ||
590 | * packet are received. | ||
591 | */ | ||
592 | if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { | ||
593 | dev_err(dev->dev, | ||
594 | "OUT request length %d is not multiple of maxpacket\n", | ||
595 | req->req.length); | ||
596 | return -EMSGSIZE; | ||
597 | } | ||
598 | |||
599 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { | 614 | if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { |
600 | dev_err(dev->dev, "-ESHUTDOWN"); | 615 | dev_err(dev->dev, "-ESHUTDOWN"); |
601 | return -ESHUTDOWN; | 616 | return -ESHUTDOWN; |
@@ -1286,8 +1301,8 @@ static int gr_handle_out_ep(struct gr_ep *ep) | |||
1286 | if (ctrl & GR_DESC_OUT_CTRL_SE) | 1301 | if (ctrl & GR_DESC_OUT_CTRL_SE) |
1287 | req->setup = 1; | 1302 | req->setup = 1; |
1288 | 1303 | ||
1289 | if (len < ep->ep.maxpacket || req->req.actual == req->req.length) { | 1304 | if (len < ep->ep.maxpacket || req->req.actual >= req->req.length) { |
1290 | /* Short packet or the expected size - we are done */ | 1305 | /* Short packet or >= expected size - we are done */ |
1291 | 1306 | ||
1292 | if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { | 1307 | if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { |
1293 | /* | 1308 | /* |
@@ -2015,6 +2030,11 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) | |||
2015 | } | 2030 | } |
2016 | list_add_tail(&ep->ep_list, &dev->ep_list); | 2031 | list_add_tail(&ep->ep_list, &dev->ep_list); |
2017 | 2032 | ||
2033 | ep->tailbuf = dma_alloc_coherent(dev->dev, ep->ep.maxpacket_limit, | ||
2034 | &ep->tailbuf_paddr, GFP_ATOMIC); | ||
2035 | if (!ep->tailbuf) | ||
2036 | return -ENOMEM; | ||
2037 | |||
2018 | return 0; | 2038 | return 0; |
2019 | } | 2039 | } |
2020 | 2040 | ||
@@ -2067,9 +2087,24 @@ static int gr_udc_init(struct gr_udc *dev) | |||
2067 | return 0; | 2087 | return 0; |
2068 | } | 2088 | } |
2069 | 2089 | ||
2090 | static void gr_ep_remove(struct gr_udc *dev, int num, int is_in) | ||
2091 | { | ||
2092 | struct gr_ep *ep; | ||
2093 | |||
2094 | if (is_in) | ||
2095 | ep = &dev->epi[num]; | ||
2096 | else | ||
2097 | ep = &dev->epo[num]; | ||
2098 | |||
2099 | if (ep->tailbuf) | ||
2100 | dma_free_coherent(dev->dev, ep->ep.maxpacket_limit, | ||
2101 | ep->tailbuf, ep->tailbuf_paddr); | ||
2102 | } | ||
2103 | |||
2070 | static int gr_remove(struct platform_device *pdev) | 2104 | static int gr_remove(struct platform_device *pdev) |
2071 | { | 2105 | { |
2072 | struct gr_udc *dev = platform_get_drvdata(pdev); | 2106 | struct gr_udc *dev = platform_get_drvdata(pdev); |
2107 | int i; | ||
2073 | 2108 | ||
2074 | if (dev->added) | 2109 | if (dev->added) |
2075 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ | 2110 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ |
@@ -2084,6 +2119,11 @@ static int gr_remove(struct platform_device *pdev) | |||
2084 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); | 2119 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); |
2085 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); | 2120 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); |
2086 | 2121 | ||
2122 | for (i = 0; i < dev->nepo; i++) | ||
2123 | gr_ep_remove(dev, i, 0); | ||
2124 | for (i = 0; i < dev->nepi; i++) | ||
2125 | gr_ep_remove(dev, i, 1); | ||
2126 | |||
2087 | return 0; | 2127 | return 0; |
2088 | } | 2128 | } |
2089 | static int gr_request_irq(struct gr_udc *dev, int irq) | 2129 | static int gr_request_irq(struct gr_udc *dev, int irq) |
@@ -2131,7 +2171,6 @@ static int gr_probe(struct platform_device *pdev) | |||
2131 | dev->gadget.name = driver_name; | 2171 | dev->gadget.name = driver_name; |
2132 | dev->gadget.max_speed = USB_SPEED_HIGH; | 2172 | dev->gadget.max_speed = USB_SPEED_HIGH; |
2133 | dev->gadget.ops = &gr_ops; | 2173 | dev->gadget.ops = &gr_ops; |
2134 | dev->gadget.quirk_ep_out_aligned_size = true; | ||
2135 | 2174 | ||
2136 | spin_lock_init(&dev->lock); | 2175 | spin_lock_init(&dev->lock); |
2137 | dev->regs = regs; | 2176 | dev->regs = regs; |
diff --git a/drivers/usb/gadget/udc/gr_udc.h b/drivers/usb/gadget/udc/gr_udc.h index 8388897d9ec3..4297c4e8021f 100644 --- a/drivers/usb/gadget/udc/gr_udc.h +++ b/drivers/usb/gadget/udc/gr_udc.h | |||
@@ -156,6 +156,10 @@ struct gr_ep { | |||
156 | struct list_head queue; | 156 | struct list_head queue; |
157 | 157 | ||
158 | struct list_head ep_list; | 158 | struct list_head ep_list; |
159 | |||
160 | /* Bounce buffer for end of "odd" sized OUT requests */ | ||
161 | void *tailbuf; | ||
162 | dma_addr_t tailbuf_paddr; | ||
159 | }; | 163 | }; |
160 | 164 | ||
161 | struct gr_request { | 165 | struct gr_request { |
@@ -167,6 +171,9 @@ struct gr_request { | |||
167 | struct gr_dma_desc *curr_desc; /* Current descriptor */ | 171 | struct gr_dma_desc *curr_desc; /* Current descriptor */ |
168 | struct gr_dma_desc *last_desc; /* Last in the chain */ | 172 | struct gr_dma_desc *last_desc; /* Last in the chain */ |
169 | 173 | ||
174 | u16 evenlen; /* Size of even length head (if oddlen != 0) */ | ||
175 | u16 oddlen; /* Size of odd length tail if buffer length is "odd" */ | ||
176 | |||
170 | u8 setup; /* Setup packet */ | 177 | u8 setup; /* Setup packet */ |
171 | }; | 178 | }; |
172 | 179 | ||
diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index 1629ad7dcb80..feab0bac8fdc 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c | |||
@@ -1479,7 +1479,7 @@ static void done(struct lpc32xx_ep *ep, struct lpc32xx_request *req, int status) | |||
1479 | 1479 | ||
1480 | ep->req_pending = 0; | 1480 | ep->req_pending = 0; |
1481 | spin_unlock(&udc->lock); | 1481 | spin_unlock(&udc->lock); |
1482 | req->req.complete(&ep->ep, &req->req); | 1482 | usb_gadget_giveback_request(&ep->ep, &req->req); |
1483 | spin_lock(&udc->lock); | 1483 | spin_lock(&udc->lock); |
1484 | } | 1484 | } |
1485 | 1485 | ||
diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c index de88d33b44b2..898565687a8c 100644 --- a/drivers/usb/gadget/udc/m66592-udc.c +++ b/drivers/usb/gadget/udc/m66592-udc.c | |||
@@ -729,7 +729,7 @@ __acquires(m66592->lock) | |||
729 | restart = 1; | 729 | restart = 1; |
730 | 730 | ||
731 | spin_unlock(&ep->m66592->lock); | 731 | spin_unlock(&ep->m66592->lock); |
732 | req->req.complete(&ep->ep, &req->req); | 732 | usb_gadget_giveback_request(&ep->ep, &req->req); |
733 | spin_lock(&ep->m66592->lock); | 733 | spin_lock(&ep->m66592->lock); |
734 | 734 | ||
735 | if (restart) { | 735 | if (restart) { |
diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index 16248711c152..046a1f808b0d 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c | |||
@@ -222,12 +222,8 @@ void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status) | |||
222 | } | 222 | } |
223 | 223 | ||
224 | spin_unlock(&ep->u3d->lock); | 224 | spin_unlock(&ep->u3d->lock); |
225 | /* | 225 | |
226 | * complete() is from gadget layer, | 226 | usb_gadget_giveback_request(&ep->ep, &req->req); |
227 | * eg fsg->bulk_in_complete() | ||
228 | */ | ||
229 | if (req->req.complete) | ||
230 | req->req.complete(&ep->ep, &req->req); | ||
231 | 227 | ||
232 | spin_lock(&ep->u3d->lock); | 228 | spin_lock(&ep->u3d->lock); |
233 | } | 229 | } |
diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index 040fb169b162..3c5db80ae325 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c | |||
@@ -248,12 +248,8 @@ static void done(struct mv_ep *ep, struct mv_req *req, int status) | |||
248 | ep->stopped = 1; | 248 | ep->stopped = 1; |
249 | 249 | ||
250 | spin_unlock(&ep->udc->lock); | 250 | spin_unlock(&ep->udc->lock); |
251 | /* | 251 | |
252 | * complete() is from gadget layer, | 252 | usb_gadget_giveback_request(&ep->ep, &req->req); |
253 | * eg fsg->bulk_in_complete() | ||
254 | */ | ||
255 | if (req->req.complete) | ||
256 | req->req.complete(&ep->ep, &req->req); | ||
257 | 253 | ||
258 | spin_lock(&ep->udc->lock); | 254 | spin_lock(&ep->udc->lock); |
259 | ep->stopped = stopped; | 255 | ep->stopped = stopped; |
diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index 059cfe527982..84d7162a8022 100644 --- a/drivers/usb/gadget/udc/net2272.c +++ b/drivers/usb/gadget/udc/net2272.c | |||
@@ -394,7 +394,7 @@ net2272_done(struct net2272_ep *ep, struct net2272_request *req, int status) | |||
394 | /* don't modify queue heads during completion callback */ | 394 | /* don't modify queue heads during completion callback */ |
395 | ep->stopped = 1; | 395 | ep->stopped = 1; |
396 | spin_unlock(&dev->lock); | 396 | spin_unlock(&dev->lock); |
397 | req->req.complete(&ep->ep, &req->req); | 397 | usb_gadget_giveback_request(&ep->ep, &req->req); |
398 | spin_lock(&dev->lock); | 398 | spin_lock(&dev->lock); |
399 | ep->stopped = stopped; | 399 | ep->stopped = stopped; |
400 | } | 400 | } |
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 2e95715b50c0..8d13337e2dde 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c | |||
@@ -928,7 +928,7 @@ done(struct net2280_ep *ep, struct net2280_request *req, int status) | |||
928 | /* don't modify queue heads during completion callback */ | 928 | /* don't modify queue heads during completion callback */ |
929 | ep->stopped = 1; | 929 | ep->stopped = 1; |
930 | spin_unlock(&dev->lock); | 930 | spin_unlock(&dev->lock); |
931 | req->req.complete(&ep->ep, &req->req); | 931 | usb_gadget_giveback_request(&ep->ep, &req->req); |
932 | spin_lock(&dev->lock); | 932 | spin_lock(&dev->lock); |
933 | ep->stopped = stopped; | 933 | ep->stopped = stopped; |
934 | } | 934 | } |
diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index e731373fd4d7..dcdfea46003b 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c | |||
@@ -315,7 +315,7 @@ done(struct omap_ep *ep, struct omap_req *req, int status) | |||
315 | /* don't modify queue heads during completion callback */ | 315 | /* don't modify queue heads during completion callback */ |
316 | ep->stopped = 1; | 316 | ep->stopped = 1; |
317 | spin_unlock(&ep->udc->lock); | 317 | spin_unlock(&ep->udc->lock); |
318 | req->req.complete(&ep->ep, &req->req); | 318 | usb_gadget_giveback_request(&ep->ep, &req->req); |
319 | spin_lock(&ep->udc->lock); | 319 | spin_lock(&ep->udc->lock); |
320 | ep->stopped = stopped; | 320 | ep->stopped = stopped; |
321 | } | 321 | } |
diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c index 460d953c91b6..ccbe3d4a2a50 100644 --- a/drivers/usb/gadget/udc/pch_udc.c +++ b/drivers/usb/gadget/udc/pch_udc.c | |||
@@ -1490,7 +1490,7 @@ static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, | |||
1490 | spin_unlock(&dev->lock); | 1490 | spin_unlock(&dev->lock); |
1491 | if (!ep->in) | 1491 | if (!ep->in) |
1492 | pch_udc_ep_clear_rrdy(ep); | 1492 | pch_udc_ep_clear_rrdy(ep); |
1493 | req->req.complete(&ep->ep, &req->req); | 1493 | usb_gadget_giveback_request(&ep->ep, &req->req); |
1494 | spin_lock(&dev->lock); | 1494 | spin_lock(&dev->lock); |
1495 | ep->halted = halted; | 1495 | ep->halted = halted; |
1496 | } | 1496 | } |
diff --git a/drivers/usb/gadget/udc/pxa25x_udc.c b/drivers/usb/gadget/udc/pxa25x_udc.c index 251e4d5ee152..42f7eeb8ff6f 100644 --- a/drivers/usb/gadget/udc/pxa25x_udc.c +++ b/drivers/usb/gadget/udc/pxa25x_udc.c | |||
@@ -347,7 +347,7 @@ static void done(struct pxa25x_ep *ep, struct pxa25x_request *req, int status) | |||
347 | 347 | ||
348 | /* don't modify queue heads during completion callback */ | 348 | /* don't modify queue heads during completion callback */ |
349 | ep->stopped = 1; | 349 | ep->stopped = 1; |
350 | req->req.complete(&ep->ep, &req->req); | 350 | usb_gadget_giveback_request(&ep->ep, &req->req); |
351 | ep->stopped = stopped; | 351 | ep->stopped = stopped; |
352 | } | 352 | } |
353 | 353 | ||
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 597d39f89420..4868369eeec6 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c | |||
@@ -758,7 +758,7 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status, | |||
758 | if (pflags) | 758 | if (pflags) |
759 | spin_unlock_irqrestore(&ep->lock, *pflags); | 759 | spin_unlock_irqrestore(&ep->lock, *pflags); |
760 | local_irq_save(flags); | 760 | local_irq_save(flags); |
761 | req->req.complete(&req->udc_usb_ep->usb_ep, &req->req); | 761 | usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req); |
762 | local_irq_restore(flags); | 762 | local_irq_restore(flags); |
763 | if (pflags) | 763 | if (pflags) |
764 | spin_lock_irqsave(&ep->lock, *pflags); | 764 | spin_lock_irqsave(&ep->lock, *pflags); |
diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c index de2a8713b428..f8186613b53e 100644 --- a/drivers/usb/gadget/udc/r8a66597-udc.c +++ b/drivers/usb/gadget/udc/r8a66597-udc.c | |||
@@ -430,7 +430,7 @@ static void r8a66597_ep_setting(struct r8a66597 *r8a66597, | |||
430 | ep->pipenum = pipenum; | 430 | ep->pipenum = pipenum; |
431 | ep->ep.maxpacket = usb_endpoint_maxp(desc); | 431 | ep->ep.maxpacket = usb_endpoint_maxp(desc); |
432 | r8a66597->pipenum2ep[pipenum] = ep; | 432 | r8a66597->pipenum2ep[pipenum] = ep; |
433 | r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] | 433 | r8a66597->epaddr2ep[usb_endpoint_num(desc)] |
434 | = ep; | 434 | = ep; |
435 | INIT_LIST_HEAD(&ep->queue); | 435 | INIT_LIST_HEAD(&ep->queue); |
436 | } | 436 | } |
@@ -464,7 +464,7 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
464 | if (ep->pipenum) /* already allocated pipe */ | 464 | if (ep->pipenum) /* already allocated pipe */ |
465 | return 0; | 465 | return 0; |
466 | 466 | ||
467 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | 467 | switch (usb_endpoint_type(desc)) { |
468 | case USB_ENDPOINT_XFER_BULK: | 468 | case USB_ENDPOINT_XFER_BULK: |
469 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { | 469 | if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { |
470 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { | 470 | if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { |
@@ -509,7 +509,7 @@ static int alloc_pipe_config(struct r8a66597_ep *ep, | |||
509 | } | 509 | } |
510 | ep->type = info.type; | 510 | ep->type = info.type; |
511 | 511 | ||
512 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | 512 | info.epnum = usb_endpoint_num(desc); |
513 | info.maxpacket = usb_endpoint_maxp(desc); | 513 | info.maxpacket = usb_endpoint_maxp(desc); |
514 | info.interval = desc->bInterval; | 514 | info.interval = desc->bInterval; |
515 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 515 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
@@ -925,7 +925,7 @@ __acquires(r8a66597->lock) | |||
925 | sudmac_free_channel(ep->r8a66597, ep, req); | 925 | sudmac_free_channel(ep->r8a66597, ep, req); |
926 | 926 | ||
927 | spin_unlock(&ep->r8a66597->lock); | 927 | spin_unlock(&ep->r8a66597->lock); |
928 | req->req.complete(&ep->ep, &req->req); | 928 | usb_gadget_giveback_request(&ep->ep, &req->req); |
929 | spin_lock(&ep->r8a66597->lock); | 929 | spin_lock(&ep->r8a66597->lock); |
930 | 930 | ||
931 | if (restart) { | 931 | if (restart) { |
@@ -1846,10 +1846,8 @@ static int r8a66597_sudmac_ioremap(struct r8a66597 *r8a66597, | |||
1846 | 1846 | ||
1847 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); | 1847 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); |
1848 | r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); | 1848 | r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); |
1849 | if (IS_ERR(r8a66597->sudmac_reg)) { | 1849 | if (IS_ERR(r8a66597->sudmac_reg)) |
1850 | dev_err(&pdev->dev, "ioremap error(sudmac).\n"); | ||
1851 | return PTR_ERR(r8a66597->sudmac_reg); | 1850 | return PTR_ERR(r8a66597->sudmac_reg); |
1852 | } | ||
1853 | 1851 | ||
1854 | return 0; | 1852 | return 0; |
1855 | } | 1853 | } |
diff --git a/drivers/usb/gadget/udc/s3c-hsudc.c b/drivers/usb/gadget/udc/s3c-hsudc.c index 10c6a128250c..dfbf55797360 100644 --- a/drivers/usb/gadget/udc/s3c-hsudc.c +++ b/drivers/usb/gadget/udc/s3c-hsudc.c | |||
@@ -258,8 +258,7 @@ static void s3c_hsudc_complete_request(struct s3c_hsudc_ep *hsep, | |||
258 | 258 | ||
259 | hsep->stopped = 1; | 259 | hsep->stopped = 1; |
260 | spin_unlock(&hsudc->lock); | 260 | spin_unlock(&hsudc->lock); |
261 | if (hsreq->req.complete != NULL) | 261 | usb_gadget_giveback_request(&hsep->ep, &hsreq->req); |
262 | hsreq->req.complete(&hsep->ep, &hsreq->req); | ||
263 | spin_lock(&hsudc->lock); | 262 | spin_lock(&hsudc->lock); |
264 | hsep->stopped = stopped; | 263 | hsep->stopped = stopped; |
265 | } | 264 | } |
diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c b/drivers/usb/gadget/udc/s3c2410_udc.c index 357b58e0087b..ff423d15beff 100644 --- a/drivers/usb/gadget/udc/s3c2410_udc.c +++ b/drivers/usb/gadget/udc/s3c2410_udc.c | |||
@@ -272,7 +272,7 @@ static void s3c2410_udc_done(struct s3c2410_ep *ep, | |||
272 | status = req->req.status; | 272 | status = req->req.status; |
273 | 273 | ||
274 | ep->halted = 1; | 274 | ep->halted = 1; |
275 | req->req.complete(&ep->ep, &req->req); | 275 | usb_gadget_giveback_request(&ep->ep, &req->req); |
276 | ep->halted = halted; | 276 | ep->halted = halted; |
277 | } | 277 | } |
278 | 278 | ||
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index b0d98172bc07..f107bb60a5ab 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | #include <linux/usb/ch9.h> | 28 | #include <linux/usb/ch9.h> |
29 | #include <linux/usb/gadget.h> | 29 | #include <linux/usb/gadget.h> |
30 | #include <linux/usb.h> | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * struct usb_udc - describes one usb device controller | 33 | * struct usb_udc - describes one usb device controller |
@@ -106,11 +107,42 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request); | |||
106 | 107 | ||
107 | /* ------------------------------------------------------------------------- */ | 108 | /* ------------------------------------------------------------------------- */ |
108 | 109 | ||
110 | /** | ||
111 | * usb_gadget_giveback_request - give the request back to the gadget layer | ||
112 | * Context: in_interrupt() | ||
113 | * | ||
114 | * This is called by device controller drivers in order to return the | ||
115 | * completed request back to the gadget layer. | ||
116 | */ | ||
117 | void usb_gadget_giveback_request(struct usb_ep *ep, | ||
118 | struct usb_request *req) | ||
119 | { | ||
120 | if (likely(req->status == 0)) | ||
121 | usb_led_activity(USB_LED_EVENT_GADGET); | ||
122 | |||
123 | req->complete(ep, req); | ||
124 | } | ||
125 | EXPORT_SYMBOL_GPL(usb_gadget_giveback_request); | ||
126 | |||
127 | /* ------------------------------------------------------------------------- */ | ||
128 | |||
109 | static void usb_gadget_state_work(struct work_struct *work) | 129 | static void usb_gadget_state_work(struct work_struct *work) |
110 | { | 130 | { |
111 | struct usb_gadget *gadget = work_to_gadget(work); | 131 | struct usb_gadget *gadget = work_to_gadget(work); |
132 | struct usb_udc *udc = NULL; | ||
133 | |||
134 | mutex_lock(&udc_lock); | ||
135 | list_for_each_entry(udc, &udc_list, list) | ||
136 | if (udc->gadget == gadget) | ||
137 | goto found; | ||
138 | mutex_unlock(&udc_lock); | ||
139 | |||
140 | return; | ||
141 | |||
142 | found: | ||
143 | mutex_unlock(&udc_lock); | ||
112 | 144 | ||
113 | sysfs_notify(&gadget->dev.kobj, NULL, "state"); | 145 | sysfs_notify(&udc->dev.kobj, NULL, "state"); |
114 | } | 146 | } |
115 | 147 | ||
116 | void usb_gadget_set_state(struct usb_gadget *gadget, | 148 | void usb_gadget_set_state(struct usb_gadget *gadget, |
@@ -124,6 +156,23 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); | |||
124 | /* ------------------------------------------------------------------------- */ | 156 | /* ------------------------------------------------------------------------- */ |
125 | 157 | ||
126 | /** | 158 | /** |
159 | * usb_gadget_udc_reset - notifies the udc core that bus reset occurs | ||
160 | * @gadget: The gadget which bus reset occurs | ||
161 | * @driver: The gadget driver we want to notify | ||
162 | * | ||
163 | * If the udc driver has bus reset handler, it needs to call this when the bus | ||
164 | * reset occurs, it notifies the gadget driver that the bus reset occurs as | ||
165 | * well as updates gadget state. | ||
166 | */ | ||
167 | void usb_gadget_udc_reset(struct usb_gadget *gadget, | ||
168 | struct usb_gadget_driver *driver) | ||
169 | { | ||
170 | driver->reset(gadget); | ||
171 | usb_gadget_set_state(gadget, USB_STATE_DEFAULT); | ||
172 | } | ||
173 | EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); | ||
174 | |||
175 | /** | ||
127 | * usb_gadget_udc_start - tells usb device controller to start up | 176 | * usb_gadget_udc_start - tells usb device controller to start up |
128 | * @gadget: The gadget we want to get started | 177 | * @gadget: The gadget we want to get started |
129 | * @driver: The driver we want to bind to @gadget | 178 | * @driver: The driver we want to bind to @gadget |
diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c new file mode 100644 index 000000000000..ed27e1687a4e --- /dev/null +++ b/drivers/usb/gadget/udc/udc-xilinx.c | |||
@@ -0,0 +1,2180 @@ | |||
1 | /* | ||
2 | * Xilinx USB peripheral controller driver | ||
3 | * | ||
4 | * Copyright (C) 2004 by Thomas Rathbone | ||
5 | * Copyright (C) 2005 by HP Labs | ||
6 | * Copyright (C) 2005 by David Brownell | ||
7 | * Copyright (C) 2010 - 2014 Xilinx, Inc. | ||
8 | * | ||
9 | * Some parts of this driver code is based on the driver for at91-series | ||
10 | * USB peripheral controller (at91_udc.c). | ||
11 | * | ||
12 | * This program is free software; you can redistribute it | ||
13 | * and/or modify it under the terms of the GNU General Public | ||
14 | * License as published by the Free Software Foundation; | ||
15 | * either version 2 of the License, or (at your option) any | ||
16 | * later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/delay.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/dma-mapping.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/io.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/of_address.h> | ||
26 | #include <linux/of_device.h> | ||
27 | #include <linux/of_platform.h> | ||
28 | #include <linux/of_irq.h> | ||
29 | #include <linux/prefetch.h> | ||
30 | #include <linux/usb/ch9.h> | ||
31 | #include <linux/usb/gadget.h> | ||
32 | |||
33 | /* Register offsets for the USB device.*/ | ||
34 | #define XUSB_EP0_CONFIG_OFFSET 0x0000 /* EP0 Config Reg Offset */ | ||
35 | #define XUSB_SETUP_PKT_ADDR_OFFSET 0x0080 /* Setup Packet Address */ | ||
36 | #define XUSB_ADDRESS_OFFSET 0x0100 /* Address Register */ | ||
37 | #define XUSB_CONTROL_OFFSET 0x0104 /* Control Register */ | ||
38 | #define XUSB_STATUS_OFFSET 0x0108 /* Status Register */ | ||
39 | #define XUSB_FRAMENUM_OFFSET 0x010C /* Frame Number Register */ | ||
40 | #define XUSB_IER_OFFSET 0x0110 /* Interrupt Enable Register */ | ||
41 | #define XUSB_BUFFREADY_OFFSET 0x0114 /* Buffer Ready Register */ | ||
42 | #define XUSB_TESTMODE_OFFSET 0x0118 /* Test Mode Register */ | ||
43 | #define XUSB_DMA_RESET_OFFSET 0x0200 /* DMA Soft Reset Register */ | ||
44 | #define XUSB_DMA_CONTROL_OFFSET 0x0204 /* DMA Control Register */ | ||
45 | #define XUSB_DMA_DSAR_ADDR_OFFSET 0x0208 /* DMA source Address Reg */ | ||
46 | #define XUSB_DMA_DDAR_ADDR_OFFSET 0x020C /* DMA destination Addr Reg */ | ||
47 | #define XUSB_DMA_LENGTH_OFFSET 0x0210 /* DMA Length Register */ | ||
48 | #define XUSB_DMA_STATUS_OFFSET 0x0214 /* DMA Status Register */ | ||
49 | |||
50 | /* Endpoint Configuration Space offsets */ | ||
51 | #define XUSB_EP_CFGSTATUS_OFFSET 0x00 /* Endpoint Config Status */ | ||
52 | #define XUSB_EP_BUF0COUNT_OFFSET 0x08 /* Buffer 0 Count */ | ||
53 | #define XUSB_EP_BUF1COUNT_OFFSET 0x0C /* Buffer 1 Count */ | ||
54 | |||
55 | #define XUSB_CONTROL_USB_READY_MASK 0x80000000 /* USB ready Mask */ | ||
56 | #define XUSB_CONTROL_USB_RMTWAKE_MASK 0x40000000 /* Remote wake up mask */ | ||
57 | |||
58 | /* Interrupt register related masks.*/ | ||
59 | #define XUSB_STATUS_GLOBAL_INTR_MASK 0x80000000 /* Global Intr Enable */ | ||
60 | #define XUSB_STATUS_DMADONE_MASK 0x04000000 /* DMA done Mask */ | ||
61 | #define XUSB_STATUS_DMAERR_MASK 0x02000000 /* DMA Error Mask */ | ||
62 | #define XUSB_STATUS_DMABUSY_MASK 0x80000000 /* DMA Error Mask */ | ||
63 | #define XUSB_STATUS_RESUME_MASK 0x01000000 /* USB Resume Mask */ | ||
64 | #define XUSB_STATUS_RESET_MASK 0x00800000 /* USB Reset Mask */ | ||
65 | #define XUSB_STATUS_SUSPEND_MASK 0x00400000 /* USB Suspend Mask */ | ||
66 | #define XUSB_STATUS_DISCONNECT_MASK 0x00200000 /* USB Disconnect Mask */ | ||
67 | #define XUSB_STATUS_FIFO_BUFF_RDY_MASK 0x00100000 /* FIFO Buff Ready Mask */ | ||
68 | #define XUSB_STATUS_FIFO_BUFF_FREE_MASK 0x00080000 /* FIFO Buff Free Mask */ | ||
69 | #define XUSB_STATUS_SETUP_PACKET_MASK 0x00040000 /* Setup packet received */ | ||
70 | #define XUSB_STATUS_EP1_BUFF2_COMP_MASK 0x00000200 /* EP 1 Buff 2 Processed */ | ||
71 | #define XUSB_STATUS_EP1_BUFF1_COMP_MASK 0x00000002 /* EP 1 Buff 1 Processed */ | ||
72 | #define XUSB_STATUS_EP0_BUFF2_COMP_MASK 0x00000100 /* EP 0 Buff 2 Processed */ | ||
73 | #define XUSB_STATUS_EP0_BUFF1_COMP_MASK 0x00000001 /* EP 0 Buff 1 Processed */ | ||
74 | #define XUSB_STATUS_HIGH_SPEED_MASK 0x00010000 /* USB Speed Mask */ | ||
75 | /* Suspend,Reset,Suspend and Disconnect Mask */ | ||
76 | #define XUSB_STATUS_INTR_EVENT_MASK 0x01E00000 | ||
77 | /* Buffers completion Mask */ | ||
78 | #define XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK 0x0000FEFF | ||
79 | /* Mask for buffer 0 and buffer 1 completion for all Endpoints */ | ||
80 | #define XUSB_STATUS_INTR_BUFF_COMP_SHIFT_MASK 0x00000101 | ||
81 | #define XUSB_STATUS_EP_BUFF2_SHIFT 8 /* EP buffer offset */ | ||
82 | |||
83 | /* Endpoint Configuration Status Register */ | ||
84 | #define XUSB_EP_CFG_VALID_MASK 0x80000000 /* Endpoint Valid bit */ | ||
85 | #define XUSB_EP_CFG_STALL_MASK 0x40000000 /* Endpoint Stall bit */ | ||
86 | #define XUSB_EP_CFG_DATA_TOGGLE_MASK 0x08000000 /* Endpoint Data toggle */ | ||
87 | |||
88 | /* USB device specific global configuration constants.*/ | ||
89 | #define XUSB_MAX_ENDPOINTS 8 /* Maximum End Points */ | ||
90 | #define XUSB_EP_NUMBER_ZERO 0 /* End point Zero */ | ||
91 | /* DPRAM is the source address for DMA transfer */ | ||
92 | #define XUSB_DMA_READ_FROM_DPRAM 0x80000000 | ||
93 | #define XUSB_DMA_DMASR_BUSY 0x80000000 /* DMA busy */ | ||
94 | #define XUSB_DMA_DMASR_ERROR 0x40000000 /* DMA Error */ | ||
95 | /* | ||
96 | * When this bit is set, the DMA buffer ready bit is set by hardware upon | ||
97 | * DMA transfer completion. | ||
98 | */ | ||
99 | #define XUSB_DMA_BRR_CTRL 0x40000000 /* DMA bufready ctrl bit */ | ||
100 | /* Phase States */ | ||
101 | #define SETUP_PHASE 0x0000 /* Setup Phase */ | ||
102 | #define DATA_PHASE 0x0001 /* Data Phase */ | ||
103 | #define STATUS_PHASE 0x0002 /* Status Phase */ | ||
104 | |||
105 | #define EP0_MAX_PACKET 64 /* Endpoint 0 maximum packet length */ | ||
106 | #define STATUSBUFF_SIZE 2 /* Buffer size for GET_STATUS command */ | ||
107 | #define EPNAME_SIZE 4 /* Buffer size for endpoint name */ | ||
108 | |||
109 | /* container_of helper macros */ | ||
110 | #define to_udc(g) container_of((g), struct xusb_udc, gadget) | ||
111 | #define to_xusb_ep(ep) container_of((ep), struct xusb_ep, ep_usb) | ||
112 | #define to_xusb_req(req) container_of((req), struct xusb_req, usb_req) | ||
113 | |||
114 | /** | ||
115 | * struct xusb_req - Xilinx USB device request structure | ||
116 | * @usb_req: Linux usb request structure | ||
117 | * @queue: usb device request queue | ||
118 | * @ep: pointer to xusb_endpoint structure | ||
119 | */ | ||
120 | struct xusb_req { | ||
121 | struct usb_request usb_req; | ||
122 | struct list_head queue; | ||
123 | struct xusb_ep *ep; | ||
124 | }; | ||
125 | |||
126 | /** | ||
127 | * struct xusb_ep - USB end point structure. | ||
128 | * @ep_usb: usb endpoint instance | ||
129 | * @queue: endpoint message queue | ||
130 | * @udc: xilinx usb peripheral driver instance pointer | ||
131 | * @desc: pointer to the usb endpoint descriptor | ||
132 | * @rambase: the endpoint buffer address | ||
133 | * @offset: the endpoint register offset value | ||
134 | * @name: name of the endpoint | ||
135 | * @epnumber: endpoint number | ||
136 | * @maxpacket: maximum packet size the endpoint can store | ||
137 | * @buffer0count: the size of the packet recieved in the first buffer | ||
138 | * @buffer1count: the size of the packet received in the second buffer | ||
139 | * @curbufnum: current buffer of endpoint that will be processed next | ||
140 | * @buffer0ready: the busy state of first buffer | ||
141 | * @buffer1ready: the busy state of second buffer | ||
142 | * @is_in: endpoint direction (IN or OUT) | ||
143 | * @is_iso: endpoint type(isochronous or non isochronous) | ||
144 | */ | ||
145 | struct xusb_ep { | ||
146 | struct usb_ep ep_usb; | ||
147 | struct list_head queue; | ||
148 | struct xusb_udc *udc; | ||
149 | const struct usb_endpoint_descriptor *desc; | ||
150 | u32 rambase; | ||
151 | u32 offset; | ||
152 | char name[4]; | ||
153 | u16 epnumber; | ||
154 | u16 maxpacket; | ||
155 | u16 buffer0count; | ||
156 | u16 buffer1count; | ||
157 | u8 curbufnum; | ||
158 | bool buffer0ready; | ||
159 | bool buffer1ready; | ||
160 | bool is_in; | ||
161 | bool is_iso; | ||
162 | }; | ||
163 | |||
164 | /** | ||
165 | * struct xusb_udc - USB peripheral driver structure | ||
166 | * @gadget: USB gadget driver instance | ||
167 | * @ep: an array of endpoint structures | ||
168 | * @driver: pointer to the usb gadget driver instance | ||
169 | * @setup: usb_ctrlrequest structure for control requests | ||
170 | * @req: pointer to dummy request for get status command | ||
171 | * @dev: pointer to device structure in gadget | ||
172 | * @usb_state: device in suspended state or not | ||
173 | * @remote_wkp: remote wakeup enabled by host | ||
174 | * @setupseqtx: tx status | ||
175 | * @setupseqrx: rx status | ||
176 | * @addr: the usb device base address | ||
177 | * @lock: instance of spinlock | ||
178 | * @dma_enabled: flag indicating whether the dma is included in the system | ||
179 | * @read_fn: function pointer to read device registers | ||
180 | * @write_fn: function pointer to write to device registers | ||
181 | */ | ||
182 | struct xusb_udc { | ||
183 | struct usb_gadget gadget; | ||
184 | struct xusb_ep ep[8]; | ||
185 | struct usb_gadget_driver *driver; | ||
186 | struct usb_ctrlrequest setup; | ||
187 | struct xusb_req *req; | ||
188 | struct device *dev; | ||
189 | u32 usb_state; | ||
190 | u32 remote_wkp; | ||
191 | u32 setupseqtx; | ||
192 | u32 setupseqrx; | ||
193 | void __iomem *addr; | ||
194 | spinlock_t lock; | ||
195 | bool dma_enabled; | ||
196 | |||
197 | unsigned int (*read_fn)(void __iomem *); | ||
198 | void (*write_fn)(void __iomem *, u32, u32); | ||
199 | }; | ||
200 | |||
201 | /* Endpoint buffer start addresses in the core */ | ||
202 | static u32 rambase[8] = { 0x22, 0x1000, 0x1100, 0x1200, 0x1300, 0x1400, 0x1500, | ||
203 | 0x1600 }; | ||
204 | |||
205 | static const char driver_name[] = "xilinx-udc"; | ||
206 | static const char ep0name[] = "ep0"; | ||
207 | |||
208 | /* Control endpoint configuration.*/ | ||
209 | static const struct usb_endpoint_descriptor config_bulk_out_desc = { | ||
210 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
211 | .bDescriptorType = USB_DT_ENDPOINT, | ||
212 | .bEndpointAddress = USB_DIR_OUT, | ||
213 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
214 | .wMaxPacketSize = cpu_to_le16(EP0_MAX_PACKET), | ||
215 | }; | ||
216 | |||
217 | /** | ||
218 | * xudc_write32 - little endian write to device registers | ||
219 | * @addr: base addr of device registers | ||
220 | * @offset: register offset | ||
221 | * @val: data to be written | ||
222 | */ | ||
223 | static void xudc_write32(void __iomem *addr, u32 offset, u32 val) | ||
224 | { | ||
225 | iowrite32(val, addr + offset); | ||
226 | } | ||
227 | |||
228 | /** | ||
229 | * xudc_read32 - little endian read from device registers | ||
230 | * @addr: addr of device register | ||
231 | * Return: value at addr | ||
232 | */ | ||
233 | static unsigned int xudc_read32(void __iomem *addr) | ||
234 | { | ||
235 | return ioread32(addr); | ||
236 | } | ||
237 | |||
238 | /** | ||
239 | * xudc_write32_be - big endian write to device registers | ||
240 | * @addr: base addr of device registers | ||
241 | * @offset: register offset | ||
242 | * @val: data to be written | ||
243 | */ | ||
244 | static void xudc_write32_be(void __iomem *addr, u32 offset, u32 val) | ||
245 | { | ||
246 | iowrite32be(val, addr + offset); | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * xudc_read32_be - big endian read from device registers | ||
251 | * @addr: addr of device register | ||
252 | * Return: value at addr | ||
253 | */ | ||
254 | static unsigned int xudc_read32_be(void __iomem *addr) | ||
255 | { | ||
256 | return ioread32be(addr); | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * xudc_wrstatus - Sets up the usb device status stages. | ||
261 | * @udc: pointer to the usb device controller structure. | ||
262 | */ | ||
263 | static void xudc_wrstatus(struct xusb_udc *udc) | ||
264 | { | ||
265 | struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; | ||
266 | u32 epcfgreg; | ||
267 | |||
268 | epcfgreg = udc->read_fn(udc->addr + ep0->offset)| | ||
269 | XUSB_EP_CFG_DATA_TOGGLE_MASK; | ||
270 | udc->write_fn(udc->addr, ep0->offset, epcfgreg); | ||
271 | udc->write_fn(udc->addr, ep0->offset + XUSB_EP_BUF0COUNT_OFFSET, 0); | ||
272 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); | ||
273 | } | ||
274 | |||
275 | /** | ||
276 | * xudc_epconfig - Configures the given endpoint. | ||
277 | * @ep: pointer to the usb device endpoint structure. | ||
278 | * @udc: pointer to the usb peripheral controller structure. | ||
279 | * | ||
280 | * This function configures a specific endpoint with the given configuration | ||
281 | * data. | ||
282 | */ | ||
283 | static void xudc_epconfig(struct xusb_ep *ep, struct xusb_udc *udc) | ||
284 | { | ||
285 | u32 epcfgreg; | ||
286 | |||
287 | /* | ||
288 | * Configure the end point direction, type, Max Packet Size and the | ||
289 | * EP buffer location. | ||
290 | */ | ||
291 | epcfgreg = ((ep->is_in << 29) | (ep->is_iso << 28) | | ||
292 | (ep->ep_usb.maxpacket << 15) | (ep->rambase)); | ||
293 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
294 | |||
295 | /* Set the Buffer count and the Buffer ready bits.*/ | ||
296 | udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF0COUNT_OFFSET, | ||
297 | ep->buffer0count); | ||
298 | udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF1COUNT_OFFSET, | ||
299 | ep->buffer1count); | ||
300 | if (ep->buffer0ready) | ||
301 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
302 | 1 << ep->epnumber); | ||
303 | if (ep->buffer1ready) | ||
304 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
305 | 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * xudc_start_dma - Starts DMA transfer. | ||
310 | * @ep: pointer to the usb device endpoint structure. | ||
311 | * @src: DMA source address. | ||
312 | * @dst: DMA destination address. | ||
313 | * @length: number of bytes to transfer. | ||
314 | * | ||
315 | * Return: 0 on success, error code on failure | ||
316 | * | ||
317 | * This function starts DMA transfer by writing to DMA source, | ||
318 | * destination and lenth registers. | ||
319 | */ | ||
320 | static int xudc_start_dma(struct xusb_ep *ep, dma_addr_t src, | ||
321 | dma_addr_t dst, u32 length) | ||
322 | { | ||
323 | struct xusb_udc *udc = ep->udc; | ||
324 | int rc = 0; | ||
325 | u32 timeout = 500; | ||
326 | u32 reg; | ||
327 | |||
328 | /* | ||
329 | * Set the addresses in the DMA source and | ||
330 | * destination registers and then set the length | ||
331 | * into the DMA length register. | ||
332 | */ | ||
333 | udc->write_fn(udc->addr, XUSB_DMA_DSAR_ADDR_OFFSET, src); | ||
334 | udc->write_fn(udc->addr, XUSB_DMA_DDAR_ADDR_OFFSET, dst); | ||
335 | udc->write_fn(udc->addr, XUSB_DMA_LENGTH_OFFSET, length); | ||
336 | |||
337 | /* | ||
338 | * Wait till DMA transaction is complete and | ||
339 | * check whether the DMA transaction was | ||
340 | * successful. | ||
341 | */ | ||
342 | do { | ||
343 | reg = udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET); | ||
344 | if (!(reg & XUSB_DMA_DMASR_BUSY)) | ||
345 | break; | ||
346 | |||
347 | /* | ||
348 | * We can't sleep here, because it's also called from | ||
349 | * interrupt context. | ||
350 | */ | ||
351 | timeout--; | ||
352 | if (!timeout) { | ||
353 | dev_err(udc->dev, "DMA timeout\n"); | ||
354 | return -ETIMEDOUT; | ||
355 | } | ||
356 | udelay(1); | ||
357 | } while (1); | ||
358 | |||
359 | if ((udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET) & | ||
360 | XUSB_DMA_DMASR_ERROR) == XUSB_DMA_DMASR_ERROR){ | ||
361 | dev_err(udc->dev, "DMA Error\n"); | ||
362 | rc = -EINVAL; | ||
363 | } | ||
364 | |||
365 | return rc; | ||
366 | } | ||
367 | |||
368 | /** | ||
369 | * xudc_dma_send - Sends IN data using DMA. | ||
370 | * @ep: pointer to the usb device endpoint structure. | ||
371 | * @req: pointer to the usb request structure. | ||
372 | * @buffer: pointer to data to be sent. | ||
373 | * @length: number of bytes to send. | ||
374 | * | ||
375 | * Return: 0 on success, -EAGAIN if no buffer is free and error | ||
376 | * code on failure. | ||
377 | * | ||
378 | * This function sends data using DMA. | ||
379 | */ | ||
380 | static int xudc_dma_send(struct xusb_ep *ep, struct xusb_req *req, | ||
381 | u8 *buffer, u32 length) | ||
382 | { | ||
383 | u32 *eprambase; | ||
384 | dma_addr_t src; | ||
385 | dma_addr_t dst; | ||
386 | struct xusb_udc *udc = ep->udc; | ||
387 | |||
388 | src = req->usb_req.dma + req->usb_req.actual; | ||
389 | if (req->usb_req.length) | ||
390 | dma_sync_single_for_device(udc->dev, src, | ||
391 | length, DMA_TO_DEVICE); | ||
392 | if (!ep->curbufnum && !ep->buffer0ready) { | ||
393 | /* Get the Buffer address and copy the transmit data.*/ | ||
394 | eprambase = (u32 __force *)(udc->addr + ep->rambase); | ||
395 | dst = virt_to_phys(eprambase); | ||
396 | udc->write_fn(udc->addr, ep->offset + | ||
397 | XUSB_EP_BUF0COUNT_OFFSET, length); | ||
398 | udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, | ||
399 | XUSB_DMA_BRR_CTRL | (1 << ep->epnumber)); | ||
400 | ep->buffer0ready = 1; | ||
401 | ep->curbufnum = 1; | ||
402 | } else if (ep->curbufnum && !ep->buffer1ready) { | ||
403 | /* Get the Buffer address and copy the transmit data.*/ | ||
404 | eprambase = (u32 __force *)(udc->addr + ep->rambase + | ||
405 | ep->ep_usb.maxpacket); | ||
406 | dst = virt_to_phys(eprambase); | ||
407 | udc->write_fn(udc->addr, ep->offset + | ||
408 | XUSB_EP_BUF1COUNT_OFFSET, length); | ||
409 | udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, | ||
410 | XUSB_DMA_BRR_CTRL | (1 << (ep->epnumber + | ||
411 | XUSB_STATUS_EP_BUFF2_SHIFT))); | ||
412 | ep->buffer1ready = 1; | ||
413 | ep->curbufnum = 0; | ||
414 | } else { | ||
415 | /* None of ping pong buffers are ready currently .*/ | ||
416 | return -EAGAIN; | ||
417 | } | ||
418 | |||
419 | return xudc_start_dma(ep, src, dst, length); | ||
420 | } | ||
421 | |||
422 | /** | ||
423 | * xudc_dma_receive - Receives OUT data using DMA. | ||
424 | * @ep: pointer to the usb device endpoint structure. | ||
425 | * @req: pointer to the usb request structure. | ||
426 | * @buffer: pointer to storage buffer of received data. | ||
427 | * @length: number of bytes to receive. | ||
428 | * | ||
429 | * Return: 0 on success, -EAGAIN if no buffer is free and error | ||
430 | * code on failure. | ||
431 | * | ||
432 | * This function receives data using DMA. | ||
433 | */ | ||
434 | static int xudc_dma_receive(struct xusb_ep *ep, struct xusb_req *req, | ||
435 | u8 *buffer, u32 length) | ||
436 | { | ||
437 | u32 *eprambase; | ||
438 | dma_addr_t src; | ||
439 | dma_addr_t dst; | ||
440 | struct xusb_udc *udc = ep->udc; | ||
441 | |||
442 | dst = req->usb_req.dma + req->usb_req.actual; | ||
443 | if (!ep->curbufnum && !ep->buffer0ready) { | ||
444 | /* Get the Buffer address and copy the transmit data */ | ||
445 | eprambase = (u32 __force *)(udc->addr + ep->rambase); | ||
446 | src = virt_to_phys(eprambase); | ||
447 | udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, | ||
448 | XUSB_DMA_BRR_CTRL | XUSB_DMA_READ_FROM_DPRAM | | ||
449 | (1 << ep->epnumber)); | ||
450 | ep->buffer0ready = 1; | ||
451 | ep->curbufnum = 1; | ||
452 | } else if (ep->curbufnum && !ep->buffer1ready) { | ||
453 | /* Get the Buffer address and copy the transmit data */ | ||
454 | eprambase = (u32 __force *)(udc->addr + | ||
455 | ep->rambase + ep->ep_usb.maxpacket); | ||
456 | src = virt_to_phys(eprambase); | ||
457 | udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, | ||
458 | XUSB_DMA_BRR_CTRL | XUSB_DMA_READ_FROM_DPRAM | | ||
459 | (1 << (ep->epnumber + | ||
460 | XUSB_STATUS_EP_BUFF2_SHIFT))); | ||
461 | ep->buffer1ready = 1; | ||
462 | ep->curbufnum = 0; | ||
463 | } else { | ||
464 | /* None of the ping-pong buffers are ready currently */ | ||
465 | return -EAGAIN; | ||
466 | } | ||
467 | |||
468 | return xudc_start_dma(ep, src, dst, length); | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * xudc_eptxrx - Transmits or receives data to or from an endpoint. | ||
473 | * @ep: pointer to the usb endpoint configuration structure. | ||
474 | * @req: pointer to the usb request structure. | ||
475 | * @bufferptr: pointer to buffer containing the data to be sent. | ||
476 | * @bufferlen: The number of data bytes to be sent. | ||
477 | * | ||
478 | * Return: 0 on success, -EAGAIN if no buffer is free. | ||
479 | * | ||
480 | * This function copies the transmit/receive data to/from the end point buffer | ||
481 | * and enables the buffer for transmission/reception. | ||
482 | */ | ||
483 | static int xudc_eptxrx(struct xusb_ep *ep, struct xusb_req *req, | ||
484 | u8 *bufferptr, u32 bufferlen) | ||
485 | { | ||
486 | u32 *eprambase; | ||
487 | u32 bytestosend; | ||
488 | int rc = 0; | ||
489 | struct xusb_udc *udc = ep->udc; | ||
490 | |||
491 | bytestosend = bufferlen; | ||
492 | if (udc->dma_enabled) { | ||
493 | if (ep->is_in) | ||
494 | rc = xudc_dma_send(ep, req, bufferptr, bufferlen); | ||
495 | else | ||
496 | rc = xudc_dma_receive(ep, req, bufferptr, bufferlen); | ||
497 | return rc; | ||
498 | } | ||
499 | /* Put the transmit buffer into the correct ping-pong buffer.*/ | ||
500 | if (!ep->curbufnum && !ep->buffer0ready) { | ||
501 | /* Get the Buffer address and copy the transmit data.*/ | ||
502 | eprambase = (u32 __force *)(udc->addr + ep->rambase); | ||
503 | if (ep->is_in) { | ||
504 | memcpy(eprambase, bufferptr, bytestosend); | ||
505 | udc->write_fn(udc->addr, ep->offset + | ||
506 | XUSB_EP_BUF0COUNT_OFFSET, bufferlen); | ||
507 | } else { | ||
508 | memcpy(bufferptr, eprambase, bytestosend); | ||
509 | } | ||
510 | /* | ||
511 | * Enable the buffer for transmission. | ||
512 | */ | ||
513 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
514 | 1 << ep->epnumber); | ||
515 | ep->buffer0ready = 1; | ||
516 | ep->curbufnum = 1; | ||
517 | } else if (ep->curbufnum && !ep->buffer1ready) { | ||
518 | /* Get the Buffer address and copy the transmit data.*/ | ||
519 | eprambase = (u32 __force *)(udc->addr + ep->rambase + | ||
520 | ep->ep_usb.maxpacket); | ||
521 | if (ep->is_in) { | ||
522 | memcpy(eprambase, bufferptr, bytestosend); | ||
523 | udc->write_fn(udc->addr, ep->offset + | ||
524 | XUSB_EP_BUF1COUNT_OFFSET, bufferlen); | ||
525 | } else { | ||
526 | memcpy(bufferptr, eprambase, bytestosend); | ||
527 | } | ||
528 | /* | ||
529 | * Enable the buffer for transmission. | ||
530 | */ | ||
531 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
532 | 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); | ||
533 | ep->buffer1ready = 1; | ||
534 | ep->curbufnum = 0; | ||
535 | } else { | ||
536 | /* None of the ping-pong buffers are ready currently */ | ||
537 | return -EAGAIN; | ||
538 | } | ||
539 | return rc; | ||
540 | } | ||
541 | |||
542 | /** | ||
543 | * xudc_done - Exeutes the endpoint data transfer completion tasks. | ||
544 | * @ep: pointer to the usb device endpoint structure. | ||
545 | * @req: pointer to the usb request structure. | ||
546 | * @status: Status of the data transfer. | ||
547 | * | ||
548 | * Deletes the message from the queue and updates data transfer completion | ||
549 | * status. | ||
550 | */ | ||
551 | static void xudc_done(struct xusb_ep *ep, struct xusb_req *req, int status) | ||
552 | { | ||
553 | struct xusb_udc *udc = ep->udc; | ||
554 | |||
555 | list_del_init(&req->queue); | ||
556 | |||
557 | if (req->usb_req.status == -EINPROGRESS) | ||
558 | req->usb_req.status = status; | ||
559 | else | ||
560 | status = req->usb_req.status; | ||
561 | |||
562 | if (status && status != -ESHUTDOWN) | ||
563 | dev_dbg(udc->dev, "%s done %p, status %d\n", | ||
564 | ep->ep_usb.name, req, status); | ||
565 | /* unmap request if DMA is present*/ | ||
566 | if (udc->dma_enabled && ep->epnumber && req->usb_req.length) | ||
567 | usb_gadget_unmap_request(&udc->gadget, &req->usb_req, | ||
568 | ep->is_in); | ||
569 | |||
570 | if (req->usb_req.complete) { | ||
571 | spin_unlock(&udc->lock); | ||
572 | req->usb_req.complete(&ep->ep_usb, &req->usb_req); | ||
573 | spin_lock(&udc->lock); | ||
574 | } | ||
575 | } | ||
576 | |||
577 | /** | ||
578 | * xudc_read_fifo - Reads the data from the given endpoint buffer. | ||
579 | * @ep: pointer to the usb device endpoint structure. | ||
580 | * @req: pointer to the usb request structure. | ||
581 | * | ||
582 | * Return: 0 if request is completed and -EAGAIN if not completed. | ||
583 | * | ||
584 | * Pulls OUT packet data from the endpoint buffer. | ||
585 | */ | ||
586 | static int xudc_read_fifo(struct xusb_ep *ep, struct xusb_req *req) | ||
587 | { | ||
588 | u8 *buf; | ||
589 | u32 is_short, count, bufferspace; | ||
590 | u8 bufoffset; | ||
591 | u8 two_pkts = 0; | ||
592 | int ret; | ||
593 | int retval = -EAGAIN; | ||
594 | struct xusb_udc *udc = ep->udc; | ||
595 | |||
596 | if (ep->buffer0ready && ep->buffer1ready) { | ||
597 | dev_dbg(udc->dev, "Packet NOT ready!\n"); | ||
598 | return retval; | ||
599 | } | ||
600 | top: | ||
601 | if (ep->curbufnum) | ||
602 | bufoffset = XUSB_EP_BUF1COUNT_OFFSET; | ||
603 | else | ||
604 | bufoffset = XUSB_EP_BUF0COUNT_OFFSET; | ||
605 | |||
606 | count = udc->read_fn(udc->addr + ep->offset + bufoffset); | ||
607 | |||
608 | if (!ep->buffer0ready && !ep->buffer1ready) | ||
609 | two_pkts = 1; | ||
610 | |||
611 | buf = req->usb_req.buf + req->usb_req.actual; | ||
612 | prefetchw(buf); | ||
613 | bufferspace = req->usb_req.length - req->usb_req.actual; | ||
614 | is_short = count < ep->ep_usb.maxpacket; | ||
615 | |||
616 | if (unlikely(!bufferspace)) { | ||
617 | /* | ||
618 | * This happens when the driver's buffer | ||
619 | * is smaller than what the host sent. | ||
620 | * discard the extra data. | ||
621 | */ | ||
622 | if (req->usb_req.status != -EOVERFLOW) | ||
623 | dev_dbg(udc->dev, "%s overflow %d\n", | ||
624 | ep->ep_usb.name, count); | ||
625 | req->usb_req.status = -EOVERFLOW; | ||
626 | xudc_done(ep, req, -EOVERFLOW); | ||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | ret = xudc_eptxrx(ep, req, buf, count); | ||
631 | switch (ret) { | ||
632 | case 0: | ||
633 | req->usb_req.actual += min(count, bufferspace); | ||
634 | dev_dbg(udc->dev, "read %s, %d bytes%s req %p %d/%d\n", | ||
635 | ep->ep_usb.name, count, is_short ? "/S" : "", req, | ||
636 | req->usb_req.actual, req->usb_req.length); | ||
637 | bufferspace -= count; | ||
638 | /* Completion */ | ||
639 | if ((req->usb_req.actual == req->usb_req.length) || is_short) { | ||
640 | if (udc->dma_enabled && req->usb_req.length) | ||
641 | dma_sync_single_for_cpu(udc->dev, | ||
642 | req->usb_req.dma, | ||
643 | req->usb_req.actual, | ||
644 | DMA_FROM_DEVICE); | ||
645 | xudc_done(ep, req, 0); | ||
646 | return 0; | ||
647 | } | ||
648 | if (two_pkts) { | ||
649 | two_pkts = 0; | ||
650 | goto top; | ||
651 | } | ||
652 | break; | ||
653 | case -EAGAIN: | ||
654 | dev_dbg(udc->dev, "receive busy\n"); | ||
655 | break; | ||
656 | case -EINVAL: | ||
657 | case -ETIMEDOUT: | ||
658 | /* DMA error, dequeue the request */ | ||
659 | xudc_done(ep, req, -ECONNRESET); | ||
660 | retval = 0; | ||
661 | break; | ||
662 | } | ||
663 | |||
664 | return retval; | ||
665 | } | ||
666 | |||
667 | /** | ||
668 | * xudc_write_fifo - Writes data into the given endpoint buffer. | ||
669 | * @ep: pointer to the usb device endpoint structure. | ||
670 | * @req: pointer to the usb request structure. | ||
671 | * | ||
672 | * Return: 0 if request is completed and -EAGAIN if not completed. | ||
673 | * | ||
674 | * Loads endpoint buffer for an IN packet. | ||
675 | */ | ||
676 | static int xudc_write_fifo(struct xusb_ep *ep, struct xusb_req *req) | ||
677 | { | ||
678 | u32 max; | ||
679 | u32 length; | ||
680 | int ret; | ||
681 | int retval = -EAGAIN; | ||
682 | struct xusb_udc *udc = ep->udc; | ||
683 | int is_last, is_short = 0; | ||
684 | u8 *buf; | ||
685 | |||
686 | max = le16_to_cpu(ep->desc->wMaxPacketSize); | ||
687 | buf = req->usb_req.buf + req->usb_req.actual; | ||
688 | prefetch(buf); | ||
689 | length = req->usb_req.length - req->usb_req.actual; | ||
690 | length = min(length, max); | ||
691 | |||
692 | ret = xudc_eptxrx(ep, req, buf, length); | ||
693 | switch (ret) { | ||
694 | case 0: | ||
695 | req->usb_req.actual += length; | ||
696 | if (unlikely(length != max)) { | ||
697 | is_last = is_short = 1; | ||
698 | } else { | ||
699 | if (likely(req->usb_req.length != | ||
700 | req->usb_req.actual) || req->usb_req.zero) | ||
701 | is_last = 0; | ||
702 | else | ||
703 | is_last = 1; | ||
704 | } | ||
705 | dev_dbg(udc->dev, "%s: wrote %s %d bytes%s%s %d left %p\n", | ||
706 | __func__, ep->ep_usb.name, length, is_last ? "/L" : "", | ||
707 | is_short ? "/S" : "", | ||
708 | req->usb_req.length - req->usb_req.actual, req); | ||
709 | /* completion */ | ||
710 | if (is_last) { | ||
711 | xudc_done(ep, req, 0); | ||
712 | retval = 0; | ||
713 | } | ||
714 | break; | ||
715 | case -EAGAIN: | ||
716 | dev_dbg(udc->dev, "Send busy\n"); | ||
717 | break; | ||
718 | case -EINVAL: | ||
719 | case -ETIMEDOUT: | ||
720 | /* DMA error, dequeue the request */ | ||
721 | xudc_done(ep, req, -ECONNRESET); | ||
722 | retval = 0; | ||
723 | break; | ||
724 | } | ||
725 | |||
726 | return retval; | ||
727 | } | ||
728 | |||
729 | /** | ||
730 | * xudc_nuke - Cleans up the data transfer message list. | ||
731 | * @ep: pointer to the usb device endpoint structure. | ||
732 | * @status: Status of the data transfer. | ||
733 | */ | ||
734 | static void xudc_nuke(struct xusb_ep *ep, int status) | ||
735 | { | ||
736 | struct xusb_req *req; | ||
737 | |||
738 | while (!list_empty(&ep->queue)) { | ||
739 | req = list_first_entry(&ep->queue, struct xusb_req, queue); | ||
740 | xudc_done(ep, req, status); | ||
741 | } | ||
742 | } | ||
743 | |||
744 | /** | ||
745 | * xudc_ep_set_halt - Stalls/unstalls the given endpoint. | ||
746 | * @_ep: pointer to the usb device endpoint structure. | ||
747 | * @value: value to indicate stall/unstall. | ||
748 | * | ||
749 | * Return: 0 for success and error value on failure | ||
750 | */ | ||
751 | static int xudc_ep_set_halt(struct usb_ep *_ep, int value) | ||
752 | { | ||
753 | struct xusb_ep *ep = to_xusb_ep(_ep); | ||
754 | struct xusb_udc *udc; | ||
755 | unsigned long flags; | ||
756 | u32 epcfgreg; | ||
757 | |||
758 | if (!_ep || (!ep->desc && ep->epnumber)) { | ||
759 | pr_debug("%s: bad ep or descriptor\n", __func__); | ||
760 | return -EINVAL; | ||
761 | } | ||
762 | udc = ep->udc; | ||
763 | |||
764 | if (ep->is_in && (!list_empty(&ep->queue)) && value) { | ||
765 | dev_dbg(udc->dev, "requests pending can't halt\n"); | ||
766 | return -EAGAIN; | ||
767 | } | ||
768 | |||
769 | if (ep->buffer0ready || ep->buffer1ready) { | ||
770 | dev_dbg(udc->dev, "HW buffers busy can't halt\n"); | ||
771 | return -EAGAIN; | ||
772 | } | ||
773 | |||
774 | spin_lock_irqsave(&udc->lock, flags); | ||
775 | |||
776 | if (value) { | ||
777 | /* Stall the device.*/ | ||
778 | epcfgreg = udc->read_fn(udc->addr + ep->offset); | ||
779 | epcfgreg |= XUSB_EP_CFG_STALL_MASK; | ||
780 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
781 | } else { | ||
782 | /* Unstall the device.*/ | ||
783 | epcfgreg = udc->read_fn(udc->addr + ep->offset); | ||
784 | epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; | ||
785 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
786 | if (ep->epnumber) { | ||
787 | /* Reset the toggle bit.*/ | ||
788 | epcfgreg = udc->read_fn(ep->udc->addr + ep->offset); | ||
789 | epcfgreg &= ~XUSB_EP_CFG_DATA_TOGGLE_MASK; | ||
790 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
791 | } | ||
792 | } | ||
793 | |||
794 | spin_unlock_irqrestore(&udc->lock, flags); | ||
795 | return 0; | ||
796 | } | ||
797 | |||
798 | /** | ||
799 | * xudc_ep_enable - Enables the given endpoint. | ||
800 | * @ep: pointer to the xusb endpoint structure. | ||
801 | * @desc: pointer to usb endpoint descriptor. | ||
802 | * | ||
803 | * Return: 0 for success and error value on failure | ||
804 | */ | ||
805 | static int __xudc_ep_enable(struct xusb_ep *ep, | ||
806 | const struct usb_endpoint_descriptor *desc) | ||
807 | { | ||
808 | struct xusb_udc *udc = ep->udc; | ||
809 | u32 tmp; | ||
810 | u32 epcfg; | ||
811 | u32 ier; | ||
812 | u16 maxpacket; | ||
813 | |||
814 | ep->is_in = ((desc->bEndpointAddress & USB_DIR_IN) != 0); | ||
815 | /* Bit 3...0:endpoint number */ | ||
816 | ep->epnumber = (desc->bEndpointAddress & 0x0f); | ||
817 | ep->desc = desc; | ||
818 | ep->ep_usb.desc = desc; | ||
819 | tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
820 | ep->ep_usb.maxpacket = maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
821 | |||
822 | switch (tmp) { | ||
823 | case USB_ENDPOINT_XFER_CONTROL: | ||
824 | dev_dbg(udc->dev, "only one control endpoint\n"); | ||
825 | /* NON- ISO */ | ||
826 | ep->is_iso = 0; | ||
827 | return -EINVAL; | ||
828 | case USB_ENDPOINT_XFER_INT: | ||
829 | /* NON- ISO */ | ||
830 | ep->is_iso = 0; | ||
831 | if (maxpacket > 64) { | ||
832 | dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); | ||
833 | return -EINVAL; | ||
834 | } | ||
835 | break; | ||
836 | case USB_ENDPOINT_XFER_BULK: | ||
837 | /* NON- ISO */ | ||
838 | ep->is_iso = 0; | ||
839 | if (!(is_power_of_2(maxpacket) && maxpacket >= 8 && | ||
840 | maxpacket <= 512)) { | ||
841 | dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); | ||
842 | return -EINVAL; | ||
843 | } | ||
844 | break; | ||
845 | case USB_ENDPOINT_XFER_ISOC: | ||
846 | /* ISO */ | ||
847 | ep->is_iso = 1; | ||
848 | break; | ||
849 | } | ||
850 | |||
851 | ep->buffer0ready = 0; | ||
852 | ep->buffer1ready = 0; | ||
853 | ep->curbufnum = 0; | ||
854 | ep->rambase = rambase[ep->epnumber]; | ||
855 | xudc_epconfig(ep, udc); | ||
856 | |||
857 | dev_dbg(udc->dev, "Enable Endpoint %d max pkt is %d\n", | ||
858 | ep->epnumber, maxpacket); | ||
859 | |||
860 | /* Enable the End point.*/ | ||
861 | epcfg = udc->read_fn(udc->addr + ep->offset); | ||
862 | epcfg |= XUSB_EP_CFG_VALID_MASK; | ||
863 | udc->write_fn(udc->addr, ep->offset, epcfg); | ||
864 | if (ep->epnumber) | ||
865 | ep->rambase <<= 2; | ||
866 | |||
867 | /* Enable buffer completion interrupts for endpoint */ | ||
868 | ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
869 | ier |= (XUSB_STATUS_INTR_BUFF_COMP_SHIFT_MASK << ep->epnumber); | ||
870 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); | ||
871 | |||
872 | /* for OUT endpoint set buffers ready to receive */ | ||
873 | if (ep->epnumber && !ep->is_in) { | ||
874 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
875 | 1 << ep->epnumber); | ||
876 | ep->buffer0ready = 1; | ||
877 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, | ||
878 | (1 << (ep->epnumber + | ||
879 | XUSB_STATUS_EP_BUFF2_SHIFT))); | ||
880 | ep->buffer1ready = 1; | ||
881 | } | ||
882 | |||
883 | return 0; | ||
884 | } | ||
885 | |||
886 | /** | ||
887 | * xudc_ep_enable - Enables the given endpoint. | ||
888 | * @_ep: pointer to the usb endpoint structure. | ||
889 | * @desc: pointer to usb endpoint descriptor. | ||
890 | * | ||
891 | * Return: 0 for success and error value on failure | ||
892 | */ | ||
893 | static int xudc_ep_enable(struct usb_ep *_ep, | ||
894 | const struct usb_endpoint_descriptor *desc) | ||
895 | { | ||
896 | struct xusb_ep *ep; | ||
897 | struct xusb_udc *udc; | ||
898 | unsigned long flags; | ||
899 | int ret; | ||
900 | |||
901 | if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { | ||
902 | pr_debug("%s: bad ep or descriptor\n", __func__); | ||
903 | return -EINVAL; | ||
904 | } | ||
905 | |||
906 | ep = to_xusb_ep(_ep); | ||
907 | udc = ep->udc; | ||
908 | |||
909 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { | ||
910 | dev_dbg(udc->dev, "bogus device state\n"); | ||
911 | return -ESHUTDOWN; | ||
912 | } | ||
913 | |||
914 | spin_lock_irqsave(&udc->lock, flags); | ||
915 | ret = __xudc_ep_enable(ep, desc); | ||
916 | spin_unlock_irqrestore(&udc->lock, flags); | ||
917 | |||
918 | return ret; | ||
919 | } | ||
920 | |||
921 | /** | ||
922 | * xudc_ep_disable - Disables the given endpoint. | ||
923 | * @_ep: pointer to the usb endpoint structure. | ||
924 | * | ||
925 | * Return: 0 for success and error value on failure | ||
926 | */ | ||
927 | static int xudc_ep_disable(struct usb_ep *_ep) | ||
928 | { | ||
929 | struct xusb_ep *ep; | ||
930 | unsigned long flags; | ||
931 | u32 epcfg; | ||
932 | struct xusb_udc *udc; | ||
933 | |||
934 | if (!_ep) { | ||
935 | pr_debug("%s: invalid ep\n", __func__); | ||
936 | return -EINVAL; | ||
937 | } | ||
938 | |||
939 | ep = to_xusb_ep(_ep); | ||
940 | udc = ep->udc; | ||
941 | |||
942 | spin_lock_irqsave(&udc->lock, flags); | ||
943 | |||
944 | xudc_nuke(ep, -ESHUTDOWN); | ||
945 | |||
946 | /* Restore the endpoint's pristine config */ | ||
947 | ep->desc = NULL; | ||
948 | ep->ep_usb.desc = NULL; | ||
949 | |||
950 | dev_dbg(udc->dev, "USB Ep %d disable\n ", ep->epnumber); | ||
951 | /* Disable the endpoint.*/ | ||
952 | epcfg = udc->read_fn(udc->addr + ep->offset); | ||
953 | epcfg &= ~XUSB_EP_CFG_VALID_MASK; | ||
954 | udc->write_fn(udc->addr, ep->offset, epcfg); | ||
955 | |||
956 | spin_unlock_irqrestore(&udc->lock, flags); | ||
957 | return 0; | ||
958 | } | ||
959 | |||
960 | /** | ||
961 | * xudc_ep_alloc_request - Initializes the request queue. | ||
962 | * @_ep: pointer to the usb endpoint structure. | ||
963 | * @gfp_flags: Flags related to the request call. | ||
964 | * | ||
965 | * Return: pointer to request structure on success and a NULL on failure. | ||
966 | */ | ||
967 | static struct usb_request *xudc_ep_alloc_request(struct usb_ep *_ep, | ||
968 | gfp_t gfp_flags) | ||
969 | { | ||
970 | struct xusb_ep *ep = to_xusb_ep(_ep); | ||
971 | struct xusb_udc *udc; | ||
972 | struct xusb_req *req; | ||
973 | |||
974 | udc = ep->udc; | ||
975 | req = kzalloc(sizeof(*req), gfp_flags); | ||
976 | if (!req) { | ||
977 | dev_err(udc->dev, "%s:not enough memory", __func__); | ||
978 | return NULL; | ||
979 | } | ||
980 | |||
981 | req->ep = ep; | ||
982 | INIT_LIST_HEAD(&req->queue); | ||
983 | return &req->usb_req; | ||
984 | } | ||
985 | |||
986 | /** | ||
987 | * xudc_free_request - Releases the request from queue. | ||
988 | * @_ep: pointer to the usb device endpoint structure. | ||
989 | * @_req: pointer to the usb request structure. | ||
990 | */ | ||
991 | static void xudc_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
992 | { | ||
993 | struct xusb_req *req = to_xusb_req(_req); | ||
994 | |||
995 | kfree(req); | ||
996 | } | ||
997 | |||
998 | /** | ||
999 | * xudc_ep0_queue - Adds the request to endpoint 0 queue. | ||
1000 | * @ep0: pointer to the xusb endpoint 0 structure. | ||
1001 | * @req: pointer to the xusb request structure. | ||
1002 | * | ||
1003 | * Return: 0 for success and error value on failure | ||
1004 | */ | ||
1005 | static int __xudc_ep0_queue(struct xusb_ep *ep0, struct xusb_req *req) | ||
1006 | { | ||
1007 | struct xusb_udc *udc = ep0->udc; | ||
1008 | u32 length; | ||
1009 | u8 *corebuf; | ||
1010 | |||
1011 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1012 | dev_dbg(udc->dev, "%s, bogus device state\n", __func__); | ||
1013 | return -EINVAL; | ||
1014 | } | ||
1015 | if (!list_empty(&ep0->queue)) { | ||
1016 | dev_dbg(udc->dev, "%s:ep0 busy\n", __func__); | ||
1017 | return -EBUSY; | ||
1018 | } | ||
1019 | |||
1020 | req->usb_req.status = -EINPROGRESS; | ||
1021 | req->usb_req.actual = 0; | ||
1022 | |||
1023 | list_add_tail(&req->queue, &ep0->queue); | ||
1024 | |||
1025 | if (udc->setup.bRequestType & USB_DIR_IN) { | ||
1026 | prefetch(req->usb_req.buf); | ||
1027 | length = req->usb_req.length; | ||
1028 | corebuf = (void __force *) ((ep0->rambase << 2) + | ||
1029 | udc->addr); | ||
1030 | length = req->usb_req.actual = min_t(u32, length, | ||
1031 | EP0_MAX_PACKET); | ||
1032 | memcpy(corebuf, req->usb_req.buf, length); | ||
1033 | udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, length); | ||
1034 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); | ||
1035 | } else { | ||
1036 | if (udc->setup.wLength) { | ||
1037 | /* Enable EP0 buffer to receive data */ | ||
1038 | udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); | ||
1039 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); | ||
1040 | } else { | ||
1041 | xudc_wrstatus(udc); | ||
1042 | } | ||
1043 | } | ||
1044 | |||
1045 | return 0; | ||
1046 | } | ||
1047 | |||
1048 | /** | ||
1049 | * xudc_ep0_queue - Adds the request to endpoint 0 queue. | ||
1050 | * @_ep: pointer to the usb endpoint 0 structure. | ||
1051 | * @_req: pointer to the usb request structure. | ||
1052 | * @gfp_flags: Flags related to the request call. | ||
1053 | * | ||
1054 | * Return: 0 for success and error value on failure | ||
1055 | */ | ||
1056 | static int xudc_ep0_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
1057 | gfp_t gfp_flags) | ||
1058 | { | ||
1059 | struct xusb_req *req = to_xusb_req(_req); | ||
1060 | struct xusb_ep *ep0 = to_xusb_ep(_ep); | ||
1061 | struct xusb_udc *udc = ep0->udc; | ||
1062 | unsigned long flags; | ||
1063 | int ret; | ||
1064 | |||
1065 | spin_lock_irqsave(&udc->lock, flags); | ||
1066 | ret = __xudc_ep0_queue(ep0, req); | ||
1067 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1068 | |||
1069 | return ret; | ||
1070 | } | ||
1071 | |||
1072 | /** | ||
1073 | * xudc_ep_queue - Adds the request to endpoint queue. | ||
1074 | * @_ep: pointer to the usb endpoint structure. | ||
1075 | * @_req: pointer to the usb request structure. | ||
1076 | * @gfp_flags: Flags related to the request call. | ||
1077 | * | ||
1078 | * Return: 0 for success and error value on failure | ||
1079 | */ | ||
1080 | static int xudc_ep_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
1081 | gfp_t gfp_flags) | ||
1082 | { | ||
1083 | struct xusb_req *req = to_xusb_req(_req); | ||
1084 | struct xusb_ep *ep = to_xusb_ep(_ep); | ||
1085 | struct xusb_udc *udc = ep->udc; | ||
1086 | int ret; | ||
1087 | unsigned long flags; | ||
1088 | |||
1089 | if (!ep->desc) { | ||
1090 | dev_dbg(udc->dev, "%s:queing request to disabled %s\n", | ||
1091 | __func__, ep->name); | ||
1092 | return -ESHUTDOWN; | ||
1093 | } | ||
1094 | |||
1095 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { | ||
1096 | dev_dbg(udc->dev, "%s, bogus device state\n", __func__); | ||
1097 | return -EINVAL; | ||
1098 | } | ||
1099 | |||
1100 | spin_lock_irqsave(&udc->lock, flags); | ||
1101 | |||
1102 | _req->status = -EINPROGRESS; | ||
1103 | _req->actual = 0; | ||
1104 | |||
1105 | if (udc->dma_enabled) { | ||
1106 | ret = usb_gadget_map_request(&udc->gadget, &req->usb_req, | ||
1107 | ep->is_in); | ||
1108 | if (ret) { | ||
1109 | dev_dbg(udc->dev, "gadget_map failed ep%d\n", | ||
1110 | ep->epnumber); | ||
1111 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1112 | return -EAGAIN; | ||
1113 | } | ||
1114 | } | ||
1115 | |||
1116 | if (list_empty(&ep->queue)) { | ||
1117 | if (ep->is_in) { | ||
1118 | dev_dbg(udc->dev, "xudc_write_fifo from ep_queue\n"); | ||
1119 | if (!xudc_write_fifo(ep, req)) | ||
1120 | req = NULL; | ||
1121 | } else { | ||
1122 | dev_dbg(udc->dev, "xudc_read_fifo from ep_queue\n"); | ||
1123 | if (!xudc_read_fifo(ep, req)) | ||
1124 | req = NULL; | ||
1125 | } | ||
1126 | } | ||
1127 | |||
1128 | if (req != NULL) | ||
1129 | list_add_tail(&req->queue, &ep->queue); | ||
1130 | |||
1131 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1132 | return 0; | ||
1133 | } | ||
1134 | |||
1135 | /** | ||
1136 | * xudc_ep_dequeue - Removes the request from the queue. | ||
1137 | * @_ep: pointer to the usb device endpoint structure. | ||
1138 | * @_req: pointer to the usb request structure. | ||
1139 | * | ||
1140 | * Return: 0 for success and error value on failure | ||
1141 | */ | ||
1142 | static int xudc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
1143 | { | ||
1144 | struct xusb_ep *ep = to_xusb_ep(_ep); | ||
1145 | struct xusb_req *req = to_xusb_req(_req); | ||
1146 | struct xusb_udc *udc = ep->udc; | ||
1147 | unsigned long flags; | ||
1148 | |||
1149 | spin_lock_irqsave(&udc->lock, flags); | ||
1150 | /* Make sure it's actually queued on this endpoint */ | ||
1151 | list_for_each_entry(req, &ep->queue, queue) { | ||
1152 | if (&req->usb_req == _req) | ||
1153 | break; | ||
1154 | } | ||
1155 | if (&req->usb_req != _req) { | ||
1156 | spin_unlock_irqrestore(&ep->udc->lock, flags); | ||
1157 | return -EINVAL; | ||
1158 | } | ||
1159 | xudc_done(ep, req, -ECONNRESET); | ||
1160 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1161 | |||
1162 | return 0; | ||
1163 | } | ||
1164 | |||
1165 | /** | ||
1166 | * xudc_ep0_enable - Enables the given endpoint. | ||
1167 | * @ep: pointer to the usb endpoint structure. | ||
1168 | * @desc: pointer to usb endpoint descriptor. | ||
1169 | * | ||
1170 | * Return: error always. | ||
1171 | * | ||
1172 | * endpoint 0 enable should not be called by gadget layer. | ||
1173 | */ | ||
1174 | static int xudc_ep0_enable(struct usb_ep *ep, | ||
1175 | const struct usb_endpoint_descriptor *desc) | ||
1176 | { | ||
1177 | return -EINVAL; | ||
1178 | } | ||
1179 | |||
1180 | /** | ||
1181 | * xudc_ep0_disable - Disables the given endpoint. | ||
1182 | * @ep: pointer to the usb endpoint structure. | ||
1183 | * | ||
1184 | * Return: error always. | ||
1185 | * | ||
1186 | * endpoint 0 disable should not be called by gadget layer. | ||
1187 | */ | ||
1188 | static int xudc_ep0_disable(struct usb_ep *ep) | ||
1189 | { | ||
1190 | return -EINVAL; | ||
1191 | } | ||
1192 | |||
1193 | static const struct usb_ep_ops xusb_ep0_ops = { | ||
1194 | .enable = xudc_ep0_enable, | ||
1195 | .disable = xudc_ep0_disable, | ||
1196 | .alloc_request = xudc_ep_alloc_request, | ||
1197 | .free_request = xudc_free_request, | ||
1198 | .queue = xudc_ep0_queue, | ||
1199 | .dequeue = xudc_ep_dequeue, | ||
1200 | .set_halt = xudc_ep_set_halt, | ||
1201 | }; | ||
1202 | |||
1203 | static const struct usb_ep_ops xusb_ep_ops = { | ||
1204 | .enable = xudc_ep_enable, | ||
1205 | .disable = xudc_ep_disable, | ||
1206 | .alloc_request = xudc_ep_alloc_request, | ||
1207 | .free_request = xudc_free_request, | ||
1208 | .queue = xudc_ep_queue, | ||
1209 | .dequeue = xudc_ep_dequeue, | ||
1210 | .set_halt = xudc_ep_set_halt, | ||
1211 | }; | ||
1212 | |||
1213 | /** | ||
1214 | * xudc_get_frame - Reads the current usb frame number. | ||
1215 | * @gadget: pointer to the usb gadget structure. | ||
1216 | * | ||
1217 | * Return: current frame number for success and error value on failure. | ||
1218 | */ | ||
1219 | static int xudc_get_frame(struct usb_gadget *gadget) | ||
1220 | { | ||
1221 | struct xusb_udc *udc; | ||
1222 | int frame; | ||
1223 | |||
1224 | if (!gadget) | ||
1225 | return -ENODEV; | ||
1226 | |||
1227 | udc = to_udc(gadget); | ||
1228 | frame = udc->read_fn(udc->addr + XUSB_FRAMENUM_OFFSET); | ||
1229 | return frame; | ||
1230 | } | ||
1231 | |||
1232 | /** | ||
1233 | * xudc_wakeup - Send remote wakeup signal to host | ||
1234 | * @gadget: pointer to the usb gadget structure. | ||
1235 | * | ||
1236 | * Return: 0 on success and error on failure | ||
1237 | */ | ||
1238 | static int xudc_wakeup(struct usb_gadget *gadget) | ||
1239 | { | ||
1240 | struct xusb_udc *udc = to_udc(gadget); | ||
1241 | u32 crtlreg; | ||
1242 | int status = -EINVAL; | ||
1243 | unsigned long flags; | ||
1244 | |||
1245 | spin_lock_irqsave(&udc->lock, flags); | ||
1246 | |||
1247 | /* Remote wake up not enabled by host */ | ||
1248 | if (!udc->remote_wkp) | ||
1249 | goto done; | ||
1250 | |||
1251 | crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); | ||
1252 | crtlreg |= XUSB_CONTROL_USB_RMTWAKE_MASK; | ||
1253 | /* set remote wake up bit */ | ||
1254 | udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); | ||
1255 | /* | ||
1256 | * wait for a while and reset remote wake up bit since this bit | ||
1257 | * is not cleared by HW after sending remote wakeup to host. | ||
1258 | */ | ||
1259 | mdelay(2); | ||
1260 | |||
1261 | crtlreg &= ~XUSB_CONTROL_USB_RMTWAKE_MASK; | ||
1262 | udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); | ||
1263 | status = 0; | ||
1264 | done: | ||
1265 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1266 | return status; | ||
1267 | } | ||
1268 | |||
1269 | /** | ||
1270 | * xudc_pullup - start/stop USB traffic | ||
1271 | * @gadget: pointer to the usb gadget structure. | ||
1272 | * @is_on: flag to start or stop | ||
1273 | * | ||
1274 | * Return: 0 always | ||
1275 | * | ||
1276 | * This function starts/stops SIE engine of IP based on is_on. | ||
1277 | */ | ||
1278 | static int xudc_pullup(struct usb_gadget *gadget, int is_on) | ||
1279 | { | ||
1280 | struct xusb_udc *udc = to_udc(gadget); | ||
1281 | unsigned long flags; | ||
1282 | u32 crtlreg; | ||
1283 | |||
1284 | spin_lock_irqsave(&udc->lock, flags); | ||
1285 | |||
1286 | crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); | ||
1287 | if (is_on) | ||
1288 | crtlreg |= XUSB_CONTROL_USB_READY_MASK; | ||
1289 | else | ||
1290 | crtlreg &= ~XUSB_CONTROL_USB_READY_MASK; | ||
1291 | |||
1292 | udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); | ||
1293 | |||
1294 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1295 | |||
1296 | return 0; | ||
1297 | } | ||
1298 | |||
1299 | /** | ||
1300 | * xudc_eps_init - initialize endpoints. | ||
1301 | * @udc: pointer to the usb device controller structure. | ||
1302 | */ | ||
1303 | static void xudc_eps_init(struct xusb_udc *udc) | ||
1304 | { | ||
1305 | u32 ep_number; | ||
1306 | |||
1307 | INIT_LIST_HEAD(&udc->gadget.ep_list); | ||
1308 | |||
1309 | for (ep_number = 0; ep_number < XUSB_MAX_ENDPOINTS; ep_number++) { | ||
1310 | struct xusb_ep *ep = &udc->ep[ep_number]; | ||
1311 | |||
1312 | if (ep_number) { | ||
1313 | list_add_tail(&ep->ep_usb.ep_list, | ||
1314 | &udc->gadget.ep_list); | ||
1315 | usb_ep_set_maxpacket_limit(&ep->ep_usb, | ||
1316 | (unsigned short) ~0); | ||
1317 | snprintf(ep->name, EPNAME_SIZE, "ep%d", ep_number); | ||
1318 | ep->ep_usb.name = ep->name; | ||
1319 | ep->ep_usb.ops = &xusb_ep_ops; | ||
1320 | } else { | ||
1321 | ep->ep_usb.name = ep0name; | ||
1322 | usb_ep_set_maxpacket_limit(&ep->ep_usb, EP0_MAX_PACKET); | ||
1323 | ep->ep_usb.ops = &xusb_ep0_ops; | ||
1324 | } | ||
1325 | |||
1326 | ep->udc = udc; | ||
1327 | ep->epnumber = ep_number; | ||
1328 | ep->desc = NULL; | ||
1329 | /* | ||
1330 | * The configuration register address offset between | ||
1331 | * each endpoint is 0x10. | ||
1332 | */ | ||
1333 | ep->offset = XUSB_EP0_CONFIG_OFFSET + (ep_number * 0x10); | ||
1334 | ep->is_in = 0; | ||
1335 | ep->is_iso = 0; | ||
1336 | ep->maxpacket = 0; | ||
1337 | xudc_epconfig(ep, udc); | ||
1338 | |||
1339 | /* Initialize one queue per endpoint */ | ||
1340 | INIT_LIST_HEAD(&ep->queue); | ||
1341 | } | ||
1342 | } | ||
1343 | |||
1344 | /** | ||
1345 | * xudc_stop_activity - Stops any further activity on the device. | ||
1346 | * @udc: pointer to the usb device controller structure. | ||
1347 | */ | ||
1348 | static void xudc_stop_activity(struct xusb_udc *udc) | ||
1349 | { | ||
1350 | int i; | ||
1351 | struct xusb_ep *ep; | ||
1352 | |||
1353 | for (i = 0; i < XUSB_MAX_ENDPOINTS; i++) { | ||
1354 | ep = &udc->ep[i]; | ||
1355 | xudc_nuke(ep, -ESHUTDOWN); | ||
1356 | } | ||
1357 | } | ||
1358 | |||
1359 | /** | ||
1360 | * xudc_start - Starts the device. | ||
1361 | * @gadget: pointer to the usb gadget structure | ||
1362 | * @driver: pointer to gadget driver structure | ||
1363 | * | ||
1364 | * Return: zero on success and error on failure | ||
1365 | */ | ||
1366 | static int xudc_start(struct usb_gadget *gadget, | ||
1367 | struct usb_gadget_driver *driver) | ||
1368 | { | ||
1369 | struct xusb_udc *udc = to_udc(gadget); | ||
1370 | struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; | ||
1371 | const struct usb_endpoint_descriptor *desc = &config_bulk_out_desc; | ||
1372 | unsigned long flags; | ||
1373 | int ret = 0; | ||
1374 | |||
1375 | spin_lock_irqsave(&udc->lock, flags); | ||
1376 | |||
1377 | if (udc->driver) { | ||
1378 | dev_err(udc->dev, "%s is already bound to %s\n", | ||
1379 | udc->gadget.name, udc->driver->driver.name); | ||
1380 | ret = -EBUSY; | ||
1381 | goto err; | ||
1382 | } | ||
1383 | |||
1384 | /* hook up the driver */ | ||
1385 | udc->driver = driver; | ||
1386 | udc->gadget.speed = driver->max_speed; | ||
1387 | |||
1388 | /* Enable the control endpoint. */ | ||
1389 | ret = __xudc_ep_enable(ep0, desc); | ||
1390 | |||
1391 | /* Set device address and remote wakeup to 0 */ | ||
1392 | udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); | ||
1393 | udc->remote_wkp = 0; | ||
1394 | err: | ||
1395 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1396 | return ret; | ||
1397 | } | ||
1398 | |||
1399 | /** | ||
1400 | * xudc_stop - stops the device. | ||
1401 | * @gadget: pointer to the usb gadget structure | ||
1402 | * @driver: pointer to usb gadget driver structure | ||
1403 | * | ||
1404 | * Return: zero always | ||
1405 | */ | ||
1406 | static int xudc_stop(struct usb_gadget *gadget, | ||
1407 | struct usb_gadget_driver *driver) | ||
1408 | { | ||
1409 | struct xusb_udc *udc = to_udc(gadget); | ||
1410 | unsigned long flags; | ||
1411 | |||
1412 | spin_lock_irqsave(&udc->lock, flags); | ||
1413 | |||
1414 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1415 | udc->driver = NULL; | ||
1416 | |||
1417 | /* Set device address and remote wakeup to 0 */ | ||
1418 | udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); | ||
1419 | udc->remote_wkp = 0; | ||
1420 | |||
1421 | xudc_stop_activity(udc); | ||
1422 | |||
1423 | spin_unlock_irqrestore(&udc->lock, flags); | ||
1424 | |||
1425 | return 0; | ||
1426 | } | ||
1427 | |||
1428 | static const struct usb_gadget_ops xusb_udc_ops = { | ||
1429 | .get_frame = xudc_get_frame, | ||
1430 | .wakeup = xudc_wakeup, | ||
1431 | .pullup = xudc_pullup, | ||
1432 | .udc_start = xudc_start, | ||
1433 | .udc_stop = xudc_stop, | ||
1434 | }; | ||
1435 | |||
1436 | /** | ||
1437 | * xudc_clear_stall_all_ep - clears stall of every endpoint. | ||
1438 | * @udc: pointer to the udc structure. | ||
1439 | */ | ||
1440 | static void xudc_clear_stall_all_ep(struct xusb_udc *udc) | ||
1441 | { | ||
1442 | struct xusb_ep *ep; | ||
1443 | u32 epcfgreg; | ||
1444 | int i; | ||
1445 | |||
1446 | for (i = 0; i < XUSB_MAX_ENDPOINTS; i++) { | ||
1447 | ep = &udc->ep[i]; | ||
1448 | epcfgreg = udc->read_fn(udc->addr + ep->offset); | ||
1449 | epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; | ||
1450 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
1451 | if (ep->epnumber) { | ||
1452 | /* Reset the toggle bit.*/ | ||
1453 | epcfgreg = udc->read_fn(udc->addr + ep->offset); | ||
1454 | epcfgreg &= ~XUSB_EP_CFG_DATA_TOGGLE_MASK; | ||
1455 | udc->write_fn(udc->addr, ep->offset, epcfgreg); | ||
1456 | } | ||
1457 | } | ||
1458 | } | ||
1459 | |||
1460 | /** | ||
1461 | * xudc_startup_handler - The usb device controller interrupt handler. | ||
1462 | * @udc: pointer to the udc structure. | ||
1463 | * @intrstatus: The mask value containing the interrupt sources. | ||
1464 | * | ||
1465 | * This function handles the RESET,SUSPEND,RESUME and DISCONNECT interrupts. | ||
1466 | */ | ||
1467 | static void xudc_startup_handler(struct xusb_udc *udc, u32 intrstatus) | ||
1468 | { | ||
1469 | u32 intrreg; | ||
1470 | |||
1471 | if (intrstatus & XUSB_STATUS_RESET_MASK) { | ||
1472 | |||
1473 | dev_dbg(udc->dev, "Reset\n"); | ||
1474 | |||
1475 | if (intrstatus & XUSB_STATUS_HIGH_SPEED_MASK) | ||
1476 | udc->gadget.speed = USB_SPEED_HIGH; | ||
1477 | else | ||
1478 | udc->gadget.speed = USB_SPEED_FULL; | ||
1479 | |||
1480 | xudc_stop_activity(udc); | ||
1481 | xudc_clear_stall_all_ep(udc); | ||
1482 | udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); | ||
1483 | |||
1484 | /* Set device address and remote wakeup to 0 */ | ||
1485 | udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); | ||
1486 | udc->remote_wkp = 0; | ||
1487 | |||
1488 | /* Enable the suspend, resume and disconnect */ | ||
1489 | intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
1490 | intrreg |= XUSB_STATUS_SUSPEND_MASK | XUSB_STATUS_RESUME_MASK | | ||
1491 | XUSB_STATUS_DISCONNECT_MASK; | ||
1492 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); | ||
1493 | } | ||
1494 | if (intrstatus & XUSB_STATUS_SUSPEND_MASK) { | ||
1495 | |||
1496 | dev_dbg(udc->dev, "Suspend\n"); | ||
1497 | |||
1498 | /* Enable the reset, resume and disconnect */ | ||
1499 | intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
1500 | intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_RESUME_MASK | | ||
1501 | XUSB_STATUS_DISCONNECT_MASK; | ||
1502 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); | ||
1503 | |||
1504 | udc->usb_state = USB_STATE_SUSPENDED; | ||
1505 | |||
1506 | if (udc->driver->suspend) { | ||
1507 | spin_unlock(&udc->lock); | ||
1508 | udc->driver->suspend(&udc->gadget); | ||
1509 | spin_lock(&udc->lock); | ||
1510 | } | ||
1511 | } | ||
1512 | if (intrstatus & XUSB_STATUS_RESUME_MASK) { | ||
1513 | bool condition = (udc->usb_state != USB_STATE_SUSPENDED); | ||
1514 | |||
1515 | dev_WARN_ONCE(udc->dev, condition, | ||
1516 | "Resume IRQ while not suspended\n"); | ||
1517 | |||
1518 | dev_dbg(udc->dev, "Resume\n"); | ||
1519 | |||
1520 | /* Enable the reset, suspend and disconnect */ | ||
1521 | intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
1522 | intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_SUSPEND_MASK | | ||
1523 | XUSB_STATUS_DISCONNECT_MASK; | ||
1524 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); | ||
1525 | |||
1526 | udc->usb_state = 0; | ||
1527 | |||
1528 | if (udc->driver->resume) { | ||
1529 | spin_unlock(&udc->lock); | ||
1530 | udc->driver->resume(&udc->gadget); | ||
1531 | spin_lock(&udc->lock); | ||
1532 | } | ||
1533 | } | ||
1534 | if (intrstatus & XUSB_STATUS_DISCONNECT_MASK) { | ||
1535 | |||
1536 | dev_dbg(udc->dev, "Disconnect\n"); | ||
1537 | |||
1538 | /* Enable the reset, resume and suspend */ | ||
1539 | intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
1540 | intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_RESUME_MASK | | ||
1541 | XUSB_STATUS_SUSPEND_MASK; | ||
1542 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); | ||
1543 | |||
1544 | if (udc->driver && udc->driver->disconnect) { | ||
1545 | spin_unlock(&udc->lock); | ||
1546 | udc->driver->disconnect(&udc->gadget); | ||
1547 | spin_lock(&udc->lock); | ||
1548 | } | ||
1549 | } | ||
1550 | } | ||
1551 | |||
1552 | /** | ||
1553 | * xudc_ep0_stall - Stall endpoint zero. | ||
1554 | * @udc: pointer to the udc structure. | ||
1555 | * | ||
1556 | * This function stalls endpoint zero. | ||
1557 | */ | ||
1558 | static void xudc_ep0_stall(struct xusb_udc *udc) | ||
1559 | { | ||
1560 | u32 epcfgreg; | ||
1561 | struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; | ||
1562 | |||
1563 | epcfgreg = udc->read_fn(udc->addr + ep0->offset); | ||
1564 | epcfgreg |= XUSB_EP_CFG_STALL_MASK; | ||
1565 | udc->write_fn(udc->addr, ep0->offset, epcfgreg); | ||
1566 | } | ||
1567 | |||
1568 | /** | ||
1569 | * xudc_setaddress - executes SET_ADDRESS command | ||
1570 | * @udc: pointer to the udc structure. | ||
1571 | * | ||
1572 | * This function executes USB SET_ADDRESS command | ||
1573 | */ | ||
1574 | static void xudc_setaddress(struct xusb_udc *udc) | ||
1575 | { | ||
1576 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1577 | struct xusb_req *req = udc->req; | ||
1578 | int ret; | ||
1579 | |||
1580 | req->usb_req.length = 0; | ||
1581 | ret = __xudc_ep0_queue(ep0, req); | ||
1582 | if (ret == 0) | ||
1583 | return; | ||
1584 | |||
1585 | dev_err(udc->dev, "Can't respond to SET ADDRESS request\n"); | ||
1586 | xudc_ep0_stall(udc); | ||
1587 | } | ||
1588 | |||
1589 | /** | ||
1590 | * xudc_getstatus - executes GET_STATUS command | ||
1591 | * @udc: pointer to the udc structure. | ||
1592 | * | ||
1593 | * This function executes USB GET_STATUS command | ||
1594 | */ | ||
1595 | static void xudc_getstatus(struct xusb_udc *udc) | ||
1596 | { | ||
1597 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1598 | struct xusb_req *req = udc->req; | ||
1599 | struct xusb_ep *target_ep; | ||
1600 | u16 status = 0; | ||
1601 | u32 epcfgreg; | ||
1602 | int epnum; | ||
1603 | u32 halt; | ||
1604 | int ret; | ||
1605 | |||
1606 | switch (udc->setup.bRequestType & USB_RECIP_MASK) { | ||
1607 | case USB_RECIP_DEVICE: | ||
1608 | /* Get device status */ | ||
1609 | status = 1 << USB_DEVICE_SELF_POWERED; | ||
1610 | if (udc->remote_wkp) | ||
1611 | status |= (1 << USB_DEVICE_REMOTE_WAKEUP); | ||
1612 | break; | ||
1613 | case USB_RECIP_INTERFACE: | ||
1614 | break; | ||
1615 | case USB_RECIP_ENDPOINT: | ||
1616 | epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
1617 | target_ep = &udc->ep[epnum]; | ||
1618 | epcfgreg = udc->read_fn(udc->addr + target_ep->offset); | ||
1619 | halt = epcfgreg & XUSB_EP_CFG_STALL_MASK; | ||
1620 | if (udc->setup.wIndex & USB_DIR_IN) { | ||
1621 | if (!target_ep->is_in) | ||
1622 | goto stall; | ||
1623 | } else { | ||
1624 | if (target_ep->is_in) | ||
1625 | goto stall; | ||
1626 | } | ||
1627 | if (halt) | ||
1628 | status = 1 << USB_ENDPOINT_HALT; | ||
1629 | break; | ||
1630 | default: | ||
1631 | goto stall; | ||
1632 | } | ||
1633 | |||
1634 | req->usb_req.length = 2; | ||
1635 | *(u16 *)req->usb_req.buf = cpu_to_le16(status); | ||
1636 | ret = __xudc_ep0_queue(ep0, req); | ||
1637 | if (ret == 0) | ||
1638 | return; | ||
1639 | stall: | ||
1640 | dev_err(udc->dev, "Can't respond to getstatus request\n"); | ||
1641 | xudc_ep0_stall(udc); | ||
1642 | } | ||
1643 | |||
1644 | /** | ||
1645 | * xudc_set_clear_feature - Executes the set feature and clear feature commands. | ||
1646 | * @udc: pointer to the usb device controller structure. | ||
1647 | * | ||
1648 | * Processes the SET_FEATURE and CLEAR_FEATURE commands. | ||
1649 | */ | ||
1650 | static void xudc_set_clear_feature(struct xusb_udc *udc) | ||
1651 | { | ||
1652 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1653 | struct xusb_req *req = udc->req; | ||
1654 | struct xusb_ep *target_ep; | ||
1655 | u8 endpoint; | ||
1656 | u8 outinbit; | ||
1657 | u32 epcfgreg; | ||
1658 | int flag = (udc->setup.bRequest == USB_REQ_SET_FEATURE ? 1 : 0); | ||
1659 | int ret; | ||
1660 | |||
1661 | switch (udc->setup.bRequestType) { | ||
1662 | case USB_RECIP_DEVICE: | ||
1663 | switch (udc->setup.wValue) { | ||
1664 | case USB_DEVICE_TEST_MODE: | ||
1665 | /* | ||
1666 | * The Test Mode will be executed | ||
1667 | * after the status phase. | ||
1668 | */ | ||
1669 | break; | ||
1670 | case USB_DEVICE_REMOTE_WAKEUP: | ||
1671 | if (flag) | ||
1672 | udc->remote_wkp = 1; | ||
1673 | else | ||
1674 | udc->remote_wkp = 0; | ||
1675 | break; | ||
1676 | default: | ||
1677 | xudc_ep0_stall(udc); | ||
1678 | break; | ||
1679 | } | ||
1680 | break; | ||
1681 | case USB_RECIP_ENDPOINT: | ||
1682 | if (!udc->setup.wValue) { | ||
1683 | endpoint = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; | ||
1684 | target_ep = &udc->ep[endpoint]; | ||
1685 | outinbit = udc->setup.wIndex & USB_ENDPOINT_DIR_MASK; | ||
1686 | outinbit = outinbit >> 7; | ||
1687 | |||
1688 | /* Make sure direction matches.*/ | ||
1689 | if (outinbit != target_ep->is_in) { | ||
1690 | xudc_ep0_stall(udc); | ||
1691 | return; | ||
1692 | } | ||
1693 | epcfgreg = udc->read_fn(udc->addr + target_ep->offset); | ||
1694 | if (!endpoint) { | ||
1695 | /* Clear the stall.*/ | ||
1696 | epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; | ||
1697 | udc->write_fn(udc->addr, | ||
1698 | target_ep->offset, epcfgreg); | ||
1699 | } else { | ||
1700 | if (flag) { | ||
1701 | epcfgreg |= XUSB_EP_CFG_STALL_MASK; | ||
1702 | udc->write_fn(udc->addr, | ||
1703 | target_ep->offset, | ||
1704 | epcfgreg); | ||
1705 | } else { | ||
1706 | /* Unstall the endpoint.*/ | ||
1707 | epcfgreg &= ~(XUSB_EP_CFG_STALL_MASK | | ||
1708 | XUSB_EP_CFG_DATA_TOGGLE_MASK); | ||
1709 | udc->write_fn(udc->addr, | ||
1710 | target_ep->offset, | ||
1711 | epcfgreg); | ||
1712 | } | ||
1713 | } | ||
1714 | } | ||
1715 | break; | ||
1716 | default: | ||
1717 | xudc_ep0_stall(udc); | ||
1718 | return; | ||
1719 | } | ||
1720 | |||
1721 | req->usb_req.length = 0; | ||
1722 | ret = __xudc_ep0_queue(ep0, req); | ||
1723 | if (ret == 0) | ||
1724 | return; | ||
1725 | |||
1726 | dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); | ||
1727 | xudc_ep0_stall(udc); | ||
1728 | } | ||
1729 | |||
1730 | /** | ||
1731 | * xudc_handle_setup - Processes the setup packet. | ||
1732 | * @udc: pointer to the usb device controller structure. | ||
1733 | * | ||
1734 | * Process setup packet and delegate to gadget layer. | ||
1735 | */ | ||
1736 | static void xudc_handle_setup(struct xusb_udc *udc) | ||
1737 | { | ||
1738 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1739 | struct usb_ctrlrequest setup; | ||
1740 | u32 *ep0rambase; | ||
1741 | |||
1742 | /* Load up the chapter 9 command buffer.*/ | ||
1743 | ep0rambase = (u32 __force *) (udc->addr + XUSB_SETUP_PKT_ADDR_OFFSET); | ||
1744 | memcpy(&setup, ep0rambase, 8); | ||
1745 | |||
1746 | udc->setup = setup; | ||
1747 | udc->setup.wValue = cpu_to_le16(setup.wValue); | ||
1748 | udc->setup.wIndex = cpu_to_le16(setup.wIndex); | ||
1749 | udc->setup.wLength = cpu_to_le16(setup.wLength); | ||
1750 | |||
1751 | /* Clear previous requests */ | ||
1752 | xudc_nuke(ep0, -ECONNRESET); | ||
1753 | |||
1754 | if (udc->setup.bRequestType & USB_DIR_IN) { | ||
1755 | /* Execute the get command.*/ | ||
1756 | udc->setupseqrx = STATUS_PHASE; | ||
1757 | udc->setupseqtx = DATA_PHASE; | ||
1758 | } else { | ||
1759 | /* Execute the put command.*/ | ||
1760 | udc->setupseqrx = DATA_PHASE; | ||
1761 | udc->setupseqtx = STATUS_PHASE; | ||
1762 | } | ||
1763 | |||
1764 | switch (udc->setup.bRequest) { | ||
1765 | case USB_REQ_GET_STATUS: | ||
1766 | /* Data+Status phase form udc */ | ||
1767 | if ((udc->setup.bRequestType & | ||
1768 | (USB_DIR_IN | USB_TYPE_MASK)) != | ||
1769 | (USB_DIR_IN | USB_TYPE_STANDARD)) | ||
1770 | break; | ||
1771 | xudc_getstatus(udc); | ||
1772 | return; | ||
1773 | case USB_REQ_SET_ADDRESS: | ||
1774 | /* Status phase from udc */ | ||
1775 | if (udc->setup.bRequestType != (USB_DIR_OUT | | ||
1776 | USB_TYPE_STANDARD | USB_RECIP_DEVICE)) | ||
1777 | break; | ||
1778 | xudc_setaddress(udc); | ||
1779 | return; | ||
1780 | case USB_REQ_CLEAR_FEATURE: | ||
1781 | case USB_REQ_SET_FEATURE: | ||
1782 | /* Requests with no data phase, status phase from udc */ | ||
1783 | if ((udc->setup.bRequestType & USB_TYPE_MASK) | ||
1784 | != USB_TYPE_STANDARD) | ||
1785 | break; | ||
1786 | xudc_set_clear_feature(udc); | ||
1787 | return; | ||
1788 | default: | ||
1789 | break; | ||
1790 | } | ||
1791 | |||
1792 | spin_unlock(&udc->lock); | ||
1793 | if (udc->driver->setup(&udc->gadget, &setup) < 0) | ||
1794 | xudc_ep0_stall(udc); | ||
1795 | spin_lock(&udc->lock); | ||
1796 | } | ||
1797 | |||
1798 | /** | ||
1799 | * xudc_ep0_out - Processes the endpoint 0 OUT token. | ||
1800 | * @udc: pointer to the usb device controller structure. | ||
1801 | */ | ||
1802 | static void xudc_ep0_out(struct xusb_udc *udc) | ||
1803 | { | ||
1804 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1805 | struct xusb_req *req; | ||
1806 | u8 *ep0rambase; | ||
1807 | unsigned int bytes_to_rx; | ||
1808 | void *buffer; | ||
1809 | |||
1810 | req = list_first_entry(&ep0->queue, struct xusb_req, queue); | ||
1811 | |||
1812 | switch (udc->setupseqrx) { | ||
1813 | case STATUS_PHASE: | ||
1814 | /* | ||
1815 | * This resets both state machines for the next | ||
1816 | * Setup packet. | ||
1817 | */ | ||
1818 | udc->setupseqrx = SETUP_PHASE; | ||
1819 | udc->setupseqtx = SETUP_PHASE; | ||
1820 | req->usb_req.actual = req->usb_req.length; | ||
1821 | xudc_done(ep0, req, 0); | ||
1822 | break; | ||
1823 | case DATA_PHASE: | ||
1824 | bytes_to_rx = udc->read_fn(udc->addr + | ||
1825 | XUSB_EP_BUF0COUNT_OFFSET); | ||
1826 | /* Copy the data to be received from the DPRAM. */ | ||
1827 | ep0rambase = (u8 __force *) (udc->addr + | ||
1828 | (ep0->rambase << 2)); | ||
1829 | buffer = req->usb_req.buf + req->usb_req.actual; | ||
1830 | req->usb_req.actual = req->usb_req.actual + bytes_to_rx; | ||
1831 | memcpy(buffer, ep0rambase, bytes_to_rx); | ||
1832 | |||
1833 | if (req->usb_req.length == req->usb_req.actual) { | ||
1834 | /* Data transfer completed get ready for Status stage */ | ||
1835 | xudc_wrstatus(udc); | ||
1836 | } else { | ||
1837 | /* Enable EP0 buffer to receive data */ | ||
1838 | udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); | ||
1839 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); | ||
1840 | } | ||
1841 | break; | ||
1842 | default: | ||
1843 | break; | ||
1844 | } | ||
1845 | } | ||
1846 | |||
1847 | /** | ||
1848 | * xudc_ep0_in - Processes the endpoint 0 IN token. | ||
1849 | * @udc: pointer to the usb device controller structure. | ||
1850 | */ | ||
1851 | static void xudc_ep0_in(struct xusb_udc *udc) | ||
1852 | { | ||
1853 | struct xusb_ep *ep0 = &udc->ep[0]; | ||
1854 | struct xusb_req *req; | ||
1855 | unsigned int bytes_to_tx; | ||
1856 | void *buffer; | ||
1857 | u32 epcfgreg; | ||
1858 | u16 count = 0; | ||
1859 | u16 length; | ||
1860 | u8 *ep0rambase; | ||
1861 | u8 test_mode = udc->setup.wIndex >> 8; | ||
1862 | |||
1863 | req = list_first_entry(&ep0->queue, struct xusb_req, queue); | ||
1864 | bytes_to_tx = req->usb_req.length - req->usb_req.actual; | ||
1865 | |||
1866 | switch (udc->setupseqtx) { | ||
1867 | case STATUS_PHASE: | ||
1868 | switch (udc->setup.bRequest) { | ||
1869 | case USB_REQ_SET_ADDRESS: | ||
1870 | /* Set the address of the device.*/ | ||
1871 | udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, | ||
1872 | udc->setup.wValue); | ||
1873 | break; | ||
1874 | case USB_REQ_SET_FEATURE: | ||
1875 | if (udc->setup.bRequestType == | ||
1876 | USB_RECIP_DEVICE) { | ||
1877 | if (udc->setup.wValue == | ||
1878 | USB_DEVICE_TEST_MODE) | ||
1879 | udc->write_fn(udc->addr, | ||
1880 | XUSB_TESTMODE_OFFSET, | ||
1881 | test_mode); | ||
1882 | } | ||
1883 | break; | ||
1884 | } | ||
1885 | req->usb_req.actual = req->usb_req.length; | ||
1886 | xudc_done(ep0, req, 0); | ||
1887 | break; | ||
1888 | case DATA_PHASE: | ||
1889 | if (!bytes_to_tx) { | ||
1890 | /* | ||
1891 | * We're done with data transfer, next | ||
1892 | * will be zero length OUT with data toggle of | ||
1893 | * 1. Setup data_toggle. | ||
1894 | */ | ||
1895 | epcfgreg = udc->read_fn(udc->addr + ep0->offset); | ||
1896 | epcfgreg |= XUSB_EP_CFG_DATA_TOGGLE_MASK; | ||
1897 | udc->write_fn(udc->addr, ep0->offset, epcfgreg); | ||
1898 | udc->setupseqtx = STATUS_PHASE; | ||
1899 | } else { | ||
1900 | length = count = min_t(u32, bytes_to_tx, | ||
1901 | EP0_MAX_PACKET); | ||
1902 | /* Copy the data to be transmitted into the DPRAM. */ | ||
1903 | ep0rambase = (u8 __force *) (udc->addr + | ||
1904 | (ep0->rambase << 2)); | ||
1905 | buffer = req->usb_req.buf + req->usb_req.actual; | ||
1906 | req->usb_req.actual = req->usb_req.actual + length; | ||
1907 | memcpy(ep0rambase, buffer, length); | ||
1908 | } | ||
1909 | udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, count); | ||
1910 | udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); | ||
1911 | break; | ||
1912 | default: | ||
1913 | break; | ||
1914 | } | ||
1915 | } | ||
1916 | |||
1917 | /** | ||
1918 | * xudc_ctrl_ep_handler - Endpoint 0 interrupt handler. | ||
1919 | * @udc: pointer to the udc structure. | ||
1920 | * @intrstatus: It's the mask value for the interrupt sources on endpoint 0. | ||
1921 | * | ||
1922 | * Processes the commands received during enumeration phase. | ||
1923 | */ | ||
1924 | static void xudc_ctrl_ep_handler(struct xusb_udc *udc, u32 intrstatus) | ||
1925 | { | ||
1926 | |||
1927 | if (intrstatus & XUSB_STATUS_SETUP_PACKET_MASK) { | ||
1928 | xudc_handle_setup(udc); | ||
1929 | } else { | ||
1930 | if (intrstatus & XUSB_STATUS_FIFO_BUFF_RDY_MASK) | ||
1931 | xudc_ep0_out(udc); | ||
1932 | else if (intrstatus & XUSB_STATUS_FIFO_BUFF_FREE_MASK) | ||
1933 | xudc_ep0_in(udc); | ||
1934 | } | ||
1935 | } | ||
1936 | |||
1937 | /** | ||
1938 | * xudc_nonctrl_ep_handler - Non control endpoint interrupt handler. | ||
1939 | * @udc: pointer to the udc structure. | ||
1940 | * @epnum: End point number for which the interrupt is to be processed | ||
1941 | * @intrstatus: mask value for interrupt sources of endpoints other | ||
1942 | * than endpoint 0. | ||
1943 | * | ||
1944 | * Processes the buffer completion interrupts. | ||
1945 | */ | ||
1946 | static void xudc_nonctrl_ep_handler(struct xusb_udc *udc, u8 epnum, | ||
1947 | u32 intrstatus) | ||
1948 | { | ||
1949 | |||
1950 | struct xusb_req *req; | ||
1951 | struct xusb_ep *ep; | ||
1952 | |||
1953 | ep = &udc->ep[epnum]; | ||
1954 | /* Process the End point interrupts.*/ | ||
1955 | if (intrstatus & (XUSB_STATUS_EP0_BUFF1_COMP_MASK << epnum)) | ||
1956 | ep->buffer0ready = 0; | ||
1957 | if (intrstatus & (XUSB_STATUS_EP0_BUFF2_COMP_MASK << epnum)) | ||
1958 | ep->buffer1ready = 0; | ||
1959 | |||
1960 | if (list_empty(&ep->queue)) | ||
1961 | return; | ||
1962 | |||
1963 | req = list_first_entry(&ep->queue, struct xusb_req, queue); | ||
1964 | |||
1965 | if (ep->is_in) | ||
1966 | xudc_write_fifo(ep, req); | ||
1967 | else | ||
1968 | xudc_read_fifo(ep, req); | ||
1969 | } | ||
1970 | |||
1971 | /** | ||
1972 | * xudc_irq - The main interrupt handler. | ||
1973 | * @irq: The interrupt number. | ||
1974 | * @_udc: pointer to the usb device controller structure. | ||
1975 | * | ||
1976 | * Return: IRQ_HANDLED after the interrupt is handled. | ||
1977 | */ | ||
1978 | static irqreturn_t xudc_irq(int irq, void *_udc) | ||
1979 | { | ||
1980 | struct xusb_udc *udc = _udc; | ||
1981 | u32 intrstatus; | ||
1982 | u32 ier; | ||
1983 | u8 index; | ||
1984 | u32 bufintr; | ||
1985 | unsigned long flags; | ||
1986 | |||
1987 | spin_lock_irqsave(&udc->lock, flags); | ||
1988 | |||
1989 | /* | ||
1990 | * Event interrupts are level sensitive hence first disable | ||
1991 | * IER, read ISR and figure out active interrupts. | ||
1992 | */ | ||
1993 | ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
1994 | ier &= ~XUSB_STATUS_INTR_EVENT_MASK; | ||
1995 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); | ||
1996 | |||
1997 | /* Read the Interrupt Status Register.*/ | ||
1998 | intrstatus = udc->read_fn(udc->addr + XUSB_STATUS_OFFSET); | ||
1999 | |||
2000 | /* Call the handler for the event interrupt.*/ | ||
2001 | if (intrstatus & XUSB_STATUS_INTR_EVENT_MASK) { | ||
2002 | /* | ||
2003 | * Check if there is any action to be done for : | ||
2004 | * - USB Reset received {XUSB_STATUS_RESET_MASK} | ||
2005 | * - USB Suspend received {XUSB_STATUS_SUSPEND_MASK} | ||
2006 | * - USB Resume received {XUSB_STATUS_RESUME_MASK} | ||
2007 | * - USB Disconnect received {XUSB_STATUS_DISCONNECT_MASK} | ||
2008 | */ | ||
2009 | xudc_startup_handler(udc, intrstatus); | ||
2010 | } | ||
2011 | |||
2012 | /* Check the buffer completion interrupts */ | ||
2013 | if (intrstatus & XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK) { | ||
2014 | /* Enable Reset, Suspend, Resume and Disconnect */ | ||
2015 | ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); | ||
2016 | ier |= XUSB_STATUS_INTR_EVENT_MASK; | ||
2017 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); | ||
2018 | |||
2019 | if (intrstatus & XUSB_STATUS_EP0_BUFF1_COMP_MASK) | ||
2020 | xudc_ctrl_ep_handler(udc, intrstatus); | ||
2021 | |||
2022 | for (index = 1; index < 8; index++) { | ||
2023 | bufintr = ((intrstatus & | ||
2024 | (XUSB_STATUS_EP1_BUFF1_COMP_MASK << | ||
2025 | (index - 1))) || (intrstatus & | ||
2026 | (XUSB_STATUS_EP1_BUFF2_COMP_MASK << | ||
2027 | (index - 1)))); | ||
2028 | if (bufintr) { | ||
2029 | xudc_nonctrl_ep_handler(udc, index, | ||
2030 | intrstatus); | ||
2031 | } | ||
2032 | } | ||
2033 | } | ||
2034 | |||
2035 | spin_unlock_irqrestore(&udc->lock, flags); | ||
2036 | return IRQ_HANDLED; | ||
2037 | } | ||
2038 | |||
2039 | /** | ||
2040 | * xudc_probe - The device probe function for driver initialization. | ||
2041 | * @pdev: pointer to the platform device structure. | ||
2042 | * | ||
2043 | * Return: 0 for success and error value on failure | ||
2044 | */ | ||
2045 | static int xudc_probe(struct platform_device *pdev) | ||
2046 | { | ||
2047 | struct device_node *np = pdev->dev.of_node; | ||
2048 | struct resource *res; | ||
2049 | struct xusb_udc *udc; | ||
2050 | struct xusb_ep *ep0; | ||
2051 | int irq; | ||
2052 | int ret; | ||
2053 | u32 ier; | ||
2054 | u8 *buff; | ||
2055 | |||
2056 | udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); | ||
2057 | if (!udc) | ||
2058 | return -ENOMEM; | ||
2059 | |||
2060 | /* Create a dummy request for GET_STATUS, SET_ADDRESS */ | ||
2061 | udc->req = devm_kzalloc(&pdev->dev, sizeof(struct xusb_req), | ||
2062 | GFP_KERNEL); | ||
2063 | if (!udc->req) | ||
2064 | return -ENOMEM; | ||
2065 | |||
2066 | buff = devm_kzalloc(&pdev->dev, STATUSBUFF_SIZE, GFP_KERNEL); | ||
2067 | if (!buff) | ||
2068 | return -ENOMEM; | ||
2069 | |||
2070 | udc->req->usb_req.buf = buff; | ||
2071 | |||
2072 | /* Map the registers */ | ||
2073 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2074 | udc->addr = devm_ioremap_resource(&pdev->dev, res); | ||
2075 | if (!udc->addr) | ||
2076 | return -ENOMEM; | ||
2077 | |||
2078 | irq = platform_get_irq(pdev, 0); | ||
2079 | if (irq < 0) { | ||
2080 | dev_err(&pdev->dev, "unable to get irq\n"); | ||
2081 | return irq; | ||
2082 | } | ||
2083 | ret = devm_request_irq(&pdev->dev, irq, xudc_irq, 0, | ||
2084 | dev_name(&pdev->dev), udc); | ||
2085 | if (ret < 0) { | ||
2086 | dev_dbg(&pdev->dev, "unable to request irq %d", irq); | ||
2087 | goto fail; | ||
2088 | } | ||
2089 | |||
2090 | udc->dma_enabled = of_property_read_bool(np, "xlnx,has-builtin-dma"); | ||
2091 | |||
2092 | /* Setup gadget structure */ | ||
2093 | udc->gadget.ops = &xusb_udc_ops; | ||
2094 | udc->gadget.max_speed = USB_SPEED_HIGH; | ||
2095 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
2096 | udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb; | ||
2097 | udc->gadget.name = driver_name; | ||
2098 | |||
2099 | spin_lock_init(&udc->lock); | ||
2100 | |||
2101 | /* Check for IP endianness */ | ||
2102 | udc->write_fn = xudc_write32_be; | ||
2103 | udc->read_fn = xudc_read32_be; | ||
2104 | udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, TEST_J); | ||
2105 | if ((udc->read_fn(udc->addr + XUSB_TESTMODE_OFFSET)) | ||
2106 | != TEST_J) { | ||
2107 | udc->write_fn = xudc_write32; | ||
2108 | udc->read_fn = xudc_read32; | ||
2109 | } | ||
2110 | udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); | ||
2111 | |||
2112 | xudc_eps_init(udc); | ||
2113 | |||
2114 | ep0 = &udc->ep[0]; | ||
2115 | |||
2116 | /* Set device address to 0.*/ | ||
2117 | udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); | ||
2118 | |||
2119 | ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); | ||
2120 | if (ret) | ||
2121 | goto fail; | ||
2122 | |||
2123 | udc->dev = &udc->gadget.dev; | ||
2124 | |||
2125 | /* Enable the interrupts.*/ | ||
2126 | ier = XUSB_STATUS_GLOBAL_INTR_MASK | XUSB_STATUS_INTR_EVENT_MASK | | ||
2127 | XUSB_STATUS_FIFO_BUFF_RDY_MASK | XUSB_STATUS_FIFO_BUFF_FREE_MASK | | ||
2128 | XUSB_STATUS_SETUP_PACKET_MASK | | ||
2129 | XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK; | ||
2130 | |||
2131 | udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); | ||
2132 | |||
2133 | platform_set_drvdata(pdev, udc); | ||
2134 | |||
2135 | dev_vdbg(&pdev->dev, "%s at 0x%08X mapped to 0x%08X %s\n", | ||
2136 | driver_name, (u32)res->start, (u32 __force)udc->addr, | ||
2137 | udc->dma_enabled ? "with DMA" : "without DMA"); | ||
2138 | |||
2139 | return 0; | ||
2140 | fail: | ||
2141 | dev_err(&pdev->dev, "probe failed, %d\n", ret); | ||
2142 | return ret; | ||
2143 | } | ||
2144 | |||
2145 | /** | ||
2146 | * xudc_remove - Releases the resources allocated during the initialization. | ||
2147 | * @pdev: pointer to the platform device structure. | ||
2148 | * | ||
2149 | * Return: 0 always | ||
2150 | */ | ||
2151 | static int xudc_remove(struct platform_device *pdev) | ||
2152 | { | ||
2153 | struct xusb_udc *udc = platform_get_drvdata(pdev); | ||
2154 | |||
2155 | usb_del_gadget_udc(&udc->gadget); | ||
2156 | |||
2157 | return 0; | ||
2158 | } | ||
2159 | |||
2160 | /* Match table for of_platform binding */ | ||
2161 | static const struct of_device_id usb_of_match[] = { | ||
2162 | { .compatible = "xlnx,usb2-device-4.00.a", }, | ||
2163 | { /* end of list */ }, | ||
2164 | }; | ||
2165 | MODULE_DEVICE_TABLE(of, usb_of_match); | ||
2166 | |||
2167 | static struct platform_driver xudc_driver = { | ||
2168 | .driver = { | ||
2169 | .name = driver_name, | ||
2170 | .of_match_table = usb_of_match, | ||
2171 | }, | ||
2172 | .probe = xudc_probe, | ||
2173 | .remove = xudc_remove, | ||
2174 | }; | ||
2175 | |||
2176 | module_platform_driver(xudc_driver); | ||
2177 | |||
2178 | MODULE_DESCRIPTION("Xilinx udc driver"); | ||
2179 | MODULE_AUTHOR("Xilinx, Inc"); | ||
2180 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 82800a775501..a8a30b1d4167 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -26,6 +26,11 @@ config USB_XHCI_HCD | |||
26 | 26 | ||
27 | if USB_XHCI_HCD | 27 | if USB_XHCI_HCD |
28 | 28 | ||
29 | config USB_XHCI_PCI | ||
30 | tristate | ||
31 | depends on PCI | ||
32 | default y | ||
33 | |||
29 | config USB_XHCI_PLATFORM | 34 | config USB_XHCI_PLATFORM |
30 | tristate | 35 | tristate |
31 | 36 | ||
@@ -126,7 +131,7 @@ config XPS_USB_HCD_XILINX | |||
126 | select USB_EHCI_BIG_ENDIAN_DESC | 131 | select USB_EHCI_BIG_ENDIAN_DESC |
127 | select USB_EHCI_BIG_ENDIAN_MMIO | 132 | select USB_EHCI_BIG_ENDIAN_MMIO |
128 | ---help--- | 133 | ---help--- |
129 | Xilinx xps USB host controller core is EHCI compilant and has | 134 | Xilinx xps USB host controller core is EHCI compliant and has |
130 | transaction translator built-in. It can be configured to either | 135 | transaction translator built-in. It can be configured to either |
131 | support both high speed and full speed devices, or high speed | 136 | support both high speed and full speed devices, or high speed |
132 | devices only. | 137 | devices only. |
@@ -174,6 +179,15 @@ config USB_EHCI_HCD_SPEAR | |||
174 | Enables support for the on-chip EHCI controller on | 179 | Enables support for the on-chip EHCI controller on |
175 | ST SPEAr chips. | 180 | ST SPEAr chips. |
176 | 181 | ||
182 | config USB_EHCI_HCD_STI | ||
183 | tristate "Support for ST STiHxxx on-chip EHCI USB controller" | ||
184 | depends on ARCH_STI && OF | ||
185 | select GENERIC_PHY | ||
186 | select USB_EHCI_HCD_PLATFORM | ||
187 | help | ||
188 | Enable support for the on-chip EHCI controller found on | ||
189 | STMicroelectronics consumer electronics SoC's. | ||
190 | |||
177 | config USB_EHCI_HCD_AT91 | 191 | config USB_EHCI_HCD_AT91 |
178 | tristate "Support for Atmel on-chip EHCI USB controller" | 192 | tristate "Support for Atmel on-chip EHCI USB controller" |
179 | depends on USB_EHCI_HCD && ARCH_AT91 | 193 | depends on USB_EHCI_HCD && ARCH_AT91 |
@@ -402,6 +416,15 @@ config USB_OHCI_HCD_SPEAR | |||
402 | Enables support for the on-chip OHCI controller on | 416 | Enables support for the on-chip OHCI controller on |
403 | ST SPEAr chips. | 417 | ST SPEAr chips. |
404 | 418 | ||
419 | config USB_OHCI_HCD_STI | ||
420 | tristate "Support for ST STiHxxx on-chip OHCI USB controller" | ||
421 | depends on ARCH_STI && OF | ||
422 | select GENERIC_PHY | ||
423 | select USB_OHCI_HCD_PLATFORM | ||
424 | help | ||
425 | Enable support for the on-chip OHCI controller found on | ||
426 | STMicroelectronics consumer electronics SoC's. | ||
427 | |||
405 | config USB_OHCI_HCD_S3C2410 | 428 | config USB_OHCI_HCD_S3C2410 |
406 | tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series" | 429 | tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series" |
407 | depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX) | 430 | depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX) |
@@ -709,7 +732,7 @@ config USB_WHCI_HCD | |||
709 | 732 | ||
710 | config USB_HWA_HCD | 733 | config USB_HWA_HCD |
711 | tristate "Host Wire Adapter (HWA) driver" | 734 | tristate "Host Wire Adapter (HWA) driver" |
712 | depends on UWB | 735 | depends on USB && UWB |
713 | select USB_WUSB | 736 | select USB_WUSB |
714 | select UWB_HWA | 737 | select UWB_HWA |
715 | help | 738 | help |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 144c038ef70f..348c24321562 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -15,22 +15,22 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o | |||
15 | xhci-hcd-y := xhci.o xhci-mem.o | 15 | xhci-hcd-y := xhci.o xhci-mem.o |
16 | xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o | 16 | xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o |
17 | xhci-hcd-y += xhci-trace.o | 17 | xhci-hcd-y += xhci-trace.o |
18 | xhci-hcd-$(CONFIG_PCI) += xhci-pci.o | ||
19 | 18 | ||
20 | ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) | 19 | xhci-plat-hcd-y := xhci-plat.o |
21 | xhci-hcd-y += xhci-plat.o | ||
22 | ifneq ($(CONFIG_USB_XHCI_MVEBU), ) | 20 | ifneq ($(CONFIG_USB_XHCI_MVEBU), ) |
23 | xhci-hcd-y += xhci-mvebu.o | 21 | xhci-plat-hcd-y += xhci-mvebu.o |
24 | endif | 22 | endif |
25 | ifneq ($(CONFIG_USB_XHCI_RCAR), ) | 23 | ifneq ($(CONFIG_USB_XHCI_RCAR), ) |
26 | xhci-hcd-y += xhci-rcar.o | 24 | xhci-plat-hcd-y += xhci-rcar.o |
27 | endif | ||
28 | endif | 25 | endif |
29 | 26 | ||
30 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ | 27 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ |
31 | 28 | ||
32 | obj-$(CONFIG_PCI) += pci-quirks.o | 29 | obj-$(CONFIG_PCI) += pci-quirks.o |
33 | 30 | ||
31 | obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o | ||
32 | obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o | ||
33 | |||
34 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o | 34 | obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o |
35 | obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o | 35 | obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o |
36 | obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o | 36 | obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o |
@@ -38,6 +38,7 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o | |||
38 | obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o | 38 | obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o |
39 | obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o | 39 | obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o |
40 | obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o | 40 | obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o |
41 | obj-$(CONFIG_USB_EHCI_HCD_STI) += ehci-st.o | ||
41 | obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o | 42 | obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o |
42 | obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o | 43 | obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o |
43 | obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o | 44 | obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o |
@@ -55,6 +56,7 @@ obj-$(CONFIG_USB_OHCI_EXYNOS) += ohci-exynos.o | |||
55 | obj-$(CONFIG_USB_OHCI_HCD_OMAP1) += ohci-omap.o | 56 | obj-$(CONFIG_USB_OHCI_HCD_OMAP1) += ohci-omap.o |
56 | obj-$(CONFIG_USB_OHCI_HCD_OMAP3) += ohci-omap3.o | 57 | obj-$(CONFIG_USB_OHCI_HCD_OMAP3) += ohci-omap3.o |
57 | obj-$(CONFIG_USB_OHCI_HCD_SPEAR) += ohci-spear.o | 58 | obj-$(CONFIG_USB_OHCI_HCD_SPEAR) += ohci-spear.o |
59 | obj-$(CONFIG_USB_OHCI_HCD_STI) += ohci-st.o | ||
58 | obj-$(CONFIG_USB_OHCI_HCD_AT91) += ohci-at91.o | 60 | obj-$(CONFIG_USB_OHCI_HCD_AT91) += ohci-at91.o |
59 | obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o | 61 | obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o |
60 | obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o | 62 | obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o |
diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index cda0a2f5c467..7189f2e32ac2 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c | |||
@@ -21,11 +21,8 @@ | |||
21 | #include <linux/of_gpio.h> | 21 | #include <linux/of_gpio.h> |
22 | #include <linux/phy/phy.h> | 22 | #include <linux/phy/phy.h> |
23 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
24 | #include <linux/usb/phy.h> | ||
25 | #include <linux/usb/samsung_usb_phy.h> | ||
26 | #include <linux/usb.h> | 24 | #include <linux/usb.h> |
27 | #include <linux/usb/hcd.h> | 25 | #include <linux/usb/hcd.h> |
28 | #include <linux/usb/otg.h> | ||
29 | 26 | ||
30 | #include "ehci.h" | 27 | #include "ehci.h" |
31 | 28 | ||
@@ -47,9 +44,7 @@ static struct hc_driver __read_mostly exynos_ehci_hc_driver; | |||
47 | 44 | ||
48 | struct exynos_ehci_hcd { | 45 | struct exynos_ehci_hcd { |
49 | struct clk *clk; | 46 | struct clk *clk; |
50 | struct usb_phy *phy; | 47 | struct phy *phy[PHY_NUMBER]; |
51 | struct usb_otg *otg; | ||
52 | struct phy *phy_g[PHY_NUMBER]; | ||
53 | }; | 48 | }; |
54 | 49 | ||
55 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) | 50 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) |
@@ -60,20 +55,9 @@ static int exynos_ehci_get_phy(struct device *dev, | |||
60 | struct device_node *child; | 55 | struct device_node *child; |
61 | struct phy *phy; | 56 | struct phy *phy; |
62 | int phy_number; | 57 | int phy_number; |
63 | int ret = 0; | 58 | int ret; |
64 | |||
65 | exynos_ehci->phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | ||
66 | if (IS_ERR(exynos_ehci->phy)) { | ||
67 | ret = PTR_ERR(exynos_ehci->phy); | ||
68 | if (ret != -ENXIO && ret != -ENODEV) { | ||
69 | dev_err(dev, "no usb2 phy configured\n"); | ||
70 | return ret; | ||
71 | } | ||
72 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
73 | } else { | ||
74 | exynos_ehci->otg = exynos_ehci->phy->otg; | ||
75 | } | ||
76 | 59 | ||
60 | /* Get PHYs for the controller */ | ||
77 | for_each_available_child_of_node(dev->of_node, child) { | 61 | for_each_available_child_of_node(dev->of_node, child) { |
78 | ret = of_property_read_u32(child, "reg", &phy_number); | 62 | ret = of_property_read_u32(child, "reg", &phy_number); |
79 | if (ret) { | 63 | if (ret) { |
@@ -89,19 +73,21 @@ static int exynos_ehci_get_phy(struct device *dev, | |||
89 | } | 73 | } |
90 | 74 | ||
91 | phy = devm_of_phy_get(dev, child, NULL); | 75 | phy = devm_of_phy_get(dev, child, NULL); |
76 | exynos_ehci->phy[phy_number] = phy; | ||
92 | of_node_put(child); | 77 | of_node_put(child); |
93 | if (IS_ERR(phy)) { | 78 | if (IS_ERR(phy)) { |
94 | ret = PTR_ERR(phy); | 79 | ret = PTR_ERR(phy); |
95 | if (ret != -ENOSYS && ret != -ENODEV) { | 80 | if (ret == -EPROBE_DEFER) { |
96 | dev_err(dev, "no usb2 phy configured\n"); | 81 | return ret; |
82 | } else if (ret != -ENOSYS && ret != -ENODEV) { | ||
83 | dev_err(dev, | ||
84 | "Error retrieving usb2 phy: %d\n", ret); | ||
97 | return ret; | 85 | return ret; |
98 | } | 86 | } |
99 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
100 | } | 87 | } |
101 | exynos_ehci->phy_g[phy_number] = phy; | ||
102 | } | 88 | } |
103 | 89 | ||
104 | return ret; | 90 | return 0; |
105 | } | 91 | } |
106 | 92 | ||
107 | static int exynos_ehci_phy_enable(struct device *dev) | 93 | static int exynos_ehci_phy_enable(struct device *dev) |
@@ -111,16 +97,13 @@ static int exynos_ehci_phy_enable(struct device *dev) | |||
111 | int i; | 97 | int i; |
112 | int ret = 0; | 98 | int ret = 0; |
113 | 99 | ||
114 | if (!IS_ERR(exynos_ehci->phy)) | ||
115 | return usb_phy_init(exynos_ehci->phy); | ||
116 | |||
117 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) | 100 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) |
118 | if (!IS_ERR(exynos_ehci->phy_g[i])) | 101 | if (!IS_ERR(exynos_ehci->phy[i])) |
119 | ret = phy_power_on(exynos_ehci->phy_g[i]); | 102 | ret = phy_power_on(exynos_ehci->phy[i]); |
120 | if (ret) | 103 | if (ret) |
121 | for (i--; i >= 0; i--) | 104 | for (i--; i >= 0; i--) |
122 | if (!IS_ERR(exynos_ehci->phy_g[i])) | 105 | if (!IS_ERR(exynos_ehci->phy[i])) |
123 | phy_power_off(exynos_ehci->phy_g[i]); | 106 | phy_power_off(exynos_ehci->phy[i]); |
124 | 107 | ||
125 | return ret; | 108 | return ret; |
126 | } | 109 | } |
@@ -131,14 +114,9 @@ static void exynos_ehci_phy_disable(struct device *dev) | |||
131 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); | 114 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
132 | int i; | 115 | int i; |
133 | 116 | ||
134 | if (!IS_ERR(exynos_ehci->phy)) { | ||
135 | usb_phy_shutdown(exynos_ehci->phy); | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | for (i = 0; i < PHY_NUMBER; i++) | 117 | for (i = 0; i < PHY_NUMBER; i++) |
140 | if (!IS_ERR(exynos_ehci->phy_g[i])) | 118 | if (!IS_ERR(exynos_ehci->phy[i])) |
141 | phy_power_off(exynos_ehci->phy_g[i]); | 119 | phy_power_off(exynos_ehci->phy[i]); |
142 | } | 120 | } |
143 | 121 | ||
144 | static void exynos_setup_vbus_gpio(struct device *dev) | 122 | static void exynos_setup_vbus_gpio(struct device *dev) |
@@ -231,9 +209,6 @@ skip_phy: | |||
231 | goto fail_io; | 209 | goto fail_io; |
232 | } | 210 | } |
233 | 211 | ||
234 | if (exynos_ehci->otg) | ||
235 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | ||
236 | |||
237 | err = exynos_ehci_phy_enable(&pdev->dev); | 212 | err = exynos_ehci_phy_enable(&pdev->dev); |
238 | if (err) { | 213 | if (err) { |
239 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); | 214 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); |
@@ -273,9 +248,6 @@ static int exynos_ehci_remove(struct platform_device *pdev) | |||
273 | 248 | ||
274 | usb_remove_hcd(hcd); | 249 | usb_remove_hcd(hcd); |
275 | 250 | ||
276 | if (exynos_ehci->otg) | ||
277 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | ||
278 | |||
279 | exynos_ehci_phy_disable(&pdev->dev); | 251 | exynos_ehci_phy_disable(&pdev->dev); |
280 | 252 | ||
281 | clk_disable_unprepare(exynos_ehci->clk); | 253 | clk_disable_unprepare(exynos_ehci->clk); |
@@ -298,9 +270,6 @@ static int exynos_ehci_suspend(struct device *dev) | |||
298 | if (rc) | 270 | if (rc) |
299 | return rc; | 271 | return rc; |
300 | 272 | ||
301 | if (exynos_ehci->otg) | ||
302 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | ||
303 | |||
304 | exynos_ehci_phy_disable(dev); | 273 | exynos_ehci_phy_disable(dev); |
305 | 274 | ||
306 | clk_disable_unprepare(exynos_ehci->clk); | 275 | clk_disable_unprepare(exynos_ehci->clk); |
@@ -316,9 +285,6 @@ static int exynos_ehci_resume(struct device *dev) | |||
316 | 285 | ||
317 | clk_prepare_enable(exynos_ehci->clk); | 286 | clk_prepare_enable(exynos_ehci->clk); |
318 | 287 | ||
319 | if (exynos_ehci->otg) | ||
320 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | ||
321 | |||
322 | ret = exynos_ehci_phy_enable(dev); | 288 | ret = exynos_ehci_phy_enable(dev); |
323 | if (ret) { | 289 | if (ret) { |
324 | dev_err(dev, "Failed to enable USB phy\n"); | 290 | dev_err(dev, "Failed to enable USB phy\n"); |
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index cf2734b532a7..2d2ae8db439e 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
@@ -136,15 +136,15 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
136 | if (pdata->operating_mode == FSL_USB2_DR_OTG) { | 136 | if (pdata->operating_mode == FSL_USB2_DR_OTG) { |
137 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 137 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
138 | 138 | ||
139 | hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2); | 139 | hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); |
140 | dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n", | 140 | dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n", |
141 | hcd, ehci, hcd->phy); | 141 | hcd, ehci, hcd->usb_phy); |
142 | 142 | ||
143 | if (!IS_ERR_OR_NULL(hcd->phy)) { | 143 | if (!IS_ERR_OR_NULL(hcd->usb_phy)) { |
144 | retval = otg_set_host(hcd->phy->otg, | 144 | retval = otg_set_host(hcd->usb_phy->otg, |
145 | &ehci_to_hcd(ehci)->self); | 145 | &ehci_to_hcd(ehci)->self); |
146 | if (retval) { | 146 | if (retval) { |
147 | usb_put_phy(hcd->phy); | 147 | usb_put_phy(hcd->usb_phy); |
148 | goto err2; | 148 | goto err2; |
149 | } | 149 | } |
150 | } else { | 150 | } else { |
@@ -181,9 +181,9 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd, | |||
181 | { | 181 | { |
182 | struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev); | 182 | struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev); |
183 | 183 | ||
184 | if (!IS_ERR_OR_NULL(hcd->phy)) { | 184 | if (!IS_ERR_OR_NULL(hcd->usb_phy)) { |
185 | otg_set_host(hcd->phy->otg, NULL); | 185 | otg_set_host(hcd->usb_phy->otg, NULL); |
186 | usb_put_phy(hcd->phy); | 186 | usb_put_phy(hcd->usb_phy); |
187 | } | 187 | } |
188 | 188 | ||
189 | usb_remove_hcd(hcd); | 189 | usb_remove_hcd(hcd); |
@@ -627,7 +627,7 @@ static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port) | |||
627 | if (!(status & PORT_CONNECT)) | 627 | if (!(status & PORT_CONNECT)) |
628 | return -ENODEV; | 628 | return -ENODEV; |
629 | 629 | ||
630 | /* khubd will finish the reset later */ | 630 | /* hub_wq will finish the reset later */ |
631 | if (ehci_is_TDI(ehci)) { | 631 | if (ehci_is_TDI(ehci)) { |
632 | writel(PORT_RESET | | 632 | writel(PORT_RESET | |
633 | (status & ~(PORT_CSC | PORT_PEC | PORT_OCC)), | 633 | (status & ~(PORT_CSC | PORT_PEC | PORT_OCC)), |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 488a30836c36..15feaf924b71 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -788,7 +788,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) | |||
788 | continue; | 788 | continue; |
789 | 789 | ||
790 | /* start 20 msec resume signaling from this port, | 790 | /* start 20 msec resume signaling from this port, |
791 | * and make khubd collect PORT_STAT_C_SUSPEND to | 791 | * and make hub_wq collect PORT_STAT_C_SUSPEND to |
792 | * stop that signaling. Use 5 ms extra for safety, | 792 | * stop that signaling. Use 5 ms extra for safety, |
793 | * like usb_port_resume() does. | 793 | * like usb_port_resume() does. |
794 | */ | 794 | */ |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 6130b7574908..5728829cf6ef 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -656,7 +656,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf) | |||
656 | 656 | ||
657 | /* | 657 | /* |
658 | * Return status information even for ports with OWNER set. | 658 | * Return status information even for ports with OWNER set. |
659 | * Otherwise khubd wouldn't see the disconnect event when a | 659 | * Otherwise hub_wq wouldn't see the disconnect event when a |
660 | * high-speed device is switched over to the companion | 660 | * high-speed device is switched over to the companion |
661 | * controller by the user. | 661 | * controller by the user. |
662 | */ | 662 | */ |
@@ -902,7 +902,7 @@ int ehci_hub_control( | |||
902 | 902 | ||
903 | /* | 903 | /* |
904 | * Even if OWNER is set, so the port is owned by the | 904 | * Even if OWNER is set, so the port is owned by the |
905 | * companion controller, khubd needs to be able to clear | 905 | * companion controller, hub_wq needs to be able to clear |
906 | * the port-change status bits (especially | 906 | * the port-change status bits (especially |
907 | * USB_PORT_STAT_C_CONNECTION). | 907 | * USB_PORT_STAT_C_CONNECTION). |
908 | */ | 908 | */ |
@@ -922,7 +922,7 @@ int ehci_hub_control( | |||
922 | #ifdef CONFIG_USB_OTG | 922 | #ifdef CONFIG_USB_OTG |
923 | if ((hcd->self.otg_port == (wIndex + 1)) | 923 | if ((hcd->self.otg_port == (wIndex + 1)) |
924 | && hcd->self.b_hnp_enable) { | 924 | && hcd->self.b_hnp_enable) { |
925 | otg_start_hnp(hcd->phy->otg); | 925 | otg_start_hnp(hcd->usb_phy->otg); |
926 | break; | 926 | break; |
927 | } | 927 | } |
928 | #endif | 928 | #endif |
@@ -1000,7 +1000,7 @@ int ehci_hub_control( | |||
1000 | * However, not all EHCI implementations do this | 1000 | * However, not all EHCI implementations do this |
1001 | * automatically, even if they _do_ support per-port | 1001 | * automatically, even if they _do_ support per-port |
1002 | * power switching; they're allowed to just limit the | 1002 | * power switching; they're allowed to just limit the |
1003 | * current. khubd will turn the power back on. | 1003 | * current. hub_wq will turn the power back on. |
1004 | */ | 1004 | */ |
1005 | if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle)) | 1005 | if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle)) |
1006 | && HCS_PPC(ehci->hcs_params)) { | 1006 | && HCS_PPC(ehci->hcs_params)) { |
@@ -1085,7 +1085,7 @@ int ehci_hub_control( | |||
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | /* | 1087 | /* |
1088 | * Even if OWNER is set, there's no harm letting khubd | 1088 | * Even if OWNER is set, there's no harm letting hub_wq |
1089 | * see the wPortStatus values (they should all be 0 except | 1089 | * see the wPortStatus values (they should all be 0 except |
1090 | * for PORT_POWER anyway). | 1090 | * for PORT_POWER anyway). |
1091 | */ | 1091 | */ |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index 934b39d5e44a..9dc2118ae808 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -124,7 +124,7 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
124 | goto put_hcd; | 124 | goto put_hcd; |
125 | } | 125 | } |
126 | 126 | ||
127 | hcd->phy = phy; | 127 | hcd->usb_phy = phy; |
128 | device_init_wakeup(&pdev->dev, 1); | 128 | device_init_wakeup(&pdev->dev, 1); |
129 | /* | 129 | /* |
130 | * OTG device parent of HCD takes care of putting | 130 | * OTG device parent of HCD takes care of putting |
@@ -151,7 +151,7 @@ static int ehci_msm_remove(struct platform_device *pdev) | |||
151 | pm_runtime_disable(&pdev->dev); | 151 | pm_runtime_disable(&pdev->dev); |
152 | pm_runtime_set_suspended(&pdev->dev); | 152 | pm_runtime_set_suspended(&pdev->dev); |
153 | 153 | ||
154 | otg_set_host(hcd->phy->otg, NULL); | 154 | otg_set_host(hcd->usb_phy->otg, NULL); |
155 | 155 | ||
156 | /* FIXME: need to call usb_remove_hcd() here? */ | 156 | /* FIXME: need to call usb_remove_hcd() here? */ |
157 | 157 | ||
diff --git a/drivers/usb/host/ehci-st.c b/drivers/usb/host/ehci-st.c new file mode 100644 index 000000000000..7e4bd39cf757 --- /dev/null +++ b/drivers/usb/host/ehci-st.c | |||
@@ -0,0 +1,375 @@ | |||
1 | /* | ||
2 | * ST EHCI driver | ||
3 | * | ||
4 | * Copyright (C) 2014 STMicroelectronics – All Rights Reserved | ||
5 | * | ||
6 | * Author: Peter Griffin <peter.griffin@linaro.org> | ||
7 | * | ||
8 | * Derived from ehci-platform.c | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/clk.h> | ||
16 | #include <linux/dma-mapping.h> | ||
17 | #include <linux/err.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/hrtimer.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/of.h> | ||
23 | #include <linux/phy/phy.h> | ||
24 | #include <linux/platform_device.h> | ||
25 | #include <linux/reset.h> | ||
26 | #include <linux/usb.h> | ||
27 | #include <linux/usb/hcd.h> | ||
28 | #include <linux/usb/ehci_pdriver.h> | ||
29 | |||
30 | #include "ehci.h" | ||
31 | |||
32 | #define USB_MAX_CLKS 3 | ||
33 | |||
34 | struct st_ehci_platform_priv { | ||
35 | struct clk *clks[USB_MAX_CLKS]; | ||
36 | struct clk *clk48; | ||
37 | struct reset_control *rst; | ||
38 | struct reset_control *pwr; | ||
39 | struct phy *phy; | ||
40 | }; | ||
41 | |||
42 | #define DRIVER_DESC "EHCI STMicroelectronics driver" | ||
43 | |||
44 | #define hcd_to_ehci_priv(h) \ | ||
45 | ((struct st_ehci_platform_priv *)hcd_to_ehci(h)->priv) | ||
46 | |||
47 | static const char hcd_name[] = "ehci-st"; | ||
48 | |||
49 | #define EHCI_CAPS_SIZE 0x10 | ||
50 | #define AHB2STBUS_INSREG01 (EHCI_CAPS_SIZE + 0x84) | ||
51 | |||
52 | static int st_ehci_platform_reset(struct usb_hcd *hcd) | ||
53 | { | ||
54 | struct platform_device *pdev = to_platform_device(hcd->self.controller); | ||
55 | struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev); | ||
56 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
57 | int retval; | ||
58 | u32 threshold; | ||
59 | |||
60 | /* Set EHCI packet buffer IN/OUT threshold to 128 bytes */ | ||
61 | threshold = 128 | (128 << 16); | ||
62 | writel(threshold, hcd->regs + AHB2STBUS_INSREG01); | ||
63 | |||
64 | ehci->caps = hcd->regs + pdata->caps_offset; | ||
65 | retval = ehci_setup(hcd); | ||
66 | if (retval) | ||
67 | return retval; | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static int st_ehci_platform_power_on(struct platform_device *dev) | ||
73 | { | ||
74 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
75 | struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); | ||
76 | int clk, ret; | ||
77 | |||
78 | ret = reset_control_deassert(priv->pwr); | ||
79 | if (ret) | ||
80 | return ret; | ||
81 | |||
82 | ret = reset_control_deassert(priv->rst); | ||
83 | if (ret) | ||
84 | goto err_assert_power; | ||
85 | |||
86 | /* some SoCs don't have a dedicated 48Mhz clock, but those that do | ||
87 | need the rate to be explicitly set */ | ||
88 | if (priv->clk48) { | ||
89 | ret = clk_set_rate(priv->clk48, 48000000); | ||
90 | if (ret) | ||
91 | goto err_assert_reset; | ||
92 | } | ||
93 | |||
94 | for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) { | ||
95 | ret = clk_prepare_enable(priv->clks[clk]); | ||
96 | if (ret) | ||
97 | goto err_disable_clks; | ||
98 | } | ||
99 | |||
100 | ret = phy_init(priv->phy); | ||
101 | if (ret) | ||
102 | goto err_disable_clks; | ||
103 | |||
104 | ret = phy_power_on(priv->phy); | ||
105 | if (ret) | ||
106 | goto err_exit_phy; | ||
107 | |||
108 | return 0; | ||
109 | |||
110 | err_exit_phy: | ||
111 | phy_exit(priv->phy); | ||
112 | err_disable_clks: | ||
113 | while (--clk >= 0) | ||
114 | clk_disable_unprepare(priv->clks[clk]); | ||
115 | err_assert_reset: | ||
116 | reset_control_assert(priv->rst); | ||
117 | err_assert_power: | ||
118 | reset_control_assert(priv->pwr); | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static void st_ehci_platform_power_off(struct platform_device *dev) | ||
124 | { | ||
125 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
126 | struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); | ||
127 | int clk; | ||
128 | |||
129 | reset_control_assert(priv->pwr); | ||
130 | |||
131 | reset_control_assert(priv->rst); | ||
132 | |||
133 | phy_power_off(priv->phy); | ||
134 | |||
135 | phy_exit(priv->phy); | ||
136 | |||
137 | for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--) | ||
138 | if (priv->clks[clk]) | ||
139 | clk_disable_unprepare(priv->clks[clk]); | ||
140 | |||
141 | } | ||
142 | |||
143 | static struct hc_driver __read_mostly ehci_platform_hc_driver; | ||
144 | |||
145 | static const struct ehci_driver_overrides platform_overrides __initconst = { | ||
146 | .reset = st_ehci_platform_reset, | ||
147 | .extra_priv_size = sizeof(struct st_ehci_platform_priv), | ||
148 | }; | ||
149 | |||
150 | static struct usb_ehci_pdata ehci_platform_defaults = { | ||
151 | .power_on = st_ehci_platform_power_on, | ||
152 | .power_suspend = st_ehci_platform_power_off, | ||
153 | .power_off = st_ehci_platform_power_off, | ||
154 | }; | ||
155 | |||
156 | static int st_ehci_platform_probe(struct platform_device *dev) | ||
157 | { | ||
158 | struct usb_hcd *hcd; | ||
159 | struct resource *res_mem; | ||
160 | struct usb_ehci_pdata *pdata = &ehci_platform_defaults; | ||
161 | struct st_ehci_platform_priv *priv; | ||
162 | struct ehci_hcd *ehci; | ||
163 | int err, irq, clk = 0; | ||
164 | |||
165 | if (usb_disabled()) | ||
166 | return -ENODEV; | ||
167 | |||
168 | irq = platform_get_irq(dev, 0); | ||
169 | if (irq < 0) { | ||
170 | dev_err(&dev->dev, "no irq provided"); | ||
171 | return irq; | ||
172 | } | ||
173 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
174 | if (!res_mem) { | ||
175 | dev_err(&dev->dev, "no memory resource provided"); | ||
176 | return -ENXIO; | ||
177 | } | ||
178 | |||
179 | hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, | ||
180 | dev_name(&dev->dev)); | ||
181 | if (!hcd) | ||
182 | return -ENOMEM; | ||
183 | |||
184 | platform_set_drvdata(dev, hcd); | ||
185 | dev->dev.platform_data = pdata; | ||
186 | priv = hcd_to_ehci_priv(hcd); | ||
187 | ehci = hcd_to_ehci(hcd); | ||
188 | |||
189 | priv->phy = devm_phy_get(&dev->dev, "usb"); | ||
190 | if (IS_ERR(priv->phy)) { | ||
191 | err = PTR_ERR(priv->phy); | ||
192 | goto err_put_hcd; | ||
193 | } | ||
194 | |||
195 | for (clk = 0; clk < USB_MAX_CLKS; clk++) { | ||
196 | priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); | ||
197 | if (IS_ERR(priv->clks[clk])) { | ||
198 | err = PTR_ERR(priv->clks[clk]); | ||
199 | if (err == -EPROBE_DEFER) | ||
200 | goto err_put_clks; | ||
201 | priv->clks[clk] = NULL; | ||
202 | break; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | /* some SoCs don't have a dedicated 48Mhz clock, but those that | ||
207 | do need the rate to be explicitly set */ | ||
208 | priv->clk48 = devm_clk_get(&dev->dev, "clk48"); | ||
209 | if (IS_ERR(priv->clk48)) { | ||
210 | dev_info(&dev->dev, "48MHz clk not found\n"); | ||
211 | priv->clk48 = NULL; | ||
212 | } | ||
213 | |||
214 | priv->pwr = devm_reset_control_get_optional(&dev->dev, "power"); | ||
215 | if (IS_ERR(priv->pwr)) { | ||
216 | err = PTR_ERR(priv->pwr); | ||
217 | if (err == -EPROBE_DEFER) | ||
218 | goto err_put_clks; | ||
219 | priv->pwr = NULL; | ||
220 | } | ||
221 | |||
222 | priv->rst = devm_reset_control_get_optional(&dev->dev, "softreset"); | ||
223 | if (IS_ERR(priv->rst)) { | ||
224 | err = PTR_ERR(priv->rst); | ||
225 | if (err == -EPROBE_DEFER) | ||
226 | goto err_put_clks; | ||
227 | priv->rst = NULL; | ||
228 | } | ||
229 | |||
230 | if (pdata->power_on) { | ||
231 | err = pdata->power_on(dev); | ||
232 | if (err < 0) | ||
233 | goto err_put_clks; | ||
234 | } | ||
235 | |||
236 | hcd->rsrc_start = res_mem->start; | ||
237 | hcd->rsrc_len = resource_size(res_mem); | ||
238 | |||
239 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); | ||
240 | if (IS_ERR(hcd->regs)) { | ||
241 | err = PTR_ERR(hcd->regs); | ||
242 | goto err_put_clks; | ||
243 | } | ||
244 | |||
245 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
246 | if (err) | ||
247 | goto err_put_clks; | ||
248 | |||
249 | device_wakeup_enable(hcd->self.controller); | ||
250 | platform_set_drvdata(dev, hcd); | ||
251 | |||
252 | return err; | ||
253 | |||
254 | err_put_clks: | ||
255 | while (--clk >= 0) | ||
256 | clk_put(priv->clks[clk]); | ||
257 | err_put_hcd: | ||
258 | if (pdata == &ehci_platform_defaults) | ||
259 | dev->dev.platform_data = NULL; | ||
260 | |||
261 | usb_put_hcd(hcd); | ||
262 | |||
263 | return err; | ||
264 | } | ||
265 | |||
266 | static int st_ehci_platform_remove(struct platform_device *dev) | ||
267 | { | ||
268 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
269 | struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); | ||
270 | struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); | ||
271 | int clk; | ||
272 | |||
273 | usb_remove_hcd(hcd); | ||
274 | |||
275 | if (pdata->power_off) | ||
276 | pdata->power_off(dev); | ||
277 | |||
278 | for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) | ||
279 | clk_put(priv->clks[clk]); | ||
280 | |||
281 | usb_put_hcd(hcd); | ||
282 | |||
283 | if (pdata == &ehci_platform_defaults) | ||
284 | dev->dev.platform_data = NULL; | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | #ifdef CONFIG_PM_SLEEP | ||
290 | |||
291 | static int st_ehci_suspend(struct device *dev) | ||
292 | { | ||
293 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
294 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); | ||
295 | struct platform_device *pdev = | ||
296 | container_of(dev, struct platform_device, dev); | ||
297 | bool do_wakeup = device_may_wakeup(dev); | ||
298 | int ret; | ||
299 | |||
300 | ret = ehci_suspend(hcd, do_wakeup); | ||
301 | if (ret) | ||
302 | return ret; | ||
303 | |||
304 | if (pdata->power_suspend) | ||
305 | pdata->power_suspend(pdev); | ||
306 | |||
307 | pinctrl_pm_select_sleep_state(dev); | ||
308 | |||
309 | return ret; | ||
310 | } | ||
311 | |||
312 | static int st_ehci_resume(struct device *dev) | ||
313 | { | ||
314 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
315 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); | ||
316 | struct platform_device *pdev = | ||
317 | container_of(dev, struct platform_device, dev); | ||
318 | int err; | ||
319 | |||
320 | pinctrl_pm_select_default_state(dev); | ||
321 | |||
322 | if (pdata->power_on) { | ||
323 | err = pdata->power_on(pdev); | ||
324 | if (err < 0) | ||
325 | return err; | ||
326 | } | ||
327 | |||
328 | ehci_resume(hcd, false); | ||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | static SIMPLE_DEV_PM_OPS(st_ehci_pm_ops, st_ehci_suspend, st_ehci_resume); | ||
333 | |||
334 | #endif /* CONFIG_PM_SLEEP */ | ||
335 | |||
336 | static const struct of_device_id st_ehci_ids[] = { | ||
337 | { .compatible = "st,st-ehci-300x", }, | ||
338 | { /* sentinel */ } | ||
339 | }; | ||
340 | MODULE_DEVICE_TABLE(of, st_ehci_ids); | ||
341 | |||
342 | static struct platform_driver ehci_platform_driver = { | ||
343 | .probe = st_ehci_platform_probe, | ||
344 | .remove = st_ehci_platform_remove, | ||
345 | .shutdown = usb_hcd_platform_shutdown, | ||
346 | .driver = { | ||
347 | .name = "st-ehci", | ||
348 | #ifdef CONFIG_PM_SLEEP | ||
349 | .pm = &st_ehci_pm_ops, | ||
350 | #endif | ||
351 | .of_match_table = st_ehci_ids, | ||
352 | } | ||
353 | }; | ||
354 | |||
355 | static int __init ehci_platform_init(void) | ||
356 | { | ||
357 | if (usb_disabled()) | ||
358 | return -ENODEV; | ||
359 | |||
360 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
361 | |||
362 | ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); | ||
363 | return platform_driver_register(&ehci_platform_driver); | ||
364 | } | ||
365 | module_init(ehci_platform_init); | ||
366 | |||
367 | static void __exit ehci_platform_cleanup(void) | ||
368 | { | ||
369 | platform_driver_unregister(&ehci_platform_driver); | ||
370 | } | ||
371 | module_exit(ehci_platform_cleanup); | ||
372 | |||
373 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
374 | MODULE_AUTHOR("Peter Griffin <peter.griffin@linaro.org>"); | ||
375 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 7aafb05e7a40..aaa01971efe9 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -206,7 +206,7 @@ static int tegra_ehci_hub_control( | |||
206 | if (tegra->port_resuming && !(temp & PORT_SUSPEND)) { | 206 | if (tegra->port_resuming && !(temp & PORT_SUSPEND)) { |
207 | /* Resume completed, re-enable disconnect detection */ | 207 | /* Resume completed, re-enable disconnect detection */ |
208 | tegra->port_resuming = 0; | 208 | tegra->port_resuming = 0; |
209 | tegra_usb_phy_postresume(hcd->phy); | 209 | tegra_usb_phy_postresume(hcd->usb_phy); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
@@ -259,7 +259,7 @@ static int tegra_ehci_hub_control( | |||
259 | goto done; | 259 | goto done; |
260 | 260 | ||
261 | /* Disable disconnect detection during port resume */ | 261 | /* Disable disconnect detection during port resume */ |
262 | tegra_usb_phy_preresume(hcd->phy); | 262 | tegra_usb_phy_preresume(hcd->usb_phy); |
263 | 263 | ||
264 | ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25); | 264 | ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25); |
265 | 265 | ||
@@ -454,7 +454,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
454 | err = PTR_ERR(u_phy); | 454 | err = PTR_ERR(u_phy); |
455 | goto cleanup_clk_en; | 455 | goto cleanup_clk_en; |
456 | } | 456 | } |
457 | hcd->phy = u_phy; | 457 | hcd->usb_phy = u_phy; |
458 | 458 | ||
459 | tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, | 459 | tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, |
460 | "nvidia,needs-double-reset"); | 460 | "nvidia,needs-double-reset"); |
@@ -475,7 +475,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
475 | ehci->caps = hcd->regs + 0x100; | 475 | ehci->caps = hcd->regs + 0x100; |
476 | ehci->has_hostpc = soc_config->has_hostpc; | 476 | ehci->has_hostpc = soc_config->has_hostpc; |
477 | 477 | ||
478 | err = usb_phy_init(hcd->phy); | 478 | err = usb_phy_init(hcd->usb_phy); |
479 | if (err) { | 479 | if (err) { |
480 | dev_err(&pdev->dev, "Failed to initialize phy\n"); | 480 | dev_err(&pdev->dev, "Failed to initialize phy\n"); |
481 | goto cleanup_clk_en; | 481 | goto cleanup_clk_en; |
@@ -490,7 +490,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
490 | } | 490 | } |
491 | u_phy->otg->host = hcd_to_bus(hcd); | 491 | u_phy->otg->host = hcd_to_bus(hcd); |
492 | 492 | ||
493 | err = usb_phy_set_suspend(hcd->phy, 0); | 493 | err = usb_phy_set_suspend(hcd->usb_phy, 0); |
494 | if (err) { | 494 | if (err) { |
495 | dev_err(&pdev->dev, "Failed to power on the phy\n"); | 495 | dev_err(&pdev->dev, "Failed to power on the phy\n"); |
496 | goto cleanup_phy; | 496 | goto cleanup_phy; |
@@ -517,7 +517,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
517 | cleanup_otg_set_host: | 517 | cleanup_otg_set_host: |
518 | otg_set_host(u_phy->otg, NULL); | 518 | otg_set_host(u_phy->otg, NULL); |
519 | cleanup_phy: | 519 | cleanup_phy: |
520 | usb_phy_shutdown(hcd->phy); | 520 | usb_phy_shutdown(hcd->usb_phy); |
521 | cleanup_clk_en: | 521 | cleanup_clk_en: |
522 | clk_disable_unprepare(tegra->clk); | 522 | clk_disable_unprepare(tegra->clk); |
523 | cleanup_hcd_create: | 523 | cleanup_hcd_create: |
@@ -531,9 +531,9 @@ static int tegra_ehci_remove(struct platform_device *pdev) | |||
531 | struct tegra_ehci_hcd *tegra = | 531 | struct tegra_ehci_hcd *tegra = |
532 | (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; | 532 | (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; |
533 | 533 | ||
534 | otg_set_host(hcd->phy->otg, NULL); | 534 | otg_set_host(hcd->usb_phy->otg, NULL); |
535 | 535 | ||
536 | usb_phy_shutdown(hcd->phy); | 536 | usb_phy_shutdown(hcd->usb_phy); |
537 | usb_remove_hcd(hcd); | 537 | usb_remove_hcd(hcd); |
538 | 538 | ||
539 | clk_disable_unprepare(tegra->clk); | 539 | clk_disable_unprepare(tegra->clk); |
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c index fe57710753e8..a2328361dc80 100644 --- a/drivers/usb/host/ehci-xilinx-of.c +++ b/drivers/usb/host/ehci-xilinx-of.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/of.h> | 31 | #include <linux/of.h> |
32 | #include <linux/of_platform.h> | 32 | #include <linux/of_platform.h> |
33 | #include <linux/of_address.h> | 33 | #include <linux/of_address.h> |
34 | #include <linux/of_irq.h> | ||
34 | 35 | ||
35 | /** | 36 | /** |
36 | * ehci_xilinx_port_handed_over - hand the port out if failed to enable it | 37 | * ehci_xilinx_port_handed_over - hand the port out if failed to enable it |
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c index 1cf68eaf2ed8..a1a1ef521436 100644 --- a/drivers/usb/host/fhci-hcd.c +++ b/drivers/usb/host/fhci-hcd.c | |||
@@ -360,12 +360,12 @@ static int fhci_start(struct usb_hcd *hcd) | |||
360 | hcd->state = HC_STATE_RUNNING; | 360 | hcd->state = HC_STATE_RUNNING; |
361 | 361 | ||
362 | /* | 362 | /* |
363 | * From here on, khubd concurrently accesses the root | 363 | * From here on, hub_wq concurrently accesses the root |
364 | * hub; drivers will be talking to enumerated devices. | 364 | * hub; drivers will be talking to enumerated devices. |
365 | * (On restart paths, khubd already knows about the root | 365 | * (On restart paths, hub_wq already knows about the root |
366 | * hub and could find work as soon as we wrote FLAG_CF.) | 366 | * hub and could find work as soon as we wrote FLAG_CF.) |
367 | * | 367 | * |
368 | * Before this point the HC was idle/ready. After, khubd | 368 | * Before this point the HC was idle/ready. After, hub_wq |
369 | * and device drivers may start it running. | 369 | * and device drivers may start it running. |
370 | */ | 370 | */ |
371 | fhci_usb_enable(fhci); | 371 | fhci_usb_enable(fhci); |
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index adcd2050dced..3de1278677d0 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c | |||
@@ -1483,7 +1483,7 @@ fotg210_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
1483 | 1483 | ||
1484 | /* | 1484 | /* |
1485 | * Return status information even for ports with OWNER set. | 1485 | * Return status information even for ports with OWNER set. |
1486 | * Otherwise khubd wouldn't see the disconnect event when a | 1486 | * Otherwise hub_wq wouldn't see the disconnect event when a |
1487 | * high-speed device is switched over to the companion | 1487 | * high-speed device is switched over to the companion |
1488 | * controller by the user. | 1488 | * controller by the user. |
1489 | */ | 1489 | */ |
@@ -1572,7 +1572,7 @@ static int fotg210_hub_control( | |||
1572 | 1572 | ||
1573 | /* | 1573 | /* |
1574 | * Even if OWNER is set, so the port is owned by the | 1574 | * Even if OWNER is set, so the port is owned by the |
1575 | * companion controller, khubd needs to be able to clear | 1575 | * companion controller, hub_wq needs to be able to clear |
1576 | * the port-change status bits (especially | 1576 | * the port-change status bits (especially |
1577 | * USB_PORT_STAT_C_CONNECTION). | 1577 | * USB_PORT_STAT_C_CONNECTION). |
1578 | */ | 1578 | */ |
@@ -1723,7 +1723,7 @@ static int fotg210_hub_control( | |||
1723 | } | 1723 | } |
1724 | 1724 | ||
1725 | /* | 1725 | /* |
1726 | * Even if OWNER is set, there's no harm letting khubd | 1726 | * Even if OWNER is set, there's no harm letting hub_wq |
1727 | * see the wPortStatus values (they should all be 0 except | 1727 | * see the wPortStatus values (they should all be 0 except |
1728 | * for PORT_POWER anyway). | 1728 | * for PORT_POWER anyway). |
1729 | */ | 1729 | */ |
@@ -5445,7 +5445,7 @@ static irqreturn_t fotg210_irq(struct usb_hcd *hcd) | |||
5445 | fotg210->reset_done[0] == 0) { | 5445 | fotg210->reset_done[0] == 0) { |
5446 | 5446 | ||
5447 | /* start 20 msec resume signaling from this port, | 5447 | /* start 20 msec resume signaling from this port, |
5448 | * and make khubd collect PORT_STAT_C_SUSPEND to | 5448 | * and make hub_wq collect PORT_STAT_C_SUSPEND to |
5449 | * stop that signaling. Use 5 ms extra for safety, | 5449 | * stop that signaling. Use 5 ms extra for safety, |
5450 | * like usb_port_resume() does. | 5450 | * like usb_port_resume() does. |
5451 | */ | 5451 | */ |
diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c index ba9499060f63..abe42f31559f 100644 --- a/drivers/usb/host/fusbh200-hcd.c +++ b/drivers/usb/host/fusbh200-hcd.c | |||
@@ -1441,7 +1441,7 @@ fusbh200_hub_status_data (struct usb_hcd *hcd, char *buf) | |||
1441 | 1441 | ||
1442 | /* | 1442 | /* |
1443 | * Return status information even for ports with OWNER set. | 1443 | * Return status information even for ports with OWNER set. |
1444 | * Otherwise khubd wouldn't see the disconnect event when a | 1444 | * Otherwise hub_wq wouldn't see the disconnect event when a |
1445 | * high-speed device is switched over to the companion | 1445 | * high-speed device is switched over to the companion |
1446 | * controller by the user. | 1446 | * controller by the user. |
1447 | */ | 1447 | */ |
@@ -1530,7 +1530,7 @@ static int fusbh200_hub_control ( | |||
1530 | 1530 | ||
1531 | /* | 1531 | /* |
1532 | * Even if OWNER is set, so the port is owned by the | 1532 | * Even if OWNER is set, so the port is owned by the |
1533 | * companion controller, khubd needs to be able to clear | 1533 | * companion controller, hub_wq needs to be able to clear |
1534 | * the port-change status bits (especially | 1534 | * the port-change status bits (especially |
1535 | * USB_PORT_STAT_C_CONNECTION). | 1535 | * USB_PORT_STAT_C_CONNECTION). |
1536 | */ | 1536 | */ |
@@ -1678,7 +1678,7 @@ static int fusbh200_hub_control ( | |||
1678 | } | 1678 | } |
1679 | 1679 | ||
1680 | /* | 1680 | /* |
1681 | * Even if OWNER is set, there's no harm letting khubd | 1681 | * Even if OWNER is set, there's no harm letting hub_wq |
1682 | * see the wPortStatus values (they should all be 0 except | 1682 | * see the wPortStatus values (they should all be 0 except |
1683 | * for PORT_POWER anyway). | 1683 | * for PORT_POWER anyway). |
1684 | */ | 1684 | */ |
@@ -5355,7 +5355,7 @@ static irqreturn_t fusbh200_irq (struct usb_hcd *hcd) | |||
5355 | fusbh200->reset_done[0] == 0) { | 5355 | fusbh200->reset_done[0] == 0) { |
5356 | 5356 | ||
5357 | /* start 20 msec resume signaling from this port, | 5357 | /* start 20 msec resume signaling from this port, |
5358 | * and make khubd collect PORT_STAT_C_SUSPEND to | 5358 | * and make hub_wq collect PORT_STAT_C_SUSPEND to |
5359 | * stop that signaling. Use 5 ms extra for safety, | 5359 | * stop that signaling. Use 5 ms extra for safety, |
5360 | * like usb_port_resume() does. | 5360 | * like usb_port_resume() does. |
5361 | */ | 5361 | */ |
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index 875bcfd3ec1a..4bb37982855e 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c | |||
@@ -2616,30 +2616,10 @@ static int isp1362_remove(struct platform_device *pdev) | |||
2616 | { | 2616 | { |
2617 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 2617 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
2618 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); | 2618 | struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd); |
2619 | struct resource *res; | ||
2620 | 2619 | ||
2621 | remove_debug_file(isp1362_hcd); | 2620 | remove_debug_file(isp1362_hcd); |
2622 | DBG(0, "%s: Removing HCD\n", __func__); | 2621 | DBG(0, "%s: Removing HCD\n", __func__); |
2623 | usb_remove_hcd(hcd); | 2622 | usb_remove_hcd(hcd); |
2624 | |||
2625 | DBG(0, "%s: Unmapping data_reg @ %p\n", __func__, | ||
2626 | isp1362_hcd->data_reg); | ||
2627 | iounmap(isp1362_hcd->data_reg); | ||
2628 | |||
2629 | DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__, | ||
2630 | isp1362_hcd->addr_reg); | ||
2631 | iounmap(isp1362_hcd->addr_reg); | ||
2632 | |||
2633 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
2634 | DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); | ||
2635 | if (res) | ||
2636 | release_mem_region(res->start, resource_size(res)); | ||
2637 | |||
2638 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2639 | DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start); | ||
2640 | if (res) | ||
2641 | release_mem_region(res->start, resource_size(res)); | ||
2642 | |||
2643 | DBG(0, "%s: put_hcd\n", __func__); | 2623 | DBG(0, "%s: put_hcd\n", __func__); |
2644 | usb_put_hcd(hcd); | 2624 | usb_put_hcd(hcd); |
2645 | DBG(0, "%s: Done\n", __func__); | 2625 | DBG(0, "%s: Done\n", __func__); |
@@ -2651,12 +2631,11 @@ static int isp1362_probe(struct platform_device *pdev) | |||
2651 | { | 2631 | { |
2652 | struct usb_hcd *hcd; | 2632 | struct usb_hcd *hcd; |
2653 | struct isp1362_hcd *isp1362_hcd; | 2633 | struct isp1362_hcd *isp1362_hcd; |
2654 | struct resource *addr, *data; | 2634 | struct resource *addr, *data, *irq_res; |
2655 | void __iomem *addr_reg; | 2635 | void __iomem *addr_reg; |
2656 | void __iomem *data_reg; | 2636 | void __iomem *data_reg; |
2657 | int irq; | 2637 | int irq; |
2658 | int retval = 0; | 2638 | int retval = 0; |
2659 | struct resource *irq_res; | ||
2660 | unsigned int irq_flags = 0; | 2639 | unsigned int irq_flags = 0; |
2661 | 2640 | ||
2662 | if (usb_disabled()) | 2641 | if (usb_disabled()) |
@@ -2667,52 +2646,35 @@ static int isp1362_probe(struct platform_device *pdev) | |||
2667 | * specific platform_data. we don't probe for IRQs, and do only | 2646 | * specific platform_data. we don't probe for IRQs, and do only |
2668 | * minimal sanity checking. | 2647 | * minimal sanity checking. |
2669 | */ | 2648 | */ |
2670 | if (pdev->num_resources < 3) { | 2649 | if (pdev->num_resources < 3) |
2671 | retval = -ENODEV; | 2650 | return -ENODEV; |
2672 | goto err1; | ||
2673 | } | ||
2674 | |||
2675 | data = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
2676 | addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
2677 | irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
2678 | if (!addr || !data || !irq_res) { | ||
2679 | retval = -ENODEV; | ||
2680 | goto err1; | ||
2681 | } | ||
2682 | irq = irq_res->start; | ||
2683 | 2651 | ||
2684 | if (pdev->dev.dma_mask) { | 2652 | if (pdev->dev.dma_mask) { |
2685 | DBG(1, "won't do DMA"); | 2653 | DBG(1, "won't do DMA"); |
2686 | retval = -ENODEV; | 2654 | return -ENODEV; |
2687 | goto err1; | ||
2688 | } | 2655 | } |
2689 | 2656 | ||
2690 | if (!request_mem_region(addr->start, resource_size(addr), hcd_name)) { | 2657 | irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
2691 | retval = -EBUSY; | 2658 | if (!irq_res) |
2692 | goto err1; | 2659 | return -ENODEV; |
2693 | } | ||
2694 | addr_reg = ioremap(addr->start, resource_size(addr)); | ||
2695 | if (addr_reg == NULL) { | ||
2696 | retval = -ENOMEM; | ||
2697 | goto err2; | ||
2698 | } | ||
2699 | 2660 | ||
2700 | if (!request_mem_region(data->start, resource_size(data), hcd_name)) { | 2661 | irq = irq_res->start; |
2701 | retval = -EBUSY; | 2662 | |
2702 | goto err3; | 2663 | addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
2703 | } | 2664 | addr_reg = devm_ioremap_resource(&pdev->dev, addr); |
2704 | data_reg = ioremap(data->start, resource_size(data)); | 2665 | if (IS_ERR(addr_reg)) |
2705 | if (data_reg == NULL) { | 2666 | return PTR_ERR(addr_reg); |
2706 | retval = -ENOMEM; | 2667 | |
2707 | goto err4; | 2668 | data = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2708 | } | 2669 | data_reg = devm_ioremap_resource(&pdev->dev, data); |
2670 | if (IS_ERR(data_reg)) | ||
2671 | return PTR_ERR(data_reg); | ||
2709 | 2672 | ||
2710 | /* allocate and initialize hcd */ | 2673 | /* allocate and initialize hcd */ |
2711 | hcd = usb_create_hcd(&isp1362_hc_driver, &pdev->dev, dev_name(&pdev->dev)); | 2674 | hcd = usb_create_hcd(&isp1362_hc_driver, &pdev->dev, dev_name(&pdev->dev)); |
2712 | if (!hcd) { | 2675 | if (!hcd) |
2713 | retval = -ENOMEM; | 2676 | return -ENOMEM; |
2714 | goto err5; | 2677 | |
2715 | } | ||
2716 | hcd->rsrc_start = data->start; | 2678 | hcd->rsrc_start = data->start; |
2717 | isp1362_hcd = hcd_to_isp1362_hcd(hcd); | 2679 | isp1362_hcd = hcd_to_isp1362_hcd(hcd); |
2718 | isp1362_hcd->data_reg = data_reg; | 2680 | isp1362_hcd->data_reg = data_reg; |
@@ -2729,7 +2691,7 @@ static int isp1362_probe(struct platform_device *pdev) | |||
2729 | if (!isp1362_hcd->board->delay) { | 2691 | if (!isp1362_hcd->board->delay) { |
2730 | dev_err(hcd->self.controller, "No platform delay function given\n"); | 2692 | dev_err(hcd->self.controller, "No platform delay function given\n"); |
2731 | retval = -ENODEV; | 2693 | retval = -ENODEV; |
2732 | goto err6; | 2694 | goto err; |
2733 | } | 2695 | } |
2734 | #endif | 2696 | #endif |
2735 | 2697 | ||
@@ -2744,32 +2706,17 @@ static int isp1362_probe(struct platform_device *pdev) | |||
2744 | 2706 | ||
2745 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_SHARED); | 2707 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_SHARED); |
2746 | if (retval != 0) | 2708 | if (retval != 0) |
2747 | goto err6; | 2709 | goto err; |
2748 | device_wakeup_enable(hcd->self.controller); | 2710 | device_wakeup_enable(hcd->self.controller); |
2749 | 2711 | ||
2750 | pr_info("%s, irq %d\n", hcd->product_desc, irq); | 2712 | dev_info(&pdev->dev, "%s, irq %d\n", hcd->product_desc, irq); |
2751 | 2713 | ||
2752 | create_debug_file(isp1362_hcd); | 2714 | create_debug_file(isp1362_hcd); |
2753 | 2715 | ||
2754 | return 0; | 2716 | return 0; |
2755 | 2717 | ||
2756 | err6: | 2718 | err: |
2757 | DBG(0, "%s: Freeing dev %p\n", __func__, isp1362_hcd); | ||
2758 | usb_put_hcd(hcd); | 2719 | usb_put_hcd(hcd); |
2759 | err5: | ||
2760 | DBG(0, "%s: Unmapping data_reg @ %p\n", __func__, data_reg); | ||
2761 | iounmap(data_reg); | ||
2762 | err4: | ||
2763 | DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start); | ||
2764 | release_mem_region(data->start, resource_size(data)); | ||
2765 | err3: | ||
2766 | DBG(0, "%s: Unmapping addr_reg @ %p\n", __func__, addr_reg); | ||
2767 | iounmap(addr_reg); | ||
2768 | err2: | ||
2769 | DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start); | ||
2770 | release_mem_region(addr->start, resource_size(addr)); | ||
2771 | err1: | ||
2772 | pr_err("%s: init error, %d\n", __func__, retval); | ||
2773 | 2720 | ||
2774 | return retval; | 2721 | return retval; |
2775 | } | 2722 | } |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index 51a0ae9cdd1d..e752c3098f38 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -1760,7 +1760,7 @@ static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
1760 | 1760 | ||
1761 | /* | 1761 | /* |
1762 | * Return status information even for ports with OWNER set. | 1762 | * Return status information even for ports with OWNER set. |
1763 | * Otherwise khubd wouldn't see the disconnect event when a | 1763 | * Otherwise hub_wq wouldn't see the disconnect event when a |
1764 | * high-speed device is switched over to the companion | 1764 | * high-speed device is switched over to the companion |
1765 | * controller by the user. | 1765 | * controller by the user. |
1766 | */ | 1766 | */ |
@@ -1871,7 +1871,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1871 | 1871 | ||
1872 | /* | 1872 | /* |
1873 | * Even if OWNER is set, so the port is owned by the | 1873 | * Even if OWNER is set, so the port is owned by the |
1874 | * companion controller, khubd needs to be able to clear | 1874 | * companion controller, hub_wq needs to be able to clear |
1875 | * the port-change status bits (especially | 1875 | * the port-change status bits (especially |
1876 | * USB_PORT_STAT_C_CONNECTION). | 1876 | * USB_PORT_STAT_C_CONNECTION). |
1877 | */ | 1877 | */ |
@@ -2000,7 +2000,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2000 | reg_read32(hcd->regs, HC_PORTSC1)); | 2000 | reg_read32(hcd->regs, HC_PORTSC1)); |
2001 | } | 2001 | } |
2002 | /* | 2002 | /* |
2003 | * Even if OWNER is set, there's no harm letting khubd | 2003 | * Even if OWNER is set, there's no harm letting hub_wq |
2004 | * see the wPortStatus values (they should all be 0 except | 2004 | * see the wPortStatus values (they should all be 0 except |
2005 | * for PORT_POWER anyway). | 2005 | * for PORT_POWER anyway). |
2006 | */ | 2006 | */ |
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index a72ab8fe8cd3..d28b6583ba02 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c | |||
@@ -19,11 +19,8 @@ | |||
19 | #include <linux/of.h> | 19 | #include <linux/of.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/phy/phy.h> | 21 | #include <linux/phy/phy.h> |
22 | #include <linux/usb/phy.h> | ||
23 | #include <linux/usb/samsung_usb_phy.h> | ||
24 | #include <linux/usb.h> | 22 | #include <linux/usb.h> |
25 | #include <linux/usb/hcd.h> | 23 | #include <linux/usb/hcd.h> |
26 | #include <linux/usb/otg.h> | ||
27 | 24 | ||
28 | #include "ohci.h" | 25 | #include "ohci.h" |
29 | 26 | ||
@@ -38,9 +35,7 @@ static struct hc_driver __read_mostly exynos_ohci_hc_driver; | |||
38 | 35 | ||
39 | struct exynos_ohci_hcd { | 36 | struct exynos_ohci_hcd { |
40 | struct clk *clk; | 37 | struct clk *clk; |
41 | struct usb_phy *phy; | 38 | struct phy *phy[PHY_NUMBER]; |
42 | struct usb_otg *otg; | ||
43 | struct phy *phy_g[PHY_NUMBER]; | ||
44 | }; | 39 | }; |
45 | 40 | ||
46 | static int exynos_ohci_get_phy(struct device *dev, | 41 | static int exynos_ohci_get_phy(struct device *dev, |
@@ -49,30 +44,9 @@ static int exynos_ohci_get_phy(struct device *dev, | |||
49 | struct device_node *child; | 44 | struct device_node *child; |
50 | struct phy *phy; | 45 | struct phy *phy; |
51 | int phy_number; | 46 | int phy_number; |
52 | int ret = 0; | 47 | int ret; |
53 | |||
54 | exynos_ohci->phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | ||
55 | if (IS_ERR(exynos_ohci->phy)) { | ||
56 | ret = PTR_ERR(exynos_ohci->phy); | ||
57 | if (ret != -ENXIO && ret != -ENODEV) { | ||
58 | dev_err(dev, "no usb2 phy configured\n"); | ||
59 | return ret; | ||
60 | } | ||
61 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
62 | } else { | ||
63 | exynos_ohci->otg = exynos_ohci->phy->otg; | ||
64 | } | ||
65 | 48 | ||
66 | /* | 49 | /* Get PHYs for the controller */ |
67 | * Getting generic phy: | ||
68 | * We are keeping both types of phys as a part of transiting OHCI | ||
69 | * to generic phy framework, so as to maintain backward compatibilty | ||
70 | * with old DTB. | ||
71 | * If there are existing devices using DTB files built from them, | ||
72 | * to remove the support for old bindings in this driver, | ||
73 | * we need to make sure that such devices have their DTBs | ||
74 | * updated to ones built from new DTS. | ||
75 | */ | ||
76 | for_each_available_child_of_node(dev->of_node, child) { | 50 | for_each_available_child_of_node(dev->of_node, child) { |
77 | ret = of_property_read_u32(child, "reg", &phy_number); | 51 | ret = of_property_read_u32(child, "reg", &phy_number); |
78 | if (ret) { | 52 | if (ret) { |
@@ -88,19 +62,21 @@ static int exynos_ohci_get_phy(struct device *dev, | |||
88 | } | 62 | } |
89 | 63 | ||
90 | phy = devm_of_phy_get(dev, child, NULL); | 64 | phy = devm_of_phy_get(dev, child, NULL); |
65 | exynos_ohci->phy[phy_number] = phy; | ||
91 | of_node_put(child); | 66 | of_node_put(child); |
92 | if (IS_ERR(phy)) { | 67 | if (IS_ERR(phy)) { |
93 | ret = PTR_ERR(phy); | 68 | ret = PTR_ERR(phy); |
94 | if (ret != -ENOSYS && ret != -ENODEV) { | 69 | if (ret == -EPROBE_DEFER) { |
95 | dev_err(dev, "no usb2 phy configured\n"); | 70 | return ret; |
71 | } else if (ret != -ENOSYS && ret != -ENODEV) { | ||
72 | dev_err(dev, | ||
73 | "Error retrieving usb2 phy: %d\n", ret); | ||
96 | return ret; | 74 | return ret; |
97 | } | 75 | } |
98 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
99 | } | 76 | } |
100 | exynos_ohci->phy_g[phy_number] = phy; | ||
101 | } | 77 | } |
102 | 78 | ||
103 | return ret; | 79 | return 0; |
104 | } | 80 | } |
105 | 81 | ||
106 | static int exynos_ohci_phy_enable(struct device *dev) | 82 | static int exynos_ohci_phy_enable(struct device *dev) |
@@ -110,16 +86,13 @@ static int exynos_ohci_phy_enable(struct device *dev) | |||
110 | int i; | 86 | int i; |
111 | int ret = 0; | 87 | int ret = 0; |
112 | 88 | ||
113 | if (!IS_ERR(exynos_ohci->phy)) | ||
114 | return usb_phy_init(exynos_ohci->phy); | ||
115 | |||
116 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) | 89 | for (i = 0; ret == 0 && i < PHY_NUMBER; i++) |
117 | if (!IS_ERR(exynos_ohci->phy_g[i])) | 90 | if (!IS_ERR(exynos_ohci->phy[i])) |
118 | ret = phy_power_on(exynos_ohci->phy_g[i]); | 91 | ret = phy_power_on(exynos_ohci->phy[i]); |
119 | if (ret) | 92 | if (ret) |
120 | for (i--; i >= 0; i--) | 93 | for (i--; i >= 0; i--) |
121 | if (!IS_ERR(exynos_ohci->phy_g[i])) | 94 | if (!IS_ERR(exynos_ohci->phy[i])) |
122 | phy_power_off(exynos_ohci->phy_g[i]); | 95 | phy_power_off(exynos_ohci->phy[i]); |
123 | 96 | ||
124 | return ret; | 97 | return ret; |
125 | } | 98 | } |
@@ -130,14 +103,9 @@ static void exynos_ohci_phy_disable(struct device *dev) | |||
130 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 103 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
131 | int i; | 104 | int i; |
132 | 105 | ||
133 | if (!IS_ERR(exynos_ohci->phy)) { | ||
134 | usb_phy_shutdown(exynos_ohci->phy); | ||
135 | return; | ||
136 | } | ||
137 | |||
138 | for (i = 0; i < PHY_NUMBER; i++) | 106 | for (i = 0; i < PHY_NUMBER; i++) |
139 | if (!IS_ERR(exynos_ohci->phy_g[i])) | 107 | if (!IS_ERR(exynos_ohci->phy[i])) |
140 | phy_power_off(exynos_ohci->phy_g[i]); | 108 | phy_power_off(exynos_ohci->phy[i]); |
141 | } | 109 | } |
142 | 110 | ||
143 | static int exynos_ohci_probe(struct platform_device *pdev) | 111 | static int exynos_ohci_probe(struct platform_device *pdev) |
@@ -209,9 +177,6 @@ skip_phy: | |||
209 | goto fail_io; | 177 | goto fail_io; |
210 | } | 178 | } |
211 | 179 | ||
212 | if (exynos_ohci->otg) | ||
213 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | ||
214 | |||
215 | platform_set_drvdata(pdev, hcd); | 180 | platform_set_drvdata(pdev, hcd); |
216 | 181 | ||
217 | err = exynos_ohci_phy_enable(&pdev->dev); | 182 | err = exynos_ohci_phy_enable(&pdev->dev); |
@@ -244,9 +209,6 @@ static int exynos_ohci_remove(struct platform_device *pdev) | |||
244 | 209 | ||
245 | usb_remove_hcd(hcd); | 210 | usb_remove_hcd(hcd); |
246 | 211 | ||
247 | if (exynos_ohci->otg) | ||
248 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | ||
249 | |||
250 | exynos_ohci_phy_disable(&pdev->dev); | 212 | exynos_ohci_phy_disable(&pdev->dev); |
251 | 213 | ||
252 | clk_disable_unprepare(exynos_ohci->clk); | 214 | clk_disable_unprepare(exynos_ohci->clk); |
@@ -275,9 +237,6 @@ static int exynos_ohci_suspend(struct device *dev) | |||
275 | if (rc) | 237 | if (rc) |
276 | return rc; | 238 | return rc; |
277 | 239 | ||
278 | if (exynos_ohci->otg) | ||
279 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | ||
280 | |||
281 | exynos_ohci_phy_disable(dev); | 240 | exynos_ohci_phy_disable(dev); |
282 | 241 | ||
283 | clk_disable_unprepare(exynos_ohci->clk); | 242 | clk_disable_unprepare(exynos_ohci->clk); |
@@ -293,9 +252,6 @@ static int exynos_ohci_resume(struct device *dev) | |||
293 | 252 | ||
294 | clk_prepare_enable(exynos_ohci->clk); | 253 | clk_prepare_enable(exynos_ohci->clk); |
295 | 254 | ||
296 | if (exynos_ohci->otg) | ||
297 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | ||
298 | |||
299 | ret = exynos_ohci_phy_enable(dev); | 255 | ret = exynos_ohci_phy_enable(dev); |
300 | if (ret) { | 256 | if (ret) { |
301 | dev_err(dev, "Failed to enable USB phy\n"); | 257 | dev_err(dev, "Failed to enable USB phy\n"); |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 46987735a2e3..d664edabf14e 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -632,7 +632,7 @@ retry: | |||
632 | return -EOVERFLOW; | 632 | return -EOVERFLOW; |
633 | } | 633 | } |
634 | 634 | ||
635 | /* use rhsc irqs after khubd is fully initialized */ | 635 | /* use rhsc irqs after hub_wq is allocated */ |
636 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 636 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
637 | hcd->uses_new_polling = 1; | 637 | hcd->uses_new_polling = 1; |
638 | 638 | ||
@@ -909,8 +909,8 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd) | |||
909 | * choices for RHSC. Many followed the spec; RHSC triggers | 909 | * choices for RHSC. Many followed the spec; RHSC triggers |
910 | * on an edge, like setting and maybe clearing a port status | 910 | * on an edge, like setting and maybe clearing a port status |
911 | * change bit. With others it's level-triggered, active | 911 | * change bit. With others it's level-triggered, active |
912 | * until khubd clears all the port status change bits. We'll | 912 | * until hub_wq clears all the port status change bits. We'll |
913 | * always disable it here and rely on polling until khubd | 913 | * always disable it here and rely on polling until hub_wq |
914 | * re-enables it. | 914 | * re-enables it. |
915 | */ | 915 | */ |
916 | ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable); | 916 | ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable); |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index 17d32b0ea565..0aa17c937115 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -585,7 +585,7 @@ static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) | |||
585 | if (!(status & RH_PS_CCS)) | 585 | if (!(status & RH_PS_CCS)) |
586 | return -ENODEV; | 586 | return -ENODEV; |
587 | 587 | ||
588 | /* khubd will finish the reset later */ | 588 | /* hub_wq will finish the reset later */ |
589 | ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); | 589 | ohci_writel(ohci, RH_PS_PRS, &ohci->regs->roothub.portstatus [port]); |
590 | return 0; | 590 | return 0; |
591 | } | 591 | } |
@@ -610,7 +610,7 @@ static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port) | |||
610 | /* wrap-aware logic morphed from <linux/jiffies.h> */ | 610 | /* wrap-aware logic morphed from <linux/jiffies.h> */ |
611 | #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) | 611 | #define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) |
612 | 612 | ||
613 | /* called from some task, normally khubd */ | 613 | /* called from some task, normally hub_wq */ |
614 | static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) | 614 | static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) |
615 | { | 615 | { |
616 | __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; | 616 | __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; |
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index c923cafcaca7..0231606d47c2 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c | |||
@@ -180,10 +180,10 @@ static void start_hnp(struct ohci_hcd *ohci) | |||
180 | unsigned long flags; | 180 | unsigned long flags; |
181 | u32 l; | 181 | u32 l; |
182 | 182 | ||
183 | otg_start_hnp(hcd->phy->otg); | 183 | otg_start_hnp(hcd->usb_phy->otg); |
184 | 184 | ||
185 | local_irq_save(flags); | 185 | local_irq_save(flags); |
186 | hcd->phy->state = OTG_STATE_A_SUSPEND; | 186 | hcd->usb_phy->state = OTG_STATE_A_SUSPEND; |
187 | writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); | 187 | writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); |
188 | l = omap_readl(OTG_CTRL); | 188 | l = omap_readl(OTG_CTRL); |
189 | l &= ~OTG_A_BUSREQ; | 189 | l &= ~OTG_A_BUSREQ; |
@@ -220,14 +220,14 @@ static int ohci_omap_reset(struct usb_hcd *hcd) | |||
220 | 220 | ||
221 | #ifdef CONFIG_USB_OTG | 221 | #ifdef CONFIG_USB_OTG |
222 | if (need_transceiver) { | 222 | if (need_transceiver) { |
223 | hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2); | 223 | hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); |
224 | if (!IS_ERR_OR_NULL(hcd->phy)) { | 224 | if (!IS_ERR_OR_NULL(hcd->usb_phy)) { |
225 | int status = otg_set_host(hcd->phy->otg, | 225 | int status = otg_set_host(hcd->usb_phy->otg, |
226 | &ohci_to_hcd(ohci)->self); | 226 | &ohci_to_hcd(ohci)->self); |
227 | dev_dbg(hcd->self.controller, "init %s phy, status %d\n", | 227 | dev_dbg(hcd->self.controller, "init %s phy, status %d\n", |
228 | hcd->phy->label, status); | 228 | hcd->usb_phy->label, status); |
229 | if (status) { | 229 | if (status) { |
230 | usb_put_phy(hcd->phy); | 230 | usb_put_phy(hcd->usb_phy); |
231 | return status; | 231 | return status; |
232 | } | 232 | } |
233 | } else { | 233 | } else { |
@@ -283,7 +283,7 @@ static int ohci_omap_reset(struct usb_hcd *hcd) | |||
283 | ohci_to_hcd(ohci)->power_budget = 0; | 283 | ohci_to_hcd(ohci)->power_budget = 0; |
284 | } | 284 | } |
285 | 285 | ||
286 | /* FIXME khubd hub requests should manage power switching */ | 286 | /* FIXME hub_wq hub requests should manage power switching */ |
287 | omap_ohci_transceiver_power(1); | 287 | omap_ohci_transceiver_power(1); |
288 | 288 | ||
289 | /* board init will have already handled HMC and mux setup. | 289 | /* board init will have already handled HMC and mux setup. |
@@ -399,9 +399,9 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) | |||
399 | dev_dbg(hcd->self.controller, "stopping USB Controller\n"); | 399 | dev_dbg(hcd->self.controller, "stopping USB Controller\n"); |
400 | usb_remove_hcd(hcd); | 400 | usb_remove_hcd(hcd); |
401 | omap_ohci_clock_power(0); | 401 | omap_ohci_clock_power(0); |
402 | if (!IS_ERR_OR_NULL(hcd->phy)) { | 402 | if (!IS_ERR_OR_NULL(hcd->usb_phy)) { |
403 | (void) otg_set_host(hcd->phy->otg, 0); | 403 | (void) otg_set_host(hcd->usb_phy->otg, 0); |
404 | usb_put_phy(hcd->phy); | 404 | usb_put_phy(hcd->usb_phy); |
405 | } | 405 | } |
406 | if (machine_is_omap_osk()) | 406 | if (machine_is_omap_osk()) |
407 | gpio_free(9); | 407 | gpio_free(9); |
diff --git a/drivers/usb/host/ohci-st.c b/drivers/usb/host/ohci-st.c new file mode 100644 index 000000000000..df9028e0d9b4 --- /dev/null +++ b/drivers/usb/host/ohci-st.c | |||
@@ -0,0 +1,349 @@ | |||
1 | /* | ||
2 | * ST OHCI driver | ||
3 | * | ||
4 | * Copyright (C) 2014 STMicroelectronics – All Rights Reserved | ||
5 | * | ||
6 | * Author: Peter Griffin <peter.griffin@linaro.org> | ||
7 | * | ||
8 | * Derived from ohci-platform.c | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/clk.h> | ||
16 | #include <linux/dma-mapping.h> | ||
17 | #include <linux/hrtimer.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/err.h> | ||
22 | #include <linux/phy/phy.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/reset.h> | ||
25 | #include <linux/usb/ohci_pdriver.h> | ||
26 | #include <linux/usb.h> | ||
27 | #include <linux/usb/hcd.h> | ||
28 | |||
29 | #include "ohci.h" | ||
30 | |||
31 | #define USB_MAX_CLKS 3 | ||
32 | |||
33 | struct st_ohci_platform_priv { | ||
34 | struct clk *clks[USB_MAX_CLKS]; | ||
35 | struct clk *clk48; | ||
36 | struct reset_control *rst; | ||
37 | struct reset_control *pwr; | ||
38 | struct phy *phy; | ||
39 | }; | ||
40 | |||
41 | #define DRIVER_DESC "OHCI STMicroelectronics driver" | ||
42 | |||
43 | #define hcd_to_ohci_priv(h) \ | ||
44 | ((struct st_ohci_platform_priv *)hcd_to_ohci(h)->priv) | ||
45 | |||
46 | static const char hcd_name[] = "ohci-st"; | ||
47 | |||
48 | static int st_ohci_platform_power_on(struct platform_device *dev) | ||
49 | { | ||
50 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
51 | struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); | ||
52 | int clk, ret; | ||
53 | |||
54 | ret = reset_control_deassert(priv->pwr); | ||
55 | if (ret) | ||
56 | return ret; | ||
57 | |||
58 | ret = reset_control_deassert(priv->rst); | ||
59 | if (ret) | ||
60 | goto err_assert_power; | ||
61 | |||
62 | /* some SoCs don't have a dedicated 48Mhz clock, but those that do | ||
63 | need the rate to be explicitly set */ | ||
64 | if (priv->clk48) { | ||
65 | ret = clk_set_rate(priv->clk48, 48000000); | ||
66 | if (ret) | ||
67 | goto err_assert_reset; | ||
68 | } | ||
69 | |||
70 | for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) { | ||
71 | ret = clk_prepare_enable(priv->clks[clk]); | ||
72 | if (ret) | ||
73 | goto err_disable_clks; | ||
74 | } | ||
75 | |||
76 | ret = phy_init(priv->phy); | ||
77 | if (ret) | ||
78 | goto err_disable_clks; | ||
79 | |||
80 | ret = phy_power_on(priv->phy); | ||
81 | if (ret) | ||
82 | goto err_exit_phy; | ||
83 | |||
84 | return 0; | ||
85 | |||
86 | err_exit_phy: | ||
87 | phy_exit(priv->phy); | ||
88 | err_disable_clks: | ||
89 | while (--clk >= 0) | ||
90 | clk_disable_unprepare(priv->clks[clk]); | ||
91 | err_assert_reset: | ||
92 | reset_control_assert(priv->rst); | ||
93 | err_assert_power: | ||
94 | reset_control_assert(priv->pwr); | ||
95 | |||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | static void st_ohci_platform_power_off(struct platform_device *dev) | ||
100 | { | ||
101 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
102 | struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); | ||
103 | |||
104 | int clk; | ||
105 | |||
106 | reset_control_assert(priv->pwr); | ||
107 | |||
108 | reset_control_assert(priv->rst); | ||
109 | |||
110 | phy_power_off(priv->phy); | ||
111 | |||
112 | phy_exit(priv->phy); | ||
113 | |||
114 | for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--) | ||
115 | if (priv->clks[clk]) | ||
116 | clk_disable_unprepare(priv->clks[clk]); | ||
117 | } | ||
118 | |||
119 | static struct hc_driver __read_mostly ohci_platform_hc_driver; | ||
120 | |||
121 | static const struct ohci_driver_overrides platform_overrides __initconst = { | ||
122 | .product_desc = "ST OHCI controller", | ||
123 | .extra_priv_size = sizeof(struct st_ohci_platform_priv), | ||
124 | }; | ||
125 | |||
126 | static struct usb_ohci_pdata ohci_platform_defaults = { | ||
127 | .power_on = st_ohci_platform_power_on, | ||
128 | .power_suspend = st_ohci_platform_power_off, | ||
129 | .power_off = st_ohci_platform_power_off, | ||
130 | }; | ||
131 | |||
132 | static int st_ohci_platform_probe(struct platform_device *dev) | ||
133 | { | ||
134 | struct usb_hcd *hcd; | ||
135 | struct resource *res_mem; | ||
136 | struct usb_ohci_pdata *pdata = &ohci_platform_defaults; | ||
137 | struct st_ohci_platform_priv *priv; | ||
138 | struct ohci_hcd *ohci; | ||
139 | int err, irq, clk = 0; | ||
140 | |||
141 | if (usb_disabled()) | ||
142 | return -ENODEV; | ||
143 | |||
144 | irq = platform_get_irq(dev, 0); | ||
145 | if (irq < 0) { | ||
146 | dev_err(&dev->dev, "no irq provided"); | ||
147 | return irq; | ||
148 | } | ||
149 | |||
150 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
151 | if (!res_mem) { | ||
152 | dev_err(&dev->dev, "no memory resource provided"); | ||
153 | return -ENXIO; | ||
154 | } | ||
155 | |||
156 | hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, | ||
157 | dev_name(&dev->dev)); | ||
158 | if (!hcd) | ||
159 | return -ENOMEM; | ||
160 | |||
161 | platform_set_drvdata(dev, hcd); | ||
162 | dev->dev.platform_data = pdata; | ||
163 | priv = hcd_to_ohci_priv(hcd); | ||
164 | ohci = hcd_to_ohci(hcd); | ||
165 | |||
166 | priv->phy = devm_phy_get(&dev->dev, "usb"); | ||
167 | if (IS_ERR(priv->phy)) { | ||
168 | err = PTR_ERR(priv->phy); | ||
169 | goto err_put_hcd; | ||
170 | } | ||
171 | |||
172 | for (clk = 0; clk < USB_MAX_CLKS; clk++) { | ||
173 | priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); | ||
174 | if (IS_ERR(priv->clks[clk])) { | ||
175 | err = PTR_ERR(priv->clks[clk]); | ||
176 | if (err == -EPROBE_DEFER) | ||
177 | goto err_put_clks; | ||
178 | priv->clks[clk] = NULL; | ||
179 | break; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /* some SoCs don't have a dedicated 48Mhz clock, but those that | ||
184 | do need the rate to be explicitly set */ | ||
185 | priv->clk48 = devm_clk_get(&dev->dev, "clk48"); | ||
186 | if (IS_ERR(priv->clk48)) { | ||
187 | dev_info(&dev->dev, "48MHz clk not found\n"); | ||
188 | priv->clk48 = NULL; | ||
189 | } | ||
190 | |||
191 | priv->pwr = devm_reset_control_get_optional(&dev->dev, "power"); | ||
192 | if (IS_ERR(priv->pwr)) { | ||
193 | err = PTR_ERR(priv->pwr); | ||
194 | goto err_put_clks; | ||
195 | } | ||
196 | |||
197 | priv->rst = devm_reset_control_get_optional(&dev->dev, "softreset"); | ||
198 | if (IS_ERR(priv->rst)) { | ||
199 | err = PTR_ERR(priv->rst); | ||
200 | goto err_put_clks; | ||
201 | } | ||
202 | |||
203 | if (pdata->power_on) { | ||
204 | err = pdata->power_on(dev); | ||
205 | if (err < 0) | ||
206 | goto err_power; | ||
207 | } | ||
208 | |||
209 | hcd->rsrc_start = res_mem->start; | ||
210 | hcd->rsrc_len = resource_size(res_mem); | ||
211 | |||
212 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); | ||
213 | if (IS_ERR(hcd->regs)) { | ||
214 | err = PTR_ERR(hcd->regs); | ||
215 | goto err_power; | ||
216 | } | ||
217 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
218 | if (err) | ||
219 | goto err_power; | ||
220 | |||
221 | device_wakeup_enable(hcd->self.controller); | ||
222 | |||
223 | platform_set_drvdata(dev, hcd); | ||
224 | |||
225 | return err; | ||
226 | |||
227 | err_power: | ||
228 | if (pdata->power_off) | ||
229 | pdata->power_off(dev); | ||
230 | |||
231 | err_put_clks: | ||
232 | while (--clk >= 0) | ||
233 | clk_put(priv->clks[clk]); | ||
234 | err_put_hcd: | ||
235 | if (pdata == &ohci_platform_defaults) | ||
236 | dev->dev.platform_data = NULL; | ||
237 | |||
238 | usb_put_hcd(hcd); | ||
239 | |||
240 | return err; | ||
241 | } | ||
242 | |||
243 | static int st_ohci_platform_remove(struct platform_device *dev) | ||
244 | { | ||
245 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
246 | struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); | ||
247 | struct st_ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); | ||
248 | int clk; | ||
249 | |||
250 | usb_remove_hcd(hcd); | ||
251 | |||
252 | if (pdata->power_off) | ||
253 | pdata->power_off(dev); | ||
254 | |||
255 | |||
256 | for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) | ||
257 | clk_put(priv->clks[clk]); | ||
258 | |||
259 | usb_put_hcd(hcd); | ||
260 | |||
261 | if (pdata == &ohci_platform_defaults) | ||
262 | dev->dev.platform_data = NULL; | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | #ifdef CONFIG_PM_SLEEP | ||
268 | |||
269 | static int st_ohci_suspend(struct device *dev) | ||
270 | { | ||
271 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
272 | struct usb_ohci_pdata *pdata = dev->platform_data; | ||
273 | struct platform_device *pdev = | ||
274 | container_of(dev, struct platform_device, dev); | ||
275 | bool do_wakeup = device_may_wakeup(dev); | ||
276 | int ret; | ||
277 | |||
278 | ret = ohci_suspend(hcd, do_wakeup); | ||
279 | if (ret) | ||
280 | return ret; | ||
281 | |||
282 | if (pdata->power_suspend) | ||
283 | pdata->power_suspend(pdev); | ||
284 | |||
285 | return ret; | ||
286 | } | ||
287 | |||
288 | static int st_ohci_resume(struct device *dev) | ||
289 | { | ||
290 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
291 | struct usb_ohci_pdata *pdata = dev_get_platdata(dev); | ||
292 | struct platform_device *pdev = | ||
293 | container_of(dev, struct platform_device, dev); | ||
294 | int err; | ||
295 | |||
296 | if (pdata->power_on) { | ||
297 | err = pdata->power_on(pdev); | ||
298 | if (err < 0) | ||
299 | return err; | ||
300 | } | ||
301 | |||
302 | ohci_resume(hcd, false); | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static SIMPLE_DEV_PM_OPS(st_ohci_pm_ops, st_ohci_suspend, st_ohci_resume); | ||
307 | |||
308 | #endif /* CONFIG_PM_SLEEP */ | ||
309 | |||
310 | static const struct of_device_id st_ohci_platform_ids[] = { | ||
311 | { .compatible = "st,st-ohci-300x", }, | ||
312 | { /* sentinel */ } | ||
313 | }; | ||
314 | MODULE_DEVICE_TABLE(of, st_ohci_platform_ids); | ||
315 | |||
316 | static struct platform_driver ohci_platform_driver = { | ||
317 | .probe = st_ohci_platform_probe, | ||
318 | .remove = st_ohci_platform_remove, | ||
319 | .shutdown = usb_hcd_platform_shutdown, | ||
320 | .driver = { | ||
321 | .name = "st-ohci", | ||
322 | #ifdef CONFIG_PM_SLEEP | ||
323 | .pm = &st_ohci_pm_ops, | ||
324 | #endif | ||
325 | .of_match_table = st_ohci_platform_ids, | ||
326 | } | ||
327 | }; | ||
328 | |||
329 | static int __init ohci_platform_init(void) | ||
330 | { | ||
331 | if (usb_disabled()) | ||
332 | return -ENODEV; | ||
333 | |||
334 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | ||
335 | |||
336 | ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides); | ||
337 | return platform_driver_register(&ohci_platform_driver); | ||
338 | } | ||
339 | module_init(ohci_platform_init); | ||
340 | |||
341 | static void __exit ohci_platform_cleanup(void) | ||
342 | { | ||
343 | platform_driver_unregister(&ohci_platform_driver); | ||
344 | } | ||
345 | module_exit(ohci_platform_cleanup); | ||
346 | |||
347 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
348 | MODULE_AUTHOR("Peter Griffin <peter.griffin@linaro.org>"); | ||
349 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index da5fb0e3c363..4fe79a2d71a9 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c | |||
@@ -2046,7 +2046,7 @@ static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh) | |||
2046 | 2046 | ||
2047 | /* simple/paranoid: always delay, expecting the HC needs to read | 2047 | /* simple/paranoid: always delay, expecting the HC needs to read |
2048 | * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and | 2048 | * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and |
2049 | * expect khubd to clean up after any CSPLITs we won't issue. | 2049 | * expect hub_wq to clean up after any CSPLITs we won't issue. |
2050 | * active high speed queues may need bigger delays... | 2050 | * active high speed queues may need bigger delays... |
2051 | */ | 2051 | */ |
2052 | if (list_empty(&qh->qtd_list) | 2052 | if (list_empty(&qh->qtd_list) |
@@ -2501,7 +2501,7 @@ static irqreturn_t oxu210_hcd_irq(struct usb_hcd *hcd) | |||
2501 | continue; | 2501 | continue; |
2502 | 2502 | ||
2503 | /* start 20 msec resume signaling from this port, | 2503 | /* start 20 msec resume signaling from this port, |
2504 | * and make khubd collect PORT_STAT_C_SUSPEND to | 2504 | * and make hub_wq collect PORT_STAT_C_SUSPEND to |
2505 | * stop that signaling. | 2505 | * stop that signaling. |
2506 | */ | 2506 | */ |
2507 | oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); | 2507 | oxu->reset_done[i] = jiffies + msecs_to_jiffies(20); |
@@ -3119,7 +3119,7 @@ static int oxu_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
3119 | 3119 | ||
3120 | /* | 3120 | /* |
3121 | * Return status information even for ports with OWNER set. | 3121 | * Return status information even for ports with OWNER set. |
3122 | * Otherwise khubd wouldn't see the disconnect event when a | 3122 | * Otherwise hub_wq wouldn't see the disconnect event when a |
3123 | * high-speed device is switched over to the companion | 3123 | * high-speed device is switched over to the companion |
3124 | * controller by the user. | 3124 | * controller by the user. |
3125 | */ | 3125 | */ |
@@ -3194,7 +3194,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
3194 | 3194 | ||
3195 | /* | 3195 | /* |
3196 | * Even if OWNER is set, so the port is owned by the | 3196 | * Even if OWNER is set, so the port is owned by the |
3197 | * companion controller, khubd needs to be able to clear | 3197 | * companion controller, hub_wq needs to be able to clear |
3198 | * the port-change status bits (especially | 3198 | * the port-change status bits (especially |
3199 | * USB_PORT_STAT_C_CONNECTION). | 3199 | * USB_PORT_STAT_C_CONNECTION). |
3200 | */ | 3200 | */ |
@@ -3336,7 +3336,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
3336 | } | 3336 | } |
3337 | 3337 | ||
3338 | /* | 3338 | /* |
3339 | * Even if OWNER is set, there's no harm letting khubd | 3339 | * Even if OWNER is set, there's no harm letting hub_wq |
3340 | * see the wPortStatus values (they should all be 0 except | 3340 | * see the wPortStatus values (they should all be 0 except |
3341 | * for PORT_POWER anyway). | 3341 | * for PORT_POWER anyway). |
3342 | */ | 3342 | */ |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index a517151867af..ad0c348e68e9 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -674,7 +674,7 @@ retry: | |||
674 | sl811->next_periodic = sl811->periodic[index]; | 674 | sl811->next_periodic = sl811->periodic[index]; |
675 | } | 675 | } |
676 | 676 | ||
677 | /* khubd manages debouncing and wakeup */ | 677 | /* hub_wq manages debouncing and wakeup */ |
678 | if (irqstat & SL11H_INTMASK_INSRMV) { | 678 | if (irqstat & SL11H_INTMASK_INSRMV) { |
679 | sl811->stat_insrmv++; | 679 | sl811->stat_insrmv++; |
680 | 680 | ||
@@ -714,7 +714,7 @@ retry: | |||
714 | #endif | 714 | #endif |
715 | 715 | ||
716 | /* port status seems weird until after reset, so | 716 | /* port status seems weird until after reset, so |
717 | * force the reset and make khubd clean up later. | 717 | * force the reset and make hub_wq clean up later. |
718 | */ | 718 | */ |
719 | if (irqstat & SL11H_INTMASK_RD) | 719 | if (irqstat & SL11H_INTMASK_RD) |
720 | sl811->port1 &= ~USB_PORT_STAT_CONNECTION; | 720 | sl811->port1 &= ~USB_PORT_STAT_CONNECTION; |
@@ -1079,7 +1079,7 @@ sl811h_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
1079 | if (!(sl811->port1 & (0xffff << 16))) | 1079 | if (!(sl811->port1 & (0xffff << 16))) |
1080 | return 0; | 1080 | return 0; |
1081 | 1081 | ||
1082 | /* tell khubd port 1 changed */ | 1082 | /* tell hub_wq port 1 changed */ |
1083 | *buf = (1 << 1); | 1083 | *buf = (1 << 1); |
1084 | return 1; | 1084 | return 1; |
1085 | } | 1085 | } |
@@ -1196,7 +1196,7 @@ sl811h_timer(unsigned long _sl811) | |||
1196 | sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), | 1196 | sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), |
1197 | SL11H_HCTLMASK_ARM); | 1197 | SL11H_HCTLMASK_ARM); |
1198 | 1198 | ||
1199 | /* khubd provides debounce delay */ | 1199 | /* hub_wq provides debounce delay */ |
1200 | } else { | 1200 | } else { |
1201 | sl811->ctrl1 = 0; | 1201 | sl811->ctrl1 = 0; |
1202 | } | 1202 | } |
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c index eb009a457fb5..bb89175ca6e5 100644 --- a/drivers/usb/host/xhci-dbg.c +++ b/drivers/usb/host/xhci-dbg.c | |||
@@ -594,3 +594,4 @@ void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *), | |||
594 | trace(&vaf); | 594 | trace(&vaf); |
595 | va_end(args); | 595 | va_end(args); |
596 | } | 596 | } |
597 | EXPORT_SYMBOL_GPL(xhci_dbg_trace); | ||
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 69aece31143a..696160d48ae8 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -319,12 +319,19 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) | |||
319 | */ | 319 | */ |
320 | void xhci_ring_device(struct xhci_hcd *xhci, int slot_id) | 320 | void xhci_ring_device(struct xhci_hcd *xhci, int slot_id) |
321 | { | 321 | { |
322 | int i; | 322 | int i, s; |
323 | struct xhci_virt_ep *ep; | ||
324 | |||
325 | for (i = 0; i < LAST_EP_INDEX + 1; i++) { | ||
326 | ep = &xhci->devs[slot_id]->eps[i]; | ||
323 | 327 | ||
324 | for (i = 0; i < LAST_EP_INDEX + 1; i++) | 328 | if (ep->ep_state & EP_HAS_STREAMS) { |
325 | if (xhci->devs[slot_id]->eps[i].ring && | 329 | for (s = 1; s < ep->stream_info->num_streams; s++) |
326 | xhci->devs[slot_id]->eps[i].ring->dequeue) | 330 | xhci_ring_ep_doorbell(xhci, slot_id, i, s); |
331 | } else if (ep->ring && ep->ring->dequeue) { | ||
327 | xhci_ring_ep_doorbell(xhci, slot_id, i, 0); | 332 | xhci_ring_ep_doorbell(xhci, slot_id, i, 0); |
333 | } | ||
334 | } | ||
328 | 335 | ||
329 | return; | 336 | return; |
330 | } | 337 | } |
@@ -892,7 +899,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
892 | /* | 899 | /* |
893 | * Turn on ports, even if there isn't per-port switching. | 900 | * Turn on ports, even if there isn't per-port switching. |
894 | * HC will report connect events even before this is set. | 901 | * HC will report connect events even before this is set. |
895 | * However, khubd will ignore the roothub events until | 902 | * However, hub_wq will ignore the roothub events until |
896 | * the roothub is registered. | 903 | * the roothub is registered. |
897 | */ | 904 | */ |
898 | writel(temp | PORT_POWER, port_array[wIndex]); | 905 | writel(temp | PORT_POWER, port_array[wIndex]); |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 8936211b161d..5cb3d7a10017 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -1904,7 +1904,7 @@ static int xhci_test_trb_in_td(struct xhci_hcd *xhci, | |||
1904 | start_dma = xhci_trb_virt_to_dma(input_seg, start_trb); | 1904 | start_dma = xhci_trb_virt_to_dma(input_seg, start_trb); |
1905 | end_dma = xhci_trb_virt_to_dma(input_seg, end_trb); | 1905 | end_dma = xhci_trb_virt_to_dma(input_seg, end_trb); |
1906 | 1906 | ||
1907 | seg = trb_in_td(input_seg, start_trb, end_trb, input_dma); | 1907 | seg = trb_in_td(xhci, input_seg, start_trb, end_trb, input_dma, false); |
1908 | if (seg != result_seg) { | 1908 | if (seg != result_seg) { |
1909 | xhci_warn(xhci, "WARN: %s TRB math test %d failed!\n", | 1909 | xhci_warn(xhci, "WARN: %s TRB math test %d failed!\n", |
1910 | test_name, test_number); | 1910 | test_name, test_number); |
@@ -1918,6 +1918,8 @@ static int xhci_test_trb_in_td(struct xhci_hcd *xhci, | |||
1918 | end_trb, end_dma); | 1918 | end_trb, end_dma); |
1919 | xhci_warn(xhci, "Expected seg %p, got seg %p\n", | 1919 | xhci_warn(xhci, "Expected seg %p, got seg %p\n", |
1920 | result_seg, seg); | 1920 | result_seg, seg); |
1921 | trb_in_td(xhci, input_seg, start_trb, end_trb, input_dma, | ||
1922 | true); | ||
1921 | return -1; | 1923 | return -1; |
1922 | } | 1924 | } |
1923 | return 0; | 1925 | return 0; |
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index c22a3e15a16e..280dde93abe5 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -40,6 +40,8 @@ | |||
40 | 40 | ||
41 | static const char hcd_name[] = "xhci_hcd"; | 41 | static const char hcd_name[] = "xhci_hcd"; |
42 | 42 | ||
43 | static struct hc_driver __read_mostly xhci_pci_hc_driver; | ||
44 | |||
43 | /* called after powerup, by probe or system-pm "wakeup" */ | 45 | /* called after powerup, by probe or system-pm "wakeup" */ |
44 | static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) | 46 | static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) |
45 | { | 47 | { |
@@ -286,7 +288,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
286 | * Systems with the TI redriver that loses port status change events | 288 | * Systems with the TI redriver that loses port status change events |
287 | * need to have the registers polled during D3, so avoid D3cold. | 289 | * need to have the registers polled during D3, so avoid D3cold. |
288 | */ | 290 | */ |
289 | if (xhci_compliance_mode_recovery_timer_quirk_check()) | 291 | if (xhci->quirks & XHCI_COMP_MODE_QUIRK) |
290 | pdev->no_d3cold = true; | 292 | pdev->no_d3cold = true; |
291 | 293 | ||
292 | return xhci_suspend(xhci); | 294 | return xhci_suspend(xhci); |
@@ -324,68 +326,6 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) | |||
324 | } | 326 | } |
325 | #endif /* CONFIG_PM */ | 327 | #endif /* CONFIG_PM */ |
326 | 328 | ||
327 | static const struct hc_driver xhci_pci_hc_driver = { | ||
328 | .description = hcd_name, | ||
329 | .product_desc = "xHCI Host Controller", | ||
330 | .hcd_priv_size = sizeof(struct xhci_hcd *), | ||
331 | |||
332 | /* | ||
333 | * generic hardware linkage | ||
334 | */ | ||
335 | .irq = xhci_irq, | ||
336 | .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, | ||
337 | |||
338 | /* | ||
339 | * basic lifecycle operations | ||
340 | */ | ||
341 | .reset = xhci_pci_setup, | ||
342 | .start = xhci_run, | ||
343 | #ifdef CONFIG_PM | ||
344 | .pci_suspend = xhci_pci_suspend, | ||
345 | .pci_resume = xhci_pci_resume, | ||
346 | #endif | ||
347 | .stop = xhci_stop, | ||
348 | .shutdown = xhci_shutdown, | ||
349 | |||
350 | /* | ||
351 | * managing i/o requests and associated device resources | ||
352 | */ | ||
353 | .urb_enqueue = xhci_urb_enqueue, | ||
354 | .urb_dequeue = xhci_urb_dequeue, | ||
355 | .alloc_dev = xhci_alloc_dev, | ||
356 | .free_dev = xhci_free_dev, | ||
357 | .alloc_streams = xhci_alloc_streams, | ||
358 | .free_streams = xhci_free_streams, | ||
359 | .add_endpoint = xhci_add_endpoint, | ||
360 | .drop_endpoint = xhci_drop_endpoint, | ||
361 | .endpoint_reset = xhci_endpoint_reset, | ||
362 | .check_bandwidth = xhci_check_bandwidth, | ||
363 | .reset_bandwidth = xhci_reset_bandwidth, | ||
364 | .address_device = xhci_address_device, | ||
365 | .enable_device = xhci_enable_device, | ||
366 | .update_hub_device = xhci_update_hub_device, | ||
367 | .reset_device = xhci_discover_or_reset_device, | ||
368 | |||
369 | /* | ||
370 | * scheduling support | ||
371 | */ | ||
372 | .get_frame_number = xhci_get_frame, | ||
373 | |||
374 | /* Root hub support */ | ||
375 | .hub_control = xhci_hub_control, | ||
376 | .hub_status_data = xhci_hub_status_data, | ||
377 | .bus_suspend = xhci_bus_suspend, | ||
378 | .bus_resume = xhci_bus_resume, | ||
379 | /* | ||
380 | * call back when device connected and addressed | ||
381 | */ | ||
382 | .update_device = xhci_update_device, | ||
383 | .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, | ||
384 | .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, | ||
385 | .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, | ||
386 | .find_raw_port_number = xhci_find_raw_port_number, | ||
387 | }; | ||
388 | |||
389 | /*-------------------------------------------------------------------------*/ | 329 | /*-------------------------------------------------------------------------*/ |
390 | 330 | ||
391 | /* PCI driver selection metadata; PCI hotplugging uses this */ | 331 | /* PCI driver selection metadata; PCI hotplugging uses this */ |
@@ -415,12 +355,22 @@ static struct pci_driver xhci_pci_driver = { | |||
415 | #endif | 355 | #endif |
416 | }; | 356 | }; |
417 | 357 | ||
418 | int __init xhci_register_pci(void) | 358 | static int __init xhci_pci_init(void) |
419 | { | 359 | { |
360 | xhci_init_driver(&xhci_pci_hc_driver, xhci_pci_setup); | ||
361 | #ifdef CONFIG_PM | ||
362 | xhci_pci_hc_driver.pci_suspend = xhci_pci_suspend; | ||
363 | xhci_pci_hc_driver.pci_resume = xhci_pci_resume; | ||
364 | #endif | ||
420 | return pci_register_driver(&xhci_pci_driver); | 365 | return pci_register_driver(&xhci_pci_driver); |
421 | } | 366 | } |
367 | module_init(xhci_pci_init); | ||
422 | 368 | ||
423 | void xhci_unregister_pci(void) | 369 | static void __exit xhci_pci_exit(void) |
424 | { | 370 | { |
425 | pci_unregister_driver(&xhci_pci_driver); | 371 | pci_unregister_driver(&xhci_pci_driver); |
426 | } | 372 | } |
373 | module_exit(xhci_pci_exit); | ||
374 | |||
375 | MODULE_DESCRIPTION("xHCI PCI Host Controller Driver"); | ||
376 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 1a0cf9f31e43..3d78b0cd674b 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c | |||
@@ -23,6 +23,8 @@ | |||
23 | #include "xhci-mvebu.h" | 23 | #include "xhci-mvebu.h" |
24 | #include "xhci-rcar.h" | 24 | #include "xhci-rcar.h" |
25 | 25 | ||
26 | static struct hc_driver __read_mostly xhci_plat_hc_driver; | ||
27 | |||
26 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) | 28 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) |
27 | { | 29 | { |
28 | /* | 30 | /* |
@@ -60,59 +62,6 @@ static int xhci_plat_start(struct usb_hcd *hcd) | |||
60 | return xhci_run(hcd); | 62 | return xhci_run(hcd); |
61 | } | 63 | } |
62 | 64 | ||
63 | static const struct hc_driver xhci_plat_xhci_driver = { | ||
64 | .description = "xhci-hcd", | ||
65 | .product_desc = "xHCI Host Controller", | ||
66 | .hcd_priv_size = sizeof(struct xhci_hcd *), | ||
67 | |||
68 | /* | ||
69 | * generic hardware linkage | ||
70 | */ | ||
71 | .irq = xhci_irq, | ||
72 | .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, | ||
73 | |||
74 | /* | ||
75 | * basic lifecycle operations | ||
76 | */ | ||
77 | .reset = xhci_plat_setup, | ||
78 | .start = xhci_plat_start, | ||
79 | .stop = xhci_stop, | ||
80 | .shutdown = xhci_shutdown, | ||
81 | |||
82 | /* | ||
83 | * managing i/o requests and associated device resources | ||
84 | */ | ||
85 | .urb_enqueue = xhci_urb_enqueue, | ||
86 | .urb_dequeue = xhci_urb_dequeue, | ||
87 | .alloc_dev = xhci_alloc_dev, | ||
88 | .free_dev = xhci_free_dev, | ||
89 | .alloc_streams = xhci_alloc_streams, | ||
90 | .free_streams = xhci_free_streams, | ||
91 | .add_endpoint = xhci_add_endpoint, | ||
92 | .drop_endpoint = xhci_drop_endpoint, | ||
93 | .endpoint_reset = xhci_endpoint_reset, | ||
94 | .check_bandwidth = xhci_check_bandwidth, | ||
95 | .reset_bandwidth = xhci_reset_bandwidth, | ||
96 | .address_device = xhci_address_device, | ||
97 | .enable_device = xhci_enable_device, | ||
98 | .update_hub_device = xhci_update_hub_device, | ||
99 | .reset_device = xhci_discover_or_reset_device, | ||
100 | |||
101 | /* | ||
102 | * scheduling support | ||
103 | */ | ||
104 | .get_frame_number = xhci_get_frame, | ||
105 | |||
106 | /* Root hub support */ | ||
107 | .hub_control = xhci_hub_control, | ||
108 | .hub_status_data = xhci_hub_status_data, | ||
109 | .bus_suspend = xhci_bus_suspend, | ||
110 | .bus_resume = xhci_bus_resume, | ||
111 | |||
112 | .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, | ||
113 | .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, | ||
114 | }; | ||
115 | |||
116 | static int xhci_plat_probe(struct platform_device *pdev) | 65 | static int xhci_plat_probe(struct platform_device *pdev) |
117 | { | 66 | { |
118 | struct device_node *node = pdev->dev.of_node; | 67 | struct device_node *node = pdev->dev.of_node; |
@@ -128,7 +77,7 @@ static int xhci_plat_probe(struct platform_device *pdev) | |||
128 | if (usb_disabled()) | 77 | if (usb_disabled()) |
129 | return -ENODEV; | 78 | return -ENODEV; |
130 | 79 | ||
131 | driver = &xhci_plat_xhci_driver; | 80 | driver = &xhci_plat_hc_driver; |
132 | 81 | ||
133 | irq = platform_get_irq(pdev, 0); | 82 | irq = platform_get_irq(pdev, 0); |
134 | if (irq < 0) | 83 | if (irq < 0) |
@@ -298,12 +247,19 @@ static struct platform_driver usb_xhci_driver = { | |||
298 | }; | 247 | }; |
299 | MODULE_ALIAS("platform:xhci-hcd"); | 248 | MODULE_ALIAS("platform:xhci-hcd"); |
300 | 249 | ||
301 | int xhci_register_plat(void) | 250 | static int __init xhci_plat_init(void) |
302 | { | 251 | { |
252 | xhci_init_driver(&xhci_plat_hc_driver, xhci_plat_setup); | ||
253 | xhci_plat_hc_driver.start = xhci_plat_start; | ||
303 | return platform_driver_register(&usb_xhci_driver); | 254 | return platform_driver_register(&usb_xhci_driver); |
304 | } | 255 | } |
256 | module_init(xhci_plat_init); | ||
305 | 257 | ||
306 | void xhci_unregister_plat(void) | 258 | static void __exit xhci_plat_exit(void) |
307 | { | 259 | { |
308 | platform_driver_unregister(&usb_xhci_driver); | 260 | platform_driver_unregister(&usb_xhci_driver); |
309 | } | 261 | } |
262 | module_exit(xhci_plat_exit); | ||
263 | |||
264 | MODULE_DESCRIPTION("xHCI Platform Host Controller Driver"); | ||
265 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index abed30b82905..bc6fcbc16f61 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -327,7 +327,6 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, | |||
327 | * We don't want to restart any stream rings if there's a set dequeue | 327 | * We don't want to restart any stream rings if there's a set dequeue |
328 | * pointer command pending because the device can choose to start any | 328 | * pointer command pending because the device can choose to start any |
329 | * stream once the endpoint is on the HW schedule. | 329 | * stream once the endpoint is on the HW schedule. |
330 | * FIXME - check all the stream rings for pending cancellations. | ||
331 | */ | 330 | */ |
332 | if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) || | 331 | if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) || |
333 | (ep_state & EP_HALTED)) | 332 | (ep_state & EP_HALTED)) |
@@ -572,40 +571,6 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | |||
572 | } | 571 | } |
573 | } | 572 | } |
574 | 573 | ||
575 | static int queue_set_tr_deq(struct xhci_hcd *xhci, | ||
576 | struct xhci_command *cmd, int slot_id, | ||
577 | unsigned int ep_index, unsigned int stream_id, | ||
578 | struct xhci_segment *deq_seg, | ||
579 | union xhci_trb *deq_ptr, u32 cycle_state); | ||
580 | |||
581 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | ||
582 | struct xhci_command *cmd, | ||
583 | unsigned int slot_id, unsigned int ep_index, | ||
584 | unsigned int stream_id, | ||
585 | struct xhci_dequeue_state *deq_state) | ||
586 | { | ||
587 | struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; | ||
588 | |||
589 | xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, | ||
590 | "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " | ||
591 | "new deq ptr = %p (0x%llx dma), new cycle = %u", | ||
592 | deq_state->new_deq_seg, | ||
593 | (unsigned long long)deq_state->new_deq_seg->dma, | ||
594 | deq_state->new_deq_ptr, | ||
595 | (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr), | ||
596 | deq_state->new_cycle_state); | ||
597 | queue_set_tr_deq(xhci, cmd, slot_id, ep_index, stream_id, | ||
598 | deq_state->new_deq_seg, | ||
599 | deq_state->new_deq_ptr, | ||
600 | (u32) deq_state->new_cycle_state); | ||
601 | /* Stop the TD queueing code from ringing the doorbell until | ||
602 | * this command completes. The HC won't set the dequeue pointer | ||
603 | * if the ring is running, and ringing the doorbell starts the | ||
604 | * ring running. | ||
605 | */ | ||
606 | ep->ep_state |= SET_DEQ_PENDING; | ||
607 | } | ||
608 | |||
609 | static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, | 574 | static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, |
610 | struct xhci_virt_ep *ep) | 575 | struct xhci_virt_ep *ep) |
611 | { | 576 | { |
@@ -743,12 +708,8 @@ remove_finished_td: | |||
743 | 708 | ||
744 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ | 709 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ |
745 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { | 710 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { |
746 | struct xhci_command *command; | 711 | xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, |
747 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | 712 | ep->stopped_td->urb->stream_id, &deq_state); |
748 | xhci_queue_new_dequeue_state(xhci, command, | ||
749 | slot_id, ep_index, | ||
750 | ep->stopped_td->urb->stream_id, | ||
751 | &deq_state); | ||
752 | xhci_ring_cmd_db(xhci); | 713 | xhci_ring_cmd_db(xhci); |
753 | } else { | 714 | } else { |
754 | /* Otherwise ring the doorbell(s) to restart queued transfers */ | 715 | /* Otherwise ring the doorbell(s) to restart queued transfers */ |
@@ -1003,8 +964,7 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, | |||
1003 | xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", | 964 | xhci_warn(xhci, "WARN Set TR deq ptr command for freed stream ID %u\n", |
1004 | stream_id); | 965 | stream_id); |
1005 | /* XXX: Harmless??? */ | 966 | /* XXX: Harmless??? */ |
1006 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; | 967 | goto cleanup; |
1007 | return; | ||
1008 | } | 968 | } |
1009 | 969 | ||
1010 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); | 970 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); |
@@ -1069,6 +1029,7 @@ static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id, | |||
1069 | } | 1029 | } |
1070 | } | 1030 | } |
1071 | 1031 | ||
1032 | cleanup: | ||
1072 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; | 1033 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; |
1073 | dev->eps[ep_index].queued_deq_seg = NULL; | 1034 | dev->eps[ep_index].queued_deq_seg = NULL; |
1074 | dev->eps[ep_index].queued_deq_ptr = NULL; | 1035 | dev->eps[ep_index].queued_deq_ptr = NULL; |
@@ -1699,10 +1660,12 @@ cleanup: | |||
1699 | * TRB in this TD, this function returns that TRB's segment. Otherwise it | 1660 | * TRB in this TD, this function returns that TRB's segment. Otherwise it |
1700 | * returns 0. | 1661 | * returns 0. |
1701 | */ | 1662 | */ |
1702 | struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, | 1663 | struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, |
1664 | struct xhci_segment *start_seg, | ||
1703 | union xhci_trb *start_trb, | 1665 | union xhci_trb *start_trb, |
1704 | union xhci_trb *end_trb, | 1666 | union xhci_trb *end_trb, |
1705 | dma_addr_t suspect_dma) | 1667 | dma_addr_t suspect_dma, |
1668 | bool debug) | ||
1706 | { | 1669 | { |
1707 | dma_addr_t start_dma; | 1670 | dma_addr_t start_dma; |
1708 | dma_addr_t end_seg_dma; | 1671 | dma_addr_t end_seg_dma; |
@@ -1721,6 +1684,15 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, | |||
1721 | /* If the end TRB isn't in this segment, this is set to 0 */ | 1684 | /* If the end TRB isn't in this segment, this is set to 0 */ |
1722 | end_trb_dma = xhci_trb_virt_to_dma(cur_seg, end_trb); | 1685 | end_trb_dma = xhci_trb_virt_to_dma(cur_seg, end_trb); |
1723 | 1686 | ||
1687 | if (debug) | ||
1688 | xhci_warn(xhci, | ||
1689 | "Looking for event-dma %016llx trb-start %016llx trb-end %016llx seg-start %016llx seg-end %016llx\n", | ||
1690 | (unsigned long long)suspect_dma, | ||
1691 | (unsigned long long)start_dma, | ||
1692 | (unsigned long long)end_trb_dma, | ||
1693 | (unsigned long long)cur_seg->dma, | ||
1694 | (unsigned long long)end_seg_dma); | ||
1695 | |||
1724 | if (end_trb_dma > 0) { | 1696 | if (end_trb_dma > 0) { |
1725 | /* The end TRB is in this segment, so suspect should be here */ | 1697 | /* The end TRB is in this segment, so suspect should be here */ |
1726 | if (start_dma <= end_trb_dma) { | 1698 | if (start_dma <= end_trb_dma) { |
@@ -2453,8 +2425,8 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
2453 | td_num--; | 2425 | td_num--; |
2454 | 2426 | ||
2455 | /* Is this a TRB in the currently executing TD? */ | 2427 | /* Is this a TRB in the currently executing TD? */ |
2456 | event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, | 2428 | event_seg = trb_in_td(xhci, ep_ring->deq_seg, ep_ring->dequeue, |
2457 | td->last_trb, event_dma); | 2429 | td->last_trb, event_dma, false); |
2458 | 2430 | ||
2459 | /* | 2431 | /* |
2460 | * Skip the Force Stopped Event. The event_trb(event_dma) of FSE | 2432 | * Skip the Force Stopped Event. The event_trb(event_dma) of FSE |
@@ -2486,7 +2458,12 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
2486 | /* HC is busted, give up! */ | 2458 | /* HC is busted, give up! */ |
2487 | xhci_err(xhci, | 2459 | xhci_err(xhci, |
2488 | "ERROR Transfer event TRB DMA ptr not " | 2460 | "ERROR Transfer event TRB DMA ptr not " |
2489 | "part of current TD\n"); | 2461 | "part of current TD ep_index %d " |
2462 | "comp_code %u\n", ep_index, | ||
2463 | trb_comp_code); | ||
2464 | trb_in_td(xhci, ep_ring->deq_seg, | ||
2465 | ep_ring->dequeue, td->last_trb, | ||
2466 | event_dma, true); | ||
2490 | return -ESHUTDOWN; | 2467 | return -ESHUTDOWN; |
2491 | } | 2468 | } |
2492 | 2469 | ||
@@ -3926,14 +3903,11 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, | |||
3926 | trb_slot_id | trb_ep_index | type | trb_suspend, false); | 3903 | trb_slot_id | trb_ep_index | type | trb_suspend, false); |
3927 | } | 3904 | } |
3928 | 3905 | ||
3929 | /* Set Transfer Ring Dequeue Pointer command. | 3906 | /* Set Transfer Ring Dequeue Pointer command */ |
3930 | * This should not be used for endpoints that have streams enabled. | 3907 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
3931 | */ | 3908 | unsigned int slot_id, unsigned int ep_index, |
3932 | static int queue_set_tr_deq(struct xhci_hcd *xhci, struct xhci_command *cmd, | 3909 | unsigned int stream_id, |
3933 | int slot_id, | 3910 | struct xhci_dequeue_state *deq_state) |
3934 | unsigned int ep_index, unsigned int stream_id, | ||
3935 | struct xhci_segment *deq_seg, | ||
3936 | union xhci_trb *deq_ptr, u32 cycle_state) | ||
3937 | { | 3911 | { |
3938 | dma_addr_t addr; | 3912 | dma_addr_t addr; |
3939 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); | 3913 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); |
@@ -3942,28 +3916,59 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, struct xhci_command *cmd, | |||
3942 | u32 trb_sct = 0; | 3916 | u32 trb_sct = 0; |
3943 | u32 type = TRB_TYPE(TRB_SET_DEQ); | 3917 | u32 type = TRB_TYPE(TRB_SET_DEQ); |
3944 | struct xhci_virt_ep *ep; | 3918 | struct xhci_virt_ep *ep; |
3919 | struct xhci_command *cmd; | ||
3920 | int ret; | ||
3945 | 3921 | ||
3946 | addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); | 3922 | xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, |
3923 | "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), new deq ptr = %p (0x%llx dma), new cycle = %u", | ||
3924 | deq_state->new_deq_seg, | ||
3925 | (unsigned long long)deq_state->new_deq_seg->dma, | ||
3926 | deq_state->new_deq_ptr, | ||
3927 | (unsigned long long)xhci_trb_virt_to_dma( | ||
3928 | deq_state->new_deq_seg, deq_state->new_deq_ptr), | ||
3929 | deq_state->new_cycle_state); | ||
3930 | |||
3931 | addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg, | ||
3932 | deq_state->new_deq_ptr); | ||
3947 | if (addr == 0) { | 3933 | if (addr == 0) { |
3948 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); | 3934 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); |
3949 | xhci_warn(xhci, "WARN deq seg = %p, deq pt = %p\n", | 3935 | xhci_warn(xhci, "WARN deq seg = %p, deq pt = %p\n", |
3950 | deq_seg, deq_ptr); | 3936 | deq_state->new_deq_seg, deq_state->new_deq_ptr); |
3951 | return 0; | 3937 | return; |
3952 | } | 3938 | } |
3953 | ep = &xhci->devs[slot_id]->eps[ep_index]; | 3939 | ep = &xhci->devs[slot_id]->eps[ep_index]; |
3954 | if ((ep->ep_state & SET_DEQ_PENDING)) { | 3940 | if ((ep->ep_state & SET_DEQ_PENDING)) { |
3955 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); | 3941 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); |
3956 | xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); | 3942 | xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); |
3957 | return 0; | 3943 | return; |
3944 | } | ||
3945 | |||
3946 | /* This function gets called from contexts where it cannot sleep */ | ||
3947 | cmd = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
3948 | if (!cmd) { | ||
3949 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr: ENOMEM\n"); | ||
3950 | return; | ||
3958 | } | 3951 | } |
3959 | ep->queued_deq_seg = deq_seg; | 3952 | |
3960 | ep->queued_deq_ptr = deq_ptr; | 3953 | ep->queued_deq_seg = deq_state->new_deq_seg; |
3954 | ep->queued_deq_ptr = deq_state->new_deq_ptr; | ||
3961 | if (stream_id) | 3955 | if (stream_id) |
3962 | trb_sct = SCT_FOR_TRB(SCT_PRI_TR); | 3956 | trb_sct = SCT_FOR_TRB(SCT_PRI_TR); |
3963 | return queue_command(xhci, cmd, | 3957 | ret = queue_command(xhci, cmd, |
3964 | lower_32_bits(addr) | trb_sct | cycle_state, | 3958 | lower_32_bits(addr) | trb_sct | deq_state->new_cycle_state, |
3965 | upper_32_bits(addr), trb_stream_id, | 3959 | upper_32_bits(addr), trb_stream_id, |
3966 | trb_slot_id | trb_ep_index | type, false); | 3960 | trb_slot_id | trb_ep_index | type, false); |
3961 | if (ret < 0) { | ||
3962 | xhci_free_command(xhci, cmd); | ||
3963 | return; | ||
3964 | } | ||
3965 | |||
3966 | /* Stop the TD queueing code from ringing the doorbell until | ||
3967 | * this command completes. The HC won't set the dequeue pointer | ||
3968 | * if the ring is running, and ringing the doorbell starts the | ||
3969 | * ring running. | ||
3970 | */ | ||
3971 | ep->ep_state |= SET_DEQ_PENDING; | ||
3967 | } | 3972 | } |
3968 | 3973 | ||
3969 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, | 3974 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, |
diff --git a/drivers/usb/host/xhci-trace.c b/drivers/usb/host/xhci-trace.c index 7cf30c83dcf3..367b630bdb3c 100644 --- a/drivers/usb/host/xhci-trace.c +++ b/drivers/usb/host/xhci-trace.c | |||
@@ -13,3 +13,5 @@ | |||
13 | 13 | ||
14 | #define CREATE_TRACE_POINTS | 14 | #define CREATE_TRACE_POINTS |
15 | #include "xhci-trace.h" | 15 | #include "xhci-trace.h" |
16 | |||
17 | EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_quirks); | ||
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index c4a8fca8ae93..2a5d45b4cb15 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -491,7 +491,7 @@ static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci) | |||
491 | * Systems: | 491 | * Systems: |
492 | * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820 | 492 | * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820 |
493 | */ | 493 | */ |
494 | bool xhci_compliance_mode_recovery_timer_quirk_check(void) | 494 | static bool xhci_compliance_mode_recovery_timer_quirk_check(void) |
495 | { | 495 | { |
496 | const char *dmi_product_name, *dmi_sys_vendor; | 496 | const char *dmi_product_name, *dmi_sys_vendor; |
497 | 497 | ||
@@ -653,6 +653,7 @@ int xhci_run(struct usb_hcd *hcd) | |||
653 | "Finished xhci_run for USB2 roothub"); | 653 | "Finished xhci_run for USB2 roothub"); |
654 | return 0; | 654 | return 0; |
655 | } | 655 | } |
656 | EXPORT_SYMBOL_GPL(xhci_run); | ||
656 | 657 | ||
657 | static void xhci_only_stop_hcd(struct usb_hcd *hcd) | 658 | static void xhci_only_stop_hcd(struct usb_hcd *hcd) |
658 | { | 659 | { |
@@ -871,6 +872,8 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
871 | xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); | 872 | xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); |
872 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 873 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
873 | del_timer_sync(&hcd->rh_timer); | 874 | del_timer_sync(&hcd->rh_timer); |
875 | clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); | ||
876 | del_timer_sync(&xhci->shared_hcd->rh_timer); | ||
874 | 877 | ||
875 | spin_lock_irq(&xhci->lock); | 878 | spin_lock_irq(&xhci->lock); |
876 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 879 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
@@ -927,6 +930,7 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
927 | 930 | ||
928 | return rc; | 931 | return rc; |
929 | } | 932 | } |
933 | EXPORT_SYMBOL_GPL(xhci_suspend); | ||
930 | 934 | ||
931 | /* | 935 | /* |
932 | * start xHC (not bus-specific) | 936 | * start xHC (not bus-specific) |
@@ -1075,9 +1079,12 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
1075 | xhci_dbg(xhci, "%s: starting port polling.\n", __func__); | 1079 | xhci_dbg(xhci, "%s: starting port polling.\n", __func__); |
1076 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 1080 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
1077 | usb_hcd_poll_rh_status(hcd); | 1081 | usb_hcd_poll_rh_status(hcd); |
1082 | set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); | ||
1083 | usb_hcd_poll_rh_status(xhci->shared_hcd); | ||
1078 | 1084 | ||
1079 | return retval; | 1085 | return retval; |
1080 | } | 1086 | } |
1087 | EXPORT_SYMBOL_GPL(xhci_resume); | ||
1081 | #endif /* CONFIG_PM */ | 1088 | #endif /* CONFIG_PM */ |
1082 | 1089 | ||
1083 | /*-------------------------------------------------------------------------*/ | 1090 | /*-------------------------------------------------------------------------*/ |
@@ -2887,14 +2894,9 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, | |||
2887 | * issue a configure endpoint command later. | 2894 | * issue a configure endpoint command later. |
2888 | */ | 2895 | */ |
2889 | if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { | 2896 | if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { |
2890 | struct xhci_command *command; | ||
2891 | /* Can't sleep if we're called from cleanup_halted_endpoint() */ | ||
2892 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
2893 | if (!command) | ||
2894 | return; | ||
2895 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, | 2897 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, |
2896 | "Queueing new dequeue state"); | 2898 | "Queueing new dequeue state"); |
2897 | xhci_queue_new_dequeue_state(xhci, command, udev->slot_id, | 2899 | xhci_queue_new_dequeue_state(xhci, udev->slot_id, |
2898 | ep_index, ep->stopped_stream, &deq_state); | 2900 | ep_index, ep->stopped_stream, &deq_state); |
2899 | } else { | 2901 | } else { |
2900 | /* Better hope no one uses the input context between now and the | 2902 | /* Better hope no one uses the input context between now and the |
@@ -3761,8 +3763,8 @@ disable_slot: | |||
3761 | /* | 3763 | /* |
3762 | * Issue an Address Device command and optionally send a corresponding | 3764 | * Issue an Address Device command and optionally send a corresponding |
3763 | * SetAddress request to the device. | 3765 | * SetAddress request to the device. |
3764 | * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so | 3766 | * We should be protected by the usb_address0_mutex in hub_wq's hub_port_init, |
3765 | * we should only issue and wait on one address command at the same time. | 3767 | * so we should only issue and wait on one address command at the same time. |
3766 | */ | 3768 | */ |
3767 | static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | 3769 | static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, |
3768 | enum xhci_setup_dev setup) | 3770 | enum xhci_setup_dev setup) |
@@ -4903,6 +4905,76 @@ error: | |||
4903 | kfree(xhci); | 4905 | kfree(xhci); |
4904 | return retval; | 4906 | return retval; |
4905 | } | 4907 | } |
4908 | EXPORT_SYMBOL_GPL(xhci_gen_setup); | ||
4909 | |||
4910 | static const struct hc_driver xhci_hc_driver = { | ||
4911 | .description = "xhci-hcd", | ||
4912 | .product_desc = "xHCI Host Controller", | ||
4913 | .hcd_priv_size = sizeof(struct xhci_hcd *), | ||
4914 | |||
4915 | /* | ||
4916 | * generic hardware linkage | ||
4917 | */ | ||
4918 | .irq = xhci_irq, | ||
4919 | .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, | ||
4920 | |||
4921 | /* | ||
4922 | * basic lifecycle operations | ||
4923 | */ | ||
4924 | .reset = NULL, /* set in xhci_init_driver() */ | ||
4925 | .start = xhci_run, | ||
4926 | .stop = xhci_stop, | ||
4927 | .shutdown = xhci_shutdown, | ||
4928 | |||
4929 | /* | ||
4930 | * managing i/o requests and associated device resources | ||
4931 | */ | ||
4932 | .urb_enqueue = xhci_urb_enqueue, | ||
4933 | .urb_dequeue = xhci_urb_dequeue, | ||
4934 | .alloc_dev = xhci_alloc_dev, | ||
4935 | .free_dev = xhci_free_dev, | ||
4936 | .alloc_streams = xhci_alloc_streams, | ||
4937 | .free_streams = xhci_free_streams, | ||
4938 | .add_endpoint = xhci_add_endpoint, | ||
4939 | .drop_endpoint = xhci_drop_endpoint, | ||
4940 | .endpoint_reset = xhci_endpoint_reset, | ||
4941 | .check_bandwidth = xhci_check_bandwidth, | ||
4942 | .reset_bandwidth = xhci_reset_bandwidth, | ||
4943 | .address_device = xhci_address_device, | ||
4944 | .enable_device = xhci_enable_device, | ||
4945 | .update_hub_device = xhci_update_hub_device, | ||
4946 | .reset_device = xhci_discover_or_reset_device, | ||
4947 | |||
4948 | /* | ||
4949 | * scheduling support | ||
4950 | */ | ||
4951 | .get_frame_number = xhci_get_frame, | ||
4952 | |||
4953 | /* | ||
4954 | * root hub support | ||
4955 | */ | ||
4956 | .hub_control = xhci_hub_control, | ||
4957 | .hub_status_data = xhci_hub_status_data, | ||
4958 | .bus_suspend = xhci_bus_suspend, | ||
4959 | .bus_resume = xhci_bus_resume, | ||
4960 | |||
4961 | /* | ||
4962 | * call back when device connected and addressed | ||
4963 | */ | ||
4964 | .update_device = xhci_update_device, | ||
4965 | .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, | ||
4966 | .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, | ||
4967 | .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, | ||
4968 | .find_raw_port_number = xhci_find_raw_port_number, | ||
4969 | }; | ||
4970 | |||
4971 | void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *)) | ||
4972 | { | ||
4973 | BUG_ON(!setup_fn); | ||
4974 | *drv = xhci_hc_driver; | ||
4975 | drv->reset = setup_fn; | ||
4976 | } | ||
4977 | EXPORT_SYMBOL_GPL(xhci_init_driver); | ||
4906 | 4978 | ||
4907 | MODULE_DESCRIPTION(DRIVER_DESC); | 4979 | MODULE_DESCRIPTION(DRIVER_DESC); |
4908 | MODULE_AUTHOR(DRIVER_AUTHOR); | 4980 | MODULE_AUTHOR(DRIVER_AUTHOR); |
@@ -4910,18 +4982,6 @@ MODULE_LICENSE("GPL"); | |||
4910 | 4982 | ||
4911 | static int __init xhci_hcd_init(void) | 4983 | static int __init xhci_hcd_init(void) |
4912 | { | 4984 | { |
4913 | int retval; | ||
4914 | |||
4915 | retval = xhci_register_pci(); | ||
4916 | if (retval < 0) { | ||
4917 | pr_debug("Problem registering PCI driver.\n"); | ||
4918 | return retval; | ||
4919 | } | ||
4920 | retval = xhci_register_plat(); | ||
4921 | if (retval < 0) { | ||
4922 | pr_debug("Problem registering platform driver.\n"); | ||
4923 | goto unreg_pci; | ||
4924 | } | ||
4925 | /* | 4985 | /* |
4926 | * Check the compiler generated sizes of structures that must be laid | 4986 | * Check the compiler generated sizes of structures that must be laid |
4927 | * out in specific ways for hardware access. | 4987 | * out in specific ways for hardware access. |
@@ -4940,15 +5000,5 @@ static int __init xhci_hcd_init(void) | |||
4940 | /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */ | 5000 | /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */ |
4941 | BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8); | 5001 | BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8); |
4942 | return 0; | 5002 | return 0; |
4943 | unreg_pci: | ||
4944 | xhci_unregister_pci(); | ||
4945 | return retval; | ||
4946 | } | 5003 | } |
4947 | module_init(xhci_hcd_init); | 5004 | module_init(xhci_hcd_init); |
4948 | |||
4949 | static void __exit xhci_hcd_cleanup(void) | ||
4950 | { | ||
4951 | xhci_unregister_pci(); | ||
4952 | xhci_unregister_plat(); | ||
4953 | } | ||
4954 | module_exit(xhci_hcd_cleanup); | ||
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index dace5152e179..df76d642e719 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -1731,25 +1731,6 @@ void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv); | |||
1731 | void xhci_free_command(struct xhci_hcd *xhci, | 1731 | void xhci_free_command(struct xhci_hcd *xhci, |
1732 | struct xhci_command *command); | 1732 | struct xhci_command *command); |
1733 | 1733 | ||
1734 | #ifdef CONFIG_PCI | ||
1735 | /* xHCI PCI glue */ | ||
1736 | int xhci_register_pci(void); | ||
1737 | void xhci_unregister_pci(void); | ||
1738 | #else | ||
1739 | static inline int xhci_register_pci(void) { return 0; } | ||
1740 | static inline void xhci_unregister_pci(void) {} | ||
1741 | #endif | ||
1742 | |||
1743 | #if IS_ENABLED(CONFIG_USB_XHCI_PLATFORM) | ||
1744 | int xhci_register_plat(void); | ||
1745 | void xhci_unregister_plat(void); | ||
1746 | #else | ||
1747 | static inline int xhci_register_plat(void) | ||
1748 | { return 0; } | ||
1749 | static inline void xhci_unregister_plat(void) | ||
1750 | { } | ||
1751 | #endif | ||
1752 | |||
1753 | /* xHCI host controller glue */ | 1734 | /* xHCI host controller glue */ |
1754 | typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); | 1735 | typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); |
1755 | int xhci_handshake(struct xhci_hcd *xhci, void __iomem *ptr, | 1736 | int xhci_handshake(struct xhci_hcd *xhci, void __iomem *ptr, |
@@ -1762,6 +1743,7 @@ int xhci_run(struct usb_hcd *hcd); | |||
1762 | void xhci_stop(struct usb_hcd *hcd); | 1743 | void xhci_stop(struct usb_hcd *hcd); |
1763 | void xhci_shutdown(struct usb_hcd *hcd); | 1744 | void xhci_shutdown(struct usb_hcd *hcd); |
1764 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); | 1745 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); |
1746 | void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *)); | ||
1765 | 1747 | ||
1766 | #ifdef CONFIG_PM | 1748 | #ifdef CONFIG_PM |
1767 | int xhci_suspend(struct xhci_hcd *xhci); | 1749 | int xhci_suspend(struct xhci_hcd *xhci); |
@@ -1804,9 +1786,9 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); | |||
1804 | 1786 | ||
1805 | /* xHCI ring, segment, TRB, and TD functions */ | 1787 | /* xHCI ring, segment, TRB, and TD functions */ |
1806 | dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); | 1788 | dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); |
1807 | struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, | 1789 | struct xhci_segment *trb_in_td(struct xhci_hcd *xhci, |
1808 | union xhci_trb *start_trb, union xhci_trb *end_trb, | 1790 | struct xhci_segment *start_seg, union xhci_trb *start_trb, |
1809 | dma_addr_t suspect_dma); | 1791 | union xhci_trb *end_trb, dma_addr_t suspect_dma, bool debug); |
1810 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); | 1792 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); |
1811 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); | 1793 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); |
1812 | int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, | 1794 | int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, |
@@ -1839,7 +1821,6 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | |||
1839 | unsigned int stream_id, struct xhci_td *cur_td, | 1821 | unsigned int stream_id, struct xhci_td *cur_td, |
1840 | struct xhci_dequeue_state *state); | 1822 | struct xhci_dequeue_state *state); |
1841 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | 1823 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
1842 | struct xhci_command *cmd, | ||
1843 | unsigned int slot_id, unsigned int ep_index, | 1824 | unsigned int slot_id, unsigned int ep_index, |
1844 | unsigned int stream_id, | 1825 | unsigned int stream_id, |
1845 | struct xhci_dequeue_state *deq_state); | 1826 | struct xhci_dequeue_state *deq_state); |
@@ -1887,7 +1868,4 @@ struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, | |||
1887 | struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); | 1868 | struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx); |
1888 | struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index); | 1869 | struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index); |
1889 | 1870 | ||
1890 | /* xHCI quirks */ | ||
1891 | bool xhci_compliance_mode_recovery_timer_quirk_check(void); | ||
1892 | |||
1893 | #endif /* __LINUX_XHCI_HCD_H */ | 1871 | #endif /* __LINUX_XHCI_HCD_H */ |
diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c index 7d589c156fb1..62cb8cd08403 100644 --- a/drivers/usb/misc/lvstest.c +++ b/drivers/usb/misc/lvstest.c | |||
@@ -333,13 +333,13 @@ static void lvs_rh_work(struct work_struct *work) | |||
333 | USB_PORT_STAT_CONNECTION) { | 333 | USB_PORT_STAT_CONNECTION) { |
334 | lvs->present = true; | 334 | lvs->present = true; |
335 | lvs->portnum = i; | 335 | lvs->portnum = i; |
336 | if (hcd->phy) | 336 | if (hcd->usb_phy) |
337 | usb_phy_notify_connect(hcd->phy, | 337 | usb_phy_notify_connect(hcd->usb_phy, |
338 | USB_SPEED_SUPER); | 338 | USB_SPEED_SUPER); |
339 | } else { | 339 | } else { |
340 | lvs->present = false; | 340 | lvs->present = false; |
341 | if (hcd->phy) | 341 | if (hcd->usb_phy) |
342 | usb_phy_notify_disconnect(hcd->phy, | 342 | usb_phy_notify_disconnect(hcd->usb_phy, |
343 | USB_SPEED_SUPER); | 343 | USB_SPEED_SUPER); |
344 | } | 344 | } |
345 | break; | 345 | break; |
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index 47cb143716a1..ae7e1206ca54 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c | |||
@@ -98,7 +98,7 @@ static int usb3503_connect(struct usb3503 *hub) | |||
98 | return err; | 98 | return err; |
99 | } | 99 | } |
100 | 100 | ||
101 | /* PDS : Disable For Self Powered Operation */ | 101 | /* PDS : Set the ports which are disabled in self-powered mode. */ |
102 | if (hub->port_off_mask) { | 102 | if (hub->port_off_mask) { |
103 | err = regmap_update_bits(hub->regmap, USB3503_PDS, | 103 | err = regmap_update_bits(hub->regmap, USB3503_PDS, |
104 | hub->port_off_mask, | 104 | hub->port_off_mask, |
@@ -109,7 +109,7 @@ static int usb3503_connect(struct usb3503 *hub) | |||
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | /* CFG1 : SELF_BUS_PWR -> Self-Powerd operation */ | 112 | /* CFG1 : Set SELF_BUS_PWR, this enables self-powered operation. */ |
113 | err = regmap_update_bits(hub->regmap, USB3503_CFG1, | 113 | err = regmap_update_bits(hub->regmap, USB3503_CFG1, |
114 | USB3503_SELF_BUS_PWR, | 114 | USB3503_SELF_BUS_PWR, |
115 | USB3503_SELF_BUS_PWR); | 115 | USB3503_SELF_BUS_PWR); |
@@ -271,7 +271,7 @@ static int usb3503_probe(struct usb3503 *hub) | |||
271 | "usb3503 intn"); | 271 | "usb3503 intn"); |
272 | if (err) { | 272 | if (err) { |
273 | dev_err(dev, | 273 | dev_err(dev, |
274 | "unable to request GPIO %d as connect pin (%d)\n", | 274 | "unable to request GPIO %d as interrupt pin (%d)\n", |
275 | hub->gpio_intn, err); | 275 | hub->gpio_intn, err); |
276 | return err; | 276 | return err; |
277 | } | 277 | } |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index 829f446064ea..0bbafe795a72 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -54,6 +54,7 @@ struct usbtest_info { | |||
54 | unsigned autoconf:1; | 54 | unsigned autoconf:1; |
55 | unsigned ctrl_out:1; | 55 | unsigned ctrl_out:1; |
56 | unsigned iso:1; /* try iso in/out */ | 56 | unsigned iso:1; /* try iso in/out */ |
57 | unsigned intr:1; /* try interrupt in/out */ | ||
57 | int alt; | 58 | int alt; |
58 | }; | 59 | }; |
59 | 60 | ||
@@ -70,7 +71,10 @@ struct usbtest_dev { | |||
70 | int out_pipe; | 71 | int out_pipe; |
71 | int in_iso_pipe; | 72 | int in_iso_pipe; |
72 | int out_iso_pipe; | 73 | int out_iso_pipe; |
74 | int in_int_pipe; | ||
75 | int out_int_pipe; | ||
73 | struct usb_endpoint_descriptor *iso_in, *iso_out; | 76 | struct usb_endpoint_descriptor *iso_in, *iso_out; |
77 | struct usb_endpoint_descriptor *int_in, *int_out; | ||
74 | struct mutex lock; | 78 | struct mutex lock; |
75 | 79 | ||
76 | #define TBUF_SIZE 256 | 80 | #define TBUF_SIZE 256 |
@@ -101,6 +105,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) | |||
101 | struct usb_host_interface *alt; | 105 | struct usb_host_interface *alt; |
102 | struct usb_host_endpoint *in, *out; | 106 | struct usb_host_endpoint *in, *out; |
103 | struct usb_host_endpoint *iso_in, *iso_out; | 107 | struct usb_host_endpoint *iso_in, *iso_out; |
108 | struct usb_host_endpoint *int_in, *int_out; | ||
104 | struct usb_device *udev; | 109 | struct usb_device *udev; |
105 | 110 | ||
106 | for (tmp = 0; tmp < intf->num_altsetting; tmp++) { | 111 | for (tmp = 0; tmp < intf->num_altsetting; tmp++) { |
@@ -108,6 +113,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) | |||
108 | 113 | ||
109 | in = out = NULL; | 114 | in = out = NULL; |
110 | iso_in = iso_out = NULL; | 115 | iso_in = iso_out = NULL; |
116 | int_in = int_out = NULL; | ||
111 | alt = intf->altsetting + tmp; | 117 | alt = intf->altsetting + tmp; |
112 | 118 | ||
113 | if (override_alt >= 0 && | 119 | if (override_alt >= 0 && |
@@ -124,6 +130,9 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) | |||
124 | switch (usb_endpoint_type(&e->desc)) { | 130 | switch (usb_endpoint_type(&e->desc)) { |
125 | case USB_ENDPOINT_XFER_BULK: | 131 | case USB_ENDPOINT_XFER_BULK: |
126 | break; | 132 | break; |
133 | case USB_ENDPOINT_XFER_INT: | ||
134 | if (dev->info->intr) | ||
135 | goto try_intr; | ||
127 | case USB_ENDPOINT_XFER_ISOC: | 136 | case USB_ENDPOINT_XFER_ISOC: |
128 | if (dev->info->iso) | 137 | if (dev->info->iso) |
129 | goto try_iso; | 138 | goto try_iso; |
@@ -139,6 +148,15 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) | |||
139 | out = e; | 148 | out = e; |
140 | } | 149 | } |
141 | continue; | 150 | continue; |
151 | try_intr: | ||
152 | if (usb_endpoint_dir_in(&e->desc)) { | ||
153 | if (!int_in) | ||
154 | int_in = e; | ||
155 | } else { | ||
156 | if (!int_out) | ||
157 | int_out = e; | ||
158 | } | ||
159 | continue; | ||
142 | try_iso: | 160 | try_iso: |
143 | if (usb_endpoint_dir_in(&e->desc)) { | 161 | if (usb_endpoint_dir_in(&e->desc)) { |
144 | if (!iso_in) | 162 | if (!iso_in) |
@@ -148,7 +166,7 @@ try_iso: | |||
148 | iso_out = e; | 166 | iso_out = e; |
149 | } | 167 | } |
150 | } | 168 | } |
151 | if ((in && out) || iso_in || iso_out) | 169 | if ((in && out) || iso_in || iso_out || int_in || int_out) |
152 | goto found; | 170 | goto found; |
153 | } | 171 | } |
154 | return -EINVAL; | 172 | return -EINVAL; |
@@ -183,6 +201,20 @@ found: | |||
183 | iso_out->desc.bEndpointAddress | 201 | iso_out->desc.bEndpointAddress |
184 | & USB_ENDPOINT_NUMBER_MASK); | 202 | & USB_ENDPOINT_NUMBER_MASK); |
185 | } | 203 | } |
204 | |||
205 | if (int_in) { | ||
206 | dev->int_in = &int_in->desc; | ||
207 | dev->in_int_pipe = usb_rcvintpipe(udev, | ||
208 | int_in->desc.bEndpointAddress | ||
209 | & USB_ENDPOINT_NUMBER_MASK); | ||
210 | } | ||
211 | |||
212 | if (int_out) { | ||
213 | dev->int_out = &int_out->desc; | ||
214 | dev->out_int_pipe = usb_sndintpipe(udev, | ||
215 | int_out->desc.bEndpointAddress | ||
216 | & USB_ENDPOINT_NUMBER_MASK); | ||
217 | } | ||
186 | return 0; | 218 | return 0; |
187 | } | 219 | } |
188 | 220 | ||
@@ -205,14 +237,22 @@ static struct urb *usbtest_alloc_urb( | |||
205 | int pipe, | 237 | int pipe, |
206 | unsigned long bytes, | 238 | unsigned long bytes, |
207 | unsigned transfer_flags, | 239 | unsigned transfer_flags, |
208 | unsigned offset) | 240 | unsigned offset, |
241 | u8 bInterval) | ||
209 | { | 242 | { |
210 | struct urb *urb; | 243 | struct urb *urb; |
211 | 244 | ||
212 | urb = usb_alloc_urb(0, GFP_KERNEL); | 245 | urb = usb_alloc_urb(0, GFP_KERNEL); |
213 | if (!urb) | 246 | if (!urb) |
214 | return urb; | 247 | return urb; |
215 | usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL); | 248 | |
249 | if (bInterval) | ||
250 | usb_fill_int_urb(urb, udev, pipe, NULL, bytes, simple_callback, | ||
251 | NULL, bInterval); | ||
252 | else | ||
253 | usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, | ||
254 | NULL); | ||
255 | |||
216 | urb->interval = (udev->speed == USB_SPEED_HIGH) | 256 | urb->interval = (udev->speed == USB_SPEED_HIGH) |
217 | ? (INTERRUPT_RATE << 3) | 257 | ? (INTERRUPT_RATE << 3) |
218 | : INTERRUPT_RATE; | 258 | : INTERRUPT_RATE; |
@@ -251,9 +291,11 @@ static struct urb *usbtest_alloc_urb( | |||
251 | static struct urb *simple_alloc_urb( | 291 | static struct urb *simple_alloc_urb( |
252 | struct usb_device *udev, | 292 | struct usb_device *udev, |
253 | int pipe, | 293 | int pipe, |
254 | unsigned long bytes) | 294 | unsigned long bytes, |
295 | u8 bInterval) | ||
255 | { | 296 | { |
256 | return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0); | 297 | return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0, |
298 | bInterval); | ||
257 | } | 299 | } |
258 | 300 | ||
259 | static unsigned pattern; | 301 | static unsigned pattern; |
@@ -1255,7 +1297,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) | |||
1255 | goto cleanup; | 1297 | goto cleanup; |
1256 | } | 1298 | } |
1257 | req.wLength = cpu_to_le16(len); | 1299 | req.wLength = cpu_to_le16(len); |
1258 | urb[i] = u = simple_alloc_urb(udev, pipe, len); | 1300 | urb[i] = u = simple_alloc_urb(udev, pipe, len, 0); |
1259 | if (!u) | 1301 | if (!u) |
1260 | goto cleanup; | 1302 | goto cleanup; |
1261 | 1303 | ||
@@ -1328,7 +1370,7 @@ static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async) | |||
1328 | int retval = 0; | 1370 | int retval = 0; |
1329 | 1371 | ||
1330 | init_completion(&completion); | 1372 | init_completion(&completion); |
1331 | urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size); | 1373 | urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size, 0); |
1332 | if (!urb) | 1374 | if (!urb) |
1333 | return -ENOMEM; | 1375 | return -ENOMEM; |
1334 | urb->context = &completion; | 1376 | urb->context = &completion; |
@@ -1616,9 +1658,9 @@ static int halt_simple(struct usbtest_dev *dev) | |||
1616 | struct usb_device *udev = testdev_to_usbdev(dev); | 1658 | struct usb_device *udev = testdev_to_usbdev(dev); |
1617 | 1659 | ||
1618 | if (udev->speed == USB_SPEED_SUPER) | 1660 | if (udev->speed == USB_SPEED_SUPER) |
1619 | urb = simple_alloc_urb(udev, 0, 1024); | 1661 | urb = simple_alloc_urb(udev, 0, 1024, 0); |
1620 | else | 1662 | else |
1621 | urb = simple_alloc_urb(udev, 0, 512); | 1663 | urb = simple_alloc_urb(udev, 0, 512, 0); |
1622 | if (urb == NULL) | 1664 | if (urb == NULL) |
1623 | return -ENOMEM; | 1665 | return -ENOMEM; |
1624 | 1666 | ||
@@ -1962,7 +2004,7 @@ static int test_unaligned_bulk( | |||
1962 | { | 2004 | { |
1963 | int retval; | 2005 | int retval; |
1964 | struct urb *urb = usbtest_alloc_urb( | 2006 | struct urb *urb = usbtest_alloc_urb( |
1965 | testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1); | 2007 | testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1, 0); |
1966 | 2008 | ||
1967 | if (!urb) | 2009 | if (!urb) |
1968 | return -ENOMEM; | 2010 | return -ENOMEM; |
@@ -1989,7 +2031,7 @@ static int test_unaligned_bulk( | |||
1989 | * | 2031 | * |
1990 | * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), | 2032 | * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), |
1991 | * it locks out usbcore in certain code paths. Notably, if you disconnect | 2033 | * it locks out usbcore in certain code paths. Notably, if you disconnect |
1992 | * the device-under-test, khubd will wait block forever waiting for the | 2034 | * the device-under-test, hub_wq will wait block forever waiting for the |
1993 | * ioctl to complete ... so that usb_disconnect() can abort the pending | 2035 | * ioctl to complete ... so that usb_disconnect() can abort the pending |
1994 | * urbs and then call usbtest_disconnect(). To abort a test, you're best | 2036 | * urbs and then call usbtest_disconnect(). To abort a test, you're best |
1995 | * off just killing the userspace task and waiting for it to exit. | 2037 | * off just killing the userspace task and waiting for it to exit. |
@@ -2068,7 +2110,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
2068 | dev_info(&intf->dev, | 2110 | dev_info(&intf->dev, |
2069 | "TEST 1: write %d bytes %u times\n", | 2111 | "TEST 1: write %d bytes %u times\n", |
2070 | param->length, param->iterations); | 2112 | param->length, param->iterations); |
2071 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length); | 2113 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); |
2072 | if (!urb) { | 2114 | if (!urb) { |
2073 | retval = -ENOMEM; | 2115 | retval = -ENOMEM; |
2074 | break; | 2116 | break; |
@@ -2083,7 +2125,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
2083 | dev_info(&intf->dev, | 2125 | dev_info(&intf->dev, |
2084 | "TEST 2: read %d bytes %u times\n", | 2126 | "TEST 2: read %d bytes %u times\n", |
2085 | param->length, param->iterations); | 2127 | param->length, param->iterations); |
2086 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length); | 2128 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); |
2087 | if (!urb) { | 2129 | if (!urb) { |
2088 | retval = -ENOMEM; | 2130 | retval = -ENOMEM; |
2089 | break; | 2131 | break; |
@@ -2098,7 +2140,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
2098 | dev_info(&intf->dev, | 2140 | dev_info(&intf->dev, |
2099 | "TEST 3: write/%d 0..%d bytes %u times\n", | 2141 | "TEST 3: write/%d 0..%d bytes %u times\n", |
2100 | param->vary, param->length, param->iterations); | 2142 | param->vary, param->length, param->iterations); |
2101 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length); | 2143 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); |
2102 | if (!urb) { | 2144 | if (!urb) { |
2103 | retval = -ENOMEM; | 2145 | retval = -ENOMEM; |
2104 | break; | 2146 | break; |
@@ -2114,7 +2156,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
2114 | dev_info(&intf->dev, | 2156 | dev_info(&intf->dev, |
2115 | "TEST 4: read/%d 0..%d bytes %u times\n", | 2157 | "TEST 4: read/%d 0..%d bytes %u times\n", |
2116 | param->vary, param->length, param->iterations); | 2158 | param->vary, param->length, param->iterations); |
2117 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length); | 2159 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); |
2118 | if (!urb) { | 2160 | if (!urb) { |
2119 | retval = -ENOMEM; | 2161 | retval = -ENOMEM; |
2120 | break; | 2162 | break; |
@@ -2411,6 +2453,39 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
2411 | } | 2453 | } |
2412 | break; | 2454 | break; |
2413 | 2455 | ||
2456 | /* Simple non-queued interrupt I/O tests */ | ||
2457 | case 25: | ||
2458 | if (dev->out_int_pipe == 0) | ||
2459 | break; | ||
2460 | dev_info(&intf->dev, | ||
2461 | "TEST 25: write %d bytes %u times\n", | ||
2462 | param->length, param->iterations); | ||
2463 | urb = simple_alloc_urb(udev, dev->out_int_pipe, param->length, | ||
2464 | dev->int_out->bInterval); | ||
2465 | if (!urb) { | ||
2466 | retval = -ENOMEM; | ||
2467 | break; | ||
2468 | } | ||
2469 | /* FIRMWARE: interrupt sink (maybe accepts short writes) */ | ||
2470 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test25"); | ||
2471 | simple_free_urb(urb); | ||
2472 | break; | ||
2473 | case 26: | ||
2474 | if (dev->in_int_pipe == 0) | ||
2475 | break; | ||
2476 | dev_info(&intf->dev, | ||
2477 | "TEST 26: read %d bytes %u times\n", | ||
2478 | param->length, param->iterations); | ||
2479 | urb = simple_alloc_urb(udev, dev->in_int_pipe, param->length, | ||
2480 | dev->int_in->bInterval); | ||
2481 | if (!urb) { | ||
2482 | retval = -ENOMEM; | ||
2483 | break; | ||
2484 | } | ||
2485 | /* FIRMWARE: interrupt source (maybe generates short writes) */ | ||
2486 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test26"); | ||
2487 | simple_free_urb(urb); | ||
2488 | break; | ||
2414 | } | 2489 | } |
2415 | do_gettimeofday(¶m->duration); | 2490 | do_gettimeofday(¶m->duration); |
2416 | param->duration.tv_sec -= start.tv_sec; | 2491 | param->duration.tv_sec -= start.tv_sec; |
@@ -2447,6 +2522,7 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
2447 | struct usbtest_info *info; | 2522 | struct usbtest_info *info; |
2448 | char *rtest, *wtest; | 2523 | char *rtest, *wtest; |
2449 | char *irtest, *iwtest; | 2524 | char *irtest, *iwtest; |
2525 | char *intrtest, *intwtest; | ||
2450 | 2526 | ||
2451 | udev = interface_to_usbdev(intf); | 2527 | udev = interface_to_usbdev(intf); |
2452 | 2528 | ||
@@ -2487,6 +2563,7 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
2487 | */ | 2563 | */ |
2488 | rtest = wtest = ""; | 2564 | rtest = wtest = ""; |
2489 | irtest = iwtest = ""; | 2565 | irtest = iwtest = ""; |
2566 | intrtest = intwtest = ""; | ||
2490 | if (force_interrupt || udev->speed == USB_SPEED_LOW) { | 2567 | if (force_interrupt || udev->speed == USB_SPEED_LOW) { |
2491 | if (info->ep_in) { | 2568 | if (info->ep_in) { |
2492 | dev->in_pipe = usb_rcvintpipe(udev, info->ep_in); | 2569 | dev->in_pipe = usb_rcvintpipe(udev, info->ep_in); |
@@ -2525,15 +2602,20 @@ usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
2525 | irtest = " iso-in"; | 2602 | irtest = " iso-in"; |
2526 | if (dev->out_iso_pipe) | 2603 | if (dev->out_iso_pipe) |
2527 | iwtest = " iso-out"; | 2604 | iwtest = " iso-out"; |
2605 | if (dev->in_int_pipe) | ||
2606 | intrtest = " int-in"; | ||
2607 | if (dev->out_int_pipe) | ||
2608 | intwtest = " int-out"; | ||
2528 | } | 2609 | } |
2529 | 2610 | ||
2530 | usb_set_intfdata(intf, dev); | 2611 | usb_set_intfdata(intf, dev); |
2531 | dev_info(&intf->dev, "%s\n", info->name); | 2612 | dev_info(&intf->dev, "%s\n", info->name); |
2532 | dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n", | 2613 | dev_info(&intf->dev, "%s {control%s%s%s%s%s%s%s} tests%s\n", |
2533 | usb_speed_string(udev->speed), | 2614 | usb_speed_string(udev->speed), |
2534 | info->ctrl_out ? " in/out" : "", | 2615 | info->ctrl_out ? " in/out" : "", |
2535 | rtest, wtest, | 2616 | rtest, wtest, |
2536 | irtest, iwtest, | 2617 | irtest, iwtest, |
2618 | intrtest, intwtest, | ||
2537 | info->alt >= 0 ? " (+alt)" : ""); | 2619 | info->alt >= 0 ? " (+alt)" : ""); |
2538 | return 0; | 2620 | return 0; |
2539 | } | 2621 | } |
@@ -2607,6 +2689,7 @@ static struct usbtest_info gz_info = { | |||
2607 | .autoconf = 1, | 2689 | .autoconf = 1, |
2608 | .ctrl_out = 1, | 2690 | .ctrl_out = 1, |
2609 | .iso = 1, | 2691 | .iso = 1, |
2692 | .intr = 1, | ||
2610 | .alt = 0, | 2693 | .alt = 0, |
2611 | }; | 2694 | }; |
2612 | 2695 | ||
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c index 1472805083de..c3a45da11610 100644 --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c | |||
@@ -358,7 +358,7 @@ static int yurex_fasync(int fd, struct file *file, int on) | |||
358 | { | 358 | { |
359 | struct usb_yurex *dev; | 359 | struct usb_yurex *dev; |
360 | 360 | ||
361 | dev = (struct usb_yurex *)file->private_data; | 361 | dev = file->private_data; |
362 | return fasync_helper(fd, file, on, &dev->async_queue); | 362 | return fasync_helper(fd, file, on, &dev->async_queue); |
363 | } | 363 | } |
364 | 364 | ||
@@ -401,7 +401,7 @@ static int yurex_release(struct inode *inode, struct file *file) | |||
401 | { | 401 | { |
402 | struct usb_yurex *dev; | 402 | struct usb_yurex *dev; |
403 | 403 | ||
404 | dev = (struct usb_yurex *)file->private_data; | 404 | dev = file->private_data; |
405 | if (dev == NULL) | 405 | if (dev == NULL) |
406 | return -ENODEV; | 406 | return -ENODEV; |
407 | 407 | ||
@@ -418,7 +418,7 @@ static ssize_t yurex_read(struct file *file, char *buffer, size_t count, loff_t | |||
418 | char in_buffer[20]; | 418 | char in_buffer[20]; |
419 | unsigned long flags; | 419 | unsigned long flags; |
420 | 420 | ||
421 | dev = (struct usb_yurex *)file->private_data; | 421 | dev = file->private_data; |
422 | 422 | ||
423 | mutex_lock(&dev->io_mutex); | 423 | mutex_lock(&dev->io_mutex); |
424 | if (!dev->interface) { /* already disconnected */ | 424 | if (!dev->interface) { /* already disconnected */ |
@@ -455,7 +455,7 @@ static ssize_t yurex_write(struct file *file, const char *user_buffer, size_t co | |||
455 | DEFINE_WAIT(wait); | 455 | DEFINE_WAIT(wait); |
456 | 456 | ||
457 | count = min(sizeof(buffer), count); | 457 | count = min(sizeof(buffer), count); |
458 | dev = (struct usb_yurex *)file->private_data; | 458 | dev = file->private_data; |
459 | 459 | ||
460 | /* verify that we actually have some data to write */ | 460 | /* verify that we actually have some data to write */ |
461 | if (count == 0) | 461 | if (count == 0) |
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index 0a34dd859555..a2735df24cc6 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -1,3 +1,4 @@ | |||
1 | |||
1 | /* | 2 | /* |
2 | * Texas Instruments AM35x "glue layer" | 3 | * Texas Instruments AM35x "glue layer" |
3 | * | 4 | * |
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index 3ee133f675ab..acdfb3e68a90 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c | |||
@@ -212,7 +212,7 @@ static enum hrtimer_restart cppi41_recheck_tx_req(struct hrtimer *timer) | |||
212 | if (!list_empty(&controller->early_tx_list)) { | 212 | if (!list_empty(&controller->early_tx_list)) { |
213 | ret = HRTIMER_RESTART; | 213 | ret = HRTIMER_RESTART; |
214 | hrtimer_forward_now(&controller->early_tx, | 214 | hrtimer_forward_now(&controller->early_tx, |
215 | ktime_set(0, 50 * NSEC_PER_USEC)); | 215 | ktime_set(0, 20 * NSEC_PER_USEC)); |
216 | } | 216 | } |
217 | 217 | ||
218 | spin_unlock_irqrestore(&musb->lock, flags); | 218 | spin_unlock_irqrestore(&musb->lock, flags); |
@@ -290,7 +290,7 @@ static void cppi41_dma_callback(void *private_data) | |||
290 | 290 | ||
291 | hrtimer_start_range_ns(&controller->early_tx, | 291 | hrtimer_start_range_ns(&controller->early_tx, |
292 | ktime_set(0, usecs * NSEC_PER_USEC), | 292 | ktime_set(0, usecs * NSEC_PER_USEC), |
293 | 40 * NSEC_PER_USEC, | 293 | 20 * NSEC_PER_USEC, |
294 | HRTIMER_MODE_REL); | 294 | HRTIMER_MODE_REL); |
295 | } | 295 | } |
296 | } | 296 | } |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index c791ba5da91a..154bcf1b5dfa 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -870,6 +870,7 @@ static int dsps_suspend(struct device *dev) | |||
870 | struct musb *musb = platform_get_drvdata(glue->musb); | 870 | struct musb *musb = platform_get_drvdata(glue->musb); |
871 | void __iomem *mbase = musb->ctrl_base; | 871 | void __iomem *mbase = musb->ctrl_base; |
872 | 872 | ||
873 | del_timer_sync(&glue->timer); | ||
873 | glue->context.control = dsps_readl(mbase, wrp->control); | 874 | glue->context.control = dsps_readl(mbase, wrp->control); |
874 | glue->context.epintr = dsps_readl(mbase, wrp->epintr_set); | 875 | glue->context.epintr = dsps_readl(mbase, wrp->epintr_set); |
875 | glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set); | 876 | glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set); |
@@ -895,6 +896,7 @@ static int dsps_resume(struct device *dev) | |||
895 | dsps_writel(mbase, wrp->mode, glue->context.mode); | 896 | dsps_writel(mbase, wrp->mode, glue->context.mode); |
896 | dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); | 897 | dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); |
897 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); | 898 | dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); |
899 | setup_timer(&glue->timer, otg_timer, (unsigned long) musb); | ||
898 | 900 | ||
899 | return 0; | 901 | return 0; |
900 | } | 902 | } |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index d4aa779339f1..24c8c0219790 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -176,7 +176,7 @@ __acquires(ep->musb->lock) | |||
176 | ep->end_point.name, request, | 176 | ep->end_point.name, request, |
177 | req->request.actual, req->request.length, | 177 | req->request.actual, req->request.length, |
178 | request->status); | 178 | request->status); |
179 | req->request.complete(&req->ep->end_point, &req->request); | 179 | usb_gadget_giveback_request(&req->ep->end_point, &req->request); |
180 | spin_lock(&musb->lock); | 180 | spin_lock(&musb->lock); |
181 | ep->busy = busy; | 181 | ep->busy = busy; |
182 | } | 182 | } |
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h index b9bcda5e3945..37122a480bc1 100644 --- a/drivers/usb/musb/musb_regs.h +++ b/drivers/usb/musb/musb_regs.h | |||
@@ -577,7 +577,7 @@ static inline u16 musb_read_hwvers(void __iomem *mbase) | |||
577 | { | 577 | { |
578 | /* | 578 | /* |
579 | * This register is invisible on Blackfin, actually the MUSB | 579 | * This register is invisible on Blackfin, actually the MUSB |
580 | * RTL version of Blackfin is 1.9, so just harcode its value. | 580 | * RTL version of Blackfin is 1.9, so just hardcode its value. |
581 | */ | 581 | */ |
582 | return MUSB_HWVERS_1900; | 582 | return MUSB_HWVERS_1900; |
583 | } | 583 | } |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 7dfc6cb732c9..2daa779f1382 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -433,7 +433,7 @@ static void musb_do_idle(unsigned long _musb) | |||
433 | if (!musb->is_active) { | 433 | if (!musb->is_active) { |
434 | u32 wakeups; | 434 | u32 wakeups; |
435 | 435 | ||
436 | /* wait until khubd handles port change status */ | 436 | /* wait until hub_wq handles port change status */ |
437 | if (is_host_active(musb) && (musb->port1_status >> 16)) | 437 | if (is_host_active(musb) && (musb->port1_status >> 16)) |
438 | goto done; | 438 | goto done; |
439 | 439 | ||
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index e253fa05be68..0cd1f44f0ee8 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -78,22 +78,6 @@ config SAMSUNG_USBPHY | |||
78 | This driver provides common interface to interact, for Samsung USB 2.0 PHY | 78 | This driver provides common interface to interact, for Samsung USB 2.0 PHY |
79 | driver and later for Samsung USB 3.0 PHY driver. | 79 | driver and later for Samsung USB 3.0 PHY driver. |
80 | 80 | ||
81 | config SAMSUNG_USB2PHY | ||
82 | tristate "Samsung USB 2.0 PHY controller Driver" | ||
83 | select SAMSUNG_USBPHY | ||
84 | select USB_PHY | ||
85 | help | ||
86 | Enable this to support Samsung USB 2.0 (High Speed) PHY controller | ||
87 | driver for Samsung SoCs. | ||
88 | |||
89 | config SAMSUNG_USB3PHY | ||
90 | tristate "Samsung USB 3.0 PHY controller Driver" | ||
91 | select SAMSUNG_USBPHY | ||
92 | select USB_PHY | ||
93 | help | ||
94 | Enable this to support Samsung USB 3.0 (Super Speed) phy controller | ||
95 | for samsung SoCs. | ||
96 | |||
97 | config TWL6030_USB | 81 | config TWL6030_USB |
98 | tristate "TWL6030 USB Transceiver Driver" | 82 | tristate "TWL6030 USB Transceiver Driver" |
99 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS | 83 | depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS |
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index 24a91332d4ad..75f2bba58c84 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -15,8 +15,6 @@ obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o | |||
15 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o | 15 | obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o |
16 | obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o | 16 | obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o |
17 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o | 17 | obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o |
18 | obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o | ||
19 | obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o | ||
20 | obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o | 18 | obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o |
21 | obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o | 19 | obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o |
22 | obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o | 20 | obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o |
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c index 2b0f968d9325..f1ea5990a50a 100644 --- a/drivers/usb/phy/phy-fsl-usb.c +++ b/drivers/usb/phy/phy-fsl-usb.c | |||
@@ -609,7 +609,7 @@ static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
609 | otg->host->otg_port = fsl_otg_initdata.otg_port; | 609 | otg->host->otg_port = fsl_otg_initdata.otg_port; |
610 | otg->host->is_b_host = otg_dev->fsm.id; | 610 | otg->host->is_b_host = otg_dev->fsm.id; |
611 | /* | 611 | /* |
612 | * must leave time for khubd to finish its thing | 612 | * must leave time for hub_wq to finish its thing |
613 | * before yanking the host driver out from under it, | 613 | * before yanking the host driver out from under it, |
614 | * so suspend the host after a short delay. | 614 | * so suspend the host after a short delay. |
615 | */ | 615 | */ |
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c index 69e49be8866b..8eea56d3ded6 100644 --- a/drivers/usb/phy/phy-isp1301-omap.c +++ b/drivers/usb/phy/phy-isp1301-omap.c | |||
@@ -1011,7 +1011,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat) | |||
1011 | break; | 1011 | break; |
1012 | case OTG_STATE_A_WAIT_VFALL: | 1012 | case OTG_STATE_A_WAIT_VFALL: |
1013 | state = OTG_STATE_A_IDLE; | 1013 | state = OTG_STATE_A_IDLE; |
1014 | /* khubd may take a while to notice and | 1014 | /* hub_wq may take a while to notice and |
1015 | * handle this disconnect, so don't go | 1015 | * handle this disconnect, so don't go |
1016 | * to B_IDLE quite yet. | 1016 | * to B_IDLE quite yet. |
1017 | */ | 1017 | */ |
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index afc09087ec36..7843ef7dd0ff 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
@@ -281,7 +281,7 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg) | |||
281 | { | 281 | { |
282 | int ret = 0; | 282 | int ret = 0; |
283 | 283 | ||
284 | if (motg->pdata->phy_clk_reset && motg->phy_reset_clk) | 284 | if (motg->pdata->phy_clk_reset) |
285 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); | 285 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); |
286 | else if (motg->phy_rst) | 286 | else if (motg->phy_rst) |
287 | ret = reset_control_reset(motg->phy_rst); | 287 | ret = reset_control_reset(motg->phy_rst); |
@@ -1394,7 +1394,7 @@ out: | |||
1394 | return status; | 1394 | return status; |
1395 | } | 1395 | } |
1396 | 1396 | ||
1397 | const struct file_operations msm_otg_mode_fops = { | 1397 | static const struct file_operations msm_otg_mode_fops = { |
1398 | .open = msm_otg_mode_open, | 1398 | .open = msm_otg_mode_open, |
1399 | .read = seq_read, | 1399 | .read = seq_read, |
1400 | .write = msm_otg_mode_write, | 1400 | .write = msm_otg_mode_write, |
@@ -1554,11 +1554,14 @@ static int msm_otg_probe(struct platform_device *pdev) | |||
1554 | phy = &motg->phy; | 1554 | phy = &motg->phy; |
1555 | phy->dev = &pdev->dev; | 1555 | phy->dev = &pdev->dev; |
1556 | 1556 | ||
1557 | motg->phy_reset_clk = devm_clk_get(&pdev->dev, | 1557 | if (motg->pdata->phy_clk_reset) { |
1558 | motg->phy_reset_clk = devm_clk_get(&pdev->dev, | ||
1558 | np ? "phy" : "usb_phy_clk"); | 1559 | np ? "phy" : "usb_phy_clk"); |
1559 | if (IS_ERR(motg->phy_reset_clk)) { | 1560 | |
1560 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); | 1561 | if (IS_ERR(motg->phy_reset_clk)) { |
1561 | motg->phy_reset_clk = NULL; | 1562 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); |
1563 | return PTR_ERR(motg->phy_reset_clk); | ||
1564 | } | ||
1562 | } | 1565 | } |
1563 | 1566 | ||
1564 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); | 1567 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); |
@@ -1838,7 +1841,6 @@ static struct platform_driver msm_otg_driver = { | |||
1838 | .remove = msm_otg_remove, | 1841 | .remove = msm_otg_remove, |
1839 | .driver = { | 1842 | .driver = { |
1840 | .name = DRIVER_NAME, | 1843 | .name = DRIVER_NAME, |
1841 | .owner = THIS_MODULE, | ||
1842 | .pm = &msm_otg_dev_pm_ops, | 1844 | .pm = &msm_otg_dev_pm_ops, |
1843 | .of_match_table = msm_otg_dt_match, | 1845 | .of_match_table = msm_otg_dt_match, |
1844 | }, | 1846 | }, |
diff --git a/drivers/usb/phy/phy-mxs-usb.c b/drivers/usb/phy/phy-mxs-usb.c index 00972eca04e7..0e0c41587a08 100644 --- a/drivers/usb/phy/phy-mxs-usb.c +++ b/drivers/usb/phy/phy-mxs-usb.c | |||
@@ -125,6 +125,11 @@ static const struct mxs_phy_data imx6sl_phy_data = { | |||
125 | MXS_PHY_NEED_IP_FIX, | 125 | MXS_PHY_NEED_IP_FIX, |
126 | }; | 126 | }; |
127 | 127 | ||
128 | static const struct mxs_phy_data vf610_phy_data = { | ||
129 | .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | | ||
130 | MXS_PHY_NEED_IP_FIX, | ||
131 | }; | ||
132 | |||
128 | static const struct mxs_phy_data imx6sx_phy_data = { | 133 | static const struct mxs_phy_data imx6sx_phy_data = { |
129 | .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | | 134 | .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | |
130 | MXS_PHY_NEED_IP_FIX, | 135 | MXS_PHY_NEED_IP_FIX, |
@@ -135,6 +140,7 @@ static const struct of_device_id mxs_phy_dt_ids[] = { | |||
135 | { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, | 140 | { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, |
136 | { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, }, | 141 | { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, }, |
137 | { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, }, | 142 | { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, }, |
143 | { .compatible = "fsl,vf610-usbphy", .data = &vf610_phy_data, }, | ||
138 | { /* sentinel */ } | 144 | { /* sentinel */ } |
139 | }; | 145 | }; |
140 | MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids); | 146 | MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids); |
diff --git a/drivers/usb/phy/phy-samsung-usb.c b/drivers/usb/phy/phy-samsung-usb.c deleted file mode 100644 index ac025ca08425..000000000000 --- a/drivers/usb/phy/phy-samsung-usb.c +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb.c | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Praveen Paneri <p.paneri@samsung.com> | ||
7 | * | ||
8 | * Samsung USB-PHY helper driver with common function calls; | ||
9 | * interacts with Samsung USB 2.0 PHY controller driver and later | ||
10 | * with Samsung USB 3.0 PHY driver. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License version 2 as | ||
14 | * published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/of_address.h> | ||
30 | #include <linux/usb/samsung_usb_phy.h> | ||
31 | |||
32 | #include "phy-samsung-usb.h" | ||
33 | |||
34 | int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy) | ||
35 | { | ||
36 | struct device_node *usbphy_sys; | ||
37 | |||
38 | /* Getting node for system controller interface for usb-phy */ | ||
39 | usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys"); | ||
40 | if (!usbphy_sys) { | ||
41 | dev_err(sphy->dev, "No sys-controller interface for usb-phy\n"); | ||
42 | return -ENODEV; | ||
43 | } | ||
44 | |||
45 | sphy->pmuregs = of_iomap(usbphy_sys, 0); | ||
46 | |||
47 | if (sphy->pmuregs == NULL) { | ||
48 | dev_err(sphy->dev, "Can't get usb-phy pmu control register\n"); | ||
49 | goto err0; | ||
50 | } | ||
51 | |||
52 | sphy->sysreg = of_iomap(usbphy_sys, 1); | ||
53 | |||
54 | /* | ||
55 | * Not returning error code here, since this situation is not fatal. | ||
56 | * Few SoCs may not have this switch available | ||
57 | */ | ||
58 | if (sphy->sysreg == NULL) | ||
59 | dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n"); | ||
60 | |||
61 | of_node_put(usbphy_sys); | ||
62 | |||
63 | return 0; | ||
64 | |||
65 | err0: | ||
66 | of_node_put(usbphy_sys); | ||
67 | return -ENXIO; | ||
68 | } | ||
69 | EXPORT_SYMBOL_GPL(samsung_usbphy_parse_dt); | ||
70 | |||
71 | /* | ||
72 | * Set isolation here for phy. | ||
73 | * Here 'on = true' would mean USB PHY block is isolated, hence | ||
74 | * de-activated and vice-versa. | ||
75 | */ | ||
76 | void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, bool on) | ||
77 | { | ||
78 | void __iomem *reg = NULL; | ||
79 | u32 reg_val; | ||
80 | u32 en_mask = 0; | ||
81 | |||
82 | if (!sphy->pmuregs) { | ||
83 | dev_warn(sphy->dev, "Can't set pmu isolation\n"); | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { | ||
88 | reg = sphy->pmuregs + sphy->drv_data->devphy_reg_offset; | ||
89 | en_mask = sphy->drv_data->devphy_en_mask; | ||
90 | } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { | ||
91 | reg = sphy->pmuregs + sphy->drv_data->hostphy_reg_offset; | ||
92 | en_mask = sphy->drv_data->hostphy_en_mask; | ||
93 | } | ||
94 | |||
95 | reg_val = readl(reg); | ||
96 | |||
97 | if (on) | ||
98 | reg_val &= ~en_mask; | ||
99 | else | ||
100 | reg_val |= en_mask; | ||
101 | |||
102 | writel(reg_val, reg); | ||
103 | |||
104 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) { | ||
105 | writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL0); | ||
106 | writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL1); | ||
107 | } | ||
108 | } | ||
109 | EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation_4210); | ||
110 | |||
111 | /* | ||
112 | * Configure the mode of working of usb-phy here: HOST/DEVICE. | ||
113 | */ | ||
114 | void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy) | ||
115 | { | ||
116 | u32 reg; | ||
117 | |||
118 | if (!sphy->sysreg) { | ||
119 | dev_warn(sphy->dev, "Can't configure specified phy mode\n"); | ||
120 | return; | ||
121 | } | ||
122 | |||
123 | reg = readl(sphy->sysreg); | ||
124 | |||
125 | if (sphy->phy_type == USB_PHY_TYPE_DEVICE) | ||
126 | reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
127 | else if (sphy->phy_type == USB_PHY_TYPE_HOST) | ||
128 | reg |= EXYNOS_USB20PHY_CFG_HOST_LINK; | ||
129 | |||
130 | writel(reg, sphy->sysreg); | ||
131 | } | ||
132 | EXPORT_SYMBOL_GPL(samsung_usbphy_cfg_sel); | ||
133 | |||
134 | /* | ||
135 | * PHYs are different for USB Device and USB Host. | ||
136 | * This make sure that correct PHY type is selected before | ||
137 | * any operation on PHY. | ||
138 | */ | ||
139 | int samsung_usbphy_set_type(struct usb_phy *phy, | ||
140 | enum samsung_usb_phy_type phy_type) | ||
141 | { | ||
142 | struct samsung_usbphy *sphy = phy_to_sphy(phy); | ||
143 | |||
144 | sphy->phy_type = phy_type; | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | EXPORT_SYMBOL_GPL(samsung_usbphy_set_type); | ||
149 | |||
150 | int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, | ||
151 | unsigned long rate) | ||
152 | { | ||
153 | unsigned int clksel; | ||
154 | |||
155 | switch (rate) { | ||
156 | case 12 * MHZ: | ||
157 | clksel = PHYCLK_CLKSEL_12M; | ||
158 | break; | ||
159 | case 24 * MHZ: | ||
160 | clksel = PHYCLK_CLKSEL_24M; | ||
161 | break; | ||
162 | case 48 * MHZ: | ||
163 | clksel = PHYCLK_CLKSEL_48M; | ||
164 | break; | ||
165 | default: | ||
166 | dev_err(sphy->dev, | ||
167 | "Invalid reference clock frequency: %lu\n", rate); | ||
168 | return -EINVAL; | ||
169 | } | ||
170 | |||
171 | return clksel; | ||
172 | } | ||
173 | EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_64xx); | ||
174 | |||
175 | int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, | ||
176 | unsigned long rate) | ||
177 | { | ||
178 | unsigned int clksel; | ||
179 | |||
180 | switch (rate) { | ||
181 | case 9600 * KHZ: | ||
182 | clksel = FSEL_CLKSEL_9600K; | ||
183 | break; | ||
184 | case 10 * MHZ: | ||
185 | clksel = FSEL_CLKSEL_10M; | ||
186 | break; | ||
187 | case 12 * MHZ: | ||
188 | clksel = FSEL_CLKSEL_12M; | ||
189 | break; | ||
190 | case 19200 * KHZ: | ||
191 | clksel = FSEL_CLKSEL_19200K; | ||
192 | break; | ||
193 | case 20 * MHZ: | ||
194 | clksel = FSEL_CLKSEL_20M; | ||
195 | break; | ||
196 | case 24 * MHZ: | ||
197 | clksel = FSEL_CLKSEL_24M; | ||
198 | break; | ||
199 | case 50 * MHZ: | ||
200 | clksel = FSEL_CLKSEL_50M; | ||
201 | break; | ||
202 | default: | ||
203 | dev_err(sphy->dev, | ||
204 | "Invalid reference clock frequency: %lu\n", rate); | ||
205 | return -EINVAL; | ||
206 | } | ||
207 | |||
208 | return clksel; | ||
209 | } | ||
210 | EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_4x12); | ||
211 | |||
212 | /* | ||
213 | * Returns reference clock frequency selection value | ||
214 | */ | ||
215 | int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) | ||
216 | { | ||
217 | struct clk *ref_clk; | ||
218 | unsigned long rate; | ||
219 | int refclk_freq; | ||
220 | |||
221 | /* | ||
222 | * In exynos5250 USB host and device PHY use | ||
223 | * external crystal clock XXTI | ||
224 | */ | ||
225 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) | ||
226 | ref_clk = clk_get(sphy->dev, "ext_xtal"); | ||
227 | else | ||
228 | ref_clk = clk_get(sphy->dev, "xusbxti"); | ||
229 | if (IS_ERR(ref_clk)) { | ||
230 | dev_err(sphy->dev, "Failed to get reference clock\n"); | ||
231 | return PTR_ERR(ref_clk); | ||
232 | } | ||
233 | |||
234 | rate = clk_get_rate(ref_clk); | ||
235 | refclk_freq = sphy->drv_data->rate_to_clksel(sphy, rate); | ||
236 | |||
237 | clk_put(ref_clk); | ||
238 | |||
239 | return refclk_freq; | ||
240 | } | ||
241 | EXPORT_SYMBOL_GPL(samsung_usbphy_get_refclk_freq); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb.h b/drivers/usb/phy/phy-samsung-usb.h deleted file mode 100644 index 80eedd45a20a..000000000000 --- a/drivers/usb/phy/phy-samsung-usb.h +++ /dev/null | |||
@@ -1,349 +0,0 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb.h | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Samsung USB-PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and | ||
7 | * OHCI-EXYNOS controllers. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License version 2 as | ||
11 | * published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | */ | ||
18 | |||
19 | #include <linux/usb/phy.h> | ||
20 | |||
21 | /* Register definitions */ | ||
22 | |||
23 | #define SAMSUNG_PHYPWR (0x00) | ||
24 | |||
25 | #define PHYPWR_NORMAL_MASK (0x19 << 0) | ||
26 | #define PHYPWR_OTG_DISABLE (0x1 << 4) | ||
27 | #define PHYPWR_ANALOG_POWERDOWN (0x1 << 3) | ||
28 | #define PHYPWR_FORCE_SUSPEND (0x1 << 1) | ||
29 | /* For Exynos4 */ | ||
30 | #define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0) | ||
31 | #define PHYPWR_SLEEP_PHY0 (0x1 << 5) | ||
32 | |||
33 | #define SAMSUNG_PHYCLK (0x04) | ||
34 | |||
35 | #define PHYCLK_MODE_USB11 (0x1 << 6) | ||
36 | #define PHYCLK_EXT_OSC (0x1 << 5) | ||
37 | #define PHYCLK_COMMON_ON_N (0x1 << 4) | ||
38 | #define PHYCLK_ID_PULL (0x1 << 2) | ||
39 | #define PHYCLK_CLKSEL_MASK (0x3 << 0) | ||
40 | #define PHYCLK_CLKSEL_48M (0x0 << 0) | ||
41 | #define PHYCLK_CLKSEL_12M (0x2 << 0) | ||
42 | #define PHYCLK_CLKSEL_24M (0x3 << 0) | ||
43 | |||
44 | #define SAMSUNG_RSTCON (0x08) | ||
45 | |||
46 | #define RSTCON_PHYLINK_SWRST (0x1 << 2) | ||
47 | #define RSTCON_HLINK_SWRST (0x1 << 1) | ||
48 | #define RSTCON_SWRST (0x1 << 0) | ||
49 | |||
50 | /* EXYNOS4X12 */ | ||
51 | #define EXYNOS4X12_PHY_HSIC_CTRL0 (0x04) | ||
52 | #define EXYNOS4X12_PHY_HSIC_CTRL1 (0x08) | ||
53 | |||
54 | #define PHYPWR_NORMAL_MASK_HSIC1 (0x7 << 12) | ||
55 | #define PHYPWR_NORMAL_MASK_HSIC0 (0x7 << 9) | ||
56 | #define PHYPWR_NORMAL_MASK_PHY1 (0x7 << 6) | ||
57 | |||
58 | #define RSTCON_HOSTPHY_SWRST (0xf << 3) | ||
59 | |||
60 | /* EXYNOS5 */ | ||
61 | #define EXYNOS5_PHY_HOST_CTRL0 (0x00) | ||
62 | |||
63 | #define HOST_CTRL0_PHYSWRSTALL (0x1 << 31) | ||
64 | |||
65 | #define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19) | ||
66 | #define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19) | ||
67 | #define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19) | ||
68 | #define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19) | ||
69 | |||
70 | #define HOST_CTRL0_FSEL_MASK (0x7 << 16) | ||
71 | #define HOST_CTRL0_FSEL(_x) ((_x) << 16) | ||
72 | |||
73 | #define FSEL_CLKSEL_50M (0x7) | ||
74 | #define FSEL_CLKSEL_24M (0x5) | ||
75 | #define FSEL_CLKSEL_20M (0x4) | ||
76 | #define FSEL_CLKSEL_19200K (0x3) | ||
77 | #define FSEL_CLKSEL_12M (0x2) | ||
78 | #define FSEL_CLKSEL_10M (0x1) | ||
79 | #define FSEL_CLKSEL_9600K (0x0) | ||
80 | |||
81 | #define HOST_CTRL0_TESTBURNIN (0x1 << 11) | ||
82 | #define HOST_CTRL0_RETENABLE (0x1 << 10) | ||
83 | #define HOST_CTRL0_COMMONON_N (0x1 << 9) | ||
84 | #define HOST_CTRL0_SIDDQ (0x1 << 6) | ||
85 | #define HOST_CTRL0_FORCESLEEP (0x1 << 5) | ||
86 | #define HOST_CTRL0_FORCESUSPEND (0x1 << 4) | ||
87 | #define HOST_CTRL0_WORDINTERFACE (0x1 << 3) | ||
88 | #define HOST_CTRL0_UTMISWRST (0x1 << 2) | ||
89 | #define HOST_CTRL0_LINKSWRST (0x1 << 1) | ||
90 | #define HOST_CTRL0_PHYSWRST (0x1 << 0) | ||
91 | |||
92 | #define EXYNOS5_PHY_HOST_TUNE0 (0x04) | ||
93 | |||
94 | #define EXYNOS5_PHY_HSIC_CTRL1 (0x10) | ||
95 | |||
96 | #define EXYNOS5_PHY_HSIC_TUNE1 (0x14) | ||
97 | |||
98 | #define EXYNOS5_PHY_HSIC_CTRL2 (0x20) | ||
99 | |||
100 | #define EXYNOS5_PHY_HSIC_TUNE2 (0x24) | ||
101 | |||
102 | #define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23) | ||
103 | #define HSIC_CTRL_REFCLKSEL (0x2 << 23) | ||
104 | |||
105 | #define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16) | ||
106 | #define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16) | ||
107 | #define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16) | ||
108 | #define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16) | ||
109 | #define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16) | ||
110 | #define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16) | ||
111 | #define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16) | ||
112 | |||
113 | #define HSIC_CTRL_SIDDQ (0x1 << 6) | ||
114 | #define HSIC_CTRL_FORCESLEEP (0x1 << 5) | ||
115 | #define HSIC_CTRL_FORCESUSPEND (0x1 << 4) | ||
116 | #define HSIC_CTRL_WORDINTERFACE (0x1 << 3) | ||
117 | #define HSIC_CTRL_UTMISWRST (0x1 << 2) | ||
118 | #define HSIC_CTRL_PHYSWRST (0x1 << 0) | ||
119 | |||
120 | #define EXYNOS5_PHY_HOST_EHCICTRL (0x30) | ||
121 | |||
122 | #define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29) | ||
123 | #define HOST_EHCICTRL_ENAINCR4 (0x1 << 28) | ||
124 | #define HOST_EHCICTRL_ENAINCR8 (0x1 << 27) | ||
125 | #define HOST_EHCICTRL_ENAINCR16 (0x1 << 26) | ||
126 | |||
127 | #define EXYNOS5_PHY_HOST_OHCICTRL (0x34) | ||
128 | |||
129 | #define HOST_OHCICTRL_SUSPLGCY (0x1 << 3) | ||
130 | #define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2) | ||
131 | #define HOST_OHCICTRL_CNTSEL (0x1 << 1) | ||
132 | #define HOST_OHCICTRL_CLKCKTRST (0x1 << 0) | ||
133 | |||
134 | #define EXYNOS5_PHY_OTG_SYS (0x38) | ||
135 | |||
136 | #define OTG_SYS_PHYLINK_SWRESET (0x1 << 14) | ||
137 | #define OTG_SYS_LINKSWRST_UOTG (0x1 << 13) | ||
138 | #define OTG_SYS_PHY0_SWRST (0x1 << 12) | ||
139 | |||
140 | #define OTG_SYS_REFCLKSEL_MASK (0x3 << 9) | ||
141 | #define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9) | ||
142 | #define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9) | ||
143 | #define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9) | ||
144 | |||
145 | #define OTG_SYS_IDPULLUP_UOTG (0x1 << 8) | ||
146 | #define OTG_SYS_COMMON_ON (0x1 << 7) | ||
147 | |||
148 | #define OTG_SYS_FSEL_MASK (0x7 << 4) | ||
149 | #define OTG_SYS_FSEL(_x) ((_x) << 4) | ||
150 | |||
151 | #define OTG_SYS_FORCESLEEP (0x1 << 3) | ||
152 | #define OTG_SYS_OTGDISABLE (0x1 << 2) | ||
153 | #define OTG_SYS_SIDDQ_UOTG (0x1 << 1) | ||
154 | #define OTG_SYS_FORCESUSPEND (0x1 << 0) | ||
155 | |||
156 | #define EXYNOS5_PHY_OTG_TUNE (0x40) | ||
157 | |||
158 | /* EXYNOS5: USB 3.0 DRD */ | ||
159 | #define EXYNOS5_DRD_LINKSYSTEM (0x04) | ||
160 | |||
161 | #define LINKSYSTEM_FLADJ_MASK (0x3f << 1) | ||
162 | #define LINKSYSTEM_FLADJ(_x) ((_x) << 1) | ||
163 | #define LINKSYSTEM_XHCI_VERSION_CONTROL (0x1 << 27) | ||
164 | |||
165 | #define EXYNOS5_DRD_PHYUTMI (0x08) | ||
166 | |||
167 | #define PHYUTMI_OTGDISABLE (0x1 << 6) | ||
168 | #define PHYUTMI_FORCESUSPEND (0x1 << 1) | ||
169 | #define PHYUTMI_FORCESLEEP (0x1 << 0) | ||
170 | |||
171 | #define EXYNOS5_DRD_PHYPIPE (0x0c) | ||
172 | |||
173 | #define EXYNOS5_DRD_PHYCLKRST (0x10) | ||
174 | |||
175 | #define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23) | ||
176 | #define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23) | ||
177 | |||
178 | #define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21) | ||
179 | #define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21) | ||
180 | |||
181 | #define PHYCLKRST_SSC_EN (0x1 << 20) | ||
182 | #define PHYCLKRST_REF_SSP_EN (0x1 << 19) | ||
183 | #define PHYCLKRST_REF_CLKDIV2 (0x1 << 18) | ||
184 | |||
185 | #define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11) | ||
186 | #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11) | ||
187 | #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x02 << 11) | ||
188 | #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11) | ||
189 | #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11) | ||
190 | #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11) | ||
191 | |||
192 | #define PHYCLKRST_FSEL_MASK (0x3f << 5) | ||
193 | #define PHYCLKRST_FSEL(_x) ((_x) << 5) | ||
194 | #define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5) | ||
195 | #define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5) | ||
196 | #define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5) | ||
197 | #define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5) | ||
198 | |||
199 | #define PHYCLKRST_RETENABLEN (0x1 << 4) | ||
200 | |||
201 | #define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2) | ||
202 | #define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2) | ||
203 | #define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2) | ||
204 | |||
205 | #define PHYCLKRST_PORTRESET (0x1 << 1) | ||
206 | #define PHYCLKRST_COMMONONN (0x1 << 0) | ||
207 | |||
208 | #define EXYNOS5_DRD_PHYREG0 (0x14) | ||
209 | #define EXYNOS5_DRD_PHYREG1 (0x18) | ||
210 | |||
211 | #define EXYNOS5_DRD_PHYPARAM0 (0x1c) | ||
212 | |||
213 | #define PHYPARAM0_REF_USE_PAD (0x1 << 31) | ||
214 | #define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26) | ||
215 | #define PHYPARAM0_REF_LOSLEVEL (0x9 << 26) | ||
216 | |||
217 | #define EXYNOS5_DRD_PHYPARAM1 (0x20) | ||
218 | |||
219 | #define PHYPARAM1_PCS_TXDEEMPH_MASK (0x3f << 0) | ||
220 | #define PHYPARAM1_PCS_TXDEEMPH (0x1c) | ||
221 | |||
222 | #define EXYNOS5_DRD_PHYTERM (0x24) | ||
223 | |||
224 | #define EXYNOS5_DRD_PHYTEST (0x28) | ||
225 | |||
226 | #define PHYTEST_POWERDOWN_SSP (0x1 << 3) | ||
227 | #define PHYTEST_POWERDOWN_HSP (0x1 << 2) | ||
228 | |||
229 | #define EXYNOS5_DRD_PHYADP (0x2c) | ||
230 | |||
231 | #define EXYNOS5_DRD_PHYBATCHG (0x30) | ||
232 | |||
233 | #define PHYBATCHG_UTMI_CLKSEL (0x1 << 2) | ||
234 | |||
235 | #define EXYNOS5_DRD_PHYRESUME (0x34) | ||
236 | #define EXYNOS5_DRD_LINKPORT (0x44) | ||
237 | |||
238 | #ifndef MHZ | ||
239 | #define MHZ (1000*1000) | ||
240 | #endif | ||
241 | |||
242 | #ifndef KHZ | ||
243 | #define KHZ (1000) | ||
244 | #endif | ||
245 | |||
246 | #define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4) | ||
247 | #define S3C64XX_USBPHY_ENABLE (0x1 << 16) | ||
248 | #define EXYNOS_USBPHY_ENABLE (0x1 << 0) | ||
249 | #define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0) | ||
250 | |||
251 | enum samsung_cpu_type { | ||
252 | TYPE_S3C64XX, | ||
253 | TYPE_EXYNOS4210, | ||
254 | TYPE_EXYNOS4X12, | ||
255 | TYPE_EXYNOS5250, | ||
256 | }; | ||
257 | |||
258 | struct samsung_usbphy; | ||
259 | |||
260 | /* | ||
261 | * struct samsung_usbphy_drvdata - driver data for various SoC variants | ||
262 | * @cpu_type: machine identifier | ||
263 | * @devphy_en_mask: device phy enable mask for PHY CONTROL register | ||
264 | * @hostphy_en_mask: host phy enable mask for PHY CONTROL register | ||
265 | * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from | ||
266 | * mapped address of system controller. | ||
267 | * @hostphy_reg_offset: offset to HOST PHY CONTROL register from | ||
268 | * mapped address of system controller. | ||
269 | * | ||
270 | * Here we have a separate mask for device type phy. | ||
271 | * Having different masks for host and device type phy helps | ||
272 | * in setting independent masks in case of SoCs like S5PV210, | ||
273 | * in which PHY0 and PHY1 enable bits belong to same register | ||
274 | * placed at position 0 and 1 respectively. | ||
275 | * Although for newer SoCs like exynos these bits belong to | ||
276 | * different registers altogether placed at position 0. | ||
277 | */ | ||
278 | struct samsung_usbphy_drvdata { | ||
279 | int cpu_type; | ||
280 | int devphy_en_mask; | ||
281 | int hostphy_en_mask; | ||
282 | u32 devphy_reg_offset; | ||
283 | u32 hostphy_reg_offset; | ||
284 | int (*rate_to_clksel)(struct samsung_usbphy *, unsigned long); | ||
285 | void (*set_isolation)(struct samsung_usbphy *, bool); | ||
286 | void (*phy_enable)(struct samsung_usbphy *); | ||
287 | void (*phy_disable)(struct samsung_usbphy *); | ||
288 | }; | ||
289 | |||
290 | /* | ||
291 | * struct samsung_usbphy - transceiver driver state | ||
292 | * @phy: transceiver structure | ||
293 | * @plat: platform data | ||
294 | * @dev: The parent device supplied to the probe function | ||
295 | * @clk: usb phy clock | ||
296 | * @regs: usb phy controller registers memory base | ||
297 | * @pmuregs: USB device PHY_CONTROL register memory base | ||
298 | * @sysreg: USB2.0 PHY_CFG register memory base | ||
299 | * @ref_clk_freq: reference clock frequency selection | ||
300 | * @drv_data: driver data available for different SoCs | ||
301 | * @phy_type: Samsung SoCs specific phy types: #HOST | ||
302 | * #DEVICE | ||
303 | * @phy_usage: usage count for phy | ||
304 | * @lock: lock for phy operations | ||
305 | */ | ||
306 | struct samsung_usbphy { | ||
307 | struct usb_phy phy; | ||
308 | struct samsung_usbphy_data *plat; | ||
309 | struct device *dev; | ||
310 | struct clk *clk; | ||
311 | void __iomem *regs; | ||
312 | void __iomem *pmuregs; | ||
313 | void __iomem *sysreg; | ||
314 | int ref_clk_freq; | ||
315 | const struct samsung_usbphy_drvdata *drv_data; | ||
316 | enum samsung_usb_phy_type phy_type; | ||
317 | atomic_t phy_usage; | ||
318 | spinlock_t lock; | ||
319 | }; | ||
320 | |||
321 | #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) | ||
322 | |||
323 | static const struct of_device_id samsung_usbphy_dt_match[]; | ||
324 | |||
325 | static inline const struct samsung_usbphy_drvdata | ||
326 | *samsung_usbphy_get_driver_data(struct platform_device *pdev) | ||
327 | { | ||
328 | if (pdev->dev.of_node) { | ||
329 | const struct of_device_id *match; | ||
330 | match = of_match_node(samsung_usbphy_dt_match, | ||
331 | pdev->dev.of_node); | ||
332 | return match->data; | ||
333 | } | ||
334 | |||
335 | return (struct samsung_usbphy_drvdata *) | ||
336 | platform_get_device_id(pdev)->driver_data; | ||
337 | } | ||
338 | |||
339 | extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy); | ||
340 | extern void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, | ||
341 | bool on); | ||
342 | extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy); | ||
343 | extern int samsung_usbphy_set_type(struct usb_phy *phy, | ||
344 | enum samsung_usb_phy_type phy_type); | ||
345 | extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy); | ||
346 | extern int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, | ||
347 | unsigned long rate); | ||
348 | extern int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, | ||
349 | unsigned long rate); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c deleted file mode 100644 index b3ba86627b72..000000000000 --- a/drivers/usb/phy/phy-samsung-usb2.c +++ /dev/null | |||
@@ -1,541 +0,0 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb2.c | ||
2 | * | ||
3 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Praveen Paneri <p.paneri@samsung.com> | ||
7 | * | ||
8 | * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and | ||
9 | * OHCI-EXYNOS controllers. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/clk.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/device.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/of.h> | ||
29 | #include <linux/usb/otg.h> | ||
30 | #include <linux/usb/samsung_usb_phy.h> | ||
31 | #include <linux/platform_data/samsung-usbphy.h> | ||
32 | |||
33 | #include "phy-samsung-usb.h" | ||
34 | |||
35 | static int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host) | ||
36 | { | ||
37 | if (!otg) | ||
38 | return -ENODEV; | ||
39 | |||
40 | if (!otg->host) | ||
41 | otg->host = host; | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static bool exynos5_phyhost_is_on(void __iomem *regs) | ||
47 | { | ||
48 | u32 reg; | ||
49 | |||
50 | reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
51 | |||
52 | return !(reg & HOST_CTRL0_SIDDQ); | ||
53 | } | ||
54 | |||
55 | static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy) | ||
56 | { | ||
57 | void __iomem *regs = sphy->regs; | ||
58 | u32 phyclk = sphy->ref_clk_freq; | ||
59 | u32 phyhost; | ||
60 | u32 phyotg; | ||
61 | u32 phyhsic; | ||
62 | u32 ehcictrl; | ||
63 | u32 ohcictrl; | ||
64 | |||
65 | /* | ||
66 | * phy_usage helps in keeping usage count for phy | ||
67 | * so that the first consumer enabling the phy is also | ||
68 | * the last consumer to disable it. | ||
69 | */ | ||
70 | |||
71 | atomic_inc(&sphy->phy_usage); | ||
72 | |||
73 | if (exynos5_phyhost_is_on(regs)) { | ||
74 | dev_info(sphy->dev, "Already power on PHY\n"); | ||
75 | return; | ||
76 | } | ||
77 | |||
78 | /* Host configuration */ | ||
79 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
80 | |||
81 | /* phy reference clock configuration */ | ||
82 | phyhost &= ~HOST_CTRL0_FSEL_MASK; | ||
83 | phyhost |= HOST_CTRL0_FSEL(phyclk); | ||
84 | |||
85 | /* host phy reset */ | ||
86 | phyhost &= ~(HOST_CTRL0_PHYSWRST | | ||
87 | HOST_CTRL0_PHYSWRSTALL | | ||
88 | HOST_CTRL0_SIDDQ | | ||
89 | /* Enable normal mode of operation */ | ||
90 | HOST_CTRL0_FORCESUSPEND | | ||
91 | HOST_CTRL0_FORCESLEEP); | ||
92 | |||
93 | /* Link reset */ | ||
94 | phyhost |= (HOST_CTRL0_LINKSWRST | | ||
95 | HOST_CTRL0_UTMISWRST | | ||
96 | /* COMMON Block configuration during suspend */ | ||
97 | HOST_CTRL0_COMMONON_N); | ||
98 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
99 | udelay(10); | ||
100 | phyhost &= ~(HOST_CTRL0_LINKSWRST | | ||
101 | HOST_CTRL0_UTMISWRST); | ||
102 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
103 | |||
104 | /* OTG configuration */ | ||
105 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
106 | |||
107 | /* phy reference clock configuration */ | ||
108 | phyotg &= ~OTG_SYS_FSEL_MASK; | ||
109 | phyotg |= OTG_SYS_FSEL(phyclk); | ||
110 | |||
111 | /* Enable normal mode of operation */ | ||
112 | phyotg &= ~(OTG_SYS_FORCESUSPEND | | ||
113 | OTG_SYS_SIDDQ_UOTG | | ||
114 | OTG_SYS_FORCESLEEP | | ||
115 | OTG_SYS_REFCLKSEL_MASK | | ||
116 | /* COMMON Block configuration during suspend */ | ||
117 | OTG_SYS_COMMON_ON); | ||
118 | |||
119 | /* OTG phy & link reset */ | ||
120 | phyotg |= (OTG_SYS_PHY0_SWRST | | ||
121 | OTG_SYS_LINKSWRST_UOTG | | ||
122 | OTG_SYS_PHYLINK_SWRESET | | ||
123 | OTG_SYS_OTGDISABLE | | ||
124 | /* Set phy refclk */ | ||
125 | OTG_SYS_REFCLKSEL_CLKCORE); | ||
126 | |||
127 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
128 | udelay(10); | ||
129 | phyotg &= ~(OTG_SYS_PHY0_SWRST | | ||
130 | OTG_SYS_LINKSWRST_UOTG | | ||
131 | OTG_SYS_PHYLINK_SWRESET); | ||
132 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
133 | |||
134 | /* HSIC phy configuration */ | ||
135 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
136 | HSIC_CTRL_REFCLKSEL | | ||
137 | HSIC_CTRL_PHYSWRST); | ||
138 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
139 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
140 | udelay(10); | ||
141 | phyhsic &= ~HSIC_CTRL_PHYSWRST; | ||
142 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
143 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
144 | |||
145 | udelay(80); | ||
146 | |||
147 | /* enable EHCI DMA burst */ | ||
148 | ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
149 | ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN | | ||
150 | HOST_EHCICTRL_ENAINCR4 | | ||
151 | HOST_EHCICTRL_ENAINCR8 | | ||
152 | HOST_EHCICTRL_ENAINCR16); | ||
153 | writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL); | ||
154 | |||
155 | /* set ohci_suspend_on_n */ | ||
156 | ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
157 | ohcictrl |= HOST_OHCICTRL_SUSPLGCY; | ||
158 | writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL); | ||
159 | } | ||
160 | |||
161 | static void samsung_usb2phy_enable(struct samsung_usbphy *sphy) | ||
162 | { | ||
163 | void __iomem *regs = sphy->regs; | ||
164 | u32 phypwr; | ||
165 | u32 phyclk; | ||
166 | u32 rstcon; | ||
167 | |||
168 | /* set clock frequency for PLL */ | ||
169 | phyclk = sphy->ref_clk_freq; | ||
170 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
171 | rstcon = readl(regs + SAMSUNG_RSTCON); | ||
172 | |||
173 | switch (sphy->drv_data->cpu_type) { | ||
174 | case TYPE_S3C64XX: | ||
175 | phyclk &= ~PHYCLK_COMMON_ON_N; | ||
176 | phypwr &= ~PHYPWR_NORMAL_MASK; | ||
177 | rstcon |= RSTCON_SWRST; | ||
178 | break; | ||
179 | case TYPE_EXYNOS4X12: | ||
180 | phypwr &= ~(PHYPWR_NORMAL_MASK_HSIC0 | | ||
181 | PHYPWR_NORMAL_MASK_HSIC1 | | ||
182 | PHYPWR_NORMAL_MASK_PHY1); | ||
183 | rstcon |= RSTCON_HOSTPHY_SWRST; | ||
184 | case TYPE_EXYNOS4210: | ||
185 | phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; | ||
186 | rstcon |= RSTCON_SWRST; | ||
187 | default: | ||
188 | break; | ||
189 | } | ||
190 | |||
191 | writel(phyclk, regs + SAMSUNG_PHYCLK); | ||
192 | /* Configure PHY0 for normal operation*/ | ||
193 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
194 | /* reset all ports of PHY and Link */ | ||
195 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
196 | udelay(10); | ||
197 | if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) | ||
198 | rstcon &= ~RSTCON_HOSTPHY_SWRST; | ||
199 | rstcon &= ~RSTCON_SWRST; | ||
200 | writel(rstcon, regs + SAMSUNG_RSTCON); | ||
201 | } | ||
202 | |||
203 | static void samsung_exynos5_usb2phy_disable(struct samsung_usbphy *sphy) | ||
204 | { | ||
205 | void __iomem *regs = sphy->regs; | ||
206 | u32 phyhost; | ||
207 | u32 phyotg; | ||
208 | u32 phyhsic; | ||
209 | |||
210 | if (atomic_dec_return(&sphy->phy_usage) > 0) { | ||
211 | dev_info(sphy->dev, "still being used\n"); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | phyhsic = (HSIC_CTRL_REFCLKDIV_12 | | ||
216 | HSIC_CTRL_REFCLKSEL | | ||
217 | HSIC_CTRL_SIDDQ | | ||
218 | HSIC_CTRL_FORCESLEEP | | ||
219 | HSIC_CTRL_FORCESUSPEND); | ||
220 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); | ||
221 | writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); | ||
222 | |||
223 | phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); | ||
224 | phyhost |= (HOST_CTRL0_SIDDQ | | ||
225 | HOST_CTRL0_FORCESUSPEND | | ||
226 | HOST_CTRL0_FORCESLEEP | | ||
227 | HOST_CTRL0_PHYSWRST | | ||
228 | HOST_CTRL0_PHYSWRSTALL); | ||
229 | writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); | ||
230 | |||
231 | phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); | ||
232 | phyotg |= (OTG_SYS_FORCESUSPEND | | ||
233 | OTG_SYS_SIDDQ_UOTG | | ||
234 | OTG_SYS_FORCESLEEP); | ||
235 | writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); | ||
236 | } | ||
237 | |||
238 | static void samsung_usb2phy_disable(struct samsung_usbphy *sphy) | ||
239 | { | ||
240 | void __iomem *regs = sphy->regs; | ||
241 | u32 phypwr; | ||
242 | |||
243 | phypwr = readl(regs + SAMSUNG_PHYPWR); | ||
244 | |||
245 | switch (sphy->drv_data->cpu_type) { | ||
246 | case TYPE_S3C64XX: | ||
247 | phypwr |= PHYPWR_NORMAL_MASK; | ||
248 | break; | ||
249 | case TYPE_EXYNOS4X12: | ||
250 | phypwr |= (PHYPWR_NORMAL_MASK_HSIC0 | | ||
251 | PHYPWR_NORMAL_MASK_HSIC1 | | ||
252 | PHYPWR_NORMAL_MASK_PHY1); | ||
253 | case TYPE_EXYNOS4210: | ||
254 | phypwr |= PHYPWR_NORMAL_MASK_PHY0; | ||
255 | default: | ||
256 | break; | ||
257 | } | ||
258 | |||
259 | /* Disable analog and otg block power */ | ||
260 | writel(phypwr, regs + SAMSUNG_PHYPWR); | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * The function passed to the usb driver for phy initialization | ||
265 | */ | ||
266 | static int samsung_usb2phy_init(struct usb_phy *phy) | ||
267 | { | ||
268 | struct samsung_usbphy *sphy; | ||
269 | struct usb_bus *host = NULL; | ||
270 | unsigned long flags; | ||
271 | int ret = 0; | ||
272 | |||
273 | sphy = phy_to_sphy(phy); | ||
274 | |||
275 | host = phy->otg->host; | ||
276 | |||
277 | /* Enable the phy clock */ | ||
278 | ret = clk_prepare_enable(sphy->clk); | ||
279 | if (ret) { | ||
280 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
281 | return ret; | ||
282 | } | ||
283 | |||
284 | spin_lock_irqsave(&sphy->lock, flags); | ||
285 | |||
286 | if (host) { | ||
287 | /* setting default phy-type for USB 2.0 */ | ||
288 | if (!strstr(dev_name(host->controller), "ehci") || | ||
289 | !strstr(dev_name(host->controller), "ohci")) | ||
290 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
291 | } else { | ||
292 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
293 | } | ||
294 | |||
295 | /* Disable phy isolation */ | ||
296 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
297 | sphy->plat->pmu_isolation(false); | ||
298 | else if (sphy->drv_data->set_isolation) | ||
299 | sphy->drv_data->set_isolation(sphy, false); | ||
300 | |||
301 | /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ | ||
302 | samsung_usbphy_cfg_sel(sphy); | ||
303 | |||
304 | /* Initialize usb phy registers */ | ||
305 | sphy->drv_data->phy_enable(sphy); | ||
306 | |||
307 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
308 | |||
309 | /* Disable the phy clock */ | ||
310 | clk_disable_unprepare(sphy->clk); | ||
311 | |||
312 | return ret; | ||
313 | } | ||
314 | |||
315 | /* | ||
316 | * The function passed to the usb driver for phy shutdown | ||
317 | */ | ||
318 | static void samsung_usb2phy_shutdown(struct usb_phy *phy) | ||
319 | { | ||
320 | struct samsung_usbphy *sphy; | ||
321 | struct usb_bus *host = NULL; | ||
322 | unsigned long flags; | ||
323 | |||
324 | sphy = phy_to_sphy(phy); | ||
325 | |||
326 | host = phy->otg->host; | ||
327 | |||
328 | if (clk_prepare_enable(sphy->clk)) { | ||
329 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
330 | return; | ||
331 | } | ||
332 | |||
333 | spin_lock_irqsave(&sphy->lock, flags); | ||
334 | |||
335 | if (host) { | ||
336 | /* setting default phy-type for USB 2.0 */ | ||
337 | if (!strstr(dev_name(host->controller), "ehci") || | ||
338 | !strstr(dev_name(host->controller), "ohci")) | ||
339 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); | ||
340 | } else { | ||
341 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
342 | } | ||
343 | |||
344 | /* De-initialize usb phy registers */ | ||
345 | sphy->drv_data->phy_disable(sphy); | ||
346 | |||
347 | /* Enable phy isolation */ | ||
348 | if (sphy->plat && sphy->plat->pmu_isolation) | ||
349 | sphy->plat->pmu_isolation(true); | ||
350 | else if (sphy->drv_data->set_isolation) | ||
351 | sphy->drv_data->set_isolation(sphy, true); | ||
352 | |||
353 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
354 | |||
355 | clk_disable_unprepare(sphy->clk); | ||
356 | } | ||
357 | |||
358 | static int samsung_usb2phy_probe(struct platform_device *pdev) | ||
359 | { | ||
360 | struct samsung_usbphy *sphy; | ||
361 | struct usb_otg *otg; | ||
362 | struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev); | ||
363 | const struct samsung_usbphy_drvdata *drv_data; | ||
364 | struct device *dev = &pdev->dev; | ||
365 | struct resource *phy_mem; | ||
366 | void __iomem *phy_base; | ||
367 | struct clk *clk; | ||
368 | int ret; | ||
369 | |||
370 | phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
371 | phy_base = devm_ioremap_resource(dev, phy_mem); | ||
372 | if (IS_ERR(phy_base)) | ||
373 | return PTR_ERR(phy_base); | ||
374 | |||
375 | sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); | ||
376 | if (!sphy) | ||
377 | return -ENOMEM; | ||
378 | |||
379 | otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); | ||
380 | if (!otg) | ||
381 | return -ENOMEM; | ||
382 | |||
383 | drv_data = samsung_usbphy_get_driver_data(pdev); | ||
384 | |||
385 | if (drv_data->cpu_type == TYPE_EXYNOS5250) | ||
386 | clk = devm_clk_get(dev, "usbhost"); | ||
387 | else | ||
388 | clk = devm_clk_get(dev, "otg"); | ||
389 | |||
390 | if (IS_ERR(clk)) { | ||
391 | dev_err(dev, "Failed to get usbhost/otg clock\n"); | ||
392 | return PTR_ERR(clk); | ||
393 | } | ||
394 | |||
395 | sphy->dev = dev; | ||
396 | |||
397 | if (dev->of_node) { | ||
398 | ret = samsung_usbphy_parse_dt(sphy); | ||
399 | if (ret < 0) | ||
400 | return ret; | ||
401 | } else { | ||
402 | if (!pdata) { | ||
403 | dev_err(dev, "no platform data specified\n"); | ||
404 | return -EINVAL; | ||
405 | } | ||
406 | } | ||
407 | |||
408 | sphy->plat = pdata; | ||
409 | sphy->regs = phy_base; | ||
410 | sphy->clk = clk; | ||
411 | sphy->drv_data = drv_data; | ||
412 | sphy->phy.dev = sphy->dev; | ||
413 | sphy->phy.label = "samsung-usb2phy"; | ||
414 | sphy->phy.type = USB_PHY_TYPE_USB2; | ||
415 | sphy->phy.init = samsung_usb2phy_init; | ||
416 | sphy->phy.shutdown = samsung_usb2phy_shutdown; | ||
417 | |||
418 | sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); | ||
419 | if (sphy->ref_clk_freq < 0) | ||
420 | return -EINVAL; | ||
421 | |||
422 | sphy->phy.otg = otg; | ||
423 | sphy->phy.otg->phy = &sphy->phy; | ||
424 | sphy->phy.otg->set_host = samsung_usbphy_set_host; | ||
425 | |||
426 | spin_lock_init(&sphy->lock); | ||
427 | |||
428 | platform_set_drvdata(pdev, sphy); | ||
429 | |||
430 | return usb_add_phy_dev(&sphy->phy); | ||
431 | } | ||
432 | |||
433 | static int samsung_usb2phy_remove(struct platform_device *pdev) | ||
434 | { | ||
435 | struct samsung_usbphy *sphy = platform_get_drvdata(pdev); | ||
436 | |||
437 | usb_remove_phy(&sphy->phy); | ||
438 | |||
439 | if (sphy->pmuregs) | ||
440 | iounmap(sphy->pmuregs); | ||
441 | if (sphy->sysreg) | ||
442 | iounmap(sphy->sysreg); | ||
443 | |||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = { | ||
448 | .cpu_type = TYPE_S3C64XX, | ||
449 | .devphy_en_mask = S3C64XX_USBPHY_ENABLE, | ||
450 | .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, | ||
451 | .set_isolation = NULL, /* TODO */ | ||
452 | .phy_enable = samsung_usb2phy_enable, | ||
453 | .phy_disable = samsung_usb2phy_disable, | ||
454 | }; | ||
455 | |||
456 | static const struct samsung_usbphy_drvdata usb2phy_exynos4 = { | ||
457 | .cpu_type = TYPE_EXYNOS4210, | ||
458 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
459 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
460 | .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, | ||
461 | .set_isolation = samsung_usbphy_set_isolation_4210, | ||
462 | .phy_enable = samsung_usb2phy_enable, | ||
463 | .phy_disable = samsung_usb2phy_disable, | ||
464 | }; | ||
465 | |||
466 | static const struct samsung_usbphy_drvdata usb2phy_exynos4x12 = { | ||
467 | .cpu_type = TYPE_EXYNOS4X12, | ||
468 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
469 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
470 | .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, | ||
471 | .set_isolation = samsung_usbphy_set_isolation_4210, | ||
472 | .phy_enable = samsung_usb2phy_enable, | ||
473 | .phy_disable = samsung_usb2phy_disable, | ||
474 | }; | ||
475 | |||
476 | static struct samsung_usbphy_drvdata usb2phy_exynos5 = { | ||
477 | .cpu_type = TYPE_EXYNOS5250, | ||
478 | .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
479 | .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, | ||
480 | .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, | ||
481 | .set_isolation = samsung_usbphy_set_isolation_4210, | ||
482 | .phy_enable = samsung_exynos5_usb2phy_enable, | ||
483 | .phy_disable = samsung_exynos5_usb2phy_disable, | ||
484 | }; | ||
485 | |||
486 | #ifdef CONFIG_OF | ||
487 | static const struct of_device_id samsung_usbphy_dt_match[] = { | ||
488 | { | ||
489 | .compatible = "samsung,s3c64xx-usb2phy", | ||
490 | .data = &usb2phy_s3c64xx, | ||
491 | }, { | ||
492 | .compatible = "samsung,exynos4210-usb2phy", | ||
493 | .data = &usb2phy_exynos4, | ||
494 | }, { | ||
495 | .compatible = "samsung,exynos4x12-usb2phy", | ||
496 | .data = &usb2phy_exynos4x12, | ||
497 | }, { | ||
498 | .compatible = "samsung,exynos5250-usb2phy", | ||
499 | .data = &usb2phy_exynos5 | ||
500 | }, | ||
501 | {}, | ||
502 | }; | ||
503 | MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); | ||
504 | #endif | ||
505 | |||
506 | static struct platform_device_id samsung_usbphy_driver_ids[] = { | ||
507 | { | ||
508 | .name = "s3c64xx-usb2phy", | ||
509 | .driver_data = (unsigned long)&usb2phy_s3c64xx, | ||
510 | }, { | ||
511 | .name = "exynos4210-usb2phy", | ||
512 | .driver_data = (unsigned long)&usb2phy_exynos4, | ||
513 | }, { | ||
514 | .name = "exynos4x12-usb2phy", | ||
515 | .driver_data = (unsigned long)&usb2phy_exynos4x12, | ||
516 | }, { | ||
517 | .name = "exynos5250-usb2phy", | ||
518 | .driver_data = (unsigned long)&usb2phy_exynos5, | ||
519 | }, | ||
520 | {}, | ||
521 | }; | ||
522 | |||
523 | MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); | ||
524 | |||
525 | static struct platform_driver samsung_usb2phy_driver = { | ||
526 | .probe = samsung_usb2phy_probe, | ||
527 | .remove = samsung_usb2phy_remove, | ||
528 | .id_table = samsung_usbphy_driver_ids, | ||
529 | .driver = { | ||
530 | .name = "samsung-usb2phy", | ||
531 | .owner = THIS_MODULE, | ||
532 | .of_match_table = of_match_ptr(samsung_usbphy_dt_match), | ||
533 | }, | ||
534 | }; | ||
535 | |||
536 | module_platform_driver(samsung_usb2phy_driver); | ||
537 | |||
538 | MODULE_DESCRIPTION("Samsung USB 2.0 phy controller"); | ||
539 | MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>"); | ||
540 | MODULE_LICENSE("GPL"); | ||
541 | MODULE_ALIAS("platform:samsung-usb2phy"); | ||
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c deleted file mode 100644 index cc0819248acf..000000000000 --- a/drivers/usb/phy/phy-samsung-usb3.c +++ /dev/null | |||
@@ -1,350 +0,0 @@ | |||
1 | /* linux/drivers/usb/phy/phy-samsung-usb3.c | ||
2 | * | ||
3 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
4 | * http://www.samsung.com | ||
5 | * | ||
6 | * Author: Vivek Gautam <gautam.vivek@samsung.com> | ||
7 | * | ||
8 | * Samsung USB 3.0 PHY transceiver; talks to DWC3 controller. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | */ | ||
19 | |||
20 | #include <linux/module.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/clk.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/of.h> | ||
27 | #include <linux/usb/samsung_usb_phy.h> | ||
28 | #include <linux/platform_data/samsung-usbphy.h> | ||
29 | |||
30 | #include "phy-samsung-usb.h" | ||
31 | |||
32 | /* | ||
33 | * Sets the phy clk as EXTREFCLK (XXTI) which is internal clock from clock core. | ||
34 | */ | ||
35 | static u32 samsung_usb3phy_set_refclk(struct samsung_usbphy *sphy) | ||
36 | { | ||
37 | u32 reg; | ||
38 | u32 refclk; | ||
39 | |||
40 | refclk = sphy->ref_clk_freq; | ||
41 | |||
42 | reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK | | ||
43 | PHYCLKRST_FSEL(refclk); | ||
44 | |||
45 | switch (refclk) { | ||
46 | case FSEL_CLKSEL_50M: | ||
47 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF | | ||
48 | PHYCLKRST_SSC_REFCLKSEL(0x00)); | ||
49 | break; | ||
50 | case FSEL_CLKSEL_20M: | ||
51 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF | | ||
52 | PHYCLKRST_SSC_REFCLKSEL(0x00)); | ||
53 | break; | ||
54 | case FSEL_CLKSEL_19200K: | ||
55 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF | | ||
56 | PHYCLKRST_SSC_REFCLKSEL(0x88)); | ||
57 | break; | ||
58 | case FSEL_CLKSEL_24M: | ||
59 | default: | ||
60 | reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF | | ||
61 | PHYCLKRST_SSC_REFCLKSEL(0x88)); | ||
62 | break; | ||
63 | } | ||
64 | |||
65 | return reg; | ||
66 | } | ||
67 | |||
68 | static void samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy) | ||
69 | { | ||
70 | void __iomem *regs = sphy->regs; | ||
71 | u32 phyparam0; | ||
72 | u32 phyparam1; | ||
73 | u32 linksystem; | ||
74 | u32 phybatchg; | ||
75 | u32 phytest; | ||
76 | u32 phyclkrst; | ||
77 | |||
78 | /* Reset USB 3.0 PHY */ | ||
79 | writel(0x0, regs + EXYNOS5_DRD_PHYREG0); | ||
80 | |||
81 | phyparam0 = readl(regs + EXYNOS5_DRD_PHYPARAM0); | ||
82 | /* Select PHY CLK source */ | ||
83 | phyparam0 &= ~PHYPARAM0_REF_USE_PAD; | ||
84 | /* Set Loss-of-Signal Detector sensitivity */ | ||
85 | phyparam0 &= ~PHYPARAM0_REF_LOSLEVEL_MASK; | ||
86 | phyparam0 |= PHYPARAM0_REF_LOSLEVEL; | ||
87 | writel(phyparam0, regs + EXYNOS5_DRD_PHYPARAM0); | ||
88 | |||
89 | writel(0x0, regs + EXYNOS5_DRD_PHYRESUME); | ||
90 | |||
91 | /* | ||
92 | * Setting the Frame length Adj value[6:1] to default 0x20 | ||
93 | * See xHCI 1.0 spec, 5.2.4 | ||
94 | */ | ||
95 | linksystem = LINKSYSTEM_XHCI_VERSION_CONTROL | | ||
96 | LINKSYSTEM_FLADJ(0x20); | ||
97 | writel(linksystem, regs + EXYNOS5_DRD_LINKSYSTEM); | ||
98 | |||
99 | phyparam1 = readl(regs + EXYNOS5_DRD_PHYPARAM1); | ||
100 | /* Set Tx De-Emphasis level */ | ||
101 | phyparam1 &= ~PHYPARAM1_PCS_TXDEEMPH_MASK; | ||
102 | phyparam1 |= PHYPARAM1_PCS_TXDEEMPH; | ||
103 | writel(phyparam1, regs + EXYNOS5_DRD_PHYPARAM1); | ||
104 | |||
105 | phybatchg = readl(regs + EXYNOS5_DRD_PHYBATCHG); | ||
106 | phybatchg |= PHYBATCHG_UTMI_CLKSEL; | ||
107 | writel(phybatchg, regs + EXYNOS5_DRD_PHYBATCHG); | ||
108 | |||
109 | /* PHYTEST POWERDOWN Control */ | ||
110 | phytest = readl(regs + EXYNOS5_DRD_PHYTEST); | ||
111 | phytest &= ~(PHYTEST_POWERDOWN_SSP | | ||
112 | PHYTEST_POWERDOWN_HSP); | ||
113 | writel(phytest, regs + EXYNOS5_DRD_PHYTEST); | ||
114 | |||
115 | /* UTMI Power Control */ | ||
116 | writel(PHYUTMI_OTGDISABLE, regs + EXYNOS5_DRD_PHYUTMI); | ||
117 | |||
118 | phyclkrst = samsung_usb3phy_set_refclk(sphy); | ||
119 | |||
120 | phyclkrst |= PHYCLKRST_PORTRESET | | ||
121 | /* Digital power supply in normal operating mode */ | ||
122 | PHYCLKRST_RETENABLEN | | ||
123 | /* Enable ref clock for SS function */ | ||
124 | PHYCLKRST_REF_SSP_EN | | ||
125 | /* Enable spread spectrum */ | ||
126 | PHYCLKRST_SSC_EN | | ||
127 | /* Power down HS Bias and PLL blocks in suspend mode */ | ||
128 | PHYCLKRST_COMMONONN; | ||
129 | |||
130 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
131 | |||
132 | udelay(10); | ||
133 | |||
134 | phyclkrst &= ~(PHYCLKRST_PORTRESET); | ||
135 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
136 | } | ||
137 | |||
138 | static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy) | ||
139 | { | ||
140 | u32 phyutmi; | ||
141 | u32 phyclkrst; | ||
142 | u32 phytest; | ||
143 | void __iomem *regs = sphy->regs; | ||
144 | |||
145 | phyutmi = PHYUTMI_OTGDISABLE | | ||
146 | PHYUTMI_FORCESUSPEND | | ||
147 | PHYUTMI_FORCESLEEP; | ||
148 | writel(phyutmi, regs + EXYNOS5_DRD_PHYUTMI); | ||
149 | |||
150 | /* Resetting the PHYCLKRST enable bits to reduce leakage current */ | ||
151 | phyclkrst = readl(regs + EXYNOS5_DRD_PHYCLKRST); | ||
152 | phyclkrst &= ~(PHYCLKRST_REF_SSP_EN | | ||
153 | PHYCLKRST_SSC_EN | | ||
154 | PHYCLKRST_COMMONONN); | ||
155 | writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); | ||
156 | |||
157 | /* Control PHYTEST to remove leakage current */ | ||
158 | phytest = readl(regs + EXYNOS5_DRD_PHYTEST); | ||
159 | phytest |= (PHYTEST_POWERDOWN_SSP | | ||
160 | PHYTEST_POWERDOWN_HSP); | ||
161 | writel(phytest, regs + EXYNOS5_DRD_PHYTEST); | ||
162 | } | ||
163 | |||
164 | static int samsung_usb3phy_init(struct usb_phy *phy) | ||
165 | { | ||
166 | struct samsung_usbphy *sphy; | ||
167 | unsigned long flags; | ||
168 | int ret = 0; | ||
169 | |||
170 | sphy = phy_to_sphy(phy); | ||
171 | |||
172 | /* Enable the phy clock */ | ||
173 | ret = clk_prepare_enable(sphy->clk); | ||
174 | if (ret) { | ||
175 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | spin_lock_irqsave(&sphy->lock, flags); | ||
180 | |||
181 | /* setting default phy-type for USB 3.0 */ | ||
182 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
183 | |||
184 | /* Disable phy isolation */ | ||
185 | if (sphy->drv_data->set_isolation) | ||
186 | sphy->drv_data->set_isolation(sphy, false); | ||
187 | |||
188 | /* Initialize usb phy registers */ | ||
189 | sphy->drv_data->phy_enable(sphy); | ||
190 | |||
191 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
192 | |||
193 | /* Disable the phy clock */ | ||
194 | clk_disable_unprepare(sphy->clk); | ||
195 | |||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | /* | ||
200 | * The function passed to the usb driver for phy shutdown | ||
201 | */ | ||
202 | static void samsung_usb3phy_shutdown(struct usb_phy *phy) | ||
203 | { | ||
204 | struct samsung_usbphy *sphy; | ||
205 | unsigned long flags; | ||
206 | |||
207 | sphy = phy_to_sphy(phy); | ||
208 | |||
209 | if (clk_prepare_enable(sphy->clk)) { | ||
210 | dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | spin_lock_irqsave(&sphy->lock, flags); | ||
215 | |||
216 | /* setting default phy-type for USB 3.0 */ | ||
217 | samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); | ||
218 | |||
219 | /* De-initialize usb phy registers */ | ||
220 | sphy->drv_data->phy_disable(sphy); | ||
221 | |||
222 | /* Enable phy isolation */ | ||
223 | if (sphy->drv_data->set_isolation) | ||
224 | sphy->drv_data->set_isolation(sphy, true); | ||
225 | |||
226 | spin_unlock_irqrestore(&sphy->lock, flags); | ||
227 | |||
228 | clk_disable_unprepare(sphy->clk); | ||
229 | } | ||
230 | |||
231 | static int samsung_usb3phy_probe(struct platform_device *pdev) | ||
232 | { | ||
233 | struct samsung_usbphy *sphy; | ||
234 | struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev); | ||
235 | struct device *dev = &pdev->dev; | ||
236 | struct resource *phy_mem; | ||
237 | void __iomem *phy_base; | ||
238 | struct clk *clk; | ||
239 | int ret; | ||
240 | |||
241 | phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
242 | phy_base = devm_ioremap_resource(dev, phy_mem); | ||
243 | if (IS_ERR(phy_base)) | ||
244 | return PTR_ERR(phy_base); | ||
245 | |||
246 | sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); | ||
247 | if (!sphy) | ||
248 | return -ENOMEM; | ||
249 | |||
250 | clk = devm_clk_get(dev, "usbdrd30"); | ||
251 | if (IS_ERR(clk)) { | ||
252 | dev_err(dev, "Failed to get device clock\n"); | ||
253 | return PTR_ERR(clk); | ||
254 | } | ||
255 | |||
256 | sphy->dev = dev; | ||
257 | |||
258 | if (dev->of_node) { | ||
259 | ret = samsung_usbphy_parse_dt(sphy); | ||
260 | if (ret < 0) | ||
261 | return ret; | ||
262 | } else { | ||
263 | if (!pdata) { | ||
264 | dev_err(dev, "no platform data specified\n"); | ||
265 | return -EINVAL; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | sphy->plat = pdata; | ||
270 | sphy->regs = phy_base; | ||
271 | sphy->clk = clk; | ||
272 | sphy->phy.dev = sphy->dev; | ||
273 | sphy->phy.label = "samsung-usb3phy"; | ||
274 | sphy->phy.type = USB_PHY_TYPE_USB3; | ||
275 | sphy->phy.init = samsung_usb3phy_init; | ||
276 | sphy->phy.shutdown = samsung_usb3phy_shutdown; | ||
277 | sphy->drv_data = samsung_usbphy_get_driver_data(pdev); | ||
278 | |||
279 | sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); | ||
280 | if (sphy->ref_clk_freq < 0) | ||
281 | return -EINVAL; | ||
282 | |||
283 | spin_lock_init(&sphy->lock); | ||
284 | |||
285 | platform_set_drvdata(pdev, sphy); | ||
286 | |||
287 | return usb_add_phy_dev(&sphy->phy); | ||
288 | } | ||
289 | |||
290 | static int samsung_usb3phy_remove(struct platform_device *pdev) | ||
291 | { | ||
292 | struct samsung_usbphy *sphy = platform_get_drvdata(pdev); | ||
293 | |||
294 | usb_remove_phy(&sphy->phy); | ||
295 | |||
296 | if (sphy->pmuregs) | ||
297 | iounmap(sphy->pmuregs); | ||
298 | if (sphy->sysreg) | ||
299 | iounmap(sphy->sysreg); | ||
300 | |||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static struct samsung_usbphy_drvdata usb3phy_exynos5 = { | ||
305 | .cpu_type = TYPE_EXYNOS5250, | ||
306 | .devphy_en_mask = EXYNOS_USBPHY_ENABLE, | ||
307 | .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, | ||
308 | .set_isolation = samsung_usbphy_set_isolation_4210, | ||
309 | .phy_enable = samsung_exynos5_usb3phy_enable, | ||
310 | .phy_disable = samsung_exynos5_usb3phy_disable, | ||
311 | }; | ||
312 | |||
313 | #ifdef CONFIG_OF | ||
314 | static const struct of_device_id samsung_usbphy_dt_match[] = { | ||
315 | { | ||
316 | .compatible = "samsung,exynos5250-usb3phy", | ||
317 | .data = &usb3phy_exynos5 | ||
318 | }, | ||
319 | {}, | ||
320 | }; | ||
321 | MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); | ||
322 | #endif | ||
323 | |||
324 | static struct platform_device_id samsung_usbphy_driver_ids[] = { | ||
325 | { | ||
326 | .name = "exynos5250-usb3phy", | ||
327 | .driver_data = (unsigned long)&usb3phy_exynos5, | ||
328 | }, | ||
329 | {}, | ||
330 | }; | ||
331 | |||
332 | MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); | ||
333 | |||
334 | static struct platform_driver samsung_usb3phy_driver = { | ||
335 | .probe = samsung_usb3phy_probe, | ||
336 | .remove = samsung_usb3phy_remove, | ||
337 | .id_table = samsung_usbphy_driver_ids, | ||
338 | .driver = { | ||
339 | .name = "samsung-usb3phy", | ||
340 | .owner = THIS_MODULE, | ||
341 | .of_match_table = of_match_ptr(samsung_usbphy_dt_match), | ||
342 | }, | ||
343 | }; | ||
344 | |||
345 | module_platform_driver(samsung_usb3phy_driver); | ||
346 | |||
347 | MODULE_DESCRIPTION("Samsung USB 3.0 phy controller"); | ||
348 | MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>"); | ||
349 | MODULE_LICENSE("GPL"); | ||
350 | MODULE_ALIAS("platform:samsung-usb3phy"); | ||
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c index 04778cf80d60..44ea082e40dc 100644 --- a/drivers/usb/phy/phy-twl6030-usb.c +++ b/drivers/usb/phy/phy-twl6030-usb.c | |||
@@ -104,7 +104,6 @@ struct twl6030_usb { | |||
104 | int irq2; | 104 | int irq2; |
105 | enum omap_musb_vbus_id_status linkstat; | 105 | enum omap_musb_vbus_id_status linkstat; |
106 | u8 asleep; | 106 | u8 asleep; |
107 | bool irq_enabled; | ||
108 | bool vbus_enable; | 107 | bool vbus_enable; |
109 | const char *regulator; | 108 | const char *regulator; |
110 | }; | 109 | }; |
@@ -373,7 +372,6 @@ static int twl6030_usb_probe(struct platform_device *pdev) | |||
373 | 372 | ||
374 | INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); | 373 | INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); |
375 | 374 | ||
376 | twl->irq_enabled = true; | ||
377 | status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, | 375 | status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, |
378 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | 376 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
379 | "twl6030_usb", twl); | 377 | "twl6030_usb", twl); |
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig index 1c4195abc108..de83b9d0cd5c 100644 --- a/drivers/usb/renesas_usbhs/Kconfig +++ b/drivers/usb/renesas_usbhs/Kconfig | |||
@@ -5,6 +5,7 @@ | |||
5 | config USB_RENESAS_USBHS | 5 | config USB_RENESAS_USBHS |
6 | tristate 'Renesas USBHS controller' | 6 | tristate 'Renesas USBHS controller' |
7 | depends on USB_GADGET | 7 | depends on USB_GADGET |
8 | depends on ARCH_SHMOBILE || SUPERH || COMPILE_TEST | ||
8 | default n | 9 | default n |
9 | help | 10 | help |
10 | Renesas USBHS is a discrete USB host and peripheral controller chip | 11 | Renesas USBHS is a discrete USB host and peripheral controller chip |
diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c index 1b9bf8d83235..b3b6813ab270 100644 --- a/drivers/usb/renesas_usbhs/common.c +++ b/drivers/usb/renesas_usbhs/common.c | |||
@@ -18,6 +18,8 @@ | |||
18 | #include <linux/gpio.h> | 18 | #include <linux/gpio.h> |
19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/of_device.h> | ||
22 | #include <linux/of_gpio.h> | ||
21 | #include <linux/pm_runtime.h> | 23 | #include <linux/pm_runtime.h> |
22 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
23 | #include <linux/sysfs.h> | 25 | #include <linux/sysfs.h> |
@@ -438,6 +440,43 @@ static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) | |||
438 | /* | 440 | /* |
439 | * platform functions | 441 | * platform functions |
440 | */ | 442 | */ |
443 | static const struct of_device_id usbhs_of_match[] = { | ||
444 | { | ||
445 | .compatible = "renesas,usbhs-r8a7790", | ||
446 | .data = (void *)USBHS_TYPE_R8A7790, | ||
447 | }, | ||
448 | { | ||
449 | .compatible = "renesas,usbhs-r8a7791", | ||
450 | .data = (void *)USBHS_TYPE_R8A7791, | ||
451 | }, | ||
452 | { }, | ||
453 | }; | ||
454 | MODULE_DEVICE_TABLE(of, usbhs_of_match); | ||
455 | |||
456 | static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) | ||
457 | { | ||
458 | struct renesas_usbhs_platform_info *info; | ||
459 | struct renesas_usbhs_driver_param *dparam; | ||
460 | const struct of_device_id *of_id = of_match_device(usbhs_of_match, dev); | ||
461 | u32 tmp; | ||
462 | int gpio; | ||
463 | |||
464 | info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); | ||
465 | if (!info) | ||
466 | return NULL; | ||
467 | |||
468 | dparam = &info->driver_param; | ||
469 | dparam->type = of_id ? (u32)of_id->data : 0; | ||
470 | if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) | ||
471 | dparam->buswait_bwait = tmp; | ||
472 | gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, | ||
473 | NULL); | ||
474 | if (gpio > 0) | ||
475 | dparam->enable_gpio = gpio; | ||
476 | |||
477 | return info; | ||
478 | } | ||
479 | |||
441 | static int usbhs_probe(struct platform_device *pdev) | 480 | static int usbhs_probe(struct platform_device *pdev) |
442 | { | 481 | { |
443 | struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev); | 482 | struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev); |
@@ -446,6 +485,10 @@ static int usbhs_probe(struct platform_device *pdev) | |||
446 | struct resource *res, *irq_res; | 485 | struct resource *res, *irq_res; |
447 | int ret; | 486 | int ret; |
448 | 487 | ||
488 | /* check device node */ | ||
489 | if (pdev->dev.of_node) | ||
490 | info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); | ||
491 | |||
449 | /* check platform information */ | 492 | /* check platform information */ |
450 | if (!info) { | 493 | if (!info) { |
451 | dev_err(&pdev->dev, "no platform information\n"); | 494 | dev_err(&pdev->dev, "no platform information\n"); |
@@ -689,6 +732,7 @@ static struct platform_driver renesas_usbhs_driver = { | |||
689 | .driver = { | 732 | .driver = { |
690 | .name = "renesas_usbhs", | 733 | .name = "renesas_usbhs", |
691 | .pm = &usbhsc_pm_ops, | 734 | .pm = &usbhsc_pm_ops, |
735 | .of_match_table = of_match_ptr(usbhs_of_match), | ||
692 | }, | 736 | }, |
693 | .probe = usbhs_probe, | 737 | .probe = usbhs_probe, |
694 | .remove = usbhs_remove, | 738 | .remove = usbhs_remove, |
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index 04e6505777d0..2d17c10a0428 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c | |||
@@ -129,7 +129,7 @@ static void usbhsg_queue_pop(struct usbhsg_uep *uep, | |||
129 | dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); | 129 | dev_dbg(dev, "pipe %d : queue pop\n", usbhs_pipe_number(pipe)); |
130 | 130 | ||
131 | ureq->req.status = status; | 131 | ureq->req.status = status; |
132 | ureq->req.complete(&uep->ep, &ureq->req); | 132 | usb_gadget_giveback_request(&uep->ep, &ureq->req); |
133 | } | 133 | } |
134 | 134 | ||
135 | static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) | 135 | static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) |
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 3ce5c74b29e4..a69f7cd9d0bf 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig | |||
@@ -58,9 +58,11 @@ config USB_SERIAL_SIMPLE | |||
58 | handles a wide range of very simple devices, all in one | 58 | handles a wide range of very simple devices, all in one |
59 | driver. Specifically, it supports: | 59 | driver. Specifically, it supports: |
60 | - Suunto ANT+ USB device. | 60 | - Suunto ANT+ USB device. |
61 | - Medtronic CareLink USB device | ||
61 | - Fundamental Software dongle. | 62 | - Fundamental Software dongle. |
62 | - HP4x calculators | 63 | - HP4x calculators |
63 | - a number of Motorola phones | 64 | - a number of Motorola phones |
65 | - Novatel Wireless GPS receivers | ||
64 | - Siemens USB/MPI adapter. | 66 | - Siemens USB/MPI adapter. |
65 | - ViVOtech ViVOpay USB device. | 67 | - ViVOtech ViVOpay USB device. |
66 | - Infineon Modem Flashloader USB interface | 68 | - Infineon Modem Flashloader USB interface |
@@ -682,14 +684,6 @@ config USB_SERIAL_WISHBONE | |||
682 | To compile this driver as a module, choose M here: the | 684 | To compile this driver as a module, choose M here: the |
683 | module will be called wishbone-serial. | 685 | module will be called wishbone-serial. |
684 | 686 | ||
685 | config USB_SERIAL_ZTE | ||
686 | tristate "ZTE USB serial driver" | ||
687 | help | ||
688 | Say Y here if you want to use a ZTE USB to serial device. | ||
689 | |||
690 | To compile this driver as a module, choose M here: the | ||
691 | module will be called zte. | ||
692 | |||
693 | config USB_SERIAL_SSU100 | 687 | config USB_SERIAL_SSU100 |
694 | tristate "USB Quatech SSU-100 Single Port Serial Driver" | 688 | tristate "USB Quatech SSU-100 Single Port Serial Driver" |
695 | help | 689 | help |
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile index bfdafd349441..349d9df0895f 100644 --- a/drivers/usb/serial/Makefile +++ b/drivers/usb/serial/Makefile | |||
@@ -60,4 +60,3 @@ obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o | |||
60 | obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o | 60 | obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o |
61 | obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o | 61 | obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o |
62 | obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o | 62 | obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o |
63 | obj-$(CONFIG_USB_SERIAL_ZTE) += zte_ev.o | ||
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index e4bb62225cb9..eca1747ca8c7 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c | |||
@@ -122,6 +122,7 @@ static const struct usb_device_id id_table[] = { | |||
122 | { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ | 122 | { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ |
123 | { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ | 123 | { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ |
124 | { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ | 124 | { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ |
125 | { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ | ||
125 | { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ | 126 | { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ |
126 | { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ | 127 | { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ |
127 | { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */ | 128 | { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */ |
@@ -155,6 +156,7 @@ static const struct usb_device_id id_table[] = { | |||
155 | { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */ | 156 | { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */ |
156 | { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */ | 157 | { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */ |
157 | { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */ | 158 | { USB_DEVICE(0x1BE3, 0x07A6) }, /* WAGO 750-923 USB Service Cable */ |
159 | { USB_DEVICE(0x1D6F, 0x0010) }, /* Seluxit ApS RF Dongle */ | ||
158 | { USB_DEVICE(0x1E29, 0x0102) }, /* Festo CPX-USB */ | 160 | { USB_DEVICE(0x1E29, 0x0102) }, /* Festo CPX-USB */ |
159 | { USB_DEVICE(0x1E29, 0x0501) }, /* Festo CMSP */ | 161 | { USB_DEVICE(0x1E29, 0x0501) }, /* Festo CMSP */ |
160 | { USB_DEVICE(0x1FB9, 0x0100) }, /* Lake Shore Model 121 Current Source */ | 162 | { USB_DEVICE(0x1FB9, 0x0100) }, /* Lake Shore Model 121 Current Source */ |
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 8a23c53b946e..12b0e67473ba 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c | |||
@@ -834,7 +834,6 @@ static void digi_set_termios(struct tty_struct *tty, | |||
834 | arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS; | 834 | arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS; |
835 | } else { | 835 | } else { |
836 | arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS; | 836 | arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS; |
837 | tty->hw_stopped = 0; | ||
838 | } | 837 | } |
839 | 838 | ||
840 | buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL; | 839 | buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL; |
@@ -1500,15 +1499,11 @@ static int digi_read_oob_callback(struct urb *urb) | |||
1500 | if (val & DIGI_READ_INPUT_SIGNALS_CTS) { | 1499 | if (val & DIGI_READ_INPUT_SIGNALS_CTS) { |
1501 | priv->dp_modem_signals |= TIOCM_CTS; | 1500 | priv->dp_modem_signals |= TIOCM_CTS; |
1502 | /* port must be open to use tty struct */ | 1501 | /* port must be open to use tty struct */ |
1503 | if (rts) { | 1502 | if (rts) |
1504 | tty->hw_stopped = 0; | ||
1505 | tty_port_tty_wakeup(&port->port); | 1503 | tty_port_tty_wakeup(&port->port); |
1506 | } | ||
1507 | } else { | 1504 | } else { |
1508 | priv->dp_modem_signals &= ~TIOCM_CTS; | 1505 | priv->dp_modem_signals &= ~TIOCM_CTS; |
1509 | /* port must be open to use tty struct */ | 1506 | /* port must be open to use tty struct */ |
1510 | if (rts) | ||
1511 | tty->hw_stopped = 1; | ||
1512 | } | 1507 | } |
1513 | if (val & DIGI_READ_INPUT_SIGNALS_DSR) | 1508 | if (val & DIGI_READ_INPUT_SIGNALS_DSR) |
1514 | priv->dp_modem_signals |= TIOCM_DSR; | 1509 | priv->dp_modem_signals |= TIOCM_DSR; |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index c0a42e9e6777..ddbb8fe1046d 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -1456,12 +1456,8 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr) | |||
1456 | tty = tty_port_tty_get(&edge_port->port->port); | 1456 | tty = tty_port_tty_get(&edge_port->port->port); |
1457 | /* handle CTS flow control */ | 1457 | /* handle CTS flow control */ |
1458 | if (tty && C_CRTSCTS(tty)) { | 1458 | if (tty && C_CRTSCTS(tty)) { |
1459 | if (msr & EDGEPORT_MSR_CTS) { | 1459 | if (msr & EDGEPORT_MSR_CTS) |
1460 | tty->hw_stopped = 0; | ||
1461 | tty_wakeup(tty); | 1460 | tty_wakeup(tty); |
1462 | } else { | ||
1463 | tty->hw_stopped = 1; | ||
1464 | } | ||
1465 | } | 1461 | } |
1466 | tty_kref_put(tty); | 1462 | tty_kref_put(tty); |
1467 | } | 1463 | } |
@@ -2177,7 +2173,6 @@ static void change_port_settings(struct tty_struct *tty, | |||
2177 | dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__); | 2173 | dev_dbg(dev, "%s - RTS/CTS is enabled\n", __func__); |
2178 | } else { | 2174 | } else { |
2179 | dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__); | 2175 | dev_dbg(dev, "%s - RTS/CTS is disabled\n", __func__); |
2180 | tty->hw_stopped = 0; | ||
2181 | restart_read(edge_port); | 2176 | restart_read(edge_port); |
2182 | } | 2177 | } |
2183 | 2178 | ||
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 54a8120897a6..d1a3f6044c8a 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -276,6 +276,7 @@ static void option_instat_callback(struct urb *urb); | |||
276 | #define ZTE_PRODUCT_MF628 0x0015 | 276 | #define ZTE_PRODUCT_MF628 0x0015 |
277 | #define ZTE_PRODUCT_MF626 0x0031 | 277 | #define ZTE_PRODUCT_MF626 0x0031 |
278 | #define ZTE_PRODUCT_AC2726 0xfff1 | 278 | #define ZTE_PRODUCT_AC2726 0xfff1 |
279 | #define ZTE_PRODUCT_MG880 0xfffd | ||
279 | #define ZTE_PRODUCT_CDMA_TECH 0xfffe | 280 | #define ZTE_PRODUCT_CDMA_TECH 0xfffe |
280 | #define ZTE_PRODUCT_AC8710T 0xffff | 281 | #define ZTE_PRODUCT_AC8710T 0xffff |
281 | #define ZTE_PRODUCT_MC2718 0xffe8 | 282 | #define ZTE_PRODUCT_MC2718 0xffe8 |
@@ -1560,7 +1561,15 @@ static const struct usb_device_id option_ids[] = { | |||
1560 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff92, 0xff, 0xff, 0xff) }, | 1561 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff92, 0xff, 0xff, 0xff) }, |
1561 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff93, 0xff, 0xff, 0xff) }, | 1562 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff93, 0xff, 0xff, 0xff) }, |
1562 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff94, 0xff, 0xff, 0xff) }, | 1563 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xff94, 0xff, 0xff, 0xff) }, |
1563 | 1564 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xffec, 0xff, 0xff, 0xff) }, | |
1565 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xffee, 0xff, 0xff, 0xff) }, | ||
1566 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfff6, 0xff, 0xff, 0xff) }, | ||
1567 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfff7, 0xff, 0xff, 0xff) }, | ||
1568 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfff8, 0xff, 0xff, 0xff) }, | ||
1569 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfff9, 0xff, 0xff, 0xff) }, | ||
1570 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfffb, 0xff, 0xff, 0xff) }, | ||
1571 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0xfffc, 0xff, 0xff, 0xff) }, | ||
1572 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MG880, 0xff, 0xff, 0xff) }, | ||
1564 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, | 1573 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, |
1565 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, | 1574 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, |
1566 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) }, | 1575 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) }, |
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index e9bad928039f..0f872e6b2c87 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -162,6 +162,9 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { | |||
162 | .max_baud_rate = 1228800, | 162 | .max_baud_rate = 1228800, |
163 | .quirks = PL2303_QUIRK_LEGACY, | 163 | .quirks = PL2303_QUIRK_LEGACY, |
164 | }, | 164 | }, |
165 | [TYPE_HX] = { | ||
166 | .max_baud_rate = 12000000, | ||
167 | }, | ||
165 | }; | 168 | }; |
166 | 169 | ||
167 | static int pl2303_vendor_read(struct usb_serial *serial, u16 value, | 170 | static int pl2303_vendor_read(struct usb_serial *serial, u16 value, |
@@ -395,16 +398,14 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty, | |||
395 | if (spriv->type->max_baud_rate) | 398 | if (spriv->type->max_baud_rate) |
396 | baud = min_t(speed_t, baud, spriv->type->max_baud_rate); | 399 | baud = min_t(speed_t, baud, spriv->type->max_baud_rate); |
397 | /* | 400 | /* |
398 | * Set baud rate to nearest supported value. | 401 | * Use direct method for supported baud rates, otherwise use divisors. |
399 | * | ||
400 | * NOTE: Baud rate 500k can only be set using divisors. | ||
401 | */ | 402 | */ |
402 | baud_sup = pl2303_get_supported_baud_rate(baud); | 403 | baud_sup = pl2303_get_supported_baud_rate(baud); |
403 | 404 | ||
404 | if (baud == 500000) | 405 | if (baud == baud_sup) |
405 | baud = pl2303_encode_baud_rate_divisor(buf, baud); | 406 | baud = pl2303_encode_baud_rate_direct(buf, baud); |
406 | else | 407 | else |
407 | baud = pl2303_encode_baud_rate_direct(buf, baud_sup); | 408 | baud = pl2303_encode_baud_rate_divisor(buf, baud); |
408 | 409 | ||
409 | /* Save resulting baud rate */ | 410 | /* Save resulting baud rate */ |
410 | tty_encode_baud_rate(tty, baud, baud); | 411 | tty_encode_baud_rate(tty, baud, baud); |
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index 3dd3ff8c50d3..e9da41d9fe7f 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c | |||
@@ -773,7 +773,6 @@ static void ti_set_termios(struct tty_struct *tty, | |||
773 | config->wFlags |= TI_UART_ENABLE_RTS_IN; | 773 | config->wFlags |= TI_UART_ENABLE_RTS_IN; |
774 | config->wFlags |= TI_UART_ENABLE_CTS_OUT; | 774 | config->wFlags |= TI_UART_ENABLE_CTS_OUT; |
775 | } else { | 775 | } else { |
776 | tty->hw_stopped = 0; | ||
777 | ti_restart_read(tport, tty); | 776 | ti_restart_read(tport, tty); |
778 | } | 777 | } |
779 | 778 | ||
@@ -1291,12 +1290,8 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) | |||
1291 | /* handle CTS flow control */ | 1290 | /* handle CTS flow control */ |
1292 | tty = tty_port_tty_get(&tport->tp_port->port); | 1291 | tty = tty_port_tty_get(&tport->tp_port->port); |
1293 | if (tty && C_CRTSCTS(tty)) { | 1292 | if (tty && C_CRTSCTS(tty)) { |
1294 | if (msr & TI_MSR_CTS) { | 1293 | if (msr & TI_MSR_CTS) |
1295 | tty->hw_stopped = 0; | ||
1296 | tty_wakeup(tty); | 1294 | tty_wakeup(tty); |
1297 | } else { | ||
1298 | tty->hw_stopped = 1; | ||
1299 | } | ||
1300 | } | 1295 | } |
1301 | tty_kref_put(tty); | 1296 | tty_kref_put(tty); |
1302 | } | 1297 | } |
diff --git a/drivers/usb/serial/usb-serial-simple.c b/drivers/usb/serial/usb-serial-simple.c index fb79775447b0..7064eb8d6142 100644 --- a/drivers/usb/serial/usb-serial-simple.c +++ b/drivers/usb/serial/usb-serial-simple.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <linux/usb.h> | 20 | #include <linux/usb.h> |
21 | #include <linux/usb/serial.h> | 21 | #include <linux/usb/serial.h> |
22 | 22 | ||
23 | #define DEVICE(vendor, IDS) \ | 23 | #define DEVICE_N(vendor, IDS, nport) \ |
24 | static const struct usb_device_id vendor##_id_table[] = { \ | 24 | static const struct usb_device_id vendor##_id_table[] = { \ |
25 | IDS(), \ | 25 | IDS(), \ |
26 | { }, \ | 26 | { }, \ |
@@ -31,9 +31,15 @@ static struct usb_serial_driver vendor##_device = { \ | |||
31 | .name = #vendor, \ | 31 | .name = #vendor, \ |
32 | }, \ | 32 | }, \ |
33 | .id_table = vendor##_id_table, \ | 33 | .id_table = vendor##_id_table, \ |
34 | .num_ports = 1, \ | 34 | .num_ports = nport, \ |
35 | }; | 35 | }; |
36 | 36 | ||
37 | #define DEVICE(vendor, IDS) DEVICE_N(vendor, IDS, 1) | ||
38 | |||
39 | /* Medtronic CareLink USB driver */ | ||
40 | #define CARELINK_IDS() \ | ||
41 | { USB_DEVICE(0x0a21, 0x8001) } /* MMT-7305WW */ | ||
42 | DEVICE(carelink, CARELINK_IDS); | ||
37 | 43 | ||
38 | /* ZIO Motherboard USB driver */ | 44 | /* ZIO Motherboard USB driver */ |
39 | #define ZIO_IDS() \ | 45 | #define ZIO_IDS() \ |
@@ -64,6 +70,11 @@ DEVICE(vivopay, VIVOPAY_IDS); | |||
64 | { USB_DEVICE(0x22b8, 0x2c64) } /* Motorola V950 phone */ | 70 | { USB_DEVICE(0x22b8, 0x2c64) } /* Motorola V950 phone */ |
65 | DEVICE(moto_modem, MOTO_IDS); | 71 | DEVICE(moto_modem, MOTO_IDS); |
66 | 72 | ||
73 | /* Novatel Wireless GPS driver */ | ||
74 | #define NOVATEL_IDS() \ | ||
75 | { USB_DEVICE(0x09d7, 0x0100) } /* NovAtel FlexPack GPS */ | ||
76 | DEVICE_N(novatel_gps, NOVATEL_IDS, 3); | ||
77 | |||
67 | /* HP4x (48/49) Generic Serial driver */ | 78 | /* HP4x (48/49) Generic Serial driver */ |
68 | #define HP4X_IDS() \ | 79 | #define HP4X_IDS() \ |
69 | { USB_DEVICE(0x03f0, 0x0121) } | 80 | { USB_DEVICE(0x03f0, 0x0121) } |
@@ -82,11 +93,13 @@ DEVICE(siemens_mpi, SIEMENS_IDS); | |||
82 | 93 | ||
83 | /* All of the above structures mushed into two lists */ | 94 | /* All of the above structures mushed into two lists */ |
84 | static struct usb_serial_driver * const serial_drivers[] = { | 95 | static struct usb_serial_driver * const serial_drivers[] = { |
96 | &carelink_device, | ||
85 | &zio_device, | 97 | &zio_device, |
86 | &funsoft_device, | 98 | &funsoft_device, |
87 | &flashloader_device, | 99 | &flashloader_device, |
88 | &vivopay_device, | 100 | &vivopay_device, |
89 | &moto_modem_device, | 101 | &moto_modem_device, |
102 | &novatel_gps_device, | ||
90 | &hp4x_device, | 103 | &hp4x_device, |
91 | &suunto_device, | 104 | &suunto_device, |
92 | &siemens_mpi_device, | 105 | &siemens_mpi_device, |
@@ -94,11 +107,13 @@ static struct usb_serial_driver * const serial_drivers[] = { | |||
94 | }; | 107 | }; |
95 | 108 | ||
96 | static const struct usb_device_id id_table[] = { | 109 | static const struct usb_device_id id_table[] = { |
110 | CARELINK_IDS(), | ||
97 | ZIO_IDS(), | 111 | ZIO_IDS(), |
98 | FUNSOFT_IDS(), | 112 | FUNSOFT_IDS(), |
99 | FLASHLOADER_IDS(), | 113 | FLASHLOADER_IDS(), |
100 | VIVOPAY_IDS(), | 114 | VIVOPAY_IDS(), |
101 | MOTO_IDS(), | 115 | MOTO_IDS(), |
116 | NOVATEL_IDS(), | ||
102 | HP4X_IDS(), | 117 | HP4X_IDS(), |
103 | SUUNTO_IDS(), | 118 | SUUNTO_IDS(), |
104 | SIEMENS_IDS(), | 119 | SIEMENS_IDS(), |
diff --git a/drivers/usb/serial/xsens_mt.c b/drivers/usb/serial/xsens_mt.c index 4841fb57400c..3837d5113bb2 100644 --- a/drivers/usb/serial/xsens_mt.c +++ b/drivers/usb/serial/xsens_mt.c | |||
@@ -41,28 +41,13 @@ static const struct usb_device_id id_table[] = { | |||
41 | }; | 41 | }; |
42 | MODULE_DEVICE_TABLE(usb, id_table); | 42 | MODULE_DEVICE_TABLE(usb, id_table); |
43 | 43 | ||
44 | static int has_required_endpoints(const struct usb_host_interface *interface) | ||
45 | { | ||
46 | __u8 i; | ||
47 | int has_bulk_in = 0; | ||
48 | int has_bulk_out = 0; | ||
49 | |||
50 | for (i = 0; i < interface->desc.bNumEndpoints; ++i) { | ||
51 | if (usb_endpoint_is_bulk_in(&interface->endpoint[i].desc)) | ||
52 | has_bulk_in = 1; | ||
53 | else if (usb_endpoint_is_bulk_out(&interface->endpoint[i].desc)) | ||
54 | has_bulk_out = 1; | ||
55 | } | ||
56 | |||
57 | return has_bulk_in && has_bulk_out; | ||
58 | } | ||
59 | |||
60 | static int xsens_mt_probe(struct usb_serial *serial, | 44 | static int xsens_mt_probe(struct usb_serial *serial, |
61 | const struct usb_device_id *id) | 45 | const struct usb_device_id *id) |
62 | { | 46 | { |
63 | if (!has_required_endpoints(serial->interface->cur_altsetting)) | 47 | if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 1) |
64 | return -ENODEV; | 48 | return 0; |
65 | return 0; | 49 | |
50 | return -ENODEV; | ||
66 | } | 51 | } |
67 | 52 | ||
68 | static struct usb_serial_driver xsens_mt_device = { | 53 | static struct usb_serial_driver xsens_mt_device = { |
@@ -82,4 +67,6 @@ static struct usb_serial_driver * const serial_drivers[] = { | |||
82 | 67 | ||
83 | module_usb_serial_driver(serial_drivers, id_table); | 68 | module_usb_serial_driver(serial_drivers, id_table); |
84 | 69 | ||
70 | MODULE_AUTHOR("Frans Klaver <frans.klaver@xsens.com>"); | ||
71 | MODULE_DESCRIPTION("USB-serial driver for Xsens motion trackers"); | ||
85 | MODULE_LICENSE("GPL"); | 72 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/serial/zte_ev.c b/drivers/usb/serial/zte_ev.c deleted file mode 100644 index c9bb107d5e5c..000000000000 --- a/drivers/usb/serial/zte_ev.c +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | /* | ||
2 | * ZTE_EV USB serial driver | ||
3 | * | ||
4 | * Copyright (C) 2012 Greg Kroah-Hartman <gregkh@linuxfoundation.org> | ||
5 | * Copyright (C) 2012 Linux Foundation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This driver is based on code found in a ZTE_ENV patch that modified | ||
12 | * the usb-serial generic driver. Comments were left in that I think | ||
13 | * show the commands used to talk to the device, but I am not sure. | ||
14 | */ | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/tty.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/usb.h> | ||
20 | #include <linux/usb/serial.h> | ||
21 | #include <linux/uaccess.h> | ||
22 | |||
23 | #define MAX_SETUP_DATA_SIZE 32 | ||
24 | |||
25 | static void debug_data(struct device *dev, const char *function, int len, | ||
26 | const unsigned char *data, int result) | ||
27 | { | ||
28 | dev_dbg(dev, "result = %d\n", result); | ||
29 | if (result == len) | ||
30 | dev_dbg(dev, "%s - length = %d, data = %*ph\n", function, | ||
31 | len, len, data); | ||
32 | } | ||
33 | |||
34 | static int zte_ev_usb_serial_open(struct tty_struct *tty, | ||
35 | struct usb_serial_port *port) | ||
36 | { | ||
37 | struct usb_device *udev = port->serial->dev; | ||
38 | struct device *dev = &port->dev; | ||
39 | int result = 0; | ||
40 | int len; | ||
41 | unsigned char *buf; | ||
42 | |||
43 | buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL); | ||
44 | if (!buf) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | /* send 1st ctl cmd(CTL 21 22 01 00 00 00 00 00) */ | ||
48 | len = 0; | ||
49 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
50 | 0x22, 0x21, | ||
51 | 0x0001, 0x0000, NULL, len, | ||
52 | USB_CTRL_GET_TIMEOUT); | ||
53 | dev_dbg(dev, "result = %d\n", result); | ||
54 | |||
55 | /* send 2st cmd and receive data */ | ||
56 | /* | ||
57 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5) | ||
58 | * 16.0 DI 00 96 00 00 00 00 08 | ||
59 | */ | ||
60 | len = 0x0007; | ||
61 | result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
62 | 0x21, 0xa1, | ||
63 | 0x0000, 0x0000, buf, len, | ||
64 | USB_CTRL_GET_TIMEOUT); | ||
65 | debug_data(dev, __func__, len, buf, result); | ||
66 | |||
67 | /* send 3rd cmd */ | ||
68 | /* | ||
69 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 | ||
70 | * 16.0 DO 80 25 00 00 00 00 08 .%..... 30.2.0 | ||
71 | */ | ||
72 | len = 0x0007; | ||
73 | buf[0] = 0x80; | ||
74 | buf[1] = 0x25; | ||
75 | buf[2] = 0x00; | ||
76 | buf[3] = 0x00; | ||
77 | buf[4] = 0x00; | ||
78 | buf[5] = 0x00; | ||
79 | buf[6] = 0x08; | ||
80 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
81 | 0x20, 0x21, | ||
82 | 0x0000, 0x0000, buf, len, | ||
83 | USB_CTRL_GET_TIMEOUT); | ||
84 | debug_data(dev, __func__, len, buf, result); | ||
85 | |||
86 | /* send 4th cmd */ | ||
87 | /* | ||
88 | * 16.0 CTL 21 22 03 00 00 00 00 00 | ||
89 | */ | ||
90 | len = 0; | ||
91 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
92 | 0x22, 0x21, | ||
93 | 0x0003, 0x0000, NULL, len, | ||
94 | USB_CTRL_GET_TIMEOUT); | ||
95 | dev_dbg(dev, "result = %d\n", result); | ||
96 | |||
97 | /* send 5th cmd */ | ||
98 | /* | ||
99 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 | ||
100 | * 16.0 DI 80 25 00 00 00 00 08 | ||
101 | */ | ||
102 | len = 0x0007; | ||
103 | result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
104 | 0x21, 0xa1, | ||
105 | 0x0000, 0x0000, buf, len, | ||
106 | USB_CTRL_GET_TIMEOUT); | ||
107 | debug_data(dev, __func__, len, buf, result); | ||
108 | |||
109 | /* send 6th cmd */ | ||
110 | /* | ||
111 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 34.1.0 | ||
112 | * 16.0 DO 80 25 00 00 00 00 08 | ||
113 | */ | ||
114 | len = 0x0007; | ||
115 | buf[0] = 0x80; | ||
116 | buf[1] = 0x25; | ||
117 | buf[2] = 0x00; | ||
118 | buf[3] = 0x00; | ||
119 | buf[4] = 0x00; | ||
120 | buf[5] = 0x00; | ||
121 | buf[6] = 0x08; | ||
122 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
123 | 0x20, 0x21, | ||
124 | 0x0000, 0x0000, buf, len, | ||
125 | USB_CTRL_GET_TIMEOUT); | ||
126 | debug_data(dev, __func__, len, buf, result); | ||
127 | kfree(buf); | ||
128 | |||
129 | return usb_serial_generic_open(tty, port); | ||
130 | } | ||
131 | |||
132 | /* | ||
133 | * CTL 21 22 02 00 00 00 00 00 CLASS 338.1.0 | ||
134 | * | ||
135 | * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 340.1.0 | ||
136 | * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 341.1.0 | ||
137 | * | ||
138 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 346.1.0(3) | ||
139 | * 16.0 DI 00 08 07 00 00 00 08 ....... 346.2.0 | ||
140 | * | ||
141 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 349.1.0 | ||
142 | * 16.0 DO 00 c2 01 00 00 00 08 ....... 349.2.0 | ||
143 | * | ||
144 | * 16.0 CTL 21 22 03 00 00 00 00 00 CLASS 350.1.0(2) | ||
145 | * | ||
146 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 352.1.0 | ||
147 | * 16.0 DI 00 c2 01 00 00 00 08 ....... 352.2.0 | ||
148 | * | ||
149 | * 16.1 DI a1 20 00 00 00 00 02 00 02 00 . ........ 353.1.0 | ||
150 | * | ||
151 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0 | ||
152 | * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0 | ||
153 | * | ||
154 | * 16.0 CTL 21 22 03 00 00 00 00 00 | ||
155 | */ | ||
156 | |||
157 | static void zte_ev_usb_serial_close(struct usb_serial_port *port) | ||
158 | { | ||
159 | struct usb_device *udev = port->serial->dev; | ||
160 | struct device *dev = &port->dev; | ||
161 | int result = 0; | ||
162 | int len; | ||
163 | unsigned char *buf; | ||
164 | |||
165 | buf = kmalloc(MAX_SETUP_DATA_SIZE, GFP_KERNEL); | ||
166 | if (!buf) | ||
167 | return; | ||
168 | |||
169 | /* send 1st ctl cmd(CTL 21 22 02 00 00 00 00 00) */ | ||
170 | len = 0; | ||
171 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
172 | 0x22, 0x21, | ||
173 | 0x0002, 0x0000, NULL, len, | ||
174 | USB_CTRL_GET_TIMEOUT); | ||
175 | dev_dbg(dev, "result = %d\n", result); | ||
176 | |||
177 | /* send 2st ctl cmd(CTL 21 22 03 00 00 00 00 00 ) */ | ||
178 | len = 0; | ||
179 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
180 | 0x22, 0x21, | ||
181 | 0x0003, 0x0000, NULL, len, | ||
182 | USB_CTRL_GET_TIMEOUT); | ||
183 | dev_dbg(dev, "result = %d\n", result); | ||
184 | |||
185 | /* send 3st cmd and recieve data */ | ||
186 | /* | ||
187 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 25.1.0(5) | ||
188 | * 16.0 DI 00 08 07 00 00 00 08 | ||
189 | */ | ||
190 | len = 0x0007; | ||
191 | result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
192 | 0x21, 0xa1, | ||
193 | 0x0000, 0x0000, buf, len, | ||
194 | USB_CTRL_GET_TIMEOUT); | ||
195 | debug_data(dev, __func__, len, buf, result); | ||
196 | |||
197 | /* send 4th cmd */ | ||
198 | /* | ||
199 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 30.1.0 | ||
200 | * 16.0 DO 00 c2 01 00 00 00 08 .%..... 30.2.0 | ||
201 | */ | ||
202 | len = 0x0007; | ||
203 | buf[0] = 0x00; | ||
204 | buf[1] = 0xc2; | ||
205 | buf[2] = 0x01; | ||
206 | buf[3] = 0x00; | ||
207 | buf[4] = 0x00; | ||
208 | buf[5] = 0x00; | ||
209 | buf[6] = 0x08; | ||
210 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
211 | 0x20, 0x21, | ||
212 | 0x0000, 0x0000, buf, len, | ||
213 | USB_CTRL_GET_TIMEOUT); | ||
214 | debug_data(dev, __func__, len, buf, result); | ||
215 | |||
216 | /* send 5th cmd */ | ||
217 | /* | ||
218 | * 16.0 CTL 21 22 03 00 00 00 00 00 | ||
219 | */ | ||
220 | len = 0; | ||
221 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
222 | 0x22, 0x21, | ||
223 | 0x0003, 0x0000, NULL, len, | ||
224 | USB_CTRL_GET_TIMEOUT); | ||
225 | dev_dbg(dev, "result = %d\n", result); | ||
226 | |||
227 | /* send 6th cmd */ | ||
228 | /* | ||
229 | * 16.0 CTL a1 21 00 00 00 00 07 00 CLASS 33.1.0 | ||
230 | * 16.0 DI 00 c2 01 00 00 00 08 | ||
231 | */ | ||
232 | len = 0x0007; | ||
233 | result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
234 | 0x21, 0xa1, | ||
235 | 0x0000, 0x0000, buf, len, | ||
236 | USB_CTRL_GET_TIMEOUT); | ||
237 | debug_data(dev, __func__, len, buf, result); | ||
238 | |||
239 | /* send 7th cmd */ | ||
240 | /* | ||
241 | * 16.0 CTL 21 20 00 00 00 00 07 00 CLASS 354.1.0 | ||
242 | * 16.0 DO 00 c2 01 00 00 00 08 ....... 354.2.0 | ||
243 | */ | ||
244 | len = 0x0007; | ||
245 | buf[0] = 0x00; | ||
246 | buf[1] = 0xc2; | ||
247 | buf[2] = 0x01; | ||
248 | buf[3] = 0x00; | ||
249 | buf[4] = 0x00; | ||
250 | buf[5] = 0x00; | ||
251 | buf[6] = 0x08; | ||
252 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
253 | 0x20, 0x21, | ||
254 | 0x0000, 0x0000, buf, len, | ||
255 | USB_CTRL_GET_TIMEOUT); | ||
256 | debug_data(dev, __func__, len, buf, result); | ||
257 | |||
258 | /* send 8th cmd */ | ||
259 | /* | ||
260 | * 16.0 CTL 21 22 03 00 00 00 00 00 | ||
261 | */ | ||
262 | len = 0; | ||
263 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
264 | 0x22, 0x21, | ||
265 | 0x0003, 0x0000, NULL, len, | ||
266 | USB_CTRL_GET_TIMEOUT); | ||
267 | dev_dbg(dev, "result = %d\n", result); | ||
268 | |||
269 | kfree(buf); | ||
270 | |||
271 | usb_serial_generic_close(port); | ||
272 | } | ||
273 | |||
274 | static const struct usb_device_id id_table[] = { | ||
275 | { USB_DEVICE(0x19d2, 0xffec) }, | ||
276 | { USB_DEVICE(0x19d2, 0xffee) }, | ||
277 | { USB_DEVICE(0x19d2, 0xfff6) }, | ||
278 | { USB_DEVICE(0x19d2, 0xfff7) }, | ||
279 | { USB_DEVICE(0x19d2, 0xfff8) }, | ||
280 | { USB_DEVICE(0x19d2, 0xfff9) }, | ||
281 | { USB_DEVICE(0x19d2, 0xfffb) }, | ||
282 | { USB_DEVICE(0x19d2, 0xfffc) }, | ||
283 | /* MG880 */ | ||
284 | { USB_DEVICE(0x19d2, 0xfffd) }, | ||
285 | { }, | ||
286 | }; | ||
287 | MODULE_DEVICE_TABLE(usb, id_table); | ||
288 | |||
289 | static struct usb_serial_driver zio_device = { | ||
290 | .driver = { | ||
291 | .owner = THIS_MODULE, | ||
292 | .name = "zte_ev", | ||
293 | }, | ||
294 | .id_table = id_table, | ||
295 | .num_ports = 1, | ||
296 | .open = zte_ev_usb_serial_open, | ||
297 | .close = zte_ev_usb_serial_close, | ||
298 | }; | ||
299 | |||
300 | static struct usb_serial_driver * const serial_drivers[] = { | ||
301 | &zio_device, NULL | ||
302 | }; | ||
303 | |||
304 | module_usb_serial_driver(serial_drivers, id_table); | ||
305 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c index 6636a583da12..62c2d9daa7d6 100644 --- a/drivers/usb/storage/alauda.c +++ b/drivers/usb/storage/alauda.c | |||
@@ -415,14 +415,11 @@ static int alauda_init_media(struct us_data *us) | |||
415 | if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) | 415 | if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) |
416 | return USB_STOR_TRANSPORT_ERROR; | 416 | return USB_STOR_TRANSPORT_ERROR; |
417 | 417 | ||
418 | usb_stor_dbg(us, "Media signature: %02X %02X %02X %02X\n", | 418 | usb_stor_dbg(us, "Media signature: %4ph\n", data); |
419 | data[0], data[1], data[2], data[3]); | ||
420 | media_info = alauda_card_find_id(data[1]); | 419 | media_info = alauda_card_find_id(data[1]); |
421 | if (media_info == NULL) { | 420 | if (media_info == NULL) { |
422 | printk(KERN_WARNING | 421 | pr_warn("alauda_init_media: Unrecognised media signature: %4ph\n", |
423 | "alauda_init_media: Unrecognised media signature: " | 422 | data); |
424 | "%02X %02X %02X %02X\n", | ||
425 | data[0], data[1], data[2], data[3]); | ||
426 | return USB_STOR_TRANSPORT_ERROR; | 423 | return USB_STOR_TRANSPORT_ERROR; |
427 | } | 424 | } |
428 | 425 | ||
@@ -513,7 +510,7 @@ static int alauda_check_status2(struct us_data *us) | |||
513 | if (rc != USB_STOR_XFER_GOOD) | 510 | if (rc != USB_STOR_XFER_GOOD) |
514 | return rc; | 511 | return rc; |
515 | 512 | ||
516 | usb_stor_dbg(us, "%02X %02X %02X\n", data[0], data[1], data[2]); | 513 | usb_stor_dbg(us, "%3ph\n", data); |
517 | if (data[0] & ALAUDA_STATUS_ERROR) | 514 | if (data[0] & ALAUDA_STATUS_ERROR) |
518 | return USB_STOR_XFER_ERROR; | 515 | return USB_STOR_XFER_ERROR; |
519 | 516 | ||
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c index 5a8b5ff1e45b..4bc2fc98636e 100644 --- a/drivers/usb/storage/initializers.c +++ b/drivers/usb/storage/initializers.c | |||
@@ -52,7 +52,7 @@ int usb_stor_euscsi_init(struct us_data *us) | |||
52 | us->iobuf[0] = 0x1; | 52 | us->iobuf[0] = 0x1; |
53 | result = usb_stor_control_msg(us, us->send_ctrl_pipe, | 53 | result = usb_stor_control_msg(us, us->send_ctrl_pipe, |
54 | 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, | 54 | 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, |
55 | 0x01, 0x0, us->iobuf, 0x1, 5000); | 55 | 0x01, 0x0, us->iobuf, 0x1, USB_CTRL_SET_TIMEOUT); |
56 | usb_stor_dbg(us, "-- result is %d\n", result); | 56 | usb_stor_dbg(us, "-- result is %d\n", result); |
57 | 57 | ||
58 | return 0; | 58 | return 0; |
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c index 281be56d5648..8591d89a38e6 100644 --- a/drivers/usb/storage/realtek_cr.c +++ b/drivers/usb/storage/realtek_cr.c | |||
@@ -115,7 +115,7 @@ struct rts51x_chip { | |||
115 | enum RTS51X_STAT state; | 115 | enum RTS51X_STAT state; |
116 | int support_auto_delink; | 116 | int support_auto_delink; |
117 | #endif | 117 | #endif |
118 | /* used to back up the protocal choosen in probe1 phase */ | 118 | /* used to back up the protocol chosen in probe1 phase */ |
119 | proto_cmnd proto_handler_backup; | 119 | proto_cmnd proto_handler_backup; |
120 | }; | 120 | }; |
121 | 121 | ||
@@ -925,7 +925,7 @@ static int realtek_cr_autosuspend_setup(struct us_data *us) | |||
925 | (unsigned long)chip); | 925 | (unsigned long)chip); |
926 | fw5895_init(us); | 926 | fw5895_init(us); |
927 | 927 | ||
928 | /* enable autosuspend funciton of the usb device */ | 928 | /* enable autosuspend function of the usb device */ |
929 | usb_enable_autosuspend(us->pusb_dev); | 929 | usb_enable_autosuspend(us->pusb_dev); |
930 | 930 | ||
931 | return 0; | 931 | return 0; |
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c index 866b5df36ed1..0e400f382f3a 100644 --- a/drivers/usb/storage/scsiglue.c +++ b/drivers/usb/storage/scsiglue.c | |||
@@ -241,7 +241,7 @@ static int slave_configure(struct scsi_device *sdev) | |||
241 | 241 | ||
242 | /* Some USB cardreaders have trouble reading an sdcard's last | 242 | /* Some USB cardreaders have trouble reading an sdcard's last |
243 | * sector in a larger then 1 sector read, since the performance | 243 | * sector in a larger then 1 sector read, since the performance |
244 | * impact is negible we set this flag for all USB disks */ | 244 | * impact is negligible we set this flag for all USB disks */ |
245 | sdev->last_sector_bug = 1; | 245 | sdev->last_sector_bug = 1; |
246 | 246 | ||
247 | /* Enable last-sector hacks for single-target devices using | 247 | /* Enable last-sector hacks for single-target devices using |
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index 38a4504ce450..3847053d732c 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c | |||
@@ -1155,8 +1155,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) { | |||
1155 | return NULL; | 1155 | return NULL; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | sprintf(blurbtxt, "sddr09: Found Flash card, ID = %02X %02X %02X %02X", | 1158 | sprintf(blurbtxt, "sddr09: Found Flash card, ID = %4ph", deviceID); |
1159 | deviceID[0], deviceID[1], deviceID[2], deviceID[3]); | ||
1160 | 1159 | ||
1161 | /* Byte 0 is the manufacturer */ | 1160 | /* Byte 0 is the manufacturer */ |
1162 | sprintf(blurbtxt + strlen(blurbtxt), | 1161 | sprintf(blurbtxt + strlen(blurbtxt), |
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 3f42785f653c..89b24349269e 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * USB Attached SCSI | 2 | * USB Attached SCSI |
3 | * Note that this is not the same as the USB Mass Storage driver | 3 | * Note that this is not the same as the USB Mass Storage driver |
4 | * | 4 | * |
5 | * Copyright Hans de Goede <hdegoede@redhat.com> for Red Hat, Inc. 2013 | 5 | * Copyright Hans de Goede <hdegoede@redhat.com> for Red Hat, Inc. 2013 - 2014 |
6 | * Copyright Matthew Wilcox for Intel Corp, 2010 | 6 | * Copyright Matthew Wilcox for Intel Corp, 2010 |
7 | * Copyright Sarah Sharp for Intel Corp, 2010 | 7 | * Copyright Sarah Sharp for Intel Corp, 2010 |
8 | * | 8 | * |
@@ -28,20 +28,9 @@ | |||
28 | #include <scsi/scsi_tcq.h> | 28 | #include <scsi/scsi_tcq.h> |
29 | 29 | ||
30 | #include "uas-detect.h" | 30 | #include "uas-detect.h" |
31 | #include "scsiglue.h" | ||
31 | 32 | ||
32 | /* | 33 | #define MAX_CMNDS 256 |
33 | * The r00-r01c specs define this version of the SENSE IU data structure. | ||
34 | * It's still in use by several different firmware releases. | ||
35 | */ | ||
36 | struct sense_iu_old { | ||
37 | __u8 iu_id; | ||
38 | __u8 rsvd1; | ||
39 | __be16 tag; | ||
40 | __be16 len; | ||
41 | __u8 status; | ||
42 | __u8 service_response; | ||
43 | __u8 sense[SCSI_SENSE_BUFFERSIZE]; | ||
44 | }; | ||
45 | 34 | ||
46 | struct uas_dev_info { | 35 | struct uas_dev_info { |
47 | struct usb_interface *intf; | 36 | struct usb_interface *intf; |
@@ -49,18 +38,14 @@ struct uas_dev_info { | |||
49 | struct usb_anchor cmd_urbs; | 38 | struct usb_anchor cmd_urbs; |
50 | struct usb_anchor sense_urbs; | 39 | struct usb_anchor sense_urbs; |
51 | struct usb_anchor data_urbs; | 40 | struct usb_anchor data_urbs; |
41 | unsigned long flags; | ||
52 | int qdepth, resetting; | 42 | int qdepth, resetting; |
53 | struct response_iu response; | ||
54 | unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; | 43 | unsigned cmd_pipe, status_pipe, data_in_pipe, data_out_pipe; |
55 | unsigned use_streams:1; | 44 | unsigned use_streams:1; |
56 | unsigned uas_sense_old:1; | ||
57 | unsigned running_task:1; | ||
58 | unsigned shutdown:1; | 45 | unsigned shutdown:1; |
59 | struct scsi_cmnd *cmnd; | 46 | struct scsi_cmnd *cmnd[MAX_CMNDS]; |
60 | spinlock_t lock; | 47 | spinlock_t lock; |
61 | struct work_struct work; | 48 | struct work_struct work; |
62 | struct list_head inflight_list; | ||
63 | struct list_head dead_list; | ||
64 | }; | 49 | }; |
65 | 50 | ||
66 | enum { | 51 | enum { |
@@ -74,10 +59,8 @@ enum { | |||
74 | COMMAND_INFLIGHT = (1 << 8), | 59 | COMMAND_INFLIGHT = (1 << 8), |
75 | DATA_IN_URB_INFLIGHT = (1 << 9), | 60 | DATA_IN_URB_INFLIGHT = (1 << 9), |
76 | DATA_OUT_URB_INFLIGHT = (1 << 10), | 61 | DATA_OUT_URB_INFLIGHT = (1 << 10), |
77 | COMMAND_COMPLETED = (1 << 11), | 62 | COMMAND_ABORTED = (1 << 11), |
78 | COMMAND_ABORTED = (1 << 12), | 63 | IS_IN_WORK_LIST = (1 << 12), |
79 | UNLINK_DATA_URBS = (1 << 13), | ||
80 | IS_IN_WORK_LIST = (1 << 14), | ||
81 | }; | 64 | }; |
82 | 65 | ||
83 | /* Overrides scsi_pointer */ | 66 | /* Overrides scsi_pointer */ |
@@ -87,7 +70,6 @@ struct uas_cmd_info { | |||
87 | struct urb *cmd_urb; | 70 | struct urb *cmd_urb; |
88 | struct urb *data_in_urb; | 71 | struct urb *data_in_urb; |
89 | struct urb *data_out_urb; | 72 | struct urb *data_out_urb; |
90 | struct list_head list; | ||
91 | }; | 73 | }; |
92 | 74 | ||
93 | /* I hate forward declarations, but I actually have a loop */ | 75 | /* I hate forward declarations, but I actually have a loop */ |
@@ -96,43 +78,29 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
96 | static void uas_do_work(struct work_struct *work); | 78 | static void uas_do_work(struct work_struct *work); |
97 | static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller); | 79 | static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller); |
98 | static void uas_free_streams(struct uas_dev_info *devinfo); | 80 | static void uas_free_streams(struct uas_dev_info *devinfo); |
99 | static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *caller); | 81 | static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix, |
100 | 82 | int status); | |
101 | /* Must be called with devinfo->lock held, will temporary unlock the lock */ | ||
102 | static void uas_unlink_data_urbs(struct uas_dev_info *devinfo, | ||
103 | struct uas_cmd_info *cmdinfo, | ||
104 | unsigned long *lock_flags) | ||
105 | { | ||
106 | /* | ||
107 | * The UNLINK_DATA_URBS flag makes sure uas_try_complete | ||
108 | * (called by urb completion) doesn't release cmdinfo | ||
109 | * underneath us. | ||
110 | */ | ||
111 | cmdinfo->state |= UNLINK_DATA_URBS; | ||
112 | spin_unlock_irqrestore(&devinfo->lock, *lock_flags); | ||
113 | |||
114 | if (cmdinfo->data_in_urb) | ||
115 | usb_unlink_urb(cmdinfo->data_in_urb); | ||
116 | if (cmdinfo->data_out_urb) | ||
117 | usb_unlink_urb(cmdinfo->data_out_urb); | ||
118 | |||
119 | spin_lock_irqsave(&devinfo->lock, *lock_flags); | ||
120 | cmdinfo->state &= ~UNLINK_DATA_URBS; | ||
121 | } | ||
122 | 83 | ||
123 | static void uas_do_work(struct work_struct *work) | 84 | static void uas_do_work(struct work_struct *work) |
124 | { | 85 | { |
125 | struct uas_dev_info *devinfo = | 86 | struct uas_dev_info *devinfo = |
126 | container_of(work, struct uas_dev_info, work); | 87 | container_of(work, struct uas_dev_info, work); |
127 | struct uas_cmd_info *cmdinfo; | 88 | struct uas_cmd_info *cmdinfo; |
89 | struct scsi_cmnd *cmnd; | ||
128 | unsigned long flags; | 90 | unsigned long flags; |
129 | int err; | 91 | int i, err; |
130 | 92 | ||
131 | spin_lock_irqsave(&devinfo->lock, flags); | 93 | spin_lock_irqsave(&devinfo->lock, flags); |
132 | list_for_each_entry(cmdinfo, &devinfo->inflight_list, list) { | 94 | |
133 | struct scsi_pointer *scp = (void *)cmdinfo; | 95 | if (devinfo->resetting) |
134 | struct scsi_cmnd *cmnd = container_of(scp, struct scsi_cmnd, | 96 | goto out; |
135 | SCp); | 97 | |
98 | for (i = 0; i < devinfo->qdepth; i++) { | ||
99 | if (!devinfo->cmnd[i]) | ||
100 | continue; | ||
101 | |||
102 | cmnd = devinfo->cmnd[i]; | ||
103 | cmdinfo = (void *)&cmnd->SCp; | ||
136 | 104 | ||
137 | if (!(cmdinfo->state & IS_IN_WORK_LIST)) | 105 | if (!(cmdinfo->state & IS_IN_WORK_LIST)) |
138 | continue; | 106 | continue; |
@@ -143,35 +111,7 @@ static void uas_do_work(struct work_struct *work) | |||
143 | else | 111 | else |
144 | schedule_work(&devinfo->work); | 112 | schedule_work(&devinfo->work); |
145 | } | 113 | } |
146 | spin_unlock_irqrestore(&devinfo->lock, flags); | 114 | out: |
147 | } | ||
148 | |||
149 | static void uas_mark_cmd_dead(struct uas_dev_info *devinfo, | ||
150 | struct uas_cmd_info *cmdinfo, | ||
151 | int result, const char *caller) | ||
152 | { | ||
153 | struct scsi_pointer *scp = (void *)cmdinfo; | ||
154 | struct scsi_cmnd *cmnd = container_of(scp, struct scsi_cmnd, SCp); | ||
155 | |||
156 | uas_log_cmd_state(cmnd, caller); | ||
157 | WARN_ON_ONCE(!spin_is_locked(&devinfo->lock)); | ||
158 | WARN_ON_ONCE(cmdinfo->state & COMMAND_ABORTED); | ||
159 | cmdinfo->state |= COMMAND_ABORTED; | ||
160 | cmdinfo->state &= ~IS_IN_WORK_LIST; | ||
161 | cmnd->result = result << 16; | ||
162 | list_move_tail(&cmdinfo->list, &devinfo->dead_list); | ||
163 | } | ||
164 | |||
165 | static void uas_abort_inflight(struct uas_dev_info *devinfo, int result, | ||
166 | const char *caller) | ||
167 | { | ||
168 | struct uas_cmd_info *cmdinfo; | ||
169 | struct uas_cmd_info *temp; | ||
170 | unsigned long flags; | ||
171 | |||
172 | spin_lock_irqsave(&devinfo->lock, flags); | ||
173 | list_for_each_entry_safe(cmdinfo, temp, &devinfo->inflight_list, list) | ||
174 | uas_mark_cmd_dead(devinfo, cmdinfo, result, caller); | ||
175 | spin_unlock_irqrestore(&devinfo->lock, flags); | 115 | spin_unlock_irqrestore(&devinfo->lock, flags); |
176 | } | 116 | } |
177 | 117 | ||
@@ -181,31 +121,32 @@ static void uas_add_work(struct uas_cmd_info *cmdinfo) | |||
181 | struct scsi_cmnd *cmnd = container_of(scp, struct scsi_cmnd, SCp); | 121 | struct scsi_cmnd *cmnd = container_of(scp, struct scsi_cmnd, SCp); |
182 | struct uas_dev_info *devinfo = cmnd->device->hostdata; | 122 | struct uas_dev_info *devinfo = cmnd->device->hostdata; |
183 | 123 | ||
184 | WARN_ON_ONCE(!spin_is_locked(&devinfo->lock)); | 124 | lockdep_assert_held(&devinfo->lock); |
185 | cmdinfo->state |= IS_IN_WORK_LIST; | 125 | cmdinfo->state |= IS_IN_WORK_LIST; |
186 | schedule_work(&devinfo->work); | 126 | schedule_work(&devinfo->work); |
187 | } | 127 | } |
188 | 128 | ||
189 | static void uas_zap_dead(struct uas_dev_info *devinfo) | 129 | static void uas_zap_pending(struct uas_dev_info *devinfo, int result) |
190 | { | 130 | { |
191 | struct uas_cmd_info *cmdinfo; | 131 | struct uas_cmd_info *cmdinfo; |
192 | struct uas_cmd_info *temp; | 132 | struct scsi_cmnd *cmnd; |
193 | unsigned long flags; | 133 | unsigned long flags; |
134 | int i, err; | ||
194 | 135 | ||
195 | spin_lock_irqsave(&devinfo->lock, flags); | 136 | spin_lock_irqsave(&devinfo->lock, flags); |
196 | list_for_each_entry_safe(cmdinfo, temp, &devinfo->dead_list, list) { | 137 | for (i = 0; i < devinfo->qdepth; i++) { |
197 | struct scsi_pointer *scp = (void *)cmdinfo; | 138 | if (!devinfo->cmnd[i]) |
198 | struct scsi_cmnd *cmnd = container_of(scp, struct scsi_cmnd, | 139 | continue; |
199 | SCp); | 140 | |
200 | uas_log_cmd_state(cmnd, __func__); | 141 | cmnd = devinfo->cmnd[i]; |
201 | WARN_ON_ONCE(!(cmdinfo->state & COMMAND_ABORTED)); | 142 | cmdinfo = (void *)&cmnd->SCp; |
202 | /* all urbs are killed, clear inflight bits */ | 143 | uas_log_cmd_state(cmnd, __func__, 0); |
203 | cmdinfo->state &= ~(COMMAND_INFLIGHT | | 144 | /* Sense urbs were killed, clear COMMAND_INFLIGHT manually */ |
204 | DATA_IN_URB_INFLIGHT | | 145 | cmdinfo->state &= ~COMMAND_INFLIGHT; |
205 | DATA_OUT_URB_INFLIGHT); | 146 | cmnd->result = result << 16; |
206 | uas_try_complete(cmnd, __func__); | 147 | err = uas_try_complete(cmnd, __func__); |
148 | WARN_ON(err != 0); | ||
207 | } | 149 | } |
208 | devinfo->running_task = 0; | ||
209 | spin_unlock_irqrestore(&devinfo->lock, flags); | 150 | spin_unlock_irqrestore(&devinfo->lock, flags); |
210 | } | 151 | } |
211 | 152 | ||
@@ -232,36 +173,30 @@ static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd) | |||
232 | cmnd->result = sense_iu->status; | 173 | cmnd->result = sense_iu->status; |
233 | } | 174 | } |
234 | 175 | ||
235 | static void uas_sense_old(struct urb *urb, struct scsi_cmnd *cmnd) | 176 | /* |
177 | * scsi-tags go from 0 - (nr_tags - 1), uas tags need to match stream-ids, | ||
178 | * which go from 1 - nr_streams. And we use 1 for untagged commands. | ||
179 | */ | ||
180 | static int uas_get_tag(struct scsi_cmnd *cmnd) | ||
236 | { | 181 | { |
237 | struct sense_iu_old *sense_iu = urb->transfer_buffer; | 182 | int tag; |
238 | struct scsi_device *sdev = cmnd->device; | ||
239 | 183 | ||
240 | if (urb->actual_length > 8) { | 184 | if (blk_rq_tagged(cmnd->request)) |
241 | unsigned len = be16_to_cpup(&sense_iu->len) - 2; | 185 | tag = cmnd->request->tag + 2; |
242 | if (len + 8 != urb->actual_length) { | 186 | else |
243 | int newlen = min(len + 8, urb->actual_length) - 8; | 187 | tag = 1; |
244 | if (newlen < 0) | ||
245 | newlen = 0; | ||
246 | sdev_printk(KERN_INFO, sdev, "%s: urb length %d " | ||
247 | "disagrees with IU sense data length %d, " | ||
248 | "using %d bytes of sense data\n", __func__, | ||
249 | urb->actual_length, len, newlen); | ||
250 | len = newlen; | ||
251 | } | ||
252 | memcpy(cmnd->sense_buffer, sense_iu->sense, len); | ||
253 | } | ||
254 | 188 | ||
255 | cmnd->result = sense_iu->status; | 189 | return tag; |
256 | } | 190 | } |
257 | 191 | ||
258 | static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *caller) | 192 | static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix, |
193 | int status) | ||
259 | { | 194 | { |
260 | struct uas_cmd_info *ci = (void *)&cmnd->SCp; | 195 | struct uas_cmd_info *ci = (void *)&cmnd->SCp; |
261 | 196 | ||
262 | scmd_printk(KERN_INFO, cmnd, "%s %p tag %d, inflight:" | 197 | scmd_printk(KERN_INFO, cmnd, |
263 | "%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", | 198 | "%s %d tag %d inflight:%s%s%s%s%s%s%s%s%s%s%s%s ", |
264 | caller, cmnd, cmnd->request->tag, | 199 | prefix, status, uas_get_tag(cmnd), |
265 | (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "", | 200 | (ci->state & SUBMIT_STATUS_URB) ? " s-st" : "", |
266 | (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "", | 201 | (ci->state & ALLOC_DATA_IN_URB) ? " a-in" : "", |
267 | (ci->state & SUBMIT_DATA_IN_URB) ? " s-in" : "", | 202 | (ci->state & SUBMIT_DATA_IN_URB) ? " s-in" : "", |
@@ -272,10 +207,28 @@ static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *caller) | |||
272 | (ci->state & COMMAND_INFLIGHT) ? " CMD" : "", | 207 | (ci->state & COMMAND_INFLIGHT) ? " CMD" : "", |
273 | (ci->state & DATA_IN_URB_INFLIGHT) ? " IN" : "", | 208 | (ci->state & DATA_IN_URB_INFLIGHT) ? " IN" : "", |
274 | (ci->state & DATA_OUT_URB_INFLIGHT) ? " OUT" : "", | 209 | (ci->state & DATA_OUT_URB_INFLIGHT) ? " OUT" : "", |
275 | (ci->state & COMMAND_COMPLETED) ? " done" : "", | ||
276 | (ci->state & COMMAND_ABORTED) ? " abort" : "", | 210 | (ci->state & COMMAND_ABORTED) ? " abort" : "", |
277 | (ci->state & UNLINK_DATA_URBS) ? " unlink": "", | ||
278 | (ci->state & IS_IN_WORK_LIST) ? " work" : ""); | 211 | (ci->state & IS_IN_WORK_LIST) ? " work" : ""); |
212 | scsi_print_command(cmnd); | ||
213 | } | ||
214 | |||
215 | static void uas_free_unsubmitted_urbs(struct scsi_cmnd *cmnd) | ||
216 | { | ||
217 | struct uas_cmd_info *cmdinfo; | ||
218 | |||
219 | if (!cmnd) | ||
220 | return; | ||
221 | |||
222 | cmdinfo = (void *)&cmnd->SCp; | ||
223 | |||
224 | if (cmdinfo->state & SUBMIT_CMD_URB) | ||
225 | usb_free_urb(cmdinfo->cmd_urb); | ||
226 | |||
227 | /* data urbs may have never gotten their submit flag set */ | ||
228 | if (!(cmdinfo->state & DATA_IN_URB_INFLIGHT)) | ||
229 | usb_free_urb(cmdinfo->data_in_urb); | ||
230 | if (!(cmdinfo->state & DATA_OUT_URB_INFLIGHT)) | ||
231 | usb_free_urb(cmdinfo->data_out_urb); | ||
279 | } | 232 | } |
280 | 233 | ||
281 | static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) | 234 | static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) |
@@ -283,19 +236,14 @@ static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller) | |||
283 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; | 236 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
284 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; | 237 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
285 | 238 | ||
286 | WARN_ON_ONCE(!spin_is_locked(&devinfo->lock)); | 239 | lockdep_assert_held(&devinfo->lock); |
287 | if (cmdinfo->state & (COMMAND_INFLIGHT | | 240 | if (cmdinfo->state & (COMMAND_INFLIGHT | |
288 | DATA_IN_URB_INFLIGHT | | 241 | DATA_IN_URB_INFLIGHT | |
289 | DATA_OUT_URB_INFLIGHT | | 242 | DATA_OUT_URB_INFLIGHT | |
290 | UNLINK_DATA_URBS)) | 243 | COMMAND_ABORTED)) |
291 | return -EBUSY; | 244 | return -EBUSY; |
292 | WARN_ON_ONCE(cmdinfo->state & COMMAND_COMPLETED); | 245 | devinfo->cmnd[uas_get_tag(cmnd) - 1] = NULL; |
293 | cmdinfo->state |= COMMAND_COMPLETED; | 246 | uas_free_unsubmitted_urbs(cmnd); |
294 | usb_free_urb(cmdinfo->data_in_urb); | ||
295 | usb_free_urb(cmdinfo->data_out_urb); | ||
296 | if (cmdinfo->state & COMMAND_ABORTED) | ||
297 | scmd_printk(KERN_INFO, cmnd, "abort completed\n"); | ||
298 | list_del(&cmdinfo->list); | ||
299 | cmnd->scsi_done(cmnd); | 247 | cmnd->scsi_done(cmnd); |
300 | return 0; | 248 | return 0; |
301 | } | 249 | } |
@@ -318,63 +266,48 @@ static void uas_stat_cmplt(struct urb *urb) | |||
318 | struct iu *iu = urb->transfer_buffer; | 266 | struct iu *iu = urb->transfer_buffer; |
319 | struct Scsi_Host *shost = urb->context; | 267 | struct Scsi_Host *shost = urb->context; |
320 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 268 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; |
269 | struct urb *data_in_urb = NULL; | ||
270 | struct urb *data_out_urb = NULL; | ||
321 | struct scsi_cmnd *cmnd; | 271 | struct scsi_cmnd *cmnd; |
322 | struct uas_cmd_info *cmdinfo; | 272 | struct uas_cmd_info *cmdinfo; |
323 | unsigned long flags; | 273 | unsigned long flags; |
324 | u16 tag; | 274 | unsigned int idx; |
275 | |||
276 | spin_lock_irqsave(&devinfo->lock, flags); | ||
277 | |||
278 | if (devinfo->resetting) | ||
279 | goto out; | ||
325 | 280 | ||
326 | if (urb->status) { | 281 | if (urb->status) { |
327 | if (urb->status == -ENOENT) { | 282 | if (urb->status != -ENOENT && urb->status != -ECONNRESET) { |
328 | dev_err(&urb->dev->dev, "stat urb: killed, stream %d\n", | ||
329 | urb->stream_id); | ||
330 | } else { | ||
331 | dev_err(&urb->dev->dev, "stat urb: status %d\n", | 283 | dev_err(&urb->dev->dev, "stat urb: status %d\n", |
332 | urb->status); | 284 | urb->status); |
333 | } | 285 | } |
334 | usb_free_urb(urb); | 286 | goto out; |
335 | return; | ||
336 | } | 287 | } |
337 | 288 | ||
338 | if (devinfo->resetting) { | 289 | idx = be16_to_cpup(&iu->tag) - 1; |
339 | usb_free_urb(urb); | 290 | if (idx >= MAX_CMNDS || !devinfo->cmnd[idx]) { |
340 | return; | 291 | dev_err(&urb->dev->dev, |
292 | "stat urb: no pending cmd for tag %d\n", idx + 1); | ||
293 | goto out; | ||
341 | } | 294 | } |
342 | 295 | ||
343 | spin_lock_irqsave(&devinfo->lock, flags); | 296 | cmnd = devinfo->cmnd[idx]; |
344 | tag = be16_to_cpup(&iu->tag) - 1; | 297 | cmdinfo = (void *)&cmnd->SCp; |
345 | if (tag == 0) | 298 | |
346 | cmnd = devinfo->cmnd; | 299 | if (!(cmdinfo->state & COMMAND_INFLIGHT)) { |
347 | else | 300 | uas_log_cmd_state(cmnd, "unexpected status cmplt", 0); |
348 | cmnd = scsi_host_find_tag(shost, tag - 1); | 301 | goto out; |
349 | |||
350 | if (!cmnd) { | ||
351 | if (iu->iu_id == IU_ID_RESPONSE) { | ||
352 | if (!devinfo->running_task) | ||
353 | dev_warn(&urb->dev->dev, | ||
354 | "stat urb: recv unexpected response iu\n"); | ||
355 | /* store results for uas_eh_task_mgmt() */ | ||
356 | memcpy(&devinfo->response, iu, sizeof(devinfo->response)); | ||
357 | } | ||
358 | usb_free_urb(urb); | ||
359 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
360 | return; | ||
361 | } | 302 | } |
362 | 303 | ||
363 | cmdinfo = (void *)&cmnd->SCp; | ||
364 | switch (iu->iu_id) { | 304 | switch (iu->iu_id) { |
365 | case IU_ID_STATUS: | 305 | case IU_ID_STATUS: |
366 | if (devinfo->cmnd == cmnd) | 306 | uas_sense(urb, cmnd); |
367 | devinfo->cmnd = NULL; | ||
368 | |||
369 | if (urb->actual_length < 16) | ||
370 | devinfo->uas_sense_old = 1; | ||
371 | if (devinfo->uas_sense_old) | ||
372 | uas_sense_old(urb, cmnd); | ||
373 | else | ||
374 | uas_sense(urb, cmnd); | ||
375 | if (cmnd->result != 0) { | 307 | if (cmnd->result != 0) { |
376 | /* cancel data transfers on error */ | 308 | /* cancel data transfers on error */ |
377 | uas_unlink_data_urbs(devinfo, cmdinfo, &flags); | 309 | data_in_urb = usb_get_urb(cmdinfo->data_in_urb); |
310 | data_out_urb = usb_get_urb(cmdinfo->data_out_urb); | ||
378 | } | 311 | } |
379 | cmdinfo->state &= ~COMMAND_INFLIGHT; | 312 | cmdinfo->state &= ~COMMAND_INFLIGHT; |
380 | uas_try_complete(cmnd, __func__); | 313 | uas_try_complete(cmnd, __func__); |
@@ -382,7 +315,7 @@ static void uas_stat_cmplt(struct urb *urb) | |||
382 | case IU_ID_READ_READY: | 315 | case IU_ID_READ_READY: |
383 | if (!cmdinfo->data_in_urb || | 316 | if (!cmdinfo->data_in_urb || |
384 | (cmdinfo->state & DATA_IN_URB_INFLIGHT)) { | 317 | (cmdinfo->state & DATA_IN_URB_INFLIGHT)) { |
385 | scmd_printk(KERN_ERR, cmnd, "unexpected read rdy\n"); | 318 | uas_log_cmd_state(cmnd, "unexpected read rdy", 0); |
386 | break; | 319 | break; |
387 | } | 320 | } |
388 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB); | 321 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_IN_URB); |
@@ -390,17 +323,37 @@ static void uas_stat_cmplt(struct urb *urb) | |||
390 | case IU_ID_WRITE_READY: | 323 | case IU_ID_WRITE_READY: |
391 | if (!cmdinfo->data_out_urb || | 324 | if (!cmdinfo->data_out_urb || |
392 | (cmdinfo->state & DATA_OUT_URB_INFLIGHT)) { | 325 | (cmdinfo->state & DATA_OUT_URB_INFLIGHT)) { |
393 | scmd_printk(KERN_ERR, cmnd, "unexpected write rdy\n"); | 326 | uas_log_cmd_state(cmnd, "unexpected write rdy", 0); |
394 | break; | 327 | break; |
395 | } | 328 | } |
396 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB); | 329 | uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB); |
397 | break; | 330 | break; |
331 | case IU_ID_RESPONSE: | ||
332 | uas_log_cmd_state(cmnd, "unexpected response iu", | ||
333 | ((struct response_iu *)iu)->response_code); | ||
334 | /* Error, cancel data transfers */ | ||
335 | data_in_urb = usb_get_urb(cmdinfo->data_in_urb); | ||
336 | data_out_urb = usb_get_urb(cmdinfo->data_out_urb); | ||
337 | cmdinfo->state &= ~COMMAND_INFLIGHT; | ||
338 | cmnd->result = DID_ERROR << 16; | ||
339 | uas_try_complete(cmnd, __func__); | ||
340 | break; | ||
398 | default: | 341 | default: |
399 | scmd_printk(KERN_ERR, cmnd, | 342 | uas_log_cmd_state(cmnd, "bogus IU", iu->iu_id); |
400 | "Bogus IU (%d) received on status pipe\n", iu->iu_id); | ||
401 | } | 343 | } |
344 | out: | ||
402 | usb_free_urb(urb); | 345 | usb_free_urb(urb); |
403 | spin_unlock_irqrestore(&devinfo->lock, flags); | 346 | spin_unlock_irqrestore(&devinfo->lock, flags); |
347 | |||
348 | /* Unlinking of data urbs must be done without holding the lock */ | ||
349 | if (data_in_urb) { | ||
350 | usb_unlink_urb(data_in_urb); | ||
351 | usb_put_urb(data_in_urb); | ||
352 | } | ||
353 | if (data_out_urb) { | ||
354 | usb_unlink_urb(data_out_urb); | ||
355 | usb_put_urb(data_out_urb); | ||
356 | } | ||
404 | } | 357 | } |
405 | 358 | ||
406 | static void uas_data_cmplt(struct urb *urb) | 359 | static void uas_data_cmplt(struct urb *urb) |
@@ -412,57 +365,69 @@ static void uas_data_cmplt(struct urb *urb) | |||
412 | unsigned long flags; | 365 | unsigned long flags; |
413 | 366 | ||
414 | spin_lock_irqsave(&devinfo->lock, flags); | 367 | spin_lock_irqsave(&devinfo->lock, flags); |
368 | |||
415 | if (cmdinfo->data_in_urb == urb) { | 369 | if (cmdinfo->data_in_urb == urb) { |
416 | sdb = scsi_in(cmnd); | 370 | sdb = scsi_in(cmnd); |
417 | cmdinfo->state &= ~DATA_IN_URB_INFLIGHT; | 371 | cmdinfo->state &= ~DATA_IN_URB_INFLIGHT; |
372 | cmdinfo->data_in_urb = NULL; | ||
418 | } else if (cmdinfo->data_out_urb == urb) { | 373 | } else if (cmdinfo->data_out_urb == urb) { |
419 | sdb = scsi_out(cmnd); | 374 | sdb = scsi_out(cmnd); |
420 | cmdinfo->state &= ~DATA_OUT_URB_INFLIGHT; | 375 | cmdinfo->state &= ~DATA_OUT_URB_INFLIGHT; |
376 | cmdinfo->data_out_urb = NULL; | ||
421 | } | 377 | } |
422 | if (sdb == NULL) { | 378 | if (sdb == NULL) { |
423 | WARN_ON_ONCE(1); | 379 | WARN_ON_ONCE(1); |
424 | } else if (urb->status) { | 380 | goto out; |
425 | if (urb->status != -ECONNRESET) { | 381 | } |
426 | uas_log_cmd_state(cmnd, __func__); | 382 | |
427 | scmd_printk(KERN_ERR, cmnd, | 383 | if (devinfo->resetting) |
428 | "data cmplt err %d stream %d\n", | 384 | goto out; |
429 | urb->status, urb->stream_id); | 385 | |
430 | } | 386 | /* Data urbs should not complete before the cmd urb is submitted */ |
387 | if (cmdinfo->state & SUBMIT_CMD_URB) { | ||
388 | uas_log_cmd_state(cmnd, "unexpected data cmplt", 0); | ||
389 | goto out; | ||
390 | } | ||
391 | |||
392 | if (urb->status) { | ||
393 | if (urb->status != -ENOENT && urb->status != -ECONNRESET) | ||
394 | uas_log_cmd_state(cmnd, "data cmplt err", urb->status); | ||
431 | /* error: no data transfered */ | 395 | /* error: no data transfered */ |
432 | sdb->resid = sdb->length; | 396 | sdb->resid = sdb->length; |
433 | } else { | 397 | } else { |
434 | sdb->resid = sdb->length - urb->actual_length; | 398 | sdb->resid = sdb->length - urb->actual_length; |
435 | } | 399 | } |
436 | uas_try_complete(cmnd, __func__); | 400 | uas_try_complete(cmnd, __func__); |
401 | out: | ||
402 | usb_free_urb(urb); | ||
437 | spin_unlock_irqrestore(&devinfo->lock, flags); | 403 | spin_unlock_irqrestore(&devinfo->lock, flags); |
438 | } | 404 | } |
439 | 405 | ||
440 | static void uas_cmd_cmplt(struct urb *urb) | 406 | static void uas_cmd_cmplt(struct urb *urb) |
441 | { | 407 | { |
442 | struct scsi_cmnd *cmnd = urb->context; | 408 | if (urb->status) |
409 | dev_err(&urb->dev->dev, "cmd cmplt err %d\n", urb->status); | ||
443 | 410 | ||
444 | if (urb->status) { | ||
445 | uas_log_cmd_state(cmnd, __func__); | ||
446 | scmd_printk(KERN_ERR, cmnd, "cmd cmplt err %d\n", urb->status); | ||
447 | } | ||
448 | usb_free_urb(urb); | 411 | usb_free_urb(urb); |
449 | } | 412 | } |
450 | 413 | ||
451 | static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, | 414 | static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, |
452 | unsigned int pipe, u16 stream_id, | ||
453 | struct scsi_cmnd *cmnd, | 415 | struct scsi_cmnd *cmnd, |
454 | enum dma_data_direction dir) | 416 | enum dma_data_direction dir) |
455 | { | 417 | { |
456 | struct usb_device *udev = devinfo->udev; | 418 | struct usb_device *udev = devinfo->udev; |
419 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; | ||
457 | struct urb *urb = usb_alloc_urb(0, gfp); | 420 | struct urb *urb = usb_alloc_urb(0, gfp); |
458 | struct scsi_data_buffer *sdb = (dir == DMA_FROM_DEVICE) | 421 | struct scsi_data_buffer *sdb = (dir == DMA_FROM_DEVICE) |
459 | ? scsi_in(cmnd) : scsi_out(cmnd); | 422 | ? scsi_in(cmnd) : scsi_out(cmnd); |
423 | unsigned int pipe = (dir == DMA_FROM_DEVICE) | ||
424 | ? devinfo->data_in_pipe : devinfo->data_out_pipe; | ||
460 | 425 | ||
461 | if (!urb) | 426 | if (!urb) |
462 | goto out; | 427 | goto out; |
463 | usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, | 428 | usb_fill_bulk_urb(urb, udev, pipe, NULL, sdb->length, |
464 | uas_data_cmplt, cmnd); | 429 | uas_data_cmplt, cmnd); |
465 | urb->stream_id = stream_id; | 430 | urb->stream_id = cmdinfo->stream; |
466 | urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; | 431 | urb->num_sgs = udev->bus->sg_tablesize ? sdb->table.nents : 0; |
467 | urb->sg = sdb->table.sgl; | 432 | urb->sg = sdb->table.sgl; |
468 | out: | 433 | out: |
@@ -470,9 +435,10 @@ static struct urb *uas_alloc_data_urb(struct uas_dev_info *devinfo, gfp_t gfp, | |||
470 | } | 435 | } |
471 | 436 | ||
472 | static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, | 437 | static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, |
473 | struct Scsi_Host *shost, u16 stream_id) | 438 | struct scsi_cmnd *cmnd) |
474 | { | 439 | { |
475 | struct usb_device *udev = devinfo->udev; | 440 | struct usb_device *udev = devinfo->udev; |
441 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; | ||
476 | struct urb *urb = usb_alloc_urb(0, gfp); | 442 | struct urb *urb = usb_alloc_urb(0, gfp); |
477 | struct sense_iu *iu; | 443 | struct sense_iu *iu; |
478 | 444 | ||
@@ -484,8 +450,8 @@ static struct urb *uas_alloc_sense_urb(struct uas_dev_info *devinfo, gfp_t gfp, | |||
484 | goto free; | 450 | goto free; |
485 | 451 | ||
486 | usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu), | 452 | usb_fill_bulk_urb(urb, udev, devinfo->status_pipe, iu, sizeof(*iu), |
487 | uas_stat_cmplt, shost); | 453 | uas_stat_cmplt, cmnd->device->host); |
488 | urb->stream_id = stream_id; | 454 | urb->stream_id = cmdinfo->stream; |
489 | urb->transfer_flags |= URB_FREE_BUFFER; | 455 | urb->transfer_flags |= URB_FREE_BUFFER; |
490 | out: | 456 | out: |
491 | return urb; | 457 | return urb; |
@@ -515,17 +481,14 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, | |||
515 | goto free; | 481 | goto free; |
516 | 482 | ||
517 | iu->iu_id = IU_ID_COMMAND; | 483 | iu->iu_id = IU_ID_COMMAND; |
518 | if (blk_rq_tagged(cmnd->request)) | 484 | iu->tag = cpu_to_be16(uas_get_tag(cmnd)); |
519 | iu->tag = cpu_to_be16(cmnd->request->tag + 2); | ||
520 | else | ||
521 | iu->tag = cpu_to_be16(1); | ||
522 | iu->prio_attr = UAS_SIMPLE_TAG; | 485 | iu->prio_attr = UAS_SIMPLE_TAG; |
523 | iu->len = len; | 486 | iu->len = len; |
524 | int_to_scsilun(sdev->lun, &iu->lun); | 487 | int_to_scsilun(sdev->lun, &iu->lun); |
525 | memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len); | 488 | memcpy(iu->cdb, cmnd->cmnd, cmnd->cmd_len); |
526 | 489 | ||
527 | usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu) + len, | 490 | usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu) + len, |
528 | uas_cmd_cmplt, cmnd); | 491 | uas_cmd_cmplt, NULL); |
529 | urb->transfer_flags |= URB_FREE_BUFFER; | 492 | urb->transfer_flags |= URB_FREE_BUFFER; |
530 | out: | 493 | out: |
531 | return urb; | 494 | return urb; |
@@ -534,81 +497,26 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, | |||
534 | return NULL; | 497 | return NULL; |
535 | } | 498 | } |
536 | 499 | ||
537 | static int uas_submit_task_urb(struct scsi_cmnd *cmnd, gfp_t gfp, | ||
538 | u8 function, u16 stream_id) | ||
539 | { | ||
540 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; | ||
541 | struct usb_device *udev = devinfo->udev; | ||
542 | struct urb *urb = usb_alloc_urb(0, gfp); | ||
543 | struct task_mgmt_iu *iu; | ||
544 | int err = -ENOMEM; | ||
545 | |||
546 | if (!urb) | ||
547 | goto err; | ||
548 | |||
549 | iu = kzalloc(sizeof(*iu), gfp); | ||
550 | if (!iu) | ||
551 | goto err; | ||
552 | |||
553 | iu->iu_id = IU_ID_TASK_MGMT; | ||
554 | iu->tag = cpu_to_be16(stream_id); | ||
555 | int_to_scsilun(cmnd->device->lun, &iu->lun); | ||
556 | |||
557 | iu->function = function; | ||
558 | switch (function) { | ||
559 | case TMF_ABORT_TASK: | ||
560 | if (blk_rq_tagged(cmnd->request)) | ||
561 | iu->task_tag = cpu_to_be16(cmnd->request->tag + 2); | ||
562 | else | ||
563 | iu->task_tag = cpu_to_be16(1); | ||
564 | break; | ||
565 | } | ||
566 | |||
567 | usb_fill_bulk_urb(urb, udev, devinfo->cmd_pipe, iu, sizeof(*iu), | ||
568 | uas_cmd_cmplt, cmnd); | ||
569 | urb->transfer_flags |= URB_FREE_BUFFER; | ||
570 | |||
571 | usb_anchor_urb(urb, &devinfo->cmd_urbs); | ||
572 | err = usb_submit_urb(urb, gfp); | ||
573 | if (err) { | ||
574 | usb_unanchor_urb(urb); | ||
575 | uas_log_cmd_state(cmnd, __func__); | ||
576 | scmd_printk(KERN_ERR, cmnd, "task submission err %d\n", err); | ||
577 | goto err; | ||
578 | } | ||
579 | |||
580 | return 0; | ||
581 | |||
582 | err: | ||
583 | usb_free_urb(urb); | ||
584 | return err; | ||
585 | } | ||
586 | |||
587 | /* | 500 | /* |
588 | * Why should I request the Status IU before sending the Command IU? Spec | 501 | * Why should I request the Status IU before sending the Command IU? Spec |
589 | * says to, but also says the device may receive them in any order. Seems | 502 | * says to, but also says the device may receive them in any order. Seems |
590 | * daft to me. | 503 | * daft to me. |
591 | */ | 504 | */ |
592 | 505 | ||
593 | static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, | 506 | static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) |
594 | gfp_t gfp, unsigned int stream) | ||
595 | { | 507 | { |
596 | struct Scsi_Host *shost = cmnd->device->host; | 508 | struct uas_dev_info *devinfo = cmnd->device->hostdata; |
597 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | ||
598 | struct urb *urb; | 509 | struct urb *urb; |
599 | int err; | 510 | int err; |
600 | 511 | ||
601 | urb = uas_alloc_sense_urb(devinfo, gfp, shost, stream); | 512 | urb = uas_alloc_sense_urb(devinfo, gfp, cmnd); |
602 | if (!urb) | 513 | if (!urb) |
603 | return NULL; | 514 | return NULL; |
604 | usb_anchor_urb(urb, &devinfo->sense_urbs); | 515 | usb_anchor_urb(urb, &devinfo->sense_urbs); |
605 | err = usb_submit_urb(urb, gfp); | 516 | err = usb_submit_urb(urb, gfp); |
606 | if (err) { | 517 | if (err) { |
607 | usb_unanchor_urb(urb); | 518 | usb_unanchor_urb(urb); |
608 | uas_log_cmd_state(cmnd, __func__); | 519 | uas_log_cmd_state(cmnd, "sense submit err", err); |
609 | shost_printk(KERN_INFO, shost, | ||
610 | "sense urb submission error %d stream %d\n", | ||
611 | err, stream); | ||
612 | usb_free_urb(urb); | 520 | usb_free_urb(urb); |
613 | return NULL; | 521 | return NULL; |
614 | } | 522 | } |
@@ -622,9 +530,9 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
622 | struct urb *urb; | 530 | struct urb *urb; |
623 | int err; | 531 | int err; |
624 | 532 | ||
625 | WARN_ON_ONCE(!spin_is_locked(&devinfo->lock)); | 533 | lockdep_assert_held(&devinfo->lock); |
626 | if (cmdinfo->state & SUBMIT_STATUS_URB) { | 534 | if (cmdinfo->state & SUBMIT_STATUS_URB) { |
627 | urb = uas_submit_sense_urb(cmnd, gfp, cmdinfo->stream); | 535 | urb = uas_submit_sense_urb(cmnd, gfp); |
628 | if (!urb) | 536 | if (!urb) |
629 | return SCSI_MLQUEUE_DEVICE_BUSY; | 537 | return SCSI_MLQUEUE_DEVICE_BUSY; |
630 | cmdinfo->state &= ~SUBMIT_STATUS_URB; | 538 | cmdinfo->state &= ~SUBMIT_STATUS_URB; |
@@ -632,8 +540,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
632 | 540 | ||
633 | if (cmdinfo->state & ALLOC_DATA_IN_URB) { | 541 | if (cmdinfo->state & ALLOC_DATA_IN_URB) { |
634 | cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, | 542 | cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, |
635 | devinfo->data_in_pipe, cmdinfo->stream, | 543 | cmnd, DMA_FROM_DEVICE); |
636 | cmnd, DMA_FROM_DEVICE); | ||
637 | if (!cmdinfo->data_in_urb) | 544 | if (!cmdinfo->data_in_urb) |
638 | return SCSI_MLQUEUE_DEVICE_BUSY; | 545 | return SCSI_MLQUEUE_DEVICE_BUSY; |
639 | cmdinfo->state &= ~ALLOC_DATA_IN_URB; | 546 | cmdinfo->state &= ~ALLOC_DATA_IN_URB; |
@@ -644,10 +551,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
644 | err = usb_submit_urb(cmdinfo->data_in_urb, gfp); | 551 | err = usb_submit_urb(cmdinfo->data_in_urb, gfp); |
645 | if (err) { | 552 | if (err) { |
646 | usb_unanchor_urb(cmdinfo->data_in_urb); | 553 | usb_unanchor_urb(cmdinfo->data_in_urb); |
647 | uas_log_cmd_state(cmnd, __func__); | 554 | uas_log_cmd_state(cmnd, "data in submit err", err); |
648 | scmd_printk(KERN_INFO, cmnd, | ||
649 | "data in urb submission error %d stream %d\n", | ||
650 | err, cmdinfo->data_in_urb->stream_id); | ||
651 | return SCSI_MLQUEUE_DEVICE_BUSY; | 555 | return SCSI_MLQUEUE_DEVICE_BUSY; |
652 | } | 556 | } |
653 | cmdinfo->state &= ~SUBMIT_DATA_IN_URB; | 557 | cmdinfo->state &= ~SUBMIT_DATA_IN_URB; |
@@ -656,8 +560,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
656 | 560 | ||
657 | if (cmdinfo->state & ALLOC_DATA_OUT_URB) { | 561 | if (cmdinfo->state & ALLOC_DATA_OUT_URB) { |
658 | cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, | 562 | cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, |
659 | devinfo->data_out_pipe, cmdinfo->stream, | 563 | cmnd, DMA_TO_DEVICE); |
660 | cmnd, DMA_TO_DEVICE); | ||
661 | if (!cmdinfo->data_out_urb) | 564 | if (!cmdinfo->data_out_urb) |
662 | return SCSI_MLQUEUE_DEVICE_BUSY; | 565 | return SCSI_MLQUEUE_DEVICE_BUSY; |
663 | cmdinfo->state &= ~ALLOC_DATA_OUT_URB; | 566 | cmdinfo->state &= ~ALLOC_DATA_OUT_URB; |
@@ -668,10 +571,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
668 | err = usb_submit_urb(cmdinfo->data_out_urb, gfp); | 571 | err = usb_submit_urb(cmdinfo->data_out_urb, gfp); |
669 | if (err) { | 572 | if (err) { |
670 | usb_unanchor_urb(cmdinfo->data_out_urb); | 573 | usb_unanchor_urb(cmdinfo->data_out_urb); |
671 | uas_log_cmd_state(cmnd, __func__); | 574 | uas_log_cmd_state(cmnd, "data out submit err", err); |
672 | scmd_printk(KERN_INFO, cmnd, | ||
673 | "data out urb submission error %d stream %d\n", | ||
674 | err, cmdinfo->data_out_urb->stream_id); | ||
675 | return SCSI_MLQUEUE_DEVICE_BUSY; | 575 | return SCSI_MLQUEUE_DEVICE_BUSY; |
676 | } | 576 | } |
677 | cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; | 577 | cmdinfo->state &= ~SUBMIT_DATA_OUT_URB; |
@@ -690,9 +590,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, | |||
690 | err = usb_submit_urb(cmdinfo->cmd_urb, gfp); | 590 | err = usb_submit_urb(cmdinfo->cmd_urb, gfp); |
691 | if (err) { | 591 | if (err) { |
692 | usb_unanchor_urb(cmdinfo->cmd_urb); | 592 | usb_unanchor_urb(cmdinfo->cmd_urb); |
693 | uas_log_cmd_state(cmnd, __func__); | 593 | uas_log_cmd_state(cmnd, "cmd submit err", err); |
694 | scmd_printk(KERN_INFO, cmnd, | ||
695 | "cmd urb submission error %d\n", err); | ||
696 | return SCSI_MLQUEUE_DEVICE_BUSY; | 594 | return SCSI_MLQUEUE_DEVICE_BUSY; |
697 | } | 595 | } |
698 | cmdinfo->cmd_urb = NULL; | 596 | cmdinfo->cmd_urb = NULL; |
@@ -710,10 +608,24 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, | |||
710 | struct uas_dev_info *devinfo = sdev->hostdata; | 608 | struct uas_dev_info *devinfo = sdev->hostdata; |
711 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; | 609 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
712 | unsigned long flags; | 610 | unsigned long flags; |
611 | unsigned int stream; | ||
713 | int err; | 612 | int err; |
714 | 613 | ||
715 | BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); | 614 | BUILD_BUG_ON(sizeof(struct uas_cmd_info) > sizeof(struct scsi_pointer)); |
716 | 615 | ||
616 | /* Re-check scsi_block_requests now that we've the host-lock */ | ||
617 | if (cmnd->device->host->host_self_blocked) | ||
618 | return SCSI_MLQUEUE_DEVICE_BUSY; | ||
619 | |||
620 | if ((devinfo->flags & US_FL_NO_ATA_1X) && | ||
621 | (cmnd->cmnd[0] == ATA_12 || cmnd->cmnd[0] == ATA_16)) { | ||
622 | memcpy(cmnd->sense_buffer, usb_stor_sense_invalidCDB, | ||
623 | sizeof(usb_stor_sense_invalidCDB)); | ||
624 | cmnd->result = SAM_STAT_CHECK_CONDITION; | ||
625 | cmnd->scsi_done(cmnd); | ||
626 | return 0; | ||
627 | } | ||
628 | |||
717 | spin_lock_irqsave(&devinfo->lock, flags); | 629 | spin_lock_irqsave(&devinfo->lock, flags); |
718 | 630 | ||
719 | if (devinfo->resetting) { | 631 | if (devinfo->resetting) { |
@@ -723,24 +635,17 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, | |||
723 | return 0; | 635 | return 0; |
724 | } | 636 | } |
725 | 637 | ||
726 | if (devinfo->cmnd) { | 638 | stream = uas_get_tag(cmnd); |
639 | if (devinfo->cmnd[stream - 1]) { | ||
727 | spin_unlock_irqrestore(&devinfo->lock, flags); | 640 | spin_unlock_irqrestore(&devinfo->lock, flags); |
728 | return SCSI_MLQUEUE_DEVICE_BUSY; | 641 | return SCSI_MLQUEUE_DEVICE_BUSY; |
729 | } | 642 | } |
730 | 643 | ||
731 | memset(cmdinfo, 0, sizeof(*cmdinfo)); | ||
732 | |||
733 | if (blk_rq_tagged(cmnd->request)) { | ||
734 | cmdinfo->stream = cmnd->request->tag + 2; | ||
735 | } else { | ||
736 | devinfo->cmnd = cmnd; | ||
737 | cmdinfo->stream = 1; | ||
738 | } | ||
739 | |||
740 | cmnd->scsi_done = done; | 644 | cmnd->scsi_done = done; |
741 | 645 | ||
742 | cmdinfo->state = SUBMIT_STATUS_URB | | 646 | memset(cmdinfo, 0, sizeof(*cmdinfo)); |
743 | ALLOC_CMD_URB | SUBMIT_CMD_URB; | 647 | cmdinfo->stream = stream; |
648 | cmdinfo->state = SUBMIT_STATUS_URB | ALLOC_CMD_URB | SUBMIT_CMD_URB; | ||
744 | 649 | ||
745 | switch (cmnd->sc_data_direction) { | 650 | switch (cmnd->sc_data_direction) { |
746 | case DMA_FROM_DEVICE: | 651 | case DMA_FROM_DEVICE: |
@@ -769,123 +674,54 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd, | |||
769 | uas_add_work(cmdinfo); | 674 | uas_add_work(cmdinfo); |
770 | } | 675 | } |
771 | 676 | ||
772 | list_add_tail(&cmdinfo->list, &devinfo->inflight_list); | 677 | devinfo->cmnd[stream - 1] = cmnd; |
773 | spin_unlock_irqrestore(&devinfo->lock, flags); | 678 | spin_unlock_irqrestore(&devinfo->lock, flags); |
774 | return 0; | 679 | return 0; |
775 | } | 680 | } |
776 | 681 | ||
777 | static DEF_SCSI_QCMD(uas_queuecommand) | 682 | static DEF_SCSI_QCMD(uas_queuecommand) |
778 | 683 | ||
779 | static int uas_eh_task_mgmt(struct scsi_cmnd *cmnd, | 684 | /* |
780 | const char *fname, u8 function) | 685 | * For now we do not support actually sending an abort to the device, so |
686 | * this eh always fails. Still we must define it to make sure that we've | ||
687 | * dropped all references to the cmnd in question once this function exits. | ||
688 | */ | ||
689 | static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) | ||
781 | { | 690 | { |
782 | struct Scsi_Host *shost = cmnd->device->host; | 691 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; |
783 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 692 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; |
784 | u16 tag = devinfo->qdepth; | 693 | struct urb *data_in_urb = NULL; |
694 | struct urb *data_out_urb = NULL; | ||
785 | unsigned long flags; | 695 | unsigned long flags; |
786 | struct urb *sense_urb; | ||
787 | int result = SUCCESS; | ||
788 | 696 | ||
789 | spin_lock_irqsave(&devinfo->lock, flags); | 697 | spin_lock_irqsave(&devinfo->lock, flags); |
790 | 698 | ||
791 | if (devinfo->resetting) { | 699 | uas_log_cmd_state(cmnd, __func__, 0); |
792 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
793 | return FAILED; | ||
794 | } | ||
795 | 700 | ||
796 | if (devinfo->running_task) { | 701 | /* Ensure that try_complete does not call scsi_done */ |
797 | shost_printk(KERN_INFO, shost, | 702 | cmdinfo->state |= COMMAND_ABORTED; |
798 | "%s: %s: error already running a task\n", | ||
799 | __func__, fname); | ||
800 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
801 | return FAILED; | ||
802 | } | ||
803 | 703 | ||
804 | devinfo->running_task = 1; | 704 | /* Drop all refs to this cmnd, kill data urbs to break their ref */ |
805 | memset(&devinfo->response, 0, sizeof(devinfo->response)); | 705 | devinfo->cmnd[uas_get_tag(cmnd) - 1] = NULL; |
806 | sense_urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC, | 706 | if (cmdinfo->state & DATA_IN_URB_INFLIGHT) |
807 | devinfo->use_streams ? tag : 0); | 707 | data_in_urb = usb_get_urb(cmdinfo->data_in_urb); |
808 | if (!sense_urb) { | 708 | if (cmdinfo->state & DATA_OUT_URB_INFLIGHT) |
809 | shost_printk(KERN_INFO, shost, | 709 | data_out_urb = usb_get_urb(cmdinfo->data_out_urb); |
810 | "%s: %s: submit sense urb failed\n", | ||
811 | __func__, fname); | ||
812 | devinfo->running_task = 0; | ||
813 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
814 | return FAILED; | ||
815 | } | ||
816 | if (uas_submit_task_urb(cmnd, GFP_ATOMIC, function, tag)) { | ||
817 | shost_printk(KERN_INFO, shost, | ||
818 | "%s: %s: submit task mgmt urb failed\n", | ||
819 | __func__, fname); | ||
820 | devinfo->running_task = 0; | ||
821 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
822 | usb_kill_urb(sense_urb); | ||
823 | return FAILED; | ||
824 | } | ||
825 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
826 | 710 | ||
827 | if (usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 3000) == 0) { | 711 | uas_free_unsubmitted_urbs(cmnd); |
828 | /* | ||
829 | * Note we deliberately do not clear running_task here. If we | ||
830 | * allow new tasks to be submitted, there is no way to figure | ||
831 | * out if a received response_iu is for the failed task or for | ||
832 | * the new one. A bus-reset will eventually clear running_task. | ||
833 | */ | ||
834 | shost_printk(KERN_INFO, shost, | ||
835 | "%s: %s timed out\n", __func__, fname); | ||
836 | return FAILED; | ||
837 | } | ||
838 | 712 | ||
839 | spin_lock_irqsave(&devinfo->lock, flags); | ||
840 | devinfo->running_task = 0; | ||
841 | if (be16_to_cpu(devinfo->response.tag) != tag) { | ||
842 | shost_printk(KERN_INFO, shost, | ||
843 | "%s: %s failed (wrong tag %d/%d)\n", __func__, | ||
844 | fname, be16_to_cpu(devinfo->response.tag), tag); | ||
845 | result = FAILED; | ||
846 | } else if (devinfo->response.response_code != RC_TMF_COMPLETE) { | ||
847 | shost_printk(KERN_INFO, shost, | ||
848 | "%s: %s failed (rc 0x%x)\n", __func__, | ||
849 | fname, devinfo->response.response_code); | ||
850 | result = FAILED; | ||
851 | } | ||
852 | spin_unlock_irqrestore(&devinfo->lock, flags); | 713 | spin_unlock_irqrestore(&devinfo->lock, flags); |
853 | 714 | ||
854 | return result; | 715 | if (data_in_urb) { |
855 | } | 716 | usb_kill_urb(data_in_urb); |
856 | 717 | usb_put_urb(data_in_urb); | |
857 | static int uas_eh_abort_handler(struct scsi_cmnd *cmnd) | ||
858 | { | ||
859 | struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; | ||
860 | struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; | ||
861 | unsigned long flags; | ||
862 | int ret; | ||
863 | |||
864 | spin_lock_irqsave(&devinfo->lock, flags); | ||
865 | |||
866 | if (devinfo->resetting) { | ||
867 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
868 | return FAILED; | ||
869 | } | 718 | } |
870 | 719 | if (data_out_urb) { | |
871 | uas_mark_cmd_dead(devinfo, cmdinfo, DID_ABORT, __func__); | 720 | usb_kill_urb(data_out_urb); |
872 | if (cmdinfo->state & COMMAND_INFLIGHT) { | 721 | usb_put_urb(data_out_urb); |
873 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
874 | ret = uas_eh_task_mgmt(cmnd, "ABORT TASK", TMF_ABORT_TASK); | ||
875 | } else { | ||
876 | uas_unlink_data_urbs(devinfo, cmdinfo, &flags); | ||
877 | uas_try_complete(cmnd, __func__); | ||
878 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
879 | ret = SUCCESS; | ||
880 | } | 722 | } |
881 | return ret; | ||
882 | } | ||
883 | 723 | ||
884 | static int uas_eh_device_reset_handler(struct scsi_cmnd *cmnd) | 724 | return FAILED; |
885 | { | ||
886 | sdev_printk(KERN_INFO, cmnd->device, "%s\n", __func__); | ||
887 | return uas_eh_task_mgmt(cmnd, "LOGICAL UNIT RESET", | ||
888 | TMF_LOGICAL_UNIT_RESET); | ||
889 | } | 725 | } |
890 | 726 | ||
891 | static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) | 727 | static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) |
@@ -893,6 +729,7 @@ static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) | |||
893 | struct scsi_device *sdev = cmnd->device; | 729 | struct scsi_device *sdev = cmnd->device; |
894 | struct uas_dev_info *devinfo = sdev->hostdata; | 730 | struct uas_dev_info *devinfo = sdev->hostdata; |
895 | struct usb_device *udev = devinfo->udev; | 731 | struct usb_device *udev = devinfo->udev; |
732 | unsigned long flags; | ||
896 | int err; | 733 | int err; |
897 | 734 | ||
898 | err = usb_lock_device_for_reset(udev, devinfo->intf); | 735 | err = usb_lock_device_for_reset(udev, devinfo->intf); |
@@ -903,19 +740,27 @@ static int uas_eh_bus_reset_handler(struct scsi_cmnd *cmnd) | |||
903 | } | 740 | } |
904 | 741 | ||
905 | shost_printk(KERN_INFO, sdev->host, "%s start\n", __func__); | 742 | shost_printk(KERN_INFO, sdev->host, "%s start\n", __func__); |
743 | |||
744 | spin_lock_irqsave(&devinfo->lock, flags); | ||
906 | devinfo->resetting = 1; | 745 | devinfo->resetting = 1; |
907 | uas_abort_inflight(devinfo, DID_RESET, __func__); | 746 | spin_unlock_irqrestore(&devinfo->lock, flags); |
747 | |||
908 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); | 748 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); |
909 | usb_kill_anchored_urbs(&devinfo->sense_urbs); | 749 | usb_kill_anchored_urbs(&devinfo->sense_urbs); |
910 | usb_kill_anchored_urbs(&devinfo->data_urbs); | 750 | usb_kill_anchored_urbs(&devinfo->data_urbs); |
911 | uas_zap_dead(devinfo); | 751 | uas_zap_pending(devinfo, DID_RESET); |
752 | |||
912 | err = usb_reset_device(udev); | 753 | err = usb_reset_device(udev); |
754 | |||
755 | spin_lock_irqsave(&devinfo->lock, flags); | ||
913 | devinfo->resetting = 0; | 756 | devinfo->resetting = 0; |
757 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
914 | 758 | ||
915 | usb_unlock_device(udev); | 759 | usb_unlock_device(udev); |
916 | 760 | ||
917 | if (err) { | 761 | if (err) { |
918 | shost_printk(KERN_INFO, sdev->host, "%s FAILED\n", __func__); | 762 | shost_printk(KERN_INFO, sdev->host, "%s FAILED err %d\n", |
763 | __func__, err); | ||
919 | return FAILED; | 764 | return FAILED; |
920 | } | 765 | } |
921 | 766 | ||
@@ -950,6 +795,10 @@ static int uas_slave_alloc(struct scsi_device *sdev) | |||
950 | static int uas_slave_configure(struct scsi_device *sdev) | 795 | static int uas_slave_configure(struct scsi_device *sdev) |
951 | { | 796 | { |
952 | struct uas_dev_info *devinfo = sdev->hostdata; | 797 | struct uas_dev_info *devinfo = sdev->hostdata; |
798 | |||
799 | if (devinfo->flags & US_FL_NO_REPORT_OPCODES) | ||
800 | sdev->no_report_opcodes = 1; | ||
801 | |||
953 | scsi_set_tag_type(sdev, MSG_ORDERED_TAG); | 802 | scsi_set_tag_type(sdev, MSG_ORDERED_TAG); |
954 | scsi_activate_tcq(sdev, devinfo->qdepth - 2); | 803 | scsi_activate_tcq(sdev, devinfo->qdepth - 2); |
955 | return 0; | 804 | return 0; |
@@ -962,7 +811,6 @@ static struct scsi_host_template uas_host_template = { | |||
962 | .slave_alloc = uas_slave_alloc, | 811 | .slave_alloc = uas_slave_alloc, |
963 | .slave_configure = uas_slave_configure, | 812 | .slave_configure = uas_slave_configure, |
964 | .eh_abort_handler = uas_eh_abort_handler, | 813 | .eh_abort_handler = uas_eh_abort_handler, |
965 | .eh_device_reset_handler = uas_eh_device_reset_handler, | ||
966 | .eh_bus_reset_handler = uas_eh_bus_reset_handler, | 814 | .eh_bus_reset_handler = uas_eh_bus_reset_handler, |
967 | .can_queue = 65536, /* Is there a limit on the _host_ ? */ | 815 | .can_queue = 65536, /* Is there a limit on the _host_ ? */ |
968 | .this_id = -1, | 816 | .this_id = -1, |
@@ -970,6 +818,13 @@ static struct scsi_host_template uas_host_template = { | |||
970 | .cmd_per_lun = 1, /* until we override it */ | 818 | .cmd_per_lun = 1, /* until we override it */ |
971 | .skip_settle_delay = 1, | 819 | .skip_settle_delay = 1, |
972 | .ordered_tag = 1, | 820 | .ordered_tag = 1, |
821 | |||
822 | /* | ||
823 | * The uas drivers expects tags not to be bigger than the maximum | ||
824 | * per-device queue depth, which is not true with the blk-mq tag | ||
825 | * allocator. | ||
826 | */ | ||
827 | .disable_blk_mq = true, | ||
973 | }; | 828 | }; |
974 | 829 | ||
975 | #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ | 830 | #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ |
@@ -982,8 +837,6 @@ static struct usb_device_id uas_usb_ids[] = { | |||
982 | # include "unusual_uas.h" | 837 | # include "unusual_uas.h" |
983 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) }, | 838 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) }, |
984 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) }, | 839 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) }, |
985 | /* 0xaa is a prototype device I happen to have access to */ | ||
986 | { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, 0xaa) }, | ||
987 | { } | 840 | { } |
988 | }; | 841 | }; |
989 | MODULE_DEVICE_TABLE(usb, uas_usb_ids); | 842 | MODULE_DEVICE_TABLE(usb, uas_usb_ids); |
@@ -1009,9 +862,6 @@ static int uas_configure_endpoints(struct uas_dev_info *devinfo) | |||
1009 | struct usb_device *udev = devinfo->udev; | 862 | struct usb_device *udev = devinfo->udev; |
1010 | int r; | 863 | int r; |
1011 | 864 | ||
1012 | devinfo->uas_sense_old = 0; | ||
1013 | devinfo->cmnd = NULL; | ||
1014 | |||
1015 | r = uas_find_endpoints(devinfo->intf->cur_altsetting, eps); | 865 | r = uas_find_endpoints(devinfo->intf->cur_altsetting, eps); |
1016 | if (r) | 866 | if (r) |
1017 | return r; | 867 | return r; |
@@ -1025,12 +875,12 @@ static int uas_configure_endpoints(struct uas_dev_info *devinfo) | |||
1025 | devinfo->data_out_pipe = usb_sndbulkpipe(udev, | 875 | devinfo->data_out_pipe = usb_sndbulkpipe(udev, |
1026 | usb_endpoint_num(&eps[3]->desc)); | 876 | usb_endpoint_num(&eps[3]->desc)); |
1027 | 877 | ||
1028 | if (udev->speed != USB_SPEED_SUPER) { | 878 | if (udev->speed < USB_SPEED_SUPER) { |
1029 | devinfo->qdepth = 32; | 879 | devinfo->qdepth = 32; |
1030 | devinfo->use_streams = 0; | 880 | devinfo->use_streams = 0; |
1031 | } else { | 881 | } else { |
1032 | devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1, | 882 | devinfo->qdepth = usb_alloc_streams(devinfo->intf, eps + 1, |
1033 | 3, 256, GFP_NOIO); | 883 | 3, MAX_CMNDS, GFP_NOIO); |
1034 | if (devinfo->qdepth < 0) | 884 | if (devinfo->qdepth < 0) |
1035 | return devinfo->qdepth; | 885 | return devinfo->qdepth; |
1036 | devinfo->use_streams = 1; | 886 | devinfo->use_streams = 1; |
@@ -1078,15 +928,14 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1078 | devinfo->intf = intf; | 928 | devinfo->intf = intf; |
1079 | devinfo->udev = udev; | 929 | devinfo->udev = udev; |
1080 | devinfo->resetting = 0; | 930 | devinfo->resetting = 0; |
1081 | devinfo->running_task = 0; | ||
1082 | devinfo->shutdown = 0; | 931 | devinfo->shutdown = 0; |
932 | devinfo->flags = id->driver_info; | ||
933 | usb_stor_adjust_quirks(udev, &devinfo->flags); | ||
1083 | init_usb_anchor(&devinfo->cmd_urbs); | 934 | init_usb_anchor(&devinfo->cmd_urbs); |
1084 | init_usb_anchor(&devinfo->sense_urbs); | 935 | init_usb_anchor(&devinfo->sense_urbs); |
1085 | init_usb_anchor(&devinfo->data_urbs); | 936 | init_usb_anchor(&devinfo->data_urbs); |
1086 | spin_lock_init(&devinfo->lock); | 937 | spin_lock_init(&devinfo->lock); |
1087 | INIT_WORK(&devinfo->work, uas_do_work); | 938 | INIT_WORK(&devinfo->work, uas_do_work); |
1088 | INIT_LIST_HEAD(&devinfo->inflight_list); | ||
1089 | INIT_LIST_HEAD(&devinfo->dead_list); | ||
1090 | 939 | ||
1091 | result = uas_configure_endpoints(devinfo); | 940 | result = uas_configure_endpoints(devinfo); |
1092 | if (result) | 941 | if (result) |
@@ -1114,6 +963,54 @@ set_alt0: | |||
1114 | return result; | 963 | return result; |
1115 | } | 964 | } |
1116 | 965 | ||
966 | static int uas_cmnd_list_empty(struct uas_dev_info *devinfo) | ||
967 | { | ||
968 | unsigned long flags; | ||
969 | int i, r = 1; | ||
970 | |||
971 | spin_lock_irqsave(&devinfo->lock, flags); | ||
972 | |||
973 | for (i = 0; i < devinfo->qdepth; i++) { | ||
974 | if (devinfo->cmnd[i]) { | ||
975 | r = 0; /* Not empty */ | ||
976 | break; | ||
977 | } | ||
978 | } | ||
979 | |||
980 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
981 | |||
982 | return r; | ||
983 | } | ||
984 | |||
985 | /* | ||
986 | * Wait for any pending cmnds to complete, on usb-2 sense_urbs may temporarily | ||
987 | * get empty while there still is more work to do due to sense-urbs completing | ||
988 | * with a READ/WRITE_READY iu code, so keep waiting until the list gets empty. | ||
989 | */ | ||
990 | static int uas_wait_for_pending_cmnds(struct uas_dev_info *devinfo) | ||
991 | { | ||
992 | unsigned long start_time; | ||
993 | int r; | ||
994 | |||
995 | start_time = jiffies; | ||
996 | do { | ||
997 | flush_work(&devinfo->work); | ||
998 | |||
999 | r = usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 5000); | ||
1000 | if (r == 0) | ||
1001 | return -ETIME; | ||
1002 | |||
1003 | r = usb_wait_anchor_empty_timeout(&devinfo->data_urbs, 500); | ||
1004 | if (r == 0) | ||
1005 | return -ETIME; | ||
1006 | |||
1007 | if (time_after(jiffies, start_time + 5 * HZ)) | ||
1008 | return -ETIME; | ||
1009 | } while (!uas_cmnd_list_empty(devinfo)); | ||
1010 | |||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1117 | static int uas_pre_reset(struct usb_interface *intf) | 1014 | static int uas_pre_reset(struct usb_interface *intf) |
1118 | { | 1015 | { |
1119 | struct Scsi_Host *shost = usb_get_intfdata(intf); | 1016 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
@@ -1128,10 +1025,9 @@ static int uas_pre_reset(struct usb_interface *intf) | |||
1128 | scsi_block_requests(shost); | 1025 | scsi_block_requests(shost); |
1129 | spin_unlock_irqrestore(shost->host_lock, flags); | 1026 | spin_unlock_irqrestore(shost->host_lock, flags); |
1130 | 1027 | ||
1131 | /* Wait for any pending requests to complete */ | 1028 | if (uas_wait_for_pending_cmnds(devinfo) != 0) { |
1132 | flush_work(&devinfo->work); | ||
1133 | if (usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 5000) == 0) { | ||
1134 | shost_printk(KERN_ERR, shost, "%s: timed out\n", __func__); | 1029 | shost_printk(KERN_ERR, shost, "%s: timed out\n", __func__); |
1030 | scsi_unblock_requests(shost); | ||
1135 | return 1; | 1031 | return 1; |
1136 | } | 1032 | } |
1137 | 1033 | ||
@@ -1145,13 +1041,16 @@ static int uas_post_reset(struct usb_interface *intf) | |||
1145 | struct Scsi_Host *shost = usb_get_intfdata(intf); | 1041 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
1146 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 1042 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; |
1147 | unsigned long flags; | 1043 | unsigned long flags; |
1044 | int err; | ||
1148 | 1045 | ||
1149 | if (devinfo->shutdown) | 1046 | if (devinfo->shutdown) |
1150 | return 0; | 1047 | return 0; |
1151 | 1048 | ||
1152 | if (uas_configure_endpoints(devinfo) != 0) { | 1049 | err = uas_configure_endpoints(devinfo); |
1050 | if (err) { | ||
1153 | shost_printk(KERN_ERR, shost, | 1051 | shost_printk(KERN_ERR, shost, |
1154 | "%s: alloc streams error after reset", __func__); | 1052 | "%s: alloc streams error %d after reset", |
1053 | __func__, err); | ||
1155 | return 1; | 1054 | return 1; |
1156 | } | 1055 | } |
1157 | 1056 | ||
@@ -1169,9 +1068,7 @@ static int uas_suspend(struct usb_interface *intf, pm_message_t message) | |||
1169 | struct Scsi_Host *shost = usb_get_intfdata(intf); | 1068 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
1170 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 1069 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; |
1171 | 1070 | ||
1172 | /* Wait for any pending requests to complete */ | 1071 | if (uas_wait_for_pending_cmnds(devinfo) != 0) { |
1173 | flush_work(&devinfo->work); | ||
1174 | if (usb_wait_anchor_empty_timeout(&devinfo->sense_urbs, 5000) == 0) { | ||
1175 | shost_printk(KERN_ERR, shost, "%s: timed out\n", __func__); | 1072 | shost_printk(KERN_ERR, shost, "%s: timed out\n", __func__); |
1176 | return -ETIME; | 1073 | return -ETIME; |
1177 | } | 1074 | } |
@@ -1189,10 +1086,13 @@ static int uas_reset_resume(struct usb_interface *intf) | |||
1189 | struct Scsi_Host *shost = usb_get_intfdata(intf); | 1086 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
1190 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 1087 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; |
1191 | unsigned long flags; | 1088 | unsigned long flags; |
1089 | int err; | ||
1192 | 1090 | ||
1193 | if (uas_configure_endpoints(devinfo) != 0) { | 1091 | err = uas_configure_endpoints(devinfo); |
1092 | if (err) { | ||
1194 | shost_printk(KERN_ERR, shost, | 1093 | shost_printk(KERN_ERR, shost, |
1195 | "%s: alloc streams error after reset", __func__); | 1094 | "%s: alloc streams error %d after reset", |
1095 | __func__, err); | ||
1196 | return -EIO; | 1096 | return -EIO; |
1197 | } | 1097 | } |
1198 | 1098 | ||
@@ -1207,14 +1107,18 @@ static void uas_disconnect(struct usb_interface *intf) | |||
1207 | { | 1107 | { |
1208 | struct Scsi_Host *shost = usb_get_intfdata(intf); | 1108 | struct Scsi_Host *shost = usb_get_intfdata(intf); |
1209 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; | 1109 | struct uas_dev_info *devinfo = (struct uas_dev_info *)shost->hostdata; |
1110 | unsigned long flags; | ||
1210 | 1111 | ||
1112 | spin_lock_irqsave(&devinfo->lock, flags); | ||
1211 | devinfo->resetting = 1; | 1113 | devinfo->resetting = 1; |
1114 | spin_unlock_irqrestore(&devinfo->lock, flags); | ||
1115 | |||
1212 | cancel_work_sync(&devinfo->work); | 1116 | cancel_work_sync(&devinfo->work); |
1213 | uas_abort_inflight(devinfo, DID_NO_CONNECT, __func__); | ||
1214 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); | 1117 | usb_kill_anchored_urbs(&devinfo->cmd_urbs); |
1215 | usb_kill_anchored_urbs(&devinfo->sense_urbs); | 1118 | usb_kill_anchored_urbs(&devinfo->sense_urbs); |
1216 | usb_kill_anchored_urbs(&devinfo->data_urbs); | 1119 | usb_kill_anchored_urbs(&devinfo->data_urbs); |
1217 | uas_zap_dead(devinfo); | 1120 | uas_zap_pending(devinfo, DID_NO_CONNECT); |
1121 | |||
1218 | scsi_remove_host(shost); | 1122 | scsi_remove_host(shost); |
1219 | uas_free_streams(devinfo); | 1123 | uas_free_streams(devinfo); |
1220 | scsi_host_put(shost); | 1124 | scsi_host_put(shost); |
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index 4a5c68a47e46..11c7a9676441 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -492,18 +492,24 @@ UNUSUAL_DEV( 0x04e6, 0x000a, 0x0200, 0x0200, | |||
492 | "eUSB CompactFlash Adapter", | 492 | "eUSB CompactFlash Adapter", |
493 | USB_SC_8020, USB_PR_CB, NULL, 0), | 493 | USB_SC_8020, USB_PR_CB, NULL, 0), |
494 | 494 | ||
495 | UNUSUAL_DEV( 0x04e6, 0x000B, 0x0100, 0x0100, | 495 | UNUSUAL_DEV( 0x04e6, 0x000b, 0x0100, 0x0100, |
496 | "Shuttle", | 496 | "Shuttle", |
497 | "eUSCSI Bridge", | 497 | "eUSCSI Bridge", |
498 | USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init, | 498 | USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init, |
499 | US_FL_SCM_MULT_TARG ), | 499 | US_FL_SCM_MULT_TARG ), |
500 | 500 | ||
501 | UNUSUAL_DEV( 0x04e6, 0x000C, 0x0100, 0x0100, | 501 | UNUSUAL_DEV( 0x04e6, 0x000c, 0x0100, 0x0100, |
502 | "Shuttle", | 502 | "Shuttle", |
503 | "eUSCSI Bridge", | 503 | "eUSCSI Bridge", |
504 | USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init, | 504 | USB_SC_SCSI, USB_PR_BULK, usb_stor_euscsi_init, |
505 | US_FL_SCM_MULT_TARG ), | 505 | US_FL_SCM_MULT_TARG ), |
506 | 506 | ||
507 | UNUSUAL_DEV( 0x04e6, 0x000f, 0x0000, 0x9999, | ||
508 | "SCM Microsystems", | ||
509 | "eUSB SCSI Adapter (Bus Powered)", | ||
510 | USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init, | ||
511 | US_FL_SCM_MULT_TARG ), | ||
512 | |||
507 | UNUSUAL_DEV( 0x04e6, 0x0101, 0x0200, 0x0200, | 513 | UNUSUAL_DEV( 0x04e6, 0x0101, 0x0200, 0x0200, |
508 | "Shuttle", | 514 | "Shuttle", |
509 | "CD-RW Device", | 515 | "CD-RW Device", |
@@ -1099,6 +1105,13 @@ UNUSUAL_DEV( 0x0840, 0x0085, 0x0001, 0x0001, | |||
1099 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | 1105 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
1100 | US_FL_FIX_CAPACITY), | 1106 | US_FL_FIX_CAPACITY), |
1101 | 1107 | ||
1108 | /* Supplied with some Castlewood ORB removable drives */ | ||
1109 | UNUSUAL_DEV( 0x084b, 0xa001, 0x0000, 0x9999, | ||
1110 | "Castlewood Systems", | ||
1111 | "USB to SCSI cable", | ||
1112 | USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init, | ||
1113 | US_FL_SCM_MULT_TARG ), | ||
1114 | |||
1102 | /* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. | 1115 | /* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. |
1103 | * Flag will support Bulk devices which use a standards-violating 32-byte | 1116 | * Flag will support Bulk devices which use a standards-violating 32-byte |
1104 | * Command Block Wrapper. Here, the "DC2MEGA" cameras (several brands) with | 1117 | * Command Block Wrapper. Here, the "DC2MEGA" cameras (several brands) with |
@@ -2063,6 +2076,13 @@ UNUSUAL_DEV( 0x1e74, 0x4621, 0x0000, 0x0000, | |||
2063 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | 2076 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
2064 | US_FL_BULK_IGNORE_TAG | US_FL_MAX_SECTORS_64 ), | 2077 | US_FL_BULK_IGNORE_TAG | US_FL_MAX_SECTORS_64 ), |
2065 | 2078 | ||
2079 | /* Supplied with some Castlewood ORB removable drives */ | ||
2080 | UNUSUAL_DEV( 0x2027, 0xa001, 0x0000, 0x9999, | ||
2081 | "Double-H Technology", | ||
2082 | "USB to SCSI Intelligent Cable", | ||
2083 | USB_SC_DEVICE, USB_PR_DEVICE, usb_stor_euscsi_init, | ||
2084 | US_FL_SCM_MULT_TARG ), | ||
2085 | |||
2066 | UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001, | 2086 | UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001, |
2067 | "ST", | 2087 | "ST", |
2068 | "2A", | 2088 | "2A", |
diff --git a/drivers/usb/storage/unusual_uas.h b/drivers/usb/storage/unusual_uas.h index 7244444df8ee..8511b54a65d9 100644 --- a/drivers/usb/storage/unusual_uas.h +++ b/drivers/usb/storage/unusual_uas.h | |||
@@ -40,13 +40,38 @@ | |||
40 | * and don't forget to CC: the USB development list <linux-usb@vger.kernel.org> | 40 | * and don't forget to CC: the USB development list <linux-usb@vger.kernel.org> |
41 | */ | 41 | */ |
42 | 42 | ||
43 | /* | 43 | /* https://bugzilla.kernel.org/show_bug.cgi?id=79511 */ |
44 | * This is an example entry for the US_FL_IGNORE_UAS flag. Once we have an | 44 | UNUSUAL_DEV(0x0bc2, 0x2312, 0x0000, 0x9999, |
45 | * actual entry using US_FL_IGNORE_UAS this entry should be removed. | 45 | "Seagate", |
46 | * | 46 | "Expansion Desk", |
47 | * UNUSUAL_DEV( 0xabcd, 0x1234, 0x0100, 0x0100, | 47 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, |
48 | * "Example", | 48 | US_FL_NO_ATA_1X), |
49 | * "Storage with broken UAS", | 49 | |
50 | * USB_SC_DEVICE, USB_PR_DEVICE, NULL, | 50 | /* https://bbs.archlinux.org/viewtopic.php?id=183190 */ |
51 | * US_FL_IGNORE_UAS), | 51 | UNUSUAL_DEV(0x0bc2, 0x3312, 0x0000, 0x9999, |
52 | */ | 52 | "Seagate", |
53 | "Expansion Desk", | ||
54 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
55 | US_FL_NO_ATA_1X), | ||
56 | |||
57 | /* https://bbs.archlinux.org/viewtopic.php?id=183190 */ | ||
58 | UNUSUAL_DEV(0x0bc2, 0xab20, 0x0000, 0x9999, | ||
59 | "Seagate", | ||
60 | "Backup+ BK", | ||
61 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
62 | US_FL_NO_ATA_1X), | ||
63 | |||
64 | /* Reported-by: Claudio Bizzarri <claudio.bizzarri@gmail.com> */ | ||
65 | UNUSUAL_DEV(0x152d, 0x0567, 0x0000, 0x9999, | ||
66 | "JMicron", | ||
67 | "JMS567", | ||
68 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
69 | US_FL_NO_REPORT_OPCODES), | ||
70 | |||
71 | /* Most ASM1051 based devices have issues with uas, blacklist them all */ | ||
72 | /* Reported-by: Hans de Goede <hdegoede@redhat.com> */ | ||
73 | UNUSUAL_DEV(0x174c, 0x5106, 0x0000, 0x9999, | ||
74 | "ASMedia", | ||
75 | "ASM1051", | ||
76 | USB_SC_DEVICE, USB_PR_DEVICE, NULL, | ||
77 | US_FL_IGNORE_UAS), | ||
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index cedb29252a92..9d66ce62542e 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -98,7 +98,7 @@ MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks"); | |||
98 | /* The vendor name should be kept at eight characters or less, and | 98 | /* The vendor name should be kept at eight characters or less, and |
99 | * the product name should be kept at 16 characters or less. If a device | 99 | * the product name should be kept at 16 characters or less. If a device |
100 | * has the US_FL_FIX_INQUIRY flag, then the vendor and product names | 100 | * has the US_FL_FIX_INQUIRY flag, then the vendor and product names |
101 | * normally generated by a device thorugh the INQUIRY response will be | 101 | * normally generated by a device through the INQUIRY response will be |
102 | * taken from this list, and this is the reason for the above size | 102 | * taken from this list, and this is the reason for the above size |
103 | * restriction. However, if the flag is not present, then you | 103 | * restriction. However, if the flag is not present, then you |
104 | * are free to use as many characters as you like. | 104 | * are free to use as many characters as you like. |
@@ -478,7 +478,8 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags) | |||
478 | US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | | 478 | US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | |
479 | US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT | | 479 | US_FL_SINGLE_LUN | US_FL_NO_WP_DETECT | |
480 | US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | | 480 | US_FL_NO_READ_DISC_INFO | US_FL_NO_READ_CAPACITY_16 | |
481 | US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE); | 481 | US_FL_INITIAL_READ10 | US_FL_WRITE_CACHE | |
482 | US_FL_NO_ATA_1X | US_FL_NO_REPORT_OPCODES); | ||
482 | 483 | ||
483 | p = quirks; | 484 | p = quirks; |
484 | while (*p) { | 485 | while (*p) { |
@@ -516,6 +517,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags) | |||
516 | case 'e': | 517 | case 'e': |
517 | f |= US_FL_NO_READ_CAPACITY_16; | 518 | f |= US_FL_NO_READ_CAPACITY_16; |
518 | break; | 519 | break; |
520 | case 'f': | ||
521 | f |= US_FL_NO_REPORT_OPCODES; | ||
522 | break; | ||
519 | case 'h': | 523 | case 'h': |
520 | f |= US_FL_CAPACITY_HEURISTICS; | 524 | f |= US_FL_CAPACITY_HEURISTICS; |
521 | break; | 525 | break; |
@@ -543,6 +547,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags) | |||
543 | case 's': | 547 | case 's': |
544 | f |= US_FL_SINGLE_LUN; | 548 | f |= US_FL_SINGLE_LUN; |
545 | break; | 549 | break; |
550 | case 't': | ||
551 | f |= US_FL_NO_ATA_1X; | ||
552 | break; | ||
546 | case 'u': | 553 | case 'u': |
547 | f |= US_FL_IGNORE_UAS; | 554 | f |= US_FL_IGNORE_UAS; |
548 | break; | 555 | break; |
@@ -983,6 +990,14 @@ int usb_stor_probe2(struct us_data *us) | |||
983 | if (!(us->fflags & US_FL_SCM_MULT_TARG)) | 990 | if (!(us->fflags & US_FL_SCM_MULT_TARG)) |
984 | us_to_host(us)->max_id = 1; | 991 | us_to_host(us)->max_id = 1; |
985 | 992 | ||
993 | /* | ||
994 | * Like Windows, we won't store the LUN bits in CDB[1] for SCSI-2 | ||
995 | * devices using the Bulk-Only transport (even though this violates | ||
996 | * the SCSI spec). | ||
997 | */ | ||
998 | if (us->transport == usb_stor_Bulk_transport) | ||
999 | us_to_host(us)->no_scsi2_lun_in_cdb = 1; | ||
1000 | |||
986 | /* Find the endpoints and calculate pipe values */ | 1001 | /* Find the endpoints and calculate pipe values */ |
987 | result = get_pipes(us); | 1002 | result = get_pipes(us); |
988 | if (result) | 1003 | if (result) |
diff --git a/drivers/usb/wusbcore/Kconfig b/drivers/usb/wusbcore/Kconfig index 0e17b966e1b4..348de1d6726e 100644 --- a/drivers/usb/wusbcore/Kconfig +++ b/drivers/usb/wusbcore/Kconfig | |||
@@ -3,7 +3,6 @@ | |||
3 | # | 3 | # |
4 | config USB_WUSB | 4 | config USB_WUSB |
5 | tristate "Enable Wireless USB extensions" | 5 | tristate "Enable Wireless USB extensions" |
6 | depends on PCI | ||
7 | depends on UWB | 6 | depends on UWB |
8 | select CRYPTO | 7 | select CRYPTO |
9 | select CRYPTO_BLKCIPHER | 8 | select CRYPTO_BLKCIPHER |
@@ -18,6 +17,7 @@ config USB_WUSB | |||
18 | 17 | ||
19 | config USB_WUSB_CBAF | 18 | config USB_WUSB_CBAF |
20 | tristate "Support WUSB Cable Based Association (CBA)" | 19 | tristate "Support WUSB Cable Based Association (CBA)" |
20 | depends on USB | ||
21 | help | 21 | help |
22 | Some WUSB devices support Cable Based Association. It's used to | 22 | Some WUSB devices support Cable Based Association. It's used to |
23 | enable the secure communication between the host and the | 23 | enable the secure communication between the host and the |
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c index 9a95b2dc6d1b..50ce80d604f3 100644 --- a/drivers/usb/wusbcore/crypto.c +++ b/drivers/usb/wusbcore/crypto.c | |||
@@ -222,8 +222,6 @@ static int wusb_ccm_mac(struct crypto_blkcipher *tfm_cbc, | |||
222 | WARN_ON(sizeof(ax) != sizeof(struct aes_ccm_block)); | 222 | WARN_ON(sizeof(ax) != sizeof(struct aes_ccm_block)); |
223 | 223 | ||
224 | result = -ENOMEM; | 224 | result = -ENOMEM; |
225 | zero_padding = sizeof(struct aes_ccm_block) | ||
226 | - blen % sizeof(struct aes_ccm_block); | ||
227 | zero_padding = blen % sizeof(struct aes_ccm_block); | 225 | zero_padding = blen % sizeof(struct aes_ccm_block); |
228 | if (zero_padding) | 226 | if (zero_padding) |
229 | zero_padding = sizeof(struct aes_ccm_block) - zero_padding; | 227 | zero_padding = sizeof(struct aes_ccm_block) - zero_padding; |
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c index 0677139c6065..3f4f5fbded55 100644 --- a/drivers/usb/wusbcore/devconnect.c +++ b/drivers/usb/wusbcore/devconnect.c | |||
@@ -329,7 +329,7 @@ void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc, | |||
329 | port->wusb_dev = wusb_dev; | 329 | port->wusb_dev = wusb_dev; |
330 | port->status |= USB_PORT_STAT_CONNECTION; | 330 | port->status |= USB_PORT_STAT_CONNECTION; |
331 | port->change |= USB_PORT_STAT_C_CONNECTION; | 331 | port->change |= USB_PORT_STAT_C_CONNECTION; |
332 | /* Now the port status changed to connected; khubd will | 332 | /* Now the port status changed to connected; hub_wq will |
333 | * pick the change up and try to reset the port to bring it to | 333 | * pick the change up and try to reset the port to bring it to |
334 | * the enabled state--so this process returns up to the stack | 334 | * the enabled state--so this process returns up to the stack |
335 | * and it calls back into wusbhc_rh_port_reset(). | 335 | * and it calls back into wusbhc_rh_port_reset(). |
@@ -343,7 +343,7 @@ error_unlock: | |||
343 | /* | 343 | /* |
344 | * Disconnect a Wireless USB device from its fake port | 344 | * Disconnect a Wireless USB device from its fake port |
345 | * | 345 | * |
346 | * Marks the port as disconnected so that khubd can pick up the change | 346 | * Marks the port as disconnected so that hub_wq can pick up the change |
347 | * and drops our knowledge about the device. | 347 | * and drops our knowledge about the device. |
348 | * | 348 | * |
349 | * Assumes there is a device connected | 349 | * Assumes there is a device connected |
@@ -379,7 +379,7 @@ static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc, | |||
379 | wusbhc_gtk_rekey(wusbhc); | 379 | wusbhc_gtk_rekey(wusbhc); |
380 | 380 | ||
381 | /* The Wireless USB part has forgotten about the device already; now | 381 | /* The Wireless USB part has forgotten about the device already; now |
382 | * khubd's timer will pick up the disconnection and remove the USB | 382 | * hub_wq's timer will pick up the disconnection and remove the USB |
383 | * device from the system | 383 | * device from the system |
384 | */ | 384 | */ |
385 | } | 385 | } |
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c index 95be9953cd47..cc74d669c802 100644 --- a/drivers/usb/wusbcore/security.c +++ b/drivers/usb/wusbcore/security.c | |||
@@ -33,6 +33,20 @@ static void wusbhc_gtk_rekey_work(struct work_struct *work); | |||
33 | 33 | ||
34 | int wusbhc_sec_create(struct wusbhc *wusbhc) | 34 | int wusbhc_sec_create(struct wusbhc *wusbhc) |
35 | { | 35 | { |
36 | /* | ||
37 | * WQ is singlethread because we need to serialize rekey operations. | ||
38 | * Use a separate workqueue for security operations instead of the | ||
39 | * wusbd workqueue because security operations may need to communicate | ||
40 | * directly with downstream wireless devices using synchronous URBs. | ||
41 | * If a device is not responding, this could block other host | ||
42 | * controller operations. | ||
43 | */ | ||
44 | wusbhc->wq_security = create_singlethread_workqueue("wusbd_security"); | ||
45 | if (wusbhc->wq_security == NULL) { | ||
46 | pr_err("WUSB-core: Cannot create wusbd_security workqueue\n"); | ||
47 | return -ENOMEM; | ||
48 | } | ||
49 | |||
36 | wusbhc->gtk.descr.bLength = sizeof(wusbhc->gtk.descr) + | 50 | wusbhc->gtk.descr.bLength = sizeof(wusbhc->gtk.descr) + |
37 | sizeof(wusbhc->gtk.data); | 51 | sizeof(wusbhc->gtk.data); |
38 | wusbhc->gtk.descr.bDescriptorType = USB_DT_KEY; | 52 | wusbhc->gtk.descr.bDescriptorType = USB_DT_KEY; |
@@ -48,6 +62,7 @@ int wusbhc_sec_create(struct wusbhc *wusbhc) | |||
48 | /* Called when the HC is destroyed */ | 62 | /* Called when the HC is destroyed */ |
49 | void wusbhc_sec_destroy(struct wusbhc *wusbhc) | 63 | void wusbhc_sec_destroy(struct wusbhc *wusbhc) |
50 | { | 64 | { |
65 | destroy_workqueue(wusbhc->wq_security); | ||
51 | } | 66 | } |
52 | 67 | ||
53 | 68 | ||
@@ -596,5 +611,5 @@ void wusbhc_gtk_rekey(struct wusbhc *wusbhc) | |||
596 | * and will cause a deadlock. Instead, queue a work item to do | 611 | * and will cause a deadlock. Instead, queue a work item to do |
597 | * it when the lock is not held | 612 | * it when the lock is not held |
598 | */ | 613 | */ |
599 | queue_work(wusbd, &wusbhc->gtk_rekey_work); | 614 | queue_work(wusbhc->wq_security, &wusbhc->gtk_rekey_work); |
600 | } | 615 | } |
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h index f2a8d29e17b9..edc7267157f3 100644 --- a/drivers/usb/wusbcore/wa-hc.h +++ b/drivers/usb/wusbcore/wa-hc.h | |||
@@ -64,7 +64,7 @@ | |||
64 | * | 64 | * |
65 | * Note much of the activity is difficult to follow. For example a | 65 | * Note much of the activity is difficult to follow. For example a |
66 | * device connect goes to devconnect, which will cause the "fake" root | 66 | * device connect goes to devconnect, which will cause the "fake" root |
67 | * hub port to show a connect and stop there. Then khubd will notice | 67 | * hub port to show a connect and stop there. Then hub_wq will notice |
68 | * and call into the rh.c:hwahc_rc_port_reset() code to authenticate | 68 | * and call into the rh.c:hwahc_rc_port_reset() code to authenticate |
69 | * the device (and this might require user intervention) and enable | 69 | * the device (and this might require user intervention) and enable |
70 | * the port. | 70 | * the port. |
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c index e279015be466..69af4fd9e072 100644 --- a/drivers/usb/wusbcore/wa-xfer.c +++ b/drivers/usb/wusbcore/wa-xfer.c | |||
@@ -459,14 +459,25 @@ static void __wa_xfer_abort_cb(struct urb *urb) | |||
459 | __func__, urb->status); | 459 | __func__, urb->status); |
460 | if (xfer) { | 460 | if (xfer) { |
461 | unsigned long flags; | 461 | unsigned long flags; |
462 | int done; | 462 | int done, seg_index = 0; |
463 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; | 463 | struct wa_rpipe *rpipe = xfer->ep->hcpriv; |
464 | 464 | ||
465 | dev_err(dev, "%s: cleaning up xfer %p ID 0x%08X.\n", | 465 | dev_err(dev, "%s: cleaning up xfer %p ID 0x%08X.\n", |
466 | __func__, xfer, wa_xfer_id(xfer)); | 466 | __func__, xfer, wa_xfer_id(xfer)); |
467 | spin_lock_irqsave(&xfer->lock, flags); | 467 | spin_lock_irqsave(&xfer->lock, flags); |
468 | /* mark all segs as aborted. */ | 468 | /* skip done segs. */ |
469 | wa_complete_remaining_xfer_segs(xfer, 0, | 469 | while (seg_index < xfer->segs) { |
470 | struct wa_seg *seg = xfer->seg[seg_index]; | ||
471 | |||
472 | if ((seg->status == WA_SEG_DONE) || | ||
473 | (seg->status == WA_SEG_ERROR)) { | ||
474 | ++seg_index; | ||
475 | } else { | ||
476 | break; | ||
477 | } | ||
478 | } | ||
479 | /* mark remaining segs as aborted. */ | ||
480 | wa_complete_remaining_xfer_segs(xfer, seg_index, | ||
470 | WA_SEG_ABORTED); | 481 | WA_SEG_ABORTED); |
471 | done = __wa_xfer_is_done(xfer); | 482 | done = __wa_xfer_is_done(xfer); |
472 | spin_unlock_irqrestore(&xfer->lock, flags); | 483 | spin_unlock_irqrestore(&xfer->lock, flags); |
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h index 2384add45371..41838db7f85c 100644 --- a/drivers/usb/wusbcore/wusbhc.h +++ b/drivers/usb/wusbcore/wusbhc.h | |||
@@ -295,6 +295,9 @@ struct wusbhc { | |||
295 | } __attribute__((packed)) gtk; | 295 | } __attribute__((packed)) gtk; |
296 | u8 gtk_index; | 296 | u8 gtk_index; |
297 | u32 gtk_tkid; | 297 | u32 gtk_tkid; |
298 | |||
299 | /* workqueue for WUSB security related tasks. */ | ||
300 | struct workqueue_struct *wq_security; | ||
298 | struct work_struct gtk_rekey_work; | 301 | struct work_struct gtk_rekey_work; |
299 | 302 | ||
300 | struct usb_encryption_descriptor *ccm1_etd; | 303 | struct usb_encryption_descriptor *ccm1_etd; |