diff options
Diffstat (limited to 'drivers/usb')
142 files changed, 10857 insertions, 6269 deletions
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 1ae2bf39d84b..3cba892b83a2 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile | |||
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_IMX21_HCD) += host/ | |||
28 | obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/ | 28 | obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/ |
29 | obj-$(CONFIG_USB_FUSBH200_HCD) += host/ | 29 | obj-$(CONFIG_USB_FUSBH200_HCD) += host/ |
30 | obj-$(CONFIG_USB_FOTG210_HCD) += host/ | 30 | obj-$(CONFIG_USB_FOTG210_HCD) += host/ |
31 | obj-$(CONFIG_USB_MAX3421_HCD) += host/ | ||
31 | 32 | ||
32 | obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ | 33 | obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ |
33 | 34 | ||
@@ -58,4 +59,4 @@ obj-$(CONFIG_USB_CHIPIDEA) += chipidea/ | |||
58 | obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/ | 59 | obj-$(CONFIG_USB_RENESAS_USBHS) += renesas_usbhs/ |
59 | obj-$(CONFIG_USB_GADGET) += gadget/ | 60 | obj-$(CONFIG_USB_GADGET) += gadget/ |
60 | 61 | ||
61 | obj-$(CONFIG_USB_COMMON) += usb-common.o | 62 | obj-$(CONFIG_USB_COMMON) += common/ |
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 480bd4d5710a..2f099c7df7b5 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile | |||
@@ -6,6 +6,7 @@ ci_hdrc-y := core.o otg.o | |||
6 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o | 6 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o |
7 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o | 7 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o |
8 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o | 8 | ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o |
9 | ci_hdrc-$(CONFIG_USB_OTG_FSM) += otg_fsm.o | ||
9 | 10 | ||
10 | # Glue/Bridge layers go here | 11 | # Glue/Bridge layers go here |
11 | 12 | ||
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h index 83d06c1455b7..ca57e3dcd3d5 100644 --- a/drivers/usb/chipidea/bits.h +++ b/drivers/usb/chipidea/bits.h | |||
@@ -44,9 +44,14 @@ | |||
44 | #define DEVICEADDR_USBADR (0x7FUL << 25) | 44 | #define DEVICEADDR_USBADR (0x7FUL << 25) |
45 | 45 | ||
46 | /* PORTSC */ | 46 | /* PORTSC */ |
47 | #define PORTSC_CCS BIT(0) | ||
48 | #define PORTSC_CSC BIT(1) | ||
49 | #define PORTSC_PEC BIT(3) | ||
50 | #define PORTSC_OCC BIT(5) | ||
47 | #define PORTSC_FPR BIT(6) | 51 | #define PORTSC_FPR BIT(6) |
48 | #define PORTSC_SUSP BIT(7) | 52 | #define PORTSC_SUSP BIT(7) |
49 | #define PORTSC_HSP BIT(9) | 53 | #define PORTSC_HSP BIT(9) |
54 | #define PORTSC_PP BIT(12) | ||
50 | #define PORTSC_PTC (0x0FUL << 16) | 55 | #define PORTSC_PTC (0x0FUL << 16) |
51 | #define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23)) | 56 | #define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23)) |
52 | /* PTS and PTW for non lpm version only */ | 57 | /* PTS and PTW for non lpm version only */ |
@@ -56,6 +61,9 @@ | |||
56 | #define PORTSC_PTW BIT(28) | 61 | #define PORTSC_PTW BIT(28) |
57 | #define PORTSC_STS BIT(29) | 62 | #define PORTSC_STS BIT(29) |
58 | 63 | ||
64 | #define PORTSC_W1C_BITS \ | ||
65 | (PORTSC_CSC | PORTSC_PEC | PORTSC_OCC) | ||
66 | |||
59 | /* DEVLC */ | 67 | /* DEVLC */ |
60 | #define DEVLC_PFSC BIT(23) | 68 | #define DEVLC_PFSC BIT(23) |
61 | #define DEVLC_PSPD (0x03UL << 25) | 69 | #define DEVLC_PSPD (0x03UL << 25) |
@@ -72,6 +80,8 @@ | |||
72 | 80 | ||
73 | /* OTGSC */ | 81 | /* OTGSC */ |
74 | #define OTGSC_IDPU BIT(5) | 82 | #define OTGSC_IDPU BIT(5) |
83 | #define OTGSC_HADP BIT(6) | ||
84 | #define OTGSC_HABA BIT(7) | ||
75 | #define OTGSC_ID BIT(8) | 85 | #define OTGSC_ID BIT(8) |
76 | #define OTGSC_AVV BIT(9) | 86 | #define OTGSC_AVV BIT(9) |
77 | #define OTGSC_ASV BIT(10) | 87 | #define OTGSC_ASV BIT(10) |
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index e206406ae1d9..9563cb56d564 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/irqreturn.h> | 17 | #include <linux/irqreturn.h> |
18 | #include <linux/usb.h> | 18 | #include <linux/usb.h> |
19 | #include <linux/usb/gadget.h> | 19 | #include <linux/usb/gadget.h> |
20 | #include <linux/usb/otg-fsm.h> | ||
20 | 21 | ||
21 | /****************************************************************************** | 22 | /****************************************************************************** |
22 | * DEFINE | 23 | * DEFINE |
@@ -139,6 +140,8 @@ struct hw_bank { | |||
139 | * @roles: array of supported roles for this controller | 140 | * @roles: array of supported roles for this controller |
140 | * @role: current role | 141 | * @role: current role |
141 | * @is_otg: if the device is otg-capable | 142 | * @is_otg: if the device is otg-capable |
143 | * @fsm: otg finite state machine | ||
144 | * @fsm_timer: pointer to timer list of otg fsm | ||
142 | * @work: work for role changing | 145 | * @work: work for role changing |
143 | * @wq: workqueue thread | 146 | * @wq: workqueue thread |
144 | * @qh_pool: allocation pool for queue heads | 147 | * @qh_pool: allocation pool for queue heads |
@@ -174,6 +177,8 @@ struct ci_hdrc { | |||
174 | struct ci_role_driver *roles[CI_ROLE_END]; | 177 | struct ci_role_driver *roles[CI_ROLE_END]; |
175 | enum ci_role role; | 178 | enum ci_role role; |
176 | bool is_otg; | 179 | bool is_otg; |
180 | struct otg_fsm fsm; | ||
181 | struct ci_otg_fsm_timer_list *fsm_timer; | ||
177 | struct work_struct work; | 182 | struct work_struct work; |
178 | struct workqueue_struct *wq; | 183 | struct workqueue_struct *wq; |
179 | 184 | ||
@@ -319,6 +324,24 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg, | |||
319 | return (val & mask) >> __ffs(mask); | 324 | return (val & mask) >> __ffs(mask); |
320 | } | 325 | } |
321 | 326 | ||
327 | /** | ||
328 | * ci_otg_is_fsm_mode: runtime check if otg controller | ||
329 | * is in otg fsm mode. | ||
330 | */ | ||
331 | static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci) | ||
332 | { | ||
333 | #ifdef CONFIG_USB_OTG_FSM | ||
334 | return ci->is_otg && ci->roles[CI_ROLE_HOST] && | ||
335 | ci->roles[CI_ROLE_GADGET]; | ||
336 | #else | ||
337 | return false; | ||
338 | #endif | ||
339 | } | ||
340 | |||
341 | u32 hw_read_intr_enable(struct ci_hdrc *ci); | ||
342 | |||
343 | u32 hw_read_intr_status(struct ci_hdrc *ci); | ||
344 | |||
322 | int hw_device_reset(struct ci_hdrc *ci, u32 mode); | 345 | int hw_device_reset(struct ci_hdrc *ci, u32 mode); |
323 | 346 | ||
324 | int hw_port_test_set(struct ci_hdrc *ci, u8 mode); | 347 | int hw_port_test_set(struct ci_hdrc *ci, u8 mode); |
diff --git a/drivers/usb/chipidea/ci_hdrc_msm.c b/drivers/usb/chipidea/ci_hdrc_msm.c index 2d51d852b474..d72b9d2de2c5 100644 --- a/drivers/usb/chipidea/ci_hdrc_msm.c +++ b/drivers/usb/chipidea/ci_hdrc_msm.c | |||
@@ -47,6 +47,7 @@ static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event) | |||
47 | 47 | ||
48 | static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { | 48 | static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { |
49 | .name = "ci_hdrc_msm", | 49 | .name = "ci_hdrc_msm", |
50 | .capoffset = DEF_CAPOFFSET, | ||
50 | .flags = CI_HDRC_REGS_SHARED | | 51 | .flags = CI_HDRC_REGS_SHARED | |
51 | CI_HDRC_REQUIRE_TRANSCEIVER | | 52 | CI_HDRC_REQUIRE_TRANSCEIVER | |
52 | CI_HDRC_DISABLE_STREAMING, | 53 | CI_HDRC_DISABLE_STREAMING, |
@@ -57,9 +58,21 @@ static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = { | |||
57 | static int ci_hdrc_msm_probe(struct platform_device *pdev) | 58 | static int ci_hdrc_msm_probe(struct platform_device *pdev) |
58 | { | 59 | { |
59 | struct platform_device *plat_ci; | 60 | struct platform_device *plat_ci; |
61 | struct usb_phy *phy; | ||
60 | 62 | ||
61 | dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); | 63 | dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n"); |
62 | 64 | ||
65 | /* | ||
66 | * OTG(PHY) driver takes care of PHY initialization, clock management, | ||
67 | * powering up VBUS, mapping of registers address space and power | ||
68 | * management. | ||
69 | */ | ||
70 | phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); | ||
71 | if (IS_ERR(phy)) | ||
72 | return PTR_ERR(phy); | ||
73 | |||
74 | ci_hdrc_msm_platdata.phy = phy; | ||
75 | |||
63 | plat_ci = ci_hdrc_add_device(&pdev->dev, | 76 | plat_ci = ci_hdrc_add_device(&pdev->dev, |
64 | pdev->resource, pdev->num_resources, | 77 | pdev->resource, pdev->num_resources, |
65 | &ci_hdrc_msm_platdata); | 78 | &ci_hdrc_msm_platdata); |
@@ -86,10 +99,19 @@ static int ci_hdrc_msm_remove(struct platform_device *pdev) | |||
86 | return 0; | 99 | return 0; |
87 | } | 100 | } |
88 | 101 | ||
102 | static const struct of_device_id msm_ci_dt_match[] = { | ||
103 | { .compatible = "qcom,ci-hdrc", }, | ||
104 | { } | ||
105 | }; | ||
106 | MODULE_DEVICE_TABLE(of, msm_ci_dt_match); | ||
107 | |||
89 | static struct platform_driver ci_hdrc_msm_driver = { | 108 | static struct platform_driver ci_hdrc_msm_driver = { |
90 | .probe = ci_hdrc_msm_probe, | 109 | .probe = ci_hdrc_msm_probe, |
91 | .remove = ci_hdrc_msm_remove, | 110 | .remove = ci_hdrc_msm_remove, |
92 | .driver = { .name = "msm_hsusb", }, | 111 | .driver = { |
112 | .name = "msm_hsusb", | ||
113 | .of_match_table = msm_ci_dt_match, | ||
114 | }, | ||
93 | }; | 115 | }; |
94 | 116 | ||
95 | module_platform_driver(ci_hdrc_msm_driver); | 117 | module_platform_driver(ci_hdrc_msm_driver); |
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 1cd5d0ba587c..619d13e29995 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -23,7 +23,7 @@ | |||
23 | * - BUS: bus glue code, bus abstraction layer | 23 | * - BUS: bus glue code, bus abstraction layer |
24 | * | 24 | * |
25 | * Compile Options | 25 | * Compile Options |
26 | * - CONFIG_USB_GADGET_DEBUG_FILES: enable debug facilities | 26 | * - CONFIG_USB_CHIPIDEA_DEBUG: enable debug facilities |
27 | * - STALL_IN: non-empty bulk-in pipes cannot be halted | 27 | * - STALL_IN: non-empty bulk-in pipes cannot be halted |
28 | * if defined mass storage compliance succeeds but with warnings | 28 | * if defined mass storage compliance succeeds but with warnings |
29 | * => case 4: Hi > Dn | 29 | * => case 4: Hi > Dn |
@@ -42,10 +42,6 @@ | |||
42 | * - Not Supported: 15 & 16 (ISO) | 42 | * - Not Supported: 15 & 16 (ISO) |
43 | * | 43 | * |
44 | * TODO List | 44 | * TODO List |
45 | * - OTG | ||
46 | * - Interrupt Traffic | ||
47 | * - GET_STATUS(device) - always reports 0 | ||
48 | * - Gadget API (majority of optional features) | ||
49 | * - Suspend & Remote Wakeup | 45 | * - Suspend & Remote Wakeup |
50 | */ | 46 | */ |
51 | #include <linux/delay.h> | 47 | #include <linux/delay.h> |
@@ -74,6 +70,7 @@ | |||
74 | #include "host.h" | 70 | #include "host.h" |
75 | #include "debug.h" | 71 | #include "debug.h" |
76 | #include "otg.h" | 72 | #include "otg.h" |
73 | #include "otg_fsm.h" | ||
77 | 74 | ||
78 | /* Controller register map */ | 75 | /* Controller register map */ |
79 | static const u8 ci_regs_nolpm[] = { | 76 | static const u8 ci_regs_nolpm[] = { |
@@ -140,6 +137,26 @@ static int hw_alloc_regmap(struct ci_hdrc *ci, bool is_lpm) | |||
140 | } | 137 | } |
141 | 138 | ||
142 | /** | 139 | /** |
140 | * hw_read_intr_enable: returns interrupt enable register | ||
141 | * | ||
142 | * This function returns register data | ||
143 | */ | ||
144 | u32 hw_read_intr_enable(struct ci_hdrc *ci) | ||
145 | { | ||
146 | return hw_read(ci, OP_USBINTR, ~0); | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * hw_read_intr_status: returns interrupt status register | ||
151 | * | ||
152 | * This function returns register data | ||
153 | */ | ||
154 | u32 hw_read_intr_status(struct ci_hdrc *ci) | ||
155 | { | ||
156 | return hw_read(ci, OP_USBSTS, ~0); | ||
157 | } | ||
158 | |||
159 | /** | ||
143 | * hw_port_test_set: writes port test mode (execute without interruption) | 160 | * hw_port_test_set: writes port test mode (execute without interruption) |
144 | * @mode: new value | 161 | * @mode: new value |
145 | * | 162 | * |
@@ -179,11 +196,10 @@ static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable) | |||
179 | hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), | 196 | hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm), |
180 | 0); | 197 | 0); |
181 | /* | 198 | /* |
182 | * The controller needs at least 1ms to reflect | 199 | * the PHY needs some time (less |
183 | * PHY's status, the PHY also needs some time (less | ||
184 | * than 1ms) to leave low power mode. | 200 | * than 1ms) to leave low power mode. |
185 | */ | 201 | */ |
186 | usleep_range(1500, 2000); | 202 | usleep_range(1000, 1100); |
187 | } | 203 | } |
188 | } | 204 | } |
189 | 205 | ||
@@ -392,8 +408,14 @@ static irqreturn_t ci_irq(int irq, void *data) | |||
392 | irqreturn_t ret = IRQ_NONE; | 408 | irqreturn_t ret = IRQ_NONE; |
393 | u32 otgsc = 0; | 409 | u32 otgsc = 0; |
394 | 410 | ||
395 | if (ci->is_otg) | 411 | if (ci->is_otg) { |
396 | otgsc = hw_read(ci, OP_OTGSC, ~0); | 412 | otgsc = hw_read_otgsc(ci, ~0); |
413 | if (ci_otg_is_fsm_mode(ci)) { | ||
414 | ret = ci_otg_fsm_irq(ci); | ||
415 | if (ret == IRQ_HANDLED) | ||
416 | return ret; | ||
417 | } | ||
418 | } | ||
397 | 419 | ||
398 | /* | 420 | /* |
399 | * Handle id change interrupt, it indicates device/host function | 421 | * Handle id change interrupt, it indicates device/host function |
@@ -401,9 +423,9 @@ static irqreturn_t ci_irq(int irq, void *data) | |||
401 | */ | 423 | */ |
402 | if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { | 424 | if (ci->is_otg && (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) { |
403 | ci->id_event = true; | 425 | ci->id_event = true; |
404 | ci_clear_otg_interrupt(ci, OTGSC_IDIS); | 426 | /* Clear ID change irq status */ |
405 | disable_irq_nosync(ci->irq); | 427 | hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); |
406 | queue_work(ci->wq, &ci->work); | 428 | ci_otg_queue_work(ci); |
407 | return IRQ_HANDLED; | 429 | return IRQ_HANDLED; |
408 | } | 430 | } |
409 | 431 | ||
@@ -413,9 +435,9 @@ static irqreturn_t ci_irq(int irq, void *data) | |||
413 | */ | 435 | */ |
414 | if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { | 436 | if (ci->is_otg && (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) { |
415 | ci->b_sess_valid_event = true; | 437 | ci->b_sess_valid_event = true; |
416 | ci_clear_otg_interrupt(ci, OTGSC_BSVIS); | 438 | /* Clear BSV irq */ |
417 | disable_irq_nosync(ci->irq); | 439 | hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); |
418 | queue_work(ci->wq, &ci->work); | 440 | ci_otg_queue_work(ci); |
419 | return IRQ_HANDLED; | 441 | return IRQ_HANDLED; |
420 | } | 442 | } |
421 | 443 | ||
@@ -533,11 +555,8 @@ static void ci_get_otg_capable(struct ci_hdrc *ci) | |||
533 | ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, | 555 | ci->is_otg = (hw_read(ci, CAP_DCCPARAMS, |
534 | DCCPARAMS_DC | DCCPARAMS_HC) | 556 | DCCPARAMS_DC | DCCPARAMS_HC) |
535 | == (DCCPARAMS_DC | DCCPARAMS_HC)); | 557 | == (DCCPARAMS_DC | DCCPARAMS_HC)); |
536 | if (ci->is_otg) { | 558 | if (ci->is_otg) |
537 | dev_dbg(ci->dev, "It is OTG capable controller\n"); | 559 | dev_dbg(ci->dev, "It is OTG capable controller\n"); |
538 | ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS); | ||
539 | ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS); | ||
540 | } | ||
541 | } | 560 | } |
542 | 561 | ||
543 | static int ci_hdrc_probe(struct platform_device *pdev) | 562 | static int ci_hdrc_probe(struct platform_device *pdev) |
@@ -599,6 +618,13 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
599 | if (ret) { | 618 | if (ret) { |
600 | dev_err(dev, "unable to init phy: %d\n", ret); | 619 | dev_err(dev, "unable to init phy: %d\n", ret); |
601 | return ret; | 620 | return ret; |
621 | } else { | ||
622 | /* | ||
623 | * The delay to sync PHY's status, the maximum delay is | ||
624 | * 2ms since the otgsc uses 1ms timer to debounce the | ||
625 | * PHY's input | ||
626 | */ | ||
627 | usleep_range(2000, 2500); | ||
602 | } | 628 | } |
603 | 629 | ||
604 | ci->hw_bank.phys = res->start; | 630 | ci->hw_bank.phys = res->start; |
@@ -633,6 +659,9 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
633 | } | 659 | } |
634 | 660 | ||
635 | if (ci->is_otg) { | 661 | if (ci->is_otg) { |
662 | /* Disable and clear all OTG irq */ | ||
663 | hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, | ||
664 | OTGSC_INT_STATUS_BITS); | ||
636 | ret = ci_hdrc_otg_init(ci); | 665 | ret = ci_hdrc_otg_init(ci); |
637 | if (ret) { | 666 | if (ret) { |
638 | dev_err(dev, "init otg fails, ret = %d\n", ret); | 667 | dev_err(dev, "init otg fails, ret = %d\n", ret); |
@@ -642,13 +671,9 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
642 | 671 | ||
643 | if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { | 672 | if (ci->roles[CI_ROLE_HOST] && ci->roles[CI_ROLE_GADGET]) { |
644 | if (ci->is_otg) { | 673 | if (ci->is_otg) { |
645 | /* | ||
646 | * ID pin needs 1ms debouce time, | ||
647 | * we delay 2ms for safe. | ||
648 | */ | ||
649 | mdelay(2); | ||
650 | ci->role = ci_otg_role(ci); | 674 | ci->role = ci_otg_role(ci); |
651 | ci_enable_otg_interrupt(ci, OTGSC_IDIE); | 675 | /* Enable ID change irq */ |
676 | hw_write_otgsc(ci, OTGSC_IDIE, OTGSC_IDIE); | ||
652 | } else { | 677 | } else { |
653 | /* | 678 | /* |
654 | * If the controller is not OTG capable, but support | 679 | * If the controller is not OTG capable, but support |
@@ -667,10 +692,13 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
667 | if (ci->role == CI_ROLE_GADGET) | 692 | if (ci->role == CI_ROLE_GADGET) |
668 | ci_handle_vbus_change(ci); | 693 | ci_handle_vbus_change(ci); |
669 | 694 | ||
670 | ret = ci_role_start(ci, ci->role); | 695 | if (!ci_otg_is_fsm_mode(ci)) { |
671 | if (ret) { | 696 | ret = ci_role_start(ci, ci->role); |
672 | dev_err(dev, "can't start %s role\n", ci_role(ci)->name); | 697 | if (ret) { |
673 | goto stop; | 698 | dev_err(dev, "can't start %s role\n", |
699 | ci_role(ci)->name); | ||
700 | goto stop; | ||
701 | } | ||
674 | } | 702 | } |
675 | 703 | ||
676 | platform_set_drvdata(pdev, ci); | 704 | platform_set_drvdata(pdev, ci); |
@@ -679,6 +707,9 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
679 | if (ret) | 707 | if (ret) |
680 | goto stop; | 708 | goto stop; |
681 | 709 | ||
710 | if (ci_otg_is_fsm_mode(ci)) | ||
711 | ci_hdrc_otg_fsm_start(ci); | ||
712 | |||
682 | ret = dbg_create_files(ci); | 713 | ret = dbg_create_files(ci); |
683 | if (!ret) | 714 | if (!ret) |
684 | return 0; | 715 | return 0; |
@@ -711,6 +742,7 @@ static struct platform_driver ci_hdrc_driver = { | |||
711 | .remove = ci_hdrc_remove, | 742 | .remove = ci_hdrc_remove, |
712 | .driver = { | 743 | .driver = { |
713 | .name = "ci_hdrc", | 744 | .name = "ci_hdrc", |
745 | .owner = THIS_MODULE, | ||
714 | }, | 746 | }, |
715 | }; | 747 | }; |
716 | 748 | ||
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c index 96d899aee473..7cccab6ff308 100644 --- a/drivers/usb/chipidea/debug.c +++ b/drivers/usb/chipidea/debug.c | |||
@@ -7,11 +7,15 @@ | |||
7 | #include <linux/uaccess.h> | 7 | #include <linux/uaccess.h> |
8 | #include <linux/usb/ch9.h> | 8 | #include <linux/usb/ch9.h> |
9 | #include <linux/usb/gadget.h> | 9 | #include <linux/usb/gadget.h> |
10 | #include <linux/usb/phy.h> | ||
11 | #include <linux/usb/otg.h> | ||
12 | #include <linux/usb/otg-fsm.h> | ||
10 | 13 | ||
11 | #include "ci.h" | 14 | #include "ci.h" |
12 | #include "udc.h" | 15 | #include "udc.h" |
13 | #include "bits.h" | 16 | #include "bits.h" |
14 | #include "debug.h" | 17 | #include "debug.h" |
18 | #include "otg.h" | ||
15 | 19 | ||
16 | /** | 20 | /** |
17 | * ci_device_show: prints information about device capabilities and status | 21 | * ci_device_show: prints information about device capabilities and status |
@@ -204,6 +208,80 @@ static const struct file_operations ci_requests_fops = { | |||
204 | .release = single_release, | 208 | .release = single_release, |
205 | }; | 209 | }; |
206 | 210 | ||
211 | int ci_otg_show(struct seq_file *s, void *unused) | ||
212 | { | ||
213 | struct ci_hdrc *ci = s->private; | ||
214 | struct otg_fsm *fsm; | ||
215 | |||
216 | if (!ci || !ci_otg_is_fsm_mode(ci)) | ||
217 | return 0; | ||
218 | |||
219 | fsm = &ci->fsm; | ||
220 | |||
221 | /* ------ State ----- */ | ||
222 | seq_printf(s, "OTG state: %s\n\n", | ||
223 | usb_otg_state_string(ci->transceiver->state)); | ||
224 | |||
225 | /* ------ State Machine Variables ----- */ | ||
226 | seq_printf(s, "a_bus_drop: %d\n", fsm->a_bus_drop); | ||
227 | |||
228 | seq_printf(s, "a_bus_req: %d\n", fsm->a_bus_req); | ||
229 | |||
230 | seq_printf(s, "a_srp_det: %d\n", fsm->a_srp_det); | ||
231 | |||
232 | seq_printf(s, "a_vbus_vld: %d\n", fsm->a_vbus_vld); | ||
233 | |||
234 | seq_printf(s, "b_conn: %d\n", fsm->b_conn); | ||
235 | |||
236 | seq_printf(s, "adp_change: %d\n", fsm->adp_change); | ||
237 | |||
238 | seq_printf(s, "power_up: %d\n", fsm->power_up); | ||
239 | |||
240 | seq_printf(s, "a_bus_resume: %d\n", fsm->a_bus_resume); | ||
241 | |||
242 | seq_printf(s, "a_bus_suspend: %d\n", fsm->a_bus_suspend); | ||
243 | |||
244 | seq_printf(s, "a_conn: %d\n", fsm->a_conn); | ||
245 | |||
246 | seq_printf(s, "b_bus_req: %d\n", fsm->b_bus_req); | ||
247 | |||
248 | seq_printf(s, "b_bus_suspend: %d\n", fsm->b_bus_suspend); | ||
249 | |||
250 | seq_printf(s, "b_se0_srp: %d\n", fsm->b_se0_srp); | ||
251 | |||
252 | seq_printf(s, "b_ssend_srp: %d\n", fsm->b_ssend_srp); | ||
253 | |||
254 | seq_printf(s, "b_sess_vld: %d\n", fsm->b_sess_vld); | ||
255 | |||
256 | seq_printf(s, "b_srp_done: %d\n", fsm->b_srp_done); | ||
257 | |||
258 | seq_printf(s, "drv_vbus: %d\n", fsm->drv_vbus); | ||
259 | |||
260 | seq_printf(s, "loc_conn: %d\n", fsm->loc_conn); | ||
261 | |||
262 | seq_printf(s, "loc_sof: %d\n", fsm->loc_sof); | ||
263 | |||
264 | seq_printf(s, "adp_prb: %d\n", fsm->adp_prb); | ||
265 | |||
266 | seq_printf(s, "id: %d\n", fsm->id); | ||
267 | |||
268 | seq_printf(s, "protocol: %d\n", fsm->protocol); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static int ci_otg_open(struct inode *inode, struct file *file) | ||
274 | { | ||
275 | return single_open(file, ci_otg_show, inode->i_private); | ||
276 | } | ||
277 | |||
278 | static const struct file_operations ci_otg_fops = { | ||
279 | .open = ci_otg_open, | ||
280 | .read = seq_read, | ||
281 | .llseek = seq_lseek, | ||
282 | .release = single_release, | ||
283 | }; | ||
284 | |||
207 | static int ci_role_show(struct seq_file *s, void *data) | 285 | static int ci_role_show(struct seq_file *s, void *data) |
208 | { | 286 | { |
209 | struct ci_hdrc *ci = s->private; | 287 | struct ci_hdrc *ci = s->private; |
@@ -253,6 +331,50 @@ static const struct file_operations ci_role_fops = { | |||
253 | .release = single_release, | 331 | .release = single_release, |
254 | }; | 332 | }; |
255 | 333 | ||
334 | int ci_registers_show(struct seq_file *s, void *unused) | ||
335 | { | ||
336 | struct ci_hdrc *ci = s->private; | ||
337 | u32 tmp_reg; | ||
338 | |||
339 | if (!ci) | ||
340 | return 0; | ||
341 | |||
342 | /* ------ Registers ----- */ | ||
343 | tmp_reg = hw_read_intr_enable(ci); | ||
344 | seq_printf(s, "USBINTR reg: %08x\n", tmp_reg); | ||
345 | |||
346 | tmp_reg = hw_read_intr_status(ci); | ||
347 | seq_printf(s, "USBSTS reg: %08x\n", tmp_reg); | ||
348 | |||
349 | tmp_reg = hw_read(ci, OP_USBMODE, ~0); | ||
350 | seq_printf(s, "USBMODE reg: %08x\n", tmp_reg); | ||
351 | |||
352 | tmp_reg = hw_read(ci, OP_USBCMD, ~0); | ||
353 | seq_printf(s, "USBCMD reg: %08x\n", tmp_reg); | ||
354 | |||
355 | tmp_reg = hw_read(ci, OP_PORTSC, ~0); | ||
356 | seq_printf(s, "PORTSC reg: %08x\n", tmp_reg); | ||
357 | |||
358 | if (ci->is_otg) { | ||
359 | tmp_reg = hw_read_otgsc(ci, ~0); | ||
360 | seq_printf(s, "OTGSC reg: %08x\n", tmp_reg); | ||
361 | } | ||
362 | |||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | static int ci_registers_open(struct inode *inode, struct file *file) | ||
367 | { | ||
368 | return single_open(file, ci_registers_show, inode->i_private); | ||
369 | } | ||
370 | |||
371 | static const struct file_operations ci_registers_fops = { | ||
372 | .open = ci_registers_open, | ||
373 | .read = seq_read, | ||
374 | .llseek = seq_lseek, | ||
375 | .release = single_release, | ||
376 | }; | ||
377 | |||
256 | /** | 378 | /** |
257 | * dbg_create_files: initializes the attribute interface | 379 | * dbg_create_files: initializes the attribute interface |
258 | * @ci: device | 380 | * @ci: device |
@@ -287,8 +409,21 @@ int dbg_create_files(struct ci_hdrc *ci) | |||
287 | if (!dent) | 409 | if (!dent) |
288 | goto err; | 410 | goto err; |
289 | 411 | ||
412 | if (ci_otg_is_fsm_mode(ci)) { | ||
413 | dent = debugfs_create_file("otg", S_IRUGO, ci->debugfs, ci, | ||
414 | &ci_otg_fops); | ||
415 | if (!dent) | ||
416 | goto err; | ||
417 | } | ||
418 | |||
290 | dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci, | 419 | dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci, |
291 | &ci_role_fops); | 420 | &ci_role_fops); |
421 | if (!dent) | ||
422 | goto err; | ||
423 | |||
424 | dent = debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci, | ||
425 | &ci_registers_fops); | ||
426 | |||
292 | if (dent) | 427 | if (dent) |
293 | return 0; | 428 | return 0; |
294 | err: | 429 | err: |
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c index a8ac6c16dac9..a93d950e9468 100644 --- a/drivers/usb/chipidea/host.c +++ b/drivers/usb/chipidea/host.c | |||
@@ -67,7 +67,11 @@ static int host_start(struct ci_hdrc *ci) | |||
67 | ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; | 67 | ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; |
68 | ehci->imx28_write_fix = ci->imx28_write_fix; | 68 | ehci->imx28_write_fix = ci->imx28_write_fix; |
69 | 69 | ||
70 | if (ci->platdata->reg_vbus) { | 70 | /* |
71 | * vbus is always on if host is not in OTG FSM mode, | ||
72 | * otherwise should be controlled by OTG FSM | ||
73 | */ | ||
74 | if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) { | ||
71 | ret = regulator_enable(ci->platdata->reg_vbus); | 75 | ret = regulator_enable(ci->platdata->reg_vbus); |
72 | if (ret) { | 76 | if (ret) { |
73 | dev_err(ci->dev, | 77 | dev_err(ci->dev, |
@@ -78,10 +82,17 @@ static int host_start(struct ci_hdrc *ci) | |||
78 | } | 82 | } |
79 | 83 | ||
80 | ret = usb_add_hcd(hcd, 0, 0); | 84 | ret = usb_add_hcd(hcd, 0, 0); |
81 | if (ret) | 85 | if (ret) { |
82 | goto disable_reg; | 86 | goto disable_reg; |
83 | else | 87 | } else { |
88 | struct usb_otg *otg = ci->transceiver->otg; | ||
89 | |||
84 | ci->hcd = hcd; | 90 | ci->hcd = hcd; |
91 | if (otg) { | ||
92 | otg->host = &hcd->self; | ||
93 | hcd->self.otg_port = 1; | ||
94 | } | ||
95 | } | ||
85 | 96 | ||
86 | if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING) | 97 | if (ci->platdata->flags & CI_HDRC_DISABLE_STREAMING) |
87 | hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); | 98 | hw_write(ci, OP_USBMODE, USBMODE_CI_SDIS, USBMODE_CI_SDIS); |
@@ -89,7 +100,7 @@ static int host_start(struct ci_hdrc *ci) | |||
89 | return ret; | 100 | return ret; |
90 | 101 | ||
91 | disable_reg: | 102 | disable_reg: |
92 | if (ci->platdata->reg_vbus) | 103 | if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) |
93 | regulator_disable(ci->platdata->reg_vbus); | 104 | regulator_disable(ci->platdata->reg_vbus); |
94 | 105 | ||
95 | put_hcd: | 106 | put_hcd: |
@@ -105,7 +116,7 @@ static void host_stop(struct ci_hdrc *ci) | |||
105 | if (hcd) { | 116 | if (hcd) { |
106 | usb_remove_hcd(hcd); | 117 | usb_remove_hcd(hcd); |
107 | usb_put_hcd(hcd); | 118 | usb_put_hcd(hcd); |
108 | if (ci->platdata->reg_vbus) | 119 | if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci)) |
109 | regulator_disable(ci->platdata->reg_vbus); | 120 | regulator_disable(ci->platdata->reg_vbus); |
110 | } | 121 | } |
111 | } | 122 | } |
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index 39bd7ec8bf75..a048b08b9d4d 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c | |||
@@ -11,8 +11,8 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * This file mainly handles otgsc register, it may include OTG operation | 14 | * This file mainly handles otgsc register, OTG fsm operations for HNP and SRP |
15 | * in the future. | 15 | * are also included. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/usb/otg.h> | 18 | #include <linux/usb/otg.h> |
@@ -22,6 +22,26 @@ | |||
22 | #include "ci.h" | 22 | #include "ci.h" |
23 | #include "bits.h" | 23 | #include "bits.h" |
24 | #include "otg.h" | 24 | #include "otg.h" |
25 | #include "otg_fsm.h" | ||
26 | |||
27 | /** | ||
28 | * hw_read_otgsc returns otgsc register bits value. | ||
29 | * @mask: bitfield mask | ||
30 | */ | ||
31 | u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask) | ||
32 | { | ||
33 | return hw_read(ci, OP_OTGSC, mask); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * hw_write_otgsc updates target bits of OTGSC register. | ||
38 | * @mask: bitfield mask | ||
39 | * @data: to be written | ||
40 | */ | ||
41 | void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data) | ||
42 | { | ||
43 | hw_write(ci, OP_OTGSC, mask | OTGSC_INT_STATUS_BITS, data); | ||
44 | } | ||
25 | 45 | ||
26 | /** | 46 | /** |
27 | * ci_otg_role - pick role based on ID pin state | 47 | * ci_otg_role - pick role based on ID pin state |
@@ -29,8 +49,7 @@ | |||
29 | */ | 49 | */ |
30 | enum ci_role ci_otg_role(struct ci_hdrc *ci) | 50 | enum ci_role ci_otg_role(struct ci_hdrc *ci) |
31 | { | 51 | { |
32 | u32 sts = hw_read(ci, OP_OTGSC, ~0); | 52 | enum ci_role role = hw_read_otgsc(ci, OTGSC_ID) |
33 | enum ci_role role = sts & OTGSC_ID | ||
34 | ? CI_ROLE_GADGET | 53 | ? CI_ROLE_GADGET |
35 | : CI_ROLE_HOST; | 54 | : CI_ROLE_HOST; |
36 | 55 | ||
@@ -39,14 +58,10 @@ enum ci_role ci_otg_role(struct ci_hdrc *ci) | |||
39 | 58 | ||
40 | void ci_handle_vbus_change(struct ci_hdrc *ci) | 59 | void ci_handle_vbus_change(struct ci_hdrc *ci) |
41 | { | 60 | { |
42 | u32 otgsc; | ||
43 | |||
44 | if (!ci->is_otg) | 61 | if (!ci->is_otg) |
45 | return; | 62 | return; |
46 | 63 | ||
47 | otgsc = hw_read(ci, OP_OTGSC, ~0); | 64 | if (hw_read_otgsc(ci, OTGSC_BSV)) |
48 | |||
49 | if (otgsc & OTGSC_BSV) | ||
50 | usb_gadget_vbus_connect(&ci->gadget); | 65 | usb_gadget_vbus_connect(&ci->gadget); |
51 | else | 66 | else |
52 | usb_gadget_vbus_disconnect(&ci->gadget); | 67 | usb_gadget_vbus_disconnect(&ci->gadget); |
@@ -76,6 +91,11 @@ static void ci_otg_work(struct work_struct *work) | |||
76 | { | 91 | { |
77 | struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); | 92 | struct ci_hdrc *ci = container_of(work, struct ci_hdrc, work); |
78 | 93 | ||
94 | if (ci_otg_is_fsm_mode(ci) && !ci_otg_fsm_work(ci)) { | ||
95 | enable_irq(ci->irq); | ||
96 | return; | ||
97 | } | ||
98 | |||
79 | if (ci->id_event) { | 99 | if (ci->id_event) { |
80 | ci->id_event = false; | 100 | ci->id_event = false; |
81 | ci_handle_id_switch(ci); | 101 | ci_handle_id_switch(ci); |
@@ -102,6 +122,9 @@ int ci_hdrc_otg_init(struct ci_hdrc *ci) | |||
102 | return -ENODEV; | 122 | return -ENODEV; |
103 | } | 123 | } |
104 | 124 | ||
125 | if (ci_otg_is_fsm_mode(ci)) | ||
126 | return ci_hdrc_otg_fsm_init(ci); | ||
127 | |||
105 | return 0; | 128 | return 0; |
106 | } | 129 | } |
107 | 130 | ||
@@ -115,6 +138,9 @@ void ci_hdrc_otg_destroy(struct ci_hdrc *ci) | |||
115 | flush_workqueue(ci->wq); | 138 | flush_workqueue(ci->wq); |
116 | destroy_workqueue(ci->wq); | 139 | destroy_workqueue(ci->wq); |
117 | } | 140 | } |
118 | ci_disable_otg_interrupt(ci, OTGSC_INT_EN_BITS); | 141 | /* Disable all OTG irq and clear status */ |
119 | ci_clear_otg_interrupt(ci, OTGSC_INT_STATUS_BITS); | 142 | hw_write_otgsc(ci, OTGSC_INT_EN_BITS | OTGSC_INT_STATUS_BITS, |
143 | OTGSC_INT_STATUS_BITS); | ||
144 | if (ci_otg_is_fsm_mode(ci)) | ||
145 | ci_hdrc_otg_fsm_remove(ci); | ||
120 | } | 146 | } |
diff --git a/drivers/usb/chipidea/otg.h b/drivers/usb/chipidea/otg.h index 449bee07f4fe..9ecb598e48f0 100644 --- a/drivers/usb/chipidea/otg.h +++ b/drivers/usb/chipidea/otg.h | |||
@@ -11,25 +11,16 @@ | |||
11 | #ifndef __DRIVERS_USB_CHIPIDEA_OTG_H | 11 | #ifndef __DRIVERS_USB_CHIPIDEA_OTG_H |
12 | #define __DRIVERS_USB_CHIPIDEA_OTG_H | 12 | #define __DRIVERS_USB_CHIPIDEA_OTG_H |
13 | 13 | ||
14 | static inline void ci_clear_otg_interrupt(struct ci_hdrc *ci, u32 bits) | 14 | u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask); |
15 | { | 15 | void hw_write_otgsc(struct ci_hdrc *ci, u32 mask, u32 data); |
16 | /* Only clear request bits */ | ||
17 | hw_write(ci, OP_OTGSC, OTGSC_INT_STATUS_BITS, bits); | ||
18 | } | ||
19 | |||
20 | static inline void ci_enable_otg_interrupt(struct ci_hdrc *ci, u32 bits) | ||
21 | { | ||
22 | hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, bits); | ||
23 | } | ||
24 | |||
25 | static inline void ci_disable_otg_interrupt(struct ci_hdrc *ci, u32 bits) | ||
26 | { | ||
27 | hw_write(ci, OP_OTGSC, bits | OTGSC_INT_STATUS_BITS, 0); | ||
28 | } | ||
29 | |||
30 | int ci_hdrc_otg_init(struct ci_hdrc *ci); | 16 | int ci_hdrc_otg_init(struct ci_hdrc *ci); |
31 | void ci_hdrc_otg_destroy(struct ci_hdrc *ci); | 17 | void ci_hdrc_otg_destroy(struct ci_hdrc *ci); |
32 | enum ci_role ci_otg_role(struct ci_hdrc *ci); | 18 | enum ci_role ci_otg_role(struct ci_hdrc *ci); |
33 | void ci_handle_vbus_change(struct ci_hdrc *ci); | 19 | void ci_handle_vbus_change(struct ci_hdrc *ci); |
20 | static inline void ci_otg_queue_work(struct ci_hdrc *ci) | ||
21 | { | ||
22 | disable_irq_nosync(ci->irq); | ||
23 | queue_work(ci->wq, &ci->work); | ||
24 | } | ||
34 | 25 | ||
35 | #endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */ | 26 | #endif /* __DRIVERS_USB_CHIPIDEA_OTG_H */ |
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c new file mode 100644 index 000000000000..caaabc58021e --- /dev/null +++ b/drivers/usb/chipidea/otg_fsm.c | |||
@@ -0,0 +1,842 @@ | |||
1 | /* | ||
2 | * otg_fsm.c - ChipIdea USB IP core OTG FSM driver | ||
3 | * | ||
4 | * Copyright (C) 2014 Freescale Semiconductor, Inc. | ||
5 | * | ||
6 | * Author: Jun Li | ||
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 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * This file mainly handles OTG fsm, it includes OTG fsm operations | ||
15 | * for HNP and SRP. | ||
16 | * | ||
17 | * TODO List | ||
18 | * - ADP | ||
19 | * - OTG test device | ||
20 | */ | ||
21 | |||
22 | #include <linux/usb/otg.h> | ||
23 | #include <linux/usb/gadget.h> | ||
24 | #include <linux/usb/hcd.h> | ||
25 | #include <linux/usb/chipidea.h> | ||
26 | #include <linux/regulator/consumer.h> | ||
27 | |||
28 | #include "ci.h" | ||
29 | #include "bits.h" | ||
30 | #include "otg.h" | ||
31 | #include "otg_fsm.h" | ||
32 | |||
33 | static struct ci_otg_fsm_timer *otg_timer_initializer | ||
34 | (struct ci_hdrc *ci, void (*function)(void *, unsigned long), | ||
35 | unsigned long expires, unsigned long data) | ||
36 | { | ||
37 | struct ci_otg_fsm_timer *timer; | ||
38 | |||
39 | timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer), | ||
40 | GFP_KERNEL); | ||
41 | if (!timer) | ||
42 | return NULL; | ||
43 | timer->function = function; | ||
44 | timer->expires = expires; | ||
45 | timer->data = data; | ||
46 | return timer; | ||
47 | } | ||
48 | |||
49 | /* Add for otg: interact with user space app */ | ||
50 | static ssize_t | ||
51 | get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf) | ||
52 | { | ||
53 | char *next; | ||
54 | unsigned size, t; | ||
55 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
56 | |||
57 | next = buf; | ||
58 | size = PAGE_SIZE; | ||
59 | t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_req); | ||
60 | size -= t; | ||
61 | next += t; | ||
62 | |||
63 | return PAGE_SIZE - size; | ||
64 | } | ||
65 | |||
66 | static ssize_t | ||
67 | set_a_bus_req(struct device *dev, struct device_attribute *attr, | ||
68 | const char *buf, size_t count) | ||
69 | { | ||
70 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
71 | |||
72 | if (count > 2) | ||
73 | return -1; | ||
74 | |||
75 | mutex_lock(&ci->fsm.lock); | ||
76 | if (buf[0] == '0') { | ||
77 | ci->fsm.a_bus_req = 0; | ||
78 | } else if (buf[0] == '1') { | ||
79 | /* If a_bus_drop is TRUE, a_bus_req can't be set */ | ||
80 | if (ci->fsm.a_bus_drop) { | ||
81 | mutex_unlock(&ci->fsm.lock); | ||
82 | return count; | ||
83 | } | ||
84 | ci->fsm.a_bus_req = 1; | ||
85 | } | ||
86 | |||
87 | ci_otg_queue_work(ci); | ||
88 | mutex_unlock(&ci->fsm.lock); | ||
89 | |||
90 | return count; | ||
91 | } | ||
92 | static DEVICE_ATTR(a_bus_req, S_IRUGO | S_IWUSR, get_a_bus_req, set_a_bus_req); | ||
93 | |||
94 | static ssize_t | ||
95 | get_a_bus_drop(struct device *dev, struct device_attribute *attr, char *buf) | ||
96 | { | ||
97 | char *next; | ||
98 | unsigned size, t; | ||
99 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
100 | |||
101 | next = buf; | ||
102 | size = PAGE_SIZE; | ||
103 | t = scnprintf(next, size, "%d\n", ci->fsm.a_bus_drop); | ||
104 | size -= t; | ||
105 | next += t; | ||
106 | |||
107 | return PAGE_SIZE - size; | ||
108 | } | ||
109 | |||
110 | static ssize_t | ||
111 | set_a_bus_drop(struct device *dev, struct device_attribute *attr, | ||
112 | const char *buf, size_t count) | ||
113 | { | ||
114 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
115 | |||
116 | if (count > 2) | ||
117 | return -1; | ||
118 | |||
119 | mutex_lock(&ci->fsm.lock); | ||
120 | if (buf[0] == '0') { | ||
121 | ci->fsm.a_bus_drop = 0; | ||
122 | } else if (buf[0] == '1') { | ||
123 | ci->fsm.a_bus_drop = 1; | ||
124 | ci->fsm.a_bus_req = 0; | ||
125 | } | ||
126 | |||
127 | ci_otg_queue_work(ci); | ||
128 | mutex_unlock(&ci->fsm.lock); | ||
129 | |||
130 | return count; | ||
131 | } | ||
132 | static DEVICE_ATTR(a_bus_drop, S_IRUGO | S_IWUSR, get_a_bus_drop, | ||
133 | set_a_bus_drop); | ||
134 | |||
135 | static ssize_t | ||
136 | get_b_bus_req(struct device *dev, struct device_attribute *attr, char *buf) | ||
137 | { | ||
138 | char *next; | ||
139 | unsigned size, t; | ||
140 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
141 | |||
142 | next = buf; | ||
143 | size = PAGE_SIZE; | ||
144 | t = scnprintf(next, size, "%d\n", ci->fsm.b_bus_req); | ||
145 | size -= t; | ||
146 | next += t; | ||
147 | |||
148 | return PAGE_SIZE - size; | ||
149 | } | ||
150 | |||
151 | static ssize_t | ||
152 | set_b_bus_req(struct device *dev, struct device_attribute *attr, | ||
153 | const char *buf, size_t count) | ||
154 | { | ||
155 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
156 | |||
157 | if (count > 2) | ||
158 | return -1; | ||
159 | |||
160 | mutex_lock(&ci->fsm.lock); | ||
161 | if (buf[0] == '0') | ||
162 | ci->fsm.b_bus_req = 0; | ||
163 | else if (buf[0] == '1') | ||
164 | ci->fsm.b_bus_req = 1; | ||
165 | |||
166 | ci_otg_queue_work(ci); | ||
167 | mutex_unlock(&ci->fsm.lock); | ||
168 | |||
169 | return count; | ||
170 | } | ||
171 | static DEVICE_ATTR(b_bus_req, S_IRUGO | S_IWUSR, get_b_bus_req, set_b_bus_req); | ||
172 | |||
173 | static ssize_t | ||
174 | set_a_clr_err(struct device *dev, struct device_attribute *attr, | ||
175 | const char *buf, size_t count) | ||
176 | { | ||
177 | struct ci_hdrc *ci = dev_get_drvdata(dev); | ||
178 | |||
179 | if (count > 2) | ||
180 | return -1; | ||
181 | |||
182 | mutex_lock(&ci->fsm.lock); | ||
183 | if (buf[0] == '1') | ||
184 | ci->fsm.a_clr_err = 1; | ||
185 | |||
186 | ci_otg_queue_work(ci); | ||
187 | mutex_unlock(&ci->fsm.lock); | ||
188 | |||
189 | return count; | ||
190 | } | ||
191 | static DEVICE_ATTR(a_clr_err, S_IWUSR, NULL, set_a_clr_err); | ||
192 | |||
193 | static struct attribute *inputs_attrs[] = { | ||
194 | &dev_attr_a_bus_req.attr, | ||
195 | &dev_attr_a_bus_drop.attr, | ||
196 | &dev_attr_b_bus_req.attr, | ||
197 | &dev_attr_a_clr_err.attr, | ||
198 | NULL, | ||
199 | }; | ||
200 | |||
201 | static struct attribute_group inputs_attr_group = { | ||
202 | .name = "inputs", | ||
203 | .attrs = inputs_attrs, | ||
204 | }; | ||
205 | |||
206 | /* | ||
207 | * Add timer to active timer list | ||
208 | */ | ||
209 | static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) | ||
210 | { | ||
211 | struct ci_otg_fsm_timer *tmp_timer; | ||
212 | struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; | ||
213 | struct list_head *active_timers = &ci->fsm_timer->active_timers; | ||
214 | |||
215 | if (t >= NUM_CI_OTG_FSM_TIMERS) | ||
216 | return; | ||
217 | |||
218 | /* | ||
219 | * Check if the timer is already in the active list, | ||
220 | * if so update timer count | ||
221 | */ | ||
222 | list_for_each_entry(tmp_timer, active_timers, list) | ||
223 | if (tmp_timer == timer) { | ||
224 | timer->count = timer->expires; | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | timer->count = timer->expires; | ||
229 | list_add_tail(&timer->list, active_timers); | ||
230 | |||
231 | /* Enable 1ms irq */ | ||
232 | if (!(hw_read_otgsc(ci, OTGSC_1MSIE))) | ||
233 | hw_write_otgsc(ci, OTGSC_1MSIE, OTGSC_1MSIE); | ||
234 | } | ||
235 | |||
236 | /* | ||
237 | * Remove timer from active timer list | ||
238 | */ | ||
239 | static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t) | ||
240 | { | ||
241 | struct ci_otg_fsm_timer *tmp_timer, *del_tmp; | ||
242 | struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t]; | ||
243 | struct list_head *active_timers = &ci->fsm_timer->active_timers; | ||
244 | |||
245 | if (t >= NUM_CI_OTG_FSM_TIMERS) | ||
246 | return; | ||
247 | |||
248 | list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) | ||
249 | if (tmp_timer == timer) | ||
250 | list_del(&timer->list); | ||
251 | |||
252 | /* Disable 1ms irq if there is no any active timer */ | ||
253 | if (list_empty(active_timers)) | ||
254 | hw_write_otgsc(ci, OTGSC_1MSIE, 0); | ||
255 | } | ||
256 | |||
257 | /* | ||
258 | * Reduce timer count by 1, and find timeout conditions. | ||
259 | * Called by otg 1ms timer interrupt | ||
260 | */ | ||
261 | static inline int ci_otg_tick_timer(struct ci_hdrc *ci) | ||
262 | { | ||
263 | struct ci_otg_fsm_timer *tmp_timer, *del_tmp; | ||
264 | struct list_head *active_timers = &ci->fsm_timer->active_timers; | ||
265 | int expired = 0; | ||
266 | |||
267 | list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list) { | ||
268 | tmp_timer->count--; | ||
269 | /* check if timer expires */ | ||
270 | if (!tmp_timer->count) { | ||
271 | list_del(&tmp_timer->list); | ||
272 | tmp_timer->function(ci, tmp_timer->data); | ||
273 | expired = 1; | ||
274 | } | ||
275 | } | ||
276 | |||
277 | /* disable 1ms irq if there is no any timer active */ | ||
278 | if ((expired == 1) && list_empty(active_timers)) | ||
279 | hw_write_otgsc(ci, OTGSC_1MSIE, 0); | ||
280 | |||
281 | return expired; | ||
282 | } | ||
283 | |||
284 | /* The timeout callback function to set time out bit */ | ||
285 | static void set_tmout(void *ptr, unsigned long indicator) | ||
286 | { | ||
287 | *(int *)indicator = 1; | ||
288 | } | ||
289 | |||
290 | static void set_tmout_and_fsm(void *ptr, unsigned long indicator) | ||
291 | { | ||
292 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
293 | |||
294 | set_tmout(ci, indicator); | ||
295 | |||
296 | ci_otg_queue_work(ci); | ||
297 | } | ||
298 | |||
299 | static void a_wait_vfall_tmout_func(void *ptr, unsigned long indicator) | ||
300 | { | ||
301 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
302 | |||
303 | set_tmout(ci, indicator); | ||
304 | /* Disable port power */ | ||
305 | hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, 0); | ||
306 | /* Clear exsiting DP irq */ | ||
307 | hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); | ||
308 | /* Enable data pulse irq */ | ||
309 | hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE); | ||
310 | ci_otg_queue_work(ci); | ||
311 | } | ||
312 | |||
313 | static void b_ase0_brst_tmout_func(void *ptr, unsigned long indicator) | ||
314 | { | ||
315 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
316 | |||
317 | set_tmout(ci, indicator); | ||
318 | if (!hw_read_otgsc(ci, OTGSC_BSV)) | ||
319 | ci->fsm.b_sess_vld = 0; | ||
320 | |||
321 | ci_otg_queue_work(ci); | ||
322 | } | ||
323 | |||
324 | static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator) | ||
325 | { | ||
326 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
327 | |||
328 | set_tmout(ci, indicator); | ||
329 | |||
330 | /* only vbus fall below B_sess_vld in b_idle state */ | ||
331 | if (ci->transceiver->state == OTG_STATE_B_IDLE) | ||
332 | ci_otg_queue_work(ci); | ||
333 | } | ||
334 | |||
335 | static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator) | ||
336 | { | ||
337 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
338 | |||
339 | /* Check if A detached */ | ||
340 | if (!(hw_read_otgsc(ci, OTGSC_BSV))) { | ||
341 | ci->fsm.b_sess_vld = 0; | ||
342 | ci_otg_add_timer(ci, B_SSEND_SRP); | ||
343 | ci_otg_queue_work(ci); | ||
344 | } | ||
345 | } | ||
346 | |||
347 | static void b_data_pulse_end(void *ptr, unsigned long indicator) | ||
348 | { | ||
349 | struct ci_hdrc *ci = (struct ci_hdrc *)ptr; | ||
350 | |||
351 | ci->fsm.b_srp_done = 1; | ||
352 | ci->fsm.b_bus_req = 0; | ||
353 | if (ci->fsm.power_up) | ||
354 | ci->fsm.power_up = 0; | ||
355 | |||
356 | hw_write_otgsc(ci, OTGSC_HABA, 0); | ||
357 | |||
358 | ci_otg_queue_work(ci); | ||
359 | } | ||
360 | |||
361 | /* Initialize timers */ | ||
362 | static int ci_otg_init_timers(struct ci_hdrc *ci) | ||
363 | { | ||
364 | struct otg_fsm *fsm = &ci->fsm; | ||
365 | |||
366 | /* FSM used timers */ | ||
367 | ci->fsm_timer->timer_list[A_WAIT_VRISE] = | ||
368 | otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_VRISE, | ||
369 | (unsigned long)&fsm->a_wait_vrise_tmout); | ||
370 | if (ci->fsm_timer->timer_list[A_WAIT_VRISE] == NULL) | ||
371 | return -ENOMEM; | ||
372 | |||
373 | ci->fsm_timer->timer_list[A_WAIT_VFALL] = | ||
374 | otg_timer_initializer(ci, &a_wait_vfall_tmout_func, | ||
375 | TA_WAIT_VFALL, (unsigned long)&fsm->a_wait_vfall_tmout); | ||
376 | if (ci->fsm_timer->timer_list[A_WAIT_VFALL] == NULL) | ||
377 | return -ENOMEM; | ||
378 | |||
379 | ci->fsm_timer->timer_list[A_WAIT_BCON] = | ||
380 | otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_BCON, | ||
381 | (unsigned long)&fsm->a_wait_bcon_tmout); | ||
382 | if (ci->fsm_timer->timer_list[A_WAIT_BCON] == NULL) | ||
383 | return -ENOMEM; | ||
384 | |||
385 | ci->fsm_timer->timer_list[A_AIDL_BDIS] = | ||
386 | otg_timer_initializer(ci, &set_tmout_and_fsm, TA_AIDL_BDIS, | ||
387 | (unsigned long)&fsm->a_aidl_bdis_tmout); | ||
388 | if (ci->fsm_timer->timer_list[A_AIDL_BDIS] == NULL) | ||
389 | return -ENOMEM; | ||
390 | |||
391 | ci->fsm_timer->timer_list[A_BIDL_ADIS] = | ||
392 | otg_timer_initializer(ci, &set_tmout_and_fsm, TA_BIDL_ADIS, | ||
393 | (unsigned long)&fsm->a_bidl_adis_tmout); | ||
394 | if (ci->fsm_timer->timer_list[A_BIDL_ADIS] == NULL) | ||
395 | return -ENOMEM; | ||
396 | |||
397 | ci->fsm_timer->timer_list[B_ASE0_BRST] = | ||
398 | otg_timer_initializer(ci, &b_ase0_brst_tmout_func, TB_ASE0_BRST, | ||
399 | (unsigned long)&fsm->b_ase0_brst_tmout); | ||
400 | if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL) | ||
401 | return -ENOMEM; | ||
402 | |||
403 | ci->fsm_timer->timer_list[B_SE0_SRP] = | ||
404 | otg_timer_initializer(ci, &set_tmout_and_fsm, TB_SE0_SRP, | ||
405 | (unsigned long)&fsm->b_se0_srp); | ||
406 | if (ci->fsm_timer->timer_list[B_SE0_SRP] == NULL) | ||
407 | return -ENOMEM; | ||
408 | |||
409 | ci->fsm_timer->timer_list[B_SSEND_SRP] = | ||
410 | otg_timer_initializer(ci, &b_ssend_srp_tmout_func, TB_SSEND_SRP, | ||
411 | (unsigned long)&fsm->b_ssend_srp); | ||
412 | if (ci->fsm_timer->timer_list[B_SSEND_SRP] == NULL) | ||
413 | return -ENOMEM; | ||
414 | |||
415 | ci->fsm_timer->timer_list[B_SRP_FAIL] = | ||
416 | otg_timer_initializer(ci, &set_tmout, TB_SRP_FAIL, | ||
417 | (unsigned long)&fsm->b_srp_done); | ||
418 | if (ci->fsm_timer->timer_list[B_SRP_FAIL] == NULL) | ||
419 | return -ENOMEM; | ||
420 | |||
421 | ci->fsm_timer->timer_list[B_DATA_PLS] = | ||
422 | otg_timer_initializer(ci, &b_data_pulse_end, TB_DATA_PLS, 0); | ||
423 | if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL) | ||
424 | return -ENOMEM; | ||
425 | |||
426 | ci->fsm_timer->timer_list[B_SESS_VLD] = otg_timer_initializer(ci, | ||
427 | &b_sess_vld_tmout_func, TB_SESS_VLD, 0); | ||
428 | if (ci->fsm_timer->timer_list[B_SESS_VLD] == NULL) | ||
429 | return -ENOMEM; | ||
430 | |||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | /* -------------------------------------------------------------*/ | ||
435 | /* Operations that will be called from OTG Finite State Machine */ | ||
436 | /* -------------------------------------------------------------*/ | ||
437 | static void ci_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) | ||
438 | { | ||
439 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
440 | |||
441 | if (t < NUM_OTG_FSM_TIMERS) | ||
442 | ci_otg_add_timer(ci, t); | ||
443 | return; | ||
444 | } | ||
445 | |||
446 | static void ci_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t) | ||
447 | { | ||
448 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
449 | |||
450 | if (t < NUM_OTG_FSM_TIMERS) | ||
451 | ci_otg_del_timer(ci, t); | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | /* | ||
456 | * A-device drive vbus: turn on vbus regulator and enable port power | ||
457 | * Data pulse irq should be disabled while vbus is on. | ||
458 | */ | ||
459 | static void ci_otg_drv_vbus(struct otg_fsm *fsm, int on) | ||
460 | { | ||
461 | int ret; | ||
462 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
463 | |||
464 | if (on) { | ||
465 | /* Enable power power */ | ||
466 | hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, | ||
467 | PORTSC_PP); | ||
468 | if (ci->platdata->reg_vbus) { | ||
469 | ret = regulator_enable(ci->platdata->reg_vbus); | ||
470 | if (ret) { | ||
471 | dev_err(ci->dev, | ||
472 | "Failed to enable vbus regulator, ret=%d\n", | ||
473 | ret); | ||
474 | return; | ||
475 | } | ||
476 | } | ||
477 | /* Disable data pulse irq */ | ||
478 | hw_write_otgsc(ci, OTGSC_DPIE, 0); | ||
479 | |||
480 | fsm->a_srp_det = 0; | ||
481 | fsm->power_up = 0; | ||
482 | } else { | ||
483 | if (ci->platdata->reg_vbus) | ||
484 | regulator_disable(ci->platdata->reg_vbus); | ||
485 | |||
486 | fsm->a_bus_drop = 1; | ||
487 | fsm->a_bus_req = 0; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | /* | ||
492 | * Control data line by Run Stop bit. | ||
493 | */ | ||
494 | static void ci_otg_loc_conn(struct otg_fsm *fsm, int on) | ||
495 | { | ||
496 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
497 | |||
498 | if (on) | ||
499 | hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); | ||
500 | else | ||
501 | hw_write(ci, OP_USBCMD, USBCMD_RS, 0); | ||
502 | } | ||
503 | |||
504 | /* | ||
505 | * Generate SOF by host. | ||
506 | * This is controlled through suspend/resume the port. | ||
507 | * In host mode, controller will automatically send SOF. | ||
508 | * Suspend will block the data on the port. | ||
509 | */ | ||
510 | static void ci_otg_loc_sof(struct otg_fsm *fsm, int on) | ||
511 | { | ||
512 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
513 | |||
514 | if (on) | ||
515 | hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_FPR, | ||
516 | PORTSC_FPR); | ||
517 | else | ||
518 | hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_SUSP, | ||
519 | PORTSC_SUSP); | ||
520 | } | ||
521 | |||
522 | /* | ||
523 | * Start SRP pulsing by data-line pulsing, | ||
524 | * no v-bus pulsing followed | ||
525 | */ | ||
526 | static void ci_otg_start_pulse(struct otg_fsm *fsm) | ||
527 | { | ||
528 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
529 | |||
530 | /* Hardware Assistant Data pulse */ | ||
531 | hw_write_otgsc(ci, OTGSC_HADP, OTGSC_HADP); | ||
532 | |||
533 | ci_otg_add_timer(ci, B_DATA_PLS); | ||
534 | } | ||
535 | |||
536 | static int ci_otg_start_host(struct otg_fsm *fsm, int on) | ||
537 | { | ||
538 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
539 | |||
540 | mutex_unlock(&fsm->lock); | ||
541 | if (on) { | ||
542 | ci_role_stop(ci); | ||
543 | ci_role_start(ci, CI_ROLE_HOST); | ||
544 | } else { | ||
545 | ci_role_stop(ci); | ||
546 | hw_device_reset(ci, USBMODE_CM_DC); | ||
547 | ci_role_start(ci, CI_ROLE_GADGET); | ||
548 | } | ||
549 | mutex_lock(&fsm->lock); | ||
550 | return 0; | ||
551 | } | ||
552 | |||
553 | static int ci_otg_start_gadget(struct otg_fsm *fsm, int on) | ||
554 | { | ||
555 | struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); | ||
556 | |||
557 | mutex_unlock(&fsm->lock); | ||
558 | if (on) | ||
559 | usb_gadget_vbus_connect(&ci->gadget); | ||
560 | else | ||
561 | usb_gadget_vbus_disconnect(&ci->gadget); | ||
562 | mutex_lock(&fsm->lock); | ||
563 | |||
564 | return 0; | ||
565 | } | ||
566 | |||
567 | static struct otg_fsm_ops ci_otg_ops = { | ||
568 | .drv_vbus = ci_otg_drv_vbus, | ||
569 | .loc_conn = ci_otg_loc_conn, | ||
570 | .loc_sof = ci_otg_loc_sof, | ||
571 | .start_pulse = ci_otg_start_pulse, | ||
572 | .add_timer = ci_otg_fsm_add_timer, | ||
573 | .del_timer = ci_otg_fsm_del_timer, | ||
574 | .start_host = ci_otg_start_host, | ||
575 | .start_gadget = ci_otg_start_gadget, | ||
576 | }; | ||
577 | |||
578 | int ci_otg_fsm_work(struct ci_hdrc *ci) | ||
579 | { | ||
580 | /* | ||
581 | * Don't do fsm transition for B device | ||
582 | * when there is no gadget class driver | ||
583 | */ | ||
584 | if (ci->fsm.id && !(ci->driver) && | ||
585 | ci->transceiver->state < OTG_STATE_A_IDLE) | ||
586 | return 0; | ||
587 | |||
588 | if (otg_statemachine(&ci->fsm)) { | ||
589 | if (ci->transceiver->state == OTG_STATE_A_IDLE) { | ||
590 | /* | ||
591 | * Further state change for cases: | ||
592 | * a_idle to b_idle; or | ||
593 | * a_idle to a_wait_vrise due to ID change(1->0), so | ||
594 | * B-dev becomes A-dev can try to start new session | ||
595 | * consequently; or | ||
596 | * a_idle to a_wait_vrise when power up | ||
597 | */ | ||
598 | if ((ci->fsm.id) || (ci->id_event) || | ||
599 | (ci->fsm.power_up)) | ||
600 | ci_otg_queue_work(ci); | ||
601 | if (ci->id_event) | ||
602 | ci->id_event = false; | ||
603 | } else if (ci->transceiver->state == OTG_STATE_B_IDLE) { | ||
604 | if (ci->fsm.b_sess_vld) { | ||
605 | ci->fsm.power_up = 0; | ||
606 | /* | ||
607 | * Further transite to b_periphearl state | ||
608 | * when register gadget driver with vbus on | ||
609 | */ | ||
610 | ci_otg_queue_work(ci); | ||
611 | } | ||
612 | } | ||
613 | } | ||
614 | return 0; | ||
615 | } | ||
616 | |||
617 | /* | ||
618 | * Update fsm variables in each state if catching expected interrupts, | ||
619 | * called by otg fsm isr. | ||
620 | */ | ||
621 | static void ci_otg_fsm_event(struct ci_hdrc *ci) | ||
622 | { | ||
623 | u32 intr_sts, otg_bsess_vld, port_conn; | ||
624 | struct otg_fsm *fsm = &ci->fsm; | ||
625 | |||
626 | intr_sts = hw_read_intr_status(ci); | ||
627 | otg_bsess_vld = hw_read_otgsc(ci, OTGSC_BSV); | ||
628 | port_conn = hw_read(ci, OP_PORTSC, PORTSC_CCS); | ||
629 | |||
630 | switch (ci->transceiver->state) { | ||
631 | case OTG_STATE_A_WAIT_BCON: | ||
632 | if (port_conn) { | ||
633 | fsm->b_conn = 1; | ||
634 | fsm->a_bus_req = 1; | ||
635 | ci_otg_queue_work(ci); | ||
636 | } | ||
637 | break; | ||
638 | case OTG_STATE_B_IDLE: | ||
639 | if (otg_bsess_vld && (intr_sts & USBi_PCI) && port_conn) { | ||
640 | fsm->b_sess_vld = 1; | ||
641 | ci_otg_queue_work(ci); | ||
642 | } | ||
643 | break; | ||
644 | case OTG_STATE_B_PERIPHERAL: | ||
645 | if ((intr_sts & USBi_SLI) && port_conn && otg_bsess_vld) { | ||
646 | fsm->a_bus_suspend = 1; | ||
647 | ci_otg_queue_work(ci); | ||
648 | } else if (intr_sts & USBi_PCI) { | ||
649 | if (fsm->a_bus_suspend == 1) | ||
650 | fsm->a_bus_suspend = 0; | ||
651 | } | ||
652 | break; | ||
653 | case OTG_STATE_B_HOST: | ||
654 | if ((intr_sts & USBi_PCI) && !port_conn) { | ||
655 | fsm->a_conn = 0; | ||
656 | fsm->b_bus_req = 0; | ||
657 | ci_otg_queue_work(ci); | ||
658 | ci_otg_add_timer(ci, B_SESS_VLD); | ||
659 | } | ||
660 | break; | ||
661 | case OTG_STATE_A_PERIPHERAL: | ||
662 | if (intr_sts & USBi_SLI) { | ||
663 | fsm->b_bus_suspend = 1; | ||
664 | /* | ||
665 | * Init a timer to know how long this suspend | ||
666 | * will contine, if time out, indicates B no longer | ||
667 | * wants to be host role | ||
668 | */ | ||
669 | ci_otg_add_timer(ci, A_BIDL_ADIS); | ||
670 | } | ||
671 | |||
672 | if (intr_sts & USBi_URI) | ||
673 | ci_otg_del_timer(ci, A_BIDL_ADIS); | ||
674 | |||
675 | if (intr_sts & USBi_PCI) { | ||
676 | if (fsm->b_bus_suspend == 1) { | ||
677 | ci_otg_del_timer(ci, A_BIDL_ADIS); | ||
678 | fsm->b_bus_suspend = 0; | ||
679 | } | ||
680 | } | ||
681 | break; | ||
682 | case OTG_STATE_A_SUSPEND: | ||
683 | if ((intr_sts & USBi_PCI) && !port_conn) { | ||
684 | fsm->b_conn = 0; | ||
685 | |||
686 | /* if gadget driver is binded */ | ||
687 | if (ci->driver) { | ||
688 | /* A device to be peripheral mode */ | ||
689 | ci->gadget.is_a_peripheral = 1; | ||
690 | } | ||
691 | ci_otg_queue_work(ci); | ||
692 | } | ||
693 | break; | ||
694 | case OTG_STATE_A_HOST: | ||
695 | if ((intr_sts & USBi_PCI) && !port_conn) { | ||
696 | fsm->b_conn = 0; | ||
697 | ci_otg_queue_work(ci); | ||
698 | } | ||
699 | break; | ||
700 | case OTG_STATE_B_WAIT_ACON: | ||
701 | if ((intr_sts & USBi_PCI) && port_conn) { | ||
702 | fsm->a_conn = 1; | ||
703 | ci_otg_queue_work(ci); | ||
704 | } | ||
705 | break; | ||
706 | default: | ||
707 | break; | ||
708 | } | ||
709 | } | ||
710 | |||
711 | /* | ||
712 | * ci_otg_irq - otg fsm related irq handling | ||
713 | * and also update otg fsm variable by monitoring usb host and udc | ||
714 | * state change interrupts. | ||
715 | * @ci: ci_hdrc | ||
716 | */ | ||
717 | irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci) | ||
718 | { | ||
719 | irqreturn_t retval = IRQ_NONE; | ||
720 | u32 otgsc, otg_int_src = 0; | ||
721 | struct otg_fsm *fsm = &ci->fsm; | ||
722 | |||
723 | otgsc = hw_read_otgsc(ci, ~0); | ||
724 | otg_int_src = otgsc & OTGSC_INT_STATUS_BITS & (otgsc >> 8); | ||
725 | fsm->id = (otgsc & OTGSC_ID) ? 1 : 0; | ||
726 | |||
727 | if (otg_int_src) { | ||
728 | if (otg_int_src & OTGSC_1MSIS) { | ||
729 | hw_write_otgsc(ci, OTGSC_1MSIS, OTGSC_1MSIS); | ||
730 | retval = ci_otg_tick_timer(ci); | ||
731 | return IRQ_HANDLED; | ||
732 | } else if (otg_int_src & OTGSC_DPIS) { | ||
733 | hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS); | ||
734 | fsm->a_srp_det = 1; | ||
735 | fsm->a_bus_drop = 0; | ||
736 | } else if (otg_int_src & OTGSC_IDIS) { | ||
737 | hw_write_otgsc(ci, OTGSC_IDIS, OTGSC_IDIS); | ||
738 | if (fsm->id == 0) { | ||
739 | fsm->a_bus_drop = 0; | ||
740 | fsm->a_bus_req = 1; | ||
741 | ci->id_event = true; | ||
742 | } | ||
743 | } else if (otg_int_src & OTGSC_BSVIS) { | ||
744 | hw_write_otgsc(ci, OTGSC_BSVIS, OTGSC_BSVIS); | ||
745 | if (otgsc & OTGSC_BSV) { | ||
746 | fsm->b_sess_vld = 1; | ||
747 | ci_otg_del_timer(ci, B_SSEND_SRP); | ||
748 | ci_otg_del_timer(ci, B_SRP_FAIL); | ||
749 | fsm->b_ssend_srp = 0; | ||
750 | } else { | ||
751 | fsm->b_sess_vld = 0; | ||
752 | if (fsm->id) | ||
753 | ci_otg_add_timer(ci, B_SSEND_SRP); | ||
754 | } | ||
755 | } else if (otg_int_src & OTGSC_AVVIS) { | ||
756 | hw_write_otgsc(ci, OTGSC_AVVIS, OTGSC_AVVIS); | ||
757 | if (otgsc & OTGSC_AVV) { | ||
758 | fsm->a_vbus_vld = 1; | ||
759 | } else { | ||
760 | fsm->a_vbus_vld = 0; | ||
761 | fsm->b_conn = 0; | ||
762 | } | ||
763 | } | ||
764 | ci_otg_queue_work(ci); | ||
765 | return IRQ_HANDLED; | ||
766 | } | ||
767 | |||
768 | ci_otg_fsm_event(ci); | ||
769 | |||
770 | return retval; | ||
771 | } | ||
772 | |||
773 | void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) | ||
774 | { | ||
775 | ci_otg_queue_work(ci); | ||
776 | } | ||
777 | |||
778 | int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) | ||
779 | { | ||
780 | int retval = 0; | ||
781 | struct usb_otg *otg; | ||
782 | |||
783 | otg = devm_kzalloc(ci->dev, | ||
784 | sizeof(struct usb_otg), GFP_KERNEL); | ||
785 | if (!otg) { | ||
786 | dev_err(ci->dev, | ||
787 | "Failed to allocate usb_otg structure for ci hdrc otg!\n"); | ||
788 | return -ENOMEM; | ||
789 | } | ||
790 | |||
791 | otg->phy = ci->transceiver; | ||
792 | otg->gadget = &ci->gadget; | ||
793 | ci->fsm.otg = otg; | ||
794 | ci->transceiver->otg = ci->fsm.otg; | ||
795 | ci->fsm.power_up = 1; | ||
796 | ci->fsm.id = hw_read_otgsc(ci, OTGSC_ID) ? 1 : 0; | ||
797 | ci->transceiver->state = OTG_STATE_UNDEFINED; | ||
798 | ci->fsm.ops = &ci_otg_ops; | ||
799 | |||
800 | mutex_init(&ci->fsm.lock); | ||
801 | |||
802 | ci->fsm_timer = devm_kzalloc(ci->dev, | ||
803 | sizeof(struct ci_otg_fsm_timer_list), GFP_KERNEL); | ||
804 | if (!ci->fsm_timer) { | ||
805 | dev_err(ci->dev, | ||
806 | "Failed to allocate timer structure for ci hdrc otg!\n"); | ||
807 | return -ENOMEM; | ||
808 | } | ||
809 | |||
810 | INIT_LIST_HEAD(&ci->fsm_timer->active_timers); | ||
811 | retval = ci_otg_init_timers(ci); | ||
812 | if (retval) { | ||
813 | dev_err(ci->dev, "Couldn't init OTG timers\n"); | ||
814 | return retval; | ||
815 | } | ||
816 | |||
817 | retval = sysfs_create_group(&ci->dev->kobj, &inputs_attr_group); | ||
818 | if (retval < 0) { | ||
819 | dev_dbg(ci->dev, | ||
820 | "Can't register sysfs attr group: %d\n", retval); | ||
821 | return retval; | ||
822 | } | ||
823 | |||
824 | /* Enable A vbus valid irq */ | ||
825 | hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE); | ||
826 | |||
827 | if (ci->fsm.id) { | ||
828 | ci->fsm.b_ssend_srp = | ||
829 | hw_read_otgsc(ci, OTGSC_BSV) ? 0 : 1; | ||
830 | ci->fsm.b_sess_vld = | ||
831 | hw_read_otgsc(ci, OTGSC_BSV) ? 1 : 0; | ||
832 | /* Enable BSV irq */ | ||
833 | hw_write_otgsc(ci, OTGSC_BSVIE, OTGSC_BSVIE); | ||
834 | } | ||
835 | |||
836 | return 0; | ||
837 | } | ||
838 | |||
839 | void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) | ||
840 | { | ||
841 | sysfs_remove_group(&ci->dev->kobj, &inputs_attr_group); | ||
842 | } | ||
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h new file mode 100644 index 000000000000..94c085f456a9 --- /dev/null +++ b/drivers/usb/chipidea/otg_fsm.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * Author: Jun Li | ||
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 | #ifndef __DRIVERS_USB_CHIPIDEA_OTG_FSM_H | ||
12 | #define __DRIVERS_USB_CHIPIDEA_OTG_FSM_H | ||
13 | |||
14 | #include <linux/usb/otg-fsm.h> | ||
15 | |||
16 | /* | ||
17 | * A-DEVICE timing constants | ||
18 | */ | ||
19 | |||
20 | /* Wait for VBUS Rise */ | ||
21 | #define TA_WAIT_VRISE (100) /* a_wait_vrise: section 7.1.2 | ||
22 | * a_wait_vrise_tmr: section 7.4.5.1 | ||
23 | * TA_VBUS_RISE <= 100ms, section 4.4 | ||
24 | * Table 4-1: Electrical Characteristics | ||
25 | * ->DC Electrical Timing | ||
26 | */ | ||
27 | /* Wait for VBUS Fall */ | ||
28 | #define TA_WAIT_VFALL (1000) /* a_wait_vfall: section 7.1.7 | ||
29 | * a_wait_vfall_tmr: section: 7.4.5.2 | ||
30 | */ | ||
31 | /* Wait for B-Connect */ | ||
32 | #define TA_WAIT_BCON (10000) /* a_wait_bcon: section 7.1.3 | ||
33 | * TA_WAIT_BCON: should be between 1100 | ||
34 | * and 30000 ms, section 5.5, Table 5-1 | ||
35 | */ | ||
36 | /* A-Idle to B-Disconnect */ | ||
37 | #define TA_AIDL_BDIS (5000) /* a_suspend min 200 ms, section 5.2.1 | ||
38 | * TA_AIDL_BDIS: section 5.5, Table 5-1 | ||
39 | */ | ||
40 | /* B-Idle to A-Disconnect */ | ||
41 | #define TA_BIDL_ADIS (500) /* TA_BIDL_ADIS: section 5.2.1 | ||
42 | * 500ms is used for B switch to host | ||
43 | * for safe | ||
44 | */ | ||
45 | |||
46 | /* | ||
47 | * B-device timing constants | ||
48 | */ | ||
49 | |||
50 | /* Data-Line Pulse Time*/ | ||
51 | #define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms | ||
52 | * section:5.1.3 | ||
53 | */ | ||
54 | /* SRP Fail Time */ | ||
55 | #define TB_SRP_FAIL (6000) /* b_srp_init,fail time 5~6s | ||
56 | * section:5.1.6 | ||
57 | */ | ||
58 | /* A-SE0 to B-Reset */ | ||
59 | #define TB_ASE0_BRST (155) /* minimum 155 ms, section:5.3.1 */ | ||
60 | /* SE0 Time Before SRP */ | ||
61 | #define TB_SE0_SRP (1000) /* b_idle,minimum 1s, section:5.1.2 */ | ||
62 | /* SSEND time before SRP */ | ||
63 | #define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */ | ||
64 | |||
65 | #define TB_SESS_VLD (1000) | ||
66 | |||
67 | enum ci_otg_fsm_timer_index { | ||
68 | /* | ||
69 | * CI specific timers, start from the end | ||
70 | * of standard and auxiliary OTG timers | ||
71 | */ | ||
72 | B_DATA_PLS = NUM_OTG_FSM_TIMERS, | ||
73 | B_SSEND_SRP, | ||
74 | B_SESS_VLD, | ||
75 | |||
76 | NUM_CI_OTG_FSM_TIMERS, | ||
77 | }; | ||
78 | |||
79 | struct ci_otg_fsm_timer { | ||
80 | unsigned long expires; /* Number of count increase to timeout */ | ||
81 | unsigned long count; /* Tick counter */ | ||
82 | void (*function)(void *, unsigned long); /* Timeout function */ | ||
83 | unsigned long data; /* Data passed to function */ | ||
84 | struct list_head list; | ||
85 | }; | ||
86 | |||
87 | struct ci_otg_fsm_timer_list { | ||
88 | struct ci_otg_fsm_timer *timer_list[NUM_CI_OTG_FSM_TIMERS]; | ||
89 | struct list_head active_timers; | ||
90 | }; | ||
91 | |||
92 | #ifdef CONFIG_USB_OTG_FSM | ||
93 | |||
94 | int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci); | ||
95 | int ci_otg_fsm_work(struct ci_hdrc *ci); | ||
96 | irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci); | ||
97 | void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci); | ||
98 | void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci); | ||
99 | |||
100 | #else | ||
101 | |||
102 | static inline int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) | ||
103 | { | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static inline int ci_otg_fsm_work(struct ci_hdrc *ci) | ||
108 | { | ||
109 | return -ENXIO; | ||
110 | } | ||
111 | |||
112 | static inline irqreturn_t ci_otg_fsm_irq(struct ci_hdrc *ci) | ||
113 | { | ||
114 | return IRQ_NONE; | ||
115 | } | ||
116 | |||
117 | static inline void ci_hdrc_otg_fsm_start(struct ci_hdrc *ci) | ||
118 | { | ||
119 | |||
120 | } | ||
121 | |||
122 | static inline void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci) | ||
123 | { | ||
124 | |||
125 | } | ||
126 | |||
127 | #endif | ||
128 | |||
129 | #endif /* __DRIVERS_USB_CHIPIDEA_OTG_FSM_H */ | ||
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 7739c64ef259..69425b3cb6b7 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/pm_runtime.h> | 20 | #include <linux/pm_runtime.h> |
21 | #include <linux/usb/ch9.h> | 21 | #include <linux/usb/ch9.h> |
22 | #include <linux/usb/gadget.h> | 22 | #include <linux/usb/gadget.h> |
23 | #include <linux/usb/otg-fsm.h> | ||
23 | #include <linux/usb/chipidea.h> | 24 | #include <linux/usb/chipidea.h> |
24 | 25 | ||
25 | #include "ci.h" | 26 | #include "ci.h" |
@@ -27,6 +28,7 @@ | |||
27 | #include "bits.h" | 28 | #include "bits.h" |
28 | #include "debug.h" | 29 | #include "debug.h" |
29 | #include "otg.h" | 30 | #include "otg.h" |
31 | #include "otg_fsm.h" | ||
30 | 32 | ||
31 | /* control endpoint description */ | 33 | /* control endpoint description */ |
32 | static const struct usb_endpoint_descriptor | 34 | static const struct usb_endpoint_descriptor |
@@ -242,26 +244,6 @@ static int hw_port_is_high_speed(struct ci_hdrc *ci) | |||
242 | } | 244 | } |
243 | 245 | ||
244 | /** | 246 | /** |
245 | * hw_read_intr_enable: returns interrupt enable register | ||
246 | * | ||
247 | * This function returns register data | ||
248 | */ | ||
249 | static u32 hw_read_intr_enable(struct ci_hdrc *ci) | ||
250 | { | ||
251 | return hw_read(ci, OP_USBINTR, ~0); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * hw_read_intr_status: returns interrupt status register | ||
256 | * | ||
257 | * This function returns register data | ||
258 | */ | ||
259 | static u32 hw_read_intr_status(struct ci_hdrc *ci) | ||
260 | { | ||
261 | return hw_read(ci, OP_USBSTS, ~0); | ||
262 | } | ||
263 | |||
264 | /** | ||
265 | * hw_test_and_clear_complete: test & clear complete status (execute without | 247 | * hw_test_and_clear_complete: test & clear complete status (execute without |
266 | * interruption) | 248 | * interruption) |
267 | * @n: endpoint number | 249 | * @n: endpoint number |
@@ -727,6 +709,8 @@ __acquires(ci->lock) | |||
727 | if (ci->status == NULL) | 709 | if (ci->status == NULL) |
728 | retval = -ENOMEM; | 710 | retval = -ENOMEM; |
729 | 711 | ||
712 | usb_gadget_set_state(&ci->gadget, USB_STATE_DEFAULT); | ||
713 | |||
730 | done: | 714 | done: |
731 | spin_lock(&ci->lock); | 715 | spin_lock(&ci->lock); |
732 | 716 | ||
@@ -841,7 +825,6 @@ __acquires(hwep->lock) | |||
841 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | 825 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { |
842 | /* Assume that device is bus powered for now. */ | 826 | /* Assume that device is bus powered for now. */ |
843 | *(u16 *)req->buf = ci->remote_wakeup << 1; | 827 | *(u16 *)req->buf = ci->remote_wakeup << 1; |
844 | retval = 0; | ||
845 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ | 828 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ |
846 | == USB_RECIP_ENDPOINT) { | 829 | == USB_RECIP_ENDPOINT) { |
847 | dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? | 830 | dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? |
@@ -883,6 +866,8 @@ isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req) | |||
883 | if (ci->setaddr) { | 866 | if (ci->setaddr) { |
884 | hw_usb_set_address(ci, ci->address); | 867 | hw_usb_set_address(ci, ci->address); |
885 | ci->setaddr = false; | 868 | ci->setaddr = false; |
869 | if (ci->address) | ||
870 | usb_gadget_set_state(&ci->gadget, USB_STATE_ADDRESS); | ||
886 | } | 871 | } |
887 | 872 | ||
888 | spin_lock_irqsave(&ci->lock, flags); | 873 | spin_lock_irqsave(&ci->lock, flags); |
@@ -1072,6 +1057,14 @@ __acquires(ci->lock) | |||
1072 | default: | 1057 | default: |
1073 | break; | 1058 | break; |
1074 | } | 1059 | } |
1060 | break; | ||
1061 | case USB_DEVICE_B_HNP_ENABLE: | ||
1062 | if (ci_otg_is_fsm_mode(ci)) { | ||
1063 | ci->gadget.b_hnp_enable = 1; | ||
1064 | err = isr_setup_status_phase( | ||
1065 | ci); | ||
1066 | } | ||
1067 | break; | ||
1075 | default: | 1068 | default: |
1076 | goto delegate; | 1069 | goto delegate; |
1077 | } | 1070 | } |
@@ -1477,7 +1470,7 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
1477 | pm_runtime_get_sync(&_gadget->dev); | 1470 | pm_runtime_get_sync(&_gadget->dev); |
1478 | hw_device_reset(ci, USBMODE_CM_DC); | 1471 | hw_device_reset(ci, USBMODE_CM_DC); |
1479 | hw_device_state(ci, ci->ep0out->qh.dma); | 1472 | hw_device_state(ci, ci->ep0out->qh.dma); |
1480 | dev_dbg(ci->dev, "Connected to host\n"); | 1473 | usb_gadget_set_state(_gadget, USB_STATE_POWERED); |
1481 | } else { | 1474 | } else { |
1482 | if (ci->driver) | 1475 | if (ci->driver) |
1483 | ci->driver->disconnect(&ci->gadget); | 1476 | ci->driver->disconnect(&ci->gadget); |
@@ -1487,7 +1480,7 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
1487 | CI_HDRC_CONTROLLER_STOPPED_EVENT); | 1480 | CI_HDRC_CONTROLLER_STOPPED_EVENT); |
1488 | _gadget_stop_activity(&ci->gadget); | 1481 | _gadget_stop_activity(&ci->gadget); |
1489 | pm_runtime_put_sync(&_gadget->dev); | 1482 | pm_runtime_put_sync(&_gadget->dev); |
1490 | dev_dbg(ci->dev, "Disconnected from host\n"); | 1483 | usb_gadget_set_state(_gadget, USB_STATE_NOTATTACHED); |
1491 | } | 1484 | } |
1492 | } | 1485 | } |
1493 | 1486 | ||
@@ -1655,6 +1648,13 @@ static int ci_udc_start(struct usb_gadget *gadget, | |||
1655 | return retval; | 1648 | return retval; |
1656 | 1649 | ||
1657 | ci->driver = driver; | 1650 | ci->driver = driver; |
1651 | |||
1652 | /* Start otg fsm for B-device */ | ||
1653 | if (ci_otg_is_fsm_mode(ci) && ci->fsm.id) { | ||
1654 | ci_hdrc_otg_fsm_start(ci); | ||
1655 | return retval; | ||
1656 | } | ||
1657 | |||
1658 | pm_runtime_get_sync(&ci->gadget.dev); | 1658 | pm_runtime_get_sync(&ci->gadget.dev); |
1659 | if (ci->vbus_active) { | 1659 | if (ci->vbus_active) { |
1660 | spin_lock_irqsave(&ci->lock, flags); | 1660 | spin_lock_irqsave(&ci->lock, flags); |
@@ -1753,6 +1753,8 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) | |||
1753 | ci->suspended = 1; | 1753 | ci->suspended = 1; |
1754 | spin_unlock(&ci->lock); | 1754 | spin_unlock(&ci->lock); |
1755 | ci->driver->suspend(&ci->gadget); | 1755 | ci->driver->suspend(&ci->gadget); |
1756 | usb_gadget_set_state(&ci->gadget, | ||
1757 | USB_STATE_SUSPENDED); | ||
1756 | spin_lock(&ci->lock); | 1758 | spin_lock(&ci->lock); |
1757 | } | 1759 | } |
1758 | } | 1760 | } |
@@ -1779,7 +1781,7 @@ static int udc_start(struct ci_hdrc *ci) | |||
1779 | ci->gadget.ops = &usb_gadget_ops; | 1781 | ci->gadget.ops = &usb_gadget_ops; |
1780 | ci->gadget.speed = USB_SPEED_UNKNOWN; | 1782 | ci->gadget.speed = USB_SPEED_UNKNOWN; |
1781 | ci->gadget.max_speed = USB_SPEED_HIGH; | 1783 | ci->gadget.max_speed = USB_SPEED_HIGH; |
1782 | ci->gadget.is_otg = 0; | 1784 | ci->gadget.is_otg = ci->is_otg ? 1 : 0; |
1783 | ci->gadget.name = ci->platdata->name; | 1785 | ci->gadget.name = ci->platdata->name; |
1784 | 1786 | ||
1785 | INIT_LIST_HEAD(&ci->gadget.ep_list); | 1787 | INIT_LIST_HEAD(&ci->gadget.ep_list); |
@@ -1843,21 +1845,22 @@ void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) | |||
1843 | 1845 | ||
1844 | static int udc_id_switch_for_device(struct ci_hdrc *ci) | 1846 | static int udc_id_switch_for_device(struct ci_hdrc *ci) |
1845 | { | 1847 | { |
1846 | if (ci->is_otg) { | 1848 | if (ci->is_otg) |
1847 | ci_clear_otg_interrupt(ci, OTGSC_BSVIS); | 1849 | /* Clear and enable BSV irq */ |
1848 | ci_enable_otg_interrupt(ci, OTGSC_BSVIE); | 1850 | hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, |
1849 | } | 1851 | OTGSC_BSVIS | OTGSC_BSVIE); |
1850 | 1852 | ||
1851 | return 0; | 1853 | return 0; |
1852 | } | 1854 | } |
1853 | 1855 | ||
1854 | static void udc_id_switch_for_host(struct ci_hdrc *ci) | 1856 | static void udc_id_switch_for_host(struct ci_hdrc *ci) |
1855 | { | 1857 | { |
1856 | if (ci->is_otg) { | 1858 | /* |
1857 | /* host doesn't care B_SESSION_VALID event */ | 1859 | * host doesn't care B_SESSION_VALID event |
1858 | ci_clear_otg_interrupt(ci, OTGSC_BSVIS); | 1860 | * so clear and disbale BSV irq |
1859 | ci_disable_otg_interrupt(ci, OTGSC_BSVIE); | 1861 | */ |
1860 | } | 1862 | if (ci->is_otg) |
1863 | hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); | ||
1861 | } | 1864 | } |
1862 | 1865 | ||
1863 | /** | 1866 | /** |
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c index cd061abe3507..85293b8b1df9 100644 --- a/drivers/usb/chipidea/usbmisc_imx.c +++ b/drivers/usb/chipidea/usbmisc_imx.c | |||
@@ -21,16 +21,39 @@ | |||
21 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 | 21 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 |
22 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) | 22 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) |
23 | 23 | ||
24 | #define MX25_EHCI_INTERFACE_SINGLE_UNI (2 << 0) | ||
25 | #define MX25_EHCI_INTERFACE_DIFF_UNI (0 << 0) | ||
26 | #define MX25_EHCI_INTERFACE_MASK (0xf) | ||
27 | |||
28 | #define MX25_OTG_SIC_SHIFT 29 | ||
29 | #define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT) | ||
30 | #define MX25_OTG_PM_BIT BIT(24) | ||
31 | #define MX25_OTG_PP_BIT BIT(11) | ||
32 | #define MX25_OTG_OCPOL_BIT BIT(3) | ||
33 | |||
34 | #define MX25_H1_SIC_SHIFT 21 | ||
35 | #define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT) | ||
36 | #define MX25_H1_PP_BIT BIT(18) | ||
37 | #define MX25_H1_PM_BIT BIT(16) | ||
38 | #define MX25_H1_IPPUE_UP_BIT BIT(7) | ||
39 | #define MX25_H1_IPPUE_DOWN_BIT BIT(6) | ||
40 | #define MX25_H1_TLL_BIT BIT(5) | ||
41 | #define MX25_H1_USBTE_BIT BIT(4) | ||
42 | #define MX25_H1_OCPOL_BIT BIT(2) | ||
43 | |||
24 | #define MX27_H1_PM_BIT BIT(8) | 44 | #define MX27_H1_PM_BIT BIT(8) |
25 | #define MX27_H2_PM_BIT BIT(16) | 45 | #define MX27_H2_PM_BIT BIT(16) |
26 | #define MX27_OTG_PM_BIT BIT(24) | 46 | #define MX27_OTG_PM_BIT BIT(24) |
27 | 47 | ||
28 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 | 48 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 |
49 | #define MX53_USB_OTG_PHY_CTRL_1_OFFSET 0x0c | ||
29 | #define MX53_USB_UH2_CTRL_OFFSET 0x14 | 50 | #define MX53_USB_UH2_CTRL_OFFSET 0x14 |
30 | #define MX53_USB_UH3_CTRL_OFFSET 0x18 | 51 | #define MX53_USB_UH3_CTRL_OFFSET 0x18 |
31 | #define MX53_BM_OVER_CUR_DIS_H1 BIT(5) | 52 | #define MX53_BM_OVER_CUR_DIS_H1 BIT(5) |
32 | #define MX53_BM_OVER_CUR_DIS_OTG BIT(8) | 53 | #define MX53_BM_OVER_CUR_DIS_OTG BIT(8) |
33 | #define MX53_BM_OVER_CUR_DIS_UHx BIT(30) | 54 | #define MX53_BM_OVER_CUR_DIS_UHx BIT(30) |
55 | #define MX53_USB_PHYCTRL1_PLLDIV_MASK 0x3 | ||
56 | #define MX53_USB_PLL_DIV_24_MHZ 0x01 | ||
34 | 57 | ||
35 | #define MX6_BM_OVER_CUR_DIS BIT(7) | 58 | #define MX6_BM_OVER_CUR_DIS BIT(7) |
36 | 59 | ||
@@ -50,6 +73,39 @@ struct imx_usbmisc { | |||
50 | 73 | ||
51 | static struct imx_usbmisc *usbmisc; | 74 | static struct imx_usbmisc *usbmisc; |
52 | 75 | ||
76 | static int usbmisc_imx25_init(struct imx_usbmisc_data *data) | ||
77 | { | ||
78 | unsigned long flags; | ||
79 | u32 val = 0; | ||
80 | |||
81 | if (data->index > 1) | ||
82 | return -EINVAL; | ||
83 | |||
84 | spin_lock_irqsave(&usbmisc->lock, flags); | ||
85 | switch (data->index) { | ||
86 | case 0: | ||
87 | val = readl(usbmisc->base); | ||
88 | val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT); | ||
89 | val |= (MX25_EHCI_INTERFACE_DIFF_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT; | ||
90 | val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT); | ||
91 | writel(val, usbmisc->base); | ||
92 | break; | ||
93 | case 1: | ||
94 | val = readl(usbmisc->base); | ||
95 | val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT); | ||
96 | val |= (MX25_EHCI_INTERFACE_SINGLE_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT; | ||
97 | val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | | ||
98 | MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); | ||
99 | |||
100 | writel(val, usbmisc->base); | ||
101 | |||
102 | break; | ||
103 | } | ||
104 | spin_unlock_irqrestore(&usbmisc->lock, flags); | ||
105 | |||
106 | return 0; | ||
107 | } | ||
108 | |||
53 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) | 109 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) |
54 | { | 110 | { |
55 | void __iomem *reg; | 111 | void __iomem *reg; |
@@ -111,6 +167,13 @@ static int usbmisc_imx53_init(struct imx_usbmisc_data *data) | |||
111 | if (data->index > 3) | 167 | if (data->index > 3) |
112 | return -EINVAL; | 168 | return -EINVAL; |
113 | 169 | ||
170 | /* Select a 24 MHz reference clock for the PHY */ | ||
171 | reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET; | ||
172 | val = readl(reg); | ||
173 | val &= ~MX53_USB_PHYCTRL1_PLLDIV_MASK; | ||
174 | val |= MX53_USB_PLL_DIV_24_MHZ; | ||
175 | writel(val, usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); | ||
176 | |||
114 | if (data->disable_oc) { | 177 | if (data->disable_oc) { |
115 | spin_lock_irqsave(&usbmisc->lock, flags); | 178 | spin_lock_irqsave(&usbmisc->lock, flags); |
116 | switch (data->index) { | 179 | switch (data->index) { |
@@ -159,6 +222,7 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) | |||
159 | } | 222 | } |
160 | 223 | ||
161 | static const struct usbmisc_ops imx25_usbmisc_ops = { | 224 | static const struct usbmisc_ops imx25_usbmisc_ops = { |
225 | .init = usbmisc_imx25_init, | ||
162 | .post = usbmisc_imx25_post, | 226 | .post = usbmisc_imx25_post, |
163 | }; | 227 | }; |
164 | 228 | ||
@@ -200,6 +264,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = { | |||
200 | .data = &imx25_usbmisc_ops, | 264 | .data = &imx25_usbmisc_ops, |
201 | }, | 265 | }, |
202 | { | 266 | { |
267 | .compatible = "fsl,imx35-usbmisc", | ||
268 | .data = &imx25_usbmisc_ops, | ||
269 | }, | ||
270 | { | ||
203 | .compatible = "fsl,imx27-usbmisc", | 271 | .compatible = "fsl,imx27-usbmisc", |
204 | .data = &imx27_usbmisc_ops, | 272 | .data = &imx27_usbmisc_ops, |
205 | }, | 273 | }, |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 904efb6035b0..e934e19f49f5 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -122,13 +122,23 @@ static void acm_release_minor(struct acm *acm) | |||
122 | static int acm_ctrl_msg(struct acm *acm, int request, int value, | 122 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
123 | void *buf, int len) | 123 | void *buf, int len) |
124 | { | 124 | { |
125 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | 125 | int retval; |
126 | |||
127 | retval = usb_autopm_get_interface(acm->control); | ||
128 | if (retval) | ||
129 | return retval; | ||
130 | |||
131 | retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | ||
126 | request, USB_RT_ACM, value, | 132 | request, USB_RT_ACM, value, |
127 | acm->control->altsetting[0].desc.bInterfaceNumber, | 133 | acm->control->altsetting[0].desc.bInterfaceNumber, |
128 | buf, len, 5000); | 134 | buf, len, 5000); |
135 | |||
129 | dev_dbg(&acm->control->dev, | 136 | dev_dbg(&acm->control->dev, |
130 | "%s - rq 0x%02x, val %#x, len %#x, result %d\n", | 137 | "%s - rq 0x%02x, val %#x, len %#x, result %d\n", |
131 | __func__, request, value, len, retval); | 138 | __func__, request, value, len, retval); |
139 | |||
140 | usb_autopm_put_interface(acm->control); | ||
141 | |||
132 | return retval < 0 ? retval : 0; | 142 | return retval < 0 ? retval : 0; |
133 | } | 143 | } |
134 | 144 | ||
@@ -406,19 +416,21 @@ static void acm_read_bulk_callback(struct urb *urb) | |||
406 | dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); | 416 | dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); |
407 | return; | 417 | return; |
408 | } | 418 | } |
409 | usb_mark_last_busy(acm->dev); | ||
410 | 419 | ||
411 | if (urb->status) { | 420 | if (urb->status) { |
412 | dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", | 421 | dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n", |
413 | __func__, urb->status); | 422 | __func__, urb->status); |
414 | return; | 423 | return; |
415 | } | 424 | } |
425 | |||
426 | usb_mark_last_busy(acm->dev); | ||
427 | |||
416 | acm_process_read_urb(acm, urb); | 428 | acm_process_read_urb(acm, urb); |
417 | 429 | ||
418 | /* throttle device if requested by tty */ | 430 | /* throttle device if requested by tty */ |
419 | spin_lock_irqsave(&acm->read_lock, flags); | 431 | spin_lock_irqsave(&acm->read_lock, flags); |
420 | acm->throttled = acm->throttle_req; | 432 | acm->throttled = acm->throttle_req; |
421 | if (!acm->throttled && !acm->susp_count) { | 433 | if (!acm->throttled) { |
422 | spin_unlock_irqrestore(&acm->read_lock, flags); | 434 | spin_unlock_irqrestore(&acm->read_lock, flags); |
423 | acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); | 435 | acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); |
424 | } else { | 436 | } else { |
@@ -492,10 +504,30 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
492 | return tty_port_open(&acm->port, tty, filp); | 504 | return tty_port_open(&acm->port, tty, filp); |
493 | } | 505 | } |
494 | 506 | ||
507 | static void acm_port_dtr_rts(struct tty_port *port, int raise) | ||
508 | { | ||
509 | struct acm *acm = container_of(port, struct acm, port); | ||
510 | int val; | ||
511 | int res; | ||
512 | |||
513 | if (raise) | ||
514 | val = ACM_CTRL_DTR | ACM_CTRL_RTS; | ||
515 | else | ||
516 | val = 0; | ||
517 | |||
518 | /* FIXME: add missing ctrlout locking throughout driver */ | ||
519 | acm->ctrlout = val; | ||
520 | |||
521 | res = acm_set_control(acm, val); | ||
522 | if (res && (acm->ctrl_caps & USB_CDC_CAP_LINE)) | ||
523 | dev_err(&acm->control->dev, "failed to set dtr/rts\n"); | ||
524 | } | ||
525 | |||
495 | static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) | 526 | static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) |
496 | { | 527 | { |
497 | struct acm *acm = container_of(port, struct acm, port); | 528 | struct acm *acm = container_of(port, struct acm, port); |
498 | int retval = -ENODEV; | 529 | int retval = -ENODEV; |
530 | int i; | ||
499 | 531 | ||
500 | dev_dbg(&acm->control->dev, "%s\n", __func__); | 532 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
501 | 533 | ||
@@ -515,22 +547,13 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) | |||
515 | acm->control->needs_remote_wakeup = 1; | 547 | acm->control->needs_remote_wakeup = 1; |
516 | 548 | ||
517 | acm->ctrlurb->dev = acm->dev; | 549 | acm->ctrlurb->dev = acm->dev; |
518 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | 550 | retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL); |
551 | if (retval) { | ||
519 | dev_err(&acm->control->dev, | 552 | dev_err(&acm->control->dev, |
520 | "%s - usb_submit_urb(ctrl irq) failed\n", __func__); | 553 | "%s - usb_submit_urb(ctrl irq) failed\n", __func__); |
521 | usb_autopm_put_interface(acm->control); | ||
522 | goto error_submit_urb; | 554 | goto error_submit_urb; |
523 | } | 555 | } |
524 | 556 | ||
525 | acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS; | ||
526 | if (acm_set_control(acm, acm->ctrlout) < 0 && | ||
527 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) { | ||
528 | usb_autopm_put_interface(acm->control); | ||
529 | goto error_set_control; | ||
530 | } | ||
531 | |||
532 | usb_autopm_put_interface(acm->control); | ||
533 | |||
534 | /* | 557 | /* |
535 | * Unthrottle device in case the TTY was closed while throttled. | 558 | * Unthrottle device in case the TTY was closed while throttled. |
536 | */ | 559 | */ |
@@ -539,23 +562,27 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty) | |||
539 | acm->throttle_req = 0; | 562 | acm->throttle_req = 0; |
540 | spin_unlock_irq(&acm->read_lock); | 563 | spin_unlock_irq(&acm->read_lock); |
541 | 564 | ||
542 | if (acm_submit_read_urbs(acm, GFP_KERNEL)) | 565 | retval = acm_submit_read_urbs(acm, GFP_KERNEL); |
566 | if (retval) | ||
543 | goto error_submit_read_urbs; | 567 | goto error_submit_read_urbs; |
544 | 568 | ||
569 | usb_autopm_put_interface(acm->control); | ||
570 | |||
545 | mutex_unlock(&acm->mutex); | 571 | mutex_unlock(&acm->mutex); |
546 | 572 | ||
547 | return 0; | 573 | return 0; |
548 | 574 | ||
549 | error_submit_read_urbs: | 575 | error_submit_read_urbs: |
550 | acm->ctrlout = 0; | 576 | for (i = 0; i < acm->rx_buflimit; i++) |
551 | acm_set_control(acm, acm->ctrlout); | 577 | usb_kill_urb(acm->read_urbs[i]); |
552 | error_set_control: | ||
553 | usb_kill_urb(acm->ctrlurb); | 578 | usb_kill_urb(acm->ctrlurb); |
554 | error_submit_urb: | 579 | error_submit_urb: |
580 | usb_autopm_put_interface(acm->control); | ||
555 | error_get_interface: | 581 | error_get_interface: |
556 | disconnected: | 582 | disconnected: |
557 | mutex_unlock(&acm->mutex); | 583 | mutex_unlock(&acm->mutex); |
558 | return retval; | 584 | |
585 | return usb_translate_errors(retval); | ||
559 | } | 586 | } |
560 | 587 | ||
561 | static void acm_port_destruct(struct tty_port *port) | 588 | static void acm_port_destruct(struct tty_port *port) |
@@ -573,23 +600,37 @@ static void acm_port_destruct(struct tty_port *port) | |||
573 | static void acm_port_shutdown(struct tty_port *port) | 600 | static void acm_port_shutdown(struct tty_port *port) |
574 | { | 601 | { |
575 | struct acm *acm = container_of(port, struct acm, port); | 602 | struct acm *acm = container_of(port, struct acm, port); |
603 | struct urb *urb; | ||
604 | struct acm_wb *wb; | ||
576 | int i; | 605 | int i; |
577 | 606 | ||
578 | dev_dbg(&acm->control->dev, "%s\n", __func__); | 607 | dev_dbg(&acm->control->dev, "%s\n", __func__); |
579 | 608 | ||
580 | mutex_lock(&acm->mutex); | 609 | /* |
581 | if (!acm->disconnected) { | 610 | * Need to grab write_lock to prevent race with resume, but no need to |
582 | usb_autopm_get_interface(acm->control); | 611 | * hold it due to the tty-port initialised flag. |
583 | acm_set_control(acm, acm->ctrlout = 0); | 612 | */ |
584 | usb_kill_urb(acm->ctrlurb); | 613 | spin_lock_irq(&acm->write_lock); |
585 | for (i = 0; i < ACM_NW; i++) | 614 | spin_unlock_irq(&acm->write_lock); |
586 | usb_kill_urb(acm->wb[i].urb); | 615 | |
587 | for (i = 0; i < acm->rx_buflimit; i++) | 616 | usb_autopm_get_interface_no_resume(acm->control); |
588 | usb_kill_urb(acm->read_urbs[i]); | 617 | acm->control->needs_remote_wakeup = 0; |
589 | acm->control->needs_remote_wakeup = 0; | 618 | usb_autopm_put_interface(acm->control); |
590 | usb_autopm_put_interface(acm->control); | 619 | |
620 | for (;;) { | ||
621 | urb = usb_get_from_anchor(&acm->delayed); | ||
622 | if (!urb) | ||
623 | break; | ||
624 | wb = urb->context; | ||
625 | wb->use = 0; | ||
626 | usb_autopm_put_interface_async(acm->control); | ||
591 | } | 627 | } |
592 | mutex_unlock(&acm->mutex); | 628 | |
629 | usb_kill_urb(acm->ctrlurb); | ||
630 | for (i = 0; i < ACM_NW; i++) | ||
631 | usb_kill_urb(acm->wb[i].urb); | ||
632 | for (i = 0; i < acm->rx_buflimit; i++) | ||
633 | usb_kill_urb(acm->read_urbs[i]); | ||
593 | } | 634 | } |
594 | 635 | ||
595 | static void acm_tty_cleanup(struct tty_struct *tty) | 636 | static void acm_tty_cleanup(struct tty_struct *tty) |
@@ -646,16 +687,18 @@ static int acm_tty_write(struct tty_struct *tty, | |||
646 | memcpy(wb->buf, buf, count); | 687 | memcpy(wb->buf, buf, count); |
647 | wb->len = count; | 688 | wb->len = count; |
648 | 689 | ||
649 | usb_autopm_get_interface_async(acm->control); | 690 | stat = usb_autopm_get_interface_async(acm->control); |
691 | if (stat) { | ||
692 | wb->use = 0; | ||
693 | spin_unlock_irqrestore(&acm->write_lock, flags); | ||
694 | return stat; | ||
695 | } | ||
696 | |||
650 | if (acm->susp_count) { | 697 | if (acm->susp_count) { |
651 | if (!acm->delayed_wb) | 698 | usb_anchor_urb(wb->urb, &acm->delayed); |
652 | acm->delayed_wb = wb; | ||
653 | else | ||
654 | usb_autopm_put_interface_async(acm->control); | ||
655 | spin_unlock_irqrestore(&acm->write_lock, flags); | 699 | spin_unlock_irqrestore(&acm->write_lock, flags); |
656 | return count; /* A white lie */ | 700 | return count; |
657 | } | 701 | } |
658 | usb_mark_last_busy(acm->dev); | ||
659 | 702 | ||
660 | stat = acm_start_wb(acm, wb); | 703 | stat = acm_start_wb(acm, wb); |
661 | spin_unlock_irqrestore(&acm->write_lock, flags); | 704 | spin_unlock_irqrestore(&acm->write_lock, flags); |
@@ -958,6 +1001,7 @@ static void acm_tty_set_termios(struct tty_struct *tty, | |||
958 | } | 1001 | } |
959 | 1002 | ||
960 | static const struct tty_port_operations acm_port_ops = { | 1003 | static const struct tty_port_operations acm_port_ops = { |
1004 | .dtr_rts = acm_port_dtr_rts, | ||
961 | .shutdown = acm_port_shutdown, | 1005 | .shutdown = acm_port_shutdown, |
962 | .activate = acm_port_activate, | 1006 | .activate = acm_port_activate, |
963 | .destruct = acm_port_destruct, | 1007 | .destruct = acm_port_destruct, |
@@ -1269,6 +1313,7 @@ made_compressed_probe: | |||
1269 | acm->bInterval = epread->bInterval; | 1313 | acm->bInterval = epread->bInterval; |
1270 | tty_port_init(&acm->port); | 1314 | tty_port_init(&acm->port); |
1271 | acm->port.ops = &acm_port_ops; | 1315 | acm->port.ops = &acm_port_ops; |
1316 | init_usb_anchor(&acm->delayed); | ||
1272 | 1317 | ||
1273 | buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 1318 | buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1274 | if (!buf) { | 1319 | if (!buf) { |
@@ -1394,8 +1439,6 @@ skip_countries: | |||
1394 | 1439 | ||
1395 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); | 1440 | dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); |
1396 | 1441 | ||
1397 | acm_set_control(acm, acm->ctrlout); | ||
1398 | |||
1399 | acm->line.dwDTERate = cpu_to_le32(9600); | 1442 | acm->line.dwDTERate = cpu_to_le32(9600); |
1400 | acm->line.bDataBits = 8; | 1443 | acm->line.bDataBits = 8; |
1401 | acm_set_line(acm, &acm->line); | 1444 | acm_set_line(acm, &acm->line); |
@@ -1514,27 +1557,20 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1514 | struct acm *acm = usb_get_intfdata(intf); | 1557 | struct acm *acm = usb_get_intfdata(intf); |
1515 | int cnt; | 1558 | int cnt; |
1516 | 1559 | ||
1560 | spin_lock_irq(&acm->write_lock); | ||
1517 | if (PMSG_IS_AUTO(message)) { | 1561 | if (PMSG_IS_AUTO(message)) { |
1518 | int b; | 1562 | if (acm->transmitting) { |
1519 | 1563 | spin_unlock_irq(&acm->write_lock); | |
1520 | spin_lock_irq(&acm->write_lock); | ||
1521 | b = acm->transmitting; | ||
1522 | spin_unlock_irq(&acm->write_lock); | ||
1523 | if (b) | ||
1524 | return -EBUSY; | 1564 | return -EBUSY; |
1565 | } | ||
1525 | } | 1566 | } |
1526 | |||
1527 | spin_lock_irq(&acm->read_lock); | ||
1528 | spin_lock(&acm->write_lock); | ||
1529 | cnt = acm->susp_count++; | 1567 | cnt = acm->susp_count++; |
1530 | spin_unlock(&acm->write_lock); | 1568 | spin_unlock_irq(&acm->write_lock); |
1531 | spin_unlock_irq(&acm->read_lock); | ||
1532 | 1569 | ||
1533 | if (cnt) | 1570 | if (cnt) |
1534 | return 0; | 1571 | return 0; |
1535 | 1572 | ||
1536 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) | 1573 | stop_data_traffic(acm); |
1537 | stop_data_traffic(acm); | ||
1538 | 1574 | ||
1539 | return 0; | 1575 | return 0; |
1540 | } | 1576 | } |
@@ -1542,29 +1578,23 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1542 | static int acm_resume(struct usb_interface *intf) | 1578 | static int acm_resume(struct usb_interface *intf) |
1543 | { | 1579 | { |
1544 | struct acm *acm = usb_get_intfdata(intf); | 1580 | struct acm *acm = usb_get_intfdata(intf); |
1545 | struct acm_wb *wb; | 1581 | struct urb *urb; |
1546 | int rv = 0; | 1582 | int rv = 0; |
1547 | int cnt; | ||
1548 | 1583 | ||
1549 | spin_lock_irq(&acm->read_lock); | 1584 | spin_lock_irq(&acm->write_lock); |
1550 | acm->susp_count -= 1; | ||
1551 | cnt = acm->susp_count; | ||
1552 | spin_unlock_irq(&acm->read_lock); | ||
1553 | 1585 | ||
1554 | if (cnt) | 1586 | if (--acm->susp_count) |
1555 | return 0; | 1587 | goto out; |
1556 | 1588 | ||
1557 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { | 1589 | if (test_bit(ASYNCB_INITIALIZED, &acm->port.flags)) { |
1558 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 1590 | rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); |
1559 | 1591 | ||
1560 | spin_lock_irq(&acm->write_lock); | 1592 | for (;;) { |
1561 | if (acm->delayed_wb) { | 1593 | urb = usb_get_from_anchor(&acm->delayed); |
1562 | wb = acm->delayed_wb; | 1594 | if (!urb) |
1563 | acm->delayed_wb = NULL; | 1595 | break; |
1564 | spin_unlock_irq(&acm->write_lock); | 1596 | |
1565 | acm_start_wb(acm, wb); | 1597 | acm_start_wb(acm, urb->context); |
1566 | } else { | ||
1567 | spin_unlock_irq(&acm->write_lock); | ||
1568 | } | 1598 | } |
1569 | 1599 | ||
1570 | /* | 1600 | /* |
@@ -1572,12 +1602,13 @@ static int acm_resume(struct usb_interface *intf) | |||
1572 | * do the write path at all cost | 1602 | * do the write path at all cost |
1573 | */ | 1603 | */ |
1574 | if (rv < 0) | 1604 | if (rv < 0) |
1575 | goto err_out; | 1605 | goto out; |
1576 | 1606 | ||
1577 | rv = acm_submit_read_urbs(acm, GFP_NOIO); | 1607 | rv = acm_submit_read_urbs(acm, GFP_ATOMIC); |
1578 | } | 1608 | } |
1609 | out: | ||
1610 | spin_unlock_irq(&acm->write_lock); | ||
1579 | 1611 | ||
1580 | err_out: | ||
1581 | return rv; | 1612 | return rv; |
1582 | } | 1613 | } |
1583 | 1614 | ||
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index e38dc785808f..fc75651afe1c 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -120,15 +120,15 @@ struct acm { | |||
120 | unsigned int throttled:1; /* actually throttled */ | 120 | unsigned int throttled:1; /* actually throttled */ |
121 | unsigned int throttle_req:1; /* throttle requested */ | 121 | unsigned int throttle_req:1; /* throttle requested */ |
122 | u8 bInterval; | 122 | u8 bInterval; |
123 | struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ | 123 | struct usb_anchor delayed; /* writes queued for a device about to be woken */ |
124 | }; | 124 | }; |
125 | 125 | ||
126 | #define CDC_DATA_INTERFACE_TYPE 0x0a | 126 | #define CDC_DATA_INTERFACE_TYPE 0x0a |
127 | 127 | ||
128 | /* constants describing various quirks and errors */ | 128 | /* constants describing various quirks and errors */ |
129 | #define NO_UNION_NORMAL 1 | 129 | #define NO_UNION_NORMAL BIT(0) |
130 | #define SINGLE_RX_URB 2 | 130 | #define SINGLE_RX_URB BIT(1) |
131 | #define NO_CAP_LINE 4 | 131 | #define NO_CAP_LINE BIT(2) |
132 | #define NOT_A_MODEM 8 | 132 | #define NOT_A_MODEM BIT(3) |
133 | #define NO_DATA_INTERFACE 16 | 133 | #define NO_DATA_INTERFACE BIT(4) |
134 | #define IGNORE_DEVICE 32 | 134 | #define IGNORE_DEVICE BIT(5) |
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index cfbec9c7e09e..103a6e9ee49d 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -383,9 +383,12 @@ exit: | |||
383 | static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t transfer_size) | 383 | static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t transfer_size) |
384 | { | 384 | { |
385 | int retval; | 385 | int retval; |
386 | u8 buffer[USBTMC_HEADER_SIZE]; | 386 | u8 *buffer; |
387 | int actual; | 387 | int actual; |
388 | 388 | ||
389 | buffer = kmalloc(USBTMC_HEADER_SIZE, GFP_KERNEL); | ||
390 | if (!buffer) | ||
391 | return -ENOMEM; | ||
389 | /* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message | 392 | /* Setup IO buffer for REQUEST_DEV_DEP_MSG_IN message |
390 | * Refer to class specs for details | 393 | * Refer to class specs for details |
391 | */ | 394 | */ |
@@ -417,6 +420,7 @@ static int send_request_dev_dep_msg_in(struct usbtmc_device_data *data, size_t t | |||
417 | if (!data->bTag) | 420 | if (!data->bTag) |
418 | data->bTag++; | 421 | data->bTag++; |
419 | 422 | ||
423 | kfree(buffer); | ||
420 | if (retval < 0) { | 424 | if (retval < 0) { |
421 | dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval); | 425 | dev_err(&data->intf->dev, "usb_bulk_msg in send_request_dev_dep_msg_in() returned %d\n", retval); |
422 | return retval; | 426 | return retval; |
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile new file mode 100644 index 000000000000..752646167e1e --- /dev/null +++ b/drivers/usb/common/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | # | ||
2 | # Makefile for the usb common parts. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_USB_COMMON) += usb-common.o | ||
6 | obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o | ||
diff --git a/drivers/usb/usb-common.c b/drivers/usb/common/usb-common.c index 6dfd30a863c7..6dfd30a863c7 100644 --- a/drivers/usb/usb-common.c +++ b/drivers/usb/common/usb-common.c | |||
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/common/usb-otg-fsm.c index d03fadd2629f..98e8340a5bb1 100644 --- a/drivers/usb/phy/phy-fsm-usb.c +++ b/drivers/usb/common/usb-otg-fsm.c | |||
@@ -364,3 +364,4 @@ int otg_statemachine(struct otg_fsm *fsm) | |||
364 | VDBG("quit statemachine, changed = %d\n", state_changed); | 364 | VDBG("quit statemachine, changed = %d\n", state_changed); |
365 | return state_changed; | 365 | return state_changed; |
366 | } | 366 | } |
367 | EXPORT_SYMBOL_GPL(otg_statemachine); | ||
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index cb8e99156f5a..1060657ca1b0 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig | |||
@@ -1,13 +1,6 @@ | |||
1 | # | 1 | # |
2 | # USB Core configuration | 2 | # USB Core configuration |
3 | # | 3 | # |
4 | config USB_DEBUG | ||
5 | bool "USB verbose debug messages" | ||
6 | help | ||
7 | Say Y here if you want the USB core & hub drivers to produce a bunch | ||
8 | of debug messages to the system log. Select this if you are having a | ||
9 | problem with USB support and want to see more of what is going on. | ||
10 | |||
11 | config USB_ANNOUNCE_NEW_DEVICES | 4 | config USB_ANNOUNCE_NEW_DEVICES |
12 | bool "USB announce new devices" | 5 | bool "USB announce new devices" |
13 | help | 6 | help |
@@ -88,3 +81,12 @@ config USB_OTG_BLACKLIST_HUB | |||
88 | and software costs by not supporting external hubs. So | 81 | and software costs by not supporting external hubs. So |
89 | are "Embedded Hosts" that don't offer OTG support. | 82 | are "Embedded Hosts" that don't offer OTG support. |
90 | 83 | ||
84 | config USB_OTG_FSM | ||
85 | tristate "USB 2.0 OTG FSM implementation" | ||
86 | depends on USB | ||
87 | select USB_OTG | ||
88 | select USB_PHY | ||
89 | help | ||
90 | Implements OTG Finite State Machine as specified in On-The-Go | ||
91 | and Embedded Host Supplement to the USB Revision 2.0 Specification. | ||
92 | |||
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 1f02e65fe305..82044b5d6113 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -192,7 +192,6 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
192 | 192 | ||
193 | if (pci_enable_device(dev) < 0) | 193 | if (pci_enable_device(dev) < 0) |
194 | return -ENODEV; | 194 | return -ENODEV; |
195 | dev->current_state = PCI_D0; | ||
196 | 195 | ||
197 | /* | 196 | /* |
198 | * The xHCI driver has its own irq management | 197 | * The xHCI driver has its own irq management |
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 9c4e2922b04d..bec31e2efb88 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -918,6 +918,7 @@ static void usb_bus_init (struct usb_bus *bus) | |||
918 | bus->bandwidth_allocated = 0; | 918 | bus->bandwidth_allocated = 0; |
919 | bus->bandwidth_int_reqs = 0; | 919 | bus->bandwidth_int_reqs = 0; |
920 | bus->bandwidth_isoc_reqs = 0; | 920 | bus->bandwidth_isoc_reqs = 0; |
921 | mutex_init(&bus->usb_address0_mutex); | ||
921 | 922 | ||
922 | INIT_LIST_HEAD (&bus->bus_list); | 923 | INIT_LIST_HEAD (&bus->bus_list); |
923 | } | 924 | } |
@@ -1502,6 +1503,9 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1502 | ret = -EAGAIN; | 1503 | ret = -EAGAIN; |
1503 | else | 1504 | else |
1504 | urb->transfer_flags |= URB_DMA_MAP_PAGE; | 1505 | urb->transfer_flags |= URB_DMA_MAP_PAGE; |
1506 | } else if (is_vmalloc_addr(urb->transfer_buffer)) { | ||
1507 | WARN_ONCE(1, "transfer buffer not dma capable\n"); | ||
1508 | ret = -EAGAIN; | ||
1505 | } else { | 1509 | } else { |
1506 | urb->transfer_dma = dma_map_single( | 1510 | urb->transfer_dma = dma_map_single( |
1507 | hcd->self.controller, | 1511 | hcd->self.controller, |
@@ -2263,9 +2267,7 @@ static void hcd_resume_work(struct work_struct *work) | |||
2263 | struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); | 2267 | struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work); |
2264 | struct usb_device *udev = hcd->self.root_hub; | 2268 | struct usb_device *udev = hcd->self.root_hub; |
2265 | 2269 | ||
2266 | usb_lock_device(udev); | ||
2267 | usb_remote_wakeup(udev); | 2270 | usb_remote_wakeup(udev); |
2268 | usb_unlock_device(udev); | ||
2269 | } | 2271 | } |
2270 | 2272 | ||
2271 | /** | 2273 | /** |
@@ -2454,11 +2456,13 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, | |||
2454 | mutex_init(hcd->bandwidth_mutex); | 2456 | mutex_init(hcd->bandwidth_mutex); |
2455 | dev_set_drvdata(dev, hcd); | 2457 | dev_set_drvdata(dev, hcd); |
2456 | } else { | 2458 | } else { |
2459 | mutex_lock(&usb_port_peer_mutex); | ||
2457 | hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; | 2460 | hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; |
2458 | hcd->primary_hcd = primary_hcd; | 2461 | hcd->primary_hcd = primary_hcd; |
2459 | primary_hcd->primary_hcd = primary_hcd; | 2462 | primary_hcd->primary_hcd = primary_hcd; |
2460 | hcd->shared_hcd = primary_hcd; | 2463 | hcd->shared_hcd = primary_hcd; |
2461 | primary_hcd->shared_hcd = hcd; | 2464 | primary_hcd->shared_hcd = hcd; |
2465 | mutex_unlock(&usb_port_peer_mutex); | ||
2462 | } | 2466 | } |
2463 | 2467 | ||
2464 | kref_init(&hcd->kref); | 2468 | kref_init(&hcd->kref); |
@@ -2510,18 +2514,25 @@ EXPORT_SYMBOL_GPL(usb_create_hcd); | |||
2510 | * deallocated. | 2514 | * deallocated. |
2511 | * | 2515 | * |
2512 | * Make sure to only deallocate the bandwidth_mutex when the primary HCD is | 2516 | * Make sure to only deallocate the bandwidth_mutex when the primary HCD is |
2513 | * freed. When hcd_release() is called for the non-primary HCD, set the | 2517 | * freed. When hcd_release() is called for either hcd in a peer set |
2514 | * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be | 2518 | * invalidate the peer's ->shared_hcd and ->primary_hcd pointers to |
2515 | * freed shortly). | 2519 | * block new peering attempts |
2516 | */ | 2520 | */ |
2517 | static void hcd_release (struct kref *kref) | 2521 | static void hcd_release(struct kref *kref) |
2518 | { | 2522 | { |
2519 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | 2523 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); |
2520 | 2524 | ||
2525 | mutex_lock(&usb_port_peer_mutex); | ||
2521 | if (usb_hcd_is_primary_hcd(hcd)) | 2526 | if (usb_hcd_is_primary_hcd(hcd)) |
2522 | kfree(hcd->bandwidth_mutex); | 2527 | kfree(hcd->bandwidth_mutex); |
2523 | else | 2528 | if (hcd->shared_hcd) { |
2524 | hcd->shared_hcd->shared_hcd = NULL; | 2529 | struct usb_hcd *peer = hcd->shared_hcd; |
2530 | |||
2531 | peer->shared_hcd = NULL; | ||
2532 | if (peer->primary_hcd == hcd) | ||
2533 | peer->primary_hcd = NULL; | ||
2534 | } | ||
2535 | mutex_unlock(&usb_port_peer_mutex); | ||
2525 | kfree(hcd); | 2536 | kfree(hcd); |
2526 | } | 2537 | } |
2527 | 2538 | ||
@@ -2589,6 +2600,21 @@ static int usb_hcd_request_irqs(struct usb_hcd *hcd, | |||
2589 | return 0; | 2600 | return 0; |
2590 | } | 2601 | } |
2591 | 2602 | ||
2603 | /* | ||
2604 | * Before we free this root hub, flush in-flight peering attempts | ||
2605 | * and disable peer lookups | ||
2606 | */ | ||
2607 | static void usb_put_invalidate_rhdev(struct usb_hcd *hcd) | ||
2608 | { | ||
2609 | struct usb_device *rhdev; | ||
2610 | |||
2611 | mutex_lock(&usb_port_peer_mutex); | ||
2612 | rhdev = hcd->self.root_hub; | ||
2613 | hcd->self.root_hub = NULL; | ||
2614 | mutex_unlock(&usb_port_peer_mutex); | ||
2615 | usb_put_dev(rhdev); | ||
2616 | } | ||
2617 | |||
2592 | /** | 2618 | /** |
2593 | * usb_add_hcd - finish generic HCD structure initialization and register | 2619 | * usb_add_hcd - finish generic HCD structure initialization and register |
2594 | * @hcd: the usb_hcd structure to initialize | 2620 | * @hcd: the usb_hcd structure to initialize |
@@ -2649,7 +2675,9 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2649 | retval = -ENOMEM; | 2675 | retval = -ENOMEM; |
2650 | goto err_allocate_root_hub; | 2676 | goto err_allocate_root_hub; |
2651 | } | 2677 | } |
2678 | mutex_lock(&usb_port_peer_mutex); | ||
2652 | hcd->self.root_hub = rhdev; | 2679 | hcd->self.root_hub = rhdev; |
2680 | mutex_unlock(&usb_port_peer_mutex); | ||
2653 | 2681 | ||
2654 | switch (hcd->speed) { | 2682 | switch (hcd->speed) { |
2655 | case HCD_USB11: | 2683 | case HCD_USB11: |
@@ -2758,7 +2786,7 @@ err_hcd_driver_start: | |||
2758 | err_request_irq: | 2786 | err_request_irq: |
2759 | err_hcd_driver_setup: | 2787 | err_hcd_driver_setup: |
2760 | err_set_rh_speed: | 2788 | err_set_rh_speed: |
2761 | usb_put_dev(hcd->self.root_hub); | 2789 | usb_put_invalidate_rhdev(hcd); |
2762 | err_allocate_root_hub: | 2790 | err_allocate_root_hub: |
2763 | usb_deregister_bus(&hcd->self); | 2791 | usb_deregister_bus(&hcd->self); |
2764 | err_register_bus: | 2792 | err_register_bus: |
@@ -2838,7 +2866,6 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2838 | free_irq(hcd->irq, hcd); | 2866 | free_irq(hcd->irq, hcd); |
2839 | } | 2867 | } |
2840 | 2868 | ||
2841 | usb_put_dev(hcd->self.root_hub); | ||
2842 | usb_deregister_bus(&hcd->self); | 2869 | usb_deregister_bus(&hcd->self); |
2843 | hcd_buffer_destroy(hcd); | 2870 | hcd_buffer_destroy(hcd); |
2844 | if (hcd->remove_phy && hcd->phy) { | 2871 | if (hcd->remove_phy && hcd->phy) { |
@@ -2846,6 +2873,8 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2846 | usb_put_phy(hcd->phy); | 2873 | usb_put_phy(hcd->phy); |
2847 | hcd->phy = NULL; | 2874 | hcd->phy = NULL; |
2848 | } | 2875 | } |
2876 | |||
2877 | usb_put_invalidate_rhdev(hcd); | ||
2849 | } | 2878 | } |
2850 | EXPORT_SYMBOL_GPL(usb_remove_hcd); | 2879 | EXPORT_SYMBOL_GPL(usb_remove_hcd); |
2851 | 2880 | ||
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 090469ebfcff..db6287025c06 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -36,11 +36,6 @@ | |||
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 |
38 | 38 | ||
39 | static inline int hub_is_superspeed(struct usb_device *hdev) | ||
40 | { | ||
41 | return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS); | ||
42 | } | ||
43 | |||
44 | /* Protect struct usb_device->state and ->children members | 39 | /* Protect struct usb_device->state and ->children members |
45 | * Note: Both are also protected by ->dev.sem, except that ->state can | 40 | * Note: Both are also protected by ->dev.sem, except that ->state can |
46 | * 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. */ |
@@ -55,6 +50,9 @@ static DECLARE_WAIT_QUEUE_HEAD(khubd_wait); | |||
55 | 50 | ||
56 | static struct task_struct *khubd_task; | 51 | static struct task_struct *khubd_task; |
57 | 52 | ||
53 | /* synchronize hub-port add/remove and peering operations */ | ||
54 | DEFINE_MUTEX(usb_port_peer_mutex); | ||
55 | |||
58 | /* cycle leds on hubs that aren't blinking for attention */ | 56 | /* cycle leds on hubs that aren't blinking for attention */ |
59 | static bool blinkenlights = 0; | 57 | static bool blinkenlights = 0; |
60 | module_param (blinkenlights, bool, S_IRUGO); | 58 | module_param (blinkenlights, bool, S_IRUGO); |
@@ -412,30 +410,35 @@ static int set_port_feature(struct usb_device *hdev, int port1, int feature) | |||
412 | NULL, 0, 1000); | 410 | NULL, 0, 1000); |
413 | } | 411 | } |
414 | 412 | ||
413 | static char *to_led_name(int selector) | ||
414 | { | ||
415 | switch (selector) { | ||
416 | case HUB_LED_AMBER: | ||
417 | return "amber"; | ||
418 | case HUB_LED_GREEN: | ||
419 | return "green"; | ||
420 | case HUB_LED_OFF: | ||
421 | return "off"; | ||
422 | case HUB_LED_AUTO: | ||
423 | return "auto"; | ||
424 | default: | ||
425 | return "??"; | ||
426 | } | ||
427 | } | ||
428 | |||
415 | /* | 429 | /* |
416 | * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7 | 430 | * USB 2.0 spec Section 11.24.2.7.1.10 and table 11-7 |
417 | * for info about using port indicators | 431 | * for info about using port indicators |
418 | */ | 432 | */ |
419 | static void set_port_led( | 433 | static void set_port_led(struct usb_hub *hub, int port1, int selector) |
420 | struct usb_hub *hub, | ||
421 | int port1, | ||
422 | int selector | ||
423 | ) | ||
424 | { | 434 | { |
425 | int status = set_port_feature(hub->hdev, (selector << 8) | port1, | 435 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
436 | int status; | ||
437 | |||
438 | status = set_port_feature(hub->hdev, (selector << 8) | port1, | ||
426 | USB_PORT_FEAT_INDICATOR); | 439 | USB_PORT_FEAT_INDICATOR); |
427 | if (status < 0) | 440 | dev_dbg(&port_dev->dev, "indicator %s status %d\n", |
428 | dev_dbg (hub->intfdev, | 441 | to_led_name(selector), status); |
429 | "port %d indicator %s status %d\n", | ||
430 | port1, | ||
431 | ({ char *s; switch (selector) { | ||
432 | case HUB_LED_AMBER: s = "amber"; break; | ||
433 | case HUB_LED_GREEN: s = "green"; break; | ||
434 | case HUB_LED_OFF: s = "off"; break; | ||
435 | case HUB_LED_AUTO: s = "auto"; break; | ||
436 | default: s = "??"; break; | ||
437 | } s; }), | ||
438 | status); | ||
439 | } | 442 | } |
440 | 443 | ||
441 | #define LED_CYCLE_PERIOD ((2*HZ)/3) | 444 | #define LED_CYCLE_PERIOD ((2*HZ)/3) |
@@ -743,16 +746,20 @@ int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub, | |||
743 | int port1, bool set) | 746 | int port1, bool set) |
744 | { | 747 | { |
745 | int ret; | 748 | int ret; |
746 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
747 | 749 | ||
748 | if (set) | 750 | if (set) |
749 | ret = set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); | 751 | ret = set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); |
750 | else | 752 | else |
751 | ret = usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_POWER); | 753 | ret = usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_POWER); |
752 | 754 | ||
753 | if (!ret) | 755 | if (ret) |
754 | port_dev->power_is_on = set; | 756 | return ret; |
755 | return ret; | 757 | |
758 | if (set) | ||
759 | set_bit(port1, hub->power_bits); | ||
760 | else | ||
761 | clear_bit(port1, hub->power_bits); | ||
762 | return 0; | ||
756 | } | 763 | } |
757 | 764 | ||
758 | /** | 765 | /** |
@@ -810,16 +817,9 @@ int usb_hub_clear_tt_buffer(struct urb *urb) | |||
810 | } | 817 | } |
811 | EXPORT_SYMBOL_GPL(usb_hub_clear_tt_buffer); | 818 | EXPORT_SYMBOL_GPL(usb_hub_clear_tt_buffer); |
812 | 819 | ||
813 | /* If do_delay is false, return the number of milliseconds the caller | 820 | static void hub_power_on(struct usb_hub *hub, bool do_delay) |
814 | * needs to delay. | ||
815 | */ | ||
816 | static unsigned hub_power_on(struct usb_hub *hub, bool do_delay) | ||
817 | { | 821 | { |
818 | int port1; | 822 | int port1; |
819 | unsigned pgood_delay = hub->descriptor->bPwrOn2PwrGood * 2; | ||
820 | unsigned delay; | ||
821 | u16 wHubCharacteristics = | ||
822 | le16_to_cpu(hub->descriptor->wHubCharacteristics); | ||
823 | 823 | ||
824 | /* Enable power on each port. Some hubs have reserved values | 824 | /* Enable power on each port. Some hubs have reserved values |
825 | * of LPSM (> 2) in their descriptors, even though they are | 825 | * of LPSM (> 2) in their descriptors, even though they are |
@@ -827,23 +827,19 @@ static unsigned hub_power_on(struct usb_hub *hub, bool do_delay) | |||
827 | * but only emulate it. In all cases, the ports won't work | 827 | * but only emulate it. In all cases, the ports won't work |
828 | * unless we send these messages to the hub. | 828 | * unless we send these messages to the hub. |
829 | */ | 829 | */ |
830 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2) | 830 | if (hub_is_port_power_switchable(hub)) |
831 | dev_dbg(hub->intfdev, "enabling power on all ports\n"); | 831 | dev_dbg(hub->intfdev, "enabling power on all ports\n"); |
832 | else | 832 | else |
833 | dev_dbg(hub->intfdev, "trying to enable port power on " | 833 | dev_dbg(hub->intfdev, "trying to enable port power on " |
834 | "non-switchable hub\n"); | 834 | "non-switchable hub\n"); |
835 | for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) | 835 | for (port1 = 1; port1 <= hub->hdev->maxchild; port1++) |
836 | if (hub->ports[port1 - 1]->power_is_on) | 836 | if (test_bit(port1, hub->power_bits)) |
837 | set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); | 837 | set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER); |
838 | else | 838 | else |
839 | usb_clear_port_feature(hub->hdev, port1, | 839 | usb_clear_port_feature(hub->hdev, port1, |
840 | USB_PORT_FEAT_POWER); | 840 | USB_PORT_FEAT_POWER); |
841 | |||
842 | /* Wait at least 100 msec for power to become stable */ | ||
843 | delay = max(pgood_delay, (unsigned) 100); | ||
844 | if (do_delay) | 841 | if (do_delay) |
845 | msleep(delay); | 842 | msleep(hub_power_on_good_delay(hub)); |
846 | return delay; | ||
847 | } | 843 | } |
848 | 844 | ||
849 | static int hub_hub_status(struct usb_hub *hub, | 845 | static int hub_hub_status(struct usb_hub *hub, |
@@ -911,20 +907,20 @@ static int hub_usb3_port_disable(struct usb_hub *hub, int port1) | |||
911 | msleep(HUB_DEBOUNCE_STEP); | 907 | msleep(HUB_DEBOUNCE_STEP); |
912 | } | 908 | } |
913 | if (total_time >= HUB_DEBOUNCE_TIMEOUT) | 909 | if (total_time >= HUB_DEBOUNCE_TIMEOUT) |
914 | dev_warn(hub->intfdev, "Could not disable port %d after %d ms\n", | 910 | dev_warn(&hub->ports[port1 - 1]->dev, |
915 | port1, total_time); | 911 | "Could not disable after %d ms\n", total_time); |
916 | 912 | ||
917 | return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT); | 913 | return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT); |
918 | } | 914 | } |
919 | 915 | ||
920 | static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | 916 | static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) |
921 | { | 917 | { |
918 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
922 | struct usb_device *hdev = hub->hdev; | 919 | struct usb_device *hdev = hub->hdev; |
923 | int ret = 0; | 920 | int ret = 0; |
924 | 921 | ||
925 | if (hub->ports[port1 - 1]->child && set_state) | 922 | if (port_dev->child && set_state) |
926 | usb_set_device_state(hub->ports[port1 - 1]->child, | 923 | usb_set_device_state(port_dev->child, USB_STATE_NOTATTACHED); |
927 | USB_STATE_NOTATTACHED); | ||
928 | if (!hub->error) { | 924 | if (!hub->error) { |
929 | if (hub_is_superspeed(hub->hdev)) | 925 | if (hub_is_superspeed(hub->hdev)) |
930 | ret = hub_usb3_port_disable(hub, port1); | 926 | ret = hub_usb3_port_disable(hub, port1); |
@@ -933,8 +929,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
933 | USB_PORT_FEAT_ENABLE); | 929 | USB_PORT_FEAT_ENABLE); |
934 | } | 930 | } |
935 | if (ret && ret != -ENODEV) | 931 | if (ret && ret != -ENODEV) |
936 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", | 932 | dev_err(&port_dev->dev, "cannot disable (err = %d)\n", ret); |
937 | port1, ret); | ||
938 | return ret; | 933 | return ret; |
939 | } | 934 | } |
940 | 935 | ||
@@ -945,7 +940,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
945 | */ | 940 | */ |
946 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) | 941 | static void hub_port_logical_disconnect(struct usb_hub *hub, int port1) |
947 | { | 942 | { |
948 | dev_dbg(hub->intfdev, "logical disconnect on port %d\n", port1); | 943 | dev_dbg(&hub->ports[port1 - 1]->dev, "logical disconnect\n"); |
949 | hub_port_disable(hub, port1, 1); | 944 | hub_port_disable(hub, port1, 1); |
950 | 945 | ||
951 | /* FIXME let caller ask to power down the port: | 946 | /* FIXME let caller ask to power down the port: |
@@ -1048,7 +1043,9 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1048 | * for HUB_POST_RESET, but it's easier not to. | 1043 | * for HUB_POST_RESET, but it's easier not to. |
1049 | */ | 1044 | */ |
1050 | if (type == HUB_INIT) { | 1045 | if (type == HUB_INIT) { |
1051 | delay = hub_power_on(hub, false); | 1046 | unsigned delay = hub_power_on_good_delay(hub); |
1047 | |||
1048 | hub_power_on(hub, false); | ||
1052 | INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); | 1049 | INIT_DELAYED_WORK(&hub->init_work, hub_init_func2); |
1053 | queue_delayed_work(system_power_efficient_wq, | 1050 | queue_delayed_work(system_power_efficient_wq, |
1054 | &hub->init_work, | 1051 | &hub->init_work, |
@@ -1083,21 +1080,23 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1083 | } | 1080 | } |
1084 | init2: | 1081 | init2: |
1085 | 1082 | ||
1086 | /* Check each port and set hub->change_bits to let khubd know | 1083 | /* |
1084 | * Check each port and set hub->change_bits to let khubd know | ||
1087 | * which ports need attention. | 1085 | * which ports need attention. |
1088 | */ | 1086 | */ |
1089 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | 1087 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { |
1090 | struct usb_device *udev = hub->ports[port1 - 1]->child; | 1088 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
1089 | struct usb_device *udev = port_dev->child; | ||
1091 | u16 portstatus, portchange; | 1090 | u16 portstatus, portchange; |
1092 | 1091 | ||
1093 | portstatus = portchange = 0; | 1092 | portstatus = portchange = 0; |
1094 | status = hub_port_status(hub, port1, &portstatus, &portchange); | 1093 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
1095 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) | 1094 | if (udev || (portstatus & USB_PORT_STAT_CONNECTION)) |
1096 | dev_dbg(hub->intfdev, | 1095 | dev_dbg(&port_dev->dev, "status %04x change %04x\n", |
1097 | "port %d: status %04x change %04x\n", | 1096 | portstatus, portchange); |
1098 | port1, portstatus, portchange); | ||
1099 | 1097 | ||
1100 | /* After anything other than HUB_RESUME (i.e., initialization | 1098 | /* |
1099 | * After anything other than HUB_RESUME (i.e., initialization | ||
1101 | * or any sort of reset), every port should be disabled. | 1100 | * or any sort of reset), every port should be disabled. |
1102 | * Unconnected ports should likewise be disabled (paranoia), | 1101 | * Unconnected ports should likewise be disabled (paranoia), |
1103 | * and so should ports for which we have no usb_device. | 1102 | * and so should ports for which we have no usb_device. |
@@ -1173,15 +1172,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
1173 | set_bit(port1, hub->change_bits); | 1172 | set_bit(port1, hub->change_bits); |
1174 | 1173 | ||
1175 | } else if (udev->persist_enabled) { | 1174 | } else if (udev->persist_enabled) { |
1176 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
1177 | |||
1178 | #ifdef CONFIG_PM | 1175 | #ifdef CONFIG_PM |
1179 | udev->reset_resume = 1; | 1176 | udev->reset_resume = 1; |
1180 | #endif | 1177 | #endif |
1181 | /* Don't set the change_bits when the device | 1178 | /* Don't set the change_bits when the device |
1182 | * was powered off. | 1179 | * was powered off. |
1183 | */ | 1180 | */ |
1184 | if (port_dev->power_is_on) | 1181 | if (test_bit(port1, hub->power_bits)) |
1185 | set_bit(port1, hub->change_bits); | 1182 | set_bit(port1, hub->change_bits); |
1186 | 1183 | ||
1187 | } else { | 1184 | } else { |
@@ -1276,12 +1273,22 @@ static void hub_quiesce(struct usb_hub *hub, enum hub_quiescing_type type) | |||
1276 | flush_work(&hub->tt.clear_work); | 1273 | flush_work(&hub->tt.clear_work); |
1277 | } | 1274 | } |
1278 | 1275 | ||
1276 | static void hub_pm_barrier_for_all_ports(struct usb_hub *hub) | ||
1277 | { | ||
1278 | int i; | ||
1279 | |||
1280 | for (i = 0; i < hub->hdev->maxchild; ++i) | ||
1281 | pm_runtime_barrier(&hub->ports[i]->dev); | ||
1282 | } | ||
1283 | |||
1279 | /* caller has locked the hub device */ | 1284 | /* caller has locked the hub device */ |
1280 | static int hub_pre_reset(struct usb_interface *intf) | 1285 | static int hub_pre_reset(struct usb_interface *intf) |
1281 | { | 1286 | { |
1282 | struct usb_hub *hub = usb_get_intfdata(intf); | 1287 | struct usb_hub *hub = usb_get_intfdata(intf); |
1283 | 1288 | ||
1284 | hub_quiesce(hub, HUB_PRE_RESET); | 1289 | hub_quiesce(hub, HUB_PRE_RESET); |
1290 | hub->in_reset = 1; | ||
1291 | hub_pm_barrier_for_all_ports(hub); | ||
1285 | return 0; | 1292 | return 0; |
1286 | } | 1293 | } |
1287 | 1294 | ||
@@ -1290,6 +1297,8 @@ static int hub_post_reset(struct usb_interface *intf) | |||
1290 | { | 1297 | { |
1291 | struct usb_hub *hub = usb_get_intfdata(intf); | 1298 | struct usb_hub *hub = usb_get_intfdata(intf); |
1292 | 1299 | ||
1300 | hub->in_reset = 0; | ||
1301 | hub_pm_barrier_for_all_ports(hub); | ||
1293 | hub_activate(hub, HUB_POST_RESET); | 1302 | hub_activate(hub, HUB_POST_RESET); |
1294 | return 0; | 1303 | return 0; |
1295 | } | 1304 | } |
@@ -1307,6 +1316,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1307 | char *message = "out of memory"; | 1316 | char *message = "out of memory"; |
1308 | unsigned unit_load; | 1317 | unsigned unit_load; |
1309 | unsigned full_load; | 1318 | unsigned full_load; |
1319 | unsigned maxchild; | ||
1310 | 1320 | ||
1311 | hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); | 1321 | hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL); |
1312 | if (!hub->buffer) { | 1322 | if (!hub->buffer) { |
@@ -1345,12 +1355,11 @@ static int hub_configure(struct usb_hub *hub, | |||
1345 | goto fail; | 1355 | goto fail; |
1346 | } | 1356 | } |
1347 | 1357 | ||
1348 | hdev->maxchild = hub->descriptor->bNbrPorts; | 1358 | maxchild = hub->descriptor->bNbrPorts; |
1349 | dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, | 1359 | dev_info(hub_dev, "%d port%s detected\n", maxchild, |
1350 | (hdev->maxchild == 1) ? "" : "s"); | 1360 | (maxchild == 1) ? "" : "s"); |
1351 | 1361 | ||
1352 | hub->ports = kzalloc(hdev->maxchild * sizeof(struct usb_port *), | 1362 | hub->ports = kzalloc(maxchild * sizeof(struct usb_port *), GFP_KERNEL); |
1353 | GFP_KERNEL); | ||
1354 | if (!hub->ports) { | 1363 | if (!hub->ports) { |
1355 | ret = -ENOMEM; | 1364 | ret = -ENOMEM; |
1356 | goto fail; | 1365 | goto fail; |
@@ -1371,11 +1380,11 @@ static int hub_configure(struct usb_hub *hub, | |||
1371 | int i; | 1380 | int i; |
1372 | char portstr[USB_MAXCHILDREN + 1]; | 1381 | char portstr[USB_MAXCHILDREN + 1]; |
1373 | 1382 | ||
1374 | for (i = 0; i < hdev->maxchild; i++) | 1383 | for (i = 0; i < maxchild; i++) |
1375 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable | 1384 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable |
1376 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) | 1385 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) |
1377 | ? 'F' : 'R'; | 1386 | ? 'F' : 'R'; |
1378 | portstr[hdev->maxchild] = 0; | 1387 | portstr[maxchild] = 0; |
1379 | dev_dbg(hub_dev, "compound device; port removable status: %s\n", portstr); | 1388 | dev_dbg(hub_dev, "compound device; port removable status: %s\n", portstr); |
1380 | } else | 1389 | } else |
1381 | dev_dbg(hub_dev, "standalone hub\n"); | 1390 | dev_dbg(hub_dev, "standalone hub\n"); |
@@ -1487,7 +1496,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1487 | if (hcd->power_budget > 0) | 1496 | if (hcd->power_budget > 0) |
1488 | hdev->bus_mA = hcd->power_budget; | 1497 | hdev->bus_mA = hcd->power_budget; |
1489 | else | 1498 | else |
1490 | hdev->bus_mA = full_load * hdev->maxchild; | 1499 | hdev->bus_mA = full_load * maxchild; |
1491 | if (hdev->bus_mA >= full_load) | 1500 | if (hdev->bus_mA >= full_load) |
1492 | hub->mA_per_port = full_load; | 1501 | hub->mA_per_port = full_load; |
1493 | else { | 1502 | else { |
@@ -1502,7 +1511,7 @@ static int hub_configure(struct usb_hub *hub, | |||
1502 | hub->descriptor->bHubContrCurrent); | 1511 | hub->descriptor->bHubContrCurrent); |
1503 | hub->limited_power = 1; | 1512 | hub->limited_power = 1; |
1504 | 1513 | ||
1505 | if (remaining < hdev->maxchild * unit_load) | 1514 | if (remaining < maxchild * unit_load) |
1506 | dev_warn(hub_dev, | 1515 | dev_warn(hub_dev, |
1507 | "insufficient power available " | 1516 | "insufficient power available " |
1508 | "to use all downstream ports\n"); | 1517 | "to use all downstream ports\n"); |
@@ -1570,15 +1579,19 @@ static int hub_configure(struct usb_hub *hub, | |||
1570 | if (hub->has_indicators && blinkenlights) | 1579 | if (hub->has_indicators && blinkenlights) |
1571 | hub->indicator[0] = INDICATOR_CYCLE; | 1580 | hub->indicator[0] = INDICATOR_CYCLE; |
1572 | 1581 | ||
1573 | for (i = 0; i < hdev->maxchild; i++) { | 1582 | mutex_lock(&usb_port_peer_mutex); |
1583 | for (i = 0; i < maxchild; i++) { | ||
1574 | ret = usb_hub_create_port_device(hub, i + 1); | 1584 | ret = usb_hub_create_port_device(hub, i + 1); |
1575 | if (ret < 0) { | 1585 | if (ret < 0) { |
1576 | dev_err(hub->intfdev, | 1586 | dev_err(hub->intfdev, |
1577 | "couldn't create port%d device.\n", i + 1); | 1587 | "couldn't create port%d device.\n", i + 1); |
1578 | hdev->maxchild = i; | 1588 | break; |
1579 | goto fail_keep_maxchild; | ||
1580 | } | 1589 | } |
1581 | } | 1590 | } |
1591 | hdev->maxchild = i; | ||
1592 | mutex_unlock(&usb_port_peer_mutex); | ||
1593 | if (ret < 0) | ||
1594 | goto fail; | ||
1582 | 1595 | ||
1583 | usb_hub_adjust_deviceremovable(hdev, hub->descriptor); | 1596 | usb_hub_adjust_deviceremovable(hdev, hub->descriptor); |
1584 | 1597 | ||
@@ -1586,8 +1599,6 @@ static int hub_configure(struct usb_hub *hub, | |||
1586 | return 0; | 1599 | return 0; |
1587 | 1600 | ||
1588 | fail: | 1601 | fail: |
1589 | hdev->maxchild = 0; | ||
1590 | fail_keep_maxchild: | ||
1591 | dev_err (hub_dev, "config failed, %s (err %d)\n", | 1602 | dev_err (hub_dev, "config failed, %s (err %d)\n", |
1592 | message, ret); | 1603 | message, ret); |
1593 | /* hub_disconnect() frees urb and descriptor */ | 1604 | /* hub_disconnect() frees urb and descriptor */ |
@@ -1623,6 +1634,8 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1623 | hub->error = 0; | 1634 | hub->error = 0; |
1624 | hub_quiesce(hub, HUB_DISCONNECT); | 1635 | hub_quiesce(hub, HUB_DISCONNECT); |
1625 | 1636 | ||
1637 | mutex_lock(&usb_port_peer_mutex); | ||
1638 | |||
1626 | /* Avoid races with recursively_mark_NOTATTACHED() */ | 1639 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1627 | spin_lock_irq(&device_state_lock); | 1640 | spin_lock_irq(&device_state_lock); |
1628 | port1 = hdev->maxchild; | 1641 | port1 = hdev->maxchild; |
@@ -1633,6 +1646,8 @@ static void hub_disconnect(struct usb_interface *intf) | |||
1633 | for (; port1 > 0; --port1) | 1646 | for (; port1 > 0; --port1) |
1634 | usb_hub_remove_port_device(hub, port1); | 1647 | usb_hub_remove_port_device(hub, port1); |
1635 | 1648 | ||
1649 | mutex_unlock(&usb_port_peer_mutex); | ||
1650 | |||
1636 | if (hub->hdev->speed == USB_SPEED_HIGH) | 1651 | if (hub->hdev->speed == USB_SPEED_HIGH) |
1637 | highspeed_hubs--; | 1652 | highspeed_hubs--; |
1638 | 1653 | ||
@@ -2024,6 +2039,18 @@ static void hub_free_dev(struct usb_device *udev) | |||
2024 | hcd->driver->free_dev(hcd, udev); | 2039 | hcd->driver->free_dev(hcd, udev); |
2025 | } | 2040 | } |
2026 | 2041 | ||
2042 | static void hub_disconnect_children(struct usb_device *udev) | ||
2043 | { | ||
2044 | struct usb_hub *hub = usb_hub_to_struct_hub(udev); | ||
2045 | int i; | ||
2046 | |||
2047 | /* Free up all the children before we remove this device */ | ||
2048 | for (i = 0; i < udev->maxchild; i++) { | ||
2049 | if (hub->ports[i]->child) | ||
2050 | usb_disconnect(&hub->ports[i]->child); | ||
2051 | } | ||
2052 | } | ||
2053 | |||
2027 | /** | 2054 | /** |
2028 | * usb_disconnect - disconnect a device (usbcore-internal) | 2055 | * usb_disconnect - disconnect a device (usbcore-internal) |
2029 | * @pdev: pointer to device being disconnected | 2056 | * @pdev: pointer to device being disconnected |
@@ -2042,9 +2069,10 @@ static void hub_free_dev(struct usb_device *udev) | |||
2042 | */ | 2069 | */ |
2043 | void usb_disconnect(struct usb_device **pdev) | 2070 | void usb_disconnect(struct usb_device **pdev) |
2044 | { | 2071 | { |
2045 | struct usb_device *udev = *pdev; | 2072 | struct usb_port *port_dev = NULL; |
2046 | struct usb_hub *hub = usb_hub_to_struct_hub(udev); | 2073 | struct usb_device *udev = *pdev; |
2047 | int i; | 2074 | struct usb_hub *hub; |
2075 | int port1; | ||
2048 | 2076 | ||
2049 | /* mark the device as inactive, so any further urb submissions for | 2077 | /* mark the device as inactive, so any further urb submissions for |
2050 | * this device (and any of its children) will fail immediately. | 2078 | * this device (and any of its children) will fail immediately. |
@@ -2056,11 +2084,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
2056 | 2084 | ||
2057 | usb_lock_device(udev); | 2085 | usb_lock_device(udev); |
2058 | 2086 | ||
2059 | /* Free up all the children before we remove this device */ | 2087 | hub_disconnect_children(udev); |
2060 | for (i = 0; i < udev->maxchild; i++) { | ||
2061 | if (hub->ports[i]->child) | ||
2062 | usb_disconnect(&hub->ports[i]->child); | ||
2063 | } | ||
2064 | 2088 | ||
2065 | /* deallocate hcd/hardware state ... nuking all pending urbs and | 2089 | /* deallocate hcd/hardware state ... nuking all pending urbs and |
2066 | * cleaning up all state associated with the current configuration | 2090 | * cleaning up all state associated with the current configuration |
@@ -2071,16 +2095,19 @@ void usb_disconnect(struct usb_device **pdev) | |||
2071 | usb_hcd_synchronize_unlinks(udev); | 2095 | usb_hcd_synchronize_unlinks(udev); |
2072 | 2096 | ||
2073 | if (udev->parent) { | 2097 | if (udev->parent) { |
2074 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); | 2098 | port1 = udev->portnum; |
2075 | struct usb_port *port_dev = hub->ports[udev->portnum - 1]; | 2099 | hub = usb_hub_to_struct_hub(udev->parent); |
2100 | port_dev = hub->ports[port1 - 1]; | ||
2076 | 2101 | ||
2077 | sysfs_remove_link(&udev->dev.kobj, "port"); | 2102 | sysfs_remove_link(&udev->dev.kobj, "port"); |
2078 | sysfs_remove_link(&port_dev->dev.kobj, "device"); | 2103 | sysfs_remove_link(&port_dev->dev.kobj, "device"); |
2079 | 2104 | ||
2080 | if (!port_dev->did_runtime_put) | 2105 | /* |
2081 | pm_runtime_put(&port_dev->dev); | 2106 | * As usb_port_runtime_resume() de-references udev, make |
2082 | else | 2107 | * sure no resumes occur during removal |
2083 | port_dev->did_runtime_put = false; | 2108 | */ |
2109 | if (!test_and_set_bit(port1, hub->child_usage_bits)) | ||
2110 | pm_runtime_get_sync(&port_dev->dev); | ||
2084 | } | 2111 | } |
2085 | 2112 | ||
2086 | usb_remove_ep_devs(&udev->ep0); | 2113 | usb_remove_ep_devs(&udev->ep0); |
@@ -2102,6 +2129,9 @@ void usb_disconnect(struct usb_device **pdev) | |||
2102 | *pdev = NULL; | 2129 | *pdev = NULL; |
2103 | spin_unlock_irq(&device_state_lock); | 2130 | spin_unlock_irq(&device_state_lock); |
2104 | 2131 | ||
2132 | if (port_dev && test_and_clear_bit(port1, hub->child_usage_bits)) | ||
2133 | pm_runtime_put(&port_dev->dev); | ||
2134 | |||
2105 | hub_free_dev(udev); | 2135 | hub_free_dev(udev); |
2106 | 2136 | ||
2107 | put_device(&udev->dev); | 2137 | put_device(&udev->dev); |
@@ -2289,6 +2319,22 @@ static void set_usb_port_removable(struct usb_device *udev) | |||
2289 | udev->removable = USB_DEVICE_REMOVABLE; | 2319 | udev->removable = USB_DEVICE_REMOVABLE; |
2290 | else | 2320 | else |
2291 | udev->removable = USB_DEVICE_FIXED; | 2321 | udev->removable = USB_DEVICE_FIXED; |
2322 | |||
2323 | /* | ||
2324 | * Platform firmware may have populated an alternative value for | ||
2325 | * removable. If the parent port has a known connect_type use | ||
2326 | * that instead. | ||
2327 | */ | ||
2328 | switch (hub->ports[udev->portnum - 1]->connect_type) { | ||
2329 | case USB_PORT_CONNECT_TYPE_HOT_PLUG: | ||
2330 | udev->removable = USB_DEVICE_REMOVABLE; | ||
2331 | break; | ||
2332 | case USB_PORT_CONNECT_TYPE_HARD_WIRED: | ||
2333 | udev->removable = USB_DEVICE_FIXED; | ||
2334 | break; | ||
2335 | default: /* use what was set above */ | ||
2336 | break; | ||
2337 | } | ||
2292 | } | 2338 | } |
2293 | 2339 | ||
2294 | /** | 2340 | /** |
@@ -2358,11 +2404,7 @@ int usb_new_device(struct usb_device *udev) | |||
2358 | 2404 | ||
2359 | device_enable_async_suspend(&udev->dev); | 2405 | device_enable_async_suspend(&udev->dev); |
2360 | 2406 | ||
2361 | /* | 2407 | /* check whether the hub or firmware marks this port as non-removable */ |
2362 | * check whether the hub marks this port as non-removable. Do it | ||
2363 | * now so that platform-specific data can override it in | ||
2364 | * device_add() | ||
2365 | */ | ||
2366 | if (udev->parent) | 2408 | if (udev->parent) |
2367 | set_usb_port_removable(udev); | 2409 | set_usb_port_removable(udev); |
2368 | 2410 | ||
@@ -2379,7 +2421,8 @@ int usb_new_device(struct usb_device *udev) | |||
2379 | /* Create link files between child device and usb port device. */ | 2421 | /* Create link files between child device and usb port device. */ |
2380 | if (udev->parent) { | 2422 | if (udev->parent) { |
2381 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); | 2423 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); |
2382 | struct usb_port *port_dev = hub->ports[udev->portnum - 1]; | 2424 | int port1 = udev->portnum; |
2425 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
2383 | 2426 | ||
2384 | err = sysfs_create_link(&udev->dev.kobj, | 2427 | err = sysfs_create_link(&udev->dev.kobj, |
2385 | &port_dev->dev.kobj, "port"); | 2428 | &port_dev->dev.kobj, "port"); |
@@ -2393,7 +2436,8 @@ int usb_new_device(struct usb_device *udev) | |||
2393 | goto fail; | 2436 | goto fail; |
2394 | } | 2437 | } |
2395 | 2438 | ||
2396 | pm_runtime_get_sync(&port_dev->dev); | 2439 | if (!test_and_set_bit(port1, hub->child_usage_bits)) |
2440 | pm_runtime_get_sync(&port_dev->dev); | ||
2397 | } | 2441 | } |
2398 | 2442 | ||
2399 | (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); | 2443 | (void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev); |
@@ -2561,9 +2605,9 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
2561 | if (delay_time >= 2 * HUB_SHORT_RESET_TIME) | 2605 | if (delay_time >= 2 * HUB_SHORT_RESET_TIME) |
2562 | delay = HUB_LONG_RESET_TIME; | 2606 | delay = HUB_LONG_RESET_TIME; |
2563 | 2607 | ||
2564 | dev_dbg (hub->intfdev, | 2608 | dev_dbg(&hub->ports[port1 - 1]->dev, |
2565 | "port %d not %sreset yet, waiting %dms\n", | 2609 | "not %sreset yet, waiting %dms\n", |
2566 | port1, warm ? "warm " : "", delay); | 2610 | warm ? "warm " : "", delay); |
2567 | } | 2611 | } |
2568 | 2612 | ||
2569 | if ((portstatus & USB_PORT_STAT_RESET)) | 2613 | if ((portstatus & USB_PORT_STAT_RESET)) |
@@ -2647,6 +2691,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2647 | { | 2691 | { |
2648 | int i, status; | 2692 | int i, status; |
2649 | u16 portchange, portstatus; | 2693 | u16 portchange, portstatus; |
2694 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
2650 | 2695 | ||
2651 | if (!hub_is_superspeed(hub->hdev)) { | 2696 | if (!hub_is_superspeed(hub->hdev)) { |
2652 | if (warm) { | 2697 | if (warm) { |
@@ -2680,9 +2725,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2680 | if (status == -ENODEV) { | 2725 | if (status == -ENODEV) { |
2681 | ; /* The hub is gone */ | 2726 | ; /* The hub is gone */ |
2682 | } else if (status) { | 2727 | } else if (status) { |
2683 | dev_err(hub->intfdev, | 2728 | dev_err(&port_dev->dev, |
2684 | "cannot %sreset port %d (err = %d)\n", | 2729 | "cannot %sreset (err = %d)\n", |
2685 | warm ? "warm " : "", port1, status); | 2730 | warm ? "warm " : "", status); |
2686 | } else { | 2731 | } else { |
2687 | status = hub_port_wait_reset(hub, port1, udev, delay, | 2732 | status = hub_port_wait_reset(hub, port1, udev, delay, |
2688 | warm); | 2733 | warm); |
@@ -2715,21 +2760,19 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2715 | * hot or warm reset failed. Try another warm reset. | 2760 | * hot or warm reset failed. Try another warm reset. |
2716 | */ | 2761 | */ |
2717 | if (!warm) { | 2762 | if (!warm) { |
2718 | dev_dbg(hub->intfdev, "hot reset failed, warm reset port %d\n", | 2763 | dev_dbg(&port_dev->dev, |
2719 | port1); | 2764 | "hot reset failed, warm reset\n"); |
2720 | warm = true; | 2765 | warm = true; |
2721 | } | 2766 | } |
2722 | } | 2767 | } |
2723 | 2768 | ||
2724 | dev_dbg (hub->intfdev, | 2769 | dev_dbg(&port_dev->dev, |
2725 | "port %d not enabled, trying %sreset again...\n", | 2770 | "not enabled, trying %sreset again...\n", |
2726 | port1, warm ? "warm " : ""); | 2771 | warm ? "warm " : ""); |
2727 | delay = HUB_LONG_RESET_TIME; | 2772 | delay = HUB_LONG_RESET_TIME; |
2728 | } | 2773 | } |
2729 | 2774 | ||
2730 | dev_err (hub->intfdev, | 2775 | dev_err(&port_dev->dev, "Cannot enable. Maybe the USB cable is bad?\n"); |
2731 | "Cannot enable port %i. Maybe the USB cable is bad?\n", | ||
2732 | port1); | ||
2733 | 2776 | ||
2734 | done: | 2777 | done: |
2735 | if (!hub_is_superspeed(hub->hdev)) | 2778 | if (!hub_is_superspeed(hub->hdev)) |
@@ -2754,6 +2797,20 @@ static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) | |||
2754 | return ret; | 2797 | return ret; |
2755 | } | 2798 | } |
2756 | 2799 | ||
2800 | static void usb_lock_port(struct usb_port *port_dev) | ||
2801 | __acquires(&port_dev->status_lock) | ||
2802 | { | ||
2803 | mutex_lock(&port_dev->status_lock); | ||
2804 | __acquire(&port_dev->status_lock); | ||
2805 | } | ||
2806 | |||
2807 | static void usb_unlock_port(struct usb_port *port_dev) | ||
2808 | __releases(&port_dev->status_lock) | ||
2809 | { | ||
2810 | mutex_unlock(&port_dev->status_lock); | ||
2811 | __release(&port_dev->status_lock); | ||
2812 | } | ||
2813 | |||
2757 | #ifdef CONFIG_PM | 2814 | #ifdef CONFIG_PM |
2758 | 2815 | ||
2759 | /* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */ | 2816 | /* Check if a port is suspended(USB2.0 port) or in U3 state(USB3.0 port) */ |
@@ -2780,6 +2837,8 @@ static int check_port_resume_type(struct usb_device *udev, | |||
2780 | struct usb_hub *hub, int port1, | 2837 | struct usb_hub *hub, int port1, |
2781 | int status, unsigned portchange, unsigned portstatus) | 2838 | int status, unsigned portchange, unsigned portstatus) |
2782 | { | 2839 | { |
2840 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
2841 | |||
2783 | /* Is the device still present? */ | 2842 | /* Is the device still present? */ |
2784 | if (status || port_is_suspended(hub, portstatus) || | 2843 | if (status || port_is_suspended(hub, portstatus) || |
2785 | !port_is_power_on(hub, portstatus) || | 2844 | !port_is_power_on(hub, portstatus) || |
@@ -2799,9 +2858,8 @@ static int check_port_resume_type(struct usb_device *udev, | |||
2799 | } | 2858 | } |
2800 | 2859 | ||
2801 | if (status) { | 2860 | if (status) { |
2802 | dev_dbg(hub->intfdev, | 2861 | dev_dbg(&port_dev->dev, "status %04x.%04x after resume, %d\n", |
2803 | "port %d status %04x.%04x after resume, %d\n", | 2862 | portchange, portstatus, status); |
2804 | port1, portchange, portstatus, status); | ||
2805 | } else if (udev->reset_resume) { | 2863 | } else if (udev->reset_resume) { |
2806 | 2864 | ||
2807 | /* Late port handoff can set status-change bits */ | 2865 | /* Late port handoff can set status-change bits */ |
@@ -2975,6 +3033,8 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
2975 | int status; | 3033 | int status; |
2976 | bool really_suspend = true; | 3034 | bool really_suspend = true; |
2977 | 3035 | ||
3036 | usb_lock_port(port_dev); | ||
3037 | |||
2978 | /* enable remote wakeup when appropriate; this lets the device | 3038 | /* enable remote wakeup when appropriate; this lets the device |
2979 | * wake up the upstream hub (including maybe the root hub). | 3039 | * wake up the upstream hub (including maybe the root hub). |
2980 | * | 3040 | * |
@@ -3032,8 +3092,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
3032 | status = 0; | 3092 | status = 0; |
3033 | } | 3093 | } |
3034 | if (status) { | 3094 | if (status) { |
3035 | dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", | 3095 | dev_dbg(&port_dev->dev, "can't suspend, status %d\n", status); |
3036 | port1, status); | ||
3037 | 3096 | ||
3038 | /* Try to enable USB3 LPM and LTM again */ | 3097 | /* Try to enable USB3 LPM and LTM again */ |
3039 | usb_unlocked_enable_lpm(udev); | 3098 | usb_unlocked_enable_lpm(udev); |
@@ -3064,12 +3123,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) | |||
3064 | usb_set_device_state(udev, USB_STATE_SUSPENDED); | 3123 | usb_set_device_state(udev, USB_STATE_SUSPENDED); |
3065 | } | 3124 | } |
3066 | 3125 | ||
3067 | if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled) { | 3126 | if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled |
3127 | && test_and_clear_bit(port1, hub->child_usage_bits)) | ||
3068 | pm_runtime_put_sync(&port_dev->dev); | 3128 | pm_runtime_put_sync(&port_dev->dev); |
3069 | port_dev->did_runtime_put = true; | ||
3070 | } | ||
3071 | 3129 | ||
3072 | usb_mark_last_busy(hub->hdev); | 3130 | usb_mark_last_busy(hub->hdev); |
3131 | |||
3132 | usb_unlock_port(port_dev); | ||
3073 | return status; | 3133 | return status; |
3074 | } | 3134 | } |
3075 | 3135 | ||
@@ -3209,9 +3269,8 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3209 | int status; | 3269 | int status; |
3210 | u16 portchange, portstatus; | 3270 | u16 portchange, portstatus; |
3211 | 3271 | ||
3212 | if (port_dev->did_runtime_put) { | 3272 | if (!test_and_set_bit(port1, hub->child_usage_bits)) { |
3213 | status = pm_runtime_get_sync(&port_dev->dev); | 3273 | status = pm_runtime_get_sync(&port_dev->dev); |
3214 | port_dev->did_runtime_put = false; | ||
3215 | if (status < 0) { | 3274 | if (status < 0) { |
3216 | dev_dbg(&udev->dev, "can't resume usb port, status %d\n", | 3275 | dev_dbg(&udev->dev, "can't resume usb port, status %d\n", |
3217 | status); | 3276 | status); |
@@ -3219,15 +3278,13 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3219 | } | 3278 | } |
3220 | } | 3279 | } |
3221 | 3280 | ||
3281 | usb_lock_port(port_dev); | ||
3282 | |||
3222 | /* Skip the initial Clear-Suspend step for a remote wakeup */ | 3283 | /* Skip the initial Clear-Suspend step for a remote wakeup */ |
3223 | status = hub_port_status(hub, port1, &portstatus, &portchange); | 3284 | status = hub_port_status(hub, port1, &portstatus, &portchange); |
3224 | if (status == 0 && !port_is_suspended(hub, portstatus)) | 3285 | if (status == 0 && !port_is_suspended(hub, portstatus)) |
3225 | goto SuspendCleared; | 3286 | goto SuspendCleared; |
3226 | 3287 | ||
3227 | /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */ | ||
3228 | |||
3229 | set_bit(port1, hub->busy_bits); | ||
3230 | |||
3231 | /* see 7.1.7.7; affects power usage, but not budgeting */ | 3288 | /* see 7.1.7.7; affects power usage, but not budgeting */ |
3232 | if (hub_is_superspeed(hub->hdev)) | 3289 | if (hub_is_superspeed(hub->hdev)) |
3233 | status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); | 3290 | status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); |
@@ -3235,8 +3292,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3235 | status = usb_clear_port_feature(hub->hdev, | 3292 | status = usb_clear_port_feature(hub->hdev, |
3236 | port1, USB_PORT_FEAT_SUSPEND); | 3293 | port1, USB_PORT_FEAT_SUSPEND); |
3237 | if (status) { | 3294 | if (status) { |
3238 | dev_dbg(hub->intfdev, "can't resume port %d, status %d\n", | 3295 | dev_dbg(&port_dev->dev, "can't resume, status %d\n", status); |
3239 | port1, status); | ||
3240 | } else { | 3296 | } else { |
3241 | /* drive resume for at least 20 msec */ | 3297 | /* drive resume for at least 20 msec */ |
3242 | dev_dbg(&udev->dev, "usb %sresume\n", | 3298 | dev_dbg(&udev->dev, "usb %sresume\n", |
@@ -3267,8 +3323,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3267 | } | 3323 | } |
3268 | } | 3324 | } |
3269 | 3325 | ||
3270 | clear_bit(port1, hub->busy_bits); | ||
3271 | |||
3272 | status = check_port_resume_type(udev, | 3326 | status = check_port_resume_type(udev, |
3273 | hub, port1, status, portchange, portstatus); | 3327 | hub, port1, status, portchange, portstatus); |
3274 | if (status == 0) | 3328 | if (status == 0) |
@@ -3286,16 +3340,18 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) | |||
3286 | usb_unlocked_enable_lpm(udev); | 3340 | usb_unlocked_enable_lpm(udev); |
3287 | } | 3341 | } |
3288 | 3342 | ||
3343 | usb_unlock_port(port_dev); | ||
3344 | |||
3289 | return status; | 3345 | return status; |
3290 | } | 3346 | } |
3291 | 3347 | ||
3292 | #ifdef CONFIG_PM_RUNTIME | 3348 | #ifdef CONFIG_PM_RUNTIME |
3293 | 3349 | ||
3294 | /* caller has locked udev */ | ||
3295 | int usb_remote_wakeup(struct usb_device *udev) | 3350 | int usb_remote_wakeup(struct usb_device *udev) |
3296 | { | 3351 | { |
3297 | int status = 0; | 3352 | int status = 0; |
3298 | 3353 | ||
3354 | usb_lock_device(udev); | ||
3299 | if (udev->state == USB_STATE_SUSPENDED) { | 3355 | if (udev->state == USB_STATE_SUSPENDED) { |
3300 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); | 3356 | dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); |
3301 | status = usb_autoresume_device(udev); | 3357 | status = usb_autoresume_device(udev); |
@@ -3304,9 +3360,59 @@ int usb_remote_wakeup(struct usb_device *udev) | |||
3304 | usb_autosuspend_device(udev); | 3360 | usb_autosuspend_device(udev); |
3305 | } | 3361 | } |
3306 | } | 3362 | } |
3363 | usb_unlock_device(udev); | ||
3307 | return status; | 3364 | return status; |
3308 | } | 3365 | } |
3309 | 3366 | ||
3367 | /* Returns 1 if there was a remote wakeup and a connect status change. */ | ||
3368 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | ||
3369 | u16 portstatus, u16 portchange) | ||
3370 | __must_hold(&port_dev->status_lock) | ||
3371 | { | ||
3372 | struct usb_port *port_dev = hub->ports[port - 1]; | ||
3373 | struct usb_device *hdev; | ||
3374 | struct usb_device *udev; | ||
3375 | int connect_change = 0; | ||
3376 | int ret; | ||
3377 | |||
3378 | hdev = hub->hdev; | ||
3379 | udev = port_dev->child; | ||
3380 | if (!hub_is_superspeed(hdev)) { | ||
3381 | if (!(portchange & USB_PORT_STAT_C_SUSPEND)) | ||
3382 | return 0; | ||
3383 | usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); | ||
3384 | } else { | ||
3385 | if (!udev || udev->state != USB_STATE_SUSPENDED || | ||
3386 | (portstatus & USB_PORT_STAT_LINK_STATE) != | ||
3387 | USB_SS_PORT_LS_U0) | ||
3388 | return 0; | ||
3389 | } | ||
3390 | |||
3391 | if (udev) { | ||
3392 | /* TRSMRCY = 10 msec */ | ||
3393 | msleep(10); | ||
3394 | |||
3395 | usb_unlock_port(port_dev); | ||
3396 | ret = usb_remote_wakeup(udev); | ||
3397 | usb_lock_port(port_dev); | ||
3398 | if (ret < 0) | ||
3399 | connect_change = 1; | ||
3400 | } else { | ||
3401 | ret = -ENODEV; | ||
3402 | hub_port_disable(hub, port, 1); | ||
3403 | } | ||
3404 | dev_dbg(&port_dev->dev, "resume, status %d\n", ret); | ||
3405 | return connect_change; | ||
3406 | } | ||
3407 | |||
3408 | #else | ||
3409 | |||
3410 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | ||
3411 | u16 portstatus, u16 portchange) | ||
3412 | { | ||
3413 | return 0; | ||
3414 | } | ||
3415 | |||
3310 | #endif | 3416 | #endif |
3311 | 3417 | ||
3312 | static int check_ports_changed(struct usb_hub *hub) | 3418 | static int check_ports_changed(struct usb_hub *hub) |
@@ -3337,12 +3443,11 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) | |||
3337 | */ | 3443 | */ |
3338 | hub->wakeup_enabled_descendants = 0; | 3444 | hub->wakeup_enabled_descendants = 0; |
3339 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { | 3445 | for (port1 = 1; port1 <= hdev->maxchild; port1++) { |
3340 | struct usb_device *udev; | 3446 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
3447 | struct usb_device *udev = port_dev->child; | ||
3341 | 3448 | ||
3342 | udev = hub->ports[port1 - 1]->child; | ||
3343 | if (udev && udev->can_submit) { | 3449 | if (udev && udev->can_submit) { |
3344 | dev_warn(&intf->dev, "port %d not suspended yet\n", | 3450 | dev_warn(&port_dev->dev, "not suspended yet\n"); |
3345 | port1); | ||
3346 | if (PMSG_IS_AUTO(msg)) | 3451 | if (PMSG_IS_AUTO(msg)) |
3347 | return -EBUSY; | 3452 | return -EBUSY; |
3348 | } | 3453 | } |
@@ -3861,6 +3966,12 @@ EXPORT_SYMBOL_GPL(usb_disable_ltm); | |||
3861 | void usb_enable_ltm(struct usb_device *udev) { } | 3966 | void usb_enable_ltm(struct usb_device *udev) { } |
3862 | EXPORT_SYMBOL_GPL(usb_enable_ltm); | 3967 | EXPORT_SYMBOL_GPL(usb_enable_ltm); |
3863 | 3968 | ||
3969 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | ||
3970 | u16 portstatus, u16 portchange) | ||
3971 | { | ||
3972 | return 0; | ||
3973 | } | ||
3974 | |||
3864 | #endif /* CONFIG_PM */ | 3975 | #endif /* CONFIG_PM */ |
3865 | 3976 | ||
3866 | 3977 | ||
@@ -3882,9 +3993,10 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm); | |||
3882 | int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) | 3993 | int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) |
3883 | { | 3994 | { |
3884 | int ret; | 3995 | int ret; |
3885 | int total_time, stable_time = 0; | ||
3886 | u16 portchange, portstatus; | 3996 | u16 portchange, portstatus; |
3887 | unsigned connection = 0xffff; | 3997 | unsigned connection = 0xffff; |
3998 | int total_time, stable_time = 0; | ||
3999 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
3888 | 4000 | ||
3889 | for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { | 4001 | for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { |
3890 | ret = hub_port_status(hub, port1, &portstatus, &portchange); | 4002 | ret = hub_port_status(hub, port1, &portstatus, &portchange); |
@@ -3913,9 +4025,8 @@ int hub_port_debounce(struct usb_hub *hub, int port1, bool must_be_connected) | |||
3913 | msleep(HUB_DEBOUNCE_STEP); | 4025 | msleep(HUB_DEBOUNCE_STEP); |
3914 | } | 4026 | } |
3915 | 4027 | ||
3916 | dev_dbg (hub->intfdev, | 4028 | dev_dbg(&port_dev->dev, "debounce total %dms stable %dms status 0x%x\n", |
3917 | "debounce: port %d: total %dms stable %dms status 0x%x\n", | 4029 | total_time, stable_time, portstatus); |
3918 | port1, total_time, stable_time, portstatus); | ||
3919 | 4030 | ||
3920 | if (stable_time < HUB_DEBOUNCE_STABLE) | 4031 | if (stable_time < HUB_DEBOUNCE_STABLE) |
3921 | return -ETIMEDOUT; | 4032 | return -ETIMEDOUT; |
@@ -3974,13 +4085,14 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
3974 | */ | 4085 | */ |
3975 | static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) | 4086 | static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev) |
3976 | { | 4087 | { |
3977 | int connect_type; | 4088 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); |
4089 | int connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; | ||
3978 | 4090 | ||
3979 | if (!udev->usb2_hw_lpm_capable) | 4091 | if (!udev->usb2_hw_lpm_capable) |
3980 | return; | 4092 | return; |
3981 | 4093 | ||
3982 | connect_type = usb_get_hub_port_connect_type(udev->parent, | 4094 | if (hub) |
3983 | udev->portnum); | 4095 | connect_type = hub->ports[udev->portnum - 1]->connect_type; |
3984 | 4096 | ||
3985 | if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || | 4097 | if ((udev->bos->ext_cap->bmAttributes & cpu_to_le32(USB_BESL_SUPPORT)) || |
3986 | connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 4098 | connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
@@ -4008,16 +4120,15 @@ static int hub_enable_device(struct usb_device *udev) | |||
4008 | * Returns device in USB_STATE_ADDRESS, except on error. | 4120 | * Returns device in USB_STATE_ADDRESS, except on error. |
4009 | * | 4121 | * |
4010 | * If this is called for an already-existing device (as part of | 4122 | * If this is called for an already-existing device (as part of |
4011 | * usb_reset_and_verify_device), the caller must own the device lock. For a | 4123 | * usb_reset_and_verify_device), the caller must own the device lock and |
4012 | * newly detected device that is not accessible through any global | 4124 | * the port lock. For a newly detected device that is not accessible |
4013 | * pointers, it's not necessary to lock the device. | 4125 | * through any global pointers, it's not necessary to lock the device, |
4126 | * but it is still necessary to lock the port. | ||
4014 | */ | 4127 | */ |
4015 | static int | 4128 | static int |
4016 | hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | 4129 | hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, |
4017 | int retry_counter) | 4130 | int retry_counter) |
4018 | { | 4131 | { |
4019 | static DEFINE_MUTEX(usb_address0_mutex); | ||
4020 | |||
4021 | struct usb_device *hdev = hub->hdev; | 4132 | struct usb_device *hdev = hub->hdev; |
4022 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | 4133 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
4023 | int i, j, retval; | 4134 | int i, j, retval; |
@@ -4040,7 +4151,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
4040 | if (oldspeed == USB_SPEED_LOW) | 4151 | if (oldspeed == USB_SPEED_LOW) |
4041 | delay = HUB_LONG_RESET_TIME; | 4152 | delay = HUB_LONG_RESET_TIME; |
4042 | 4153 | ||
4043 | mutex_lock(&usb_address0_mutex); | 4154 | mutex_lock(&hdev->bus->usb_address0_mutex); |
4044 | 4155 | ||
4045 | /* Reset the device; full speed may morph to high speed */ | 4156 | /* Reset the device; full speed may morph to high speed */ |
4046 | /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ | 4157 | /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ |
@@ -4317,7 +4428,7 @@ fail: | |||
4317 | hub_port_disable(hub, port1, 0); | 4428 | hub_port_disable(hub, port1, 0); |
4318 | update_devnum(udev, devnum); /* for disconnect processing */ | 4429 | update_devnum(udev, devnum); /* for disconnect processing */ |
4319 | } | 4430 | } |
4320 | mutex_unlock(&usb_address0_mutex); | 4431 | mutex_unlock(&hdev->bus->usb_address0_mutex); |
4321 | return retval; | 4432 | return retval; |
4322 | } | 4433 | } |
4323 | 4434 | ||
@@ -4358,9 +4469,10 @@ hub_power_remaining (struct usb_hub *hub) | |||
4358 | 4469 | ||
4359 | remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; | 4470 | remaining = hdev->bus_mA - hub->descriptor->bHubContrCurrent; |
4360 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { | 4471 | for (port1 = 1; port1 <= hdev->maxchild; ++port1) { |
4361 | struct usb_device *udev = hub->ports[port1 - 1]->child; | 4472 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
4362 | int delta; | 4473 | struct usb_device *udev = port_dev->child; |
4363 | unsigned unit_load; | 4474 | unsigned unit_load; |
4475 | int delta; | ||
4364 | 4476 | ||
4365 | if (!udev) | 4477 | if (!udev) |
4366 | continue; | 4478 | continue; |
@@ -4380,9 +4492,8 @@ hub_power_remaining (struct usb_hub *hub) | |||
4380 | else | 4492 | else |
4381 | delta = 8; | 4493 | delta = 8; |
4382 | if (delta > hub->mA_per_port) | 4494 | if (delta > hub->mA_per_port) |
4383 | dev_warn(&udev->dev, | 4495 | dev_warn(&port_dev->dev, "%dmA is over %umA budget!\n", |
4384 | "%dmA is over %umA budget for port %d!\n", | 4496 | delta, hub->mA_per_port); |
4385 | delta, hub->mA_per_port, port1); | ||
4386 | remaining -= delta; | 4497 | remaining -= delta; |
4387 | } | 4498 | } |
4388 | if (remaining < 0) { | 4499 | if (remaining < 0) { |
@@ -4393,78 +4504,23 @@ hub_power_remaining (struct usb_hub *hub) | |||
4393 | return remaining; | 4504 | return remaining; |
4394 | } | 4505 | } |
4395 | 4506 | ||
4396 | /* Handle physical or logical connection change events. | 4507 | static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, |
4397 | * This routine is called when: | 4508 | u16 portchange) |
4398 | * a port connection-change occurs; | ||
4399 | * a port enable-change occurs (often caused by EMI); | ||
4400 | * usb_reset_and_verify_device() encounters changed descriptors (as from | ||
4401 | * a firmware download) | ||
4402 | * caller already locked the hub | ||
4403 | */ | ||
4404 | static void hub_port_connect_change(struct usb_hub *hub, int port1, | ||
4405 | u16 portstatus, u16 portchange) | ||
4406 | { | 4509 | { |
4407 | struct usb_device *hdev = hub->hdev; | ||
4408 | struct device *hub_dev = hub->intfdev; | ||
4409 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | ||
4410 | unsigned wHubCharacteristics = | ||
4411 | le16_to_cpu(hub->descriptor->wHubCharacteristics); | ||
4412 | struct usb_device *udev; | ||
4413 | int status, i; | 4510 | int status, i; |
4414 | unsigned unit_load; | 4511 | unsigned unit_load; |
4415 | 4512 | struct usb_device *hdev = hub->hdev; | |
4416 | dev_dbg (hub_dev, | 4513 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); |
4417 | "port %d, status %04x, change %04x, %s\n", | 4514 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
4418 | port1, portstatus, portchange, portspeed(hub, portstatus)); | 4515 | struct usb_device *udev = port_dev->child; |
4419 | |||
4420 | if (hub->has_indicators) { | ||
4421 | set_port_led(hub, port1, HUB_LED_AUTO); | ||
4422 | hub->indicator[port1-1] = INDICATOR_AUTO; | ||
4423 | } | ||
4424 | |||
4425 | #ifdef CONFIG_USB_OTG | ||
4426 | /* during HNP, don't repeat the debounce */ | ||
4427 | if (hdev->bus->is_b_host) | ||
4428 | portchange &= ~(USB_PORT_STAT_C_CONNECTION | | ||
4429 | USB_PORT_STAT_C_ENABLE); | ||
4430 | #endif | ||
4431 | |||
4432 | /* Try to resuscitate an existing device */ | ||
4433 | udev = hub->ports[port1 - 1]->child; | ||
4434 | if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && | ||
4435 | udev->state != USB_STATE_NOTATTACHED) { | ||
4436 | usb_lock_device(udev); | ||
4437 | if (portstatus & USB_PORT_STAT_ENABLE) { | ||
4438 | status = 0; /* Nothing to do */ | ||
4439 | |||
4440 | #ifdef CONFIG_PM_RUNTIME | ||
4441 | } else if (udev->state == USB_STATE_SUSPENDED && | ||
4442 | udev->persist_enabled) { | ||
4443 | /* For a suspended device, treat this as a | ||
4444 | * remote wakeup event. | ||
4445 | */ | ||
4446 | status = usb_remote_wakeup(udev); | ||
4447 | #endif | ||
4448 | |||
4449 | } else { | ||
4450 | status = -ENODEV; /* Don't resuscitate */ | ||
4451 | } | ||
4452 | usb_unlock_device(udev); | ||
4453 | |||
4454 | if (status == 0) { | ||
4455 | clear_bit(port1, hub->change_bits); | ||
4456 | return; | ||
4457 | } | ||
4458 | } | ||
4459 | 4516 | ||
4460 | /* Disconnect any existing devices under this port */ | 4517 | /* Disconnect any existing devices under this port */ |
4461 | if (udev) { | 4518 | if (udev) { |
4462 | if (hcd->phy && !hdev->parent && | 4519 | if (hcd->phy && !hdev->parent && |
4463 | !(portstatus & USB_PORT_STAT_CONNECTION)) | 4520 | !(portstatus & USB_PORT_STAT_CONNECTION)) |
4464 | usb_phy_notify_disconnect(hcd->phy, udev->speed); | 4521 | usb_phy_notify_disconnect(hcd->phy, udev->speed); |
4465 | usb_disconnect(&hub->ports[port1 - 1]->child); | 4522 | usb_disconnect(&port_dev->child); |
4466 | } | 4523 | } |
4467 | clear_bit(port1, hub->change_bits); | ||
4468 | 4524 | ||
4469 | /* We can forget about a "removed" device when there's a physical | 4525 | /* We can forget about a "removed" device when there's a physical |
4470 | * disconnect or the connect status changes. | 4526 | * disconnect or the connect status changes. |
@@ -4478,8 +4534,8 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4478 | status = hub_port_debounce_be_stable(hub, port1); | 4534 | status = hub_port_debounce_be_stable(hub, port1); |
4479 | if (status < 0) { | 4535 | if (status < 0) { |
4480 | if (status != -ENODEV && printk_ratelimit()) | 4536 | if (status != -ENODEV && printk_ratelimit()) |
4481 | dev_err(hub_dev, "connect-debounce failed, " | 4537 | dev_err(&port_dev->dev, |
4482 | "port %d disabled\n", port1); | 4538 | "connect-debounce failed\n"); |
4483 | portstatus &= ~USB_PORT_STAT_CONNECTION; | 4539 | portstatus &= ~USB_PORT_STAT_CONNECTION; |
4484 | } else { | 4540 | } else { |
4485 | portstatus = status; | 4541 | portstatus = status; |
@@ -4493,7 +4549,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4493 | test_bit(port1, hub->removed_bits)) { | 4549 | test_bit(port1, hub->removed_bits)) { |
4494 | 4550 | ||
4495 | /* maybe switch power back on (e.g. root hub was reset) */ | 4551 | /* maybe switch power back on (e.g. root hub was reset) */ |
4496 | if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 | 4552 | if (hub_is_port_power_switchable(hub) |
4497 | && !port_is_power_on(hub, portstatus)) | 4553 | && !port_is_power_on(hub, portstatus)) |
4498 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); | 4554 | set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); |
4499 | 4555 | ||
@@ -4514,9 +4570,8 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4514 | */ | 4570 | */ |
4515 | udev = usb_alloc_dev(hdev, hdev->bus, port1); | 4571 | udev = usb_alloc_dev(hdev, hdev->bus, port1); |
4516 | if (!udev) { | 4572 | if (!udev) { |
4517 | dev_err (hub_dev, | 4573 | dev_err(&port_dev->dev, |
4518 | "couldn't allocate port %d usb_device\n", | 4574 | "couldn't allocate usb_device\n"); |
4519 | port1); | ||
4520 | goto done; | 4575 | goto done; |
4521 | } | 4576 | } |
4522 | 4577 | ||
@@ -4538,7 +4593,9 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4538 | } | 4593 | } |
4539 | 4594 | ||
4540 | /* reset (non-USB 3.0 devices) and get descriptor */ | 4595 | /* reset (non-USB 3.0 devices) and get descriptor */ |
4596 | usb_lock_port(port_dev); | ||
4541 | status = hub_port_init(hub, udev, port1, i); | 4597 | status = hub_port_init(hub, udev, port1, i); |
4598 | usb_unlock_port(port_dev); | ||
4542 | if (status < 0) | 4599 | if (status < 0) |
4543 | goto loop; | 4600 | goto loop; |
4544 | 4601 | ||
@@ -4590,6 +4647,8 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4590 | */ | 4647 | */ |
4591 | status = 0; | 4648 | status = 0; |
4592 | 4649 | ||
4650 | mutex_lock(&usb_port_peer_mutex); | ||
4651 | |||
4593 | /* We mustn't add new devices if the parent hub has | 4652 | /* We mustn't add new devices if the parent hub has |
4594 | * been disconnected; we would race with the | 4653 | * been disconnected; we would race with the |
4595 | * recursively_mark_NOTATTACHED() routine. | 4654 | * recursively_mark_NOTATTACHED() routine. |
@@ -4598,16 +4657,19 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4598 | if (hdev->state == USB_STATE_NOTATTACHED) | 4657 | if (hdev->state == USB_STATE_NOTATTACHED) |
4599 | status = -ENOTCONN; | 4658 | status = -ENOTCONN; |
4600 | else | 4659 | else |
4601 | hub->ports[port1 - 1]->child = udev; | 4660 | port_dev->child = udev; |
4602 | spin_unlock_irq(&device_state_lock); | 4661 | spin_unlock_irq(&device_state_lock); |
4662 | mutex_unlock(&usb_port_peer_mutex); | ||
4603 | 4663 | ||
4604 | /* Run it through the hoops (find a driver, etc) */ | 4664 | /* Run it through the hoops (find a driver, etc) */ |
4605 | if (!status) { | 4665 | if (!status) { |
4606 | status = usb_new_device(udev); | 4666 | status = usb_new_device(udev); |
4607 | if (status) { | 4667 | if (status) { |
4668 | mutex_lock(&usb_port_peer_mutex); | ||
4608 | spin_lock_irq(&device_state_lock); | 4669 | spin_lock_irq(&device_state_lock); |
4609 | hub->ports[port1 - 1]->child = NULL; | 4670 | port_dev->child = NULL; |
4610 | spin_unlock_irq(&device_state_lock); | 4671 | spin_unlock_irq(&device_state_lock); |
4672 | mutex_unlock(&usb_port_peer_mutex); | ||
4611 | } | 4673 | } |
4612 | } | 4674 | } |
4613 | 4675 | ||
@@ -4616,7 +4678,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
4616 | 4678 | ||
4617 | status = hub_power_remaining(hub); | 4679 | status = hub_power_remaining(hub); |
4618 | if (status) | 4680 | if (status) |
4619 | dev_dbg(hub_dev, "%dmA power budget left\n", status); | 4681 | dev_dbg(hub->intfdev, "%dmA power budget left\n", status); |
4620 | 4682 | ||
4621 | return; | 4683 | return; |
4622 | 4684 | ||
@@ -4634,56 +4696,200 @@ loop: | |||
4634 | !hcd->driver->port_handed_over || | 4696 | !hcd->driver->port_handed_over || |
4635 | !(hcd->driver->port_handed_over)(hcd, port1)) { | 4697 | !(hcd->driver->port_handed_over)(hcd, port1)) { |
4636 | if (status != -ENOTCONN && status != -ENODEV) | 4698 | if (status != -ENOTCONN && status != -ENODEV) |
4637 | dev_err(hub_dev, "unable to enumerate USB device on port %d\n", | 4699 | dev_err(&port_dev->dev, |
4638 | port1); | 4700 | "unable to enumerate USB device\n"); |
4639 | } | 4701 | } |
4640 | 4702 | ||
4641 | done: | 4703 | done: |
4642 | hub_port_disable(hub, port1, 1); | 4704 | hub_port_disable(hub, port1, 1); |
4643 | if (hcd->driver->relinquish_port && !hub->hdev->parent) | 4705 | if (hcd->driver->relinquish_port && !hub->hdev->parent) |
4644 | hcd->driver->relinquish_port(hcd, port1); | 4706 | hcd->driver->relinquish_port(hcd, port1); |
4707 | |||
4645 | } | 4708 | } |
4646 | 4709 | ||
4647 | /* Returns 1 if there was a remote wakeup and a connect status change. */ | 4710 | /* Handle physical or logical connection change events. |
4648 | static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port, | 4711 | * This routine is called when: |
4649 | u16 portstatus, u16 portchange) | 4712 | * a port connection-change occurs; |
4713 | * a port enable-change occurs (often caused by EMI); | ||
4714 | * usb_reset_and_verify_device() encounters changed descriptors (as from | ||
4715 | * a firmware download) | ||
4716 | * caller already locked the hub | ||
4717 | */ | ||
4718 | static void hub_port_connect_change(struct usb_hub *hub, int port1, | ||
4719 | u16 portstatus, u16 portchange) | ||
4720 | __must_hold(&port_dev->status_lock) | ||
4650 | { | 4721 | { |
4651 | struct usb_device *hdev; | 4722 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
4652 | struct usb_device *udev; | 4723 | struct usb_device *udev = port_dev->child; |
4653 | int connect_change = 0; | 4724 | int status = -ENODEV; |
4654 | int ret; | ||
4655 | 4725 | ||
4656 | hdev = hub->hdev; | 4726 | dev_dbg(&port_dev->dev, "status %04x, change %04x, %s\n", portstatus, |
4657 | udev = hub->ports[port - 1]->child; | 4727 | portchange, portspeed(hub, portstatus)); |
4658 | if (!hub_is_superspeed(hdev)) { | 4728 | |
4659 | if (!(portchange & USB_PORT_STAT_C_SUSPEND)) | 4729 | if (hub->has_indicators) { |
4660 | return 0; | 4730 | set_port_led(hub, port1, HUB_LED_AUTO); |
4661 | usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND); | 4731 | hub->indicator[port1-1] = INDICATOR_AUTO; |
4662 | } else { | ||
4663 | if (!udev || udev->state != USB_STATE_SUSPENDED || | ||
4664 | (portstatus & USB_PORT_STAT_LINK_STATE) != | ||
4665 | USB_SS_PORT_LS_U0) | ||
4666 | return 0; | ||
4667 | } | 4732 | } |
4668 | 4733 | ||
4669 | if (udev) { | 4734 | #ifdef CONFIG_USB_OTG |
4670 | /* TRSMRCY = 10 msec */ | 4735 | /* during HNP, don't repeat the debounce */ |
4671 | msleep(10); | 4736 | if (hub->hdev->bus->is_b_host) |
4737 | portchange &= ~(USB_PORT_STAT_C_CONNECTION | | ||
4738 | USB_PORT_STAT_C_ENABLE); | ||
4739 | #endif | ||
4740 | |||
4741 | /* Try to resuscitate an existing device */ | ||
4742 | if ((portstatus & USB_PORT_STAT_CONNECTION) && udev && | ||
4743 | udev->state != USB_STATE_NOTATTACHED) { | ||
4744 | if (portstatus & USB_PORT_STAT_ENABLE) { | ||
4745 | status = 0; /* Nothing to do */ | ||
4746 | #ifdef CONFIG_PM_RUNTIME | ||
4747 | } else if (udev->state == USB_STATE_SUSPENDED && | ||
4748 | udev->persist_enabled) { | ||
4749 | /* For a suspended device, treat this as a | ||
4750 | * remote wakeup event. | ||
4751 | */ | ||
4752 | usb_unlock_port(port_dev); | ||
4753 | status = usb_remote_wakeup(udev); | ||
4754 | usb_lock_port(port_dev); | ||
4755 | #endif | ||
4756 | } else { | ||
4757 | /* Don't resuscitate */; | ||
4758 | } | ||
4759 | } | ||
4760 | clear_bit(port1, hub->change_bits); | ||
4761 | |||
4762 | /* successfully revalidated the connection */ | ||
4763 | if (status == 0) | ||
4764 | return; | ||
4765 | |||
4766 | usb_unlock_port(port_dev); | ||
4767 | hub_port_connect(hub, port1, portstatus, portchange); | ||
4768 | usb_lock_port(port_dev); | ||
4769 | } | ||
4770 | |||
4771 | static void port_event(struct usb_hub *hub, int port1) | ||
4772 | __must_hold(&port_dev->status_lock) | ||
4773 | { | ||
4774 | int connect_change, reset_device = 0; | ||
4775 | struct usb_port *port_dev = hub->ports[port1 - 1]; | ||
4776 | struct usb_device *udev = port_dev->child; | ||
4777 | struct usb_device *hdev = hub->hdev; | ||
4778 | u16 portstatus, portchange; | ||
4779 | |||
4780 | connect_change = test_bit(port1, hub->change_bits); | ||
4781 | clear_bit(port1, hub->event_bits); | ||
4782 | clear_bit(port1, hub->wakeup_bits); | ||
4783 | |||
4784 | if (hub_port_status(hub, port1, &portstatus, &portchange) < 0) | ||
4785 | return; | ||
4786 | |||
4787 | if (portchange & USB_PORT_STAT_C_CONNECTION) { | ||
4788 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION); | ||
4789 | connect_change = 1; | ||
4790 | } | ||
4791 | |||
4792 | if (portchange & USB_PORT_STAT_C_ENABLE) { | ||
4793 | if (!connect_change) | ||
4794 | dev_dbg(&port_dev->dev, "enable change, status %08x\n", | ||
4795 | portstatus); | ||
4796 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); | ||
4797 | |||
4798 | /* | ||
4799 | * EM interference sometimes causes badly shielded USB devices | ||
4800 | * to be shutdown by the hub, this hack enables them again. | ||
4801 | * Works at least with mouse driver. | ||
4802 | */ | ||
4803 | if (!(portstatus & USB_PORT_STAT_ENABLE) | ||
4804 | && !connect_change && udev) { | ||
4805 | dev_err(&port_dev->dev, "disabled by hub (EMI?), re-enabling...\n"); | ||
4806 | connect_change = 1; | ||
4807 | } | ||
4808 | } | ||
4809 | |||
4810 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { | ||
4811 | u16 status = 0, unused; | ||
4812 | |||
4813 | dev_dbg(&port_dev->dev, "over-current change\n"); | ||
4814 | usb_clear_port_feature(hdev, port1, | ||
4815 | USB_PORT_FEAT_C_OVER_CURRENT); | ||
4816 | msleep(100); /* Cool down */ | ||
4817 | hub_power_on(hub, true); | ||
4818 | hub_port_status(hub, port1, &status, &unused); | ||
4819 | if (status & USB_PORT_STAT_OVERCURRENT) | ||
4820 | dev_err(&port_dev->dev, "over-current condition\n"); | ||
4821 | } | ||
4822 | |||
4823 | if (portchange & USB_PORT_STAT_C_RESET) { | ||
4824 | dev_dbg(&port_dev->dev, "reset change\n"); | ||
4825 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_RESET); | ||
4826 | } | ||
4827 | if ((portchange & USB_PORT_STAT_C_BH_RESET) | ||
4828 | && hub_is_superspeed(hdev)) { | ||
4829 | dev_dbg(&port_dev->dev, "warm reset change\n"); | ||
4830 | usb_clear_port_feature(hdev, port1, | ||
4831 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
4832 | } | ||
4833 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
4834 | dev_dbg(&port_dev->dev, "link state change\n"); | ||
4835 | usb_clear_port_feature(hdev, port1, | ||
4836 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
4837 | } | ||
4838 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | ||
4839 | dev_warn(&port_dev->dev, "config error\n"); | ||
4840 | usb_clear_port_feature(hdev, port1, | ||
4841 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | ||
4842 | } | ||
4843 | |||
4844 | /* skip port actions that require the port to be powered on */ | ||
4845 | if (!pm_runtime_active(&port_dev->dev)) | ||
4846 | return; | ||
4672 | 4847 | ||
4848 | if (hub_handle_remote_wakeup(hub, port1, portstatus, portchange)) | ||
4849 | connect_change = 1; | ||
4850 | |||
4851 | /* | ||
4852 | * Warm reset a USB3 protocol port if it's in | ||
4853 | * SS.Inactive state. | ||
4854 | */ | ||
4855 | if (hub_port_warm_reset_required(hub, portstatus)) { | ||
4856 | dev_dbg(&port_dev->dev, "do warm reset\n"); | ||
4857 | if (!udev || !(portstatus & USB_PORT_STAT_CONNECTION) | ||
4858 | || udev->state == USB_STATE_NOTATTACHED) { | ||
4859 | if (hub_port_reset(hub, port1, NULL, | ||
4860 | HUB_BH_RESET_TIME, true) < 0) | ||
4861 | hub_port_disable(hub, port1, 1); | ||
4862 | } else | ||
4863 | reset_device = 1; | ||
4864 | } | ||
4865 | |||
4866 | /* | ||
4867 | * On disconnect USB3 protocol ports transit from U0 to | ||
4868 | * SS.Inactive to Rx.Detect. If this happens a warm- | ||
4869 | * reset is not needed, but a (re)connect may happen | ||
4870 | * before khubd runs and sees the disconnect, and the | ||
4871 | * device may be an unknown state. | ||
4872 | * | ||
4873 | * If the port went through SS.Inactive without khubd | ||
4874 | * seeing it the C_LINK_STATE change flag will be set, | ||
4875 | * and we reset the dev to put it in a known state. | ||
4876 | */ | ||
4877 | if (reset_device || (udev && hub_is_superspeed(hub->hdev) | ||
4878 | && (portchange & USB_PORT_STAT_C_LINK_STATE) | ||
4879 | && (portstatus & USB_PORT_STAT_CONNECTION))) { | ||
4880 | usb_unlock_port(port_dev); | ||
4673 | usb_lock_device(udev); | 4881 | usb_lock_device(udev); |
4674 | ret = usb_remote_wakeup(udev); | 4882 | usb_reset_device(udev); |
4675 | usb_unlock_device(udev); | 4883 | usb_unlock_device(udev); |
4676 | if (ret < 0) | 4884 | usb_lock_port(port_dev); |
4677 | connect_change = 1; | 4885 | connect_change = 0; |
4678 | } else { | ||
4679 | ret = -ENODEV; | ||
4680 | hub_port_disable(hub, port, 1); | ||
4681 | } | 4886 | } |
4682 | dev_dbg(hub->intfdev, "resume on port %d, status %d\n", | 4887 | |
4683 | port, ret); | 4888 | if (connect_change) |
4684 | return connect_change; | 4889 | hub_port_connect_change(hub, port1, portstatus, portchange); |
4685 | } | 4890 | } |
4686 | 4891 | ||
4892 | |||
4687 | static void hub_events(void) | 4893 | static void hub_events(void) |
4688 | { | 4894 | { |
4689 | struct list_head *tmp; | 4895 | struct list_head *tmp; |
@@ -4693,10 +4899,7 @@ static void hub_events(void) | |||
4693 | struct device *hub_dev; | 4899 | struct device *hub_dev; |
4694 | u16 hubstatus; | 4900 | u16 hubstatus; |
4695 | u16 hubchange; | 4901 | u16 hubchange; |
4696 | u16 portstatus; | ||
4697 | u16 portchange; | ||
4698 | int i, ret; | 4902 | int i, ret; |
4699 | int connect_change, wakeup_change; | ||
4700 | 4903 | ||
4701 | /* | 4904 | /* |
4702 | * We restart the list every time to avoid a deadlock with | 4905 | * We restart the list every time to avoid a deadlock with |
@@ -4770,146 +4973,28 @@ static void hub_events(void) | |||
4770 | 4973 | ||
4771 | /* deal with port status changes */ | 4974 | /* deal with port status changes */ |
4772 | for (i = 1; i <= hdev->maxchild; i++) { | 4975 | for (i = 1; i <= hdev->maxchild; i++) { |
4773 | struct usb_device *udev = hub->ports[i - 1]->child; | 4976 | struct usb_port *port_dev = hub->ports[i - 1]; |
4774 | |||
4775 | if (test_bit(i, hub->busy_bits)) | ||
4776 | continue; | ||
4777 | connect_change = test_bit(i, hub->change_bits); | ||
4778 | wakeup_change = test_and_clear_bit(i, hub->wakeup_bits); | ||
4779 | if (!test_and_clear_bit(i, hub->event_bits) && | ||
4780 | !connect_change && !wakeup_change) | ||
4781 | continue; | ||
4782 | |||
4783 | ret = hub_port_status(hub, i, | ||
4784 | &portstatus, &portchange); | ||
4785 | if (ret < 0) | ||
4786 | continue; | ||
4787 | |||
4788 | if (portchange & USB_PORT_STAT_C_CONNECTION) { | ||
4789 | usb_clear_port_feature(hdev, i, | ||
4790 | USB_PORT_FEAT_C_CONNECTION); | ||
4791 | connect_change = 1; | ||
4792 | } | ||
4793 | |||
4794 | if (portchange & USB_PORT_STAT_C_ENABLE) { | ||
4795 | if (!connect_change) | ||
4796 | dev_dbg (hub_dev, | ||
4797 | "port %d enable change, " | ||
4798 | "status %08x\n", | ||
4799 | i, portstatus); | ||
4800 | usb_clear_port_feature(hdev, i, | ||
4801 | USB_PORT_FEAT_C_ENABLE); | ||
4802 | 4977 | ||
4978 | if (test_bit(i, hub->event_bits) | ||
4979 | || test_bit(i, hub->change_bits) | ||
4980 | || test_bit(i, hub->wakeup_bits)) { | ||
4803 | /* | 4981 | /* |
4804 | * EM interference sometimes causes badly | 4982 | * The get_noresume and barrier ensure that if |
4805 | * shielded USB devices to be shutdown by | 4983 | * the port was in the process of resuming, we |
4806 | * the hub, this hack enables them again. | 4984 | * flush that work and keep the port active for |
4807 | * Works at least with mouse driver. | 4985 | * the duration of the port_event(). However, |
4986 | * if the port is runtime pm suspended | ||
4987 | * (powered-off), we leave it in that state, run | ||
4988 | * an abbreviated port_event(), and move on. | ||
4808 | */ | 4989 | */ |
4809 | if (!(portstatus & USB_PORT_STAT_ENABLE) | 4990 | pm_runtime_get_noresume(&port_dev->dev); |
4810 | && !connect_change | 4991 | pm_runtime_barrier(&port_dev->dev); |
4811 | && hub->ports[i - 1]->child) { | 4992 | usb_lock_port(port_dev); |
4812 | dev_err (hub_dev, | 4993 | port_event(hub, i); |
4813 | "port %i " | 4994 | usb_unlock_port(port_dev); |
4814 | "disabled by hub (EMI?), " | 4995 | pm_runtime_put_sync(&port_dev->dev); |
4815 | "re-enabling...\n", | ||
4816 | i); | ||
4817 | connect_change = 1; | ||
4818 | } | ||
4819 | } | ||
4820 | |||
4821 | if (hub_handle_remote_wakeup(hub, i, | ||
4822 | portstatus, portchange)) | ||
4823 | connect_change = 1; | ||
4824 | |||
4825 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { | ||
4826 | u16 status = 0; | ||
4827 | u16 unused; | ||
4828 | |||
4829 | dev_dbg(hub_dev, "over-current change on port " | ||
4830 | "%d\n", i); | ||
4831 | usb_clear_port_feature(hdev, i, | ||
4832 | USB_PORT_FEAT_C_OVER_CURRENT); | ||
4833 | msleep(100); /* Cool down */ | ||
4834 | hub_power_on(hub, true); | ||
4835 | hub_port_status(hub, i, &status, &unused); | ||
4836 | if (status & USB_PORT_STAT_OVERCURRENT) | ||
4837 | dev_err(hub_dev, "over-current " | ||
4838 | "condition on port %d\n", i); | ||
4839 | } | ||
4840 | |||
4841 | if (portchange & USB_PORT_STAT_C_RESET) { | ||
4842 | dev_dbg (hub_dev, | ||
4843 | "reset change on port %d\n", | ||
4844 | i); | ||
4845 | usb_clear_port_feature(hdev, i, | ||
4846 | USB_PORT_FEAT_C_RESET); | ||
4847 | } | ||
4848 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | ||
4849 | hub_is_superspeed(hub->hdev)) { | ||
4850 | dev_dbg(hub_dev, | ||
4851 | "warm reset change on port %d\n", | ||
4852 | i); | ||
4853 | usb_clear_port_feature(hdev, i, | ||
4854 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
4855 | } | ||
4856 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
4857 | usb_clear_port_feature(hub->hdev, i, | ||
4858 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
4859 | } | ||
4860 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | ||
4861 | dev_warn(hub_dev, | ||
4862 | "config error on port %d\n", | ||
4863 | i); | ||
4864 | usb_clear_port_feature(hub->hdev, i, | ||
4865 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | ||
4866 | } | 4996 | } |
4867 | 4997 | } | |
4868 | /* Warm reset a USB3 protocol port if it's in | ||
4869 | * SS.Inactive state. | ||
4870 | */ | ||
4871 | if (hub_port_warm_reset_required(hub, portstatus)) { | ||
4872 | int status; | ||
4873 | |||
4874 | dev_dbg(hub_dev, "warm reset port %d\n", i); | ||
4875 | if (!udev || | ||
4876 | !(portstatus & USB_PORT_STAT_CONNECTION) || | ||
4877 | udev->state == USB_STATE_NOTATTACHED) { | ||
4878 | status = hub_port_reset(hub, i, | ||
4879 | NULL, HUB_BH_RESET_TIME, | ||
4880 | true); | ||
4881 | if (status < 0) | ||
4882 | hub_port_disable(hub, i, 1); | ||
4883 | } else { | ||
4884 | usb_lock_device(udev); | ||
4885 | status = usb_reset_device(udev); | ||
4886 | usb_unlock_device(udev); | ||
4887 | connect_change = 0; | ||
4888 | } | ||
4889 | /* | ||
4890 | * On disconnect USB3 protocol ports transit from U0 to | ||
4891 | * SS.Inactive to Rx.Detect. If this happens a warm- | ||
4892 | * reset is not needed, but a (re)connect may happen | ||
4893 | * before khubd runs and sees the disconnect, and the | ||
4894 | * device may be an unknown state. | ||
4895 | * | ||
4896 | * If the port went through SS.Inactive without khubd | ||
4897 | * seeing it the C_LINK_STATE change flag will be set, | ||
4898 | * and we reset the dev to put it in a known state. | ||
4899 | */ | ||
4900 | } else if (udev && hub_is_superspeed(hub->hdev) && | ||
4901 | (portchange & USB_PORT_STAT_C_LINK_STATE) && | ||
4902 | (portstatus & USB_PORT_STAT_CONNECTION)) { | ||
4903 | usb_lock_device(udev); | ||
4904 | usb_reset_device(udev); | ||
4905 | usb_unlock_device(udev); | ||
4906 | connect_change = 0; | ||
4907 | } | ||
4908 | |||
4909 | if (connect_change) | ||
4910 | hub_port_connect_change(hub, i, | ||
4911 | portstatus, portchange); | ||
4912 | } /* end for i */ | ||
4913 | 4998 | ||
4914 | /* deal with hub status changes */ | 4999 | /* deal with hub status changes */ |
4915 | if (test_and_clear_bit(0, hub->event_bits) == 0) | 5000 | if (test_and_clear_bit(0, hub->event_bits) == 0) |
@@ -5144,15 +5229,18 @@ static int descriptors_changed(struct usb_device *udev, | |||
5144 | * if the reset wasn't even attempted. | 5229 | * if the reset wasn't even attempted. |
5145 | * | 5230 | * |
5146 | * Note: | 5231 | * Note: |
5147 | * The caller must own the device lock. For example, it's safe to use | 5232 | * The caller must own the device lock and the port lock, the latter is |
5148 | * this from a driver probe() routine after downloading new firmware. | 5233 | * taken by usb_reset_device(). For example, it's safe to use |
5149 | * For calls that might not occur during probe(), drivers should lock | 5234 | * usb_reset_device() from a driver probe() routine after downloading |
5150 | * the device using usb_lock_device_for_reset(). | 5235 | * new firmware. For calls that might not occur during probe(), drivers |
5236 | * should lock the device using usb_lock_device_for_reset(). | ||
5151 | * | 5237 | * |
5152 | * Locking exception: This routine may also be called from within an | 5238 | * Locking exception: This routine may also be called from within an |
5153 | * autoresume handler. Such usage won't conflict with other tasks | 5239 | * autoresume handler. Such usage won't conflict with other tasks |
5154 | * holding the device lock because these tasks should always call | 5240 | * holding the device lock because these tasks should always call |
5155 | * usb_autopm_resume_device(), thereby preventing any unwanted autoresume. | 5241 | * usb_autopm_resume_device(), thereby preventing any unwanted |
5242 | * autoresume. The autoresume handler is expected to have already | ||
5243 | * acquired the port lock before calling this routine. | ||
5156 | */ | 5244 | */ |
5157 | static int usb_reset_and_verify_device(struct usb_device *udev) | 5245 | static int usb_reset_and_verify_device(struct usb_device *udev) |
5158 | { | 5246 | { |
@@ -5171,11 +5259,9 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5171 | return -EINVAL; | 5259 | return -EINVAL; |
5172 | } | 5260 | } |
5173 | 5261 | ||
5174 | if (!parent_hdev) { | 5262 | if (!parent_hdev) |
5175 | /* this requires hcd-specific logic; see ohci_restart() */ | ||
5176 | dev_dbg(&udev->dev, "%s for root hub!\n", __func__); | ||
5177 | return -EISDIR; | 5263 | return -EISDIR; |
5178 | } | 5264 | |
5179 | parent_hub = usb_hub_to_struct_hub(parent_hdev); | 5265 | parent_hub = usb_hub_to_struct_hub(parent_hdev); |
5180 | 5266 | ||
5181 | /* Disable USB2 hardware LPM. | 5267 | /* Disable USB2 hardware LPM. |
@@ -5204,7 +5290,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5204 | goto re_enumerate; | 5290 | goto re_enumerate; |
5205 | } | 5291 | } |
5206 | 5292 | ||
5207 | set_bit(port1, parent_hub->busy_bits); | ||
5208 | for (i = 0; i < SET_CONFIG_TRIES; ++i) { | 5293 | for (i = 0; i < SET_CONFIG_TRIES; ++i) { |
5209 | 5294 | ||
5210 | /* ep0 maxpacket size may change; let the HCD know about it. | 5295 | /* ep0 maxpacket size may change; let the HCD know about it. |
@@ -5214,7 +5299,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
5214 | if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) | 5299 | if (ret >= 0 || ret == -ENOTCONN || ret == -ENODEV) |
5215 | break; | 5300 | break; |
5216 | } | 5301 | } |
5217 | clear_bit(port1, parent_hub->busy_bits); | ||
5218 | 5302 | ||
5219 | if (ret < 0) | 5303 | if (ret < 0) |
5220 | goto re_enumerate; | 5304 | goto re_enumerate; |
@@ -5335,7 +5419,9 @@ int usb_reset_device(struct usb_device *udev) | |||
5335 | int ret; | 5419 | int ret; |
5336 | int i; | 5420 | int i; |
5337 | unsigned int noio_flag; | 5421 | unsigned int noio_flag; |
5422 | struct usb_port *port_dev; | ||
5338 | struct usb_host_config *config = udev->actconfig; | 5423 | struct usb_host_config *config = udev->actconfig; |
5424 | struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent); | ||
5339 | 5425 | ||
5340 | if (udev->state == USB_STATE_NOTATTACHED || | 5426 | if (udev->state == USB_STATE_NOTATTACHED || |
5341 | udev->state == USB_STATE_SUSPENDED) { | 5427 | udev->state == USB_STATE_SUSPENDED) { |
@@ -5344,6 +5430,14 @@ int usb_reset_device(struct usb_device *udev) | |||
5344 | return -EINVAL; | 5430 | return -EINVAL; |
5345 | } | 5431 | } |
5346 | 5432 | ||
5433 | if (!udev->parent) { | ||
5434 | /* this requires hcd-specific logic; see ohci_restart() */ | ||
5435 | dev_dbg(&udev->dev, "%s for root hub!\n", __func__); | ||
5436 | return -EISDIR; | ||
5437 | } | ||
5438 | |||
5439 | port_dev = hub->ports[udev->portnum - 1]; | ||
5440 | |||
5347 | /* | 5441 | /* |
5348 | * Don't allocate memory with GFP_KERNEL in current | 5442 | * Don't allocate memory with GFP_KERNEL in current |
5349 | * context to avoid possible deadlock if usb mass | 5443 | * context to avoid possible deadlock if usb mass |
@@ -5377,7 +5471,9 @@ int usb_reset_device(struct usb_device *udev) | |||
5377 | } | 5471 | } |
5378 | } | 5472 | } |
5379 | 5473 | ||
5474 | usb_lock_port(port_dev); | ||
5380 | ret = usb_reset_and_verify_device(udev); | 5475 | ret = usb_reset_and_verify_device(udev); |
5476 | usb_unlock_port(port_dev); | ||
5381 | 5477 | ||
5382 | if (config) { | 5478 | if (config) { |
5383 | for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { | 5479 | for (i = config->desc.bNumInterfaces - 1; i >= 0; --i) { |
@@ -5472,56 +5568,26 @@ struct usb_device *usb_hub_find_child(struct usb_device *hdev, | |||
5472 | } | 5568 | } |
5473 | EXPORT_SYMBOL_GPL(usb_hub_find_child); | 5569 | EXPORT_SYMBOL_GPL(usb_hub_find_child); |
5474 | 5570 | ||
5475 | /** | ||
5476 | * usb_set_hub_port_connect_type - set hub port connect type. | ||
5477 | * @hdev: USB device belonging to the usb hub | ||
5478 | * @port1: port num of the port | ||
5479 | * @type: connect type of the port | ||
5480 | */ | ||
5481 | void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, | ||
5482 | enum usb_port_connect_type type) | ||
5483 | { | ||
5484 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5485 | |||
5486 | if (hub) | ||
5487 | hub->ports[port1 - 1]->connect_type = type; | ||
5488 | } | ||
5489 | |||
5490 | /** | ||
5491 | * usb_get_hub_port_connect_type - Get the port's connect type | ||
5492 | * @hdev: USB device belonging to the usb hub | ||
5493 | * @port1: port num of the port | ||
5494 | * | ||
5495 | * Return: The connect type of the port if successful. Or | ||
5496 | * USB_PORT_CONNECT_TYPE_UNKNOWN if input params are invalid. | ||
5497 | */ | ||
5498 | enum usb_port_connect_type | ||
5499 | usb_get_hub_port_connect_type(struct usb_device *hdev, int port1) | ||
5500 | { | ||
5501 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5502 | |||
5503 | if (!hub) | ||
5504 | return USB_PORT_CONNECT_TYPE_UNKNOWN; | ||
5505 | |||
5506 | return hub->ports[port1 - 1]->connect_type; | ||
5507 | } | ||
5508 | |||
5509 | void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | 5571 | void usb_hub_adjust_deviceremovable(struct usb_device *hdev, |
5510 | struct usb_hub_descriptor *desc) | 5572 | struct usb_hub_descriptor *desc) |
5511 | { | 5573 | { |
5574 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
5512 | enum usb_port_connect_type connect_type; | 5575 | enum usb_port_connect_type connect_type; |
5513 | int i; | 5576 | int i; |
5514 | 5577 | ||
5578 | if (!hub) | ||
5579 | return; | ||
5580 | |||
5515 | if (!hub_is_superspeed(hdev)) { | 5581 | if (!hub_is_superspeed(hdev)) { |
5516 | for (i = 1; i <= hdev->maxchild; i++) { | 5582 | for (i = 1; i <= hdev->maxchild; i++) { |
5517 | connect_type = usb_get_hub_port_connect_type(hdev, i); | 5583 | struct usb_port *port_dev = hub->ports[i - 1]; |
5518 | 5584 | ||
5585 | connect_type = port_dev->connect_type; | ||
5519 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 5586 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
5520 | u8 mask = 1 << (i%8); | 5587 | u8 mask = 1 << (i%8); |
5521 | 5588 | ||
5522 | if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { | 5589 | if (!(desc->u.hs.DeviceRemovable[i/8] & mask)) { |
5523 | dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", | 5590 | dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); |
5524 | i); | ||
5525 | desc->u.hs.DeviceRemovable[i/8] |= mask; | 5591 | desc->u.hs.DeviceRemovable[i/8] |= mask; |
5526 | } | 5592 | } |
5527 | } | 5593 | } |
@@ -5530,14 +5596,14 @@ void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | |||
5530 | u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); | 5596 | u16 port_removable = le16_to_cpu(desc->u.ss.DeviceRemovable); |
5531 | 5597 | ||
5532 | for (i = 1; i <= hdev->maxchild; i++) { | 5598 | for (i = 1; i <= hdev->maxchild; i++) { |
5533 | connect_type = usb_get_hub_port_connect_type(hdev, i); | 5599 | struct usb_port *port_dev = hub->ports[i - 1]; |
5534 | 5600 | ||
5601 | connect_type = port_dev->connect_type; | ||
5535 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { | 5602 | if (connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) { |
5536 | u16 mask = 1 << i; | 5603 | u16 mask = 1 << i; |
5537 | 5604 | ||
5538 | if (!(port_removable & mask)) { | 5605 | if (!(port_removable & mask)) { |
5539 | dev_dbg(&hdev->dev, "usb port%d's DeviceRemovable is changed to 1 according to platform information.\n", | 5606 | dev_dbg(&port_dev->dev, "DeviceRemovable is changed to 1 according to platform information.\n"); |
5540 | i); | ||
5541 | port_removable |= mask; | 5607 | port_removable |= mask; |
5542 | } | 5608 | } |
5543 | } | 5609 | } |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 33bcb2c6f90a..0a7cdc0ef0a9 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h | |||
@@ -45,12 +45,13 @@ struct usb_hub { | |||
45 | unsigned long event_bits[1]; /* status change bitmask */ | 45 | unsigned long event_bits[1]; /* status change bitmask */ |
46 | unsigned long change_bits[1]; /* ports with logical connect | 46 | unsigned long change_bits[1]; /* ports with logical connect |
47 | status change */ | 47 | status change */ |
48 | unsigned long busy_bits[1]; /* ports being reset or | ||
49 | resumed */ | ||
50 | unsigned long removed_bits[1]; /* ports with a "removed" | 48 | unsigned long removed_bits[1]; /* ports with a "removed" |
51 | device present */ | 49 | device present */ |
52 | unsigned long wakeup_bits[1]; /* ports that have signaled | 50 | unsigned long wakeup_bits[1]; /* ports that have signaled |
53 | remote wakeup */ | 51 | remote wakeup */ |
52 | unsigned long power_bits[1]; /* ports that are powered */ | ||
53 | unsigned long child_usage_bits[1]; /* ports powered on for | ||
54 | children */ | ||
54 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | 55 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ |
55 | #error event_bits[] is too short! | 56 | #error event_bits[] is too short! |
56 | #endif | 57 | #endif |
@@ -66,6 +67,7 @@ struct usb_hub { | |||
66 | unsigned limited_power:1; | 67 | unsigned limited_power:1; |
67 | unsigned quiescing:1; | 68 | unsigned quiescing:1; |
68 | unsigned disconnected:1; | 69 | unsigned disconnected:1; |
70 | unsigned in_reset:1; | ||
69 | 71 | ||
70 | unsigned quirk_check_port_auto_suspend:1; | 72 | unsigned quirk_check_port_auto_suspend:1; |
71 | 73 | ||
@@ -81,19 +83,23 @@ struct usb_hub { | |||
81 | * @child: usb device attached to the port | 83 | * @child: usb device attached to the port |
82 | * @dev: generic device interface | 84 | * @dev: generic device interface |
83 | * @port_owner: port's owner | 85 | * @port_owner: port's owner |
86 | * @peer: related usb2 and usb3 ports (share the same connector) | ||
84 | * @connect_type: port's connect type | 87 | * @connect_type: port's connect type |
88 | * @location: opaque representation of platform connector location | ||
89 | * @status_lock: synchronize port_event() vs usb_port_{suspend|resume} | ||
85 | * @portnum: port index num based one | 90 | * @portnum: port index num based one |
86 | * @power_is_on: port's power state | 91 | * @is_superspeed cache super-speed status |
87 | * @did_runtime_put: port has done pm_runtime_put(). | ||
88 | */ | 92 | */ |
89 | struct usb_port { | 93 | struct usb_port { |
90 | struct usb_device *child; | 94 | struct usb_device *child; |
91 | struct device dev; | 95 | struct device dev; |
92 | struct usb_dev_state *port_owner; | 96 | struct usb_dev_state *port_owner; |
97 | struct usb_port *peer; | ||
93 | enum usb_port_connect_type connect_type; | 98 | enum usb_port_connect_type connect_type; |
99 | usb_port_location_t location; | ||
100 | struct mutex status_lock; | ||
94 | u8 portnum; | 101 | u8 portnum; |
95 | unsigned power_is_on:1; | 102 | unsigned int is_superspeed:1; |
96 | unsigned did_runtime_put:1; | ||
97 | }; | 103 | }; |
98 | 104 | ||
99 | #define to_usb_port(_dev) \ | 105 | #define to_usb_port(_dev) \ |
@@ -111,6 +117,29 @@ extern int hub_port_debounce(struct usb_hub *hub, int port1, | |||
111 | extern int usb_clear_port_feature(struct usb_device *hdev, | 117 | extern int usb_clear_port_feature(struct usb_device *hdev, |
112 | int port1, int feature); | 118 | int port1, int feature); |
113 | 119 | ||
120 | static inline bool hub_is_port_power_switchable(struct usb_hub *hub) | ||
121 | { | ||
122 | __le16 hcs; | ||
123 | |||
124 | if (!hub) | ||
125 | return false; | ||
126 | hcs = hub->descriptor->wHubCharacteristics; | ||
127 | return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM; | ||
128 | } | ||
129 | |||
130 | static inline int hub_is_superspeed(struct usb_device *hdev) | ||
131 | { | ||
132 | return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS; | ||
133 | } | ||
134 | |||
135 | static inline unsigned hub_power_on_good_delay(struct usb_hub *hub) | ||
136 | { | ||
137 | unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2; | ||
138 | |||
139 | /* Wait at least 100 msec for power to become stable */ | ||
140 | return max(delay, 100U); | ||
141 | } | ||
142 | |||
114 | static inline int hub_port_debounce_be_connected(struct usb_hub *hub, | 143 | static inline int hub_port_debounce_be_connected(struct usb_hub *hub, |
115 | int port1) | 144 | int port1) |
116 | { | 145 | { |
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 51542f852393..62036faf56c0 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c | |||
@@ -76,17 +76,29 @@ static int usb_port_runtime_resume(struct device *dev) | |||
76 | struct usb_device *hdev = to_usb_device(dev->parent->parent); | 76 | struct usb_device *hdev = to_usb_device(dev->parent->parent); |
77 | struct usb_interface *intf = to_usb_interface(dev->parent); | 77 | struct usb_interface *intf = to_usb_interface(dev->parent); |
78 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | 78 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); |
79 | struct usb_device *udev = port_dev->child; | ||
80 | struct usb_port *peer = port_dev->peer; | ||
79 | int port1 = port_dev->portnum; | 81 | int port1 = port_dev->portnum; |
80 | int retval; | 82 | int retval; |
81 | 83 | ||
82 | if (!hub) | 84 | if (!hub) |
83 | return -EINVAL; | 85 | return -EINVAL; |
86 | if (hub->in_reset) { | ||
87 | set_bit(port1, hub->power_bits); | ||
88 | return 0; | ||
89 | } | ||
84 | 90 | ||
85 | usb_autopm_get_interface(intf); | 91 | /* |
86 | set_bit(port1, hub->busy_bits); | 92 | * Power on our usb3 peer before this usb2 port to prevent a usb3 |
93 | * device from degrading to its usb2 connection | ||
94 | */ | ||
95 | if (!port_dev->is_superspeed && peer) | ||
96 | pm_runtime_get_sync(&peer->dev); | ||
87 | 97 | ||
98 | usb_autopm_get_interface(intf); | ||
88 | retval = usb_hub_set_port_power(hdev, hub, port1, true); | 99 | retval = usb_hub_set_port_power(hdev, hub, port1, true); |
89 | if (port_dev->child && !retval) { | 100 | msleep(hub_power_on_good_delay(hub)); |
101 | if (udev && !retval) { | ||
90 | /* | 102 | /* |
91 | * Attempt to wait for usb hub port to be reconnected in order | 103 | * Attempt to wait for usb hub port to be reconnected in order |
92 | * to make the resume procedure successful. The device may have | 104 | * to make the resume procedure successful. The device may have |
@@ -97,12 +109,17 @@ static int usb_port_runtime_resume(struct device *dev) | |||
97 | if (retval < 0) | 109 | if (retval < 0) |
98 | dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n", | 110 | dev_dbg(&port_dev->dev, "can't get reconnection after setting port power on, status %d\n", |
99 | retval); | 111 | retval); |
100 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); | ||
101 | retval = 0; | 112 | retval = 0; |
113 | |||
114 | /* Force the child awake to revalidate after the power loss. */ | ||
115 | if (!test_and_set_bit(port1, hub->child_usage_bits)) { | ||
116 | pm_runtime_get_noresume(&port_dev->dev); | ||
117 | pm_request_resume(&udev->dev); | ||
118 | } | ||
102 | } | 119 | } |
103 | 120 | ||
104 | clear_bit(port1, hub->busy_bits); | ||
105 | usb_autopm_put_interface(intf); | 121 | usb_autopm_put_interface(intf); |
122 | |||
106 | return retval; | 123 | return retval; |
107 | } | 124 | } |
108 | 125 | ||
@@ -112,23 +129,34 @@ static int usb_port_runtime_suspend(struct device *dev) | |||
112 | struct usb_device *hdev = to_usb_device(dev->parent->parent); | 129 | struct usb_device *hdev = to_usb_device(dev->parent->parent); |
113 | struct usb_interface *intf = to_usb_interface(dev->parent); | 130 | struct usb_interface *intf = to_usb_interface(dev->parent); |
114 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | 131 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); |
132 | struct usb_port *peer = port_dev->peer; | ||
115 | int port1 = port_dev->portnum; | 133 | int port1 = port_dev->portnum; |
116 | int retval; | 134 | int retval; |
117 | 135 | ||
118 | if (!hub) | 136 | if (!hub) |
119 | return -EINVAL; | 137 | return -EINVAL; |
138 | if (hub->in_reset) | ||
139 | return -EBUSY; | ||
120 | 140 | ||
121 | if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) | 141 | if (dev_pm_qos_flags(&port_dev->dev, PM_QOS_FLAG_NO_POWER_OFF) |
122 | == PM_QOS_FLAGS_ALL) | 142 | == PM_QOS_FLAGS_ALL) |
123 | return -EAGAIN; | 143 | return -EAGAIN; |
124 | 144 | ||
125 | usb_autopm_get_interface(intf); | 145 | usb_autopm_get_interface(intf); |
126 | set_bit(port1, hub->busy_bits); | ||
127 | retval = usb_hub_set_port_power(hdev, hub, port1, false); | 146 | retval = usb_hub_set_port_power(hdev, hub, port1, false); |
128 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION); | 147 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_CONNECTION); |
129 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); | 148 | if (!port_dev->is_superspeed) |
130 | clear_bit(port1, hub->busy_bits); | 149 | usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE); |
131 | usb_autopm_put_interface(intf); | 150 | usb_autopm_put_interface(intf); |
151 | |||
152 | /* | ||
153 | * Our peer usb3 port may now be able to suspend, so | ||
154 | * asynchronously queue a suspend request to observe that this | ||
155 | * usb2 port is now off. | ||
156 | */ | ||
157 | if (!port_dev->is_superspeed && peer) | ||
158 | pm_runtime_put(&peer->dev); | ||
159 | |||
132 | return retval; | 160 | return retval; |
133 | } | 161 | } |
134 | #endif | 162 | #endif |
@@ -146,9 +174,215 @@ struct device_type usb_port_device_type = { | |||
146 | .pm = &usb_port_pm_ops, | 174 | .pm = &usb_port_pm_ops, |
147 | }; | 175 | }; |
148 | 176 | ||
177 | static struct device_driver usb_port_driver = { | ||
178 | .name = "usb", | ||
179 | .owner = THIS_MODULE, | ||
180 | }; | ||
181 | |||
182 | static int link_peers(struct usb_port *left, struct usb_port *right) | ||
183 | { | ||
184 | struct usb_port *ss_port, *hs_port; | ||
185 | int rc; | ||
186 | |||
187 | if (left->peer == right && right->peer == left) | ||
188 | return 0; | ||
189 | |||
190 | if (left->peer || right->peer) { | ||
191 | struct usb_port *lpeer = left->peer; | ||
192 | struct usb_port *rpeer = right->peer; | ||
193 | |||
194 | WARN(1, "failed to peer %s and %s (%s -> %p) (%s -> %p)\n", | ||
195 | dev_name(&left->dev), dev_name(&right->dev), | ||
196 | dev_name(&left->dev), lpeer, | ||
197 | dev_name(&right->dev), rpeer); | ||
198 | return -EBUSY; | ||
199 | } | ||
200 | |||
201 | rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer"); | ||
202 | if (rc) | ||
203 | return rc; | ||
204 | rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer"); | ||
205 | if (rc) { | ||
206 | sysfs_remove_link(&left->dev.kobj, "peer"); | ||
207 | return rc; | ||
208 | } | ||
209 | |||
210 | /* | ||
211 | * We need to wake the HiSpeed port to make sure we don't race | ||
212 | * setting ->peer with usb_port_runtime_suspend(). Otherwise we | ||
213 | * may miss a suspend event for the SuperSpeed port. | ||
214 | */ | ||
215 | if (left->is_superspeed) { | ||
216 | ss_port = left; | ||
217 | WARN_ON(right->is_superspeed); | ||
218 | hs_port = right; | ||
219 | } else { | ||
220 | ss_port = right; | ||
221 | WARN_ON(!right->is_superspeed); | ||
222 | hs_port = left; | ||
223 | } | ||
224 | pm_runtime_get_sync(&hs_port->dev); | ||
225 | |||
226 | left->peer = right; | ||
227 | right->peer = left; | ||
228 | |||
229 | /* | ||
230 | * The SuperSpeed reference is dropped when the HiSpeed port in | ||
231 | * this relationship suspends, i.e. when it is safe to allow a | ||
232 | * SuperSpeed connection to drop since there is no risk of a | ||
233 | * device degrading to its powered-off HiSpeed connection. | ||
234 | * | ||
235 | * Also, drop the HiSpeed ref taken above. | ||
236 | */ | ||
237 | pm_runtime_get_sync(&ss_port->dev); | ||
238 | pm_runtime_put(&hs_port->dev); | ||
239 | |||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | static void link_peers_report(struct usb_port *left, struct usb_port *right) | ||
244 | { | ||
245 | int rc; | ||
246 | |||
247 | rc = link_peers(left, right); | ||
248 | if (rc == 0) { | ||
249 | dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev)); | ||
250 | } else { | ||
251 | dev_warn(&left->dev, "failed to peer to %s (%d)\n", | ||
252 | dev_name(&right->dev), rc); | ||
253 | pr_warn_once("usb: port power management may be unreliable\n"); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | static void unlink_peers(struct usb_port *left, struct usb_port *right) | ||
258 | { | ||
259 | struct usb_port *ss_port, *hs_port; | ||
260 | |||
261 | WARN(right->peer != left || left->peer != right, | ||
262 | "%s and %s are not peers?\n", | ||
263 | dev_name(&left->dev), dev_name(&right->dev)); | ||
264 | |||
265 | /* | ||
266 | * We wake the HiSpeed port to make sure we don't race its | ||
267 | * usb_port_runtime_resume() event which takes a SuperSpeed ref | ||
268 | * when ->peer is !NULL. | ||
269 | */ | ||
270 | if (left->is_superspeed) { | ||
271 | ss_port = left; | ||
272 | hs_port = right; | ||
273 | } else { | ||
274 | ss_port = right; | ||
275 | hs_port = left; | ||
276 | } | ||
277 | |||
278 | pm_runtime_get_sync(&hs_port->dev); | ||
279 | |||
280 | sysfs_remove_link(&left->dev.kobj, "peer"); | ||
281 | right->peer = NULL; | ||
282 | sysfs_remove_link(&right->dev.kobj, "peer"); | ||
283 | left->peer = NULL; | ||
284 | |||
285 | /* Drop the SuperSpeed ref held on behalf of the active HiSpeed port */ | ||
286 | pm_runtime_put(&ss_port->dev); | ||
287 | |||
288 | /* Drop the ref taken above */ | ||
289 | pm_runtime_put(&hs_port->dev); | ||
290 | } | ||
291 | |||
292 | /* | ||
293 | * For each usb hub device in the system check to see if it is in the | ||
294 | * peer domain of the given port_dev, and if it is check to see if it | ||
295 | * has a port that matches the given port by location | ||
296 | */ | ||
297 | static int match_location(struct usb_device *peer_hdev, void *p) | ||
298 | { | ||
299 | int port1; | ||
300 | struct usb_hcd *hcd, *peer_hcd; | ||
301 | struct usb_port *port_dev = p, *peer; | ||
302 | struct usb_hub *peer_hub = usb_hub_to_struct_hub(peer_hdev); | ||
303 | struct usb_device *hdev = to_usb_device(port_dev->dev.parent->parent); | ||
304 | |||
305 | if (!peer_hub) | ||
306 | return 0; | ||
307 | |||
308 | hcd = bus_to_hcd(hdev->bus); | ||
309 | peer_hcd = bus_to_hcd(peer_hdev->bus); | ||
310 | /* peer_hcd is provisional until we verify it against the known peer */ | ||
311 | if (peer_hcd != hcd->shared_hcd) | ||
312 | return 0; | ||
313 | |||
314 | for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) { | ||
315 | peer = peer_hub->ports[port1 - 1]; | ||
316 | if (peer && peer->location == port_dev->location) { | ||
317 | link_peers_report(port_dev, peer); | ||
318 | return 1; /* done */ | ||
319 | } | ||
320 | } | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | /* | ||
326 | * Find the peer port either via explicit platform firmware "location" | ||
327 | * data, the peer hcd for root hubs, or the upstream peer relationship | ||
328 | * for all other hubs. | ||
329 | */ | ||
330 | static void find_and_link_peer(struct usb_hub *hub, int port1) | ||
331 | { | ||
332 | struct usb_port *port_dev = hub->ports[port1 - 1], *peer; | ||
333 | struct usb_device *hdev = hub->hdev; | ||
334 | struct usb_device *peer_hdev; | ||
335 | struct usb_hub *peer_hub; | ||
336 | |||
337 | /* | ||
338 | * If location data is available then we can only peer this port | ||
339 | * by a location match, not the default peer (lest we create a | ||
340 | * situation where we need to go back and undo a default peering | ||
341 | * when the port is later peered by location data) | ||
342 | */ | ||
343 | if (port_dev->location) { | ||
344 | /* we link the peer in match_location() if found */ | ||
345 | usb_for_each_dev(port_dev, match_location); | ||
346 | return; | ||
347 | } else if (!hdev->parent) { | ||
348 | struct usb_hcd *hcd = bus_to_hcd(hdev->bus); | ||
349 | struct usb_hcd *peer_hcd = hcd->shared_hcd; | ||
350 | |||
351 | if (!peer_hcd) | ||
352 | return; | ||
353 | |||
354 | peer_hdev = peer_hcd->self.root_hub; | ||
355 | } else { | ||
356 | struct usb_port *upstream; | ||
357 | struct usb_device *parent = hdev->parent; | ||
358 | struct usb_hub *parent_hub = usb_hub_to_struct_hub(parent); | ||
359 | |||
360 | if (!parent_hub) | ||
361 | return; | ||
362 | |||
363 | upstream = parent_hub->ports[hdev->portnum - 1]; | ||
364 | if (!upstream || !upstream->peer) | ||
365 | return; | ||
366 | |||
367 | peer_hdev = upstream->peer->child; | ||
368 | } | ||
369 | |||
370 | peer_hub = usb_hub_to_struct_hub(peer_hdev); | ||
371 | if (!peer_hub || port1 > peer_hdev->maxchild) | ||
372 | return; | ||
373 | |||
374 | /* | ||
375 | * we found a valid default peer, last check is to make sure it | ||
376 | * does not have location data | ||
377 | */ | ||
378 | peer = peer_hub->ports[port1 - 1]; | ||
379 | if (peer && peer->location == 0) | ||
380 | link_peers_report(port_dev, peer); | ||
381 | } | ||
382 | |||
149 | int usb_hub_create_port_device(struct usb_hub *hub, int port1) | 383 | int usb_hub_create_port_device(struct usb_hub *hub, int port1) |
150 | { | 384 | { |
151 | struct usb_port *port_dev = NULL; | 385 | struct usb_port *port_dev; |
152 | int retval; | 386 | int retval; |
153 | 387 | ||
154 | port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); | 388 | port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); |
@@ -159,24 +393,33 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) | |||
159 | 393 | ||
160 | hub->ports[port1 - 1] = port_dev; | 394 | hub->ports[port1 - 1] = port_dev; |
161 | port_dev->portnum = port1; | 395 | port_dev->portnum = port1; |
162 | port_dev->power_is_on = true; | 396 | set_bit(port1, hub->power_bits); |
163 | port_dev->dev.parent = hub->intfdev; | 397 | port_dev->dev.parent = hub->intfdev; |
164 | port_dev->dev.groups = port_dev_group; | 398 | port_dev->dev.groups = port_dev_group; |
165 | port_dev->dev.type = &usb_port_device_type; | 399 | port_dev->dev.type = &usb_port_device_type; |
166 | dev_set_name(&port_dev->dev, "port%d", port1); | 400 | port_dev->dev.driver = &usb_port_driver; |
167 | 401 | if (hub_is_superspeed(hub->hdev)) | |
402 | port_dev->is_superspeed = 1; | ||
403 | dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev), | ||
404 | port1); | ||
405 | mutex_init(&port_dev->status_lock); | ||
168 | retval = device_register(&port_dev->dev); | 406 | retval = device_register(&port_dev->dev); |
169 | if (retval) | 407 | if (retval) |
170 | goto error_register; | 408 | goto error_register; |
171 | 409 | ||
410 | find_and_link_peer(hub, port1); | ||
411 | |||
172 | pm_runtime_set_active(&port_dev->dev); | 412 | pm_runtime_set_active(&port_dev->dev); |
173 | 413 | ||
174 | /* It would be dangerous if user space couldn't | 414 | /* |
175 | * prevent usb device from being powered off. So don't | 415 | * Do not enable port runtime pm if the hub does not support |
176 | * enable port runtime pm if failed to expose port's pm qos. | 416 | * power switching. Also, userspace must have final say of |
417 | * whether a port is permitted to power-off. Do not enable | ||
418 | * runtime pm if we fail to expose pm_qos_no_power_off. | ||
177 | */ | 419 | */ |
178 | if (!dev_pm_qos_expose_flags(&port_dev->dev, | 420 | if (hub_is_port_power_switchable(hub) |
179 | PM_QOS_FLAG_NO_POWER_OFF)) | 421 | && dev_pm_qos_expose_flags(&port_dev->dev, |
422 | PM_QOS_FLAG_NO_POWER_OFF) == 0) | ||
180 | pm_runtime_enable(&port_dev->dev); | 423 | pm_runtime_enable(&port_dev->dev); |
181 | 424 | ||
182 | device_enable_async_suspend(&port_dev->dev); | 425 | device_enable_async_suspend(&port_dev->dev); |
@@ -188,9 +431,13 @@ exit: | |||
188 | return retval; | 431 | return retval; |
189 | } | 432 | } |
190 | 433 | ||
191 | void usb_hub_remove_port_device(struct usb_hub *hub, | 434 | void usb_hub_remove_port_device(struct usb_hub *hub, int port1) |
192 | int port1) | ||
193 | { | 435 | { |
194 | device_unregister(&hub->ports[port1 - 1]->dev); | 436 | struct usb_port *port_dev = hub->ports[port1 - 1]; |
195 | } | 437 | struct usb_port *peer; |
196 | 438 | ||
439 | peer = port_dev->peer; | ||
440 | if (peer) | ||
441 | unlink_peers(port_dev, peer); | ||
442 | device_unregister(&port_dev->dev); | ||
443 | } | ||
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c index 5ca4070b1f38..2776cfe64c09 100644 --- a/drivers/usb/core/usb-acpi.c +++ b/drivers/usb/core/usb-acpi.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include <linux/pci.h> | 17 | #include <linux/pci.h> |
18 | #include <linux/usb/hcd.h> | 18 | #include <linux/usb/hcd.h> |
19 | 19 | ||
20 | #include "usb.h" | 20 | #include "hub.h" |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * usb_acpi_power_manageable - check whether usb port has | 23 | * usb_acpi_power_manageable - check whether usb port has |
@@ -55,13 +55,18 @@ EXPORT_SYMBOL_GPL(usb_acpi_power_manageable); | |||
55 | */ | 55 | */ |
56 | int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) | 56 | int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) |
57 | { | 57 | { |
58 | struct usb_hub *hub = usb_hub_to_struct_hub(hdev); | ||
59 | struct usb_port *port_dev; | ||
58 | acpi_handle port_handle; | 60 | acpi_handle port_handle; |
59 | unsigned char state; | 61 | unsigned char state; |
60 | int port1 = index + 1; | 62 | int port1 = index + 1; |
61 | int error = -EINVAL; | 63 | int error = -EINVAL; |
62 | 64 | ||
63 | port_handle = (acpi_handle)usb_get_hub_port_acpi_handle(hdev, | 65 | if (!hub) |
64 | port1); | 66 | return -ENODEV; |
67 | port_dev = hub->ports[port1 - 1]; | ||
68 | |||
69 | port_handle = (acpi_handle) usb_get_hub_port_acpi_handle(hdev, port1); | ||
65 | if (!port_handle) | 70 | if (!port_handle) |
66 | return error; | 71 | return error; |
67 | 72 | ||
@@ -72,23 +77,21 @@ int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) | |||
72 | 77 | ||
73 | error = acpi_bus_set_power(port_handle, state); | 78 | error = acpi_bus_set_power(port_handle, state); |
74 | if (!error) | 79 | if (!error) |
75 | dev_dbg(&hdev->dev, "The power of hub port %d was set to %d\n", | 80 | dev_dbg(&port_dev->dev, "acpi: power was set to %d\n", enable); |
76 | port1, enable); | ||
77 | else | 81 | else |
78 | dev_dbg(&hdev->dev, "The power of hub port failed to be set\n"); | 82 | dev_dbg(&port_dev->dev, "acpi: power failed to be set\n"); |
79 | 83 | ||
80 | return error; | 84 | return error; |
81 | } | 85 | } |
82 | EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); | 86 | EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); |
83 | 87 | ||
84 | static int usb_acpi_check_port_connect_type(struct usb_device *hdev, | 88 | static enum usb_port_connect_type usb_acpi_get_connect_type(acpi_handle handle, |
85 | acpi_handle handle, int port1) | 89 | struct acpi_pld_info *pld) |
86 | { | 90 | { |
87 | acpi_status status; | 91 | enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; |
88 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 92 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
89 | union acpi_object *upc; | 93 | union acpi_object *upc; |
90 | struct acpi_pld_info *pld; | 94 | acpi_status status; |
91 | int ret = 0; | ||
92 | 95 | ||
93 | /* | 96 | /* |
94 | * According to ACPI Spec 9.13. PLD indicates whether usb port is | 97 | * According to ACPI Spec 9.13. PLD indicates whether usb port is |
@@ -98,39 +101,37 @@ static int usb_acpi_check_port_connect_type(struct usb_device *hdev, | |||
98 | * a usb device is directly hard-wired to the port. If no visible and | 101 | * a usb device is directly hard-wired to the port. If no visible and |
99 | * no connectable, the port would be not used. | 102 | * no connectable, the port would be not used. |
100 | */ | 103 | */ |
101 | status = acpi_get_physical_device_location(handle, &pld); | ||
102 | if (ACPI_FAILURE(status)) | ||
103 | return -ENODEV; | ||
104 | |||
105 | status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer); | 104 | status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer); |
106 | upc = buffer.pointer; | 105 | upc = buffer.pointer; |
107 | if (!upc || (upc->type != ACPI_TYPE_PACKAGE) | 106 | if (!upc || (upc->type != ACPI_TYPE_PACKAGE) |
108 | || upc->package.count != 4) { | 107 | || upc->package.count != 4) { |
109 | ret = -EINVAL; | ||
110 | goto out; | 108 | goto out; |
111 | } | 109 | } |
112 | 110 | ||
113 | if (upc->package.elements[0].integer.value) | 111 | if (upc->package.elements[0].integer.value) |
114 | if (pld->user_visible) | 112 | if (pld->user_visible) |
115 | usb_set_hub_port_connect_type(hdev, port1, | 113 | connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG; |
116 | USB_PORT_CONNECT_TYPE_HOT_PLUG); | ||
117 | else | 114 | else |
118 | usb_set_hub_port_connect_type(hdev, port1, | 115 | connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED; |
119 | USB_PORT_CONNECT_TYPE_HARD_WIRED); | ||
120 | else if (!pld->user_visible) | 116 | else if (!pld->user_visible) |
121 | usb_set_hub_port_connect_type(hdev, port1, USB_PORT_NOT_USED); | 117 | connect_type = USB_PORT_NOT_USED; |
122 | |||
123 | out: | 118 | out: |
124 | ACPI_FREE(pld); | ||
125 | kfree(upc); | 119 | kfree(upc); |
126 | return ret; | 120 | return connect_type; |
127 | } | 121 | } |
128 | 122 | ||
123 | |||
124 | /* | ||
125 | * Private to usb-acpi, all the core needs to know is that | ||
126 | * port_dev->location is non-zero when it has been set by the firmware. | ||
127 | */ | ||
128 | #define USB_ACPI_LOCATION_VALID (1 << 31) | ||
129 | |||
129 | static struct acpi_device *usb_acpi_find_companion(struct device *dev) | 130 | static struct acpi_device *usb_acpi_find_companion(struct device *dev) |
130 | { | 131 | { |
131 | struct usb_device *udev; | 132 | struct usb_device *udev; |
133 | struct acpi_device *adev; | ||
132 | acpi_handle *parent_handle; | 134 | acpi_handle *parent_handle; |
133 | int port_num; | ||
134 | 135 | ||
135 | /* | 136 | /* |
136 | * In the ACPI DSDT table, only usb root hub and usb ports are | 137 | * In the ACPI DSDT table, only usb root hub and usb ports are |
@@ -147,37 +148,19 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
147 | */ | 148 | */ |
148 | if (is_usb_device(dev)) { | 149 | if (is_usb_device(dev)) { |
149 | udev = to_usb_device(dev); | 150 | udev = to_usb_device(dev); |
150 | if (udev->parent) { | 151 | if (udev->parent) |
151 | enum usb_port_connect_type type; | ||
152 | |||
153 | /* | ||
154 | * According usb port's connect type to set usb device's | ||
155 | * removability. | ||
156 | */ | ||
157 | type = usb_get_hub_port_connect_type(udev->parent, | ||
158 | udev->portnum); | ||
159 | switch (type) { | ||
160 | case USB_PORT_CONNECT_TYPE_HOT_PLUG: | ||
161 | udev->removable = USB_DEVICE_REMOVABLE; | ||
162 | break; | ||
163 | case USB_PORT_CONNECT_TYPE_HARD_WIRED: | ||
164 | udev->removable = USB_DEVICE_FIXED; | ||
165 | break; | ||
166 | default: | ||
167 | udev->removable = USB_DEVICE_REMOVABLE_UNKNOWN; | ||
168 | break; | ||
169 | } | ||
170 | |||
171 | return NULL; | 152 | return NULL; |
172 | } | ||
173 | 153 | ||
174 | /* root hub's parent is the usb hcd. */ | 154 | /* root hub is only child (_ADR=0) under its parent, the HC */ |
175 | return acpi_find_child_device(ACPI_COMPANION(dev->parent), | 155 | adev = ACPI_COMPANION(dev->parent); |
176 | udev->portnum, false); | 156 | return acpi_find_child_device(adev, 0, false); |
177 | } else if (is_usb_port(dev)) { | 157 | } else if (is_usb_port(dev)) { |
178 | struct acpi_device *adev = NULL; | 158 | struct usb_port *port_dev = to_usb_port(dev); |
159 | int port1 = port_dev->portnum; | ||
160 | struct acpi_pld_info *pld; | ||
161 | acpi_handle *handle; | ||
162 | acpi_status status; | ||
179 | 163 | ||
180 | sscanf(dev_name(dev), "port%d", &port_num); | ||
181 | /* Get the struct usb_device point of port's hub */ | 164 | /* Get the struct usb_device point of port's hub */ |
182 | udev = to_usb_device(dev->parent->parent); | 165 | udev = to_usb_device(dev->parent->parent); |
183 | 166 | ||
@@ -188,12 +171,11 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
188 | */ | 171 | */ |
189 | if (!udev->parent) { | 172 | if (!udev->parent) { |
190 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 173 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
191 | int raw_port_num; | 174 | int raw; |
192 | 175 | ||
193 | raw_port_num = usb_hcd_find_raw_port_number(hcd, | 176 | raw = usb_hcd_find_raw_port_number(hcd, port1); |
194 | port_num); | ||
195 | adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev), | 177 | adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev), |
196 | raw_port_num, false); | 178 | raw, false); |
197 | if (!adev) | 179 | if (!adev) |
198 | return NULL; | 180 | return NULL; |
199 | } else { | 181 | } else { |
@@ -204,11 +186,20 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev) | |||
204 | return NULL; | 186 | return NULL; |
205 | 187 | ||
206 | acpi_bus_get_device(parent_handle, &adev); | 188 | acpi_bus_get_device(parent_handle, &adev); |
207 | adev = acpi_find_child_device(adev, port_num, false); | 189 | adev = acpi_find_child_device(adev, port1, false); |
208 | if (!adev) | 190 | if (!adev) |
209 | return NULL; | 191 | return NULL; |
210 | } | 192 | } |
211 | usb_acpi_check_port_connect_type(udev, adev->handle, port_num); | 193 | handle = adev->handle; |
194 | status = acpi_get_physical_device_location(handle, &pld); | ||
195 | if (ACPI_FAILURE(status) || !pld) | ||
196 | return adev; | ||
197 | |||
198 | port_dev->location = USB_ACPI_LOCATION_VALID | ||
199 | | pld->group_token << 8 | pld->group_position; | ||
200 | port_dev->connect_type = usb_acpi_get_connect_type(handle, pld); | ||
201 | ACPI_FREE(pld); | ||
202 | |||
212 | return adev; | 203 | return adev; |
213 | } | 204 | } |
214 | 205 | ||
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 75bf649da82d..d9d08720c386 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -107,11 +107,6 @@ static inline int usb_autoresume_device(struct usb_device *udev) | |||
107 | return 0; | 107 | return 0; |
108 | } | 108 | } |
109 | 109 | ||
110 | static inline int usb_remote_wakeup(struct usb_device *udev) | ||
111 | { | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) | 110 | static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) |
116 | { | 111 | { |
117 | return 0; | 112 | return 0; |
@@ -119,6 +114,7 @@ static inline int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) | |||
119 | #endif | 114 | #endif |
120 | 115 | ||
121 | extern struct bus_type usb_bus_type; | 116 | extern struct bus_type usb_bus_type; |
117 | extern struct mutex usb_port_peer_mutex; | ||
122 | extern struct device_type usb_device_type; | 118 | extern struct device_type usb_device_type; |
123 | extern struct device_type usb_if_device_type; | 119 | extern struct device_type usb_if_device_type; |
124 | extern struct device_type usb_ep_device_type; | 120 | extern struct device_type usb_ep_device_type; |
@@ -170,15 +166,17 @@ extern void usbfs_conn_disc_event(void); | |||
170 | extern int usb_devio_init(void); | 166 | extern int usb_devio_init(void); |
171 | extern void usb_devio_cleanup(void); | 167 | extern void usb_devio_cleanup(void); |
172 | 168 | ||
169 | /* | ||
170 | * Firmware specific cookie identifying a port's location. '0' == no location | ||
171 | * data available | ||
172 | */ | ||
173 | typedef u32 usb_port_location_t; | ||
174 | |||
173 | /* internal notify stuff */ | 175 | /* internal notify stuff */ |
174 | extern void usb_notify_add_device(struct usb_device *udev); | 176 | extern void usb_notify_add_device(struct usb_device *udev); |
175 | extern void usb_notify_remove_device(struct usb_device *udev); | 177 | extern void usb_notify_remove_device(struct usb_device *udev); |
176 | extern void usb_notify_add_bus(struct usb_bus *ubus); | 178 | extern void usb_notify_add_bus(struct usb_bus *ubus); |
177 | extern void usb_notify_remove_bus(struct usb_bus *ubus); | 179 | extern void usb_notify_remove_bus(struct usb_bus *ubus); |
178 | extern enum usb_port_connect_type | ||
179 | usb_get_hub_port_connect_type(struct usb_device *hdev, int port1); | ||
180 | extern void usb_set_hub_port_connect_type(struct usb_device *hdev, int port1, | ||
181 | enum usb_port_connect_type type); | ||
182 | extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, | 180 | extern void usb_hub_adjust_deviceremovable(struct usb_device *hdev, |
183 | struct usb_hub_descriptor *desc); | 181 | struct usb_hub_descriptor *desc); |
184 | 182 | ||
diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig index be947d673844..f93807b3631a 100644 --- a/drivers/usb/dwc2/Kconfig +++ b/drivers/usb/dwc2/Kconfig | |||
@@ -1,25 +1,58 @@ | |||
1 | config USB_DWC2 | 1 | config USB_DWC2 |
2 | tristate "DesignWare USB2 DRD Core Support" | 2 | bool "DesignWare USB2 DRD Core Support" |
3 | depends on USB | 3 | depends on USB |
4 | help | 4 | help |
5 | Say Y or M here if your system has a Dual Role HighSpeed | 5 | Say Y here if your system has a Dual Role Hi-Speed USB |
6 | USB controller based on the DesignWare HSOTG IP Core. | 6 | controller based on the DesignWare HSOTG IP Core. |
7 | 7 | ||
8 | If you choose to build this driver as dynamically linked | 8 | For host mode, if you choose to build the driver as dynamically |
9 | modules, the core module will be called dwc2.ko, the | 9 | linked modules, the core module will be called dwc2.ko, the PCI |
10 | PCI bus interface module (if you have a PCI bus system) | 10 | bus interface module (if you have a PCI bus system) will be |
11 | will be called dwc2_pci.ko and the platform interface module | 11 | called dwc2_pci.ko, and the platform interface module (for |
12 | (for controllers directly connected to the CPU) will be called | 12 | controllers directly connected to the CPU) will be called |
13 | dwc2_platform.ko. | 13 | dwc2_platform.ko. For gadget mode, there will be a single |
14 | module called dwc2_gadget.ko. | ||
14 | 15 | ||
15 | NOTE: This driver at present only implements the Host mode | 16 | NOTE: The s3c-hsotg driver is now renamed to dwc2_gadget. The |
16 | of the controller. The existing s3c-hsotg driver supports | 17 | host and gadget drivers are still currently separate drivers. |
17 | Peripheral mode, but only for the Samsung S3C platforms. | 18 | There are plans to merge the dwc2_gadget driver with the dwc2 |
18 | There are plans to merge the s3c-hsotg driver with this | 19 | host driver in the near future to create a dual-role driver. |
19 | driver in the near future to create a dual-role driver. | ||
20 | 20 | ||
21 | if USB_DWC2 | 21 | if USB_DWC2 |
22 | 22 | ||
23 | config USB_DWC2_HOST | ||
24 | tristate "Host only mode" | ||
25 | depends on USB | ||
26 | help | ||
27 | The Designware USB2.0 high-speed host controller | ||
28 | integrated into many SoCs. | ||
29 | |||
30 | config USB_DWC2_PLATFORM | ||
31 | bool "DWC2 Platform" | ||
32 | depends on USB_DWC2_HOST | ||
33 | default USB_DWC2_HOST | ||
34 | help | ||
35 | The Designware USB2.0 platform interface module for | ||
36 | controllers directly connected to the CPU. This is only | ||
37 | used for host mode. | ||
38 | |||
39 | config USB_DWC2_PCI | ||
40 | bool "DWC2 PCI" | ||
41 | depends on USB_DWC2_HOST && PCI | ||
42 | default USB_DWC2_HOST | ||
43 | help | ||
44 | The Designware USB2.0 PCI interface module for controllers | ||
45 | connected to a PCI bus. This is only used for host mode. | ||
46 | |||
47 | comment "Gadget mode requires USB Gadget support to be enabled" | ||
48 | |||
49 | config USB_DWC2_PERIPHERAL | ||
50 | tristate "Gadget only mode" | ||
51 | depends on USB_GADGET | ||
52 | help | ||
53 | The Designware USB2.0 high-speed gadget controller | ||
54 | integrated into many SoCs. | ||
55 | |||
23 | config USB_DWC2_DEBUG | 56 | config USB_DWC2_DEBUG |
24 | bool "Enable Debugging Messages" | 57 | bool "Enable Debugging Messages" |
25 | help | 58 | help |
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile index 11529d3439b0..b73d2a527970 100644 --- a/drivers/usb/dwc2/Makefile +++ b/drivers/usb/dwc2/Makefile | |||
@@ -1,25 +1,28 @@ | |||
1 | ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG | 1 | ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG |
2 | ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG | 2 | ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG |
3 | 3 | ||
4 | obj-$(CONFIG_USB_DWC2) += dwc2.o | 4 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2.o |
5 | 5 | dwc2-y := core.o core_intr.o | |
6 | dwc2-y += core.o core_intr.o | ||
7 | |||
8 | # NOTE: This driver at present only implements the Host mode | ||
9 | # of the controller. The existing s3c-hsotg driver supports | ||
10 | # Peripheral mode, but only for the Samsung S3C platforms. | ||
11 | # There are plans to merge the s3c-hsotg driver with this | ||
12 | # driver in the near future to create a dual-role driver. Once | ||
13 | # that is done, Host mode will become an optional feature that | ||
14 | # is selected with a config option. | ||
15 | |||
16 | dwc2-y += hcd.o hcd_intr.o | 6 | dwc2-y += hcd.o hcd_intr.o |
17 | dwc2-y += hcd_queue.o hcd_ddma.o | 7 | dwc2-y += hcd_queue.o hcd_ddma.o |
18 | 8 | ||
19 | ifneq ($(CONFIG_PCI),) | 9 | # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to |
20 | obj-$(CONFIG_USB_DWC2) += dwc2_pci.o | 10 | # this location and renamed gadget.c. When building for dynamically linked |
11 | # modules, dwc2_gadget.ko will get built for peripheral mode. For host mode, | ||
12 | # the core module will be dwc2.ko, the PCI bus interface module will called | ||
13 | # dwc2_pci.ko and the platform interface module will be called dwc2_platform.ko. | ||
14 | # At present the host and gadget driver will be separate drivers, but there | ||
15 | # are plans in the near future to create a dual-role driver. | ||
16 | |||
17 | ifneq ($(CONFIG_USB_DWC2_PCI),) | ||
18 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2_pci.o | ||
19 | dwc2_pci-y := pci.o | ||
20 | endif | ||
21 | |||
22 | ifneq ($(CONFIG_USB_DWC2_PLATFORM),) | ||
23 | obj-$(CONFIG_USB_DWC2_HOST) += dwc2_platform.o | ||
24 | dwc2_platform-y := platform.o | ||
21 | endif | 25 | endif |
22 | obj-$(CONFIG_USB_DWC2) += dwc2_platform.o | ||
23 | 26 | ||
24 | dwc2_pci-y += pci.o | 27 | obj-$(CONFIG_USB_DWC2_PERIPHERAL) += dwc2_gadget.o |
25 | dwc2_platform-y += platform.o | 28 | dwc2_gadget-y := gadget.o |
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 1d129884cc39..27d2c9b8a034 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c | |||
@@ -507,6 +507,72 @@ void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) | |||
507 | writel(intmsk, hsotg->regs + GINTMSK); | 507 | writel(intmsk, hsotg->regs + GINTMSK); |
508 | } | 508 | } |
509 | 509 | ||
510 | /* | ||
511 | * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size | ||
512 | * For system that have a total fifo depth that is smaller than the default | ||
513 | * RX + TX fifo size. | ||
514 | * | ||
515 | * @hsotg: Programming view of DWC_otg controller | ||
516 | */ | ||
517 | static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg) | ||
518 | { | ||
519 | struct dwc2_core_params *params = hsotg->core_params; | ||
520 | struct dwc2_hw_params *hw = &hsotg->hw_params; | ||
521 | u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size; | ||
522 | |||
523 | total_fifo_size = hw->total_fifo_size; | ||
524 | rxfsiz = params->host_rx_fifo_size; | ||
525 | nptxfsiz = params->host_nperio_tx_fifo_size; | ||
526 | ptxfsiz = params->host_perio_tx_fifo_size; | ||
527 | |||
528 | /* | ||
529 | * Will use Method 2 defined in the DWC2 spec: minimum FIFO depth | ||
530 | * allocation with support for high bandwidth endpoints. Synopsys | ||
531 | * defines MPS(Max Packet size) for a periodic EP=1024, and for | ||
532 | * non-periodic as 512. | ||
533 | */ | ||
534 | if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) { | ||
535 | /* | ||
536 | * For Buffer DMA mode/Scatter Gather DMA mode | ||
537 | * 2 * ((Largest Packet size / 4) + 1 + 1) + n | ||
538 | * with n = number of host channel. | ||
539 | * 2 * ((1024/4) + 2) = 516 | ||
540 | */ | ||
541 | rxfsiz = 516 + hw->host_channels; | ||
542 | |||
543 | /* | ||
544 | * min non-periodic tx fifo depth | ||
545 | * 2 * (largest non-periodic USB packet used / 4) | ||
546 | * 2 * (512/4) = 256 | ||
547 | */ | ||
548 | nptxfsiz = 256; | ||
549 | |||
550 | /* | ||
551 | * min periodic tx fifo depth | ||
552 | * (largest packet size*MC)/4 | ||
553 | * (1024 * 3)/4 = 768 | ||
554 | */ | ||
555 | ptxfsiz = 768; | ||
556 | |||
557 | params->host_rx_fifo_size = rxfsiz; | ||
558 | params->host_nperio_tx_fifo_size = nptxfsiz; | ||
559 | params->host_perio_tx_fifo_size = ptxfsiz; | ||
560 | } | ||
561 | |||
562 | /* | ||
563 | * If the summation of RX, NPTX and PTX fifo sizes is still | ||
564 | * bigger than the total_fifo_size, then we have a problem. | ||
565 | * | ||
566 | * We won't be able to allocate as many endpoints. Right now, | ||
567 | * we're just printing an error message, but ideally this FIFO | ||
568 | * allocation algorithm would be improved in the future. | ||
569 | * | ||
570 | * FIXME improve this FIFO allocation algorithm. | ||
571 | */ | ||
572 | if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))) | ||
573 | dev_err(hsotg->dev, "invalid fifo sizes\n"); | ||
574 | } | ||
575 | |||
510 | static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) | 576 | static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) |
511 | { | 577 | { |
512 | struct dwc2_core_params *params = hsotg->core_params; | 578 | struct dwc2_core_params *params = hsotg->core_params; |
@@ -515,6 +581,8 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) | |||
515 | if (!params->enable_dynamic_fifo) | 581 | if (!params->enable_dynamic_fifo) |
516 | return; | 582 | return; |
517 | 583 | ||
584 | dwc2_calculate_dynamic_fifo(hsotg); | ||
585 | |||
518 | /* Rx FIFO */ | 586 | /* Rx FIFO */ |
519 | grxfsiz = readl(hsotg->regs + GRXFSIZ); | 587 | grxfsiz = readl(hsotg->regs + GRXFSIZ); |
520 | dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); | 588 | dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); |
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 648519c024b5..1efd10cc9629 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h | |||
@@ -37,6 +37,10 @@ | |||
37 | #ifndef __DWC2_CORE_H__ | 37 | #ifndef __DWC2_CORE_H__ |
38 | #define __DWC2_CORE_H__ | 38 | #define __DWC2_CORE_H__ |
39 | 39 | ||
40 | #include <linux/phy/phy.h> | ||
41 | #include <linux/regulator/consumer.h> | ||
42 | #include <linux/usb/gadget.h> | ||
43 | #include <linux/usb/otg.h> | ||
40 | #include <linux/usb/phy.h> | 44 | #include <linux/usb/phy.h> |
41 | #include "hw.h" | 45 | #include "hw.h" |
42 | 46 | ||
@@ -54,6 +58,184 @@ static inline void do_write(u32 value, void *addr) | |||
54 | /* Maximum number of Endpoints/HostChannels */ | 58 | /* Maximum number of Endpoints/HostChannels */ |
55 | #define MAX_EPS_CHANNELS 16 | 59 | #define MAX_EPS_CHANNELS 16 |
56 | 60 | ||
61 | /* s3c-hsotg declarations */ | ||
62 | static const char * const s3c_hsotg_supply_names[] = { | ||
63 | "vusb_d", /* digital USB supply, 1.2V */ | ||
64 | "vusb_a", /* analog USB supply, 1.1V */ | ||
65 | }; | ||
66 | |||
67 | /* | ||
68 | * EP0_MPS_LIMIT | ||
69 | * | ||
70 | * Unfortunately there seems to be a limit of the amount of data that can | ||
71 | * be transferred by IN transactions on EP0. This is either 127 bytes or 3 | ||
72 | * packets (which practically means 1 packet and 63 bytes of data) when the | ||
73 | * MPS is set to 64. | ||
74 | * | ||
75 | * This means if we are wanting to move >127 bytes of data, we need to | ||
76 | * split the transactions up, but just doing one packet at a time does | ||
77 | * not work (this may be an implicit DATA0 PID on first packet of the | ||
78 | * transaction) and doing 2 packets is outside the controller's limits. | ||
79 | * | ||
80 | * If we try to lower the MPS size for EP0, then no transfers work properly | ||
81 | * for EP0, and the system will fail basic enumeration. As no cause for this | ||
82 | * has currently been found, we cannot support any large IN transfers for | ||
83 | * EP0. | ||
84 | */ | ||
85 | #define EP0_MPS_LIMIT 64 | ||
86 | |||
87 | struct s3c_hsotg; | ||
88 | struct s3c_hsotg_req; | ||
89 | |||
90 | /** | ||
91 | * struct s3c_hsotg_ep - driver endpoint definition. | ||
92 | * @ep: The gadget layer representation of the endpoint. | ||
93 | * @name: The driver generated name for the endpoint. | ||
94 | * @queue: Queue of requests for this endpoint. | ||
95 | * @parent: Reference back to the parent device structure. | ||
96 | * @req: The current request that the endpoint is processing. This is | ||
97 | * used to indicate an request has been loaded onto the endpoint | ||
98 | * and has yet to be completed (maybe due to data move, or simply | ||
99 | * awaiting an ack from the core all the data has been completed). | ||
100 | * @debugfs: File entry for debugfs file for this endpoint. | ||
101 | * @lock: State lock to protect contents of endpoint. | ||
102 | * @dir_in: Set to true if this endpoint is of the IN direction, which | ||
103 | * means that it is sending data to the Host. | ||
104 | * @index: The index for the endpoint registers. | ||
105 | * @mc: Multi Count - number of transactions per microframe | ||
106 | * @interval - Interval for periodic endpoints | ||
107 | * @name: The name array passed to the USB core. | ||
108 | * @halted: Set if the endpoint has been halted. | ||
109 | * @periodic: Set if this is a periodic ep, such as Interrupt | ||
110 | * @isochronous: Set if this is a isochronous ep | ||
111 | * @sent_zlp: Set if we've sent a zero-length packet. | ||
112 | * @total_data: The total number of data bytes done. | ||
113 | * @fifo_size: The size of the FIFO (for periodic IN endpoints) | ||
114 | * @fifo_load: The amount of data loaded into the FIFO (periodic IN) | ||
115 | * @last_load: The offset of data for the last start of request. | ||
116 | * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN | ||
117 | * | ||
118 | * This is the driver's state for each registered enpoint, allowing it | ||
119 | * to keep track of transactions that need doing. Each endpoint has a | ||
120 | * lock to protect the state, to try and avoid using an overall lock | ||
121 | * for the host controller as much as possible. | ||
122 | * | ||
123 | * For periodic IN endpoints, we have fifo_size and fifo_load to try | ||
124 | * and keep track of the amount of data in the periodic FIFO for each | ||
125 | * of these as we don't have a status register that tells us how much | ||
126 | * is in each of them. (note, this may actually be useless information | ||
127 | * as in shared-fifo mode periodic in acts like a single-frame packet | ||
128 | * buffer than a fifo) | ||
129 | */ | ||
130 | struct s3c_hsotg_ep { | ||
131 | struct usb_ep ep; | ||
132 | struct list_head queue; | ||
133 | struct s3c_hsotg *parent; | ||
134 | struct s3c_hsotg_req *req; | ||
135 | struct dentry *debugfs; | ||
136 | |||
137 | unsigned long total_data; | ||
138 | unsigned int size_loaded; | ||
139 | unsigned int last_load; | ||
140 | unsigned int fifo_load; | ||
141 | unsigned short fifo_size; | ||
142 | |||
143 | unsigned char dir_in; | ||
144 | unsigned char index; | ||
145 | unsigned char mc; | ||
146 | unsigned char interval; | ||
147 | |||
148 | unsigned int halted:1; | ||
149 | unsigned int periodic:1; | ||
150 | unsigned int isochronous:1; | ||
151 | unsigned int sent_zlp:1; | ||
152 | |||
153 | char name[10]; | ||
154 | }; | ||
155 | |||
156 | /** | ||
157 | * struct s3c_hsotg - driver state. | ||
158 | * @dev: The parent device supplied to the probe function | ||
159 | * @driver: USB gadget driver | ||
160 | * @phy: The otg phy transceiver structure for phy control. | ||
161 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
162 | * @plat: The platform specific configuration data. This can be removed once | ||
163 | * all SoCs support usb transceiver. | ||
164 | * @regs: The memory area mapped for accessing registers. | ||
165 | * @irq: The IRQ number we are using | ||
166 | * @supplies: Definition of USB power supplies | ||
167 | * @phyif: PHY interface width | ||
168 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | ||
169 | * @num_of_eps: Number of available EPs (excluding EP0) | ||
170 | * @debug_root: root directrory for debugfs. | ||
171 | * @debug_file: main status file for debugfs. | ||
172 | * @debug_fifo: FIFO status file for debugfs. | ||
173 | * @ep0_reply: Request used for ep0 reply. | ||
174 | * @ep0_buff: Buffer for EP0 reply data, if needed. | ||
175 | * @ctrl_buff: Buffer for EP0 control requests. | ||
176 | * @ctrl_req: Request for EP0 control packets. | ||
177 | * @setup: NAK management for EP0 SETUP | ||
178 | * @last_rst: Time of last reset | ||
179 | * @eps: The endpoints being supplied to the gadget framework | ||
180 | */ | ||
181 | struct s3c_hsotg { | ||
182 | struct device *dev; | ||
183 | struct usb_gadget_driver *driver; | ||
184 | struct phy *phy; | ||
185 | struct usb_phy *uphy; | ||
186 | struct s3c_hsotg_plat *plat; | ||
187 | |||
188 | spinlock_t lock; | ||
189 | |||
190 | void __iomem *regs; | ||
191 | int irq; | ||
192 | struct clk *clk; | ||
193 | |||
194 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | ||
195 | |||
196 | u32 phyif; | ||
197 | unsigned int dedicated_fifos:1; | ||
198 | unsigned char num_of_eps; | ||
199 | |||
200 | struct dentry *debug_root; | ||
201 | struct dentry *debug_file; | ||
202 | struct dentry *debug_fifo; | ||
203 | |||
204 | struct usb_request *ep0_reply; | ||
205 | struct usb_request *ctrl_req; | ||
206 | u8 ep0_buff[8]; | ||
207 | u8 ctrl_buff[8]; | ||
208 | |||
209 | struct usb_gadget gadget; | ||
210 | unsigned int setup; | ||
211 | unsigned long last_rst; | ||
212 | struct s3c_hsotg_ep *eps; | ||
213 | }; | ||
214 | |||
215 | /** | ||
216 | * struct s3c_hsotg_req - data transfer request | ||
217 | * @req: The USB gadget request | ||
218 | * @queue: The list of requests for the endpoint this is queued for. | ||
219 | * @in_progress: Has already had size/packets written to core | ||
220 | * @mapped: DMA buffer for this request has been mapped via dma_map_single(). | ||
221 | */ | ||
222 | struct s3c_hsotg_req { | ||
223 | struct usb_request req; | ||
224 | struct list_head queue; | ||
225 | unsigned char in_progress; | ||
226 | unsigned char mapped; | ||
227 | }; | ||
228 | |||
229 | #define call_gadget(_hs, _entry) \ | ||
230 | do { \ | ||
231 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ | ||
232 | (_hs)->driver && (_hs)->driver->_entry) { \ | ||
233 | spin_unlock(&_hs->lock); \ | ||
234 | (_hs)->driver->_entry(&(_hs)->gadget); \ | ||
235 | spin_lock(&_hs->lock); \ | ||
236 | } \ | ||
237 | } while (0) | ||
238 | |||
57 | struct dwc2_hsotg; | 239 | struct dwc2_hsotg; |
58 | struct dwc2_host_chan; | 240 | struct dwc2_host_chan; |
59 | 241 | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/dwc2/gadget.c index 2a9cb674926a..f3c56a2fed5b 100644 --- a/drivers/usb/gadget/s3c-hsotg.c +++ b/drivers/usb/dwc2/gadget.c | |||
@@ -37,175 +37,7 @@ | |||
37 | #include <linux/usb/phy.h> | 37 | #include <linux/usb/phy.h> |
38 | #include <linux/platform_data/s3c-hsotg.h> | 38 | #include <linux/platform_data/s3c-hsotg.h> |
39 | 39 | ||
40 | #include "s3c-hsotg.h" | 40 | #include "core.h" |
41 | |||
42 | static const char * const s3c_hsotg_supply_names[] = { | ||
43 | "vusb_d", /* digital USB supply, 1.2V */ | ||
44 | "vusb_a", /* analog USB supply, 1.1V */ | ||
45 | }; | ||
46 | |||
47 | /* | ||
48 | * EP0_MPS_LIMIT | ||
49 | * | ||
50 | * Unfortunately there seems to be a limit of the amount of data that can | ||
51 | * be transferred by IN transactions on EP0. This is either 127 bytes or 3 | ||
52 | * packets (which practically means 1 packet and 63 bytes of data) when the | ||
53 | * MPS is set to 64. | ||
54 | * | ||
55 | * This means if we are wanting to move >127 bytes of data, we need to | ||
56 | * split the transactions up, but just doing one packet at a time does | ||
57 | * not work (this may be an implicit DATA0 PID on first packet of the | ||
58 | * transaction) and doing 2 packets is outside the controller's limits. | ||
59 | * | ||
60 | * If we try to lower the MPS size for EP0, then no transfers work properly | ||
61 | * for EP0, and the system will fail basic enumeration. As no cause for this | ||
62 | * has currently been found, we cannot support any large IN transfers for | ||
63 | * EP0. | ||
64 | */ | ||
65 | #define EP0_MPS_LIMIT 64 | ||
66 | |||
67 | struct s3c_hsotg; | ||
68 | struct s3c_hsotg_req; | ||
69 | |||
70 | /** | ||
71 | * struct s3c_hsotg_ep - driver endpoint definition. | ||
72 | * @ep: The gadget layer representation of the endpoint. | ||
73 | * @name: The driver generated name for the endpoint. | ||
74 | * @queue: Queue of requests for this endpoint. | ||
75 | * @parent: Reference back to the parent device structure. | ||
76 | * @req: The current request that the endpoint is processing. This is | ||
77 | * used to indicate an request has been loaded onto the endpoint | ||
78 | * and has yet to be completed (maybe due to data move, or simply | ||
79 | * awaiting an ack from the core all the data has been completed). | ||
80 | * @debugfs: File entry for debugfs file for this endpoint. | ||
81 | * @lock: State lock to protect contents of endpoint. | ||
82 | * @dir_in: Set to true if this endpoint is of the IN direction, which | ||
83 | * means that it is sending data to the Host. | ||
84 | * @index: The index for the endpoint registers. | ||
85 | * @mc: Multi Count - number of transactions per microframe | ||
86 | * @interval - Interval for periodic endpoints | ||
87 | * @name: The name array passed to the USB core. | ||
88 | * @halted: Set if the endpoint has been halted. | ||
89 | * @periodic: Set if this is a periodic ep, such as Interrupt | ||
90 | * @isochronous: Set if this is a isochronous ep | ||
91 | * @sent_zlp: Set if we've sent a zero-length packet. | ||
92 | * @total_data: The total number of data bytes done. | ||
93 | * @fifo_size: The size of the FIFO (for periodic IN endpoints) | ||
94 | * @fifo_load: The amount of data loaded into the FIFO (periodic IN) | ||
95 | * @last_load: The offset of data for the last start of request. | ||
96 | * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN | ||
97 | * | ||
98 | * This is the driver's state for each registered enpoint, allowing it | ||
99 | * to keep track of transactions that need doing. Each endpoint has a | ||
100 | * lock to protect the state, to try and avoid using an overall lock | ||
101 | * for the host controller as much as possible. | ||
102 | * | ||
103 | * For periodic IN endpoints, we have fifo_size and fifo_load to try | ||
104 | * and keep track of the amount of data in the periodic FIFO for each | ||
105 | * of these as we don't have a status register that tells us how much | ||
106 | * is in each of them. (note, this may actually be useless information | ||
107 | * as in shared-fifo mode periodic in acts like a single-frame packet | ||
108 | * buffer than a fifo) | ||
109 | */ | ||
110 | struct s3c_hsotg_ep { | ||
111 | struct usb_ep ep; | ||
112 | struct list_head queue; | ||
113 | struct s3c_hsotg *parent; | ||
114 | struct s3c_hsotg_req *req; | ||
115 | struct dentry *debugfs; | ||
116 | |||
117 | |||
118 | unsigned long total_data; | ||
119 | unsigned int size_loaded; | ||
120 | unsigned int last_load; | ||
121 | unsigned int fifo_load; | ||
122 | unsigned short fifo_size; | ||
123 | |||
124 | unsigned char dir_in; | ||
125 | unsigned char index; | ||
126 | unsigned char mc; | ||
127 | unsigned char interval; | ||
128 | |||
129 | unsigned int halted:1; | ||
130 | unsigned int periodic:1; | ||
131 | unsigned int isochronous:1; | ||
132 | unsigned int sent_zlp:1; | ||
133 | |||
134 | char name[10]; | ||
135 | }; | ||
136 | |||
137 | /** | ||
138 | * struct s3c_hsotg - driver state. | ||
139 | * @dev: The parent device supplied to the probe function | ||
140 | * @driver: USB gadget driver | ||
141 | * @phy: The otg phy transceiver structure for phy control. | ||
142 | * @uphy: The otg phy transceiver structure for old USB phy control. | ||
143 | * @plat: The platform specific configuration data. This can be removed once | ||
144 | * all SoCs support usb transceiver. | ||
145 | * @regs: The memory area mapped for accessing registers. | ||
146 | * @irq: The IRQ number we are using | ||
147 | * @supplies: Definition of USB power supplies | ||
148 | * @phyif: PHY interface width | ||
149 | * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. | ||
150 | * @num_of_eps: Number of available EPs (excluding EP0) | ||
151 | * @debug_root: root directrory for debugfs. | ||
152 | * @debug_file: main status file for debugfs. | ||
153 | * @debug_fifo: FIFO status file for debugfs. | ||
154 | * @ep0_reply: Request used for ep0 reply. | ||
155 | * @ep0_buff: Buffer for EP0 reply data, if needed. | ||
156 | * @ctrl_buff: Buffer for EP0 control requests. | ||
157 | * @ctrl_req: Request for EP0 control packets. | ||
158 | * @setup: NAK management for EP0 SETUP | ||
159 | * @last_rst: Time of last reset | ||
160 | * @eps: The endpoints being supplied to the gadget framework | ||
161 | */ | ||
162 | struct s3c_hsotg { | ||
163 | struct device *dev; | ||
164 | struct usb_gadget_driver *driver; | ||
165 | struct phy *phy; | ||
166 | struct usb_phy *uphy; | ||
167 | struct s3c_hsotg_plat *plat; | ||
168 | |||
169 | spinlock_t lock; | ||
170 | |||
171 | void __iomem *regs; | ||
172 | int irq; | ||
173 | struct clk *clk; | ||
174 | |||
175 | struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; | ||
176 | |||
177 | u32 phyif; | ||
178 | unsigned int dedicated_fifos:1; | ||
179 | unsigned char num_of_eps; | ||
180 | |||
181 | struct dentry *debug_root; | ||
182 | struct dentry *debug_file; | ||
183 | struct dentry *debug_fifo; | ||
184 | |||
185 | struct usb_request *ep0_reply; | ||
186 | struct usb_request *ctrl_req; | ||
187 | u8 ep0_buff[8]; | ||
188 | u8 ctrl_buff[8]; | ||
189 | |||
190 | struct usb_gadget gadget; | ||
191 | unsigned int setup; | ||
192 | unsigned long last_rst; | ||
193 | struct s3c_hsotg_ep *eps; | ||
194 | }; | ||
195 | |||
196 | /** | ||
197 | * struct s3c_hsotg_req - data transfer request | ||
198 | * @req: The USB gadget request | ||
199 | * @queue: The list of requests for the endpoint this is queued for. | ||
200 | * @in_progress: Has already had size/packets written to core | ||
201 | * @mapped: DMA buffer for this request has been mapped via dma_map_single(). | ||
202 | */ | ||
203 | struct s3c_hsotg_req { | ||
204 | struct usb_request req; | ||
205 | struct list_head queue; | ||
206 | unsigned char in_progress; | ||
207 | unsigned char mapped; | ||
208 | }; | ||
209 | 41 | ||
210 | /* conversion functions */ | 42 | /* conversion functions */ |
211 | static inline struct s3c_hsotg_req *our_req(struct usb_request *req) | 43 | static inline struct s3c_hsotg_req *our_req(struct usb_request *req) |
@@ -340,9 +172,8 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
340 | /* set FIFO sizes to 2048/1024 */ | 172 | /* set FIFO sizes to 2048/1024 */ |
341 | 173 | ||
342 | writel(2048, hsotg->regs + GRXFSIZ); | 174 | writel(2048, hsotg->regs + GRXFSIZ); |
343 | writel(GNPTXFSIZ_NPTxFStAddr(2048) | | 175 | writel((2048 << FIFOSIZE_STARTADDR_SHIFT) | |
344 | GNPTXFSIZ_NPTxFDep(1024), | 176 | (1024 << FIFOSIZE_DEPTH_SHIFT), hsotg->regs + GNPTXFSIZ); |
345 | hsotg->regs + GNPTXFSIZ); | ||
346 | 177 | ||
347 | /* | 178 | /* |
348 | * arange all the rest of the TX FIFOs, as some versions of this | 179 | * arange all the rest of the TX FIFOs, as some versions of this |
@@ -362,10 +193,10 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
362 | 193 | ||
363 | for (ep = 1; ep <= 15; ep++) { | 194 | for (ep = 1; ep <= 15; ep++) { |
364 | val = addr; | 195 | val = addr; |
365 | val |= size << DPTXFSIZn_DPTxFSize_SHIFT; | 196 | val |= size << FIFOSIZE_DEPTH_SHIFT; |
366 | addr += size; | 197 | addr += size; |
367 | 198 | ||
368 | writel(val, hsotg->regs + DPTXFSIZn(ep)); | 199 | writel(val, hsotg->regs + DPTXFSIZN(ep)); |
369 | } | 200 | } |
370 | 201 | ||
371 | /* | 202 | /* |
@@ -373,15 +204,15 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg) | |||
373 | * all fifos are flushed before continuing | 204 | * all fifos are flushed before continuing |
374 | */ | 205 | */ |
375 | 206 | ||
376 | writel(GRSTCTL_TxFNum(0x10) | GRSTCTL_TxFFlsh | | 207 | writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH | |
377 | GRSTCTL_RxFFlsh, hsotg->regs + GRSTCTL); | 208 | GRSTCTL_RXFFLSH, hsotg->regs + GRSTCTL); |
378 | 209 | ||
379 | /* wait until the fifos are both flushed */ | 210 | /* wait until the fifos are both flushed */ |
380 | timeout = 100; | 211 | timeout = 100; |
381 | while (1) { | 212 | while (1) { |
382 | val = readl(hsotg->regs + GRSTCTL); | 213 | val = readl(hsotg->regs + GRSTCTL); |
383 | 214 | ||
384 | if ((val & (GRSTCTL_TxFFlsh | GRSTCTL_RxFFlsh)) == 0) | 215 | if ((val & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0) |
385 | break; | 216 | break; |
386 | 217 | ||
387 | if (--timeout == 0) { | 218 | if (--timeout == 0) { |
@@ -495,14 +326,14 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
495 | * how much data is left in the fifo. | 326 | * how much data is left in the fifo. |
496 | */ | 327 | */ |
497 | 328 | ||
498 | size_left = DxEPTSIZ_XferSize_GET(epsize); | 329 | size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
499 | 330 | ||
500 | /* | 331 | /* |
501 | * if shared fifo, we cannot write anything until the | 332 | * if shared fifo, we cannot write anything until the |
502 | * previous data has been completely sent. | 333 | * previous data has been completely sent. |
503 | */ | 334 | */ |
504 | if (hs_ep->fifo_load != 0) { | 335 | if (hs_ep->fifo_load != 0) { |
505 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp); | 336 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); |
506 | return -ENOSPC; | 337 | return -ENOSPC; |
507 | } | 338 | } |
508 | 339 | ||
@@ -523,7 +354,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
523 | __func__, can_write); | 354 | __func__, can_write); |
524 | 355 | ||
525 | if (can_write <= 0) { | 356 | if (can_write <= 0) { |
526 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp); | 357 | s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP); |
527 | return -ENOSPC; | 358 | return -ENOSPC; |
528 | } | 359 | } |
529 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { | 360 | } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { |
@@ -532,16 +363,16 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
532 | can_write &= 0xffff; | 363 | can_write &= 0xffff; |
533 | can_write *= 4; | 364 | can_write *= 4; |
534 | } else { | 365 | } else { |
535 | if (GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { | 366 | if (GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(gnptxsts) == 0) { |
536 | dev_dbg(hsotg->dev, | 367 | dev_dbg(hsotg->dev, |
537 | "%s: no queue slots available (0x%08x)\n", | 368 | "%s: no queue slots available (0x%08x)\n", |
538 | __func__, gnptxsts); | 369 | __func__, gnptxsts); |
539 | 370 | ||
540 | s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTxFEmp); | 371 | s3c_hsotg_en_gsint(hsotg, GINTSTS_NPTXFEMP); |
541 | return -ENOSPC; | 372 | return -ENOSPC; |
542 | } | 373 | } |
543 | 374 | ||
544 | can_write = GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); | 375 | can_write = GNPTXSTS_NP_TXF_SPC_AVAIL_GET(gnptxsts); |
545 | can_write *= 4; /* fifo size is in 32bit quantities. */ | 376 | can_write *= 4; /* fifo size is in 32bit quantities. */ |
546 | } | 377 | } |
547 | 378 | ||
@@ -569,8 +400,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
569 | /* it's needed only when we do not use dedicated fifos */ | 400 | /* it's needed only when we do not use dedicated fifos */ |
570 | if (!hsotg->dedicated_fifos) | 401 | if (!hsotg->dedicated_fifos) |
571 | s3c_hsotg_en_gsint(hsotg, | 402 | s3c_hsotg_en_gsint(hsotg, |
572 | periodic ? GINTSTS_PTxFEmp : | 403 | periodic ? GINTSTS_PTXFEMP : |
573 | GINTSTS_NPTxFEmp); | 404 | GINTSTS_NPTXFEMP); |
574 | } | 405 | } |
575 | 406 | ||
576 | /* see if we can write data */ | 407 | /* see if we can write data */ |
@@ -598,8 +429,8 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg, | |||
598 | /* it's needed only when we do not use dedicated fifos */ | 429 | /* it's needed only when we do not use dedicated fifos */ |
599 | if (!hsotg->dedicated_fifos) | 430 | if (!hsotg->dedicated_fifos) |
600 | s3c_hsotg_en_gsint(hsotg, | 431 | s3c_hsotg_en_gsint(hsotg, |
601 | periodic ? GINTSTS_PTxFEmp : | 432 | periodic ? GINTSTS_PTXFEMP : |
602 | GINTSTS_NPTxFEmp); | 433 | GINTSTS_NPTXFEMP); |
603 | } | 434 | } |
604 | 435 | ||
605 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", | 436 | dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", |
@@ -636,12 +467,12 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep) | |||
636 | unsigned maxpkt; | 467 | unsigned maxpkt; |
637 | 468 | ||
638 | if (index != 0) { | 469 | if (index != 0) { |
639 | maxsize = DxEPTSIZ_XferSize_LIMIT + 1; | 470 | maxsize = DXEPTSIZ_XFERSIZE_LIMIT + 1; |
640 | maxpkt = DxEPTSIZ_PktCnt_LIMIT + 1; | 471 | maxpkt = DXEPTSIZ_PKTCNT_LIMIT + 1; |
641 | } else { | 472 | } else { |
642 | maxsize = 64+64; | 473 | maxsize = 64+64; |
643 | if (hs_ep->dir_in) | 474 | if (hs_ep->dir_in) |
644 | maxpkt = DIEPTSIZ0_PktCnt_LIMIT + 1; | 475 | maxpkt = DIEPTSIZ0_PKTCNT_LIMIT + 1; |
645 | else | 476 | else |
646 | maxpkt = 2; | 477 | maxpkt = 2; |
647 | } | 478 | } |
@@ -710,7 +541,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
710 | /* If endpoint is stalled, we will restart request later */ | 541 | /* If endpoint is stalled, we will restart request later */ |
711 | ctrl = readl(hsotg->regs + epctrl_reg); | 542 | ctrl = readl(hsotg->regs + epctrl_reg); |
712 | 543 | ||
713 | if (ctrl & DxEPCTL_Stall) { | 544 | if (ctrl & DXEPCTL_STALL) { |
714 | dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); | 545 | dev_warn(hsotg->dev, "%s: ep%d is stalled\n", __func__, index); |
715 | return; | 546 | return; |
716 | } | 547 | } |
@@ -720,7 +551,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
720 | ureq->length, ureq->actual); | 551 | ureq->length, ureq->actual); |
721 | if (0) | 552 | if (0) |
722 | dev_dbg(hsotg->dev, | 553 | dev_dbg(hsotg->dev, |
723 | "REQ buf %p len %d dma 0x%pad noi=%d zp=%d snok=%d\n", | 554 | "REQ buf %p len %d dma %pad noi=%d zp=%d snok=%d\n", |
724 | ureq->buf, length, &ureq->dma, | 555 | ureq->buf, length, &ureq->dma, |
725 | ureq->no_interrupt, ureq->zero, ureq->short_not_ok); | 556 | ureq->no_interrupt, ureq->zero, ureq->short_not_ok); |
726 | 557 | ||
@@ -750,9 +581,9 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
750 | 581 | ||
751 | if (dir_in && index != 0) | 582 | if (dir_in && index != 0) |
752 | if (hs_ep->isochronous) | 583 | if (hs_ep->isochronous) |
753 | epsize = DxEPTSIZ_MC(packets); | 584 | epsize = DXEPTSIZ_MC(packets); |
754 | else | 585 | else |
755 | epsize = DxEPTSIZ_MC(1); | 586 | epsize = DXEPTSIZ_MC(1); |
756 | else | 587 | else |
757 | epsize = 0; | 588 | epsize = 0; |
758 | 589 | ||
@@ -766,8 +597,8 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
766 | packets++; | 597 | packets++; |
767 | } | 598 | } |
768 | 599 | ||
769 | epsize |= DxEPTSIZ_PktCnt(packets); | 600 | epsize |= DXEPTSIZ_PKTCNT(packets); |
770 | epsize |= DxEPTSIZ_XferSize(length); | 601 | epsize |= DXEPTSIZ_XFERSIZE(length); |
771 | 602 | ||
772 | dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", | 603 | dev_dbg(hsotg->dev, "%s: %d@%d/%d, 0x%08x => 0x%08x\n", |
773 | __func__, packets, length, ureq->length, epsize, epsize_reg); | 604 | __func__, packets, length, ureq->length, epsize, epsize_reg); |
@@ -789,12 +620,12 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
789 | dma_reg = dir_in ? DIEPDMA(index) : DOEPDMA(index); | 620 | dma_reg = dir_in ? DIEPDMA(index) : DOEPDMA(index); |
790 | writel(ureq->dma, hsotg->regs + dma_reg); | 621 | writel(ureq->dma, hsotg->regs + dma_reg); |
791 | 622 | ||
792 | dev_dbg(hsotg->dev, "%s: 0x%pad => 0x%08x\n", | 623 | dev_dbg(hsotg->dev, "%s: %pad => 0x%08x\n", |
793 | __func__, &ureq->dma, dma_reg); | 624 | __func__, &ureq->dma, dma_reg); |
794 | } | 625 | } |
795 | 626 | ||
796 | ctrl |= DxEPCTL_EPEna; /* ensure ep enabled */ | 627 | ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ |
797 | ctrl |= DxEPCTL_USBActEp; | 628 | ctrl |= DXEPCTL_USBACTEP; |
798 | 629 | ||
799 | dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup); | 630 | dev_dbg(hsotg->dev, "setup req:%d\n", hsotg->setup); |
800 | 631 | ||
@@ -802,7 +633,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
802 | if (hsotg->setup && index == 0) | 633 | if (hsotg->setup && index == 0) |
803 | hsotg->setup = 0; | 634 | hsotg->setup = 0; |
804 | else | 635 | else |
805 | ctrl |= DxEPCTL_CNAK; /* clear NAK set by core */ | 636 | ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ |
806 | 637 | ||
807 | 638 | ||
808 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); | 639 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
@@ -828,7 +659,7 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
828 | * to debugging to see what is going on. | 659 | * to debugging to see what is going on. |
829 | */ | 660 | */ |
830 | if (dir_in) | 661 | if (dir_in) |
831 | writel(DIEPMSK_INTknTXFEmpMsk, | 662 | writel(DIEPMSK_INTKNTXFEMPMSK, |
832 | hsotg->regs + DIEPINT(index)); | 663 | hsotg->regs + DIEPINT(index)); |
833 | 664 | ||
834 | /* | 665 | /* |
@@ -837,12 +668,12 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg, | |||
837 | */ | 668 | */ |
838 | 669 | ||
839 | /* check ep is enabled */ | 670 | /* check ep is enabled */ |
840 | if (!(readl(hsotg->regs + epctrl_reg) & DxEPCTL_EPEna)) | 671 | if (!(readl(hsotg->regs + epctrl_reg) & DXEPCTL_EPENA)) |
841 | dev_warn(hsotg->dev, | 672 | dev_warn(hsotg->dev, |
842 | "ep%d: failed to become enabled (DxEPCTL=0x%08x)?\n", | 673 | "ep%d: failed to become enabled (DXEPCTL=0x%08x)?\n", |
843 | index, readl(hsotg->regs + epctrl_reg)); | 674 | index, readl(hsotg->regs + epctrl_reg)); |
844 | 675 | ||
845 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", | 676 | dev_dbg(hsotg->dev, "%s: DXEPCTL=0x%08x\n", |
846 | __func__, readl(hsotg->regs + epctrl_reg)); | 677 | __func__, readl(hsotg->regs + epctrl_reg)); |
847 | 678 | ||
848 | /* enable ep interrupts */ | 679 | /* enable ep interrupts */ |
@@ -1205,12 +1036,12 @@ static void s3c_hsotg_stall_ep0(struct s3c_hsotg *hsotg) { | |||
1205 | */ | 1036 | */ |
1206 | 1037 | ||
1207 | ctrl = readl(hsotg->regs + reg); | 1038 | ctrl = readl(hsotg->regs + reg); |
1208 | ctrl |= DxEPCTL_Stall; | 1039 | ctrl |= DXEPCTL_STALL; |
1209 | ctrl |= DxEPCTL_CNAK; | 1040 | ctrl |= DXEPCTL_CNAK; |
1210 | writel(ctrl, hsotg->regs + reg); | 1041 | writel(ctrl, hsotg->regs + reg); |
1211 | 1042 | ||
1212 | dev_dbg(hsotg->dev, | 1043 | dev_dbg(hsotg->dev, |
1213 | "written DxEPCTL=0x%08x to %08x (DxEPCTL=0x%08x)\n", | 1044 | "written DXEPCTL=0x%08x to %08x (DXEPCTL=0x%08x)\n", |
1214 | ctrl, reg, readl(hsotg->regs + reg)); | 1045 | ctrl, reg, readl(hsotg->regs + reg)); |
1215 | 1046 | ||
1216 | /* | 1047 | /* |
@@ -1262,8 +1093,9 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, | |||
1262 | case USB_REQ_SET_ADDRESS: | 1093 | case USB_REQ_SET_ADDRESS: |
1263 | s3c_hsotg_disconnect(hsotg); | 1094 | s3c_hsotg_disconnect(hsotg); |
1264 | dcfg = readl(hsotg->regs + DCFG); | 1095 | dcfg = readl(hsotg->regs + DCFG); |
1265 | dcfg &= ~DCFG_DevAddr_MASK; | 1096 | dcfg &= ~DCFG_DEVADDR_MASK; |
1266 | dcfg |= ctrl->wValue << DCFG_DevAddr_SHIFT; | 1097 | dcfg |= (le16_to_cpu(ctrl->wValue) << |
1098 | DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK; | ||
1267 | writel(dcfg, hsotg->regs + DCFG); | 1099 | writel(dcfg, hsotg->regs + DCFG); |
1268 | 1100 | ||
1269 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); | 1101 | dev_info(hsotg->dev, "new address %d\n", ctrl->wValue); |
@@ -1458,7 +1290,7 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size) | |||
1458 | int ptr; | 1290 | int ptr; |
1459 | 1291 | ||
1460 | dev_warn(hsotg->dev, | 1292 | dev_warn(hsotg->dev, |
1461 | "%s: FIFO %d bytes on ep%d but no req (DxEPCTl=0x%08x)\n", | 1293 | "%s: FIFO %d bytes on ep%d but no req (DXEPCTl=0x%08x)\n", |
1462 | __func__, size, ep_idx, epctl); | 1294 | __func__, size, ep_idx, epctl); |
1463 | 1295 | ||
1464 | /* dump the data from the FIFO, we've nothing we can do */ | 1296 | /* dump the data from the FIFO, we've nothing we can do */ |
@@ -1530,13 +1362,13 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg, | |||
1530 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); | 1362 | dev_dbg(hsotg->dev, "sending zero-length packet\n"); |
1531 | 1363 | ||
1532 | /* issue a zero-sized packet to terminate this */ | 1364 | /* issue a zero-sized packet to terminate this */ |
1533 | writel(DxEPTSIZ_MC(1) | DxEPTSIZ_PktCnt(1) | | 1365 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
1534 | DxEPTSIZ_XferSize(0), hsotg->regs + DIEPTSIZ(0)); | 1366 | DXEPTSIZ_XFERSIZE(0), hsotg->regs + DIEPTSIZ(0)); |
1535 | 1367 | ||
1536 | ctrl = readl(hsotg->regs + DIEPCTL0); | 1368 | ctrl = readl(hsotg->regs + DIEPCTL0); |
1537 | ctrl |= DxEPCTL_CNAK; /* clear NAK set by core */ | 1369 | ctrl |= DXEPCTL_CNAK; /* clear NAK set by core */ |
1538 | ctrl |= DxEPCTL_EPEna; /* ensure ep enabled */ | 1370 | ctrl |= DXEPCTL_EPENA; /* ensure ep enabled */ |
1539 | ctrl |= DxEPCTL_USBActEp; | 1371 | ctrl |= DXEPCTL_USBACTEP; |
1540 | writel(ctrl, hsotg->regs + DIEPCTL0); | 1372 | writel(ctrl, hsotg->regs + DIEPCTL0); |
1541 | } | 1373 | } |
1542 | 1374 | ||
@@ -1557,7 +1389,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, | |||
1557 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; | 1389 | struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; |
1558 | struct s3c_hsotg_req *hs_req = hs_ep->req; | 1390 | struct s3c_hsotg_req *hs_req = hs_ep->req; |
1559 | struct usb_request *req = &hs_req->req; | 1391 | struct usb_request *req = &hs_req->req; |
1560 | unsigned size_left = DxEPTSIZ_XferSize_GET(epsize); | 1392 | unsigned size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
1561 | int result = 0; | 1393 | int result = 0; |
1562 | 1394 | ||
1563 | if (!hs_req) { | 1395 | if (!hs_req) { |
@@ -1657,24 +1489,22 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1657 | 1489 | ||
1658 | WARN_ON(using_dma(hsotg)); | 1490 | WARN_ON(using_dma(hsotg)); |
1659 | 1491 | ||
1660 | epnum = grxstsr & GRXSTS_EPNum_MASK; | 1492 | epnum = grxstsr & GRXSTS_EPNUM_MASK; |
1661 | status = grxstsr & GRXSTS_PktSts_MASK; | 1493 | status = grxstsr & GRXSTS_PKTSTS_MASK; |
1662 | 1494 | ||
1663 | size = grxstsr & GRXSTS_ByteCnt_MASK; | 1495 | size = grxstsr & GRXSTS_BYTECNT_MASK; |
1664 | size >>= GRXSTS_ByteCnt_SHIFT; | 1496 | size >>= GRXSTS_BYTECNT_SHIFT; |
1665 | 1497 | ||
1666 | if (1) | 1498 | if (1) |
1667 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", | 1499 | dev_dbg(hsotg->dev, "%s: GRXSTSP=0x%08x (%d@%d)\n", |
1668 | __func__, grxstsr, size, epnum); | 1500 | __func__, grxstsr, size, epnum); |
1669 | 1501 | ||
1670 | #define __status(x) ((x) >> GRXSTS_PktSts_SHIFT) | 1502 | switch ((status & GRXSTS_PKTSTS_MASK) >> GRXSTS_PKTSTS_SHIFT) { |
1671 | 1503 | case GRXSTS_PKTSTS_GLOBALOUTNAK: | |
1672 | switch (status >> GRXSTS_PktSts_SHIFT) { | 1504 | dev_dbg(hsotg->dev, "GLOBALOUTNAK\n"); |
1673 | case __status(GRXSTS_PktSts_GlobalOutNAK): | ||
1674 | dev_dbg(hsotg->dev, "GlobalOutNAK\n"); | ||
1675 | break; | 1505 | break; |
1676 | 1506 | ||
1677 | case __status(GRXSTS_PktSts_OutDone): | 1507 | case GRXSTS_PKTSTS_OUTDONE: |
1678 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", | 1508 | dev_dbg(hsotg->dev, "OutDone (Frame=0x%08x)\n", |
1679 | s3c_hsotg_read_frameno(hsotg)); | 1509 | s3c_hsotg_read_frameno(hsotg)); |
1680 | 1510 | ||
@@ -1682,7 +1512,7 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1682 | s3c_hsotg_handle_outdone(hsotg, epnum, false); | 1512 | s3c_hsotg_handle_outdone(hsotg, epnum, false); |
1683 | break; | 1513 | break; |
1684 | 1514 | ||
1685 | case __status(GRXSTS_PktSts_SetupDone): | 1515 | case GRXSTS_PKTSTS_SETUPDONE: |
1686 | dev_dbg(hsotg->dev, | 1516 | dev_dbg(hsotg->dev, |
1687 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", | 1517 | "SetupDone (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
1688 | s3c_hsotg_read_frameno(hsotg), | 1518 | s3c_hsotg_read_frameno(hsotg), |
@@ -1691,11 +1521,11 @@ static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) | |||
1691 | s3c_hsotg_handle_outdone(hsotg, epnum, true); | 1521 | s3c_hsotg_handle_outdone(hsotg, epnum, true); |
1692 | break; | 1522 | break; |
1693 | 1523 | ||
1694 | case __status(GRXSTS_PktSts_OutRX): | 1524 | case GRXSTS_PKTSTS_OUTRX: |
1695 | s3c_hsotg_rx_data(hsotg, epnum, size); | 1525 | s3c_hsotg_rx_data(hsotg, epnum, size); |
1696 | break; | 1526 | break; |
1697 | 1527 | ||
1698 | case __status(GRXSTS_PktSts_SetupRX): | 1528 | case GRXSTS_PKTSTS_SETUPRX: |
1699 | dev_dbg(hsotg->dev, | 1529 | dev_dbg(hsotg->dev, |
1700 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", | 1530 | "SetupRX (Frame=0x%08x, DOPEPCTL=0x%08x)\n", |
1701 | s3c_hsotg_read_frameno(hsotg), | 1531 | s3c_hsotg_read_frameno(hsotg), |
@@ -1761,7 +1591,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1761 | hs_ep->ep.maxpacket = mps; | 1591 | hs_ep->ep.maxpacket = mps; |
1762 | hs_ep->mc = 1; | 1592 | hs_ep->mc = 1; |
1763 | } else { | 1593 | } else { |
1764 | mpsval = mps & DxEPCTL_MPS_MASK; | 1594 | mpsval = mps & DXEPCTL_MPS_MASK; |
1765 | if (mpsval > 1024) | 1595 | if (mpsval > 1024) |
1766 | goto bad_mps; | 1596 | goto bad_mps; |
1767 | mcval = ((mps >> 11) & 0x3) + 1; | 1597 | mcval = ((mps >> 11) & 0x3) + 1; |
@@ -1777,13 +1607,13 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg, | |||
1777 | */ | 1607 | */ |
1778 | 1608 | ||
1779 | reg = readl(regs + DIEPCTL(ep)); | 1609 | reg = readl(regs + DIEPCTL(ep)); |
1780 | reg &= ~DxEPCTL_MPS_MASK; | 1610 | reg &= ~DXEPCTL_MPS_MASK; |
1781 | reg |= mpsval; | 1611 | reg |= mpsval; |
1782 | writel(reg, regs + DIEPCTL(ep)); | 1612 | writel(reg, regs + DIEPCTL(ep)); |
1783 | 1613 | ||
1784 | if (ep) { | 1614 | if (ep) { |
1785 | reg = readl(regs + DOEPCTL(ep)); | 1615 | reg = readl(regs + DOEPCTL(ep)); |
1786 | reg &= ~DxEPCTL_MPS_MASK; | 1616 | reg &= ~DXEPCTL_MPS_MASK; |
1787 | reg |= mpsval; | 1617 | reg |= mpsval; |
1788 | writel(reg, regs + DOEPCTL(ep)); | 1618 | writel(reg, regs + DOEPCTL(ep)); |
1789 | } | 1619 | } |
@@ -1804,7 +1634,7 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) | |||
1804 | int timeout; | 1634 | int timeout; |
1805 | int val; | 1635 | int val; |
1806 | 1636 | ||
1807 | writel(GRSTCTL_TxFNum(idx) | GRSTCTL_TxFFlsh, | 1637 | writel(GRSTCTL_TXFNUM(idx) | GRSTCTL_TXFFLSH, |
1808 | hsotg->regs + GRSTCTL); | 1638 | hsotg->regs + GRSTCTL); |
1809 | 1639 | ||
1810 | /* wait until the fifo is flushed */ | 1640 | /* wait until the fifo is flushed */ |
@@ -1813,7 +1643,7 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx) | |||
1813 | while (1) { | 1643 | while (1) { |
1814 | val = readl(hsotg->regs + GRSTCTL); | 1644 | val = readl(hsotg->regs + GRSTCTL); |
1815 | 1645 | ||
1816 | if ((val & (GRSTCTL_TxFFlsh)) == 0) | 1646 | if ((val & (GRSTCTL_TXFFLSH)) == 0) |
1817 | break; | 1647 | break; |
1818 | 1648 | ||
1819 | if (--timeout == 0) { | 1649 | if (--timeout == 0) { |
@@ -1896,7 +1726,7 @@ static void s3c_hsotg_complete_in(struct s3c_hsotg *hsotg, | |||
1896 | * aligned). | 1726 | * aligned). |
1897 | */ | 1727 | */ |
1898 | 1728 | ||
1899 | size_left = DxEPTSIZ_XferSize_GET(epsize); | 1729 | size_left = DXEPTSIZ_XFERSIZE_GET(epsize); |
1900 | 1730 | ||
1901 | size_done = hs_ep->size_loaded - size_left; | 1731 | size_done = hs_ep->size_loaded - size_left; |
1902 | size_done += hs_ep->last_load; | 1732 | size_done += hs_ep->last_load; |
@@ -1963,17 +1793,17 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1963 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", | 1793 | dev_dbg(hsotg->dev, "%s: ep%d(%s) DxEPINT=0x%08x\n", |
1964 | __func__, idx, dir_in ? "in" : "out", ints); | 1794 | __func__, idx, dir_in ? "in" : "out", ints); |
1965 | 1795 | ||
1966 | if (ints & DxEPINT_XferCompl) { | 1796 | if (ints & DXEPINT_XFERCOMPL) { |
1967 | if (hs_ep->isochronous && hs_ep->interval == 1) { | 1797 | if (hs_ep->isochronous && hs_ep->interval == 1) { |
1968 | if (ctrl & DxEPCTL_EOFrNum) | 1798 | if (ctrl & DXEPCTL_EOFRNUM) |
1969 | ctrl |= DxEPCTL_SetEvenFr; | 1799 | ctrl |= DXEPCTL_SETEVENFR; |
1970 | else | 1800 | else |
1971 | ctrl |= DxEPCTL_SetOddFr; | 1801 | ctrl |= DXEPCTL_SETODDFR; |
1972 | writel(ctrl, hsotg->regs + epctl_reg); | 1802 | writel(ctrl, hsotg->regs + epctl_reg); |
1973 | } | 1803 | } |
1974 | 1804 | ||
1975 | dev_dbg(hsotg->dev, | 1805 | dev_dbg(hsotg->dev, |
1976 | "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", | 1806 | "%s: XferCompl: DxEPCTL=0x%08x, DXEPTSIZ=%08x\n", |
1977 | __func__, readl(hsotg->regs + epctl_reg), | 1807 | __func__, readl(hsotg->regs + epctl_reg), |
1978 | readl(hsotg->regs + epsiz_reg)); | 1808 | readl(hsotg->regs + epsiz_reg)); |
1979 | 1809 | ||
@@ -1996,7 +1826,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
1996 | } | 1826 | } |
1997 | } | 1827 | } |
1998 | 1828 | ||
1999 | if (ints & DxEPINT_EPDisbld) { | 1829 | if (ints & DXEPINT_EPDISBLD) { |
2000 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); | 1830 | dev_dbg(hsotg->dev, "%s: EPDisbld\n", __func__); |
2001 | 1831 | ||
2002 | if (dir_in) { | 1832 | if (dir_in) { |
@@ -2004,20 +1834,20 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
2004 | 1834 | ||
2005 | s3c_hsotg_txfifo_flush(hsotg, idx); | 1835 | s3c_hsotg_txfifo_flush(hsotg, idx); |
2006 | 1836 | ||
2007 | if ((epctl & DxEPCTL_Stall) && | 1837 | if ((epctl & DXEPCTL_STALL) && |
2008 | (epctl & DxEPCTL_EPType_Bulk)) { | 1838 | (epctl & DXEPCTL_EPTYPE_BULK)) { |
2009 | int dctl = readl(hsotg->regs + DCTL); | 1839 | int dctl = readl(hsotg->regs + DCTL); |
2010 | 1840 | ||
2011 | dctl |= DCTL_CGNPInNAK; | 1841 | dctl |= DCTL_CGNPINNAK; |
2012 | writel(dctl, hsotg->regs + DCTL); | 1842 | writel(dctl, hsotg->regs + DCTL); |
2013 | } | 1843 | } |
2014 | } | 1844 | } |
2015 | } | 1845 | } |
2016 | 1846 | ||
2017 | if (ints & DxEPINT_AHBErr) | 1847 | if (ints & DXEPINT_AHBERR) |
2018 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); | 1848 | dev_dbg(hsotg->dev, "%s: AHBErr\n", __func__); |
2019 | 1849 | ||
2020 | if (ints & DxEPINT_Setup) { /* Setup or Timeout */ | 1850 | if (ints & DXEPINT_SETUP) { /* Setup or Timeout */ |
2021 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); | 1851 | dev_dbg(hsotg->dev, "%s: Setup/Timeout\n", __func__); |
2022 | 1852 | ||
2023 | if (using_dma(hsotg) && idx == 0) { | 1853 | if (using_dma(hsotg) && idx == 0) { |
@@ -2035,25 +1865,25 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx, | |||
2035 | } | 1865 | } |
2036 | } | 1866 | } |
2037 | 1867 | ||
2038 | if (ints & DxEPINT_Back2BackSetup) | 1868 | if (ints & DXEPINT_BACK2BACKSETUP) |
2039 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); | 1869 | dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); |
2040 | 1870 | ||
2041 | if (dir_in && !hs_ep->isochronous) { | 1871 | if (dir_in && !hs_ep->isochronous) { |
2042 | /* not sure if this is important, but we'll clear it anyway */ | 1872 | /* not sure if this is important, but we'll clear it anyway */ |
2043 | if (ints & DIEPMSK_INTknTXFEmpMsk) { | 1873 | if (ints & DIEPMSK_INTKNTXFEMPMSK) { |
2044 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", | 1874 | dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", |
2045 | __func__, idx); | 1875 | __func__, idx); |
2046 | } | 1876 | } |
2047 | 1877 | ||
2048 | /* this probably means something bad is happening */ | 1878 | /* this probably means something bad is happening */ |
2049 | if (ints & DIEPMSK_INTknEPMisMsk) { | 1879 | if (ints & DIEPMSK_INTKNEPMISMSK) { |
2050 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", | 1880 | dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", |
2051 | __func__, idx); | 1881 | __func__, idx); |
2052 | } | 1882 | } |
2053 | 1883 | ||
2054 | /* FIFO has space or is empty (see GAHBCFG) */ | 1884 | /* FIFO has space or is empty (see GAHBCFG) */ |
2055 | if (hsotg->dedicated_fifos && | 1885 | if (hsotg->dedicated_fifos && |
2056 | ints & DIEPMSK_TxFIFOEmpty) { | 1886 | ints & DIEPMSK_TXFIFOEMPTY) { |
2057 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", | 1887 | dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", |
2058 | __func__, idx); | 1888 | __func__, idx); |
2059 | if (!using_dma(hsotg)) | 1889 | if (!using_dma(hsotg)) |
@@ -2089,21 +1919,21 @@ static void s3c_hsotg_irq_enumdone(struct s3c_hsotg *hsotg) | |||
2089 | */ | 1919 | */ |
2090 | 1920 | ||
2091 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ | 1921 | /* catch both EnumSpd_FS and EnumSpd_FS48 */ |
2092 | switch (dsts & DSTS_EnumSpd_MASK) { | 1922 | switch (dsts & DSTS_ENUMSPD_MASK) { |
2093 | case DSTS_EnumSpd_FS: | 1923 | case DSTS_ENUMSPD_FS: |
2094 | case DSTS_EnumSpd_FS48: | 1924 | case DSTS_ENUMSPD_FS48: |
2095 | hsotg->gadget.speed = USB_SPEED_FULL; | 1925 | hsotg->gadget.speed = USB_SPEED_FULL; |
2096 | ep0_mps = EP0_MPS_LIMIT; | 1926 | ep0_mps = EP0_MPS_LIMIT; |
2097 | ep_mps = 1023; | 1927 | ep_mps = 1023; |
2098 | break; | 1928 | break; |
2099 | 1929 | ||
2100 | case DSTS_EnumSpd_HS: | 1930 | case DSTS_ENUMSPD_HS: |
2101 | hsotg->gadget.speed = USB_SPEED_HIGH; | 1931 | hsotg->gadget.speed = USB_SPEED_HIGH; |
2102 | ep0_mps = EP0_MPS_LIMIT; | 1932 | ep0_mps = EP0_MPS_LIMIT; |
2103 | ep_mps = 1024; | 1933 | ep_mps = 1024; |
2104 | break; | 1934 | break; |
2105 | 1935 | ||
2106 | case DSTS_EnumSpd_LS: | 1936 | case DSTS_ENUMSPD_LS: |
2107 | hsotg->gadget.speed = USB_SPEED_LOW; | 1937 | hsotg->gadget.speed = USB_SPEED_LOW; |
2108 | /* | 1938 | /* |
2109 | * note, we don't actually support LS in this driver at the | 1939 | * note, we don't actually support LS in this driver at the |
@@ -2169,16 +1999,6 @@ static void kill_all_requests(struct s3c_hsotg *hsotg, | |||
2169 | s3c_hsotg_txfifo_flush(hsotg, ep->index); | 1999 | s3c_hsotg_txfifo_flush(hsotg, ep->index); |
2170 | } | 2000 | } |
2171 | 2001 | ||
2172 | #define call_gadget(_hs, _entry) \ | ||
2173 | do { \ | ||
2174 | if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ | ||
2175 | (_hs)->driver && (_hs)->driver->_entry) { \ | ||
2176 | spin_unlock(&_hs->lock); \ | ||
2177 | (_hs)->driver->_entry(&(_hs)->gadget); \ | ||
2178 | spin_lock(&_hs->lock); \ | ||
2179 | } \ | ||
2180 | } while (0) | ||
2181 | |||
2182 | /** | 2002 | /** |
2183 | * s3c_hsotg_disconnect - disconnect service | 2003 | * s3c_hsotg_disconnect - disconnect service |
2184 | * @hsotg: The device state. | 2004 | * @hsotg: The device state. |
@@ -2226,9 +2046,9 @@ static void s3c_hsotg_irq_fifoempty(struct s3c_hsotg *hsotg, bool periodic) | |||
2226 | } | 2046 | } |
2227 | 2047 | ||
2228 | /* IRQ flags which will trigger a retry around the IRQ loop */ | 2048 | /* IRQ flags which will trigger a retry around the IRQ loop */ |
2229 | #define IRQ_RETRY_MASK (GINTSTS_NPTxFEmp | \ | 2049 | #define IRQ_RETRY_MASK (GINTSTS_NPTXFEMP | \ |
2230 | GINTSTS_PTxFEmp | \ | 2050 | GINTSTS_PTXFEMP | \ |
2231 | GINTSTS_RxFLvl) | 2051 | GINTSTS_RXFLVL) |
2232 | 2052 | ||
2233 | /** | 2053 | /** |
2234 | * s3c_hsotg_corereset - issue softreset to the core | 2054 | * s3c_hsotg_corereset - issue softreset to the core |
@@ -2244,14 +2064,14 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2244 | dev_dbg(hsotg->dev, "resetting core\n"); | 2064 | dev_dbg(hsotg->dev, "resetting core\n"); |
2245 | 2065 | ||
2246 | /* issue soft reset */ | 2066 | /* issue soft reset */ |
2247 | writel(GRSTCTL_CSftRst, hsotg->regs + GRSTCTL); | 2067 | writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); |
2248 | 2068 | ||
2249 | timeout = 10000; | 2069 | timeout = 10000; |
2250 | do { | 2070 | do { |
2251 | grstctl = readl(hsotg->regs + GRSTCTL); | 2071 | grstctl = readl(hsotg->regs + GRSTCTL); |
2252 | } while ((grstctl & GRSTCTL_CSftRst) && timeout-- > 0); | 2072 | } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); |
2253 | 2073 | ||
2254 | if (grstctl & GRSTCTL_CSftRst) { | 2074 | if (grstctl & GRSTCTL_CSFTRST) { |
2255 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); | 2075 | dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); |
2256 | return -EINVAL; | 2076 | return -EINVAL; |
2257 | } | 2077 | } |
@@ -2268,7 +2088,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg) | |||
2268 | return -ETIMEDOUT; | 2088 | return -ETIMEDOUT; |
2269 | } | 2089 | } |
2270 | 2090 | ||
2271 | if (!(grstctl & GRSTCTL_AHBIdle)) | 2091 | if (!(grstctl & GRSTCTL_AHBIDLE)) |
2272 | continue; | 2092 | continue; |
2273 | 2093 | ||
2274 | break; /* reset done */ | 2094 | break; /* reset done */ |
@@ -2294,14 +2114,14 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2294 | */ | 2114 | */ |
2295 | 2115 | ||
2296 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | 2116 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
2297 | writel(hsotg->phyif | GUSBCFG_TOutCal(7) | | 2117 | writel(hsotg->phyif | GUSBCFG_TOUTCAL(7) | |
2298 | (0x5 << 10), hsotg->regs + GUSBCFG); | 2118 | (0x5 << 10), hsotg->regs + GUSBCFG); |
2299 | 2119 | ||
2300 | s3c_hsotg_init_fifo(hsotg); | 2120 | s3c_hsotg_init_fifo(hsotg); |
2301 | 2121 | ||
2302 | __orr32(hsotg->regs + DCTL, DCTL_SftDiscon); | 2122 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
2303 | 2123 | ||
2304 | writel(1 << 18 | DCFG_DevSpd_HS, hsotg->regs + DCFG); | 2124 | writel(1 << 18 | DCFG_DEVSPD_HS, hsotg->regs + DCFG); |
2305 | 2125 | ||
2306 | /* Clear any pending OTG interrupts */ | 2126 | /* Clear any pending OTG interrupts */ |
2307 | writel(0xffffffff, hsotg->regs + GOTGINT); | 2127 | writel(0xffffffff, hsotg->regs + GOTGINT); |
@@ -2309,21 +2129,21 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2309 | /* Clear any pending interrupts */ | 2129 | /* Clear any pending interrupts */ |
2310 | writel(0xffffffff, hsotg->regs + GINTSTS); | 2130 | writel(0xffffffff, hsotg->regs + GINTSTS); |
2311 | 2131 | ||
2312 | writel(GINTSTS_ErlySusp | GINTSTS_SessReqInt | | 2132 | writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT | |
2313 | GINTSTS_GOUTNakEff | GINTSTS_GINNakEff | | 2133 | GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF | |
2314 | GINTSTS_ConIDStsChng | GINTSTS_USBRst | | 2134 | GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST | |
2315 | GINTSTS_EnumDone | GINTSTS_OTGInt | | 2135 | GINTSTS_ENUMDONE | GINTSTS_OTGINT | |
2316 | GINTSTS_USBSusp | GINTSTS_WkUpInt, | 2136 | GINTSTS_USBSUSP | GINTSTS_WKUPINT, |
2317 | hsotg->regs + GINTMSK); | 2137 | hsotg->regs + GINTMSK); |
2318 | 2138 | ||
2319 | if (using_dma(hsotg)) | 2139 | if (using_dma(hsotg)) |
2320 | writel(GAHBCFG_GlblIntrEn | GAHBCFG_DMAEn | | 2140 | writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | |
2321 | GAHBCFG_HBstLen_Incr4, | 2141 | GAHBCFG_HBSTLEN_INCR4, |
2322 | hsotg->regs + GAHBCFG); | 2142 | hsotg->regs + GAHBCFG); |
2323 | else | 2143 | else |
2324 | writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NPTxFEmpLvl | | 2144 | writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL | |
2325 | GAHBCFG_PTxFEmpLvl) : 0) | | 2145 | GAHBCFG_P_TXF_EMP_LVL) : 0) | |
2326 | GAHBCFG_GlblIntrEn, | 2146 | GAHBCFG_GLBL_INTR_EN, |
2327 | hsotg->regs + GAHBCFG); | 2147 | hsotg->regs + GAHBCFG); |
2328 | 2148 | ||
2329 | /* | 2149 | /* |
@@ -2332,22 +2152,22 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2332 | * interrupts. | 2152 | * interrupts. |
2333 | */ | 2153 | */ |
2334 | 2154 | ||
2335 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty | | 2155 | writel(((hsotg->dedicated_fifos) ? DIEPMSK_TXFIFOEMPTY | |
2336 | DIEPMSK_INTknTXFEmpMsk : 0) | | 2156 | DIEPMSK_INTKNTXFEMPMSK : 0) | |
2337 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | | 2157 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK | |
2338 | DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | | 2158 | DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
2339 | DIEPMSK_INTknEPMisMsk, | 2159 | DIEPMSK_INTKNEPMISMSK, |
2340 | hsotg->regs + DIEPMSK); | 2160 | hsotg->regs + DIEPMSK); |
2341 | 2161 | ||
2342 | /* | 2162 | /* |
2343 | * don't need XferCompl, we get that from RXFIFO in slave mode. In | 2163 | * don't need XferCompl, we get that from RXFIFO in slave mode. In |
2344 | * DMA mode we may need this. | 2164 | * DMA mode we may need this. |
2345 | */ | 2165 | */ |
2346 | writel((using_dma(hsotg) ? (DIEPMSK_XferComplMsk | | 2166 | writel((using_dma(hsotg) ? (DIEPMSK_XFERCOMPLMSK | |
2347 | DIEPMSK_TimeOUTMsk) : 0) | | 2167 | DIEPMSK_TIMEOUTMSK) : 0) | |
2348 | DOEPMSK_EPDisbldMsk | DOEPMSK_AHBErrMsk | | 2168 | DOEPMSK_EPDISBLDMSK | DOEPMSK_AHBERRMSK | |
2349 | DOEPMSK_SetupMsk, | 2169 | DOEPMSK_SETUPMSK, |
2350 | hsotg->regs + DOEPMSK); | 2170 | hsotg->regs + DOEPMSK); |
2351 | 2171 | ||
2352 | writel(0, hsotg->regs + DAINTMSK); | 2172 | writel(0, hsotg->regs + DAINTMSK); |
2353 | 2173 | ||
@@ -2356,7 +2176,7 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2356 | readl(hsotg->regs + DOEPCTL0)); | 2176 | readl(hsotg->regs + DOEPCTL0)); |
2357 | 2177 | ||
2358 | /* enable in and out endpoint interrupts */ | 2178 | /* enable in and out endpoint interrupts */ |
2359 | s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPInt | GINTSTS_IEPInt); | 2179 | s3c_hsotg_en_gsint(hsotg, GINTSTS_OEPINT | GINTSTS_IEPINT); |
2360 | 2180 | ||
2361 | /* | 2181 | /* |
2362 | * Enable the RXFIFO when in slave mode, as this is how we collect | 2182 | * Enable the RXFIFO when in slave mode, as this is how we collect |
@@ -2364,15 +2184,15 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2364 | * things we cannot process, so do not use it. | 2184 | * things we cannot process, so do not use it. |
2365 | */ | 2185 | */ |
2366 | if (!using_dma(hsotg)) | 2186 | if (!using_dma(hsotg)) |
2367 | s3c_hsotg_en_gsint(hsotg, GINTSTS_RxFLvl); | 2187 | s3c_hsotg_en_gsint(hsotg, GINTSTS_RXFLVL); |
2368 | 2188 | ||
2369 | /* Enable interrupts for EP0 in and out */ | 2189 | /* Enable interrupts for EP0 in and out */ |
2370 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); | 2190 | s3c_hsotg_ctrl_epint(hsotg, 0, 0, 1); |
2371 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); | 2191 | s3c_hsotg_ctrl_epint(hsotg, 0, 1, 1); |
2372 | 2192 | ||
2373 | __orr32(hsotg->regs + DCTL, DCTL_PWROnPrgDone); | 2193 | __orr32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
2374 | udelay(10); /* see openiboot */ | 2194 | udelay(10); /* see openiboot */ |
2375 | __bic32(hsotg->regs + DCTL, DCTL_PWROnPrgDone); | 2195 | __bic32(hsotg->regs + DCTL, DCTL_PWRONPRGDONE); |
2376 | 2196 | ||
2377 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); | 2197 | dev_dbg(hsotg->dev, "DCTL=0x%08x\n", readl(hsotg->regs + DCTL)); |
2378 | 2198 | ||
@@ -2382,17 +2202,17 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2382 | */ | 2202 | */ |
2383 | 2203 | ||
2384 | /* set to read 1 8byte packet */ | 2204 | /* set to read 1 8byte packet */ |
2385 | writel(DxEPTSIZ_MC(1) | DxEPTSIZ_PktCnt(1) | | 2205 | writel(DXEPTSIZ_MC(1) | DXEPTSIZ_PKTCNT(1) | |
2386 | DxEPTSIZ_XferSize(8), hsotg->regs + DOEPTSIZ0); | 2206 | DXEPTSIZ_XFERSIZE(8), hsotg->regs + DOEPTSIZ0); |
2387 | 2207 | ||
2388 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | 2208 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
2389 | DxEPCTL_CNAK | DxEPCTL_EPEna | | 2209 | DXEPCTL_CNAK | DXEPCTL_EPENA | |
2390 | DxEPCTL_USBActEp, | 2210 | DXEPCTL_USBACTEP, |
2391 | hsotg->regs + DOEPCTL0); | 2211 | hsotg->regs + DOEPCTL0); |
2392 | 2212 | ||
2393 | /* enable, but don't activate EP0in */ | 2213 | /* enable, but don't activate EP0in */ |
2394 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | | 2214 | writel(s3c_hsotg_ep0_mps(hsotg->eps[0].ep.maxpacket) | |
2395 | DxEPCTL_USBActEp, hsotg->regs + DIEPCTL0); | 2215 | DXEPCTL_USBACTEP, hsotg->regs + DIEPCTL0); |
2396 | 2216 | ||
2397 | s3c_hsotg_enqueue_setup(hsotg); | 2217 | s3c_hsotg_enqueue_setup(hsotg); |
2398 | 2218 | ||
@@ -2401,14 +2221,14 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) | |||
2401 | readl(hsotg->regs + DOEPCTL0)); | 2221 | readl(hsotg->regs + DOEPCTL0)); |
2402 | 2222 | ||
2403 | /* clear global NAKs */ | 2223 | /* clear global NAKs */ |
2404 | writel(DCTL_CGOUTNak | DCTL_CGNPInNAK, | 2224 | writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK, |
2405 | hsotg->regs + DCTL); | 2225 | hsotg->regs + DCTL); |
2406 | 2226 | ||
2407 | /* must be at-least 3ms to allow bus to see disconnect */ | 2227 | /* must be at-least 3ms to allow bus to see disconnect */ |
2408 | mdelay(3); | 2228 | mdelay(3); |
2409 | 2229 | ||
2410 | /* remove the soft-disconnect and let's go */ | 2230 | /* remove the soft-disconnect and let's go */ |
2411 | __bic32(hsotg->regs + DCTL, DCTL_SftDiscon); | 2231 | __bic32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
2412 | } | 2232 | } |
2413 | 2233 | ||
2414 | /** | 2234 | /** |
@@ -2433,7 +2253,7 @@ irq_retry: | |||
2433 | 2253 | ||
2434 | gintsts &= gintmsk; | 2254 | gintsts &= gintmsk; |
2435 | 2255 | ||
2436 | if (gintsts & GINTSTS_OTGInt) { | 2256 | if (gintsts & GINTSTS_OTGINT) { |
2437 | u32 otgint = readl(hsotg->regs + GOTGINT); | 2257 | u32 otgint = readl(hsotg->regs + GOTGINT); |
2438 | 2258 | ||
2439 | dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); | 2259 | dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); |
@@ -2441,34 +2261,34 @@ irq_retry: | |||
2441 | writel(otgint, hsotg->regs + GOTGINT); | 2261 | writel(otgint, hsotg->regs + GOTGINT); |
2442 | } | 2262 | } |
2443 | 2263 | ||
2444 | if (gintsts & GINTSTS_SessReqInt) { | 2264 | if (gintsts & GINTSTS_SESSREQINT) { |
2445 | dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); | 2265 | dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); |
2446 | writel(GINTSTS_SessReqInt, hsotg->regs + GINTSTS); | 2266 | writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); |
2447 | } | 2267 | } |
2448 | 2268 | ||
2449 | if (gintsts & GINTSTS_EnumDone) { | 2269 | if (gintsts & GINTSTS_ENUMDONE) { |
2450 | writel(GINTSTS_EnumDone, hsotg->regs + GINTSTS); | 2270 | writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); |
2451 | 2271 | ||
2452 | s3c_hsotg_irq_enumdone(hsotg); | 2272 | s3c_hsotg_irq_enumdone(hsotg); |
2453 | } | 2273 | } |
2454 | 2274 | ||
2455 | if (gintsts & GINTSTS_ConIDStsChng) { | 2275 | if (gintsts & GINTSTS_CONIDSTSCHNG) { |
2456 | dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", | 2276 | dev_dbg(hsotg->dev, "ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n", |
2457 | readl(hsotg->regs + DSTS), | 2277 | readl(hsotg->regs + DSTS), |
2458 | readl(hsotg->regs + GOTGCTL)); | 2278 | readl(hsotg->regs + GOTGCTL)); |
2459 | 2279 | ||
2460 | writel(GINTSTS_ConIDStsChng, hsotg->regs + GINTSTS); | 2280 | writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); |
2461 | } | 2281 | } |
2462 | 2282 | ||
2463 | if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { | 2283 | if (gintsts & (GINTSTS_OEPINT | GINTSTS_IEPINT)) { |
2464 | u32 daint = readl(hsotg->regs + DAINT); | 2284 | u32 daint = readl(hsotg->regs + DAINT); |
2465 | u32 daintmsk = readl(hsotg->regs + DAINTMSK); | 2285 | u32 daintmsk = readl(hsotg->regs + DAINTMSK); |
2466 | u32 daint_out, daint_in; | 2286 | u32 daint_out, daint_in; |
2467 | int ep; | 2287 | int ep; |
2468 | 2288 | ||
2469 | daint &= daintmsk; | 2289 | daint &= daintmsk; |
2470 | daint_out = daint >> DAINT_OutEP_SHIFT; | 2290 | daint_out = daint >> DAINT_OUTEP_SHIFT; |
2471 | daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); | 2291 | daint_in = daint & ~(daint_out << DAINT_OUTEP_SHIFT); |
2472 | 2292 | ||
2473 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); | 2293 | dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); |
2474 | 2294 | ||
@@ -2483,7 +2303,7 @@ irq_retry: | |||
2483 | } | 2303 | } |
2484 | } | 2304 | } |
2485 | 2305 | ||
2486 | if (gintsts & GINTSTS_USBRst) { | 2306 | if (gintsts & GINTSTS_USBRST) { |
2487 | 2307 | ||
2488 | u32 usb_status = readl(hsotg->regs + GOTGCTL); | 2308 | u32 usb_status = readl(hsotg->regs + GOTGCTL); |
2489 | 2309 | ||
@@ -2491,7 +2311,7 @@ irq_retry: | |||
2491 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", | 2311 | dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", |
2492 | readl(hsotg->regs + GNPTXSTS)); | 2312 | readl(hsotg->regs + GNPTXSTS)); |
2493 | 2313 | ||
2494 | writel(GINTSTS_USBRst, hsotg->regs + GINTSTS); | 2314 | writel(GINTSTS_USBRST, hsotg->regs + GINTSTS); |
2495 | 2315 | ||
2496 | if (usb_status & GOTGCTL_BSESVLD) { | 2316 | if (usb_status & GOTGCTL_BSESVLD) { |
2497 | if (time_after(jiffies, hsotg->last_rst + | 2317 | if (time_after(jiffies, hsotg->last_rst + |
@@ -2508,7 +2328,7 @@ irq_retry: | |||
2508 | 2328 | ||
2509 | /* check both FIFOs */ | 2329 | /* check both FIFOs */ |
2510 | 2330 | ||
2511 | if (gintsts & GINTSTS_NPTxFEmp) { | 2331 | if (gintsts & GINTSTS_NPTXFEMP) { |
2512 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); | 2332 | dev_dbg(hsotg->dev, "NPTxFEmp\n"); |
2513 | 2333 | ||
2514 | /* | 2334 | /* |
@@ -2517,20 +2337,20 @@ irq_retry: | |||
2517 | * it needs re-enabling | 2337 | * it needs re-enabling |
2518 | */ | 2338 | */ |
2519 | 2339 | ||
2520 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTxFEmp); | 2340 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_NPTXFEMP); |
2521 | s3c_hsotg_irq_fifoempty(hsotg, false); | 2341 | s3c_hsotg_irq_fifoempty(hsotg, false); |
2522 | } | 2342 | } |
2523 | 2343 | ||
2524 | if (gintsts & GINTSTS_PTxFEmp) { | 2344 | if (gintsts & GINTSTS_PTXFEMP) { |
2525 | dev_dbg(hsotg->dev, "PTxFEmp\n"); | 2345 | dev_dbg(hsotg->dev, "PTxFEmp\n"); |
2526 | 2346 | ||
2527 | /* See note in GINTSTS_NPTxFEmp */ | 2347 | /* See note in GINTSTS_NPTxFEmp */ |
2528 | 2348 | ||
2529 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTxFEmp); | 2349 | s3c_hsotg_disable_gsint(hsotg, GINTSTS_PTXFEMP); |
2530 | s3c_hsotg_irq_fifoempty(hsotg, true); | 2350 | s3c_hsotg_irq_fifoempty(hsotg, true); |
2531 | } | 2351 | } |
2532 | 2352 | ||
2533 | if (gintsts & GINTSTS_RxFLvl) { | 2353 | if (gintsts & GINTSTS_RXFLVL) { |
2534 | /* | 2354 | /* |
2535 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, | 2355 | * note, since GINTSTS_RxFLvl doubles as FIFO-not-empty, |
2536 | * we need to retry s3c_hsotg_handle_rx if this is still | 2356 | * we need to retry s3c_hsotg_handle_rx if this is still |
@@ -2540,28 +2360,28 @@ irq_retry: | |||
2540 | s3c_hsotg_handle_rx(hsotg); | 2360 | s3c_hsotg_handle_rx(hsotg); |
2541 | } | 2361 | } |
2542 | 2362 | ||
2543 | if (gintsts & GINTSTS_ModeMis) { | 2363 | if (gintsts & GINTSTS_MODEMIS) { |
2544 | dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); | 2364 | dev_warn(hsotg->dev, "warning, mode mismatch triggered\n"); |
2545 | writel(GINTSTS_ModeMis, hsotg->regs + GINTSTS); | 2365 | writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); |
2546 | } | 2366 | } |
2547 | 2367 | ||
2548 | if (gintsts & GINTSTS_USBSusp) { | 2368 | if (gintsts & GINTSTS_USBSUSP) { |
2549 | dev_info(hsotg->dev, "GINTSTS_USBSusp\n"); | 2369 | dev_info(hsotg->dev, "GINTSTS_USBSusp\n"); |
2550 | writel(GINTSTS_USBSusp, hsotg->regs + GINTSTS); | 2370 | writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); |
2551 | 2371 | ||
2552 | call_gadget(hsotg, suspend); | 2372 | call_gadget(hsotg, suspend); |
2553 | } | 2373 | } |
2554 | 2374 | ||
2555 | if (gintsts & GINTSTS_WkUpInt) { | 2375 | if (gintsts & GINTSTS_WKUPINT) { |
2556 | dev_info(hsotg->dev, "GINTSTS_WkUpIn\n"); | 2376 | dev_info(hsotg->dev, "GINTSTS_WkUpIn\n"); |
2557 | writel(GINTSTS_WkUpInt, hsotg->regs + GINTSTS); | 2377 | writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); |
2558 | 2378 | ||
2559 | call_gadget(hsotg, resume); | 2379 | call_gadget(hsotg, resume); |
2560 | } | 2380 | } |
2561 | 2381 | ||
2562 | if (gintsts & GINTSTS_ErlySusp) { | 2382 | if (gintsts & GINTSTS_ERLYSUSP) { |
2563 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); | 2383 | dev_dbg(hsotg->dev, "GINTSTS_ErlySusp\n"); |
2564 | writel(GINTSTS_ErlySusp, hsotg->regs + GINTSTS); | 2384 | writel(GINTSTS_ERLYSUSP, hsotg->regs + GINTSTS); |
2565 | } | 2385 | } |
2566 | 2386 | ||
2567 | /* | 2387 | /* |
@@ -2570,18 +2390,18 @@ irq_retry: | |||
2570 | * the occurrence. | 2390 | * the occurrence. |
2571 | */ | 2391 | */ |
2572 | 2392 | ||
2573 | if (gintsts & GINTSTS_GOUTNakEff) { | 2393 | if (gintsts & GINTSTS_GOUTNAKEFF) { |
2574 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); | 2394 | dev_info(hsotg->dev, "GOUTNakEff triggered\n"); |
2575 | 2395 | ||
2576 | writel(DCTL_CGOUTNak, hsotg->regs + DCTL); | 2396 | writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); |
2577 | 2397 | ||
2578 | s3c_hsotg_dump(hsotg); | 2398 | s3c_hsotg_dump(hsotg); |
2579 | } | 2399 | } |
2580 | 2400 | ||
2581 | if (gintsts & GINTSTS_GINNakEff) { | 2401 | if (gintsts & GINTSTS_GINNAKEFF) { |
2582 | dev_info(hsotg->dev, "GINNakEff triggered\n"); | 2402 | dev_info(hsotg->dev, "GINNakEff triggered\n"); |
2583 | 2403 | ||
2584 | writel(DCTL_CGNPInNAK, hsotg->regs + DCTL); | 2404 | writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); |
2585 | 2405 | ||
2586 | s3c_hsotg_dump(hsotg); | 2406 | s3c_hsotg_dump(hsotg); |
2587 | } | 2407 | } |
@@ -2645,14 +2465,14 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2645 | 2465 | ||
2646 | spin_lock_irqsave(&hsotg->lock, flags); | 2466 | spin_lock_irqsave(&hsotg->lock, flags); |
2647 | 2467 | ||
2648 | epctrl &= ~(DxEPCTL_EPType_MASK | DxEPCTL_MPS_MASK); | 2468 | epctrl &= ~(DXEPCTL_EPTYPE_MASK | DXEPCTL_MPS_MASK); |
2649 | epctrl |= DxEPCTL_MPS(mps); | 2469 | epctrl |= DXEPCTL_MPS(mps); |
2650 | 2470 | ||
2651 | /* | 2471 | /* |
2652 | * mark the endpoint as active, otherwise the core may ignore | 2472 | * mark the endpoint as active, otherwise the core may ignore |
2653 | * transactions entirely for this endpoint | 2473 | * transactions entirely for this endpoint |
2654 | */ | 2474 | */ |
2655 | epctrl |= DxEPCTL_USBActEp; | 2475 | epctrl |= DXEPCTL_USBACTEP; |
2656 | 2476 | ||
2657 | /* | 2477 | /* |
2658 | * set the NAK status on the endpoint, otherwise we might try and | 2478 | * set the NAK status on the endpoint, otherwise we might try and |
@@ -2661,7 +2481,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2661 | * size register hasn't been set. | 2481 | * size register hasn't been set. |
2662 | */ | 2482 | */ |
2663 | 2483 | ||
2664 | epctrl |= DxEPCTL_SNAK; | 2484 | epctrl |= DXEPCTL_SNAK; |
2665 | 2485 | ||
2666 | /* update the endpoint state */ | 2486 | /* update the endpoint state */ |
2667 | s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); | 2487 | s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps); |
@@ -2677,15 +2497,15 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2677 | 2497 | ||
2678 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | 2498 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
2679 | case USB_ENDPOINT_XFER_ISOC: | 2499 | case USB_ENDPOINT_XFER_ISOC: |
2680 | epctrl |= DxEPCTL_EPType_Iso; | 2500 | epctrl |= DXEPCTL_EPTYPE_ISO; |
2681 | epctrl |= DxEPCTL_SetEvenFr; | 2501 | epctrl |= DXEPCTL_SETEVENFR; |
2682 | hs_ep->isochronous = 1; | 2502 | hs_ep->isochronous = 1; |
2683 | if (dir_in) | 2503 | if (dir_in) |
2684 | hs_ep->periodic = 1; | 2504 | hs_ep->periodic = 1; |
2685 | break; | 2505 | break; |
2686 | 2506 | ||
2687 | case USB_ENDPOINT_XFER_BULK: | 2507 | case USB_ENDPOINT_XFER_BULK: |
2688 | epctrl |= DxEPCTL_EPType_Bulk; | 2508 | epctrl |= DXEPCTL_EPTYPE_BULK; |
2689 | break; | 2509 | break; |
2690 | 2510 | ||
2691 | case USB_ENDPOINT_XFER_INT: | 2511 | case USB_ENDPOINT_XFER_INT: |
@@ -2698,14 +2518,14 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2698 | */ | 2518 | */ |
2699 | 2519 | ||
2700 | hs_ep->periodic = 1; | 2520 | hs_ep->periodic = 1; |
2701 | epctrl |= DxEPCTL_TxFNum(index); | 2521 | epctrl |= DXEPCTL_TXFNUM(index); |
2702 | } | 2522 | } |
2703 | 2523 | ||
2704 | epctrl |= DxEPCTL_EPType_Intterupt; | 2524 | epctrl |= DXEPCTL_EPTYPE_INTERRUPT; |
2705 | break; | 2525 | break; |
2706 | 2526 | ||
2707 | case USB_ENDPOINT_XFER_CONTROL: | 2527 | case USB_ENDPOINT_XFER_CONTROL: |
2708 | epctrl |= DxEPCTL_EPType_Control; | 2528 | epctrl |= DXEPCTL_EPTYPE_CONTROL; |
2709 | break; | 2529 | break; |
2710 | } | 2530 | } |
2711 | 2531 | ||
@@ -2714,11 +2534,11 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep, | |||
2714 | * a unique tx-fifo even if it is non-periodic. | 2534 | * a unique tx-fifo even if it is non-periodic. |
2715 | */ | 2535 | */ |
2716 | if (dir_in && hsotg->dedicated_fifos) | 2536 | if (dir_in && hsotg->dedicated_fifos) |
2717 | epctrl |= DxEPCTL_TxFNum(index); | 2537 | epctrl |= DXEPCTL_TXFNUM(index); |
2718 | 2538 | ||
2719 | /* for non control endpoints, set PID to D0 */ | 2539 | /* for non control endpoints, set PID to D0 */ |
2720 | if (index) | 2540 | if (index) |
2721 | epctrl |= DxEPCTL_SetD0PID; | 2541 | epctrl |= DXEPCTL_SETD0PID; |
2722 | 2542 | ||
2723 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", | 2543 | dev_dbg(hsotg->dev, "%s: write DxEPCTL=0x%08x\n", |
2724 | __func__, epctrl); | 2544 | __func__, epctrl); |
@@ -2763,9 +2583,9 @@ static int s3c_hsotg_ep_disable(struct usb_ep *ep) | |||
2763 | 2583 | ||
2764 | 2584 | ||
2765 | ctrl = readl(hsotg->regs + epctrl_reg); | 2585 | ctrl = readl(hsotg->regs + epctrl_reg); |
2766 | ctrl &= ~DxEPCTL_EPEna; | 2586 | ctrl &= ~DXEPCTL_EPENA; |
2767 | ctrl &= ~DxEPCTL_USBActEp; | 2587 | ctrl &= ~DXEPCTL_USBACTEP; |
2768 | ctrl |= DxEPCTL_SNAK; | 2588 | ctrl |= DXEPCTL_SNAK; |
2769 | 2589 | ||
2770 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); | 2590 | dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", __func__, ctrl); |
2771 | writel(ctrl, hsotg->regs + epctrl_reg); | 2591 | writel(ctrl, hsotg->regs + epctrl_reg); |
@@ -2852,15 +2672,15 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | |||
2852 | epctl = readl(hs->regs + epreg); | 2672 | epctl = readl(hs->regs + epreg); |
2853 | 2673 | ||
2854 | if (value) { | 2674 | if (value) { |
2855 | epctl |= DxEPCTL_Stall + DxEPCTL_SNAK; | 2675 | epctl |= DXEPCTL_STALL + DXEPCTL_SNAK; |
2856 | if (epctl & DxEPCTL_EPEna) | 2676 | if (epctl & DXEPCTL_EPENA) |
2857 | epctl |= DxEPCTL_EPDis; | 2677 | epctl |= DXEPCTL_EPDIS; |
2858 | } else { | 2678 | } else { |
2859 | epctl &= ~DxEPCTL_Stall; | 2679 | epctl &= ~DXEPCTL_STALL; |
2860 | xfertype = epctl & DxEPCTL_EPType_MASK; | 2680 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
2861 | if (xfertype == DxEPCTL_EPType_Bulk || | 2681 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
2862 | xfertype == DxEPCTL_EPType_Intterupt) | 2682 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
2863 | epctl |= DxEPCTL_SetD0PID; | 2683 | epctl |= DXEPCTL_SETD0PID; |
2864 | } | 2684 | } |
2865 | 2685 | ||
2866 | writel(epctl, hs->regs + epreg); | 2686 | writel(epctl, hs->regs + epreg); |
@@ -2869,13 +2689,13 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value) | |||
2869 | epctl = readl(hs->regs + epreg); | 2689 | epctl = readl(hs->regs + epreg); |
2870 | 2690 | ||
2871 | if (value) | 2691 | if (value) |
2872 | epctl |= DxEPCTL_Stall; | 2692 | epctl |= DXEPCTL_STALL; |
2873 | else { | 2693 | else { |
2874 | epctl &= ~DxEPCTL_Stall; | 2694 | epctl &= ~DXEPCTL_STALL; |
2875 | xfertype = epctl & DxEPCTL_EPType_MASK; | 2695 | xfertype = epctl & DXEPCTL_EPTYPE_MASK; |
2876 | if (xfertype == DxEPCTL_EPType_Bulk || | 2696 | if (xfertype == DXEPCTL_EPTYPE_BULK || |
2877 | xfertype == DxEPCTL_EPType_Intterupt) | 2697 | xfertype == DXEPCTL_EPTYPE_INTERRUPT) |
2878 | epctl |= DxEPCTL_SetD0PID; | 2698 | epctl |= DXEPCTL_SETD0PID; |
2879 | } | 2699 | } |
2880 | 2700 | ||
2881 | writel(epctl, hs->regs + epreg); | 2701 | writel(epctl, hs->regs + epreg); |
@@ -2965,22 +2785,22 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2965 | { | 2785 | { |
2966 | /* unmask subset of endpoint interrupts */ | 2786 | /* unmask subset of endpoint interrupts */ |
2967 | 2787 | ||
2968 | writel(DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | | 2788 | writel(DIEPMSK_TIMEOUTMSK | DIEPMSK_AHBERRMSK | |
2969 | DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk, | 2789 | DIEPMSK_EPDISBLDMSK | DIEPMSK_XFERCOMPLMSK, |
2970 | hsotg->regs + DIEPMSK); | 2790 | hsotg->regs + DIEPMSK); |
2971 | 2791 | ||
2972 | writel(DOEPMSK_SetupMsk | DOEPMSK_AHBErrMsk | | 2792 | writel(DOEPMSK_SETUPMSK | DOEPMSK_AHBERRMSK | |
2973 | DOEPMSK_EPDisbldMsk | DOEPMSK_XferComplMsk, | 2793 | DOEPMSK_EPDISBLDMSK | DOEPMSK_XFERCOMPLMSK, |
2974 | hsotg->regs + DOEPMSK); | 2794 | hsotg->regs + DOEPMSK); |
2975 | 2795 | ||
2976 | writel(0, hsotg->regs + DAINTMSK); | 2796 | writel(0, hsotg->regs + DAINTMSK); |
2977 | 2797 | ||
2978 | /* Be in disconnected state until gadget is registered */ | 2798 | /* Be in disconnected state until gadget is registered */ |
2979 | __orr32(hsotg->regs + DCTL, DCTL_SftDiscon); | 2799 | __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON); |
2980 | 2800 | ||
2981 | if (0) { | 2801 | if (0) { |
2982 | /* post global nak until we're ready */ | 2802 | /* post global nak until we're ready */ |
2983 | writel(DCTL_SGNPInNAK | DCTL_SGOUTNak, | 2803 | writel(DCTL_SGNPINNAK | DCTL_SGOUTNAK, |
2984 | hsotg->regs + DCTL); | 2804 | hsotg->regs + DCTL); |
2985 | } | 2805 | } |
2986 | 2806 | ||
@@ -2993,10 +2813,10 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg) | |||
2993 | s3c_hsotg_init_fifo(hsotg); | 2813 | s3c_hsotg_init_fifo(hsotg); |
2994 | 2814 | ||
2995 | /* set the PLL on, remove the HNP/SRP and set the PHY */ | 2815 | /* set the PLL on, remove the HNP/SRP and set the PHY */ |
2996 | writel(GUSBCFG_PHYIf16 | GUSBCFG_TOutCal(7) | (0x5 << 10), | 2816 | writel(GUSBCFG_PHYIF16 | GUSBCFG_TOUTCAL(7) | (0x5 << 10), |
2997 | hsotg->regs + GUSBCFG); | 2817 | hsotg->regs + GUSBCFG); |
2998 | 2818 | ||
2999 | writel(using_dma(hsotg) ? GAHBCFG_DMAEn : 0x0, | 2819 | writel(using_dma(hsotg) ? GAHBCFG_DMA_EN : 0x0, |
3000 | hsotg->regs + GAHBCFG); | 2820 | hsotg->regs + GAHBCFG); |
3001 | } | 2821 | } |
3002 | 2822 | ||
@@ -3187,8 +3007,8 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3187 | * code is changed to make each endpoint's direction changeable. | 3007 | * code is changed to make each endpoint's direction changeable. |
3188 | */ | 3008 | */ |
3189 | 3009 | ||
3190 | ptxfifo = readl(hsotg->regs + DPTXFSIZn(epnum)); | 3010 | ptxfifo = readl(hsotg->regs + DPTXFSIZN(epnum)); |
3191 | hs_ep->fifo_size = DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; | 3011 | hs_ep->fifo_size = FIFOSIZE_DEPTH_GET(ptxfifo) * 4; |
3192 | 3012 | ||
3193 | /* | 3013 | /* |
3194 | * if we're using dma, we need to set the next-endpoint pointer | 3014 | * if we're using dma, we need to set the next-endpoint pointer |
@@ -3196,7 +3016,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg, | |||
3196 | */ | 3016 | */ |
3197 | 3017 | ||
3198 | if (using_dma(hsotg)) { | 3018 | if (using_dma(hsotg)) { |
3199 | u32 next = DxEPCTL_NextEp((epnum + 1) % 15); | 3019 | u32 next = DXEPCTL_NEXTEP((epnum + 1) % 15); |
3200 | writel(next, hsotg->regs + DIEPCTL(epnum)); | 3020 | writel(next, hsotg->regs + DIEPCTL(epnum)); |
3201 | writel(next, hsotg->regs + DOEPCTL(epnum)); | 3021 | writel(next, hsotg->regs + DOEPCTL(epnum)); |
3202 | } | 3022 | } |
@@ -3250,10 +3070,10 @@ static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) | |||
3250 | /* show periodic fifo settings */ | 3070 | /* show periodic fifo settings */ |
3251 | 3071 | ||
3252 | for (idx = 1; idx <= 15; idx++) { | 3072 | for (idx = 1; idx <= 15; idx++) { |
3253 | val = readl(regs + DPTXFSIZn(idx)); | 3073 | val = readl(regs + DPTXFSIZN(idx)); |
3254 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, | 3074 | dev_info(dev, "DPTx[%d] FSize=%d, StAddr=0x%08x\n", idx, |
3255 | val >> DPTXFSIZn_DPTxFSize_SHIFT, | 3075 | val >> FIFOSIZE_DEPTH_SHIFT, |
3256 | val & DPTXFSIZn_DPTxFStAddr_MASK); | 3076 | val & FIFOSIZE_STARTADDR_MASK); |
3257 | } | 3077 | } |
3258 | 3078 | ||
3259 | for (idx = 0; idx < 15; idx++) { | 3079 | for (idx = 0; idx < 15; idx++) { |
@@ -3368,17 +3188,17 @@ static int fifo_show(struct seq_file *seq, void *v) | |||
3368 | 3188 | ||
3369 | val = readl(regs + GNPTXFSIZ); | 3189 | val = readl(regs + GNPTXFSIZ); |
3370 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", | 3190 | seq_printf(seq, "NPTXFIFO: Size %d, Start 0x%08x\n", |
3371 | val >> GNPTXFSIZ_NPTxFDep_SHIFT, | 3191 | val >> FIFOSIZE_DEPTH_SHIFT, |
3372 | val & GNPTXFSIZ_NPTxFStAddr_MASK); | 3192 | val & FIFOSIZE_DEPTH_MASK); |
3373 | 3193 | ||
3374 | seq_puts(seq, "\nPeriodic TXFIFOs:\n"); | 3194 | seq_puts(seq, "\nPeriodic TXFIFOs:\n"); |
3375 | 3195 | ||
3376 | for (idx = 1; idx <= 15; idx++) { | 3196 | for (idx = 1; idx <= 15; idx++) { |
3377 | val = readl(regs + DPTXFSIZn(idx)); | 3197 | val = readl(regs + DPTXFSIZN(idx)); |
3378 | 3198 | ||
3379 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, | 3199 | seq_printf(seq, "\tDPTXFIFO%2d: Size %d, Start 0x%08x\n", idx, |
3380 | val >> DPTXFSIZn_DPTxFSize_SHIFT, | 3200 | val >> FIFOSIZE_DEPTH_SHIFT, |
3381 | val & DPTXFSIZn_DPTxFStAddr_MASK); | 3201 | val & FIFOSIZE_STARTADDR_MASK); |
3382 | } | 3202 | } |
3383 | 3203 | ||
3384 | return 0; | 3204 | return 0; |
@@ -3662,14 +3482,14 @@ static int s3c_hsotg_probe(struct platform_device *pdev) | |||
3662 | } | 3482 | } |
3663 | 3483 | ||
3664 | /* Set default UTMI width */ | 3484 | /* Set default UTMI width */ |
3665 | hsotg->phyif = GUSBCFG_PHYIf16; | 3485 | hsotg->phyif = GUSBCFG_PHYIF16; |
3666 | 3486 | ||
3667 | /* | 3487 | /* |
3668 | * If using the generic PHY framework, check if the PHY bus | 3488 | * If using the generic PHY framework, check if the PHY bus |
3669 | * width is 8-bit and set the phyif appropriately. | 3489 | * width is 8-bit and set the phyif appropriately. |
3670 | */ | 3490 | */ |
3671 | if (hsotg->phy && (phy_get_bus_width(phy) == 8)) | 3491 | if (hsotg->phy && (phy_get_bus_width(phy) == 8)) |
3672 | hsotg->phyif = GUSBCFG_PHYIf8; | 3492 | hsotg->phyif = GUSBCFG_PHYIF8; |
3673 | 3493 | ||
3674 | if (hsotg->phy) | 3494 | if (hsotg->phy) |
3675 | phy_init(hsotg->phy); | 3495 | phy_init(hsotg->phy); |
diff --git a/drivers/usb/dwc2/hw.h b/drivers/usb/dwc2/hw.h index 9c92a3c7588a..51248b935493 100644 --- a/drivers/usb/dwc2/hw.h +++ b/drivers/usb/dwc2/hw.h | |||
@@ -109,6 +109,7 @@ | |||
109 | #define GUSBCFG_FSINTF (1 << 5) | 109 | #define GUSBCFG_FSINTF (1 << 5) |
110 | #define GUSBCFG_ULPI_UTMI_SEL (1 << 4) | 110 | #define GUSBCFG_ULPI_UTMI_SEL (1 << 4) |
111 | #define GUSBCFG_PHYIF16 (1 << 3) | 111 | #define GUSBCFG_PHYIF16 (1 << 3) |
112 | #define GUSBCFG_PHYIF8 (0 << 3) | ||
112 | #define GUSBCFG_TOUTCAL_MASK (0x7 << 0) | 113 | #define GUSBCFG_TOUTCAL_MASK (0x7 << 0) |
113 | #define GUSBCFG_TOUTCAL_SHIFT 0 | 114 | #define GUSBCFG_TOUTCAL_SHIFT 0 |
114 | #define GUSBCFG_TOUTCAL_LIMIT 0x7 | 115 | #define GUSBCFG_TOUTCAL_LIMIT 0x7 |
@@ -403,6 +404,7 @@ | |||
403 | #define FIFOSIZE_DEPTH_SHIFT 16 | 404 | #define FIFOSIZE_DEPTH_SHIFT 16 |
404 | #define FIFOSIZE_STARTADDR_MASK (0xffff << 0) | 405 | #define FIFOSIZE_STARTADDR_MASK (0xffff << 0) |
405 | #define FIFOSIZE_STARTADDR_SHIFT 0 | 406 | #define FIFOSIZE_STARTADDR_SHIFT 0 |
407 | #define FIFOSIZE_DEPTH_GET(_x) (((_x) >> 16) & 0xffff) | ||
406 | 408 | ||
407 | /* Device mode registers */ | 409 | /* Device mode registers */ |
408 | 410 | ||
@@ -519,11 +521,11 @@ | |||
519 | #define DXEPCTL_STALL (1 << 21) | 521 | #define DXEPCTL_STALL (1 << 21) |
520 | #define DXEPCTL_SNP (1 << 20) | 522 | #define DXEPCTL_SNP (1 << 20) |
521 | #define DXEPCTL_EPTYPE_MASK (0x3 << 18) | 523 | #define DXEPCTL_EPTYPE_MASK (0x3 << 18) |
522 | #define DXEPCTL_EPTYPE_SHIFT 18 | 524 | #define DXEPCTL_EPTYPE_CONTROL (0x0 << 18) |
523 | #define DXEPCTL_EPTYPE_CONTROL 0 | 525 | #define DXEPCTL_EPTYPE_ISO (0x1 << 18) |
524 | #define DXEPCTL_EPTYPE_ISO 1 | 526 | #define DXEPCTL_EPTYPE_BULK (0x2 << 18) |
525 | #define DXEPCTL_EPTYPE_BULK 2 | 527 | #define DXEPCTL_EPTYPE_INTERRUPT (0x3 << 18) |
526 | #define DXEPCTL_EPTYPE_INTTERUPT 3 | 528 | |
527 | #define DXEPCTL_NAKSTS (1 << 17) | 529 | #define DXEPCTL_NAKSTS (1 << 17) |
528 | #define DXEPCTL_DPID (1 << 16) | 530 | #define DXEPCTL_DPID (1 << 16) |
529 | #define DXEPCTL_EOFRNUM (1 << 16) | 531 | #define DXEPCTL_EOFRNUM (1 << 16) |
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index eaba547ce26b..a10e7a353576 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c | |||
@@ -134,6 +134,12 @@ static int dwc2_driver_probe(struct platform_device *dev) | |||
134 | /* Default all params to autodetect */ | 134 | /* Default all params to autodetect */ |
135 | dwc2_set_all_params(&defparams, -1); | 135 | dwc2_set_all_params(&defparams, -1); |
136 | params = &defparams; | 136 | params = &defparams; |
137 | |||
138 | /* | ||
139 | * Disable descriptor dma mode by default as the HW can support | ||
140 | * it, but does not support it for SPLIT transactions. | ||
141 | */ | ||
142 | defparams.dma_desc_enable = 0; | ||
137 | } | 143 | } |
138 | 144 | ||
139 | hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); | 145 | hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); |
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index e2c730fc9a90..8eb996e4f058 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig | |||
@@ -44,7 +44,7 @@ comment "Platform Glue Driver Support" | |||
44 | 44 | ||
45 | config USB_DWC3_OMAP | 45 | config USB_DWC3_OMAP |
46 | tristate "Texas Instruments OMAP5 and similar Platforms" | 46 | tristate "Texas Instruments OMAP5 and similar Platforms" |
47 | depends on EXTCON | 47 | depends on EXTCON && (ARCH_OMAP2PLUS || COMPILE_TEST) |
48 | default USB_DWC3 | 48 | default USB_DWC3 |
49 | help | 49 | help |
50 | Some platforms from Texas Instruments like OMAP5, DRA7xxx and | 50 | Some platforms from Texas Instruments like OMAP5, DRA7xxx and |
@@ -54,6 +54,7 @@ config USB_DWC3_OMAP | |||
54 | 54 | ||
55 | config USB_DWC3_EXYNOS | 55 | config USB_DWC3_EXYNOS |
56 | tristate "Samsung Exynos Platform" | 56 | tristate "Samsung Exynos Platform" |
57 | depends on ARCH_EXYNOS || COMPILE_TEST | ||
57 | default USB_DWC3 | 58 | default USB_DWC3 |
58 | help | 59 | help |
59 | Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside, | 60 | Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside, |
@@ -72,6 +73,7 @@ config USB_DWC3_PCI | |||
72 | 73 | ||
73 | config USB_DWC3_KEYSTONE | 74 | config USB_DWC3_KEYSTONE |
74 | tristate "Texas Instruments Keystone2 Platforms" | 75 | tristate "Texas Instruments Keystone2 Platforms" |
76 | depends on ARCH_KEYSTONE || COMPILE_TEST | ||
75 | default USB_DWC3 | 77 | default USB_DWC3 |
76 | help | 78 | help |
77 | Support of USB2/3 functionality in TI Keystone2 platforms. | 79 | Support of USB2/3 functionality in TI Keystone2 platforms. |
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 10aaaae9af25..eb69eb9f06c8 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -486,70 +486,20 @@ static void dwc3_core_exit(struct dwc3 *dwc) | |||
486 | phy_exit(dwc->usb3_generic_phy); | 486 | phy_exit(dwc->usb3_generic_phy); |
487 | } | 487 | } |
488 | 488 | ||
489 | #define DWC3_ALIGN_MASK (16 - 1) | 489 | static int dwc3_core_get_phy(struct dwc3 *dwc) |
490 | |||
491 | static int dwc3_probe(struct platform_device *pdev) | ||
492 | { | 490 | { |
493 | struct device *dev = &pdev->dev; | 491 | struct device *dev = dwc->dev; |
494 | struct dwc3_platform_data *pdata = dev_get_platdata(dev); | ||
495 | struct device_node *node = dev->of_node; | 492 | struct device_node *node = dev->of_node; |
496 | struct resource *res; | 493 | int ret; |
497 | struct dwc3 *dwc; | ||
498 | |||
499 | int ret = -ENOMEM; | ||
500 | |||
501 | void __iomem *regs; | ||
502 | void *mem; | ||
503 | |||
504 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); | ||
505 | if (!mem) { | ||
506 | dev_err(dev, "not enough memory\n"); | ||
507 | return -ENOMEM; | ||
508 | } | ||
509 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); | ||
510 | dwc->mem = mem; | ||
511 | |||
512 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
513 | if (!res) { | ||
514 | dev_err(dev, "missing IRQ\n"); | ||
515 | return -ENODEV; | ||
516 | } | ||
517 | dwc->xhci_resources[1].start = res->start; | ||
518 | dwc->xhci_resources[1].end = res->end; | ||
519 | dwc->xhci_resources[1].flags = res->flags; | ||
520 | dwc->xhci_resources[1].name = res->name; | ||
521 | |||
522 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
523 | if (!res) { | ||
524 | dev_err(dev, "missing memory resource\n"); | ||
525 | return -ENODEV; | ||
526 | } | ||
527 | 494 | ||
528 | if (node) { | 495 | if (node) { |
529 | dwc->maximum_speed = of_usb_get_maximum_speed(node); | ||
530 | |||
531 | dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); | 496 | dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0); |
532 | dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); | 497 | dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1); |
533 | |||
534 | dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); | ||
535 | dwc->dr_mode = of_usb_get_dr_mode(node); | ||
536 | } else if (pdata) { | ||
537 | dwc->maximum_speed = pdata->maximum_speed; | ||
538 | |||
539 | dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | ||
540 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); | ||
541 | |||
542 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; | ||
543 | dwc->dr_mode = pdata->dr_mode; | ||
544 | } else { | 498 | } else { |
545 | dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); | 499 | dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); |
546 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); | 500 | dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); |
547 | } | 501 | } |
548 | 502 | ||
549 | /* default to superspeed if no maximum_speed passed */ | ||
550 | if (dwc->maximum_speed == USB_SPEED_UNKNOWN) | ||
551 | dwc->maximum_speed = USB_SPEED_SUPER; | ||
552 | |||
553 | if (IS_ERR(dwc->usb2_phy)) { | 503 | if (IS_ERR(dwc->usb2_phy)) { |
554 | ret = PTR_ERR(dwc->usb2_phy); | 504 | ret = PTR_ERR(dwc->usb2_phy); |
555 | if (ret == -ENXIO || ret == -ENODEV) { | 505 | if (ret == -ENXIO || ret == -ENODEV) { |
@@ -600,6 +550,132 @@ static int dwc3_probe(struct platform_device *pdev) | |||
600 | } | 550 | } |
601 | } | 551 | } |
602 | 552 | ||
553 | return 0; | ||
554 | } | ||
555 | |||
556 | static int dwc3_core_init_mode(struct dwc3 *dwc) | ||
557 | { | ||
558 | struct device *dev = dwc->dev; | ||
559 | int ret; | ||
560 | |||
561 | switch (dwc->dr_mode) { | ||
562 | case USB_DR_MODE_PERIPHERAL: | ||
563 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); | ||
564 | ret = dwc3_gadget_init(dwc); | ||
565 | if (ret) { | ||
566 | dev_err(dev, "failed to initialize gadget\n"); | ||
567 | return ret; | ||
568 | } | ||
569 | break; | ||
570 | case USB_DR_MODE_HOST: | ||
571 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); | ||
572 | ret = dwc3_host_init(dwc); | ||
573 | if (ret) { | ||
574 | dev_err(dev, "failed to initialize host\n"); | ||
575 | return ret; | ||
576 | } | ||
577 | break; | ||
578 | case USB_DR_MODE_OTG: | ||
579 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); | ||
580 | ret = dwc3_host_init(dwc); | ||
581 | if (ret) { | ||
582 | dev_err(dev, "failed to initialize host\n"); | ||
583 | return ret; | ||
584 | } | ||
585 | |||
586 | ret = dwc3_gadget_init(dwc); | ||
587 | if (ret) { | ||
588 | dev_err(dev, "failed to initialize gadget\n"); | ||
589 | return ret; | ||
590 | } | ||
591 | break; | ||
592 | default: | ||
593 | dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); | ||
594 | return -EINVAL; | ||
595 | } | ||
596 | |||
597 | return 0; | ||
598 | } | ||
599 | |||
600 | static void dwc3_core_exit_mode(struct dwc3 *dwc) | ||
601 | { | ||
602 | switch (dwc->dr_mode) { | ||
603 | case USB_DR_MODE_PERIPHERAL: | ||
604 | dwc3_gadget_exit(dwc); | ||
605 | break; | ||
606 | case USB_DR_MODE_HOST: | ||
607 | dwc3_host_exit(dwc); | ||
608 | break; | ||
609 | case USB_DR_MODE_OTG: | ||
610 | dwc3_host_exit(dwc); | ||
611 | dwc3_gadget_exit(dwc); | ||
612 | break; | ||
613 | default: | ||
614 | /* do nothing */ | ||
615 | break; | ||
616 | } | ||
617 | } | ||
618 | |||
619 | #define DWC3_ALIGN_MASK (16 - 1) | ||
620 | |||
621 | static int dwc3_probe(struct platform_device *pdev) | ||
622 | { | ||
623 | struct device *dev = &pdev->dev; | ||
624 | struct dwc3_platform_data *pdata = dev_get_platdata(dev); | ||
625 | struct device_node *node = dev->of_node; | ||
626 | struct resource *res; | ||
627 | struct dwc3 *dwc; | ||
628 | |||
629 | int ret; | ||
630 | |||
631 | void __iomem *regs; | ||
632 | void *mem; | ||
633 | |||
634 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); | ||
635 | if (!mem) { | ||
636 | dev_err(dev, "not enough memory\n"); | ||
637 | return -ENOMEM; | ||
638 | } | ||
639 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); | ||
640 | dwc->mem = mem; | ||
641 | dwc->dev = dev; | ||
642 | |||
643 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
644 | if (!res) { | ||
645 | dev_err(dev, "missing IRQ\n"); | ||
646 | return -ENODEV; | ||
647 | } | ||
648 | dwc->xhci_resources[1].start = res->start; | ||
649 | dwc->xhci_resources[1].end = res->end; | ||
650 | dwc->xhci_resources[1].flags = res->flags; | ||
651 | dwc->xhci_resources[1].name = res->name; | ||
652 | |||
653 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
654 | if (!res) { | ||
655 | dev_err(dev, "missing memory resource\n"); | ||
656 | return -ENODEV; | ||
657 | } | ||
658 | |||
659 | if (node) { | ||
660 | dwc->maximum_speed = of_usb_get_maximum_speed(node); | ||
661 | |||
662 | dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize"); | ||
663 | dwc->dr_mode = of_usb_get_dr_mode(node); | ||
664 | } else if (pdata) { | ||
665 | dwc->maximum_speed = pdata->maximum_speed; | ||
666 | |||
667 | dwc->needs_fifo_resize = pdata->tx_fifo_resize; | ||
668 | dwc->dr_mode = pdata->dr_mode; | ||
669 | } | ||
670 | |||
671 | /* default to superspeed if no maximum_speed passed */ | ||
672 | if (dwc->maximum_speed == USB_SPEED_UNKNOWN) | ||
673 | dwc->maximum_speed = USB_SPEED_SUPER; | ||
674 | |||
675 | ret = dwc3_core_get_phy(dwc); | ||
676 | if (ret) | ||
677 | return ret; | ||
678 | |||
603 | dwc->xhci_resources[0].start = res->start; | 679 | dwc->xhci_resources[0].start = res->start; |
604 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + | 680 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + |
605 | DWC3_XHCI_REGS_END; | 681 | DWC3_XHCI_REGS_END; |
@@ -621,7 +697,6 @@ static int dwc3_probe(struct platform_device *pdev) | |||
621 | 697 | ||
622 | dwc->regs = regs; | 698 | dwc->regs = regs; |
623 | dwc->regs_size = resource_size(res); | 699 | dwc->regs_size = resource_size(res); |
624 | dwc->dev = dev; | ||
625 | 700 | ||
626 | dev->dma_mask = dev->parent->dma_mask; | 701 | dev->dma_mask = dev->parent->dma_mask; |
627 | dev->dma_parms = dev->parent->dma_parms; | 702 | dev->dma_parms = dev->parent->dma_parms; |
@@ -670,41 +745,9 @@ static int dwc3_probe(struct platform_device *pdev) | |||
670 | goto err_usb3phy_power; | 745 | goto err_usb3phy_power; |
671 | } | 746 | } |
672 | 747 | ||
673 | switch (dwc->dr_mode) { | 748 | ret = dwc3_core_init_mode(dwc); |
674 | case USB_DR_MODE_PERIPHERAL: | 749 | if (ret) |
675 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); | ||
676 | ret = dwc3_gadget_init(dwc); | ||
677 | if (ret) { | ||
678 | dev_err(dev, "failed to initialize gadget\n"); | ||
679 | goto err2; | ||
680 | } | ||
681 | break; | ||
682 | case USB_DR_MODE_HOST: | ||
683 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); | ||
684 | ret = dwc3_host_init(dwc); | ||
685 | if (ret) { | ||
686 | dev_err(dev, "failed to initialize host\n"); | ||
687 | goto err2; | ||
688 | } | ||
689 | break; | ||
690 | case USB_DR_MODE_OTG: | ||
691 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); | ||
692 | ret = dwc3_host_init(dwc); | ||
693 | if (ret) { | ||
694 | dev_err(dev, "failed to initialize host\n"); | ||
695 | goto err2; | ||
696 | } | ||
697 | |||
698 | ret = dwc3_gadget_init(dwc); | ||
699 | if (ret) { | ||
700 | dev_err(dev, "failed to initialize gadget\n"); | ||
701 | goto err2; | ||
702 | } | ||
703 | break; | ||
704 | default: | ||
705 | dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode); | ||
706 | goto err2; | 750 | goto err2; |
707 | } | ||
708 | 751 | ||
709 | ret = dwc3_debugfs_init(dwc); | 752 | ret = dwc3_debugfs_init(dwc); |
710 | if (ret) { | 753 | if (ret) { |
@@ -717,21 +760,7 @@ static int dwc3_probe(struct platform_device *pdev) | |||
717 | return 0; | 760 | return 0; |
718 | 761 | ||
719 | err3: | 762 | err3: |
720 | switch (dwc->dr_mode) { | 763 | dwc3_core_exit_mode(dwc); |
721 | case USB_DR_MODE_PERIPHERAL: | ||
722 | dwc3_gadget_exit(dwc); | ||
723 | break; | ||
724 | case USB_DR_MODE_HOST: | ||
725 | dwc3_host_exit(dwc); | ||
726 | break; | ||
727 | case USB_DR_MODE_OTG: | ||
728 | dwc3_host_exit(dwc); | ||
729 | dwc3_gadget_exit(dwc); | ||
730 | break; | ||
731 | default: | ||
732 | /* do nothing */ | ||
733 | break; | ||
734 | } | ||
735 | 764 | ||
736 | err2: | 765 | err2: |
737 | dwc3_event_buffers_cleanup(dwc); | 766 | dwc3_event_buffers_cleanup(dwc); |
@@ -766,23 +795,7 @@ static int dwc3_remove(struct platform_device *pdev) | |||
766 | pm_runtime_disable(&pdev->dev); | 795 | pm_runtime_disable(&pdev->dev); |
767 | 796 | ||
768 | dwc3_debugfs_exit(dwc); | 797 | dwc3_debugfs_exit(dwc); |
769 | 798 | dwc3_core_exit_mode(dwc); | |
770 | switch (dwc->dr_mode) { | ||
771 | case USB_DR_MODE_PERIPHERAL: | ||
772 | dwc3_gadget_exit(dwc); | ||
773 | break; | ||
774 | case USB_DR_MODE_HOST: | ||
775 | dwc3_host_exit(dwc); | ||
776 | break; | ||
777 | case USB_DR_MODE_OTG: | ||
778 | dwc3_host_exit(dwc); | ||
779 | dwc3_gadget_exit(dwc); | ||
780 | break; | ||
781 | default: | ||
782 | /* do nothing */ | ||
783 | break; | ||
784 | } | ||
785 | |||
786 | dwc3_event_buffers_cleanup(dwc); | 799 | dwc3_event_buffers_cleanup(dwc); |
787 | dwc3_free_event_buffers(dwc); | 800 | dwc3_free_event_buffers(dwc); |
788 | dwc3_core_exit(dwc); | 801 | dwc3_core_exit(dwc); |
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 28c8ad79f5e6..f9fb8adb785b 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -24,9 +24,10 @@ | |||
24 | #include <linux/dma-mapping.h> | 24 | #include <linux/dma-mapping.h> |
25 | #include <linux/clk.h> | 25 | #include <linux/clk.h> |
26 | #include <linux/usb/otg.h> | 26 | #include <linux/usb/otg.h> |
27 | #include <linux/usb/usb_phy_gen_xceiv.h> | 27 | #include <linux/usb/usb_phy_generic.h> |
28 | #include <linux/of.h> | 28 | #include <linux/of.h> |
29 | #include <linux/of_platform.h> | 29 | #include <linux/of_platform.h> |
30 | #include <linux/regulator/consumer.h> | ||
30 | 31 | ||
31 | struct dwc3_exynos { | 32 | struct dwc3_exynos { |
32 | struct platform_device *usb2_phy; | 33 | struct platform_device *usb2_phy; |
@@ -34,17 +35,19 @@ struct dwc3_exynos { | |||
34 | struct device *dev; | 35 | struct device *dev; |
35 | 36 | ||
36 | struct clk *clk; | 37 | struct clk *clk; |
38 | struct regulator *vdd33; | ||
39 | struct regulator *vdd10; | ||
37 | }; | 40 | }; |
38 | 41 | ||
39 | static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) | 42 | static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) |
40 | { | 43 | { |
41 | struct usb_phy_gen_xceiv_platform_data pdata; | 44 | struct usb_phy_generic_platform_data pdata; |
42 | struct platform_device *pdev; | 45 | struct platform_device *pdev; |
43 | int ret; | 46 | int ret; |
44 | 47 | ||
45 | memset(&pdata, 0x00, sizeof(pdata)); | 48 | memset(&pdata, 0x00, sizeof(pdata)); |
46 | 49 | ||
47 | pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO); | 50 | pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO); |
48 | if (!pdev) | 51 | if (!pdev) |
49 | return -ENOMEM; | 52 | return -ENOMEM; |
50 | 53 | ||
@@ -56,7 +59,7 @@ static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos) | |||
56 | if (ret) | 59 | if (ret) |
57 | goto err1; | 60 | goto err1; |
58 | 61 | ||
59 | pdev = platform_device_alloc("usb_phy_gen_xceiv", PLATFORM_DEVID_AUTO); | 62 | pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO); |
60 | if (!pdev) { | 63 | if (!pdev) { |
61 | ret = -ENOMEM; | 64 | ret = -ENOMEM; |
62 | goto err1; | 65 | goto err1; |
@@ -107,12 +110,12 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
107 | struct device *dev = &pdev->dev; | 110 | struct device *dev = &pdev->dev; |
108 | struct device_node *node = dev->of_node; | 111 | struct device_node *node = dev->of_node; |
109 | 112 | ||
110 | int ret = -ENOMEM; | 113 | int ret; |
111 | 114 | ||
112 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); | 115 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
113 | if (!exynos) { | 116 | if (!exynos) { |
114 | dev_err(dev, "not enough memory\n"); | 117 | dev_err(dev, "not enough memory\n"); |
115 | goto err1; | 118 | return -ENOMEM; |
116 | } | 119 | } |
117 | 120 | ||
118 | /* | 121 | /* |
@@ -122,21 +125,20 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
122 | */ | 125 | */ |
123 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); | 126 | ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); |
124 | if (ret) | 127 | if (ret) |
125 | goto err1; | 128 | return ret; |
126 | 129 | ||
127 | platform_set_drvdata(pdev, exynos); | 130 | platform_set_drvdata(pdev, exynos); |
128 | 131 | ||
129 | ret = dwc3_exynos_register_phys(exynos); | 132 | ret = dwc3_exynos_register_phys(exynos); |
130 | if (ret) { | 133 | if (ret) { |
131 | dev_err(dev, "couldn't register PHYs\n"); | 134 | dev_err(dev, "couldn't register PHYs\n"); |
132 | goto err1; | 135 | return ret; |
133 | } | 136 | } |
134 | 137 | ||
135 | clk = devm_clk_get(dev, "usbdrd30"); | 138 | clk = devm_clk_get(dev, "usbdrd30"); |
136 | if (IS_ERR(clk)) { | 139 | if (IS_ERR(clk)) { |
137 | dev_err(dev, "couldn't get clock\n"); | 140 | dev_err(dev, "couldn't get clock\n"); |
138 | ret = -EINVAL; | 141 | return -EINVAL; |
139 | goto err1; | ||
140 | } | 142 | } |
141 | 143 | ||
142 | exynos->dev = dev; | 144 | exynos->dev = dev; |
@@ -144,23 +146,48 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
144 | 146 | ||
145 | clk_prepare_enable(exynos->clk); | 147 | clk_prepare_enable(exynos->clk); |
146 | 148 | ||
149 | exynos->vdd33 = devm_regulator_get(dev, "vdd33"); | ||
150 | if (IS_ERR(exynos->vdd33)) { | ||
151 | ret = PTR_ERR(exynos->vdd33); | ||
152 | goto err2; | ||
153 | } | ||
154 | ret = regulator_enable(exynos->vdd33); | ||
155 | if (ret) { | ||
156 | dev_err(dev, "Failed to enable VDD33 supply\n"); | ||
157 | goto err2; | ||
158 | } | ||
159 | |||
160 | exynos->vdd10 = devm_regulator_get(dev, "vdd10"); | ||
161 | if (IS_ERR(exynos->vdd10)) { | ||
162 | ret = PTR_ERR(exynos->vdd10); | ||
163 | goto err3; | ||
164 | } | ||
165 | ret = regulator_enable(exynos->vdd10); | ||
166 | if (ret) { | ||
167 | dev_err(dev, "Failed to enable VDD10 supply\n"); | ||
168 | goto err3; | ||
169 | } | ||
170 | |||
147 | if (node) { | 171 | if (node) { |
148 | ret = of_platform_populate(node, NULL, NULL, dev); | 172 | ret = of_platform_populate(node, NULL, NULL, dev); |
149 | if (ret) { | 173 | if (ret) { |
150 | dev_err(dev, "failed to add dwc3 core\n"); | 174 | dev_err(dev, "failed to add dwc3 core\n"); |
151 | goto err2; | 175 | goto err4; |
152 | } | 176 | } |
153 | } else { | 177 | } else { |
154 | dev_err(dev, "no device node, failed to add dwc3 core\n"); | 178 | dev_err(dev, "no device node, failed to add dwc3 core\n"); |
155 | ret = -ENODEV; | 179 | ret = -ENODEV; |
156 | goto err2; | 180 | goto err4; |
157 | } | 181 | } |
158 | 182 | ||
159 | return 0; | 183 | return 0; |
160 | 184 | ||
185 | err4: | ||
186 | regulator_disable(exynos->vdd10); | ||
187 | err3: | ||
188 | regulator_disable(exynos->vdd33); | ||
161 | err2: | 189 | err2: |
162 | clk_disable_unprepare(clk); | 190 | clk_disable_unprepare(clk); |
163 | err1: | ||
164 | return ret; | 191 | return ret; |
165 | } | 192 | } |
166 | 193 | ||
@@ -174,6 +201,9 @@ static int dwc3_exynos_remove(struct platform_device *pdev) | |||
174 | 201 | ||
175 | clk_disable_unprepare(exynos->clk); | 202 | clk_disable_unprepare(exynos->clk); |
176 | 203 | ||
204 | regulator_disable(exynos->vdd33); | ||
205 | regulator_disable(exynos->vdd10); | ||
206 | |||
177 | return 0; | 207 | return 0; |
178 | } | 208 | } |
179 | 209 | ||
@@ -192,12 +222,27 @@ static int dwc3_exynos_suspend(struct device *dev) | |||
192 | 222 | ||
193 | clk_disable(exynos->clk); | 223 | clk_disable(exynos->clk); |
194 | 224 | ||
225 | regulator_disable(exynos->vdd33); | ||
226 | regulator_disable(exynos->vdd10); | ||
227 | |||
195 | return 0; | 228 | return 0; |
196 | } | 229 | } |
197 | 230 | ||
198 | static int dwc3_exynos_resume(struct device *dev) | 231 | static int dwc3_exynos_resume(struct device *dev) |
199 | { | 232 | { |
200 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); | 233 | struct dwc3_exynos *exynos = dev_get_drvdata(dev); |
234 | int ret; | ||
235 | |||
236 | ret = regulator_enable(exynos->vdd33); | ||
237 | if (ret) { | ||
238 | dev_err(dev, "Failed to enable VDD33 supply\n"); | ||
239 | return ret; | ||
240 | } | ||
241 | ret = regulator_enable(exynos->vdd10); | ||
242 | if (ret) { | ||
243 | dev_err(dev, "Failed to enable VDD10 supply\n"); | ||
244 | return ret; | ||
245 | } | ||
201 | 246 | ||
202 | clk_enable(exynos->clk); | 247 | clk_enable(exynos->clk); |
203 | 248 | ||
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 1160ff41bed4..4af4c3567656 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -393,7 +393,7 @@ static int dwc3_omap_probe(struct platform_device *pdev) | |||
393 | struct extcon_dev *edev; | 393 | struct extcon_dev *edev; |
394 | struct regulator *vbus_reg = NULL; | 394 | struct regulator *vbus_reg = NULL; |
395 | 395 | ||
396 | int ret = -ENOMEM; | 396 | int ret; |
397 | int irq; | 397 | int irq; |
398 | 398 | ||
399 | int utmi_mode = 0; | 399 | int utmi_mode = 0; |
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index f393c183cc69..a60bab7dfa0a 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
24 | 24 | ||
25 | #include <linux/usb/otg.h> | 25 | #include <linux/usb/otg.h> |
26 | #include <linux/usb/usb_phy_gen_xceiv.h> | 26 | #include <linux/usb/usb_phy_generic.h> |
27 | 27 | ||
28 | /* FIXME define these in <linux/pci_ids.h> */ | 28 | /* FIXME define these in <linux/pci_ids.h> */ |
29 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 | 29 | #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 |
@@ -40,13 +40,13 @@ struct dwc3_pci { | |||
40 | 40 | ||
41 | static int dwc3_pci_register_phys(struct dwc3_pci *glue) | 41 | static int dwc3_pci_register_phys(struct dwc3_pci *glue) |
42 | { | 42 | { |
43 | struct usb_phy_gen_xceiv_platform_data pdata; | 43 | struct usb_phy_generic_platform_data pdata; |
44 | struct platform_device *pdev; | 44 | struct platform_device *pdev; |
45 | int ret; | 45 | int ret; |
46 | 46 | ||
47 | memset(&pdata, 0x00, sizeof(pdata)); | 47 | memset(&pdata, 0x00, sizeof(pdata)); |
48 | 48 | ||
49 | pdev = platform_device_alloc("usb_phy_gen_xceiv", 0); | 49 | pdev = platform_device_alloc("usb_phy_generic", 0); |
50 | if (!pdev) | 50 | if (!pdev) |
51 | return -ENOMEM; | 51 | return -ENOMEM; |
52 | 52 | ||
@@ -58,7 +58,7 @@ static int dwc3_pci_register_phys(struct dwc3_pci *glue) | |||
58 | if (ret) | 58 | if (ret) |
59 | goto err1; | 59 | goto err1; |
60 | 60 | ||
61 | pdev = platform_device_alloc("usb_phy_gen_xceiv", 1); | 61 | pdev = platform_device_alloc("usb_phy_generic", 1); |
62 | if (!pdev) { | 62 | if (!pdev) { |
63 | ret = -ENOMEM; | 63 | ret = -ENOMEM; |
64 | goto err1; | 64 | goto err1; |
@@ -99,7 +99,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
99 | struct resource res[2]; | 99 | struct resource res[2]; |
100 | struct platform_device *dwc3; | 100 | struct platform_device *dwc3; |
101 | struct dwc3_pci *glue; | 101 | struct dwc3_pci *glue; |
102 | int ret = -ENOMEM; | 102 | int ret; |
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); |
@@ -110,7 +110,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
110 | 110 | ||
111 | glue->dev = dev; | 111 | glue->dev = dev; |
112 | 112 | ||
113 | ret = pci_enable_device(pci); | 113 | ret = pcim_enable_device(pci); |
114 | if (ret) { | 114 | if (ret) { |
115 | dev_err(dev, "failed to enable pci device\n"); | 115 | dev_err(dev, "failed to enable pci device\n"); |
116 | return -ENODEV; | 116 | return -ENODEV; |
@@ -127,8 +127,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
127 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); | 127 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); |
128 | if (!dwc3) { | 128 | if (!dwc3) { |
129 | dev_err(dev, "couldn't allocate dwc3 device\n"); | 129 | dev_err(dev, "couldn't allocate dwc3 device\n"); |
130 | ret = -ENOMEM; | 130 | return -ENOMEM; |
131 | goto err1; | ||
132 | } | 131 | } |
133 | 132 | ||
134 | memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); | 133 | memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); |
@@ -145,7 +144,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
145 | ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); | 144 | ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); |
146 | if (ret) { | 145 | if (ret) { |
147 | dev_err(dev, "couldn't add resources to dwc3 device\n"); | 146 | dev_err(dev, "couldn't add resources to dwc3 device\n"); |
148 | goto err1; | 147 | return ret; |
149 | } | 148 | } |
150 | 149 | ||
151 | pci_set_drvdata(pci, glue); | 150 | pci_set_drvdata(pci, glue); |
@@ -167,9 +166,6 @@ static int dwc3_pci_probe(struct pci_dev *pci, | |||
167 | 166 | ||
168 | err3: | 167 | err3: |
169 | platform_device_put(dwc3); | 168 | platform_device_put(dwc3); |
170 | err1: | ||
171 | pci_disable_device(pci); | ||
172 | |||
173 | return ret; | 169 | return ret; |
174 | } | 170 | } |
175 | 171 | ||
@@ -180,7 +176,6 @@ static void dwc3_pci_remove(struct pci_dev *pci) | |||
180 | platform_device_unregister(glue->dwc3); | 176 | platform_device_unregister(glue->dwc3); |
181 | platform_device_unregister(glue->usb2_phy); | 177 | platform_device_unregister(glue->usb2_phy); |
182 | platform_device_unregister(glue->usb3_phy); | 178 | platform_device_unregister(glue->usb3_phy); |
183 | pci_disable_device(pci); | ||
184 | } | 179 | } |
185 | 180 | ||
186 | static const struct pci_device_id dwc3_pci_id_table[] = { | 181 | static const struct pci_device_id dwc3_pci_id_table[] = { |
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 70715eeededd..9d64dd02c57e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c | |||
@@ -298,11 +298,76 @@ static const char *dwc3_gadget_ep_cmd_string(u8 cmd) | |||
298 | } | 298 | } |
299 | } | 299 | } |
300 | 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 | |||
301 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) | 363 | int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) |
302 | { | 364 | { |
303 | u32 timeout = 500; | 365 | u32 timeout = 500; |
304 | u32 reg; | 366 | u32 reg; |
305 | 367 | ||
368 | dev_vdbg(dwc->dev, "generic cmd '%s' [%d] param %08x\n", | ||
369 | dwc3_gadget_generic_cmd_string(cmd), cmd, param); | ||
370 | |||
306 | dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); | 371 | dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); |
307 | dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); | 372 | dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); |
308 | 373 | ||
@@ -332,9 +397,9 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, | |||
332 | u32 timeout = 500; | 397 | u32 timeout = 500; |
333 | u32 reg; | 398 | u32 reg; |
334 | 399 | ||
335 | dev_vdbg(dwc->dev, "%s: cmd '%s' params %08x %08x %08x\n", | 400 | dev_vdbg(dwc->dev, "%s: cmd '%s' [%d] params %08x %08x %08x\n", |
336 | dep->name, | 401 | dep->name, |
337 | dwc3_gadget_ep_cmd_string(cmd), params->param0, | 402 | dwc3_gadget_ep_cmd_string(cmd), cmd, params->param0, |
338 | params->param1, params->param2); | 403 | params->param1, params->param2); |
339 | 404 | ||
340 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); | 405 | dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); |
@@ -515,7 +580,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, | |||
515 | { | 580 | { |
516 | struct dwc3 *dwc = dep->dwc; | 581 | struct dwc3 *dwc = dep->dwc; |
517 | u32 reg; | 582 | u32 reg; |
518 | int ret = -ENOMEM; | 583 | int ret; |
519 | 584 | ||
520 | dev_vdbg(dwc->dev, "Enabling %s\n", dep->name); | 585 | dev_vdbg(dwc->dev, "Enabling %s\n", dep->name); |
521 | 586 | ||
@@ -604,6 +669,10 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) | |||
604 | 669 | ||
605 | dwc3_remove_requests(dwc, dep); | 670 | dwc3_remove_requests(dwc, dep); |
606 | 671 | ||
672 | /* make sure HW endpoint isn't stalled */ | ||
673 | if (dep->flags & DWC3_EP_STALL) | ||
674 | __dwc3_gadget_ep_set_halt(dep, 0); | ||
675 | |||
607 | reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); | 676 | reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); |
608 | reg &= ~DWC3_DALEPENA_EP(dep->number); | 677 | reg &= ~DWC3_DALEPENA_EP(dep->number); |
609 | dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); | 678 | dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); |
@@ -2441,8 +2510,6 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, | |||
2441 | } | 2510 | } |
2442 | } | 2511 | } |
2443 | 2512 | ||
2444 | dwc->link_state = next; | ||
2445 | |||
2446 | switch (next) { | 2513 | switch (next) { |
2447 | case DWC3_LINK_STATE_U1: | 2514 | case DWC3_LINK_STATE_U1: |
2448 | if (dwc->speed == USB_SPEED_SUPER) | 2515 | if (dwc->speed == USB_SPEED_SUPER) |
@@ -2460,7 +2527,11 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, | |||
2460 | break; | 2527 | break; |
2461 | } | 2528 | } |
2462 | 2529 | ||
2463 | dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state); | 2530 | dev_vdbg(dwc->dev, "link change: %s [%d] -> %s [%d]\n", |
2531 | dwc3_gadget_link_string(dwc->link_state), | ||
2532 | dwc->link_state, dwc3_gadget_link_string(next), next); | ||
2533 | |||
2534 | dwc->link_state = next; | ||
2464 | } | 2535 | } |
2465 | 2536 | ||
2466 | static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc, | 2537 | static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc, |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 3557c7e5040d..ba18e9c110cc 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -157,7 +157,7 @@ config USB_AT91 | |||
157 | 157 | ||
158 | config USB_LPC32XX | 158 | config USB_LPC32XX |
159 | tristate "LPC32XX USB Peripheral Controller" | 159 | tristate "LPC32XX USB Peripheral Controller" |
160 | depends on ARCH_LPC32XX | 160 | depends on ARCH_LPC32XX && I2C |
161 | select USB_ISP1301 | 161 | select USB_ISP1301 |
162 | help | 162 | help |
163 | This option selects the USB device controller in the LPC32xx SoC. | 163 | This option selects the USB device controller in the LPC32xx SoC. |
@@ -226,7 +226,7 @@ config USB_GR_UDC | |||
226 | config USB_OMAP | 226 | config USB_OMAP |
227 | tristate "OMAP USB Device Controller" | 227 | tristate "OMAP USB Device Controller" |
228 | depends on ARCH_OMAP1 | 228 | depends on ARCH_OMAP1 |
229 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 | 229 | depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3) |
230 | help | 230 | help |
231 | Many Texas Instruments OMAP processors have flexible full | 231 | Many Texas Instruments OMAP processors have flexible full |
232 | speed USB device controllers, with support for up to 30 | 232 | speed USB device controllers, with support for up to 30 |
@@ -300,12 +300,6 @@ config USB_PXA27X | |||
300 | dynamically linked module called "pxa27x_udc" and force all | 300 | dynamically linked module called "pxa27x_udc" and force all |
301 | gadget drivers to also be dynamically linked. | 301 | gadget drivers to also be dynamically linked. |
302 | 302 | ||
303 | config USB_S3C_HSOTG | ||
304 | tristate "Designware/S3C HS/OtG USB Device controller" | ||
305 | help | ||
306 | The Designware USB2.0 high-speed gadget controller | ||
307 | integrated into many SoCs. | ||
308 | |||
309 | config USB_S3C2410 | 303 | config USB_S3C2410 |
310 | tristate "S3C2410 USB Device Controller" | 304 | tristate "S3C2410 USB Device Controller" |
311 | depends on ARCH_S3C24XX | 305 | depends on ARCH_S3C24XX |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 5f150bc1b4bc..49514ea60a98 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -26,7 +26,6 @@ fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o | |||
26 | obj-$(CONFIG_USB_M66592) += m66592-udc.o | 26 | obj-$(CONFIG_USB_M66592) += m66592-udc.o |
27 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o | 27 | obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o |
28 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o | 28 | obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o |
29 | obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o | ||
30 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o | 29 | obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o |
31 | obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o | 30 | obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o |
32 | obj-$(CONFIG_USB_EG20T) += pch_udc.o | 31 | obj-$(CONFIG_USB_EG20T) += pch_udc.o |
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index 9f65324f9ae0..76023ce449a3 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c | |||
@@ -1686,7 +1686,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid) | |||
1686 | reset_all_endpoints(udc); | 1686 | reset_all_endpoints(udc); |
1687 | 1687 | ||
1688 | if (udc->gadget.speed != USB_SPEED_UNKNOWN | 1688 | if (udc->gadget.speed != USB_SPEED_UNKNOWN |
1689 | && udc->driver->disconnect) { | 1689 | && udc->driver && udc->driver->disconnect) { |
1690 | udc->gadget.speed = USB_SPEED_UNKNOWN; | 1690 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
1691 | spin_unlock(&udc->lock); | 1691 | spin_unlock(&udc->lock); |
1692 | udc->driver->disconnect(&udc->gadget); | 1692 | udc->driver->disconnect(&udc->gadget); |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index fab906429b80..f80151932053 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -21,6 +21,24 @@ | |||
21 | #include <linux/usb/composite.h> | 21 | #include <linux/usb/composite.h> |
22 | #include <asm/unaligned.h> | 22 | #include <asm/unaligned.h> |
23 | 23 | ||
24 | #include "u_os_desc.h" | ||
25 | |||
26 | /** | ||
27 | * struct usb_os_string - represents OS String to be reported by a gadget | ||
28 | * @bLength: total length of the entire descritor, always 0x12 | ||
29 | * @bDescriptorType: USB_DT_STRING | ||
30 | * @qwSignature: the OS String proper | ||
31 | * @bMS_VendorCode: code used by the host for subsequent requests | ||
32 | * @bPad: not used, must be zero | ||
33 | */ | ||
34 | struct usb_os_string { | ||
35 | __u8 bLength; | ||
36 | __u8 bDescriptorType; | ||
37 | __u8 qwSignature[OS_STRING_QW_SIGN_LEN]; | ||
38 | __u8 bMS_VendorCode; | ||
39 | __u8 bPad; | ||
40 | } __packed; | ||
41 | |||
24 | /* | 42 | /* |
25 | * The code in this file is utility code, used to build a gadget driver | 43 | * The code in this file is utility code, used to build a gadget driver |
26 | * from one or more "function" drivers, one or more "configuration" | 44 | * from one or more "function" drivers, one or more "configuration" |
@@ -422,6 +440,7 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) | |||
422 | { | 440 | { |
423 | struct usb_gadget *gadget = cdev->gadget; | 441 | struct usb_gadget *gadget = cdev->gadget; |
424 | struct usb_configuration *c; | 442 | struct usb_configuration *c; |
443 | struct list_head *pos; | ||
425 | u8 type = w_value >> 8; | 444 | u8 type = w_value >> 8; |
426 | enum usb_device_speed speed = USB_SPEED_UNKNOWN; | 445 | enum usb_device_speed speed = USB_SPEED_UNKNOWN; |
427 | 446 | ||
@@ -440,7 +459,20 @@ static int config_desc(struct usb_composite_dev *cdev, unsigned w_value) | |||
440 | 459 | ||
441 | /* This is a lookup by config *INDEX* */ | 460 | /* This is a lookup by config *INDEX* */ |
442 | w_value &= 0xff; | 461 | w_value &= 0xff; |
443 | list_for_each_entry(c, &cdev->configs, list) { | 462 | |
463 | pos = &cdev->configs; | ||
464 | c = cdev->os_desc_config; | ||
465 | if (c) | ||
466 | goto check_config; | ||
467 | |||
468 | while ((pos = pos->next) != &cdev->configs) { | ||
469 | c = list_entry(pos, typeof(*c), list); | ||
470 | |||
471 | /* skip OS Descriptors config which is handled separately */ | ||
472 | if (c == cdev->os_desc_config) | ||
473 | continue; | ||
474 | |||
475 | check_config: | ||
444 | /* ignore configs that won't work at this speed */ | 476 | /* ignore configs that won't work at this speed */ |
445 | switch (speed) { | 477 | switch (speed) { |
446 | case USB_SPEED_SUPER: | 478 | case USB_SPEED_SUPER: |
@@ -634,6 +666,7 @@ static int set_config(struct usb_composite_dev *cdev, | |||
634 | if (!c) | 666 | if (!c) |
635 | goto done; | 667 | goto done; |
636 | 668 | ||
669 | usb_gadget_set_state(gadget, USB_STATE_CONFIGURED); | ||
637 | cdev->config = c; | 670 | cdev->config = c; |
638 | 671 | ||
639 | /* Initialize all interfaces by setting them to altsetting zero. */ | 672 | /* Initialize all interfaces by setting them to altsetting zero. */ |
@@ -960,6 +993,19 @@ static int get_string(struct usb_composite_dev *cdev, | |||
960 | return s->bLength; | 993 | return s->bLength; |
961 | } | 994 | } |
962 | 995 | ||
996 | if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) { | ||
997 | struct usb_os_string *b = buf; | ||
998 | b->bLength = sizeof(*b); | ||
999 | b->bDescriptorType = USB_DT_STRING; | ||
1000 | compiletime_assert( | ||
1001 | sizeof(b->qwSignature) == sizeof(cdev->qw_sign), | ||
1002 | "qwSignature size must be equal to qw_sign"); | ||
1003 | memcpy(&b->qwSignature, cdev->qw_sign, sizeof(b->qwSignature)); | ||
1004 | b->bMS_VendorCode = cdev->b_vendor_code; | ||
1005 | b->bPad = 0; | ||
1006 | return sizeof(*b); | ||
1007 | } | ||
1008 | |||
963 | list_for_each_entry(uc, &cdev->gstrings, list) { | 1009 | list_for_each_entry(uc, &cdev->gstrings, list) { |
964 | struct usb_gadget_strings **sp; | 1010 | struct usb_gadget_strings **sp; |
965 | 1011 | ||
@@ -1206,6 +1252,156 @@ static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) | |||
1206 | req->status, req->actual, req->length); | 1252 | req->status, req->actual, req->length); |
1207 | } | 1253 | } |
1208 | 1254 | ||
1255 | static int count_ext_compat(struct usb_configuration *c) | ||
1256 | { | ||
1257 | int i, res; | ||
1258 | |||
1259 | res = 0; | ||
1260 | for (i = 0; i < c->next_interface_id; ++i) { | ||
1261 | struct usb_function *f; | ||
1262 | int j; | ||
1263 | |||
1264 | f = c->interface[i]; | ||
1265 | for (j = 0; j < f->os_desc_n; ++j) { | ||
1266 | struct usb_os_desc *d; | ||
1267 | |||
1268 | if (i != f->os_desc_table[j].if_id) | ||
1269 | continue; | ||
1270 | d = f->os_desc_table[j].os_desc; | ||
1271 | if (d && d->ext_compat_id) | ||
1272 | ++res; | ||
1273 | } | ||
1274 | } | ||
1275 | BUG_ON(res > 255); | ||
1276 | return res; | ||
1277 | } | ||
1278 | |||
1279 | static void fill_ext_compat(struct usb_configuration *c, u8 *buf) | ||
1280 | { | ||
1281 | int i, count; | ||
1282 | |||
1283 | count = 16; | ||
1284 | for (i = 0; i < c->next_interface_id; ++i) { | ||
1285 | struct usb_function *f; | ||
1286 | int j; | ||
1287 | |||
1288 | f = c->interface[i]; | ||
1289 | for (j = 0; j < f->os_desc_n; ++j) { | ||
1290 | struct usb_os_desc *d; | ||
1291 | |||
1292 | if (i != f->os_desc_table[j].if_id) | ||
1293 | continue; | ||
1294 | d = f->os_desc_table[j].os_desc; | ||
1295 | if (d && d->ext_compat_id) { | ||
1296 | *buf++ = i; | ||
1297 | *buf++ = 0x01; | ||
1298 | memcpy(buf, d->ext_compat_id, 16); | ||
1299 | buf += 22; | ||
1300 | } else { | ||
1301 | ++buf; | ||
1302 | *buf = 0x01; | ||
1303 | buf += 23; | ||
1304 | } | ||
1305 | count += 24; | ||
1306 | if (count >= 4096) | ||
1307 | return; | ||
1308 | } | ||
1309 | } | ||
1310 | } | ||
1311 | |||
1312 | static int count_ext_prop(struct usb_configuration *c, int interface) | ||
1313 | { | ||
1314 | struct usb_function *f; | ||
1315 | int j; | ||
1316 | |||
1317 | f = c->interface[interface]; | ||
1318 | for (j = 0; j < f->os_desc_n; ++j) { | ||
1319 | struct usb_os_desc *d; | ||
1320 | |||
1321 | if (interface != f->os_desc_table[j].if_id) | ||
1322 | continue; | ||
1323 | d = f->os_desc_table[j].os_desc; | ||
1324 | if (d && d->ext_compat_id) | ||
1325 | return d->ext_prop_count; | ||
1326 | } | ||
1327 | return 0; | ||
1328 | } | ||
1329 | |||
1330 | static int len_ext_prop(struct usb_configuration *c, int interface) | ||
1331 | { | ||
1332 | struct usb_function *f; | ||
1333 | struct usb_os_desc *d; | ||
1334 | int j, res; | ||
1335 | |||
1336 | res = 10; /* header length */ | ||
1337 | f = c->interface[interface]; | ||
1338 | for (j = 0; j < f->os_desc_n; ++j) { | ||
1339 | if (interface != f->os_desc_table[j].if_id) | ||
1340 | continue; | ||
1341 | d = f->os_desc_table[j].os_desc; | ||
1342 | if (d) | ||
1343 | return min(res + d->ext_prop_len, 4096); | ||
1344 | } | ||
1345 | return res; | ||
1346 | } | ||
1347 | |||
1348 | static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf) | ||
1349 | { | ||
1350 | struct usb_function *f; | ||
1351 | struct usb_os_desc *d; | ||
1352 | struct usb_os_desc_ext_prop *ext_prop; | ||
1353 | int j, count, n, ret; | ||
1354 | u8 *start = buf; | ||
1355 | |||
1356 | f = c->interface[interface]; | ||
1357 | for (j = 0; j < f->os_desc_n; ++j) { | ||
1358 | if (interface != f->os_desc_table[j].if_id) | ||
1359 | continue; | ||
1360 | d = f->os_desc_table[j].os_desc; | ||
1361 | if (d) | ||
1362 | list_for_each_entry(ext_prop, &d->ext_prop, entry) { | ||
1363 | /* 4kB minus header length */ | ||
1364 | n = buf - start; | ||
1365 | if (n >= 4086) | ||
1366 | return 0; | ||
1367 | |||
1368 | count = ext_prop->data_len + | ||
1369 | ext_prop->name_len + 14; | ||
1370 | if (count > 4086 - n) | ||
1371 | return -EINVAL; | ||
1372 | usb_ext_prop_put_size(buf, count); | ||
1373 | usb_ext_prop_put_type(buf, ext_prop->type); | ||
1374 | ret = usb_ext_prop_put_name(buf, ext_prop->name, | ||
1375 | ext_prop->name_len); | ||
1376 | if (ret < 0) | ||
1377 | return ret; | ||
1378 | switch (ext_prop->type) { | ||
1379 | case USB_EXT_PROP_UNICODE: | ||
1380 | case USB_EXT_PROP_UNICODE_ENV: | ||
1381 | case USB_EXT_PROP_UNICODE_LINK: | ||
1382 | usb_ext_prop_put_unicode(buf, ret, | ||
1383 | ext_prop->data, | ||
1384 | ext_prop->data_len); | ||
1385 | break; | ||
1386 | case USB_EXT_PROP_BINARY: | ||
1387 | usb_ext_prop_put_binary(buf, ret, | ||
1388 | ext_prop->data, | ||
1389 | ext_prop->data_len); | ||
1390 | break; | ||
1391 | case USB_EXT_PROP_LE32: | ||
1392 | /* not implemented */ | ||
1393 | case USB_EXT_PROP_BE32: | ||
1394 | /* not implemented */ | ||
1395 | default: | ||
1396 | return -EINVAL; | ||
1397 | } | ||
1398 | buf += count; | ||
1399 | } | ||
1400 | } | ||
1401 | |||
1402 | return 0; | ||
1403 | } | ||
1404 | |||
1209 | /* | 1405 | /* |
1210 | * The setup() callback implements all the ep0 functionality that's | 1406 | * The setup() callback implements all the ep0 functionality that's |
1211 | * not handled lower down, in hardware or the hardware driver(like | 1407 | * not handled lower down, in hardware or the hardware driver(like |
@@ -1415,6 +1611,91 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1415 | break; | 1611 | break; |
1416 | default: | 1612 | default: |
1417 | unknown: | 1613 | unknown: |
1614 | /* | ||
1615 | * OS descriptors handling | ||
1616 | */ | ||
1617 | if (cdev->use_os_string && cdev->os_desc_config && | ||
1618 | (ctrl->bRequest & USB_TYPE_VENDOR) && | ||
1619 | ctrl->bRequest == cdev->b_vendor_code) { | ||
1620 | struct usb_request *req; | ||
1621 | struct usb_configuration *os_desc_cfg; | ||
1622 | u8 *buf; | ||
1623 | int interface; | ||
1624 | int count = 0; | ||
1625 | |||
1626 | req = cdev->os_desc_req; | ||
1627 | req->complete = composite_setup_complete; | ||
1628 | buf = req->buf; | ||
1629 | os_desc_cfg = cdev->os_desc_config; | ||
1630 | memset(buf, 0, w_length); | ||
1631 | buf[5] = 0x01; | ||
1632 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
1633 | case USB_RECIP_DEVICE: | ||
1634 | if (w_index != 0x4 || (w_value >> 8)) | ||
1635 | break; | ||
1636 | buf[6] = w_index; | ||
1637 | if (w_length == 0x10) { | ||
1638 | /* Number of ext compat interfaces */ | ||
1639 | count = count_ext_compat(os_desc_cfg); | ||
1640 | buf[8] = count; | ||
1641 | count *= 24; /* 24 B/ext compat desc */ | ||
1642 | count += 16; /* header */ | ||
1643 | put_unaligned_le32(count, buf); | ||
1644 | value = w_length; | ||
1645 | } else { | ||
1646 | /* "extended compatibility ID"s */ | ||
1647 | count = count_ext_compat(os_desc_cfg); | ||
1648 | buf[8] = count; | ||
1649 | count *= 24; /* 24 B/ext compat desc */ | ||
1650 | count += 16; /* header */ | ||
1651 | put_unaligned_le32(count, buf); | ||
1652 | buf += 16; | ||
1653 | fill_ext_compat(os_desc_cfg, buf); | ||
1654 | value = w_length; | ||
1655 | } | ||
1656 | break; | ||
1657 | case USB_RECIP_INTERFACE: | ||
1658 | if (w_index != 0x5 || (w_value >> 8)) | ||
1659 | break; | ||
1660 | interface = w_value & 0xFF; | ||
1661 | buf[6] = w_index; | ||
1662 | if (w_length == 0x0A) { | ||
1663 | count = count_ext_prop(os_desc_cfg, | ||
1664 | interface); | ||
1665 | put_unaligned_le16(count, buf + 8); | ||
1666 | count = len_ext_prop(os_desc_cfg, | ||
1667 | interface); | ||
1668 | put_unaligned_le32(count, buf); | ||
1669 | |||
1670 | value = w_length; | ||
1671 | } else { | ||
1672 | count = count_ext_prop(os_desc_cfg, | ||
1673 | interface); | ||
1674 | put_unaligned_le16(count, buf + 8); | ||
1675 | count = len_ext_prop(os_desc_cfg, | ||
1676 | interface); | ||
1677 | put_unaligned_le32(count, buf); | ||
1678 | buf += 10; | ||
1679 | value = fill_ext_prop(os_desc_cfg, | ||
1680 | interface, buf); | ||
1681 | if (value < 0) | ||
1682 | return value; | ||
1683 | |||
1684 | value = w_length; | ||
1685 | } | ||
1686 | break; | ||
1687 | } | ||
1688 | req->length = value; | ||
1689 | req->zero = value < w_length; | ||
1690 | value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); | ||
1691 | if (value < 0) { | ||
1692 | DBG(cdev, "ep_queue --> %d\n", value); | ||
1693 | req->status = 0; | ||
1694 | composite_setup_complete(gadget->ep0, req); | ||
1695 | } | ||
1696 | return value; | ||
1697 | } | ||
1698 | |||
1418 | VDBG(cdev, | 1699 | VDBG(cdev, |
1419 | "non-core control req%02x.%02x v%04x i%04x l%d\n", | 1700 | "non-core control req%02x.%02x v%04x i%04x l%d\n", |
1420 | ctrl->bRequestType, ctrl->bRequest, | 1701 | ctrl->bRequestType, ctrl->bRequest, |
@@ -1638,6 +1919,29 @@ fail: | |||
1638 | return ret; | 1919 | return ret; |
1639 | } | 1920 | } |
1640 | 1921 | ||
1922 | int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, | ||
1923 | struct usb_ep *ep0) | ||
1924 | { | ||
1925 | int ret = 0; | ||
1926 | |||
1927 | cdev->os_desc_req = usb_ep_alloc_request(ep0, GFP_KERNEL); | ||
1928 | if (!cdev->os_desc_req) { | ||
1929 | ret = PTR_ERR(cdev->os_desc_req); | ||
1930 | goto end; | ||
1931 | } | ||
1932 | |||
1933 | /* OS feature descriptor length <= 4kB */ | ||
1934 | cdev->os_desc_req->buf = kmalloc(4096, GFP_KERNEL); | ||
1935 | if (!cdev->os_desc_req->buf) { | ||
1936 | ret = PTR_ERR(cdev->os_desc_req->buf); | ||
1937 | kfree(cdev->os_desc_req); | ||
1938 | goto end; | ||
1939 | } | ||
1940 | cdev->os_desc_req->complete = composite_setup_complete; | ||
1941 | end: | ||
1942 | return ret; | ||
1943 | } | ||
1944 | |||
1641 | void composite_dev_cleanup(struct usb_composite_dev *cdev) | 1945 | void composite_dev_cleanup(struct usb_composite_dev *cdev) |
1642 | { | 1946 | { |
1643 | struct usb_gadget_string_container *uc, *tmp; | 1947 | struct usb_gadget_string_container *uc, *tmp; |
@@ -1646,6 +1950,10 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev) | |||
1646 | list_del(&uc->list); | 1950 | list_del(&uc->list); |
1647 | kfree(uc); | 1951 | kfree(uc); |
1648 | } | 1952 | } |
1953 | if (cdev->os_desc_req) { | ||
1954 | kfree(cdev->os_desc_req->buf); | ||
1955 | usb_ep_free_request(cdev->gadget->ep0, cdev->os_desc_req); | ||
1956 | } | ||
1649 | if (cdev->req) { | 1957 | if (cdev->req) { |
1650 | kfree(cdev->req->buf); | 1958 | kfree(cdev->req->buf); |
1651 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); | 1959 | usb_ep_free_request(cdev->gadget->ep0, cdev->req); |
@@ -1683,6 +1991,12 @@ static int composite_bind(struct usb_gadget *gadget, | |||
1683 | if (status < 0) | 1991 | if (status < 0) |
1684 | goto fail; | 1992 | goto fail; |
1685 | 1993 | ||
1994 | if (cdev->use_os_string) { | ||
1995 | status = composite_os_desc_req_prepare(cdev, gadget->ep0); | ||
1996 | if (status) | ||
1997 | goto fail; | ||
1998 | } | ||
1999 | |||
1686 | update_unchanged_dev_desc(&cdev->desc, composite->dev); | 2000 | update_unchanged_dev_desc(&cdev->desc, composite->dev); |
1687 | 2001 | ||
1688 | /* has userspace failed to provide a serial number? */ | 2002 | /* has userspace failed to provide a serial number? */ |
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 7d1cc01796b6..2ddcd635ca2a 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c | |||
@@ -2,9 +2,12 @@ | |||
2 | #include <linux/module.h> | 2 | #include <linux/module.h> |
3 | #include <linux/slab.h> | 3 | #include <linux/slab.h> |
4 | #include <linux/device.h> | 4 | #include <linux/device.h> |
5 | #include <linux/nls.h> | ||
5 | #include <linux/usb/composite.h> | 6 | #include <linux/usb/composite.h> |
6 | #include <linux/usb/gadget_configfs.h> | 7 | #include <linux/usb/gadget_configfs.h> |
7 | #include "configfs.h" | 8 | #include "configfs.h" |
9 | #include "u_f.h" | ||
10 | #include "u_os_desc.h" | ||
8 | 11 | ||
9 | int check_user_usb_string(const char *name, | 12 | int check_user_usb_string(const char *name, |
10 | struct usb_gadget_strings *stringtab_dev) | 13 | struct usb_gadget_strings *stringtab_dev) |
@@ -43,7 +46,8 @@ struct gadget_info { | |||
43 | struct config_group functions_group; | 46 | struct config_group functions_group; |
44 | struct config_group configs_group; | 47 | struct config_group configs_group; |
45 | struct config_group strings_group; | 48 | struct config_group strings_group; |
46 | struct config_group *default_groups[4]; | 49 | struct config_group os_desc_group; |
50 | struct config_group *default_groups[5]; | ||
47 | 51 | ||
48 | struct mutex lock; | 52 | struct mutex lock; |
49 | struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; | 53 | struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; |
@@ -56,6 +60,9 @@ struct gadget_info { | |||
56 | #endif | 60 | #endif |
57 | struct usb_composite_driver composite; | 61 | struct usb_composite_driver composite; |
58 | struct usb_composite_dev cdev; | 62 | struct usb_composite_dev cdev; |
63 | bool use_os_desc; | ||
64 | char b_vendor_code; | ||
65 | char qw_sign[OS_STRING_QW_SIGN_LEN]; | ||
59 | }; | 66 | }; |
60 | 67 | ||
61 | struct config_usb_cfg { | 68 | struct config_usb_cfg { |
@@ -79,6 +86,10 @@ struct gadget_strings { | |||
79 | struct list_head list; | 86 | struct list_head list; |
80 | }; | 87 | }; |
81 | 88 | ||
89 | struct os_desc { | ||
90 | struct config_group group; | ||
91 | }; | ||
92 | |||
82 | struct gadget_config_name { | 93 | struct gadget_config_name { |
83 | struct usb_gadget_strings stringtab_dev; | 94 | struct usb_gadget_strings stringtab_dev; |
84 | struct usb_string strings; | 95 | struct usb_string strings; |
@@ -736,6 +747,525 @@ static void gadget_strings_attr_release(struct config_item *item) | |||
736 | USB_CONFIG_STRING_RW_OPS(gadget_strings); | 747 | USB_CONFIG_STRING_RW_OPS(gadget_strings); |
737 | USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info); | 748 | USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info); |
738 | 749 | ||
750 | static inline struct os_desc *to_os_desc(struct config_item *item) | ||
751 | { | ||
752 | return container_of(to_config_group(item), struct os_desc, group); | ||
753 | } | ||
754 | |||
755 | CONFIGFS_ATTR_STRUCT(os_desc); | ||
756 | CONFIGFS_ATTR_OPS(os_desc); | ||
757 | |||
758 | static ssize_t os_desc_use_show(struct os_desc *os_desc, char *page) | ||
759 | { | ||
760 | struct gadget_info *gi; | ||
761 | |||
762 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
763 | |||
764 | return sprintf(page, "%d", gi->use_os_desc); | ||
765 | } | ||
766 | |||
767 | static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page, | ||
768 | size_t len) | ||
769 | { | ||
770 | struct gadget_info *gi; | ||
771 | int ret; | ||
772 | bool use; | ||
773 | |||
774 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
775 | |||
776 | mutex_lock(&gi->lock); | ||
777 | ret = strtobool(page, &use); | ||
778 | if (!ret) { | ||
779 | gi->use_os_desc = use; | ||
780 | ret = len; | ||
781 | } | ||
782 | mutex_unlock(&gi->lock); | ||
783 | |||
784 | return ret; | ||
785 | } | ||
786 | |||
787 | static struct os_desc_attribute os_desc_use = | ||
788 | __CONFIGFS_ATTR(use, S_IRUGO | S_IWUSR, | ||
789 | os_desc_use_show, | ||
790 | os_desc_use_store); | ||
791 | |||
792 | static ssize_t os_desc_b_vendor_code_show(struct os_desc *os_desc, char *page) | ||
793 | { | ||
794 | struct gadget_info *gi; | ||
795 | |||
796 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
797 | |||
798 | return sprintf(page, "%d", gi->b_vendor_code); | ||
799 | } | ||
800 | |||
801 | static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc, | ||
802 | const char *page, size_t len) | ||
803 | { | ||
804 | struct gadget_info *gi; | ||
805 | int ret; | ||
806 | u8 b_vendor_code; | ||
807 | |||
808 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
809 | |||
810 | mutex_lock(&gi->lock); | ||
811 | ret = kstrtou8(page, 0, &b_vendor_code); | ||
812 | if (!ret) { | ||
813 | gi->b_vendor_code = b_vendor_code; | ||
814 | ret = len; | ||
815 | } | ||
816 | mutex_unlock(&gi->lock); | ||
817 | |||
818 | return ret; | ||
819 | } | ||
820 | |||
821 | static struct os_desc_attribute os_desc_b_vendor_code = | ||
822 | __CONFIGFS_ATTR(b_vendor_code, S_IRUGO | S_IWUSR, | ||
823 | os_desc_b_vendor_code_show, | ||
824 | os_desc_b_vendor_code_store); | ||
825 | |||
826 | static ssize_t os_desc_qw_sign_show(struct os_desc *os_desc, char *page) | ||
827 | { | ||
828 | struct gadget_info *gi; | ||
829 | |||
830 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
831 | |||
832 | memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN); | ||
833 | |||
834 | return OS_STRING_QW_SIGN_LEN; | ||
835 | } | ||
836 | |||
837 | static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page, | ||
838 | size_t len) | ||
839 | { | ||
840 | struct gadget_info *gi; | ||
841 | int res, l; | ||
842 | |||
843 | gi = to_gadget_info(os_desc->group.cg_item.ci_parent); | ||
844 | l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); | ||
845 | if (page[l - 1] == '\n') | ||
846 | --l; | ||
847 | |||
848 | mutex_lock(&gi->lock); | ||
849 | res = utf8s_to_utf16s(page, l, | ||
850 | UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign, | ||
851 | OS_STRING_QW_SIGN_LEN); | ||
852 | if (res > 0) | ||
853 | res = len; | ||
854 | mutex_unlock(&gi->lock); | ||
855 | |||
856 | return res; | ||
857 | } | ||
858 | |||
859 | static struct os_desc_attribute os_desc_qw_sign = | ||
860 | __CONFIGFS_ATTR(qw_sign, S_IRUGO | S_IWUSR, | ||
861 | os_desc_qw_sign_show, | ||
862 | os_desc_qw_sign_store); | ||
863 | |||
864 | static struct configfs_attribute *os_desc_attrs[] = { | ||
865 | &os_desc_use.attr, | ||
866 | &os_desc_b_vendor_code.attr, | ||
867 | &os_desc_qw_sign.attr, | ||
868 | NULL, | ||
869 | }; | ||
870 | |||
871 | static void os_desc_attr_release(struct config_item *item) | ||
872 | { | ||
873 | struct os_desc *os_desc = to_os_desc(item); | ||
874 | kfree(os_desc); | ||
875 | } | ||
876 | |||
877 | static int os_desc_link(struct config_item *os_desc_ci, | ||
878 | struct config_item *usb_cfg_ci) | ||
879 | { | ||
880 | struct gadget_info *gi = container_of(to_config_group(os_desc_ci), | ||
881 | struct gadget_info, os_desc_group); | ||
882 | struct usb_composite_dev *cdev = &gi->cdev; | ||
883 | struct config_usb_cfg *c_target = | ||
884 | container_of(to_config_group(usb_cfg_ci), | ||
885 | struct config_usb_cfg, group); | ||
886 | struct usb_configuration *c; | ||
887 | int ret; | ||
888 | |||
889 | mutex_lock(&gi->lock); | ||
890 | list_for_each_entry(c, &cdev->configs, list) { | ||
891 | if (c == &c_target->c) | ||
892 | break; | ||
893 | } | ||
894 | if (c != &c_target->c) { | ||
895 | ret = -EINVAL; | ||
896 | goto out; | ||
897 | } | ||
898 | |||
899 | if (cdev->os_desc_config) { | ||
900 | ret = -EBUSY; | ||
901 | goto out; | ||
902 | } | ||
903 | |||
904 | cdev->os_desc_config = &c_target->c; | ||
905 | ret = 0; | ||
906 | |||
907 | out: | ||
908 | mutex_unlock(&gi->lock); | ||
909 | return ret; | ||
910 | } | ||
911 | |||
912 | static int os_desc_unlink(struct config_item *os_desc_ci, | ||
913 | struct config_item *usb_cfg_ci) | ||
914 | { | ||
915 | struct gadget_info *gi = container_of(to_config_group(os_desc_ci), | ||
916 | struct gadget_info, os_desc_group); | ||
917 | struct usb_composite_dev *cdev = &gi->cdev; | ||
918 | |||
919 | mutex_lock(&gi->lock); | ||
920 | if (gi->udc_name) | ||
921 | unregister_gadget(gi); | ||
922 | cdev->os_desc_config = NULL; | ||
923 | WARN_ON(gi->udc_name); | ||
924 | mutex_unlock(&gi->lock); | ||
925 | return 0; | ||
926 | } | ||
927 | |||
928 | static struct configfs_item_operations os_desc_ops = { | ||
929 | .release = os_desc_attr_release, | ||
930 | .show_attribute = os_desc_attr_show, | ||
931 | .store_attribute = os_desc_attr_store, | ||
932 | .allow_link = os_desc_link, | ||
933 | .drop_link = os_desc_unlink, | ||
934 | }; | ||
935 | |||
936 | static struct config_item_type os_desc_type = { | ||
937 | .ct_item_ops = &os_desc_ops, | ||
938 | .ct_attrs = os_desc_attrs, | ||
939 | .ct_owner = THIS_MODULE, | ||
940 | }; | ||
941 | |||
942 | CONFIGFS_ATTR_STRUCT(usb_os_desc); | ||
943 | CONFIGFS_ATTR_OPS(usb_os_desc); | ||
944 | |||
945 | |||
946 | static inline struct usb_os_desc_ext_prop | ||
947 | *to_usb_os_desc_ext_prop(struct config_item *item) | ||
948 | { | ||
949 | return container_of(item, struct usb_os_desc_ext_prop, item); | ||
950 | } | ||
951 | |||
952 | CONFIGFS_ATTR_STRUCT(usb_os_desc_ext_prop); | ||
953 | CONFIGFS_ATTR_OPS(usb_os_desc_ext_prop); | ||
954 | |||
955 | static ssize_t ext_prop_type_show(struct usb_os_desc_ext_prop *ext_prop, | ||
956 | char *page) | ||
957 | { | ||
958 | return sprintf(page, "%d", ext_prop->type); | ||
959 | } | ||
960 | |||
961 | static ssize_t ext_prop_type_store(struct usb_os_desc_ext_prop *ext_prop, | ||
962 | const char *page, size_t len) | ||
963 | { | ||
964 | struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); | ||
965 | u8 type; | ||
966 | int ret; | ||
967 | |||
968 | if (desc->opts_mutex) | ||
969 | mutex_lock(desc->opts_mutex); | ||
970 | ret = kstrtou8(page, 0, &type); | ||
971 | if (ret) | ||
972 | goto end; | ||
973 | if (type < USB_EXT_PROP_UNICODE || type > USB_EXT_PROP_UNICODE_MULTI) { | ||
974 | ret = -EINVAL; | ||
975 | goto end; | ||
976 | } | ||
977 | |||
978 | if ((ext_prop->type == USB_EXT_PROP_BINARY || | ||
979 | ext_prop->type == USB_EXT_PROP_LE32 || | ||
980 | ext_prop->type == USB_EXT_PROP_BE32) && | ||
981 | (type == USB_EXT_PROP_UNICODE || | ||
982 | type == USB_EXT_PROP_UNICODE_ENV || | ||
983 | type == USB_EXT_PROP_UNICODE_LINK)) | ||
984 | ext_prop->data_len <<= 1; | ||
985 | else if ((ext_prop->type == USB_EXT_PROP_UNICODE || | ||
986 | ext_prop->type == USB_EXT_PROP_UNICODE_ENV || | ||
987 | ext_prop->type == USB_EXT_PROP_UNICODE_LINK) && | ||
988 | (type == USB_EXT_PROP_BINARY || | ||
989 | type == USB_EXT_PROP_LE32 || | ||
990 | type == USB_EXT_PROP_BE32)) | ||
991 | ext_prop->data_len >>= 1; | ||
992 | ext_prop->type = type; | ||
993 | ret = len; | ||
994 | |||
995 | end: | ||
996 | if (desc->opts_mutex) | ||
997 | mutex_unlock(desc->opts_mutex); | ||
998 | return ret; | ||
999 | } | ||
1000 | |||
1001 | static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop, | ||
1002 | char *page) | ||
1003 | { | ||
1004 | int len = ext_prop->data_len; | ||
1005 | |||
1006 | if (ext_prop->type == USB_EXT_PROP_UNICODE || | ||
1007 | ext_prop->type == USB_EXT_PROP_UNICODE_ENV || | ||
1008 | ext_prop->type == USB_EXT_PROP_UNICODE_LINK) | ||
1009 | len >>= 1; | ||
1010 | memcpy(page, ext_prop->data, len); | ||
1011 | |||
1012 | return len; | ||
1013 | } | ||
1014 | |||
1015 | static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, | ||
1016 | const char *page, size_t len) | ||
1017 | { | ||
1018 | struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); | ||
1019 | char *new_data; | ||
1020 | size_t ret_len = len; | ||
1021 | |||
1022 | if (page[len - 1] == '\n' || page[len - 1] == '\0') | ||
1023 | --len; | ||
1024 | new_data = kzalloc(len, GFP_KERNEL); | ||
1025 | if (!new_data) | ||
1026 | return -ENOMEM; | ||
1027 | |||
1028 | memcpy(new_data, page, len); | ||
1029 | |||
1030 | if (desc->opts_mutex) | ||
1031 | mutex_lock(desc->opts_mutex); | ||
1032 | kfree(ext_prop->data); | ||
1033 | ext_prop->data = new_data; | ||
1034 | desc->ext_prop_len -= ext_prop->data_len; | ||
1035 | ext_prop->data_len = len; | ||
1036 | desc->ext_prop_len += ext_prop->data_len; | ||
1037 | if (ext_prop->type == USB_EXT_PROP_UNICODE || | ||
1038 | ext_prop->type == USB_EXT_PROP_UNICODE_ENV || | ||
1039 | ext_prop->type == USB_EXT_PROP_UNICODE_LINK) { | ||
1040 | desc->ext_prop_len -= ext_prop->data_len; | ||
1041 | ext_prop->data_len <<= 1; | ||
1042 | ext_prop->data_len += 2; | ||
1043 | desc->ext_prop_len += ext_prop->data_len; | ||
1044 | } | ||
1045 | if (desc->opts_mutex) | ||
1046 | mutex_unlock(desc->opts_mutex); | ||
1047 | return ret_len; | ||
1048 | } | ||
1049 | |||
1050 | static struct usb_os_desc_ext_prop_attribute ext_prop_type = | ||
1051 | __CONFIGFS_ATTR(type, S_IRUGO | S_IWUSR, | ||
1052 | ext_prop_type_show, ext_prop_type_store); | ||
1053 | |||
1054 | static struct usb_os_desc_ext_prop_attribute ext_prop_data = | ||
1055 | __CONFIGFS_ATTR(data, S_IRUGO | S_IWUSR, | ||
1056 | ext_prop_data_show, ext_prop_data_store); | ||
1057 | |||
1058 | static struct configfs_attribute *ext_prop_attrs[] = { | ||
1059 | &ext_prop_type.attr, | ||
1060 | &ext_prop_data.attr, | ||
1061 | NULL, | ||
1062 | }; | ||
1063 | |||
1064 | static void usb_os_desc_ext_prop_release(struct config_item *item) | ||
1065 | { | ||
1066 | struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); | ||
1067 | |||
1068 | kfree(ext_prop); /* frees a whole chunk */ | ||
1069 | } | ||
1070 | |||
1071 | static struct configfs_item_operations ext_prop_ops = { | ||
1072 | .release = usb_os_desc_ext_prop_release, | ||
1073 | .show_attribute = usb_os_desc_ext_prop_attr_show, | ||
1074 | .store_attribute = usb_os_desc_ext_prop_attr_store, | ||
1075 | }; | ||
1076 | |||
1077 | static struct config_item *ext_prop_make( | ||
1078 | struct config_group *group, | ||
1079 | const char *name) | ||
1080 | { | ||
1081 | struct usb_os_desc_ext_prop *ext_prop; | ||
1082 | struct config_item_type *ext_prop_type; | ||
1083 | struct usb_os_desc *desc; | ||
1084 | char *vlabuf; | ||
1085 | |||
1086 | vla_group(data_chunk); | ||
1087 | vla_item(data_chunk, struct usb_os_desc_ext_prop, ext_prop, 1); | ||
1088 | vla_item(data_chunk, struct config_item_type, ext_prop_type, 1); | ||
1089 | |||
1090 | vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL); | ||
1091 | if (!vlabuf) | ||
1092 | return ERR_PTR(-ENOMEM); | ||
1093 | |||
1094 | ext_prop = vla_ptr(vlabuf, data_chunk, ext_prop); | ||
1095 | ext_prop_type = vla_ptr(vlabuf, data_chunk, ext_prop_type); | ||
1096 | |||
1097 | desc = container_of(group, struct usb_os_desc, group); | ||
1098 | ext_prop_type->ct_item_ops = &ext_prop_ops; | ||
1099 | ext_prop_type->ct_attrs = ext_prop_attrs; | ||
1100 | ext_prop_type->ct_owner = desc->owner; | ||
1101 | |||
1102 | config_item_init_type_name(&ext_prop->item, name, ext_prop_type); | ||
1103 | |||
1104 | ext_prop->name = kstrdup(name, GFP_KERNEL); | ||
1105 | if (!ext_prop->name) { | ||
1106 | kfree(vlabuf); | ||
1107 | return ERR_PTR(-ENOMEM); | ||
1108 | } | ||
1109 | desc->ext_prop_len += 14; | ||
1110 | ext_prop->name_len = 2 * strlen(ext_prop->name) + 2; | ||
1111 | if (desc->opts_mutex) | ||
1112 | mutex_lock(desc->opts_mutex); | ||
1113 | desc->ext_prop_len += ext_prop->name_len; | ||
1114 | list_add_tail(&ext_prop->entry, &desc->ext_prop); | ||
1115 | ++desc->ext_prop_count; | ||
1116 | if (desc->opts_mutex) | ||
1117 | mutex_unlock(desc->opts_mutex); | ||
1118 | |||
1119 | return &ext_prop->item; | ||
1120 | } | ||
1121 | |||
1122 | static void ext_prop_drop(struct config_group *group, struct config_item *item) | ||
1123 | { | ||
1124 | struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); | ||
1125 | struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); | ||
1126 | |||
1127 | if (desc->opts_mutex) | ||
1128 | mutex_lock(desc->opts_mutex); | ||
1129 | list_del(&ext_prop->entry); | ||
1130 | --desc->ext_prop_count; | ||
1131 | kfree(ext_prop->name); | ||
1132 | desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); | ||
1133 | if (desc->opts_mutex) | ||
1134 | mutex_unlock(desc->opts_mutex); | ||
1135 | config_item_put(item); | ||
1136 | } | ||
1137 | |||
1138 | static struct configfs_group_operations interf_grp_ops = { | ||
1139 | .make_item = &ext_prop_make, | ||
1140 | .drop_item = &ext_prop_drop, | ||
1141 | }; | ||
1142 | |||
1143 | static struct configfs_item_operations interf_item_ops = { | ||
1144 | .show_attribute = usb_os_desc_attr_show, | ||
1145 | .store_attribute = usb_os_desc_attr_store, | ||
1146 | }; | ||
1147 | |||
1148 | static ssize_t rndis_grp_compatible_id_show(struct usb_os_desc *desc, | ||
1149 | char *page) | ||
1150 | { | ||
1151 | memcpy(page, desc->ext_compat_id, 8); | ||
1152 | return 8; | ||
1153 | } | ||
1154 | |||
1155 | static ssize_t rndis_grp_compatible_id_store(struct usb_os_desc *desc, | ||
1156 | const char *page, size_t len) | ||
1157 | { | ||
1158 | int l; | ||
1159 | |||
1160 | l = min_t(int, 8, len); | ||
1161 | if (page[l - 1] == '\n') | ||
1162 | --l; | ||
1163 | if (desc->opts_mutex) | ||
1164 | mutex_lock(desc->opts_mutex); | ||
1165 | memcpy(desc->ext_compat_id, page, l); | ||
1166 | desc->ext_compat_id[l] = '\0'; | ||
1167 | |||
1168 | if (desc->opts_mutex) | ||
1169 | mutex_unlock(desc->opts_mutex); | ||
1170 | |||
1171 | return len; | ||
1172 | } | ||
1173 | |||
1174 | static struct usb_os_desc_attribute rndis_grp_attr_compatible_id = | ||
1175 | __CONFIGFS_ATTR(compatible_id, S_IRUGO | S_IWUSR, | ||
1176 | rndis_grp_compatible_id_show, | ||
1177 | rndis_grp_compatible_id_store); | ||
1178 | |||
1179 | static ssize_t rndis_grp_sub_compatible_id_show(struct usb_os_desc *desc, | ||
1180 | char *page) | ||
1181 | { | ||
1182 | memcpy(page, desc->ext_compat_id + 8, 8); | ||
1183 | return 8; | ||
1184 | } | ||
1185 | |||
1186 | static ssize_t rndis_grp_sub_compatible_id_store(struct usb_os_desc *desc, | ||
1187 | const char *page, size_t len) | ||
1188 | { | ||
1189 | int l; | ||
1190 | |||
1191 | l = min_t(int, 8, len); | ||
1192 | if (page[l - 1] == '\n') | ||
1193 | --l; | ||
1194 | if (desc->opts_mutex) | ||
1195 | mutex_lock(desc->opts_mutex); | ||
1196 | memcpy(desc->ext_compat_id + 8, page, l); | ||
1197 | desc->ext_compat_id[l + 8] = '\0'; | ||
1198 | |||
1199 | if (desc->opts_mutex) | ||
1200 | mutex_unlock(desc->opts_mutex); | ||
1201 | |||
1202 | return len; | ||
1203 | } | ||
1204 | |||
1205 | static struct usb_os_desc_attribute rndis_grp_attr_sub_compatible_id = | ||
1206 | __CONFIGFS_ATTR(sub_compatible_id, S_IRUGO | S_IWUSR, | ||
1207 | rndis_grp_sub_compatible_id_show, | ||
1208 | rndis_grp_sub_compatible_id_store); | ||
1209 | |||
1210 | static struct configfs_attribute *interf_grp_attrs[] = { | ||
1211 | &rndis_grp_attr_compatible_id.attr, | ||
1212 | &rndis_grp_attr_sub_compatible_id.attr, | ||
1213 | NULL | ||
1214 | }; | ||
1215 | |||
1216 | int usb_os_desc_prepare_interf_dir(struct config_group *parent, | ||
1217 | int n_interf, | ||
1218 | struct usb_os_desc **desc, | ||
1219 | struct module *owner) | ||
1220 | { | ||
1221 | struct config_group **f_default_groups, *os_desc_group, | ||
1222 | **interface_groups; | ||
1223 | struct config_item_type *os_desc_type, *interface_type; | ||
1224 | |||
1225 | vla_group(data_chunk); | ||
1226 | vla_item(data_chunk, struct config_group *, f_default_groups, 2); | ||
1227 | vla_item(data_chunk, struct config_group, os_desc_group, 1); | ||
1228 | vla_item(data_chunk, struct config_group *, interface_groups, | ||
1229 | n_interf + 1); | ||
1230 | vla_item(data_chunk, struct config_item_type, os_desc_type, 1); | ||
1231 | vla_item(data_chunk, struct config_item_type, interface_type, 1); | ||
1232 | |||
1233 | char *vlabuf = kzalloc(vla_group_size(data_chunk), GFP_KERNEL); | ||
1234 | if (!vlabuf) | ||
1235 | return -ENOMEM; | ||
1236 | |||
1237 | f_default_groups = vla_ptr(vlabuf, data_chunk, f_default_groups); | ||
1238 | os_desc_group = vla_ptr(vlabuf, data_chunk, os_desc_group); | ||
1239 | os_desc_type = vla_ptr(vlabuf, data_chunk, os_desc_type); | ||
1240 | interface_groups = vla_ptr(vlabuf, data_chunk, interface_groups); | ||
1241 | interface_type = vla_ptr(vlabuf, data_chunk, interface_type); | ||
1242 | |||
1243 | parent->default_groups = f_default_groups; | ||
1244 | os_desc_type->ct_owner = owner; | ||
1245 | config_group_init_type_name(os_desc_group, "os_desc", os_desc_type); | ||
1246 | f_default_groups[0] = os_desc_group; | ||
1247 | |||
1248 | os_desc_group->default_groups = interface_groups; | ||
1249 | interface_type->ct_item_ops = &interf_item_ops; | ||
1250 | interface_type->ct_group_ops = &interf_grp_ops; | ||
1251 | interface_type->ct_attrs = interf_grp_attrs; | ||
1252 | interface_type->ct_owner = owner; | ||
1253 | |||
1254 | while (n_interf--) { | ||
1255 | struct usb_os_desc *d; | ||
1256 | |||
1257 | d = desc[n_interf]; | ||
1258 | d->owner = owner; | ||
1259 | config_group_init_type_name(&d->group, "", interface_type); | ||
1260 | config_item_set_name(&d->group.cg_item, "interface.%d", | ||
1261 | n_interf); | ||
1262 | interface_groups[n_interf] = &d->group; | ||
1263 | } | ||
1264 | |||
1265 | return 0; | ||
1266 | } | ||
1267 | EXPORT_SYMBOL(usb_os_desc_prepare_interf_dir); | ||
1268 | |||
739 | static int configfs_do_nothing(struct usb_composite_dev *cdev) | 1269 | static int configfs_do_nothing(struct usb_composite_dev *cdev) |
740 | { | 1270 | { |
741 | WARN_ON(1); | 1271 | WARN_ON(1); |
@@ -745,6 +1275,9 @@ static int configfs_do_nothing(struct usb_composite_dev *cdev) | |||
745 | int composite_dev_prepare(struct usb_composite_driver *composite, | 1275 | int composite_dev_prepare(struct usb_composite_driver *composite, |
746 | struct usb_composite_dev *dev); | 1276 | struct usb_composite_dev *dev); |
747 | 1277 | ||
1278 | int composite_os_desc_req_prepare(struct usb_composite_dev *cdev, | ||
1279 | struct usb_ep *ep0); | ||
1280 | |||
748 | static void purge_configs_funcs(struct gadget_info *gi) | 1281 | static void purge_configs_funcs(struct gadget_info *gi) |
749 | { | 1282 | { |
750 | struct usb_configuration *c; | 1283 | struct usb_configuration *c; |
@@ -793,7 +1326,7 @@ static int configfs_composite_bind(struct usb_gadget *gadget, | |||
793 | ret = -EINVAL; | 1326 | ret = -EINVAL; |
794 | 1327 | ||
795 | if (list_empty(&gi->cdev.configs)) { | 1328 | if (list_empty(&gi->cdev.configs)) { |
796 | pr_err("Need atleast one configuration in %s.\n", | 1329 | pr_err("Need at least one configuration in %s.\n", |
797 | gi->composite.name); | 1330 | gi->composite.name); |
798 | goto err_comp_cleanup; | 1331 | goto err_comp_cleanup; |
799 | } | 1332 | } |
@@ -804,7 +1337,7 @@ static int configfs_composite_bind(struct usb_gadget *gadget, | |||
804 | 1337 | ||
805 | cfg = container_of(c, struct config_usb_cfg, c); | 1338 | cfg = container_of(c, struct config_usb_cfg, c); |
806 | if (list_empty(&cfg->func_list)) { | 1339 | if (list_empty(&cfg->func_list)) { |
807 | pr_err("Config %s/%d of %s needs atleast one function.\n", | 1340 | pr_err("Config %s/%d of %s needs at least one function.\n", |
808 | c->label, c->bConfigurationValue, | 1341 | c->label, c->bConfigurationValue, |
809 | gi->composite.name); | 1342 | gi->composite.name); |
810 | goto err_comp_cleanup; | 1343 | goto err_comp_cleanup; |
@@ -839,6 +1372,12 @@ static int configfs_composite_bind(struct usb_gadget *gadget, | |||
839 | gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; | 1372 | gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id; |
840 | } | 1373 | } |
841 | 1374 | ||
1375 | if (gi->use_os_desc) { | ||
1376 | cdev->use_os_string = true; | ||
1377 | cdev->b_vendor_code = gi->b_vendor_code; | ||
1378 | memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); | ||
1379 | } | ||
1380 | |||
842 | /* Go through all configs, attach all functions */ | 1381 | /* Go through all configs, attach all functions */ |
843 | list_for_each_entry(c, &gi->cdev.configs, list) { | 1382 | list_for_each_entry(c, &gi->cdev.configs, list) { |
844 | struct config_usb_cfg *cfg; | 1383 | struct config_usb_cfg *cfg; |
@@ -874,6 +1413,12 @@ static int configfs_composite_bind(struct usb_gadget *gadget, | |||
874 | } | 1413 | } |
875 | usb_ep_autoconfig_reset(cdev->gadget); | 1414 | usb_ep_autoconfig_reset(cdev->gadget); |
876 | } | 1415 | } |
1416 | if (cdev->use_os_string) { | ||
1417 | ret = composite_os_desc_req_prepare(cdev, gadget->ep0); | ||
1418 | if (ret) | ||
1419 | goto err_purge_funcs; | ||
1420 | } | ||
1421 | |||
877 | usb_ep_autoconfig_reset(cdev->gadget); | 1422 | usb_ep_autoconfig_reset(cdev->gadget); |
878 | return 0; | 1423 | return 0; |
879 | 1424 | ||
@@ -929,6 +1474,7 @@ static struct config_group *gadgets_make( | |||
929 | gi->group.default_groups[0] = &gi->functions_group; | 1474 | gi->group.default_groups[0] = &gi->functions_group; |
930 | gi->group.default_groups[1] = &gi->configs_group; | 1475 | gi->group.default_groups[1] = &gi->configs_group; |
931 | gi->group.default_groups[2] = &gi->strings_group; | 1476 | gi->group.default_groups[2] = &gi->strings_group; |
1477 | gi->group.default_groups[3] = &gi->os_desc_group; | ||
932 | 1478 | ||
933 | config_group_init_type_name(&gi->functions_group, "functions", | 1479 | config_group_init_type_name(&gi->functions_group, "functions", |
934 | &functions_type); | 1480 | &functions_type); |
@@ -936,6 +1482,8 @@ static struct config_group *gadgets_make( | |||
936 | &config_desc_type); | 1482 | &config_desc_type); |
937 | config_group_init_type_name(&gi->strings_group, "strings", | 1483 | config_group_init_type_name(&gi->strings_group, "strings", |
938 | &gadget_strings_strings_type); | 1484 | &gadget_strings_strings_type); |
1485 | config_group_init_type_name(&gi->os_desc_group, "os_desc", | ||
1486 | &os_desc_type); | ||
939 | 1487 | ||
940 | gi->composite.bind = configfs_do_nothing; | 1488 | gi->composite.bind = configfs_do_nothing; |
941 | gi->composite.unbind = configfs_do_nothing; | 1489 | gi->composite.unbind = configfs_do_nothing; |
@@ -1005,7 +1553,7 @@ void unregister_gadget_item(struct config_item *item) | |||
1005 | 1553 | ||
1006 | unregister_gadget(gi); | 1554 | unregister_gadget(gi); |
1007 | } | 1555 | } |
1008 | EXPORT_SYMBOL(unregister_gadget_item); | 1556 | EXPORT_SYMBOL_GPL(unregister_gadget_item); |
1009 | 1557 | ||
1010 | static int __init gadget_cfs_init(void) | 1558 | static int __init gadget_cfs_init(void) |
1011 | { | 1559 | { |
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h index a7b564a913d1..a14ac792c698 100644 --- a/drivers/usb/gadget/configfs.h +++ b/drivers/usb/gadget/configfs.h | |||
@@ -1,6 +1,18 @@ | |||
1 | #ifndef USB__GADGET__CONFIGFS__H | 1 | #ifndef USB__GADGET__CONFIGFS__H |
2 | #define USB__GADGET__CONFIGFS__H | 2 | #define USB__GADGET__CONFIGFS__H |
3 | 3 | ||
4 | #include <linux/configfs.h> | ||
5 | |||
4 | void unregister_gadget_item(struct config_item *item); | 6 | void unregister_gadget_item(struct config_item *item); |
5 | 7 | ||
8 | int usb_os_desc_prepare_interf_dir(struct config_group *parent, | ||
9 | int n_interf, | ||
10 | struct usb_os_desc **desc, | ||
11 | struct module *owner); | ||
12 | |||
13 | static inline struct usb_os_desc *to_usb_os_desc(struct config_item *item) | ||
14 | { | ||
15 | return container_of(to_config_group(item), struct usb_os_desc, group); | ||
16 | } | ||
17 | |||
6 | #endif /* USB__GADGET__CONFIGFS__H */ | 18 | #endif /* USB__GADGET__CONFIGFS__H */ |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 8c06430dcc47..2b54955d3166 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -561,7 +561,6 @@ static int dummy_disable(struct usb_ep *_ep) | |||
561 | struct dummy_ep *ep; | 561 | struct dummy_ep *ep; |
562 | struct dummy *dum; | 562 | struct dummy *dum; |
563 | unsigned long flags; | 563 | unsigned long flags; |
564 | int retval; | ||
565 | 564 | ||
566 | ep = usb_ep_to_dummy_ep(_ep); | 565 | ep = usb_ep_to_dummy_ep(_ep); |
567 | if (!_ep || !ep->desc || _ep->name == ep0name) | 566 | if (!_ep || !ep->desc || _ep->name == ep0name) |
@@ -571,12 +570,11 @@ static int dummy_disable(struct usb_ep *_ep) | |||
571 | spin_lock_irqsave(&dum->lock, flags); | 570 | spin_lock_irqsave(&dum->lock, flags); |
572 | ep->desc = NULL; | 571 | ep->desc = NULL; |
573 | ep->stream_en = 0; | 572 | ep->stream_en = 0; |
574 | retval = 0; | ||
575 | nuke(dum, ep); | 573 | nuke(dum, ep); |
576 | spin_unlock_irqrestore(&dum->lock, flags); | 574 | spin_unlock_irqrestore(&dum->lock, flags); |
577 | 575 | ||
578 | dev_dbg(udc_dev(dum), "disabled %s\n", _ep->name); | 576 | dev_dbg(udc_dev(dum), "disabled %s\n", _ep->name); |
579 | return retval; | 577 | return 0; |
580 | } | 578 | } |
581 | 579 | ||
582 | static struct usb_request *dummy_alloc_request(struct usb_ep *_ep, | 580 | static struct usb_request *dummy_alloc_request(struct usb_ep *_ep, |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 1e12b3ee56fd..74202d67f911 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -33,36 +33,11 @@ | |||
33 | #include <linux/poll.h> | 33 | #include <linux/poll.h> |
34 | 34 | ||
35 | #include "u_fs.h" | 35 | #include "u_fs.h" |
36 | #include "u_f.h" | ||
36 | #include "configfs.h" | 37 | #include "configfs.h" |
37 | 38 | ||
38 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ | 39 | #define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */ |
39 | 40 | ||
40 | /* Variable Length Array Macros **********************************************/ | ||
41 | #define vla_group(groupname) size_t groupname##__next = 0 | ||
42 | #define vla_group_size(groupname) groupname##__next | ||
43 | |||
44 | #define vla_item(groupname, type, name, n) \ | ||
45 | size_t groupname##_##name##__offset = ({ \ | ||
46 | size_t align_mask = __alignof__(type) - 1; \ | ||
47 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | ||
48 | size_t size = (n) * sizeof(type); \ | ||
49 | groupname##__next = offset + size; \ | ||
50 | offset; \ | ||
51 | }) | ||
52 | |||
53 | #define vla_item_with_sz(groupname, type, name, n) \ | ||
54 | size_t groupname##_##name##__sz = (n) * sizeof(type); \ | ||
55 | size_t groupname##_##name##__offset = ({ \ | ||
56 | size_t align_mask = __alignof__(type) - 1; \ | ||
57 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | ||
58 | size_t size = groupname##_##name##__sz; \ | ||
59 | groupname##__next = offset + size; \ | ||
60 | offset; \ | ||
61 | }) | ||
62 | |||
63 | #define vla_ptr(ptr, groupname, name) \ | ||
64 | ((void *) ((char *)ptr + groupname##_##name##__offset)) | ||
65 | |||
66 | /* Reference counter handling */ | 41 | /* Reference counter handling */ |
67 | static void ffs_data_get(struct ffs_data *ffs); | 42 | static void ffs_data_get(struct ffs_data *ffs); |
68 | static void ffs_data_put(struct ffs_data *ffs); | 43 | static void ffs_data_put(struct ffs_data *ffs); |
@@ -190,7 +165,7 @@ ffs_sb_create_file(struct super_block *sb, const char *name, void *data, | |||
190 | /* Devices management *******************************************************/ | 165 | /* Devices management *******************************************************/ |
191 | 166 | ||
192 | DEFINE_MUTEX(ffs_lock); | 167 | DEFINE_MUTEX(ffs_lock); |
193 | EXPORT_SYMBOL(ffs_lock); | 168 | EXPORT_SYMBOL_GPL(ffs_lock); |
194 | 169 | ||
195 | static struct ffs_dev *_ffs_find_dev(const char *name); | 170 | static struct ffs_dev *_ffs_find_dev(const char *name); |
196 | static struct ffs_dev *_ffs_alloc_dev(void); | 171 | static struct ffs_dev *_ffs_alloc_dev(void); |
@@ -2883,7 +2858,7 @@ int ffs_name_dev(struct ffs_dev *dev, const char *name) | |||
2883 | 2858 | ||
2884 | return ret; | 2859 | return ret; |
2885 | } | 2860 | } |
2886 | EXPORT_SYMBOL(ffs_name_dev); | 2861 | EXPORT_SYMBOL_GPL(ffs_name_dev); |
2887 | 2862 | ||
2888 | int ffs_single_dev(struct ffs_dev *dev) | 2863 | int ffs_single_dev(struct ffs_dev *dev) |
2889 | { | 2864 | { |
@@ -2900,7 +2875,7 @@ int ffs_single_dev(struct ffs_dev *dev) | |||
2900 | ffs_dev_unlock(); | 2875 | ffs_dev_unlock(); |
2901 | return ret; | 2876 | return ret; |
2902 | } | 2877 | } |
2903 | EXPORT_SYMBOL(ffs_single_dev); | 2878 | EXPORT_SYMBOL_GPL(ffs_single_dev); |
2904 | 2879 | ||
2905 | /* | 2880 | /* |
2906 | * ffs_lock must be taken by the caller of this function | 2881 | * ffs_lock must be taken by the caller of this function |
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c index 9a4f49dc6ac4..eed3ad878047 100644 --- a/drivers/usb/gadget/f_rndis.c +++ b/drivers/usb/gadget/f_rndis.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "u_ether_configfs.h" | 27 | #include "u_ether_configfs.h" |
28 | #include "u_rndis.h" | 28 | #include "u_rndis.h" |
29 | #include "rndis.h" | 29 | #include "rndis.h" |
30 | #include "configfs.h" | ||
30 | 31 | ||
31 | /* | 32 | /* |
32 | * This function is an RNDIS Ethernet port -- a Microsoft protocol that's | 33 | * This function is an RNDIS Ethernet port -- a Microsoft protocol that's |
@@ -682,6 +683,15 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
682 | 683 | ||
683 | rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); | 684 | rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); |
684 | 685 | ||
686 | if (cdev->use_os_string) { | ||
687 | f->os_desc_table = kzalloc(sizeof(*f->os_desc_table), | ||
688 | GFP_KERNEL); | ||
689 | if (!f->os_desc_table) | ||
690 | return PTR_ERR(f->os_desc_table); | ||
691 | f->os_desc_n = 1; | ||
692 | f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc; | ||
693 | } | ||
694 | |||
685 | /* | 695 | /* |
686 | * in drivers/usb/gadget/configfs.c:configfs_composite_bind() | 696 | * in drivers/usb/gadget/configfs.c:configfs_composite_bind() |
687 | * configurations are bound in sequence with list_for_each_entry, | 697 | * configurations are bound in sequence with list_for_each_entry, |
@@ -693,14 +703,16 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
693 | gether_set_gadget(rndis_opts->net, cdev->gadget); | 703 | gether_set_gadget(rndis_opts->net, cdev->gadget); |
694 | status = gether_register_netdev(rndis_opts->net); | 704 | status = gether_register_netdev(rndis_opts->net); |
695 | if (status) | 705 | if (status) |
696 | return status; | 706 | goto fail; |
697 | rndis_opts->bound = true; | 707 | rndis_opts->bound = true; |
698 | } | 708 | } |
699 | 709 | ||
700 | us = usb_gstrings_attach(cdev, rndis_strings, | 710 | us = usb_gstrings_attach(cdev, rndis_strings, |
701 | ARRAY_SIZE(rndis_string_defs)); | 711 | ARRAY_SIZE(rndis_string_defs)); |
702 | if (IS_ERR(us)) | 712 | if (IS_ERR(us)) { |
703 | return PTR_ERR(us); | 713 | status = PTR_ERR(us); |
714 | goto fail; | ||
715 | } | ||
704 | rndis_control_intf.iInterface = us[0].id; | 716 | rndis_control_intf.iInterface = us[0].id; |
705 | rndis_data_intf.iInterface = us[1].id; | 717 | rndis_data_intf.iInterface = us[1].id; |
706 | rndis_iad_descriptor.iFunction = us[2].id; | 718 | rndis_iad_descriptor.iFunction = us[2].id; |
@@ -802,6 +814,8 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) | |||
802 | return 0; | 814 | return 0; |
803 | 815 | ||
804 | fail: | 816 | fail: |
817 | kfree(f->os_desc_table); | ||
818 | f->os_desc_n = 0; | ||
805 | usb_free_all_descriptors(f); | 819 | usb_free_all_descriptors(f); |
806 | 820 | ||
807 | if (rndis->notify_req) { | 821 | if (rndis->notify_req) { |
@@ -834,7 +848,7 @@ void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net) | |||
834 | opts->borrowed_net = opts->bound = true; | 848 | opts->borrowed_net = opts->bound = true; |
835 | opts->net = net; | 849 | opts->net = net; |
836 | } | 850 | } |
837 | EXPORT_SYMBOL(rndis_borrow_net); | 851 | EXPORT_SYMBOL_GPL(rndis_borrow_net); |
838 | 852 | ||
839 | static inline struct f_rndis_opts *to_f_rndis_opts(struct config_item *item) | 853 | static inline struct f_rndis_opts *to_f_rndis_opts(struct config_item *item) |
840 | { | 854 | { |
@@ -882,16 +896,21 @@ static void rndis_free_inst(struct usb_function_instance *f) | |||
882 | else | 896 | else |
883 | free_netdev(opts->net); | 897 | free_netdev(opts->net); |
884 | } | 898 | } |
899 | |||
900 | kfree(opts->rndis_os_desc.group.default_groups); /* single VLA chunk */ | ||
885 | kfree(opts); | 901 | kfree(opts); |
886 | } | 902 | } |
887 | 903 | ||
888 | static struct usb_function_instance *rndis_alloc_inst(void) | 904 | static struct usb_function_instance *rndis_alloc_inst(void) |
889 | { | 905 | { |
890 | struct f_rndis_opts *opts; | 906 | struct f_rndis_opts *opts; |
907 | struct usb_os_desc *descs[1]; | ||
891 | 908 | ||
892 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | 909 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); |
893 | if (!opts) | 910 | if (!opts) |
894 | return ERR_PTR(-ENOMEM); | 911 | return ERR_PTR(-ENOMEM); |
912 | opts->rndis_os_desc.ext_compat_id = opts->rndis_ext_compat_id; | ||
913 | |||
895 | mutex_init(&opts->lock); | 914 | mutex_init(&opts->lock); |
896 | opts->func_inst.free_func_inst = rndis_free_inst; | 915 | opts->func_inst.free_func_inst = rndis_free_inst; |
897 | opts->net = gether_setup_default(); | 916 | opts->net = gether_setup_default(); |
@@ -900,7 +919,11 @@ static struct usb_function_instance *rndis_alloc_inst(void) | |||
900 | kfree(opts); | 919 | kfree(opts); |
901 | return ERR_CAST(net); | 920 | return ERR_CAST(net); |
902 | } | 921 | } |
922 | INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop); | ||
903 | 923 | ||
924 | descs[0] = &opts->rndis_os_desc; | ||
925 | usb_os_desc_prepare_interf_dir(&opts->func_inst.group, 1, descs, | ||
926 | THIS_MODULE); | ||
904 | config_group_init_type_name(&opts->func_inst.group, "", | 927 | config_group_init_type_name(&opts->func_inst.group, "", |
905 | &rndis_func_type); | 928 | &rndis_func_type); |
906 | 929 | ||
@@ -925,6 +948,8 @@ static void rndis_unbind(struct usb_configuration *c, struct usb_function *f) | |||
925 | { | 948 | { |
926 | struct f_rndis *rndis = func_to_rndis(f); | 949 | struct f_rndis *rndis = func_to_rndis(f); |
927 | 950 | ||
951 | kfree(f->os_desc_table); | ||
952 | f->os_desc_n = 0; | ||
928 | usb_free_all_descriptors(f); | 953 | usb_free_all_descriptors(f); |
929 | 954 | ||
930 | kfree(rndis->notify_req->buf); | 955 | kfree(rndis->notify_req->buf); |
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c index df4a0dcbc993..1ea8baf33333 100644 --- a/drivers/usb/gadget/f_subset.c +++ b/drivers/usb/gadget/f_subset.c | |||
@@ -276,7 +276,7 @@ static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
276 | } | 276 | } |
277 | 277 | ||
278 | net = gether_connect(&geth->port); | 278 | net = gether_connect(&geth->port); |
279 | return PTR_RET(net); | 279 | return PTR_ERR_OR_ZERO(net); |
280 | } | 280 | } |
281 | 281 | ||
282 | static void geth_disable(struct usb_function *f) | 282 | static void geth_disable(struct usb_function *f) |
diff --git a/drivers/usb/gadget/f_uac2.c b/drivers/usb/gadget/f_uac2.c index bc23040c7790..6261db4a9910 100644 --- a/drivers/usb/gadget/f_uac2.c +++ b/drivers/usb/gadget/f_uac2.c | |||
@@ -196,7 +196,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) | |||
196 | struct snd_uac2_chip *uac2 = prm->uac2; | 196 | struct snd_uac2_chip *uac2 = prm->uac2; |
197 | 197 | ||
198 | /* i/f shutting down */ | 198 | /* i/f shutting down */ |
199 | if (!prm->ep_enabled) | 199 | if (!prm->ep_enabled || req->status == -ESHUTDOWN) |
200 | return; | 200 | return; |
201 | 201 | ||
202 | /* | 202 | /* |
@@ -974,8 +974,6 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
974 | prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); | 974 | prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); |
975 | if (!prm->rbuf) { | 975 | if (!prm->rbuf) { |
976 | prm->max_psize = 0; | 976 | prm->max_psize = 0; |
977 | dev_err(&uac2->pdev.dev, | ||
978 | "%s:%d Error!\n", __func__, __LINE__); | ||
979 | goto err; | 977 | goto err; |
980 | } | 978 | } |
981 | 979 | ||
@@ -984,8 +982,6 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) | |||
984 | prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); | 982 | prm->rbuf = kzalloc(prm->max_psize * USB_XFERS, GFP_KERNEL); |
985 | if (!prm->rbuf) { | 983 | if (!prm->rbuf) { |
986 | prm->max_psize = 0; | 984 | prm->max_psize = 0; |
987 | dev_err(&uac2->pdev.dev, | ||
988 | "%s:%d Error!\n", __func__, __LINE__); | ||
989 | goto err; | 985 | goto err; |
990 | } | 986 | } |
991 | 987 | ||
@@ -1298,10 +1294,8 @@ static int audio_bind_config(struct usb_configuration *cfg) | |||
1298 | int res; | 1294 | int res; |
1299 | 1295 | ||
1300 | agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL); | 1296 | agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL); |
1301 | if (agdev_g == NULL) { | 1297 | if (agdev_g == NULL) |
1302 | printk(KERN_ERR "Unable to allocate audio gadget\n"); | ||
1303 | return -ENOMEM; | 1298 | return -ENOMEM; |
1304 | } | ||
1305 | 1299 | ||
1306 | res = usb_string_ids_tab(cfg->cdev, strings_fn); | 1300 | res = usb_string_ids_tab(cfg->cdev, strings_fn); |
1307 | if (res) | 1301 | if (res) |
diff --git a/drivers/usb/gadget/fotg210-udc.c b/drivers/usb/gadget/fotg210-udc.c index 2d0305280e8c..e143d69f6017 100644 --- a/drivers/usb/gadget/fotg210-udc.c +++ b/drivers/usb/gadget/fotg210-udc.c | |||
@@ -1112,17 +1112,13 @@ static int fotg210_udc_probe(struct platform_device *pdev) | |||
1112 | 1112 | ||
1113 | /* initialize udc */ | 1113 | /* initialize udc */ |
1114 | fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); | 1114 | fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); |
1115 | if (fotg210 == NULL) { | 1115 | if (fotg210 == NULL) |
1116 | pr_err("kzalloc error\n"); | ||
1117 | goto err_alloc; | 1116 | goto err_alloc; |
1118 | } | ||
1119 | 1117 | ||
1120 | for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { | 1118 | for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { |
1121 | _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); | 1119 | _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); |
1122 | if (_ep[i] == NULL) { | 1120 | if (_ep[i] == NULL) |
1123 | pr_err("_ep kzalloc error\n"); | ||
1124 | goto err_alloc; | 1121 | goto err_alloc; |
1125 | } | ||
1126 | fotg210->ep[i] = _ep[i]; | 1122 | fotg210->ep[i] = _ep[i]; |
1127 | } | 1123 | } |
1128 | 1124 | ||
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index a2f26cdb56fe..28e4fc957026 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -2256,10 +2256,8 @@ static int __init struct_udc_setup(struct fsl_udc *udc, | |||
2256 | udc->phy_mode = pdata->phy_mode; | 2256 | udc->phy_mode = pdata->phy_mode; |
2257 | 2257 | ||
2258 | udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL); | 2258 | udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL); |
2259 | if (!udc->eps) { | 2259 | if (!udc->eps) |
2260 | ERR("malloc fsl_ep failed\n"); | ||
2261 | return -1; | 2260 | return -1; |
2262 | } | ||
2263 | 2261 | ||
2264 | /* initialized QHs, take care of alignment */ | 2262 | /* initialized QHs, take care of alignment */ |
2265 | size = udc->max_ep * sizeof(struct ep_queue_head); | 2263 | size = udc->max_ep * sizeof(struct ep_queue_head); |
@@ -2342,10 +2340,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev) | |||
2342 | u32 dccparams; | 2340 | u32 dccparams; |
2343 | 2341 | ||
2344 | udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL); | 2342 | udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL); |
2345 | if (udc_controller == NULL) { | 2343 | if (udc_controller == NULL) |
2346 | ERR("malloc udc failed\n"); | ||
2347 | return -ENOMEM; | 2344 | return -ENOMEM; |
2348 | } | ||
2349 | 2345 | ||
2350 | pdata = dev_get_platdata(&pdev->dev); | 2346 | pdata = dev_get_platdata(&pdev->dev); |
2351 | udc_controller->pdata = pdata; | 2347 | udc_controller->pdata = pdata; |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c index 6423f1840ed9..3deb4e938071 100644 --- a/drivers/usb/gadget/fusb300_udc.c +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -1400,17 +1400,13 @@ static int __init fusb300_probe(struct platform_device *pdev) | |||
1400 | 1400 | ||
1401 | /* initialize udc */ | 1401 | /* initialize udc */ |
1402 | fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL); | 1402 | fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL); |
1403 | if (fusb300 == NULL) { | 1403 | if (fusb300 == NULL) |
1404 | pr_err("kzalloc error\n"); | ||
1405 | goto clean_up; | 1404 | goto clean_up; |
1406 | } | ||
1407 | 1405 | ||
1408 | for (i = 0; i < FUSB300_MAX_NUM_EP; i++) { | 1406 | for (i = 0; i < FUSB300_MAX_NUM_EP; i++) { |
1409 | _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL); | 1407 | _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL); |
1410 | if (_ep[i] == NULL) { | 1408 | if (_ep[i] == NULL) |
1411 | pr_err("_ep kzalloc error\n"); | ||
1412 | goto clean_up; | 1409 | goto clean_up; |
1413 | } | ||
1414 | fusb300->ep[i] = _ep[i]; | 1410 | fusb300->ep[i] = _ep[i]; |
1415 | } | 1411 | } |
1416 | 1412 | ||
diff --git a/drivers/usb/gadget/gr_udc.c b/drivers/usb/gadget/gr_udc.c index f984ee75324d..99a37ed03e27 100644 --- a/drivers/usb/gadget/gr_udc.c +++ b/drivers/usb/gadget/gr_udc.c | |||
@@ -143,6 +143,7 @@ static void gr_seq_ep_show(struct seq_file *seq, struct gr_ep *ep) | |||
143 | seq_printf(seq, " wedged = %d\n", ep->wedged); | 143 | seq_printf(seq, " wedged = %d\n", ep->wedged); |
144 | seq_printf(seq, " callback = %d\n", ep->callback); | 144 | seq_printf(seq, " callback = %d\n", ep->callback); |
145 | seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); | 145 | seq_printf(seq, " maxpacket = %d\n", ep->ep.maxpacket); |
146 | seq_printf(seq, " maxpacket_limit = %d\n", ep->ep.maxpacket_limit); | ||
146 | seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); | 147 | seq_printf(seq, " bytes_per_buffer = %d\n", ep->bytes_per_buffer); |
147 | if (mode == 1 || mode == 3) | 148 | if (mode == 1 || mode == 3) |
148 | seq_printf(seq, " nt = %d\n", | 149 | seq_printf(seq, " nt = %d\n", |
@@ -1541,6 +1542,10 @@ static int gr_ep_enable(struct usb_ep *_ep, | |||
1541 | } else if (max == 0) { | 1542 | } else if (max == 0) { |
1542 | dev_err(dev->dev, "Max payload cannot be set to 0\n"); | 1543 | dev_err(dev->dev, "Max payload cannot be set to 0\n"); |
1543 | return -EINVAL; | 1544 | return -EINVAL; |
1545 | } else if (max > ep->ep.maxpacket_limit) { | ||
1546 | dev_err(dev->dev, "Requested max payload %d > limit %d\n", | ||
1547 | max, ep->ep.maxpacket_limit); | ||
1548 | return -EINVAL; | ||
1544 | } | 1549 | } |
1545 | 1550 | ||
1546 | spin_lock(&ep->dev->lock); | 1551 | spin_lock(&ep->dev->lock); |
@@ -1679,7 +1684,7 @@ static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, | |||
1679 | if (ep->is_in) | 1684 | if (ep->is_in) |
1680 | gr_dbgprint_request("EXTERN", ep, req); | 1685 | gr_dbgprint_request("EXTERN", ep, req); |
1681 | 1686 | ||
1682 | ret = gr_queue(ep, req, gfp_flags); | 1687 | ret = gr_queue(ep, req, GFP_ATOMIC); |
1683 | 1688 | ||
1684 | spin_unlock(&ep->dev->lock); | 1689 | spin_unlock(&ep->dev->lock); |
1685 | 1690 | ||
@@ -1985,8 +1990,8 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) | |||
1985 | INIT_LIST_HEAD(&ep->queue); | 1990 | INIT_LIST_HEAD(&ep->queue); |
1986 | 1991 | ||
1987 | if (num == 0) { | 1992 | if (num == 0) { |
1988 | _req = gr_alloc_request(&ep->ep, GFP_KERNEL); | 1993 | _req = gr_alloc_request(&ep->ep, GFP_ATOMIC); |
1989 | buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_KERNEL); | 1994 | buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC); |
1990 | if (!_req || !buf) { | 1995 | if (!_req || !buf) { |
1991 | /* possible _req freed by gr_probe via gr_remove */ | 1996 | /* possible _req freed by gr_probe via gr_remove */ |
1992 | return -ENOMEM; | 1997 | return -ENOMEM; |
@@ -2020,9 +2025,7 @@ static int gr_udc_init(struct gr_udc *dev) | |||
2020 | u32 dmactrl_val; | 2025 | u32 dmactrl_val; |
2021 | int i; | 2026 | int i; |
2022 | int ret = 0; | 2027 | int ret = 0; |
2023 | u32 *bufsizes; | ||
2024 | u32 bufsize; | 2028 | u32 bufsize; |
2025 | int len; | ||
2026 | 2029 | ||
2027 | gr_set_address(dev, 0); | 2030 | gr_set_address(dev, 0); |
2028 | 2031 | ||
@@ -2033,19 +2036,17 @@ static int gr_udc_init(struct gr_udc *dev) | |||
2033 | INIT_LIST_HEAD(&dev->ep_list); | 2036 | INIT_LIST_HEAD(&dev->ep_list); |
2034 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); | 2037 | gr_set_ep0state(dev, GR_EP0_DISCONNECT); |
2035 | 2038 | ||
2036 | bufsizes = (u32 *)of_get_property(np, "epobufsizes", &len); | ||
2037 | len /= sizeof(u32); | ||
2038 | for (i = 0; i < dev->nepo; i++) { | 2039 | for (i = 0; i < dev->nepo; i++) { |
2039 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | 2040 | if (of_property_read_u32_index(np, "epobufsizes", i, &bufsize)) |
2041 | bufsize = 1024; | ||
2040 | ret = gr_ep_init(dev, i, 0, bufsize); | 2042 | ret = gr_ep_init(dev, i, 0, bufsize); |
2041 | if (ret) | 2043 | if (ret) |
2042 | return ret; | 2044 | return ret; |
2043 | } | 2045 | } |
2044 | 2046 | ||
2045 | bufsizes = (u32 *)of_get_property(np, "epibufsizes", &len); | ||
2046 | len /= sizeof(u32); | ||
2047 | for (i = 0; i < dev->nepi; i++) { | 2047 | for (i = 0; i < dev->nepi; i++) { |
2048 | bufsize = (bufsizes && i < len) ? bufsizes[i] : 1024; | 2048 | if (of_property_read_u32_index(np, "epibufsizes", i, &bufsize)) |
2049 | bufsize = 1024; | ||
2049 | ret = gr_ep_init(dev, i, 1, bufsize); | 2050 | ret = gr_ep_init(dev, i, 1, bufsize); |
2050 | if (ret) | 2051 | if (ret) |
2051 | return ret; | 2052 | return ret; |
@@ -2065,9 +2066,9 @@ static int gr_udc_init(struct gr_udc *dev) | |||
2065 | return 0; | 2066 | return 0; |
2066 | } | 2067 | } |
2067 | 2068 | ||
2068 | static int gr_remove(struct platform_device *ofdev) | 2069 | static int gr_remove(struct platform_device *pdev) |
2069 | { | 2070 | { |
2070 | struct gr_udc *dev = dev_get_drvdata(&ofdev->dev); | 2071 | struct gr_udc *dev = platform_get_drvdata(pdev); |
2071 | 2072 | ||
2072 | if (dev->added) | 2073 | if (dev->added) |
2073 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ | 2074 | usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ |
@@ -2077,7 +2078,7 @@ static int gr_remove(struct platform_device *ofdev) | |||
2077 | gr_dfs_delete(dev); | 2078 | gr_dfs_delete(dev); |
2078 | if (dev->desc_pool) | 2079 | if (dev->desc_pool) |
2079 | dma_pool_destroy(dev->desc_pool); | 2080 | dma_pool_destroy(dev->desc_pool); |
2080 | dev_set_drvdata(&ofdev->dev, NULL); | 2081 | platform_set_drvdata(pdev, NULL); |
2081 | 2082 | ||
2082 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); | 2083 | gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); |
2083 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); | 2084 | gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); |
@@ -2090,7 +2091,7 @@ static int gr_request_irq(struct gr_udc *dev, int irq) | |||
2090 | IRQF_SHARED, driver_name, dev); | 2091 | IRQF_SHARED, driver_name, dev); |
2091 | } | 2092 | } |
2092 | 2093 | ||
2093 | static int gr_probe(struct platform_device *ofdev) | 2094 | static int gr_probe(struct platform_device *pdev) |
2094 | { | 2095 | { |
2095 | struct gr_udc *dev; | 2096 | struct gr_udc *dev; |
2096 | struct resource *res; | 2097 | struct resource *res; |
@@ -2098,30 +2099,32 @@ static int gr_probe(struct platform_device *ofdev) | |||
2098 | int retval; | 2099 | int retval; |
2099 | u32 status; | 2100 | u32 status; |
2100 | 2101 | ||
2101 | dev = devm_kzalloc(&ofdev->dev, sizeof(*dev), GFP_KERNEL); | 2102 | dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); |
2102 | if (!dev) | 2103 | if (!dev) |
2103 | return -ENOMEM; | 2104 | return -ENOMEM; |
2104 | dev->dev = &ofdev->dev; | 2105 | dev->dev = &pdev->dev; |
2105 | 2106 | ||
2106 | res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); | 2107 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
2107 | regs = devm_ioremap_resource(dev->dev, res); | 2108 | regs = devm_ioremap_resource(dev->dev, res); |
2108 | if (IS_ERR(regs)) | 2109 | if (IS_ERR(regs)) |
2109 | return PTR_ERR(regs); | 2110 | return PTR_ERR(regs); |
2110 | 2111 | ||
2111 | dev->irq = irq_of_parse_and_map(dev->dev->of_node, 0); | 2112 | dev->irq = platform_get_irq(pdev, 0); |
2112 | if (!dev->irq) { | 2113 | if (dev->irq <= 0) { |
2113 | dev_err(dev->dev, "No irq found\n"); | 2114 | dev_err(dev->dev, "No irq found\n"); |
2114 | return -ENODEV; | 2115 | return -ENODEV; |
2115 | } | 2116 | } |
2116 | 2117 | ||
2117 | /* Some core configurations has separate irqs for IN and OUT events */ | 2118 | /* Some core configurations has separate irqs for IN and OUT events */ |
2118 | dev->irqi = irq_of_parse_and_map(dev->dev->of_node, 1); | 2119 | dev->irqi = platform_get_irq(pdev, 1); |
2119 | if (dev->irqi) { | 2120 | if (dev->irqi > 0) { |
2120 | dev->irqo = irq_of_parse_and_map(dev->dev->of_node, 2); | 2121 | dev->irqo = platform_get_irq(pdev, 2); |
2121 | if (!dev->irqo) { | 2122 | if (dev->irqo <= 0) { |
2122 | dev_err(dev->dev, "Found irqi but not irqo\n"); | 2123 | dev_err(dev->dev, "Found irqi but not irqo\n"); |
2123 | return -ENODEV; | 2124 | return -ENODEV; |
2124 | } | 2125 | } |
2126 | } else { | ||
2127 | dev->irqi = 0; | ||
2125 | } | 2128 | } |
2126 | 2129 | ||
2127 | dev->gadget.name = driver_name; | 2130 | dev->gadget.name = driver_name; |
@@ -2132,7 +2135,7 @@ static int gr_probe(struct platform_device *ofdev) | |||
2132 | spin_lock_init(&dev->lock); | 2135 | spin_lock_init(&dev->lock); |
2133 | dev->regs = regs; | 2136 | dev->regs = regs; |
2134 | 2137 | ||
2135 | dev_set_drvdata(&ofdev->dev, dev); | 2138 | platform_set_drvdata(pdev, dev); |
2136 | 2139 | ||
2137 | /* Determine number of endpoints and data interface mode */ | 2140 | /* Determine number of endpoints and data interface mode */ |
2138 | status = gr_read32(&dev->regs->status); | 2141 | status = gr_read32(&dev->regs->status); |
@@ -2204,7 +2207,7 @@ out: | |||
2204 | spin_unlock(&dev->lock); | 2207 | spin_unlock(&dev->lock); |
2205 | 2208 | ||
2206 | if (retval) | 2209 | if (retval) |
2207 | gr_remove(ofdev); | 2210 | gr_remove(pdev); |
2208 | 2211 | ||
2209 | return retval; | 2212 | return retval; |
2210 | } | 2213 | } |
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c index a925d0cbcd41..ee6c16416c30 100644 --- a/drivers/usb/gadget/inode.c +++ b/drivers/usb/gadget/inode.c | |||
@@ -1494,6 +1494,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1494 | */ | 1494 | */ |
1495 | if (value == 0) { | 1495 | if (value == 0) { |
1496 | INFO (dev, "configuration #%d\n", dev->current_config); | 1496 | INFO (dev, "configuration #%d\n", dev->current_config); |
1497 | usb_gadget_set_state(gadget, USB_STATE_CONFIGURED); | ||
1497 | if (dev->usermode_setup) { | 1498 | if (dev->usermode_setup) { |
1498 | dev->setup_can_stall = 0; | 1499 | dev->setup_can_stall = 0; |
1499 | goto delegate; | 1500 | goto delegate; |
@@ -1501,7 +1502,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1501 | } | 1502 | } |
1502 | break; | 1503 | break; |
1503 | 1504 | ||
1504 | #ifndef CONFIG_USB_GADGET_PXA25X | 1505 | #ifndef CONFIG_USB_PXA25X |
1505 | /* PXA automagically handles this request too */ | 1506 | /* PXA automagically handles this request too */ |
1506 | case USB_REQ_GET_CONFIGURATION: | 1507 | case USB_REQ_GET_CONFIGURATION: |
1507 | if (ctrl->bRequestType != 0x80) | 1508 | if (ctrl->bRequestType != 0x80) |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 8cae01d88597..0d17174b86f8 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -1594,7 +1594,6 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1594 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); | 1594 | m66592 = kzalloc(sizeof(struct m66592), GFP_KERNEL); |
1595 | if (m66592 == NULL) { | 1595 | if (m66592 == NULL) { |
1596 | ret = -ENOMEM; | 1596 | ret = -ENOMEM; |
1597 | pr_err("kzalloc error\n"); | ||
1598 | goto clean_up; | 1597 | goto clean_up; |
1599 | } | 1598 | } |
1600 | 1599 | ||
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c index d2ca59e7b477..16248711c152 100644 --- a/drivers/usb/gadget/mv_u3d_core.c +++ b/drivers/usb/gadget/mv_u3d_core.c | |||
@@ -297,10 +297,8 @@ static struct mv_u3d_trb *mv_u3d_build_trb_one(struct mv_u3d_req *req, | |||
297 | u3d = req->ep->u3d; | 297 | u3d = req->ep->u3d; |
298 | 298 | ||
299 | trb = kzalloc(sizeof(*trb), GFP_ATOMIC); | 299 | trb = kzalloc(sizeof(*trb), GFP_ATOMIC); |
300 | if (!trb) { | 300 | if (!trb) |
301 | dev_err(u3d->dev, "%s, trb alloc fail\n", __func__); | ||
302 | return NULL; | 301 | return NULL; |
303 | } | ||
304 | 302 | ||
305 | /* | 303 | /* |
306 | * Be careful that no _GFP_HIGHMEM is set, | 304 | * Be careful that no _GFP_HIGHMEM is set, |
@@ -446,17 +444,12 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req) | |||
446 | trb_num++; | 444 | trb_num++; |
447 | 445 | ||
448 | trb = kcalloc(trb_num, sizeof(*trb), GFP_ATOMIC); | 446 | trb = kcalloc(trb_num, sizeof(*trb), GFP_ATOMIC); |
449 | if (!trb) { | 447 | if (!trb) |
450 | dev_err(u3d->dev, | ||
451 | "%s, trb alloc fail\n", __func__); | ||
452 | return -ENOMEM; | 448 | return -ENOMEM; |
453 | } | ||
454 | 449 | ||
455 | trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); | 450 | trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); |
456 | if (!trb_hw) { | 451 | if (!trb_hw) { |
457 | kfree(trb); | 452 | kfree(trb); |
458 | dev_err(u3d->dev, | ||
459 | "%s, trb_hw alloc fail\n", __func__); | ||
460 | return -ENOMEM; | 453 | return -ENOMEM; |
461 | } | 454 | } |
462 | 455 | ||
@@ -1811,7 +1804,6 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1811 | 1804 | ||
1812 | u3d = kzalloc(sizeof(*u3d), GFP_KERNEL); | 1805 | u3d = kzalloc(sizeof(*u3d), GFP_KERNEL); |
1813 | if (!u3d) { | 1806 | if (!u3d) { |
1814 | dev_err(&dev->dev, "failed to allocate memory for u3d\n"); | ||
1815 | retval = -ENOMEM; | 1807 | retval = -ENOMEM; |
1816 | goto err_alloc_private; | 1808 | goto err_alloc_private; |
1817 | } | 1809 | } |
@@ -1905,7 +1897,6 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1905 | size = u3d->max_eps * sizeof(struct mv_u3d_ep) * 2; | 1897 | size = u3d->max_eps * sizeof(struct mv_u3d_ep) * 2; |
1906 | u3d->eps = kzalloc(size, GFP_KERNEL); | 1898 | u3d->eps = kzalloc(size, GFP_KERNEL); |
1907 | if (!u3d->eps) { | 1899 | if (!u3d->eps) { |
1908 | dev_err(&dev->dev, "allocate ep memory failed\n"); | ||
1909 | retval = -ENOMEM; | 1900 | retval = -ENOMEM; |
1910 | goto err_alloc_eps; | 1901 | goto err_alloc_eps; |
1911 | } | 1902 | } |
@@ -1913,7 +1904,6 @@ static int mv_u3d_probe(struct platform_device *dev) | |||
1913 | /* initialize ep0 status request structure */ | 1904 | /* initialize ep0 status request structure */ |
1914 | u3d->status_req = kzalloc(sizeof(struct mv_u3d_req) + 8, GFP_KERNEL); | 1905 | u3d->status_req = kzalloc(sizeof(struct mv_u3d_req) + 8, GFP_KERNEL); |
1915 | if (!u3d->status_req) { | 1906 | if (!u3d->status_req) { |
1916 | dev_err(&dev->dev, "allocate status_req memory failed\n"); | ||
1917 | retval = -ENOMEM; | 1907 | retval = -ENOMEM; |
1918 | goto err_alloc_status_req; | 1908 | goto err_alloc_status_req; |
1919 | } | 1909 | } |
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c index 43e5e2f9888f..300b3a71383b 100644 --- a/drivers/usb/gadget/net2280.c +++ b/drivers/usb/gadget/net2280.c | |||
@@ -1972,7 +1972,9 @@ static int net2280_stop(struct usb_gadget *_gadget, | |||
1972 | device_remove_file (&dev->pdev->dev, &dev_attr_function); | 1972 | device_remove_file (&dev->pdev->dev, &dev_attr_function); |
1973 | device_remove_file (&dev->pdev->dev, &dev_attr_queues); | 1973 | device_remove_file (&dev->pdev->dev, &dev_attr_queues); |
1974 | 1974 | ||
1975 | DEBUG (dev, "unregistered driver '%s'\n", driver->driver.name); | 1975 | DEBUG(dev, "unregistered driver '%s'\n", |
1976 | driver ? driver->driver.name : ""); | ||
1977 | |||
1976 | return 0; | 1978 | return 0; |
1977 | } | 1979 | } |
1978 | 1980 | ||
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c index aff0a6718bc6..b698a490cc7d 100644 --- a/drivers/usb/gadget/r8a66597-udc.c +++ b/drivers/usb/gadget/r8a66597-udc.c | |||
@@ -1904,7 +1904,6 @@ static int __init r8a66597_probe(struct platform_device *pdev) | |||
1904 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); | 1904 | r8a66597 = kzalloc(sizeof(struct r8a66597), GFP_KERNEL); |
1905 | if (r8a66597 == NULL) { | 1905 | if (r8a66597 == NULL) { |
1906 | ret = -ENOMEM; | 1906 | ret = -ENOMEM; |
1907 | dev_err(&pdev->dev, "kzalloc error\n"); | ||
1908 | goto clean_up; | 1907 | goto clean_up; |
1909 | } | 1908 | } |
1910 | 1909 | ||
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 7ed452d90f4d..95d2324f6977 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c | |||
@@ -761,7 +761,7 @@ int rndis_signal_connect(int configNr) | |||
761 | return rndis_indicate_status_msg(configNr, | 761 | return rndis_indicate_status_msg(configNr, |
762 | RNDIS_STATUS_MEDIA_CONNECT); | 762 | RNDIS_STATUS_MEDIA_CONNECT); |
763 | } | 763 | } |
764 | EXPORT_SYMBOL(rndis_signal_connect); | 764 | EXPORT_SYMBOL_GPL(rndis_signal_connect); |
765 | 765 | ||
766 | int rndis_signal_disconnect(int configNr) | 766 | int rndis_signal_disconnect(int configNr) |
767 | { | 767 | { |
@@ -770,7 +770,7 @@ int rndis_signal_disconnect(int configNr) | |||
770 | return rndis_indicate_status_msg(configNr, | 770 | return rndis_indicate_status_msg(configNr, |
771 | RNDIS_STATUS_MEDIA_DISCONNECT); | 771 | RNDIS_STATUS_MEDIA_DISCONNECT); |
772 | } | 772 | } |
773 | EXPORT_SYMBOL(rndis_signal_disconnect); | 773 | EXPORT_SYMBOL_GPL(rndis_signal_disconnect); |
774 | 774 | ||
775 | void rndis_uninit(int configNr) | 775 | void rndis_uninit(int configNr) |
776 | { | 776 | { |
@@ -785,13 +785,13 @@ void rndis_uninit(int configNr) | |||
785 | while ((buf = rndis_get_next_response(configNr, &length))) | 785 | while ((buf = rndis_get_next_response(configNr, &length))) |
786 | rndis_free_response(configNr, buf); | 786 | rndis_free_response(configNr, buf); |
787 | } | 787 | } |
788 | EXPORT_SYMBOL(rndis_uninit); | 788 | EXPORT_SYMBOL_GPL(rndis_uninit); |
789 | 789 | ||
790 | void rndis_set_host_mac(int configNr, const u8 *addr) | 790 | void rndis_set_host_mac(int configNr, const u8 *addr) |
791 | { | 791 | { |
792 | rndis_per_dev_params[configNr].host_mac = addr; | 792 | rndis_per_dev_params[configNr].host_mac = addr; |
793 | } | 793 | } |
794 | EXPORT_SYMBOL(rndis_set_host_mac); | 794 | EXPORT_SYMBOL_GPL(rndis_set_host_mac); |
795 | 795 | ||
796 | /* | 796 | /* |
797 | * Message Parser | 797 | * Message Parser |
@@ -874,7 +874,7 @@ int rndis_msg_parser(u8 configNr, u8 *buf) | |||
874 | 874 | ||
875 | return -ENOTSUPP; | 875 | return -ENOTSUPP; |
876 | } | 876 | } |
877 | EXPORT_SYMBOL(rndis_msg_parser); | 877 | EXPORT_SYMBOL_GPL(rndis_msg_parser); |
878 | 878 | ||
879 | int rndis_register(void (*resp_avail)(void *v), void *v) | 879 | int rndis_register(void (*resp_avail)(void *v), void *v) |
880 | { | 880 | { |
@@ -896,7 +896,7 @@ int rndis_register(void (*resp_avail)(void *v), void *v) | |||
896 | 896 | ||
897 | return -ENODEV; | 897 | return -ENODEV; |
898 | } | 898 | } |
899 | EXPORT_SYMBOL(rndis_register); | 899 | EXPORT_SYMBOL_GPL(rndis_register); |
900 | 900 | ||
901 | void rndis_deregister(int configNr) | 901 | void rndis_deregister(int configNr) |
902 | { | 902 | { |
@@ -905,7 +905,7 @@ void rndis_deregister(int configNr) | |||
905 | if (configNr >= RNDIS_MAX_CONFIGS) return; | 905 | if (configNr >= RNDIS_MAX_CONFIGS) return; |
906 | rndis_per_dev_params[configNr].used = 0; | 906 | rndis_per_dev_params[configNr].used = 0; |
907 | } | 907 | } |
908 | EXPORT_SYMBOL(rndis_deregister); | 908 | EXPORT_SYMBOL_GPL(rndis_deregister); |
909 | 909 | ||
910 | int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) | 910 | int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) |
911 | { | 911 | { |
@@ -919,7 +919,7 @@ int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) | |||
919 | 919 | ||
920 | return 0; | 920 | return 0; |
921 | } | 921 | } |
922 | EXPORT_SYMBOL(rndis_set_param_dev); | 922 | EXPORT_SYMBOL_GPL(rndis_set_param_dev); |
923 | 923 | ||
924 | int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) | 924 | int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) |
925 | { | 925 | { |
@@ -932,7 +932,7 @@ int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr) | |||
932 | 932 | ||
933 | return 0; | 933 | return 0; |
934 | } | 934 | } |
935 | EXPORT_SYMBOL(rndis_set_param_vendor); | 935 | EXPORT_SYMBOL_GPL(rndis_set_param_vendor); |
936 | 936 | ||
937 | int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) | 937 | int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) |
938 | { | 938 | { |
@@ -944,7 +944,7 @@ int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed) | |||
944 | 944 | ||
945 | return 0; | 945 | return 0; |
946 | } | 946 | } |
947 | EXPORT_SYMBOL(rndis_set_param_medium); | 947 | EXPORT_SYMBOL_GPL(rndis_set_param_medium); |
948 | 948 | ||
949 | void rndis_add_hdr(struct sk_buff *skb) | 949 | void rndis_add_hdr(struct sk_buff *skb) |
950 | { | 950 | { |
@@ -959,7 +959,7 @@ void rndis_add_hdr(struct sk_buff *skb) | |||
959 | header->DataOffset = cpu_to_le32(36); | 959 | header->DataOffset = cpu_to_le32(36); |
960 | header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); | 960 | header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); |
961 | } | 961 | } |
962 | EXPORT_SYMBOL(rndis_add_hdr); | 962 | EXPORT_SYMBOL_GPL(rndis_add_hdr); |
963 | 963 | ||
964 | void rndis_free_response(int configNr, u8 *buf) | 964 | void rndis_free_response(int configNr, u8 *buf) |
965 | { | 965 | { |
@@ -976,7 +976,7 @@ void rndis_free_response(int configNr, u8 *buf) | |||
976 | } | 976 | } |
977 | } | 977 | } |
978 | } | 978 | } |
979 | EXPORT_SYMBOL(rndis_free_response); | 979 | EXPORT_SYMBOL_GPL(rndis_free_response); |
980 | 980 | ||
981 | u8 *rndis_get_next_response(int configNr, u32 *length) | 981 | u8 *rndis_get_next_response(int configNr, u32 *length) |
982 | { | 982 | { |
@@ -998,7 +998,7 @@ u8 *rndis_get_next_response(int configNr, u32 *length) | |||
998 | 998 | ||
999 | return NULL; | 999 | return NULL; |
1000 | } | 1000 | } |
1001 | EXPORT_SYMBOL(rndis_get_next_response); | 1001 | EXPORT_SYMBOL_GPL(rndis_get_next_response); |
1002 | 1002 | ||
1003 | static rndis_resp_t *rndis_add_response(int configNr, u32 length) | 1003 | static rndis_resp_t *rndis_add_response(int configNr, u32 length) |
1004 | { | 1004 | { |
@@ -1042,7 +1042,7 @@ int rndis_rm_hdr(struct gether *port, | |||
1042 | skb_queue_tail(list, skb); | 1042 | skb_queue_tail(list, skb); |
1043 | return 0; | 1043 | return 0; |
1044 | } | 1044 | } |
1045 | EXPORT_SYMBOL(rndis_rm_hdr); | 1045 | EXPORT_SYMBOL_GPL(rndis_rm_hdr); |
1046 | 1046 | ||
1047 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES | 1047 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
1048 | 1048 | ||
diff --git a/drivers/usb/gadget/s3c-hsotg.h b/drivers/usb/gadget/s3c-hsotg.h deleted file mode 100644 index 85f549ff8c1f..000000000000 --- a/drivers/usb/gadget/s3c-hsotg.h +++ /dev/null | |||
@@ -1,378 +0,0 @@ | |||
1 | /* drivers/usb/gadget/s3c-hsotg.h | ||
2 | * | ||
3 | * Copyright 2008 Openmoko, Inc. | ||
4 | * Copyright 2008 Simtec Electronics | ||
5 | * http://armlinux.simtec.co.uk/ | ||
6 | * Ben Dooks <ben@simtec.co.uk> | ||
7 | * | ||
8 | * USB2.0 Highspeed/OtG Synopsis DWC2 device block registers | ||
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 | #ifndef __REGS_USB_HSOTG_H | ||
16 | #define __REGS_USB_HSOTG_H __FILE__ | ||
17 | |||
18 | #define HSOTG_REG(x) (x) | ||
19 | |||
20 | #define GOTGCTL HSOTG_REG(0x000) | ||
21 | #define GOTGCTL_BSESVLD (1 << 19) | ||
22 | #define GOTGCTL_ASESVLD (1 << 18) | ||
23 | #define GOTGCTL_DBNC_SHORT (1 << 17) | ||
24 | #define GOTGCTL_CONID_B (1 << 16) | ||
25 | #define GOTGCTL_DEVHNPEN (1 << 11) | ||
26 | #define GOTGCTL_HSSETHNPEN (1 << 10) | ||
27 | #define GOTGCTL_HNPREQ (1 << 9) | ||
28 | #define GOTGCTL_HSTNEGSCS (1 << 8) | ||
29 | #define GOTGCTL_SESREQ (1 << 1) | ||
30 | #define GOTGCTL_SESREQSCS (1 << 0) | ||
31 | |||
32 | #define GOTGINT HSOTG_REG(0x004) | ||
33 | #define GOTGINT_DbnceDone (1 << 19) | ||
34 | #define GOTGINT_ADevTOUTChg (1 << 18) | ||
35 | #define GOTGINT_HstNegDet (1 << 17) | ||
36 | #define GOTGINT_HstnegSucStsChng (1 << 9) | ||
37 | #define GOTGINT_SesReqSucStsChng (1 << 8) | ||
38 | #define GOTGINT_SesEndDet (1 << 2) | ||
39 | |||
40 | #define GAHBCFG HSOTG_REG(0x008) | ||
41 | #define GAHBCFG_PTxFEmpLvl (1 << 8) | ||
42 | #define GAHBCFG_NPTxFEmpLvl (1 << 7) | ||
43 | #define GAHBCFG_DMAEn (1 << 5) | ||
44 | #define GAHBCFG_HBstLen_MASK (0xf << 1) | ||
45 | #define GAHBCFG_HBstLen_SHIFT (1) | ||
46 | #define GAHBCFG_HBstLen_Single (0x0 << 1) | ||
47 | #define GAHBCFG_HBstLen_Incr (0x1 << 1) | ||
48 | #define GAHBCFG_HBstLen_Incr4 (0x3 << 1) | ||
49 | #define GAHBCFG_HBstLen_Incr8 (0x5 << 1) | ||
50 | #define GAHBCFG_HBstLen_Incr16 (0x7 << 1) | ||
51 | #define GAHBCFG_GlblIntrEn (1 << 0) | ||
52 | |||
53 | #define GUSBCFG HSOTG_REG(0x00C) | ||
54 | #define GUSBCFG_PHYLPClkSel (1 << 15) | ||
55 | #define GUSBCFG_HNPCap (1 << 9) | ||
56 | #define GUSBCFG_SRPCap (1 << 8) | ||
57 | #define GUSBCFG_PHYIf16 (1 << 3) | ||
58 | #define GUSBCFG_PHYIf8 (0 << 3) | ||
59 | #define GUSBCFG_TOutCal_MASK (0x7 << 0) | ||
60 | #define GUSBCFG_TOutCal_SHIFT (0) | ||
61 | #define GUSBCFG_TOutCal_LIMIT (0x7) | ||
62 | #define GUSBCFG_TOutCal(_x) ((_x) << 0) | ||
63 | |||
64 | #define GRSTCTL HSOTG_REG(0x010) | ||
65 | |||
66 | #define GRSTCTL_AHBIdle (1 << 31) | ||
67 | #define GRSTCTL_DMAReq (1 << 30) | ||
68 | #define GRSTCTL_TxFNum_MASK (0x1f << 6) | ||
69 | #define GRSTCTL_TxFNum_SHIFT (6) | ||
70 | #define GRSTCTL_TxFNum_LIMIT (0x1f) | ||
71 | #define GRSTCTL_TxFNum(_x) ((_x) << 6) | ||
72 | #define GRSTCTL_TxFFlsh (1 << 5) | ||
73 | #define GRSTCTL_RxFFlsh (1 << 4) | ||
74 | #define GRSTCTL_INTknQFlsh (1 << 3) | ||
75 | #define GRSTCTL_FrmCntrRst (1 << 2) | ||
76 | #define GRSTCTL_HSftRst (1 << 1) | ||
77 | #define GRSTCTL_CSftRst (1 << 0) | ||
78 | |||
79 | #define GINTSTS HSOTG_REG(0x014) | ||
80 | #define GINTMSK HSOTG_REG(0x018) | ||
81 | |||
82 | #define GINTSTS_WkUpInt (1 << 31) | ||
83 | #define GINTSTS_SessReqInt (1 << 30) | ||
84 | #define GINTSTS_DisconnInt (1 << 29) | ||
85 | #define GINTSTS_ConIDStsChng (1 << 28) | ||
86 | #define GINTSTS_PTxFEmp (1 << 26) | ||
87 | #define GINTSTS_HChInt (1 << 25) | ||
88 | #define GINTSTS_PrtInt (1 << 24) | ||
89 | #define GINTSTS_FetSusp (1 << 22) | ||
90 | #define GINTSTS_incompIP (1 << 21) | ||
91 | #define GINTSTS_IncomplSOIN (1 << 20) | ||
92 | #define GINTSTS_OEPInt (1 << 19) | ||
93 | #define GINTSTS_IEPInt (1 << 18) | ||
94 | #define GINTSTS_EPMis (1 << 17) | ||
95 | #define GINTSTS_EOPF (1 << 15) | ||
96 | #define GINTSTS_ISOutDrop (1 << 14) | ||
97 | #define GINTSTS_EnumDone (1 << 13) | ||
98 | #define GINTSTS_USBRst (1 << 12) | ||
99 | #define GINTSTS_USBSusp (1 << 11) | ||
100 | #define GINTSTS_ErlySusp (1 << 10) | ||
101 | #define GINTSTS_GOUTNakEff (1 << 7) | ||
102 | #define GINTSTS_GINNakEff (1 << 6) | ||
103 | #define GINTSTS_NPTxFEmp (1 << 5) | ||
104 | #define GINTSTS_RxFLvl (1 << 4) | ||
105 | #define GINTSTS_SOF (1 << 3) | ||
106 | #define GINTSTS_OTGInt (1 << 2) | ||
107 | #define GINTSTS_ModeMis (1 << 1) | ||
108 | #define GINTSTS_CurMod_Host (1 << 0) | ||
109 | |||
110 | #define GRXSTSR HSOTG_REG(0x01C) | ||
111 | #define GRXSTSP HSOTG_REG(0x020) | ||
112 | |||
113 | #define GRXSTS_FN_MASK (0x7f << 25) | ||
114 | #define GRXSTS_FN_SHIFT (25) | ||
115 | |||
116 | #define GRXSTS_PktSts_MASK (0xf << 17) | ||
117 | #define GRXSTS_PktSts_SHIFT (17) | ||
118 | #define GRXSTS_PktSts_GlobalOutNAK (0x1 << 17) | ||
119 | #define GRXSTS_PktSts_OutRX (0x2 << 17) | ||
120 | #define GRXSTS_PktSts_OutDone (0x3 << 17) | ||
121 | #define GRXSTS_PktSts_SetupDone (0x4 << 17) | ||
122 | #define GRXSTS_PktSts_SetupRX (0x6 << 17) | ||
123 | |||
124 | #define GRXSTS_DPID_MASK (0x3 << 15) | ||
125 | #define GRXSTS_DPID_SHIFT (15) | ||
126 | #define GRXSTS_ByteCnt_MASK (0x7ff << 4) | ||
127 | #define GRXSTS_ByteCnt_SHIFT (4) | ||
128 | #define GRXSTS_EPNum_MASK (0xf << 0) | ||
129 | #define GRXSTS_EPNum_SHIFT (0) | ||
130 | |||
131 | #define GRXFSIZ HSOTG_REG(0x024) | ||
132 | |||
133 | #define GNPTXFSIZ HSOTG_REG(0x028) | ||
134 | |||
135 | #define GNPTXFSIZ_NPTxFDep_MASK (0xffff << 16) | ||
136 | #define GNPTXFSIZ_NPTxFDep_SHIFT (16) | ||
137 | #define GNPTXFSIZ_NPTxFDep_LIMIT (0xffff) | ||
138 | #define GNPTXFSIZ_NPTxFDep(_x) ((_x) << 16) | ||
139 | #define GNPTXFSIZ_NPTxFStAddr_MASK (0xffff << 0) | ||
140 | #define GNPTXFSIZ_NPTxFStAddr_SHIFT (0) | ||
141 | #define GNPTXFSIZ_NPTxFStAddr_LIMIT (0xffff) | ||
142 | #define GNPTXFSIZ_NPTxFStAddr(_x) ((_x) << 0) | ||
143 | |||
144 | #define GNPTXSTS HSOTG_REG(0x02C) | ||
145 | |||
146 | #define GNPTXSTS_NPtxQTop_MASK (0x7f << 24) | ||
147 | #define GNPTXSTS_NPtxQTop_SHIFT (24) | ||
148 | |||
149 | #define GNPTXSTS_NPTxQSpcAvail_MASK (0xff << 16) | ||
150 | #define GNPTXSTS_NPTxQSpcAvail_SHIFT (16) | ||
151 | #define GNPTXSTS_NPTxQSpcAvail_GET(_v) (((_v) >> 16) & 0xff) | ||
152 | |||
153 | #define GNPTXSTS_NPTxFSpcAvail_MASK (0xffff << 0) | ||
154 | #define GNPTXSTS_NPTxFSpcAvail_SHIFT (0) | ||
155 | #define GNPTXSTS_NPTxFSpcAvail_GET(_v) (((_v) >> 0) & 0xffff) | ||
156 | |||
157 | |||
158 | #define HPTXFSIZ HSOTG_REG(0x100) | ||
159 | |||
160 | #define DPTXFSIZn(_a) HSOTG_REG(0x104 + (((_a) - 1) * 4)) | ||
161 | |||
162 | #define DPTXFSIZn_DPTxFSize_MASK (0xffff << 16) | ||
163 | #define DPTXFSIZn_DPTxFSize_SHIFT (16) | ||
164 | #define DPTXFSIZn_DPTxFSize_GET(_v) (((_v) >> 16) & 0xffff) | ||
165 | #define DPTXFSIZn_DPTxFSize_LIMIT (0xffff) | ||
166 | #define DPTXFSIZn_DPTxFSize(_x) ((_x) << 16) | ||
167 | |||
168 | #define DPTXFSIZn_DPTxFStAddr_MASK (0xffff << 0) | ||
169 | #define DPTXFSIZn_DPTxFStAddr_SHIFT (0) | ||
170 | |||
171 | /* Device mode registers */ | ||
172 | #define DCFG HSOTG_REG(0x800) | ||
173 | |||
174 | #define DCFG_EPMisCnt_MASK (0x1f << 18) | ||
175 | #define DCFG_EPMisCnt_SHIFT (18) | ||
176 | #define DCFG_EPMisCnt_LIMIT (0x1f) | ||
177 | #define DCFG_EPMisCnt(_x) ((_x) << 18) | ||
178 | |||
179 | #define DCFG_PerFrInt_MASK (0x3 << 11) | ||
180 | #define DCFG_PerFrInt_SHIFT (11) | ||
181 | #define DCFG_PerFrInt_LIMIT (0x3) | ||
182 | #define DCFG_PerFrInt(_x) ((_x) << 11) | ||
183 | |||
184 | #define DCFG_DevAddr_MASK (0x7f << 4) | ||
185 | #define DCFG_DevAddr_SHIFT (4) | ||
186 | #define DCFG_DevAddr_LIMIT (0x7f) | ||
187 | #define DCFG_DevAddr(_x) ((_x) << 4) | ||
188 | |||
189 | #define DCFG_NZStsOUTHShk (1 << 2) | ||
190 | |||
191 | #define DCFG_DevSpd_MASK (0x3 << 0) | ||
192 | #define DCFG_DevSpd_SHIFT (0) | ||
193 | #define DCFG_DevSpd_HS (0x0 << 0) | ||
194 | #define DCFG_DevSpd_FS (0x1 << 0) | ||
195 | #define DCFG_DevSpd_LS (0x2 << 0) | ||
196 | #define DCFG_DevSpd_FS48 (0x3 << 0) | ||
197 | |||
198 | #define DCTL HSOTG_REG(0x804) | ||
199 | |||
200 | #define DCTL_PWROnPrgDone (1 << 11) | ||
201 | #define DCTL_CGOUTNak (1 << 10) | ||
202 | #define DCTL_SGOUTNak (1 << 9) | ||
203 | #define DCTL_CGNPInNAK (1 << 8) | ||
204 | #define DCTL_SGNPInNAK (1 << 7) | ||
205 | #define DCTL_TstCtl_MASK (0x7 << 4) | ||
206 | #define DCTL_TstCtl_SHIFT (4) | ||
207 | #define DCTL_GOUTNakSts (1 << 3) | ||
208 | #define DCTL_GNPINNakSts (1 << 2) | ||
209 | #define DCTL_SftDiscon (1 << 1) | ||
210 | #define DCTL_RmtWkUpSig (1 << 0) | ||
211 | |||
212 | #define DSTS HSOTG_REG(0x808) | ||
213 | |||
214 | #define DSTS_SOFFN_MASK (0x3fff << 8) | ||
215 | #define DSTS_SOFFN_SHIFT (8) | ||
216 | #define DSTS_SOFFN_LIMIT (0x3fff) | ||
217 | #define DSTS_SOFFN(_x) ((_x) << 8) | ||
218 | #define DSTS_ErraticErr (1 << 3) | ||
219 | #define DSTS_EnumSpd_MASK (0x3 << 1) | ||
220 | #define DSTS_EnumSpd_SHIFT (1) | ||
221 | #define DSTS_EnumSpd_HS (0x0 << 1) | ||
222 | #define DSTS_EnumSpd_FS (0x1 << 1) | ||
223 | #define DSTS_EnumSpd_LS (0x2 << 1) | ||
224 | #define DSTS_EnumSpd_FS48 (0x3 << 1) | ||
225 | |||
226 | #define DSTS_SuspSts (1 << 0) | ||
227 | |||
228 | #define DIEPMSK HSOTG_REG(0x810) | ||
229 | |||
230 | #define DIEPMSK_TxFIFOEmpty (1 << 7) | ||
231 | #define DIEPMSK_INEPNakEffMsk (1 << 6) | ||
232 | #define DIEPMSK_INTknEPMisMsk (1 << 5) | ||
233 | #define DIEPMSK_INTknTXFEmpMsk (1 << 4) | ||
234 | #define DIEPMSK_TimeOUTMsk (1 << 3) | ||
235 | #define DIEPMSK_AHBErrMsk (1 << 2) | ||
236 | #define DIEPMSK_EPDisbldMsk (1 << 1) | ||
237 | #define DIEPMSK_XferComplMsk (1 << 0) | ||
238 | |||
239 | #define DOEPMSK HSOTG_REG(0x814) | ||
240 | |||
241 | #define DOEPMSK_Back2BackSetup (1 << 6) | ||
242 | #define DOEPMSK_OUTTknEPdisMsk (1 << 4) | ||
243 | #define DOEPMSK_SetupMsk (1 << 3) | ||
244 | #define DOEPMSK_AHBErrMsk (1 << 2) | ||
245 | #define DOEPMSK_EPDisbldMsk (1 << 1) | ||
246 | #define DOEPMSK_XferComplMsk (1 << 0) | ||
247 | |||
248 | #define DAINT HSOTG_REG(0x818) | ||
249 | #define DAINTMSK HSOTG_REG(0x81C) | ||
250 | |||
251 | #define DAINT_OutEP_SHIFT (16) | ||
252 | #define DAINT_OutEP(x) (1 << ((x) + 16)) | ||
253 | #define DAINT_InEP(x) (1 << (x)) | ||
254 | |||
255 | #define DTKNQR1 HSOTG_REG(0x820) | ||
256 | #define DTKNQR2 HSOTG_REG(0x824) | ||
257 | #define DTKNQR3 HSOTG_REG(0x830) | ||
258 | #define DTKNQR4 HSOTG_REG(0x834) | ||
259 | |||
260 | #define DVBUSDIS HSOTG_REG(0x828) | ||
261 | #define DVBUSPULSE HSOTG_REG(0x82C) | ||
262 | |||
263 | #define DIEPCTL0 HSOTG_REG(0x900) | ||
264 | #define DOEPCTL0 HSOTG_REG(0xB00) | ||
265 | #define DIEPCTL(_a) HSOTG_REG(0x900 + ((_a) * 0x20)) | ||
266 | #define DOEPCTL(_a) HSOTG_REG(0xB00 + ((_a) * 0x20)) | ||
267 | |||
268 | /* EP0 specialness: | ||
269 | * bits[29..28] - reserved (no SetD0PID, SetD1PID) | ||
270 | * bits[25..22] - should always be zero, this isn't a periodic endpoint | ||
271 | * bits[10..0] - MPS setting differenct for EP0 | ||
272 | */ | ||
273 | #define D0EPCTL_MPS_MASK (0x3 << 0) | ||
274 | #define D0EPCTL_MPS_SHIFT (0) | ||
275 | #define D0EPCTL_MPS_64 (0x0 << 0) | ||
276 | #define D0EPCTL_MPS_32 (0x1 << 0) | ||
277 | #define D0EPCTL_MPS_16 (0x2 << 0) | ||
278 | #define D0EPCTL_MPS_8 (0x3 << 0) | ||
279 | |||
280 | #define DxEPCTL_EPEna (1 << 31) | ||
281 | #define DxEPCTL_EPDis (1 << 30) | ||
282 | #define DxEPCTL_SetD1PID (1 << 29) | ||
283 | #define DxEPCTL_SetOddFr (1 << 29) | ||
284 | #define DxEPCTL_SetD0PID (1 << 28) | ||
285 | #define DxEPCTL_SetEvenFr (1 << 28) | ||
286 | #define DxEPCTL_SNAK (1 << 27) | ||
287 | #define DxEPCTL_CNAK (1 << 26) | ||
288 | #define DxEPCTL_TxFNum_MASK (0xf << 22) | ||
289 | #define DxEPCTL_TxFNum_SHIFT (22) | ||
290 | #define DxEPCTL_TxFNum_LIMIT (0xf) | ||
291 | #define DxEPCTL_TxFNum(_x) ((_x) << 22) | ||
292 | |||
293 | #define DxEPCTL_Stall (1 << 21) | ||
294 | #define DxEPCTL_Snp (1 << 20) | ||
295 | #define DxEPCTL_EPType_MASK (0x3 << 18) | ||
296 | #define DxEPCTL_EPType_SHIFT (18) | ||
297 | #define DxEPCTL_EPType_Control (0x0 << 18) | ||
298 | #define DxEPCTL_EPType_Iso (0x1 << 18) | ||
299 | #define DxEPCTL_EPType_Bulk (0x2 << 18) | ||
300 | #define DxEPCTL_EPType_Intterupt (0x3 << 18) | ||
301 | |||
302 | #define DxEPCTL_NAKsts (1 << 17) | ||
303 | #define DxEPCTL_DPID (1 << 16) | ||
304 | #define DxEPCTL_EOFrNum (1 << 16) | ||
305 | #define DxEPCTL_USBActEp (1 << 15) | ||
306 | #define DxEPCTL_NextEp_MASK (0xf << 11) | ||
307 | #define DxEPCTL_NextEp_SHIFT (11) | ||
308 | #define DxEPCTL_NextEp_LIMIT (0xf) | ||
309 | #define DxEPCTL_NextEp(_x) ((_x) << 11) | ||
310 | |||
311 | #define DxEPCTL_MPS_MASK (0x7ff << 0) | ||
312 | #define DxEPCTL_MPS_SHIFT (0) | ||
313 | #define DxEPCTL_MPS_LIMIT (0x7ff) | ||
314 | #define DxEPCTL_MPS(_x) ((_x) << 0) | ||
315 | |||
316 | #define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20)) | ||
317 | #define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20)) | ||
318 | |||
319 | #define DxEPINT_INEPNakEff (1 << 6) | ||
320 | #define DxEPINT_Back2BackSetup (1 << 6) | ||
321 | #define DxEPINT_INTknEPMis (1 << 5) | ||
322 | #define DxEPINT_INTknTXFEmp (1 << 4) | ||
323 | #define DxEPINT_OUTTknEPdis (1 << 4) | ||
324 | #define DxEPINT_Timeout (1 << 3) | ||
325 | #define DxEPINT_Setup (1 << 3) | ||
326 | #define DxEPINT_AHBErr (1 << 2) | ||
327 | #define DxEPINT_EPDisbld (1 << 1) | ||
328 | #define DxEPINT_XferCompl (1 << 0) | ||
329 | |||
330 | #define DIEPTSIZ0 HSOTG_REG(0x910) | ||
331 | |||
332 | #define DIEPTSIZ0_PktCnt_MASK (0x3 << 19) | ||
333 | #define DIEPTSIZ0_PktCnt_SHIFT (19) | ||
334 | #define DIEPTSIZ0_PktCnt_LIMIT (0x3) | ||
335 | #define DIEPTSIZ0_PktCnt(_x) ((_x) << 19) | ||
336 | |||
337 | #define DIEPTSIZ0_XferSize_MASK (0x7f << 0) | ||
338 | #define DIEPTSIZ0_XferSize_SHIFT (0) | ||
339 | #define DIEPTSIZ0_XferSize_LIMIT (0x7f) | ||
340 | #define DIEPTSIZ0_XferSize(_x) ((_x) << 0) | ||
341 | |||
342 | #define DOEPTSIZ0 HSOTG_REG(0xB10) | ||
343 | #define DOEPTSIZ0_SUPCnt_MASK (0x3 << 29) | ||
344 | #define DOEPTSIZ0_SUPCnt_SHIFT (29) | ||
345 | #define DOEPTSIZ0_SUPCnt_LIMIT (0x3) | ||
346 | #define DOEPTSIZ0_SUPCnt(_x) ((_x) << 29) | ||
347 | |||
348 | #define DOEPTSIZ0_PktCnt (1 << 19) | ||
349 | #define DOEPTSIZ0_XferSize_MASK (0x7f << 0) | ||
350 | #define DOEPTSIZ0_XferSize_SHIFT (0) | ||
351 | |||
352 | #define DIEPTSIZ(_a) HSOTG_REG(0x910 + ((_a) * 0x20)) | ||
353 | #define DOEPTSIZ(_a) HSOTG_REG(0xB10 + ((_a) * 0x20)) | ||
354 | |||
355 | #define DxEPTSIZ_MC_MASK (0x3 << 29) | ||
356 | #define DxEPTSIZ_MC_SHIFT (29) | ||
357 | #define DxEPTSIZ_MC_LIMIT (0x3) | ||
358 | #define DxEPTSIZ_MC(_x) ((_x) << 29) | ||
359 | |||
360 | #define DxEPTSIZ_PktCnt_MASK (0x3ff << 19) | ||
361 | #define DxEPTSIZ_PktCnt_SHIFT (19) | ||
362 | #define DxEPTSIZ_PktCnt_GET(_v) (((_v) >> 19) & 0x3ff) | ||
363 | #define DxEPTSIZ_PktCnt_LIMIT (0x3ff) | ||
364 | #define DxEPTSIZ_PktCnt(_x) ((_x) << 19) | ||
365 | |||
366 | #define DxEPTSIZ_XferSize_MASK (0x7ffff << 0) | ||
367 | #define DxEPTSIZ_XferSize_SHIFT (0) | ||
368 | #define DxEPTSIZ_XferSize_GET(_v) (((_v) >> 0) & 0x7ffff) | ||
369 | #define DxEPTSIZ_XferSize_LIMIT (0x7ffff) | ||
370 | #define DxEPTSIZ_XferSize(_x) ((_x) << 0) | ||
371 | |||
372 | #define DIEPDMA(_a) HSOTG_REG(0x914 + ((_a) * 0x20)) | ||
373 | #define DOEPDMA(_a) HSOTG_REG(0xB14 + ((_a) * 0x20)) | ||
374 | #define DTXFSTS(_a) HSOTG_REG(0x918 + ((_a) * 0x20)) | ||
375 | |||
376 | #define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000)) | ||
377 | |||
378 | #endif /* __REGS_USB_HSOTG_H */ | ||
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index dd9678f85c58..7987aa049fab 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -117,7 +117,8 @@ static int dprintk(int level, const char *fmt, ...) | |||
117 | sizeof(printk_buf)-len, fmt, args); | 117 | sizeof(printk_buf)-len, fmt, args); |
118 | va_end(args); | 118 | va_end(args); |
119 | 119 | ||
120 | return pr_debug("%s", printk_buf); | 120 | pr_debug("%s", printk_buf); |
121 | return len; | ||
121 | } | 122 | } |
122 | #else | 123 | #else |
123 | static int dprintk(int level, const char *fmt, ...) | 124 | static int dprintk(int level, const char *fmt, ...) |
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index ec20a1f50c2d..ff205a7bc55c 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -43,7 +43,7 @@ struct usb_interface_descriptor fsg_intf_desc = { | |||
43 | .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ | 43 | .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ |
44 | .iInterface = FSG_STRING_INTERFACE, | 44 | .iInterface = FSG_STRING_INTERFACE, |
45 | }; | 45 | }; |
46 | EXPORT_SYMBOL(fsg_intf_desc); | 46 | EXPORT_SYMBOL_GPL(fsg_intf_desc); |
47 | 47 | ||
48 | /* | 48 | /* |
49 | * Three full-speed endpoint descriptors: bulk-in, bulk-out, and | 49 | * Three full-speed endpoint descriptors: bulk-in, bulk-out, and |
@@ -58,7 +58,7 @@ struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = { | |||
58 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 58 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
59 | /* wMaxPacketSize set by autoconfiguration */ | 59 | /* wMaxPacketSize set by autoconfiguration */ |
60 | }; | 60 | }; |
61 | EXPORT_SYMBOL(fsg_fs_bulk_in_desc); | 61 | EXPORT_SYMBOL_GPL(fsg_fs_bulk_in_desc); |
62 | 62 | ||
63 | struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { | 63 | struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { |
64 | .bLength = USB_DT_ENDPOINT_SIZE, | 64 | .bLength = USB_DT_ENDPOINT_SIZE, |
@@ -68,7 +68,7 @@ struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = { | |||
68 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 68 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
69 | /* wMaxPacketSize set by autoconfiguration */ | 69 | /* wMaxPacketSize set by autoconfiguration */ |
70 | }; | 70 | }; |
71 | EXPORT_SYMBOL(fsg_fs_bulk_out_desc); | 71 | EXPORT_SYMBOL_GPL(fsg_fs_bulk_out_desc); |
72 | 72 | ||
73 | struct usb_descriptor_header *fsg_fs_function[] = { | 73 | struct usb_descriptor_header *fsg_fs_function[] = { |
74 | (struct usb_descriptor_header *) &fsg_intf_desc, | 74 | (struct usb_descriptor_header *) &fsg_intf_desc, |
@@ -76,7 +76,7 @@ struct usb_descriptor_header *fsg_fs_function[] = { | |||
76 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, | 76 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, |
77 | NULL, | 77 | NULL, |
78 | }; | 78 | }; |
79 | EXPORT_SYMBOL(fsg_fs_function); | 79 | EXPORT_SYMBOL_GPL(fsg_fs_function); |
80 | 80 | ||
81 | 81 | ||
82 | /* | 82 | /* |
@@ -95,7 +95,7 @@ struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = { | |||
95 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 95 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
96 | .wMaxPacketSize = cpu_to_le16(512), | 96 | .wMaxPacketSize = cpu_to_le16(512), |
97 | }; | 97 | }; |
98 | EXPORT_SYMBOL(fsg_hs_bulk_in_desc); | 98 | EXPORT_SYMBOL_GPL(fsg_hs_bulk_in_desc); |
99 | 99 | ||
100 | struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { | 100 | struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { |
101 | .bLength = USB_DT_ENDPOINT_SIZE, | 101 | .bLength = USB_DT_ENDPOINT_SIZE, |
@@ -106,7 +106,7 @@ struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = { | |||
106 | .wMaxPacketSize = cpu_to_le16(512), | 106 | .wMaxPacketSize = cpu_to_le16(512), |
107 | .bInterval = 1, /* NAK every 1 uframe */ | 107 | .bInterval = 1, /* NAK every 1 uframe */ |
108 | }; | 108 | }; |
109 | EXPORT_SYMBOL(fsg_hs_bulk_out_desc); | 109 | EXPORT_SYMBOL_GPL(fsg_hs_bulk_out_desc); |
110 | 110 | ||
111 | 111 | ||
112 | struct usb_descriptor_header *fsg_hs_function[] = { | 112 | struct usb_descriptor_header *fsg_hs_function[] = { |
@@ -115,7 +115,7 @@ struct usb_descriptor_header *fsg_hs_function[] = { | |||
115 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, | 115 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, |
116 | NULL, | 116 | NULL, |
117 | }; | 117 | }; |
118 | EXPORT_SYMBOL(fsg_hs_function); | 118 | EXPORT_SYMBOL_GPL(fsg_hs_function); |
119 | 119 | ||
120 | struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { | 120 | struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { |
121 | .bLength = USB_DT_ENDPOINT_SIZE, | 121 | .bLength = USB_DT_ENDPOINT_SIZE, |
@@ -125,7 +125,7 @@ struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = { | |||
125 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 125 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
126 | .wMaxPacketSize = cpu_to_le16(1024), | 126 | .wMaxPacketSize = cpu_to_le16(1024), |
127 | }; | 127 | }; |
128 | EXPORT_SYMBOL(fsg_ss_bulk_in_desc); | 128 | EXPORT_SYMBOL_GPL(fsg_ss_bulk_in_desc); |
129 | 129 | ||
130 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { | 130 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { |
131 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | 131 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), |
@@ -133,7 +133,7 @@ struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { | |||
133 | 133 | ||
134 | /*.bMaxBurst = DYNAMIC, */ | 134 | /*.bMaxBurst = DYNAMIC, */ |
135 | }; | 135 | }; |
136 | EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc); | 136 | EXPORT_SYMBOL_GPL(fsg_ss_bulk_in_comp_desc); |
137 | 137 | ||
138 | struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { | 138 | struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { |
139 | .bLength = USB_DT_ENDPOINT_SIZE, | 139 | .bLength = USB_DT_ENDPOINT_SIZE, |
@@ -143,7 +143,7 @@ struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = { | |||
143 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 143 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
144 | .wMaxPacketSize = cpu_to_le16(1024), | 144 | .wMaxPacketSize = cpu_to_le16(1024), |
145 | }; | 145 | }; |
146 | EXPORT_SYMBOL(fsg_ss_bulk_out_desc); | 146 | EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_desc); |
147 | 147 | ||
148 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { | 148 | struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { |
149 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | 149 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), |
@@ -151,7 +151,7 @@ struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { | |||
151 | 151 | ||
152 | /*.bMaxBurst = DYNAMIC, */ | 152 | /*.bMaxBurst = DYNAMIC, */ |
153 | }; | 153 | }; |
154 | EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc); | 154 | EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_comp_desc); |
155 | 155 | ||
156 | struct usb_descriptor_header *fsg_ss_function[] = { | 156 | struct usb_descriptor_header *fsg_ss_function[] = { |
157 | (struct usb_descriptor_header *) &fsg_intf_desc, | 157 | (struct usb_descriptor_header *) &fsg_intf_desc, |
@@ -161,7 +161,7 @@ struct usb_descriptor_header *fsg_ss_function[] = { | |||
161 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, | 161 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, |
162 | NULL, | 162 | NULL, |
163 | }; | 163 | }; |
164 | EXPORT_SYMBOL(fsg_ss_function); | 164 | EXPORT_SYMBOL_GPL(fsg_ss_function); |
165 | 165 | ||
166 | 166 | ||
167 | /*-------------------------------------------------------------------------*/ | 167 | /*-------------------------------------------------------------------------*/ |
@@ -179,7 +179,7 @@ void fsg_lun_close(struct fsg_lun *curlun) | |||
179 | curlun->filp = NULL; | 179 | curlun->filp = NULL; |
180 | } | 180 | } |
181 | } | 181 | } |
182 | EXPORT_SYMBOL(fsg_lun_close); | 182 | EXPORT_SYMBOL_GPL(fsg_lun_close); |
183 | 183 | ||
184 | int fsg_lun_open(struct fsg_lun *curlun, const char *filename) | 184 | int fsg_lun_open(struct fsg_lun *curlun, const char *filename) |
185 | { | 185 | { |
@@ -278,7 +278,7 @@ out: | |||
278 | fput(filp); | 278 | fput(filp); |
279 | return rc; | 279 | return rc; |
280 | } | 280 | } |
281 | EXPORT_SYMBOL(fsg_lun_open); | 281 | EXPORT_SYMBOL_GPL(fsg_lun_open); |
282 | 282 | ||
283 | 283 | ||
284 | /*-------------------------------------------------------------------------*/ | 284 | /*-------------------------------------------------------------------------*/ |
@@ -295,7 +295,7 @@ int fsg_lun_fsync_sub(struct fsg_lun *curlun) | |||
295 | return 0; | 295 | return 0; |
296 | return vfs_fsync(filp, 1); | 296 | return vfs_fsync(filp, 1); |
297 | } | 297 | } |
298 | EXPORT_SYMBOL(fsg_lun_fsync_sub); | 298 | EXPORT_SYMBOL_GPL(fsg_lun_fsync_sub); |
299 | 299 | ||
300 | void store_cdrom_address(u8 *dest, int msf, u32 addr) | 300 | void store_cdrom_address(u8 *dest, int msf, u32 addr) |
301 | { | 301 | { |
@@ -314,7 +314,7 @@ void store_cdrom_address(u8 *dest, int msf, u32 addr) | |||
314 | put_unaligned_be32(addr, dest); | 314 | put_unaligned_be32(addr, dest); |
315 | } | 315 | } |
316 | } | 316 | } |
317 | EXPORT_SYMBOL(store_cdrom_address); | 317 | EXPORT_SYMBOL_GPL(store_cdrom_address); |
318 | 318 | ||
319 | /*-------------------------------------------------------------------------*/ | 319 | /*-------------------------------------------------------------------------*/ |
320 | 320 | ||
@@ -325,13 +325,13 @@ ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf) | |||
325 | ? curlun->ro | 325 | ? curlun->ro |
326 | : curlun->initially_ro); | 326 | : curlun->initially_ro); |
327 | } | 327 | } |
328 | EXPORT_SYMBOL(fsg_show_ro); | 328 | EXPORT_SYMBOL_GPL(fsg_show_ro); |
329 | 329 | ||
330 | ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf) | 330 | ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf) |
331 | { | 331 | { |
332 | return sprintf(buf, "%u\n", curlun->nofua); | 332 | return sprintf(buf, "%u\n", curlun->nofua); |
333 | } | 333 | } |
334 | EXPORT_SYMBOL(fsg_show_nofua); | 334 | EXPORT_SYMBOL_GPL(fsg_show_nofua); |
335 | 335 | ||
336 | ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | 336 | ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, |
337 | char *buf) | 337 | char *buf) |
@@ -357,19 +357,19 @@ ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | |||
357 | up_read(filesem); | 357 | up_read(filesem); |
358 | return rc; | 358 | return rc; |
359 | } | 359 | } |
360 | EXPORT_SYMBOL(fsg_show_file); | 360 | EXPORT_SYMBOL_GPL(fsg_show_file); |
361 | 361 | ||
362 | ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf) | 362 | ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf) |
363 | { | 363 | { |
364 | return sprintf(buf, "%u\n", curlun->cdrom); | 364 | return sprintf(buf, "%u\n", curlun->cdrom); |
365 | } | 365 | } |
366 | EXPORT_SYMBOL(fsg_show_cdrom); | 366 | EXPORT_SYMBOL_GPL(fsg_show_cdrom); |
367 | 367 | ||
368 | ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) | 368 | ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf) |
369 | { | 369 | { |
370 | return sprintf(buf, "%u\n", curlun->removable); | 370 | return sprintf(buf, "%u\n", curlun->removable); |
371 | } | 371 | } |
372 | EXPORT_SYMBOL(fsg_show_removable); | 372 | EXPORT_SYMBOL_GPL(fsg_show_removable); |
373 | 373 | ||
374 | /* | 374 | /* |
375 | * The caller must hold fsg->filesem for reading when calling this function. | 375 | * The caller must hold fsg->filesem for reading when calling this function. |
@@ -410,7 +410,7 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, | |||
410 | 410 | ||
411 | return rc; | 411 | return rc; |
412 | } | 412 | } |
413 | EXPORT_SYMBOL(fsg_store_ro); | 413 | EXPORT_SYMBOL_GPL(fsg_store_ro); |
414 | 414 | ||
415 | ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) | 415 | ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) |
416 | { | 416 | { |
@@ -429,7 +429,7 @@ ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) | |||
429 | 429 | ||
430 | return count; | 430 | return count; |
431 | } | 431 | } |
432 | EXPORT_SYMBOL(fsg_store_nofua); | 432 | EXPORT_SYMBOL_GPL(fsg_store_nofua); |
433 | 433 | ||
434 | ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | 434 | ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, |
435 | const char *buf, size_t count) | 435 | const char *buf, size_t count) |
@@ -460,7 +460,7 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, | |||
460 | up_write(filesem); | 460 | up_write(filesem); |
461 | return (rc < 0 ? rc : count); | 461 | return (rc < 0 ? rc : count); |
462 | } | 462 | } |
463 | EXPORT_SYMBOL(fsg_store_file); | 463 | EXPORT_SYMBOL_GPL(fsg_store_file); |
464 | 464 | ||
465 | ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, | 465 | ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, |
466 | const char *buf, size_t count) | 466 | const char *buf, size_t count) |
@@ -483,7 +483,7 @@ ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, | |||
483 | 483 | ||
484 | return ret; | 484 | return ret; |
485 | } | 485 | } |
486 | EXPORT_SYMBOL(fsg_store_cdrom); | 486 | EXPORT_SYMBOL_GPL(fsg_store_cdrom); |
487 | 487 | ||
488 | ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, | 488 | ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, |
489 | size_t count) | 489 | size_t count) |
@@ -499,6 +499,6 @@ ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf, | |||
499 | 499 | ||
500 | return count; | 500 | return count; |
501 | } | 501 | } |
502 | EXPORT_SYMBOL(fsg_store_removable); | 502 | EXPORT_SYMBOL_GPL(fsg_store_removable); |
503 | 503 | ||
504 | MODULE_LICENSE("GPL"); | 504 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c index f058c0368d61..6cdb7a534f23 100644 --- a/drivers/usb/gadget/tcm_usb_gadget.c +++ b/drivers/usb/gadget/tcm_usb_gadget.c | |||
@@ -1383,10 +1383,8 @@ static struct se_node_acl *usbg_alloc_fabric_acl(struct se_portal_group *se_tpg) | |||
1383 | struct usbg_nacl *nacl; | 1383 | struct usbg_nacl *nacl; |
1384 | 1384 | ||
1385 | nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL); | 1385 | nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL); |
1386 | if (!nacl) { | 1386 | if (!nacl) |
1387 | printk(KERN_ERR "Unable to allocate struct usbg_nacl\n"); | ||
1388 | return NULL; | 1387 | return NULL; |
1389 | } | ||
1390 | 1388 | ||
1391 | return &nacl->se_node_acl; | 1389 | return &nacl->se_node_acl; |
1392 | } | 1390 | } |
@@ -1561,10 +1559,8 @@ static struct se_portal_group *usbg_make_tpg( | |||
1561 | } | 1559 | } |
1562 | 1560 | ||
1563 | tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); | 1561 | tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); |
1564 | if (!tpg) { | 1562 | if (!tpg) |
1565 | printk(KERN_ERR "Unable to allocate struct usbg_tpg"); | ||
1566 | return ERR_PTR(-ENOMEM); | 1563 | return ERR_PTR(-ENOMEM); |
1567 | } | ||
1568 | mutex_init(&tpg->tpg_mutex); | 1564 | mutex_init(&tpg->tpg_mutex); |
1569 | atomic_set(&tpg->tpg_port_count, 0); | 1565 | atomic_set(&tpg->tpg_port_count, 0); |
1570 | tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); | 1566 | tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); |
@@ -1613,10 +1609,8 @@ static struct se_wwn *usbg_make_tport( | |||
1613 | return ERR_PTR(-EINVAL); | 1609 | return ERR_PTR(-EINVAL); |
1614 | 1610 | ||
1615 | tport = kzalloc(sizeof(struct usbg_tport), GFP_KERNEL); | 1611 | tport = kzalloc(sizeof(struct usbg_tport), GFP_KERNEL); |
1616 | if (!(tport)) { | 1612 | if (!(tport)) |
1617 | printk(KERN_ERR "Unable to allocate struct usbg_tport"); | ||
1618 | return ERR_PTR(-ENOMEM); | 1613 | return ERR_PTR(-ENOMEM); |
1619 | } | ||
1620 | tport->tport_wwpn = wwpn; | 1614 | tport->tport_wwpn = wwpn; |
1621 | snprintf(tport->tport_name, sizeof(tport->tport_name), "%s", wnn_name); | 1615 | snprintf(tport->tport_name, sizeof(tport->tport_name), "%s", wnn_name); |
1622 | return &tport->tport_wwn; | 1616 | return &tport->tport_wwn; |
@@ -1727,10 +1721,8 @@ static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name) | |||
1727 | 1721 | ||
1728 | ret = -ENOMEM; | 1722 | ret = -ENOMEM; |
1729 | tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); | 1723 | tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); |
1730 | if (!tv_nexus) { | 1724 | if (!tv_nexus) |
1731 | pr_err("Unable to allocate struct tcm_vhost_nexus\n"); | ||
1732 | goto err_unlock; | 1725 | goto err_unlock; |
1733 | } | ||
1734 | tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL); | 1726 | tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL); |
1735 | if (IS_ERR(tv_nexus->tvn_se_sess)) | 1727 | if (IS_ERR(tv_nexus->tvn_se_sess)) |
1736 | goto err_free; | 1728 | goto err_free; |
@@ -1851,7 +1843,7 @@ static int usbg_port_link(struct se_portal_group *se_tpg, struct se_lun *lun) | |||
1851 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | 1843 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); |
1852 | 1844 | ||
1853 | atomic_inc(&tpg->tpg_port_count); | 1845 | atomic_inc(&tpg->tpg_port_count); |
1854 | smp_mb__after_atomic_inc(); | 1846 | smp_mb__after_atomic(); |
1855 | return 0; | 1847 | return 0; |
1856 | } | 1848 | } |
1857 | 1849 | ||
@@ -1861,7 +1853,7 @@ static void usbg_port_unlink(struct se_portal_group *se_tpg, | |||
1861 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); | 1853 | struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); |
1862 | 1854 | ||
1863 | atomic_dec(&tpg->tpg_port_count); | 1855 | atomic_dec(&tpg->tpg_port_count); |
1864 | smp_mb__after_atomic_dec(); | 1856 | smp_mb__after_atomic(); |
1865 | } | 1857 | } |
1866 | 1858 | ||
1867 | static int usbg_check_stop_free(struct se_cmd *se_cmd) | 1859 | static int usbg_check_stop_free(struct se_cmd *se_cmd) |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index b7d4f82872b7..fe0880d0873e 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -818,7 +818,7 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, | |||
818 | 818 | ||
819 | return dev; | 819 | return dev; |
820 | } | 820 | } |
821 | EXPORT_SYMBOL(gether_setup_name); | 821 | EXPORT_SYMBOL_GPL(gether_setup_name); |
822 | 822 | ||
823 | struct net_device *gether_setup_name_default(const char *netname) | 823 | struct net_device *gether_setup_name_default(const char *netname) |
824 | { | 824 | { |
@@ -855,7 +855,7 @@ struct net_device *gether_setup_name_default(const char *netname) | |||
855 | 855 | ||
856 | return net; | 856 | return net; |
857 | } | 857 | } |
858 | EXPORT_SYMBOL(gether_setup_name_default); | 858 | EXPORT_SYMBOL_GPL(gether_setup_name_default); |
859 | 859 | ||
860 | int gether_register_netdev(struct net_device *net) | 860 | int gether_register_netdev(struct net_device *net) |
861 | { | 861 | { |
@@ -893,7 +893,7 @@ int gether_register_netdev(struct net_device *net) | |||
893 | 893 | ||
894 | return status; | 894 | return status; |
895 | } | 895 | } |
896 | EXPORT_SYMBOL(gether_register_netdev); | 896 | EXPORT_SYMBOL_GPL(gether_register_netdev); |
897 | 897 | ||
898 | void gether_set_gadget(struct net_device *net, struct usb_gadget *g) | 898 | void gether_set_gadget(struct net_device *net, struct usb_gadget *g) |
899 | { | 899 | { |
@@ -903,7 +903,7 @@ void gether_set_gadget(struct net_device *net, struct usb_gadget *g) | |||
903 | dev->gadget = g; | 903 | dev->gadget = g; |
904 | SET_NETDEV_DEV(net, &g->dev); | 904 | SET_NETDEV_DEV(net, &g->dev); |
905 | } | 905 | } |
906 | EXPORT_SYMBOL(gether_set_gadget); | 906 | EXPORT_SYMBOL_GPL(gether_set_gadget); |
907 | 907 | ||
908 | int gether_set_dev_addr(struct net_device *net, const char *dev_addr) | 908 | int gether_set_dev_addr(struct net_device *net, const char *dev_addr) |
909 | { | 909 | { |
@@ -916,7 +916,7 @@ int gether_set_dev_addr(struct net_device *net, const char *dev_addr) | |||
916 | memcpy(dev->dev_mac, new_addr, ETH_ALEN); | 916 | memcpy(dev->dev_mac, new_addr, ETH_ALEN); |
917 | return 0; | 917 | return 0; |
918 | } | 918 | } |
919 | EXPORT_SYMBOL(gether_set_dev_addr); | 919 | EXPORT_SYMBOL_GPL(gether_set_dev_addr); |
920 | 920 | ||
921 | int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len) | 921 | int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len) |
922 | { | 922 | { |
@@ -925,7 +925,7 @@ int gether_get_dev_addr(struct net_device *net, char *dev_addr, int len) | |||
925 | dev = netdev_priv(net); | 925 | dev = netdev_priv(net); |
926 | return get_ether_addr_str(dev->dev_mac, dev_addr, len); | 926 | return get_ether_addr_str(dev->dev_mac, dev_addr, len); |
927 | } | 927 | } |
928 | EXPORT_SYMBOL(gether_get_dev_addr); | 928 | EXPORT_SYMBOL_GPL(gether_get_dev_addr); |
929 | 929 | ||
930 | int gether_set_host_addr(struct net_device *net, const char *host_addr) | 930 | int gether_set_host_addr(struct net_device *net, const char *host_addr) |
931 | { | 931 | { |
@@ -938,7 +938,7 @@ int gether_set_host_addr(struct net_device *net, const char *host_addr) | |||
938 | memcpy(dev->host_mac, new_addr, ETH_ALEN); | 938 | memcpy(dev->host_mac, new_addr, ETH_ALEN); |
939 | return 0; | 939 | return 0; |
940 | } | 940 | } |
941 | EXPORT_SYMBOL(gether_set_host_addr); | 941 | EXPORT_SYMBOL_GPL(gether_set_host_addr); |
942 | 942 | ||
943 | int gether_get_host_addr(struct net_device *net, char *host_addr, int len) | 943 | int gether_get_host_addr(struct net_device *net, char *host_addr, int len) |
944 | { | 944 | { |
@@ -947,7 +947,7 @@ int gether_get_host_addr(struct net_device *net, char *host_addr, int len) | |||
947 | dev = netdev_priv(net); | 947 | dev = netdev_priv(net); |
948 | return get_ether_addr_str(dev->host_mac, host_addr, len); | 948 | return get_ether_addr_str(dev->host_mac, host_addr, len); |
949 | } | 949 | } |
950 | EXPORT_SYMBOL(gether_get_host_addr); | 950 | EXPORT_SYMBOL_GPL(gether_get_host_addr); |
951 | 951 | ||
952 | int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) | 952 | int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) |
953 | { | 953 | { |
@@ -961,7 +961,7 @@ int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) | |||
961 | 961 | ||
962 | return strlen(host_addr); | 962 | return strlen(host_addr); |
963 | } | 963 | } |
964 | EXPORT_SYMBOL(gether_get_host_addr_cdc); | 964 | EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc); |
965 | 965 | ||
966 | void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]) | 966 | void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]) |
967 | { | 967 | { |
@@ -970,7 +970,7 @@ void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]) | |||
970 | dev = netdev_priv(net); | 970 | dev = netdev_priv(net); |
971 | memcpy(host_mac, dev->host_mac, ETH_ALEN); | 971 | memcpy(host_mac, dev->host_mac, ETH_ALEN); |
972 | } | 972 | } |
973 | EXPORT_SYMBOL(gether_get_host_addr_u8); | 973 | EXPORT_SYMBOL_GPL(gether_get_host_addr_u8); |
974 | 974 | ||
975 | void gether_set_qmult(struct net_device *net, unsigned qmult) | 975 | void gether_set_qmult(struct net_device *net, unsigned qmult) |
976 | { | 976 | { |
@@ -979,7 +979,7 @@ void gether_set_qmult(struct net_device *net, unsigned qmult) | |||
979 | dev = netdev_priv(net); | 979 | dev = netdev_priv(net); |
980 | dev->qmult = qmult; | 980 | dev->qmult = qmult; |
981 | } | 981 | } |
982 | EXPORT_SYMBOL(gether_set_qmult); | 982 | EXPORT_SYMBOL_GPL(gether_set_qmult); |
983 | 983 | ||
984 | unsigned gether_get_qmult(struct net_device *net) | 984 | unsigned gether_get_qmult(struct net_device *net) |
985 | { | 985 | { |
@@ -988,7 +988,7 @@ unsigned gether_get_qmult(struct net_device *net) | |||
988 | dev = netdev_priv(net); | 988 | dev = netdev_priv(net); |
989 | return dev->qmult; | 989 | return dev->qmult; |
990 | } | 990 | } |
991 | EXPORT_SYMBOL(gether_get_qmult); | 991 | EXPORT_SYMBOL_GPL(gether_get_qmult); |
992 | 992 | ||
993 | int gether_get_ifname(struct net_device *net, char *name, int len) | 993 | int gether_get_ifname(struct net_device *net, char *name, int len) |
994 | { | 994 | { |
@@ -997,7 +997,7 @@ int gether_get_ifname(struct net_device *net, char *name, int len) | |||
997 | rtnl_unlock(); | 997 | rtnl_unlock(); |
998 | return strlen(name); | 998 | return strlen(name); |
999 | } | 999 | } |
1000 | EXPORT_SYMBOL(gether_get_ifname); | 1000 | EXPORT_SYMBOL_GPL(gether_get_ifname); |
1001 | 1001 | ||
1002 | /** | 1002 | /** |
1003 | * gether_cleanup - remove Ethernet-over-USB device | 1003 | * gether_cleanup - remove Ethernet-over-USB device |
@@ -1014,7 +1014,7 @@ void gether_cleanup(struct eth_dev *dev) | |||
1014 | flush_work(&dev->work); | 1014 | flush_work(&dev->work); |
1015 | free_netdev(dev->net); | 1015 | free_netdev(dev->net); |
1016 | } | 1016 | } |
1017 | EXPORT_SYMBOL(gether_cleanup); | 1017 | EXPORT_SYMBOL_GPL(gether_cleanup); |
1018 | 1018 | ||
1019 | /** | 1019 | /** |
1020 | * gether_connect - notify network layer that USB link is active | 1020 | * gether_connect - notify network layer that USB link is active |
@@ -1095,7 +1095,7 @@ fail0: | |||
1095 | return ERR_PTR(result); | 1095 | return ERR_PTR(result); |
1096 | return dev->net; | 1096 | return dev->net; |
1097 | } | 1097 | } |
1098 | EXPORT_SYMBOL(gether_connect); | 1098 | EXPORT_SYMBOL_GPL(gether_connect); |
1099 | 1099 | ||
1100 | /** | 1100 | /** |
1101 | * gether_disconnect - notify network layer that USB link is inactive | 1101 | * gether_disconnect - notify network layer that USB link is inactive |
@@ -1166,7 +1166,7 @@ void gether_disconnect(struct gether *link) | |||
1166 | dev->port_usb = NULL; | 1166 | dev->port_usb = NULL; |
1167 | spin_unlock(&dev->lock); | 1167 | spin_unlock(&dev->lock); |
1168 | } | 1168 | } |
1169 | EXPORT_SYMBOL(gether_disconnect); | 1169 | EXPORT_SYMBOL_GPL(gether_disconnect); |
1170 | 1170 | ||
1171 | MODULE_LICENSE("GPL"); | 1171 | MODULE_LICENSE("GPL"); |
1172 | MODULE_AUTHOR("David Brownell"); | 1172 | MODULE_AUTHOR("David Brownell"); |
diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c index 63b6642c162b..c6276f0268ae 100644 --- a/drivers/usb/gadget/u_f.c +++ b/drivers/usb/gadget/u_f.c | |||
@@ -29,4 +29,4 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len) | |||
29 | } | 29 | } |
30 | return req; | 30 | return req; |
31 | } | 31 | } |
32 | EXPORT_SYMBOL(alloc_ep_req); | 32 | EXPORT_SYMBOL_GPL(alloc_ep_req); |
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h index 71034c061fca..1d5f0eb68552 100644 --- a/drivers/usb/gadget/u_f.h +++ b/drivers/usb/gadget/u_f.h | |||
@@ -16,6 +16,32 @@ | |||
16 | #ifndef __U_F_H__ | 16 | #ifndef __U_F_H__ |
17 | #define __U_F_H__ | 17 | #define __U_F_H__ |
18 | 18 | ||
19 | /* Variable Length Array Macros **********************************************/ | ||
20 | #define vla_group(groupname) size_t groupname##__next = 0 | ||
21 | #define vla_group_size(groupname) groupname##__next | ||
22 | |||
23 | #define vla_item(groupname, type, name, n) \ | ||
24 | size_t groupname##_##name##__offset = ({ \ | ||
25 | size_t align_mask = __alignof__(type) - 1; \ | ||
26 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | ||
27 | size_t size = (n) * sizeof(type); \ | ||
28 | groupname##__next = offset + size; \ | ||
29 | offset; \ | ||
30 | }) | ||
31 | |||
32 | #define vla_item_with_sz(groupname, type, name, n) \ | ||
33 | size_t groupname##_##name##__sz = (n) * sizeof(type); \ | ||
34 | size_t groupname##_##name##__offset = ({ \ | ||
35 | size_t align_mask = __alignof__(type) - 1; \ | ||
36 | size_t offset = (groupname##__next + align_mask) & ~align_mask;\ | ||
37 | size_t size = groupname##_##name##__sz; \ | ||
38 | groupname##__next = offset + size; \ | ||
39 | offset; \ | ||
40 | }) | ||
41 | |||
42 | #define vla_ptr(ptr, groupname, name) \ | ||
43 | ((void *) ((char *)ptr + groupname##_##name##__offset)) | ||
44 | |||
19 | struct usb_ep; | 45 | struct usb_ep; |
20 | struct usb_request; | 46 | struct usb_request; |
21 | 47 | ||
diff --git a/drivers/usb/gadget/u_os_desc.h b/drivers/usb/gadget/u_os_desc.h new file mode 100644 index 000000000000..ea5cf8c2da28 --- /dev/null +++ b/drivers/usb/gadget/u_os_desc.h | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | * u_os_desc.h | ||
3 | * | ||
4 | * Utility definitions for "OS Descriptors" support | ||
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_OS_DESC_H__ | ||
17 | #define __U_OS_DESC_H__ | ||
18 | |||
19 | #include <asm/unaligned.h> | ||
20 | #include <linux/nls.h> | ||
21 | |||
22 | #define USB_EXT_PROP_DW_SIZE 0 | ||
23 | #define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4 | ||
24 | #define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8 | ||
25 | #define USB_EXT_PROP_B_PROPERTY_NAME 10 | ||
26 | #define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10 | ||
27 | #define USB_EXT_PROP_B_PROPERTY_DATA 14 | ||
28 | |||
29 | #define USB_EXT_PROP_RESERVED 0 | ||
30 | #define USB_EXT_PROP_UNICODE 1 | ||
31 | #define USB_EXT_PROP_UNICODE_ENV 2 | ||
32 | #define USB_EXT_PROP_BINARY 3 | ||
33 | #define USB_EXT_PROP_LE32 4 | ||
34 | #define USB_EXT_PROP_BE32 5 | ||
35 | #define USB_EXT_PROP_UNICODE_LINK 6 | ||
36 | #define USB_EXT_PROP_UNICODE_MULTI 7 | ||
37 | |||
38 | static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) | ||
39 | { | ||
40 | put_unaligned_le32(dw_size, &buf[USB_EXT_PROP_DW_SIZE]); | ||
41 | } | ||
42 | |||
43 | static inline void usb_ext_prop_put_type(u8 *buf, int type) | ||
44 | { | ||
45 | put_unaligned_le32(type, &buf[USB_EXT_PROP_DW_PROPERTY_DATA_TYPE]); | ||
46 | } | ||
47 | |||
48 | static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) | ||
49 | { | ||
50 | int result; | ||
51 | |||
52 | put_unaligned_le16(pnl, &buf[USB_EXT_PROP_W_PROPERTY_NAME_LENGTH]); | ||
53 | result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN, | ||
54 | (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_NAME], pnl - 2); | ||
55 | if (result < 0) | ||
56 | return result; | ||
57 | |||
58 | put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl]); | ||
59 | |||
60 | return pnl; | ||
61 | } | ||
62 | |||
63 | static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, | ||
64 | int data_len) | ||
65 | { | ||
66 | put_unaligned_le32(data_len, | ||
67 | &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); | ||
68 | memcpy(&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], data, data_len); | ||
69 | } | ||
70 | |||
71 | static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, | ||
72 | int data_len) | ||
73 | { | ||
74 | int result; | ||
75 | put_unaligned_le32(data_len, | ||
76 | &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); | ||
77 | |||
78 | result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN, | ||
79 | (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], | ||
80 | data_len - 2); | ||
81 | if (result < 0) | ||
82 | return result; | ||
83 | |||
84 | put_unaligned_le16(0, | ||
85 | &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len]); | ||
86 | |||
87 | return data_len; | ||
88 | } | ||
89 | |||
90 | #endif /* __U_OS_DESC_H__ */ | ||
diff --git a/drivers/usb/gadget/u_rndis.h b/drivers/usb/gadget/u_rndis.h index 7291b15c9dce..e902aa42a297 100644 --- a/drivers/usb/gadget/u_rndis.h +++ b/drivers/usb/gadget/u_rndis.h | |||
@@ -26,6 +26,9 @@ struct f_rndis_opts { | |||
26 | bool bound; | 26 | bool bound; |
27 | bool borrowed_net; | 27 | bool borrowed_net; |
28 | 28 | ||
29 | struct usb_os_desc rndis_os_desc; | ||
30 | char rndis_ext_compat_id[16]; | ||
31 | |||
29 | /* | 32 | /* |
30 | * Read/write access to configfs attributes is handled by configfs. | 33 | * Read/write access to configfs attributes is handled by configfs. |
31 | * | 34 | * |
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c index 27768a7d986a..b0d98172bc07 100644 --- a/drivers/usb/gadget/udc-core.c +++ b/drivers/usb/gadget/udc-core.c | |||
@@ -428,6 +428,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
428 | list_for_each_entry(udc, &udc_list, list) | 428 | list_for_each_entry(udc, &udc_list, list) |
429 | if (udc->driver == driver) { | 429 | if (udc->driver == driver) { |
430 | usb_gadget_remove_driver(udc); | 430 | usb_gadget_remove_driver(udc); |
431 | usb_gadget_set_state(udc->gadget, | ||
432 | USB_STATE_NOTATTACHED); | ||
431 | ret = 0; | 433 | ret = 0; |
432 | break; | 434 | break; |
433 | } | 435 | } |
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c index 0bb5d50075de..1c29bc954db9 100644 --- a/drivers/usb/gadget/uvc_queue.c +++ b/drivers/usb/gadget/uvc_queue.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/vmalloc.h> | 20 | #include <linux/vmalloc.h> |
21 | #include <linux/wait.h> | 21 | #include <linux/wait.h> |
22 | 22 | ||
23 | #include <media/v4l2-common.h> | ||
23 | #include <media/videobuf2-vmalloc.h> | 24 | #include <media/videobuf2-vmalloc.h> |
24 | 25 | ||
25 | #include "uvc.h" | 26 | #include "uvc.h" |
@@ -136,6 +137,8 @@ static int uvc_queue_init(struct uvc_video_queue *queue, | |||
136 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); | 137 | queue->queue.buf_struct_size = sizeof(struct uvc_buffer); |
137 | queue->queue.ops = &uvc_queue_qops; | 138 | queue->queue.ops = &uvc_queue_qops; |
138 | queue->queue.mem_ops = &vb2_vmalloc_memops; | 139 | queue->queue.mem_ops = &vb2_vmalloc_memops; |
140 | queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC | ||
141 | | V4L2_BUF_FLAG_TSTAMP_SRC_EOF; | ||
139 | ret = vb2_queue_init(&queue->queue); | 142 | ret = vb2_queue_init(&queue->queue); |
140 | if (ret) | 143 | if (ret) |
141 | return ret; | 144 | return ret; |
@@ -379,14 +382,9 @@ static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |||
379 | else | 382 | else |
380 | nextbuf = NULL; | 383 | nextbuf = NULL; |
381 | 384 | ||
382 | /* | 385 | buf->buf.v4l2_buf.field = V4L2_FIELD_NONE; |
383 | * FIXME: with videobuf2, the sequence number or timestamp fields | ||
384 | * are valid only for video capture devices and the UVC gadget usually | ||
385 | * is a video output device. Keeping these until the specs are clear on | ||
386 | * this aspect. | ||
387 | */ | ||
388 | buf->buf.v4l2_buf.sequence = queue->sequence++; | 386 | buf->buf.v4l2_buf.sequence = queue->sequence++; |
389 | do_gettimeofday(&buf->buf.v4l2_buf.timestamp); | 387 | v4l2_get_timestamp(&buf->buf.v4l2_buf.timestamp); |
390 | 388 | ||
391 | vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); | 389 | vb2_set_plane_payload(&buf->buf, 0, buf->bytesused); |
392 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE); | 390 | vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE); |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 3d9e54062d62..61b7817bd66b 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -29,6 +29,14 @@ if USB_XHCI_HCD | |||
29 | config USB_XHCI_PLATFORM | 29 | config USB_XHCI_PLATFORM |
30 | tristate | 30 | tristate |
31 | 31 | ||
32 | config USB_XHCI_MVEBU | ||
33 | tristate "xHCI support for Marvell Armada 375/38x" | ||
34 | select USB_XHCI_PLATFORM | ||
35 | depends on ARCH_MVEBU || COMPILE_TEST | ||
36 | ---help--- | ||
37 | Say 'Y' to enable the support for the xHCI host controller | ||
38 | found in Marvell Armada 375/38x ARM SOCs. | ||
39 | |||
32 | endif # USB_XHCI_HCD | 40 | endif # USB_XHCI_HCD |
33 | 41 | ||
34 | config USB_EHCI_HCD | 42 | config USB_EHCI_HCD |
@@ -170,7 +178,6 @@ config USB_EHCI_MSM | |||
170 | tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller" | 178 | tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller" |
171 | depends on ARCH_MSM | 179 | depends on ARCH_MSM |
172 | select USB_EHCI_ROOT_HUB_TT | 180 | select USB_EHCI_ROOT_HUB_TT |
173 | select USB_MSM_OTG | ||
174 | ---help--- | 181 | ---help--- |
175 | Enables support for the USB Host controller present on the | 182 | Enables support for the USB Host controller present on the |
176 | Qualcomm chipsets. Root Hub has inbuilt TT. | 183 | Qualcomm chipsets. Root Hub has inbuilt TT. |
@@ -343,10 +350,19 @@ config USB_FOTG210_HCD | |||
343 | To compile this driver as a module, choose M here: the | 350 | To compile this driver as a module, choose M here: the |
344 | module will be called fotg210-hcd. | 351 | module will be called fotg210-hcd. |
345 | 352 | ||
353 | config USB_MAX3421_HCD | ||
354 | tristate "MAX3421 HCD (USB-over-SPI) support" | ||
355 | depends on USB && SPI | ||
356 | ---help--- | ||
357 | The Maxim MAX3421E chip supports standard USB 2.0-compliant | ||
358 | full-speed devices either in host or peripheral mode. This | ||
359 | driver supports the host-mode of the MAX3421E only. | ||
360 | |||
361 | To compile this driver as a module, choose M here: the module will | ||
362 | be called max3421-hcd. | ||
363 | |||
346 | config USB_OHCI_HCD | 364 | config USB_OHCI_HCD |
347 | tristate "OHCI HCD (USB 1.1) support" | 365 | tristate "OHCI HCD (USB 1.1) support" |
348 | select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 | ||
349 | depends on USB_ISP1301 || !ARCH_LPC32XX | ||
350 | ---help--- | 366 | ---help--- |
351 | The Open Host Controller Interface (OHCI) is a standard for accessing | 367 | The Open Host Controller Interface (OHCI) is a standard for accessing |
352 | USB 1.1 host controller hardware. It does more in hardware than Intel's | 368 | USB 1.1 host controller hardware. It does more in hardware than Intel's |
@@ -365,6 +381,7 @@ if USB_OHCI_HCD | |||
365 | config USB_OHCI_HCD_OMAP1 | 381 | config USB_OHCI_HCD_OMAP1 |
366 | tristate "OHCI support for OMAP1/2 chips" | 382 | tristate "OHCI support for OMAP1/2 chips" |
367 | depends on ARCH_OMAP1 | 383 | depends on ARCH_OMAP1 |
384 | depends on ISP1301_OMAP || !(MACH_OMAP_H2 || MACH_OMAP_H3) | ||
368 | default y | 385 | default y |
369 | ---help--- | 386 | ---help--- |
370 | Enables support for the OHCI controller on OMAP1/2 chips. | 387 | Enables support for the OHCI controller on OMAP1/2 chips. |
@@ -388,6 +405,7 @@ config USB_OHCI_HCD_S3C2410 | |||
388 | config USB_OHCI_HCD_LPC32XX | 405 | config USB_OHCI_HCD_LPC32XX |
389 | tristate "Support for LPC on-chip OHCI USB controller" | 406 | tristate "Support for LPC on-chip OHCI USB controller" |
390 | depends on USB_OHCI_HCD && ARCH_LPC32XX | 407 | depends on USB_OHCI_HCD && ARCH_LPC32XX |
408 | depends on USB_ISP1301 | ||
391 | default y | 409 | default y |
392 | ---help--- | 410 | ---help--- |
393 | Enables support for the on-chip OHCI controller on | 411 | Enables support for the on-chip OHCI controller on |
@@ -417,6 +435,16 @@ config USB_OHCI_HCD_OMAP3 | |||
417 | Enables support for the on-chip OHCI controller on | 435 | Enables support for the on-chip OHCI controller on |
418 | OMAP3 and later chips. | 436 | OMAP3 and later chips. |
419 | 437 | ||
438 | config USB_OHCI_HCD_DAVINCI | ||
439 | bool "OHCI support for TI DaVinci DA8xx" | ||
440 | depends on ARCH_DAVINCI_DA8XX | ||
441 | depends on USB_OHCI_HCD=y | ||
442 | default y | ||
443 | help | ||
444 | Enables support for the DaVinci DA8xx integrated OHCI | ||
445 | controller. This driver cannot currently be a loadable | ||
446 | module because it lacks a proper PHY abstraction. | ||
447 | |||
420 | config USB_OHCI_ATH79 | 448 | config USB_OHCI_ATH79 |
421 | bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)" | 449 | bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)" |
422 | depends on (SOC_AR71XX || SOC_AR724X) | 450 | depends on (SOC_AR71XX || SOC_AR724X) |
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 7530468c9a4f..af89a903d97e 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
@@ -19,6 +19,9 @@ xhci-hcd-$(CONFIG_PCI) += xhci-pci.o | |||
19 | 19 | ||
20 | ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) | 20 | ifneq ($(CONFIG_USB_XHCI_PLATFORM), ) |
21 | xhci-hcd-y += xhci-plat.o | 21 | xhci-hcd-y += xhci-plat.o |
22 | ifneq ($(CONFIG_USB_XHCI_MVEBU), ) | ||
23 | xhci-hcd-y += xhci-mvebu.o | ||
24 | endif | ||
22 | endif | 25 | endif |
23 | 26 | ||
24 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ | 27 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ |
@@ -70,3 +73,4 @@ obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o | |||
70 | obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o | 73 | obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o |
71 | obj-$(CONFIG_USB_FUSBH200_HCD) += fusbh200-hcd.o | 74 | obj-$(CONFIG_USB_FUSBH200_HCD) += fusbh200-hcd.o |
72 | obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o | 75 | obj-$(CONFIG_USB_FOTG210_HCD) += fotg210-hcd.o |
76 | obj-$(CONFIG_USB_MAX3421_HCD) += max3421-hcd.o | ||
diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index 7f425acd9be5..d1c76216350f 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
21 | #include <linux/of_gpio.h> | 21 | #include <linux/of_gpio.h> |
22 | #include <linux/phy/phy.h> | ||
22 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
23 | #include <linux/usb/phy.h> | 24 | #include <linux/usb/phy.h> |
24 | #include <linux/usb/samsung_usb_phy.h> | 25 | #include <linux/usb/samsung_usb_phy.h> |
@@ -42,17 +43,106 @@ | |||
42 | static const char hcd_name[] = "ehci-exynos"; | 43 | static const char hcd_name[] = "ehci-exynos"; |
43 | static struct hc_driver __read_mostly exynos_ehci_hc_driver; | 44 | static struct hc_driver __read_mostly exynos_ehci_hc_driver; |
44 | 45 | ||
46 | #define PHY_NUMBER 3 | ||
47 | |||
45 | struct exynos_ehci_hcd { | 48 | struct exynos_ehci_hcd { |
46 | struct clk *clk; | 49 | struct clk *clk; |
47 | struct usb_phy *phy; | 50 | struct usb_phy *phy; |
48 | struct usb_otg *otg; | 51 | struct usb_otg *otg; |
52 | struct phy *phy_g[PHY_NUMBER]; | ||
49 | }; | 53 | }; |
50 | 54 | ||
51 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) | 55 | #define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv) |
52 | 56 | ||
53 | static void exynos_setup_vbus_gpio(struct platform_device *pdev) | 57 | static int exynos_ehci_get_phy(struct device *dev, |
58 | struct exynos_ehci_hcd *exynos_ehci) | ||
59 | { | ||
60 | struct device_node *child; | ||
61 | struct phy *phy; | ||
62 | int phy_number; | ||
63 | int ret = 0; | ||
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 | |||
77 | for_each_available_child_of_node(dev->of_node, child) { | ||
78 | ret = of_property_read_u32(child, "reg", &phy_number); | ||
79 | if (ret) { | ||
80 | dev_err(dev, "Failed to parse device tree\n"); | ||
81 | of_node_put(child); | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | if (phy_number >= PHY_NUMBER) { | ||
86 | dev_err(dev, "Invalid number of PHYs\n"); | ||
87 | of_node_put(child); | ||
88 | return -EINVAL; | ||
89 | } | ||
90 | |||
91 | phy = devm_of_phy_get(dev, child, 0); | ||
92 | of_node_put(child); | ||
93 | if (IS_ERR(phy)) { | ||
94 | ret = PTR_ERR(phy); | ||
95 | if (ret != -ENOSYS && ret != -ENODEV) { | ||
96 | dev_err(dev, "no usb2 phy configured\n"); | ||
97 | return ret; | ||
98 | } | ||
99 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
100 | } | ||
101 | exynos_ehci->phy_g[phy_number] = phy; | ||
102 | } | ||
103 | |||
104 | return ret; | ||
105 | } | ||
106 | |||
107 | static int exynos_ehci_phy_enable(struct device *dev) | ||
108 | { | ||
109 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
110 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); | ||
111 | int i; | ||
112 | int ret = 0; | ||
113 | |||
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++) | ||
118 | if (!IS_ERR(exynos_ehci->phy_g[i])) | ||
119 | ret = phy_power_on(exynos_ehci->phy_g[i]); | ||
120 | if (ret) | ||
121 | for (i--; i >= 0; i--) | ||
122 | if (!IS_ERR(exynos_ehci->phy_g[i])) | ||
123 | phy_power_off(exynos_ehci->phy_g[i]); | ||
124 | |||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | static void exynos_ehci_phy_disable(struct device *dev) | ||
129 | { | ||
130 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
131 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); | ||
132 | int i; | ||
133 | |||
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++) | ||
140 | if (!IS_ERR(exynos_ehci->phy_g[i])) | ||
141 | phy_power_off(exynos_ehci->phy_g[i]); | ||
142 | } | ||
143 | |||
144 | static void exynos_setup_vbus_gpio(struct device *dev) | ||
54 | { | 145 | { |
55 | struct device *dev = &pdev->dev; | ||
56 | int err; | 146 | int err; |
57 | int gpio; | 147 | int gpio; |
58 | 148 | ||
@@ -75,7 +165,6 @@ static int exynos_ehci_probe(struct platform_device *pdev) | |||
75 | struct usb_hcd *hcd; | 165 | struct usb_hcd *hcd; |
76 | struct ehci_hcd *ehci; | 166 | struct ehci_hcd *ehci; |
77 | struct resource *res; | 167 | struct resource *res; |
78 | struct usb_phy *phy; | ||
79 | int irq; | 168 | int irq; |
80 | int err; | 169 | int err; |
81 | 170 | ||
@@ -88,7 +177,7 @@ static int exynos_ehci_probe(struct platform_device *pdev) | |||
88 | if (err) | 177 | if (err) |
89 | return err; | 178 | return err; |
90 | 179 | ||
91 | exynos_setup_vbus_gpio(pdev); | 180 | exynos_setup_vbus_gpio(&pdev->dev); |
92 | 181 | ||
93 | hcd = usb_create_hcd(&exynos_ehci_hc_driver, | 182 | hcd = usb_create_hcd(&exynos_ehci_hc_driver, |
94 | &pdev->dev, dev_name(&pdev->dev)); | 183 | &pdev->dev, dev_name(&pdev->dev)); |
@@ -102,15 +191,9 @@ static int exynos_ehci_probe(struct platform_device *pdev) | |||
102 | "samsung,exynos5440-ehci")) | 191 | "samsung,exynos5440-ehci")) |
103 | goto skip_phy; | 192 | goto skip_phy; |
104 | 193 | ||
105 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 194 | err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci); |
106 | if (IS_ERR(phy)) { | 195 | if (err) |
107 | usb_put_hcd(hcd); | 196 | goto fail_clk; |
108 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | ||
109 | return -EPROBE_DEFER; | ||
110 | } else { | ||
111 | exynos_ehci->phy = phy; | ||
112 | exynos_ehci->otg = phy->otg; | ||
113 | } | ||
114 | 197 | ||
115 | skip_phy: | 198 | skip_phy: |
116 | 199 | ||
@@ -135,10 +218,9 @@ skip_phy: | |||
135 | 218 | ||
136 | hcd->rsrc_start = res->start; | 219 | hcd->rsrc_start = res->start; |
137 | hcd->rsrc_len = resource_size(res); | 220 | hcd->rsrc_len = resource_size(res); |
138 | hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len); | 221 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
139 | if (!hcd->regs) { | 222 | if (IS_ERR(hcd->regs)) { |
140 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | 223 | err = PTR_ERR(hcd->regs); |
141 | err = -ENOMEM; | ||
142 | goto fail_io; | 224 | goto fail_io; |
143 | } | 225 | } |
144 | 226 | ||
@@ -152,8 +234,11 @@ skip_phy: | |||
152 | if (exynos_ehci->otg) | 234 | if (exynos_ehci->otg) |
153 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | 235 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
154 | 236 | ||
155 | if (exynos_ehci->phy) | 237 | err = exynos_ehci_phy_enable(&pdev->dev); |
156 | usb_phy_init(exynos_ehci->phy); | 238 | if (err) { |
239 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); | ||
240 | goto fail_io; | ||
241 | } | ||
157 | 242 | ||
158 | ehci = hcd_to_ehci(hcd); | 243 | ehci = hcd_to_ehci(hcd); |
159 | ehci->caps = hcd->regs; | 244 | ehci->caps = hcd->regs; |
@@ -173,8 +258,7 @@ skip_phy: | |||
173 | return 0; | 258 | return 0; |
174 | 259 | ||
175 | fail_add_hcd: | 260 | fail_add_hcd: |
176 | if (exynos_ehci->phy) | 261 | exynos_ehci_phy_disable(&pdev->dev); |
177 | usb_phy_shutdown(exynos_ehci->phy); | ||
178 | fail_io: | 262 | fail_io: |
179 | clk_disable_unprepare(exynos_ehci->clk); | 263 | clk_disable_unprepare(exynos_ehci->clk); |
180 | fail_clk: | 264 | fail_clk: |
@@ -192,8 +276,7 @@ static int exynos_ehci_remove(struct platform_device *pdev) | |||
192 | if (exynos_ehci->otg) | 276 | if (exynos_ehci->otg) |
193 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | 277 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
194 | 278 | ||
195 | if (exynos_ehci->phy) | 279 | exynos_ehci_phy_disable(&pdev->dev); |
196 | usb_phy_shutdown(exynos_ehci->phy); | ||
197 | 280 | ||
198 | clk_disable_unprepare(exynos_ehci->clk); | 281 | clk_disable_unprepare(exynos_ehci->clk); |
199 | 282 | ||
@@ -218,8 +301,7 @@ static int exynos_ehci_suspend(struct device *dev) | |||
218 | if (exynos_ehci->otg) | 301 | if (exynos_ehci->otg) |
219 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | 302 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
220 | 303 | ||
221 | if (exynos_ehci->phy) | 304 | exynos_ehci_phy_disable(dev); |
222 | usb_phy_shutdown(exynos_ehci->phy); | ||
223 | 305 | ||
224 | clk_disable_unprepare(exynos_ehci->clk); | 306 | clk_disable_unprepare(exynos_ehci->clk); |
225 | 307 | ||
@@ -230,14 +312,19 @@ static int exynos_ehci_resume(struct device *dev) | |||
230 | { | 312 | { |
231 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 313 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
232 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); | 314 | struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd); |
315 | int ret; | ||
233 | 316 | ||
234 | clk_prepare_enable(exynos_ehci->clk); | 317 | clk_prepare_enable(exynos_ehci->clk); |
235 | 318 | ||
236 | if (exynos_ehci->otg) | 319 | if (exynos_ehci->otg) |
237 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); | 320 | exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self); |
238 | 321 | ||
239 | if (exynos_ehci->phy) | 322 | ret = exynos_ehci_phy_enable(dev); |
240 | usb_phy_init(exynos_ehci->phy); | 323 | if (ret) { |
324 | dev_err(dev, "Failed to enable USB phy\n"); | ||
325 | clk_disable_unprepare(exynos_ehci->clk); | ||
326 | return ret; | ||
327 | } | ||
241 | 328 | ||
242 | /* DMA burst Enable */ | 329 | /* DMA burst Enable */ |
243 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); | 330 | writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 7ae0c4d51741..cc305c71ac3d 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -33,15 +33,6 @@ | |||
33 | 33 | ||
34 | #ifdef CONFIG_PM | 34 | #ifdef CONFIG_PM |
35 | 35 | ||
36 | static int ehci_hub_control( | ||
37 | struct usb_hcd *hcd, | ||
38 | u16 typeReq, | ||
39 | u16 wValue, | ||
40 | u16 wIndex, | ||
41 | char *buf, | ||
42 | u16 wLength | ||
43 | ); | ||
44 | |||
45 | static int persist_enabled_on_companion(struct usb_device *udev, void *unused) | 36 | static int persist_enabled_on_companion(struct usb_device *udev, void *unused) |
46 | { | 37 | { |
47 | return !udev->maxchild && udev->persist_enabled && | 38 | return !udev->maxchild && udev->persist_enabled && |
@@ -865,7 +856,7 @@ cleanup: | |||
865 | #endif /* CONFIG_USB_HCD_TEST_MODE */ | 856 | #endif /* CONFIG_USB_HCD_TEST_MODE */ |
866 | /*-------------------------------------------------------------------------*/ | 857 | /*-------------------------------------------------------------------------*/ |
867 | 858 | ||
868 | static int ehci_hub_control ( | 859 | int ehci_hub_control( |
869 | struct usb_hcd *hcd, | 860 | struct usb_hcd *hcd, |
870 | u16 typeReq, | 861 | u16 typeReq, |
871 | u16 wValue, | 862 | u16 wValue, |
@@ -1285,6 +1276,7 @@ error_exit: | |||
1285 | spin_unlock_irqrestore (&ehci->lock, flags); | 1276 | spin_unlock_irqrestore (&ehci->lock, flags); |
1286 | return retval; | 1277 | return retval; |
1287 | } | 1278 | } |
1279 | EXPORT_SYMBOL_GPL(ehci_hub_control); | ||
1288 | 1280 | ||
1289 | static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum) | 1281 | static void ehci_relinquish_port(struct usb_hcd *hcd, int portnum) |
1290 | { | 1282 | { |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index f341651d6f6c..982c09bebe0f 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -96,10 +96,9 @@ static int ehci_msm_probe(struct platform_device *pdev) | |||
96 | 96 | ||
97 | hcd->rsrc_start = res->start; | 97 | hcd->rsrc_start = res->start; |
98 | hcd->rsrc_len = resource_size(res); | 98 | hcd->rsrc_len = resource_size(res); |
99 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); | 99 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
100 | if (!hcd->regs) { | 100 | if (IS_ERR(hcd->regs)) { |
101 | dev_err(&pdev->dev, "ioremap failed\n"); | 101 | ret = PTR_ERR(hcd->regs); |
102 | ret = -ENOMEM; | ||
103 | goto put_hcd; | 102 | goto put_hcd; |
104 | } | 103 | } |
105 | 104 | ||
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c index bd61612a7251..08147c35f836 100644 --- a/drivers/usb/host/ehci-mv.c +++ b/drivers/usb/host/ehci-mv.c | |||
@@ -176,11 +176,9 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
176 | goto err_put_hcd; | 176 | goto err_put_hcd; |
177 | } | 177 | } |
178 | 178 | ||
179 | ehci_mv->phy_regs = devm_ioremap(&pdev->dev, r->start, | 179 | ehci_mv->phy_regs = devm_ioremap_resource(&pdev->dev, r); |
180 | resource_size(r)); | 180 | if (IS_ERR(ehci_mv->phy_regs)) { |
181 | if (!ehci_mv->phy_regs) { | 181 | retval = PTR_ERR(ehci_mv->phy_regs); |
182 | dev_err(&pdev->dev, "failed to map phy I/O memory\n"); | ||
183 | retval = -EFAULT; | ||
184 | goto err_put_hcd; | 182 | goto err_put_hcd; |
185 | } | 183 | } |
186 | 184 | ||
@@ -191,11 +189,9 @@ static int mv_ehci_probe(struct platform_device *pdev) | |||
191 | goto err_put_hcd; | 189 | goto err_put_hcd; |
192 | } | 190 | } |
193 | 191 | ||
194 | ehci_mv->cap_regs = devm_ioremap(&pdev->dev, r->start, | 192 | ehci_mv->cap_regs = devm_ioremap_resource(&pdev->dev, r); |
195 | resource_size(r)); | 193 | if (IS_ERR(ehci_mv->cap_regs)) { |
196 | if (ehci_mv->cap_regs == NULL) { | 194 | retval = PTR_ERR(ehci_mv->cap_regs); |
197 | dev_err(&pdev->dev, "failed to map I/O memory\n"); | ||
198 | retval = -EFAULT; | ||
199 | goto err_put_hcd; | 195 | goto err_put_hcd; |
200 | } | 196 | } |
201 | 197 | ||
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c index 30d35e5e503a..22e15cab8ea5 100644 --- a/drivers/usb/host/ehci-orion.c +++ b/drivers/usb/host/ehci-orion.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/clk.h> | 15 | #include <linux/clk.h> |
16 | #include <linux/platform_data/usb-ehci-orion.h> | 16 | #include <linux/platform_data/usb-ehci-orion.h> |
17 | #include <linux/of.h> | 17 | #include <linux/of.h> |
18 | #include <linux/phy/phy.h> | ||
18 | #include <linux/of_device.h> | 19 | #include <linux/of_device.h> |
19 | #include <linux/of_irq.h> | 20 | #include <linux/of_irq.h> |
20 | #include <linux/usb.h> | 21 | #include <linux/usb.h> |
@@ -42,6 +43,13 @@ | |||
42 | 43 | ||
43 | #define DRIVER_DESC "EHCI orion driver" | 44 | #define DRIVER_DESC "EHCI orion driver" |
44 | 45 | ||
46 | #define hcd_to_orion_priv(h) ((struct orion_ehci_hcd *)hcd_to_ehci(h)->priv) | ||
47 | |||
48 | struct orion_ehci_hcd { | ||
49 | struct clk *clk; | ||
50 | struct phy *phy; | ||
51 | }; | ||
52 | |||
45 | static const char hcd_name[] = "ehci-orion"; | 53 | static const char hcd_name[] = "ehci-orion"; |
46 | 54 | ||
47 | static struct hc_driver __read_mostly ehci_orion_hc_driver; | 55 | static struct hc_driver __read_mostly ehci_orion_hc_driver; |
@@ -137,6 +145,10 @@ ehci_orion_conf_mbus_windows(struct usb_hcd *hcd, | |||
137 | } | 145 | } |
138 | } | 146 | } |
139 | 147 | ||
148 | static const struct ehci_driver_overrides orion_overrides __initconst = { | ||
149 | .extra_priv_size = sizeof(struct orion_ehci_hcd), | ||
150 | }; | ||
151 | |||
140 | static int ehci_orion_drv_probe(struct platform_device *pdev) | 152 | static int ehci_orion_drv_probe(struct platform_device *pdev) |
141 | { | 153 | { |
142 | struct orion_ehci_data *pd = dev_get_platdata(&pdev->dev); | 154 | struct orion_ehci_data *pd = dev_get_platdata(&pdev->dev); |
@@ -144,26 +156,23 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
144 | struct resource *res; | 156 | struct resource *res; |
145 | struct usb_hcd *hcd; | 157 | struct usb_hcd *hcd; |
146 | struct ehci_hcd *ehci; | 158 | struct ehci_hcd *ehci; |
147 | struct clk *clk; | ||
148 | void __iomem *regs; | 159 | void __iomem *regs; |
149 | int irq, err; | 160 | int irq, err; |
150 | enum orion_ehci_phy_ver phy_version; | 161 | enum orion_ehci_phy_ver phy_version; |
162 | struct orion_ehci_hcd *priv; | ||
151 | 163 | ||
152 | if (usb_disabled()) | 164 | if (usb_disabled()) |
153 | return -ENODEV; | 165 | return -ENODEV; |
154 | 166 | ||
155 | pr_debug("Initializing Orion-SoC USB Host Controller\n"); | 167 | pr_debug("Initializing Orion-SoC USB Host Controller\n"); |
156 | 168 | ||
157 | if (pdev->dev.of_node) | 169 | irq = platform_get_irq(pdev, 0); |
158 | irq = irq_of_parse_and_map(pdev->dev.of_node, 0); | ||
159 | else | ||
160 | irq = platform_get_irq(pdev, 0); | ||
161 | if (irq <= 0) { | 170 | if (irq <= 0) { |
162 | dev_err(&pdev->dev, | 171 | dev_err(&pdev->dev, |
163 | "Found HC with no IRQ. Check %s setup!\n", | 172 | "Found HC with no IRQ. Check %s setup!\n", |
164 | dev_name(&pdev->dev)); | 173 | dev_name(&pdev->dev)); |
165 | err = -ENODEV; | 174 | err = -ENODEV; |
166 | goto err1; | 175 | goto err; |
167 | } | 176 | } |
168 | 177 | ||
169 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 178 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
@@ -172,7 +181,7 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
172 | "Found HC with no register addr. Check %s setup!\n", | 181 | "Found HC with no register addr. Check %s setup!\n", |
173 | dev_name(&pdev->dev)); | 182 | dev_name(&pdev->dev)); |
174 | err = -ENODEV; | 183 | err = -ENODEV; |
175 | goto err1; | 184 | goto err; |
176 | } | 185 | } |
177 | 186 | ||
178 | /* | 187 | /* |
@@ -182,25 +191,19 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
182 | */ | 191 | */ |
183 | err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); | 192 | err = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
184 | if (err) | 193 | if (err) |
185 | goto err1; | 194 | goto err; |
186 | 195 | ||
187 | regs = devm_ioremap_resource(&pdev->dev, res); | 196 | regs = devm_ioremap_resource(&pdev->dev, res); |
188 | if (IS_ERR(regs)) { | 197 | if (IS_ERR(regs)) { |
189 | err = PTR_ERR(regs); | 198 | err = PTR_ERR(regs); |
190 | goto err1; | 199 | goto err; |
191 | } | 200 | } |
192 | 201 | ||
193 | /* Not all platforms can gate the clock, so it is not | ||
194 | an error if the clock does not exists. */ | ||
195 | clk = devm_clk_get(&pdev->dev, NULL); | ||
196 | if (!IS_ERR(clk)) | ||
197 | clk_prepare_enable(clk); | ||
198 | |||
199 | hcd = usb_create_hcd(&ehci_orion_hc_driver, | 202 | hcd = usb_create_hcd(&ehci_orion_hc_driver, |
200 | &pdev->dev, dev_name(&pdev->dev)); | 203 | &pdev->dev, dev_name(&pdev->dev)); |
201 | if (!hcd) { | 204 | if (!hcd) { |
202 | err = -ENOMEM; | 205 | err = -ENOMEM; |
203 | goto err2; | 206 | goto err; |
204 | } | 207 | } |
205 | 208 | ||
206 | hcd->rsrc_start = res->start; | 209 | hcd->rsrc_start = res->start; |
@@ -211,6 +214,29 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
211 | ehci->caps = hcd->regs + 0x100; | 214 | ehci->caps = hcd->regs + 0x100; |
212 | hcd->has_tt = 1; | 215 | hcd->has_tt = 1; |
213 | 216 | ||
217 | priv = hcd_to_orion_priv(hcd); | ||
218 | /* | ||
219 | * Not all platforms can gate the clock, so it is not an error if | ||
220 | * the clock does not exists. | ||
221 | */ | ||
222 | priv->clk = devm_clk_get(&pdev->dev, NULL); | ||
223 | if (!IS_ERR(priv->clk)) | ||
224 | clk_prepare_enable(priv->clk); | ||
225 | |||
226 | priv->phy = devm_phy_optional_get(&pdev->dev, "usb"); | ||
227 | if (IS_ERR(priv->phy)) { | ||
228 | err = PTR_ERR(priv->phy); | ||
229 | goto err_phy_get; | ||
230 | } else { | ||
231 | err = phy_init(priv->phy); | ||
232 | if (err) | ||
233 | goto err_phy_init; | ||
234 | |||
235 | err = phy_power_on(priv->phy); | ||
236 | if (err) | ||
237 | goto err_phy_power_on; | ||
238 | } | ||
239 | |||
214 | /* | 240 | /* |
215 | * (Re-)program MBUS remapping windows if we are asked to. | 241 | * (Re-)program MBUS remapping windows if we are asked to. |
216 | */ | 242 | */ |
@@ -240,17 +266,23 @@ static int ehci_orion_drv_probe(struct platform_device *pdev) | |||
240 | 266 | ||
241 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 267 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
242 | if (err) | 268 | if (err) |
243 | goto err3; | 269 | goto err_add_hcd; |
244 | 270 | ||
245 | device_wakeup_enable(hcd->self.controller); | 271 | device_wakeup_enable(hcd->self.controller); |
246 | return 0; | 272 | return 0; |
247 | 273 | ||
248 | err3: | 274 | err_add_hcd: |
275 | if (!IS_ERR(priv->phy)) | ||
276 | phy_power_off(priv->phy); | ||
277 | err_phy_power_on: | ||
278 | if (!IS_ERR(priv->phy)) | ||
279 | phy_exit(priv->phy); | ||
280 | err_phy_init: | ||
281 | err_phy_get: | ||
282 | if (!IS_ERR(priv->clk)) | ||
283 | clk_disable_unprepare(priv->clk); | ||
249 | usb_put_hcd(hcd); | 284 | usb_put_hcd(hcd); |
250 | err2: | 285 | err: |
251 | if (!IS_ERR(clk)) | ||
252 | clk_disable_unprepare(clk); | ||
253 | err1: | ||
254 | dev_err(&pdev->dev, "init %s fail, %d\n", | 286 | dev_err(&pdev->dev, "init %s fail, %d\n", |
255 | dev_name(&pdev->dev), err); | 287 | dev_name(&pdev->dev), err); |
256 | 288 | ||
@@ -260,14 +292,20 @@ err1: | |||
260 | static int ehci_orion_drv_remove(struct platform_device *pdev) | 292 | static int ehci_orion_drv_remove(struct platform_device *pdev) |
261 | { | 293 | { |
262 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 294 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
263 | struct clk *clk; | 295 | struct orion_ehci_hcd *priv = hcd_to_orion_priv(hcd); |
264 | 296 | ||
265 | usb_remove_hcd(hcd); | 297 | usb_remove_hcd(hcd); |
298 | |||
299 | if (!IS_ERR(priv->phy)) { | ||
300 | phy_power_off(priv->phy); | ||
301 | phy_exit(priv->phy); | ||
302 | } | ||
303 | |||
304 | if (!IS_ERR(priv->clk)) | ||
305 | clk_disable_unprepare(priv->clk); | ||
306 | |||
266 | usb_put_hcd(hcd); | 307 | usb_put_hcd(hcd); |
267 | 308 | ||
268 | clk = devm_clk_get(&pdev->dev, NULL); | ||
269 | if (!IS_ERR(clk)) | ||
270 | clk_disable_unprepare(clk); | ||
271 | return 0; | 309 | return 0; |
272 | } | 310 | } |
273 | 311 | ||
@@ -295,7 +333,7 @@ static int __init ehci_orion_init(void) | |||
295 | 333 | ||
296 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | 334 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
297 | 335 | ||
298 | ehci_init_driver(&ehci_orion_hc_driver, NULL); | 336 | ehci_init_driver(&ehci_orion_hc_driver, &orion_overrides); |
299 | return platform_driver_register(&ehci_orion_driver); | 337 | return platform_driver_register(&ehci_orion_driver); |
300 | } | 338 | } |
301 | module_init(ehci_orion_init); | 339 | module_init(ehci_orion_init); |
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c index c7dd93aad20c..2f5b9ce3e042 100644 --- a/drivers/usb/host/ehci-platform.c +++ b/drivers/usb/host/ehci-platform.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <linux/of.h> | 29 | #include <linux/of.h> |
30 | #include <linux/phy/phy.h> | 30 | #include <linux/phy/phy.h> |
31 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
32 | #include <linux/reset.h> | ||
32 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
33 | #include <linux/usb/hcd.h> | 34 | #include <linux/usb/hcd.h> |
34 | #include <linux/usb/ehci_pdriver.h> | 35 | #include <linux/usb/ehci_pdriver.h> |
@@ -41,6 +42,7 @@ | |||
41 | 42 | ||
42 | struct ehci_platform_priv { | 43 | struct ehci_platform_priv { |
43 | struct clk *clks[EHCI_MAX_CLKS]; | 44 | struct clk *clks[EHCI_MAX_CLKS]; |
45 | struct reset_control *rst; | ||
44 | struct phy *phy; | 46 | struct phy *phy; |
45 | }; | 47 | }; |
46 | 48 | ||
@@ -208,6 +210,18 @@ static int ehci_platform_probe(struct platform_device *dev) | |||
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
213 | priv->rst = devm_reset_control_get_optional(&dev->dev, NULL); | ||
214 | if (IS_ERR(priv->rst)) { | ||
215 | err = PTR_ERR(priv->rst); | ||
216 | if (err == -EPROBE_DEFER) | ||
217 | goto err_put_clks; | ||
218 | priv->rst = NULL; | ||
219 | } else { | ||
220 | err = reset_control_deassert(priv->rst); | ||
221 | if (err) | ||
222 | goto err_put_clks; | ||
223 | } | ||
224 | |||
211 | if (pdata->big_endian_desc) | 225 | if (pdata->big_endian_desc) |
212 | ehci->big_endian_desc = 1; | 226 | ehci->big_endian_desc = 1; |
213 | if (pdata->big_endian_mmio) | 227 | if (pdata->big_endian_mmio) |
@@ -218,7 +232,7 @@ static int ehci_platform_probe(struct platform_device *dev) | |||
218 | dev_err(&dev->dev, | 232 | dev_err(&dev->dev, |
219 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n"); | 233 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n"); |
220 | err = -EINVAL; | 234 | err = -EINVAL; |
221 | goto err_put_clks; | 235 | goto err_reset; |
222 | } | 236 | } |
223 | #endif | 237 | #endif |
224 | #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC | 238 | #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC |
@@ -226,14 +240,14 @@ static int ehci_platform_probe(struct platform_device *dev) | |||
226 | dev_err(&dev->dev, | 240 | dev_err(&dev->dev, |
227 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n"); | 241 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n"); |
228 | err = -EINVAL; | 242 | err = -EINVAL; |
229 | goto err_put_clks; | 243 | goto err_reset; |
230 | } | 244 | } |
231 | #endif | 245 | #endif |
232 | 246 | ||
233 | if (pdata->power_on) { | 247 | if (pdata->power_on) { |
234 | err = pdata->power_on(dev); | 248 | err = pdata->power_on(dev); |
235 | if (err < 0) | 249 | if (err < 0) |
236 | goto err_put_clks; | 250 | goto err_reset; |
237 | } | 251 | } |
238 | 252 | ||
239 | hcd->rsrc_start = res_mem->start; | 253 | hcd->rsrc_start = res_mem->start; |
@@ -256,6 +270,9 @@ static int ehci_platform_probe(struct platform_device *dev) | |||
256 | err_power: | 270 | err_power: |
257 | if (pdata->power_off) | 271 | if (pdata->power_off) |
258 | pdata->power_off(dev); | 272 | pdata->power_off(dev); |
273 | err_reset: | ||
274 | if (priv->rst) | ||
275 | reset_control_assert(priv->rst); | ||
259 | err_put_clks: | 276 | err_put_clks: |
260 | while (--clk >= 0) | 277 | while (--clk >= 0) |
261 | clk_put(priv->clks[clk]); | 278 | clk_put(priv->clks[clk]); |
@@ -280,6 +297,9 @@ static int ehci_platform_remove(struct platform_device *dev) | |||
280 | if (pdata->power_off) | 297 | if (pdata->power_off) |
281 | pdata->power_off(dev); | 298 | pdata->power_off(dev); |
282 | 299 | ||
300 | if (priv->rst) | ||
301 | reset_control_assert(priv->rst); | ||
302 | |||
283 | for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) | 303 | for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) |
284 | clk_put(priv->clks[clk]); | 304 | clk_put(priv->clks[clk]); |
285 | 305 | ||
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c index 8bd915b2ae8c..1d59958ad0ce 100644 --- a/drivers/usb/host/ehci-spear.c +++ b/drivers/usb/host/ehci-spear.c | |||
@@ -106,16 +106,9 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) | |||
106 | 106 | ||
107 | hcd->rsrc_start = res->start; | 107 | hcd->rsrc_start = res->start; |
108 | hcd->rsrc_len = resource_size(res); | 108 | hcd->rsrc_len = resource_size(res); |
109 | if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len, | 109 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
110 | driver->description)) { | 110 | if (IS_ERR(hcd->regs)) { |
111 | retval = -EBUSY; | 111 | retval = PTR_ERR(hcd->regs); |
112 | goto err_put_hcd; | ||
113 | } | ||
114 | |||
115 | hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len); | ||
116 | if (hcd->regs == NULL) { | ||
117 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
118 | retval = -ENOMEM; | ||
119 | goto err_put_hcd; | 112 | goto err_put_hcd; |
120 | } | 113 | } |
121 | 114 | ||
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 7ef00ecb0da1..6fdcb8ad2296 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -51,10 +51,6 @@ struct tegra_ehci_soc_config { | |||
51 | bool has_hostpc; | 51 | bool has_hostpc; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | static int (*orig_hub_control)(struct usb_hcd *hcd, | ||
55 | u16 typeReq, u16 wValue, u16 wIndex, | ||
56 | char *buf, u16 wLength); | ||
57 | |||
58 | struct tegra_ehci_hcd { | 54 | struct tegra_ehci_hcd { |
59 | struct tegra_usb_phy *phy; | 55 | struct tegra_usb_phy *phy; |
60 | struct clk *clk; | 56 | struct clk *clk; |
@@ -236,7 +232,7 @@ static int tegra_ehci_hub_control( | |||
236 | spin_unlock_irqrestore(&ehci->lock, flags); | 232 | spin_unlock_irqrestore(&ehci->lock, flags); |
237 | 233 | ||
238 | /* Handle the hub control events here */ | 234 | /* Handle the hub control events here */ |
239 | return orig_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | 235 | return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
240 | 236 | ||
241 | done: | 237 | done: |
242 | spin_unlock_irqrestore(&ehci->lock, flags); | 238 | spin_unlock_irqrestore(&ehci->lock, flags); |
@@ -415,10 +411,9 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
415 | } | 411 | } |
416 | hcd->rsrc_start = res->start; | 412 | hcd->rsrc_start = res->start; |
417 | hcd->rsrc_len = resource_size(res); | 413 | hcd->rsrc_len = resource_size(res); |
418 | hcd->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); | 414 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
419 | if (!hcd->regs) { | 415 | if (IS_ERR(hcd->regs)) { |
420 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | 416 | err = PTR_ERR(hcd->regs); |
421 | err = -ENOMEM; | ||
422 | goto cleanup_clk_en; | 417 | goto cleanup_clk_en; |
423 | } | 418 | } |
424 | ehci->caps = hcd->regs + 0x100; | 419 | ehci->caps = hcd->regs + 0x100; |
@@ -554,8 +549,6 @@ static int __init ehci_tegra_init(void) | |||
554 | * too easy. | 549 | * too easy. |
555 | */ | 550 | */ |
556 | 551 | ||
557 | orig_hub_control = tegra_ehci_hc_driver.hub_control; | ||
558 | |||
559 | tegra_ehci_hc_driver.map_urb_for_dma = tegra_ehci_map_urb_for_dma; | 552 | tegra_ehci_hc_driver.map_urb_for_dma = tegra_ehci_map_urb_for_dma; |
560 | tegra_ehci_hc_driver.unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma; | 553 | tegra_ehci_hc_driver.unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma; |
561 | tegra_ehci_hc_driver.hub_control = tegra_ehci_hub_control; | 554 | tegra_ehci_hc_driver.hub_control = tegra_ehci_hub_control; |
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 9dfc6c1394d6..eee228a26a0e 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -872,4 +872,7 @@ extern int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup); | |||
872 | extern int ehci_resume(struct usb_hcd *hcd, bool hibernated); | 872 | extern int ehci_resume(struct usb_hcd *hcd, bool hibernated); |
873 | #endif /* CONFIG_PM */ | 873 | #endif /* CONFIG_PM */ |
874 | 874 | ||
875 | extern int ehci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
876 | u16 wIndex, char *buf, u16 wLength); | ||
877 | |||
875 | #endif /* __LINUX_EHCI_HCD_H */ | 878 | #endif /* __LINUX_EHCI_HCD_H */ |
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c new file mode 100644 index 000000000000..858efcfda50b --- /dev/null +++ b/drivers/usb/host/max3421-hcd.c | |||
@@ -0,0 +1,1957 @@ | |||
1 | /* | ||
2 | * MAX3421 Host Controller driver for USB. | ||
3 | * | ||
4 | * Author: David Mosberger-Tang <davidm@egauge.net> | ||
5 | * | ||
6 | * (C) Copyright 2014 David Mosberger-Tang <davidm@egauge.net> | ||
7 | * | ||
8 | * MAX3421 is a chip implementing a USB 2.0 Full-/Low-Speed host | ||
9 | * controller on a SPI bus. | ||
10 | * | ||
11 | * Based on: | ||
12 | * o MAX3421E datasheet | ||
13 | * http://datasheets.maximintegrated.com/en/ds/MAX3421E.pdf | ||
14 | * o MAX3421E Programming Guide | ||
15 | * http://www.hdl.co.jp/ftpdata/utl-001/AN3785.pdf | ||
16 | * o gadget/dummy_hcd.c | ||
17 | * For USB HCD implementation. | ||
18 | * o Arduino MAX3421 driver | ||
19 | * https://github.com/felis/USB_Host_Shield_2.0/blob/master/Usb.cpp | ||
20 | * | ||
21 | * This file is licenced under the GPL v2. | ||
22 | * | ||
23 | * Important note on worst-case (full-speed) packet size constraints | ||
24 | * (See USB 2.0 Section 5.6.3 and following): | ||
25 | * | ||
26 | * - control: 64 bytes | ||
27 | * - isochronous: 1023 bytes | ||
28 | * - interrupt: 64 bytes | ||
29 | * - bulk: 64 bytes | ||
30 | * | ||
31 | * Since the MAX3421 FIFO size is 64 bytes, we do not have to work about | ||
32 | * multi-FIFO writes/reads for a single USB packet *except* for isochronous | ||
33 | * transfers. We don't support isochronous transfers at this time, so we | ||
34 | * just assume that a USB packet always fits into a single FIFO buffer. | ||
35 | * | ||
36 | * NOTE: The June 2006 version of "MAX3421E Programming Guide" | ||
37 | * (AN3785) has conflicting info for the RCVDAVIRQ bit: | ||
38 | * | ||
39 | * The description of RCVDAVIRQ says "The CPU *must* clear | ||
40 | * this IRQ bit (by writing a 1 to it) before reading the | ||
41 | * RCVFIFO data. | ||
42 | * | ||
43 | * However, the earlier section on "Programming BULK-IN | ||
44 | * Transfers" says * that: | ||
45 | * | ||
46 | * After the CPU retrieves the data, it clears the | ||
47 | * RCVDAVIRQ bit. | ||
48 | * | ||
49 | * The December 2006 version has been corrected and it consistently | ||
50 | * states the second behavior is the correct one. | ||
51 | * | ||
52 | * Synchronous SPI transactions sleep so we can't perform any such | ||
53 | * transactions while holding a spin-lock (and/or while interrupts are | ||
54 | * masked). To achieve this, all SPI transactions are issued from a | ||
55 | * single thread (max3421_spi_thread). | ||
56 | */ | ||
57 | |||
58 | #include <linux/module.h> | ||
59 | #include <linux/spi/spi.h> | ||
60 | #include <linux/usb.h> | ||
61 | #include <linux/usb/hcd.h> | ||
62 | |||
63 | #include <linux/platform_data/max3421-hcd.h> | ||
64 | |||
65 | #define DRIVER_DESC "MAX3421 USB Host-Controller Driver" | ||
66 | #define DRIVER_VERSION "1.0" | ||
67 | |||
68 | /* 11-bit counter that wraps around (USB 2.0 Section 8.3.3): */ | ||
69 | #define USB_MAX_FRAME_NUMBER 0x7ff | ||
70 | #define USB_MAX_RETRIES 3 /* # of retries before error is reported */ | ||
71 | |||
72 | /* | ||
73 | * Max. # of times we're willing to retransmit a request immediately in | ||
74 | * resposne to a NAK. Afterwards, we fall back on trying once a frame. | ||
75 | */ | ||
76 | #define NAK_MAX_FAST_RETRANSMITS 2 | ||
77 | |||
78 | #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */ | ||
79 | |||
80 | /* Port-change mask: */ | ||
81 | #define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | \ | ||
82 | USB_PORT_STAT_C_ENABLE | \ | ||
83 | USB_PORT_STAT_C_SUSPEND | \ | ||
84 | USB_PORT_STAT_C_OVERCURRENT | \ | ||
85 | USB_PORT_STAT_C_RESET) << 16) | ||
86 | |||
87 | enum max3421_rh_state { | ||
88 | MAX3421_RH_RESET, | ||
89 | MAX3421_RH_SUSPENDED, | ||
90 | MAX3421_RH_RUNNING | ||
91 | }; | ||
92 | |||
93 | enum pkt_state { | ||
94 | PKT_STATE_SETUP, /* waiting to send setup packet to ctrl pipe */ | ||
95 | PKT_STATE_TRANSFER, /* waiting to xfer transfer_buffer */ | ||
96 | PKT_STATE_TERMINATE /* waiting to terminate control transfer */ | ||
97 | }; | ||
98 | |||
99 | enum scheduling_pass { | ||
100 | SCHED_PASS_PERIODIC, | ||
101 | SCHED_PASS_NON_PERIODIC, | ||
102 | SCHED_PASS_DONE | ||
103 | }; | ||
104 | |||
105 | struct max3421_dma_buf { | ||
106 | u8 data[2]; | ||
107 | }; | ||
108 | |||
109 | struct max3421_hcd { | ||
110 | spinlock_t lock; | ||
111 | |||
112 | struct task_struct *spi_thread; | ||
113 | |||
114 | struct max3421_hcd *next; | ||
115 | |||
116 | enum max3421_rh_state rh_state; | ||
117 | /* lower 16 bits contain port status, upper 16 bits the change mask: */ | ||
118 | u32 port_status; | ||
119 | |||
120 | unsigned active:1; | ||
121 | |||
122 | struct list_head ep_list; /* list of EP's with work */ | ||
123 | |||
124 | /* | ||
125 | * The following are owned by spi_thread (may be accessed by | ||
126 | * SPI-thread without acquiring the HCD lock: | ||
127 | */ | ||
128 | u8 rev; /* chip revision */ | ||
129 | u16 frame_number; | ||
130 | /* | ||
131 | * kmalloc'd buffers guaranteed to be in separate (DMA) | ||
132 | * cache-lines: | ||
133 | */ | ||
134 | struct max3421_dma_buf *tx; | ||
135 | struct max3421_dma_buf *rx; | ||
136 | /* | ||
137 | * URB we're currently processing. Must not be reset to NULL | ||
138 | * unless MAX3421E chip is idle: | ||
139 | */ | ||
140 | struct urb *curr_urb; | ||
141 | enum scheduling_pass sched_pass; | ||
142 | struct usb_device *loaded_dev; /* dev that's loaded into the chip */ | ||
143 | int loaded_epnum; /* epnum whose toggles are loaded */ | ||
144 | int urb_done; /* > 0 -> no errors, < 0: errno */ | ||
145 | size_t curr_len; | ||
146 | u8 hien; | ||
147 | u8 mode; | ||
148 | u8 iopins[2]; | ||
149 | unsigned int do_enable_irq:1; | ||
150 | unsigned int do_reset_hcd:1; | ||
151 | unsigned int do_reset_port:1; | ||
152 | unsigned int do_check_unlink:1; | ||
153 | unsigned int do_iopin_update:1; | ||
154 | #ifdef DEBUG | ||
155 | unsigned long err_stat[16]; | ||
156 | #endif | ||
157 | }; | ||
158 | |||
159 | struct max3421_ep { | ||
160 | struct usb_host_endpoint *ep; | ||
161 | struct list_head ep_list; | ||
162 | u32 naks; | ||
163 | u16 last_active; /* frame # this ep was last active */ | ||
164 | enum pkt_state pkt_state; | ||
165 | u8 retries; | ||
166 | u8 retransmit; /* packet needs retransmission */ | ||
167 | }; | ||
168 | |||
169 | static struct max3421_hcd *max3421_hcd_list; | ||
170 | |||
171 | #define MAX3421_FIFO_SIZE 64 | ||
172 | |||
173 | #define MAX3421_SPI_DIR_RD 0 /* read register from MAX3421 */ | ||
174 | #define MAX3421_SPI_DIR_WR 1 /* write register to MAX3421 */ | ||
175 | |||
176 | /* SPI commands: */ | ||
177 | #define MAX3421_SPI_DIR_SHIFT 1 | ||
178 | #define MAX3421_SPI_REG_SHIFT 3 | ||
179 | |||
180 | #define MAX3421_REG_RCVFIFO 1 | ||
181 | #define MAX3421_REG_SNDFIFO 2 | ||
182 | #define MAX3421_REG_SUDFIFO 4 | ||
183 | #define MAX3421_REG_RCVBC 6 | ||
184 | #define MAX3421_REG_SNDBC 7 | ||
185 | #define MAX3421_REG_USBIRQ 13 | ||
186 | #define MAX3421_REG_USBIEN 14 | ||
187 | #define MAX3421_REG_USBCTL 15 | ||
188 | #define MAX3421_REG_CPUCTL 16 | ||
189 | #define MAX3421_REG_PINCTL 17 | ||
190 | #define MAX3421_REG_REVISION 18 | ||
191 | #define MAX3421_REG_IOPINS1 20 | ||
192 | #define MAX3421_REG_IOPINS2 21 | ||
193 | #define MAX3421_REG_GPINIRQ 22 | ||
194 | #define MAX3421_REG_GPINIEN 23 | ||
195 | #define MAX3421_REG_GPINPOL 24 | ||
196 | #define MAX3421_REG_HIRQ 25 | ||
197 | #define MAX3421_REG_HIEN 26 | ||
198 | #define MAX3421_REG_MODE 27 | ||
199 | #define MAX3421_REG_PERADDR 28 | ||
200 | #define MAX3421_REG_HCTL 29 | ||
201 | #define MAX3421_REG_HXFR 30 | ||
202 | #define MAX3421_REG_HRSL 31 | ||
203 | |||
204 | enum { | ||
205 | MAX3421_USBIRQ_OSCOKIRQ_BIT = 0, | ||
206 | MAX3421_USBIRQ_NOVBUSIRQ_BIT = 5, | ||
207 | MAX3421_USBIRQ_VBUSIRQ_BIT | ||
208 | }; | ||
209 | |||
210 | enum { | ||
211 | MAX3421_CPUCTL_IE_BIT = 0, | ||
212 | MAX3421_CPUCTL_PULSEWID0_BIT = 6, | ||
213 | MAX3421_CPUCTL_PULSEWID1_BIT | ||
214 | }; | ||
215 | |||
216 | enum { | ||
217 | MAX3421_USBCTL_PWRDOWN_BIT = 4, | ||
218 | MAX3421_USBCTL_CHIPRES_BIT | ||
219 | }; | ||
220 | |||
221 | enum { | ||
222 | MAX3421_PINCTL_GPXA_BIT = 0, | ||
223 | MAX3421_PINCTL_GPXB_BIT, | ||
224 | MAX3421_PINCTL_POSINT_BIT, | ||
225 | MAX3421_PINCTL_INTLEVEL_BIT, | ||
226 | MAX3421_PINCTL_FDUPSPI_BIT, | ||
227 | MAX3421_PINCTL_EP0INAK_BIT, | ||
228 | MAX3421_PINCTL_EP2INAK_BIT, | ||
229 | MAX3421_PINCTL_EP3INAK_BIT, | ||
230 | }; | ||
231 | |||
232 | enum { | ||
233 | MAX3421_HI_BUSEVENT_BIT = 0, /* bus-reset/-resume */ | ||
234 | MAX3421_HI_RWU_BIT, /* remote wakeup */ | ||
235 | MAX3421_HI_RCVDAV_BIT, /* receive FIFO data available */ | ||
236 | MAX3421_HI_SNDBAV_BIT, /* send buffer available */ | ||
237 | MAX3421_HI_SUSDN_BIT, /* suspend operation done */ | ||
238 | MAX3421_HI_CONDET_BIT, /* peripheral connect/disconnect */ | ||
239 | MAX3421_HI_FRAME_BIT, /* frame generator */ | ||
240 | MAX3421_HI_HXFRDN_BIT, /* host transfer done */ | ||
241 | }; | ||
242 | |||
243 | enum { | ||
244 | MAX3421_HCTL_BUSRST_BIT = 0, | ||
245 | MAX3421_HCTL_FRMRST_BIT, | ||
246 | MAX3421_HCTL_SAMPLEBUS_BIT, | ||
247 | MAX3421_HCTL_SIGRSM_BIT, | ||
248 | MAX3421_HCTL_RCVTOG0_BIT, | ||
249 | MAX3421_HCTL_RCVTOG1_BIT, | ||
250 | MAX3421_HCTL_SNDTOG0_BIT, | ||
251 | MAX3421_HCTL_SNDTOG1_BIT | ||
252 | }; | ||
253 | |||
254 | enum { | ||
255 | MAX3421_MODE_HOST_BIT = 0, | ||
256 | MAX3421_MODE_LOWSPEED_BIT, | ||
257 | MAX3421_MODE_HUBPRE_BIT, | ||
258 | MAX3421_MODE_SOFKAENAB_BIT, | ||
259 | MAX3421_MODE_SEPIRQ_BIT, | ||
260 | MAX3421_MODE_DELAYISO_BIT, | ||
261 | MAX3421_MODE_DMPULLDN_BIT, | ||
262 | MAX3421_MODE_DPPULLDN_BIT | ||
263 | }; | ||
264 | |||
265 | enum { | ||
266 | MAX3421_HRSL_OK = 0, | ||
267 | MAX3421_HRSL_BUSY, | ||
268 | MAX3421_HRSL_BADREQ, | ||
269 | MAX3421_HRSL_UNDEF, | ||
270 | MAX3421_HRSL_NAK, | ||
271 | MAX3421_HRSL_STALL, | ||
272 | MAX3421_HRSL_TOGERR, | ||
273 | MAX3421_HRSL_WRONGPID, | ||
274 | MAX3421_HRSL_BADBC, | ||
275 | MAX3421_HRSL_PIDERR, | ||
276 | MAX3421_HRSL_PKTERR, | ||
277 | MAX3421_HRSL_CRCERR, | ||
278 | MAX3421_HRSL_KERR, | ||
279 | MAX3421_HRSL_JERR, | ||
280 | MAX3421_HRSL_TIMEOUT, | ||
281 | MAX3421_HRSL_BABBLE, | ||
282 | MAX3421_HRSL_RESULT_MASK = 0xf, | ||
283 | MAX3421_HRSL_RCVTOGRD_BIT = 4, | ||
284 | MAX3421_HRSL_SNDTOGRD_BIT, | ||
285 | MAX3421_HRSL_KSTATUS_BIT, | ||
286 | MAX3421_HRSL_JSTATUS_BIT | ||
287 | }; | ||
288 | |||
289 | /* Return same error-codes as ohci.h:cc_to_error: */ | ||
290 | static const int hrsl_to_error[] = { | ||
291 | [MAX3421_HRSL_OK] = 0, | ||
292 | [MAX3421_HRSL_BUSY] = -EINVAL, | ||
293 | [MAX3421_HRSL_BADREQ] = -EINVAL, | ||
294 | [MAX3421_HRSL_UNDEF] = -EINVAL, | ||
295 | [MAX3421_HRSL_NAK] = -EAGAIN, | ||
296 | [MAX3421_HRSL_STALL] = -EPIPE, | ||
297 | [MAX3421_HRSL_TOGERR] = -EILSEQ, | ||
298 | [MAX3421_HRSL_WRONGPID] = -EPROTO, | ||
299 | [MAX3421_HRSL_BADBC] = -EREMOTEIO, | ||
300 | [MAX3421_HRSL_PIDERR] = -EPROTO, | ||
301 | [MAX3421_HRSL_PKTERR] = -EPROTO, | ||
302 | [MAX3421_HRSL_CRCERR] = -EILSEQ, | ||
303 | [MAX3421_HRSL_KERR] = -EIO, | ||
304 | [MAX3421_HRSL_JERR] = -EIO, | ||
305 | [MAX3421_HRSL_TIMEOUT] = -ETIME, | ||
306 | [MAX3421_HRSL_BABBLE] = -EOVERFLOW | ||
307 | }; | ||
308 | |||
309 | /* | ||
310 | * See http://www.beyondlogic.org/usbnutshell/usb4.shtml#Control for a | ||
311 | * reasonable overview of how control transfers use the the IN/OUT | ||
312 | * tokens. | ||
313 | */ | ||
314 | #define MAX3421_HXFR_BULK_IN(ep) (0x00 | (ep)) /* bulk or interrupt */ | ||
315 | #define MAX3421_HXFR_SETUP 0x10 | ||
316 | #define MAX3421_HXFR_BULK_OUT(ep) (0x20 | (ep)) /* bulk or interrupt */ | ||
317 | #define MAX3421_HXFR_ISO_IN(ep) (0x40 | (ep)) | ||
318 | #define MAX3421_HXFR_ISO_OUT(ep) (0x60 | (ep)) | ||
319 | #define MAX3421_HXFR_HS_IN 0x80 /* handshake in */ | ||
320 | #define MAX3421_HXFR_HS_OUT 0xa0 /* handshake out */ | ||
321 | |||
322 | #define field(val, bit) ((val) << (bit)) | ||
323 | |||
324 | static inline s16 | ||
325 | frame_diff(u16 left, u16 right) | ||
326 | { | ||
327 | return ((unsigned) (left - right)) % (USB_MAX_FRAME_NUMBER + 1); | ||
328 | } | ||
329 | |||
330 | static inline struct max3421_hcd * | ||
331 | hcd_to_max3421(struct usb_hcd *hcd) | ||
332 | { | ||
333 | return (struct max3421_hcd *) hcd->hcd_priv; | ||
334 | } | ||
335 | |||
336 | static inline struct usb_hcd * | ||
337 | max3421_to_hcd(struct max3421_hcd *max3421_hcd) | ||
338 | { | ||
339 | return container_of((void *) max3421_hcd, struct usb_hcd, hcd_priv); | ||
340 | } | ||
341 | |||
342 | static u8 | ||
343 | spi_rd8(struct usb_hcd *hcd, unsigned int reg) | ||
344 | { | ||
345 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
346 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
347 | struct spi_transfer transfer; | ||
348 | struct spi_message msg; | ||
349 | |||
350 | memset(&transfer, 0, sizeof(transfer)); | ||
351 | |||
352 | spi_message_init(&msg); | ||
353 | |||
354 | max3421_hcd->tx->data[0] = | ||
355 | (field(reg, MAX3421_SPI_REG_SHIFT) | | ||
356 | field(MAX3421_SPI_DIR_RD, MAX3421_SPI_DIR_SHIFT)); | ||
357 | |||
358 | transfer.tx_buf = max3421_hcd->tx->data; | ||
359 | transfer.rx_buf = max3421_hcd->rx->data; | ||
360 | transfer.len = 2; | ||
361 | |||
362 | spi_message_add_tail(&transfer, &msg); | ||
363 | spi_sync(spi, &msg); | ||
364 | |||
365 | return max3421_hcd->rx->data[1]; | ||
366 | } | ||
367 | |||
368 | static void | ||
369 | spi_wr8(struct usb_hcd *hcd, unsigned int reg, u8 val) | ||
370 | { | ||
371 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
372 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
373 | struct spi_transfer transfer; | ||
374 | struct spi_message msg; | ||
375 | |||
376 | memset(&transfer, 0, sizeof(transfer)); | ||
377 | |||
378 | spi_message_init(&msg); | ||
379 | |||
380 | max3421_hcd->tx->data[0] = | ||
381 | (field(reg, MAX3421_SPI_REG_SHIFT) | | ||
382 | field(MAX3421_SPI_DIR_WR, MAX3421_SPI_DIR_SHIFT)); | ||
383 | max3421_hcd->tx->data[1] = val; | ||
384 | |||
385 | transfer.tx_buf = max3421_hcd->tx->data; | ||
386 | transfer.len = 2; | ||
387 | |||
388 | spi_message_add_tail(&transfer, &msg); | ||
389 | spi_sync(spi, &msg); | ||
390 | } | ||
391 | |||
392 | static void | ||
393 | spi_rd_buf(struct usb_hcd *hcd, unsigned int reg, void *buf, size_t len) | ||
394 | { | ||
395 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
396 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
397 | struct spi_transfer transfer[2]; | ||
398 | struct spi_message msg; | ||
399 | |||
400 | memset(transfer, 0, sizeof(transfer)); | ||
401 | |||
402 | spi_message_init(&msg); | ||
403 | |||
404 | max3421_hcd->tx->data[0] = | ||
405 | (field(reg, MAX3421_SPI_REG_SHIFT) | | ||
406 | field(MAX3421_SPI_DIR_RD, MAX3421_SPI_DIR_SHIFT)); | ||
407 | transfer[0].tx_buf = max3421_hcd->tx->data; | ||
408 | transfer[0].len = 1; | ||
409 | |||
410 | transfer[1].rx_buf = buf; | ||
411 | transfer[1].len = len; | ||
412 | |||
413 | spi_message_add_tail(&transfer[0], &msg); | ||
414 | spi_message_add_tail(&transfer[1], &msg); | ||
415 | spi_sync(spi, &msg); | ||
416 | } | ||
417 | |||
418 | static void | ||
419 | spi_wr_buf(struct usb_hcd *hcd, unsigned int reg, void *buf, size_t len) | ||
420 | { | ||
421 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
422 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
423 | struct spi_transfer transfer[2]; | ||
424 | struct spi_message msg; | ||
425 | |||
426 | memset(transfer, 0, sizeof(transfer)); | ||
427 | |||
428 | spi_message_init(&msg); | ||
429 | |||
430 | max3421_hcd->tx->data[0] = | ||
431 | (field(reg, MAX3421_SPI_REG_SHIFT) | | ||
432 | field(MAX3421_SPI_DIR_WR, MAX3421_SPI_DIR_SHIFT)); | ||
433 | |||
434 | transfer[0].tx_buf = max3421_hcd->tx->data; | ||
435 | transfer[0].len = 1; | ||
436 | |||
437 | transfer[1].tx_buf = buf; | ||
438 | transfer[1].len = len; | ||
439 | |||
440 | spi_message_add_tail(&transfer[0], &msg); | ||
441 | spi_message_add_tail(&transfer[1], &msg); | ||
442 | spi_sync(spi, &msg); | ||
443 | } | ||
444 | |||
445 | /* | ||
446 | * Figure out the correct setting for the LOWSPEED and HUBPRE mode | ||
447 | * bits. The HUBPRE bit needs to be set when MAX3421E operates at | ||
448 | * full speed, but it's talking to a low-speed device (i.e., through a | ||
449 | * hub). Setting that bit ensures that every low-speed packet is | ||
450 | * preceded by a full-speed PRE PID. Possible configurations: | ||
451 | * | ||
452 | * Hub speed: Device speed: => LOWSPEED bit: HUBPRE bit: | ||
453 | * FULL FULL => 0 0 | ||
454 | * FULL LOW => 1 1 | ||
455 | * LOW LOW => 1 0 | ||
456 | * LOW FULL => 1 0 | ||
457 | */ | ||
458 | static void | ||
459 | max3421_set_speed(struct usb_hcd *hcd, struct usb_device *dev) | ||
460 | { | ||
461 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
462 | u8 mode_lowspeed, mode_hubpre, mode = max3421_hcd->mode; | ||
463 | |||
464 | mode_lowspeed = BIT(MAX3421_MODE_LOWSPEED_BIT); | ||
465 | mode_hubpre = BIT(MAX3421_MODE_HUBPRE_BIT); | ||
466 | if (max3421_hcd->port_status & USB_PORT_STAT_LOW_SPEED) { | ||
467 | mode |= mode_lowspeed; | ||
468 | mode &= ~mode_hubpre; | ||
469 | } else if (dev->speed == USB_SPEED_LOW) { | ||
470 | mode |= mode_lowspeed | mode_hubpre; | ||
471 | } else { | ||
472 | mode &= ~(mode_lowspeed | mode_hubpre); | ||
473 | } | ||
474 | if (mode != max3421_hcd->mode) { | ||
475 | max3421_hcd->mode = mode; | ||
476 | spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); | ||
477 | } | ||
478 | |||
479 | } | ||
480 | |||
481 | /* | ||
482 | * Caller must NOT hold HCD spinlock. | ||
483 | */ | ||
484 | static void | ||
485 | max3421_set_address(struct usb_hcd *hcd, struct usb_device *dev, int epnum, | ||
486 | int force_toggles) | ||
487 | { | ||
488 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
489 | int old_epnum, same_ep, rcvtog, sndtog; | ||
490 | struct usb_device *old_dev; | ||
491 | u8 hctl; | ||
492 | |||
493 | old_dev = max3421_hcd->loaded_dev; | ||
494 | old_epnum = max3421_hcd->loaded_epnum; | ||
495 | |||
496 | same_ep = (dev == old_dev && epnum == old_epnum); | ||
497 | if (same_ep && !force_toggles) | ||
498 | return; | ||
499 | |||
500 | if (old_dev && !same_ep) { | ||
501 | /* save the old end-points toggles: */ | ||
502 | u8 hrsl = spi_rd8(hcd, MAX3421_REG_HRSL); | ||
503 | |||
504 | rcvtog = (hrsl >> MAX3421_HRSL_RCVTOGRD_BIT) & 1; | ||
505 | sndtog = (hrsl >> MAX3421_HRSL_SNDTOGRD_BIT) & 1; | ||
506 | |||
507 | /* no locking: HCD (i.e., we) own toggles, don't we? */ | ||
508 | usb_settoggle(old_dev, old_epnum, 0, rcvtog); | ||
509 | usb_settoggle(old_dev, old_epnum, 1, sndtog); | ||
510 | } | ||
511 | /* setup new endpoint's toggle bits: */ | ||
512 | rcvtog = usb_gettoggle(dev, epnum, 0); | ||
513 | sndtog = usb_gettoggle(dev, epnum, 1); | ||
514 | hctl = (BIT(rcvtog + MAX3421_HCTL_RCVTOG0_BIT) | | ||
515 | BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); | ||
516 | |||
517 | max3421_hcd->loaded_epnum = epnum; | ||
518 | spi_wr8(hcd, MAX3421_REG_HCTL, hctl); | ||
519 | |||
520 | /* | ||
521 | * Note: devnum for one and the same device can change during | ||
522 | * address-assignment so it's best to just always load the | ||
523 | * address whenever the end-point changed/was forced. | ||
524 | */ | ||
525 | max3421_hcd->loaded_dev = dev; | ||
526 | spi_wr8(hcd, MAX3421_REG_PERADDR, dev->devnum); | ||
527 | } | ||
528 | |||
529 | static int | ||
530 | max3421_ctrl_setup(struct usb_hcd *hcd, struct urb *urb) | ||
531 | { | ||
532 | spi_wr_buf(hcd, MAX3421_REG_SUDFIFO, urb->setup_packet, 8); | ||
533 | return MAX3421_HXFR_SETUP; | ||
534 | } | ||
535 | |||
536 | static int | ||
537 | max3421_transfer_in(struct usb_hcd *hcd, struct urb *urb) | ||
538 | { | ||
539 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
540 | int epnum = usb_pipeendpoint(urb->pipe); | ||
541 | |||
542 | max3421_hcd->curr_len = 0; | ||
543 | max3421_hcd->hien |= BIT(MAX3421_HI_RCVDAV_BIT); | ||
544 | return MAX3421_HXFR_BULK_IN(epnum); | ||
545 | } | ||
546 | |||
547 | static int | ||
548 | max3421_transfer_out(struct usb_hcd *hcd, struct urb *urb, int fast_retransmit) | ||
549 | { | ||
550 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
551 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
552 | int epnum = usb_pipeendpoint(urb->pipe); | ||
553 | u32 max_packet; | ||
554 | void *src; | ||
555 | |||
556 | src = urb->transfer_buffer + urb->actual_length; | ||
557 | |||
558 | if (fast_retransmit) { | ||
559 | if (max3421_hcd->rev == 0x12) { | ||
560 | /* work around rev 0x12 bug: */ | ||
561 | spi_wr8(hcd, MAX3421_REG_SNDBC, 0); | ||
562 | spi_wr8(hcd, MAX3421_REG_SNDFIFO, ((u8 *) src)[0]); | ||
563 | spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); | ||
564 | } | ||
565 | return MAX3421_HXFR_BULK_OUT(epnum); | ||
566 | } | ||
567 | |||
568 | max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); | ||
569 | |||
570 | if (max_packet > MAX3421_FIFO_SIZE) { | ||
571 | /* | ||
572 | * We do not support isochronous transfers at this | ||
573 | * time. | ||
574 | */ | ||
575 | dev_err(&spi->dev, | ||
576 | "%s: packet-size of %u too big (limit is %u bytes)", | ||
577 | __func__, max_packet, MAX3421_FIFO_SIZE); | ||
578 | max3421_hcd->urb_done = -EMSGSIZE; | ||
579 | return -EMSGSIZE; | ||
580 | } | ||
581 | max3421_hcd->curr_len = min((urb->transfer_buffer_length - | ||
582 | urb->actual_length), max_packet); | ||
583 | |||
584 | spi_wr_buf(hcd, MAX3421_REG_SNDFIFO, src, max3421_hcd->curr_len); | ||
585 | spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); | ||
586 | return MAX3421_HXFR_BULK_OUT(epnum); | ||
587 | } | ||
588 | |||
589 | /* | ||
590 | * Issue the next host-transfer command. | ||
591 | * Caller must NOT hold HCD spinlock. | ||
592 | */ | ||
593 | static void | ||
594 | max3421_next_transfer(struct usb_hcd *hcd, int fast_retransmit) | ||
595 | { | ||
596 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
597 | struct urb *urb = max3421_hcd->curr_urb; | ||
598 | struct max3421_ep *max3421_ep; | ||
599 | int cmd = -EINVAL; | ||
600 | |||
601 | if (!urb) | ||
602 | return; /* nothing to do */ | ||
603 | |||
604 | max3421_ep = urb->ep->hcpriv; | ||
605 | |||
606 | switch (max3421_ep->pkt_state) { | ||
607 | case PKT_STATE_SETUP: | ||
608 | cmd = max3421_ctrl_setup(hcd, urb); | ||
609 | break; | ||
610 | |||
611 | case PKT_STATE_TRANSFER: | ||
612 | if (usb_urb_dir_in(urb)) | ||
613 | cmd = max3421_transfer_in(hcd, urb); | ||
614 | else | ||
615 | cmd = max3421_transfer_out(hcd, urb, fast_retransmit); | ||
616 | break; | ||
617 | |||
618 | case PKT_STATE_TERMINATE: | ||
619 | /* | ||
620 | * IN transfers are terminated with HS_OUT token, | ||
621 | * OUT transfers with HS_IN: | ||
622 | */ | ||
623 | if (usb_urb_dir_in(urb)) | ||
624 | cmd = MAX3421_HXFR_HS_OUT; | ||
625 | else | ||
626 | cmd = MAX3421_HXFR_HS_IN; | ||
627 | break; | ||
628 | } | ||
629 | |||
630 | if (cmd < 0) | ||
631 | return; | ||
632 | |||
633 | /* issue the command and wait for host-xfer-done interrupt: */ | ||
634 | |||
635 | spi_wr8(hcd, MAX3421_REG_HXFR, cmd); | ||
636 | max3421_hcd->hien |= BIT(MAX3421_HI_HXFRDN_BIT); | ||
637 | } | ||
638 | |||
639 | /* | ||
640 | * Find the next URB to process and start its execution. | ||
641 | * | ||
642 | * At this time, we do not anticipate ever connecting a USB hub to the | ||
643 | * MAX3421 chip, so at most USB device can be connected and we can use | ||
644 | * a simplistic scheduler: at the start of a frame, schedule all | ||
645 | * periodic transfers. Once that is done, use the remainder of the | ||
646 | * frame to process non-periodic (bulk & control) transfers. | ||
647 | * | ||
648 | * Preconditions: | ||
649 | * o Caller must NOT hold HCD spinlock. | ||
650 | * o max3421_hcd->curr_urb MUST BE NULL. | ||
651 | * o MAX3421E chip must be idle. | ||
652 | */ | ||
653 | static int | ||
654 | max3421_select_and_start_urb(struct usb_hcd *hcd) | ||
655 | { | ||
656 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
657 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
658 | struct urb *urb, *curr_urb = NULL; | ||
659 | struct max3421_ep *max3421_ep; | ||
660 | int epnum, force_toggles = 0; | ||
661 | struct usb_host_endpoint *ep; | ||
662 | struct list_head *pos; | ||
663 | unsigned long flags; | ||
664 | |||
665 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
666 | |||
667 | for (; | ||
668 | max3421_hcd->sched_pass < SCHED_PASS_DONE; | ||
669 | ++max3421_hcd->sched_pass) | ||
670 | list_for_each(pos, &max3421_hcd->ep_list) { | ||
671 | urb = NULL; | ||
672 | max3421_ep = container_of(pos, struct max3421_ep, | ||
673 | ep_list); | ||
674 | ep = max3421_ep->ep; | ||
675 | |||
676 | switch (usb_endpoint_type(&ep->desc)) { | ||
677 | case USB_ENDPOINT_XFER_ISOC: | ||
678 | case USB_ENDPOINT_XFER_INT: | ||
679 | if (max3421_hcd->sched_pass != | ||
680 | SCHED_PASS_PERIODIC) | ||
681 | continue; | ||
682 | break; | ||
683 | |||
684 | case USB_ENDPOINT_XFER_CONTROL: | ||
685 | case USB_ENDPOINT_XFER_BULK: | ||
686 | if (max3421_hcd->sched_pass != | ||
687 | SCHED_PASS_NON_PERIODIC) | ||
688 | continue; | ||
689 | break; | ||
690 | } | ||
691 | |||
692 | if (list_empty(&ep->urb_list)) | ||
693 | continue; /* nothing to do */ | ||
694 | urb = list_first_entry(&ep->urb_list, struct urb, | ||
695 | urb_list); | ||
696 | if (urb->unlinked) { | ||
697 | dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", | ||
698 | __func__, urb, urb->unlinked); | ||
699 | max3421_hcd->curr_urb = urb; | ||
700 | max3421_hcd->urb_done = 1; | ||
701 | spin_unlock_irqrestore(&max3421_hcd->lock, | ||
702 | flags); | ||
703 | return 1; | ||
704 | } | ||
705 | |||
706 | switch (usb_endpoint_type(&ep->desc)) { | ||
707 | case USB_ENDPOINT_XFER_CONTROL: | ||
708 | /* | ||
709 | * Allow one control transaction per | ||
710 | * frame per endpoint: | ||
711 | */ | ||
712 | if (frame_diff(max3421_ep->last_active, | ||
713 | max3421_hcd->frame_number) == 0) | ||
714 | continue; | ||
715 | break; | ||
716 | |||
717 | case USB_ENDPOINT_XFER_BULK: | ||
718 | if (max3421_ep->retransmit | ||
719 | && (frame_diff(max3421_ep->last_active, | ||
720 | max3421_hcd->frame_number) | ||
721 | == 0)) | ||
722 | /* | ||
723 | * We already tried this EP | ||
724 | * during this frame and got a | ||
725 | * NAK or error; wait for next frame | ||
726 | */ | ||
727 | continue; | ||
728 | break; | ||
729 | |||
730 | case USB_ENDPOINT_XFER_ISOC: | ||
731 | case USB_ENDPOINT_XFER_INT: | ||
732 | if (frame_diff(max3421_hcd->frame_number, | ||
733 | max3421_ep->last_active) | ||
734 | < urb->interval) | ||
735 | /* | ||
736 | * We already processed this | ||
737 | * end-point in the current | ||
738 | * frame | ||
739 | */ | ||
740 | continue; | ||
741 | break; | ||
742 | } | ||
743 | |||
744 | /* move current ep to tail: */ | ||
745 | list_move_tail(pos, &max3421_hcd->ep_list); | ||
746 | curr_urb = urb; | ||
747 | goto done; | ||
748 | } | ||
749 | done: | ||
750 | if (!curr_urb) { | ||
751 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
752 | return 0; | ||
753 | } | ||
754 | |||
755 | urb = max3421_hcd->curr_urb = curr_urb; | ||
756 | epnum = usb_endpoint_num(&urb->ep->desc); | ||
757 | if (max3421_ep->retransmit) | ||
758 | /* restart (part of) a USB transaction: */ | ||
759 | max3421_ep->retransmit = 0; | ||
760 | else { | ||
761 | /* start USB transaction: */ | ||
762 | if (usb_endpoint_xfer_control(&ep->desc)) { | ||
763 | /* | ||
764 | * See USB 2.0 spec section 8.6.1 | ||
765 | * Initialization via SETUP Token: | ||
766 | */ | ||
767 | usb_settoggle(urb->dev, epnum, 0, 1); | ||
768 | usb_settoggle(urb->dev, epnum, 1, 1); | ||
769 | max3421_ep->pkt_state = PKT_STATE_SETUP; | ||
770 | force_toggles = 1; | ||
771 | } else | ||
772 | max3421_ep->pkt_state = PKT_STATE_TRANSFER; | ||
773 | } | ||
774 | |||
775 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
776 | |||
777 | max3421_ep->last_active = max3421_hcd->frame_number; | ||
778 | max3421_set_address(hcd, urb->dev, epnum, force_toggles); | ||
779 | max3421_set_speed(hcd, urb->dev); | ||
780 | max3421_next_transfer(hcd, 0); | ||
781 | return 1; | ||
782 | } | ||
783 | |||
784 | /* | ||
785 | * Check all endpoints for URBs that got unlinked. | ||
786 | * | ||
787 | * Caller must NOT hold HCD spinlock. | ||
788 | */ | ||
789 | static int | ||
790 | max3421_check_unlink(struct usb_hcd *hcd) | ||
791 | { | ||
792 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
793 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
794 | struct list_head *pos, *upos, *next_upos; | ||
795 | struct max3421_ep *max3421_ep; | ||
796 | struct usb_host_endpoint *ep; | ||
797 | struct urb *urb; | ||
798 | unsigned long flags; | ||
799 | int retval = 0; | ||
800 | |||
801 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
802 | list_for_each(pos, &max3421_hcd->ep_list) { | ||
803 | max3421_ep = container_of(pos, struct max3421_ep, ep_list); | ||
804 | ep = max3421_ep->ep; | ||
805 | list_for_each_safe(upos, next_upos, &ep->urb_list) { | ||
806 | urb = container_of(upos, struct urb, urb_list); | ||
807 | if (urb->unlinked) { | ||
808 | retval = 1; | ||
809 | dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", | ||
810 | __func__, urb, urb->unlinked); | ||
811 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
812 | spin_unlock_irqrestore(&max3421_hcd->lock, | ||
813 | flags); | ||
814 | usb_hcd_giveback_urb(hcd, urb, 0); | ||
815 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
816 | } | ||
817 | } | ||
818 | } | ||
819 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
820 | return retval; | ||
821 | } | ||
822 | |||
823 | /* | ||
824 | * Caller must NOT hold HCD spinlock. | ||
825 | */ | ||
826 | static void | ||
827 | max3421_slow_retransmit(struct usb_hcd *hcd) | ||
828 | { | ||
829 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
830 | struct urb *urb = max3421_hcd->curr_urb; | ||
831 | struct max3421_ep *max3421_ep; | ||
832 | |||
833 | max3421_ep = urb->ep->hcpriv; | ||
834 | max3421_ep->retransmit = 1; | ||
835 | max3421_hcd->curr_urb = NULL; | ||
836 | } | ||
837 | |||
838 | /* | ||
839 | * Caller must NOT hold HCD spinlock. | ||
840 | */ | ||
841 | static void | ||
842 | max3421_recv_data_available(struct usb_hcd *hcd) | ||
843 | { | ||
844 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
845 | struct urb *urb = max3421_hcd->curr_urb; | ||
846 | size_t remaining, transfer_size; | ||
847 | u8 rcvbc; | ||
848 | |||
849 | rcvbc = spi_rd8(hcd, MAX3421_REG_RCVBC); | ||
850 | |||
851 | if (rcvbc > MAX3421_FIFO_SIZE) | ||
852 | rcvbc = MAX3421_FIFO_SIZE; | ||
853 | if (urb->actual_length >= urb->transfer_buffer_length) | ||
854 | remaining = 0; | ||
855 | else | ||
856 | remaining = urb->transfer_buffer_length - urb->actual_length; | ||
857 | transfer_size = rcvbc; | ||
858 | if (transfer_size > remaining) | ||
859 | transfer_size = remaining; | ||
860 | if (transfer_size > 0) { | ||
861 | void *dst = urb->transfer_buffer + urb->actual_length; | ||
862 | |||
863 | spi_rd_buf(hcd, MAX3421_REG_RCVFIFO, dst, transfer_size); | ||
864 | urb->actual_length += transfer_size; | ||
865 | max3421_hcd->curr_len = transfer_size; | ||
866 | } | ||
867 | |||
868 | /* ack the RCVDAV irq now that the FIFO has been read: */ | ||
869 | spi_wr8(hcd, MAX3421_REG_HIRQ, BIT(MAX3421_HI_RCVDAV_BIT)); | ||
870 | } | ||
871 | |||
872 | static void | ||
873 | max3421_handle_error(struct usb_hcd *hcd, u8 hrsl) | ||
874 | { | ||
875 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
876 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
877 | u8 result_code = hrsl & MAX3421_HRSL_RESULT_MASK; | ||
878 | struct urb *urb = max3421_hcd->curr_urb; | ||
879 | struct max3421_ep *max3421_ep = urb->ep->hcpriv; | ||
880 | int switch_sndfifo; | ||
881 | |||
882 | /* | ||
883 | * If an OUT command results in any response other than OK | ||
884 | * (i.e., error or NAK), we have to perform a dummy-write to | ||
885 | * SNDBC so the FIFO gets switched back to us. Otherwise, we | ||
886 | * get out of sync with the SNDFIFO double buffer. | ||
887 | */ | ||
888 | switch_sndfifo = (max3421_ep->pkt_state == PKT_STATE_TRANSFER && | ||
889 | usb_urb_dir_out(urb)); | ||
890 | |||
891 | switch (result_code) { | ||
892 | case MAX3421_HRSL_OK: | ||
893 | return; /* this shouldn't happen */ | ||
894 | |||
895 | case MAX3421_HRSL_WRONGPID: /* received wrong PID */ | ||
896 | case MAX3421_HRSL_BUSY: /* SIE busy */ | ||
897 | case MAX3421_HRSL_BADREQ: /* bad val in HXFR */ | ||
898 | case MAX3421_HRSL_UNDEF: /* reserved */ | ||
899 | case MAX3421_HRSL_KERR: /* K-state instead of response */ | ||
900 | case MAX3421_HRSL_JERR: /* J-state instead of response */ | ||
901 | /* | ||
902 | * packet experienced an error that we cannot recover | ||
903 | * from; report error | ||
904 | */ | ||
905 | max3421_hcd->urb_done = hrsl_to_error[result_code]; | ||
906 | dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", | ||
907 | __func__, hrsl); | ||
908 | break; | ||
909 | |||
910 | case MAX3421_HRSL_TOGERR: | ||
911 | if (usb_urb_dir_in(urb)) | ||
912 | ; /* don't do anything (device will switch toggle) */ | ||
913 | else { | ||
914 | /* flip the send toggle bit: */ | ||
915 | int sndtog = (hrsl >> MAX3421_HRSL_SNDTOGRD_BIT) & 1; | ||
916 | |||
917 | sndtog ^= 1; | ||
918 | spi_wr8(hcd, MAX3421_REG_HCTL, | ||
919 | BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); | ||
920 | } | ||
921 | /* FALL THROUGH */ | ||
922 | case MAX3421_HRSL_BADBC: /* bad byte count */ | ||
923 | case MAX3421_HRSL_PIDERR: /* received PID is corrupted */ | ||
924 | case MAX3421_HRSL_PKTERR: /* packet error (stuff, EOP) */ | ||
925 | case MAX3421_HRSL_CRCERR: /* CRC error */ | ||
926 | case MAX3421_HRSL_BABBLE: /* device talked too long */ | ||
927 | case MAX3421_HRSL_TIMEOUT: | ||
928 | if (max3421_ep->retries++ < USB_MAX_RETRIES) | ||
929 | /* retry the packet again in the next frame */ | ||
930 | max3421_slow_retransmit(hcd); | ||
931 | else { | ||
932 | /* Based on ohci.h cc_to_err[]: */ | ||
933 | max3421_hcd->urb_done = hrsl_to_error[result_code]; | ||
934 | dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", | ||
935 | __func__, hrsl); | ||
936 | } | ||
937 | break; | ||
938 | |||
939 | case MAX3421_HRSL_STALL: | ||
940 | dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", | ||
941 | __func__, hrsl); | ||
942 | max3421_hcd->urb_done = hrsl_to_error[result_code]; | ||
943 | break; | ||
944 | |||
945 | case MAX3421_HRSL_NAK: | ||
946 | /* | ||
947 | * Device wasn't ready for data or has no data | ||
948 | * available: retry the packet again. | ||
949 | */ | ||
950 | if (max3421_ep->naks++ < NAK_MAX_FAST_RETRANSMITS) { | ||
951 | max3421_next_transfer(hcd, 1); | ||
952 | switch_sndfifo = 0; | ||
953 | } else | ||
954 | max3421_slow_retransmit(hcd); | ||
955 | break; | ||
956 | } | ||
957 | if (switch_sndfifo) | ||
958 | spi_wr8(hcd, MAX3421_REG_SNDBC, 0); | ||
959 | } | ||
960 | |||
961 | /* | ||
962 | * Caller must NOT hold HCD spinlock. | ||
963 | */ | ||
964 | static int | ||
965 | max3421_transfer_in_done(struct usb_hcd *hcd, struct urb *urb) | ||
966 | { | ||
967 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
968 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
969 | u32 max_packet; | ||
970 | |||
971 | if (urb->actual_length >= urb->transfer_buffer_length) | ||
972 | return 1; /* read is complete, so we're done */ | ||
973 | |||
974 | /* | ||
975 | * USB 2.0 Section 5.3.2 Pipes: packets must be full size | ||
976 | * except for last one. | ||
977 | */ | ||
978 | max_packet = usb_maxpacket(urb->dev, urb->pipe, 0); | ||
979 | if (max_packet > MAX3421_FIFO_SIZE) { | ||
980 | /* | ||
981 | * We do not support isochronous transfers at this | ||
982 | * time... | ||
983 | */ | ||
984 | dev_err(&spi->dev, | ||
985 | "%s: packet-size of %u too big (limit is %u bytes)", | ||
986 | __func__, max_packet, MAX3421_FIFO_SIZE); | ||
987 | return -EINVAL; | ||
988 | } | ||
989 | |||
990 | if (max3421_hcd->curr_len < max_packet) { | ||
991 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
992 | /* | ||
993 | * remaining > 0 and received an | ||
994 | * unexpected partial packet -> | ||
995 | * error | ||
996 | */ | ||
997 | return -EREMOTEIO; | ||
998 | } else | ||
999 | /* short read, but it's OK */ | ||
1000 | return 1; | ||
1001 | } | ||
1002 | return 0; /* not done */ | ||
1003 | } | ||
1004 | |||
1005 | /* | ||
1006 | * Caller must NOT hold HCD spinlock. | ||
1007 | */ | ||
1008 | static int | ||
1009 | max3421_transfer_out_done(struct usb_hcd *hcd, struct urb *urb) | ||
1010 | { | ||
1011 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1012 | |||
1013 | urb->actual_length += max3421_hcd->curr_len; | ||
1014 | if (urb->actual_length < urb->transfer_buffer_length) | ||
1015 | return 0; | ||
1016 | if (urb->transfer_flags & URB_ZERO_PACKET) { | ||
1017 | /* | ||
1018 | * Some hardware needs a zero-size packet at the end | ||
1019 | * of a bulk-out transfer if the last transfer was a | ||
1020 | * full-sized packet (i.e., such hardware use < | ||
1021 | * max_packet as an indicator that the end of the | ||
1022 | * packet has been reached). | ||
1023 | */ | ||
1024 | u32 max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); | ||
1025 | |||
1026 | if (max3421_hcd->curr_len == max_packet) | ||
1027 | return 0; | ||
1028 | } | ||
1029 | return 1; | ||
1030 | } | ||
1031 | |||
1032 | /* | ||
1033 | * Caller must NOT hold HCD spinlock. | ||
1034 | */ | ||
1035 | static void | ||
1036 | max3421_host_transfer_done(struct usb_hcd *hcd) | ||
1037 | { | ||
1038 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1039 | struct urb *urb = max3421_hcd->curr_urb; | ||
1040 | struct max3421_ep *max3421_ep; | ||
1041 | u8 result_code, hrsl; | ||
1042 | int urb_done = 0; | ||
1043 | |||
1044 | max3421_hcd->hien &= ~(BIT(MAX3421_HI_HXFRDN_BIT) | | ||
1045 | BIT(MAX3421_HI_RCVDAV_BIT)); | ||
1046 | |||
1047 | hrsl = spi_rd8(hcd, MAX3421_REG_HRSL); | ||
1048 | result_code = hrsl & MAX3421_HRSL_RESULT_MASK; | ||
1049 | |||
1050 | #ifdef DEBUG | ||
1051 | ++max3421_hcd->err_stat[result_code]; | ||
1052 | #endif | ||
1053 | |||
1054 | max3421_ep = urb->ep->hcpriv; | ||
1055 | |||
1056 | if (unlikely(result_code != MAX3421_HRSL_OK)) { | ||
1057 | max3421_handle_error(hcd, hrsl); | ||
1058 | return; | ||
1059 | } | ||
1060 | |||
1061 | max3421_ep->naks = 0; | ||
1062 | max3421_ep->retries = 0; | ||
1063 | switch (max3421_ep->pkt_state) { | ||
1064 | |||
1065 | case PKT_STATE_SETUP: | ||
1066 | if (urb->transfer_buffer_length > 0) | ||
1067 | max3421_ep->pkt_state = PKT_STATE_TRANSFER; | ||
1068 | else | ||
1069 | max3421_ep->pkt_state = PKT_STATE_TERMINATE; | ||
1070 | break; | ||
1071 | |||
1072 | case PKT_STATE_TRANSFER: | ||
1073 | if (usb_urb_dir_in(urb)) | ||
1074 | urb_done = max3421_transfer_in_done(hcd, urb); | ||
1075 | else | ||
1076 | urb_done = max3421_transfer_out_done(hcd, urb); | ||
1077 | if (urb_done > 0 && usb_pipetype(urb->pipe) == PIPE_CONTROL) { | ||
1078 | /* | ||
1079 | * We aren't really done - we still need to | ||
1080 | * terminate the control transfer: | ||
1081 | */ | ||
1082 | max3421_hcd->urb_done = urb_done = 0; | ||
1083 | max3421_ep->pkt_state = PKT_STATE_TERMINATE; | ||
1084 | } | ||
1085 | break; | ||
1086 | |||
1087 | case PKT_STATE_TERMINATE: | ||
1088 | urb_done = 1; | ||
1089 | break; | ||
1090 | } | ||
1091 | |||
1092 | if (urb_done) | ||
1093 | max3421_hcd->urb_done = urb_done; | ||
1094 | else | ||
1095 | max3421_next_transfer(hcd, 0); | ||
1096 | } | ||
1097 | |||
1098 | /* | ||
1099 | * Caller must NOT hold HCD spinlock. | ||
1100 | */ | ||
1101 | static void | ||
1102 | max3421_detect_conn(struct usb_hcd *hcd) | ||
1103 | { | ||
1104 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1105 | unsigned int jk, have_conn = 0; | ||
1106 | u32 old_port_status, chg; | ||
1107 | unsigned long flags; | ||
1108 | u8 hrsl, mode; | ||
1109 | |||
1110 | hrsl = spi_rd8(hcd, MAX3421_REG_HRSL); | ||
1111 | |||
1112 | jk = ((((hrsl >> MAX3421_HRSL_JSTATUS_BIT) & 1) << 0) | | ||
1113 | (((hrsl >> MAX3421_HRSL_KSTATUS_BIT) & 1) << 1)); | ||
1114 | |||
1115 | mode = max3421_hcd->mode; | ||
1116 | |||
1117 | switch (jk) { | ||
1118 | case 0x0: /* SE0: disconnect */ | ||
1119 | /* | ||
1120 | * Turn off SOFKAENAB bit to avoid getting interrupt | ||
1121 | * every milli-second: | ||
1122 | */ | ||
1123 | mode &= ~BIT(MAX3421_MODE_SOFKAENAB_BIT); | ||
1124 | break; | ||
1125 | |||
1126 | case 0x1: /* J=0,K=1: low-speed (in full-speed or vice versa) */ | ||
1127 | case 0x2: /* J=1,K=0: full-speed (in full-speed or vice versa) */ | ||
1128 | if (jk == 0x2) | ||
1129 | /* need to switch to the other speed: */ | ||
1130 | mode ^= BIT(MAX3421_MODE_LOWSPEED_BIT); | ||
1131 | /* turn on SOFKAENAB bit: */ | ||
1132 | mode |= BIT(MAX3421_MODE_SOFKAENAB_BIT); | ||
1133 | have_conn = 1; | ||
1134 | break; | ||
1135 | |||
1136 | case 0x3: /* illegal */ | ||
1137 | break; | ||
1138 | } | ||
1139 | |||
1140 | max3421_hcd->mode = mode; | ||
1141 | spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); | ||
1142 | |||
1143 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1144 | old_port_status = max3421_hcd->port_status; | ||
1145 | if (have_conn) | ||
1146 | max3421_hcd->port_status |= USB_PORT_STAT_CONNECTION; | ||
1147 | else | ||
1148 | max3421_hcd->port_status &= ~USB_PORT_STAT_CONNECTION; | ||
1149 | if (mode & BIT(MAX3421_MODE_LOWSPEED_BIT)) | ||
1150 | max3421_hcd->port_status |= USB_PORT_STAT_LOW_SPEED; | ||
1151 | else | ||
1152 | max3421_hcd->port_status &= ~USB_PORT_STAT_LOW_SPEED; | ||
1153 | chg = (old_port_status ^ max3421_hcd->port_status); | ||
1154 | max3421_hcd->port_status |= chg << 16; | ||
1155 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1156 | } | ||
1157 | |||
1158 | static irqreturn_t | ||
1159 | max3421_irq_handler(int irq, void *dev_id) | ||
1160 | { | ||
1161 | struct usb_hcd *hcd = dev_id; | ||
1162 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
1163 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1164 | |||
1165 | if (max3421_hcd->spi_thread && | ||
1166 | max3421_hcd->spi_thread->state != TASK_RUNNING) | ||
1167 | wake_up_process(max3421_hcd->spi_thread); | ||
1168 | if (!max3421_hcd->do_enable_irq) { | ||
1169 | max3421_hcd->do_enable_irq = 1; | ||
1170 | disable_irq_nosync(spi->irq); | ||
1171 | } | ||
1172 | return IRQ_HANDLED; | ||
1173 | } | ||
1174 | |||
1175 | #ifdef DEBUG | ||
1176 | |||
1177 | static void | ||
1178 | dump_eps(struct usb_hcd *hcd) | ||
1179 | { | ||
1180 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1181 | struct max3421_ep *max3421_ep; | ||
1182 | struct usb_host_endpoint *ep; | ||
1183 | struct list_head *pos, *upos; | ||
1184 | char ubuf[512], *dp, *end; | ||
1185 | unsigned long flags; | ||
1186 | struct urb *urb; | ||
1187 | int epnum, ret; | ||
1188 | |||
1189 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1190 | list_for_each(pos, &max3421_hcd->ep_list) { | ||
1191 | max3421_ep = container_of(pos, struct max3421_ep, ep_list); | ||
1192 | ep = max3421_ep->ep; | ||
1193 | |||
1194 | dp = ubuf; | ||
1195 | end = dp + sizeof(ubuf); | ||
1196 | *dp = '\0'; | ||
1197 | list_for_each(upos, &ep->urb_list) { | ||
1198 | urb = container_of(upos, struct urb, urb_list); | ||
1199 | ret = snprintf(dp, end - dp, " %p(%d.%s %d/%d)", urb, | ||
1200 | usb_pipetype(urb->pipe), | ||
1201 | usb_urb_dir_in(urb) ? "IN" : "OUT", | ||
1202 | urb->actual_length, | ||
1203 | urb->transfer_buffer_length); | ||
1204 | if (ret < 0 || ret >= end - dp) | ||
1205 | break; /* error or buffer full */ | ||
1206 | dp += ret; | ||
1207 | } | ||
1208 | |||
1209 | epnum = usb_endpoint_num(&ep->desc); | ||
1210 | pr_info("EP%0u %u lst %04u rtr %u nak %6u rxmt %u: %s\n", | ||
1211 | epnum, max3421_ep->pkt_state, max3421_ep->last_active, | ||
1212 | max3421_ep->retries, max3421_ep->naks, | ||
1213 | max3421_ep->retransmit, ubuf); | ||
1214 | } | ||
1215 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1216 | } | ||
1217 | |||
1218 | #endif /* DEBUG */ | ||
1219 | |||
1220 | /* Return zero if no work was performed, 1 otherwise. */ | ||
1221 | static int | ||
1222 | max3421_handle_irqs(struct usb_hcd *hcd) | ||
1223 | { | ||
1224 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1225 | u32 chg, old_port_status; | ||
1226 | unsigned long flags; | ||
1227 | u8 hirq; | ||
1228 | |||
1229 | /* | ||
1230 | * Read and ack pending interrupts (CPU must never | ||
1231 | * clear SNDBAV directly and RCVDAV must be cleared by | ||
1232 | * max3421_recv_data_available()!): | ||
1233 | */ | ||
1234 | hirq = spi_rd8(hcd, MAX3421_REG_HIRQ); | ||
1235 | hirq &= max3421_hcd->hien; | ||
1236 | if (!hirq) | ||
1237 | return 0; | ||
1238 | |||
1239 | spi_wr8(hcd, MAX3421_REG_HIRQ, | ||
1240 | hirq & ~(BIT(MAX3421_HI_SNDBAV_BIT) | | ||
1241 | BIT(MAX3421_HI_RCVDAV_BIT))); | ||
1242 | |||
1243 | if (hirq & BIT(MAX3421_HI_FRAME_BIT)) { | ||
1244 | max3421_hcd->frame_number = ((max3421_hcd->frame_number + 1) | ||
1245 | & USB_MAX_FRAME_NUMBER); | ||
1246 | max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; | ||
1247 | } | ||
1248 | |||
1249 | if (hirq & BIT(MAX3421_HI_RCVDAV_BIT)) | ||
1250 | max3421_recv_data_available(hcd); | ||
1251 | |||
1252 | if (hirq & BIT(MAX3421_HI_HXFRDN_BIT)) | ||
1253 | max3421_host_transfer_done(hcd); | ||
1254 | |||
1255 | if (hirq & BIT(MAX3421_HI_CONDET_BIT)) | ||
1256 | max3421_detect_conn(hcd); | ||
1257 | |||
1258 | /* | ||
1259 | * Now process interrupts that may affect HCD state | ||
1260 | * other than the end-points: | ||
1261 | */ | ||
1262 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1263 | |||
1264 | old_port_status = max3421_hcd->port_status; | ||
1265 | if (hirq & BIT(MAX3421_HI_BUSEVENT_BIT)) { | ||
1266 | if (max3421_hcd->port_status & USB_PORT_STAT_RESET) { | ||
1267 | /* BUSEVENT due to completion of Bus Reset */ | ||
1268 | max3421_hcd->port_status &= ~USB_PORT_STAT_RESET; | ||
1269 | max3421_hcd->port_status |= USB_PORT_STAT_ENABLE; | ||
1270 | } else { | ||
1271 | /* BUSEVENT due to completion of Bus Resume */ | ||
1272 | pr_info("%s: BUSEVENT Bus Resume Done\n", __func__); | ||
1273 | } | ||
1274 | } | ||
1275 | if (hirq & BIT(MAX3421_HI_RWU_BIT)) | ||
1276 | pr_info("%s: RWU\n", __func__); | ||
1277 | if (hirq & BIT(MAX3421_HI_SUSDN_BIT)) | ||
1278 | pr_info("%s: SUSDN\n", __func__); | ||
1279 | |||
1280 | chg = (old_port_status ^ max3421_hcd->port_status); | ||
1281 | max3421_hcd->port_status |= chg << 16; | ||
1282 | |||
1283 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1284 | |||
1285 | #ifdef DEBUG | ||
1286 | { | ||
1287 | static unsigned long last_time; | ||
1288 | char sbuf[16 * 16], *dp, *end; | ||
1289 | int i; | ||
1290 | |||
1291 | if (jiffies - last_time > 5*HZ) { | ||
1292 | dp = sbuf; | ||
1293 | end = sbuf + sizeof(sbuf); | ||
1294 | *dp = '\0'; | ||
1295 | for (i = 0; i < 16; ++i) { | ||
1296 | int ret = snprintf(dp, end - dp, " %lu", | ||
1297 | max3421_hcd->err_stat[i]); | ||
1298 | if (ret < 0 || ret >= end - dp) | ||
1299 | break; /* error or buffer full */ | ||
1300 | dp += ret; | ||
1301 | } | ||
1302 | pr_info("%s: hrsl_stats %s\n", __func__, sbuf); | ||
1303 | memset(max3421_hcd->err_stat, 0, | ||
1304 | sizeof(max3421_hcd->err_stat)); | ||
1305 | last_time = jiffies; | ||
1306 | |||
1307 | dump_eps(hcd); | ||
1308 | } | ||
1309 | } | ||
1310 | #endif | ||
1311 | return 1; | ||
1312 | } | ||
1313 | |||
1314 | static int | ||
1315 | max3421_reset_hcd(struct usb_hcd *hcd) | ||
1316 | { | ||
1317 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
1318 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1319 | int timeout; | ||
1320 | |||
1321 | /* perform a chip reset and wait for OSCIRQ signal to appear: */ | ||
1322 | spi_wr8(hcd, MAX3421_REG_USBCTL, BIT(MAX3421_USBCTL_CHIPRES_BIT)); | ||
1323 | /* clear reset: */ | ||
1324 | spi_wr8(hcd, MAX3421_REG_USBCTL, 0); | ||
1325 | timeout = 1000; | ||
1326 | while (1) { | ||
1327 | if (spi_rd8(hcd, MAX3421_REG_USBIRQ) | ||
1328 | & BIT(MAX3421_USBIRQ_OSCOKIRQ_BIT)) | ||
1329 | break; | ||
1330 | if (--timeout < 0) { | ||
1331 | dev_err(&spi->dev, | ||
1332 | "timed out waiting for oscillator OK signal"); | ||
1333 | return 1; | ||
1334 | } | ||
1335 | cond_resched(); | ||
1336 | } | ||
1337 | |||
1338 | /* | ||
1339 | * Turn on host mode, automatic generation of SOF packets, and | ||
1340 | * enable pull-down registers on DM/DP: | ||
1341 | */ | ||
1342 | max3421_hcd->mode = (BIT(MAX3421_MODE_HOST_BIT) | | ||
1343 | BIT(MAX3421_MODE_SOFKAENAB_BIT) | | ||
1344 | BIT(MAX3421_MODE_DMPULLDN_BIT) | | ||
1345 | BIT(MAX3421_MODE_DPPULLDN_BIT)); | ||
1346 | spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); | ||
1347 | |||
1348 | /* reset frame-number: */ | ||
1349 | max3421_hcd->frame_number = USB_MAX_FRAME_NUMBER; | ||
1350 | spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_FRMRST_BIT)); | ||
1351 | |||
1352 | /* sample the state of the D+ and D- lines */ | ||
1353 | spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_SAMPLEBUS_BIT)); | ||
1354 | max3421_detect_conn(hcd); | ||
1355 | |||
1356 | /* enable frame, connection-detected, and bus-event interrupts: */ | ||
1357 | max3421_hcd->hien = (BIT(MAX3421_HI_FRAME_BIT) | | ||
1358 | BIT(MAX3421_HI_CONDET_BIT) | | ||
1359 | BIT(MAX3421_HI_BUSEVENT_BIT)); | ||
1360 | spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); | ||
1361 | |||
1362 | /* enable interrupts: */ | ||
1363 | spi_wr8(hcd, MAX3421_REG_CPUCTL, BIT(MAX3421_CPUCTL_IE_BIT)); | ||
1364 | return 1; | ||
1365 | } | ||
1366 | |||
1367 | static int | ||
1368 | max3421_urb_done(struct usb_hcd *hcd) | ||
1369 | { | ||
1370 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1371 | unsigned long flags; | ||
1372 | struct urb *urb; | ||
1373 | int status; | ||
1374 | |||
1375 | status = max3421_hcd->urb_done; | ||
1376 | max3421_hcd->urb_done = 0; | ||
1377 | if (status > 0) | ||
1378 | status = 0; | ||
1379 | urb = max3421_hcd->curr_urb; | ||
1380 | if (urb) { | ||
1381 | max3421_hcd->curr_urb = NULL; | ||
1382 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1383 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
1384 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1385 | |||
1386 | /* must be called without the HCD spinlock: */ | ||
1387 | usb_hcd_giveback_urb(hcd, urb, status); | ||
1388 | } | ||
1389 | return 1; | ||
1390 | } | ||
1391 | |||
1392 | static int | ||
1393 | max3421_spi_thread(void *dev_id) | ||
1394 | { | ||
1395 | struct usb_hcd *hcd = dev_id; | ||
1396 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
1397 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1398 | int i, i_worked = 1; | ||
1399 | |||
1400 | /* set full-duplex SPI mode, low-active interrupt pin: */ | ||
1401 | spi_wr8(hcd, MAX3421_REG_PINCTL, | ||
1402 | (BIT(MAX3421_PINCTL_FDUPSPI_BIT) | /* full-duplex */ | ||
1403 | BIT(MAX3421_PINCTL_INTLEVEL_BIT))); /* low-active irq */ | ||
1404 | |||
1405 | while (!kthread_should_stop()) { | ||
1406 | max3421_hcd->rev = spi_rd8(hcd, MAX3421_REG_REVISION); | ||
1407 | if (max3421_hcd->rev == 0x12 || max3421_hcd->rev == 0x13) | ||
1408 | break; | ||
1409 | dev_err(&spi->dev, "bad rev 0x%02x", max3421_hcd->rev); | ||
1410 | msleep(10000); | ||
1411 | } | ||
1412 | dev_info(&spi->dev, "rev 0x%x, SPI clk %dHz, bpw %u, irq %d\n", | ||
1413 | max3421_hcd->rev, spi->max_speed_hz, spi->bits_per_word, | ||
1414 | spi->irq); | ||
1415 | |||
1416 | while (!kthread_should_stop()) { | ||
1417 | if (!i_worked) { | ||
1418 | /* | ||
1419 | * We'll be waiting for wakeups from the hard | ||
1420 | * interrupt handler, so now is a good time to | ||
1421 | * sync our hien with the chip: | ||
1422 | */ | ||
1423 | spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); | ||
1424 | |||
1425 | set_current_state(TASK_INTERRUPTIBLE); | ||
1426 | if (max3421_hcd->do_enable_irq) { | ||
1427 | max3421_hcd->do_enable_irq = 0; | ||
1428 | enable_irq(spi->irq); | ||
1429 | } | ||
1430 | schedule(); | ||
1431 | __set_current_state(TASK_RUNNING); | ||
1432 | } | ||
1433 | |||
1434 | i_worked = 0; | ||
1435 | |||
1436 | if (max3421_hcd->urb_done) | ||
1437 | i_worked |= max3421_urb_done(hcd); | ||
1438 | else if (max3421_handle_irqs(hcd)) | ||
1439 | i_worked = 1; | ||
1440 | else if (!max3421_hcd->curr_urb) | ||
1441 | i_worked |= max3421_select_and_start_urb(hcd); | ||
1442 | |||
1443 | if (max3421_hcd->do_reset_hcd) { | ||
1444 | /* reset the HCD: */ | ||
1445 | max3421_hcd->do_reset_hcd = 0; | ||
1446 | i_worked |= max3421_reset_hcd(hcd); | ||
1447 | } | ||
1448 | if (max3421_hcd->do_reset_port) { | ||
1449 | /* perform a USB bus reset: */ | ||
1450 | max3421_hcd->do_reset_port = 0; | ||
1451 | spi_wr8(hcd, MAX3421_REG_HCTL, | ||
1452 | BIT(MAX3421_HCTL_BUSRST_BIT)); | ||
1453 | i_worked = 1; | ||
1454 | } | ||
1455 | if (max3421_hcd->do_check_unlink) { | ||
1456 | max3421_hcd->do_check_unlink = 0; | ||
1457 | i_worked |= max3421_check_unlink(hcd); | ||
1458 | } | ||
1459 | if (max3421_hcd->do_iopin_update) { | ||
1460 | /* | ||
1461 | * IOPINS1/IOPINS2 do not auto-increment, so we can't | ||
1462 | * use spi_wr_buf(). | ||
1463 | */ | ||
1464 | for (i = 0; i < ARRAY_SIZE(max3421_hcd->iopins); ++i) { | ||
1465 | u8 val = spi_rd8(hcd, MAX3421_REG_IOPINS1); | ||
1466 | |||
1467 | val = ((val & 0xf0) | | ||
1468 | (max3421_hcd->iopins[i] & 0x0f)); | ||
1469 | spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val); | ||
1470 | max3421_hcd->iopins[i] = val; | ||
1471 | } | ||
1472 | max3421_hcd->do_iopin_update = 0; | ||
1473 | i_worked = 1; | ||
1474 | } | ||
1475 | } | ||
1476 | set_current_state(TASK_RUNNING); | ||
1477 | dev_info(&spi->dev, "SPI thread exiting"); | ||
1478 | return 0; | ||
1479 | } | ||
1480 | |||
1481 | static int | ||
1482 | max3421_reset_port(struct usb_hcd *hcd) | ||
1483 | { | ||
1484 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1485 | |||
1486 | max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | | ||
1487 | USB_PORT_STAT_LOW_SPEED); | ||
1488 | max3421_hcd->do_reset_port = 1; | ||
1489 | wake_up_process(max3421_hcd->spi_thread); | ||
1490 | return 0; | ||
1491 | } | ||
1492 | |||
1493 | static int | ||
1494 | max3421_reset(struct usb_hcd *hcd) | ||
1495 | { | ||
1496 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1497 | |||
1498 | hcd->self.sg_tablesize = 0; | ||
1499 | hcd->speed = HCD_USB2; | ||
1500 | hcd->self.root_hub->speed = USB_SPEED_FULL; | ||
1501 | max3421_hcd->do_reset_hcd = 1; | ||
1502 | wake_up_process(max3421_hcd->spi_thread); | ||
1503 | return 0; | ||
1504 | } | ||
1505 | |||
1506 | static int | ||
1507 | max3421_start(struct usb_hcd *hcd) | ||
1508 | { | ||
1509 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1510 | |||
1511 | spin_lock_init(&max3421_hcd->lock); | ||
1512 | max3421_hcd->rh_state = MAX3421_RH_RUNNING; | ||
1513 | |||
1514 | INIT_LIST_HEAD(&max3421_hcd->ep_list); | ||
1515 | |||
1516 | hcd->power_budget = POWER_BUDGET; | ||
1517 | hcd->state = HC_STATE_RUNNING; | ||
1518 | hcd->uses_new_polling = 1; | ||
1519 | return 0; | ||
1520 | } | ||
1521 | |||
1522 | static void | ||
1523 | max3421_stop(struct usb_hcd *hcd) | ||
1524 | { | ||
1525 | } | ||
1526 | |||
1527 | static int | ||
1528 | max3421_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | ||
1529 | { | ||
1530 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
1531 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1532 | struct max3421_ep *max3421_ep; | ||
1533 | unsigned long flags; | ||
1534 | int retval; | ||
1535 | |||
1536 | switch (usb_pipetype(urb->pipe)) { | ||
1537 | case PIPE_INTERRUPT: | ||
1538 | case PIPE_ISOCHRONOUS: | ||
1539 | if (urb->interval < 0) { | ||
1540 | dev_err(&spi->dev, | ||
1541 | "%s: interval=%d for intr-/iso-pipe; expected > 0\n", | ||
1542 | __func__, urb->interval); | ||
1543 | return -EINVAL; | ||
1544 | } | ||
1545 | default: | ||
1546 | break; | ||
1547 | } | ||
1548 | |||
1549 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1550 | |||
1551 | max3421_ep = urb->ep->hcpriv; | ||
1552 | if (!max3421_ep) { | ||
1553 | /* gets freed in max3421_endpoint_disable: */ | ||
1554 | max3421_ep = kzalloc(sizeof(struct max3421_ep), mem_flags); | ||
1555 | if (!max3421_ep) { | ||
1556 | retval = -ENOMEM; | ||
1557 | goto out; | ||
1558 | } | ||
1559 | max3421_ep->ep = urb->ep; | ||
1560 | max3421_ep->last_active = max3421_hcd->frame_number; | ||
1561 | urb->ep->hcpriv = max3421_ep; | ||
1562 | |||
1563 | list_add_tail(&max3421_ep->ep_list, &max3421_hcd->ep_list); | ||
1564 | } | ||
1565 | |||
1566 | retval = usb_hcd_link_urb_to_ep(hcd, urb); | ||
1567 | if (retval == 0) { | ||
1568 | /* Since we added to the queue, restart scheduling: */ | ||
1569 | max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; | ||
1570 | wake_up_process(max3421_hcd->spi_thread); | ||
1571 | } | ||
1572 | |||
1573 | out: | ||
1574 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1575 | return retval; | ||
1576 | } | ||
1577 | |||
1578 | static int | ||
1579 | max3421_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | ||
1580 | { | ||
1581 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1582 | unsigned long flags; | ||
1583 | int retval; | ||
1584 | |||
1585 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1586 | |||
1587 | /* | ||
1588 | * This will set urb->unlinked which in turn causes the entry | ||
1589 | * to be dropped at the next opportunity. | ||
1590 | */ | ||
1591 | retval = usb_hcd_check_unlink_urb(hcd, urb, status); | ||
1592 | if (retval == 0) { | ||
1593 | max3421_hcd->do_check_unlink = 1; | ||
1594 | wake_up_process(max3421_hcd->spi_thread); | ||
1595 | } | ||
1596 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1597 | return retval; | ||
1598 | } | ||
1599 | |||
1600 | static void | ||
1601 | max3421_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) | ||
1602 | { | ||
1603 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1604 | unsigned long flags; | ||
1605 | |||
1606 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1607 | |||
1608 | if (ep->hcpriv) { | ||
1609 | struct max3421_ep *max3421_ep = ep->hcpriv; | ||
1610 | |||
1611 | /* remove myself from the ep_list: */ | ||
1612 | if (!list_empty(&max3421_ep->ep_list)) | ||
1613 | list_del(&max3421_ep->ep_list); | ||
1614 | kfree(max3421_ep); | ||
1615 | ep->hcpriv = NULL; | ||
1616 | } | ||
1617 | |||
1618 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1619 | } | ||
1620 | |||
1621 | static int | ||
1622 | max3421_get_frame_number(struct usb_hcd *hcd) | ||
1623 | { | ||
1624 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1625 | return max3421_hcd->frame_number; | ||
1626 | } | ||
1627 | |||
1628 | /* | ||
1629 | * Should return a non-zero value when any port is undergoing a resume | ||
1630 | * transition while the root hub is suspended. | ||
1631 | */ | ||
1632 | static int | ||
1633 | max3421_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
1634 | { | ||
1635 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1636 | unsigned long flags; | ||
1637 | int retval = 0; | ||
1638 | |||
1639 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1640 | if (!HCD_HW_ACCESSIBLE(hcd)) | ||
1641 | goto done; | ||
1642 | |||
1643 | *buf = 0; | ||
1644 | if ((max3421_hcd->port_status & PORT_C_MASK) != 0) { | ||
1645 | *buf = (1 << 1); /* a hub over-current condition exists */ | ||
1646 | dev_dbg(hcd->self.controller, | ||
1647 | "port status 0x%08x has changes\n", | ||
1648 | max3421_hcd->port_status); | ||
1649 | retval = 1; | ||
1650 | if (max3421_hcd->rh_state == MAX3421_RH_SUSPENDED) | ||
1651 | usb_hcd_resume_root_hub(hcd); | ||
1652 | } | ||
1653 | done: | ||
1654 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1655 | return retval; | ||
1656 | } | ||
1657 | |||
1658 | static inline void | ||
1659 | hub_descriptor(struct usb_hub_descriptor *desc) | ||
1660 | { | ||
1661 | memset(desc, 0, sizeof(*desc)); | ||
1662 | /* | ||
1663 | * See Table 11-13: Hub Descriptor in USB 2.0 spec. | ||
1664 | */ | ||
1665 | desc->bDescriptorType = 0x29; /* hub descriptor */ | ||
1666 | desc->bDescLength = 9; | ||
1667 | desc->wHubCharacteristics = cpu_to_le16(0x0001); | ||
1668 | desc->bNbrPorts = 1; | ||
1669 | } | ||
1670 | |||
1671 | /* | ||
1672 | * Set the MAX3421E general-purpose output with number PIN_NUMBER to | ||
1673 | * VALUE (0 or 1). PIN_NUMBER may be in the range from 1-8. For | ||
1674 | * any other value, this function acts as a no-op. | ||
1675 | */ | ||
1676 | static void | ||
1677 | max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value) | ||
1678 | { | ||
1679 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1680 | u8 mask, idx; | ||
1681 | |||
1682 | --pin_number; | ||
1683 | if (pin_number > 7) | ||
1684 | return; | ||
1685 | |||
1686 | mask = 1u << pin_number; | ||
1687 | idx = pin_number / 4; | ||
1688 | |||
1689 | if (value) | ||
1690 | max3421_hcd->iopins[idx] |= mask; | ||
1691 | else | ||
1692 | max3421_hcd->iopins[idx] &= ~mask; | ||
1693 | max3421_hcd->do_iopin_update = 1; | ||
1694 | wake_up_process(max3421_hcd->spi_thread); | ||
1695 | } | ||
1696 | |||
1697 | static int | ||
1698 | max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index, | ||
1699 | char *buf, u16 length) | ||
1700 | { | ||
1701 | struct spi_device *spi = to_spi_device(hcd->self.controller); | ||
1702 | struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd); | ||
1703 | struct max3421_hcd_platform_data *pdata; | ||
1704 | unsigned long flags; | ||
1705 | int retval = 0; | ||
1706 | |||
1707 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1708 | |||
1709 | pdata = spi->dev.platform_data; | ||
1710 | |||
1711 | switch (type_req) { | ||
1712 | case ClearHubFeature: | ||
1713 | break; | ||
1714 | case ClearPortFeature: | ||
1715 | switch (value) { | ||
1716 | case USB_PORT_FEAT_SUSPEND: | ||
1717 | break; | ||
1718 | case USB_PORT_FEAT_POWER: | ||
1719 | dev_dbg(hcd->self.controller, "power-off\n"); | ||
1720 | max3421_gpout_set_value(hcd, pdata->vbus_gpout, | ||
1721 | !pdata->vbus_active_level); | ||
1722 | /* FALLS THROUGH */ | ||
1723 | default: | ||
1724 | max3421_hcd->port_status &= ~(1 << value); | ||
1725 | } | ||
1726 | break; | ||
1727 | case GetHubDescriptor: | ||
1728 | hub_descriptor((struct usb_hub_descriptor *) buf); | ||
1729 | break; | ||
1730 | |||
1731 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | ||
1732 | case GetPortErrorCount: | ||
1733 | case SetHubDepth: | ||
1734 | /* USB3 only */ | ||
1735 | goto error; | ||
1736 | |||
1737 | case GetHubStatus: | ||
1738 | *(__le32 *) buf = cpu_to_le32(0); | ||
1739 | break; | ||
1740 | |||
1741 | case GetPortStatus: | ||
1742 | if (index != 1) { | ||
1743 | retval = -EPIPE; | ||
1744 | goto error; | ||
1745 | } | ||
1746 | ((__le16 *) buf)[0] = cpu_to_le16(max3421_hcd->port_status); | ||
1747 | ((__le16 *) buf)[1] = | ||
1748 | cpu_to_le16(max3421_hcd->port_status >> 16); | ||
1749 | break; | ||
1750 | |||
1751 | case SetHubFeature: | ||
1752 | retval = -EPIPE; | ||
1753 | break; | ||
1754 | |||
1755 | case SetPortFeature: | ||
1756 | switch (value) { | ||
1757 | case USB_PORT_FEAT_LINK_STATE: | ||
1758 | case USB_PORT_FEAT_U1_TIMEOUT: | ||
1759 | case USB_PORT_FEAT_U2_TIMEOUT: | ||
1760 | case USB_PORT_FEAT_BH_PORT_RESET: | ||
1761 | goto error; | ||
1762 | case USB_PORT_FEAT_SUSPEND: | ||
1763 | if (max3421_hcd->active) | ||
1764 | max3421_hcd->port_status |= | ||
1765 | USB_PORT_STAT_SUSPEND; | ||
1766 | break; | ||
1767 | case USB_PORT_FEAT_POWER: | ||
1768 | dev_dbg(hcd->self.controller, "power-on\n"); | ||
1769 | max3421_hcd->port_status |= USB_PORT_STAT_POWER; | ||
1770 | max3421_gpout_set_value(hcd, pdata->vbus_gpout, | ||
1771 | pdata->vbus_active_level); | ||
1772 | break; | ||
1773 | case USB_PORT_FEAT_RESET: | ||
1774 | max3421_reset_port(hcd); | ||
1775 | /* FALLS THROUGH */ | ||
1776 | default: | ||
1777 | if ((max3421_hcd->port_status & USB_PORT_STAT_POWER) | ||
1778 | != 0) | ||
1779 | max3421_hcd->port_status |= (1 << value); | ||
1780 | } | ||
1781 | break; | ||
1782 | |||
1783 | default: | ||
1784 | dev_dbg(hcd->self.controller, | ||
1785 | "hub control req%04x v%04x i%04x l%d\n", | ||
1786 | type_req, value, index, length); | ||
1787 | error: /* "protocol stall" on error */ | ||
1788 | retval = -EPIPE; | ||
1789 | } | ||
1790 | |||
1791 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1792 | return retval; | ||
1793 | } | ||
1794 | |||
1795 | static int | ||
1796 | max3421_bus_suspend(struct usb_hcd *hcd) | ||
1797 | { | ||
1798 | return -1; | ||
1799 | } | ||
1800 | |||
1801 | static int | ||
1802 | max3421_bus_resume(struct usb_hcd *hcd) | ||
1803 | { | ||
1804 | return -1; | ||
1805 | } | ||
1806 | |||
1807 | /* | ||
1808 | * The SPI driver already takes care of DMA-mapping/unmapping, so no | ||
1809 | * reason to do it twice. | ||
1810 | */ | ||
1811 | static int | ||
1812 | max3421_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | ||
1813 | { | ||
1814 | return 0; | ||
1815 | } | ||
1816 | |||
1817 | static void | ||
1818 | max3421_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
1819 | { | ||
1820 | } | ||
1821 | |||
1822 | static struct hc_driver max3421_hcd_desc = { | ||
1823 | .description = "max3421", | ||
1824 | .product_desc = DRIVER_DESC, | ||
1825 | .hcd_priv_size = sizeof(struct max3421_hcd), | ||
1826 | .flags = HCD_USB11, | ||
1827 | .reset = max3421_reset, | ||
1828 | .start = max3421_start, | ||
1829 | .stop = max3421_stop, | ||
1830 | .get_frame_number = max3421_get_frame_number, | ||
1831 | .urb_enqueue = max3421_urb_enqueue, | ||
1832 | .urb_dequeue = max3421_urb_dequeue, | ||
1833 | .map_urb_for_dma = max3421_map_urb_for_dma, | ||
1834 | .unmap_urb_for_dma = max3421_unmap_urb_for_dma, | ||
1835 | .endpoint_disable = max3421_endpoint_disable, | ||
1836 | .hub_status_data = max3421_hub_status_data, | ||
1837 | .hub_control = max3421_hub_control, | ||
1838 | .bus_suspend = max3421_bus_suspend, | ||
1839 | .bus_resume = max3421_bus_resume, | ||
1840 | }; | ||
1841 | |||
1842 | static int | ||
1843 | max3421_probe(struct spi_device *spi) | ||
1844 | { | ||
1845 | struct max3421_hcd *max3421_hcd; | ||
1846 | struct usb_hcd *hcd = NULL; | ||
1847 | int retval = -ENOMEM; | ||
1848 | |||
1849 | if (spi_setup(spi) < 0) { | ||
1850 | dev_err(&spi->dev, "Unable to setup SPI bus"); | ||
1851 | return -EFAULT; | ||
1852 | } | ||
1853 | |||
1854 | hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev, | ||
1855 | dev_name(&spi->dev)); | ||
1856 | if (!hcd) { | ||
1857 | dev_err(&spi->dev, "failed to create HCD structure\n"); | ||
1858 | goto error; | ||
1859 | } | ||
1860 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
1861 | max3421_hcd = hcd_to_max3421(hcd); | ||
1862 | max3421_hcd->next = max3421_hcd_list; | ||
1863 | max3421_hcd_list = max3421_hcd; | ||
1864 | INIT_LIST_HEAD(&max3421_hcd->ep_list); | ||
1865 | |||
1866 | max3421_hcd->tx = kmalloc(sizeof(*max3421_hcd->tx), GFP_KERNEL); | ||
1867 | if (!max3421_hcd->tx) { | ||
1868 | dev_err(&spi->dev, "failed to kmalloc tx buffer\n"); | ||
1869 | goto error; | ||
1870 | } | ||
1871 | max3421_hcd->rx = kmalloc(sizeof(*max3421_hcd->rx), GFP_KERNEL); | ||
1872 | if (!max3421_hcd->rx) { | ||
1873 | dev_err(&spi->dev, "failed to kmalloc rx buffer\n"); | ||
1874 | goto error; | ||
1875 | } | ||
1876 | |||
1877 | max3421_hcd->spi_thread = kthread_run(max3421_spi_thread, hcd, | ||
1878 | "max3421_spi_thread"); | ||
1879 | if (max3421_hcd->spi_thread == ERR_PTR(-ENOMEM)) { | ||
1880 | dev_err(&spi->dev, | ||
1881 | "failed to create SPI thread (out of memory)\n"); | ||
1882 | goto error; | ||
1883 | } | ||
1884 | |||
1885 | retval = usb_add_hcd(hcd, 0, 0); | ||
1886 | if (retval) { | ||
1887 | dev_err(&spi->dev, "failed to add HCD\n"); | ||
1888 | goto error; | ||
1889 | } | ||
1890 | |||
1891 | retval = request_irq(spi->irq, max3421_irq_handler, | ||
1892 | IRQF_TRIGGER_LOW, "max3421", hcd); | ||
1893 | if (retval < 0) { | ||
1894 | dev_err(&spi->dev, "failed to request irq %d\n", spi->irq); | ||
1895 | goto error; | ||
1896 | } | ||
1897 | return 0; | ||
1898 | |||
1899 | error: | ||
1900 | if (hcd) { | ||
1901 | kfree(max3421_hcd->tx); | ||
1902 | kfree(max3421_hcd->rx); | ||
1903 | if (max3421_hcd->spi_thread) | ||
1904 | kthread_stop(max3421_hcd->spi_thread); | ||
1905 | usb_put_hcd(hcd); | ||
1906 | } | ||
1907 | return retval; | ||
1908 | } | ||
1909 | |||
1910 | static int | ||
1911 | max3421_remove(struct spi_device *spi) | ||
1912 | { | ||
1913 | struct max3421_hcd *max3421_hcd = NULL, **prev; | ||
1914 | struct usb_hcd *hcd = NULL; | ||
1915 | unsigned long flags; | ||
1916 | |||
1917 | for (prev = &max3421_hcd_list; *prev; prev = &(*prev)->next) { | ||
1918 | max3421_hcd = *prev; | ||
1919 | hcd = max3421_to_hcd(max3421_hcd); | ||
1920 | if (hcd->self.controller == &spi->dev) | ||
1921 | break; | ||
1922 | } | ||
1923 | if (!max3421_hcd) { | ||
1924 | dev_err(&spi->dev, "no MAX3421 HCD found for SPI device %p\n", | ||
1925 | spi); | ||
1926 | return -ENODEV; | ||
1927 | } | ||
1928 | |||
1929 | usb_remove_hcd(hcd); | ||
1930 | |||
1931 | spin_lock_irqsave(&max3421_hcd->lock, flags); | ||
1932 | |||
1933 | kthread_stop(max3421_hcd->spi_thread); | ||
1934 | *prev = max3421_hcd->next; | ||
1935 | |||
1936 | spin_unlock_irqrestore(&max3421_hcd->lock, flags); | ||
1937 | |||
1938 | free_irq(spi->irq, hcd); | ||
1939 | |||
1940 | usb_put_hcd(hcd); | ||
1941 | return 0; | ||
1942 | } | ||
1943 | |||
1944 | static struct spi_driver max3421_driver = { | ||
1945 | .probe = max3421_probe, | ||
1946 | .remove = max3421_remove, | ||
1947 | .driver = { | ||
1948 | .name = "max3421-hcd", | ||
1949 | .owner = THIS_MODULE, | ||
1950 | }, | ||
1951 | }; | ||
1952 | |||
1953 | module_spi_driver(max3421_driver); | ||
1954 | |||
1955 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
1956 | MODULE_AUTHOR("David Mosberger <davidm@egauge.net>"); | ||
1957 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 091ae4905cfc..e49eb4f90f5d 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
@@ -46,9 +46,6 @@ static const char hcd_name[] = "ohci-atmel"; | |||
46 | 46 | ||
47 | static struct hc_driver __read_mostly ohci_at91_hc_driver; | 47 | static struct hc_driver __read_mostly ohci_at91_hc_driver; |
48 | static int clocked; | 48 | static int clocked; |
49 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, | ||
50 | u16 wValue, u16 wIndex, char *buf, u16 wLength); | ||
51 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); | ||
52 | 49 | ||
53 | extern int usb_disabled(void); | 50 | extern int usb_disabled(void); |
54 | 51 | ||
@@ -262,7 +259,7 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) | |||
262 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) | 259 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) |
263 | { | 260 | { |
264 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; | 261 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; |
265 | int length = orig_ohci_hub_status_data(hcd, buf); | 262 | int length = ohci_hub_status_data(hcd, buf); |
266 | int port; | 263 | int port; |
267 | 264 | ||
268 | at91_for_each_port(port) { | 265 | at91_for_each_port(port) { |
@@ -340,8 +337,7 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
340 | break; | 337 | break; |
341 | } | 338 | } |
342 | 339 | ||
343 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, | 340 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); |
344 | buf, wLength); | ||
345 | if (ret) | 341 | if (ret) |
346 | goto out; | 342 | goto out; |
347 | 343 | ||
@@ -690,9 +686,6 @@ static int __init ohci_at91_init(void) | |||
690 | * too easy. | 686 | * too easy. |
691 | */ | 687 | */ |
692 | 688 | ||
693 | orig_ohci_hub_control = ohci_at91_hc_driver.hub_control; | ||
694 | orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data; | ||
695 | |||
696 | ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data; | 689 | ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data; |
697 | ohci_at91_hc_driver.hub_control = ohci_at91_hub_control; | 690 | ohci_at91_hc_driver.hub_control = ohci_at91_hub_control; |
698 | 691 | ||
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c index 68588d8a09bb..060a6a414750 100644 --- a/drivers/usb/host/ohci-exynos.c +++ b/drivers/usb/host/ohci-exynos.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
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/usb/phy.h> | 22 | #include <linux/usb/phy.h> |
22 | #include <linux/usb/samsung_usb_phy.h> | 23 | #include <linux/usb/samsung_usb_phy.h> |
23 | #include <linux/usb.h> | 24 | #include <linux/usb.h> |
@@ -33,28 +34,110 @@ static struct hc_driver __read_mostly exynos_ohci_hc_driver; | |||
33 | 34 | ||
34 | #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) | 35 | #define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv) |
35 | 36 | ||
37 | #define PHY_NUMBER 3 | ||
38 | |||
36 | struct exynos_ohci_hcd { | 39 | struct exynos_ohci_hcd { |
37 | struct clk *clk; | 40 | struct clk *clk; |
38 | struct usb_phy *phy; | 41 | struct usb_phy *phy; |
39 | struct usb_otg *otg; | 42 | struct usb_otg *otg; |
43 | struct phy *phy_g[PHY_NUMBER]; | ||
40 | }; | 44 | }; |
41 | 45 | ||
42 | static void exynos_ohci_phy_enable(struct platform_device *pdev) | 46 | static int exynos_ohci_get_phy(struct device *dev, |
47 | struct exynos_ohci_hcd *exynos_ohci) | ||
43 | { | 48 | { |
44 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 49 | struct device_node *child; |
50 | struct phy *phy; | ||
51 | int phy_number; | ||
52 | int ret = 0; | ||
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 | |||
66 | /* | ||
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) { | ||
77 | ret = of_property_read_u32(child, "reg", &phy_number); | ||
78 | if (ret) { | ||
79 | dev_err(dev, "Failed to parse device tree\n"); | ||
80 | of_node_put(child); | ||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | if (phy_number >= PHY_NUMBER) { | ||
85 | dev_err(dev, "Invalid number of PHYs\n"); | ||
86 | of_node_put(child); | ||
87 | return -EINVAL; | ||
88 | } | ||
89 | |||
90 | phy = devm_of_phy_get(dev, child, 0); | ||
91 | of_node_put(child); | ||
92 | if (IS_ERR(phy)) { | ||
93 | ret = PTR_ERR(phy); | ||
94 | if (ret != -ENOSYS && ret != -ENODEV) { | ||
95 | dev_err(dev, "no usb2 phy configured\n"); | ||
96 | return ret; | ||
97 | } | ||
98 | dev_dbg(dev, "Failed to get usb2 phy\n"); | ||
99 | } | ||
100 | exynos_ohci->phy_g[phy_number] = phy; | ||
101 | } | ||
102 | |||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | static int exynos_ohci_phy_enable(struct device *dev) | ||
107 | { | ||
108 | struct usb_hcd *hcd = dev_get_drvdata(dev); | ||
45 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 109 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
110 | int i; | ||
111 | int ret = 0; | ||
112 | |||
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++) | ||
117 | if (!IS_ERR(exynos_ohci->phy_g[i])) | ||
118 | ret = phy_power_on(exynos_ohci->phy_g[i]); | ||
119 | if (ret) | ||
120 | for (i--; i >= 0; i--) | ||
121 | if (!IS_ERR(exynos_ohci->phy_g[i])) | ||
122 | phy_power_off(exynos_ohci->phy_g[i]); | ||
46 | 123 | ||
47 | if (exynos_ohci->phy) | 124 | return ret; |
48 | usb_phy_init(exynos_ohci->phy); | ||
49 | } | 125 | } |
50 | 126 | ||
51 | static void exynos_ohci_phy_disable(struct platform_device *pdev) | 127 | static void exynos_ohci_phy_disable(struct device *dev) |
52 | { | 128 | { |
53 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 129 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
54 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 130 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
131 | int i; | ||
55 | 132 | ||
56 | if (exynos_ohci->phy) | 133 | if (!IS_ERR(exynos_ohci->phy)) { |
57 | usb_phy_shutdown(exynos_ohci->phy); | 134 | usb_phy_shutdown(exynos_ohci->phy); |
135 | return; | ||
136 | } | ||
137 | |||
138 | for (i = 0; i < PHY_NUMBER; i++) | ||
139 | if (!IS_ERR(exynos_ohci->phy_g[i])) | ||
140 | phy_power_off(exynos_ohci->phy_g[i]); | ||
58 | } | 141 | } |
59 | 142 | ||
60 | static int exynos_ohci_probe(struct platform_device *pdev) | 143 | static int exynos_ohci_probe(struct platform_device *pdev) |
@@ -62,7 +145,6 @@ static int exynos_ohci_probe(struct platform_device *pdev) | |||
62 | struct exynos_ohci_hcd *exynos_ohci; | 145 | struct exynos_ohci_hcd *exynos_ohci; |
63 | struct usb_hcd *hcd; | 146 | struct usb_hcd *hcd; |
64 | struct resource *res; | 147 | struct resource *res; |
65 | struct usb_phy *phy; | ||
66 | int irq; | 148 | int irq; |
67 | int err; | 149 | int err; |
68 | 150 | ||
@@ -88,15 +170,9 @@ static int exynos_ohci_probe(struct platform_device *pdev) | |||
88 | "samsung,exynos5440-ohci")) | 170 | "samsung,exynos5440-ohci")) |
89 | goto skip_phy; | 171 | goto skip_phy; |
90 | 172 | ||
91 | phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); | 173 | err = exynos_ohci_get_phy(&pdev->dev, exynos_ohci); |
92 | if (IS_ERR(phy)) { | 174 | if (err) |
93 | usb_put_hcd(hcd); | 175 | goto fail_clk; |
94 | dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); | ||
95 | return -EPROBE_DEFER; | ||
96 | } else { | ||
97 | exynos_ohci->phy = phy; | ||
98 | exynos_ohci->otg = phy->otg; | ||
99 | } | ||
100 | 176 | ||
101 | skip_phy: | 177 | skip_phy: |
102 | exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); | 178 | exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); |
@@ -120,10 +196,9 @@ skip_phy: | |||
120 | 196 | ||
121 | hcd->rsrc_start = res->start; | 197 | hcd->rsrc_start = res->start; |
122 | hcd->rsrc_len = resource_size(res); | 198 | hcd->rsrc_len = resource_size(res); |
123 | hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len); | 199 | hcd->regs = devm_ioremap_resource(&pdev->dev, res); |
124 | if (!hcd->regs) { | 200 | if (IS_ERR(hcd->regs)) { |
125 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | 201 | err = PTR_ERR(hcd->regs); |
126 | err = -ENOMEM; | ||
127 | goto fail_io; | 202 | goto fail_io; |
128 | } | 203 | } |
129 | 204 | ||
@@ -139,7 +214,11 @@ skip_phy: | |||
139 | 214 | ||
140 | platform_set_drvdata(pdev, hcd); | 215 | platform_set_drvdata(pdev, hcd); |
141 | 216 | ||
142 | exynos_ohci_phy_enable(pdev); | 217 | err = exynos_ohci_phy_enable(&pdev->dev); |
218 | if (err) { | ||
219 | dev_err(&pdev->dev, "Failed to enable USB phy\n"); | ||
220 | goto fail_io; | ||
221 | } | ||
143 | 222 | ||
144 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); | 223 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
145 | if (err) { | 224 | if (err) { |
@@ -150,7 +229,7 @@ skip_phy: | |||
150 | return 0; | 229 | return 0; |
151 | 230 | ||
152 | fail_add_hcd: | 231 | fail_add_hcd: |
153 | exynos_ohci_phy_disable(pdev); | 232 | exynos_ohci_phy_disable(&pdev->dev); |
154 | fail_io: | 233 | fail_io: |
155 | clk_disable_unprepare(exynos_ohci->clk); | 234 | clk_disable_unprepare(exynos_ohci->clk); |
156 | fail_clk: | 235 | fail_clk: |
@@ -168,7 +247,7 @@ static int exynos_ohci_remove(struct platform_device *pdev) | |||
168 | if (exynos_ohci->otg) | 247 | if (exynos_ohci->otg) |
169 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | 248 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
170 | 249 | ||
171 | exynos_ohci_phy_disable(pdev); | 250 | exynos_ohci_phy_disable(&pdev->dev); |
172 | 251 | ||
173 | clk_disable_unprepare(exynos_ohci->clk); | 252 | clk_disable_unprepare(exynos_ohci->clk); |
174 | 253 | ||
@@ -190,26 +269,19 @@ static int exynos_ohci_suspend(struct device *dev) | |||
190 | { | 269 | { |
191 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 270 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
192 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 271 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
193 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
194 | struct platform_device *pdev = to_platform_device(dev); | ||
195 | bool do_wakeup = device_may_wakeup(dev); | 272 | bool do_wakeup = device_may_wakeup(dev); |
196 | unsigned long flags; | ||
197 | int rc = ohci_suspend(hcd, do_wakeup); | 273 | int rc = ohci_suspend(hcd, do_wakeup); |
198 | 274 | ||
199 | if (rc) | 275 | if (rc) |
200 | return rc; | 276 | return rc; |
201 | 277 | ||
202 | spin_lock_irqsave(&ohci->lock, flags); | ||
203 | |||
204 | if (exynos_ohci->otg) | 278 | if (exynos_ohci->otg) |
205 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | 279 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
206 | 280 | ||
207 | exynos_ohci_phy_disable(pdev); | 281 | exynos_ohci_phy_disable(dev); |
208 | 282 | ||
209 | clk_disable_unprepare(exynos_ohci->clk); | 283 | clk_disable_unprepare(exynos_ohci->clk); |
210 | 284 | ||
211 | spin_unlock_irqrestore(&ohci->lock, flags); | ||
212 | |||
213 | return 0; | 285 | return 0; |
214 | } | 286 | } |
215 | 287 | ||
@@ -217,14 +289,19 @@ static int exynos_ohci_resume(struct device *dev) | |||
217 | { | 289 | { |
218 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 290 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
219 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); | 291 | struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd); |
220 | struct platform_device *pdev = to_platform_device(dev); | 292 | int ret; |
221 | 293 | ||
222 | clk_prepare_enable(exynos_ohci->clk); | 294 | clk_prepare_enable(exynos_ohci->clk); |
223 | 295 | ||
224 | if (exynos_ohci->otg) | 296 | if (exynos_ohci->otg) |
225 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); | 297 | exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self); |
226 | 298 | ||
227 | exynos_ohci_phy_enable(pdev); | 299 | ret = exynos_ohci_phy_enable(dev); |
300 | if (ret) { | ||
301 | dev_err(dev, "Failed to enable USB phy\n"); | ||
302 | clk_disable_unprepare(exynos_ohci->clk); | ||
303 | return ret; | ||
304 | } | ||
228 | 305 | ||
229 | ohci_resume(hcd, false); | 306 | ohci_resume(hcd, false); |
230 | 307 | ||
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 3586460fb2a1..f98d03f3144c 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -1178,7 +1178,7 @@ MODULE_LICENSE ("GPL"); | |||
1178 | #define SA1111_DRIVER ohci_hcd_sa1111_driver | 1178 | #define SA1111_DRIVER ohci_hcd_sa1111_driver |
1179 | #endif | 1179 | #endif |
1180 | 1180 | ||
1181 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX | 1181 | #ifdef CONFIG_USB_OHCI_HCD_DAVINCI |
1182 | #include "ohci-da8xx.c" | 1182 | #include "ohci-da8xx.c" |
1183 | #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver | 1183 | #define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver |
1184 | #endif | 1184 | #endif |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index cd871b895013..b4940de1eba3 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -456,8 +456,7 @@ static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed, | |||
456 | 456 | ||
457 | /* build "status change" packet (one or two bytes) from HC registers */ | 457 | /* build "status change" packet (one or two bytes) from HC registers */ |
458 | 458 | ||
459 | static int | 459 | int ohci_hub_status_data(struct usb_hcd *hcd, char *buf) |
460 | ohci_hub_status_data (struct usb_hcd *hcd, char *buf) | ||
461 | { | 460 | { |
462 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); | 461 | struct ohci_hcd *ohci = hcd_to_ohci (hcd); |
463 | int i, changed = 0, length = 1; | 462 | int i, changed = 0, length = 1; |
@@ -522,6 +521,7 @@ done: | |||
522 | 521 | ||
523 | return changed ? length : 0; | 522 | return changed ? length : 0; |
524 | } | 523 | } |
524 | EXPORT_SYMBOL_GPL(ohci_hub_status_data); | ||
525 | 525 | ||
526 | /*-------------------------------------------------------------------------*/ | 526 | /*-------------------------------------------------------------------------*/ |
527 | 527 | ||
@@ -664,7 +664,7 @@ static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) | |||
664 | return 0; | 664 | return 0; |
665 | } | 665 | } |
666 | 666 | ||
667 | static int ohci_hub_control ( | 667 | int ohci_hub_control( |
668 | struct usb_hcd *hcd, | 668 | struct usb_hcd *hcd, |
669 | u16 typeReq, | 669 | u16 typeReq, |
670 | u16 wValue, | 670 | u16 wValue, |
@@ -790,4 +790,4 @@ error: | |||
790 | } | 790 | } |
791 | return retval; | 791 | return retval; |
792 | } | 792 | } |
793 | 793 | EXPORT_SYMBOL_GPL(ohci_hub_control); | |
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c index b6002c951c5c..4369299064c7 100644 --- a/drivers/usb/host/ohci-platform.c +++ b/drivers/usb/host/ohci-platform.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/phy/phy.h> | 25 | #include <linux/phy/phy.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | #include <linux/reset.h> | ||
27 | #include <linux/usb/ohci_pdriver.h> | 28 | #include <linux/usb/ohci_pdriver.h> |
28 | #include <linux/usb.h> | 29 | #include <linux/usb.h> |
29 | #include <linux/usb/hcd.h> | 30 | #include <linux/usb/hcd.h> |
@@ -36,6 +37,7 @@ | |||
36 | 37 | ||
37 | struct ohci_platform_priv { | 38 | struct ohci_platform_priv { |
38 | struct clk *clks[OHCI_MAX_CLKS]; | 39 | struct clk *clks[OHCI_MAX_CLKS]; |
40 | struct reset_control *rst; | ||
39 | struct phy *phy; | 41 | struct phy *phy; |
40 | }; | 42 | }; |
41 | 43 | ||
@@ -191,6 +193,19 @@ static int ohci_platform_probe(struct platform_device *dev) | |||
191 | break; | 193 | break; |
192 | } | 194 | } |
193 | } | 195 | } |
196 | |||
197 | } | ||
198 | |||
199 | priv->rst = devm_reset_control_get_optional(&dev->dev, NULL); | ||
200 | if (IS_ERR(priv->rst)) { | ||
201 | err = PTR_ERR(priv->rst); | ||
202 | if (err == -EPROBE_DEFER) | ||
203 | goto err_put_clks; | ||
204 | priv->rst = NULL; | ||
205 | } else { | ||
206 | err = reset_control_deassert(priv->rst); | ||
207 | if (err) | ||
208 | goto err_put_clks; | ||
194 | } | 209 | } |
195 | 210 | ||
196 | if (pdata->big_endian_desc) | 211 | if (pdata->big_endian_desc) |
@@ -203,7 +218,7 @@ static int ohci_platform_probe(struct platform_device *dev) | |||
203 | dev_err(&dev->dev, | 218 | dev_err(&dev->dev, |
204 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n"); | 219 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n"); |
205 | err = -EINVAL; | 220 | err = -EINVAL; |
206 | goto err_put_clks; | 221 | goto err_reset; |
207 | } | 222 | } |
208 | #endif | 223 | #endif |
209 | #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC | 224 | #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC |
@@ -211,14 +226,14 @@ static int ohci_platform_probe(struct platform_device *dev) | |||
211 | dev_err(&dev->dev, | 226 | dev_err(&dev->dev, |
212 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n"); | 227 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n"); |
213 | err = -EINVAL; | 228 | err = -EINVAL; |
214 | goto err_put_clks; | 229 | goto err_reset; |
215 | } | 230 | } |
216 | #endif | 231 | #endif |
217 | 232 | ||
218 | if (pdata->power_on) { | 233 | if (pdata->power_on) { |
219 | err = pdata->power_on(dev); | 234 | err = pdata->power_on(dev); |
220 | if (err < 0) | 235 | if (err < 0) |
221 | goto err_put_clks; | 236 | goto err_reset; |
222 | } | 237 | } |
223 | 238 | ||
224 | hcd->rsrc_start = res_mem->start; | 239 | hcd->rsrc_start = res_mem->start; |
@@ -242,6 +257,9 @@ static int ohci_platform_probe(struct platform_device *dev) | |||
242 | err_power: | 257 | err_power: |
243 | if (pdata->power_off) | 258 | if (pdata->power_off) |
244 | pdata->power_off(dev); | 259 | pdata->power_off(dev); |
260 | err_reset: | ||
261 | if (priv->rst) | ||
262 | reset_control_assert(priv->rst); | ||
245 | err_put_clks: | 263 | err_put_clks: |
246 | while (--clk >= 0) | 264 | while (--clk >= 0) |
247 | clk_put(priv->clks[clk]); | 265 | clk_put(priv->clks[clk]); |
@@ -266,6 +284,9 @@ static int ohci_platform_remove(struct platform_device *dev) | |||
266 | if (pdata->power_off) | 284 | if (pdata->power_off) |
267 | pdata->power_off(dev); | 285 | pdata->power_off(dev); |
268 | 286 | ||
287 | if (priv->rst) | ||
288 | reset_control_assert(priv->rst); | ||
289 | |||
269 | for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) | 290 | for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) |
270 | clk_put(priv->clks[clk]); | 291 | clk_put(priv->clks[clk]); |
271 | 292 | ||
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index d21d5fefa76c..e68f3d02cd1a 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/platform_data/usb-ohci-pxa27x.h> | 30 | #include <linux/platform_data/usb-ohci-pxa27x.h> |
31 | #include <linux/platform_data/usb-pxa3xx-ulpi.h> | 31 | #include <linux/platform_data/usb-pxa3xx-ulpi.h> |
32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/regulator/consumer.h> | ||
33 | #include <linux/signal.h> | 34 | #include <linux/signal.h> |
34 | #include <linux/usb.h> | 35 | #include <linux/usb.h> |
35 | #include <linux/usb/hcd.h> | 36 | #include <linux/usb/hcd.h> |
@@ -120,6 +121,8 @@ static struct hc_driver __read_mostly ohci_pxa27x_hc_driver; | |||
120 | struct pxa27x_ohci { | 121 | struct pxa27x_ohci { |
121 | struct clk *clk; | 122 | struct clk *clk; |
122 | void __iomem *mmio_base; | 123 | void __iomem *mmio_base; |
124 | struct regulator *vbus[3]; | ||
125 | bool vbus_enabled[3]; | ||
123 | }; | 126 | }; |
124 | 127 | ||
125 | #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv) | 128 | #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv) |
@@ -166,6 +169,52 @@ static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode) | |||
166 | return 0; | 169 | return 0; |
167 | } | 170 | } |
168 | 171 | ||
172 | static int pxa27x_ohci_set_vbus_power(struct pxa27x_ohci *pxa_ohci, | ||
173 | unsigned int port, bool enable) | ||
174 | { | ||
175 | struct regulator *vbus = pxa_ohci->vbus[port]; | ||
176 | int ret = 0; | ||
177 | |||
178 | if (IS_ERR_OR_NULL(vbus)) | ||
179 | return 0; | ||
180 | |||
181 | if (enable && !pxa_ohci->vbus_enabled[port]) | ||
182 | ret = regulator_enable(vbus); | ||
183 | else if (!enable && pxa_ohci->vbus_enabled[port]) | ||
184 | ret = regulator_disable(vbus); | ||
185 | |||
186 | if (ret < 0) | ||
187 | return ret; | ||
188 | |||
189 | pxa_ohci->vbus_enabled[port] = enable; | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int pxa27x_ohci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
195 | u16 wIndex, char *buf, u16 wLength) | ||
196 | { | ||
197 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); | ||
198 | int ret; | ||
199 | |||
200 | switch (typeReq) { | ||
201 | case SetPortFeature: | ||
202 | case ClearPortFeature: | ||
203 | if (!wIndex || wIndex > 3) | ||
204 | return -EPIPE; | ||
205 | |||
206 | if (wValue != USB_PORT_FEAT_POWER) | ||
207 | break; | ||
208 | |||
209 | ret = pxa27x_ohci_set_vbus_power(pxa_ohci, wIndex - 1, | ||
210 | typeReq == SetPortFeature); | ||
211 | if (ret) | ||
212 | return ret; | ||
213 | break; | ||
214 | } | ||
215 | |||
216 | return ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | ||
217 | } | ||
169 | /*-------------------------------------------------------------------------*/ | 218 | /*-------------------------------------------------------------------------*/ |
170 | 219 | ||
171 | static inline void pxa27x_setup_hc(struct pxa27x_ohci *pxa_ohci, | 220 | static inline void pxa27x_setup_hc(struct pxa27x_ohci *pxa_ohci, |
@@ -372,6 +421,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
372 | struct ohci_hcd *ohci; | 421 | struct ohci_hcd *ohci; |
373 | struct resource *r; | 422 | struct resource *r; |
374 | struct clk *usb_clk; | 423 | struct clk *usb_clk; |
424 | unsigned int i; | ||
375 | 425 | ||
376 | retval = ohci_pxa_of_init(pdev); | 426 | retval = ohci_pxa_of_init(pdev); |
377 | if (retval) | 427 | if (retval) |
@@ -417,6 +467,16 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
417 | pxa_ohci->clk = usb_clk; | 467 | pxa_ohci->clk = usb_clk; |
418 | pxa_ohci->mmio_base = (void __iomem *)hcd->regs; | 468 | pxa_ohci->mmio_base = (void __iomem *)hcd->regs; |
419 | 469 | ||
470 | for (i = 0; i < 3; ++i) { | ||
471 | char name[6]; | ||
472 | |||
473 | if (!(inf->flags & (ENABLE_PORT1 << i))) | ||
474 | continue; | ||
475 | |||
476 | sprintf(name, "vbus%u", i + 1); | ||
477 | pxa_ohci->vbus[i] = devm_regulator_get(&pdev->dev, name); | ||
478 | } | ||
479 | |||
420 | retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); | 480 | retval = pxa27x_start_hc(pxa_ohci, &pdev->dev); |
421 | if (retval < 0) { | 481 | if (retval < 0) { |
422 | pr_debug("pxa27x_start_hc failed"); | 482 | pr_debug("pxa27x_start_hc failed"); |
@@ -462,9 +522,14 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
462 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) | 522 | void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) |
463 | { | 523 | { |
464 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); | 524 | struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd); |
525 | unsigned int i; | ||
465 | 526 | ||
466 | usb_remove_hcd(hcd); | 527 | usb_remove_hcd(hcd); |
467 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); | 528 | pxa27x_stop_hc(pxa_ohci, &pdev->dev); |
529 | |||
530 | for (i = 0; i < 3; ++i) | ||
531 | pxa27x_ohci_set_vbus_power(pxa_ohci, i, false); | ||
532 | |||
468 | usb_put_hcd(hcd); | 533 | usb_put_hcd(hcd); |
469 | } | 534 | } |
470 | 535 | ||
@@ -563,7 +628,10 @@ static int __init ohci_pxa27x_init(void) | |||
563 | return -ENODEV; | 628 | return -ENODEV; |
564 | 629 | ||
565 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); | 630 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
631 | |||
566 | ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides); | 632 | ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides); |
633 | ohci_pxa27x_hc_driver.hub_control = pxa27x_ohci_hub_control; | ||
634 | |||
567 | return platform_driver_register(&ohci_hcd_pxa27x_driver); | 635 | return platform_driver_register(&ohci_hcd_pxa27x_driver); |
568 | } | 636 | } |
569 | module_init(ohci_pxa27x_init); | 637 | module_init(ohci_pxa27x_init); |
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c index ff7c8f1c48fb..3d753a9d3141 100644 --- a/drivers/usb/host/ohci-s3c2410.c +++ b/drivers/usb/host/ohci-s3c2410.c | |||
@@ -45,10 +45,6 @@ static struct clk *usb_clk; | |||
45 | 45 | ||
46 | /* forward definitions */ | 46 | /* forward definitions */ |
47 | 47 | ||
48 | static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, | ||
49 | u16 wValue, u16 wIndex, char *buf, u16 wLength); | ||
50 | static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); | ||
51 | |||
52 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); | 48 | static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); |
53 | 49 | ||
54 | /* conversion functions */ | 50 | /* conversion functions */ |
@@ -110,7 +106,7 @@ ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
110 | int orig; | 106 | int orig; |
111 | int portno; | 107 | int portno; |
112 | 108 | ||
113 | orig = orig_ohci_hub_status_data(hcd, buf); | 109 | orig = ohci_hub_status_data(hcd, buf); |
114 | 110 | ||
115 | if (info == NULL) | 111 | if (info == NULL) |
116 | return orig; | 112 | return orig; |
@@ -181,7 +177,7 @@ static int ohci_s3c2410_hub_control( | |||
181 | * process the request straight away and exit */ | 177 | * process the request straight away and exit */ |
182 | 178 | ||
183 | if (info == NULL) { | 179 | if (info == NULL) { |
184 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, | 180 | ret = ohci_hub_control(hcd, typeReq, wValue, |
185 | wIndex, buf, wLength); | 181 | wIndex, buf, wLength); |
186 | goto out; | 182 | goto out; |
187 | } | 183 | } |
@@ -231,7 +227,7 @@ static int ohci_s3c2410_hub_control( | |||
231 | break; | 227 | break; |
232 | } | 228 | } |
233 | 229 | ||
234 | ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | 230 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); |
235 | if (ret) | 231 | if (ret) |
236 | goto out; | 232 | goto out; |
237 | 233 | ||
@@ -489,9 +485,6 @@ static int __init ohci_s3c2410_init(void) | |||
489 | * override these functions by making it too easy. | 485 | * override these functions by making it too easy. |
490 | */ | 486 | */ |
491 | 487 | ||
492 | orig_ohci_hub_control = ohci_s3c2410_hc_driver.hub_control; | ||
493 | orig_ohci_hub_status_data = ohci_s3c2410_hc_driver.hub_status_data; | ||
494 | |||
495 | ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data; | 488 | ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data; |
496 | ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control; | 489 | ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control; |
497 | 490 | ||
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index 4550ce05af7f..05e02a709d4f 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h | |||
@@ -729,3 +729,6 @@ extern int ohci_setup(struct usb_hcd *hcd); | |||
729 | extern int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup); | 729 | extern int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup); |
730 | extern int ohci_resume(struct usb_hcd *hcd, bool hibernated); | 730 | extern int ohci_resume(struct usb_hcd *hcd, bool hibernated); |
731 | #endif | 731 | #endif |
732 | extern int ohci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
733 | u16 wIndex, char *buf, u16 wLength); | ||
734 | extern int ohci_hub_status_data(struct usb_hcd *hcd, char *buf); | ||
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h index 638e88f7a28b..c622ddf21c94 100644 --- a/drivers/usb/host/pci-quirks.h +++ b/drivers/usb/host/pci-quirks.h | |||
@@ -5,6 +5,7 @@ | |||
5 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); | 5 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); |
6 | int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); | 6 | int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); |
7 | int usb_amd_find_chipset_info(void); | 7 | int usb_amd_find_chipset_info(void); |
8 | int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *pdev); | ||
8 | bool usb_amd_hang_symptom_quirk(void); | 9 | bool usb_amd_hang_symptom_quirk(void); |
9 | bool usb_amd_prefetch_quirk(void); | 10 | bool usb_amd_prefetch_quirk(void); |
10 | void usb_amd_dev_put(void); | 11 | void usb_amd_dev_put(void); |
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 1ad6bc1951c7..6231ce6aa0c3 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -20,7 +20,8 @@ | |||
20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/gfp.h> | 23 | |
24 | #include <linux/slab.h> | ||
24 | #include <asm/unaligned.h> | 25 | #include <asm/unaligned.h> |
25 | 26 | ||
26 | #include "xhci.h" | 27 | #include "xhci.h" |
@@ -270,7 +271,6 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) | |||
270 | struct xhci_virt_device *virt_dev; | 271 | struct xhci_virt_device *virt_dev; |
271 | struct xhci_command *cmd; | 272 | struct xhci_command *cmd; |
272 | unsigned long flags; | 273 | unsigned long flags; |
273 | int timeleft; | ||
274 | int ret; | 274 | int ret; |
275 | int i; | 275 | int i; |
276 | 276 | ||
@@ -284,34 +284,31 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend) | |||
284 | 284 | ||
285 | spin_lock_irqsave(&xhci->lock, flags); | 285 | spin_lock_irqsave(&xhci->lock, flags); |
286 | for (i = LAST_EP_INDEX; i > 0; i--) { | 286 | for (i = LAST_EP_INDEX; i > 0; i--) { |
287 | if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) | 287 | if (virt_dev->eps[i].ring && virt_dev->eps[i].ring->dequeue) { |
288 | xhci_queue_stop_endpoint(xhci, slot_id, i, suspend); | 288 | struct xhci_command *command; |
289 | command = xhci_alloc_command(xhci, false, false, | ||
290 | GFP_NOIO); | ||
291 | if (!command) { | ||
292 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
293 | xhci_free_command(xhci, cmd); | ||
294 | return -ENOMEM; | ||
295 | |||
296 | } | ||
297 | xhci_queue_stop_endpoint(xhci, command, slot_id, i, | ||
298 | suspend); | ||
299 | } | ||
289 | } | 300 | } |
290 | cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring); | 301 | xhci_queue_stop_endpoint(xhci, cmd, slot_id, 0, suspend); |
291 | list_add_tail(&cmd->cmd_list, &virt_dev->cmd_list); | ||
292 | xhci_queue_stop_endpoint(xhci, slot_id, 0, suspend); | ||
293 | xhci_ring_cmd_db(xhci); | 302 | xhci_ring_cmd_db(xhci); |
294 | spin_unlock_irqrestore(&xhci->lock, flags); | 303 | spin_unlock_irqrestore(&xhci->lock, flags); |
295 | 304 | ||
296 | /* Wait for last stop endpoint command to finish */ | 305 | /* Wait for last stop endpoint command to finish */ |
297 | timeleft = wait_for_completion_interruptible_timeout( | 306 | wait_for_completion(cmd->completion); |
298 | cmd->completion, | 307 | |
299 | XHCI_CMD_DEFAULT_TIMEOUT); | 308 | if (cmd->status == COMP_CMD_ABORT || cmd->status == COMP_CMD_STOP) { |
300 | if (timeleft <= 0) { | 309 | xhci_warn(xhci, "Timeout while waiting for stop endpoint command\n"); |
301 | xhci_warn(xhci, "%s while waiting for stop endpoint command\n", | ||
302 | timeleft == 0 ? "Timeout" : "Signal"); | ||
303 | spin_lock_irqsave(&xhci->lock, flags); | ||
304 | /* The timeout might have raced with the event ring handler, so | ||
305 | * only delete from the list if the item isn't poisoned. | ||
306 | */ | ||
307 | if (cmd->cmd_list.next != LIST_POISON1) | ||
308 | list_del(&cmd->cmd_list); | ||
309 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
310 | ret = -ETIME; | 310 | ret = -ETIME; |
311 | goto command_cleanup; | ||
312 | } | 311 | } |
313 | |||
314 | command_cleanup: | ||
315 | xhci_free_command(xhci, cmd); | 312 | xhci_free_command(xhci, cmd); |
316 | return ret; | 313 | return ret; |
317 | } | 314 | } |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index c089668308ad..6a57e81c2a76 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -1020,7 +1020,6 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
1020 | dev->num_rings_cached = 0; | 1020 | dev->num_rings_cached = 0; |
1021 | 1021 | ||
1022 | init_completion(&dev->cmd_completion); | 1022 | init_completion(&dev->cmd_completion); |
1023 | INIT_LIST_HEAD(&dev->cmd_list); | ||
1024 | dev->udev = udev; | 1023 | dev->udev = udev; |
1025 | 1024 | ||
1026 | /* Point to output device context in dcbaa. */ | 1025 | /* Point to output device context in dcbaa. */ |
@@ -1794,10 +1793,11 @@ void xhci_free_command(struct xhci_hcd *xhci, | |||
1794 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 1793 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
1795 | { | 1794 | { |
1796 | struct device *dev = xhci_to_hcd(xhci)->self.controller; | 1795 | struct device *dev = xhci_to_hcd(xhci)->self.controller; |
1797 | struct xhci_cd *cur_cd, *next_cd; | ||
1798 | int size; | 1796 | int size; |
1799 | int i, j, num_ports; | 1797 | int i, j, num_ports; |
1800 | 1798 | ||
1799 | del_timer_sync(&xhci->cmd_timer); | ||
1800 | |||
1801 | /* Free the Event Ring Segment Table and the actual Event Ring */ | 1801 | /* Free the Event Ring Segment Table and the actual Event Ring */ |
1802 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); | 1802 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); |
1803 | if (xhci->erst.entries) | 1803 | if (xhci->erst.entries) |
@@ -1816,11 +1816,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1816 | xhci_ring_free(xhci, xhci->cmd_ring); | 1816 | xhci_ring_free(xhci, xhci->cmd_ring); |
1817 | xhci->cmd_ring = NULL; | 1817 | xhci->cmd_ring = NULL; |
1818 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring"); | 1818 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring"); |
1819 | list_for_each_entry_safe(cur_cd, next_cd, | 1819 | xhci_cleanup_command_queue(xhci); |
1820 | &xhci->cancel_cmd_list, cancel_cmd_list) { | ||
1821 | list_del(&cur_cd->cancel_cmd_list); | ||
1822 | kfree(cur_cd); | ||
1823 | } | ||
1824 | 1820 | ||
1825 | for (i = 1; i < MAX_HC_SLOTS; ++i) | 1821 | for (i = 1; i < MAX_HC_SLOTS; ++i) |
1826 | xhci_free_virt_device(xhci, i); | 1822 | xhci_free_virt_device(xhci, i); |
@@ -2323,7 +2319,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2323 | u32 page_size, temp; | 2319 | u32 page_size, temp; |
2324 | int i; | 2320 | int i; |
2325 | 2321 | ||
2326 | INIT_LIST_HEAD(&xhci->cancel_cmd_list); | 2322 | INIT_LIST_HEAD(&xhci->cmd_list); |
2327 | 2323 | ||
2328 | page_size = readl(&xhci->op_regs->page_size); | 2324 | page_size = readl(&xhci->op_regs->page_size); |
2329 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 2325 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
@@ -2509,6 +2505,11 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
2509 | "Wrote ERST address to ir_set 0."); | 2505 | "Wrote ERST address to ir_set 0."); |
2510 | xhci_print_ir_set(xhci, 0); | 2506 | xhci_print_ir_set(xhci, 0); |
2511 | 2507 | ||
2508 | /* init command timeout timer */ | ||
2509 | init_timer(&xhci->cmd_timer); | ||
2510 | xhci->cmd_timer.data = (unsigned long) xhci; | ||
2511 | xhci->cmd_timer.function = xhci_handle_command_timeout; | ||
2512 | |||
2512 | /* | 2513 | /* |
2513 | * XXX: Might need to set the Interrupter Moderation Register to | 2514 | * XXX: Might need to set the Interrupter Moderation Register to |
2514 | * something other than the default (~1ms minimum between interrupts). | 2515 | * something other than the default (~1ms minimum between interrupts). |
diff --git a/drivers/usb/host/xhci-mvebu.c b/drivers/usb/host/xhci-mvebu.c new file mode 100644 index 000000000000..1eefc988192d --- /dev/null +++ b/drivers/usb/host/xhci-mvebu.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Marvell | ||
3 | * Author: Gregory CLEMENT <gregory.clement@free-electrons.com> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * version 2 as published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/io.h> | ||
11 | #include <linux/mbus.h> | ||
12 | #include <linux/of.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | |||
15 | #include "xhci-mvebu.h" | ||
16 | |||
17 | #define USB3_MAX_WINDOWS 4 | ||
18 | #define USB3_WIN_CTRL(w) (0x0 + ((w) * 8)) | ||
19 | #define USB3_WIN_BASE(w) (0x4 + ((w) * 8)) | ||
20 | |||
21 | static void xhci_mvebu_mbus_config(void __iomem *base, | ||
22 | const struct mbus_dram_target_info *dram) | ||
23 | { | ||
24 | int win; | ||
25 | |||
26 | /* Clear all existing windows */ | ||
27 | for (win = 0; win < USB3_MAX_WINDOWS; win++) { | ||
28 | writel(0, base + USB3_WIN_CTRL(win)); | ||
29 | writel(0, base + USB3_WIN_BASE(win)); | ||
30 | } | ||
31 | |||
32 | /* Program each DRAM CS in a seperate window */ | ||
33 | for (win = 0; win < dram->num_cs; win++) { | ||
34 | const struct mbus_dram_window *cs = dram->cs + win; | ||
35 | |||
36 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | | ||
37 | (dram->mbus_dram_target_id << 4) | 1, | ||
38 | base + USB3_WIN_CTRL(win)); | ||
39 | |||
40 | writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win)); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev) | ||
45 | { | ||
46 | struct resource *res; | ||
47 | void __iomem *base; | ||
48 | const struct mbus_dram_target_info *dram; | ||
49 | |||
50 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
51 | if (!res) | ||
52 | return -ENODEV; | ||
53 | |||
54 | /* | ||
55 | * We don't use devm_ioremap() because this mapping should | ||
56 | * only exists for the duration of this probe function. | ||
57 | */ | ||
58 | base = ioremap(res->start, resource_size(res)); | ||
59 | if (!base) | ||
60 | return -ENODEV; | ||
61 | |||
62 | dram = mv_mbus_dram_info(); | ||
63 | xhci_mvebu_mbus_config(base, dram); | ||
64 | |||
65 | /* | ||
66 | * This memory area was only needed to configure the MBus | ||
67 | * windows, and is therefore no longer useful. | ||
68 | */ | ||
69 | iounmap(base); | ||
70 | |||
71 | return 0; | ||
72 | } | ||
diff --git a/drivers/usb/host/xhci-mvebu.h b/drivers/usb/host/xhci-mvebu.h new file mode 100644 index 000000000000..7ede92aa41f6 --- /dev/null +++ b/drivers/usb/host/xhci-mvebu.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Marvell | ||
3 | * | ||
4 | * Gregory Clement <gregory.clement@free-electrons.com> | ||
5 | * | ||
6 | * This file is licensed under the terms of the GNU General Public | ||
7 | * License version 2. This program is licensed "as is" without any | ||
8 | * warranty of any kind, whether express or implied. | ||
9 | */ | ||
10 | |||
11 | #ifndef __LINUX_XHCI_MVEBU_H | ||
12 | #define __LINUX_XHCI_MVEBU_H | ||
13 | #if IS_ENABLED(CONFIG_USB_XHCI_MVEBU) | ||
14 | int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev); | ||
15 | #else | ||
16 | static inline int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev) | ||
17 | { | ||
18 | return 0; | ||
19 | } | ||
20 | #endif | ||
21 | #endif /* __LINUX_XHCI_MVEBU_H */ | ||
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 35d447780707..e20520f42753 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -134,14 +134,14 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) | |||
134 | */ | 134 | */ |
135 | if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP) | 135 | if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP) |
136 | xhci->quirks |= XHCI_SPURIOUS_WAKEUP; | 136 | xhci->quirks |= XHCI_SPURIOUS_WAKEUP; |
137 | 137 | } | |
138 | if (pdev->vendor == PCI_VENDOR_ID_INTEL && | ||
139 | pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI) { | ||
138 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; | 140 | xhci->quirks |= XHCI_SPURIOUS_REBOOT; |
139 | } | 141 | } |
140 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && | 142 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
141 | pdev->device == PCI_DEVICE_ID_ASROCK_P67) { | 143 | pdev->device == PCI_DEVICE_ID_ASROCK_P67) { |
142 | xhci->quirks |= XHCI_RESET_ON_RESUME; | 144 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
143 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
144 | "QUIRK: Resetting on resume"); | ||
145 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; | 145 | xhci->quirks |= XHCI_TRUST_TX_LENGTH; |
146 | } | 146 | } |
147 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && | 147 | if (pdev->vendor == PCI_VENDOR_ID_RENESAS && |
@@ -149,6 +149,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) | |||
149 | xhci->quirks |= XHCI_RESET_ON_RESUME; | 149 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
150 | if (pdev->vendor == PCI_VENDOR_ID_VIA) | 150 | if (pdev->vendor == PCI_VENDOR_ID_VIA) |
151 | xhci->quirks |= XHCI_RESET_ON_RESUME; | 151 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
152 | |||
153 | if (xhci->quirks & XHCI_RESET_ON_RESUME) | ||
154 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | ||
155 | "QUIRK: Resetting on resume"); | ||
152 | } | 156 | } |
153 | 157 | ||
154 | /* called during probe() after chip reset completes */ | 158 | /* called during probe() after chip reset completes */ |
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 151901ce1ba9..29d8adb5c8d1 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c | |||
@@ -11,13 +11,15 @@ | |||
11 | * version 2 as published by the Free Software Foundation. | 11 | * version 2 as published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/platform_device.h> | 14 | #include <linux/clk.h> |
15 | #include <linux/dma-mapping.h> | ||
15 | #include <linux/module.h> | 16 | #include <linux/module.h> |
16 | #include <linux/slab.h> | ||
17 | #include <linux/of.h> | 17 | #include <linux/of.h> |
18 | #include <linux/dma-mapping.h> | 18 | #include <linux/platform_device.h> |
19 | #include <linux/slab.h> | ||
19 | 20 | ||
20 | #include "xhci.h" | 21 | #include "xhci.h" |
22 | #include "xhci-mvebu.h" | ||
21 | 23 | ||
22 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) | 24 | static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) |
23 | { | 25 | { |
@@ -35,6 +37,11 @@ static int xhci_plat_setup(struct usb_hcd *hcd) | |||
35 | return xhci_gen_setup(hcd, xhci_plat_quirks); | 37 | return xhci_gen_setup(hcd, xhci_plat_quirks); |
36 | } | 38 | } |
37 | 39 | ||
40 | static int xhci_plat_start(struct usb_hcd *hcd) | ||
41 | { | ||
42 | return xhci_run(hcd); | ||
43 | } | ||
44 | |||
38 | static const struct hc_driver xhci_plat_xhci_driver = { | 45 | static const struct hc_driver xhci_plat_xhci_driver = { |
39 | .description = "xhci-hcd", | 46 | .description = "xhci-hcd", |
40 | .product_desc = "xHCI Host Controller", | 47 | .product_desc = "xHCI Host Controller", |
@@ -50,7 +57,7 @@ static const struct hc_driver xhci_plat_xhci_driver = { | |||
50 | * basic lifecycle operations | 57 | * basic lifecycle operations |
51 | */ | 58 | */ |
52 | .reset = xhci_plat_setup, | 59 | .reset = xhci_plat_setup, |
53 | .start = xhci_run, | 60 | .start = xhci_plat_start, |
54 | .stop = xhci_stop, | 61 | .stop = xhci_stop, |
55 | .shutdown = xhci_shutdown, | 62 | .shutdown = xhci_shutdown, |
56 | 63 | ||
@@ -91,6 +98,7 @@ static int xhci_plat_probe(struct platform_device *pdev) | |||
91 | struct xhci_hcd *xhci; | 98 | struct xhci_hcd *xhci; |
92 | struct resource *res; | 99 | struct resource *res; |
93 | struct usb_hcd *hcd; | 100 | struct usb_hcd *hcd; |
101 | struct clk *clk; | ||
94 | int ret; | 102 | int ret; |
95 | int irq; | 103 | int irq; |
96 | 104 | ||
@@ -107,6 +115,15 @@ static int xhci_plat_probe(struct platform_device *pdev) | |||
107 | if (!res) | 115 | if (!res) |
108 | return -ENODEV; | 116 | return -ENODEV; |
109 | 117 | ||
118 | if (of_device_is_compatible(pdev->dev.of_node, | ||
119 | "marvell,armada-375-xhci") || | ||
120 | of_device_is_compatible(pdev->dev.of_node, | ||
121 | "marvell,armada-380-xhci")) { | ||
122 | ret = xhci_mvebu_mbus_init_quirk(pdev); | ||
123 | if (ret) | ||
124 | return ret; | ||
125 | } | ||
126 | |||
110 | /* Initialize dma_mask and coherent_dma_mask to 32-bits */ | 127 | /* Initialize dma_mask and coherent_dma_mask to 32-bits */ |
111 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); | 128 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
112 | if (ret) | 129 | if (ret) |
@@ -137,14 +154,27 @@ static int xhci_plat_probe(struct platform_device *pdev) | |||
137 | goto release_mem_region; | 154 | goto release_mem_region; |
138 | } | 155 | } |
139 | 156 | ||
157 | /* | ||
158 | * Not all platforms have a clk so it is not an error if the | ||
159 | * clock does not exists. | ||
160 | */ | ||
161 | clk = devm_clk_get(&pdev->dev, NULL); | ||
162 | if (!IS_ERR(clk)) { | ||
163 | ret = clk_prepare_enable(clk); | ||
164 | if (ret) | ||
165 | goto unmap_registers; | ||
166 | } | ||
167 | |||
140 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); | 168 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
141 | if (ret) | 169 | if (ret) |
142 | goto unmap_registers; | 170 | goto disable_clk; |
171 | |||
143 | device_wakeup_enable(hcd->self.controller); | 172 | device_wakeup_enable(hcd->self.controller); |
144 | 173 | ||
145 | /* USB 2.0 roothub is stored in the platform_device now. */ | 174 | /* USB 2.0 roothub is stored in the platform_device now. */ |
146 | hcd = platform_get_drvdata(pdev); | 175 | hcd = platform_get_drvdata(pdev); |
147 | xhci = hcd_to_xhci(hcd); | 176 | xhci = hcd_to_xhci(hcd); |
177 | xhci->clk = clk; | ||
148 | xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev, | 178 | xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev, |
149 | dev_name(&pdev->dev), hcd); | 179 | dev_name(&pdev->dev), hcd); |
150 | if (!xhci->shared_hcd) { | 180 | if (!xhci->shared_hcd) { |
@@ -173,6 +203,10 @@ put_usb3_hcd: | |||
173 | dealloc_usb2_hcd: | 203 | dealloc_usb2_hcd: |
174 | usb_remove_hcd(hcd); | 204 | usb_remove_hcd(hcd); |
175 | 205 | ||
206 | disable_clk: | ||
207 | if (!IS_ERR(clk)) | ||
208 | clk_disable_unprepare(clk); | ||
209 | |||
176 | unmap_registers: | 210 | unmap_registers: |
177 | iounmap(hcd->regs); | 211 | iounmap(hcd->regs); |
178 | 212 | ||
@@ -189,11 +223,14 @@ static int xhci_plat_remove(struct platform_device *dev) | |||
189 | { | 223 | { |
190 | struct usb_hcd *hcd = platform_get_drvdata(dev); | 224 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
191 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 225 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
226 | struct clk *clk = xhci->clk; | ||
192 | 227 | ||
193 | usb_remove_hcd(xhci->shared_hcd); | 228 | usb_remove_hcd(xhci->shared_hcd); |
194 | usb_put_hcd(xhci->shared_hcd); | 229 | usb_put_hcd(xhci->shared_hcd); |
195 | 230 | ||
196 | usb_remove_hcd(hcd); | 231 | usb_remove_hcd(hcd); |
232 | if (!IS_ERR(clk)) | ||
233 | clk_disable_unprepare(clk); | ||
197 | iounmap(hcd->regs); | 234 | iounmap(hcd->regs); |
198 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 235 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
199 | usb_put_hcd(hcd); | 236 | usb_put_hcd(hcd); |
@@ -202,7 +239,7 @@ static int xhci_plat_remove(struct platform_device *dev) | |||
202 | return 0; | 239 | return 0; |
203 | } | 240 | } |
204 | 241 | ||
205 | #ifdef CONFIG_PM | 242 | #ifdef CONFIG_PM_SLEEP |
206 | static int xhci_plat_suspend(struct device *dev) | 243 | static int xhci_plat_suspend(struct device *dev) |
207 | { | 244 | { |
208 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 245 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
@@ -231,6 +268,8 @@ static const struct dev_pm_ops xhci_plat_pm_ops = { | |||
231 | static const struct of_device_id usb_xhci_of_match[] = { | 268 | static const struct of_device_id usb_xhci_of_match[] = { |
232 | { .compatible = "generic-xhci" }, | 269 | { .compatible = "generic-xhci" }, |
233 | { .compatible = "xhci-platform" }, | 270 | { .compatible = "xhci-platform" }, |
271 | { .compatible = "marvell,armada-375-xhci"}, | ||
272 | { .compatible = "marvell,armada-380-xhci"}, | ||
234 | { }, | 273 | { }, |
235 | }; | 274 | }; |
236 | MODULE_DEVICE_TABLE(of, usb_xhci_of_match); | 275 | MODULE_DEVICE_TABLE(of, usb_xhci_of_match); |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 7a0e3c720c00..d67ff71209f5 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -69,10 +69,6 @@ | |||
69 | #include "xhci.h" | 69 | #include "xhci.h" |
70 | #include "xhci-trace.h" | 70 | #include "xhci-trace.h" |
71 | 71 | ||
72 | static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, | ||
73 | struct xhci_virt_device *virt_dev, | ||
74 | struct xhci_event_cmd *event); | ||
75 | |||
76 | /* | 72 | /* |
77 | * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA | 73 | * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA |
78 | * address of the TRB. | 74 | * address of the TRB. |
@@ -123,16 +119,6 @@ static int enqueue_is_link_trb(struct xhci_ring *ring) | |||
123 | return TRB_TYPE_LINK_LE32(link->control); | 119 | return TRB_TYPE_LINK_LE32(link->control); |
124 | } | 120 | } |
125 | 121 | ||
126 | union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring) | ||
127 | { | ||
128 | /* Enqueue pointer can be left pointing to the link TRB, | ||
129 | * we must handle that | ||
130 | */ | ||
131 | if (TRB_TYPE_LINK_LE32(ring->enqueue->link.control)) | ||
132 | return ring->enq_seg->next->trbs; | ||
133 | return ring->enqueue; | ||
134 | } | ||
135 | |||
136 | /* Updates trb to point to the next TRB in the ring, and updates seg if the next | 122 | /* Updates trb to point to the next TRB in the ring, and updates seg if the next |
137 | * TRB is in a new segment. This does not skip over link TRBs, and it does not | 123 | * TRB is in a new segment. This does not skip over link TRBs, and it does not |
138 | * effect the ring dequeue or enqueue pointers. | 124 | * effect the ring dequeue or enqueue pointers. |
@@ -301,17 +287,7 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) | |||
301 | 287 | ||
302 | xhci_dbg(xhci, "Abort command ring\n"); | 288 | xhci_dbg(xhci, "Abort command ring\n"); |
303 | 289 | ||
304 | if (!(xhci->cmd_ring_state & CMD_RING_STATE_RUNNING)) { | ||
305 | xhci_dbg(xhci, "The command ring isn't running, " | ||
306 | "Have the command ring been stopped?\n"); | ||
307 | return 0; | ||
308 | } | ||
309 | |||
310 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | 290 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); |
311 | if (!(temp_64 & CMD_RING_RUNNING)) { | ||
312 | xhci_dbg(xhci, "Command ring had been stopped\n"); | ||
313 | return 0; | ||
314 | } | ||
315 | xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; | 291 | xhci->cmd_ring_state = CMD_RING_STATE_ABORTED; |
316 | xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, | 292 | xhci_write_64(xhci, temp_64 | CMD_RING_ABORT, |
317 | &xhci->op_regs->cmd_ring); | 293 | &xhci->op_regs->cmd_ring); |
@@ -337,71 +313,6 @@ static int xhci_abort_cmd_ring(struct xhci_hcd *xhci) | |||
337 | return 0; | 313 | return 0; |
338 | } | 314 | } |
339 | 315 | ||
340 | static int xhci_queue_cd(struct xhci_hcd *xhci, | ||
341 | struct xhci_command *command, | ||
342 | union xhci_trb *cmd_trb) | ||
343 | { | ||
344 | struct xhci_cd *cd; | ||
345 | cd = kzalloc(sizeof(struct xhci_cd), GFP_ATOMIC); | ||
346 | if (!cd) | ||
347 | return -ENOMEM; | ||
348 | INIT_LIST_HEAD(&cd->cancel_cmd_list); | ||
349 | |||
350 | cd->command = command; | ||
351 | cd->cmd_trb = cmd_trb; | ||
352 | list_add_tail(&cd->cancel_cmd_list, &xhci->cancel_cmd_list); | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | /* | ||
358 | * Cancel the command which has issue. | ||
359 | * | ||
360 | * Some commands may hang due to waiting for acknowledgement from | ||
361 | * usb device. It is outside of the xHC's ability to control and | ||
362 | * will cause the command ring is blocked. When it occurs software | ||
363 | * should intervene to recover the command ring. | ||
364 | * See Section 4.6.1.1 and 4.6.1.2 | ||
365 | */ | ||
366 | int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, | ||
367 | union xhci_trb *cmd_trb) | ||
368 | { | ||
369 | int retval = 0; | ||
370 | unsigned long flags; | ||
371 | |||
372 | spin_lock_irqsave(&xhci->lock, flags); | ||
373 | |||
374 | if (xhci->xhc_state & XHCI_STATE_DYING) { | ||
375 | xhci_warn(xhci, "Abort the command ring," | ||
376 | " but the xHCI is dead.\n"); | ||
377 | retval = -ESHUTDOWN; | ||
378 | goto fail; | ||
379 | } | ||
380 | |||
381 | /* queue the cmd desriptor to cancel_cmd_list */ | ||
382 | retval = xhci_queue_cd(xhci, command, cmd_trb); | ||
383 | if (retval) { | ||
384 | xhci_warn(xhci, "Queuing command descriptor failed.\n"); | ||
385 | goto fail; | ||
386 | } | ||
387 | |||
388 | /* abort command ring */ | ||
389 | retval = xhci_abort_cmd_ring(xhci); | ||
390 | if (retval) { | ||
391 | xhci_err(xhci, "Abort command ring failed\n"); | ||
392 | if (unlikely(retval == -ESHUTDOWN)) { | ||
393 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
394 | usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); | ||
395 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); | ||
396 | return retval; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | fail: | ||
401 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
402 | return retval; | ||
403 | } | ||
404 | |||
405 | void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, | 316 | void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, |
406 | unsigned int slot_id, | 317 | unsigned int slot_id, |
407 | unsigned int ep_index, | 318 | unsigned int ep_index, |
@@ -684,12 +595,14 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | |||
684 | } | 595 | } |
685 | } | 596 | } |
686 | 597 | ||
687 | static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | 598 | static int queue_set_tr_deq(struct xhci_hcd *xhci, |
599 | struct xhci_command *cmd, int slot_id, | ||
688 | unsigned int ep_index, unsigned int stream_id, | 600 | unsigned int ep_index, unsigned int stream_id, |
689 | struct xhci_segment *deq_seg, | 601 | struct xhci_segment *deq_seg, |
690 | union xhci_trb *deq_ptr, u32 cycle_state); | 602 | union xhci_trb *deq_ptr, u32 cycle_state); |
691 | 603 | ||
692 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | 604 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
605 | struct xhci_command *cmd, | ||
693 | unsigned int slot_id, unsigned int ep_index, | 606 | unsigned int slot_id, unsigned int ep_index, |
694 | unsigned int stream_id, | 607 | unsigned int stream_id, |
695 | struct xhci_dequeue_state *deq_state) | 608 | struct xhci_dequeue_state *deq_state) |
@@ -704,7 +617,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | |||
704 | deq_state->new_deq_ptr, | 617 | deq_state->new_deq_ptr, |
705 | (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr), | 618 | (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr), |
706 | deq_state->new_cycle_state); | 619 | deq_state->new_cycle_state); |
707 | queue_set_tr_deq(xhci, slot_id, ep_index, stream_id, | 620 | queue_set_tr_deq(xhci, cmd, slot_id, ep_index, stream_id, |
708 | deq_state->new_deq_seg, | 621 | deq_state->new_deq_seg, |
709 | deq_state->new_deq_ptr, | 622 | deq_state->new_deq_ptr, |
710 | (u32) deq_state->new_cycle_state); | 623 | (u32) deq_state->new_cycle_state); |
@@ -773,7 +686,6 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, | |||
773 | union xhci_trb *trb, struct xhci_event_cmd *event) | 686 | union xhci_trb *trb, struct xhci_event_cmd *event) |
774 | { | 687 | { |
775 | unsigned int ep_index; | 688 | unsigned int ep_index; |
776 | struct xhci_virt_device *virt_dev; | ||
777 | struct xhci_ring *ep_ring; | 689 | struct xhci_ring *ep_ring; |
778 | struct xhci_virt_ep *ep; | 690 | struct xhci_virt_ep *ep; |
779 | struct list_head *entry; | 691 | struct list_head *entry; |
@@ -783,11 +695,7 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id, | |||
783 | struct xhci_dequeue_state deq_state; | 695 | struct xhci_dequeue_state deq_state; |
784 | 696 | ||
785 | if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { | 697 | if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) { |
786 | virt_dev = xhci->devs[slot_id]; | 698 | if (!xhci->devs[slot_id]) |
787 | if (virt_dev) | ||
788 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, | ||
789 | event); | ||
790 | else | ||
791 | xhci_warn(xhci, "Stop endpoint command " | 699 | xhci_warn(xhci, "Stop endpoint command " |
792 | "completion for disabled slot %u\n", | 700 | "completion for disabled slot %u\n", |
793 | slot_id); | 701 | slot_id); |
@@ -858,7 +766,9 @@ remove_finished_td: | |||
858 | 766 | ||
859 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ | 767 | /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ |
860 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { | 768 | if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { |
861 | xhci_queue_new_dequeue_state(xhci, | 769 | struct xhci_command *command; |
770 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
771 | xhci_queue_new_dequeue_state(xhci, command, | ||
862 | slot_id, ep_index, | 772 | slot_id, ep_index, |
863 | ep->stopped_td->urb->stream_id, | 773 | ep->stopped_td->urb->stream_id, |
864 | &deq_state); | 774 | &deq_state); |
@@ -1206,9 +1116,11 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, | |||
1206 | * because the HW can't handle two commands being queued in a row. | 1116 | * because the HW can't handle two commands being queued in a row. |
1207 | */ | 1117 | */ |
1208 | if (xhci->quirks & XHCI_RESET_EP_QUIRK) { | 1118 | if (xhci->quirks & XHCI_RESET_EP_QUIRK) { |
1119 | struct xhci_command *command; | ||
1120 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
1209 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | 1121 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
1210 | "Queueing configure endpoint command"); | 1122 | "Queueing configure endpoint command"); |
1211 | xhci_queue_configure_endpoint(xhci, | 1123 | xhci_queue_configure_endpoint(xhci, command, |
1212 | xhci->devs[slot_id]->in_ctx->dma, slot_id, | 1124 | xhci->devs[slot_id]->in_ctx->dma, slot_id, |
1213 | false); | 1125 | false); |
1214 | xhci_ring_cmd_db(xhci); | 1126 | xhci_ring_cmd_db(xhci); |
@@ -1219,187 +1131,6 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id, | |||
1219 | } | 1131 | } |
1220 | } | 1132 | } |
1221 | 1133 | ||
1222 | /* Complete the command and detele it from the devcie's command queue. | ||
1223 | */ | ||
1224 | static void xhci_complete_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, | ||
1225 | struct xhci_command *command, u32 status) | ||
1226 | { | ||
1227 | command->status = status; | ||
1228 | list_del(&command->cmd_list); | ||
1229 | if (command->completion) | ||
1230 | complete(command->completion); | ||
1231 | else | ||
1232 | xhci_free_command(xhci, command); | ||
1233 | } | ||
1234 | |||
1235 | |||
1236 | /* Check to see if a command in the device's command queue matches this one. | ||
1237 | * Signal the completion or free the command, and return 1. Return 0 if the | ||
1238 | * completed command isn't at the head of the command list. | ||
1239 | */ | ||
1240 | static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci, | ||
1241 | struct xhci_virt_device *virt_dev, | ||
1242 | struct xhci_event_cmd *event) | ||
1243 | { | ||
1244 | struct xhci_command *command; | ||
1245 | |||
1246 | if (list_empty(&virt_dev->cmd_list)) | ||
1247 | return 0; | ||
1248 | |||
1249 | command = list_entry(virt_dev->cmd_list.next, | ||
1250 | struct xhci_command, cmd_list); | ||
1251 | if (xhci->cmd_ring->dequeue != command->command_trb) | ||
1252 | return 0; | ||
1253 | |||
1254 | xhci_complete_cmd_in_cmd_wait_list(xhci, command, | ||
1255 | GET_COMP_CODE(le32_to_cpu(event->status))); | ||
1256 | return 1; | ||
1257 | } | ||
1258 | |||
1259 | /* | ||
1260 | * Finding the command trb need to be cancelled and modifying it to | ||
1261 | * NO OP command. And if the command is in device's command wait | ||
1262 | * list, finishing and freeing it. | ||
1263 | * | ||
1264 | * If we can't find the command trb, we think it had already been | ||
1265 | * executed. | ||
1266 | */ | ||
1267 | static void xhci_cmd_to_noop(struct xhci_hcd *xhci, struct xhci_cd *cur_cd) | ||
1268 | { | ||
1269 | struct xhci_segment *cur_seg; | ||
1270 | union xhci_trb *cmd_trb; | ||
1271 | u32 cycle_state; | ||
1272 | |||
1273 | if (xhci->cmd_ring->dequeue == xhci->cmd_ring->enqueue) | ||
1274 | return; | ||
1275 | |||
1276 | /* find the current segment of command ring */ | ||
1277 | cur_seg = find_trb_seg(xhci->cmd_ring->first_seg, | ||
1278 | xhci->cmd_ring->dequeue, &cycle_state); | ||
1279 | |||
1280 | if (!cur_seg) { | ||
1281 | xhci_warn(xhci, "Command ring mismatch, dequeue = %p %llx (dma)\n", | ||
1282 | xhci->cmd_ring->dequeue, | ||
1283 | (unsigned long long) | ||
1284 | xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, | ||
1285 | xhci->cmd_ring->dequeue)); | ||
1286 | xhci_debug_ring(xhci, xhci->cmd_ring); | ||
1287 | xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); | ||
1288 | return; | ||
1289 | } | ||
1290 | |||
1291 | /* find the command trb matched by cd from command ring */ | ||
1292 | for (cmd_trb = xhci->cmd_ring->dequeue; | ||
1293 | cmd_trb != xhci->cmd_ring->enqueue; | ||
1294 | next_trb(xhci, xhci->cmd_ring, &cur_seg, &cmd_trb)) { | ||
1295 | /* If the trb is link trb, continue */ | ||
1296 | if (TRB_TYPE_LINK_LE32(cmd_trb->generic.field[3])) | ||
1297 | continue; | ||
1298 | |||
1299 | if (cur_cd->cmd_trb == cmd_trb) { | ||
1300 | |||
1301 | /* If the command in device's command list, we should | ||
1302 | * finish it and free the command structure. | ||
1303 | */ | ||
1304 | if (cur_cd->command) | ||
1305 | xhci_complete_cmd_in_cmd_wait_list(xhci, | ||
1306 | cur_cd->command, COMP_CMD_STOP); | ||
1307 | |||
1308 | /* get cycle state from the origin command trb */ | ||
1309 | cycle_state = le32_to_cpu(cmd_trb->generic.field[3]) | ||
1310 | & TRB_CYCLE; | ||
1311 | |||
1312 | /* modify the command trb to NO OP command */ | ||
1313 | cmd_trb->generic.field[0] = 0; | ||
1314 | cmd_trb->generic.field[1] = 0; | ||
1315 | cmd_trb->generic.field[2] = 0; | ||
1316 | cmd_trb->generic.field[3] = cpu_to_le32( | ||
1317 | TRB_TYPE(TRB_CMD_NOOP) | cycle_state); | ||
1318 | break; | ||
1319 | } | ||
1320 | } | ||
1321 | } | ||
1322 | |||
1323 | static void xhci_cancel_cmd_in_cd_list(struct xhci_hcd *xhci) | ||
1324 | { | ||
1325 | struct xhci_cd *cur_cd, *next_cd; | ||
1326 | |||
1327 | if (list_empty(&xhci->cancel_cmd_list)) | ||
1328 | return; | ||
1329 | |||
1330 | list_for_each_entry_safe(cur_cd, next_cd, | ||
1331 | &xhci->cancel_cmd_list, cancel_cmd_list) { | ||
1332 | xhci_cmd_to_noop(xhci, cur_cd); | ||
1333 | list_del(&cur_cd->cancel_cmd_list); | ||
1334 | kfree(cur_cd); | ||
1335 | } | ||
1336 | } | ||
1337 | |||
1338 | /* | ||
1339 | * traversing the cancel_cmd_list. If the command descriptor according | ||
1340 | * to cmd_trb is found, the function free it and return 1, otherwise | ||
1341 | * return 0. | ||
1342 | */ | ||
1343 | static int xhci_search_cmd_trb_in_cd_list(struct xhci_hcd *xhci, | ||
1344 | union xhci_trb *cmd_trb) | ||
1345 | { | ||
1346 | struct xhci_cd *cur_cd, *next_cd; | ||
1347 | |||
1348 | if (list_empty(&xhci->cancel_cmd_list)) | ||
1349 | return 0; | ||
1350 | |||
1351 | list_for_each_entry_safe(cur_cd, next_cd, | ||
1352 | &xhci->cancel_cmd_list, cancel_cmd_list) { | ||
1353 | if (cur_cd->cmd_trb == cmd_trb) { | ||
1354 | if (cur_cd->command) | ||
1355 | xhci_complete_cmd_in_cmd_wait_list(xhci, | ||
1356 | cur_cd->command, COMP_CMD_STOP); | ||
1357 | list_del(&cur_cd->cancel_cmd_list); | ||
1358 | kfree(cur_cd); | ||
1359 | return 1; | ||
1360 | } | ||
1361 | } | ||
1362 | |||
1363 | return 0; | ||
1364 | } | ||
1365 | |||
1366 | /* | ||
1367 | * If the cmd_trb_comp_code is COMP_CMD_ABORT, we just check whether the | ||
1368 | * trb pointed by the command ring dequeue pointer is the trb we want to | ||
1369 | * cancel or not. And if the cmd_trb_comp_code is COMP_CMD_STOP, we will | ||
1370 | * traverse the cancel_cmd_list to trun the all of the commands according | ||
1371 | * to command descriptor to NO-OP trb. | ||
1372 | */ | ||
1373 | static int handle_stopped_cmd_ring(struct xhci_hcd *xhci, | ||
1374 | int cmd_trb_comp_code) | ||
1375 | { | ||
1376 | int cur_trb_is_good = 0; | ||
1377 | |||
1378 | /* Searching the cmd trb pointed by the command ring dequeue | ||
1379 | * pointer in command descriptor list. If it is found, free it. | ||
1380 | */ | ||
1381 | cur_trb_is_good = xhci_search_cmd_trb_in_cd_list(xhci, | ||
1382 | xhci->cmd_ring->dequeue); | ||
1383 | |||
1384 | if (cmd_trb_comp_code == COMP_CMD_ABORT) | ||
1385 | xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; | ||
1386 | else if (cmd_trb_comp_code == COMP_CMD_STOP) { | ||
1387 | /* traversing the cancel_cmd_list and canceling | ||
1388 | * the command according to command descriptor | ||
1389 | */ | ||
1390 | xhci_cancel_cmd_in_cd_list(xhci); | ||
1391 | |||
1392 | xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; | ||
1393 | /* | ||
1394 | * ring command ring doorbell again to restart the | ||
1395 | * command ring | ||
1396 | */ | ||
1397 | if (xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) | ||
1398 | xhci_ring_cmd_db(xhci); | ||
1399 | } | ||
1400 | return cur_trb_is_good; | ||
1401 | } | ||
1402 | |||
1403 | static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, | 1134 | static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, |
1404 | u32 cmd_comp_code) | 1135 | u32 cmd_comp_code) |
1405 | { | 1136 | { |
@@ -1407,7 +1138,6 @@ static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id, | |||
1407 | xhci->slot_id = slot_id; | 1138 | xhci->slot_id = slot_id; |
1408 | else | 1139 | else |
1409 | xhci->slot_id = 0; | 1140 | xhci->slot_id = 0; |
1410 | complete(&xhci->addr_dev); | ||
1411 | } | 1141 | } |
1412 | 1142 | ||
1413 | static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) | 1143 | static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id) |
@@ -1432,9 +1162,6 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, | |||
1432 | unsigned int ep_state; | 1162 | unsigned int ep_state; |
1433 | u32 add_flags, drop_flags; | 1163 | u32 add_flags, drop_flags; |
1434 | 1164 | ||
1435 | virt_dev = xhci->devs[slot_id]; | ||
1436 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1437 | return; | ||
1438 | /* | 1165 | /* |
1439 | * Configure endpoint commands can come from the USB core | 1166 | * Configure endpoint commands can come from the USB core |
1440 | * configuration or alt setting changes, or because the HW | 1167 | * configuration or alt setting changes, or because the HW |
@@ -1443,6 +1170,7 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, | |||
1443 | * If the command was for a halted endpoint, the xHCI driver | 1170 | * If the command was for a halted endpoint, the xHCI driver |
1444 | * is not waiting on the configure endpoint command. | 1171 | * is not waiting on the configure endpoint command. |
1445 | */ | 1172 | */ |
1173 | virt_dev = xhci->devs[slot_id]; | ||
1446 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | 1174 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); |
1447 | if (!ctrl_ctx) { | 1175 | if (!ctrl_ctx) { |
1448 | xhci_warn(xhci, "Could not get input context, bad type.\n"); | 1176 | xhci_warn(xhci, "Could not get input context, bad type.\n"); |
@@ -1465,7 +1193,7 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, | |||
1465 | add_flags - SLOT_FLAG == drop_flags) { | 1193 | add_flags - SLOT_FLAG == drop_flags) { |
1466 | ep_state = virt_dev->eps[ep_index].ep_state; | 1194 | ep_state = virt_dev->eps[ep_index].ep_state; |
1467 | if (!(ep_state & EP_HALTED)) | 1195 | if (!(ep_state & EP_HALTED)) |
1468 | goto bandwidth_change; | 1196 | return; |
1469 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, | 1197 | xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, |
1470 | "Completed config ep cmd - " | 1198 | "Completed config ep cmd - " |
1471 | "last ep index = %d, state = %d", | 1199 | "last ep index = %d, state = %d", |
@@ -1475,43 +1203,14 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id, | |||
1475 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); | 1203 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); |
1476 | return; | 1204 | return; |
1477 | } | 1205 | } |
1478 | bandwidth_change: | ||
1479 | xhci_dbg_trace(xhci, trace_xhci_dbg_context_change, | ||
1480 | "Completed config ep cmd"); | ||
1481 | virt_dev->cmd_status = cmd_comp_code; | ||
1482 | complete(&virt_dev->cmd_completion); | ||
1483 | return; | 1206 | return; |
1484 | } | 1207 | } |
1485 | 1208 | ||
1486 | static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id, | ||
1487 | struct xhci_event_cmd *event, u32 cmd_comp_code) | ||
1488 | { | ||
1489 | struct xhci_virt_device *virt_dev; | ||
1490 | |||
1491 | virt_dev = xhci->devs[slot_id]; | ||
1492 | if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event)) | ||
1493 | return; | ||
1494 | virt_dev->cmd_status = cmd_comp_code; | ||
1495 | complete(&virt_dev->cmd_completion); | ||
1496 | } | ||
1497 | |||
1498 | static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id, | ||
1499 | u32 cmd_comp_code) | ||
1500 | { | ||
1501 | xhci->devs[slot_id]->cmd_status = cmd_comp_code; | ||
1502 | complete(&xhci->addr_dev); | ||
1503 | } | ||
1504 | |||
1505 | static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, | 1209 | static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id, |
1506 | struct xhci_event_cmd *event) | 1210 | struct xhci_event_cmd *event) |
1507 | { | 1211 | { |
1508 | struct xhci_virt_device *virt_dev; | ||
1509 | |||
1510 | xhci_dbg(xhci, "Completed reset device command.\n"); | 1212 | xhci_dbg(xhci, "Completed reset device command.\n"); |
1511 | virt_dev = xhci->devs[slot_id]; | 1213 | if (!xhci->devs[slot_id]) |
1512 | if (virt_dev) | ||
1513 | handle_cmd_in_cmd_wait_list(xhci, virt_dev, event); | ||
1514 | else | ||
1515 | xhci_warn(xhci, "Reset device command completion " | 1214 | xhci_warn(xhci, "Reset device command completion " |
1516 | "for disabled slot %u\n", slot_id); | 1215 | "for disabled slot %u\n", slot_id); |
1517 | } | 1216 | } |
@@ -1529,6 +1228,116 @@ static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci, | |||
1529 | NEC_FW_MINOR(le32_to_cpu(event->status))); | 1228 | NEC_FW_MINOR(le32_to_cpu(event->status))); |
1530 | } | 1229 | } |
1531 | 1230 | ||
1231 | static void xhci_complete_del_and_free_cmd(struct xhci_command *cmd, u32 status) | ||
1232 | { | ||
1233 | list_del(&cmd->cmd_list); | ||
1234 | |||
1235 | if (cmd->completion) { | ||
1236 | cmd->status = status; | ||
1237 | complete(cmd->completion); | ||
1238 | } else { | ||
1239 | kfree(cmd); | ||
1240 | } | ||
1241 | } | ||
1242 | |||
1243 | void xhci_cleanup_command_queue(struct xhci_hcd *xhci) | ||
1244 | { | ||
1245 | struct xhci_command *cur_cmd, *tmp_cmd; | ||
1246 | list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) | ||
1247 | xhci_complete_del_and_free_cmd(cur_cmd, COMP_CMD_ABORT); | ||
1248 | } | ||
1249 | |||
1250 | /* | ||
1251 | * Turn all commands on command ring with status set to "aborted" to no-op trbs. | ||
1252 | * If there are other commands waiting then restart the ring and kick the timer. | ||
1253 | * This must be called with command ring stopped and xhci->lock held. | ||
1254 | */ | ||
1255 | static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci, | ||
1256 | struct xhci_command *cur_cmd) | ||
1257 | { | ||
1258 | struct xhci_command *i_cmd, *tmp_cmd; | ||
1259 | u32 cycle_state; | ||
1260 | |||
1261 | /* Turn all aborted commands in list to no-ops, then restart */ | ||
1262 | list_for_each_entry_safe(i_cmd, tmp_cmd, &xhci->cmd_list, | ||
1263 | cmd_list) { | ||
1264 | |||
1265 | if (i_cmd->status != COMP_CMD_ABORT) | ||
1266 | continue; | ||
1267 | |||
1268 | i_cmd->status = COMP_CMD_STOP; | ||
1269 | |||
1270 | xhci_dbg(xhci, "Turn aborted command %p to no-op\n", | ||
1271 | i_cmd->command_trb); | ||
1272 | /* get cycle state from the original cmd trb */ | ||
1273 | cycle_state = le32_to_cpu( | ||
1274 | i_cmd->command_trb->generic.field[3]) & TRB_CYCLE; | ||
1275 | /* modify the command trb to no-op command */ | ||
1276 | i_cmd->command_trb->generic.field[0] = 0; | ||
1277 | i_cmd->command_trb->generic.field[1] = 0; | ||
1278 | i_cmd->command_trb->generic.field[2] = 0; | ||
1279 | i_cmd->command_trb->generic.field[3] = cpu_to_le32( | ||
1280 | TRB_TYPE(TRB_CMD_NOOP) | cycle_state); | ||
1281 | |||
1282 | /* | ||
1283 | * caller waiting for completion is called when command | ||
1284 | * completion event is received for these no-op commands | ||
1285 | */ | ||
1286 | } | ||
1287 | |||
1288 | xhci->cmd_ring_state = CMD_RING_STATE_RUNNING; | ||
1289 | |||
1290 | /* ring command ring doorbell to restart the command ring */ | ||
1291 | if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && | ||
1292 | !(xhci->xhc_state & XHCI_STATE_DYING)) { | ||
1293 | xhci->current_cmd = cur_cmd; | ||
1294 | mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); | ||
1295 | xhci_ring_cmd_db(xhci); | ||
1296 | } | ||
1297 | return; | ||
1298 | } | ||
1299 | |||
1300 | |||
1301 | void xhci_handle_command_timeout(unsigned long data) | ||
1302 | { | ||
1303 | struct xhci_hcd *xhci; | ||
1304 | int ret; | ||
1305 | unsigned long flags; | ||
1306 | u64 hw_ring_state; | ||
1307 | struct xhci_command *cur_cmd = NULL; | ||
1308 | xhci = (struct xhci_hcd *) data; | ||
1309 | |||
1310 | /* mark this command to be cancelled */ | ||
1311 | spin_lock_irqsave(&xhci->lock, flags); | ||
1312 | if (xhci->current_cmd) { | ||
1313 | cur_cmd = xhci->current_cmd; | ||
1314 | cur_cmd->status = COMP_CMD_ABORT; | ||
1315 | } | ||
1316 | |||
1317 | |||
1318 | /* Make sure command ring is running before aborting it */ | ||
1319 | hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); | ||
1320 | if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) && | ||
1321 | (hw_ring_state & CMD_RING_RUNNING)) { | ||
1322 | |||
1323 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1324 | xhci_dbg(xhci, "Command timeout\n"); | ||
1325 | ret = xhci_abort_cmd_ring(xhci); | ||
1326 | if (unlikely(ret == -ESHUTDOWN)) { | ||
1327 | xhci_err(xhci, "Abort command ring failed\n"); | ||
1328 | xhci_cleanup_command_queue(xhci); | ||
1329 | usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); | ||
1330 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); | ||
1331 | } | ||
1332 | return; | ||
1333 | } | ||
1334 | /* command timeout on stopped ring, ring can't be aborted */ | ||
1335 | xhci_dbg(xhci, "Command timeout on stopped ring\n"); | ||
1336 | xhci_handle_stopped_cmd_ring(xhci, xhci->current_cmd); | ||
1337 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
1338 | return; | ||
1339 | } | ||
1340 | |||
1532 | static void handle_cmd_completion(struct xhci_hcd *xhci, | 1341 | static void handle_cmd_completion(struct xhci_hcd *xhci, |
1533 | struct xhci_event_cmd *event) | 1342 | struct xhci_event_cmd *event) |
1534 | { | 1343 | { |
@@ -1537,6 +1346,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1537 | dma_addr_t cmd_dequeue_dma; | 1346 | dma_addr_t cmd_dequeue_dma; |
1538 | u32 cmd_comp_code; | 1347 | u32 cmd_comp_code; |
1539 | union xhci_trb *cmd_trb; | 1348 | union xhci_trb *cmd_trb; |
1349 | struct xhci_command *cmd; | ||
1540 | u32 cmd_type; | 1350 | u32 cmd_type; |
1541 | 1351 | ||
1542 | cmd_dma = le64_to_cpu(event->cmd_trb); | 1352 | cmd_dma = le64_to_cpu(event->cmd_trb); |
@@ -1554,26 +1364,35 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1554 | return; | 1364 | return; |
1555 | } | 1365 | } |
1556 | 1366 | ||
1367 | cmd = list_entry(xhci->cmd_list.next, struct xhci_command, cmd_list); | ||
1368 | |||
1369 | if (cmd->command_trb != xhci->cmd_ring->dequeue) { | ||
1370 | xhci_err(xhci, | ||
1371 | "Command completion event does not match command\n"); | ||
1372 | return; | ||
1373 | } | ||
1374 | |||
1375 | del_timer(&xhci->cmd_timer); | ||
1376 | |||
1557 | trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); | 1377 | trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event); |
1558 | 1378 | ||
1559 | cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); | 1379 | cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status)); |
1560 | if (cmd_comp_code == COMP_CMD_ABORT || cmd_comp_code == COMP_CMD_STOP) { | 1380 | |
1561 | /* If the return value is 0, we think the trb pointed by | 1381 | /* If CMD ring stopped we own the trbs between enqueue and dequeue */ |
1562 | * command ring dequeue pointer is a good trb. The good | 1382 | if (cmd_comp_code == COMP_CMD_STOP) { |
1563 | * trb means we don't want to cancel the trb, but it have | 1383 | xhci_handle_stopped_cmd_ring(xhci, cmd); |
1564 | * been stopped by host. So we should handle it normally. | 1384 | return; |
1565 | * Otherwise, driver should invoke inc_deq() and return. | 1385 | } |
1566 | */ | 1386 | /* |
1567 | if (handle_stopped_cmd_ring(xhci, cmd_comp_code)) { | 1387 | * Host aborted the command ring, check if the current command was |
1568 | inc_deq(xhci, xhci->cmd_ring); | 1388 | * supposed to be aborted, otherwise continue normally. |
1569 | return; | 1389 | * The command ring is stopped now, but the xHC will issue a Command |
1570 | } | 1390 | * Ring Stopped event which will cause us to restart it. |
1571 | /* There is no command to handle if we get a stop event when the | 1391 | */ |
1572 | * command ring is empty, event->cmd_trb points to the next | 1392 | if (cmd_comp_code == COMP_CMD_ABORT) { |
1573 | * unset command | 1393 | xhci->cmd_ring_state = CMD_RING_STATE_STOPPED; |
1574 | */ | 1394 | if (cmd->status == COMP_CMD_ABORT) |
1575 | if (xhci->cmd_ring->dequeue == xhci->cmd_ring->enqueue) | 1395 | goto event_handled; |
1576 | return; | ||
1577 | } | 1396 | } |
1578 | 1397 | ||
1579 | cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); | 1398 | cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3])); |
@@ -1585,13 +1404,13 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1585 | xhci_handle_cmd_disable_slot(xhci, slot_id); | 1404 | xhci_handle_cmd_disable_slot(xhci, slot_id); |
1586 | break; | 1405 | break; |
1587 | case TRB_CONFIG_EP: | 1406 | case TRB_CONFIG_EP: |
1588 | xhci_handle_cmd_config_ep(xhci, slot_id, event, cmd_comp_code); | 1407 | if (!cmd->completion) |
1408 | xhci_handle_cmd_config_ep(xhci, slot_id, event, | ||
1409 | cmd_comp_code); | ||
1589 | break; | 1410 | break; |
1590 | case TRB_EVAL_CONTEXT: | 1411 | case TRB_EVAL_CONTEXT: |
1591 | xhci_handle_cmd_eval_ctx(xhci, slot_id, event, cmd_comp_code); | ||
1592 | break; | 1412 | break; |
1593 | case TRB_ADDR_DEV: | 1413 | case TRB_ADDR_DEV: |
1594 | xhci_handle_cmd_addr_dev(xhci, slot_id, cmd_comp_code); | ||
1595 | break; | 1414 | break; |
1596 | case TRB_STOP_RING: | 1415 | case TRB_STOP_RING: |
1597 | WARN_ON(slot_id != TRB_TO_SLOT_ID( | 1416 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
@@ -1604,6 +1423,9 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1604 | xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); | 1423 | xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code); |
1605 | break; | 1424 | break; |
1606 | case TRB_CMD_NOOP: | 1425 | case TRB_CMD_NOOP: |
1426 | /* Is this an aborted command turned to NO-OP? */ | ||
1427 | if (cmd->status == COMP_CMD_STOP) | ||
1428 | cmd_comp_code = COMP_CMD_STOP; | ||
1607 | break; | 1429 | break; |
1608 | case TRB_RESET_EP: | 1430 | case TRB_RESET_EP: |
1609 | WARN_ON(slot_id != TRB_TO_SLOT_ID( | 1431 | WARN_ON(slot_id != TRB_TO_SLOT_ID( |
@@ -1623,6 +1445,17 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, | |||
1623 | xhci->error_bitmask |= 1 << 6; | 1445 | xhci->error_bitmask |= 1 << 6; |
1624 | break; | 1446 | break; |
1625 | } | 1447 | } |
1448 | |||
1449 | /* restart timer if this wasn't the last command */ | ||
1450 | if (cmd->cmd_list.next != &xhci->cmd_list) { | ||
1451 | xhci->current_cmd = list_entry(cmd->cmd_list.next, | ||
1452 | struct xhci_command, cmd_list); | ||
1453 | mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); | ||
1454 | } | ||
1455 | |||
1456 | event_handled: | ||
1457 | xhci_complete_del_and_free_cmd(cmd, cmd_comp_code); | ||
1458 | |||
1626 | inc_deq(xhci, xhci->cmd_ring); | 1459 | inc_deq(xhci, xhci->cmd_ring); |
1627 | } | 1460 | } |
1628 | 1461 | ||
@@ -1938,11 +1771,16 @@ static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, | |||
1938 | struct xhci_td *td, union xhci_trb *event_trb) | 1771 | struct xhci_td *td, union xhci_trb *event_trb) |
1939 | { | 1772 | { |
1940 | struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; | 1773 | struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; |
1774 | struct xhci_command *command; | ||
1775 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
1776 | if (!command) | ||
1777 | return; | ||
1778 | |||
1941 | ep->ep_state |= EP_HALTED; | 1779 | ep->ep_state |= EP_HALTED; |
1942 | ep->stopped_td = td; | 1780 | ep->stopped_td = td; |
1943 | ep->stopped_stream = stream_id; | 1781 | ep->stopped_stream = stream_id; |
1944 | 1782 | ||
1945 | xhci_queue_reset_ep(xhci, slot_id, ep_index); | 1783 | xhci_queue_reset_ep(xhci, command, slot_id, ep_index); |
1946 | xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index); | 1784 | xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index); |
1947 | 1785 | ||
1948 | ep->stopped_td = NULL; | 1786 | ep->stopped_td = NULL; |
@@ -2654,7 +2492,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
2654 | * successful event after a short transfer. | 2492 | * successful event after a short transfer. |
2655 | * Ignore it. | 2493 | * Ignore it. |
2656 | */ | 2494 | */ |
2657 | if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && | 2495 | if ((xhci->quirks & XHCI_SPURIOUS_SUCCESS) && |
2658 | ep_ring->last_td_was_short) { | 2496 | ep_ring->last_td_was_short) { |
2659 | ep_ring->last_td_was_short = false; | 2497 | ep_ring->last_td_was_short = false; |
2660 | ret = 0; | 2498 | ret = 0; |
@@ -3996,11 +3834,14 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
3996 | * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB | 3834 | * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB |
3997 | * because the command event handler may want to resubmit a failed command. | 3835 | * because the command event handler may want to resubmit a failed command. |
3998 | */ | 3836 | */ |
3999 | static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | 3837 | static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4000 | u32 field3, u32 field4, bool command_must_succeed) | 3838 | u32 field1, u32 field2, |
3839 | u32 field3, u32 field4, bool command_must_succeed) | ||
4001 | { | 3840 | { |
4002 | int reserved_trbs = xhci->cmd_ring_reserved_trbs; | 3841 | int reserved_trbs = xhci->cmd_ring_reserved_trbs; |
4003 | int ret; | 3842 | int ret; |
3843 | if (xhci->xhc_state & XHCI_STATE_DYING) | ||
3844 | return -ESHUTDOWN; | ||
4004 | 3845 | ||
4005 | if (!command_must_succeed) | 3846 | if (!command_must_succeed) |
4006 | reserved_trbs++; | 3847 | reserved_trbs++; |
@@ -4014,57 +3855,71 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | |||
4014 | "unfailable commands failed.\n"); | 3855 | "unfailable commands failed.\n"); |
4015 | return ret; | 3856 | return ret; |
4016 | } | 3857 | } |
3858 | |||
3859 | cmd->command_trb = xhci->cmd_ring->enqueue; | ||
3860 | list_add_tail(&cmd->cmd_list, &xhci->cmd_list); | ||
3861 | |||
3862 | /* if there are no other commands queued we start the timeout timer */ | ||
3863 | if (xhci->cmd_list.next == &cmd->cmd_list && | ||
3864 | !timer_pending(&xhci->cmd_timer)) { | ||
3865 | xhci->current_cmd = cmd; | ||
3866 | mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); | ||
3867 | } | ||
3868 | |||
4017 | queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, | 3869 | queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, |
4018 | field4 | xhci->cmd_ring->cycle_state); | 3870 | field4 | xhci->cmd_ring->cycle_state); |
4019 | return 0; | 3871 | return 0; |
4020 | } | 3872 | } |
4021 | 3873 | ||
4022 | /* Queue a slot enable or disable request on the command ring */ | 3874 | /* Queue a slot enable or disable request on the command ring */ |
4023 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) | 3875 | int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, |
3876 | u32 trb_type, u32 slot_id) | ||
4024 | { | 3877 | { |
4025 | return queue_command(xhci, 0, 0, 0, | 3878 | return queue_command(xhci, cmd, 0, 0, 0, |
4026 | TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id), false); | 3879 | TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id), false); |
4027 | } | 3880 | } |
4028 | 3881 | ||
4029 | /* Queue an address device command TRB */ | 3882 | /* Queue an address device command TRB */ |
4030 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 3883 | int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4031 | u32 slot_id, enum xhci_setup_dev setup) | 3884 | dma_addr_t in_ctx_ptr, u32 slot_id, enum xhci_setup_dev setup) |
4032 | { | 3885 | { |
4033 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 3886 | return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), |
4034 | upper_32_bits(in_ctx_ptr), 0, | 3887 | upper_32_bits(in_ctx_ptr), 0, |
4035 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id) | 3888 | TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id) |
4036 | | (setup == SETUP_CONTEXT_ONLY ? TRB_BSR : 0), false); | 3889 | | (setup == SETUP_CONTEXT_ONLY ? TRB_BSR : 0), false); |
4037 | } | 3890 | } |
4038 | 3891 | ||
4039 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, | 3892 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4040 | u32 field1, u32 field2, u32 field3, u32 field4) | 3893 | u32 field1, u32 field2, u32 field3, u32 field4) |
4041 | { | 3894 | { |
4042 | return queue_command(xhci, field1, field2, field3, field4, false); | 3895 | return queue_command(xhci, cmd, field1, field2, field3, field4, false); |
4043 | } | 3896 | } |
4044 | 3897 | ||
4045 | /* Queue a reset device command TRB */ | 3898 | /* Queue a reset device command TRB */ |
4046 | int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id) | 3899 | int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, |
3900 | u32 slot_id) | ||
4047 | { | 3901 | { |
4048 | return queue_command(xhci, 0, 0, 0, | 3902 | return queue_command(xhci, cmd, 0, 0, 0, |
4049 | TRB_TYPE(TRB_RESET_DEV) | SLOT_ID_FOR_TRB(slot_id), | 3903 | TRB_TYPE(TRB_RESET_DEV) | SLOT_ID_FOR_TRB(slot_id), |
4050 | false); | 3904 | false); |
4051 | } | 3905 | } |
4052 | 3906 | ||
4053 | /* Queue a configure endpoint command TRB */ | 3907 | /* Queue a configure endpoint command TRB */ |
4054 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 3908 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, |
3909 | struct xhci_command *cmd, dma_addr_t in_ctx_ptr, | ||
4055 | u32 slot_id, bool command_must_succeed) | 3910 | u32 slot_id, bool command_must_succeed) |
4056 | { | 3911 | { |
4057 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 3912 | return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), |
4058 | upper_32_bits(in_ctx_ptr), 0, | 3913 | upper_32_bits(in_ctx_ptr), 0, |
4059 | TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id), | 3914 | TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id), |
4060 | command_must_succeed); | 3915 | command_must_succeed); |
4061 | } | 3916 | } |
4062 | 3917 | ||
4063 | /* Queue an evaluate context command TRB */ | 3918 | /* Queue an evaluate context command TRB */ |
4064 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 3919 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4065 | u32 slot_id, bool command_must_succeed) | 3920 | dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed) |
4066 | { | 3921 | { |
4067 | return queue_command(xhci, lower_32_bits(in_ctx_ptr), | 3922 | return queue_command(xhci, cmd, lower_32_bits(in_ctx_ptr), |
4068 | upper_32_bits(in_ctx_ptr), 0, | 3923 | upper_32_bits(in_ctx_ptr), 0, |
4069 | TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), | 3924 | TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), |
4070 | command_must_succeed); | 3925 | command_must_succeed); |
@@ -4074,25 +3929,26 @@ int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | |||
4074 | * Suspend is set to indicate "Stop Endpoint Command" is being issued to stop | 3929 | * Suspend is set to indicate "Stop Endpoint Command" is being issued to stop |
4075 | * activity on an endpoint that is about to be suspended. | 3930 | * activity on an endpoint that is about to be suspended. |
4076 | */ | 3931 | */ |
4077 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, | 3932 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4078 | unsigned int ep_index, int suspend) | 3933 | int slot_id, unsigned int ep_index, int suspend) |
4079 | { | 3934 | { |
4080 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); | 3935 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); |
4081 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); | 3936 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); |
4082 | u32 type = TRB_TYPE(TRB_STOP_RING); | 3937 | u32 type = TRB_TYPE(TRB_STOP_RING); |
4083 | u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend); | 3938 | u32 trb_suspend = SUSPEND_PORT_FOR_TRB(suspend); |
4084 | 3939 | ||
4085 | return queue_command(xhci, 0, 0, 0, | 3940 | return queue_command(xhci, cmd, 0, 0, 0, |
4086 | trb_slot_id | trb_ep_index | type | trb_suspend, false); | 3941 | trb_slot_id | trb_ep_index | type | trb_suspend, false); |
4087 | } | 3942 | } |
4088 | 3943 | ||
4089 | /* Set Transfer Ring Dequeue Pointer command. | 3944 | /* Set Transfer Ring Dequeue Pointer command. |
4090 | * This should not be used for endpoints that have streams enabled. | 3945 | * This should not be used for endpoints that have streams enabled. |
4091 | */ | 3946 | */ |
4092 | static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | 3947 | static int queue_set_tr_deq(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4093 | unsigned int ep_index, unsigned int stream_id, | 3948 | int slot_id, |
4094 | struct xhci_segment *deq_seg, | 3949 | unsigned int ep_index, unsigned int stream_id, |
4095 | union xhci_trb *deq_ptr, u32 cycle_state) | 3950 | struct xhci_segment *deq_seg, |
3951 | union xhci_trb *deq_ptr, u32 cycle_state) | ||
4096 | { | 3952 | { |
4097 | dma_addr_t addr; | 3953 | dma_addr_t addr; |
4098 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); | 3954 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); |
@@ -4119,18 +3975,19 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
4119 | ep->queued_deq_ptr = deq_ptr; | 3975 | ep->queued_deq_ptr = deq_ptr; |
4120 | if (stream_id) | 3976 | if (stream_id) |
4121 | trb_sct = SCT_FOR_TRB(SCT_PRI_TR); | 3977 | trb_sct = SCT_FOR_TRB(SCT_PRI_TR); |
4122 | return queue_command(xhci, lower_32_bits(addr) | trb_sct | cycle_state, | 3978 | return queue_command(xhci, cmd, |
3979 | lower_32_bits(addr) | trb_sct | cycle_state, | ||
4123 | upper_32_bits(addr), trb_stream_id, | 3980 | upper_32_bits(addr), trb_stream_id, |
4124 | trb_slot_id | trb_ep_index | type, false); | 3981 | trb_slot_id | trb_ep_index | type, false); |
4125 | } | 3982 | } |
4126 | 3983 | ||
4127 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | 3984 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, |
4128 | unsigned int ep_index) | 3985 | int slot_id, unsigned int ep_index) |
4129 | { | 3986 | { |
4130 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); | 3987 | u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); |
4131 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); | 3988 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); |
4132 | u32 type = TRB_TYPE(TRB_RESET_EP); | 3989 | u32 type = TRB_TYPE(TRB_RESET_EP); |
4133 | 3990 | ||
4134 | return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type, | 3991 | return queue_command(xhci, cmd, 0, 0, 0, |
4135 | false); | 3992 | trb_slot_id | trb_ep_index | type, false); |
4136 | } | 3993 | } |
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 300836972faa..2b8d9a24af09 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -291,7 +291,7 @@ static int xhci_setup_msix(struct xhci_hcd *xhci) | |||
291 | xhci->msix_entries[i].vector = 0; | 291 | xhci->msix_entries[i].vector = 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); | 294 | ret = pci_enable_msix_exact(pdev, xhci->msix_entries, xhci->msix_count); |
295 | if (ret) { | 295 | if (ret) { |
296 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 296 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
297 | "Failed to enable MSI-X"); | 297 | "Failed to enable MSI-X"); |
@@ -641,10 +641,14 @@ int xhci_run(struct usb_hcd *hcd) | |||
641 | writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); | 641 | writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); |
642 | xhci_print_ir_set(xhci, 0); | 642 | xhci_print_ir_set(xhci, 0); |
643 | 643 | ||
644 | if (xhci->quirks & XHCI_NEC_HOST) | 644 | if (xhci->quirks & XHCI_NEC_HOST) { |
645 | xhci_queue_vendor_command(xhci, 0, 0, 0, | 645 | struct xhci_command *command; |
646 | command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); | ||
647 | if (!command) | ||
648 | return -ENOMEM; | ||
649 | xhci_queue_vendor_command(xhci, command, 0, 0, 0, | ||
646 | TRB_TYPE(TRB_NEC_GET_FW)); | 650 | TRB_TYPE(TRB_NEC_GET_FW)); |
647 | 651 | } | |
648 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, | 652 | xhci_dbg_trace(xhci, trace_xhci_dbg_init, |
649 | "Finished xhci_run for USB2 roothub"); | 653 | "Finished xhci_run for USB2 roothub"); |
650 | return 0; | 654 | return 0; |
@@ -1187,10 +1191,10 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
1187 | static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | 1191 | static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, |
1188 | unsigned int ep_index, struct urb *urb) | 1192 | unsigned int ep_index, struct urb *urb) |
1189 | { | 1193 | { |
1190 | struct xhci_container_ctx *in_ctx; | ||
1191 | struct xhci_container_ctx *out_ctx; | 1194 | struct xhci_container_ctx *out_ctx; |
1192 | struct xhci_input_control_ctx *ctrl_ctx; | 1195 | struct xhci_input_control_ctx *ctrl_ctx; |
1193 | struct xhci_ep_ctx *ep_ctx; | 1196 | struct xhci_ep_ctx *ep_ctx; |
1197 | struct xhci_command *command; | ||
1194 | int max_packet_size; | 1198 | int max_packet_size; |
1195 | int hw_max_packet_size; | 1199 | int hw_max_packet_size; |
1196 | int ret = 0; | 1200 | int ret = 0; |
@@ -1215,18 +1219,24 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | |||
1215 | /* FIXME: This won't work if a non-default control endpoint | 1219 | /* FIXME: This won't work if a non-default control endpoint |
1216 | * changes max packet sizes. | 1220 | * changes max packet sizes. |
1217 | */ | 1221 | */ |
1218 | in_ctx = xhci->devs[slot_id]->in_ctx; | 1222 | |
1219 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); | 1223 | command = xhci_alloc_command(xhci, false, true, GFP_KERNEL); |
1224 | if (!command) | ||
1225 | return -ENOMEM; | ||
1226 | |||
1227 | command->in_ctx = xhci->devs[slot_id]->in_ctx; | ||
1228 | ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx); | ||
1220 | if (!ctrl_ctx) { | 1229 | if (!ctrl_ctx) { |
1221 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", | 1230 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", |
1222 | __func__); | 1231 | __func__); |
1223 | return -ENOMEM; | 1232 | ret = -ENOMEM; |
1233 | goto command_cleanup; | ||
1224 | } | 1234 | } |
1225 | /* Set up the modified control endpoint 0 */ | 1235 | /* Set up the modified control endpoint 0 */ |
1226 | xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, | 1236 | xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx, |
1227 | xhci->devs[slot_id]->out_ctx, ep_index); | 1237 | xhci->devs[slot_id]->out_ctx, ep_index); |
1228 | 1238 | ||
1229 | ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); | 1239 | ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); |
1230 | ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); | 1240 | ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); |
1231 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); | 1241 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); |
1232 | 1242 | ||
@@ -1234,17 +1244,20 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | |||
1234 | ctrl_ctx->drop_flags = 0; | 1244 | ctrl_ctx->drop_flags = 0; |
1235 | 1245 | ||
1236 | xhci_dbg(xhci, "Slot %d input context\n", slot_id); | 1246 | xhci_dbg(xhci, "Slot %d input context\n", slot_id); |
1237 | xhci_dbg_ctx(xhci, in_ctx, ep_index); | 1247 | xhci_dbg_ctx(xhci, command->in_ctx, ep_index); |
1238 | xhci_dbg(xhci, "Slot %d output context\n", slot_id); | 1248 | xhci_dbg(xhci, "Slot %d output context\n", slot_id); |
1239 | xhci_dbg_ctx(xhci, out_ctx, ep_index); | 1249 | xhci_dbg_ctx(xhci, out_ctx, ep_index); |
1240 | 1250 | ||
1241 | ret = xhci_configure_endpoint(xhci, urb->dev, NULL, | 1251 | ret = xhci_configure_endpoint(xhci, urb->dev, command, |
1242 | true, false); | 1252 | true, false); |
1243 | 1253 | ||
1244 | /* Clean up the input context for later use by bandwidth | 1254 | /* Clean up the input context for later use by bandwidth |
1245 | * functions. | 1255 | * functions. |
1246 | */ | 1256 | */ |
1247 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); | 1257 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); |
1258 | command_cleanup: | ||
1259 | kfree(command->completion); | ||
1260 | kfree(command); | ||
1248 | } | 1261 | } |
1249 | return ret; | 1262 | return ret; |
1250 | } | 1263 | } |
@@ -1465,6 +1478,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1465 | unsigned int ep_index; | 1478 | unsigned int ep_index; |
1466 | struct xhci_ring *ep_ring; | 1479 | struct xhci_ring *ep_ring; |
1467 | struct xhci_virt_ep *ep; | 1480 | struct xhci_virt_ep *ep; |
1481 | struct xhci_command *command; | ||
1468 | 1482 | ||
1469 | xhci = hcd_to_xhci(hcd); | 1483 | xhci = hcd_to_xhci(hcd); |
1470 | spin_lock_irqsave(&xhci->lock, flags); | 1484 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -1534,12 +1548,14 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1534 | * the first cancellation to be handled. | 1548 | * the first cancellation to be handled. |
1535 | */ | 1549 | */ |
1536 | if (!(ep->ep_state & EP_HALT_PENDING)) { | 1550 | if (!(ep->ep_state & EP_HALT_PENDING)) { |
1551 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
1537 | ep->ep_state |= EP_HALT_PENDING; | 1552 | ep->ep_state |= EP_HALT_PENDING; |
1538 | ep->stop_cmds_pending++; | 1553 | ep->stop_cmds_pending++; |
1539 | ep->stop_cmd_timer.expires = jiffies + | 1554 | ep->stop_cmd_timer.expires = jiffies + |
1540 | XHCI_STOP_EP_CMD_TIMEOUT * HZ; | 1555 | XHCI_STOP_EP_CMD_TIMEOUT * HZ; |
1541 | add_timer(&ep->stop_cmd_timer); | 1556 | add_timer(&ep->stop_cmd_timer); |
1542 | xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index, 0); | 1557 | xhci_queue_stop_endpoint(xhci, command, urb->dev->slot_id, |
1558 | ep_index, 0); | ||
1543 | xhci_ring_cmd_db(xhci); | 1559 | xhci_ring_cmd_db(xhci); |
1544 | } | 1560 | } |
1545 | done: | 1561 | done: |
@@ -1804,6 +1820,11 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci, | |||
1804 | int ret; | 1820 | int ret; |
1805 | 1821 | ||
1806 | switch (*cmd_status) { | 1822 | switch (*cmd_status) { |
1823 | case COMP_CMD_ABORT: | ||
1824 | case COMP_CMD_STOP: | ||
1825 | xhci_warn(xhci, "Timeout while waiting for configure endpoint command\n"); | ||
1826 | ret = -ETIME; | ||
1827 | break; | ||
1807 | case COMP_ENOMEM: | 1828 | case COMP_ENOMEM: |
1808 | dev_warn(&udev->dev, "Not enough host controller resources " | 1829 | dev_warn(&udev->dev, "Not enough host controller resources " |
1809 | "for new device state.\n"); | 1830 | "for new device state.\n"); |
@@ -1850,6 +1871,11 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci, | |||
1850 | struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id]; | 1871 | struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id]; |
1851 | 1872 | ||
1852 | switch (*cmd_status) { | 1873 | switch (*cmd_status) { |
1874 | case COMP_CMD_ABORT: | ||
1875 | case COMP_CMD_STOP: | ||
1876 | xhci_warn(xhci, "Timeout while waiting for evaluate context command\n"); | ||
1877 | ret = -ETIME; | ||
1878 | break; | ||
1853 | case COMP_EINVAL: | 1879 | case COMP_EINVAL: |
1854 | dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate " | 1880 | dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate " |
1855 | "context command.\n"); | 1881 | "context command.\n"); |
@@ -2574,23 +2600,17 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
2574 | bool ctx_change, bool must_succeed) | 2600 | bool ctx_change, bool must_succeed) |
2575 | { | 2601 | { |
2576 | int ret; | 2602 | int ret; |
2577 | int timeleft; | ||
2578 | unsigned long flags; | 2603 | unsigned long flags; |
2579 | struct xhci_container_ctx *in_ctx; | ||
2580 | struct xhci_input_control_ctx *ctrl_ctx; | 2604 | struct xhci_input_control_ctx *ctrl_ctx; |
2581 | struct completion *cmd_completion; | ||
2582 | u32 *cmd_status; | ||
2583 | struct xhci_virt_device *virt_dev; | 2605 | struct xhci_virt_device *virt_dev; |
2584 | union xhci_trb *cmd_trb; | 2606 | |
2607 | if (!command) | ||
2608 | return -EINVAL; | ||
2585 | 2609 | ||
2586 | spin_lock_irqsave(&xhci->lock, flags); | 2610 | spin_lock_irqsave(&xhci->lock, flags); |
2587 | virt_dev = xhci->devs[udev->slot_id]; | 2611 | virt_dev = xhci->devs[udev->slot_id]; |
2588 | 2612 | ||
2589 | if (command) | 2613 | ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx); |
2590 | in_ctx = command->in_ctx; | ||
2591 | else | ||
2592 | in_ctx = virt_dev->in_ctx; | ||
2593 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); | ||
2594 | if (!ctrl_ctx) { | 2614 | if (!ctrl_ctx) { |
2595 | spin_unlock_irqrestore(&xhci->lock, flags); | 2615 | spin_unlock_irqrestore(&xhci->lock, flags); |
2596 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", | 2616 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", |
@@ -2607,7 +2627,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
2607 | return -ENOMEM; | 2627 | return -ENOMEM; |
2608 | } | 2628 | } |
2609 | if ((xhci->quirks & XHCI_SW_BW_CHECKING) && | 2629 | if ((xhci->quirks & XHCI_SW_BW_CHECKING) && |
2610 | xhci_reserve_bandwidth(xhci, virt_dev, in_ctx)) { | 2630 | xhci_reserve_bandwidth(xhci, virt_dev, command->in_ctx)) { |
2611 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) | 2631 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) |
2612 | xhci_free_host_resources(xhci, ctrl_ctx); | 2632 | xhci_free_host_resources(xhci, ctrl_ctx); |
2613 | spin_unlock_irqrestore(&xhci->lock, flags); | 2633 | spin_unlock_irqrestore(&xhci->lock, flags); |
@@ -2615,27 +2635,15 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
2615 | return -ENOMEM; | 2635 | return -ENOMEM; |
2616 | } | 2636 | } |
2617 | 2637 | ||
2618 | if (command) { | ||
2619 | cmd_completion = command->completion; | ||
2620 | cmd_status = &command->status; | ||
2621 | command->command_trb = xhci_find_next_enqueue(xhci->cmd_ring); | ||
2622 | list_add_tail(&command->cmd_list, &virt_dev->cmd_list); | ||
2623 | } else { | ||
2624 | cmd_completion = &virt_dev->cmd_completion; | ||
2625 | cmd_status = &virt_dev->cmd_status; | ||
2626 | } | ||
2627 | init_completion(cmd_completion); | ||
2628 | |||
2629 | cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); | ||
2630 | if (!ctx_change) | 2638 | if (!ctx_change) |
2631 | ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma, | 2639 | ret = xhci_queue_configure_endpoint(xhci, command, |
2640 | command->in_ctx->dma, | ||
2632 | udev->slot_id, must_succeed); | 2641 | udev->slot_id, must_succeed); |
2633 | else | 2642 | else |
2634 | ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, | 2643 | ret = xhci_queue_evaluate_context(xhci, command, |
2644 | command->in_ctx->dma, | ||
2635 | udev->slot_id, must_succeed); | 2645 | udev->slot_id, must_succeed); |
2636 | if (ret < 0) { | 2646 | if (ret < 0) { |
2637 | if (command) | ||
2638 | list_del(&command->cmd_list); | ||
2639 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) | 2647 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) |
2640 | xhci_free_host_resources(xhci, ctrl_ctx); | 2648 | xhci_free_host_resources(xhci, ctrl_ctx); |
2641 | spin_unlock_irqrestore(&xhci->lock, flags); | 2649 | spin_unlock_irqrestore(&xhci->lock, flags); |
@@ -2647,26 +2655,14 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
2647 | spin_unlock_irqrestore(&xhci->lock, flags); | 2655 | spin_unlock_irqrestore(&xhci->lock, flags); |
2648 | 2656 | ||
2649 | /* Wait for the configure endpoint command to complete */ | 2657 | /* Wait for the configure endpoint command to complete */ |
2650 | timeleft = wait_for_completion_interruptible_timeout( | 2658 | wait_for_completion(command->completion); |
2651 | cmd_completion, | ||
2652 | XHCI_CMD_DEFAULT_TIMEOUT); | ||
2653 | if (timeleft <= 0) { | ||
2654 | xhci_warn(xhci, "%s while waiting for %s command\n", | ||
2655 | timeleft == 0 ? "Timeout" : "Signal", | ||
2656 | ctx_change == 0 ? | ||
2657 | "configure endpoint" : | ||
2658 | "evaluate context"); | ||
2659 | /* cancel the configure endpoint command */ | ||
2660 | ret = xhci_cancel_cmd(xhci, command, cmd_trb); | ||
2661 | if (ret < 0) | ||
2662 | return ret; | ||
2663 | return -ETIME; | ||
2664 | } | ||
2665 | 2659 | ||
2666 | if (!ctx_change) | 2660 | if (!ctx_change) |
2667 | ret = xhci_configure_endpoint_result(xhci, udev, cmd_status); | 2661 | ret = xhci_configure_endpoint_result(xhci, udev, |
2662 | &command->status); | ||
2668 | else | 2663 | else |
2669 | ret = xhci_evaluate_context_result(xhci, udev, cmd_status); | 2664 | ret = xhci_evaluate_context_result(xhci, udev, |
2665 | &command->status); | ||
2670 | 2666 | ||
2671 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { | 2667 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) { |
2672 | spin_lock_irqsave(&xhci->lock, flags); | 2668 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -2714,6 +2710,7 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
2714 | struct xhci_virt_device *virt_dev; | 2710 | struct xhci_virt_device *virt_dev; |
2715 | struct xhci_input_control_ctx *ctrl_ctx; | 2711 | struct xhci_input_control_ctx *ctrl_ctx; |
2716 | struct xhci_slot_ctx *slot_ctx; | 2712 | struct xhci_slot_ctx *slot_ctx; |
2713 | struct xhci_command *command; | ||
2717 | 2714 | ||
2718 | ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); | 2715 | ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); |
2719 | if (ret <= 0) | 2716 | if (ret <= 0) |
@@ -2725,12 +2722,19 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
2725 | xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); | 2722 | xhci_dbg(xhci, "%s called for udev %p\n", __func__, udev); |
2726 | virt_dev = xhci->devs[udev->slot_id]; | 2723 | virt_dev = xhci->devs[udev->slot_id]; |
2727 | 2724 | ||
2725 | command = xhci_alloc_command(xhci, false, true, GFP_KERNEL); | ||
2726 | if (!command) | ||
2727 | return -ENOMEM; | ||
2728 | |||
2729 | command->in_ctx = virt_dev->in_ctx; | ||
2730 | |||
2728 | /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ | 2731 | /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ |
2729 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | 2732 | ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx); |
2730 | if (!ctrl_ctx) { | 2733 | if (!ctrl_ctx) { |
2731 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", | 2734 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", |
2732 | __func__); | 2735 | __func__); |
2733 | return -ENOMEM; | 2736 | ret = -ENOMEM; |
2737 | goto command_cleanup; | ||
2734 | } | 2738 | } |
2735 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); | 2739 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); |
2736 | ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); | 2740 | ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); |
@@ -2738,20 +2742,20 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
2738 | 2742 | ||
2739 | /* Don't issue the command if there's no endpoints to update. */ | 2743 | /* Don't issue the command if there's no endpoints to update. */ |
2740 | if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && | 2744 | if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && |
2741 | ctrl_ctx->drop_flags == 0) | 2745 | ctrl_ctx->drop_flags == 0) { |
2742 | return 0; | 2746 | ret = 0; |
2743 | 2747 | goto command_cleanup; | |
2748 | } | ||
2744 | xhci_dbg(xhci, "New Input Control Context:\n"); | 2749 | xhci_dbg(xhci, "New Input Control Context:\n"); |
2745 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); | 2750 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
2746 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, | 2751 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, |
2747 | LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info))); | 2752 | LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info))); |
2748 | 2753 | ||
2749 | ret = xhci_configure_endpoint(xhci, udev, NULL, | 2754 | ret = xhci_configure_endpoint(xhci, udev, command, |
2750 | false, false); | 2755 | false, false); |
2751 | if (ret) { | 2756 | if (ret) |
2752 | /* Callee should call reset_bandwidth() */ | 2757 | /* Callee should call reset_bandwidth() */ |
2753 | return ret; | 2758 | goto command_cleanup; |
2754 | } | ||
2755 | 2759 | ||
2756 | xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); | 2760 | xhci_dbg(xhci, "Output context after successful config ep cmd:\n"); |
2757 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, | 2761 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, |
@@ -2783,6 +2787,9 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
2783 | virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; | 2787 | virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; |
2784 | virt_dev->eps[i].new_ring = NULL; | 2788 | virt_dev->eps[i].new_ring = NULL; |
2785 | } | 2789 | } |
2790 | command_cleanup: | ||
2791 | kfree(command->completion); | ||
2792 | kfree(command); | ||
2786 | 2793 | ||
2787 | return ret; | 2794 | return ret; |
2788 | } | 2795 | } |
@@ -2884,9 +2891,14 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, | |||
2884 | * issue a configure endpoint command later. | 2891 | * issue a configure endpoint command later. |
2885 | */ | 2892 | */ |
2886 | if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { | 2893 | if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { |
2894 | struct xhci_command *command; | ||
2895 | /* Can't sleep if we're called from cleanup_halted_endpoint() */ | ||
2896 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
2897 | if (!command) | ||
2898 | return; | ||
2887 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, | 2899 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, |
2888 | "Queueing new dequeue state"); | 2900 | "Queueing new dequeue state"); |
2889 | xhci_queue_new_dequeue_state(xhci, udev->slot_id, | 2901 | xhci_queue_new_dequeue_state(xhci, command, udev->slot_id, |
2890 | ep_index, ep->stopped_stream, &deq_state); | 2902 | ep_index, ep->stopped_stream, &deq_state); |
2891 | } else { | 2903 | } else { |
2892 | /* Better hope no one uses the input context between now and the | 2904 | /* Better hope no one uses the input context between now and the |
@@ -2917,6 +2929,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
2917 | unsigned long flags; | 2929 | unsigned long flags; |
2918 | int ret; | 2930 | int ret; |
2919 | struct xhci_virt_ep *virt_ep; | 2931 | struct xhci_virt_ep *virt_ep; |
2932 | struct xhci_command *command; | ||
2920 | 2933 | ||
2921 | xhci = hcd_to_xhci(hcd); | 2934 | xhci = hcd_to_xhci(hcd); |
2922 | udev = (struct usb_device *) ep->hcpriv; | 2935 | udev = (struct usb_device *) ep->hcpriv; |
@@ -2939,10 +2952,14 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
2939 | return; | 2952 | return; |
2940 | } | 2953 | } |
2941 | 2954 | ||
2955 | command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); | ||
2956 | if (!command) | ||
2957 | return; | ||
2958 | |||
2942 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, | 2959 | xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, |
2943 | "Queueing reset endpoint command"); | 2960 | "Queueing reset endpoint command"); |
2944 | spin_lock_irqsave(&xhci->lock, flags); | 2961 | spin_lock_irqsave(&xhci->lock, flags); |
2945 | ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); | 2962 | ret = xhci_queue_reset_ep(xhci, command, udev->slot_id, ep_index); |
2946 | /* | 2963 | /* |
2947 | * Can't change the ring dequeue pointer until it's transitioned to the | 2964 | * Can't change the ring dequeue pointer until it's transitioned to the |
2948 | * stopped state, which is only upon a successful reset endpoint | 2965 | * stopped state, which is only upon a successful reset endpoint |
@@ -3416,7 +3433,6 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3416 | unsigned int slot_id; | 3433 | unsigned int slot_id; |
3417 | struct xhci_virt_device *virt_dev; | 3434 | struct xhci_virt_device *virt_dev; |
3418 | struct xhci_command *reset_device_cmd; | 3435 | struct xhci_command *reset_device_cmd; |
3419 | int timeleft; | ||
3420 | int last_freed_endpoint; | 3436 | int last_freed_endpoint; |
3421 | struct xhci_slot_ctx *slot_ctx; | 3437 | struct xhci_slot_ctx *slot_ctx; |
3422 | int old_active_eps = 0; | 3438 | int old_active_eps = 0; |
@@ -3473,13 +3489,10 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3473 | 3489 | ||
3474 | /* Attempt to submit the Reset Device command to the command ring */ | 3490 | /* Attempt to submit the Reset Device command to the command ring */ |
3475 | spin_lock_irqsave(&xhci->lock, flags); | 3491 | spin_lock_irqsave(&xhci->lock, flags); |
3476 | reset_device_cmd->command_trb = xhci_find_next_enqueue(xhci->cmd_ring); | ||
3477 | 3492 | ||
3478 | list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list); | 3493 | ret = xhci_queue_reset_device(xhci, reset_device_cmd, slot_id); |
3479 | ret = xhci_queue_reset_device(xhci, slot_id); | ||
3480 | if (ret) { | 3494 | if (ret) { |
3481 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); | 3495 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
3482 | list_del(&reset_device_cmd->cmd_list); | ||
3483 | spin_unlock_irqrestore(&xhci->lock, flags); | 3496 | spin_unlock_irqrestore(&xhci->lock, flags); |
3484 | goto command_cleanup; | 3497 | goto command_cleanup; |
3485 | } | 3498 | } |
@@ -3487,22 +3500,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3487 | spin_unlock_irqrestore(&xhci->lock, flags); | 3500 | spin_unlock_irqrestore(&xhci->lock, flags); |
3488 | 3501 | ||
3489 | /* Wait for the Reset Device command to finish */ | 3502 | /* Wait for the Reset Device command to finish */ |
3490 | timeleft = wait_for_completion_interruptible_timeout( | 3503 | wait_for_completion(reset_device_cmd->completion); |
3491 | reset_device_cmd->completion, | ||
3492 | XHCI_CMD_DEFAULT_TIMEOUT); | ||
3493 | if (timeleft <= 0) { | ||
3494 | xhci_warn(xhci, "%s while waiting for reset device command\n", | ||
3495 | timeleft == 0 ? "Timeout" : "Signal"); | ||
3496 | spin_lock_irqsave(&xhci->lock, flags); | ||
3497 | /* The timeout might have raced with the event ring handler, so | ||
3498 | * only delete from the list if the item isn't poisoned. | ||
3499 | */ | ||
3500 | if (reset_device_cmd->cmd_list.next != LIST_POISON1) | ||
3501 | list_del(&reset_device_cmd->cmd_list); | ||
3502 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
3503 | ret = -ETIME; | ||
3504 | goto command_cleanup; | ||
3505 | } | ||
3506 | 3504 | ||
3507 | /* The Reset Device command can't fail, according to the 0.95/0.96 spec, | 3505 | /* The Reset Device command can't fail, according to the 0.95/0.96 spec, |
3508 | * unless we tried to reset a slot ID that wasn't enabled, | 3506 | * unless we tried to reset a slot ID that wasn't enabled, |
@@ -3510,6 +3508,11 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
3510 | */ | 3508 | */ |
3511 | ret = reset_device_cmd->status; | 3509 | ret = reset_device_cmd->status; |
3512 | switch (ret) { | 3510 | switch (ret) { |
3511 | case COMP_CMD_ABORT: | ||
3512 | case COMP_CMD_STOP: | ||
3513 | xhci_warn(xhci, "Timeout waiting for reset device command\n"); | ||
3514 | ret = -ETIME; | ||
3515 | goto command_cleanup; | ||
3513 | case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */ | 3516 | case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */ |
3514 | case COMP_CTX_STATE: /* 0.96 completion code for same thing */ | 3517 | case COMP_CTX_STATE: /* 0.96 completion code for same thing */ |
3515 | xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", | 3518 | xhci_dbg(xhci, "Can't reset device (slot ID %u) in %s state\n", |
@@ -3589,6 +3592,11 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3589 | unsigned long flags; | 3592 | unsigned long flags; |
3590 | u32 state; | 3593 | u32 state; |
3591 | int i, ret; | 3594 | int i, ret; |
3595 | struct xhci_command *command; | ||
3596 | |||
3597 | command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); | ||
3598 | if (!command) | ||
3599 | return; | ||
3592 | 3600 | ||
3593 | #ifndef CONFIG_USB_DEFAULT_PERSIST | 3601 | #ifndef CONFIG_USB_DEFAULT_PERSIST |
3594 | /* | 3602 | /* |
@@ -3604,8 +3612,10 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3604 | /* If the host is halted due to driver unload, we still need to free the | 3612 | /* If the host is halted due to driver unload, we still need to free the |
3605 | * device. | 3613 | * device. |
3606 | */ | 3614 | */ |
3607 | if (ret <= 0 && ret != -ENODEV) | 3615 | if (ret <= 0 && ret != -ENODEV) { |
3616 | kfree(command); | ||
3608 | return; | 3617 | return; |
3618 | } | ||
3609 | 3619 | ||
3610 | virt_dev = xhci->devs[udev->slot_id]; | 3620 | virt_dev = xhci->devs[udev->slot_id]; |
3611 | 3621 | ||
@@ -3622,16 +3632,19 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3622 | (xhci->xhc_state & XHCI_STATE_HALTED)) { | 3632 | (xhci->xhc_state & XHCI_STATE_HALTED)) { |
3623 | xhci_free_virt_device(xhci, udev->slot_id); | 3633 | xhci_free_virt_device(xhci, udev->slot_id); |
3624 | spin_unlock_irqrestore(&xhci->lock, flags); | 3634 | spin_unlock_irqrestore(&xhci->lock, flags); |
3635 | kfree(command); | ||
3625 | return; | 3636 | return; |
3626 | } | 3637 | } |
3627 | 3638 | ||
3628 | if (xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id)) { | 3639 | if (xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, |
3640 | udev->slot_id)) { | ||
3629 | spin_unlock_irqrestore(&xhci->lock, flags); | 3641 | spin_unlock_irqrestore(&xhci->lock, flags); |
3630 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); | 3642 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
3631 | return; | 3643 | return; |
3632 | } | 3644 | } |
3633 | xhci_ring_cmd_db(xhci); | 3645 | xhci_ring_cmd_db(xhci); |
3634 | spin_unlock_irqrestore(&xhci->lock, flags); | 3646 | spin_unlock_irqrestore(&xhci->lock, flags); |
3647 | |||
3635 | /* | 3648 | /* |
3636 | * Event command completion handler will free any data structures | 3649 | * Event command completion handler will free any data structures |
3637 | * associated with the slot. XXX Can free sleep? | 3650 | * associated with the slot. XXX Can free sleep? |
@@ -3669,33 +3682,33 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3669 | { | 3682 | { |
3670 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 3683 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
3671 | unsigned long flags; | 3684 | unsigned long flags; |
3672 | int timeleft; | ||
3673 | int ret; | 3685 | int ret; |
3674 | union xhci_trb *cmd_trb; | 3686 | struct xhci_command *command; |
3687 | |||
3688 | command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); | ||
3689 | if (!command) | ||
3690 | return 0; | ||
3675 | 3691 | ||
3676 | spin_lock_irqsave(&xhci->lock, flags); | 3692 | spin_lock_irqsave(&xhci->lock, flags); |
3677 | cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); | 3693 | command->completion = &xhci->addr_dev; |
3678 | ret = xhci_queue_slot_control(xhci, TRB_ENABLE_SLOT, 0); | 3694 | ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0); |
3679 | if (ret) { | 3695 | if (ret) { |
3680 | spin_unlock_irqrestore(&xhci->lock, flags); | 3696 | spin_unlock_irqrestore(&xhci->lock, flags); |
3681 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); | 3697 | xhci_dbg(xhci, "FIXME: allocate a command ring segment\n"); |
3698 | kfree(command); | ||
3682 | return 0; | 3699 | return 0; |
3683 | } | 3700 | } |
3684 | xhci_ring_cmd_db(xhci); | 3701 | xhci_ring_cmd_db(xhci); |
3685 | spin_unlock_irqrestore(&xhci->lock, flags); | 3702 | spin_unlock_irqrestore(&xhci->lock, flags); |
3686 | 3703 | ||
3687 | /* XXX: how much time for xHC slot assignment? */ | 3704 | wait_for_completion(command->completion); |
3688 | timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, | ||
3689 | XHCI_CMD_DEFAULT_TIMEOUT); | ||
3690 | if (timeleft <= 0) { | ||
3691 | xhci_warn(xhci, "%s while waiting for a slot\n", | ||
3692 | timeleft == 0 ? "Timeout" : "Signal"); | ||
3693 | /* cancel the enable slot request */ | ||
3694 | return xhci_cancel_cmd(xhci, NULL, cmd_trb); | ||
3695 | } | ||
3696 | 3705 | ||
3697 | if (!xhci->slot_id) { | 3706 | if (!xhci->slot_id || command->status != COMP_SUCCESS) { |
3698 | xhci_err(xhci, "Error while assigning device slot ID\n"); | 3707 | xhci_err(xhci, "Error while assigning device slot ID\n"); |
3708 | xhci_err(xhci, "Max number of devices this xHCI host supports is %u.\n", | ||
3709 | HCS_MAX_SLOTS( | ||
3710 | readl(&xhci->cap_regs->hcs_params1))); | ||
3711 | kfree(command); | ||
3699 | return 0; | 3712 | return 0; |
3700 | } | 3713 | } |
3701 | 3714 | ||
@@ -3730,6 +3743,8 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3730 | pm_runtime_get_noresume(hcd->self.controller); | 3743 | pm_runtime_get_noresume(hcd->self.controller); |
3731 | #endif | 3744 | #endif |
3732 | 3745 | ||
3746 | |||
3747 | kfree(command); | ||
3733 | /* Is this a LS or FS device under a HS hub? */ | 3748 | /* Is this a LS or FS device under a HS hub? */ |
3734 | /* Hub or peripherial? */ | 3749 | /* Hub or peripherial? */ |
3735 | return 1; | 3750 | return 1; |
@@ -3737,7 +3752,10 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
3737 | disable_slot: | 3752 | disable_slot: |
3738 | /* Disable slot, if we can do it without mem alloc */ | 3753 | /* Disable slot, if we can do it without mem alloc */ |
3739 | spin_lock_irqsave(&xhci->lock, flags); | 3754 | spin_lock_irqsave(&xhci->lock, flags); |
3740 | if (!xhci_queue_slot_control(xhci, TRB_DISABLE_SLOT, udev->slot_id)) | 3755 | command->completion = NULL; |
3756 | command->status = 0; | ||
3757 | if (!xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT, | ||
3758 | udev->slot_id)) | ||
3741 | xhci_ring_cmd_db(xhci); | 3759 | xhci_ring_cmd_db(xhci); |
3742 | spin_unlock_irqrestore(&xhci->lock, flags); | 3760 | spin_unlock_irqrestore(&xhci->lock, flags); |
3743 | return 0; | 3761 | return 0; |
@@ -3754,14 +3772,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3754 | { | 3772 | { |
3755 | const char *act = setup == SETUP_CONTEXT_ONLY ? "context" : "address"; | 3773 | const char *act = setup == SETUP_CONTEXT_ONLY ? "context" : "address"; |
3756 | unsigned long flags; | 3774 | unsigned long flags; |
3757 | int timeleft; | ||
3758 | struct xhci_virt_device *virt_dev; | 3775 | struct xhci_virt_device *virt_dev; |
3759 | int ret = 0; | 3776 | int ret = 0; |
3760 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 3777 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
3761 | struct xhci_slot_ctx *slot_ctx; | 3778 | struct xhci_slot_ctx *slot_ctx; |
3762 | struct xhci_input_control_ctx *ctrl_ctx; | 3779 | struct xhci_input_control_ctx *ctrl_ctx; |
3763 | u64 temp_64; | 3780 | u64 temp_64; |
3764 | union xhci_trb *cmd_trb; | 3781 | struct xhci_command *command; |
3765 | 3782 | ||
3766 | if (!udev->slot_id) { | 3783 | if (!udev->slot_id) { |
3767 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3784 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
@@ -3782,11 +3799,19 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3782 | return -EINVAL; | 3799 | return -EINVAL; |
3783 | } | 3800 | } |
3784 | 3801 | ||
3802 | command = xhci_alloc_command(xhci, false, false, GFP_KERNEL); | ||
3803 | if (!command) | ||
3804 | return -ENOMEM; | ||
3805 | |||
3806 | command->in_ctx = virt_dev->in_ctx; | ||
3807 | command->completion = &xhci->addr_dev; | ||
3808 | |||
3785 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); | 3809 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
3786 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | 3810 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); |
3787 | if (!ctrl_ctx) { | 3811 | if (!ctrl_ctx) { |
3788 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", | 3812 | xhci_warn(xhci, "%s: Could not get input context, bad type.\n", |
3789 | __func__); | 3813 | __func__); |
3814 | kfree(command); | ||
3790 | return -EINVAL; | 3815 | return -EINVAL; |
3791 | } | 3816 | } |
3792 | /* | 3817 | /* |
@@ -3808,36 +3833,31 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3808 | le32_to_cpu(slot_ctx->dev_info) >> 27); | 3833 | le32_to_cpu(slot_ctx->dev_info) >> 27); |
3809 | 3834 | ||
3810 | spin_lock_irqsave(&xhci->lock, flags); | 3835 | spin_lock_irqsave(&xhci->lock, flags); |
3811 | cmd_trb = xhci_find_next_enqueue(xhci->cmd_ring); | 3836 | ret = xhci_queue_address_device(xhci, command, virt_dev->in_ctx->dma, |
3812 | ret = xhci_queue_address_device(xhci, virt_dev->in_ctx->dma, | ||
3813 | udev->slot_id, setup); | 3837 | udev->slot_id, setup); |
3814 | if (ret) { | 3838 | if (ret) { |
3815 | spin_unlock_irqrestore(&xhci->lock, flags); | 3839 | spin_unlock_irqrestore(&xhci->lock, flags); |
3816 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3840 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
3817 | "FIXME: allocate a command ring segment"); | 3841 | "FIXME: allocate a command ring segment"); |
3842 | kfree(command); | ||
3818 | return ret; | 3843 | return ret; |
3819 | } | 3844 | } |
3820 | xhci_ring_cmd_db(xhci); | 3845 | xhci_ring_cmd_db(xhci); |
3821 | spin_unlock_irqrestore(&xhci->lock, flags); | 3846 | spin_unlock_irqrestore(&xhci->lock, flags); |
3822 | 3847 | ||
3823 | /* ctrl tx can take up to 5 sec; XXX: need more time for xHC? */ | 3848 | /* ctrl tx can take up to 5 sec; XXX: need more time for xHC? */ |
3824 | timeleft = wait_for_completion_interruptible_timeout(&xhci->addr_dev, | 3849 | wait_for_completion(command->completion); |
3825 | XHCI_CMD_DEFAULT_TIMEOUT); | 3850 | |
3826 | /* FIXME: From section 4.3.4: "Software shall be responsible for timing | 3851 | /* FIXME: From section 4.3.4: "Software shall be responsible for timing |
3827 | * the SetAddress() "recovery interval" required by USB and aborting the | 3852 | * the SetAddress() "recovery interval" required by USB and aborting the |
3828 | * command on a timeout. | 3853 | * command on a timeout. |
3829 | */ | 3854 | */ |
3830 | if (timeleft <= 0) { | 3855 | switch (command->status) { |
3831 | xhci_warn(xhci, "%s while waiting for setup %s command\n", | 3856 | case COMP_CMD_ABORT: |
3832 | timeleft == 0 ? "Timeout" : "Signal", act); | 3857 | case COMP_CMD_STOP: |
3833 | /* cancel the address device command */ | 3858 | xhci_warn(xhci, "Timeout while waiting for setup device command\n"); |
3834 | ret = xhci_cancel_cmd(xhci, NULL, cmd_trb); | 3859 | ret = -ETIME; |
3835 | if (ret < 0) | 3860 | break; |
3836 | return ret; | ||
3837 | return -ETIME; | ||
3838 | } | ||
3839 | |||
3840 | switch (virt_dev->cmd_status) { | ||
3841 | case COMP_CTX_STATE: | 3861 | case COMP_CTX_STATE: |
3842 | case COMP_EBADSLT: | 3862 | case COMP_EBADSLT: |
3843 | xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", | 3863 | xhci_err(xhci, "Setup ERROR: setup %s command for slot %d.\n", |
@@ -3860,7 +3880,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3860 | default: | 3880 | default: |
3861 | xhci_err(xhci, | 3881 | xhci_err(xhci, |
3862 | "ERROR: unexpected setup %s command completion code 0x%x.\n", | 3882 | "ERROR: unexpected setup %s command completion code 0x%x.\n", |
3863 | act, virt_dev->cmd_status); | 3883 | act, command->status); |
3864 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); | 3884 | xhci_dbg(xhci, "Slot ID %d Output Context:\n", udev->slot_id); |
3865 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); | 3885 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, 2); |
3866 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); | 3886 | trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 1); |
@@ -3868,6 +3888,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3868 | break; | 3888 | break; |
3869 | } | 3889 | } |
3870 | if (ret) { | 3890 | if (ret) { |
3891 | kfree(command); | ||
3871 | return ret; | 3892 | return ret; |
3872 | } | 3893 | } |
3873 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); | 3894 | temp_64 = xhci_read_64(xhci, &xhci->op_regs->dcbaa_ptr); |
@@ -3902,7 +3923,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, | |||
3902 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, | 3923 | xhci_dbg_trace(xhci, trace_xhci_dbg_address, |
3903 | "Internal device address = %d", | 3924 | "Internal device address = %d", |
3904 | le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); | 3925 | le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK); |
3905 | 3926 | kfree(command); | |
3906 | return 0; | 3927 | return 0; |
3907 | } | 3928 | } |
3908 | 3929 | ||
@@ -4092,7 +4113,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | |||
4092 | field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); | 4113 | field = le32_to_cpu(udev->bos->ext_cap->bmAttributes); |
4093 | 4114 | ||
4094 | xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", | 4115 | xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", |
4095 | enable ? "enable" : "disable", port_num); | 4116 | enable ? "enable" : "disable", port_num + 1); |
4096 | 4117 | ||
4097 | if (enable) { | 4118 | if (enable) { |
4098 | /* Host supports BESL timeout instead of HIRD */ | 4119 | /* Host supports BESL timeout instead of HIRD */ |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 4746816aed3e..9ffecd56600d 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -937,9 +937,6 @@ struct xhci_virt_device { | |||
937 | #define XHCI_MAX_RINGS_CACHED 31 | 937 | #define XHCI_MAX_RINGS_CACHED 31 |
938 | struct xhci_virt_ep eps[31]; | 938 | struct xhci_virt_ep eps[31]; |
939 | struct completion cmd_completion; | 939 | struct completion cmd_completion; |
940 | /* Status of the last command issued for this device */ | ||
941 | u32 cmd_status; | ||
942 | struct list_head cmd_list; | ||
943 | u8 fake_port; | 940 | u8 fake_port; |
944 | u8 real_port; | 941 | u8 real_port; |
945 | struct xhci_interval_bw_table *bw_table; | 942 | struct xhci_interval_bw_table *bw_table; |
@@ -1298,7 +1295,6 @@ struct xhci_td { | |||
1298 | 1295 | ||
1299 | /* command descriptor */ | 1296 | /* command descriptor */ |
1300 | struct xhci_cd { | 1297 | struct xhci_cd { |
1301 | struct list_head cancel_cmd_list; | ||
1302 | struct xhci_command *command; | 1298 | struct xhci_command *command; |
1303 | union xhci_trb *cmd_trb; | 1299 | union xhci_trb *cmd_trb; |
1304 | }; | 1300 | }; |
@@ -1476,6 +1472,8 @@ struct xhci_hcd { | |||
1476 | /* msi-x vectors */ | 1472 | /* msi-x vectors */ |
1477 | int msix_count; | 1473 | int msix_count; |
1478 | struct msix_entry *msix_entries; | 1474 | struct msix_entry *msix_entries; |
1475 | /* optional clock */ | ||
1476 | struct clk *clk; | ||
1479 | /* data structures */ | 1477 | /* data structures */ |
1480 | struct xhci_device_context_array *dcbaa; | 1478 | struct xhci_device_context_array *dcbaa; |
1481 | struct xhci_ring *cmd_ring; | 1479 | struct xhci_ring *cmd_ring; |
@@ -1483,8 +1481,10 @@ struct xhci_hcd { | |||
1483 | #define CMD_RING_STATE_RUNNING (1 << 0) | 1481 | #define CMD_RING_STATE_RUNNING (1 << 0) |
1484 | #define CMD_RING_STATE_ABORTED (1 << 1) | 1482 | #define CMD_RING_STATE_ABORTED (1 << 1) |
1485 | #define CMD_RING_STATE_STOPPED (1 << 2) | 1483 | #define CMD_RING_STATE_STOPPED (1 << 2) |
1486 | struct list_head cancel_cmd_list; | 1484 | struct list_head cmd_list; |
1487 | unsigned int cmd_ring_reserved_trbs; | 1485 | unsigned int cmd_ring_reserved_trbs; |
1486 | struct timer_list cmd_timer; | ||
1487 | struct xhci_command *current_cmd; | ||
1488 | struct xhci_ring *event_ring; | 1488 | struct xhci_ring *event_ring; |
1489 | struct xhci_erst erst; | 1489 | struct xhci_erst erst; |
1490 | /* Scratchpad */ | 1490 | /* Scratchpad */ |
@@ -1738,8 +1738,7 @@ static inline int xhci_register_pci(void) { return 0; } | |||
1738 | static inline void xhci_unregister_pci(void) {} | 1738 | static inline void xhci_unregister_pci(void) {} |
1739 | #endif | 1739 | #endif |
1740 | 1740 | ||
1741 | #if defined(CONFIG_USB_XHCI_PLATFORM) \ | 1741 | #if IS_ENABLED(CONFIG_USB_XHCI_PLATFORM) |
1742 | || defined(CONFIG_USB_XHCI_PLATFORM_MODULE) | ||
1743 | int xhci_register_plat(void); | 1742 | int xhci_register_plat(void); |
1744 | void xhci_unregister_plat(void); | 1743 | void xhci_unregister_plat(void); |
1745 | #else | 1744 | #else |
@@ -1808,13 +1807,14 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, | |||
1808 | dma_addr_t suspect_dma); | 1807 | dma_addr_t suspect_dma); |
1809 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); | 1808 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); |
1810 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); | 1809 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); |
1811 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); | 1810 | int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd, |
1812 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1811 | u32 trb_type, u32 slot_id); |
1813 | u32 slot_id, enum xhci_setup_dev); | 1812 | int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd, |
1814 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, | 1813 | dma_addr_t in_ctx_ptr, u32 slot_id, enum xhci_setup_dev); |
1814 | int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd, | ||
1815 | u32 field1, u32 field2, u32 field3, u32 field4); | 1815 | u32 field1, u32 field2, u32 field3, u32 field4); |
1816 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, | 1816 | int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd, |
1817 | unsigned int ep_index, int suspend); | 1817 | int slot_id, unsigned int ep_index, int suspend); |
1818 | int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | 1818 | int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, |
1819 | int slot_id, unsigned int ep_index); | 1819 | int slot_id, unsigned int ep_index); |
1820 | int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | 1820 | int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, |
@@ -1823,18 +1823,21 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, | |||
1823 | int slot_id, unsigned int ep_index); | 1823 | int slot_id, unsigned int ep_index); |
1824 | int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, | 1824 | int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, |
1825 | struct urb *urb, int slot_id, unsigned int ep_index); | 1825 | struct urb *urb, int slot_id, unsigned int ep_index); |
1826 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1826 | int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, |
1827 | u32 slot_id, bool command_must_succeed); | 1827 | struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id, |
1828 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1828 | bool command_must_succeed); |
1829 | u32 slot_id, bool command_must_succeed); | 1829 | int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd, |
1830 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, | 1830 | dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed); |
1831 | unsigned int ep_index); | 1831 | int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd, |
1832 | int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); | 1832 | int slot_id, unsigned int ep_index); |
1833 | int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, | ||
1834 | u32 slot_id); | ||
1833 | void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | 1835 | void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, |
1834 | unsigned int slot_id, unsigned int ep_index, | 1836 | unsigned int slot_id, unsigned int ep_index, |
1835 | unsigned int stream_id, struct xhci_td *cur_td, | 1837 | unsigned int stream_id, struct xhci_td *cur_td, |
1836 | struct xhci_dequeue_state *state); | 1838 | struct xhci_dequeue_state *state); |
1837 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | 1839 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, |
1840 | struct xhci_command *cmd, | ||
1838 | unsigned int slot_id, unsigned int ep_index, | 1841 | unsigned int slot_id, unsigned int ep_index, |
1839 | unsigned int stream_id, | 1842 | unsigned int stream_id, |
1840 | struct xhci_dequeue_state *deq_state); | 1843 | struct xhci_dequeue_state *deq_state); |
@@ -1844,11 +1847,11 @@ void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, | |||
1844 | unsigned int slot_id, unsigned int ep_index, | 1847 | unsigned int slot_id, unsigned int ep_index, |
1845 | struct xhci_dequeue_state *deq_state); | 1848 | struct xhci_dequeue_state *deq_state); |
1846 | void xhci_stop_endpoint_command_watchdog(unsigned long arg); | 1849 | void xhci_stop_endpoint_command_watchdog(unsigned long arg); |
1847 | int xhci_cancel_cmd(struct xhci_hcd *xhci, struct xhci_command *command, | 1850 | void xhci_handle_command_timeout(unsigned long data); |
1848 | union xhci_trb *cmd_trb); | 1851 | |
1849 | void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, | 1852 | void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, |
1850 | unsigned int ep_index, unsigned int stream_id); | 1853 | unsigned int ep_index, unsigned int stream_id); |
1851 | union xhci_trb *xhci_find_next_enqueue(struct xhci_ring *ring); | 1854 | void xhci_cleanup_command_queue(struct xhci_hcd *xhci); |
1852 | 1855 | ||
1853 | /* xHCI roothub code */ | 1856 | /* xHCI roothub code */ |
1854 | void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, | 1857 | void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, |
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index ba6a5d6e618e..b3d245ef46ef 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c | |||
@@ -81,6 +81,7 @@ struct appledisplay { | |||
81 | struct delayed_work work; | 81 | struct delayed_work work; |
82 | int button_pressed; | 82 | int button_pressed; |
83 | spinlock_t lock; | 83 | spinlock_t lock; |
84 | struct mutex sysfslock; /* concurrent read and write */ | ||
84 | }; | 85 | }; |
85 | 86 | ||
86 | static atomic_t count_displays = ATOMIC_INIT(0); | 87 | static atomic_t count_displays = ATOMIC_INIT(0); |
@@ -110,7 +111,7 @@ static void appledisplay_complete(struct urb *urb) | |||
110 | __func__, status); | 111 | __func__, status); |
111 | return; | 112 | return; |
112 | default: | 113 | default: |
113 | dev_dbg(dev, "%s - nonzero urb status received: %d/n", | 114 | dev_dbg(dev, "%s - nonzero urb status received: %d\n", |
114 | __func__, status); | 115 | __func__, status); |
115 | goto exit; | 116 | goto exit; |
116 | } | 117 | } |
@@ -144,6 +145,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) | |||
144 | struct appledisplay *pdata = bl_get_data(bd); | 145 | struct appledisplay *pdata = bl_get_data(bd); |
145 | int retval; | 146 | int retval; |
146 | 147 | ||
148 | mutex_lock(&pdata->sysfslock); | ||
147 | pdata->msgdata[0] = 0x10; | 149 | pdata->msgdata[0] = 0x10; |
148 | pdata->msgdata[1] = bd->props.brightness; | 150 | pdata->msgdata[1] = bd->props.brightness; |
149 | 151 | ||
@@ -156,15 +158,17 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) | |||
156 | 0, | 158 | 0, |
157 | pdata->msgdata, 2, | 159 | pdata->msgdata, 2, |
158 | ACD_USB_TIMEOUT); | 160 | ACD_USB_TIMEOUT); |
159 | 161 | mutex_unlock(&pdata->sysfslock); | |
162 | |||
160 | return retval; | 163 | return retval; |
161 | } | 164 | } |
162 | 165 | ||
163 | static int appledisplay_bl_get_brightness(struct backlight_device *bd) | 166 | static int appledisplay_bl_get_brightness(struct backlight_device *bd) |
164 | { | 167 | { |
165 | struct appledisplay *pdata = bl_get_data(bd); | 168 | struct appledisplay *pdata = bl_get_data(bd); |
166 | int retval; | 169 | int retval, brightness; |
167 | 170 | ||
171 | mutex_lock(&pdata->sysfslock); | ||
168 | retval = usb_control_msg( | 172 | retval = usb_control_msg( |
169 | pdata->udev, | 173 | pdata->udev, |
170 | usb_rcvctrlpipe(pdata->udev, 0), | 174 | usb_rcvctrlpipe(pdata->udev, 0), |
@@ -174,11 +178,13 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd) | |||
174 | 0, | 178 | 0, |
175 | pdata->msgdata, 2, | 179 | pdata->msgdata, 2, |
176 | ACD_USB_TIMEOUT); | 180 | ACD_USB_TIMEOUT); |
181 | brightness = pdata->msgdata[1]; | ||
182 | mutex_unlock(&pdata->sysfslock); | ||
177 | 183 | ||
178 | if (retval < 0) | 184 | if (retval < 0) |
179 | return retval; | 185 | return retval; |
180 | else | 186 | else |
181 | return pdata->msgdata[1]; | 187 | return brightness; |
182 | } | 188 | } |
183 | 189 | ||
184 | static const struct backlight_ops appledisplay_bl_data = { | 190 | static const struct backlight_ops appledisplay_bl_data = { |
@@ -241,6 +247,7 @@ static int appledisplay_probe(struct usb_interface *iface, | |||
241 | 247 | ||
242 | spin_lock_init(&pdata->lock); | 248 | spin_lock_init(&pdata->lock); |
243 | INIT_DELAYED_WORK(&pdata->work, appledisplay_work); | 249 | INIT_DELAYED_WORK(&pdata->work, appledisplay_work); |
250 | mutex_init(&pdata->sysfslock); | ||
244 | 251 | ||
245 | /* Allocate buffer for control messages */ | 252 | /* Allocate buffer for control messages */ |
246 | pdata->msgdata = kmalloc(ACD_MSG_BUFFER_LEN, GFP_KERNEL); | 253 | pdata->msgdata = kmalloc(ACD_MSG_BUFFER_LEN, GFP_KERNEL); |
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c index a4a3c7cd4a11..8ab1f8f3c26e 100644 --- a/drivers/usb/misc/ftdi-elan.c +++ b/drivers/usb/misc/ftdi-elan.c | |||
@@ -1,40 +1,43 @@ | |||
1 | /* | 1 | /* |
2 | * USB FTDI client driver for Elan Digital Systems's Uxxx adapters | 2 | * USB FTDI client driver for Elan Digital Systems's Uxxx adapters |
3 | * | 3 | * |
4 | * Copyright(C) 2006 Elan Digital Systems Limited | 4 | * Copyright(C) 2006 Elan Digital Systems Limited |
5 | * http://www.elandigitalsystems.com | 5 | * http://www.elandigitalsystems.com |
6 | * | 6 | * |
7 | * Author and Maintainer - Tony Olech - Elan Digital Systems | 7 | * Author and Maintainer - Tony Olech - Elan Digital Systems |
8 | * tony.olech@elandigitalsystems.com | 8 | * tony.olech@elandigitalsystems.com |
9 | * | 9 | * |
10 | * This program is free software;you can redistribute it and/or | 10 | * This program is free software;you can redistribute it and/or |
11 | * modify it under the terms of the GNU General Public License as | 11 | * modify it under the terms of the GNU General Public License as |
12 | * published by the Free Software Foundation, version 2. | 12 | * published by the Free Software Foundation, version 2. |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com) | 15 | * This driver was written by Tony Olech(tony.olech@elandigitalsystems.com) |
16 | * based on various USB client drivers in the 2.6.15 linux kernel | 16 | * based on various USB client drivers in the 2.6.15 linux kernel |
17 | * with constant reference to the 3rd Edition of Linux Device Drivers | 17 | * with constant reference to the 3rd Edition of Linux Device Drivers |
18 | * published by O'Reilly | 18 | * published by O'Reilly |
19 | * | 19 | * |
20 | * The U132 adapter is a USB to CardBus adapter specifically designed | 20 | * The U132 adapter is a USB to CardBus adapter specifically designed |
21 | * for PC cards that contain an OHCI host controller. Typical PC cards | 21 | * for PC cards that contain an OHCI host controller. Typical PC cards |
22 | * are the Orange Mobile 3G Option GlobeTrotter Fusion card. | 22 | * are the Orange Mobile 3G Option GlobeTrotter Fusion card. |
23 | * | 23 | * |
24 | * The U132 adapter will *NOT *work with PC cards that do not contain | 24 | * The U132 adapter will *NOT *work with PC cards that do not contain |
25 | * an OHCI controller. A simple way to test whether a PC card has an | 25 | * an OHCI controller. A simple way to test whether a PC card has an |
26 | * OHCI controller as an interface is to insert the PC card directly | 26 | * OHCI controller as an interface is to insert the PC card directly |
27 | * into a laptop(or desktop) with a CardBus slot and if "lspci" shows | 27 | * into a laptop(or desktop) with a CardBus slot and if "lspci" shows |
28 | * a new USB controller and "lsusb -v" shows a new OHCI Host Controller | 28 | * a new USB controller and "lsusb -v" shows a new OHCI Host Controller |
29 | * then there is a good chance that the U132 adapter will support the | 29 | * then there is a good chance that the U132 adapter will support the |
30 | * PC card.(you also need the specific client driver for the PC card) | 30 | * PC card.(you also need the specific client driver for the PC card) |
31 | * | 31 | * |
32 | * Please inform the Author and Maintainer about any PC cards that | 32 | * Please inform the Author and Maintainer about any PC cards that |
33 | * contain OHCI Host Controller and work when directly connected to | 33 | * contain OHCI Host Controller and work when directly connected to |
34 | * an embedded CardBus slot but do not work when they are connected | 34 | * an embedded CardBus slot but do not work when they are connected |
35 | * via an ELAN U132 adapter. | 35 | * via an ELAN U132 adapter. |
36 | * | 36 | * |
37 | */ | 37 | */ |
38 | |||
39 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
40 | |||
38 | #include <linux/kernel.h> | 41 | #include <linux/kernel.h> |
39 | #include <linux/errno.h> | 42 | #include <linux/errno.h> |
40 | #include <linux/init.h> | 43 | #include <linux/init.h> |
@@ -55,31 +58,31 @@ MODULE_LICENSE("GPL"); | |||
55 | #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) | 58 | #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) |
56 | static bool distrust_firmware = 1; | 59 | static bool distrust_firmware = 1; |
57 | module_param(distrust_firmware, bool, 0); | 60 | module_param(distrust_firmware, bool, 0); |
58 | MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren" | 61 | MODULE_PARM_DESC(distrust_firmware, |
59 | "t setup"); | 62 | "true to distrust firmware power/overcurrent setup"); |
60 | extern struct platform_driver u132_platform_driver; | 63 | extern struct platform_driver u132_platform_driver; |
61 | static struct workqueue_struct *status_queue; | 64 | static struct workqueue_struct *status_queue; |
62 | static struct workqueue_struct *command_queue; | 65 | static struct workqueue_struct *command_queue; |
63 | static struct workqueue_struct *respond_queue; | 66 | static struct workqueue_struct *respond_queue; |
64 | /* | 67 | /* |
65 | * ftdi_module_lock exists to protect access to global variables | 68 | * ftdi_module_lock exists to protect access to global variables |
66 | * | 69 | * |
67 | */ | 70 | */ |
68 | static struct mutex ftdi_module_lock; | 71 | static struct mutex ftdi_module_lock; |
69 | static int ftdi_instances = 0; | 72 | static int ftdi_instances = 0; |
70 | static struct list_head ftdi_static_list; | 73 | static struct list_head ftdi_static_list; |
71 | /* | 74 | /* |
72 | * end of the global variables protected by ftdi_module_lock | 75 | * end of the global variables protected by ftdi_module_lock |
73 | */ | 76 | */ |
74 | #include "usb_u132.h" | 77 | #include "usb_u132.h" |
75 | #include <asm/io.h> | 78 | #include <asm/io.h> |
76 | #include <linux/usb/hcd.h> | 79 | #include <linux/usb/hcd.h> |
77 | 80 | ||
78 | /* FIXME ohci.h is ONLY for internal use by the OHCI driver. | 81 | /* FIXME ohci.h is ONLY for internal use by the OHCI driver. |
79 | * If you're going to try stuff like this, you need to split | 82 | * If you're going to try stuff like this, you need to split |
80 | * out shareable stuff (register declarations?) into its own | 83 | * out shareable stuff (register declarations?) into its own |
81 | * file, maybe name <linux/usb/ohci.h> | 84 | * file, maybe name <linux/usb/ohci.h> |
82 | */ | 85 | */ |
83 | 86 | ||
84 | #include "../host/ohci.h" | 87 | #include "../host/ohci.h" |
85 | /* Define these values to match your devices*/ | 88 | /* Define these values to match your devices*/ |
@@ -87,140 +90,140 @@ static struct list_head ftdi_static_list; | |||
87 | #define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea | 90 | #define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea |
88 | /* table of devices that work with this driver*/ | 91 | /* table of devices that work with this driver*/ |
89 | static const struct usb_device_id ftdi_elan_table[] = { | 92 | static const struct usb_device_id ftdi_elan_table[] = { |
90 | {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)}, | 93 | {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)}, |
91 | { /* Terminating entry */ } | 94 | { /* Terminating entry */ } |
92 | }; | 95 | }; |
93 | 96 | ||
94 | MODULE_DEVICE_TABLE(usb, ftdi_elan_table); | 97 | MODULE_DEVICE_TABLE(usb, ftdi_elan_table); |
95 | /* only the jtag(firmware upgrade device) interface requires | 98 | /* only the jtag(firmware upgrade device) interface requires |
96 | * a device file and corresponding minor number, but the | 99 | * a device file and corresponding minor number, but the |
97 | * interface is created unconditionally - I suppose it could | 100 | * interface is created unconditionally - I suppose it could |
98 | * be configured or not according to a module parameter. | 101 | * be configured or not according to a module parameter. |
99 | * But since we(now) require one interface per device, | 102 | * But since we(now) require one interface per device, |
100 | * and since it unlikely that a normal installation would | 103 | * and since it unlikely that a normal installation would |
101 | * require more than a couple of elan-ftdi devices, 8 seems | 104 | * require more than a couple of elan-ftdi devices, 8 seems |
102 | * like a reasonable limit to have here, and if someone | 105 | * like a reasonable limit to have here, and if someone |
103 | * really requires more than 8 devices, then they can frig the | 106 | * really requires more than 8 devices, then they can frig the |
104 | * code and recompile | 107 | * code and recompile |
105 | */ | 108 | */ |
106 | #define USB_FTDI_ELAN_MINOR_BASE 192 | 109 | #define USB_FTDI_ELAN_MINOR_BASE 192 |
107 | #define COMMAND_BITS 5 | 110 | #define COMMAND_BITS 5 |
108 | #define COMMAND_SIZE (1<<COMMAND_BITS) | 111 | #define COMMAND_SIZE (1<<COMMAND_BITS) |
109 | #define COMMAND_MASK (COMMAND_SIZE-1) | 112 | #define COMMAND_MASK (COMMAND_SIZE-1) |
110 | struct u132_command { | 113 | struct u132_command { |
111 | u8 header; | 114 | u8 header; |
112 | u16 length; | 115 | u16 length; |
113 | u8 address; | 116 | u8 address; |
114 | u8 width; | 117 | u8 width; |
115 | u32 value; | 118 | u32 value; |
116 | int follows; | 119 | int follows; |
117 | void *buffer; | 120 | void *buffer; |
118 | }; | 121 | }; |
119 | #define RESPOND_BITS 5 | 122 | #define RESPOND_BITS 5 |
120 | #define RESPOND_SIZE (1<<RESPOND_BITS) | 123 | #define RESPOND_SIZE (1<<RESPOND_BITS) |
121 | #define RESPOND_MASK (RESPOND_SIZE-1) | 124 | #define RESPOND_MASK (RESPOND_SIZE-1) |
122 | struct u132_respond { | 125 | struct u132_respond { |
123 | u8 header; | 126 | u8 header; |
124 | u8 address; | 127 | u8 address; |
125 | u32 *value; | 128 | u32 *value; |
126 | int *result; | 129 | int *result; |
127 | struct completion wait_completion; | 130 | struct completion wait_completion; |
128 | }; | 131 | }; |
129 | struct u132_target { | 132 | struct u132_target { |
130 | void *endp; | 133 | void *endp; |
131 | struct urb *urb; | 134 | struct urb *urb; |
132 | int toggle_bits; | 135 | int toggle_bits; |
133 | int error_count; | 136 | int error_count; |
134 | int condition_code; | 137 | int condition_code; |
135 | int repeat_number; | 138 | int repeat_number; |
136 | int halted; | 139 | int halted; |
137 | int skipped; | 140 | int skipped; |
138 | int actual; | 141 | int actual; |
139 | int non_null; | 142 | int non_null; |
140 | int active; | 143 | int active; |
141 | int abandoning; | 144 | int abandoning; |
142 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 145 | void (*callback)(void *endp, struct urb *urb, u8 *buf, int len, |
143 | int toggle_bits, int error_count, int condition_code, | 146 | int toggle_bits, int error_count, int condition_code, |
144 | int repeat_number, int halted, int skipped, int actual, | 147 | int repeat_number, int halted, int skipped, int actual, |
145 | int non_null); | 148 | int non_null); |
146 | }; | 149 | }; |
147 | /* Structure to hold all of our device specific stuff*/ | 150 | /* Structure to hold all of our device specific stuff*/ |
148 | struct usb_ftdi { | 151 | struct usb_ftdi { |
149 | struct list_head ftdi_list; | 152 | struct list_head ftdi_list; |
150 | struct mutex u132_lock; | 153 | struct mutex u132_lock; |
151 | int command_next; | 154 | int command_next; |
152 | int command_head; | 155 | int command_head; |
153 | struct u132_command command[COMMAND_SIZE]; | 156 | struct u132_command command[COMMAND_SIZE]; |
154 | int respond_next; | 157 | int respond_next; |
155 | int respond_head; | 158 | int respond_head; |
156 | struct u132_respond respond[RESPOND_SIZE]; | 159 | struct u132_respond respond[RESPOND_SIZE]; |
157 | struct u132_target target[4]; | 160 | struct u132_target target[4]; |
158 | char device_name[16]; | 161 | char device_name[16]; |
159 | unsigned synchronized:1; | 162 | unsigned synchronized:1; |
160 | unsigned enumerated:1; | 163 | unsigned enumerated:1; |
161 | unsigned registered:1; | 164 | unsigned registered:1; |
162 | unsigned initialized:1; | 165 | unsigned initialized:1; |
163 | unsigned card_ejected:1; | 166 | unsigned card_ejected:1; |
164 | int function; | 167 | int function; |
165 | int sequence_num; | 168 | int sequence_num; |
166 | int disconnected; | 169 | int disconnected; |
167 | int gone_away; | 170 | int gone_away; |
168 | int stuck_status; | 171 | int stuck_status; |
169 | int status_queue_delay; | 172 | int status_queue_delay; |
170 | struct semaphore sw_lock; | 173 | struct semaphore sw_lock; |
171 | struct usb_device *udev; | 174 | struct usb_device *udev; |
172 | struct usb_interface *interface; | 175 | struct usb_interface *interface; |
173 | struct usb_class_driver *class; | 176 | struct usb_class_driver *class; |
174 | struct delayed_work status_work; | 177 | struct delayed_work status_work; |
175 | struct delayed_work command_work; | 178 | struct delayed_work command_work; |
176 | struct delayed_work respond_work; | 179 | struct delayed_work respond_work; |
177 | struct u132_platform_data platform_data; | 180 | struct u132_platform_data platform_data; |
178 | struct resource resources[0]; | 181 | struct resource resources[0]; |
179 | struct platform_device platform_dev; | 182 | struct platform_device platform_dev; |
180 | unsigned char *bulk_in_buffer; | 183 | unsigned char *bulk_in_buffer; |
181 | size_t bulk_in_size; | 184 | size_t bulk_in_size; |
182 | size_t bulk_in_last; | 185 | size_t bulk_in_last; |
183 | size_t bulk_in_left; | 186 | size_t bulk_in_left; |
184 | __u8 bulk_in_endpointAddr; | 187 | __u8 bulk_in_endpointAddr; |
185 | __u8 bulk_out_endpointAddr; | 188 | __u8 bulk_out_endpointAddr; |
186 | struct kref kref; | 189 | struct kref kref; |
187 | u32 controlreg; | 190 | u32 controlreg; |
188 | u8 response[4 + 1024]; | 191 | u8 response[4 + 1024]; |
189 | int expected; | 192 | int expected; |
190 | int received; | 193 | int received; |
191 | int ed_found; | 194 | int ed_found; |
192 | }; | 195 | }; |
193 | #define kref_to_usb_ftdi(d) container_of(d, struct usb_ftdi, kref) | 196 | #define kref_to_usb_ftdi(d) container_of(d, struct usb_ftdi, kref) |
194 | #define platform_device_to_usb_ftdi(d) container_of(d, struct usb_ftdi, \ | 197 | #define platform_device_to_usb_ftdi(d) container_of(d, struct usb_ftdi, \ |
195 | platform_dev) | 198 | platform_dev) |
196 | static struct usb_driver ftdi_elan_driver; | 199 | static struct usb_driver ftdi_elan_driver; |
197 | static void ftdi_elan_delete(struct kref *kref) | 200 | static void ftdi_elan_delete(struct kref *kref) |
198 | { | 201 | { |
199 | struct usb_ftdi *ftdi = kref_to_usb_ftdi(kref); | 202 | struct usb_ftdi *ftdi = kref_to_usb_ftdi(kref); |
200 | dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi); | 203 | dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi); |
201 | usb_put_dev(ftdi->udev); | 204 | usb_put_dev(ftdi->udev); |
202 | ftdi->disconnected += 1; | 205 | ftdi->disconnected += 1; |
203 | mutex_lock(&ftdi_module_lock); | 206 | mutex_lock(&ftdi_module_lock); |
204 | list_del_init(&ftdi->ftdi_list); | 207 | list_del_init(&ftdi->ftdi_list); |
205 | ftdi_instances -= 1; | 208 | ftdi_instances -= 1; |
206 | mutex_unlock(&ftdi_module_lock); | 209 | mutex_unlock(&ftdi_module_lock); |
207 | kfree(ftdi->bulk_in_buffer); | 210 | kfree(ftdi->bulk_in_buffer); |
208 | ftdi->bulk_in_buffer = NULL; | 211 | ftdi->bulk_in_buffer = NULL; |
209 | } | 212 | } |
210 | 213 | ||
211 | static void ftdi_elan_put_kref(struct usb_ftdi *ftdi) | 214 | static void ftdi_elan_put_kref(struct usb_ftdi *ftdi) |
212 | { | 215 | { |
213 | kref_put(&ftdi->kref, ftdi_elan_delete); | 216 | kref_put(&ftdi->kref, ftdi_elan_delete); |
214 | } | 217 | } |
215 | 218 | ||
216 | static void ftdi_elan_get_kref(struct usb_ftdi *ftdi) | 219 | static void ftdi_elan_get_kref(struct usb_ftdi *ftdi) |
217 | { | 220 | { |
218 | kref_get(&ftdi->kref); | 221 | kref_get(&ftdi->kref); |
219 | } | 222 | } |
220 | 223 | ||
221 | static void ftdi_elan_init_kref(struct usb_ftdi *ftdi) | 224 | static void ftdi_elan_init_kref(struct usb_ftdi *ftdi) |
222 | { | 225 | { |
223 | kref_init(&ftdi->kref); | 226 | kref_init(&ftdi->kref); |
224 | } | 227 | } |
225 | 228 | ||
226 | static void ftdi_status_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) | 229 | static void ftdi_status_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) |
@@ -237,8 +240,8 @@ static void ftdi_status_queue_work(struct usb_ftdi *ftdi, unsigned int delta) | |||
237 | 240 | ||
238 | static void ftdi_status_cancel_work(struct usb_ftdi *ftdi) | 241 | static void ftdi_status_cancel_work(struct usb_ftdi *ftdi) |
239 | { | 242 | { |
240 | if (cancel_delayed_work(&ftdi->status_work)) | 243 | if (cancel_delayed_work(&ftdi->status_work)) |
241 | kref_put(&ftdi->kref, ftdi_elan_delete); | 244 | kref_put(&ftdi->kref, ftdi_elan_delete); |
242 | } | 245 | } |
243 | 246 | ||
244 | static void ftdi_command_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) | 247 | static void ftdi_command_requeue_work(struct usb_ftdi *ftdi, unsigned int delta) |
@@ -255,12 +258,12 @@ static void ftdi_command_queue_work(struct usb_ftdi *ftdi, unsigned int delta) | |||
255 | 258 | ||
256 | static void ftdi_command_cancel_work(struct usb_ftdi *ftdi) | 259 | static void ftdi_command_cancel_work(struct usb_ftdi *ftdi) |
257 | { | 260 | { |
258 | if (cancel_delayed_work(&ftdi->command_work)) | 261 | if (cancel_delayed_work(&ftdi->command_work)) |
259 | kref_put(&ftdi->kref, ftdi_elan_delete); | 262 | kref_put(&ftdi->kref, ftdi_elan_delete); |
260 | } | 263 | } |
261 | 264 | ||
262 | static void ftdi_response_requeue_work(struct usb_ftdi *ftdi, | 265 | static void ftdi_response_requeue_work(struct usb_ftdi *ftdi, |
263 | unsigned int delta) | 266 | unsigned int delta) |
264 | { | 267 | { |
265 | if (!queue_delayed_work(respond_queue, &ftdi->respond_work, delta)) | 268 | if (!queue_delayed_work(respond_queue, &ftdi->respond_work, delta)) |
266 | kref_put(&ftdi->kref, ftdi_elan_delete); | 269 | kref_put(&ftdi->kref, ftdi_elan_delete); |
@@ -274,26 +277,26 @@ static void ftdi_respond_queue_work(struct usb_ftdi *ftdi, unsigned int delta) | |||
274 | 277 | ||
275 | static void ftdi_response_cancel_work(struct usb_ftdi *ftdi) | 278 | static void ftdi_response_cancel_work(struct usb_ftdi *ftdi) |
276 | { | 279 | { |
277 | if (cancel_delayed_work(&ftdi->respond_work)) | 280 | if (cancel_delayed_work(&ftdi->respond_work)) |
278 | kref_put(&ftdi->kref, ftdi_elan_delete); | 281 | kref_put(&ftdi->kref, ftdi_elan_delete); |
279 | } | 282 | } |
280 | 283 | ||
281 | void ftdi_elan_gone_away(struct platform_device *pdev) | 284 | void ftdi_elan_gone_away(struct platform_device *pdev) |
282 | { | 285 | { |
283 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 286 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
284 | ftdi->gone_away += 1; | 287 | ftdi->gone_away += 1; |
285 | ftdi_elan_put_kref(ftdi); | 288 | ftdi_elan_put_kref(ftdi); |
286 | } | 289 | } |
287 | 290 | ||
288 | 291 | ||
289 | EXPORT_SYMBOL_GPL(ftdi_elan_gone_away); | 292 | EXPORT_SYMBOL_GPL(ftdi_elan_gone_away); |
290 | static void ftdi_release_platform_dev(struct device *dev) | 293 | static void ftdi_release_platform_dev(struct device *dev) |
291 | { | 294 | { |
292 | dev->parent = NULL; | 295 | dev->parent = NULL; |
293 | } | 296 | } |
294 | 297 | ||
295 | static void ftdi_elan_do_callback(struct usb_ftdi *ftdi, | 298 | static void ftdi_elan_do_callback(struct usb_ftdi *ftdi, |
296 | struct u132_target *target, u8 *buffer, int length); | 299 | struct u132_target *target, u8 *buffer, int length); |
297 | static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi); | 300 | static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi); |
298 | static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi); | 301 | static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi); |
299 | static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi); | 302 | static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi); |
@@ -305,421 +308,416 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi); | |||
305 | static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi); | 308 | static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi); |
306 | static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi) | 309 | static int ftdi_elan_hcd_init(struct usb_ftdi *ftdi) |
307 | { | 310 | { |
308 | int result; | 311 | int result; |
309 | if (ftdi->platform_dev.dev.parent) | 312 | if (ftdi->platform_dev.dev.parent) |
310 | return -EBUSY; | 313 | return -EBUSY; |
311 | ftdi_elan_get_kref(ftdi); | 314 | ftdi_elan_get_kref(ftdi); |
312 | ftdi->platform_data.potpg = 100; | 315 | ftdi->platform_data.potpg = 100; |
313 | ftdi->platform_data.reset = NULL; | 316 | ftdi->platform_data.reset = NULL; |
314 | ftdi->platform_dev.id = ftdi->sequence_num; | 317 | ftdi->platform_dev.id = ftdi->sequence_num; |
315 | ftdi->platform_dev.resource = ftdi->resources; | 318 | ftdi->platform_dev.resource = ftdi->resources; |
316 | ftdi->platform_dev.num_resources = ARRAY_SIZE(ftdi->resources); | 319 | ftdi->platform_dev.num_resources = ARRAY_SIZE(ftdi->resources); |
317 | ftdi->platform_dev.dev.platform_data = &ftdi->platform_data; | 320 | ftdi->platform_dev.dev.platform_data = &ftdi->platform_data; |
318 | ftdi->platform_dev.dev.parent = NULL; | 321 | ftdi->platform_dev.dev.parent = NULL; |
319 | ftdi->platform_dev.dev.release = ftdi_release_platform_dev; | 322 | ftdi->platform_dev.dev.release = ftdi_release_platform_dev; |
320 | ftdi->platform_dev.dev.dma_mask = NULL; | 323 | ftdi->platform_dev.dev.dma_mask = NULL; |
321 | snprintf(ftdi->device_name, sizeof(ftdi->device_name), "u132_hcd"); | 324 | snprintf(ftdi->device_name, sizeof(ftdi->device_name), "u132_hcd"); |
322 | ftdi->platform_dev.name = ftdi->device_name; | 325 | ftdi->platform_dev.name = ftdi->device_name; |
323 | dev_info(&ftdi->udev->dev, "requesting module '%s'\n", "u132_hcd"); | 326 | dev_info(&ftdi->udev->dev, "requesting module '%s'\n", "u132_hcd"); |
324 | request_module("u132_hcd"); | 327 | request_module("u132_hcd"); |
325 | dev_info(&ftdi->udev->dev, "registering '%s'\n", | 328 | dev_info(&ftdi->udev->dev, "registering '%s'\n", |
326 | ftdi->platform_dev.name); | 329 | ftdi->platform_dev.name); |
327 | result = platform_device_register(&ftdi->platform_dev); | 330 | result = platform_device_register(&ftdi->platform_dev); |
328 | return result; | 331 | return result; |
329 | } | 332 | } |
330 | 333 | ||
331 | static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi) | 334 | static void ftdi_elan_abandon_completions(struct usb_ftdi *ftdi) |
332 | { | 335 | { |
333 | mutex_lock(&ftdi->u132_lock); | 336 | mutex_lock(&ftdi->u132_lock); |
334 | while (ftdi->respond_next > ftdi->respond_head) { | 337 | while (ftdi->respond_next > ftdi->respond_head) { |
335 | struct u132_respond *respond = &ftdi->respond[RESPOND_MASK & | 338 | struct u132_respond *respond = &ftdi->respond[RESPOND_MASK & |
336 | ftdi->respond_head++]; | 339 | ftdi->respond_head++]; |
337 | *respond->result = -ESHUTDOWN; | 340 | *respond->result = -ESHUTDOWN; |
338 | *respond->value = 0; | 341 | *respond->value = 0; |
339 | complete(&respond->wait_completion); | 342 | complete(&respond->wait_completion); |
340 | } mutex_unlock(&ftdi->u132_lock); | 343 | } mutex_unlock(&ftdi->u132_lock); |
341 | } | 344 | } |
342 | 345 | ||
343 | static void ftdi_elan_abandon_targets(struct usb_ftdi *ftdi) | 346 | static void ftdi_elan_abandon_targets(struct usb_ftdi *ftdi) |
344 | { | 347 | { |
345 | int ed_number = 4; | 348 | int ed_number = 4; |
346 | mutex_lock(&ftdi->u132_lock); | 349 | mutex_lock(&ftdi->u132_lock); |
347 | while (ed_number-- > 0) { | 350 | while (ed_number-- > 0) { |
348 | struct u132_target *target = &ftdi->target[ed_number]; | 351 | struct u132_target *target = &ftdi->target[ed_number]; |
349 | if (target->active == 1) { | 352 | if (target->active == 1) { |
350 | target->condition_code = TD_DEVNOTRESP; | 353 | target->condition_code = TD_DEVNOTRESP; |
351 | mutex_unlock(&ftdi->u132_lock); | 354 | mutex_unlock(&ftdi->u132_lock); |
352 | ftdi_elan_do_callback(ftdi, target, NULL, 0); | 355 | ftdi_elan_do_callback(ftdi, target, NULL, 0); |
353 | mutex_lock(&ftdi->u132_lock); | 356 | mutex_lock(&ftdi->u132_lock); |
354 | } | 357 | } |
355 | } | 358 | } |
356 | ftdi->received = 0; | 359 | ftdi->received = 0; |
357 | ftdi->expected = 4; | 360 | ftdi->expected = 4; |
358 | ftdi->ed_found = 0; | 361 | ftdi->ed_found = 0; |
359 | mutex_unlock(&ftdi->u132_lock); | 362 | mutex_unlock(&ftdi->u132_lock); |
360 | } | 363 | } |
361 | 364 | ||
362 | static void ftdi_elan_flush_targets(struct usb_ftdi *ftdi) | 365 | static void ftdi_elan_flush_targets(struct usb_ftdi *ftdi) |
363 | { | 366 | { |
364 | int ed_number = 4; | 367 | int ed_number = 4; |
365 | mutex_lock(&ftdi->u132_lock); | 368 | mutex_lock(&ftdi->u132_lock); |
366 | while (ed_number-- > 0) { | 369 | while (ed_number-- > 0) { |
367 | struct u132_target *target = &ftdi->target[ed_number]; | 370 | struct u132_target *target = &ftdi->target[ed_number]; |
368 | target->abandoning = 1; | 371 | target->abandoning = 1; |
369 | wait_1:if (target->active == 1) { | 372 | wait_1:if (target->active == 1) { |
370 | int command_size = ftdi->command_next - | 373 | int command_size = ftdi->command_next - |
371 | ftdi->command_head; | 374 | ftdi->command_head; |
372 | if (command_size < COMMAND_SIZE) { | 375 | if (command_size < COMMAND_SIZE) { |
373 | struct u132_command *command = &ftdi->command[ | 376 | struct u132_command *command = &ftdi->command[ |
374 | COMMAND_MASK & ftdi->command_next]; | 377 | COMMAND_MASK & ftdi->command_next]; |
375 | command->header = 0x80 | (ed_number << 5) | 0x4; | 378 | command->header = 0x80 | (ed_number << 5) | 0x4; |
376 | command->length = 0x00; | 379 | command->length = 0x00; |
377 | command->address = 0x00; | 380 | command->address = 0x00; |
378 | command->width = 0x00; | 381 | command->width = 0x00; |
379 | command->follows = 0; | 382 | command->follows = 0; |
380 | command->value = 0; | 383 | command->value = 0; |
381 | command->buffer = &command->value; | 384 | command->buffer = &command->value; |
382 | ftdi->command_next += 1; | 385 | ftdi->command_next += 1; |
383 | ftdi_elan_kick_command_queue(ftdi); | 386 | ftdi_elan_kick_command_queue(ftdi); |
384 | } else { | 387 | } else { |
385 | mutex_unlock(&ftdi->u132_lock); | 388 | mutex_unlock(&ftdi->u132_lock); |
386 | msleep(100); | 389 | msleep(100); |
387 | mutex_lock(&ftdi->u132_lock); | 390 | mutex_lock(&ftdi->u132_lock); |
388 | goto wait_1; | 391 | goto wait_1; |
389 | } | 392 | } |
390 | } | 393 | } |
391 | wait_2:if (target->active == 1) { | 394 | wait_2:if (target->active == 1) { |
392 | int command_size = ftdi->command_next - | 395 | int command_size = ftdi->command_next - |
393 | ftdi->command_head; | 396 | ftdi->command_head; |
394 | if (command_size < COMMAND_SIZE) { | 397 | if (command_size < COMMAND_SIZE) { |
395 | struct u132_command *command = &ftdi->command[ | 398 | struct u132_command *command = &ftdi->command[ |
396 | COMMAND_MASK & ftdi->command_next]; | 399 | COMMAND_MASK & ftdi->command_next]; |
397 | command->header = 0x90 | (ed_number << 5); | 400 | command->header = 0x90 | (ed_number << 5); |
398 | command->length = 0x00; | 401 | command->length = 0x00; |
399 | command->address = 0x00; | 402 | command->address = 0x00; |
400 | command->width = 0x00; | 403 | command->width = 0x00; |
401 | command->follows = 0; | 404 | command->follows = 0; |
402 | command->value = 0; | 405 | command->value = 0; |
403 | command->buffer = &command->value; | 406 | command->buffer = &command->value; |
404 | ftdi->command_next += 1; | 407 | ftdi->command_next += 1; |
405 | ftdi_elan_kick_command_queue(ftdi); | 408 | ftdi_elan_kick_command_queue(ftdi); |
406 | } else { | 409 | } else { |
407 | mutex_unlock(&ftdi->u132_lock); | 410 | mutex_unlock(&ftdi->u132_lock); |
408 | msleep(100); | 411 | msleep(100); |
409 | mutex_lock(&ftdi->u132_lock); | 412 | mutex_lock(&ftdi->u132_lock); |
410 | goto wait_2; | 413 | goto wait_2; |
411 | } | 414 | } |
412 | } | 415 | } |
413 | } | 416 | } |
414 | ftdi->received = 0; | 417 | ftdi->received = 0; |
415 | ftdi->expected = 4; | 418 | ftdi->expected = 4; |
416 | ftdi->ed_found = 0; | 419 | ftdi->ed_found = 0; |
417 | mutex_unlock(&ftdi->u132_lock); | 420 | mutex_unlock(&ftdi->u132_lock); |
418 | } | 421 | } |
419 | 422 | ||
420 | static void ftdi_elan_cancel_targets(struct usb_ftdi *ftdi) | 423 | static void ftdi_elan_cancel_targets(struct usb_ftdi *ftdi) |
421 | { | 424 | { |
422 | int ed_number = 4; | 425 | int ed_number = 4; |
423 | mutex_lock(&ftdi->u132_lock); | 426 | mutex_lock(&ftdi->u132_lock); |
424 | while (ed_number-- > 0) { | 427 | while (ed_number-- > 0) { |
425 | struct u132_target *target = &ftdi->target[ed_number]; | 428 | struct u132_target *target = &ftdi->target[ed_number]; |
426 | target->abandoning = 1; | 429 | target->abandoning = 1; |
427 | wait:if (target->active == 1) { | 430 | wait:if (target->active == 1) { |
428 | int command_size = ftdi->command_next - | 431 | int command_size = ftdi->command_next - |
429 | ftdi->command_head; | 432 | ftdi->command_head; |
430 | if (command_size < COMMAND_SIZE) { | 433 | if (command_size < COMMAND_SIZE) { |
431 | struct u132_command *command = &ftdi->command[ | 434 | struct u132_command *command = &ftdi->command[ |
432 | COMMAND_MASK & ftdi->command_next]; | 435 | COMMAND_MASK & ftdi->command_next]; |
433 | command->header = 0x80 | (ed_number << 5) | 0x4; | 436 | command->header = 0x80 | (ed_number << 5) | 0x4; |
434 | command->length = 0x00; | 437 | command->length = 0x00; |
435 | command->address = 0x00; | 438 | command->address = 0x00; |
436 | command->width = 0x00; | 439 | command->width = 0x00; |
437 | command->follows = 0; | 440 | command->follows = 0; |
438 | command->value = 0; | 441 | command->value = 0; |
439 | command->buffer = &command->value; | 442 | command->buffer = &command->value; |
440 | ftdi->command_next += 1; | 443 | ftdi->command_next += 1; |
441 | ftdi_elan_kick_command_queue(ftdi); | 444 | ftdi_elan_kick_command_queue(ftdi); |
442 | } else { | 445 | } else { |
443 | mutex_unlock(&ftdi->u132_lock); | 446 | mutex_unlock(&ftdi->u132_lock); |
444 | msleep(100); | 447 | msleep(100); |
445 | mutex_lock(&ftdi->u132_lock); | 448 | mutex_lock(&ftdi->u132_lock); |
446 | goto wait; | 449 | goto wait; |
447 | } | 450 | } |
448 | } | 451 | } |
449 | } | 452 | } |
450 | ftdi->received = 0; | 453 | ftdi->received = 0; |
451 | ftdi->expected = 4; | 454 | ftdi->expected = 4; |
452 | ftdi->ed_found = 0; | 455 | ftdi->ed_found = 0; |
453 | mutex_unlock(&ftdi->u132_lock); | 456 | mutex_unlock(&ftdi->u132_lock); |
454 | } | 457 | } |
455 | 458 | ||
456 | static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi) | 459 | static void ftdi_elan_kick_command_queue(struct usb_ftdi *ftdi) |
457 | { | 460 | { |
458 | ftdi_command_queue_work(ftdi, 0); | 461 | ftdi_command_queue_work(ftdi, 0); |
459 | } | 462 | } |
460 | 463 | ||
461 | static void ftdi_elan_command_work(struct work_struct *work) | 464 | static void ftdi_elan_command_work(struct work_struct *work) |
462 | { | 465 | { |
463 | struct usb_ftdi *ftdi = | 466 | struct usb_ftdi *ftdi = |
464 | container_of(work, struct usb_ftdi, command_work.work); | 467 | container_of(work, struct usb_ftdi, command_work.work); |
465 | 468 | ||
466 | if (ftdi->disconnected > 0) { | 469 | if (ftdi->disconnected > 0) { |
467 | ftdi_elan_put_kref(ftdi); | 470 | ftdi_elan_put_kref(ftdi); |
468 | return; | 471 | return; |
469 | } else { | 472 | } else { |
470 | int retval = ftdi_elan_command_engine(ftdi); | 473 | int retval = ftdi_elan_command_engine(ftdi); |
471 | if (retval == -ESHUTDOWN) { | 474 | if (retval == -ESHUTDOWN) { |
472 | ftdi->disconnected += 1; | 475 | ftdi->disconnected += 1; |
473 | } else if (retval == -ENODEV) { | 476 | } else if (retval == -ENODEV) { |
474 | ftdi->disconnected += 1; | 477 | ftdi->disconnected += 1; |
475 | } else if (retval) | 478 | } else if (retval) |
476 | dev_err(&ftdi->udev->dev, "command error %d\n", retval); | 479 | dev_err(&ftdi->udev->dev, "command error %d\n", retval); |
477 | ftdi_command_requeue_work(ftdi, msecs_to_jiffies(10)); | 480 | ftdi_command_requeue_work(ftdi, msecs_to_jiffies(10)); |
478 | return; | 481 | return; |
479 | } | 482 | } |
480 | } | 483 | } |
481 | 484 | ||
482 | static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi) | 485 | static void ftdi_elan_kick_respond_queue(struct usb_ftdi *ftdi) |
483 | { | 486 | { |
484 | ftdi_respond_queue_work(ftdi, 0); | 487 | ftdi_respond_queue_work(ftdi, 0); |
485 | } | 488 | } |
486 | 489 | ||
487 | static void ftdi_elan_respond_work(struct work_struct *work) | 490 | static void ftdi_elan_respond_work(struct work_struct *work) |
488 | { | 491 | { |
489 | struct usb_ftdi *ftdi = | 492 | struct usb_ftdi *ftdi = |
490 | container_of(work, struct usb_ftdi, respond_work.work); | 493 | container_of(work, struct usb_ftdi, respond_work.work); |
491 | if (ftdi->disconnected > 0) { | 494 | if (ftdi->disconnected > 0) { |
492 | ftdi_elan_put_kref(ftdi); | 495 | ftdi_elan_put_kref(ftdi); |
493 | return; | 496 | return; |
494 | } else { | 497 | } else { |
495 | int retval = ftdi_elan_respond_engine(ftdi); | 498 | int retval = ftdi_elan_respond_engine(ftdi); |
496 | if (retval == 0) { | 499 | if (retval == 0) { |
497 | } else if (retval == -ESHUTDOWN) { | 500 | } else if (retval == -ESHUTDOWN) { |
498 | ftdi->disconnected += 1; | 501 | ftdi->disconnected += 1; |
499 | } else if (retval == -ENODEV) { | 502 | } else if (retval == -ENODEV) { |
500 | ftdi->disconnected += 1; | 503 | ftdi->disconnected += 1; |
501 | } else if (retval == -EILSEQ) { | 504 | } else if (retval == -EILSEQ) { |
502 | ftdi->disconnected += 1; | 505 | ftdi->disconnected += 1; |
503 | } else { | 506 | } else { |
504 | ftdi->disconnected += 1; | 507 | ftdi->disconnected += 1; |
505 | dev_err(&ftdi->udev->dev, "respond error %d\n", retval); | 508 | dev_err(&ftdi->udev->dev, "respond error %d\n", retval); |
506 | } | 509 | } |
507 | if (ftdi->disconnected > 0) { | 510 | if (ftdi->disconnected > 0) { |
508 | ftdi_elan_abandon_completions(ftdi); | 511 | ftdi_elan_abandon_completions(ftdi); |
509 | ftdi_elan_abandon_targets(ftdi); | 512 | ftdi_elan_abandon_targets(ftdi); |
510 | } | 513 | } |
511 | ftdi_response_requeue_work(ftdi, msecs_to_jiffies(10)); | 514 | ftdi_response_requeue_work(ftdi, msecs_to_jiffies(10)); |
512 | return; | 515 | return; |
513 | } | 516 | } |
514 | } | 517 | } |
515 | 518 | ||
516 | 519 | ||
517 | /* | 520 | /* |
518 | * the sw_lock is initially held and will be freed | 521 | * the sw_lock is initially held and will be freed |
519 | * after the FTDI has been synchronized | 522 | * after the FTDI has been synchronized |
520 | * | 523 | * |
521 | */ | 524 | */ |
522 | static void ftdi_elan_status_work(struct work_struct *work) | 525 | static void ftdi_elan_status_work(struct work_struct *work) |
523 | { | 526 | { |
524 | struct usb_ftdi *ftdi = | 527 | struct usb_ftdi *ftdi = |
525 | container_of(work, struct usb_ftdi, status_work.work); | 528 | container_of(work, struct usb_ftdi, status_work.work); |
526 | int work_delay_in_msec = 0; | 529 | int work_delay_in_msec = 0; |
527 | if (ftdi->disconnected > 0) { | 530 | if (ftdi->disconnected > 0) { |
528 | ftdi_elan_put_kref(ftdi); | 531 | ftdi_elan_put_kref(ftdi); |
529 | return; | 532 | return; |
530 | } else if (ftdi->synchronized == 0) { | 533 | } else if (ftdi->synchronized == 0) { |
531 | down(&ftdi->sw_lock); | 534 | down(&ftdi->sw_lock); |
532 | if (ftdi_elan_synchronize(ftdi) == 0) { | 535 | if (ftdi_elan_synchronize(ftdi) == 0) { |
533 | ftdi->synchronized = 1; | 536 | ftdi->synchronized = 1; |
534 | ftdi_command_queue_work(ftdi, 1); | 537 | ftdi_command_queue_work(ftdi, 1); |
535 | ftdi_respond_queue_work(ftdi, 1); | 538 | ftdi_respond_queue_work(ftdi, 1); |
536 | up(&ftdi->sw_lock); | 539 | up(&ftdi->sw_lock); |
537 | work_delay_in_msec = 100; | 540 | work_delay_in_msec = 100; |
538 | } else { | 541 | } else { |
539 | dev_err(&ftdi->udev->dev, "synchronize failed\n"); | 542 | dev_err(&ftdi->udev->dev, "synchronize failed\n"); |
540 | up(&ftdi->sw_lock); | 543 | up(&ftdi->sw_lock); |
541 | work_delay_in_msec = 10 *1000; | 544 | work_delay_in_msec = 10 *1000; |
542 | } | 545 | } |
543 | } else if (ftdi->stuck_status > 0) { | 546 | } else if (ftdi->stuck_status > 0) { |
544 | if (ftdi_elan_stuck_waiting(ftdi) == 0) { | 547 | if (ftdi_elan_stuck_waiting(ftdi) == 0) { |
545 | ftdi->stuck_status = 0; | 548 | ftdi->stuck_status = 0; |
546 | ftdi->synchronized = 0; | 549 | ftdi->synchronized = 0; |
547 | } else if ((ftdi->stuck_status++ % 60) == 1) { | 550 | } else if ((ftdi->stuck_status++ % 60) == 1) { |
548 | dev_err(&ftdi->udev->dev, "WRONG type of card inserted " | 551 | dev_err(&ftdi->udev->dev, "WRONG type of card inserted - please remove\n"); |
549 | "- please remove\n"); | 552 | } else |
550 | } else | 553 | dev_err(&ftdi->udev->dev, "WRONG type of card inserted - checked %d times\n", |
551 | dev_err(&ftdi->udev->dev, "WRONG type of card inserted " | 554 | ftdi->stuck_status); |
552 | "- checked %d times\n", ftdi->stuck_status); | 555 | work_delay_in_msec = 100; |
553 | work_delay_in_msec = 100; | 556 | } else if (ftdi->enumerated == 0) { |
554 | } else if (ftdi->enumerated == 0) { | 557 | if (ftdi_elan_enumeratePCI(ftdi) == 0) { |
555 | if (ftdi_elan_enumeratePCI(ftdi) == 0) { | 558 | ftdi->enumerated = 1; |
556 | ftdi->enumerated = 1; | 559 | work_delay_in_msec = 250; |
557 | work_delay_in_msec = 250; | 560 | } else |
558 | } else | 561 | work_delay_in_msec = 1000; |
559 | work_delay_in_msec = 1000; | 562 | } else if (ftdi->initialized == 0) { |
560 | } else if (ftdi->initialized == 0) { | 563 | if (ftdi_elan_setupOHCI(ftdi) == 0) { |
561 | if (ftdi_elan_setupOHCI(ftdi) == 0) { | 564 | ftdi->initialized = 1; |
562 | ftdi->initialized = 1; | 565 | work_delay_in_msec = 500; |
563 | work_delay_in_msec = 500; | 566 | } else { |
564 | } else { | 567 | dev_err(&ftdi->udev->dev, "initialized failed - trying again in 10 seconds\n"); |
565 | dev_err(&ftdi->udev->dev, "initialized failed - trying " | 568 | work_delay_in_msec = 1 *1000; |
566 | "again in 10 seconds\n"); | 569 | } |
567 | work_delay_in_msec = 1 *1000; | 570 | } else if (ftdi->registered == 0) { |
568 | } | 571 | work_delay_in_msec = 10; |
569 | } else if (ftdi->registered == 0) { | 572 | if (ftdi_elan_hcd_init(ftdi) == 0) { |
570 | work_delay_in_msec = 10; | 573 | ftdi->registered = 1; |
571 | if (ftdi_elan_hcd_init(ftdi) == 0) { | 574 | } else |
572 | ftdi->registered = 1; | 575 | dev_err(&ftdi->udev->dev, "register failed\n"); |
573 | } else | 576 | work_delay_in_msec = 250; |
574 | dev_err(&ftdi->udev->dev, "register failed\n"); | 577 | } else { |
575 | work_delay_in_msec = 250; | 578 | if (ftdi_elan_checkingPCI(ftdi) == 0) { |
576 | } else { | 579 | work_delay_in_msec = 250; |
577 | if (ftdi_elan_checkingPCI(ftdi) == 0) { | 580 | } else if (ftdi->controlreg & 0x00400000) { |
578 | work_delay_in_msec = 250; | 581 | if (ftdi->gone_away > 0) { |
579 | } else if (ftdi->controlreg & 0x00400000) { | 582 | dev_err(&ftdi->udev->dev, "PCI device eject confirmed platform_dev.dev.parent=%p platform_dev.dev=%p\n", |
580 | if (ftdi->gone_away > 0) { | 583 | ftdi->platform_dev.dev.parent, |
581 | dev_err(&ftdi->udev->dev, "PCI device eject con" | 584 | &ftdi->platform_dev.dev); |
582 | "firmed platform_dev.dev.parent=%p plat" | 585 | platform_device_unregister(&ftdi->platform_dev); |
583 | "form_dev.dev=%p\n", | 586 | ftdi->platform_dev.dev.parent = NULL; |
584 | ftdi->platform_dev.dev.parent, | 587 | ftdi->registered = 0; |
585 | &ftdi->platform_dev.dev); | 588 | ftdi->enumerated = 0; |
586 | platform_device_unregister(&ftdi->platform_dev); | 589 | ftdi->card_ejected = 0; |
587 | ftdi->platform_dev.dev.parent = NULL; | 590 | ftdi->initialized = 0; |
588 | ftdi->registered = 0; | 591 | ftdi->gone_away = 0; |
589 | ftdi->enumerated = 0; | 592 | } else |
590 | ftdi->card_ejected = 0; | 593 | ftdi_elan_flush_targets(ftdi); |
591 | ftdi->initialized = 0; | 594 | work_delay_in_msec = 250; |
592 | ftdi->gone_away = 0; | 595 | } else { |
593 | } else | 596 | dev_err(&ftdi->udev->dev, "PCI device has disappeared\n"); |
594 | ftdi_elan_flush_targets(ftdi); | 597 | ftdi_elan_cancel_targets(ftdi); |
595 | work_delay_in_msec = 250; | 598 | work_delay_in_msec = 500; |
596 | } else { | 599 | ftdi->enumerated = 0; |
597 | dev_err(&ftdi->udev->dev, "PCI device has disappeared\n" | 600 | ftdi->initialized = 0; |
598 | ); | 601 | } |
599 | ftdi_elan_cancel_targets(ftdi); | 602 | } |
600 | work_delay_in_msec = 500; | 603 | if (ftdi->disconnected > 0) { |
601 | ftdi->enumerated = 0; | 604 | ftdi_elan_put_kref(ftdi); |
602 | ftdi->initialized = 0; | 605 | return; |
603 | } | 606 | } else { |
604 | } | 607 | ftdi_status_requeue_work(ftdi, |
605 | if (ftdi->disconnected > 0) { | 608 | msecs_to_jiffies(work_delay_in_msec)); |
606 | ftdi_elan_put_kref(ftdi); | 609 | return; |
607 | return; | 610 | } |
608 | } else { | ||
609 | ftdi_status_requeue_work(ftdi, | ||
610 | msecs_to_jiffies(work_delay_in_msec)); | ||
611 | return; | ||
612 | } | ||
613 | } | 611 | } |
614 | 612 | ||
615 | 613 | ||
616 | /* | 614 | /* |
617 | * file_operations for the jtag interface | 615 | * file_operations for the jtag interface |
618 | * | 616 | * |
619 | * the usage count for the device is incremented on open() | 617 | * the usage count for the device is incremented on open() |
620 | * and decremented on release() | 618 | * and decremented on release() |
621 | */ | 619 | */ |
622 | static int ftdi_elan_open(struct inode *inode, struct file *file) | 620 | static int ftdi_elan_open(struct inode *inode, struct file *file) |
623 | { | 621 | { |
624 | int subminor; | 622 | int subminor; |
625 | struct usb_interface *interface; | 623 | struct usb_interface *interface; |
626 | 624 | ||
627 | subminor = iminor(inode); | 625 | subminor = iminor(inode); |
628 | interface = usb_find_interface(&ftdi_elan_driver, subminor); | 626 | interface = usb_find_interface(&ftdi_elan_driver, subminor); |
629 | 627 | ||
630 | if (!interface) { | 628 | if (!interface) { |
631 | printk(KERN_ERR "can't find device for minor %d\n", subminor); | 629 | pr_err("can't find device for minor %d\n", subminor); |
632 | return -ENODEV; | 630 | return -ENODEV; |
633 | } else { | 631 | } else { |
634 | struct usb_ftdi *ftdi = usb_get_intfdata(interface); | 632 | struct usb_ftdi *ftdi = usb_get_intfdata(interface); |
635 | if (!ftdi) { | 633 | if (!ftdi) { |
636 | return -ENODEV; | 634 | return -ENODEV; |
637 | } else { | 635 | } else { |
638 | if (down_interruptible(&ftdi->sw_lock)) { | 636 | if (down_interruptible(&ftdi->sw_lock)) { |
639 | return -EINTR; | 637 | return -EINTR; |
640 | } else { | 638 | } else { |
641 | ftdi_elan_get_kref(ftdi); | 639 | ftdi_elan_get_kref(ftdi); |
642 | file->private_data = ftdi; | 640 | file->private_data = ftdi; |
643 | return 0; | 641 | return 0; |
644 | } | 642 | } |
645 | } | 643 | } |
646 | } | 644 | } |
647 | } | 645 | } |
648 | 646 | ||
649 | static int ftdi_elan_release(struct inode *inode, struct file *file) | 647 | static int ftdi_elan_release(struct inode *inode, struct file *file) |
650 | { | 648 | { |
651 | struct usb_ftdi *ftdi = file->private_data; | 649 | struct usb_ftdi *ftdi = file->private_data; |
652 | if (ftdi == NULL) | 650 | if (ftdi == NULL) |
653 | return -ENODEV; | 651 | return -ENODEV; |
654 | up(&ftdi->sw_lock); /* decrement the count on our device */ | 652 | up(&ftdi->sw_lock); /* decrement the count on our device */ |
655 | ftdi_elan_put_kref(ftdi); | 653 | ftdi_elan_put_kref(ftdi); |
656 | return 0; | 654 | return 0; |
657 | } | 655 | } |
658 | 656 | ||
659 | 657 | ||
660 | /* | 658 | /* |
661 | * | 659 | * |
662 | * blocking bulk reads are used to get data from the device | 660 | * blocking bulk reads are used to get data from the device |
663 | * | 661 | * |
664 | */ | 662 | */ |
665 | static ssize_t ftdi_elan_read(struct file *file, char __user *buffer, | 663 | static ssize_t ftdi_elan_read(struct file *file, char __user *buffer, |
666 | size_t count, loff_t *ppos) | 664 | size_t count, loff_t *ppos) |
667 | { | 665 | { |
668 | char data[30 *3 + 4]; | 666 | char data[30 *3 + 4]; |
669 | char *d = data; | 667 | char *d = data; |
670 | int m = (sizeof(data) - 1) / 3; | 668 | int m = (sizeof(data) - 1) / 3; |
671 | int bytes_read = 0; | 669 | int bytes_read = 0; |
672 | int retry_on_empty = 10; | 670 | int retry_on_empty = 10; |
673 | int retry_on_timeout = 5; | 671 | int retry_on_timeout = 5; |
674 | struct usb_ftdi *ftdi = file->private_data; | 672 | struct usb_ftdi *ftdi = file->private_data; |
675 | if (ftdi->disconnected > 0) { | 673 | if (ftdi->disconnected > 0) { |
676 | return -ENODEV; | 674 | return -ENODEV; |
677 | } | 675 | } |
678 | data[0] = 0; | 676 | data[0] = 0; |
679 | have:if (ftdi->bulk_in_left > 0) { | 677 | have:if (ftdi->bulk_in_left > 0) { |
680 | if (count-- > 0) { | 678 | if (count-- > 0) { |
681 | char *p = ++ftdi->bulk_in_last + ftdi->bulk_in_buffer; | 679 | char *p = ++ftdi->bulk_in_last + ftdi->bulk_in_buffer; |
682 | ftdi->bulk_in_left -= 1; | 680 | ftdi->bulk_in_left -= 1; |
683 | if (bytes_read < m) { | 681 | if (bytes_read < m) { |
684 | d += sprintf(d, " %02X", 0x000000FF & *p); | 682 | d += sprintf(d, " %02X", 0x000000FF & *p); |
685 | } else if (bytes_read > m) { | 683 | } else if (bytes_read > m) { |
686 | } else | 684 | } else |
687 | d += sprintf(d, " .."); | 685 | d += sprintf(d, " .."); |
688 | if (copy_to_user(buffer++, p, 1)) { | 686 | if (copy_to_user(buffer++, p, 1)) { |
689 | return -EFAULT; | 687 | return -EFAULT; |
690 | } else { | 688 | } else { |
691 | bytes_read += 1; | 689 | bytes_read += 1; |
692 | goto have; | 690 | goto have; |
693 | } | 691 | } |
694 | } else | 692 | } else |
695 | return bytes_read; | 693 | return bytes_read; |
696 | } | 694 | } |
697 | more:if (count > 0) { | 695 | more:if (count > 0) { |
698 | int packet_bytes = 0; | 696 | int packet_bytes = 0; |
699 | int retval = usb_bulk_msg(ftdi->udev, | 697 | int retval = usb_bulk_msg(ftdi->udev, |
700 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), | 698 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), |
701 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, | 699 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, |
702 | &packet_bytes, 50); | 700 | &packet_bytes, 50); |
703 | if (packet_bytes > 2) { | 701 | if (packet_bytes > 2) { |
704 | ftdi->bulk_in_left = packet_bytes - 2; | 702 | ftdi->bulk_in_left = packet_bytes - 2; |
705 | ftdi->bulk_in_last = 1; | 703 | ftdi->bulk_in_last = 1; |
706 | goto have; | 704 | goto have; |
707 | } else if (retval == -ETIMEDOUT) { | 705 | } else if (retval == -ETIMEDOUT) { |
708 | if (retry_on_timeout-- > 0) { | 706 | if (retry_on_timeout-- > 0) { |
709 | goto more; | 707 | goto more; |
710 | } else if (bytes_read > 0) { | 708 | } else if (bytes_read > 0) { |
711 | return bytes_read; | 709 | return bytes_read; |
712 | } else | 710 | } else |
713 | return retval; | 711 | return retval; |
714 | } else if (retval == 0) { | 712 | } else if (retval == 0) { |
715 | if (retry_on_empty-- > 0) { | 713 | if (retry_on_empty-- > 0) { |
716 | goto more; | 714 | goto more; |
717 | } else | 715 | } else |
718 | return bytes_read; | 716 | return bytes_read; |
719 | } else | 717 | } else |
720 | return retval; | 718 | return retval; |
721 | } else | 719 | } else |
722 | return bytes_read; | 720 | return bytes_read; |
723 | } | 721 | } |
724 | 722 | ||
725 | static void ftdi_elan_write_bulk_callback(struct urb *urb) | 723 | static void ftdi_elan_write_bulk_callback(struct urb *urb) |
@@ -728,467 +726,460 @@ static void ftdi_elan_write_bulk_callback(struct urb *urb) | |||
728 | int status = urb->status; | 726 | int status = urb->status; |
729 | 727 | ||
730 | if (status && !(status == -ENOENT || status == -ECONNRESET || | 728 | if (status && !(status == -ENOENT || status == -ECONNRESET || |
731 | status == -ESHUTDOWN)) { | 729 | status == -ESHUTDOWN)) { |
732 | dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %" | 730 | dev_err(&ftdi->udev->dev, |
733 | "d\n", urb, status); | 731 | "urb=%p write bulk status received: %d\n", urb, status); |
734 | } | 732 | } |
735 | usb_free_coherent(urb->dev, urb->transfer_buffer_length, | 733 | usb_free_coherent(urb->dev, urb->transfer_buffer_length, |
736 | urb->transfer_buffer, urb->transfer_dma); | 734 | urb->transfer_buffer, urb->transfer_dma); |
737 | } | 735 | } |
738 | 736 | ||
739 | static int fill_buffer_with_all_queued_commands(struct usb_ftdi *ftdi, | 737 | static int fill_buffer_with_all_queued_commands(struct usb_ftdi *ftdi, |
740 | char *buf, int command_size, int total_size) | 738 | char *buf, int command_size, int total_size) |
741 | { | 739 | { |
742 | int ed_commands = 0; | 740 | int ed_commands = 0; |
743 | int b = 0; | 741 | int b = 0; |
744 | int I = command_size; | 742 | int I = command_size; |
745 | int i = ftdi->command_head; | 743 | int i = ftdi->command_head; |
746 | while (I-- > 0) { | 744 | while (I-- > 0) { |
747 | struct u132_command *command = &ftdi->command[COMMAND_MASK & | 745 | struct u132_command *command = &ftdi->command[COMMAND_MASK & |
748 | i++]; | 746 | i++]; |
749 | int F = command->follows; | 747 | int F = command->follows; |
750 | u8 *f = command->buffer; | 748 | u8 *f = command->buffer; |
751 | if (command->header & 0x80) { | 749 | if (command->header & 0x80) { |
752 | ed_commands |= 1 << (0x3 & (command->header >> 5)); | 750 | ed_commands |= 1 << (0x3 & (command->header >> 5)); |
753 | } | 751 | } |
754 | buf[b++] = command->header; | 752 | buf[b++] = command->header; |
755 | buf[b++] = (command->length >> 0) & 0x00FF; | 753 | buf[b++] = (command->length >> 0) & 0x00FF; |
756 | buf[b++] = (command->length >> 8) & 0x00FF; | 754 | buf[b++] = (command->length >> 8) & 0x00FF; |
757 | buf[b++] = command->address; | 755 | buf[b++] = command->address; |
758 | buf[b++] = command->width; | 756 | buf[b++] = command->width; |
759 | while (F-- > 0) { | 757 | while (F-- > 0) { |
760 | buf[b++] = *f++; | 758 | buf[b++] = *f++; |
761 | } | 759 | } |
762 | } | 760 | } |
763 | return ed_commands; | 761 | return ed_commands; |
764 | } | 762 | } |
765 | 763 | ||
766 | static int ftdi_elan_total_command_size(struct usb_ftdi *ftdi, int command_size) | 764 | static int ftdi_elan_total_command_size(struct usb_ftdi *ftdi, int command_size) |
767 | { | 765 | { |
768 | int total_size = 0; | 766 | int total_size = 0; |
769 | int I = command_size; | 767 | int I = command_size; |
770 | int i = ftdi->command_head; | 768 | int i = ftdi->command_head; |
771 | while (I-- > 0) { | 769 | while (I-- > 0) { |
772 | struct u132_command *command = &ftdi->command[COMMAND_MASK & | 770 | struct u132_command *command = &ftdi->command[COMMAND_MASK & |
773 | i++]; | 771 | i++]; |
774 | total_size += 5 + command->follows; | 772 | total_size += 5 + command->follows; |
775 | } return total_size; | 773 | } return total_size; |
776 | } | 774 | } |
777 | 775 | ||
778 | static int ftdi_elan_command_engine(struct usb_ftdi *ftdi) | 776 | static int ftdi_elan_command_engine(struct usb_ftdi *ftdi) |
779 | { | 777 | { |
780 | int retval; | 778 | int retval; |
781 | char *buf; | 779 | char *buf; |
782 | int ed_commands; | 780 | int ed_commands; |
783 | int total_size; | 781 | int total_size; |
784 | struct urb *urb; | 782 | struct urb *urb; |
785 | int command_size = ftdi->command_next - ftdi->command_head; | 783 | int command_size = ftdi->command_next - ftdi->command_head; |
786 | if (command_size == 0) | 784 | if (command_size == 0) |
787 | return 0; | 785 | return 0; |
788 | total_size = ftdi_elan_total_command_size(ftdi, command_size); | 786 | total_size = ftdi_elan_total_command_size(ftdi, command_size); |
789 | urb = usb_alloc_urb(0, GFP_KERNEL); | 787 | urb = usb_alloc_urb(0, GFP_KERNEL); |
790 | if (!urb) { | 788 | if (!urb) { |
791 | dev_err(&ftdi->udev->dev, "could not get a urb to write %d comm" | 789 | dev_err(&ftdi->udev->dev, "could not get a urb to write %d commands totaling %d bytes to the Uxxx\n", |
792 | "ands totaling %d bytes to the Uxxx\n", command_size, | 790 | command_size, total_size); |
793 | total_size); | 791 | return -ENOMEM; |
794 | return -ENOMEM; | 792 | } |
795 | } | 793 | buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL, |
796 | buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL, | 794 | &urb->transfer_dma); |
797 | &urb->transfer_dma); | 795 | if (!buf) { |
798 | if (!buf) { | 796 | dev_err(&ftdi->udev->dev, "could not get a buffer to write %d commands totaling %d bytes to the Uxxx\n", |
799 | dev_err(&ftdi->udev->dev, "could not get a buffer to write %d c" | 797 | command_size, total_size); |
800 | "ommands totaling %d bytes to the Uxxx\n", command_size, | 798 | usb_free_urb(urb); |
801 | total_size); | 799 | return -ENOMEM; |
802 | usb_free_urb(urb); | 800 | } |
803 | return -ENOMEM; | 801 | ed_commands = fill_buffer_with_all_queued_commands(ftdi, buf, |
804 | } | 802 | command_size, total_size); |
805 | ed_commands = fill_buffer_with_all_queued_commands(ftdi, buf, | 803 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, |
806 | command_size, total_size); | 804 | ftdi->bulk_out_endpointAddr), buf, total_size, |
807 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, | 805 | ftdi_elan_write_bulk_callback, ftdi); |
808 | ftdi->bulk_out_endpointAddr), buf, total_size, | 806 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
809 | ftdi_elan_write_bulk_callback, ftdi); | 807 | if (ed_commands) { |
810 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 808 | char diag[40 *3 + 4]; |
811 | if (ed_commands) { | 809 | char *d = diag; |
812 | char diag[40 *3 + 4]; | 810 | int m = total_size; |
813 | char *d = diag; | 811 | u8 *c = buf; |
814 | int m = total_size; | 812 | int s = (sizeof(diag) - 1) / 3; |
815 | u8 *c = buf; | 813 | diag[0] = 0; |
816 | int s = (sizeof(diag) - 1) / 3; | 814 | while (s-- > 0 && m-- > 0) { |
817 | diag[0] = 0; | 815 | if (s > 0 || m == 0) { |
818 | while (s-- > 0 && m-- > 0) { | 816 | d += sprintf(d, " %02X", *c++); |
819 | if (s > 0 || m == 0) { | 817 | } else |
820 | d += sprintf(d, " %02X", *c++); | 818 | d += sprintf(d, " .."); |
821 | } else | 819 | } |
822 | d += sprintf(d, " .."); | 820 | } |
823 | } | 821 | retval = usb_submit_urb(urb, GFP_KERNEL); |
824 | } | 822 | if (retval) { |
825 | retval = usb_submit_urb(urb, GFP_KERNEL); | 823 | dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write %d commands totaling %d bytes to the Uxxx\n", |
826 | if (retval) { | 824 | retval, urb, command_size, total_size); |
827 | dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write " | 825 | usb_free_coherent(ftdi->udev, total_size, buf, urb->transfer_dma); |
828 | "%d commands totaling %d bytes to the Uxxx\n", retval, | 826 | usb_free_urb(urb); |
829 | urb, command_size, total_size); | 827 | return retval; |
830 | usb_free_coherent(ftdi->udev, total_size, buf, urb->transfer_dma); | 828 | } |
831 | usb_free_urb(urb); | 829 | usb_free_urb(urb); /* release our reference to this urb, |
832 | return retval; | 830 | the USB core will eventually free it entirely */ |
833 | } | 831 | ftdi->command_head += command_size; |
834 | usb_free_urb(urb); /* release our reference to this urb, | 832 | ftdi_elan_kick_respond_queue(ftdi); |
835 | the USB core will eventually free it entirely */ | 833 | return 0; |
836 | ftdi->command_head += command_size; | ||
837 | ftdi_elan_kick_respond_queue(ftdi); | ||
838 | return 0; | ||
839 | } | 834 | } |
840 | 835 | ||
841 | static void ftdi_elan_do_callback(struct usb_ftdi *ftdi, | 836 | static void ftdi_elan_do_callback(struct usb_ftdi *ftdi, |
842 | struct u132_target *target, u8 *buffer, int length) | 837 | struct u132_target *target, u8 *buffer, int length) |
843 | { | 838 | { |
844 | struct urb *urb = target->urb; | 839 | struct urb *urb = target->urb; |
845 | int halted = target->halted; | 840 | int halted = target->halted; |
846 | int skipped = target->skipped; | 841 | int skipped = target->skipped; |
847 | int actual = target->actual; | 842 | int actual = target->actual; |
848 | int non_null = target->non_null; | 843 | int non_null = target->non_null; |
849 | int toggle_bits = target->toggle_bits; | 844 | int toggle_bits = target->toggle_bits; |
850 | int error_count = target->error_count; | 845 | int error_count = target->error_count; |
851 | int condition_code = target->condition_code; | 846 | int condition_code = target->condition_code; |
852 | int repeat_number = target->repeat_number; | 847 | int repeat_number = target->repeat_number; |
853 | void (*callback) (void *, struct urb *, u8 *, int, int, int, int, int, | 848 | void (*callback) (void *, struct urb *, u8 *, int, int, int, int, int, |
854 | int, int, int, int) = target->callback; | 849 | int, int, int, int) = target->callback; |
855 | target->active -= 1; | 850 | target->active -= 1; |
856 | target->callback = NULL; | 851 | target->callback = NULL; |
857 | (*callback) (target->endp, urb, buffer, length, toggle_bits, | 852 | (*callback) (target->endp, urb, buffer, length, toggle_bits, |
858 | error_count, condition_code, repeat_number, halted, skipped, | 853 | error_count, condition_code, repeat_number, halted, skipped, |
859 | actual, non_null); | 854 | actual, non_null); |
860 | } | 855 | } |
861 | 856 | ||
862 | static char *have_ed_set_response(struct usb_ftdi *ftdi, | 857 | static char *have_ed_set_response(struct usb_ftdi *ftdi, |
863 | struct u132_target *target, u16 ed_length, int ed_number, int ed_type, | 858 | struct u132_target *target, u16 ed_length, int ed_number, int ed_type, |
864 | char *b) | 859 | char *b) |
865 | { | 860 | { |
866 | int payload = (ed_length >> 0) & 0x07FF; | 861 | int payload = (ed_length >> 0) & 0x07FF; |
867 | mutex_lock(&ftdi->u132_lock); | 862 | mutex_lock(&ftdi->u132_lock); |
868 | target->actual = 0; | 863 | target->actual = 0; |
869 | target->non_null = (ed_length >> 15) & 0x0001; | 864 | target->non_null = (ed_length >> 15) & 0x0001; |
870 | target->repeat_number = (ed_length >> 11) & 0x000F; | 865 | target->repeat_number = (ed_length >> 11) & 0x000F; |
871 | if (ed_type == 0x02) { | 866 | if (ed_type == 0x02) { |
872 | if (payload == 0 || target->abandoning > 0) { | 867 | if (payload == 0 || target->abandoning > 0) { |
873 | target->abandoning = 0; | 868 | target->abandoning = 0; |
874 | mutex_unlock(&ftdi->u132_lock); | 869 | mutex_unlock(&ftdi->u132_lock); |
875 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, | 870 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, |
876 | payload); | 871 | payload); |
877 | ftdi->received = 0; | 872 | ftdi->received = 0; |
878 | ftdi->expected = 4; | 873 | ftdi->expected = 4; |
879 | ftdi->ed_found = 0; | 874 | ftdi->ed_found = 0; |
880 | return ftdi->response; | 875 | return ftdi->response; |
881 | } else { | 876 | } else { |
882 | ftdi->expected = 4 + payload; | 877 | ftdi->expected = 4 + payload; |
883 | ftdi->ed_found = 1; | 878 | ftdi->ed_found = 1; |
884 | mutex_unlock(&ftdi->u132_lock); | 879 | mutex_unlock(&ftdi->u132_lock); |
885 | return b; | 880 | return b; |
886 | } | 881 | } |
887 | } else if (ed_type == 0x03) { | 882 | } else if (ed_type == 0x03) { |
888 | if (payload == 0 || target->abandoning > 0) { | 883 | if (payload == 0 || target->abandoning > 0) { |
889 | target->abandoning = 0; | 884 | target->abandoning = 0; |
890 | mutex_unlock(&ftdi->u132_lock); | 885 | mutex_unlock(&ftdi->u132_lock); |
891 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, | 886 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, |
892 | payload); | 887 | payload); |
893 | ftdi->received = 0; | 888 | ftdi->received = 0; |
894 | ftdi->expected = 4; | 889 | ftdi->expected = 4; |
895 | ftdi->ed_found = 0; | 890 | ftdi->ed_found = 0; |
896 | return ftdi->response; | 891 | return ftdi->response; |
897 | } else { | 892 | } else { |
898 | ftdi->expected = 4 + payload; | 893 | ftdi->expected = 4 + payload; |
899 | ftdi->ed_found = 1; | 894 | ftdi->ed_found = 1; |
900 | mutex_unlock(&ftdi->u132_lock); | 895 | mutex_unlock(&ftdi->u132_lock); |
901 | return b; | 896 | return b; |
902 | } | 897 | } |
903 | } else if (ed_type == 0x01) { | 898 | } else if (ed_type == 0x01) { |
904 | target->abandoning = 0; | 899 | target->abandoning = 0; |
905 | mutex_unlock(&ftdi->u132_lock); | 900 | mutex_unlock(&ftdi->u132_lock); |
906 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, | 901 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, |
907 | payload); | 902 | payload); |
908 | ftdi->received = 0; | 903 | ftdi->received = 0; |
909 | ftdi->expected = 4; | 904 | ftdi->expected = 4; |
910 | ftdi->ed_found = 0; | 905 | ftdi->ed_found = 0; |
911 | return ftdi->response; | 906 | return ftdi->response; |
912 | } else { | 907 | } else { |
913 | target->abandoning = 0; | 908 | target->abandoning = 0; |
914 | mutex_unlock(&ftdi->u132_lock); | 909 | mutex_unlock(&ftdi->u132_lock); |
915 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, | 910 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, |
916 | payload); | 911 | payload); |
917 | ftdi->received = 0; | 912 | ftdi->received = 0; |
918 | ftdi->expected = 4; | 913 | ftdi->expected = 4; |
919 | ftdi->ed_found = 0; | 914 | ftdi->ed_found = 0; |
920 | return ftdi->response; | 915 | return ftdi->response; |
921 | } | 916 | } |
922 | } | 917 | } |
923 | 918 | ||
924 | static char *have_ed_get_response(struct usb_ftdi *ftdi, | 919 | static char *have_ed_get_response(struct usb_ftdi *ftdi, |
925 | struct u132_target *target, u16 ed_length, int ed_number, int ed_type, | 920 | struct u132_target *target, u16 ed_length, int ed_number, int ed_type, |
926 | char *b) | 921 | char *b) |
927 | { | 922 | { |
928 | mutex_lock(&ftdi->u132_lock); | 923 | mutex_lock(&ftdi->u132_lock); |
929 | target->condition_code = TD_DEVNOTRESP; | 924 | target->condition_code = TD_DEVNOTRESP; |
930 | target->actual = (ed_length >> 0) & 0x01FF; | 925 | target->actual = (ed_length >> 0) & 0x01FF; |
931 | target->non_null = (ed_length >> 15) & 0x0001; | 926 | target->non_null = (ed_length >> 15) & 0x0001; |
932 | target->repeat_number = (ed_length >> 11) & 0x000F; | 927 | target->repeat_number = (ed_length >> 11) & 0x000F; |
933 | mutex_unlock(&ftdi->u132_lock); | 928 | mutex_unlock(&ftdi->u132_lock); |
934 | if (target->active) | 929 | if (target->active) |
935 | ftdi_elan_do_callback(ftdi, target, NULL, 0); | 930 | ftdi_elan_do_callback(ftdi, target, NULL, 0); |
936 | target->abandoning = 0; | 931 | target->abandoning = 0; |
937 | ftdi->received = 0; | 932 | ftdi->received = 0; |
938 | ftdi->expected = 4; | 933 | ftdi->expected = 4; |
939 | ftdi->ed_found = 0; | 934 | ftdi->ed_found = 0; |
940 | return ftdi->response; | 935 | return ftdi->response; |
941 | } | 936 | } |
942 | 937 | ||
943 | 938 | ||
944 | /* | 939 | /* |
945 | * The engine tries to empty the FTDI fifo | 940 | * The engine tries to empty the FTDI fifo |
946 | * | 941 | * |
947 | * all responses found in the fifo data are dispatched thus | 942 | * all responses found in the fifo data are dispatched thus |
948 | * the response buffer can only ever hold a maximum sized | 943 | * the response buffer can only ever hold a maximum sized |
949 | * response from the Uxxx. | 944 | * response from the Uxxx. |
950 | * | 945 | * |
951 | */ | 946 | */ |
952 | static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi) | 947 | static int ftdi_elan_respond_engine(struct usb_ftdi *ftdi) |
953 | { | 948 | { |
954 | u8 *b = ftdi->response + ftdi->received; | 949 | u8 *b = ftdi->response + ftdi->received; |
955 | int bytes_read = 0; | 950 | int bytes_read = 0; |
956 | int retry_on_empty = 1; | 951 | int retry_on_empty = 1; |
957 | int retry_on_timeout = 3; | 952 | int retry_on_timeout = 3; |
958 | int empty_packets = 0; | 953 | int empty_packets = 0; |
959 | read:{ | 954 | read:{ |
960 | int packet_bytes = 0; | 955 | int packet_bytes = 0; |
961 | int retval = usb_bulk_msg(ftdi->udev, | 956 | int retval = usb_bulk_msg(ftdi->udev, |
962 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), | 957 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), |
963 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, | 958 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, |
964 | &packet_bytes, 500); | 959 | &packet_bytes, 500); |
965 | char diag[30 *3 + 4]; | 960 | char diag[30 *3 + 4]; |
966 | char *d = diag; | 961 | char *d = diag; |
967 | int m = packet_bytes; | 962 | int m = packet_bytes; |
968 | u8 *c = ftdi->bulk_in_buffer; | 963 | u8 *c = ftdi->bulk_in_buffer; |
969 | int s = (sizeof(diag) - 1) / 3; | 964 | int s = (sizeof(diag) - 1) / 3; |
970 | diag[0] = 0; | 965 | diag[0] = 0; |
971 | while (s-- > 0 && m-- > 0) { | 966 | while (s-- > 0 && m-- > 0) { |
972 | if (s > 0 || m == 0) { | 967 | if (s > 0 || m == 0) { |
973 | d += sprintf(d, " %02X", *c++); | 968 | d += sprintf(d, " %02X", *c++); |
974 | } else | 969 | } else |
975 | d += sprintf(d, " .."); | 970 | d += sprintf(d, " .."); |
976 | } | 971 | } |
977 | if (packet_bytes > 2) { | 972 | if (packet_bytes > 2) { |
978 | ftdi->bulk_in_left = packet_bytes - 2; | 973 | ftdi->bulk_in_left = packet_bytes - 2; |
979 | ftdi->bulk_in_last = 1; | 974 | ftdi->bulk_in_last = 1; |
980 | goto have; | 975 | goto have; |
981 | } else if (retval == -ETIMEDOUT) { | 976 | } else if (retval == -ETIMEDOUT) { |
982 | if (retry_on_timeout-- > 0) { | 977 | if (retry_on_timeout-- > 0) { |
983 | dev_err(&ftdi->udev->dev, "TIMED OUT with packe" | 978 | dev_err(&ftdi->udev->dev, "TIMED OUT with packet_bytes = %d with total %d bytes%s\n", |
984 | "t_bytes = %d with total %d bytes%s\n", | 979 | packet_bytes, bytes_read, diag); |
985 | packet_bytes, bytes_read, diag); | 980 | goto more; |
986 | goto more; | 981 | } else if (bytes_read > 0) { |
987 | } else if (bytes_read > 0) { | 982 | dev_err(&ftdi->udev->dev, "ONLY %d bytes%s\n", |
988 | dev_err(&ftdi->udev->dev, "ONLY %d bytes%s\n", | 983 | bytes_read, diag); |
989 | bytes_read, diag); | 984 | return -ENOMEM; |
990 | return -ENOMEM; | 985 | } else { |
991 | } else { | 986 | dev_err(&ftdi->udev->dev, "TIMED OUT with packet_bytes = %d with total %d bytes%s\n", |
992 | dev_err(&ftdi->udev->dev, "TIMED OUT with packe" | 987 | packet_bytes, bytes_read, diag); |
993 | "t_bytes = %d with total %d bytes%s\n", | 988 | return -ENOMEM; |
994 | packet_bytes, bytes_read, diag); | 989 | } |
995 | return -ENOMEM; | 990 | } else if (retval == -EILSEQ) { |
996 | } | 991 | dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n", |
997 | } else if (retval == -EILSEQ) { | 992 | retval, packet_bytes, bytes_read, diag); |
998 | dev_err(&ftdi->udev->dev, "error = %d with packet_bytes" | 993 | return retval; |
999 | " = %d with total %d bytes%s\n", retval, | 994 | } else if (retval) { |
1000 | packet_bytes, bytes_read, diag); | 995 | dev_err(&ftdi->udev->dev, "error = %d with packet_bytes = %d with total %d bytes%s\n", |
1001 | return retval; | 996 | retval, packet_bytes, bytes_read, diag); |
1002 | } else if (retval) { | 997 | return retval; |
1003 | dev_err(&ftdi->udev->dev, "error = %d with packet_bytes" | 998 | } else if (packet_bytes == 2) { |
1004 | " = %d with total %d bytes%s\n", retval, | 999 | unsigned char s0 = ftdi->bulk_in_buffer[0]; |
1005 | packet_bytes, bytes_read, diag); | 1000 | unsigned char s1 = ftdi->bulk_in_buffer[1]; |
1006 | return retval; | 1001 | empty_packets += 1; |
1007 | } else if (packet_bytes == 2) { | 1002 | if (s0 == 0x31 && s1 == 0x60) { |
1008 | unsigned char s0 = ftdi->bulk_in_buffer[0]; | 1003 | if (retry_on_empty-- > 0) { |
1009 | unsigned char s1 = ftdi->bulk_in_buffer[1]; | 1004 | goto more; |
1010 | empty_packets += 1; | 1005 | } else |
1011 | if (s0 == 0x31 && s1 == 0x60) { | 1006 | return 0; |
1012 | if (retry_on_empty-- > 0) { | 1007 | } else if (s0 == 0x31 && s1 == 0x00) { |
1013 | goto more; | 1008 | if (retry_on_empty-- > 0) { |
1014 | } else | 1009 | goto more; |
1015 | return 0; | 1010 | } else |
1016 | } else if (s0 == 0x31 && s1 == 0x00) { | 1011 | return 0; |
1017 | if (retry_on_empty-- > 0) { | 1012 | } else { |
1018 | goto more; | 1013 | if (retry_on_empty-- > 0) { |
1019 | } else | 1014 | goto more; |
1020 | return 0; | 1015 | } else |
1021 | } else { | 1016 | return 0; |
1022 | if (retry_on_empty-- > 0) { | 1017 | } |
1023 | goto more; | 1018 | } else if (packet_bytes == 1) { |
1024 | } else | 1019 | if (retry_on_empty-- > 0) { |
1025 | return 0; | 1020 | goto more; |
1026 | } | 1021 | } else |
1027 | } else if (packet_bytes == 1) { | 1022 | return 0; |
1028 | if (retry_on_empty-- > 0) { | 1023 | } else { |
1029 | goto more; | 1024 | if (retry_on_empty-- > 0) { |
1030 | } else | 1025 | goto more; |
1031 | return 0; | 1026 | } else |
1032 | } else { | 1027 | return 0; |
1033 | if (retry_on_empty-- > 0) { | 1028 | } |
1034 | goto more; | 1029 | } |
1035 | } else | 1030 | more:{ |
1036 | return 0; | 1031 | goto read; |
1037 | } | 1032 | } |
1038 | } | 1033 | have:if (ftdi->bulk_in_left > 0) { |
1039 | more:{ | 1034 | u8 c = ftdi->bulk_in_buffer[++ftdi->bulk_in_last]; |
1040 | goto read; | 1035 | bytes_read += 1; |
1041 | } | 1036 | ftdi->bulk_in_left -= 1; |
1042 | have:if (ftdi->bulk_in_left > 0) { | 1037 | if (ftdi->received == 0 && c == 0xFF) { |
1043 | u8 c = ftdi->bulk_in_buffer[++ftdi->bulk_in_last]; | 1038 | goto have; |
1044 | bytes_read += 1; | 1039 | } else |
1045 | ftdi->bulk_in_left -= 1; | 1040 | *b++ = c; |
1046 | if (ftdi->received == 0 && c == 0xFF) { | 1041 | if (++ftdi->received < ftdi->expected) { |
1047 | goto have; | 1042 | goto have; |
1048 | } else | 1043 | } else if (ftdi->ed_found) { |
1049 | *b++ = c; | 1044 | int ed_number = (ftdi->response[0] >> 5) & 0x03; |
1050 | if (++ftdi->received < ftdi->expected) { | 1045 | u16 ed_length = (ftdi->response[2] << 8) | |
1051 | goto have; | 1046 | ftdi->response[1]; |
1052 | } else if (ftdi->ed_found) { | 1047 | struct u132_target *target = &ftdi->target[ed_number]; |
1053 | int ed_number = (ftdi->response[0] >> 5) & 0x03; | 1048 | int payload = (ed_length >> 0) & 0x07FF; |
1054 | u16 ed_length = (ftdi->response[2] << 8) | | 1049 | char diag[30 *3 + 4]; |
1055 | ftdi->response[1]; | 1050 | char *d = diag; |
1056 | struct u132_target *target = &ftdi->target[ed_number]; | 1051 | int m = payload; |
1057 | int payload = (ed_length >> 0) & 0x07FF; | 1052 | u8 *c = 4 + ftdi->response; |
1058 | char diag[30 *3 + 4]; | 1053 | int s = (sizeof(diag) - 1) / 3; |
1059 | char *d = diag; | 1054 | diag[0] = 0; |
1060 | int m = payload; | 1055 | while (s-- > 0 && m-- > 0) { |
1061 | u8 *c = 4 + ftdi->response; | 1056 | if (s > 0 || m == 0) { |
1062 | int s = (sizeof(diag) - 1) / 3; | 1057 | d += sprintf(d, " %02X", *c++); |
1063 | diag[0] = 0; | 1058 | } else |
1064 | while (s-- > 0 && m-- > 0) { | 1059 | d += sprintf(d, " .."); |
1065 | if (s > 0 || m == 0) { | 1060 | } |
1066 | d += sprintf(d, " %02X", *c++); | 1061 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, |
1067 | } else | 1062 | payload); |
1068 | d += sprintf(d, " .."); | 1063 | ftdi->received = 0; |
1069 | } | 1064 | ftdi->expected = 4; |
1070 | ftdi_elan_do_callback(ftdi, target, 4 + ftdi->response, | 1065 | ftdi->ed_found = 0; |
1071 | payload); | 1066 | b = ftdi->response; |
1072 | ftdi->received = 0; | 1067 | goto have; |
1073 | ftdi->expected = 4; | 1068 | } else if (ftdi->expected == 8) { |
1074 | ftdi->ed_found = 0; | 1069 | u8 buscmd; |
1075 | b = ftdi->response; | 1070 | int respond_head = ftdi->respond_head++; |
1076 | goto have; | 1071 | struct u132_respond *respond = &ftdi->respond[ |
1077 | } else if (ftdi->expected == 8) { | 1072 | RESPOND_MASK & respond_head]; |
1078 | u8 buscmd; | 1073 | u32 data = ftdi->response[7]; |
1079 | int respond_head = ftdi->respond_head++; | 1074 | data <<= 8; |
1080 | struct u132_respond *respond = &ftdi->respond[ | 1075 | data |= ftdi->response[6]; |
1081 | RESPOND_MASK & respond_head]; | 1076 | data <<= 8; |
1082 | u32 data = ftdi->response[7]; | 1077 | data |= ftdi->response[5]; |
1083 | data <<= 8; | 1078 | data <<= 8; |
1084 | data |= ftdi->response[6]; | 1079 | data |= ftdi->response[4]; |
1085 | data <<= 8; | 1080 | *respond->value = data; |
1086 | data |= ftdi->response[5]; | 1081 | *respond->result = 0; |
1087 | data <<= 8; | 1082 | complete(&respond->wait_completion); |
1088 | data |= ftdi->response[4]; | 1083 | ftdi->received = 0; |
1089 | *respond->value = data; | 1084 | ftdi->expected = 4; |
1090 | *respond->result = 0; | 1085 | ftdi->ed_found = 0; |
1091 | complete(&respond->wait_completion); | 1086 | b = ftdi->response; |
1092 | ftdi->received = 0; | 1087 | buscmd = (ftdi->response[0] >> 0) & 0x0F; |
1093 | ftdi->expected = 4; | 1088 | if (buscmd == 0x00) { |
1094 | ftdi->ed_found = 0; | 1089 | } else if (buscmd == 0x02) { |
1095 | b = ftdi->response; | 1090 | } else if (buscmd == 0x06) { |
1096 | buscmd = (ftdi->response[0] >> 0) & 0x0F; | 1091 | } else if (buscmd == 0x0A) { |
1097 | if (buscmd == 0x00) { | 1092 | } else |
1098 | } else if (buscmd == 0x02) { | 1093 | dev_err(&ftdi->udev->dev, "Uxxx unknown(%0X) value = %08X\n", |
1099 | } else if (buscmd == 0x06) { | 1094 | buscmd, data); |
1100 | } else if (buscmd == 0x0A) { | 1095 | goto have; |
1101 | } else | 1096 | } else { |
1102 | dev_err(&ftdi->udev->dev, "Uxxx unknown(%0X) va" | 1097 | if ((ftdi->response[0] & 0x80) == 0x00) { |
1103 | "lue = %08X\n", buscmd, data); | 1098 | ftdi->expected = 8; |
1104 | goto have; | 1099 | goto have; |
1105 | } else { | 1100 | } else { |
1106 | if ((ftdi->response[0] & 0x80) == 0x00) { | 1101 | int ed_number = (ftdi->response[0] >> 5) & 0x03; |
1107 | ftdi->expected = 8; | 1102 | int ed_type = (ftdi->response[0] >> 0) & 0x03; |
1108 | goto have; | 1103 | u16 ed_length = (ftdi->response[2] << 8) | |
1109 | } else { | 1104 | ftdi->response[1]; |
1110 | int ed_number = (ftdi->response[0] >> 5) & 0x03; | 1105 | struct u132_target *target = &ftdi->target[ |
1111 | int ed_type = (ftdi->response[0] >> 0) & 0x03; | 1106 | ed_number]; |
1112 | u16 ed_length = (ftdi->response[2] << 8) | | 1107 | target->halted = (ftdi->response[0] >> 3) & |
1113 | ftdi->response[1]; | 1108 | 0x01; |
1114 | struct u132_target *target = &ftdi->target[ | 1109 | target->skipped = (ftdi->response[0] >> 2) & |
1115 | ed_number]; | 1110 | 0x01; |
1116 | target->halted = (ftdi->response[0] >> 3) & | 1111 | target->toggle_bits = (ftdi->response[3] >> 6) |
1117 | 0x01; | 1112 | & 0x03; |
1118 | target->skipped = (ftdi->response[0] >> 2) & | 1113 | target->error_count = (ftdi->response[3] >> 4) |
1119 | 0x01; | 1114 | & 0x03; |
1120 | target->toggle_bits = (ftdi->response[3] >> 6) | 1115 | target->condition_code = (ftdi->response[ |
1121 | & 0x03; | 1116 | 3] >> 0) & 0x0F; |
1122 | target->error_count = (ftdi->response[3] >> 4) | 1117 | if ((ftdi->response[0] & 0x10) == 0x00) { |
1123 | & 0x03; | 1118 | b = have_ed_set_response(ftdi, target, |
1124 | target->condition_code = (ftdi->response[ | 1119 | ed_length, ed_number, ed_type, |
1125 | 3] >> 0) & 0x0F; | 1120 | b); |
1126 | if ((ftdi->response[0] & 0x10) == 0x00) { | 1121 | goto have; |
1127 | b = have_ed_set_response(ftdi, target, | 1122 | } else { |
1128 | ed_length, ed_number, ed_type, | 1123 | b = have_ed_get_response(ftdi, target, |
1129 | b); | 1124 | ed_length, ed_number, ed_type, |
1130 | goto have; | 1125 | b); |
1131 | } else { | 1126 | goto have; |
1132 | b = have_ed_get_response(ftdi, target, | 1127 | } |
1133 | ed_length, ed_number, ed_type, | 1128 | } |
1134 | b); | 1129 | } |
1135 | goto have; | 1130 | } else |
1136 | } | 1131 | goto more; |
1137 | } | ||
1138 | } | ||
1139 | } else | ||
1140 | goto more; | ||
1141 | } | 1132 | } |
1142 | 1133 | ||
1143 | 1134 | ||
1144 | /* | 1135 | /* |
1145 | * create a urb, and a buffer for it, and copy the data to the urb | 1136 | * create a urb, and a buffer for it, and copy the data to the urb |
1146 | * | 1137 | * |
1147 | */ | 1138 | */ |
1148 | static ssize_t ftdi_elan_write(struct file *file, | 1139 | static ssize_t ftdi_elan_write(struct file *file, |
1149 | const char __user *user_buffer, size_t count, | 1140 | const char __user *user_buffer, size_t count, |
1150 | loff_t *ppos) | 1141 | loff_t *ppos) |
1151 | { | 1142 | { |
1152 | int retval = 0; | 1143 | int retval = 0; |
1153 | struct urb *urb; | 1144 | struct urb *urb; |
1154 | char *buf; | 1145 | char *buf; |
1155 | struct usb_ftdi *ftdi = file->private_data; | 1146 | struct usb_ftdi *ftdi = file->private_data; |
1156 | 1147 | ||
1157 | if (ftdi->disconnected > 0) { | 1148 | if (ftdi->disconnected > 0) { |
1158 | return -ENODEV; | 1149 | return -ENODEV; |
1159 | } | 1150 | } |
1160 | if (count == 0) { | 1151 | if (count == 0) { |
1161 | goto exit; | 1152 | goto exit; |
1162 | } | 1153 | } |
1163 | urb = usb_alloc_urb(0, GFP_KERNEL); | 1154 | urb = usb_alloc_urb(0, GFP_KERNEL); |
1164 | if (!urb) { | 1155 | if (!urb) { |
1165 | retval = -ENOMEM; | 1156 | retval = -ENOMEM; |
1166 | goto error_1; | 1157 | goto error_1; |
1167 | } | 1158 | } |
1168 | buf = usb_alloc_coherent(ftdi->udev, count, GFP_KERNEL, | 1159 | buf = usb_alloc_coherent(ftdi->udev, count, GFP_KERNEL, |
1169 | &urb->transfer_dma); | 1160 | &urb->transfer_dma); |
1170 | if (!buf) { | 1161 | if (!buf) { |
1171 | retval = -ENOMEM; | 1162 | retval = -ENOMEM; |
1172 | goto error_2; | 1163 | goto error_2; |
1173 | } | 1164 | } |
1174 | if (copy_from_user(buf, user_buffer, count)) { | 1165 | if (copy_from_user(buf, user_buffer, count)) { |
1175 | retval = -EFAULT; | 1166 | retval = -EFAULT; |
1176 | goto error_3; | 1167 | goto error_3; |
1177 | } | 1168 | } |
1178 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, | 1169 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, |
1179 | ftdi->bulk_out_endpointAddr), buf, count, | 1170 | ftdi->bulk_out_endpointAddr), buf, count, |
1180 | ftdi_elan_write_bulk_callback, ftdi); | 1171 | ftdi_elan_write_bulk_callback, ftdi); |
1181 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1172 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1182 | retval = usb_submit_urb(urb, GFP_KERNEL); | 1173 | retval = usb_submit_urb(urb, GFP_KERNEL); |
1183 | if (retval) { | 1174 | if (retval) { |
1184 | dev_err(&ftdi->udev->dev, "failed submitting write urb, error %" | 1175 | dev_err(&ftdi->udev->dev, |
1185 | "d\n", retval); | 1176 | "failed submitting write urb, error %d\n", retval); |
1186 | goto error_3; | 1177 | goto error_3; |
1187 | } | 1178 | } |
1188 | usb_free_urb(urb); | 1179 | usb_free_urb(urb); |
1189 | 1180 | ||
1190 | exit: | 1181 | exit: |
1191 | return count; | 1182 | return count; |
1192 | error_3: | 1183 | error_3: |
1193 | usb_free_coherent(ftdi->udev, count, buf, urb->transfer_dma); | 1184 | usb_free_coherent(ftdi->udev, count, buf, urb->transfer_dma); |
1194 | error_2: | 1185 | error_2: |
@@ -1198,29 +1189,29 @@ error_1: | |||
1198 | } | 1189 | } |
1199 | 1190 | ||
1200 | static const struct file_operations ftdi_elan_fops = { | 1191 | static const struct file_operations ftdi_elan_fops = { |
1201 | .owner = THIS_MODULE, | 1192 | .owner = THIS_MODULE, |
1202 | .llseek = no_llseek, | 1193 | .llseek = no_llseek, |
1203 | .read = ftdi_elan_read, | 1194 | .read = ftdi_elan_read, |
1204 | .write = ftdi_elan_write, | 1195 | .write = ftdi_elan_write, |
1205 | .open = ftdi_elan_open, | 1196 | .open = ftdi_elan_open, |
1206 | .release = ftdi_elan_release, | 1197 | .release = ftdi_elan_release, |
1207 | }; | 1198 | }; |
1208 | 1199 | ||
1209 | /* | 1200 | /* |
1210 | * usb class driver info in order to get a minor number from the usb core, | 1201 | * usb class driver info in order to get a minor number from the usb core, |
1211 | * and to have the device registered with the driver core | 1202 | * and to have the device registered with the driver core |
1212 | */ | 1203 | */ |
1213 | static struct usb_class_driver ftdi_elan_jtag_class = { | 1204 | static struct usb_class_driver ftdi_elan_jtag_class = { |
1214 | .name = "ftdi-%d-jtag", | 1205 | .name = "ftdi-%d-jtag", |
1215 | .fops = &ftdi_elan_fops, | 1206 | .fops = &ftdi_elan_fops, |
1216 | .minor_base = USB_FTDI_ELAN_MINOR_BASE, | 1207 | .minor_base = USB_FTDI_ELAN_MINOR_BASE, |
1217 | }; | 1208 | }; |
1218 | 1209 | ||
1219 | /* | 1210 | /* |
1220 | * the following definitions are for the | 1211 | * the following definitions are for the |
1221 | * ELAN FPGA state machgine processor that | 1212 | * ELAN FPGA state machgine processor that |
1222 | * lies on the other side of the FTDI chip | 1213 | * lies on the other side of the FTDI chip |
1223 | */ | 1214 | */ |
1224 | #define cPCIu132rd 0x0 | 1215 | #define cPCIu132rd 0x0 |
1225 | #define cPCIu132wr 0x1 | 1216 | #define cPCIu132wr 0x1 |
1226 | #define cPCIiord 0x2 | 1217 | #define cPCIiord 0x2 |
@@ -1251,1694 +1242,1663 @@ static struct usb_class_driver ftdi_elan_jtag_class = { | |||
1251 | #define cCCnotaccessed 0xF | 1242 | #define cCCnotaccessed 0xF |
1252 | static int ftdi_elan_write_reg(struct usb_ftdi *ftdi, u32 data) | 1243 | static int ftdi_elan_write_reg(struct usb_ftdi *ftdi, u32 data) |
1253 | { | 1244 | { |
1254 | wait:if (ftdi->disconnected > 0) { | 1245 | wait:if (ftdi->disconnected > 0) { |
1255 | return -ENODEV; | 1246 | return -ENODEV; |
1256 | } else { | 1247 | } else { |
1257 | int command_size; | 1248 | int command_size; |
1258 | mutex_lock(&ftdi->u132_lock); | 1249 | mutex_lock(&ftdi->u132_lock); |
1259 | command_size = ftdi->command_next - ftdi->command_head; | 1250 | command_size = ftdi->command_next - ftdi->command_head; |
1260 | if (command_size < COMMAND_SIZE) { | 1251 | if (command_size < COMMAND_SIZE) { |
1261 | struct u132_command *command = &ftdi->command[ | 1252 | struct u132_command *command = &ftdi->command[ |
1262 | COMMAND_MASK & ftdi->command_next]; | 1253 | COMMAND_MASK & ftdi->command_next]; |
1263 | command->header = 0x00 | cPCIu132wr; | 1254 | command->header = 0x00 | cPCIu132wr; |
1264 | command->length = 0x04; | 1255 | command->length = 0x04; |
1265 | command->address = 0x00; | 1256 | command->address = 0x00; |
1266 | command->width = 0x00; | 1257 | command->width = 0x00; |
1267 | command->follows = 4; | 1258 | command->follows = 4; |
1268 | command->value = data; | 1259 | command->value = data; |
1269 | command->buffer = &command->value; | 1260 | command->buffer = &command->value; |
1270 | ftdi->command_next += 1; | 1261 | ftdi->command_next += 1; |
1271 | ftdi_elan_kick_command_queue(ftdi); | 1262 | ftdi_elan_kick_command_queue(ftdi); |
1272 | mutex_unlock(&ftdi->u132_lock); | 1263 | mutex_unlock(&ftdi->u132_lock); |
1273 | return 0; | 1264 | return 0; |
1274 | } else { | 1265 | } else { |
1275 | mutex_unlock(&ftdi->u132_lock); | 1266 | mutex_unlock(&ftdi->u132_lock); |
1276 | msleep(100); | 1267 | msleep(100); |
1277 | goto wait; | 1268 | goto wait; |
1278 | } | 1269 | } |
1279 | } | 1270 | } |
1280 | } | 1271 | } |
1281 | 1272 | ||
1282 | static int ftdi_elan_write_config(struct usb_ftdi *ftdi, int config_offset, | 1273 | static int ftdi_elan_write_config(struct usb_ftdi *ftdi, int config_offset, |
1283 | u8 width, u32 data) | 1274 | u8 width, u32 data) |
1284 | { | 1275 | { |
1285 | u8 addressofs = config_offset / 4; | 1276 | u8 addressofs = config_offset / 4; |
1286 | wait:if (ftdi->disconnected > 0) { | 1277 | wait:if (ftdi->disconnected > 0) { |
1287 | return -ENODEV; | 1278 | return -ENODEV; |
1288 | } else { | 1279 | } else { |
1289 | int command_size; | 1280 | int command_size; |
1290 | mutex_lock(&ftdi->u132_lock); | 1281 | mutex_lock(&ftdi->u132_lock); |
1291 | command_size = ftdi->command_next - ftdi->command_head; | 1282 | command_size = ftdi->command_next - ftdi->command_head; |
1292 | if (command_size < COMMAND_SIZE) { | 1283 | if (command_size < COMMAND_SIZE) { |
1293 | struct u132_command *command = &ftdi->command[ | 1284 | struct u132_command *command = &ftdi->command[ |
1294 | COMMAND_MASK & ftdi->command_next]; | 1285 | COMMAND_MASK & ftdi->command_next]; |
1295 | command->header = 0x00 | (cPCIcfgwr & 0x0F); | 1286 | command->header = 0x00 | (cPCIcfgwr & 0x0F); |
1296 | command->length = 0x04; | 1287 | command->length = 0x04; |
1297 | command->address = addressofs; | 1288 | command->address = addressofs; |
1298 | command->width = 0x00 | (width & 0x0F); | 1289 | command->width = 0x00 | (width & 0x0F); |
1299 | command->follows = 4; | 1290 | command->follows = 4; |
1300 | command->value = data; | 1291 | command->value = data; |
1301 | command->buffer = &command->value; | 1292 | command->buffer = &command->value; |
1302 | ftdi->command_next += 1; | 1293 | ftdi->command_next += 1; |
1303 | ftdi_elan_kick_command_queue(ftdi); | 1294 | ftdi_elan_kick_command_queue(ftdi); |
1304 | mutex_unlock(&ftdi->u132_lock); | 1295 | mutex_unlock(&ftdi->u132_lock); |
1305 | return 0; | 1296 | return 0; |
1306 | } else { | 1297 | } else { |
1307 | mutex_unlock(&ftdi->u132_lock); | 1298 | mutex_unlock(&ftdi->u132_lock); |
1308 | msleep(100); | 1299 | msleep(100); |
1309 | goto wait; | 1300 | goto wait; |
1310 | } | 1301 | } |
1311 | } | 1302 | } |
1312 | } | 1303 | } |
1313 | 1304 | ||
1314 | static int ftdi_elan_write_pcimem(struct usb_ftdi *ftdi, int mem_offset, | 1305 | static int ftdi_elan_write_pcimem(struct usb_ftdi *ftdi, int mem_offset, |
1315 | u8 width, u32 data) | 1306 | u8 width, u32 data) |
1316 | { | 1307 | { |
1317 | u8 addressofs = mem_offset / 4; | 1308 | u8 addressofs = mem_offset / 4; |
1318 | wait:if (ftdi->disconnected > 0) { | 1309 | wait:if (ftdi->disconnected > 0) { |
1319 | return -ENODEV; | 1310 | return -ENODEV; |
1320 | } else { | 1311 | } else { |
1321 | int command_size; | 1312 | int command_size; |
1322 | mutex_lock(&ftdi->u132_lock); | 1313 | mutex_lock(&ftdi->u132_lock); |
1323 | command_size = ftdi->command_next - ftdi->command_head; | 1314 | command_size = ftdi->command_next - ftdi->command_head; |
1324 | if (command_size < COMMAND_SIZE) { | 1315 | if (command_size < COMMAND_SIZE) { |
1325 | struct u132_command *command = &ftdi->command[ | 1316 | struct u132_command *command = &ftdi->command[ |
1326 | COMMAND_MASK & ftdi->command_next]; | 1317 | COMMAND_MASK & ftdi->command_next]; |
1327 | command->header = 0x00 | (cPCImemwr & 0x0F); | 1318 | command->header = 0x00 | (cPCImemwr & 0x0F); |
1328 | command->length = 0x04; | 1319 | command->length = 0x04; |
1329 | command->address = addressofs; | 1320 | command->address = addressofs; |
1330 | command->width = 0x00 | (width & 0x0F); | 1321 | command->width = 0x00 | (width & 0x0F); |
1331 | command->follows = 4; | 1322 | command->follows = 4; |
1332 | command->value = data; | 1323 | command->value = data; |
1333 | command->buffer = &command->value; | 1324 | command->buffer = &command->value; |
1334 | ftdi->command_next += 1; | 1325 | ftdi->command_next += 1; |
1335 | ftdi_elan_kick_command_queue(ftdi); | 1326 | ftdi_elan_kick_command_queue(ftdi); |
1336 | mutex_unlock(&ftdi->u132_lock); | 1327 | mutex_unlock(&ftdi->u132_lock); |
1337 | return 0; | 1328 | return 0; |
1338 | } else { | 1329 | } else { |
1339 | mutex_unlock(&ftdi->u132_lock); | 1330 | mutex_unlock(&ftdi->u132_lock); |
1340 | msleep(100); | 1331 | msleep(100); |
1341 | goto wait; | 1332 | goto wait; |
1342 | } | 1333 | } |
1343 | } | 1334 | } |
1344 | } | 1335 | } |
1345 | 1336 | ||
1346 | int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset, | 1337 | int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset, |
1347 | u8 width, u32 data) | 1338 | u8 width, u32 data) |
1348 | { | 1339 | { |
1349 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1340 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1350 | return ftdi_elan_write_pcimem(ftdi, mem_offset, width, data); | 1341 | return ftdi_elan_write_pcimem(ftdi, mem_offset, width, data); |
1351 | } | 1342 | } |
1352 | 1343 | ||
1353 | 1344 | ||
1354 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_write_pcimem); | 1345 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_write_pcimem); |
1355 | static int ftdi_elan_read_reg(struct usb_ftdi *ftdi, u32 *data) | 1346 | static int ftdi_elan_read_reg(struct usb_ftdi *ftdi, u32 *data) |
1356 | { | 1347 | { |
1357 | wait:if (ftdi->disconnected > 0) { | 1348 | wait:if (ftdi->disconnected > 0) { |
1358 | return -ENODEV; | 1349 | return -ENODEV; |
1359 | } else { | 1350 | } else { |
1360 | int command_size; | 1351 | int command_size; |
1361 | int respond_size; | 1352 | int respond_size; |
1362 | mutex_lock(&ftdi->u132_lock); | 1353 | mutex_lock(&ftdi->u132_lock); |
1363 | command_size = ftdi->command_next - ftdi->command_head; | 1354 | command_size = ftdi->command_next - ftdi->command_head; |
1364 | respond_size = ftdi->respond_next - ftdi->respond_head; | 1355 | respond_size = ftdi->respond_next - ftdi->respond_head; |
1365 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) | 1356 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) |
1366 | { | 1357 | { |
1367 | struct u132_command *command = &ftdi->command[ | 1358 | struct u132_command *command = &ftdi->command[ |
1368 | COMMAND_MASK & ftdi->command_next]; | 1359 | COMMAND_MASK & ftdi->command_next]; |
1369 | struct u132_respond *respond = &ftdi->respond[ | 1360 | struct u132_respond *respond = &ftdi->respond[ |
1370 | RESPOND_MASK & ftdi->respond_next]; | 1361 | RESPOND_MASK & ftdi->respond_next]; |
1371 | int result = -ENODEV; | 1362 | int result = -ENODEV; |
1372 | respond->result = &result; | 1363 | respond->result = &result; |
1373 | respond->header = command->header = 0x00 | cPCIu132rd; | 1364 | respond->header = command->header = 0x00 | cPCIu132rd; |
1374 | command->length = 0x04; | 1365 | command->length = 0x04; |
1375 | respond->address = command->address = cU132cmd_status; | 1366 | respond->address = command->address = cU132cmd_status; |
1376 | command->width = 0x00; | 1367 | command->width = 0x00; |
1377 | command->follows = 0; | 1368 | command->follows = 0; |
1378 | command->value = 0; | 1369 | command->value = 0; |
1379 | command->buffer = NULL; | 1370 | command->buffer = NULL; |
1380 | respond->value = data; | 1371 | respond->value = data; |
1381 | init_completion(&respond->wait_completion); | 1372 | init_completion(&respond->wait_completion); |
1382 | ftdi->command_next += 1; | 1373 | ftdi->command_next += 1; |
1383 | ftdi->respond_next += 1; | 1374 | ftdi->respond_next += 1; |
1384 | ftdi_elan_kick_command_queue(ftdi); | 1375 | ftdi_elan_kick_command_queue(ftdi); |
1385 | mutex_unlock(&ftdi->u132_lock); | 1376 | mutex_unlock(&ftdi->u132_lock); |
1386 | wait_for_completion(&respond->wait_completion); | 1377 | wait_for_completion(&respond->wait_completion); |
1387 | return result; | 1378 | return result; |
1388 | } else { | 1379 | } else { |
1389 | mutex_unlock(&ftdi->u132_lock); | 1380 | mutex_unlock(&ftdi->u132_lock); |
1390 | msleep(100); | 1381 | msleep(100); |
1391 | goto wait; | 1382 | goto wait; |
1392 | } | 1383 | } |
1393 | } | 1384 | } |
1394 | } | 1385 | } |
1395 | 1386 | ||
1396 | static int ftdi_elan_read_config(struct usb_ftdi *ftdi, int config_offset, | 1387 | static int ftdi_elan_read_config(struct usb_ftdi *ftdi, int config_offset, |
1397 | u8 width, u32 *data) | 1388 | u8 width, u32 *data) |
1398 | { | 1389 | { |
1399 | u8 addressofs = config_offset / 4; | 1390 | u8 addressofs = config_offset / 4; |
1400 | wait:if (ftdi->disconnected > 0) { | 1391 | wait:if (ftdi->disconnected > 0) { |
1401 | return -ENODEV; | 1392 | return -ENODEV; |
1402 | } else { | 1393 | } else { |
1403 | int command_size; | 1394 | int command_size; |
1404 | int respond_size; | 1395 | int respond_size; |
1405 | mutex_lock(&ftdi->u132_lock); | 1396 | mutex_lock(&ftdi->u132_lock); |
1406 | command_size = ftdi->command_next - ftdi->command_head; | 1397 | command_size = ftdi->command_next - ftdi->command_head; |
1407 | respond_size = ftdi->respond_next - ftdi->respond_head; | 1398 | respond_size = ftdi->respond_next - ftdi->respond_head; |
1408 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) | 1399 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) |
1409 | { | 1400 | { |
1410 | struct u132_command *command = &ftdi->command[ | 1401 | struct u132_command *command = &ftdi->command[ |
1411 | COMMAND_MASK & ftdi->command_next]; | 1402 | COMMAND_MASK & ftdi->command_next]; |
1412 | struct u132_respond *respond = &ftdi->respond[ | 1403 | struct u132_respond *respond = &ftdi->respond[ |
1413 | RESPOND_MASK & ftdi->respond_next]; | 1404 | RESPOND_MASK & ftdi->respond_next]; |
1414 | int result = -ENODEV; | 1405 | int result = -ENODEV; |
1415 | respond->result = &result; | 1406 | respond->result = &result; |
1416 | respond->header = command->header = 0x00 | (cPCIcfgrd & | 1407 | respond->header = command->header = 0x00 | (cPCIcfgrd & |
1417 | 0x0F); | 1408 | 0x0F); |
1418 | command->length = 0x04; | 1409 | command->length = 0x04; |
1419 | respond->address = command->address = addressofs; | 1410 | respond->address = command->address = addressofs; |
1420 | command->width = 0x00 | (width & 0x0F); | 1411 | command->width = 0x00 | (width & 0x0F); |
1421 | command->follows = 0; | 1412 | command->follows = 0; |
1422 | command->value = 0; | 1413 | command->value = 0; |
1423 | command->buffer = NULL; | 1414 | command->buffer = NULL; |
1424 | respond->value = data; | 1415 | respond->value = data; |
1425 | init_completion(&respond->wait_completion); | 1416 | init_completion(&respond->wait_completion); |
1426 | ftdi->command_next += 1; | 1417 | ftdi->command_next += 1; |
1427 | ftdi->respond_next += 1; | 1418 | ftdi->respond_next += 1; |
1428 | ftdi_elan_kick_command_queue(ftdi); | 1419 | ftdi_elan_kick_command_queue(ftdi); |
1429 | mutex_unlock(&ftdi->u132_lock); | 1420 | mutex_unlock(&ftdi->u132_lock); |
1430 | wait_for_completion(&respond->wait_completion); | 1421 | wait_for_completion(&respond->wait_completion); |
1431 | return result; | 1422 | return result; |
1432 | } else { | 1423 | } else { |
1433 | mutex_unlock(&ftdi->u132_lock); | 1424 | mutex_unlock(&ftdi->u132_lock); |
1434 | msleep(100); | 1425 | msleep(100); |
1435 | goto wait; | 1426 | goto wait; |
1436 | } | 1427 | } |
1437 | } | 1428 | } |
1438 | } | 1429 | } |
1439 | 1430 | ||
1440 | static int ftdi_elan_read_pcimem(struct usb_ftdi *ftdi, int mem_offset, | 1431 | static int ftdi_elan_read_pcimem(struct usb_ftdi *ftdi, int mem_offset, |
1441 | u8 width, u32 *data) | 1432 | u8 width, u32 *data) |
1442 | { | 1433 | { |
1443 | u8 addressofs = mem_offset / 4; | 1434 | u8 addressofs = mem_offset / 4; |
1444 | wait:if (ftdi->disconnected > 0) { | 1435 | wait:if (ftdi->disconnected > 0) { |
1445 | return -ENODEV; | 1436 | return -ENODEV; |
1446 | } else { | 1437 | } else { |
1447 | int command_size; | 1438 | int command_size; |
1448 | int respond_size; | 1439 | int respond_size; |
1449 | mutex_lock(&ftdi->u132_lock); | 1440 | mutex_lock(&ftdi->u132_lock); |
1450 | command_size = ftdi->command_next - ftdi->command_head; | 1441 | command_size = ftdi->command_next - ftdi->command_head; |
1451 | respond_size = ftdi->respond_next - ftdi->respond_head; | 1442 | respond_size = ftdi->respond_next - ftdi->respond_head; |
1452 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) | 1443 | if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE) |
1453 | { | 1444 | { |
1454 | struct u132_command *command = &ftdi->command[ | 1445 | struct u132_command *command = &ftdi->command[ |
1455 | COMMAND_MASK & ftdi->command_next]; | 1446 | COMMAND_MASK & ftdi->command_next]; |
1456 | struct u132_respond *respond = &ftdi->respond[ | 1447 | struct u132_respond *respond = &ftdi->respond[ |
1457 | RESPOND_MASK & ftdi->respond_next]; | 1448 | RESPOND_MASK & ftdi->respond_next]; |
1458 | int result = -ENODEV; | 1449 | int result = -ENODEV; |
1459 | respond->result = &result; | 1450 | respond->result = &result; |
1460 | respond->header = command->header = 0x00 | (cPCImemrd & | 1451 | respond->header = command->header = 0x00 | (cPCImemrd & |
1461 | 0x0F); | 1452 | 0x0F); |
1462 | command->length = 0x04; | 1453 | command->length = 0x04; |
1463 | respond->address = command->address = addressofs; | 1454 | respond->address = command->address = addressofs; |
1464 | command->width = 0x00 | (width & 0x0F); | 1455 | command->width = 0x00 | (width & 0x0F); |
1465 | command->follows = 0; | 1456 | command->follows = 0; |
1466 | command->value = 0; | 1457 | command->value = 0; |
1467 | command->buffer = NULL; | 1458 | command->buffer = NULL; |
1468 | respond->value = data; | 1459 | respond->value = data; |
1469 | init_completion(&respond->wait_completion); | 1460 | init_completion(&respond->wait_completion); |
1470 | ftdi->command_next += 1; | 1461 | ftdi->command_next += 1; |
1471 | ftdi->respond_next += 1; | 1462 | ftdi->respond_next += 1; |
1472 | ftdi_elan_kick_command_queue(ftdi); | 1463 | ftdi_elan_kick_command_queue(ftdi); |
1473 | mutex_unlock(&ftdi->u132_lock); | 1464 | mutex_unlock(&ftdi->u132_lock); |
1474 | wait_for_completion(&respond->wait_completion); | 1465 | wait_for_completion(&respond->wait_completion); |
1475 | return result; | 1466 | return result; |
1476 | } else { | 1467 | } else { |
1477 | mutex_unlock(&ftdi->u132_lock); | 1468 | mutex_unlock(&ftdi->u132_lock); |
1478 | msleep(100); | 1469 | msleep(100); |
1479 | goto wait; | 1470 | goto wait; |
1480 | } | 1471 | } |
1481 | } | 1472 | } |
1482 | } | 1473 | } |
1483 | 1474 | ||
1484 | int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset, | 1475 | int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset, |
1485 | u8 width, u32 *data) | 1476 | u8 width, u32 *data) |
1486 | { | 1477 | { |
1487 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1478 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1488 | if (ftdi->initialized == 0) { | 1479 | if (ftdi->initialized == 0) { |
1489 | return -ENODEV; | 1480 | return -ENODEV; |
1490 | } else | 1481 | } else |
1491 | return ftdi_elan_read_pcimem(ftdi, mem_offset, width, data); | 1482 | return ftdi_elan_read_pcimem(ftdi, mem_offset, width, data); |
1492 | } | 1483 | } |
1493 | 1484 | ||
1494 | 1485 | ||
1495 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_pcimem); | 1486 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_pcimem); |
1496 | static int ftdi_elan_edset_setup(struct usb_ftdi *ftdi, u8 ed_number, | 1487 | static int ftdi_elan_edset_setup(struct usb_ftdi *ftdi, u8 ed_number, |
1497 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1488 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1498 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1489 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1499 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1490 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1500 | int halted, int skipped, int actual, int non_null)) | 1491 | int halted, int skipped, int actual, int non_null)) |
1501 | { | 1492 | { |
1502 | u8 ed = ed_number - 1; | 1493 | u8 ed = ed_number - 1; |
1503 | wait:if (ftdi->disconnected > 0) { | 1494 | wait:if (ftdi->disconnected > 0) { |
1504 | return -ENODEV; | 1495 | return -ENODEV; |
1505 | } else if (ftdi->initialized == 0) { | 1496 | } else if (ftdi->initialized == 0) { |
1506 | return -ENODEV; | 1497 | return -ENODEV; |
1507 | } else { | 1498 | } else { |
1508 | int command_size; | 1499 | int command_size; |
1509 | mutex_lock(&ftdi->u132_lock); | 1500 | mutex_lock(&ftdi->u132_lock); |
1510 | command_size = ftdi->command_next - ftdi->command_head; | 1501 | command_size = ftdi->command_next - ftdi->command_head; |
1511 | if (command_size < COMMAND_SIZE) { | 1502 | if (command_size < COMMAND_SIZE) { |
1512 | struct u132_target *target = &ftdi->target[ed]; | 1503 | struct u132_target *target = &ftdi->target[ed]; |
1513 | struct u132_command *command = &ftdi->command[ | 1504 | struct u132_command *command = &ftdi->command[ |
1514 | COMMAND_MASK & ftdi->command_next]; | 1505 | COMMAND_MASK & ftdi->command_next]; |
1515 | command->header = 0x80 | (ed << 5); | 1506 | command->header = 0x80 | (ed << 5); |
1516 | command->length = 0x8007; | 1507 | command->length = 0x8007; |
1517 | command->address = (toggle_bits << 6) | (ep_number << 2) | 1508 | command->address = (toggle_bits << 6) | (ep_number << 2) |
1518 | | (address << 0); | 1509 | | (address << 0); |
1519 | command->width = usb_maxpacket(urb->dev, urb->pipe, | 1510 | command->width = usb_maxpacket(urb->dev, urb->pipe, |
1520 | usb_pipeout(urb->pipe)); | 1511 | usb_pipeout(urb->pipe)); |
1521 | command->follows = 8; | 1512 | command->follows = 8; |
1522 | command->value = 0; | 1513 | command->value = 0; |
1523 | command->buffer = urb->setup_packet; | 1514 | command->buffer = urb->setup_packet; |
1524 | target->callback = callback; | 1515 | target->callback = callback; |
1525 | target->endp = endp; | 1516 | target->endp = endp; |
1526 | target->urb = urb; | 1517 | target->urb = urb; |
1527 | target->active = 1; | 1518 | target->active = 1; |
1528 | ftdi->command_next += 1; | 1519 | ftdi->command_next += 1; |
1529 | ftdi_elan_kick_command_queue(ftdi); | 1520 | ftdi_elan_kick_command_queue(ftdi); |
1530 | mutex_unlock(&ftdi->u132_lock); | 1521 | mutex_unlock(&ftdi->u132_lock); |
1531 | return 0; | 1522 | return 0; |
1532 | } else { | 1523 | } else { |
1533 | mutex_unlock(&ftdi->u132_lock); | 1524 | mutex_unlock(&ftdi->u132_lock); |
1534 | msleep(100); | 1525 | msleep(100); |
1535 | goto wait; | 1526 | goto wait; |
1536 | } | 1527 | } |
1537 | } | 1528 | } |
1538 | } | 1529 | } |
1539 | 1530 | ||
1540 | int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number, | 1531 | int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number, |
1541 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1532 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1542 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1533 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1543 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1534 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1544 | int halted, int skipped, int actual, int non_null)) | 1535 | int halted, int skipped, int actual, int non_null)) |
1545 | { | 1536 | { |
1546 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1537 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1547 | return ftdi_elan_edset_setup(ftdi, ed_number, endp, urb, address, | 1538 | return ftdi_elan_edset_setup(ftdi, ed_number, endp, urb, address, |
1548 | ep_number, toggle_bits, callback); | 1539 | ep_number, toggle_bits, callback); |
1549 | } | 1540 | } |
1550 | 1541 | ||
1551 | 1542 | ||
1552 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_setup); | 1543 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_setup); |
1553 | static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number, | 1544 | static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number, |
1554 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1545 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1555 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1546 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1556 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1547 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1557 | int halted, int skipped, int actual, int non_null)) | 1548 | int halted, int skipped, int actual, int non_null)) |
1558 | { | 1549 | { |
1559 | u8 ed = ed_number - 1; | 1550 | u8 ed = ed_number - 1; |
1560 | wait:if (ftdi->disconnected > 0) { | 1551 | wait:if (ftdi->disconnected > 0) { |
1561 | return -ENODEV; | 1552 | return -ENODEV; |
1562 | } else if (ftdi->initialized == 0) { | 1553 | } else if (ftdi->initialized == 0) { |
1563 | return -ENODEV; | 1554 | return -ENODEV; |
1564 | } else { | 1555 | } else { |
1565 | int command_size; | 1556 | int command_size; |
1566 | mutex_lock(&ftdi->u132_lock); | 1557 | mutex_lock(&ftdi->u132_lock); |
1567 | command_size = ftdi->command_next - ftdi->command_head; | 1558 | command_size = ftdi->command_next - ftdi->command_head; |
1568 | if (command_size < COMMAND_SIZE) { | 1559 | if (command_size < COMMAND_SIZE) { |
1569 | struct u132_target *target = &ftdi->target[ed]; | 1560 | struct u132_target *target = &ftdi->target[ed]; |
1570 | struct u132_command *command = &ftdi->command[ | 1561 | struct u132_command *command = &ftdi->command[ |
1571 | COMMAND_MASK & ftdi->command_next]; | 1562 | COMMAND_MASK & ftdi->command_next]; |
1572 | u32 remaining_length = urb->transfer_buffer_length - | 1563 | u32 remaining_length = urb->transfer_buffer_length - |
1573 | urb->actual_length; | 1564 | urb->actual_length; |
1574 | command->header = 0x82 | (ed << 5); | 1565 | command->header = 0x82 | (ed << 5); |
1575 | if (remaining_length == 0) { | 1566 | if (remaining_length == 0) { |
1576 | command->length = 0x0000; | 1567 | command->length = 0x0000; |
1577 | } else if (remaining_length > 1024) { | 1568 | } else if (remaining_length > 1024) { |
1578 | command->length = 0x8000 | 1023; | 1569 | command->length = 0x8000 | 1023; |
1579 | } else | 1570 | } else |
1580 | command->length = 0x8000 | (remaining_length - | 1571 | command->length = 0x8000 | (remaining_length - |
1581 | 1); | 1572 | 1); |
1582 | command->address = (toggle_bits << 6) | (ep_number << 2) | 1573 | command->address = (toggle_bits << 6) | (ep_number << 2) |
1583 | | (address << 0); | 1574 | | (address << 0); |
1584 | command->width = usb_maxpacket(urb->dev, urb->pipe, | 1575 | command->width = usb_maxpacket(urb->dev, urb->pipe, |
1585 | usb_pipeout(urb->pipe)); | 1576 | usb_pipeout(urb->pipe)); |
1586 | command->follows = 0; | 1577 | command->follows = 0; |
1587 | command->value = 0; | 1578 | command->value = 0; |
1588 | command->buffer = NULL; | 1579 | command->buffer = NULL; |
1589 | target->callback = callback; | 1580 | target->callback = callback; |
1590 | target->endp = endp; | 1581 | target->endp = endp; |
1591 | target->urb = urb; | 1582 | target->urb = urb; |
1592 | target->active = 1; | 1583 | target->active = 1; |
1593 | ftdi->command_next += 1; | 1584 | ftdi->command_next += 1; |
1594 | ftdi_elan_kick_command_queue(ftdi); | 1585 | ftdi_elan_kick_command_queue(ftdi); |
1595 | mutex_unlock(&ftdi->u132_lock); | 1586 | mutex_unlock(&ftdi->u132_lock); |
1596 | return 0; | 1587 | return 0; |
1597 | } else { | 1588 | } else { |
1598 | mutex_unlock(&ftdi->u132_lock); | 1589 | mutex_unlock(&ftdi->u132_lock); |
1599 | msleep(100); | 1590 | msleep(100); |
1600 | goto wait; | 1591 | goto wait; |
1601 | } | 1592 | } |
1602 | } | 1593 | } |
1603 | } | 1594 | } |
1604 | 1595 | ||
1605 | int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number, | 1596 | int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number, |
1606 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1597 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1607 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1598 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1608 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1599 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1609 | int halted, int skipped, int actual, int non_null)) | 1600 | int halted, int skipped, int actual, int non_null)) |
1610 | { | 1601 | { |
1611 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1602 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1612 | return ftdi_elan_edset_input(ftdi, ed_number, endp, urb, address, | 1603 | return ftdi_elan_edset_input(ftdi, ed_number, endp, urb, address, |
1613 | ep_number, toggle_bits, callback); | 1604 | ep_number, toggle_bits, callback); |
1614 | } | 1605 | } |
1615 | 1606 | ||
1616 | 1607 | ||
1617 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_input); | 1608 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_input); |
1618 | static int ftdi_elan_edset_empty(struct usb_ftdi *ftdi, u8 ed_number, | 1609 | static int ftdi_elan_edset_empty(struct usb_ftdi *ftdi, u8 ed_number, |
1619 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1610 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1620 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1611 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1621 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1612 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1622 | int halted, int skipped, int actual, int non_null)) | 1613 | int halted, int skipped, int actual, int non_null)) |
1623 | { | 1614 | { |
1624 | u8 ed = ed_number - 1; | 1615 | u8 ed = ed_number - 1; |
1625 | wait:if (ftdi->disconnected > 0) { | 1616 | wait:if (ftdi->disconnected > 0) { |
1626 | return -ENODEV; | 1617 | return -ENODEV; |
1627 | } else if (ftdi->initialized == 0) { | 1618 | } else if (ftdi->initialized == 0) { |
1628 | return -ENODEV; | 1619 | return -ENODEV; |
1629 | } else { | 1620 | } else { |
1630 | int command_size; | 1621 | int command_size; |
1631 | mutex_lock(&ftdi->u132_lock); | 1622 | mutex_lock(&ftdi->u132_lock); |
1632 | command_size = ftdi->command_next - ftdi->command_head; | 1623 | command_size = ftdi->command_next - ftdi->command_head; |
1633 | if (command_size < COMMAND_SIZE) { | 1624 | if (command_size < COMMAND_SIZE) { |
1634 | struct u132_target *target = &ftdi->target[ed]; | 1625 | struct u132_target *target = &ftdi->target[ed]; |
1635 | struct u132_command *command = &ftdi->command[ | 1626 | struct u132_command *command = &ftdi->command[ |
1636 | COMMAND_MASK & ftdi->command_next]; | 1627 | COMMAND_MASK & ftdi->command_next]; |
1637 | command->header = 0x81 | (ed << 5); | 1628 | command->header = 0x81 | (ed << 5); |
1638 | command->length = 0x0000; | 1629 | command->length = 0x0000; |
1639 | command->address = (toggle_bits << 6) | (ep_number << 2) | 1630 | command->address = (toggle_bits << 6) | (ep_number << 2) |
1640 | | (address << 0); | 1631 | | (address << 0); |
1641 | command->width = usb_maxpacket(urb->dev, urb->pipe, | 1632 | command->width = usb_maxpacket(urb->dev, urb->pipe, |
1642 | usb_pipeout(urb->pipe)); | 1633 | usb_pipeout(urb->pipe)); |
1643 | command->follows = 0; | 1634 | command->follows = 0; |
1644 | command->value = 0; | 1635 | command->value = 0; |
1645 | command->buffer = NULL; | 1636 | command->buffer = NULL; |
1646 | target->callback = callback; | 1637 | target->callback = callback; |
1647 | target->endp = endp; | 1638 | target->endp = endp; |
1648 | target->urb = urb; | 1639 | target->urb = urb; |
1649 | target->active = 1; | 1640 | target->active = 1; |
1650 | ftdi->command_next += 1; | 1641 | ftdi->command_next += 1; |
1651 | ftdi_elan_kick_command_queue(ftdi); | 1642 | ftdi_elan_kick_command_queue(ftdi); |
1652 | mutex_unlock(&ftdi->u132_lock); | 1643 | mutex_unlock(&ftdi->u132_lock); |
1653 | return 0; | 1644 | return 0; |
1654 | } else { | 1645 | } else { |
1655 | mutex_unlock(&ftdi->u132_lock); | 1646 | mutex_unlock(&ftdi->u132_lock); |
1656 | msleep(100); | 1647 | msleep(100); |
1657 | goto wait; | 1648 | goto wait; |
1658 | } | 1649 | } |
1659 | } | 1650 | } |
1660 | } | 1651 | } |
1661 | 1652 | ||
1662 | int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number, | 1653 | int usb_ftdi_elan_edset_empty(struct platform_device *pdev, u8 ed_number, |
1663 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1654 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1664 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1655 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1665 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1656 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1666 | int halted, int skipped, int actual, int non_null)) | 1657 | int halted, int skipped, int actual, int non_null)) |
1667 | { | 1658 | { |
1668 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1659 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1669 | return ftdi_elan_edset_empty(ftdi, ed_number, endp, urb, address, | 1660 | return ftdi_elan_edset_empty(ftdi, ed_number, endp, urb, address, |
1670 | ep_number, toggle_bits, callback); | 1661 | ep_number, toggle_bits, callback); |
1671 | } | 1662 | } |
1672 | 1663 | ||
1673 | 1664 | ||
1674 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_empty); | 1665 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_empty); |
1675 | static int ftdi_elan_edset_output(struct usb_ftdi *ftdi, u8 ed_number, | 1666 | static int ftdi_elan_edset_output(struct usb_ftdi *ftdi, u8 ed_number, |
1676 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1667 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1677 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1668 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1678 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1669 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1679 | int halted, int skipped, int actual, int non_null)) | 1670 | int halted, int skipped, int actual, int non_null)) |
1680 | { | 1671 | { |
1681 | u8 ed = ed_number - 1; | 1672 | u8 ed = ed_number - 1; |
1682 | wait:if (ftdi->disconnected > 0) { | 1673 | wait:if (ftdi->disconnected > 0) { |
1683 | return -ENODEV; | 1674 | return -ENODEV; |
1684 | } else if (ftdi->initialized == 0) { | 1675 | } else if (ftdi->initialized == 0) { |
1685 | return -ENODEV; | 1676 | return -ENODEV; |
1686 | } else { | 1677 | } else { |
1687 | int command_size; | 1678 | int command_size; |
1688 | mutex_lock(&ftdi->u132_lock); | 1679 | mutex_lock(&ftdi->u132_lock); |
1689 | command_size = ftdi->command_next - ftdi->command_head; | 1680 | command_size = ftdi->command_next - ftdi->command_head; |
1690 | if (command_size < COMMAND_SIZE) { | 1681 | if (command_size < COMMAND_SIZE) { |
1691 | u8 *b; | 1682 | u8 *b; |
1692 | u16 urb_size; | 1683 | u16 urb_size; |
1693 | int i = 0; | 1684 | int i = 0; |
1694 | char data[30 *3 + 4]; | 1685 | char data[30 *3 + 4]; |
1695 | char *d = data; | 1686 | char *d = data; |
1696 | int m = (sizeof(data) - 1) / 3; | 1687 | int m = (sizeof(data) - 1) / 3; |
1697 | int l = 0; | 1688 | int l = 0; |
1698 | struct u132_target *target = &ftdi->target[ed]; | 1689 | struct u132_target *target = &ftdi->target[ed]; |
1699 | struct u132_command *command = &ftdi->command[ | 1690 | struct u132_command *command = &ftdi->command[ |
1700 | COMMAND_MASK & ftdi->command_next]; | 1691 | COMMAND_MASK & ftdi->command_next]; |
1701 | command->header = 0x81 | (ed << 5); | 1692 | command->header = 0x81 | (ed << 5); |
1702 | command->address = (toggle_bits << 6) | (ep_number << 2) | 1693 | command->address = (toggle_bits << 6) | (ep_number << 2) |
1703 | | (address << 0); | 1694 | | (address << 0); |
1704 | command->width = usb_maxpacket(urb->dev, urb->pipe, | 1695 | command->width = usb_maxpacket(urb->dev, urb->pipe, |
1705 | usb_pipeout(urb->pipe)); | 1696 | usb_pipeout(urb->pipe)); |
1706 | command->follows = min_t(u32, 1024, | 1697 | command->follows = min_t(u32, 1024, |
1707 | urb->transfer_buffer_length - | 1698 | urb->transfer_buffer_length - |
1708 | urb->actual_length); | 1699 | urb->actual_length); |
1709 | command->value = 0; | 1700 | command->value = 0; |
1710 | command->buffer = urb->transfer_buffer + | 1701 | command->buffer = urb->transfer_buffer + |
1711 | urb->actual_length; | 1702 | urb->actual_length; |
1712 | command->length = 0x8000 | (command->follows - 1); | 1703 | command->length = 0x8000 | (command->follows - 1); |
1713 | b = command->buffer; | 1704 | b = command->buffer; |
1714 | urb_size = command->follows; | 1705 | urb_size = command->follows; |
1715 | data[0] = 0; | 1706 | data[0] = 0; |
1716 | while (urb_size-- > 0) { | 1707 | while (urb_size-- > 0) { |
1717 | if (i > m) { | 1708 | if (i > m) { |
1718 | } else if (i++ < m) { | 1709 | } else if (i++ < m) { |
1719 | int w = sprintf(d, " %02X", *b++); | 1710 | int w = sprintf(d, " %02X", *b++); |
1720 | d += w; | 1711 | d += w; |
1721 | l += w; | 1712 | l += w; |
1722 | } else | 1713 | } else |
1723 | d += sprintf(d, " .."); | 1714 | d += sprintf(d, " .."); |
1724 | } | 1715 | } |
1725 | target->callback = callback; | 1716 | target->callback = callback; |
1726 | target->endp = endp; | 1717 | target->endp = endp; |
1727 | target->urb = urb; | 1718 | target->urb = urb; |
1728 | target->active = 1; | 1719 | target->active = 1; |
1729 | ftdi->command_next += 1; | 1720 | ftdi->command_next += 1; |
1730 | ftdi_elan_kick_command_queue(ftdi); | 1721 | ftdi_elan_kick_command_queue(ftdi); |
1731 | mutex_unlock(&ftdi->u132_lock); | 1722 | mutex_unlock(&ftdi->u132_lock); |
1732 | return 0; | 1723 | return 0; |
1733 | } else { | 1724 | } else { |
1734 | mutex_unlock(&ftdi->u132_lock); | 1725 | mutex_unlock(&ftdi->u132_lock); |
1735 | msleep(100); | 1726 | msleep(100); |
1736 | goto wait; | 1727 | goto wait; |
1737 | } | 1728 | } |
1738 | } | 1729 | } |
1739 | } | 1730 | } |
1740 | 1731 | ||
1741 | int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number, | 1732 | int usb_ftdi_elan_edset_output(struct platform_device *pdev, u8 ed_number, |
1742 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1733 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1743 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1734 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1744 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1735 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1745 | int halted, int skipped, int actual, int non_null)) | 1736 | int halted, int skipped, int actual, int non_null)) |
1746 | { | 1737 | { |
1747 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1738 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1748 | return ftdi_elan_edset_output(ftdi, ed_number, endp, urb, address, | 1739 | return ftdi_elan_edset_output(ftdi, ed_number, endp, urb, address, |
1749 | ep_number, toggle_bits, callback); | 1740 | ep_number, toggle_bits, callback); |
1750 | } | 1741 | } |
1751 | 1742 | ||
1752 | 1743 | ||
1753 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_output); | 1744 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_output); |
1754 | static int ftdi_elan_edset_single(struct usb_ftdi *ftdi, u8 ed_number, | 1745 | static int ftdi_elan_edset_single(struct usb_ftdi *ftdi, u8 ed_number, |
1755 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1746 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1756 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1747 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1757 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1748 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1758 | int halted, int skipped, int actual, int non_null)) | 1749 | int halted, int skipped, int actual, int non_null)) |
1759 | { | 1750 | { |
1760 | u8 ed = ed_number - 1; | 1751 | u8 ed = ed_number - 1; |
1761 | wait:if (ftdi->disconnected > 0) { | 1752 | wait:if (ftdi->disconnected > 0) { |
1762 | return -ENODEV; | 1753 | return -ENODEV; |
1763 | } else if (ftdi->initialized == 0) { | 1754 | } else if (ftdi->initialized == 0) { |
1764 | return -ENODEV; | 1755 | return -ENODEV; |
1765 | } else { | 1756 | } else { |
1766 | int command_size; | 1757 | int command_size; |
1767 | mutex_lock(&ftdi->u132_lock); | 1758 | mutex_lock(&ftdi->u132_lock); |
1768 | command_size = ftdi->command_next - ftdi->command_head; | 1759 | command_size = ftdi->command_next - ftdi->command_head; |
1769 | if (command_size < COMMAND_SIZE) { | 1760 | if (command_size < COMMAND_SIZE) { |
1770 | u32 remaining_length = urb->transfer_buffer_length - | 1761 | u32 remaining_length = urb->transfer_buffer_length - |
1771 | urb->actual_length; | 1762 | urb->actual_length; |
1772 | struct u132_target *target = &ftdi->target[ed]; | 1763 | struct u132_target *target = &ftdi->target[ed]; |
1773 | struct u132_command *command = &ftdi->command[ | 1764 | struct u132_command *command = &ftdi->command[ |
1774 | COMMAND_MASK & ftdi->command_next]; | 1765 | COMMAND_MASK & ftdi->command_next]; |
1775 | command->header = 0x83 | (ed << 5); | 1766 | command->header = 0x83 | (ed << 5); |
1776 | if (remaining_length == 0) { | 1767 | if (remaining_length == 0) { |
1777 | command->length = 0x0000; | 1768 | command->length = 0x0000; |
1778 | } else if (remaining_length > 1024) { | 1769 | } else if (remaining_length > 1024) { |
1779 | command->length = 0x8000 | 1023; | 1770 | command->length = 0x8000 | 1023; |
1780 | } else | 1771 | } else |
1781 | command->length = 0x8000 | (remaining_length - | 1772 | command->length = 0x8000 | (remaining_length - |
1782 | 1); | 1773 | 1); |
1783 | command->address = (toggle_bits << 6) | (ep_number << 2) | 1774 | command->address = (toggle_bits << 6) | (ep_number << 2) |
1784 | | (address << 0); | 1775 | | (address << 0); |
1785 | command->width = usb_maxpacket(urb->dev, urb->pipe, | 1776 | command->width = usb_maxpacket(urb->dev, urb->pipe, |
1786 | usb_pipeout(urb->pipe)); | 1777 | usb_pipeout(urb->pipe)); |
1787 | command->follows = 0; | 1778 | command->follows = 0; |
1788 | command->value = 0; | 1779 | command->value = 0; |
1789 | command->buffer = NULL; | 1780 | command->buffer = NULL; |
1790 | target->callback = callback; | 1781 | target->callback = callback; |
1791 | target->endp = endp; | 1782 | target->endp = endp; |
1792 | target->urb = urb; | 1783 | target->urb = urb; |
1793 | target->active = 1; | 1784 | target->active = 1; |
1794 | ftdi->command_next += 1; | 1785 | ftdi->command_next += 1; |
1795 | ftdi_elan_kick_command_queue(ftdi); | 1786 | ftdi_elan_kick_command_queue(ftdi); |
1796 | mutex_unlock(&ftdi->u132_lock); | 1787 | mutex_unlock(&ftdi->u132_lock); |
1797 | return 0; | 1788 | return 0; |
1798 | } else { | 1789 | } else { |
1799 | mutex_unlock(&ftdi->u132_lock); | 1790 | mutex_unlock(&ftdi->u132_lock); |
1800 | msleep(100); | 1791 | msleep(100); |
1801 | goto wait; | 1792 | goto wait; |
1802 | } | 1793 | } |
1803 | } | 1794 | } |
1804 | } | 1795 | } |
1805 | 1796 | ||
1806 | int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number, | 1797 | int usb_ftdi_elan_edset_single(struct platform_device *pdev, u8 ed_number, |
1807 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, | 1798 | void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits, |
1808 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, | 1799 | void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, |
1809 | int toggle_bits, int error_count, int condition_code, int repeat_number, | 1800 | int toggle_bits, int error_count, int condition_code, int repeat_number, |
1810 | int halted, int skipped, int actual, int non_null)) | 1801 | int halted, int skipped, int actual, int non_null)) |
1811 | { | 1802 | { |
1812 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1803 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1813 | return ftdi_elan_edset_single(ftdi, ed_number, endp, urb, address, | 1804 | return ftdi_elan_edset_single(ftdi, ed_number, endp, urb, address, |
1814 | ep_number, toggle_bits, callback); | 1805 | ep_number, toggle_bits, callback); |
1815 | } | 1806 | } |
1816 | 1807 | ||
1817 | 1808 | ||
1818 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_single); | 1809 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_single); |
1819 | static int ftdi_elan_edset_flush(struct usb_ftdi *ftdi, u8 ed_number, | 1810 | static int ftdi_elan_edset_flush(struct usb_ftdi *ftdi, u8 ed_number, |
1820 | void *endp) | 1811 | void *endp) |
1821 | { | 1812 | { |
1822 | u8 ed = ed_number - 1; | 1813 | u8 ed = ed_number - 1; |
1823 | if (ftdi->disconnected > 0) { | 1814 | if (ftdi->disconnected > 0) { |
1824 | return -ENODEV; | 1815 | return -ENODEV; |
1825 | } else if (ftdi->initialized == 0) { | 1816 | } else if (ftdi->initialized == 0) { |
1826 | return -ENODEV; | 1817 | return -ENODEV; |
1827 | } else { | 1818 | } else { |
1828 | struct u132_target *target = &ftdi->target[ed]; | 1819 | struct u132_target *target = &ftdi->target[ed]; |
1829 | mutex_lock(&ftdi->u132_lock); | 1820 | mutex_lock(&ftdi->u132_lock); |
1830 | if (target->abandoning > 0) { | 1821 | if (target->abandoning > 0) { |
1831 | mutex_unlock(&ftdi->u132_lock); | 1822 | mutex_unlock(&ftdi->u132_lock); |
1832 | return 0; | 1823 | return 0; |
1833 | } else { | 1824 | } else { |
1834 | target->abandoning = 1; | 1825 | target->abandoning = 1; |
1835 | wait_1:if (target->active == 1) { | 1826 | wait_1:if (target->active == 1) { |
1836 | int command_size = ftdi->command_next - | 1827 | int command_size = ftdi->command_next - |
1837 | ftdi->command_head; | 1828 | ftdi->command_head; |
1838 | if (command_size < COMMAND_SIZE) { | 1829 | if (command_size < COMMAND_SIZE) { |
1839 | struct u132_command *command = | 1830 | struct u132_command *command = |
1840 | &ftdi->command[COMMAND_MASK & | 1831 | &ftdi->command[COMMAND_MASK & |
1841 | ftdi->command_next]; | 1832 | ftdi->command_next]; |
1842 | command->header = 0x80 | (ed << 5) | | 1833 | command->header = 0x80 | (ed << 5) | |
1843 | 0x4; | 1834 | 0x4; |
1844 | command->length = 0x00; | 1835 | command->length = 0x00; |
1845 | command->address = 0x00; | 1836 | command->address = 0x00; |
1846 | command->width = 0x00; | 1837 | command->width = 0x00; |
1847 | command->follows = 0; | 1838 | command->follows = 0; |
1848 | command->value = 0; | 1839 | command->value = 0; |
1849 | command->buffer = &command->value; | 1840 | command->buffer = &command->value; |
1850 | ftdi->command_next += 1; | 1841 | ftdi->command_next += 1; |
1851 | ftdi_elan_kick_command_queue(ftdi); | 1842 | ftdi_elan_kick_command_queue(ftdi); |
1852 | } else { | 1843 | } else { |
1853 | mutex_unlock(&ftdi->u132_lock); | 1844 | mutex_unlock(&ftdi->u132_lock); |
1854 | msleep(100); | 1845 | msleep(100); |
1855 | mutex_lock(&ftdi->u132_lock); | 1846 | mutex_lock(&ftdi->u132_lock); |
1856 | goto wait_1; | 1847 | goto wait_1; |
1857 | } | 1848 | } |
1858 | } | 1849 | } |
1859 | mutex_unlock(&ftdi->u132_lock); | 1850 | mutex_unlock(&ftdi->u132_lock); |
1860 | return 0; | 1851 | return 0; |
1861 | } | 1852 | } |
1862 | } | 1853 | } |
1863 | } | 1854 | } |
1864 | 1855 | ||
1865 | int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number, | 1856 | int usb_ftdi_elan_edset_flush(struct platform_device *pdev, u8 ed_number, |
1866 | void *endp) | 1857 | void *endp) |
1867 | { | 1858 | { |
1868 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); | 1859 | struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev); |
1869 | return ftdi_elan_edset_flush(ftdi, ed_number, endp); | 1860 | return ftdi_elan_edset_flush(ftdi, ed_number, endp); |
1870 | } | 1861 | } |
1871 | 1862 | ||
1872 | 1863 | ||
1873 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_flush); | 1864 | EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_flush); |
1874 | static int ftdi_elan_flush_input_fifo(struct usb_ftdi *ftdi) | 1865 | static int ftdi_elan_flush_input_fifo(struct usb_ftdi *ftdi) |
1875 | { | 1866 | { |
1876 | int retry_on_empty = 10; | 1867 | int retry_on_empty = 10; |
1877 | int retry_on_timeout = 5; | 1868 | int retry_on_timeout = 5; |
1878 | int retry_on_status = 20; | 1869 | int retry_on_status = 20; |
1879 | more:{ | 1870 | more:{ |
1880 | int packet_bytes = 0; | 1871 | int packet_bytes = 0; |
1881 | int retval = usb_bulk_msg(ftdi->udev, | 1872 | int retval = usb_bulk_msg(ftdi->udev, |
1882 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), | 1873 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), |
1883 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, | 1874 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, |
1884 | &packet_bytes, 100); | 1875 | &packet_bytes, 100); |
1885 | if (packet_bytes > 2) { | 1876 | if (packet_bytes > 2) { |
1886 | char diag[30 *3 + 4]; | 1877 | char diag[30 *3 + 4]; |
1887 | char *d = diag; | 1878 | char *d = diag; |
1888 | int m = (sizeof(diag) - 1) / 3; | 1879 | int m = (sizeof(diag) - 1) / 3; |
1889 | char *b = ftdi->bulk_in_buffer; | 1880 | char *b = ftdi->bulk_in_buffer; |
1890 | int bytes_read = 0; | 1881 | int bytes_read = 0; |
1891 | diag[0] = 0; | 1882 | diag[0] = 0; |
1892 | while (packet_bytes-- > 0) { | 1883 | while (packet_bytes-- > 0) { |
1893 | char c = *b++; | 1884 | char c = *b++; |
1894 | if (bytes_read < m) { | 1885 | if (bytes_read < m) { |
1895 | d += sprintf(d, " %02X", | 1886 | d += sprintf(d, " %02X", |
1896 | 0x000000FF & c); | 1887 | 0x000000FF & c); |
1897 | } else if (bytes_read > m) { | 1888 | } else if (bytes_read > m) { |
1898 | } else | 1889 | } else |
1899 | d += sprintf(d, " .."); | 1890 | d += sprintf(d, " .."); |
1900 | bytes_read += 1; | 1891 | bytes_read += 1; |
1901 | continue; | 1892 | continue; |
1902 | } | 1893 | } |
1903 | goto more; | 1894 | goto more; |
1904 | } else if (packet_bytes > 1) { | 1895 | } else if (packet_bytes > 1) { |
1905 | char s1 = ftdi->bulk_in_buffer[0]; | 1896 | char s1 = ftdi->bulk_in_buffer[0]; |
1906 | char s2 = ftdi->bulk_in_buffer[1]; | 1897 | char s2 = ftdi->bulk_in_buffer[1]; |
1907 | if (s1 == 0x31 && s2 == 0x60) { | 1898 | if (s1 == 0x31 && s2 == 0x60) { |
1908 | return 0; | 1899 | return 0; |
1909 | } else if (retry_on_status-- > 0) { | 1900 | } else if (retry_on_status-- > 0) { |
1910 | goto more; | 1901 | goto more; |
1911 | } else { | 1902 | } else { |
1912 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry l" | 1903 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n"); |
1913 | "imit reached\n"); | 1904 | return -EFAULT; |
1914 | return -EFAULT; | 1905 | } |
1915 | } | 1906 | } else if (packet_bytes > 0) { |
1916 | } else if (packet_bytes > 0) { | 1907 | char b1 = ftdi->bulk_in_buffer[0]; |
1917 | char b1 = ftdi->bulk_in_buffer[0]; | 1908 | dev_err(&ftdi->udev->dev, "only one byte flushed from FTDI = %02X\n", |
1918 | dev_err(&ftdi->udev->dev, "only one byte flushed from F" | 1909 | b1); |
1919 | "TDI = %02X\n", b1); | 1910 | if (retry_on_status-- > 0) { |
1920 | if (retry_on_status-- > 0) { | 1911 | goto more; |
1921 | goto more; | 1912 | } else { |
1922 | } else { | 1913 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n"); |
1923 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry l" | 1914 | return -EFAULT; |
1924 | "imit reached\n"); | 1915 | } |
1925 | return -EFAULT; | 1916 | } else if (retval == -ETIMEDOUT) { |
1926 | } | 1917 | if (retry_on_timeout-- > 0) { |
1927 | } else if (retval == -ETIMEDOUT) { | 1918 | goto more; |
1928 | if (retry_on_timeout-- > 0) { | 1919 | } else { |
1929 | goto more; | 1920 | dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n"); |
1930 | } else { | 1921 | return -ENOMEM; |
1931 | dev_err(&ftdi->udev->dev, "TIMED OUT retry limi" | 1922 | } |
1932 | "t reached\n"); | 1923 | } else if (retval == 0) { |
1933 | return -ENOMEM; | 1924 | if (retry_on_empty-- > 0) { |
1934 | } | 1925 | goto more; |
1935 | } else if (retval == 0) { | 1926 | } else { |
1936 | if (retry_on_empty-- > 0) { | 1927 | dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n"); |
1937 | goto more; | 1928 | return -ENOMEM; |
1938 | } else { | 1929 | } |
1939 | dev_err(&ftdi->udev->dev, "empty packet retry l" | 1930 | } else { |
1940 | "imit reached\n"); | 1931 | dev_err(&ftdi->udev->dev, "error = %d\n", retval); |
1941 | return -ENOMEM; | 1932 | return retval; |
1942 | } | 1933 | } |
1943 | } else { | 1934 | } |
1944 | dev_err(&ftdi->udev->dev, "error = %d\n", retval); | 1935 | return -1; |
1945 | return retval; | ||
1946 | } | ||
1947 | } | ||
1948 | return -1; | ||
1949 | } | 1936 | } |
1950 | 1937 | ||
1951 | 1938 | ||
1952 | /* | 1939 | /* |
1953 | * send the long flush sequence | 1940 | * send the long flush sequence |
1954 | * | 1941 | * |
1955 | */ | 1942 | */ |
1956 | static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi) | 1943 | static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi) |
1957 | { | 1944 | { |
1958 | int retval; | 1945 | int retval; |
1959 | struct urb *urb; | 1946 | struct urb *urb; |
1960 | char *buf; | 1947 | char *buf; |
1961 | int I = 257; | 1948 | int I = 257; |
1962 | int i = 0; | 1949 | int i = 0; |
1963 | urb = usb_alloc_urb(0, GFP_KERNEL); | 1950 | urb = usb_alloc_urb(0, GFP_KERNEL); |
1964 | if (!urb) { | 1951 | if (!urb) { |
1965 | dev_err(&ftdi->udev->dev, "could not alloc a urb for flush sequ" | 1952 | dev_err(&ftdi->udev->dev, "could not alloc a urb for flush sequence\n"); |
1966 | "ence\n"); | 1953 | return -ENOMEM; |
1967 | return -ENOMEM; | 1954 | } |
1968 | } | 1955 | buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); |
1969 | buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); | 1956 | if (!buf) { |
1970 | if (!buf) { | 1957 | dev_err(&ftdi->udev->dev, "could not get a buffer for flush sequence\n"); |
1971 | dev_err(&ftdi->udev->dev, "could not get a buffer for flush seq" | 1958 | usb_free_urb(urb); |
1972 | "uence\n"); | 1959 | return -ENOMEM; |
1973 | usb_free_urb(urb); | 1960 | } |
1974 | return -ENOMEM; | 1961 | while (I-- > 0) |
1975 | } | 1962 | buf[i++] = 0x55; |
1976 | while (I-- > 0) | 1963 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, |
1977 | buf[i++] = 0x55; | 1964 | ftdi->bulk_out_endpointAddr), buf, i, |
1978 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, | 1965 | ftdi_elan_write_bulk_callback, ftdi); |
1979 | ftdi->bulk_out_endpointAddr), buf, i, | 1966 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1980 | ftdi_elan_write_bulk_callback, ftdi); | 1967 | retval = usb_submit_urb(urb, GFP_KERNEL); |
1981 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1968 | if (retval) { |
1982 | retval = usb_submit_urb(urb, GFP_KERNEL); | 1969 | dev_err(&ftdi->udev->dev, "failed to submit urb containing the flush sequence\n"); |
1983 | if (retval) { | 1970 | usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma); |
1984 | dev_err(&ftdi->udev->dev, "failed to submit urb containing the " | 1971 | usb_free_urb(urb); |
1985 | "flush sequence\n"); | 1972 | return -ENOMEM; |
1986 | usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma); | 1973 | } |
1987 | usb_free_urb(urb); | 1974 | usb_free_urb(urb); |
1988 | return -ENOMEM; | 1975 | return 0; |
1989 | } | ||
1990 | usb_free_urb(urb); | ||
1991 | return 0; | ||
1992 | } | 1976 | } |
1993 | 1977 | ||
1994 | 1978 | ||
1995 | /* | 1979 | /* |
1996 | * send the reset sequence | 1980 | * send the reset sequence |
1997 | * | 1981 | * |
1998 | */ | 1982 | */ |
1999 | static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi) | 1983 | static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi) |
2000 | { | 1984 | { |
2001 | int retval; | 1985 | int retval; |
2002 | struct urb *urb; | 1986 | struct urb *urb; |
2003 | char *buf; | 1987 | char *buf; |
2004 | int I = 4; | 1988 | int I = 4; |
2005 | int i = 0; | 1989 | int i = 0; |
2006 | urb = usb_alloc_urb(0, GFP_KERNEL); | 1990 | urb = usb_alloc_urb(0, GFP_KERNEL); |
2007 | if (!urb) { | 1991 | if (!urb) { |
2008 | dev_err(&ftdi->udev->dev, "could not get a urb for the reset se" | 1992 | dev_err(&ftdi->udev->dev, "could not get a urb for the reset sequence\n"); |
2009 | "quence\n"); | 1993 | return -ENOMEM; |
2010 | return -ENOMEM; | 1994 | } |
2011 | } | 1995 | buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); |
2012 | buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); | 1996 | if (!buf) { |
2013 | if (!buf) { | 1997 | dev_err(&ftdi->udev->dev, "could not get a buffer for the reset sequence\n"); |
2014 | dev_err(&ftdi->udev->dev, "could not get a buffer for the reset" | 1998 | usb_free_urb(urb); |
2015 | " sequence\n"); | 1999 | return -ENOMEM; |
2016 | usb_free_urb(urb); | 2000 | } |
2017 | return -ENOMEM; | 2001 | buf[i++] = 0x55; |
2018 | } | 2002 | buf[i++] = 0xAA; |
2019 | buf[i++] = 0x55; | 2003 | buf[i++] = 0x5A; |
2020 | buf[i++] = 0xAA; | 2004 | buf[i++] = 0xA5; |
2021 | buf[i++] = 0x5A; | 2005 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, |
2022 | buf[i++] = 0xA5; | 2006 | ftdi->bulk_out_endpointAddr), buf, i, |
2023 | usb_fill_bulk_urb(urb, ftdi->udev, usb_sndbulkpipe(ftdi->udev, | 2007 | ftdi_elan_write_bulk_callback, ftdi); |
2024 | ftdi->bulk_out_endpointAddr), buf, i, | 2008 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
2025 | ftdi_elan_write_bulk_callback, ftdi); | 2009 | retval = usb_submit_urb(urb, GFP_KERNEL); |
2026 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 2010 | if (retval) { |
2027 | retval = usb_submit_urb(urb, GFP_KERNEL); | 2011 | dev_err(&ftdi->udev->dev, "failed to submit urb containing the reset sequence\n"); |
2028 | if (retval) { | 2012 | usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma); |
2029 | dev_err(&ftdi->udev->dev, "failed to submit urb containing the " | 2013 | usb_free_urb(urb); |
2030 | "reset sequence\n"); | 2014 | return -ENOMEM; |
2031 | usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma); | 2015 | } |
2032 | usb_free_urb(urb); | 2016 | usb_free_urb(urb); |
2033 | return -ENOMEM; | 2017 | return 0; |
2034 | } | ||
2035 | usb_free_urb(urb); | ||
2036 | return 0; | ||
2037 | } | 2018 | } |
2038 | 2019 | ||
2039 | static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) | 2020 | static int ftdi_elan_synchronize(struct usb_ftdi *ftdi) |
2040 | { | 2021 | { |
2041 | int retval; | 2022 | int retval; |
2042 | int long_stop = 10; | 2023 | int long_stop = 10; |
2043 | int retry_on_timeout = 5; | 2024 | int retry_on_timeout = 5; |
2044 | int retry_on_empty = 10; | 2025 | int retry_on_empty = 10; |
2045 | int err_count = 0; | 2026 | int err_count = 0; |
2046 | retval = ftdi_elan_flush_input_fifo(ftdi); | 2027 | retval = ftdi_elan_flush_input_fifo(ftdi); |
2047 | if (retval) | 2028 | if (retval) |
2048 | return retval; | 2029 | return retval; |
2049 | ftdi->bulk_in_left = 0; | 2030 | ftdi->bulk_in_left = 0; |
2050 | ftdi->bulk_in_last = -1; | 2031 | ftdi->bulk_in_last = -1; |
2051 | while (long_stop-- > 0) { | 2032 | while (long_stop-- > 0) { |
2052 | int read_stop; | 2033 | int read_stop; |
2053 | int read_stuck; | 2034 | int read_stuck; |
2054 | retval = ftdi_elan_synchronize_flush(ftdi); | 2035 | retval = ftdi_elan_synchronize_flush(ftdi); |
2055 | if (retval) | 2036 | if (retval) |
2056 | return retval; | 2037 | return retval; |
2057 | retval = ftdi_elan_flush_input_fifo(ftdi); | 2038 | retval = ftdi_elan_flush_input_fifo(ftdi); |
2058 | if (retval) | 2039 | if (retval) |
2059 | return retval; | 2040 | return retval; |
2060 | reset:retval = ftdi_elan_synchronize_reset(ftdi); | 2041 | reset:retval = ftdi_elan_synchronize_reset(ftdi); |
2061 | if (retval) | 2042 | if (retval) |
2062 | return retval; | 2043 | return retval; |
2063 | read_stop = 100; | 2044 | read_stop = 100; |
2064 | read_stuck = 10; | 2045 | read_stuck = 10; |
2065 | read:{ | 2046 | read:{ |
2066 | int packet_bytes = 0; | 2047 | int packet_bytes = 0; |
2067 | retval = usb_bulk_msg(ftdi->udev, | 2048 | retval = usb_bulk_msg(ftdi->udev, |
2068 | usb_rcvbulkpipe(ftdi->udev, | 2049 | usb_rcvbulkpipe(ftdi->udev, |
2069 | ftdi->bulk_in_endpointAddr), | 2050 | ftdi->bulk_in_endpointAddr), |
2070 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, | 2051 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, |
2071 | &packet_bytes, 500); | 2052 | &packet_bytes, 500); |
2072 | if (packet_bytes > 2) { | 2053 | if (packet_bytes > 2) { |
2073 | char diag[30 *3 + 4]; | 2054 | char diag[30 *3 + 4]; |
2074 | char *d = diag; | 2055 | char *d = diag; |
2075 | int m = (sizeof(diag) - 1) / 3; | 2056 | int m = (sizeof(diag) - 1) / 3; |
2076 | char *b = ftdi->bulk_in_buffer; | 2057 | char *b = ftdi->bulk_in_buffer; |
2077 | int bytes_read = 0; | 2058 | int bytes_read = 0; |
2078 | unsigned char c = 0; | 2059 | unsigned char c = 0; |
2079 | diag[0] = 0; | 2060 | diag[0] = 0; |
2080 | while (packet_bytes-- > 0) { | 2061 | while (packet_bytes-- > 0) { |
2081 | c = *b++; | 2062 | c = *b++; |
2082 | if (bytes_read < m) { | 2063 | if (bytes_read < m) { |
2083 | d += sprintf(d, " %02X", c); | 2064 | d += sprintf(d, " %02X", c); |
2084 | } else if (bytes_read > m) { | 2065 | } else if (bytes_read > m) { |
2085 | } else | 2066 | } else |
2086 | d += sprintf(d, " .."); | 2067 | d += sprintf(d, " .."); |
2087 | bytes_read += 1; | 2068 | bytes_read += 1; |
2088 | continue; | 2069 | continue; |
2089 | } | 2070 | } |
2090 | if (c == 0x7E) { | 2071 | if (c == 0x7E) { |
2091 | return 0; | 2072 | return 0; |
2092 | } else { | 2073 | } else { |
2093 | if (c == 0x55) { | 2074 | if (c == 0x55) { |
2094 | goto read; | 2075 | goto read; |
2095 | } else if (read_stop-- > 0) { | 2076 | } else if (read_stop-- > 0) { |
2096 | goto read; | 2077 | goto read; |
2097 | } else { | 2078 | } else { |
2098 | dev_err(&ftdi->udev->dev, "retr" | 2079 | dev_err(&ftdi->udev->dev, "retry limit reached\n"); |
2099 | "y limit reached\n"); | 2080 | continue; |
2100 | continue; | 2081 | } |
2101 | } | 2082 | } |
2102 | } | 2083 | } else if (packet_bytes > 1) { |
2103 | } else if (packet_bytes > 1) { | 2084 | unsigned char s1 = ftdi->bulk_in_buffer[0]; |
2104 | unsigned char s1 = ftdi->bulk_in_buffer[0]; | 2085 | unsigned char s2 = ftdi->bulk_in_buffer[1]; |
2105 | unsigned char s2 = ftdi->bulk_in_buffer[1]; | 2086 | if (s1 == 0x31 && s2 == 0x00) { |
2106 | if (s1 == 0x31 && s2 == 0x00) { | 2087 | if (read_stuck-- > 0) { |
2107 | if (read_stuck-- > 0) { | 2088 | goto read; |
2108 | goto read; | 2089 | } else |
2109 | } else | 2090 | goto reset; |
2110 | goto reset; | 2091 | } else if (s1 == 0x31 && s2 == 0x60) { |
2111 | } else if (s1 == 0x31 && s2 == 0x60) { | 2092 | if (read_stop-- > 0) { |
2112 | if (read_stop-- > 0) { | 2093 | goto read; |
2113 | goto read; | 2094 | } else { |
2114 | } else { | 2095 | dev_err(&ftdi->udev->dev, "retry limit reached\n"); |
2115 | dev_err(&ftdi->udev->dev, "retr" | 2096 | continue; |
2116 | "y limit reached\n"); | 2097 | } |
2117 | continue; | 2098 | } else { |
2118 | } | 2099 | if (read_stop-- > 0) { |
2119 | } else { | 2100 | goto read; |
2120 | if (read_stop-- > 0) { | 2101 | } else { |
2121 | goto read; | 2102 | dev_err(&ftdi->udev->dev, "retry limit reached\n"); |
2122 | } else { | 2103 | continue; |
2123 | dev_err(&ftdi->udev->dev, "retr" | 2104 | } |
2124 | "y limit reached\n"); | 2105 | } |
2125 | continue; | 2106 | } else if (packet_bytes > 0) { |
2126 | } | 2107 | if (read_stop-- > 0) { |
2127 | } | 2108 | goto read; |
2128 | } else if (packet_bytes > 0) { | 2109 | } else { |
2129 | if (read_stop-- > 0) { | 2110 | dev_err(&ftdi->udev->dev, "retry limit reached\n"); |
2130 | goto read; | 2111 | continue; |
2131 | } else { | 2112 | } |
2132 | dev_err(&ftdi->udev->dev, "retry limit " | 2113 | } else if (retval == -ETIMEDOUT) { |
2133 | "reached\n"); | 2114 | if (retry_on_timeout-- > 0) { |
2134 | continue; | 2115 | goto read; |
2135 | } | 2116 | } else { |
2136 | } else if (retval == -ETIMEDOUT) { | 2117 | dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n"); |
2137 | if (retry_on_timeout-- > 0) { | 2118 | continue; |
2138 | goto read; | 2119 | } |
2139 | } else { | 2120 | } else if (retval == 0) { |
2140 | dev_err(&ftdi->udev->dev, "TIMED OUT re" | 2121 | if (retry_on_empty-- > 0) { |
2141 | "try limit reached\n"); | 2122 | goto read; |
2142 | continue; | 2123 | } else { |
2143 | } | 2124 | dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n"); |
2144 | } else if (retval == 0) { | 2125 | continue; |
2145 | if (retry_on_empty-- > 0) { | 2126 | } |
2146 | goto read; | 2127 | } else { |
2147 | } else { | 2128 | err_count += 1; |
2148 | dev_err(&ftdi->udev->dev, "empty packet" | 2129 | dev_err(&ftdi->udev->dev, "error = %d\n", |
2149 | " retry limit reached\n"); | 2130 | retval); |
2150 | continue; | 2131 | if (read_stop-- > 0) { |
2151 | } | 2132 | goto read; |
2152 | } else { | 2133 | } else { |
2153 | err_count += 1; | 2134 | dev_err(&ftdi->udev->dev, "retry limit reached\n"); |
2154 | dev_err(&ftdi->udev->dev, "error = %d\n", | 2135 | continue; |
2155 | retval); | 2136 | } |
2156 | if (read_stop-- > 0) { | 2137 | } |
2157 | goto read; | 2138 | } |
2158 | } else { | 2139 | } |
2159 | dev_err(&ftdi->udev->dev, "retry limit " | 2140 | dev_err(&ftdi->udev->dev, "failed to synchronize\n"); |
2160 | "reached\n"); | 2141 | return -EFAULT; |
2161 | continue; | ||
2162 | } | ||
2163 | } | ||
2164 | } | ||
2165 | } | ||
2166 | dev_err(&ftdi->udev->dev, "failed to synchronize\n"); | ||
2167 | return -EFAULT; | ||
2168 | } | 2142 | } |
2169 | 2143 | ||
2170 | static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi) | 2144 | static int ftdi_elan_stuck_waiting(struct usb_ftdi *ftdi) |
2171 | { | 2145 | { |
2172 | int retry_on_empty = 10; | 2146 | int retry_on_empty = 10; |
2173 | int retry_on_timeout = 5; | 2147 | int retry_on_timeout = 5; |
2174 | int retry_on_status = 50; | 2148 | int retry_on_status = 50; |
2175 | more:{ | 2149 | more:{ |
2176 | int packet_bytes = 0; | 2150 | int packet_bytes = 0; |
2177 | int retval = usb_bulk_msg(ftdi->udev, | 2151 | int retval = usb_bulk_msg(ftdi->udev, |
2178 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), | 2152 | usb_rcvbulkpipe(ftdi->udev, ftdi->bulk_in_endpointAddr), |
2179 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, | 2153 | ftdi->bulk_in_buffer, ftdi->bulk_in_size, |
2180 | &packet_bytes, 1000); | 2154 | &packet_bytes, 1000); |
2181 | if (packet_bytes > 2) { | 2155 | if (packet_bytes > 2) { |
2182 | char diag[30 *3 + 4]; | 2156 | char diag[30 *3 + 4]; |
2183 | char *d = diag; | 2157 | char *d = diag; |
2184 | int m = (sizeof(diag) - 1) / 3; | 2158 | int m = (sizeof(diag) - 1) / 3; |
2185 | char *b = ftdi->bulk_in_buffer; | 2159 | char *b = ftdi->bulk_in_buffer; |
2186 | int bytes_read = 0; | 2160 | int bytes_read = 0; |
2187 | diag[0] = 0; | 2161 | diag[0] = 0; |
2188 | while (packet_bytes-- > 0) { | 2162 | while (packet_bytes-- > 0) { |
2189 | char c = *b++; | 2163 | char c = *b++; |
2190 | if (bytes_read < m) { | 2164 | if (bytes_read < m) { |
2191 | d += sprintf(d, " %02X", | 2165 | d += sprintf(d, " %02X", |
2192 | 0x000000FF & c); | 2166 | 0x000000FF & c); |
2193 | } else if (bytes_read > m) { | 2167 | } else if (bytes_read > m) { |
2194 | } else | 2168 | } else |
2195 | d += sprintf(d, " .."); | 2169 | d += sprintf(d, " .."); |
2196 | bytes_read += 1; | 2170 | bytes_read += 1; |
2197 | continue; | 2171 | continue; |
2198 | } | 2172 | } |
2199 | goto more; | 2173 | goto more; |
2200 | } else if (packet_bytes > 1) { | 2174 | } else if (packet_bytes > 1) { |
2201 | char s1 = ftdi->bulk_in_buffer[0]; | 2175 | char s1 = ftdi->bulk_in_buffer[0]; |
2202 | char s2 = ftdi->bulk_in_buffer[1]; | 2176 | char s2 = ftdi->bulk_in_buffer[1]; |
2203 | if (s1 == 0x31 && s2 == 0x60) { | 2177 | if (s1 == 0x31 && s2 == 0x60) { |
2204 | return 0; | 2178 | return 0; |
2205 | } else if (retry_on_status-- > 0) { | 2179 | } else if (retry_on_status-- > 0) { |
2206 | msleep(5); | 2180 | msleep(5); |
2207 | goto more; | 2181 | goto more; |
2208 | } else | 2182 | } else |
2209 | return -EFAULT; | 2183 | return -EFAULT; |
2210 | } else if (packet_bytes > 0) { | 2184 | } else if (packet_bytes > 0) { |
2211 | char b1 = ftdi->bulk_in_buffer[0]; | 2185 | char b1 = ftdi->bulk_in_buffer[0]; |
2212 | dev_err(&ftdi->udev->dev, "only one byte flushed from F" | 2186 | dev_err(&ftdi->udev->dev, "only one byte flushed from FTDI = %02X\n", b1); |
2213 | "TDI = %02X\n", b1); | 2187 | if (retry_on_status-- > 0) { |
2214 | if (retry_on_status-- > 0) { | 2188 | msleep(5); |
2215 | msleep(5); | 2189 | goto more; |
2216 | goto more; | 2190 | } else { |
2217 | } else { | 2191 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry limit reached\n"); |
2218 | dev_err(&ftdi->udev->dev, "STATUS ERROR retry l" | 2192 | return -EFAULT; |
2219 | "imit reached\n"); | 2193 | } |
2220 | return -EFAULT; | 2194 | } else if (retval == -ETIMEDOUT) { |
2221 | } | 2195 | if (retry_on_timeout-- > 0) { |
2222 | } else if (retval == -ETIMEDOUT) { | 2196 | goto more; |
2223 | if (retry_on_timeout-- > 0) { | 2197 | } else { |
2224 | goto more; | 2198 | dev_err(&ftdi->udev->dev, "TIMED OUT retry limit reached\n"); |
2225 | } else { | 2199 | return -ENOMEM; |
2226 | dev_err(&ftdi->udev->dev, "TIMED OUT retry limi" | 2200 | } |
2227 | "t reached\n"); | 2201 | } else if (retval == 0) { |
2228 | return -ENOMEM; | 2202 | if (retry_on_empty-- > 0) { |
2229 | } | 2203 | goto more; |
2230 | } else if (retval == 0) { | 2204 | } else { |
2231 | if (retry_on_empty-- > 0) { | 2205 | dev_err(&ftdi->udev->dev, "empty packet retry limit reached\n"); |
2232 | goto more; | 2206 | return -ENOMEM; |
2233 | } else { | 2207 | } |
2234 | dev_err(&ftdi->udev->dev, "empty packet retry l" | 2208 | } else { |
2235 | "imit reached\n"); | 2209 | dev_err(&ftdi->udev->dev, "error = %d\n", retval); |
2236 | return -ENOMEM; | 2210 | return -ENOMEM; |
2237 | } | 2211 | } |
2238 | } else { | 2212 | } |
2239 | dev_err(&ftdi->udev->dev, "error = %d\n", retval); | 2213 | return -1; |
2240 | return -ENOMEM; | ||
2241 | } | ||
2242 | } | ||
2243 | return -1; | ||
2244 | } | 2214 | } |
2245 | 2215 | ||
2246 | static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi) | 2216 | static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi) |
2247 | { | 2217 | { |
2248 | int UxxxStatus = ftdi_elan_read_reg(ftdi, &ftdi->controlreg); | 2218 | int UxxxStatus = ftdi_elan_read_reg(ftdi, &ftdi->controlreg); |
2249 | if (UxxxStatus) | 2219 | if (UxxxStatus) |
2250 | return UxxxStatus; | 2220 | return UxxxStatus; |
2251 | if (ftdi->controlreg & 0x00400000) { | 2221 | if (ftdi->controlreg & 0x00400000) { |
2252 | if (ftdi->card_ejected) { | 2222 | if (ftdi->card_ejected) { |
2253 | } else { | 2223 | } else { |
2254 | ftdi->card_ejected = 1; | 2224 | ftdi->card_ejected = 1; |
2255 | dev_err(&ftdi->udev->dev, "CARD EJECTED - controlreg = " | 2225 | dev_err(&ftdi->udev->dev, "CARD EJECTED - controlreg = %08X\n", |
2256 | "%08X\n", ftdi->controlreg); | 2226 | ftdi->controlreg); |
2257 | } | 2227 | } |
2258 | return -ENODEV; | 2228 | return -ENODEV; |
2259 | } else { | 2229 | } else { |
2260 | u8 fn = ftdi->function - 1; | 2230 | u8 fn = ftdi->function - 1; |
2261 | int activePCIfn = fn << 8; | 2231 | int activePCIfn = fn << 8; |
2262 | u32 pcidata; | 2232 | u32 pcidata; |
2263 | u32 pciVID; | 2233 | u32 pciVID; |
2264 | u32 pciPID; | 2234 | u32 pciPID; |
2265 | int reg = 0; | 2235 | int reg = 0; |
2266 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2236 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2267 | &pcidata); | 2237 | &pcidata); |
2268 | if (UxxxStatus) | 2238 | if (UxxxStatus) |
2269 | return UxxxStatus; | 2239 | return UxxxStatus; |
2270 | pciVID = pcidata & 0xFFFF; | 2240 | pciVID = pcidata & 0xFFFF; |
2271 | pciPID = (pcidata >> 16) & 0xFFFF; | 2241 | pciPID = (pcidata >> 16) & 0xFFFF; |
2272 | if (pciVID == ftdi->platform_data.vendor && pciPID == | 2242 | if (pciVID == ftdi->platform_data.vendor && pciPID == |
2273 | ftdi->platform_data.device) { | 2243 | ftdi->platform_data.device) { |
2274 | return 0; | 2244 | return 0; |
2275 | } else { | 2245 | } else { |
2276 | dev_err(&ftdi->udev->dev, "vendor=%04X pciVID=%04X devi" | 2246 | dev_err(&ftdi->udev->dev, "vendor=%04X pciVID=%04X device=%04X pciPID=%04X\n", |
2277 | "ce=%04X pciPID=%04X\n", | 2247 | ftdi->platform_data.vendor, pciVID, |
2278 | ftdi->platform_data.vendor, pciVID, | 2248 | ftdi->platform_data.device, pciPID); |
2279 | ftdi->platform_data.device, pciPID); | 2249 | return -ENODEV; |
2280 | return -ENODEV; | 2250 | } |
2281 | } | 2251 | } |
2282 | } | ||
2283 | } | 2252 | } |
2284 | 2253 | ||
2285 | 2254 | ||
2286 | #define ftdi_read_pcimem(ftdi, member, data) ftdi_elan_read_pcimem(ftdi, \ | 2255 | #define ftdi_read_pcimem(ftdi, member, data) ftdi_elan_read_pcimem(ftdi, \ |
2287 | offsetof(struct ohci_regs, member), 0, data); | 2256 | offsetof(struct ohci_regs, member), 0, data); |
2288 | #define ftdi_write_pcimem(ftdi, member, data) ftdi_elan_write_pcimem(ftdi, \ | 2257 | #define ftdi_write_pcimem(ftdi, member, data) ftdi_elan_write_pcimem(ftdi, \ |
2289 | offsetof(struct ohci_regs, member), 0, data); | 2258 | offsetof(struct ohci_regs, member), 0, data); |
2290 | 2259 | ||
2291 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR | 2260 | #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR |
2292 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ | 2261 | #define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ |
2293 | OHCI_INTR_WDH) | 2262 | OHCI_INTR_WDH) |
2294 | static int ftdi_elan_check_controller(struct usb_ftdi *ftdi, int quirk) | 2263 | static int ftdi_elan_check_controller(struct usb_ftdi *ftdi, int quirk) |
2295 | { | 2264 | { |
2296 | int devices = 0; | 2265 | int devices = 0; |
2297 | int retval; | 2266 | int retval; |
2298 | u32 hc_control; | 2267 | u32 hc_control; |
2299 | int num_ports; | 2268 | int num_ports; |
2300 | u32 control; | 2269 | u32 control; |
2301 | u32 rh_a = -1; | 2270 | u32 rh_a = -1; |
2302 | u32 status; | 2271 | u32 status; |
2303 | u32 fminterval; | 2272 | u32 fminterval; |
2304 | u32 hc_fminterval; | 2273 | u32 hc_fminterval; |
2305 | u32 periodicstart; | 2274 | u32 periodicstart; |
2306 | u32 cmdstatus; | 2275 | u32 cmdstatus; |
2307 | u32 roothub_a; | 2276 | u32 roothub_a; |
2308 | int mask = OHCI_INTR_INIT; | 2277 | int mask = OHCI_INTR_INIT; |
2309 | int sleep_time = 0; | 2278 | int sleep_time = 0; |
2310 | int reset_timeout = 30; /* ... allow extra time */ | 2279 | int reset_timeout = 30; /* ... allow extra time */ |
2311 | int temp; | 2280 | int temp; |
2312 | retval = ftdi_write_pcimem(ftdi, intrdisable, OHCI_INTR_MIE); | 2281 | retval = ftdi_write_pcimem(ftdi, intrdisable, OHCI_INTR_MIE); |
2313 | if (retval) | 2282 | if (retval) |
2314 | return retval; | 2283 | return retval; |
2315 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2284 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2316 | if (retval) | 2285 | if (retval) |
2317 | return retval; | 2286 | return retval; |
2318 | retval = ftdi_read_pcimem(ftdi, roothub.a, &rh_a); | 2287 | retval = ftdi_read_pcimem(ftdi, roothub.a, &rh_a); |
2319 | if (retval) | 2288 | if (retval) |
2320 | return retval; | 2289 | return retval; |
2321 | num_ports = rh_a & RH_A_NDP; | 2290 | num_ports = rh_a & RH_A_NDP; |
2322 | retval = ftdi_read_pcimem(ftdi, fminterval, &hc_fminterval); | 2291 | retval = ftdi_read_pcimem(ftdi, fminterval, &hc_fminterval); |
2323 | if (retval) | 2292 | if (retval) |
2324 | return retval; | 2293 | return retval; |
2325 | hc_fminterval &= 0x3fff; | 2294 | hc_fminterval &= 0x3fff; |
2326 | if (hc_fminterval != FI) { | 2295 | if (hc_fminterval != FI) { |
2327 | } | 2296 | } |
2328 | hc_fminterval |= FSMP(hc_fminterval) << 16; | 2297 | hc_fminterval |= FSMP(hc_fminterval) << 16; |
2329 | retval = ftdi_read_pcimem(ftdi, control, &hc_control); | 2298 | retval = ftdi_read_pcimem(ftdi, control, &hc_control); |
2330 | if (retval) | 2299 | if (retval) |
2331 | return retval; | 2300 | return retval; |
2332 | switch (hc_control & OHCI_CTRL_HCFS) { | 2301 | switch (hc_control & OHCI_CTRL_HCFS) { |
2333 | case OHCI_USB_OPER: | 2302 | case OHCI_USB_OPER: |
2334 | sleep_time = 0; | 2303 | sleep_time = 0; |
2335 | break; | 2304 | break; |
2336 | case OHCI_USB_SUSPEND: | 2305 | case OHCI_USB_SUSPEND: |
2337 | case OHCI_USB_RESUME: | 2306 | case OHCI_USB_RESUME: |
2338 | hc_control &= OHCI_CTRL_RWC; | 2307 | hc_control &= OHCI_CTRL_RWC; |
2339 | hc_control |= OHCI_USB_RESUME; | 2308 | hc_control |= OHCI_USB_RESUME; |
2340 | sleep_time = 10; | 2309 | sleep_time = 10; |
2341 | break; | 2310 | break; |
2342 | default: | 2311 | default: |
2343 | hc_control &= OHCI_CTRL_RWC; | 2312 | hc_control &= OHCI_CTRL_RWC; |
2344 | hc_control |= OHCI_USB_RESET; | 2313 | hc_control |= OHCI_USB_RESET; |
2345 | sleep_time = 50; | 2314 | sleep_time = 50; |
2346 | break; | 2315 | break; |
2347 | } | 2316 | } |
2348 | retval = ftdi_write_pcimem(ftdi, control, hc_control); | 2317 | retval = ftdi_write_pcimem(ftdi, control, hc_control); |
2349 | if (retval) | 2318 | if (retval) |
2350 | return retval; | 2319 | return retval; |
2351 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2320 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2352 | if (retval) | 2321 | if (retval) |
2353 | return retval; | 2322 | return retval; |
2354 | msleep(sleep_time); | 2323 | msleep(sleep_time); |
2355 | retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a); | 2324 | retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a); |
2356 | if (retval) | 2325 | if (retval) |
2357 | return retval; | 2326 | return retval; |
2358 | if (!(roothub_a & RH_A_NPS)) { /* power down each port */ | 2327 | if (!(roothub_a & RH_A_NPS)) { /* power down each port */ |
2359 | for (temp = 0; temp < num_ports; temp++) { | 2328 | for (temp = 0; temp < num_ports; temp++) { |
2360 | retval = ftdi_write_pcimem(ftdi, | 2329 | retval = ftdi_write_pcimem(ftdi, |
2361 | roothub.portstatus[temp], RH_PS_LSDA); | 2330 | roothub.portstatus[temp], RH_PS_LSDA); |
2362 | if (retval) | 2331 | if (retval) |
2363 | return retval; | 2332 | return retval; |
2364 | } | 2333 | } |
2365 | } | 2334 | } |
2366 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2335 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2367 | if (retval) | 2336 | if (retval) |
2368 | return retval; | 2337 | return retval; |
2369 | retry:retval = ftdi_read_pcimem(ftdi, cmdstatus, &status); | 2338 | retry:retval = ftdi_read_pcimem(ftdi, cmdstatus, &status); |
2370 | if (retval) | 2339 | if (retval) |
2371 | return retval; | 2340 | return retval; |
2372 | retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_HCR); | 2341 | retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_HCR); |
2373 | if (retval) | 2342 | if (retval) |
2374 | return retval; | 2343 | return retval; |
2375 | extra:{ | 2344 | extra:{ |
2376 | retval = ftdi_read_pcimem(ftdi, cmdstatus, &status); | 2345 | retval = ftdi_read_pcimem(ftdi, cmdstatus, &status); |
2377 | if (retval) | 2346 | if (retval) |
2378 | return retval; | 2347 | return retval; |
2379 | if (0 != (status & OHCI_HCR)) { | 2348 | if (0 != (status & OHCI_HCR)) { |
2380 | if (--reset_timeout == 0) { | 2349 | if (--reset_timeout == 0) { |
2381 | dev_err(&ftdi->udev->dev, "USB HC reset timed o" | 2350 | dev_err(&ftdi->udev->dev, "USB HC reset timed out!\n"); |
2382 | "ut!\n"); | 2351 | return -ENODEV; |
2383 | return -ENODEV; | 2352 | } else { |
2384 | } else { | 2353 | msleep(5); |
2385 | msleep(5); | 2354 | goto extra; |
2386 | goto extra; | 2355 | } |
2387 | } | 2356 | } |
2388 | } | 2357 | } |
2389 | } | 2358 | if (quirk & OHCI_QUIRK_INITRESET) { |
2390 | if (quirk & OHCI_QUIRK_INITRESET) { | 2359 | retval = ftdi_write_pcimem(ftdi, control, hc_control); |
2391 | retval = ftdi_write_pcimem(ftdi, control, hc_control); | 2360 | if (retval) |
2392 | if (retval) | 2361 | return retval; |
2393 | return retval; | 2362 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2394 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2363 | if (retval) |
2395 | if (retval) | 2364 | return retval; |
2396 | return retval; | 2365 | } |
2397 | } | 2366 | retval = ftdi_write_pcimem(ftdi, ed_controlhead, 0x00000000); |
2398 | retval = ftdi_write_pcimem(ftdi, ed_controlhead, 0x00000000); | 2367 | if (retval) |
2399 | if (retval) | 2368 | return retval; |
2400 | return retval; | 2369 | retval = ftdi_write_pcimem(ftdi, ed_bulkhead, 0x11000000); |
2401 | retval = ftdi_write_pcimem(ftdi, ed_bulkhead, 0x11000000); | 2370 | if (retval) |
2402 | if (retval) | 2371 | return retval; |
2403 | return retval; | 2372 | retval = ftdi_write_pcimem(ftdi, hcca, 0x00000000); |
2404 | retval = ftdi_write_pcimem(ftdi, hcca, 0x00000000); | 2373 | if (retval) |
2405 | if (retval) | 2374 | return retval; |
2406 | return retval; | 2375 | retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval); |
2407 | retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval); | 2376 | if (retval) |
2408 | if (retval) | 2377 | return retval; |
2409 | return retval; | 2378 | retval = ftdi_write_pcimem(ftdi, fminterval, |
2410 | retval = ftdi_write_pcimem(ftdi, fminterval, | 2379 | ((fminterval & FIT) ^ FIT) | hc_fminterval); |
2411 | ((fminterval & FIT) ^ FIT) | hc_fminterval); | 2380 | if (retval) |
2412 | if (retval) | 2381 | return retval; |
2413 | return retval; | 2382 | retval = ftdi_write_pcimem(ftdi, periodicstart, |
2414 | retval = ftdi_write_pcimem(ftdi, periodicstart, | 2383 | ((9 *hc_fminterval) / 10) & 0x3fff); |
2415 | ((9 *hc_fminterval) / 10) & 0x3fff); | 2384 | if (retval) |
2416 | if (retval) | 2385 | return retval; |
2417 | return retval; | 2386 | retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval); |
2418 | retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval); | 2387 | if (retval) |
2419 | if (retval) | 2388 | return retval; |
2420 | return retval; | 2389 | retval = ftdi_read_pcimem(ftdi, periodicstart, &periodicstart); |
2421 | retval = ftdi_read_pcimem(ftdi, periodicstart, &periodicstart); | 2390 | if (retval) |
2422 | if (retval) | 2391 | return retval; |
2423 | return retval; | 2392 | if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { |
2424 | if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { | 2393 | if (!(quirk & OHCI_QUIRK_INITRESET)) { |
2425 | if (!(quirk & OHCI_QUIRK_INITRESET)) { | 2394 | quirk |= OHCI_QUIRK_INITRESET; |
2426 | quirk |= OHCI_QUIRK_INITRESET; | 2395 | goto retry; |
2427 | goto retry; | 2396 | } else |
2428 | } else | 2397 | dev_err(&ftdi->udev->dev, "init err(%08x %04x)\n", |
2429 | dev_err(&ftdi->udev->dev, "init err(%08x %04x)\n", | 2398 | fminterval, periodicstart); |
2430 | fminterval, periodicstart); | 2399 | } /* start controller operations */ |
2431 | } /* start controller operations */ | 2400 | hc_control &= OHCI_CTRL_RWC; |
2432 | hc_control &= OHCI_CTRL_RWC; | 2401 | hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; |
2433 | hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; | 2402 | retval = ftdi_write_pcimem(ftdi, control, hc_control); |
2434 | retval = ftdi_write_pcimem(ftdi, control, hc_control); | 2403 | if (retval) |
2435 | if (retval) | 2404 | return retval; |
2436 | return retval; | 2405 | retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_BLF); |
2437 | retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_BLF); | 2406 | if (retval) |
2438 | if (retval) | 2407 | return retval; |
2439 | return retval; | 2408 | retval = ftdi_read_pcimem(ftdi, cmdstatus, &cmdstatus); |
2440 | retval = ftdi_read_pcimem(ftdi, cmdstatus, &cmdstatus); | 2409 | if (retval) |
2441 | if (retval) | 2410 | return retval; |
2442 | return retval; | 2411 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2443 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2412 | if (retval) |
2444 | if (retval) | 2413 | return retval; |
2445 | return retval; | 2414 | retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_DRWE); |
2446 | retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_DRWE); | 2415 | if (retval) |
2447 | if (retval) | 2416 | return retval; |
2448 | return retval; | 2417 | retval = ftdi_write_pcimem(ftdi, intrstatus, mask); |
2449 | retval = ftdi_write_pcimem(ftdi, intrstatus, mask); | 2418 | if (retval) |
2450 | if (retval) | 2419 | return retval; |
2451 | return retval; | 2420 | retval = ftdi_write_pcimem(ftdi, intrdisable, |
2452 | retval = ftdi_write_pcimem(ftdi, intrdisable, | 2421 | OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | |
2453 | OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | | 2422 | OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | |
2454 | OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | | 2423 | OHCI_INTR_SO); |
2455 | OHCI_INTR_SO); | 2424 | if (retval) |
2456 | if (retval) | 2425 | return retval; /* handle root hub init quirks ... */ |
2457 | return retval; /* handle root hub init quirks ... */ | 2426 | retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a); |
2458 | retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a); | 2427 | if (retval) |
2459 | if (retval) | 2428 | return retval; |
2460 | return retval; | 2429 | roothub_a &= ~(RH_A_PSM | RH_A_OCPM); |
2461 | roothub_a &= ~(RH_A_PSM | RH_A_OCPM); | 2430 | if (quirk & OHCI_QUIRK_SUPERIO) { |
2462 | if (quirk & OHCI_QUIRK_SUPERIO) { | 2431 | roothub_a |= RH_A_NOCP; |
2463 | roothub_a |= RH_A_NOCP; | 2432 | roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); |
2464 | roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); | 2433 | retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a); |
2465 | retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a); | 2434 | if (retval) |
2466 | if (retval) | 2435 | return retval; |
2467 | return retval; | 2436 | } else if ((quirk & OHCI_QUIRK_AMD756) || distrust_firmware) { |
2468 | } else if ((quirk & OHCI_QUIRK_AMD756) || distrust_firmware) { | 2437 | roothub_a |= RH_A_NPS; |
2469 | roothub_a |= RH_A_NPS; | 2438 | retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a); |
2470 | retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a); | 2439 | if (retval) |
2471 | if (retval) | 2440 | return retval; |
2472 | return retval; | 2441 | } |
2473 | } | 2442 | retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_LPSC); |
2474 | retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_LPSC); | 2443 | if (retval) |
2475 | if (retval) | 2444 | return retval; |
2476 | return retval; | 2445 | retval = ftdi_write_pcimem(ftdi, roothub.b, |
2477 | retval = ftdi_write_pcimem(ftdi, roothub.b, | 2446 | (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); |
2478 | (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); | 2447 | if (retval) |
2479 | if (retval) | 2448 | return retval; |
2480 | return retval; | 2449 | retval = ftdi_read_pcimem(ftdi, control, &control); |
2481 | retval = ftdi_read_pcimem(ftdi, control, &control); | 2450 | if (retval) |
2482 | if (retval) | 2451 | return retval; |
2483 | return retval; | 2452 | mdelay((roothub_a >> 23) & 0x1fe); |
2484 | mdelay((roothub_a >> 23) & 0x1fe); | 2453 | for (temp = 0; temp < num_ports; temp++) { |
2485 | for (temp = 0; temp < num_ports; temp++) { | 2454 | u32 portstatus; |
2486 | u32 portstatus; | 2455 | retval = ftdi_read_pcimem(ftdi, roothub.portstatus[temp], |
2487 | retval = ftdi_read_pcimem(ftdi, roothub.portstatus[temp], | 2456 | &portstatus); |
2488 | &portstatus); | 2457 | if (retval) |
2489 | if (retval) | 2458 | return retval; |
2490 | return retval; | 2459 | if (1 & portstatus) |
2491 | if (1 & portstatus) | 2460 | devices += 1; |
2492 | devices += 1; | 2461 | } |
2493 | } | 2462 | return devices; |
2494 | return devices; | ||
2495 | } | 2463 | } |
2496 | 2464 | ||
2497 | static int ftdi_elan_setup_controller(struct usb_ftdi *ftdi, int fn) | 2465 | static int ftdi_elan_setup_controller(struct usb_ftdi *ftdi, int fn) |
2498 | { | 2466 | { |
2499 | u32 latence_timer; | 2467 | u32 latence_timer; |
2500 | int UxxxStatus; | 2468 | int UxxxStatus; |
2501 | u32 pcidata; | 2469 | u32 pcidata; |
2502 | int reg = 0; | 2470 | int reg = 0; |
2503 | int activePCIfn = fn << 8; | 2471 | int activePCIfn = fn << 8; |
2504 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); | 2472 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); |
2505 | if (UxxxStatus) | 2473 | if (UxxxStatus) |
2506 | return UxxxStatus; | 2474 | return UxxxStatus; |
2507 | reg = 16; | 2475 | reg = 16; |
2508 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, | 2476 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, |
2509 | 0xFFFFFFFF); | 2477 | 0xFFFFFFFF); |
2510 | if (UxxxStatus) | 2478 | if (UxxxStatus) |
2511 | return UxxxStatus; | 2479 | return UxxxStatus; |
2512 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2480 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2513 | &pcidata); | 2481 | &pcidata); |
2514 | if (UxxxStatus) | 2482 | if (UxxxStatus) |
2515 | return UxxxStatus; | 2483 | return UxxxStatus; |
2516 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, | 2484 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, |
2517 | 0xF0000000); | 2485 | 0xF0000000); |
2518 | if (UxxxStatus) | 2486 | if (UxxxStatus) |
2519 | return UxxxStatus; | 2487 | return UxxxStatus; |
2520 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2488 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2521 | &pcidata); | 2489 | &pcidata); |
2522 | if (UxxxStatus) | 2490 | if (UxxxStatus) |
2523 | return UxxxStatus; | 2491 | return UxxxStatus; |
2524 | reg = 12; | 2492 | reg = 12; |
2525 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2493 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2526 | &latence_timer); | 2494 | &latence_timer); |
2527 | if (UxxxStatus) | 2495 | if (UxxxStatus) |
2528 | return UxxxStatus; | 2496 | return UxxxStatus; |
2529 | latence_timer &= 0xFFFF00FF; | 2497 | latence_timer &= 0xFFFF00FF; |
2530 | latence_timer |= 0x00001600; | 2498 | latence_timer |= 0x00001600; |
2531 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, | 2499 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, |
2532 | latence_timer); | 2500 | latence_timer); |
2533 | if (UxxxStatus) | 2501 | if (UxxxStatus) |
2534 | return UxxxStatus; | 2502 | return UxxxStatus; |
2535 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2503 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2536 | &pcidata); | 2504 | &pcidata); |
2537 | if (UxxxStatus) | 2505 | if (UxxxStatus) |
2538 | return UxxxStatus; | 2506 | return UxxxStatus; |
2539 | reg = 4; | 2507 | reg = 4; |
2540 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, | 2508 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, |
2541 | 0x06); | 2509 | 0x06); |
2542 | if (UxxxStatus) | 2510 | if (UxxxStatus) |
2543 | return UxxxStatus; | 2511 | return UxxxStatus; |
2544 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2512 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2545 | &pcidata); | 2513 | &pcidata); |
2546 | if (UxxxStatus) | 2514 | if (UxxxStatus) |
2547 | return UxxxStatus; | 2515 | return UxxxStatus; |
2548 | for (reg = 0; reg <= 0x54; reg += 4) { | 2516 | for (reg = 0; reg <= 0x54; reg += 4) { |
2549 | UxxxStatus = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); | 2517 | UxxxStatus = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); |
2550 | if (UxxxStatus) | 2518 | if (UxxxStatus) |
2551 | return UxxxStatus; | 2519 | return UxxxStatus; |
2552 | } | 2520 | } |
2553 | return 0; | 2521 | return 0; |
2554 | } | 2522 | } |
2555 | 2523 | ||
2556 | static int ftdi_elan_close_controller(struct usb_ftdi *ftdi, int fn) | 2524 | static int ftdi_elan_close_controller(struct usb_ftdi *ftdi, int fn) |
2557 | { | 2525 | { |
2558 | u32 latence_timer; | 2526 | u32 latence_timer; |
2559 | int UxxxStatus; | 2527 | int UxxxStatus; |
2560 | u32 pcidata; | 2528 | u32 pcidata; |
2561 | int reg = 0; | 2529 | int reg = 0; |
2562 | int activePCIfn = fn << 8; | 2530 | int activePCIfn = fn << 8; |
2563 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); | 2531 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); |
2564 | if (UxxxStatus) | 2532 | if (UxxxStatus) |
2565 | return UxxxStatus; | 2533 | return UxxxStatus; |
2566 | reg = 16; | 2534 | reg = 16; |
2567 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, | 2535 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, |
2568 | 0xFFFFFFFF); | 2536 | 0xFFFFFFFF); |
2569 | if (UxxxStatus) | 2537 | if (UxxxStatus) |
2570 | return UxxxStatus; | 2538 | return UxxxStatus; |
2571 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2539 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2572 | &pcidata); | 2540 | &pcidata); |
2573 | if (UxxxStatus) | 2541 | if (UxxxStatus) |
2574 | return UxxxStatus; | 2542 | return UxxxStatus; |
2575 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, | 2543 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, |
2576 | 0x00000000); | 2544 | 0x00000000); |
2577 | if (UxxxStatus) | 2545 | if (UxxxStatus) |
2578 | return UxxxStatus; | 2546 | return UxxxStatus; |
2579 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2547 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2580 | &pcidata); | 2548 | &pcidata); |
2581 | if (UxxxStatus) | 2549 | if (UxxxStatus) |
2582 | return UxxxStatus; | 2550 | return UxxxStatus; |
2583 | reg = 12; | 2551 | reg = 12; |
2584 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2552 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2585 | &latence_timer); | 2553 | &latence_timer); |
2586 | if (UxxxStatus) | 2554 | if (UxxxStatus) |
2587 | return UxxxStatus; | 2555 | return UxxxStatus; |
2588 | latence_timer &= 0xFFFF00FF; | 2556 | latence_timer &= 0xFFFF00FF; |
2589 | latence_timer |= 0x00001600; | 2557 | latence_timer |= 0x00001600; |
2590 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, | 2558 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, |
2591 | latence_timer); | 2559 | latence_timer); |
2592 | if (UxxxStatus) | 2560 | if (UxxxStatus) |
2593 | return UxxxStatus; | 2561 | return UxxxStatus; |
2594 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2562 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2595 | &pcidata); | 2563 | &pcidata); |
2596 | if (UxxxStatus) | 2564 | if (UxxxStatus) |
2597 | return UxxxStatus; | 2565 | return UxxxStatus; |
2598 | reg = 4; | 2566 | reg = 4; |
2599 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, | 2567 | UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, |
2600 | 0x00); | 2568 | 0x00); |
2601 | if (UxxxStatus) | 2569 | if (UxxxStatus) |
2602 | return UxxxStatus; | 2570 | return UxxxStatus; |
2603 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2571 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2604 | &pcidata); | 2572 | &pcidata); |
2605 | if (UxxxStatus) | 2573 | if (UxxxStatus) |
2606 | return UxxxStatus; | 2574 | return UxxxStatus; |
2607 | return 0; | 2575 | return 0; |
2608 | } | 2576 | } |
2609 | 2577 | ||
2610 | static int ftdi_elan_found_controller(struct usb_ftdi *ftdi, int fn, int quirk) | 2578 | static int ftdi_elan_found_controller(struct usb_ftdi *ftdi, int fn, int quirk) |
2611 | { | 2579 | { |
2612 | int result; | 2580 | int result; |
2613 | int UxxxStatus; | 2581 | int UxxxStatus; |
2614 | UxxxStatus = ftdi_elan_setup_controller(ftdi, fn); | 2582 | UxxxStatus = ftdi_elan_setup_controller(ftdi, fn); |
2615 | if (UxxxStatus) | 2583 | if (UxxxStatus) |
2616 | return UxxxStatus; | 2584 | return UxxxStatus; |
2617 | result = ftdi_elan_check_controller(ftdi, quirk); | 2585 | result = ftdi_elan_check_controller(ftdi, quirk); |
2618 | UxxxStatus = ftdi_elan_close_controller(ftdi, fn); | 2586 | UxxxStatus = ftdi_elan_close_controller(ftdi, fn); |
2619 | if (UxxxStatus) | 2587 | if (UxxxStatus) |
2620 | return UxxxStatus; | 2588 | return UxxxStatus; |
2621 | return result; | 2589 | return result; |
2622 | } | 2590 | } |
2623 | 2591 | ||
2624 | static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi) | 2592 | static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi) |
2625 | { | 2593 | { |
2626 | u32 controlreg; | 2594 | u32 controlreg; |
2627 | u8 sensebits; | 2595 | u8 sensebits; |
2628 | int UxxxStatus; | 2596 | int UxxxStatus; |
2629 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); | 2597 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); |
2630 | if (UxxxStatus) | 2598 | if (UxxxStatus) |
2631 | return UxxxStatus; | 2599 | return UxxxStatus; |
2632 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L); | 2600 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L); |
2633 | if (UxxxStatus) | 2601 | if (UxxxStatus) |
2634 | return UxxxStatus; | 2602 | return UxxxStatus; |
2635 | msleep(750); | 2603 | msleep(750); |
2636 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100); | 2604 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100); |
2637 | if (UxxxStatus) | 2605 | if (UxxxStatus) |
2638 | return UxxxStatus; | 2606 | return UxxxStatus; |
2639 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500); | 2607 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500); |
2640 | if (UxxxStatus) | 2608 | if (UxxxStatus) |
2641 | return UxxxStatus; | 2609 | return UxxxStatus; |
2642 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); | 2610 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); |
2643 | if (UxxxStatus) | 2611 | if (UxxxStatus) |
2644 | return UxxxStatus; | 2612 | return UxxxStatus; |
2645 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000); | 2613 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000); |
2646 | if (UxxxStatus) | 2614 | if (UxxxStatus) |
2647 | return UxxxStatus; | 2615 | return UxxxStatus; |
2648 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000); | 2616 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000); |
2649 | if (UxxxStatus) | 2617 | if (UxxxStatus) |
2650 | return UxxxStatus; | 2618 | return UxxxStatus; |
2651 | msleep(250); | 2619 | msleep(250); |
2652 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000); | 2620 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000); |
2653 | if (UxxxStatus) | 2621 | if (UxxxStatus) |
2654 | return UxxxStatus; | 2622 | return UxxxStatus; |
2655 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); | 2623 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); |
2656 | if (UxxxStatus) | 2624 | if (UxxxStatus) |
2657 | return UxxxStatus; | 2625 | return UxxxStatus; |
2658 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800); | 2626 | UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800); |
2659 | if (UxxxStatus) | 2627 | if (UxxxStatus) |
2660 | return UxxxStatus; | 2628 | return UxxxStatus; |
2661 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); | 2629 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); |
2662 | if (UxxxStatus) | 2630 | if (UxxxStatus) |
2663 | return UxxxStatus; | 2631 | return UxxxStatus; |
2664 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); | 2632 | UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); |
2665 | if (UxxxStatus) | 2633 | if (UxxxStatus) |
2666 | return UxxxStatus; | 2634 | return UxxxStatus; |
2667 | msleep(1000); | 2635 | msleep(1000); |
2668 | sensebits = (controlreg >> 16) & 0x000F; | 2636 | sensebits = (controlreg >> 16) & 0x000F; |
2669 | if (0x0D == sensebits) | 2637 | if (0x0D == sensebits) |
2670 | return 0; | 2638 | return 0; |
2671 | else | 2639 | else |
2672 | return - ENXIO; | 2640 | return - ENXIO; |
2673 | } | 2641 | } |
2674 | 2642 | ||
2675 | static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi) | 2643 | static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi) |
2676 | { | 2644 | { |
2677 | int UxxxStatus; | 2645 | int UxxxStatus; |
2678 | u32 pcidata; | 2646 | u32 pcidata; |
2679 | int reg = 0; | 2647 | int reg = 0; |
2680 | u8 fn; | 2648 | u8 fn; |
2681 | int activePCIfn = 0; | 2649 | int activePCIfn = 0; |
2682 | int max_devices = 0; | 2650 | int max_devices = 0; |
2683 | int controllers = 0; | 2651 | int controllers = 0; |
2684 | int unrecognized = 0; | 2652 | int unrecognized = 0; |
2685 | ftdi->function = 0; | 2653 | ftdi->function = 0; |
2686 | for (fn = 0; (fn < 4); fn++) { | 2654 | for (fn = 0; (fn < 4); fn++) { |
2687 | u32 pciVID = 0; | 2655 | u32 pciVID = 0; |
2688 | u32 pciPID = 0; | 2656 | u32 pciPID = 0; |
2689 | int devices = 0; | 2657 | int devices = 0; |
2690 | activePCIfn = fn << 8; | 2658 | activePCIfn = fn << 8; |
2691 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, | 2659 | UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, |
2692 | &pcidata); | 2660 | &pcidata); |
2693 | if (UxxxStatus) | 2661 | if (UxxxStatus) |
2694 | return UxxxStatus; | 2662 | return UxxxStatus; |
2695 | pciVID = pcidata & 0xFFFF; | 2663 | pciVID = pcidata & 0xFFFF; |
2696 | pciPID = (pcidata >> 16) & 0xFFFF; | 2664 | pciPID = (pcidata >> 16) & 0xFFFF; |
2697 | if ((pciVID == PCI_VENDOR_ID_OPTI) && (pciPID == 0xc861)) { | 2665 | if ((pciVID == PCI_VENDOR_ID_OPTI) && (pciPID == 0xc861)) { |
2698 | devices = ftdi_elan_found_controller(ftdi, fn, 0); | 2666 | devices = ftdi_elan_found_controller(ftdi, fn, 0); |
2699 | controllers += 1; | 2667 | controllers += 1; |
2700 | } else if ((pciVID == PCI_VENDOR_ID_NEC) && (pciPID == 0x0035)) | 2668 | } else if ((pciVID == PCI_VENDOR_ID_NEC) && (pciPID == 0x0035)) |
2701 | { | 2669 | { |
2702 | devices = ftdi_elan_found_controller(ftdi, fn, 0); | 2670 | devices = ftdi_elan_found_controller(ftdi, fn, 0); |
2703 | controllers += 1; | 2671 | controllers += 1; |
2704 | } else if ((pciVID == PCI_VENDOR_ID_AL) && (pciPID == 0x5237)) { | 2672 | } else if ((pciVID == PCI_VENDOR_ID_AL) && (pciPID == 0x5237)) { |
2705 | devices = ftdi_elan_found_controller(ftdi, fn, 0); | 2673 | devices = ftdi_elan_found_controller(ftdi, fn, 0); |
2706 | controllers += 1; | 2674 | controllers += 1; |
2707 | } else if ((pciVID == PCI_VENDOR_ID_ATT) && (pciPID == 0x5802)) | 2675 | } else if ((pciVID == PCI_VENDOR_ID_ATT) && (pciPID == 0x5802)) |
2708 | { | 2676 | { |
2709 | devices = ftdi_elan_found_controller(ftdi, fn, 0); | 2677 | devices = ftdi_elan_found_controller(ftdi, fn, 0); |
2710 | controllers += 1; | 2678 | controllers += 1; |
2711 | } else if (pciVID == PCI_VENDOR_ID_AMD && pciPID == 0x740c) { | 2679 | } else if (pciVID == PCI_VENDOR_ID_AMD && pciPID == 0x740c) { |
2712 | devices = ftdi_elan_found_controller(ftdi, fn, | 2680 | devices = ftdi_elan_found_controller(ftdi, fn, |
2713 | OHCI_QUIRK_AMD756); | 2681 | OHCI_QUIRK_AMD756); |
2714 | controllers += 1; | 2682 | controllers += 1; |
2715 | } else if (pciVID == PCI_VENDOR_ID_COMPAQ && pciPID == 0xa0f8) { | 2683 | } else if (pciVID == PCI_VENDOR_ID_COMPAQ && pciPID == 0xa0f8) { |
2716 | devices = ftdi_elan_found_controller(ftdi, fn, | 2684 | devices = ftdi_elan_found_controller(ftdi, fn, |
2717 | OHCI_QUIRK_ZFMICRO); | 2685 | OHCI_QUIRK_ZFMICRO); |
2718 | controllers += 1; | 2686 | controllers += 1; |
2719 | } else if (0 == pcidata) { | 2687 | } else if (0 == pcidata) { |
2720 | } else | 2688 | } else |
2721 | unrecognized += 1; | 2689 | unrecognized += 1; |
2722 | if (devices > max_devices) { | 2690 | if (devices > max_devices) { |
2723 | max_devices = devices; | 2691 | max_devices = devices; |
2724 | ftdi->function = fn + 1; | 2692 | ftdi->function = fn + 1; |
2725 | ftdi->platform_data.vendor = pciVID; | 2693 | ftdi->platform_data.vendor = pciVID; |
2726 | ftdi->platform_data.device = pciPID; | 2694 | ftdi->platform_data.device = pciPID; |
2727 | } | 2695 | } |
2728 | } | 2696 | } |
2729 | if (ftdi->function > 0) { | 2697 | if (ftdi->function > 0) { |
2730 | UxxxStatus = ftdi_elan_setup_controller(ftdi, | 2698 | UxxxStatus = ftdi_elan_setup_controller(ftdi, |
2731 | ftdi->function - 1); | 2699 | ftdi->function - 1); |
2732 | if (UxxxStatus) | 2700 | if (UxxxStatus) |
2733 | return UxxxStatus; | 2701 | return UxxxStatus; |
2734 | return 0; | 2702 | return 0; |
2735 | } else if (controllers > 0) { | 2703 | } else if (controllers > 0) { |
2736 | return -ENXIO; | 2704 | return -ENXIO; |
2737 | } else if (unrecognized > 0) { | 2705 | } else if (unrecognized > 0) { |
2738 | return -ENXIO; | 2706 | return -ENXIO; |
2739 | } else { | 2707 | } else { |
2740 | ftdi->enumerated = 0; | 2708 | ftdi->enumerated = 0; |
2741 | return -ENXIO; | 2709 | return -ENXIO; |
2742 | } | 2710 | } |
2743 | } | 2711 | } |
2744 | 2712 | ||
2745 | 2713 | ||
2746 | /* | 2714 | /* |
2747 | * we use only the first bulk-in and bulk-out endpoints | 2715 | * we use only the first bulk-in and bulk-out endpoints |
2748 | */ | 2716 | */ |
2749 | static int ftdi_elan_probe(struct usb_interface *interface, | 2717 | static int ftdi_elan_probe(struct usb_interface *interface, |
2750 | const struct usb_device_id *id) | 2718 | const struct usb_device_id *id) |
2751 | { | 2719 | { |
2752 | struct usb_host_interface *iface_desc; | 2720 | struct usb_host_interface *iface_desc; |
2753 | struct usb_endpoint_descriptor *endpoint; | 2721 | struct usb_endpoint_descriptor *endpoint; |
2754 | size_t buffer_size; | 2722 | size_t buffer_size; |
2755 | int i; | 2723 | int i; |
2756 | int retval = -ENOMEM; | 2724 | int retval = -ENOMEM; |
2757 | struct usb_ftdi *ftdi; | 2725 | struct usb_ftdi *ftdi; |
2758 | 2726 | ||
2759 | ftdi = kzalloc(sizeof(struct usb_ftdi), GFP_KERNEL); | 2727 | ftdi = kzalloc(sizeof(struct usb_ftdi), GFP_KERNEL); |
2760 | if (!ftdi) { | 2728 | if (!ftdi) |
2761 | printk(KERN_ERR "Out of memory\n"); | 2729 | return -ENOMEM; |
2762 | return -ENOMEM; | 2730 | |
2763 | } | 2731 | mutex_lock(&ftdi_module_lock); |
2764 | 2732 | list_add_tail(&ftdi->ftdi_list, &ftdi_static_list); | |
2765 | mutex_lock(&ftdi_module_lock); | 2733 | ftdi->sequence_num = ++ftdi_instances; |
2766 | list_add_tail(&ftdi->ftdi_list, &ftdi_static_list); | 2734 | mutex_unlock(&ftdi_module_lock); |
2767 | ftdi->sequence_num = ++ftdi_instances; | 2735 | ftdi_elan_init_kref(ftdi); |
2768 | mutex_unlock(&ftdi_module_lock); | ||
2769 | ftdi_elan_init_kref(ftdi); | ||
2770 | sema_init(&ftdi->sw_lock, 1); | 2736 | sema_init(&ftdi->sw_lock, 1); |
2771 | ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); | 2737 | ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); |
2772 | ftdi->interface = interface; | 2738 | ftdi->interface = interface; |
2773 | mutex_init(&ftdi->u132_lock); | 2739 | mutex_init(&ftdi->u132_lock); |
2774 | ftdi->expected = 4; | 2740 | ftdi->expected = 4; |
2775 | iface_desc = interface->cur_altsetting; | 2741 | iface_desc = interface->cur_altsetting; |
2776 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { | 2742 | for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
2777 | endpoint = &iface_desc->endpoint[i].desc; | 2743 | endpoint = &iface_desc->endpoint[i].desc; |
2778 | if (!ftdi->bulk_in_endpointAddr && | 2744 | if (!ftdi->bulk_in_endpointAddr && |
2779 | usb_endpoint_is_bulk_in(endpoint)) { | 2745 | usb_endpoint_is_bulk_in(endpoint)) { |
2780 | buffer_size = usb_endpoint_maxp(endpoint); | 2746 | buffer_size = usb_endpoint_maxp(endpoint); |
2781 | ftdi->bulk_in_size = buffer_size; | 2747 | ftdi->bulk_in_size = buffer_size; |
2782 | ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress; | 2748 | ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress; |
2783 | ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | 2749 | ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); |
2784 | if (!ftdi->bulk_in_buffer) { | 2750 | if (!ftdi->bulk_in_buffer) { |
2785 | dev_err(&ftdi->udev->dev, "Could not allocate b" | 2751 | dev_err(&ftdi->udev->dev, "Could not allocate bulk_in_buffer\n"); |
2786 | "ulk_in_buffer\n"); | 2752 | retval = -ENOMEM; |
2787 | retval = -ENOMEM; | 2753 | goto error; |
2788 | goto error; | 2754 | } |
2789 | } | 2755 | } |
2790 | } | 2756 | if (!ftdi->bulk_out_endpointAddr && |
2791 | if (!ftdi->bulk_out_endpointAddr && | ||
2792 | usb_endpoint_is_bulk_out(endpoint)) { | 2757 | usb_endpoint_is_bulk_out(endpoint)) { |
2793 | ftdi->bulk_out_endpointAddr = | 2758 | ftdi->bulk_out_endpointAddr = |
2794 | endpoint->bEndpointAddress; | 2759 | endpoint->bEndpointAddress; |
2795 | } | 2760 | } |
2796 | } | 2761 | } |
2797 | if (!(ftdi->bulk_in_endpointAddr && ftdi->bulk_out_endpointAddr)) { | 2762 | if (!(ftdi->bulk_in_endpointAddr && ftdi->bulk_out_endpointAddr)) { |
2798 | dev_err(&ftdi->udev->dev, "Could not find both bulk-in and bulk" | 2763 | dev_err(&ftdi->udev->dev, "Could not find both bulk-in and bulk-out endpoints\n"); |
2799 | "-out endpoints\n"); | 2764 | retval = -ENODEV; |
2800 | retval = -ENODEV; | 2765 | goto error; |
2801 | goto error; | 2766 | } |
2802 | } | 2767 | dev_info(&ftdi->udev->dev, "interface %d has I=%02X O=%02X\n", |
2803 | dev_info(&ftdi->udev->dev, "interface %d has I=%02X O=%02X\n", | 2768 | iface_desc->desc.bInterfaceNumber, ftdi->bulk_in_endpointAddr, |
2804 | iface_desc->desc.bInterfaceNumber, ftdi->bulk_in_endpointAddr, | 2769 | ftdi->bulk_out_endpointAddr); |
2805 | ftdi->bulk_out_endpointAddr); | 2770 | usb_set_intfdata(interface, ftdi); |
2806 | usb_set_intfdata(interface, ftdi); | 2771 | if (iface_desc->desc.bInterfaceNumber == 0 && |
2807 | if (iface_desc->desc.bInterfaceNumber == 0 && | 2772 | ftdi->bulk_in_endpointAddr == 0x81 && |
2808 | ftdi->bulk_in_endpointAddr == 0x81 && | 2773 | ftdi->bulk_out_endpointAddr == 0x02) { |
2809 | ftdi->bulk_out_endpointAddr == 0x02) { | 2774 | retval = usb_register_dev(interface, &ftdi_elan_jtag_class); |
2810 | retval = usb_register_dev(interface, &ftdi_elan_jtag_class); | 2775 | if (retval) { |
2811 | if (retval) { | 2776 | dev_err(&ftdi->udev->dev, "Not able to get a minor for this device\n"); |
2812 | dev_err(&ftdi->udev->dev, "Not able to get a minor for " | 2777 | usb_set_intfdata(interface, NULL); |
2813 | "this device.\n"); | 2778 | retval = -ENOMEM; |
2814 | usb_set_intfdata(interface, NULL); | 2779 | goto error; |
2815 | retval = -ENOMEM; | 2780 | } else { |
2816 | goto error; | 2781 | ftdi->class = &ftdi_elan_jtag_class; |
2817 | } else { | 2782 | dev_info(&ftdi->udev->dev, "USB FDTI=%p JTAG interface %d now attached to ftdi%d\n", |
2818 | ftdi->class = &ftdi_elan_jtag_class; | 2783 | ftdi, iface_desc->desc.bInterfaceNumber, |
2819 | dev_info(&ftdi->udev->dev, "USB FDTI=%p JTAG interface " | 2784 | interface->minor); |
2820 | "%d now attached to ftdi%d\n", ftdi, | 2785 | return 0; |
2821 | iface_desc->desc.bInterfaceNumber, | 2786 | } |
2822 | interface->minor); | 2787 | } else if (iface_desc->desc.bInterfaceNumber == 1 && |
2823 | return 0; | 2788 | ftdi->bulk_in_endpointAddr == 0x83 && |
2824 | } | 2789 | ftdi->bulk_out_endpointAddr == 0x04) { |
2825 | } else if (iface_desc->desc.bInterfaceNumber == 1 && | 2790 | ftdi->class = NULL; |
2826 | ftdi->bulk_in_endpointAddr == 0x83 && | 2791 | dev_info(&ftdi->udev->dev, "USB FDTI=%p ELAN interface %d now activated\n", |
2827 | ftdi->bulk_out_endpointAddr == 0x04) { | 2792 | ftdi, iface_desc->desc.bInterfaceNumber); |
2828 | ftdi->class = NULL; | 2793 | INIT_DELAYED_WORK(&ftdi->status_work, ftdi_elan_status_work); |
2829 | dev_info(&ftdi->udev->dev, "USB FDTI=%p ELAN interface %d now a" | 2794 | INIT_DELAYED_WORK(&ftdi->command_work, ftdi_elan_command_work); |
2830 | "ctivated\n", ftdi, iface_desc->desc.bInterfaceNumber); | 2795 | INIT_DELAYED_WORK(&ftdi->respond_work, ftdi_elan_respond_work); |
2831 | INIT_DELAYED_WORK(&ftdi->status_work, ftdi_elan_status_work); | 2796 | ftdi_status_queue_work(ftdi, msecs_to_jiffies(3 *1000)); |
2832 | INIT_DELAYED_WORK(&ftdi->command_work, ftdi_elan_command_work); | 2797 | return 0; |
2833 | INIT_DELAYED_WORK(&ftdi->respond_work, ftdi_elan_respond_work); | 2798 | } else { |
2834 | ftdi_status_queue_work(ftdi, msecs_to_jiffies(3 *1000)); | 2799 | dev_err(&ftdi->udev->dev, |
2835 | return 0; | 2800 | "Could not find ELAN's U132 device\n"); |
2836 | } else { | 2801 | retval = -ENODEV; |
2837 | dev_err(&ftdi->udev->dev, | 2802 | goto error; |
2838 | "Could not find ELAN's U132 device\n"); | 2803 | } |
2839 | retval = -ENODEV; | 2804 | error:if (ftdi) { |
2840 | goto error; | 2805 | ftdi_elan_put_kref(ftdi); |
2841 | } | 2806 | } |
2842 | error:if (ftdi) { | 2807 | return retval; |
2843 | ftdi_elan_put_kref(ftdi); | ||
2844 | } | ||
2845 | return retval; | ||
2846 | } | 2808 | } |
2847 | 2809 | ||
2848 | static void ftdi_elan_disconnect(struct usb_interface *interface) | 2810 | static void ftdi_elan_disconnect(struct usb_interface *interface) |
2849 | { | 2811 | { |
2850 | struct usb_ftdi *ftdi = usb_get_intfdata(interface); | 2812 | struct usb_ftdi *ftdi = usb_get_intfdata(interface); |
2851 | ftdi->disconnected += 1; | 2813 | ftdi->disconnected += 1; |
2852 | if (ftdi->class) { | 2814 | if (ftdi->class) { |
2853 | int minor = interface->minor; | 2815 | int minor = interface->minor; |
2854 | struct usb_class_driver *class = ftdi->class; | 2816 | struct usb_class_driver *class = ftdi->class; |
2855 | usb_set_intfdata(interface, NULL); | 2817 | usb_set_intfdata(interface, NULL); |
2856 | usb_deregister_dev(interface, class); | 2818 | usb_deregister_dev(interface, class); |
2857 | dev_info(&ftdi->udev->dev, "USB FTDI U132 jtag interface on min" | 2819 | dev_info(&ftdi->udev->dev, "USB FTDI U132 jtag interface on minor %d now disconnected\n", |
2858 | "or %d now disconnected\n", minor); | 2820 | minor); |
2859 | } else { | 2821 | } else { |
2860 | ftdi_status_cancel_work(ftdi); | 2822 | ftdi_status_cancel_work(ftdi); |
2861 | ftdi_command_cancel_work(ftdi); | 2823 | ftdi_command_cancel_work(ftdi); |
2862 | ftdi_response_cancel_work(ftdi); | 2824 | ftdi_response_cancel_work(ftdi); |
2863 | ftdi_elan_abandon_completions(ftdi); | 2825 | ftdi_elan_abandon_completions(ftdi); |
2864 | ftdi_elan_abandon_targets(ftdi); | 2826 | ftdi_elan_abandon_targets(ftdi); |
2865 | if (ftdi->registered) { | 2827 | if (ftdi->registered) { |
2866 | platform_device_unregister(&ftdi->platform_dev); | 2828 | platform_device_unregister(&ftdi->platform_dev); |
2867 | ftdi->synchronized = 0; | 2829 | ftdi->synchronized = 0; |
2868 | ftdi->enumerated = 0; | 2830 | ftdi->enumerated = 0; |
2869 | ftdi->initialized = 0; | 2831 | ftdi->initialized = 0; |
2870 | ftdi->registered = 0; | 2832 | ftdi->registered = 0; |
2871 | } | 2833 | } |
2872 | flush_workqueue(status_queue); | 2834 | flush_workqueue(status_queue); |
2873 | flush_workqueue(command_queue); | 2835 | flush_workqueue(command_queue); |
2874 | flush_workqueue(respond_queue); | 2836 | flush_workqueue(respond_queue); |
2875 | ftdi->disconnected += 1; | 2837 | ftdi->disconnected += 1; |
2876 | usb_set_intfdata(interface, NULL); | 2838 | usb_set_intfdata(interface, NULL); |
2877 | dev_info(&ftdi->udev->dev, "USB FTDI U132 host controller inter" | 2839 | dev_info(&ftdi->udev->dev, "USB FTDI U132 host controller interface now disconnected\n"); |
2878 | "face now disconnected\n"); | 2840 | } |
2879 | } | 2841 | ftdi_elan_put_kref(ftdi); |
2880 | ftdi_elan_put_kref(ftdi); | ||
2881 | } | 2842 | } |
2882 | 2843 | ||
2883 | static struct usb_driver ftdi_elan_driver = { | 2844 | static struct usb_driver ftdi_elan_driver = { |
2884 | .name = "ftdi-elan", | 2845 | .name = "ftdi-elan", |
2885 | .probe = ftdi_elan_probe, | 2846 | .probe = ftdi_elan_probe, |
2886 | .disconnect = ftdi_elan_disconnect, | 2847 | .disconnect = ftdi_elan_disconnect, |
2887 | .id_table = ftdi_elan_table, | 2848 | .id_table = ftdi_elan_table, |
2888 | }; | 2849 | }; |
2889 | static int __init ftdi_elan_init(void) | 2850 | static int __init ftdi_elan_init(void) |
2890 | { | 2851 | { |
2891 | int result; | 2852 | int result; |
2892 | printk(KERN_INFO "driver %s\n", ftdi_elan_driver.name); | 2853 | pr_info("driver %s\n", ftdi_elan_driver.name); |
2893 | mutex_init(&ftdi_module_lock); | 2854 | mutex_init(&ftdi_module_lock); |
2894 | INIT_LIST_HEAD(&ftdi_static_list); | 2855 | INIT_LIST_HEAD(&ftdi_static_list); |
2895 | status_queue = create_singlethread_workqueue("ftdi-status-control"); | 2856 | status_queue = create_singlethread_workqueue("ftdi-status-control"); |
2896 | if (!status_queue) | 2857 | if (!status_queue) |
2897 | goto err_status_queue; | 2858 | goto err_status_queue; |
2898 | command_queue = create_singlethread_workqueue("ftdi-command-engine"); | 2859 | command_queue = create_singlethread_workqueue("ftdi-command-engine"); |
2899 | if (!command_queue) | 2860 | if (!command_queue) |
2900 | goto err_command_queue; | 2861 | goto err_command_queue; |
2901 | respond_queue = create_singlethread_workqueue("ftdi-respond-engine"); | 2862 | respond_queue = create_singlethread_workqueue("ftdi-respond-engine"); |
2902 | if (!respond_queue) | 2863 | if (!respond_queue) |
2903 | goto err_respond_queue; | 2864 | goto err_respond_queue; |
2904 | result = usb_register(&ftdi_elan_driver); | 2865 | result = usb_register(&ftdi_elan_driver); |
2905 | if (result) { | 2866 | if (result) { |
2906 | destroy_workqueue(status_queue); | 2867 | destroy_workqueue(status_queue); |
2907 | destroy_workqueue(command_queue); | 2868 | destroy_workqueue(command_queue); |
2908 | destroy_workqueue(respond_queue); | 2869 | destroy_workqueue(respond_queue); |
2909 | printk(KERN_ERR "usb_register failed. Error number %d\n", | 2870 | pr_err("usb_register failed. Error number %d\n", result); |
2910 | result); | ||
2911 | } | 2871 | } |
2912 | return result; | 2872 | return result; |
2913 | 2873 | ||
2914 | err_respond_queue: | 2874 | err_respond_queue: |
2915 | destroy_workqueue(command_queue); | 2875 | destroy_workqueue(command_queue); |
2916 | err_command_queue: | 2876 | err_command_queue: |
2917 | destroy_workqueue(status_queue); | 2877 | destroy_workqueue(status_queue); |
2918 | err_status_queue: | 2878 | err_status_queue: |
2919 | printk(KERN_ERR "%s couldn't create workqueue\n", ftdi_elan_driver.name); | 2879 | pr_err("%s couldn't create workqueue\n", ftdi_elan_driver.name); |
2920 | return -ENOMEM; | 2880 | return -ENOMEM; |
2921 | } | 2881 | } |
2922 | 2882 | ||
2923 | static void __exit ftdi_elan_exit(void) | 2883 | static void __exit ftdi_elan_exit(void) |
2924 | { | 2884 | { |
2925 | struct usb_ftdi *ftdi; | 2885 | struct usb_ftdi *ftdi; |
2926 | struct usb_ftdi *temp; | 2886 | struct usb_ftdi *temp; |
2927 | usb_deregister(&ftdi_elan_driver); | 2887 | usb_deregister(&ftdi_elan_driver); |
2928 | printk(KERN_INFO "ftdi_u132 driver deregistered\n"); | 2888 | pr_info("ftdi_u132 driver deregistered\n"); |
2929 | list_for_each_entry_safe(ftdi, temp, &ftdi_static_list, ftdi_list) { | 2889 | list_for_each_entry_safe(ftdi, temp, &ftdi_static_list, ftdi_list) { |
2930 | ftdi_status_cancel_work(ftdi); | 2890 | ftdi_status_cancel_work(ftdi); |
2931 | ftdi_command_cancel_work(ftdi); | 2891 | ftdi_command_cancel_work(ftdi); |
2932 | ftdi_response_cancel_work(ftdi); | 2892 | ftdi_response_cancel_work(ftdi); |
2933 | } flush_workqueue(status_queue); | 2893 | } flush_workqueue(status_queue); |
2934 | destroy_workqueue(status_queue); | 2894 | destroy_workqueue(status_queue); |
2935 | status_queue = NULL; | 2895 | status_queue = NULL; |
2936 | flush_workqueue(command_queue); | 2896 | flush_workqueue(command_queue); |
2937 | destroy_workqueue(command_queue); | 2897 | destroy_workqueue(command_queue); |
2938 | command_queue = NULL; | 2898 | command_queue = NULL; |
2939 | flush_workqueue(respond_queue); | 2899 | flush_workqueue(respond_queue); |
2940 | destroy_workqueue(respond_queue); | 2900 | destroy_workqueue(respond_queue); |
2941 | respond_queue = NULL; | 2901 | respond_queue = NULL; |
2942 | } | 2902 | } |
2943 | 2903 | ||
2944 | 2904 | ||
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 20bcfdd7eace..c6bfd13f6c92 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -51,19 +51,12 @@ | |||
51 | */ | 51 | */ |
52 | #define MAX_WRITES_IN_FLIGHT 4 | 52 | #define MAX_WRITES_IN_FLIGHT 4 |
53 | 53 | ||
54 | /* Use our own dbg macro */ | ||
55 | #undef dbg | ||
56 | #define dbg( format, arg... ) do { if( debug ) printk( KERN_DEBUG __FILE__ ": " format "\n" , ## arg ); } while ( 0 ) | ||
57 | |||
58 | MODULE_AUTHOR(DRIVER_AUTHOR); | 54 | MODULE_AUTHOR(DRIVER_AUTHOR); |
59 | MODULE_DESCRIPTION(DRIVER_DESC); | 55 | MODULE_DESCRIPTION(DRIVER_DESC); |
60 | MODULE_LICENSE("GPL"); | 56 | MODULE_LICENSE("GPL"); |
61 | 57 | ||
62 | /* Module parameters */ | 58 | /* Module parameters */ |
63 | static DEFINE_MUTEX(iowarrior_mutex); | 59 | static DEFINE_MUTEX(iowarrior_mutex); |
64 | static bool debug = 0; | ||
65 | module_param(debug, bool, 0644); | ||
66 | MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); | ||
67 | 60 | ||
68 | static struct usb_driver iowarrior_driver; | 61 | static struct usb_driver iowarrior_driver; |
69 | static DEFINE_MUTEX(iowarrior_open_disc_lock); | 62 | static DEFINE_MUTEX(iowarrior_open_disc_lock); |
@@ -235,8 +228,8 @@ static void iowarrior_write_callback(struct urb *urb) | |||
235 | if (status && | 228 | if (status && |
236 | !(status == -ENOENT || | 229 | !(status == -ENOENT || |
237 | status == -ECONNRESET || status == -ESHUTDOWN)) { | 230 | status == -ECONNRESET || status == -ESHUTDOWN)) { |
238 | dbg("%s - nonzero write bulk status received: %d", | 231 | dev_dbg(&dev->interface->dev, |
239 | __func__, status); | 232 | "nonzero write bulk status received: %d\n", status); |
240 | } | 233 | } |
241 | /* free up our allocated buffer */ | 234 | /* free up our allocated buffer */ |
242 | usb_free_coherent(urb->dev, urb->transfer_buffer_length, | 235 | usb_free_coherent(urb->dev, urb->transfer_buffer_length, |
@@ -251,7 +244,7 @@ static void iowarrior_write_callback(struct urb *urb) | |||
251 | */ | 244 | */ |
252 | static inline void iowarrior_delete(struct iowarrior *dev) | 245 | static inline void iowarrior_delete(struct iowarrior *dev) |
253 | { | 246 | { |
254 | dbg("%s - minor %d", __func__, dev->minor); | 247 | dev_dbg(&dev->interface->dev, "minor %d\n", dev->minor); |
255 | kfree(dev->int_in_buffer); | 248 | kfree(dev->int_in_buffer); |
256 | usb_free_urb(dev->int_in_urb); | 249 | usb_free_urb(dev->int_in_urb); |
257 | kfree(dev->read_queue); | 250 | kfree(dev->read_queue); |
@@ -288,7 +281,8 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer, | |||
288 | if (dev == NULL || !dev->present) | 281 | if (dev == NULL || !dev->present) |
289 | return -ENODEV; | 282 | return -ENODEV; |
290 | 283 | ||
291 | dbg("%s - minor %d, count = %zd", __func__, dev->minor, count); | 284 | dev_dbg(&dev->interface->dev, "minor %d, count = %zd\n", |
285 | dev->minor, count); | ||
292 | 286 | ||
293 | /* read count must be packet size (+ time stamp) */ | 287 | /* read count must be packet size (+ time stamp) */ |
294 | if ((count != dev->report_size) | 288 | if ((count != dev->report_size) |
@@ -356,7 +350,8 @@ static ssize_t iowarrior_write(struct file *file, | |||
356 | retval = -ENODEV; | 350 | retval = -ENODEV; |
357 | goto exit; | 351 | goto exit; |
358 | } | 352 | } |
359 | dbg("%s - minor %d, count = %zd", __func__, dev->minor, count); | 353 | dev_dbg(&dev->interface->dev, "minor %d, count = %zd\n", |
354 | dev->minor, count); | ||
360 | /* if count is 0 we're already done */ | 355 | /* if count is 0 we're already done */ |
361 | if (count == 0) { | 356 | if (count == 0) { |
362 | retval = 0; | 357 | retval = 0; |
@@ -418,14 +413,16 @@ static ssize_t iowarrior_write(struct file *file, | |||
418 | int_out_urb = usb_alloc_urb(0, GFP_KERNEL); | 413 | int_out_urb = usb_alloc_urb(0, GFP_KERNEL); |
419 | if (!int_out_urb) { | 414 | if (!int_out_urb) { |
420 | retval = -ENOMEM; | 415 | retval = -ENOMEM; |
421 | dbg("%s Unable to allocate urb ", __func__); | 416 | dev_dbg(&dev->interface->dev, |
417 | "Unable to allocate urb\n"); | ||
422 | goto error_no_urb; | 418 | goto error_no_urb; |
423 | } | 419 | } |
424 | buf = usb_alloc_coherent(dev->udev, dev->report_size, | 420 | buf = usb_alloc_coherent(dev->udev, dev->report_size, |
425 | GFP_KERNEL, &int_out_urb->transfer_dma); | 421 | GFP_KERNEL, &int_out_urb->transfer_dma); |
426 | if (!buf) { | 422 | if (!buf) { |
427 | retval = -ENOMEM; | 423 | retval = -ENOMEM; |
428 | dbg("%s Unable to allocate buffer ", __func__); | 424 | dev_dbg(&dev->interface->dev, |
425 | "Unable to allocate buffer\n"); | ||
429 | goto error_no_buffer; | 426 | goto error_no_buffer; |
430 | } | 427 | } |
431 | usb_fill_int_urb(int_out_urb, dev->udev, | 428 | usb_fill_int_urb(int_out_urb, dev->udev, |
@@ -441,8 +438,9 @@ static ssize_t iowarrior_write(struct file *file, | |||
441 | } | 438 | } |
442 | retval = usb_submit_urb(int_out_urb, GFP_KERNEL); | 439 | retval = usb_submit_urb(int_out_urb, GFP_KERNEL); |
443 | if (retval) { | 440 | if (retval) { |
444 | dbg("%s submit error %d for urb nr.%d", __func__, | 441 | dev_dbg(&dev->interface->dev, |
445 | retval, atomic_read(&dev->write_busy)); | 442 | "submit error %d for urb nr.%d\n", |
443 | retval, atomic_read(&dev->write_busy)); | ||
446 | goto error; | 444 | goto error; |
447 | } | 445 | } |
448 | /* submit was ok */ | 446 | /* submit was ok */ |
@@ -502,8 +500,8 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd, | |||
502 | goto error_out; | 500 | goto error_out; |
503 | } | 501 | } |
504 | 502 | ||
505 | dbg("%s - minor %d, cmd 0x%.4x, arg %ld", __func__, dev->minor, cmd, | 503 | dev_dbg(&dev->interface->dev, "minor %d, cmd 0x%.4x, arg %ld\n", |
506 | arg); | 504 | dev->minor, cmd, arg); |
507 | 505 | ||
508 | retval = 0; | 506 | retval = 0; |
509 | io_res = 0; | 507 | io_res = 0; |
@@ -601,8 +599,6 @@ static int iowarrior_open(struct inode *inode, struct file *file) | |||
601 | int subminor; | 599 | int subminor; |
602 | int retval = 0; | 600 | int retval = 0; |
603 | 601 | ||
604 | dbg("%s", __func__); | ||
605 | |||
606 | mutex_lock(&iowarrior_mutex); | 602 | mutex_lock(&iowarrior_mutex); |
607 | subminor = iminor(inode); | 603 | subminor = iminor(inode); |
608 | 604 | ||
@@ -662,7 +658,7 @@ static int iowarrior_release(struct inode *inode, struct file *file) | |||
662 | return -ENODEV; | 658 | return -ENODEV; |
663 | } | 659 | } |
664 | 660 | ||
665 | dbg("%s - minor %d", __func__, dev->minor); | 661 | dev_dbg(&dev->interface->dev, "minor %d\n", dev->minor); |
666 | 662 | ||
667 | /* lock our device */ | 663 | /* lock our device */ |
668 | mutex_lock(&dev->mutex); | 664 | mutex_lock(&dev->mutex); |
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index a31641e18d19..f43c61989cef 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <linux/clk.h> | ||
21 | #include <linux/i2c.h> | 22 | #include <linux/i2c.h> |
22 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
23 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
@@ -57,10 +58,12 @@ struct usb3503 { | |||
57 | enum usb3503_mode mode; | 58 | enum usb3503_mode mode; |
58 | struct regmap *regmap; | 59 | struct regmap *regmap; |
59 | struct device *dev; | 60 | struct device *dev; |
61 | struct clk *clk; | ||
60 | u8 port_off_mask; | 62 | u8 port_off_mask; |
61 | int gpio_intn; | 63 | int gpio_intn; |
62 | int gpio_reset; | 64 | int gpio_reset; |
63 | int gpio_connect; | 65 | int gpio_connect; |
66 | bool secondary_ref_clk; | ||
64 | }; | 67 | }; |
65 | 68 | ||
66 | static int usb3503_reset(struct usb3503 *hub, int state) | 69 | static int usb3503_reset(struct usb3503 *hub, int state) |
@@ -184,8 +187,58 @@ static int usb3503_probe(struct usb3503 *hub) | |||
184 | hub->gpio_reset = pdata->gpio_reset; | 187 | hub->gpio_reset = pdata->gpio_reset; |
185 | hub->mode = pdata->initial_mode; | 188 | hub->mode = pdata->initial_mode; |
186 | } else if (np) { | 189 | } else if (np) { |
190 | struct clk *clk; | ||
187 | hub->port_off_mask = 0; | 191 | hub->port_off_mask = 0; |
188 | 192 | ||
193 | clk = devm_clk_get(dev, "refclk"); | ||
194 | if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { | ||
195 | dev_err(dev, "unable to request refclk (%d)\n", err); | ||
196 | return PTR_ERR(clk); | ||
197 | } | ||
198 | |||
199 | if (!IS_ERR(clk)) { | ||
200 | u32 rate = 0; | ||
201 | hub->clk = clk; | ||
202 | |||
203 | if (!of_property_read_u32(np, "refclk-frequency", | ||
204 | &rate)) { | ||
205 | |||
206 | switch (rate) { | ||
207 | case 38400000: | ||
208 | case 26000000: | ||
209 | case 19200000: | ||
210 | case 12000000: | ||
211 | hub->secondary_ref_clk = 0; | ||
212 | break; | ||
213 | case 24000000: | ||
214 | case 27000000: | ||
215 | case 25000000: | ||
216 | case 50000000: | ||
217 | hub->secondary_ref_clk = 1; | ||
218 | break; | ||
219 | default: | ||
220 | dev_err(dev, | ||
221 | "unsupported reference clock rate (%d)\n", | ||
222 | (int) rate); | ||
223 | return -EINVAL; | ||
224 | } | ||
225 | err = clk_set_rate(hub->clk, rate); | ||
226 | if (err) { | ||
227 | dev_err(dev, | ||
228 | "unable to set reference clock rate to %d\n", | ||
229 | (int) rate); | ||
230 | return err; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | err = clk_prepare_enable(hub->clk); | ||
235 | if (err) { | ||
236 | dev_err(dev, | ||
237 | "unable to enable reference clock\n"); | ||
238 | return err; | ||
239 | } | ||
240 | } | ||
241 | |||
189 | property = of_get_property(np, "disabled-ports", &len); | 242 | property = of_get_property(np, "disabled-ports", &len); |
190 | if (property && (len / sizeof(u32)) > 0) { | 243 | if (property && (len / sizeof(u32)) > 0) { |
191 | int i; | 244 | int i; |
@@ -213,8 +266,10 @@ static int usb3503_probe(struct usb3503 *hub) | |||
213 | dev_err(dev, "Ports disabled with no control interface\n"); | 266 | dev_err(dev, "Ports disabled with no control interface\n"); |
214 | 267 | ||
215 | if (gpio_is_valid(hub->gpio_intn)) { | 268 | if (gpio_is_valid(hub->gpio_intn)) { |
216 | err = devm_gpio_request_one(dev, hub->gpio_intn, | 269 | int val = hub->secondary_ref_clk ? GPIOF_OUT_INIT_LOW : |
217 | GPIOF_OUT_INIT_HIGH, "usb3503 intn"); | 270 | GPIOF_OUT_INIT_HIGH; |
271 | err = devm_gpio_request_one(dev, hub->gpio_intn, val, | ||
272 | "usb3503 intn"); | ||
218 | if (err) { | 273 | if (err) { |
219 | dev_err(dev, | 274 | dev_err(dev, |
220 | "unable to request GPIO %d as connect pin (%d)\n", | 275 | "unable to request GPIO %d as connect pin (%d)\n", |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index f6568b5e9b06..51a6da256772 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -1320,6 +1320,11 @@ static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async) | |||
1320 | urb->context = &completion; | 1320 | urb->context = &completion; |
1321 | urb->complete = unlink1_callback; | 1321 | urb->complete = unlink1_callback; |
1322 | 1322 | ||
1323 | if (usb_pipeout(urb->pipe)) { | ||
1324 | simple_fill_buf(urb); | ||
1325 | urb->transfer_flags |= URB_ZERO_PACKET; | ||
1326 | } | ||
1327 | |||
1323 | /* keep the endpoint busy. there are lots of hc/hcd-internal | 1328 | /* keep the endpoint busy. there are lots of hc/hcd-internal |
1324 | * states, and testing should get to all of them over time. | 1329 | * states, and testing should get to all of them over time. |
1325 | * | 1330 | * |
@@ -1340,6 +1345,9 @@ static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async) | |||
1340 | while (!completion_done(&completion)) { | 1345 | while (!completion_done(&completion)) { |
1341 | retval = usb_unlink_urb(urb); | 1346 | retval = usb_unlink_urb(urb); |
1342 | 1347 | ||
1348 | if (retval == 0 && usb_pipein(urb->pipe)) | ||
1349 | retval = simple_check_buf(dev, urb); | ||
1350 | |||
1343 | switch (retval) { | 1351 | switch (retval) { |
1344 | case -EBUSY: | 1352 | case -EBUSY: |
1345 | case -EIDRM: | 1353 | case -EIDRM: |
@@ -1450,6 +1458,11 @@ static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num, | |||
1450 | unlink_queued_callback, &ctx); | 1458 | unlink_queued_callback, &ctx); |
1451 | ctx.urbs[i]->transfer_dma = buf_dma; | 1459 | ctx.urbs[i]->transfer_dma = buf_dma; |
1452 | ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; | 1460 | ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; |
1461 | |||
1462 | if (usb_pipeout(ctx.urbs[i]->pipe)) { | ||
1463 | simple_fill_buf(ctx.urbs[i]); | ||
1464 | ctx.urbs[i]->transfer_flags |= URB_ZERO_PACKET; | ||
1465 | } | ||
1453 | } | 1466 | } |
1454 | 1467 | ||
1455 | /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */ | 1468 | /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */ |
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c index 24278208bf74..1472805083de 100644 --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c | |||
@@ -296,6 +296,7 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_ | |||
296 | 296 | ||
297 | /* save our data pointer in this interface device */ | 297 | /* save our data pointer in this interface device */ |
298 | usb_set_intfdata(interface, dev); | 298 | usb_set_intfdata(interface, dev); |
299 | dev->bbu = -1; | ||
299 | 300 | ||
300 | /* we can register the device now, as it is ready */ | 301 | /* we can register the device now, as it is ready */ |
301 | retval = usb_register_dev(interface, &yurex_class); | 302 | retval = usb_register_dev(interface, &yurex_class); |
@@ -306,8 +307,6 @@ static int yurex_probe(struct usb_interface *interface, const struct usb_device_ | |||
306 | goto error; | 307 | goto error; |
307 | } | 308 | } |
308 | 309 | ||
309 | dev->bbu = -1; | ||
310 | |||
311 | dev_info(&interface->dev, | 310 | dev_info(&interface->dev, |
312 | "USB YUREX device now attached to Yurex #%d\n", | 311 | "USB YUREX device now attached to Yurex #%d\n", |
313 | interface->minor); | 312 | interface->minor); |
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 8b789792f6fa..06cc5d6ea681 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig | |||
@@ -76,7 +76,7 @@ config USB_MUSB_TUSB6010 | |||
76 | 76 | ||
77 | config USB_MUSB_OMAP2PLUS | 77 | config USB_MUSB_OMAP2PLUS |
78 | tristate "OMAP2430 and onwards" | 78 | tristate "OMAP2430 and onwards" |
79 | depends on ARCH_OMAP2PLUS | 79 | depends on ARCH_OMAP2PLUS && USB |
80 | select GENERIC_PHY | 80 | select GENERIC_PHY |
81 | 81 | ||
82 | config USB_MUSB_AM35X | 82 | config USB_MUSB_AM35X |
@@ -141,10 +141,11 @@ config USB_TI_CPPI_DMA | |||
141 | config USB_TI_CPPI41_DMA | 141 | config USB_TI_CPPI41_DMA |
142 | bool 'TI CPPI 4.1 (AM335x)' | 142 | bool 'TI CPPI 4.1 (AM335x)' |
143 | depends on ARCH_OMAP | 143 | depends on ARCH_OMAP |
144 | select TI_CPPI41 | ||
144 | 145 | ||
145 | config USB_TUSB_OMAP_DMA | 146 | config USB_TUSB_OMAP_DMA |
146 | bool 'TUSB 6010' | 147 | bool 'TUSB 6010' |
147 | depends on USB_MUSB_TUSB6010 | 148 | depends on USB_MUSB_TUSB6010 = USB_MUSB_HDRC # both built-in or both modules |
148 | depends on ARCH_OMAP | 149 | depends on ARCH_OMAP |
149 | help | 150 | help |
150 | Enable DMA transfers on TUSB 6010 when OMAP DMA is available. | 151 | Enable DMA transfers on TUSB 6010 when OMAP DMA is available. |
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c index b3aa0184af9a..0a34dd859555 100644 --- a/drivers/usb/musb/am35x.c +++ b/drivers/usb/musb/am35x.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
34 | #include <linux/dma-mapping.h> | 34 | #include <linux/dma-mapping.h> |
35 | #include <linux/usb/usb_phy_gen_xceiv.h> | 35 | #include <linux/usb/usb_phy_generic.h> |
36 | #include <linux/platform_data/usb-omap.h> | 36 | #include <linux/platform_data/usb-omap.h> |
37 | 37 | ||
38 | #include "musb_core.h" | 38 | #include "musb_core.h" |
@@ -85,6 +85,7 @@ | |||
85 | struct am35x_glue { | 85 | struct am35x_glue { |
86 | struct device *dev; | 86 | struct device *dev; |
87 | struct platform_device *musb; | 87 | struct platform_device *musb; |
88 | struct platform_device *phy; | ||
88 | struct clk *phy_clk; | 89 | struct clk *phy_clk; |
89 | struct clk *clk; | 90 | struct clk *clk; |
90 | }; | 91 | }; |
@@ -360,7 +361,6 @@ static int am35x_musb_init(struct musb *musb) | |||
360 | if (!rev) | 361 | if (!rev) |
361 | return -ENODEV; | 362 | return -ENODEV; |
362 | 363 | ||
363 | usb_nop_xceiv_register(); | ||
364 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 364 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
365 | if (IS_ERR_OR_NULL(musb->xceiv)) | 365 | if (IS_ERR_OR_NULL(musb->xceiv)) |
366 | return -EPROBE_DEFER; | 366 | return -EPROBE_DEFER; |
@@ -402,7 +402,6 @@ static int am35x_musb_exit(struct musb *musb) | |||
402 | data->set_phy_power(0); | 402 | data->set_phy_power(0); |
403 | 403 | ||
404 | usb_put_phy(musb->xceiv); | 404 | usb_put_phy(musb->xceiv); |
405 | usb_nop_xceiv_unregister(); | ||
406 | 405 | ||
407 | return 0; | 406 | return 0; |
408 | } | 407 | } |
@@ -505,6 +504,9 @@ static int am35x_probe(struct platform_device *pdev) | |||
505 | 504 | ||
506 | pdata->platform_ops = &am35x_ops; | 505 | pdata->platform_ops = &am35x_ops; |
507 | 506 | ||
507 | glue->phy = usb_phy_generic_register(); | ||
508 | if (IS_ERR(glue->phy)) | ||
509 | goto err7; | ||
508 | platform_set_drvdata(pdev, glue); | 510 | platform_set_drvdata(pdev, glue); |
509 | 511 | ||
510 | pinfo = am35x_dev_info; | 512 | pinfo = am35x_dev_info; |
@@ -518,11 +520,14 @@ static int am35x_probe(struct platform_device *pdev) | |||
518 | if (IS_ERR(musb)) { | 520 | if (IS_ERR(musb)) { |
519 | ret = PTR_ERR(musb); | 521 | ret = PTR_ERR(musb); |
520 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | 522 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
521 | goto err7; | 523 | goto err8; |
522 | } | 524 | } |
523 | 525 | ||
524 | return 0; | 526 | return 0; |
525 | 527 | ||
528 | err8: | ||
529 | usb_phy_generic_unregister(glue->phy); | ||
530 | |||
526 | err7: | 531 | err7: |
527 | clk_disable(clk); | 532 | clk_disable(clk); |
528 | 533 | ||
@@ -547,6 +552,7 @@ static int am35x_remove(struct platform_device *pdev) | |||
547 | struct am35x_glue *glue = platform_get_drvdata(pdev); | 552 | struct am35x_glue *glue = platform_get_drvdata(pdev); |
548 | 553 | ||
549 | platform_device_unregister(glue->musb); | 554 | platform_device_unregister(glue->musb); |
555 | usb_phy_generic_unregister(glue->phy); | ||
550 | clk_disable(glue->clk); | 556 | clk_disable(glue->clk); |
551 | clk_disable(glue->phy_clk); | 557 | clk_disable(glue->phy_clk); |
552 | clk_put(glue->clk); | 558 | clk_put(glue->clk); |
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c index 796677fa9a15..d40d5f0b5528 100644 --- a/drivers/usb/musb/blackfin.c +++ b/drivers/usb/musb/blackfin.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
19 | #include <linux/dma-mapping.h> | 19 | #include <linux/dma-mapping.h> |
20 | #include <linux/prefetch.h> | 20 | #include <linux/prefetch.h> |
21 | #include <linux/usb/usb_phy_gen_xceiv.h> | 21 | #include <linux/usb/usb_phy_generic.h> |
22 | 22 | ||
23 | #include <asm/cacheflush.h> | 23 | #include <asm/cacheflush.h> |
24 | 24 | ||
@@ -29,6 +29,7 @@ | |||
29 | struct bfin_glue { | 29 | struct bfin_glue { |
30 | struct device *dev; | 30 | struct device *dev; |
31 | struct platform_device *musb; | 31 | struct platform_device *musb; |
32 | struct platform_device *phy; | ||
32 | }; | 33 | }; |
33 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | 34 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
34 | 35 | ||
@@ -401,7 +402,6 @@ static int bfin_musb_init(struct musb *musb) | |||
401 | } | 402 | } |
402 | gpio_direction_output(musb->config->gpio_vrsel, 0); | 403 | gpio_direction_output(musb->config->gpio_vrsel, 0); |
403 | 404 | ||
404 | usb_nop_xceiv_register(); | ||
405 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 405 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
406 | if (IS_ERR_OR_NULL(musb->xceiv)) { | 406 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
407 | gpio_free(musb->config->gpio_vrsel); | 407 | gpio_free(musb->config->gpio_vrsel); |
@@ -424,9 +424,8 @@ static int bfin_musb_init(struct musb *musb) | |||
424 | static int bfin_musb_exit(struct musb *musb) | 424 | static int bfin_musb_exit(struct musb *musb) |
425 | { | 425 | { |
426 | gpio_free(musb->config->gpio_vrsel); | 426 | gpio_free(musb->config->gpio_vrsel); |
427 | |||
428 | usb_put_phy(musb->xceiv); | 427 | usb_put_phy(musb->xceiv); |
429 | usb_nop_xceiv_unregister(); | 428 | |
430 | return 0; | 429 | return 0; |
431 | } | 430 | } |
432 | 431 | ||
@@ -477,6 +476,9 @@ static int bfin_probe(struct platform_device *pdev) | |||
477 | 476 | ||
478 | pdata->platform_ops = &bfin_ops; | 477 | pdata->platform_ops = &bfin_ops; |
479 | 478 | ||
479 | glue->phy = usb_phy_generic_register(); | ||
480 | if (IS_ERR(glue->phy)) | ||
481 | goto err2; | ||
480 | platform_set_drvdata(pdev, glue); | 482 | platform_set_drvdata(pdev, glue); |
481 | 483 | ||
482 | memset(musb_resources, 0x00, sizeof(*musb_resources) * | 484 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
@@ -514,6 +516,9 @@ static int bfin_probe(struct platform_device *pdev) | |||
514 | return 0; | 516 | return 0; |
515 | 517 | ||
516 | err3: | 518 | err3: |
519 | usb_phy_generic_unregister(glue->phy); | ||
520 | |||
521 | err2: | ||
517 | platform_device_put(musb); | 522 | platform_device_put(musb); |
518 | 523 | ||
519 | err1: | 524 | err1: |
@@ -528,6 +533,7 @@ static int bfin_remove(struct platform_device *pdev) | |||
528 | struct bfin_glue *glue = platform_get_drvdata(pdev); | 533 | struct bfin_glue *glue = platform_get_drvdata(pdev); |
529 | 534 | ||
530 | platform_device_unregister(glue->musb); | 535 | platform_device_unregister(glue->musb); |
536 | usb_phy_generic_unregister(glue->phy); | ||
531 | kfree(glue); | 537 | kfree(glue); |
532 | 538 | ||
533 | return 0; | 539 | return 0; |
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c index e3486de71995..058775e647ad 100644 --- a/drivers/usb/musb/da8xx.c +++ b/drivers/usb/musb/da8xx.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
34 | #include <linux/dma-mapping.h> | 34 | #include <linux/dma-mapping.h> |
35 | #include <linux/usb/usb_phy_gen_xceiv.h> | 35 | #include <linux/usb/usb_phy_generic.h> |
36 | 36 | ||
37 | #include <mach/da8xx.h> | 37 | #include <mach/da8xx.h> |
38 | #include <linux/platform_data/usb-davinci.h> | 38 | #include <linux/platform_data/usb-davinci.h> |
@@ -85,6 +85,7 @@ | |||
85 | struct da8xx_glue { | 85 | struct da8xx_glue { |
86 | struct device *dev; | 86 | struct device *dev; |
87 | struct platform_device *musb; | 87 | struct platform_device *musb; |
88 | struct platform_device *phy; | ||
88 | struct clk *clk; | 89 | struct clk *clk; |
89 | }; | 90 | }; |
90 | 91 | ||
@@ -418,7 +419,6 @@ static int da8xx_musb_init(struct musb *musb) | |||
418 | if (!rev) | 419 | if (!rev) |
419 | goto fail; | 420 | goto fail; |
420 | 421 | ||
421 | usb_nop_xceiv_register(); | ||
422 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 422 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
423 | if (IS_ERR_OR_NULL(musb->xceiv)) { | 423 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
424 | ret = -EPROBE_DEFER; | 424 | ret = -EPROBE_DEFER; |
@@ -453,7 +453,6 @@ static int da8xx_musb_exit(struct musb *musb) | |||
453 | phy_off(); | 453 | phy_off(); |
454 | 454 | ||
455 | usb_put_phy(musb->xceiv); | 455 | usb_put_phy(musb->xceiv); |
456 | usb_nop_xceiv_unregister(); | ||
457 | 456 | ||
458 | return 0; | 457 | return 0; |
459 | } | 458 | } |
@@ -512,6 +511,11 @@ static int da8xx_probe(struct platform_device *pdev) | |||
512 | 511 | ||
513 | pdata->platform_ops = &da8xx_ops; | 512 | pdata->platform_ops = &da8xx_ops; |
514 | 513 | ||
514 | glue->phy = usb_phy_generic_register(); | ||
515 | if (IS_ERR(glue->phy)) { | ||
516 | ret = PTR_ERR(glue->phy); | ||
517 | goto err5; | ||
518 | } | ||
515 | platform_set_drvdata(pdev, glue); | 519 | platform_set_drvdata(pdev, glue); |
516 | 520 | ||
517 | memset(musb_resources, 0x00, sizeof(*musb_resources) * | 521 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
@@ -538,11 +542,14 @@ static int da8xx_probe(struct platform_device *pdev) | |||
538 | if (IS_ERR(musb)) { | 542 | if (IS_ERR(musb)) { |
539 | ret = PTR_ERR(musb); | 543 | ret = PTR_ERR(musb); |
540 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); | 544 | dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); |
541 | goto err5; | 545 | goto err6; |
542 | } | 546 | } |
543 | 547 | ||
544 | return 0; | 548 | return 0; |
545 | 549 | ||
550 | err6: | ||
551 | usb_phy_generic_unregister(glue->phy); | ||
552 | |||
546 | err5: | 553 | err5: |
547 | clk_disable(clk); | 554 | clk_disable(clk); |
548 | 555 | ||
@@ -561,6 +568,7 @@ static int da8xx_remove(struct platform_device *pdev) | |||
561 | struct da8xx_glue *glue = platform_get_drvdata(pdev); | 568 | struct da8xx_glue *glue = platform_get_drvdata(pdev); |
562 | 569 | ||
563 | platform_device_unregister(glue->musb); | 570 | platform_device_unregister(glue->musb); |
571 | usb_phy_generic_unregister(glue->phy); | ||
564 | clk_disable(glue->clk); | 572 | clk_disable(glue->clk); |
565 | clk_put(glue->clk); | 573 | clk_put(glue->clk); |
566 | kfree(glue); | 574 | kfree(glue); |
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c index c259dac9d056..de8492b06e46 100644 --- a/drivers/usb/musb/davinci.c +++ b/drivers/usb/musb/davinci.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <linux/gpio.h> | 32 | #include <linux/gpio.h> |
33 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
34 | #include <linux/dma-mapping.h> | 34 | #include <linux/dma-mapping.h> |
35 | #include <linux/usb/usb_phy_gen_xceiv.h> | 35 | #include <linux/usb/usb_phy_generic.h> |
36 | 36 | ||
37 | #include <mach/cputype.h> | 37 | #include <mach/cputype.h> |
38 | #include <mach/hardware.h> | 38 | #include <mach/hardware.h> |
@@ -381,7 +381,6 @@ static int davinci_musb_init(struct musb *musb) | |||
381 | u32 revision; | 381 | u32 revision; |
382 | int ret = -ENODEV; | 382 | int ret = -ENODEV; |
383 | 383 | ||
384 | usb_nop_xceiv_register(); | ||
385 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 384 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
386 | if (IS_ERR_OR_NULL(musb->xceiv)) { | 385 | if (IS_ERR_OR_NULL(musb->xceiv)) { |
387 | ret = -EPROBE_DEFER; | 386 | ret = -EPROBE_DEFER; |
@@ -439,7 +438,7 @@ static int davinci_musb_init(struct musb *musb) | |||
439 | fail: | 438 | fail: |
440 | usb_put_phy(musb->xceiv); | 439 | usb_put_phy(musb->xceiv); |
441 | unregister: | 440 | unregister: |
442 | usb_nop_xceiv_unregister(); | 441 | usb_phy_generic_unregister(); |
443 | return ret; | 442 | return ret; |
444 | } | 443 | } |
445 | 444 | ||
@@ -487,7 +486,6 @@ static int davinci_musb_exit(struct musb *musb) | |||
487 | phy_off(); | 486 | phy_off(); |
488 | 487 | ||
489 | usb_put_phy(musb->xceiv); | 488 | usb_put_phy(musb->xceiv); |
490 | usb_nop_xceiv_unregister(); | ||
491 | 489 | ||
492 | return 0; | 490 | return 0; |
493 | } | 491 | } |
@@ -545,6 +543,7 @@ static int davinci_probe(struct platform_device *pdev) | |||
545 | 543 | ||
546 | pdata->platform_ops = &davinci_ops; | 544 | pdata->platform_ops = &davinci_ops; |
547 | 545 | ||
546 | usb_phy_generic_register(); | ||
548 | platform_set_drvdata(pdev, glue); | 547 | platform_set_drvdata(pdev, glue); |
549 | 548 | ||
550 | memset(musb_resources, 0x00, sizeof(*musb_resources) * | 549 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
@@ -603,6 +602,7 @@ static int davinci_remove(struct platform_device *pdev) | |||
603 | struct davinci_glue *glue = platform_get_drvdata(pdev); | 602 | struct davinci_glue *glue = platform_get_drvdata(pdev); |
604 | 603 | ||
605 | platform_device_unregister(glue->musb); | 604 | platform_device_unregister(glue->musb); |
605 | usb_phy_generic_unregister(); | ||
606 | clk_disable(glue->clk); | 606 | clk_disable(glue->clk); |
607 | clk_put(glue->clk); | 607 | clk_put(glue->clk); |
608 | kfree(glue); | 608 | kfree(glue); |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 07576907e2c6..61da471b7aed 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -848,6 +848,10 @@ b_host: | |||
848 | } | 848 | } |
849 | } | 849 | } |
850 | 850 | ||
851 | /* handle babble condition */ | ||
852 | if (int_usb & MUSB_INTR_BABBLE) | ||
853 | schedule_work(&musb->recover_work); | ||
854 | |||
851 | #if 0 | 855 | #if 0 |
852 | /* REVISIT ... this would be for multiplexing periodic endpoints, or | 856 | /* REVISIT ... this would be for multiplexing periodic endpoints, or |
853 | * supporting transfer phasing to prevent exceeding ISO bandwidth | 857 | * supporting transfer phasing to prevent exceeding ISO bandwidth |
@@ -1746,6 +1750,34 @@ static void musb_irq_work(struct work_struct *data) | |||
1746 | } | 1750 | } |
1747 | } | 1751 | } |
1748 | 1752 | ||
1753 | /* Recover from babble interrupt conditions */ | ||
1754 | static void musb_recover_work(struct work_struct *data) | ||
1755 | { | ||
1756 | struct musb *musb = container_of(data, struct musb, recover_work); | ||
1757 | int status; | ||
1758 | |||
1759 | musb_platform_reset(musb); | ||
1760 | |||
1761 | usb_phy_vbus_off(musb->xceiv); | ||
1762 | udelay(100); | ||
1763 | |||
1764 | usb_phy_vbus_on(musb->xceiv); | ||
1765 | udelay(100); | ||
1766 | |||
1767 | /* | ||
1768 | * When a babble condition occurs, the musb controller removes the | ||
1769 | * session bit and the endpoint config is lost. | ||
1770 | */ | ||
1771 | if (musb->dyn_fifo) | ||
1772 | status = ep_config_from_table(musb); | ||
1773 | else | ||
1774 | status = ep_config_from_hw(musb); | ||
1775 | |||
1776 | /* start the session again */ | ||
1777 | if (status == 0) | ||
1778 | musb_start(musb); | ||
1779 | } | ||
1780 | |||
1749 | /* -------------------------------------------------------------------------- | 1781 | /* -------------------------------------------------------------------------- |
1750 | * Init support | 1782 | * Init support |
1751 | */ | 1783 | */ |
@@ -1913,6 +1945,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1913 | 1945 | ||
1914 | /* Init IRQ workqueue before request_irq */ | 1946 | /* Init IRQ workqueue before request_irq */ |
1915 | INIT_WORK(&musb->irq_work, musb_irq_work); | 1947 | INIT_WORK(&musb->irq_work, musb_irq_work); |
1948 | INIT_WORK(&musb->recover_work, musb_recover_work); | ||
1916 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); | 1949 | INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); |
1917 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); | 1950 | INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); |
1918 | 1951 | ||
@@ -2008,6 +2041,7 @@ fail4: | |||
2008 | 2041 | ||
2009 | fail3: | 2042 | fail3: |
2010 | cancel_work_sync(&musb->irq_work); | 2043 | cancel_work_sync(&musb->irq_work); |
2044 | cancel_work_sync(&musb->recover_work); | ||
2011 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2045 | cancel_delayed_work_sync(&musb->finish_resume_work); |
2012 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2046 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
2013 | if (musb->dma_controller) | 2047 | if (musb->dma_controller) |
@@ -2073,6 +2107,7 @@ static int musb_remove(struct platform_device *pdev) | |||
2073 | dma_controller_destroy(musb->dma_controller); | 2107 | dma_controller_destroy(musb->dma_controller); |
2074 | 2108 | ||
2075 | cancel_work_sync(&musb->irq_work); | 2109 | cancel_work_sync(&musb->irq_work); |
2110 | cancel_work_sync(&musb->recover_work); | ||
2076 | cancel_delayed_work_sync(&musb->finish_resume_work); | 2111 | cancel_delayed_work_sync(&musb->finish_resume_work); |
2077 | cancel_delayed_work_sync(&musb->deassert_reset_work); | 2112 | cancel_delayed_work_sync(&musb->deassert_reset_work); |
2078 | musb_free(musb); | 2113 | musb_free(musb); |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index 7083e82776ff..d155a156f240 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -192,6 +192,7 @@ struct musb_platform_ops { | |||
192 | 192 | ||
193 | int (*set_mode)(struct musb *musb, u8 mode); | 193 | int (*set_mode)(struct musb *musb, u8 mode); |
194 | void (*try_idle)(struct musb *musb, unsigned long timeout); | 194 | void (*try_idle)(struct musb *musb, unsigned long timeout); |
195 | void (*reset)(struct musb *musb); | ||
195 | 196 | ||
196 | int (*vbus_status)(struct musb *musb); | 197 | int (*vbus_status)(struct musb *musb); |
197 | void (*set_vbus)(struct musb *musb, int on); | 198 | void (*set_vbus)(struct musb *musb, int on); |
@@ -296,6 +297,7 @@ struct musb { | |||
296 | 297 | ||
297 | irqreturn_t (*isr)(int, void *); | 298 | irqreturn_t (*isr)(int, void *); |
298 | struct work_struct irq_work; | 299 | struct work_struct irq_work; |
300 | struct work_struct recover_work; | ||
299 | struct delayed_work deassert_reset_work; | 301 | struct delayed_work deassert_reset_work; |
300 | struct delayed_work finish_resume_work; | 302 | struct delayed_work finish_resume_work; |
301 | u16 hwvers; | 303 | u16 hwvers; |
@@ -337,6 +339,7 @@ struct musb { | |||
337 | dma_addr_t async; | 339 | dma_addr_t async; |
338 | dma_addr_t sync; | 340 | dma_addr_t sync; |
339 | void __iomem *sync_va; | 341 | void __iomem *sync_va; |
342 | u8 tusb_revision; | ||
340 | #endif | 343 | #endif |
341 | 344 | ||
342 | /* passed down from chip/board specific irq handlers */ | 345 | /* passed down from chip/board specific irq handlers */ |
@@ -552,6 +555,12 @@ static inline void musb_platform_try_idle(struct musb *musb, | |||
552 | musb->ops->try_idle(musb, timeout); | 555 | musb->ops->try_idle(musb, timeout); |
553 | } | 556 | } |
554 | 557 | ||
558 | static inline void musb_platform_reset(struct musb *musb) | ||
559 | { | ||
560 | if (musb->ops->reset) | ||
561 | musb->ops->reset(musb); | ||
562 | } | ||
563 | |||
555 | static inline int musb_platform_get_vbus_status(struct musb *musb) | 564 | static inline int musb_platform_get_vbus_status(struct musb *musb) |
556 | { | 565 | { |
557 | if (!musb->ops->vbus_status) | 566 | if (!musb->ops->vbus_status) |
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c index e2fd263585de..51beb13c7e1a 100644 --- a/drivers/usb/musb/musb_dsps.c +++ b/drivers/usb/musb/musb_dsps.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/pm_runtime.h> | 36 | #include <linux/pm_runtime.h> |
37 | #include <linux/module.h> | 37 | #include <linux/module.h> |
38 | #include <linux/usb/usb_phy_gen_xceiv.h> | 38 | #include <linux/usb/usb_phy_generic.h> |
39 | #include <linux/platform_data/usb-omap.h> | 39 | #include <linux/platform_data/usb-omap.h> |
40 | #include <linux/sizes.h> | 40 | #include <linux/sizes.h> |
41 | 41 | ||
@@ -329,9 +329,21 @@ static irqreturn_t dsps_interrupt(int irq, void *hci) | |||
329 | * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. | 329 | * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. |
330 | * Also, DRVVBUS pulses for SRP (but not at 5V) ... | 330 | * Also, DRVVBUS pulses for SRP (but not at 5V) ... |
331 | */ | 331 | */ |
332 | if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) | 332 | if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE) { |
333 | pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); | 333 | pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); |
334 | 334 | ||
335 | /* | ||
336 | * When a babble condition occurs, the musb controller removes | ||
337 | * the session and is no longer in host mode. Hence, all | ||
338 | * devices connected to its root hub get disconnected. | ||
339 | * | ||
340 | * Hand this error down to the musb core isr, so it can | ||
341 | * recover. | ||
342 | */ | ||
343 | musb->int_usb = MUSB_INTR_BABBLE | MUSB_INTR_DISCONNECT; | ||
344 | musb->int_tx = musb->int_rx = 0; | ||
345 | } | ||
346 | |||
335 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { | 347 | if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { |
336 | int drvvbus = dsps_readl(reg_base, wrp->status); | 348 | int drvvbus = dsps_readl(reg_base, wrp->status); |
337 | void __iomem *mregs = musb->mregs; | 349 | void __iomem *mregs = musb->mregs; |
@@ -524,6 +536,16 @@ static int dsps_musb_set_mode(struct musb *musb, u8 mode) | |||
524 | return 0; | 536 | return 0; |
525 | } | 537 | } |
526 | 538 | ||
539 | static void dsps_musb_reset(struct musb *musb) | ||
540 | { | ||
541 | struct device *dev = musb->controller; | ||
542 | struct dsps_glue *glue = dev_get_drvdata(dev->parent); | ||
543 | const struct dsps_musb_wrapper *wrp = glue->wrp; | ||
544 | |||
545 | dsps_writel(musb->ctrl_base, wrp->control, (1 << wrp->reset)); | ||
546 | udelay(100); | ||
547 | } | ||
548 | |||
527 | static struct musb_platform_ops dsps_ops = { | 549 | static struct musb_platform_ops dsps_ops = { |
528 | .init = dsps_musb_init, | 550 | .init = dsps_musb_init, |
529 | .exit = dsps_musb_exit, | 551 | .exit = dsps_musb_exit, |
@@ -533,6 +555,7 @@ static struct musb_platform_ops dsps_ops = { | |||
533 | 555 | ||
534 | .try_idle = dsps_musb_try_idle, | 556 | .try_idle = dsps_musb_try_idle, |
535 | .set_mode = dsps_musb_set_mode, | 557 | .set_mode = dsps_musb_set_mode, |
558 | .reset = dsps_musb_reset, | ||
536 | }; | 559 | }; |
537 | 560 | ||
538 | static u64 musb_dmamask = DMA_BIT_MASK(32); | 561 | static u64 musb_dmamask = DMA_BIT_MASK(32); |
@@ -750,7 +773,7 @@ static const struct of_device_id musb_dsps_of_match[] = { | |||
750 | }; | 773 | }; |
751 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); | 774 | MODULE_DEVICE_TABLE(of, musb_dsps_of_match); |
752 | 775 | ||
753 | #ifdef CONFIG_PM | 776 | #ifdef CONFIG_PM_SLEEP |
754 | static int dsps_suspend(struct device *dev) | 777 | static int dsps_suspend(struct device *dev) |
755 | { | 778 | { |
756 | struct dsps_glue *glue = dev_get_drvdata(dev); | 779 | struct dsps_glue *glue = dev_get_drvdata(dev); |
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c index 4e9fb1d08698..159ef4be1ef2 100644 --- a/drivers/usb/musb/tusb6010.c +++ b/drivers/usb/musb/tusb6010.c | |||
@@ -24,13 +24,14 @@ | |||
24 | #include <linux/io.h> | 24 | #include <linux/io.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | #include <linux/dma-mapping.h> | 26 | #include <linux/dma-mapping.h> |
27 | #include <linux/usb/usb_phy_gen_xceiv.h> | 27 | #include <linux/usb/usb_phy_generic.h> |
28 | 28 | ||
29 | #include "musb_core.h" | 29 | #include "musb_core.h" |
30 | 30 | ||
31 | struct tusb6010_glue { | 31 | struct tusb6010_glue { |
32 | struct device *dev; | 32 | struct device *dev; |
33 | struct platform_device *musb; | 33 | struct platform_device *musb; |
34 | struct platform_device *phy; | ||
34 | }; | 35 | }; |
35 | 36 | ||
36 | static void tusb_musb_set_vbus(struct musb *musb, int is_on); | 37 | static void tusb_musb_set_vbus(struct musb *musb, int is_on); |
@@ -42,7 +43,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on); | |||
42 | * Checks the revision. We need to use the DMA register as 3.0 does not | 43 | * Checks the revision. We need to use the DMA register as 3.0 does not |
43 | * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV. | 44 | * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV. |
44 | */ | 45 | */ |
45 | u8 tusb_get_revision(struct musb *musb) | 46 | static u8 tusb_get_revision(struct musb *musb) |
46 | { | 47 | { |
47 | void __iomem *tbase = musb->ctrl_base; | 48 | void __iomem *tbase = musb->ctrl_base; |
48 | u32 die_id; | 49 | u32 die_id; |
@@ -58,14 +59,13 @@ u8 tusb_get_revision(struct musb *musb) | |||
58 | 59 | ||
59 | return rev; | 60 | return rev; |
60 | } | 61 | } |
61 | EXPORT_SYMBOL_GPL(tusb_get_revision); | ||
62 | 62 | ||
63 | static int tusb_print_revision(struct musb *musb) | 63 | static void tusb_print_revision(struct musb *musb) |
64 | { | 64 | { |
65 | void __iomem *tbase = musb->ctrl_base; | 65 | void __iomem *tbase = musb->ctrl_base; |
66 | u8 rev; | 66 | u8 rev; |
67 | 67 | ||
68 | rev = tusb_get_revision(musb); | 68 | rev = musb->tusb_revision; |
69 | 69 | ||
70 | pr_info("tusb: %s%i.%i %s%i.%i %s%i.%i %s%i.%i %s%i %s%i.%i\n", | 70 | pr_info("tusb: %s%i.%i %s%i.%i %s%i.%i %s%i.%i %s%i %s%i.%i\n", |
71 | "prcm", | 71 | "prcm", |
@@ -84,8 +84,6 @@ static int tusb_print_revision(struct musb *musb) | |||
84 | TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase, TUSB_DIDR1_HI)), | 84 | TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase, TUSB_DIDR1_HI)), |
85 | "rev", | 85 | "rev", |
86 | TUSB_REV_MAJOR(rev), TUSB_REV_MINOR(rev)); | 86 | TUSB_REV_MAJOR(rev), TUSB_REV_MINOR(rev)); |
87 | |||
88 | return tusb_get_revision(musb); | ||
89 | } | 87 | } |
90 | 88 | ||
91 | #define WBUS_QUIRK_MASK (TUSB_PHY_OTG_CTRL_TESTM2 | TUSB_PHY_OTG_CTRL_TESTM1 \ | 89 | #define WBUS_QUIRK_MASK (TUSB_PHY_OTG_CTRL_TESTM2 | TUSB_PHY_OTG_CTRL_TESTM1 \ |
@@ -349,7 +347,7 @@ static void tusb_allow_idle(struct musb *musb, u32 wakeup_enables) | |||
349 | u32 reg; | 347 | u32 reg; |
350 | 348 | ||
351 | if ((wakeup_enables & TUSB_PRCM_WBUS) | 349 | if ((wakeup_enables & TUSB_PRCM_WBUS) |
352 | && (tusb_get_revision(musb) == TUSB_REV_30)) | 350 | && (musb->tusb_revision == TUSB_REV_30)) |
353 | tusb_wbus_quirk(musb, 1); | 351 | tusb_wbus_quirk(musb, 1); |
354 | 352 | ||
355 | tusb_set_clock_source(musb, 0); | 353 | tusb_set_clock_source(musb, 0); |
@@ -797,7 +795,7 @@ static irqreturn_t tusb_musb_interrupt(int irq, void *__hci) | |||
797 | u32 reg; | 795 | u32 reg; |
798 | u32 i; | 796 | u32 i; |
799 | 797 | ||
800 | if (tusb_get_revision(musb) == TUSB_REV_30) | 798 | if (musb->tusb_revision == TUSB_REV_30) |
801 | tusb_wbus_quirk(musb, 0); | 799 | tusb_wbus_quirk(musb, 0); |
802 | 800 | ||
803 | /* there are issues re-locking the PLL on wakeup ... */ | 801 | /* there are issues re-locking the PLL on wakeup ... */ |
@@ -1011,10 +1009,11 @@ static int tusb_musb_start(struct musb *musb) | |||
1011 | goto err; | 1009 | goto err; |
1012 | } | 1010 | } |
1013 | 1011 | ||
1014 | ret = tusb_print_revision(musb); | 1012 | musb->tusb_revision = tusb_get_revision(musb); |
1015 | if (ret < 2) { | 1013 | tusb_print_revision(musb); |
1014 | if (musb->tusb_revision < 2) { | ||
1016 | printk(KERN_ERR "tusb: Unsupported TUSB6010 revision %i\n", | 1015 | printk(KERN_ERR "tusb: Unsupported TUSB6010 revision %i\n", |
1017 | ret); | 1016 | musb->tusb_revision); |
1018 | goto err; | 1017 | goto err; |
1019 | } | 1018 | } |
1020 | 1019 | ||
@@ -1065,7 +1064,6 @@ static int tusb_musb_init(struct musb *musb) | |||
1065 | void __iomem *sync = NULL; | 1064 | void __iomem *sync = NULL; |
1066 | int ret; | 1065 | int ret; |
1067 | 1066 | ||
1068 | usb_nop_xceiv_register(); | ||
1069 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 1067 | musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); |
1070 | if (IS_ERR_OR_NULL(musb->xceiv)) | 1068 | if (IS_ERR_OR_NULL(musb->xceiv)) |
1071 | return -EPROBE_DEFER; | 1069 | return -EPROBE_DEFER; |
@@ -1117,7 +1115,6 @@ done: | |||
1117 | iounmap(sync); | 1115 | iounmap(sync); |
1118 | 1116 | ||
1119 | usb_put_phy(musb->xceiv); | 1117 | usb_put_phy(musb->xceiv); |
1120 | usb_nop_xceiv_unregister(); | ||
1121 | } | 1118 | } |
1122 | return ret; | 1119 | return ret; |
1123 | } | 1120 | } |
@@ -1133,7 +1130,6 @@ static int tusb_musb_exit(struct musb *musb) | |||
1133 | iounmap(musb->sync_va); | 1130 | iounmap(musb->sync_va); |
1134 | 1131 | ||
1135 | usb_put_phy(musb->xceiv); | 1132 | usb_put_phy(musb->xceiv); |
1136 | usb_nop_xceiv_unregister(); | ||
1137 | return 0; | 1133 | return 0; |
1138 | } | 1134 | } |
1139 | 1135 | ||
@@ -1176,6 +1172,7 @@ static int tusb_probe(struct platform_device *pdev) | |||
1176 | 1172 | ||
1177 | pdata->platform_ops = &tusb_ops; | 1173 | pdata->platform_ops = &tusb_ops; |
1178 | 1174 | ||
1175 | usb_phy_generic_register(); | ||
1179 | platform_set_drvdata(pdev, glue); | 1176 | platform_set_drvdata(pdev, glue); |
1180 | 1177 | ||
1181 | memset(musb_resources, 0x00, sizeof(*musb_resources) * | 1178 | memset(musb_resources, 0x00, sizeof(*musb_resources) * |
@@ -1224,6 +1221,7 @@ static int tusb_remove(struct platform_device *pdev) | |||
1224 | struct tusb6010_glue *glue = platform_get_drvdata(pdev); | 1221 | struct tusb6010_glue *glue = platform_get_drvdata(pdev); |
1225 | 1222 | ||
1226 | platform_device_unregister(glue->musb); | 1223 | platform_device_unregister(glue->musb); |
1224 | usb_phy_generic_unregister(glue->phy); | ||
1227 | kfree(glue); | 1225 | kfree(glue); |
1228 | 1226 | ||
1229 | return 0; | 1227 | return 0; |
diff --git a/drivers/usb/musb/tusb6010.h b/drivers/usb/musb/tusb6010.h index 35c933a5d991..aec86c86ce32 100644 --- a/drivers/usb/musb/tusb6010.h +++ b/drivers/usb/musb/tusb6010.h | |||
@@ -12,14 +12,6 @@ | |||
12 | #ifndef __TUSB6010_H__ | 12 | #ifndef __TUSB6010_H__ |
13 | #define __TUSB6010_H__ | 13 | #define __TUSB6010_H__ |
14 | 14 | ||
15 | extern u8 tusb_get_revision(struct musb *musb); | ||
16 | |||
17 | #ifdef CONFIG_USB_TUSB6010 | ||
18 | #define musb_in_tusb() 1 | ||
19 | #else | ||
20 | #define musb_in_tusb() 0 | ||
21 | #endif | ||
22 | |||
23 | #ifdef CONFIG_USB_TUSB_OMAP_DMA | 15 | #ifdef CONFIG_USB_TUSB_OMAP_DMA |
24 | #define tusb_dma_omap() 1 | 16 | #define tusb_dma_omap() 1 |
25 | #else | 17 | #else |
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c index e33b6b2c44c2..3ce152c0408e 100644 --- a/drivers/usb/musb/tusb6010_omap.c +++ b/drivers/usb/musb/tusb6010_omap.c | |||
@@ -677,7 +677,7 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba | |||
677 | tusb_dma->controller.channel_program = tusb_omap_dma_program; | 677 | tusb_dma->controller.channel_program = tusb_omap_dma_program; |
678 | tusb_dma->controller.channel_abort = tusb_omap_dma_abort; | 678 | tusb_dma->controller.channel_abort = tusb_omap_dma_abort; |
679 | 679 | ||
680 | if (tusb_get_revision(musb) >= TUSB_REV_30) | 680 | if (musb->tusb_revision >= TUSB_REV_30) |
681 | tusb_dma->multichannel = 1; | 681 | tusb_dma->multichannel = 1; |
682 | 682 | ||
683 | for (i = 0; i < MAX_DMAREQ; i++) { | 683 | for (i = 0; i < MAX_DMAREQ; i++) { |
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 416e0c8cf6ff..e253fa05be68 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig | |||
@@ -6,15 +6,6 @@ menu "USB Physical Layer drivers" | |||
6 | config USB_PHY | 6 | config USB_PHY |
7 | def_bool n | 7 | def_bool n |
8 | 8 | ||
9 | config USB_OTG_FSM | ||
10 | tristate "USB 2.0 OTG FSM implementation" | ||
11 | depends on USB | ||
12 | select USB_OTG | ||
13 | select USB_PHY | ||
14 | help | ||
15 | Implements OTG Final State Machine as specified in On-The-Go | ||
16 | and Embedded Host Supplement to the USB Revision 2.0 Specification. | ||
17 | |||
18 | # | 9 | # |
19 | # USB Transceiver Drivers | 10 | # USB Transceiver Drivers |
20 | # | 11 | # |
@@ -59,14 +50,6 @@ config KEYSTONE_USB_PHY | |||
59 | interface to interact with USB 2.0 and USB 3.0 PHY that is part | 50 | interface to interact with USB 2.0 and USB 3.0 PHY that is part |
60 | of the Keystone SOC. | 51 | of the Keystone SOC. |
61 | 52 | ||
62 | config MV_U3D_PHY | ||
63 | bool "Marvell USB 3.0 PHY controller Driver" | ||
64 | depends on CPU_MMP3 | ||
65 | select USB_PHY | ||
66 | help | ||
67 | Enable this to support Marvell USB 3.0 phy controller for Marvell | ||
68 | SoC. | ||
69 | |||
70 | config NOP_USB_XCEIV | 53 | config NOP_USB_XCEIV |
71 | tristate "NOP USB Transceiver Driver" | 54 | tristate "NOP USB Transceiver Driver" |
72 | select USB_PHY | 55 | select USB_PHY |
@@ -171,11 +154,12 @@ config USB_ISP1301 | |||
171 | module will be called phy-isp1301. | 154 | module will be called phy-isp1301. |
172 | 155 | ||
173 | config USB_MSM_OTG | 156 | config USB_MSM_OTG |
174 | tristate "OTG support for Qualcomm on-chip USB controller" | 157 | tristate "Qualcomm on-chip USB OTG controller support" |
175 | depends on (USB || USB_GADGET) && ARCH_MSM | 158 | depends on (USB || USB_GADGET) && (ARCH_MSM || ARCH_QCOM || COMPILE_TEST) |
159 | depends on RESET_CONTROLLER | ||
176 | select USB_PHY | 160 | select USB_PHY |
177 | help | 161 | help |
178 | Enable this to support the USB OTG transceiver on MSM chips. It | 162 | Enable this to support the USB OTG transceiver on Qualcomm chips. It |
179 | handles PHY initialization, clock management, and workarounds | 163 | handles PHY initialization, clock management, and workarounds |
180 | required after resetting the hardware and power management. | 164 | required after resetting the hardware and power management. |
181 | This driver is required even for peripheral only or host only | 165 | This driver is required even for peripheral only or host only |
@@ -208,6 +192,7 @@ config USB_MXS_PHY | |||
208 | config USB_RCAR_PHY | 192 | config USB_RCAR_PHY |
209 | tristate "Renesas R-Car USB PHY support" | 193 | tristate "Renesas R-Car USB PHY support" |
210 | depends on USB || USB_GADGET | 194 | depends on USB || USB_GADGET |
195 | depends on ARCH_R8A7778 || ARCH_R8A7779 || COMPILE_TEST | ||
211 | select USB_PHY | 196 | select USB_PHY |
212 | help | 197 | help |
213 | Say Y here to add support for the Renesas R-Car USB common PHY driver. | 198 | Say Y here to add support for the Renesas R-Car USB common PHY driver. |
@@ -232,7 +217,7 @@ config USB_RCAR_GEN2_PHY | |||
232 | 217 | ||
233 | config USB_ULPI | 218 | config USB_ULPI |
234 | bool "Generic ULPI Transceiver Driver" | 219 | bool "Generic ULPI Transceiver Driver" |
235 | depends on ARM | 220 | depends on ARM || ARM64 |
236 | help | 221 | help |
237 | Enable this to support ULPI connected USB OTG transceivers which | 222 | Enable this to support ULPI connected USB OTG transceivers which |
238 | are likely found on embedded boards. | 223 | are likely found on embedded boards. |
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile index f8fa719a31b9..24a91332d4ad 100644 --- a/drivers/usb/phy/Makefile +++ b/drivers/usb/phy/Makefile | |||
@@ -3,14 +3,12 @@ | |||
3 | # | 3 | # |
4 | obj-$(CONFIG_USB_PHY) += phy.o | 4 | obj-$(CONFIG_USB_PHY) += phy.o |
5 | obj-$(CONFIG_OF) += of.o | 5 | obj-$(CONFIG_OF) += of.o |
6 | obj-$(CONFIG_USB_OTG_FSM) += phy-fsm-usb.o | ||
7 | 6 | ||
8 | # transceiver drivers, keep the list sorted | 7 | # transceiver drivers, keep the list sorted |
9 | 8 | ||
10 | obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o | 9 | obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o |
11 | obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb.o | 10 | obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb.o |
12 | obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o | 11 | obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o |
13 | obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o | ||
14 | obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o | 12 | obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o |
15 | obj-$(CONFIG_TAHVO_USB) += phy-tahvo.o | 13 | obj-$(CONFIG_TAHVO_USB) += phy-tahvo.o |
16 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o | 14 | obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o |
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c index 12fc3468a01e..585e50cb1980 100644 --- a/drivers/usb/phy/phy-am335x.c +++ b/drivers/usb/phy/phy-am335x.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <linux/platform_device.h> | 2 | #include <linux/platform_device.h> |
3 | #include <linux/dma-mapping.h> | 3 | #include <linux/dma-mapping.h> |
4 | #include <linux/usb/otg.h> | 4 | #include <linux/usb/otg.h> |
5 | #include <linux/usb/usb_phy_gen_xceiv.h> | 5 | #include <linux/usb/usb_phy_generic.h> |
6 | #include <linux/slab.h> | 6 | #include <linux/slab.h> |
7 | #include <linux/clk.h> | 7 | #include <linux/clk.h> |
8 | #include <linux/regulator/consumer.h> | 8 | #include <linux/regulator/consumer.h> |
@@ -13,7 +13,7 @@ | |||
13 | #include "phy-generic.h" | 13 | #include "phy-generic.h" |
14 | 14 | ||
15 | struct am335x_phy { | 15 | struct am335x_phy { |
16 | struct usb_phy_gen_xceiv usb_phy_gen; | 16 | struct usb_phy_generic usb_phy_gen; |
17 | struct phy_control *phy_ctrl; | 17 | struct phy_control *phy_ctrl; |
18 | int id; | 18 | int id; |
19 | }; | 19 | }; |
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c index bb394980532b..7594e5069ae5 100644 --- a/drivers/usb/phy/phy-generic.c +++ b/drivers/usb/phy/phy-generic.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/dma-mapping.h> | 31 | #include <linux/dma-mapping.h> |
32 | #include <linux/usb/otg.h> | 32 | #include <linux/usb/otg.h> |
33 | #include <linux/usb/usb_phy_gen_xceiv.h> | 33 | #include <linux/usb/usb_phy_generic.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/clk.h> | 35 | #include <linux/clk.h> |
36 | #include <linux/regulator/consumer.h> | 36 | #include <linux/regulator/consumer.h> |
@@ -41,34 +41,25 @@ | |||
41 | 41 | ||
42 | #include "phy-generic.h" | 42 | #include "phy-generic.h" |
43 | 43 | ||
44 | static struct platform_device *pd; | 44 | struct platform_device *usb_phy_generic_register(void) |
45 | |||
46 | void usb_nop_xceiv_register(void) | ||
47 | { | 45 | { |
48 | if (pd) | 46 | return platform_device_register_simple("usb_phy_generic", |
49 | return; | 47 | PLATFORM_DEVID_AUTO, NULL, 0); |
50 | pd = platform_device_register_simple("usb_phy_gen_xceiv", -1, NULL, 0); | ||
51 | if (IS_ERR(pd)) { | ||
52 | pr_err("Unable to register generic usb transceiver\n"); | ||
53 | pd = NULL; | ||
54 | return; | ||
55 | } | ||
56 | } | 48 | } |
57 | EXPORT_SYMBOL(usb_nop_xceiv_register); | 49 | EXPORT_SYMBOL_GPL(usb_phy_generic_register); |
58 | 50 | ||
59 | void usb_nop_xceiv_unregister(void) | 51 | void usb_phy_generic_unregister(struct platform_device *pdev) |
60 | { | 52 | { |
61 | platform_device_unregister(pd); | 53 | platform_device_unregister(pdev); |
62 | pd = NULL; | ||
63 | } | 54 | } |
64 | EXPORT_SYMBOL(usb_nop_xceiv_unregister); | 55 | EXPORT_SYMBOL_GPL(usb_phy_generic_unregister); |
65 | 56 | ||
66 | static int nop_set_suspend(struct usb_phy *x, int suspend) | 57 | static int nop_set_suspend(struct usb_phy *x, int suspend) |
67 | { | 58 | { |
68 | return 0; | 59 | return 0; |
69 | } | 60 | } |
70 | 61 | ||
71 | static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted) | 62 | static void nop_reset_set(struct usb_phy_generic *nop, int asserted) |
72 | { | 63 | { |
73 | int value; | 64 | int value; |
74 | 65 | ||
@@ -87,7 +78,7 @@ static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted) | |||
87 | 78 | ||
88 | int usb_gen_phy_init(struct usb_phy *phy) | 79 | int usb_gen_phy_init(struct usb_phy *phy) |
89 | { | 80 | { |
90 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); | 81 | struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); |
91 | 82 | ||
92 | if (!IS_ERR(nop->vcc)) { | 83 | if (!IS_ERR(nop->vcc)) { |
93 | if (regulator_enable(nop->vcc)) | 84 | if (regulator_enable(nop->vcc)) |
@@ -106,7 +97,7 @@ EXPORT_SYMBOL_GPL(usb_gen_phy_init); | |||
106 | 97 | ||
107 | void usb_gen_phy_shutdown(struct usb_phy *phy) | 98 | void usb_gen_phy_shutdown(struct usb_phy *phy) |
108 | { | 99 | { |
109 | struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); | 100 | struct usb_phy_generic *nop = dev_get_drvdata(phy->dev); |
110 | 101 | ||
111 | /* Assert RESET */ | 102 | /* Assert RESET */ |
112 | nop_reset_set(nop, 1); | 103 | nop_reset_set(nop, 1); |
@@ -150,8 +141,8 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
150 | return 0; | 141 | return 0; |
151 | } | 142 | } |
152 | 143 | ||
153 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | 144 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, |
154 | struct usb_phy_gen_xceiv_platform_data *pdata) | 145 | struct usb_phy_generic_platform_data *pdata) |
155 | { | 146 | { |
156 | enum usb_phy_type type = USB_PHY_TYPE_USB2; | 147 | enum usb_phy_type type = USB_PHY_TYPE_USB2; |
157 | int err; | 148 | int err; |
@@ -245,10 +236,10 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | |||
245 | } | 236 | } |
246 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); | 237 | EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); |
247 | 238 | ||
248 | static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) | 239 | static int usb_phy_generic_probe(struct platform_device *pdev) |
249 | { | 240 | { |
250 | struct device *dev = &pdev->dev; | 241 | struct device *dev = &pdev->dev; |
251 | struct usb_phy_gen_xceiv *nop; | 242 | struct usb_phy_generic *nop; |
252 | int err; | 243 | int err; |
253 | 244 | ||
254 | nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); | 245 | nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); |
@@ -274,9 +265,9 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) | |||
274 | return 0; | 265 | return 0; |
275 | } | 266 | } |
276 | 267 | ||
277 | static int usb_phy_gen_xceiv_remove(struct platform_device *pdev) | 268 | static int usb_phy_generic_remove(struct platform_device *pdev) |
278 | { | 269 | { |
279 | struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); | 270 | struct usb_phy_generic *nop = platform_get_drvdata(pdev); |
280 | 271 | ||
281 | usb_remove_phy(&nop->phy); | 272 | usb_remove_phy(&nop->phy); |
282 | 273 | ||
@@ -290,29 +281,29 @@ static const struct of_device_id nop_xceiv_dt_ids[] = { | |||
290 | 281 | ||
291 | MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids); | 282 | MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids); |
292 | 283 | ||
293 | static struct platform_driver usb_phy_gen_xceiv_driver = { | 284 | static struct platform_driver usb_phy_generic_driver = { |
294 | .probe = usb_phy_gen_xceiv_probe, | 285 | .probe = usb_phy_generic_probe, |
295 | .remove = usb_phy_gen_xceiv_remove, | 286 | .remove = usb_phy_generic_remove, |
296 | .driver = { | 287 | .driver = { |
297 | .name = "usb_phy_gen_xceiv", | 288 | .name = "usb_phy_generic", |
298 | .owner = THIS_MODULE, | 289 | .owner = THIS_MODULE, |
299 | .of_match_table = nop_xceiv_dt_ids, | 290 | .of_match_table = nop_xceiv_dt_ids, |
300 | }, | 291 | }, |
301 | }; | 292 | }; |
302 | 293 | ||
303 | static int __init usb_phy_gen_xceiv_init(void) | 294 | static int __init usb_phy_generic_init(void) |
304 | { | 295 | { |
305 | return platform_driver_register(&usb_phy_gen_xceiv_driver); | 296 | return platform_driver_register(&usb_phy_generic_driver); |
306 | } | 297 | } |
307 | subsys_initcall(usb_phy_gen_xceiv_init); | 298 | subsys_initcall(usb_phy_generic_init); |
308 | 299 | ||
309 | static void __exit usb_phy_gen_xceiv_exit(void) | 300 | static void __exit usb_phy_generic_exit(void) |
310 | { | 301 | { |
311 | platform_driver_unregister(&usb_phy_gen_xceiv_driver); | 302 | platform_driver_unregister(&usb_phy_generic_driver); |
312 | } | 303 | } |
313 | module_exit(usb_phy_gen_xceiv_exit); | 304 | module_exit(usb_phy_generic_exit); |
314 | 305 | ||
315 | MODULE_ALIAS("platform:usb_phy_gen_xceiv"); | 306 | MODULE_ALIAS("platform:usb_phy_generic"); |
316 | MODULE_AUTHOR("Texas Instruments Inc"); | 307 | MODULE_AUTHOR("Texas Instruments Inc"); |
317 | MODULE_DESCRIPTION("NOP USB Transceiver driver"); | 308 | MODULE_DESCRIPTION("NOP USB Transceiver driver"); |
318 | MODULE_LICENSE("GPL"); | 309 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h index 38a81f307b82..d8feacc0b7fb 100644 --- a/drivers/usb/phy/phy-generic.h +++ b/drivers/usb/phy/phy-generic.h | |||
@@ -1,9 +1,9 @@ | |||
1 | #ifndef _PHY_GENERIC_H_ | 1 | #ifndef _PHY_GENERIC_H_ |
2 | #define _PHY_GENERIC_H_ | 2 | #define _PHY_GENERIC_H_ |
3 | 3 | ||
4 | #include <linux/usb/usb_phy_gen_xceiv.h> | 4 | #include <linux/usb/usb_phy_generic.h> |
5 | 5 | ||
6 | struct usb_phy_gen_xceiv { | 6 | struct usb_phy_generic { |
7 | struct usb_phy phy; | 7 | struct usb_phy phy; |
8 | struct device *dev; | 8 | struct device *dev; |
9 | struct clk *clk; | 9 | struct clk *clk; |
@@ -15,7 +15,7 @@ struct usb_phy_gen_xceiv { | |||
15 | int usb_gen_phy_init(struct usb_phy *phy); | 15 | int usb_gen_phy_init(struct usb_phy *phy); |
16 | void usb_gen_phy_shutdown(struct usb_phy *phy); | 16 | void usb_gen_phy_shutdown(struct usb_phy *phy); |
17 | 17 | ||
18 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, | 18 | int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop, |
19 | struct usb_phy_gen_xceiv_platform_data *pdata); | 19 | struct usb_phy_generic_platform_data *pdata); |
20 | 20 | ||
21 | #endif | 21 | #endif |
diff --git a/drivers/usb/phy/phy-isp1301-omap.c b/drivers/usb/phy/phy-isp1301-omap.c index 6e146d723b37..69e49be8866b 100644 --- a/drivers/usb/phy/phy-isp1301-omap.c +++ b/drivers/usb/phy/phy-isp1301-omap.c | |||
@@ -1295,7 +1295,7 @@ isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
1295 | return isp1301_otg_enable(isp); | 1295 | return isp1301_otg_enable(isp); |
1296 | return 0; | 1296 | return 0; |
1297 | 1297 | ||
1298 | #elif !defined(CONFIG_USB_GADGET_OMAP) | 1298 | #elif !IS_ENABLED(CONFIG_USB_OMAP) |
1299 | // FIXME update its refcount | 1299 | // FIXME update its refcount |
1300 | otg->host = host; | 1300 | otg->host = host; |
1301 | 1301 | ||
diff --git a/drivers/usb/phy/phy-keystone.c b/drivers/usb/phy/phy-keystone.c index d762003896c0..f4d722de912b 100644 --- a/drivers/usb/phy/phy-keystone.c +++ b/drivers/usb/phy/phy-keystone.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/usb/usb_phy_gen_xceiv.h> | 21 | #include <linux/usb/usb_phy_generic.h> |
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | #include <linux/of.h> | 23 | #include <linux/of.h> |
24 | 24 | ||
@@ -35,7 +35,7 @@ | |||
35 | #define PHY_REF_SSP_EN BIT(29) | 35 | #define PHY_REF_SSP_EN BIT(29) |
36 | 36 | ||
37 | struct keystone_usbphy { | 37 | struct keystone_usbphy { |
38 | struct usb_phy_gen_xceiv usb_phy_gen; | 38 | struct usb_phy_generic usb_phy_gen; |
39 | void __iomem *phy_ctrl; | 39 | void __iomem *phy_ctrl; |
40 | }; | 40 | }; |
41 | 41 | ||
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index 5b37b81f2ef6..ced34f39bdd4 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c | |||
@@ -30,9 +30,13 @@ | |||
30 | #include <linux/debugfs.h> | 30 | #include <linux/debugfs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/pm_runtime.h> | 32 | #include <linux/pm_runtime.h> |
33 | #include <linux/of.h> | ||
34 | #include <linux/of_device.h> | ||
35 | #include <linux/reset.h> | ||
33 | 36 | ||
34 | #include <linux/usb.h> | 37 | #include <linux/usb.h> |
35 | #include <linux/usb/otg.h> | 38 | #include <linux/usb/otg.h> |
39 | #include <linux/usb/of.h> | ||
36 | #include <linux/usb/ulpi.h> | 40 | #include <linux/usb/ulpi.h> |
37 | #include <linux/usb/gadget.h> | 41 | #include <linux/usb/gadget.h> |
38 | #include <linux/usb/hcd.h> | 42 | #include <linux/usb/hcd.h> |
@@ -44,6 +48,7 @@ | |||
44 | #define DRIVER_NAME "msm_otg" | 48 | #define DRIVER_NAME "msm_otg" |
45 | 49 | ||
46 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) | 50 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
51 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) | ||
47 | 52 | ||
48 | #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ | 53 | #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
49 | #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ | 54 | #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
@@ -57,48 +62,38 @@ | |||
57 | 62 | ||
58 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ | 63 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
59 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ | 64 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
65 | #define USB_PHY_SUSP_DIG_VOL 500000 /* uV */ | ||
60 | 66 | ||
61 | static struct regulator *hsusb_3p3; | 67 | enum vdd_levels { |
62 | static struct regulator *hsusb_1p8; | 68 | VDD_LEVEL_NONE = 0, |
63 | static struct regulator *hsusb_vddcx; | 69 | VDD_LEVEL_MIN, |
70 | VDD_LEVEL_MAX, | ||
71 | }; | ||
64 | 72 | ||
65 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) | 73 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) |
66 | { | 74 | { |
67 | int ret = 0; | 75 | int ret = 0; |
68 | 76 | ||
69 | if (init) { | 77 | if (init) { |
70 | hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX"); | 78 | ret = regulator_set_voltage(motg->vddcx, |
71 | if (IS_ERR(hsusb_vddcx)) { | 79 | motg->vdd_levels[VDD_LEVEL_MIN], |
72 | dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); | 80 | motg->vdd_levels[VDD_LEVEL_MAX]); |
73 | return PTR_ERR(hsusb_vddcx); | ||
74 | } | ||
75 | |||
76 | ret = regulator_set_voltage(hsusb_vddcx, | ||
77 | USB_PHY_VDD_DIG_VOL_MIN, | ||
78 | USB_PHY_VDD_DIG_VOL_MAX); | ||
79 | if (ret) { | 81 | if (ret) { |
80 | dev_err(motg->phy.dev, "unable to set the voltage " | 82 | dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); |
81 | "for hsusb vddcx\n"); | ||
82 | regulator_put(hsusb_vddcx); | ||
83 | return ret; | 83 | return ret; |
84 | } | 84 | } |
85 | 85 | ||
86 | ret = regulator_enable(hsusb_vddcx); | 86 | ret = regulator_enable(motg->vddcx); |
87 | if (ret) { | 87 | if (ret) |
88 | dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); | 88 | dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); |
89 | regulator_put(hsusb_vddcx); | ||
90 | } | ||
91 | } else { | 89 | } else { |
92 | ret = regulator_set_voltage(hsusb_vddcx, 0, | 90 | ret = regulator_set_voltage(motg->vddcx, 0, |
93 | USB_PHY_VDD_DIG_VOL_MAX); | 91 | motg->vdd_levels[VDD_LEVEL_MAX]); |
94 | if (ret) | 92 | if (ret) |
95 | dev_err(motg->phy.dev, "unable to set the voltage " | 93 | dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); |
96 | "for hsusb vddcx\n"); | 94 | ret = regulator_disable(motg->vddcx); |
97 | ret = regulator_disable(hsusb_vddcx); | ||
98 | if (ret) | 95 | if (ret) |
99 | dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); | 96 | dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); |
100 | |||
101 | regulator_put(hsusb_vddcx); | ||
102 | } | 97 | } |
103 | 98 | ||
104 | return ret; | 99 | return ret; |
@@ -109,98 +104,67 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) | |||
109 | int rc = 0; | 104 | int rc = 0; |
110 | 105 | ||
111 | if (init) { | 106 | if (init) { |
112 | hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3"); | 107 | rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN, |
113 | if (IS_ERR(hsusb_3p3)) { | ||
114 | dev_err(motg->phy.dev, "unable to get hsusb 3p3\n"); | ||
115 | return PTR_ERR(hsusb_3p3); | ||
116 | } | ||
117 | |||
118 | rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, | ||
119 | USB_PHY_3P3_VOL_MAX); | 108 | USB_PHY_3P3_VOL_MAX); |
120 | if (rc) { | 109 | if (rc) { |
121 | dev_err(motg->phy.dev, "unable to set voltage level " | 110 | dev_err(motg->phy.dev, "Cannot set v3p3 voltage\n"); |
122 | "for hsusb 3p3\n"); | 111 | goto exit; |
123 | goto put_3p3; | ||
124 | } | 112 | } |
125 | rc = regulator_enable(hsusb_3p3); | 113 | rc = regulator_enable(motg->v3p3); |
126 | if (rc) { | 114 | if (rc) { |
127 | dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); | 115 | dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); |
128 | goto put_3p3; | 116 | goto exit; |
129 | } | 117 | } |
130 | hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8"); | 118 | rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN, |
131 | if (IS_ERR(hsusb_1p8)) { | ||
132 | dev_err(motg->phy.dev, "unable to get hsusb 1p8\n"); | ||
133 | rc = PTR_ERR(hsusb_1p8); | ||
134 | goto disable_3p3; | ||
135 | } | ||
136 | rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, | ||
137 | USB_PHY_1P8_VOL_MAX); | 119 | USB_PHY_1P8_VOL_MAX); |
138 | if (rc) { | 120 | if (rc) { |
139 | dev_err(motg->phy.dev, "unable to set voltage level " | 121 | dev_err(motg->phy.dev, "Cannot set v1p8 voltage\n"); |
140 | "for hsusb 1p8\n"); | 122 | goto disable_3p3; |
141 | goto put_1p8; | ||
142 | } | 123 | } |
143 | rc = regulator_enable(hsusb_1p8); | 124 | rc = regulator_enable(motg->v1p8); |
144 | if (rc) { | 125 | if (rc) { |
145 | dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); | 126 | dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); |
146 | goto put_1p8; | 127 | goto disable_3p3; |
147 | } | 128 | } |
148 | 129 | ||
149 | return 0; | 130 | return 0; |
150 | } | 131 | } |
151 | 132 | ||
152 | regulator_disable(hsusb_1p8); | 133 | regulator_disable(motg->v1p8); |
153 | put_1p8: | ||
154 | regulator_put(hsusb_1p8); | ||
155 | disable_3p3: | 134 | disable_3p3: |
156 | regulator_disable(hsusb_3p3); | 135 | regulator_disable(motg->v3p3); |
157 | put_3p3: | 136 | exit: |
158 | regulator_put(hsusb_3p3); | ||
159 | return rc; | 137 | return rc; |
160 | } | 138 | } |
161 | 139 | ||
162 | static int msm_hsusb_ldo_set_mode(int on) | 140 | static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on) |
163 | { | 141 | { |
164 | int ret = 0; | 142 | int ret = 0; |
165 | 143 | ||
166 | if (!hsusb_1p8 || IS_ERR(hsusb_1p8)) { | ||
167 | pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); | ||
168 | return -ENODEV; | ||
169 | } | ||
170 | |||
171 | if (!hsusb_3p3 || IS_ERR(hsusb_3p3)) { | ||
172 | pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); | ||
173 | return -ENODEV; | ||
174 | } | ||
175 | |||
176 | if (on) { | 144 | if (on) { |
177 | ret = regulator_set_optimum_mode(hsusb_1p8, | 145 | ret = regulator_set_optimum_mode(motg->v1p8, |
178 | USB_PHY_1P8_HPM_LOAD); | 146 | USB_PHY_1P8_HPM_LOAD); |
179 | if (ret < 0) { | 147 | if (ret < 0) { |
180 | pr_err("%s: Unable to set HPM of the regulator " | 148 | pr_err("Could not set HPM for v1p8\n"); |
181 | "HSUSB_1p8\n", __func__); | ||
182 | return ret; | 149 | return ret; |
183 | } | 150 | } |
184 | ret = regulator_set_optimum_mode(hsusb_3p3, | 151 | ret = regulator_set_optimum_mode(motg->v3p3, |
185 | USB_PHY_3P3_HPM_LOAD); | 152 | USB_PHY_3P3_HPM_LOAD); |
186 | if (ret < 0) { | 153 | if (ret < 0) { |
187 | pr_err("%s: Unable to set HPM of the regulator " | 154 | pr_err("Could not set HPM for v3p3\n"); |
188 | "HSUSB_3p3\n", __func__); | 155 | regulator_set_optimum_mode(motg->v1p8, |
189 | regulator_set_optimum_mode(hsusb_1p8, | ||
190 | USB_PHY_1P8_LPM_LOAD); | 156 | USB_PHY_1P8_LPM_LOAD); |
191 | return ret; | 157 | return ret; |
192 | } | 158 | } |
193 | } else { | 159 | } else { |
194 | ret = regulator_set_optimum_mode(hsusb_1p8, | 160 | ret = regulator_set_optimum_mode(motg->v1p8, |
195 | USB_PHY_1P8_LPM_LOAD); | 161 | USB_PHY_1P8_LPM_LOAD); |
196 | if (ret < 0) | 162 | if (ret < 0) |
197 | pr_err("%s: Unable to set LPM of the regulator " | 163 | pr_err("Could not set LPM for v1p8\n"); |
198 | "HSUSB_1p8\n", __func__); | 164 | ret = regulator_set_optimum_mode(motg->v3p3, |
199 | ret = regulator_set_optimum_mode(hsusb_3p3, | ||
200 | USB_PHY_3P3_LPM_LOAD); | 165 | USB_PHY_3P3_LPM_LOAD); |
201 | if (ret < 0) | 166 | if (ret < 0) |
202 | pr_err("%s: Unable to set LPM of the regulator " | 167 | pr_err("Could not set LPM for v3p3\n"); |
203 | "HSUSB_3p3\n", __func__); | ||
204 | } | 168 | } |
205 | 169 | ||
206 | pr_debug("reg (%s)\n", on ? "HPM" : "LPM"); | 170 | pr_debug("reg (%s)\n", on ? "HPM" : "LPM"); |
@@ -265,27 +229,47 @@ static struct usb_phy_io_ops msm_otg_io_ops = { | |||
265 | static void ulpi_init(struct msm_otg *motg) | 229 | static void ulpi_init(struct msm_otg *motg) |
266 | { | 230 | { |
267 | struct msm_otg_platform_data *pdata = motg->pdata; | 231 | struct msm_otg_platform_data *pdata = motg->pdata; |
268 | int *seq = pdata->phy_init_seq; | 232 | int *seq = pdata->phy_init_seq, idx; |
233 | u32 addr = ULPI_EXT_VENDOR_SPECIFIC; | ||
269 | 234 | ||
270 | if (!seq) | 235 | for (idx = 0; idx < pdata->phy_init_sz; idx++) { |
271 | return; | 236 | if (seq[idx] == -1) |
237 | continue; | ||
272 | 238 | ||
273 | while (seq[0] >= 0) { | ||
274 | dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n", | 239 | dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n", |
275 | seq[0], seq[1]); | 240 | seq[idx], addr + idx); |
276 | ulpi_write(&motg->phy, seq[0], seq[1]); | 241 | ulpi_write(&motg->phy, seq[idx], addr + idx); |
277 | seq += 2; | ||
278 | } | 242 | } |
279 | } | 243 | } |
280 | 244 | ||
245 | static int msm_phy_notify_disconnect(struct usb_phy *phy, | ||
246 | enum usb_device_speed speed) | ||
247 | { | ||
248 | int val; | ||
249 | |||
250 | /* | ||
251 | * Put the transceiver in non-driving mode. Otherwise host | ||
252 | * may not detect soft-disconnection. | ||
253 | */ | ||
254 | val = ulpi_read(phy, ULPI_FUNC_CTRL); | ||
255 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; | ||
256 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; | ||
257 | ulpi_write(phy, val, ULPI_FUNC_CTRL); | ||
258 | |||
259 | return 0; | ||
260 | } | ||
261 | |||
281 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) | 262 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) |
282 | { | 263 | { |
283 | int ret = 0; | 264 | int ret; |
284 | 265 | ||
285 | if (!motg->pdata->link_clk_reset) | 266 | if (motg->pdata->link_clk_reset) |
286 | return ret; | 267 | ret = motg->pdata->link_clk_reset(motg->clk, assert); |
268 | else if (assert) | ||
269 | ret = reset_control_assert(motg->link_rst); | ||
270 | else | ||
271 | ret = reset_control_deassert(motg->link_rst); | ||
287 | 272 | ||
288 | ret = motg->pdata->link_clk_reset(motg->clk, assert); | ||
289 | if (ret) | 273 | if (ret) |
290 | dev_err(motg->phy.dev, "usb link clk reset %s failed\n", | 274 | dev_err(motg->phy.dev, "usb link clk reset %s failed\n", |
291 | assert ? "assert" : "deassert"); | 275 | assert ? "assert" : "deassert"); |
@@ -295,111 +279,150 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) | |||
295 | 279 | ||
296 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) | 280 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
297 | { | 281 | { |
298 | int ret = 0; | 282 | int ret; |
299 | 283 | ||
300 | if (!motg->pdata->phy_clk_reset) | 284 | if (motg->pdata->phy_clk_reset) |
301 | return ret; | 285 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); |
286 | else | ||
287 | ret = reset_control_reset(motg->phy_rst); | ||
302 | 288 | ||
303 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); | ||
304 | if (ret) | 289 | if (ret) |
305 | dev_err(motg->phy.dev, "usb phy clk reset failed\n"); | 290 | dev_err(motg->phy.dev, "usb phy clk reset failed\n"); |
306 | 291 | ||
307 | return ret; | 292 | return ret; |
308 | } | 293 | } |
309 | 294 | ||
310 | static int msm_otg_phy_reset(struct msm_otg *motg) | 295 | static int msm_link_reset(struct msm_otg *motg) |
311 | { | 296 | { |
312 | u32 val; | 297 | u32 val; |
313 | int ret; | 298 | int ret; |
314 | int retries; | ||
315 | 299 | ||
316 | ret = msm_otg_link_clk_reset(motg, 1); | 300 | ret = msm_otg_link_clk_reset(motg, 1); |
317 | if (ret) | 301 | if (ret) |
318 | return ret; | 302 | return ret; |
319 | ret = msm_otg_phy_clk_reset(motg); | 303 | |
320 | if (ret) | 304 | /* wait for 1ms delay as suggested in HPG. */ |
321 | return ret; | 305 | usleep_range(1000, 1200); |
306 | |||
322 | ret = msm_otg_link_clk_reset(motg, 0); | 307 | ret = msm_otg_link_clk_reset(motg, 0); |
323 | if (ret) | 308 | if (ret) |
324 | return ret; | 309 | return ret; |
325 | 310 | ||
311 | if (motg->phy_number) | ||
312 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); | ||
313 | |||
314 | /* put transceiver in serial mode as part of reset */ | ||
326 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; | 315 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; |
327 | writel(val | PORTSC_PTS_ULPI, USB_PORTSC); | 316 | writel(val | PORTSC_PTS_SERIAL, USB_PORTSC); |
328 | 317 | ||
329 | for (retries = 3; retries > 0; retries--) { | 318 | return 0; |
330 | ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM, | 319 | } |
331 | ULPI_CLR(ULPI_FUNC_CTRL)); | ||
332 | if (!ret) | ||
333 | break; | ||
334 | ret = msm_otg_phy_clk_reset(motg); | ||
335 | if (ret) | ||
336 | return ret; | ||
337 | } | ||
338 | if (!retries) | ||
339 | return -ETIMEDOUT; | ||
340 | 320 | ||
341 | /* This reset calibrates the phy, if the above write succeeded */ | 321 | static int msm_otg_reset(struct usb_phy *phy) |
342 | ret = msm_otg_phy_clk_reset(motg); | 322 | { |
343 | if (ret) | 323 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
344 | return ret; | 324 | int cnt = 0; |
345 | 325 | ||
346 | for (retries = 3; retries > 0; retries--) { | 326 | writel(USBCMD_RESET, USB_USBCMD); |
347 | ret = ulpi_read(&motg->phy, ULPI_DEBUG); | 327 | while (cnt < LINK_RESET_TIMEOUT_USEC) { |
348 | if (ret != -ETIMEDOUT) | 328 | if (!(readl(USB_USBCMD) & USBCMD_RESET)) |
349 | break; | 329 | break; |
350 | ret = msm_otg_phy_clk_reset(motg); | 330 | udelay(1); |
351 | if (ret) | 331 | cnt++; |
352 | return ret; | ||
353 | } | 332 | } |
354 | if (!retries) | 333 | if (cnt >= LINK_RESET_TIMEOUT_USEC) |
355 | return -ETIMEDOUT; | 334 | return -ETIMEDOUT; |
356 | 335 | ||
357 | dev_info(motg->phy.dev, "phy_reset: success\n"); | 336 | /* select ULPI phy and clear other status/control bits in PORTSC */ |
337 | writel(PORTSC_PTS_ULPI, USB_PORTSC); | ||
338 | |||
339 | writel(0x0, USB_AHBBURST); | ||
340 | writel(0x08, USB_AHBMODE); | ||
341 | |||
342 | if (motg->phy_number) | ||
343 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); | ||
358 | return 0; | 344 | return 0; |
359 | } | 345 | } |
360 | 346 | ||
361 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) | 347 | static void msm_phy_reset(struct msm_otg *motg) |
362 | static int msm_otg_reset(struct usb_phy *phy) | 348 | { |
349 | void __iomem *addr; | ||
350 | |||
351 | if (motg->pdata->phy_type != SNPS_28NM_INTEGRATED_PHY) { | ||
352 | msm_otg_phy_clk_reset(motg); | ||
353 | return; | ||
354 | } | ||
355 | |||
356 | addr = USB_PHY_CTRL; | ||
357 | if (motg->phy_number) | ||
358 | addr = USB_PHY_CTRL2; | ||
359 | |||
360 | /* Assert USB PHY_POR */ | ||
361 | writel(readl(addr) | PHY_POR_ASSERT, addr); | ||
362 | |||
363 | /* | ||
364 | * wait for minimum 10 microseconds as suggested in HPG. | ||
365 | * Use a slightly larger value since the exact value didn't | ||
366 | * work 100% of the time. | ||
367 | */ | ||
368 | udelay(12); | ||
369 | |||
370 | /* Deassert USB PHY_POR */ | ||
371 | writel(readl(addr) & ~PHY_POR_ASSERT, addr); | ||
372 | } | ||
373 | |||
374 | static int msm_usb_reset(struct usb_phy *phy) | ||
363 | { | 375 | { |
364 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); | 376 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
365 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
366 | int cnt = 0; | ||
367 | int ret; | 377 | int ret; |
368 | u32 val = 0; | ||
369 | u32 ulpi_val = 0; | ||
370 | 378 | ||
371 | ret = msm_otg_phy_reset(motg); | 379 | if (!IS_ERR(motg->core_clk)) |
380 | clk_prepare_enable(motg->core_clk); | ||
381 | |||
382 | ret = msm_link_reset(motg); | ||
372 | if (ret) { | 383 | if (ret) { |
373 | dev_err(phy->dev, "phy_reset failed\n"); | 384 | dev_err(phy->dev, "phy_reset failed\n"); |
374 | return ret; | 385 | return ret; |
375 | } | 386 | } |
376 | 387 | ||
377 | ulpi_init(motg); | 388 | ret = msm_otg_reset(&motg->phy); |
378 | 389 | if (ret) { | |
379 | writel(USBCMD_RESET, USB_USBCMD); | 390 | dev_err(phy->dev, "link reset failed\n"); |
380 | while (cnt < LINK_RESET_TIMEOUT_USEC) { | 391 | return ret; |
381 | if (!(readl(USB_USBCMD) & USBCMD_RESET)) | ||
382 | break; | ||
383 | udelay(1); | ||
384 | cnt++; | ||
385 | } | 392 | } |
386 | if (cnt >= LINK_RESET_TIMEOUT_USEC) | ||
387 | return -ETIMEDOUT; | ||
388 | |||
389 | /* select ULPI phy */ | ||
390 | writel(0x80000000, USB_PORTSC); | ||
391 | 393 | ||
392 | msleep(100); | 394 | msleep(100); |
393 | 395 | ||
394 | writel(0x0, USB_AHBBURST); | 396 | /* Reset USB PHY after performing USB Link RESET */ |
395 | writel(0x00, USB_AHBMODE); | 397 | msm_phy_reset(motg); |
398 | |||
399 | if (!IS_ERR(motg->core_clk)) | ||
400 | clk_disable_unprepare(motg->core_clk); | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | static int msm_phy_init(struct usb_phy *phy) | ||
406 | { | ||
407 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); | ||
408 | struct msm_otg_platform_data *pdata = motg->pdata; | ||
409 | u32 val, ulpi_val = 0; | ||
410 | |||
411 | /* Program USB PHY Override registers. */ | ||
412 | ulpi_init(motg); | ||
413 | |||
414 | /* | ||
415 | * It is recommended in HPG to reset USB PHY after programming | ||
416 | * USB PHY Override registers. | ||
417 | */ | ||
418 | msm_phy_reset(motg); | ||
396 | 419 | ||
397 | if (pdata->otg_control == OTG_PHY_CONTROL) { | 420 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
398 | val = readl(USB_OTGSC); | 421 | val = readl(USB_OTGSC); |
399 | if (pdata->mode == USB_OTG) { | 422 | if (pdata->mode == USB_DR_MODE_OTG) { |
400 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; | 423 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; |
401 | val |= OTGSC_IDIE | OTGSC_BSVIE; | 424 | val |= OTGSC_IDIE | OTGSC_BSVIE; |
402 | } else if (pdata->mode == USB_PERIPHERAL) { | 425 | } else if (pdata->mode == USB_DR_MODE_PERIPHERAL) { |
403 | ulpi_val = ULPI_INT_SESS_VALID; | 426 | ulpi_val = ULPI_INT_SESS_VALID; |
404 | val |= OTGSC_BSVIE; | 427 | val |= OTGSC_BSVIE; |
405 | } | 428 | } |
@@ -408,6 +431,9 @@ static int msm_otg_reset(struct usb_phy *phy) | |||
408 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); | 431 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); |
409 | } | 432 | } |
410 | 433 | ||
434 | if (motg->phy_number) | ||
435 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); | ||
436 | |||
411 | return 0; | 437 | return 0; |
412 | } | 438 | } |
413 | 439 | ||
@@ -416,22 +442,20 @@ static int msm_otg_reset(struct usb_phy *phy) | |||
416 | 442 | ||
417 | #ifdef CONFIG_PM | 443 | #ifdef CONFIG_PM |
418 | 444 | ||
419 | #define USB_PHY_SUSP_DIG_VOL 500000 | 445 | static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high) |
420 | static int msm_hsusb_config_vddcx(int high) | ||
421 | { | 446 | { |
422 | int max_vol = USB_PHY_VDD_DIG_VOL_MAX; | 447 | int max_vol = motg->vdd_levels[VDD_LEVEL_MAX]; |
423 | int min_vol; | 448 | int min_vol; |
424 | int ret; | 449 | int ret; |
425 | 450 | ||
426 | if (high) | 451 | if (high) |
427 | min_vol = USB_PHY_VDD_DIG_VOL_MIN; | 452 | min_vol = motg->vdd_levels[VDD_LEVEL_MIN]; |
428 | else | 453 | else |
429 | min_vol = USB_PHY_SUSP_DIG_VOL; | 454 | min_vol = motg->vdd_levels[VDD_LEVEL_NONE]; |
430 | 455 | ||
431 | ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol); | 456 | ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol); |
432 | if (ret) { | 457 | if (ret) { |
433 | pr_err("%s: unable to set the voltage for regulator " | 458 | pr_err("Cannot set vddcx voltage\n"); |
434 | "HSUSB_VDDCX\n", __func__); | ||
435 | return ret; | 459 | return ret; |
436 | } | 460 | } |
437 | 461 | ||
@@ -445,6 +469,7 @@ static int msm_otg_suspend(struct msm_otg *motg) | |||
445 | struct usb_phy *phy = &motg->phy; | 469 | struct usb_phy *phy = &motg->phy; |
446 | struct usb_bus *bus = phy->otg->host; | 470 | struct usb_bus *bus = phy->otg->host; |
447 | struct msm_otg_platform_data *pdata = motg->pdata; | 471 | struct msm_otg_platform_data *pdata = motg->pdata; |
472 | void __iomem *addr; | ||
448 | int cnt = 0; | 473 | int cnt = 0; |
449 | 474 | ||
450 | if (atomic_read(&motg->in_lpm)) | 475 | if (atomic_read(&motg->in_lpm)) |
@@ -504,22 +529,23 @@ static int msm_otg_suspend(struct msm_otg *motg) | |||
504 | */ | 529 | */ |
505 | writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); | 530 | writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); |
506 | 531 | ||
532 | addr = USB_PHY_CTRL; | ||
533 | if (motg->phy_number) | ||
534 | addr = USB_PHY_CTRL2; | ||
535 | |||
507 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && | 536 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
508 | motg->pdata->otg_control == OTG_PMIC_CONTROL) | 537 | motg->pdata->otg_control == OTG_PMIC_CONTROL) |
509 | writel(readl(USB_PHY_CTRL) | PHY_RETEN, USB_PHY_CTRL); | 538 | writel(readl(addr) | PHY_RETEN, addr); |
510 | 539 | ||
511 | clk_disable_unprepare(motg->pclk); | 540 | clk_disable_unprepare(motg->pclk); |
512 | clk_disable_unprepare(motg->clk); | 541 | clk_disable_unprepare(motg->clk); |
513 | if (motg->core_clk) | 542 | if (!IS_ERR(motg->core_clk)) |
514 | clk_disable_unprepare(motg->core_clk); | 543 | clk_disable_unprepare(motg->core_clk); |
515 | 544 | ||
516 | if (!IS_ERR(motg->pclk_src)) | ||
517 | clk_disable_unprepare(motg->pclk_src); | ||
518 | |||
519 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && | 545 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
520 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { | 546 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
521 | msm_hsusb_ldo_set_mode(0); | 547 | msm_hsusb_ldo_set_mode(motg, 0); |
522 | msm_hsusb_config_vddcx(0); | 548 | msm_hsusb_config_vddcx(motg, 0); |
523 | } | 549 | } |
524 | 550 | ||
525 | if (device_may_wakeup(phy->dev)) | 551 | if (device_may_wakeup(phy->dev)) |
@@ -539,25 +565,28 @@ static int msm_otg_resume(struct msm_otg *motg) | |||
539 | { | 565 | { |
540 | struct usb_phy *phy = &motg->phy; | 566 | struct usb_phy *phy = &motg->phy; |
541 | struct usb_bus *bus = phy->otg->host; | 567 | struct usb_bus *bus = phy->otg->host; |
568 | void __iomem *addr; | ||
542 | int cnt = 0; | 569 | int cnt = 0; |
543 | unsigned temp; | 570 | unsigned temp; |
544 | 571 | ||
545 | if (!atomic_read(&motg->in_lpm)) | 572 | if (!atomic_read(&motg->in_lpm)) |
546 | return 0; | 573 | return 0; |
547 | 574 | ||
548 | if (!IS_ERR(motg->pclk_src)) | ||
549 | clk_prepare_enable(motg->pclk_src); | ||
550 | |||
551 | clk_prepare_enable(motg->pclk); | 575 | clk_prepare_enable(motg->pclk); |
552 | clk_prepare_enable(motg->clk); | 576 | clk_prepare_enable(motg->clk); |
553 | if (motg->core_clk) | 577 | if (!IS_ERR(motg->core_clk)) |
554 | clk_prepare_enable(motg->core_clk); | 578 | clk_prepare_enable(motg->core_clk); |
555 | 579 | ||
556 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && | 580 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
557 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { | 581 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
558 | msm_hsusb_ldo_set_mode(1); | 582 | |
559 | msm_hsusb_config_vddcx(1); | 583 | addr = USB_PHY_CTRL; |
560 | writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL); | 584 | if (motg->phy_number) |
585 | addr = USB_PHY_CTRL2; | ||
586 | |||
587 | msm_hsusb_ldo_set_mode(motg, 1); | ||
588 | msm_hsusb_config_vddcx(motg, 1); | ||
589 | writel(readl(addr) & ~PHY_RETEN, addr); | ||
561 | } | 590 | } |
562 | 591 | ||
563 | temp = readl(USB_USBCMD); | 592 | temp = readl(USB_USBCMD); |
@@ -586,8 +615,7 @@ static int msm_otg_resume(struct msm_otg *motg) | |||
586 | * PHY. USB state can not be restored. Re-insertion | 615 | * PHY. USB state can not be restored. Re-insertion |
587 | * of USB cable is the only way to get USB working. | 616 | * of USB cable is the only way to get USB working. |
588 | */ | 617 | */ |
589 | dev_err(phy->dev, "Unable to resume USB." | 618 | dev_err(phy->dev, "Unable to resume USB. Re-plugin the cable\n"); |
590 | "Re-plugin the cable\n"); | ||
591 | msm_otg_reset(phy); | 619 | msm_otg_reset(phy); |
592 | } | 620 | } |
593 | 621 | ||
@@ -687,7 +715,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
687 | * Fail host registration if this board can support | 715 | * Fail host registration if this board can support |
688 | * only peripheral configuration. | 716 | * only peripheral configuration. |
689 | */ | 717 | */ |
690 | if (motg->pdata->mode == USB_PERIPHERAL) { | 718 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) { |
691 | dev_info(otg->phy->dev, "Host mode is not supported\n"); | 719 | dev_info(otg->phy->dev, "Host mode is not supported\n"); |
692 | return -ENODEV; | 720 | return -ENODEV; |
693 | } | 721 | } |
@@ -716,7 +744,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) | |||
716 | * Kick the state machine work, if peripheral is not supported | 744 | * Kick the state machine work, if peripheral is not supported |
717 | * or peripheral is already registered with us. | 745 | * or peripheral is already registered with us. |
718 | */ | 746 | */ |
719 | if (motg->pdata->mode == USB_HOST || otg->gadget) { | 747 | if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) { |
720 | pm_runtime_get_sync(otg->phy->dev); | 748 | pm_runtime_get_sync(otg->phy->dev); |
721 | schedule_work(&motg->sm_work); | 749 | schedule_work(&motg->sm_work); |
722 | } | 750 | } |
@@ -760,7 +788,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg, | |||
760 | * Fail peripheral registration if this board can support | 788 | * Fail peripheral registration if this board can support |
761 | * only host configuration. | 789 | * only host configuration. |
762 | */ | 790 | */ |
763 | if (motg->pdata->mode == USB_HOST) { | 791 | if (motg->pdata->mode == USB_DR_MODE_HOST) { |
764 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); | 792 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); |
765 | return -ENODEV; | 793 | return -ENODEV; |
766 | } | 794 | } |
@@ -785,7 +813,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg, | |||
785 | * Kick the state machine work, if host is not supported | 813 | * Kick the state machine work, if host is not supported |
786 | * or host is already registered with us. | 814 | * or host is already registered with us. |
787 | */ | 815 | */ |
788 | if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { | 816 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) { |
789 | pm_runtime_get_sync(otg->phy->dev); | 817 | pm_runtime_get_sync(otg->phy->dev); |
790 | schedule_work(&motg->sm_work); | 818 | schedule_work(&motg->sm_work); |
791 | } | 819 | } |
@@ -1106,7 +1134,7 @@ static void msm_otg_init_sm(struct msm_otg *motg) | |||
1106 | u32 otgsc = readl(USB_OTGSC); | 1134 | u32 otgsc = readl(USB_OTGSC); |
1107 | 1135 | ||
1108 | switch (pdata->mode) { | 1136 | switch (pdata->mode) { |
1109 | case USB_OTG: | 1137 | case USB_DR_MODE_OTG: |
1110 | if (pdata->otg_control == OTG_PHY_CONTROL) { | 1138 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
1111 | if (otgsc & OTGSC_ID) | 1139 | if (otgsc & OTGSC_ID) |
1112 | set_bit(ID, &motg->inputs); | 1140 | set_bit(ID, &motg->inputs); |
@@ -1118,21 +1146,14 @@ static void msm_otg_init_sm(struct msm_otg *motg) | |||
1118 | else | 1146 | else |
1119 | clear_bit(B_SESS_VLD, &motg->inputs); | 1147 | clear_bit(B_SESS_VLD, &motg->inputs); |
1120 | } else if (pdata->otg_control == OTG_USER_CONTROL) { | 1148 | } else if (pdata->otg_control == OTG_USER_CONTROL) { |
1121 | if (pdata->default_mode == USB_HOST) { | ||
1122 | clear_bit(ID, &motg->inputs); | ||
1123 | } else if (pdata->default_mode == USB_PERIPHERAL) { | ||
1124 | set_bit(ID, &motg->inputs); | ||
1125 | set_bit(B_SESS_VLD, &motg->inputs); | ||
1126 | } else { | ||
1127 | set_bit(ID, &motg->inputs); | 1149 | set_bit(ID, &motg->inputs); |
1128 | clear_bit(B_SESS_VLD, &motg->inputs); | 1150 | clear_bit(B_SESS_VLD, &motg->inputs); |
1129 | } | ||
1130 | } | 1151 | } |
1131 | break; | 1152 | break; |
1132 | case USB_HOST: | 1153 | case USB_DR_MODE_HOST: |
1133 | clear_bit(ID, &motg->inputs); | 1154 | clear_bit(ID, &motg->inputs); |
1134 | break; | 1155 | break; |
1135 | case USB_PERIPHERAL: | 1156 | case USB_DR_MODE_PERIPHERAL: |
1136 | set_bit(ID, &motg->inputs); | 1157 | set_bit(ID, &motg->inputs); |
1137 | if (otgsc & OTGSC_BSV) | 1158 | if (otgsc & OTGSC_BSV) |
1138 | set_bit(B_SESS_VLD, &motg->inputs); | 1159 | set_bit(B_SESS_VLD, &motg->inputs); |
@@ -1282,13 +1303,13 @@ static int msm_otg_mode_show(struct seq_file *s, void *unused) | |||
1282 | 1303 | ||
1283 | switch (otg->phy->state) { | 1304 | switch (otg->phy->state) { |
1284 | case OTG_STATE_A_HOST: | 1305 | case OTG_STATE_A_HOST: |
1285 | seq_printf(s, "host\n"); | 1306 | seq_puts(s, "host\n"); |
1286 | break; | 1307 | break; |
1287 | case OTG_STATE_B_PERIPHERAL: | 1308 | case OTG_STATE_B_PERIPHERAL: |
1288 | seq_printf(s, "peripheral\n"); | 1309 | seq_puts(s, "peripheral\n"); |
1289 | break; | 1310 | break; |
1290 | default: | 1311 | default: |
1291 | seq_printf(s, "none\n"); | 1312 | seq_puts(s, "none\n"); |
1292 | break; | 1313 | break; |
1293 | } | 1314 | } |
1294 | 1315 | ||
@@ -1308,7 +1329,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1308 | char buf[16]; | 1329 | char buf[16]; |
1309 | struct usb_otg *otg = motg->phy.otg; | 1330 | struct usb_otg *otg = motg->phy.otg; |
1310 | int status = count; | 1331 | int status = count; |
1311 | enum usb_mode_type req_mode; | 1332 | enum usb_dr_mode req_mode; |
1312 | 1333 | ||
1313 | memset(buf, 0x00, sizeof(buf)); | 1334 | memset(buf, 0x00, sizeof(buf)); |
1314 | 1335 | ||
@@ -1318,18 +1339,18 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1318 | } | 1339 | } |
1319 | 1340 | ||
1320 | if (!strncmp(buf, "host", 4)) { | 1341 | if (!strncmp(buf, "host", 4)) { |
1321 | req_mode = USB_HOST; | 1342 | req_mode = USB_DR_MODE_HOST; |
1322 | } else if (!strncmp(buf, "peripheral", 10)) { | 1343 | } else if (!strncmp(buf, "peripheral", 10)) { |
1323 | req_mode = USB_PERIPHERAL; | 1344 | req_mode = USB_DR_MODE_PERIPHERAL; |
1324 | } else if (!strncmp(buf, "none", 4)) { | 1345 | } else if (!strncmp(buf, "none", 4)) { |
1325 | req_mode = USB_NONE; | 1346 | req_mode = USB_DR_MODE_UNKNOWN; |
1326 | } else { | 1347 | } else { |
1327 | status = -EINVAL; | 1348 | status = -EINVAL; |
1328 | goto out; | 1349 | goto out; |
1329 | } | 1350 | } |
1330 | 1351 | ||
1331 | switch (req_mode) { | 1352 | switch (req_mode) { |
1332 | case USB_NONE: | 1353 | case USB_DR_MODE_UNKNOWN: |
1333 | switch (otg->phy->state) { | 1354 | switch (otg->phy->state) { |
1334 | case OTG_STATE_A_HOST: | 1355 | case OTG_STATE_A_HOST: |
1335 | case OTG_STATE_B_PERIPHERAL: | 1356 | case OTG_STATE_B_PERIPHERAL: |
@@ -1340,7 +1361,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1340 | goto out; | 1361 | goto out; |
1341 | } | 1362 | } |
1342 | break; | 1363 | break; |
1343 | case USB_PERIPHERAL: | 1364 | case USB_DR_MODE_PERIPHERAL: |
1344 | switch (otg->phy->state) { | 1365 | switch (otg->phy->state) { |
1345 | case OTG_STATE_B_IDLE: | 1366 | case OTG_STATE_B_IDLE: |
1346 | case OTG_STATE_A_HOST: | 1367 | case OTG_STATE_A_HOST: |
@@ -1351,7 +1372,7 @@ static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | |||
1351 | goto out; | 1372 | goto out; |
1352 | } | 1373 | } |
1353 | break; | 1374 | break; |
1354 | case USB_HOST: | 1375 | case USB_DR_MODE_HOST: |
1355 | switch (otg->phy->state) { | 1376 | switch (otg->phy->state) { |
1356 | case OTG_STATE_B_IDLE: | 1377 | case OTG_STATE_B_IDLE: |
1357 | case OTG_STATE_B_PERIPHERAL: | 1378 | case OTG_STATE_B_PERIPHERAL: |
@@ -1406,74 +1427,154 @@ static void msm_otg_debugfs_cleanup(void) | |||
1406 | debugfs_remove(msm_otg_dbg_root); | 1427 | debugfs_remove(msm_otg_dbg_root); |
1407 | } | 1428 | } |
1408 | 1429 | ||
1409 | static int __init msm_otg_probe(struct platform_device *pdev) | 1430 | static struct of_device_id msm_otg_dt_match[] = { |
1431 | { | ||
1432 | .compatible = "qcom,usb-otg-ci", | ||
1433 | .data = (void *) CI_45NM_INTEGRATED_PHY | ||
1434 | }, | ||
1435 | { | ||
1436 | .compatible = "qcom,usb-otg-snps", | ||
1437 | .data = (void *) SNPS_28NM_INTEGRATED_PHY | ||
1438 | }, | ||
1439 | { } | ||
1440 | }; | ||
1441 | MODULE_DEVICE_TABLE(of, msm_otg_dt_match); | ||
1442 | |||
1443 | static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) | ||
1444 | { | ||
1445 | struct msm_otg_platform_data *pdata; | ||
1446 | const struct of_device_id *id; | ||
1447 | struct device_node *node = pdev->dev.of_node; | ||
1448 | struct property *prop; | ||
1449 | int len, ret, words; | ||
1450 | u32 val, tmp[3]; | ||
1451 | |||
1452 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
1453 | if (!pdata) | ||
1454 | return -ENOMEM; | ||
1455 | |||
1456 | motg->pdata = pdata; | ||
1457 | |||
1458 | id = of_match_device(msm_otg_dt_match, &pdev->dev); | ||
1459 | pdata->phy_type = (enum msm_usb_phy_type) id->data; | ||
1460 | |||
1461 | motg->link_rst = devm_reset_control_get(&pdev->dev, "link"); | ||
1462 | if (IS_ERR(motg->link_rst)) | ||
1463 | return PTR_ERR(motg->link_rst); | ||
1464 | |||
1465 | motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy"); | ||
1466 | if (IS_ERR(motg->phy_rst)) | ||
1467 | return PTR_ERR(motg->phy_rst); | ||
1468 | |||
1469 | pdata->mode = of_usb_get_dr_mode(node); | ||
1470 | if (pdata->mode == USB_DR_MODE_UNKNOWN) | ||
1471 | pdata->mode = USB_DR_MODE_OTG; | ||
1472 | |||
1473 | pdata->otg_control = OTG_PHY_CONTROL; | ||
1474 | if (!of_property_read_u32(node, "qcom,otg-control", &val)) | ||
1475 | if (val == OTG_PMIC_CONTROL) | ||
1476 | pdata->otg_control = val; | ||
1477 | |||
1478 | if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2) | ||
1479 | motg->phy_number = val; | ||
1480 | |||
1481 | motg->vdd_levels[VDD_LEVEL_NONE] = USB_PHY_SUSP_DIG_VOL; | ||
1482 | motg->vdd_levels[VDD_LEVEL_MIN] = USB_PHY_VDD_DIG_VOL_MIN; | ||
1483 | motg->vdd_levels[VDD_LEVEL_MAX] = USB_PHY_VDD_DIG_VOL_MAX; | ||
1484 | |||
1485 | if (of_get_property(node, "qcom,vdd-levels", &len) && | ||
1486 | len == sizeof(tmp)) { | ||
1487 | of_property_read_u32_array(node, "qcom,vdd-levels", | ||
1488 | tmp, len / sizeof(*tmp)); | ||
1489 | motg->vdd_levels[VDD_LEVEL_NONE] = tmp[VDD_LEVEL_NONE]; | ||
1490 | motg->vdd_levels[VDD_LEVEL_MIN] = tmp[VDD_LEVEL_MIN]; | ||
1491 | motg->vdd_levels[VDD_LEVEL_MAX] = tmp[VDD_LEVEL_MAX]; | ||
1492 | } | ||
1493 | |||
1494 | prop = of_find_property(node, "qcom,phy-init-sequence", &len); | ||
1495 | if (!prop || !len) | ||
1496 | return 0; | ||
1497 | |||
1498 | words = len / sizeof(u32); | ||
1499 | |||
1500 | if (words >= ULPI_EXT_VENDOR_SPECIFIC) { | ||
1501 | dev_warn(&pdev->dev, "Too big PHY init sequence %d\n", words); | ||
1502 | return 0; | ||
1503 | } | ||
1504 | |||
1505 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); | ||
1506 | if (!pdata->phy_init_seq) { | ||
1507 | dev_warn(&pdev->dev, "No space for PHY init sequence\n"); | ||
1508 | return 0; | ||
1509 | } | ||
1510 | |||
1511 | ret = of_property_read_u32_array(node, "qcom,phy-init-sequence", | ||
1512 | pdata->phy_init_seq, words); | ||
1513 | if (!ret) | ||
1514 | pdata->phy_init_sz = words; | ||
1515 | |||
1516 | return 0; | ||
1517 | } | ||
1518 | |||
1519 | static int msm_otg_probe(struct platform_device *pdev) | ||
1410 | { | 1520 | { |
1521 | struct regulator_bulk_data regs[3]; | ||
1411 | int ret = 0; | 1522 | int ret = 0; |
1523 | struct device_node *np = pdev->dev.of_node; | ||
1524 | struct msm_otg_platform_data *pdata; | ||
1412 | struct resource *res; | 1525 | struct resource *res; |
1413 | struct msm_otg *motg; | 1526 | struct msm_otg *motg; |
1414 | struct usb_phy *phy; | 1527 | struct usb_phy *phy; |
1528 | void __iomem *phy_select; | ||
1415 | 1529 | ||
1416 | dev_info(&pdev->dev, "msm_otg probe\n"); | 1530 | motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); |
1417 | if (!dev_get_platdata(&pdev->dev)) { | ||
1418 | dev_err(&pdev->dev, "No platform data given. Bailing out\n"); | ||
1419 | return -ENODEV; | ||
1420 | } | ||
1421 | |||
1422 | motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); | ||
1423 | if (!motg) { | 1531 | if (!motg) { |
1424 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); | 1532 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
1425 | return -ENOMEM; | 1533 | return -ENOMEM; |
1426 | } | 1534 | } |
1427 | 1535 | ||
1428 | motg->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); | 1536 | pdata = dev_get_platdata(&pdev->dev); |
1537 | if (!pdata) { | ||
1538 | if (!np) | ||
1539 | return -ENXIO; | ||
1540 | ret = msm_otg_read_dt(pdev, motg); | ||
1541 | if (ret) | ||
1542 | return ret; | ||
1543 | } | ||
1544 | |||
1545 | motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), | ||
1546 | GFP_KERNEL); | ||
1429 | if (!motg->phy.otg) { | 1547 | if (!motg->phy.otg) { |
1430 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); | 1548 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
1431 | ret = -ENOMEM; | 1549 | return -ENOMEM; |
1432 | goto free_motg; | ||
1433 | } | 1550 | } |
1434 | 1551 | ||
1435 | motg->pdata = dev_get_platdata(&pdev->dev); | ||
1436 | phy = &motg->phy; | 1552 | phy = &motg->phy; |
1437 | phy->dev = &pdev->dev; | 1553 | phy->dev = &pdev->dev; |
1438 | 1554 | ||
1439 | motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk"); | 1555 | motg->phy_reset_clk = devm_clk_get(&pdev->dev, |
1556 | np ? "phy" : "usb_phy_clk"); | ||
1440 | if (IS_ERR(motg->phy_reset_clk)) { | 1557 | if (IS_ERR(motg->phy_reset_clk)) { |
1441 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); | 1558 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); |
1442 | ret = PTR_ERR(motg->phy_reset_clk); | 1559 | return PTR_ERR(motg->phy_reset_clk); |
1443 | goto free_motg; | ||
1444 | } | 1560 | } |
1445 | 1561 | ||
1446 | motg->clk = clk_get(&pdev->dev, "usb_hs_clk"); | 1562 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); |
1447 | if (IS_ERR(motg->clk)) { | 1563 | if (IS_ERR(motg->clk)) { |
1448 | dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); | 1564 | dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); |
1449 | ret = PTR_ERR(motg->clk); | 1565 | return PTR_ERR(motg->clk); |
1450 | goto put_phy_reset_clk; | ||
1451 | } | 1566 | } |
1452 | clk_set_rate(motg->clk, 60000000); | ||
1453 | 1567 | ||
1454 | /* | 1568 | /* |
1455 | * If USB Core is running its protocol engine based on CORE CLK, | 1569 | * If USB Core is running its protocol engine based on CORE CLK, |
1456 | * CORE CLK must be running at >55Mhz for correct HSUSB | 1570 | * CORE CLK must be running at >55Mhz for correct HSUSB |
1457 | * operation and USB core cannot tolerate frequency changes on | 1571 | * operation and USB core cannot tolerate frequency changes on |
1458 | * CORE CLK. For such USB cores, vote for maximum clk frequency | 1572 | * CORE CLK. |
1459 | * on pclk source | ||
1460 | */ | 1573 | */ |
1461 | if (motg->pdata->pclk_src_name) { | 1574 | motg->pclk = devm_clk_get(&pdev->dev, np ? "iface" : "usb_hs_pclk"); |
1462 | motg->pclk_src = clk_get(&pdev->dev, | ||
1463 | motg->pdata->pclk_src_name); | ||
1464 | if (IS_ERR(motg->pclk_src)) | ||
1465 | goto put_clk; | ||
1466 | clk_set_rate(motg->pclk_src, INT_MAX); | ||
1467 | clk_prepare_enable(motg->pclk_src); | ||
1468 | } else | ||
1469 | motg->pclk_src = ERR_PTR(-ENOENT); | ||
1470 | |||
1471 | |||
1472 | motg->pclk = clk_get(&pdev->dev, "usb_hs_pclk"); | ||
1473 | if (IS_ERR(motg->pclk)) { | 1575 | if (IS_ERR(motg->pclk)) { |
1474 | dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); | 1576 | dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); |
1475 | ret = PTR_ERR(motg->pclk); | 1577 | return PTR_ERR(motg->pclk); |
1476 | goto put_pclk_src; | ||
1477 | } | 1578 | } |
1478 | 1579 | ||
1479 | /* | 1580 | /* |
@@ -1481,69 +1582,90 @@ static int __init msm_otg_probe(struct platform_device *pdev) | |||
1481 | * clock is introduced to remove the dependency on AXI | 1582 | * clock is introduced to remove the dependency on AXI |
1482 | * bus frequency. | 1583 | * bus frequency. |
1483 | */ | 1584 | */ |
1484 | motg->core_clk = clk_get(&pdev->dev, "usb_hs_core_clk"); | 1585 | motg->core_clk = devm_clk_get(&pdev->dev, |
1485 | if (IS_ERR(motg->core_clk)) | 1586 | np ? "alt_core" : "usb_hs_core_clk"); |
1486 | motg->core_clk = NULL; | ||
1487 | 1587 | ||
1488 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1588 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1489 | if (!res) { | 1589 | if (!res) |
1490 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); | 1590 | return -EINVAL; |
1491 | ret = -ENODEV; | 1591 | motg->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
1492 | goto put_core_clk; | 1592 | if (!motg->regs) |
1493 | } | 1593 | return -ENOMEM; |
1494 | 1594 | ||
1495 | motg->regs = ioremap(res->start, resource_size(res)); | 1595 | /* |
1496 | if (!motg->regs) { | 1596 | * NOTE: The PHYs can be multiplexed between the chipidea controller |
1497 | dev_err(&pdev->dev, "ioremap failed\n"); | 1597 | * and the dwc3 controller, using a single bit. It is important that |
1498 | ret = -ENOMEM; | 1598 | * the dwc3 driver does not set this bit in an incompatible way. |
1499 | goto put_core_clk; | 1599 | */ |
1600 | if (motg->phy_number) { | ||
1601 | phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4); | ||
1602 | if (IS_ERR(phy_select)) | ||
1603 | return PTR_ERR(phy_select); | ||
1604 | /* Enable second PHY with the OTG port */ | ||
1605 | writel(0x1, phy_select); | ||
1500 | } | 1606 | } |
1607 | |||
1501 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); | 1608 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); |
1502 | 1609 | ||
1503 | motg->irq = platform_get_irq(pdev, 0); | 1610 | motg->irq = platform_get_irq(pdev, 0); |
1504 | if (!motg->irq) { | 1611 | if (motg->irq < 0) { |
1505 | dev_err(&pdev->dev, "platform_get_irq failed\n"); | 1612 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
1506 | ret = -ENODEV; | 1613 | return motg->irq; |
1507 | goto free_regs; | ||
1508 | } | 1614 | } |
1509 | 1615 | ||
1616 | regs[0].supply = "vddcx"; | ||
1617 | regs[1].supply = "v3p3"; | ||
1618 | regs[2].supply = "v1p8"; | ||
1619 | |||
1620 | ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs); | ||
1621 | if (ret) | ||
1622 | return ret; | ||
1623 | |||
1624 | motg->vddcx = regs[0].consumer; | ||
1625 | motg->v3p3 = regs[1].consumer; | ||
1626 | motg->v1p8 = regs[2].consumer; | ||
1627 | |||
1628 | clk_set_rate(motg->clk, 60000000); | ||
1629 | |||
1510 | clk_prepare_enable(motg->clk); | 1630 | clk_prepare_enable(motg->clk); |
1511 | clk_prepare_enable(motg->pclk); | 1631 | clk_prepare_enable(motg->pclk); |
1512 | 1632 | ||
1633 | if (!IS_ERR(motg->core_clk)) | ||
1634 | clk_prepare_enable(motg->core_clk); | ||
1635 | |||
1513 | ret = msm_hsusb_init_vddcx(motg, 1); | 1636 | ret = msm_hsusb_init_vddcx(motg, 1); |
1514 | if (ret) { | 1637 | if (ret) { |
1515 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); | 1638 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
1516 | goto free_regs; | 1639 | goto disable_clks; |
1517 | } | 1640 | } |
1518 | 1641 | ||
1519 | ret = msm_hsusb_ldo_init(motg, 1); | 1642 | ret = msm_hsusb_ldo_init(motg, 1); |
1520 | if (ret) { | 1643 | if (ret) { |
1521 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); | 1644 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
1522 | goto vddcx_exit; | 1645 | goto disable_vddcx; |
1523 | } | 1646 | } |
1524 | ret = msm_hsusb_ldo_set_mode(1); | 1647 | ret = msm_hsusb_ldo_set_mode(motg, 1); |
1525 | if (ret) { | 1648 | if (ret) { |
1526 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); | 1649 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
1527 | goto ldo_exit; | 1650 | goto disable_ldo; |
1528 | } | 1651 | } |
1529 | 1652 | ||
1530 | if (motg->core_clk) | ||
1531 | clk_prepare_enable(motg->core_clk); | ||
1532 | |||
1533 | writel(0, USB_USBINTR); | 1653 | writel(0, USB_USBINTR); |
1534 | writel(0, USB_OTGSC); | 1654 | writel(0, USB_OTGSC); |
1535 | 1655 | ||
1536 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); | 1656 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); |
1537 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); | 1657 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); |
1538 | ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, | 1658 | ret = devm_request_irq(&pdev->dev, motg->irq, msm_otg_irq, IRQF_SHARED, |
1539 | "msm_otg", motg); | 1659 | "msm_otg", motg); |
1540 | if (ret) { | 1660 | if (ret) { |
1541 | dev_err(&pdev->dev, "request irq failed\n"); | 1661 | dev_err(&pdev->dev, "request irq failed\n"); |
1542 | goto disable_clks; | 1662 | goto disable_ldo; |
1543 | } | 1663 | } |
1544 | 1664 | ||
1545 | phy->init = msm_otg_reset; | 1665 | phy->init = msm_phy_init; |
1546 | phy->set_power = msm_otg_set_power; | 1666 | phy->set_power = msm_otg_set_power; |
1667 | phy->notify_disconnect = msm_phy_notify_disconnect; | ||
1668 | phy->type = USB_PHY_TYPE_USB2; | ||
1547 | 1669 | ||
1548 | phy->io_ops = &msm_otg_io_ops; | 1670 | phy->io_ops = &msm_otg_io_ops; |
1549 | 1671 | ||
@@ -1551,54 +1673,38 @@ static int __init msm_otg_probe(struct platform_device *pdev) | |||
1551 | phy->otg->set_host = msm_otg_set_host; | 1673 | phy->otg->set_host = msm_otg_set_host; |
1552 | phy->otg->set_peripheral = msm_otg_set_peripheral; | 1674 | phy->otg->set_peripheral = msm_otg_set_peripheral; |
1553 | 1675 | ||
1554 | ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2); | 1676 | msm_usb_reset(phy); |
1677 | |||
1678 | ret = usb_add_phy_dev(&motg->phy); | ||
1555 | if (ret) { | 1679 | if (ret) { |
1556 | dev_err(&pdev->dev, "usb_add_phy failed\n"); | 1680 | dev_err(&pdev->dev, "usb_add_phy failed\n"); |
1557 | goto free_irq; | 1681 | goto disable_ldo; |
1558 | } | 1682 | } |
1559 | 1683 | ||
1560 | platform_set_drvdata(pdev, motg); | 1684 | platform_set_drvdata(pdev, motg); |
1561 | device_init_wakeup(&pdev->dev, 1); | 1685 | device_init_wakeup(&pdev->dev, 1); |
1562 | 1686 | ||
1563 | if (motg->pdata->mode == USB_OTG && | 1687 | if (motg->pdata->mode == USB_DR_MODE_OTG && |
1564 | motg->pdata->otg_control == OTG_USER_CONTROL) { | 1688 | motg->pdata->otg_control == OTG_USER_CONTROL) { |
1565 | ret = msm_otg_debugfs_init(motg); | 1689 | ret = msm_otg_debugfs_init(motg); |
1566 | if (ret) | 1690 | if (ret) |
1567 | dev_dbg(&pdev->dev, "mode debugfs file is" | 1691 | dev_dbg(&pdev->dev, "Can not create mode change file\n"); |
1568 | "not available\n"); | ||
1569 | } | 1692 | } |
1570 | 1693 | ||
1571 | pm_runtime_set_active(&pdev->dev); | 1694 | pm_runtime_set_active(&pdev->dev); |
1572 | pm_runtime_enable(&pdev->dev); | 1695 | pm_runtime_enable(&pdev->dev); |
1573 | 1696 | ||
1574 | return 0; | 1697 | return 0; |
1575 | free_irq: | 1698 | |
1576 | free_irq(motg->irq, motg); | 1699 | disable_ldo: |
1700 | msm_hsusb_ldo_init(motg, 0); | ||
1701 | disable_vddcx: | ||
1702 | msm_hsusb_init_vddcx(motg, 0); | ||
1577 | disable_clks: | 1703 | disable_clks: |
1578 | clk_disable_unprepare(motg->pclk); | 1704 | clk_disable_unprepare(motg->pclk); |
1579 | clk_disable_unprepare(motg->clk); | 1705 | clk_disable_unprepare(motg->clk); |
1580 | ldo_exit: | 1706 | if (!IS_ERR(motg->core_clk)) |
1581 | msm_hsusb_ldo_init(motg, 0); | 1707 | clk_disable_unprepare(motg->core_clk); |
1582 | vddcx_exit: | ||
1583 | msm_hsusb_init_vddcx(motg, 0); | ||
1584 | free_regs: | ||
1585 | iounmap(motg->regs); | ||
1586 | put_core_clk: | ||
1587 | if (motg->core_clk) | ||
1588 | clk_put(motg->core_clk); | ||
1589 | clk_put(motg->pclk); | ||
1590 | put_pclk_src: | ||
1591 | if (!IS_ERR(motg->pclk_src)) { | ||
1592 | clk_disable_unprepare(motg->pclk_src); | ||
1593 | clk_put(motg->pclk_src); | ||
1594 | } | ||
1595 | put_clk: | ||
1596 | clk_put(motg->clk); | ||
1597 | put_phy_reset_clk: | ||
1598 | clk_put(motg->phy_reset_clk); | ||
1599 | free_motg: | ||
1600 | kfree(motg->phy.otg); | ||
1601 | kfree(motg); | ||
1602 | return ret; | 1708 | return ret; |
1603 | } | 1709 | } |
1604 | 1710 | ||
@@ -1621,7 +1727,7 @@ static int msm_otg_remove(struct platform_device *pdev) | |||
1621 | pm_runtime_disable(&pdev->dev); | 1727 | pm_runtime_disable(&pdev->dev); |
1622 | 1728 | ||
1623 | usb_remove_phy(phy); | 1729 | usb_remove_phy(phy); |
1624 | free_irq(motg->irq, motg); | 1730 | disable_irq(motg->irq); |
1625 | 1731 | ||
1626 | /* | 1732 | /* |
1627 | * Put PHY in low power mode. | 1733 | * Put PHY in low power mode. |
@@ -1641,26 +1747,12 @@ static int msm_otg_remove(struct platform_device *pdev) | |||
1641 | 1747 | ||
1642 | clk_disable_unprepare(motg->pclk); | 1748 | clk_disable_unprepare(motg->pclk); |
1643 | clk_disable_unprepare(motg->clk); | 1749 | clk_disable_unprepare(motg->clk); |
1644 | if (motg->core_clk) | 1750 | if (!IS_ERR(motg->core_clk)) |
1645 | clk_disable_unprepare(motg->core_clk); | 1751 | clk_disable_unprepare(motg->core_clk); |
1646 | if (!IS_ERR(motg->pclk_src)) { | ||
1647 | clk_disable_unprepare(motg->pclk_src); | ||
1648 | clk_put(motg->pclk_src); | ||
1649 | } | ||
1650 | msm_hsusb_ldo_init(motg, 0); | 1752 | msm_hsusb_ldo_init(motg, 0); |
1651 | 1753 | ||
1652 | iounmap(motg->regs); | ||
1653 | pm_runtime_set_suspended(&pdev->dev); | 1754 | pm_runtime_set_suspended(&pdev->dev); |
1654 | 1755 | ||
1655 | clk_put(motg->phy_reset_clk); | ||
1656 | clk_put(motg->pclk); | ||
1657 | clk_put(motg->clk); | ||
1658 | if (motg->core_clk) | ||
1659 | clk_put(motg->core_clk); | ||
1660 | |||
1661 | kfree(motg->phy.otg); | ||
1662 | kfree(motg); | ||
1663 | |||
1664 | return 0; | 1756 | return 0; |
1665 | } | 1757 | } |
1666 | 1758 | ||
@@ -1740,15 +1832,17 @@ static const struct dev_pm_ops msm_otg_dev_pm_ops = { | |||
1740 | }; | 1832 | }; |
1741 | 1833 | ||
1742 | static struct platform_driver msm_otg_driver = { | 1834 | static struct platform_driver msm_otg_driver = { |
1835 | .probe = msm_otg_probe, | ||
1743 | .remove = msm_otg_remove, | 1836 | .remove = msm_otg_remove, |
1744 | .driver = { | 1837 | .driver = { |
1745 | .name = DRIVER_NAME, | 1838 | .name = DRIVER_NAME, |
1746 | .owner = THIS_MODULE, | 1839 | .owner = THIS_MODULE, |
1747 | .pm = &msm_otg_dev_pm_ops, | 1840 | .pm = &msm_otg_dev_pm_ops, |
1841 | .of_match_table = msm_otg_dt_match, | ||
1748 | }, | 1842 | }, |
1749 | }; | 1843 | }; |
1750 | 1844 | ||
1751 | module_platform_driver_probe(msm_otg_driver, msm_otg_probe); | 1845 | module_platform_driver(msm_otg_driver); |
1752 | 1846 | ||
1753 | MODULE_LICENSE("GPL v2"); | 1847 | MODULE_LICENSE("GPL v2"); |
1754 | MODULE_DESCRIPTION("MSM USB transceiver driver"); | 1848 | MODULE_DESCRIPTION("MSM USB transceiver driver"); |
diff --git a/drivers/usb/phy/phy-mv-u3d-usb.c b/drivers/usb/phy/phy-mv-u3d-usb.c deleted file mode 100644 index d317903022bf..000000000000 --- a/drivers/usb/phy/phy-mv-u3d-usb.c +++ /dev/null | |||
@@ -1,338 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Marvell International Ltd. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/platform_device.h> | ||
11 | #include <linux/clk.h> | ||
12 | #include <linux/delay.h> | ||
13 | #include <linux/err.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/usb/otg.h> | ||
16 | #include <linux/platform_data/mv_usb.h> | ||
17 | |||
18 | #include "phy-mv-u3d-usb.h" | ||
19 | |||
20 | /* | ||
21 | * struct mv_u3d_phy - transceiver driver state | ||
22 | * @phy: transceiver structure | ||
23 | * @dev: The parent device supplied to the probe function | ||
24 | * @clk: usb phy clock | ||
25 | * @base: usb phy register memory base | ||
26 | */ | ||
27 | struct mv_u3d_phy { | ||
28 | struct usb_phy phy; | ||
29 | struct mv_usb_platform_data *plat; | ||
30 | struct device *dev; | ||
31 | struct clk *clk; | ||
32 | void __iomem *base; | ||
33 | }; | ||
34 | |||
35 | static u32 mv_u3d_phy_read(void __iomem *base, u32 reg) | ||
36 | { | ||
37 | void __iomem *addr, *data; | ||
38 | |||
39 | addr = base; | ||
40 | data = base + 0x4; | ||
41 | |||
42 | writel_relaxed(reg, addr); | ||
43 | return readl_relaxed(data); | ||
44 | } | ||
45 | |||
46 | static void mv_u3d_phy_set(void __iomem *base, u32 reg, u32 value) | ||
47 | { | ||
48 | void __iomem *addr, *data; | ||
49 | u32 tmp; | ||
50 | |||
51 | addr = base; | ||
52 | data = base + 0x4; | ||
53 | |||
54 | writel_relaxed(reg, addr); | ||
55 | tmp = readl_relaxed(data); | ||
56 | tmp |= value; | ||
57 | writel_relaxed(tmp, data); | ||
58 | } | ||
59 | |||
60 | static void mv_u3d_phy_clear(void __iomem *base, u32 reg, u32 value) | ||
61 | { | ||
62 | void __iomem *addr, *data; | ||
63 | u32 tmp; | ||
64 | |||
65 | addr = base; | ||
66 | data = base + 0x4; | ||
67 | |||
68 | writel_relaxed(reg, addr); | ||
69 | tmp = readl_relaxed(data); | ||
70 | tmp &= ~value; | ||
71 | writel_relaxed(tmp, data); | ||
72 | } | ||
73 | |||
74 | static void mv_u3d_phy_write(void __iomem *base, u32 reg, u32 value) | ||
75 | { | ||
76 | void __iomem *addr, *data; | ||
77 | |||
78 | addr = base; | ||
79 | data = base + 0x4; | ||
80 | |||
81 | writel_relaxed(reg, addr); | ||
82 | writel_relaxed(value, data); | ||
83 | } | ||
84 | |||
85 | static void mv_u3d_phy_shutdown(struct usb_phy *phy) | ||
86 | { | ||
87 | struct mv_u3d_phy *mv_u3d_phy; | ||
88 | void __iomem *base; | ||
89 | u32 val; | ||
90 | |||
91 | mv_u3d_phy = container_of(phy, struct mv_u3d_phy, phy); | ||
92 | base = mv_u3d_phy->base; | ||
93 | |||
94 | /* Power down Reference Analog current, bit 15 | ||
95 | * Power down PLL, bit 14 | ||
96 | * Power down Receiver, bit 13 | ||
97 | * Power down Transmitter, bit 12 | ||
98 | * of USB3_POWER_PLL_CONTROL register | ||
99 | */ | ||
100 | val = mv_u3d_phy_read(base, USB3_POWER_PLL_CONTROL); | ||
101 | val &= ~(USB3_POWER_PLL_CONTROL_PU); | ||
102 | mv_u3d_phy_write(base, USB3_POWER_PLL_CONTROL, val); | ||
103 | |||
104 | if (mv_u3d_phy->clk) | ||
105 | clk_disable(mv_u3d_phy->clk); | ||
106 | } | ||
107 | |||
108 | static int mv_u3d_phy_init(struct usb_phy *phy) | ||
109 | { | ||
110 | struct mv_u3d_phy *mv_u3d_phy; | ||
111 | void __iomem *base; | ||
112 | u32 val, count; | ||
113 | |||
114 | /* enable usb3 phy */ | ||
115 | mv_u3d_phy = container_of(phy, struct mv_u3d_phy, phy); | ||
116 | |||
117 | if (mv_u3d_phy->clk) | ||
118 | clk_enable(mv_u3d_phy->clk); | ||
119 | |||
120 | base = mv_u3d_phy->base; | ||
121 | |||
122 | val = mv_u3d_phy_read(base, USB3_POWER_PLL_CONTROL); | ||
123 | val &= ~(USB3_POWER_PLL_CONTROL_PU_MASK); | ||
124 | val |= 0xF << USB3_POWER_PLL_CONTROL_PU_SHIFT; | ||
125 | mv_u3d_phy_write(base, USB3_POWER_PLL_CONTROL, val); | ||
126 | udelay(100); | ||
127 | |||
128 | mv_u3d_phy_write(base, USB3_RESET_CONTROL, | ||
129 | USB3_RESET_CONTROL_RESET_PIPE); | ||
130 | udelay(100); | ||
131 | |||
132 | mv_u3d_phy_write(base, USB3_RESET_CONTROL, | ||
133 | USB3_RESET_CONTROL_RESET_PIPE | ||
134 | | USB3_RESET_CONTROL_RESET_PHY); | ||
135 | udelay(100); | ||
136 | |||
137 | val = mv_u3d_phy_read(base, USB3_POWER_PLL_CONTROL); | ||
138 | val &= ~(USB3_POWER_PLL_CONTROL_REF_FREF_SEL_MASK | ||
139 | | USB3_POWER_PLL_CONTROL_PHY_MODE_MASK); | ||
140 | val |= (USB3_PLL_25MHZ << USB3_POWER_PLL_CONTROL_REF_FREF_SEL_SHIFT) | ||
141 | | (0x5 << USB3_POWER_PLL_CONTROL_PHY_MODE_SHIFT); | ||
142 | mv_u3d_phy_write(base, USB3_POWER_PLL_CONTROL, val); | ||
143 | udelay(100); | ||
144 | |||
145 | mv_u3d_phy_clear(base, USB3_KVCO_CALI_CONTROL, | ||
146 | USB3_KVCO_CALI_CONTROL_USE_MAX_PLL_RATE_MASK); | ||
147 | udelay(100); | ||
148 | |||
149 | val = mv_u3d_phy_read(base, USB3_SQUELCH_FFE); | ||
150 | val &= ~(USB3_SQUELCH_FFE_FFE_CAP_SEL_MASK | ||
151 | | USB3_SQUELCH_FFE_FFE_RES_SEL_MASK | ||
152 | | USB3_SQUELCH_FFE_SQ_THRESH_IN_MASK); | ||
153 | val |= ((0xD << USB3_SQUELCH_FFE_FFE_CAP_SEL_SHIFT) | ||
154 | | (0x7 << USB3_SQUELCH_FFE_FFE_RES_SEL_SHIFT) | ||
155 | | (0x8 << USB3_SQUELCH_FFE_SQ_THRESH_IN_SHIFT)); | ||
156 | mv_u3d_phy_write(base, USB3_SQUELCH_FFE, val); | ||
157 | udelay(100); | ||
158 | |||
159 | val = mv_u3d_phy_read(base, USB3_GEN1_SET0); | ||
160 | val &= ~USB3_GEN1_SET0_G1_TX_SLEW_CTRL_EN_MASK; | ||
161 | val |= 1 << USB3_GEN1_SET0_G1_TX_EMPH_EN_SHIFT; | ||
162 | mv_u3d_phy_write(base, USB3_GEN1_SET0, val); | ||
163 | udelay(100); | ||
164 | |||
165 | val = mv_u3d_phy_read(base, USB3_GEN2_SET0); | ||
166 | val &= ~(USB3_GEN2_SET0_G2_TX_AMP_MASK | ||
167 | | USB3_GEN2_SET0_G2_TX_EMPH_AMP_MASK | ||
168 | | USB3_GEN2_SET0_G2_TX_SLEW_CTRL_EN_MASK); | ||
169 | val |= ((0x14 << USB3_GEN2_SET0_G2_TX_AMP_SHIFT) | ||
170 | | (1 << USB3_GEN2_SET0_G2_TX_AMP_ADJ_SHIFT) | ||
171 | | (0xA << USB3_GEN2_SET0_G2_TX_EMPH_AMP_SHIFT) | ||
172 | | (1 << USB3_GEN2_SET0_G2_TX_EMPH_EN_SHIFT)); | ||
173 | mv_u3d_phy_write(base, USB3_GEN2_SET0, val); | ||
174 | udelay(100); | ||
175 | |||
176 | mv_u3d_phy_read(base, USB3_TX_EMPPH); | ||
177 | val &= ~(USB3_TX_EMPPH_AMP_MASK | ||
178 | | USB3_TX_EMPPH_EN_MASK | ||
179 | | USB3_TX_EMPPH_AMP_FORCE_MASK | ||
180 | | USB3_TX_EMPPH_PAR1_MASK | ||
181 | | USB3_TX_EMPPH_PAR2_MASK); | ||
182 | val |= ((0xB << USB3_TX_EMPPH_AMP_SHIFT) | ||
183 | | (1 << USB3_TX_EMPPH_EN_SHIFT) | ||
184 | | (1 << USB3_TX_EMPPH_AMP_FORCE_SHIFT) | ||
185 | | (0x1C << USB3_TX_EMPPH_PAR1_SHIFT) | ||
186 | | (1 << USB3_TX_EMPPH_PAR2_SHIFT)); | ||
187 | |||
188 | mv_u3d_phy_write(base, USB3_TX_EMPPH, val); | ||
189 | udelay(100); | ||
190 | |||
191 | val = mv_u3d_phy_read(base, USB3_GEN2_SET1); | ||
192 | val &= ~(USB3_GEN2_SET1_G2_RX_SELMUPI_MASK | ||
193 | | USB3_GEN2_SET1_G2_RX_SELMUPF_MASK | ||
194 | | USB3_GEN2_SET1_G2_RX_SELMUFI_MASK | ||
195 | | USB3_GEN2_SET1_G2_RX_SELMUFF_MASK); | ||
196 | val |= ((1 << USB3_GEN2_SET1_G2_RX_SELMUPI_SHIFT) | ||
197 | | (1 << USB3_GEN2_SET1_G2_RX_SELMUPF_SHIFT) | ||
198 | | (1 << USB3_GEN2_SET1_G2_RX_SELMUFI_SHIFT) | ||
199 | | (1 << USB3_GEN2_SET1_G2_RX_SELMUFF_SHIFT)); | ||
200 | mv_u3d_phy_write(base, USB3_GEN2_SET1, val); | ||
201 | udelay(100); | ||
202 | |||
203 | val = mv_u3d_phy_read(base, USB3_DIGITAL_LOOPBACK_EN); | ||
204 | val &= ~USB3_DIGITAL_LOOPBACK_EN_SEL_BITS_MASK; | ||
205 | val |= 1 << USB3_DIGITAL_LOOPBACK_EN_SEL_BITS_SHIFT; | ||
206 | mv_u3d_phy_write(base, USB3_DIGITAL_LOOPBACK_EN, val); | ||
207 | udelay(100); | ||
208 | |||
209 | val = mv_u3d_phy_read(base, USB3_IMPEDANCE_TX_SSC); | ||
210 | val &= ~USB3_IMPEDANCE_TX_SSC_SSC_AMP_MASK; | ||
211 | val |= 0xC << USB3_IMPEDANCE_TX_SSC_SSC_AMP_SHIFT; | ||
212 | mv_u3d_phy_write(base, USB3_IMPEDANCE_TX_SSC, val); | ||
213 | udelay(100); | ||
214 | |||
215 | val = mv_u3d_phy_read(base, USB3_IMPEDANCE_CALI_CTRL); | ||
216 | val &= ~USB3_IMPEDANCE_CALI_CTRL_IMP_CAL_THR_MASK; | ||
217 | val |= 0x4 << USB3_IMPEDANCE_CALI_CTRL_IMP_CAL_THR_SHIFT; | ||
218 | mv_u3d_phy_write(base, USB3_IMPEDANCE_CALI_CTRL, val); | ||
219 | udelay(100); | ||
220 | |||
221 | val = mv_u3d_phy_read(base, USB3_PHY_ISOLATION_MODE); | ||
222 | val &= ~(USB3_PHY_ISOLATION_MODE_PHY_GEN_RX_MASK | ||
223 | | USB3_PHY_ISOLATION_MODE_PHY_GEN_TX_MASK | ||
224 | | USB3_PHY_ISOLATION_MODE_TX_DRV_IDLE_MASK); | ||
225 | val |= ((1 << USB3_PHY_ISOLATION_MODE_PHY_GEN_RX_SHIFT) | ||
226 | | (1 << USB3_PHY_ISOLATION_MODE_PHY_GEN_TX_SHIFT)); | ||
227 | mv_u3d_phy_write(base, USB3_PHY_ISOLATION_MODE, val); | ||
228 | udelay(100); | ||
229 | |||
230 | val = mv_u3d_phy_read(base, USB3_TXDETRX); | ||
231 | val &= ~(USB3_TXDETRX_VTHSEL_MASK); | ||
232 | val |= 0x1 << USB3_TXDETRX_VTHSEL_SHIFT; | ||
233 | mv_u3d_phy_write(base, USB3_TXDETRX, val); | ||
234 | udelay(100); | ||
235 | |||
236 | dev_dbg(mv_u3d_phy->dev, "start calibration\n"); | ||
237 | |||
238 | calstart: | ||
239 | /* Perform Manual Calibration */ | ||
240 | mv_u3d_phy_set(base, USB3_KVCO_CALI_CONTROL, | ||
241 | 1 << USB3_KVCO_CALI_CONTROL_CAL_START_SHIFT); | ||
242 | |||
243 | mdelay(1); | ||
244 | |||
245 | count = 0; | ||
246 | while (1) { | ||
247 | val = mv_u3d_phy_read(base, USB3_KVCO_CALI_CONTROL); | ||
248 | if (val & (1 << USB3_KVCO_CALI_CONTROL_CAL_DONE_SHIFT)) | ||
249 | break; | ||
250 | else if (count > 50) { | ||
251 | dev_dbg(mv_u3d_phy->dev, "calibration failure, retry...\n"); | ||
252 | goto calstart; | ||
253 | } | ||
254 | count++; | ||
255 | mdelay(1); | ||
256 | } | ||
257 | |||
258 | /* active PIPE interface */ | ||
259 | mv_u3d_phy_write(base, USB3_PIPE_SM_CTRL, | ||
260 | 1 << USB3_PIPE_SM_CTRL_PHY_INIT_DONE); | ||
261 | |||
262 | return 0; | ||
263 | } | ||
264 | |||
265 | static int mv_u3d_phy_probe(struct platform_device *pdev) | ||
266 | { | ||
267 | struct mv_u3d_phy *mv_u3d_phy; | ||
268 | struct mv_usb_platform_data *pdata; | ||
269 | struct device *dev = &pdev->dev; | ||
270 | struct resource *res; | ||
271 | void __iomem *phy_base; | ||
272 | int ret; | ||
273 | |||
274 | pdata = dev_get_platdata(&pdev->dev); | ||
275 | if (!pdata) { | ||
276 | dev_err(&pdev->dev, "%s: no platform data defined\n", __func__); | ||
277 | return -EINVAL; | ||
278 | } | ||
279 | |||
280 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
281 | phy_base = devm_ioremap_resource(dev, res); | ||
282 | if (IS_ERR(phy_base)) | ||
283 | return PTR_ERR(phy_base); | ||
284 | |||
285 | mv_u3d_phy = devm_kzalloc(dev, sizeof(*mv_u3d_phy), GFP_KERNEL); | ||
286 | if (!mv_u3d_phy) | ||
287 | return -ENOMEM; | ||
288 | |||
289 | mv_u3d_phy->dev = &pdev->dev; | ||
290 | mv_u3d_phy->plat = pdata; | ||
291 | mv_u3d_phy->base = phy_base; | ||
292 | mv_u3d_phy->phy.dev = mv_u3d_phy->dev; | ||
293 | mv_u3d_phy->phy.label = "mv-u3d-phy"; | ||
294 | mv_u3d_phy->phy.init = mv_u3d_phy_init; | ||
295 | mv_u3d_phy->phy.shutdown = mv_u3d_phy_shutdown; | ||
296 | |||
297 | ret = usb_add_phy(&mv_u3d_phy->phy, USB_PHY_TYPE_USB3); | ||
298 | if (ret) | ||
299 | goto err; | ||
300 | |||
301 | if (!mv_u3d_phy->clk) | ||
302 | mv_u3d_phy->clk = clk_get(mv_u3d_phy->dev, "u3dphy"); | ||
303 | |||
304 | platform_set_drvdata(pdev, mv_u3d_phy); | ||
305 | |||
306 | dev_info(&pdev->dev, "Initialized Marvell USB 3.0 PHY\n"); | ||
307 | err: | ||
308 | return ret; | ||
309 | } | ||
310 | |||
311 | static int mv_u3d_phy_remove(struct platform_device *pdev) | ||
312 | { | ||
313 | struct mv_u3d_phy *mv_u3d_phy = platform_get_drvdata(pdev); | ||
314 | |||
315 | usb_remove_phy(&mv_u3d_phy->phy); | ||
316 | |||
317 | if (mv_u3d_phy->clk) { | ||
318 | clk_put(mv_u3d_phy->clk); | ||
319 | mv_u3d_phy->clk = NULL; | ||
320 | } | ||
321 | |||
322 | return 0; | ||
323 | } | ||
324 | |||
325 | static struct platform_driver mv_u3d_phy_driver = { | ||
326 | .probe = mv_u3d_phy_probe, | ||
327 | .remove = mv_u3d_phy_remove, | ||
328 | .driver = { | ||
329 | .name = "mv-u3d-phy", | ||
330 | .owner = THIS_MODULE, | ||
331 | }, | ||
332 | }; | ||
333 | |||
334 | module_platform_driver(mv_u3d_phy_driver); | ||
335 | MODULE_DESCRIPTION("Marvell USB 3.0 PHY controller"); | ||
336 | MODULE_AUTHOR("Yu Xu <yuxu@marvell.com>"); | ||
337 | MODULE_LICENSE("GPL"); | ||
338 | MODULE_ALIAS("platform:mv-u3d-phy"); | ||
diff --git a/drivers/usb/phy/phy-mv-u3d-usb.h b/drivers/usb/phy/phy-mv-u3d-usb.h deleted file mode 100644 index 2a658cb9a527..000000000000 --- a/drivers/usb/phy/phy-mv-u3d-usb.h +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Marvell International Ltd. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef __MV_U3D_PHY_H | ||
10 | #define __MV_U3D_PHY_H | ||
11 | |||
12 | #define USB3_POWER_PLL_CONTROL 0x1 | ||
13 | #define USB3_KVCO_CALI_CONTROL 0x2 | ||
14 | #define USB3_IMPEDANCE_CALI_CTRL 0x3 | ||
15 | #define USB3_IMPEDANCE_TX_SSC 0x4 | ||
16 | #define USB3_SQUELCH_FFE 0x6 | ||
17 | #define USB3_GEN1_SET0 0xD | ||
18 | #define USB3_GEN2_SET0 0xF | ||
19 | #define USB3_GEN2_SET1 0x10 | ||
20 | #define USB3_DIGITAL_LOOPBACK_EN 0x23 | ||
21 | #define USB3_PHY_ISOLATION_MODE 0x26 | ||
22 | #define USB3_TXDETRX 0x48 | ||
23 | #define USB3_TX_EMPPH 0x5E | ||
24 | #define USB3_RESET_CONTROL 0x90 | ||
25 | #define USB3_PIPE_SM_CTRL 0x91 | ||
26 | |||
27 | #define USB3_RESET_CONTROL_RESET_PIPE 0x1 | ||
28 | #define USB3_RESET_CONTROL_RESET_PHY 0x2 | ||
29 | |||
30 | #define USB3_POWER_PLL_CONTROL_REF_FREF_SEL_MASK (0x1F << 0) | ||
31 | #define USB3_POWER_PLL_CONTROL_REF_FREF_SEL_SHIFT 0 | ||
32 | #define USB3_PLL_25MHZ 0x2 | ||
33 | #define USB3_PLL_26MHZ 0x5 | ||
34 | #define USB3_POWER_PLL_CONTROL_PHY_MODE_MASK (0x7 << 5) | ||
35 | #define USB3_POWER_PLL_CONTROL_PHY_MODE_SHIFT 5 | ||
36 | #define USB3_POWER_PLL_CONTROL_PU_MASK (0xF << 12) | ||
37 | #define USB3_POWER_PLL_CONTROL_PU_SHIFT 12 | ||
38 | #define USB3_POWER_PLL_CONTROL_PU (0xF << 12) | ||
39 | |||
40 | #define USB3_KVCO_CALI_CONTROL_USE_MAX_PLL_RATE_MASK (0x1 << 12) | ||
41 | #define USB3_KVCO_CALI_CONTROL_USE_MAX_PLL_RATE_SHIFT 12 | ||
42 | #define USB3_KVCO_CALI_CONTROL_CAL_DONE_SHIFT 14 | ||
43 | #define USB3_KVCO_CALI_CONTROL_CAL_START_SHIFT 15 | ||
44 | |||
45 | #define USB3_SQUELCH_FFE_FFE_CAP_SEL_MASK 0xF | ||
46 | #define USB3_SQUELCH_FFE_FFE_CAP_SEL_SHIFT 0 | ||
47 | #define USB3_SQUELCH_FFE_FFE_RES_SEL_MASK (0x7 << 4) | ||
48 | #define USB3_SQUELCH_FFE_FFE_RES_SEL_SHIFT 4 | ||
49 | #define USB3_SQUELCH_FFE_SQ_THRESH_IN_MASK (0x1F << 8) | ||
50 | #define USB3_SQUELCH_FFE_SQ_THRESH_IN_SHIFT 8 | ||
51 | |||
52 | #define USB3_GEN1_SET0_G1_TX_SLEW_CTRL_EN_MASK (0x1 << 15) | ||
53 | #define USB3_GEN1_SET0_G1_TX_EMPH_EN_SHIFT 11 | ||
54 | |||
55 | #define USB3_GEN2_SET0_G2_TX_AMP_MASK (0x1F << 1) | ||
56 | #define USB3_GEN2_SET0_G2_TX_AMP_SHIFT 1 | ||
57 | #define USB3_GEN2_SET0_G2_TX_AMP_ADJ_SHIFT 6 | ||
58 | #define USB3_GEN2_SET0_G2_TX_EMPH_AMP_MASK (0xF << 7) | ||
59 | #define USB3_GEN2_SET0_G2_TX_EMPH_AMP_SHIFT 7 | ||
60 | #define USB3_GEN2_SET0_G2_TX_EMPH_EN_MASK (0x1 << 11) | ||
61 | #define USB3_GEN2_SET0_G2_TX_EMPH_EN_SHIFT 11 | ||
62 | #define USB3_GEN2_SET0_G2_TX_SLEW_CTRL_EN_MASK (0x1 << 15) | ||
63 | #define USB3_GEN2_SET0_G2_TX_SLEW_CTRL_EN_SHIFT 15 | ||
64 | |||
65 | #define USB3_GEN2_SET1_G2_RX_SELMUPI_MASK (0x7 << 0) | ||
66 | #define USB3_GEN2_SET1_G2_RX_SELMUPI_SHIFT 0 | ||
67 | #define USB3_GEN2_SET1_G2_RX_SELMUPF_MASK (0x7 << 3) | ||
68 | #define USB3_GEN2_SET1_G2_RX_SELMUPF_SHIFT 3 | ||
69 | #define USB3_GEN2_SET1_G2_RX_SELMUFI_MASK (0x3 << 6) | ||
70 | #define USB3_GEN2_SET1_G2_RX_SELMUFI_SHIFT 6 | ||
71 | #define USB3_GEN2_SET1_G2_RX_SELMUFF_MASK (0x3 << 8) | ||
72 | #define USB3_GEN2_SET1_G2_RX_SELMUFF_SHIFT 8 | ||
73 | |||
74 | #define USB3_DIGITAL_LOOPBACK_EN_SEL_BITS_MASK (0x3 << 10) | ||
75 | #define USB3_DIGITAL_LOOPBACK_EN_SEL_BITS_SHIFT 10 | ||
76 | |||
77 | #define USB3_IMPEDANCE_CALI_CTRL_IMP_CAL_THR_MASK (0x7 << 12) | ||
78 | #define USB3_IMPEDANCE_CALI_CTRL_IMP_CAL_THR_SHIFT 12 | ||
79 | |||
80 | #define USB3_IMPEDANCE_TX_SSC_SSC_AMP_MASK (0x3F << 0) | ||
81 | #define USB3_IMPEDANCE_TX_SSC_SSC_AMP_SHIFT 0 | ||
82 | |||
83 | #define USB3_PHY_ISOLATION_MODE_PHY_GEN_RX_MASK 0xF | ||
84 | #define USB3_PHY_ISOLATION_MODE_PHY_GEN_RX_SHIFT 0 | ||
85 | #define USB3_PHY_ISOLATION_MODE_PHY_GEN_TX_MASK (0xF << 4) | ||
86 | #define USB3_PHY_ISOLATION_MODE_PHY_GEN_TX_SHIFT 4 | ||
87 | #define USB3_PHY_ISOLATION_MODE_TX_DRV_IDLE_MASK (0x1 << 8) | ||
88 | |||
89 | #define USB3_TXDETRX_VTHSEL_MASK (0x3 << 4) | ||
90 | #define USB3_TXDETRX_VTHSEL_SHIFT 4 | ||
91 | |||
92 | #define USB3_TX_EMPPH_AMP_MASK (0xF << 0) | ||
93 | #define USB3_TX_EMPPH_AMP_SHIFT 0 | ||
94 | #define USB3_TX_EMPPH_EN_MASK (0x1 << 6) | ||
95 | #define USB3_TX_EMPPH_EN_SHIFT 6 | ||
96 | #define USB3_TX_EMPPH_AMP_FORCE_MASK (0x1 << 7) | ||
97 | #define USB3_TX_EMPPH_AMP_FORCE_SHIFT 7 | ||
98 | #define USB3_TX_EMPPH_PAR1_MASK (0x1F << 8) | ||
99 | #define USB3_TX_EMPPH_PAR1_SHIFT 8 | ||
100 | #define USB3_TX_EMPPH_PAR2_MASK (0x1 << 13) | ||
101 | #define USB3_TX_EMPPH_PAR2_SHIFT 13 | ||
102 | |||
103 | #define USB3_PIPE_SM_CTRL_PHY_INIT_DONE 15 | ||
104 | |||
105 | #endif /* __MV_U3D_PHY_H */ | ||
diff --git a/drivers/usb/phy/phy-ulpi.c b/drivers/usb/phy/phy-ulpi.c index 17ea3f271bd8..4e3877c329f2 100644 --- a/drivers/usb/phy/phy-ulpi.c +++ b/drivers/usb/phy/phy-ulpi.c | |||
@@ -48,6 +48,7 @@ static struct ulpi_info ulpi_ids[] = { | |||
48 | ULPI_INFO(ULPI_ID(0x04cc, 0x1504), "NXP ISP1504"), | 48 | ULPI_INFO(ULPI_ID(0x04cc, 0x1504), "NXP ISP1504"), |
49 | ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"), | 49 | ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"), |
50 | ULPI_INFO(ULPI_ID(0x0424, 0x0007), "SMSC USB3320"), | 50 | ULPI_INFO(ULPI_ID(0x0424, 0x0007), "SMSC USB3320"), |
51 | ULPI_INFO(ULPI_ID(0x0424, 0x0009), "SMSC USB334x"), | ||
51 | ULPI_INFO(ULPI_ID(0x0451, 0x1507), "TI TUSB1210"), | 52 | ULPI_INFO(ULPI_ID(0x0451, 0x1507), "TI TUSB1210"), |
52 | }; | 53 | }; |
53 | 54 | ||
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index 35a2373cde67..9374bd2aba20 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c | |||
@@ -97,13 +97,19 @@ static int usb_serial_device_remove(struct device *dev) | |||
97 | struct usb_serial_port *port; | 97 | struct usb_serial_port *port; |
98 | int retval = 0; | 98 | int retval = 0; |
99 | int minor; | 99 | int minor; |
100 | int autopm_err; | ||
100 | 101 | ||
101 | port = to_usb_serial_port(dev); | 102 | port = to_usb_serial_port(dev); |
102 | if (!port) | 103 | if (!port) |
103 | return -ENODEV; | 104 | return -ENODEV; |
104 | 105 | ||
105 | /* make sure suspend/resume doesn't race against port_remove */ | 106 | /* |
106 | usb_autopm_get_interface(port->serial->interface); | 107 | * Make sure suspend/resume doesn't race against port_remove. |
108 | * | ||
109 | * Note that no further runtime PM callbacks will be made if | ||
110 | * autopm_get fails. | ||
111 | */ | ||
112 | autopm_err = usb_autopm_get_interface(port->serial->interface); | ||
107 | 113 | ||
108 | minor = port->minor; | 114 | minor = port->minor; |
109 | tty_unregister_device(usb_serial_tty_driver, minor); | 115 | tty_unregister_device(usb_serial_tty_driver, minor); |
@@ -117,7 +123,9 @@ static int usb_serial_device_remove(struct device *dev) | |||
117 | dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", | 123 | dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", |
118 | driver->description, minor); | 124 | driver->description, minor); |
119 | 125 | ||
120 | usb_autopm_put_interface(port->serial->interface); | 126 | if (!autopm_err) |
127 | usb_autopm_put_interface(port->serial->interface); | ||
128 | |||
121 | return retval; | 129 | return retval; |
122 | } | 130 | } |
123 | 131 | ||
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index d3acaead5a81..93cb7cebda62 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -1535,14 +1535,14 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial, | |||
1535 | 1535 | ||
1536 | this_urb = p_priv->outcont_urb; | 1536 | this_urb = p_priv->outcont_urb; |
1537 | 1537 | ||
1538 | dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe)); | ||
1539 | |||
1540 | /* Make sure we have an urb then send the message */ | 1538 | /* Make sure we have an urb then send the message */ |
1541 | if (this_urb == NULL) { | 1539 | if (this_urb == NULL) { |
1542 | dev_dbg(&port->dev, "%s - oops no urb.\n", __func__); | 1540 | dev_dbg(&port->dev, "%s - oops no urb.\n", __func__); |
1543 | return -1; | 1541 | return -1; |
1544 | } | 1542 | } |
1545 | 1543 | ||
1544 | dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe)); | ||
1545 | |||
1546 | /* Save reset port val for resend. | 1546 | /* Save reset port val for resend. |
1547 | Don't overwrite resend for open/close condition. */ | 1547 | Don't overwrite resend for open/close condition. */ |
1548 | if ((reset_port + 1) > p_priv->resend_cont) | 1548 | if ((reset_port + 1) > p_priv->resend_cont) |
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index fee242387f55..078f9ed419c8 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -215,13 +215,13 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
215 | priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { | 215 | priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { |
216 | /* Setting Baudrate, Parity and Stopbits */ | 216 | /* Setting Baudrate, Parity and Stopbits */ |
217 | result = usb_control_msg(port->serial->dev, | 217 | result = usb_control_msg(port->serial->dev, |
218 | usb_rcvctrlpipe(port->serial->dev, 0), | 218 | usb_sndctrlpipe(port->serial->dev, 0), |
219 | SUSBCRequest_SetBaudRateParityAndStopBits, | 219 | SUSBCRequest_SetBaudRateParityAndStopBits, |
220 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 220 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
221 | SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity | | 221 | SUSBCR_SBR_9600 | SUSBCR_SPASB_EvenParity | |
222 | SUSBCR_SPASB_1StopBit, | 222 | SUSBCR_SPASB_1StopBit, |
223 | 0, | 223 | 0, |
224 | transfer_buffer, | 224 | NULL, |
225 | 0, | 225 | 0, |
226 | KOBIL_TIMEOUT | 226 | KOBIL_TIMEOUT |
227 | ); | 227 | ); |
@@ -229,12 +229,12 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
229 | 229 | ||
230 | /* reset all queues */ | 230 | /* reset all queues */ |
231 | result = usb_control_msg(port->serial->dev, | 231 | result = usb_control_msg(port->serial->dev, |
232 | usb_rcvctrlpipe(port->serial->dev, 0), | 232 | usb_sndctrlpipe(port->serial->dev, 0), |
233 | SUSBCRequest_Misc, | 233 | SUSBCRequest_Misc, |
234 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 234 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
235 | SUSBCR_MSC_ResetAllQueues, | 235 | SUSBCR_MSC_ResetAllQueues, |
236 | 0, | 236 | 0, |
237 | transfer_buffer, | 237 | NULL, |
238 | 0, | 238 | 0, |
239 | KOBIL_TIMEOUT | 239 | KOBIL_TIMEOUT |
240 | ); | 240 | ); |
@@ -445,12 +445,12 @@ static int kobil_tiocmset(struct tty_struct *tty, | |||
445 | else | 445 | else |
446 | dev_dbg(dev, "%s - Clearing DTR\n", __func__); | 446 | dev_dbg(dev, "%s - Clearing DTR\n", __func__); |
447 | result = usb_control_msg(port->serial->dev, | 447 | result = usb_control_msg(port->serial->dev, |
448 | usb_rcvctrlpipe(port->serial->dev, 0), | 448 | usb_sndctrlpipe(port->serial->dev, 0), |
449 | SUSBCRequest_SetStatusLinesOrQueues, | 449 | SUSBCRequest_SetStatusLinesOrQueues, |
450 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 450 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
451 | ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR), | 451 | ((dtr != 0) ? SUSBCR_SSL_SETDTR : SUSBCR_SSL_CLRDTR), |
452 | 0, | 452 | 0, |
453 | transfer_buffer, | 453 | NULL, |
454 | 0, | 454 | 0, |
455 | KOBIL_TIMEOUT); | 455 | KOBIL_TIMEOUT); |
456 | } else { | 456 | } else { |
@@ -459,12 +459,12 @@ static int kobil_tiocmset(struct tty_struct *tty, | |||
459 | else | 459 | else |
460 | dev_dbg(dev, "%s - Clearing RTS\n", __func__); | 460 | dev_dbg(dev, "%s - Clearing RTS\n", __func__); |
461 | result = usb_control_msg(port->serial->dev, | 461 | result = usb_control_msg(port->serial->dev, |
462 | usb_rcvctrlpipe(port->serial->dev, 0), | 462 | usb_sndctrlpipe(port->serial->dev, 0), |
463 | SUSBCRequest_SetStatusLinesOrQueues, | 463 | SUSBCRequest_SetStatusLinesOrQueues, |
464 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 464 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
465 | ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS), | 465 | ((rts != 0) ? SUSBCR_SSL_SETRTS : SUSBCR_SSL_CLRRTS), |
466 | 0, | 466 | 0, |
467 | transfer_buffer, | 467 | NULL, |
468 | 0, | 468 | 0, |
469 | KOBIL_TIMEOUT); | 469 | KOBIL_TIMEOUT); |
470 | } | 470 | } |
@@ -514,7 +514,7 @@ static void kobil_set_termios(struct tty_struct *tty, | |||
514 | tty_encode_baud_rate(tty, speed, speed); | 514 | tty_encode_baud_rate(tty, speed, speed); |
515 | 515 | ||
516 | result = usb_control_msg(port->serial->dev, | 516 | result = usb_control_msg(port->serial->dev, |
517 | usb_rcvctrlpipe(port->serial->dev, 0), | 517 | usb_sndctrlpipe(port->serial->dev, 0), |
518 | SUSBCRequest_SetBaudRateParityAndStopBits, | 518 | SUSBCRequest_SetBaudRateParityAndStopBits, |
519 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 519 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
520 | urb_val, | 520 | urb_val, |
@@ -546,12 +546,12 @@ static int kobil_ioctl(struct tty_struct *tty, | |||
546 | return -ENOBUFS; | 546 | return -ENOBUFS; |
547 | 547 | ||
548 | result = usb_control_msg(port->serial->dev, | 548 | result = usb_control_msg(port->serial->dev, |
549 | usb_rcvctrlpipe(port->serial->dev, 0), | 549 | usb_sndctrlpipe(port->serial->dev, 0), |
550 | SUSBCRequest_Misc, | 550 | SUSBCRequest_Misc, |
551 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, | 551 | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, |
552 | SUSBCR_MSC_ResetAllQueues, | 552 | SUSBCR_MSC_ResetAllQueues, |
553 | 0, | 553 | 0, |
554 | NULL, /* transfer_buffer, */ | 554 | NULL, |
555 | 0, | 555 | 0, |
556 | KOBIL_TIMEOUT | 556 | KOBIL_TIMEOUT |
557 | ); | 557 | ); |
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index f213ee978516..51e30740b2fe 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -1729,7 +1729,6 @@ static struct usb_serial_driver option_1port_device = { | |||
1729 | .write = usb_wwan_write, | 1729 | .write = usb_wwan_write, |
1730 | .write_room = usb_wwan_write_room, | 1730 | .write_room = usb_wwan_write_room, |
1731 | .chars_in_buffer = usb_wwan_chars_in_buffer, | 1731 | .chars_in_buffer = usb_wwan_chars_in_buffer, |
1732 | .set_termios = usb_wwan_set_termios, | ||
1733 | .tiocmget = usb_wwan_tiocmget, | 1732 | .tiocmget = usb_wwan_tiocmget, |
1734 | .tiocmset = usb_wwan_tiocmset, | 1733 | .tiocmset = usb_wwan_tiocmset, |
1735 | .ioctl = usb_wwan_ioctl, | 1734 | .ioctl = usb_wwan_ioctl, |
@@ -1904,6 +1903,7 @@ static void option_instat_callback(struct urb *urb) | |||
1904 | 1903 | ||
1905 | /* Resubmit urb so we continue receiving IRQ data */ | 1904 | /* Resubmit urb so we continue receiving IRQ data */ |
1906 | if (status != -ESHUTDOWN && status != -ENOENT) { | 1905 | if (status != -ESHUTDOWN && status != -ENOENT) { |
1906 | usb_mark_last_busy(port->serial->dev); | ||
1907 | err = usb_submit_urb(urb, GFP_ATOMIC); | 1907 | err = usb_submit_urb(urb, GFP_ATOMIC); |
1908 | if (err) | 1908 | if (err) |
1909 | dev_dbg(dev, "%s: resubmit intr urb failed. (%d)\n", | 1909 | dev_dbg(dev, "%s: resubmit intr urb failed. (%d)\n", |
@@ -1923,6 +1923,7 @@ static int option_send_setup(struct usb_serial_port *port) | |||
1923 | struct option_private *priv = intfdata->private; | 1923 | struct option_private *priv = intfdata->private; |
1924 | struct usb_wwan_port_private *portdata; | 1924 | struct usb_wwan_port_private *portdata; |
1925 | int val = 0; | 1925 | int val = 0; |
1926 | int res; | ||
1926 | 1927 | ||
1927 | portdata = usb_get_serial_port_data(port); | 1928 | portdata = usb_get_serial_port_data(port); |
1928 | 1929 | ||
@@ -1931,9 +1932,17 @@ static int option_send_setup(struct usb_serial_port *port) | |||
1931 | if (portdata->rts_state) | 1932 | if (portdata->rts_state) |
1932 | val |= 0x02; | 1933 | val |= 0x02; |
1933 | 1934 | ||
1934 | return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 1935 | res = usb_autopm_get_interface(serial->interface); |
1936 | if (res) | ||
1937 | return res; | ||
1938 | |||
1939 | res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
1935 | 0x22, 0x21, val, priv->bInterfaceNumber, NULL, | 1940 | 0x22, 0x21, val, priv->bInterfaceNumber, NULL, |
1936 | 0, USB_CTRL_SET_TIMEOUT); | 1941 | 0, USB_CTRL_SET_TIMEOUT); |
1942 | |||
1943 | usb_autopm_put_interface(serial->interface); | ||
1944 | |||
1945 | return res; | ||
1937 | } | 1946 | } |
1938 | 1947 | ||
1939 | MODULE_AUTHOR(DRIVER_AUTHOR); | 1948 | MODULE_AUTHOR(DRIVER_AUTHOR); |
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c index 6c0a542e8ec1..b2aa003bf411 100644 --- a/drivers/usb/serial/qcserial.c +++ b/drivers/usb/serial/qcserial.c | |||
@@ -22,8 +22,17 @@ | |||
22 | #define DRIVER_AUTHOR "Qualcomm Inc" | 22 | #define DRIVER_AUTHOR "Qualcomm Inc" |
23 | #define DRIVER_DESC "Qualcomm USB Serial driver" | 23 | #define DRIVER_DESC "Qualcomm USB Serial driver" |
24 | 24 | ||
25 | /* standard device layouts supported by this driver */ | ||
26 | enum qcserial_layouts { | ||
27 | QCSERIAL_G2K = 0, /* Gobi 2000 */ | ||
28 | QCSERIAL_G1K = 1, /* Gobi 1000 */ | ||
29 | QCSERIAL_SWI = 2, /* Sierra Wireless */ | ||
30 | }; | ||
31 | |||
25 | #define DEVICE_G1K(v, p) \ | 32 | #define DEVICE_G1K(v, p) \ |
26 | USB_DEVICE(v, p), .driver_info = 1 | 33 | USB_DEVICE(v, p), .driver_info = QCSERIAL_G1K |
34 | #define DEVICE_SWI(v, p) \ | ||
35 | USB_DEVICE(v, p), .driver_info = QCSERIAL_SWI | ||
27 | 36 | ||
28 | static const struct usb_device_id id_table[] = { | 37 | static const struct usb_device_id id_table[] = { |
29 | /* Gobi 1000 devices */ | 38 | /* Gobi 1000 devices */ |
@@ -126,46 +135,27 @@ static const struct usb_device_id id_table[] = { | |||
126 | {USB_DEVICE(0x12D1, 0x14F1)}, /* Sony Gobi 3000 Composite */ | 135 | {USB_DEVICE(0x12D1, 0x14F1)}, /* Sony Gobi 3000 Composite */ |
127 | {USB_DEVICE(0x0AF0, 0x8120)}, /* Option GTM681W */ | 136 | {USB_DEVICE(0x0AF0, 0x8120)}, /* Option GTM681W */ |
128 | 137 | ||
129 | /* non Gobi Qualcomm serial devices */ | 138 | /* non-Gobi Sierra Wireless devices */ |
130 | {USB_DEVICE_INTERFACE_NUMBER(0x0f3d, 0x68a2, 0)}, /* Sierra Wireless MC7700 Device Management */ | 139 | {DEVICE_SWI(0x0f3d, 0x68a2)}, /* Sierra Wireless MC7700 */ |
131 | {USB_DEVICE_INTERFACE_NUMBER(0x0f3d, 0x68a2, 2)}, /* Sierra Wireless MC7700 NMEA */ | 140 | {DEVICE_SWI(0x114f, 0x68a2)}, /* Sierra Wireless MC7750 */ |
132 | {USB_DEVICE_INTERFACE_NUMBER(0x0f3d, 0x68a2, 3)}, /* Sierra Wireless MC7700 Modem */ | 141 | {DEVICE_SWI(0x1199, 0x68a2)}, /* Sierra Wireless MC7710 */ |
133 | {USB_DEVICE_INTERFACE_NUMBER(0x114f, 0x68a2, 0)}, /* Sierra Wireless MC7750 Device Management */ | 142 | {DEVICE_SWI(0x1199, 0x68c0)}, /* Sierra Wireless MC73xx */ |
134 | {USB_DEVICE_INTERFACE_NUMBER(0x114f, 0x68a2, 2)}, /* Sierra Wireless MC7750 NMEA */ | 143 | {DEVICE_SWI(0x1199, 0x901c)}, /* Sierra Wireless EM7700 */ |
135 | {USB_DEVICE_INTERFACE_NUMBER(0x114f, 0x68a2, 3)}, /* Sierra Wireless MC7750 Modem */ | 144 | {DEVICE_SWI(0x1199, 0x901f)}, /* Sierra Wireless EM7355 */ |
136 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68a2, 0)}, /* Sierra Wireless MC7710 Device Management */ | 145 | {DEVICE_SWI(0x1199, 0x9040)}, /* Sierra Wireless Modem */ |
137 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68a2, 2)}, /* Sierra Wireless MC7710 NMEA */ | 146 | {DEVICE_SWI(0x1199, 0x9041)}, /* Sierra Wireless MC7305/MC7355 */ |
138 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68a2, 3)}, /* Sierra Wireless MC7710 Modem */ | 147 | {DEVICE_SWI(0x1199, 0x9051)}, /* Netgear AirCard 340U */ |
139 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68c0, 0)}, /* Sierra Wireless MC73xx Device Management */ | 148 | {DEVICE_SWI(0x1199, 0x9053)}, /* Sierra Wireless Modem */ |
140 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68c0, 2)}, /* Sierra Wireless MC73xx NMEA */ | 149 | {DEVICE_SWI(0x1199, 0x9054)}, /* Sierra Wireless Modem */ |
141 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x68c0, 3)}, /* Sierra Wireless MC73xx Modem */ | 150 | {DEVICE_SWI(0x1199, 0x9055)}, /* Netgear AirCard 341U */ |
142 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 0)}, /* Sierra Wireless EM7700 Device Management */ | 151 | {DEVICE_SWI(0x1199, 0x9056)}, /* Sierra Wireless Modem */ |
143 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 2)}, /* Sierra Wireless EM7700 NMEA */ | 152 | {DEVICE_SWI(0x1199, 0x9060)}, /* Sierra Wireless Modem */ |
144 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901c, 3)}, /* Sierra Wireless EM7700 Modem */ | 153 | {DEVICE_SWI(0x1199, 0x9061)}, /* Sierra Wireless Modem */ |
145 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901f, 0)}, /* Sierra Wireless EM7355 Device Management */ | 154 | {DEVICE_SWI(0x413c, 0x81a2)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card */ |
146 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901f, 2)}, /* Sierra Wireless EM7355 NMEA */ | 155 | {DEVICE_SWI(0x413c, 0x81a3)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card */ |
147 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x901f, 3)}, /* Sierra Wireless EM7355 Modem */ | 156 | {DEVICE_SWI(0x413c, 0x81a4)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */ |
148 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9041, 0)}, /* Sierra Wireless MC7305/MC7355 Device Management */ | 157 | {DEVICE_SWI(0x413c, 0x81a8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */ |
149 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9041, 2)}, /* Sierra Wireless MC7305/MC7355 NMEA */ | 158 | {DEVICE_SWI(0x413c, 0x81a9)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */ |
150 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9041, 3)}, /* Sierra Wireless MC7305/MC7355 Modem */ | ||
151 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 0)}, /* Netgear AirCard 340U Device Management */ | ||
152 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 2)}, /* Netgear AirCard 340U NMEA */ | ||
153 | {USB_DEVICE_INTERFACE_NUMBER(0x1199, 0x9051, 3)}, /* Netgear AirCard 340U Modem */ | ||
154 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a2, 0)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card Device Management */ | ||
155 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a2, 2)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card NMEA */ | ||
156 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a2, 3)}, /* Dell Wireless 5806 Gobi(TM) 4G LTE Mobile Broadband Card Modem */ | ||
157 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a3, 0)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card Device Management */ | ||
158 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a3, 2)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card NMEA */ | ||
159 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a3, 3)}, /* Dell Wireless 5570 HSPA+ (42Mbps) Mobile Broadband Card Modem */ | ||
160 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a4, 0)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card Device Management */ | ||
161 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a4, 2)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card NMEA */ | ||
162 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a4, 3)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card Modem */ | ||
163 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a8, 0)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card Device Management */ | ||
164 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a8, 2)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card NMEA */ | ||
165 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a8, 3)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card Modem */ | ||
166 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a9, 0)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card Device Management */ | ||
167 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a9, 2)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card NMEA */ | ||
168 | {USB_DEVICE_INTERFACE_NUMBER(0x413c, 0x81a9, 3)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card Modem */ | ||
169 | 159 | ||
170 | { } /* Terminating entry */ | 160 | { } /* Terminating entry */ |
171 | }; | 161 | }; |
@@ -178,11 +168,8 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) | |||
178 | int retval = -ENODEV; | 168 | int retval = -ENODEV; |
179 | __u8 nintf; | 169 | __u8 nintf; |
180 | __u8 ifnum; | 170 | __u8 ifnum; |
181 | bool is_gobi1k = id->driver_info ? true : false; | ||
182 | int altsetting = -1; | 171 | int altsetting = -1; |
183 | 172 | ||
184 | dev_dbg(dev, "Is Gobi 1000 = %d\n", is_gobi1k); | ||
185 | |||
186 | nintf = serial->dev->actconfig->desc.bNumInterfaces; | 173 | nintf = serial->dev->actconfig->desc.bNumInterfaces; |
187 | dev_dbg(dev, "Num Interfaces = %d\n", nintf); | 174 | dev_dbg(dev, "Num Interfaces = %d\n", nintf); |
188 | ifnum = intf->desc.bInterfaceNumber; | 175 | ifnum = intf->desc.bInterfaceNumber; |
@@ -210,32 +197,29 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) | |||
210 | 197 | ||
211 | } | 198 | } |
212 | 199 | ||
213 | /* allow any number of interfaces when doing direct interface match */ | ||
214 | if (id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER) { | ||
215 | dev_dbg(dev, "Generic Qualcomm serial interface found\n"); | ||
216 | altsetting = 0; | ||
217 | goto done; | ||
218 | } | ||
219 | |||
220 | if (nintf < 3 || nintf > 4) { | ||
221 | dev_err(dev, "unknown number of interfaces: %d\n", nintf); | ||
222 | goto done; | ||
223 | } | ||
224 | |||
225 | /* default to enabling interface */ | 200 | /* default to enabling interface */ |
226 | altsetting = 0; | 201 | altsetting = 0; |
227 | 202 | ||
228 | /* Composite mode; don't bind to the QMI/net interface as that | 203 | /* |
204 | * Composite mode; don't bind to the QMI/net interface as that | ||
229 | * gets handled by other drivers. | 205 | * gets handled by other drivers. |
230 | */ | 206 | */ |
231 | 207 | ||
232 | if (is_gobi1k) { | 208 | switch (id->driver_info) { |
233 | /* Gobi 1K USB layout: | 209 | case QCSERIAL_G1K: |
210 | /* | ||
211 | * Gobi 1K USB layout: | ||
234 | * 0: DM/DIAG (use libqcdm from ModemManager for communication) | 212 | * 0: DM/DIAG (use libqcdm from ModemManager for communication) |
235 | * 1: serial port (doesn't respond) | 213 | * 1: serial port (doesn't respond) |
236 | * 2: AT-capable modem port | 214 | * 2: AT-capable modem port |
237 | * 3: QMI/net | 215 | * 3: QMI/net |
238 | */ | 216 | */ |
217 | if (nintf < 3 || nintf > 4) { | ||
218 | dev_err(dev, "unknown number of interfaces: %d\n", nintf); | ||
219 | altsetting = -1; | ||
220 | goto done; | ||
221 | } | ||
222 | |||
239 | if (ifnum == 0) { | 223 | if (ifnum == 0) { |
240 | dev_dbg(dev, "Gobi 1K DM/DIAG interface found\n"); | 224 | dev_dbg(dev, "Gobi 1K DM/DIAG interface found\n"); |
241 | altsetting = 1; | 225 | altsetting = 1; |
@@ -243,13 +227,21 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) | |||
243 | dev_dbg(dev, "Modem port found\n"); | 227 | dev_dbg(dev, "Modem port found\n"); |
244 | else | 228 | else |
245 | altsetting = -1; | 229 | altsetting = -1; |
246 | } else { | 230 | break; |
247 | /* Gobi 2K+ USB layout: | 231 | case QCSERIAL_G2K: |
232 | /* | ||
233 | * Gobi 2K+ USB layout: | ||
248 | * 0: QMI/net | 234 | * 0: QMI/net |
249 | * 1: DM/DIAG (use libqcdm from ModemManager for communication) | 235 | * 1: DM/DIAG (use libqcdm from ModemManager for communication) |
250 | * 2: AT-capable modem port | 236 | * 2: AT-capable modem port |
251 | * 3: NMEA | 237 | * 3: NMEA |
252 | */ | 238 | */ |
239 | if (nintf < 3 || nintf > 4) { | ||
240 | dev_err(dev, "unknown number of interfaces: %d\n", nintf); | ||
241 | altsetting = -1; | ||
242 | goto done; | ||
243 | } | ||
244 | |||
253 | switch (ifnum) { | 245 | switch (ifnum) { |
254 | case 0: | 246 | case 0: |
255 | /* Don't claim the QMI/net interface */ | 247 | /* Don't claim the QMI/net interface */ |
@@ -270,6 +262,35 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) | |||
270 | dev_dbg(dev, "Gobi 2K+ NMEA GPS interface found\n"); | 262 | dev_dbg(dev, "Gobi 2K+ NMEA GPS interface found\n"); |
271 | break; | 263 | break; |
272 | } | 264 | } |
265 | break; | ||
266 | case QCSERIAL_SWI: | ||
267 | /* | ||
268 | * Sierra Wireless layout: | ||
269 | * 0: DM/DIAG (use libqcdm from ModemManager for communication) | ||
270 | * 2: NMEA | ||
271 | * 3: AT-capable modem port | ||
272 | * 8: QMI/net | ||
273 | */ | ||
274 | switch (ifnum) { | ||
275 | case 0: | ||
276 | dev_dbg(dev, "DM/DIAG interface found\n"); | ||
277 | break; | ||
278 | case 2: | ||
279 | dev_dbg(dev, "NMEA GPS interface found\n"); | ||
280 | break; | ||
281 | case 3: | ||
282 | dev_dbg(dev, "Modem port found\n"); | ||
283 | break; | ||
284 | default: | ||
285 | /* don't claim any unsupported interface */ | ||
286 | altsetting = -1; | ||
287 | break; | ||
288 | } | ||
289 | break; | ||
290 | default: | ||
291 | dev_err(dev, "unsupported device layout type: %lu\n", | ||
292 | id->driver_info); | ||
293 | break; | ||
273 | } | 294 | } |
274 | 295 | ||
275 | done: | 296 | done: |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 6b192e602ce0..6f7f01eb556a 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -58,6 +58,7 @@ struct sierra_intf_private { | |||
58 | spinlock_t susp_lock; | 58 | spinlock_t susp_lock; |
59 | unsigned int suspended:1; | 59 | unsigned int suspended:1; |
60 | int in_flight; | 60 | int in_flight; |
61 | unsigned int open_ports; | ||
61 | }; | 62 | }; |
62 | 63 | ||
63 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) | 64 | static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) |
@@ -315,7 +316,6 @@ struct sierra_port_private { | |||
315 | int dsr_state; | 316 | int dsr_state; |
316 | int dcd_state; | 317 | int dcd_state; |
317 | int ri_state; | 318 | int ri_state; |
318 | unsigned int opened:1; | ||
319 | }; | 319 | }; |
320 | 320 | ||
321 | static int sierra_send_setup(struct usb_serial_port *port) | 321 | static int sierra_send_setup(struct usb_serial_port *port) |
@@ -364,20 +364,13 @@ static int sierra_send_setup(struct usb_serial_port *port) | |||
364 | if (retval < 0) | 364 | if (retval < 0) |
365 | return retval; | 365 | return retval; |
366 | 366 | ||
367 | retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 367 | retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
368 | 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); | 368 | 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); |
369 | usb_autopm_put_interface(serial->interface); | 369 | usb_autopm_put_interface(serial->interface); |
370 | 370 | ||
371 | return retval; | 371 | return retval; |
372 | } | 372 | } |
373 | 373 | ||
374 | static void sierra_set_termios(struct tty_struct *tty, | ||
375 | struct usb_serial_port *port, struct ktermios *old_termios) | ||
376 | { | ||
377 | tty_termios_copy_hw(&tty->termios, old_termios); | ||
378 | sierra_send_setup(port); | ||
379 | } | ||
380 | |||
381 | static int sierra_tiocmget(struct tty_struct *tty) | 374 | static int sierra_tiocmget(struct tty_struct *tty) |
382 | { | 375 | { |
383 | struct usb_serial_port *port = tty->driver_data; | 376 | struct usb_serial_port *port = tty->driver_data; |
@@ -418,9 +411,7 @@ static int sierra_tiocmset(struct tty_struct *tty, | |||
418 | 411 | ||
419 | static void sierra_release_urb(struct urb *urb) | 412 | static void sierra_release_urb(struct urb *urb) |
420 | { | 413 | { |
421 | struct usb_serial_port *port; | ||
422 | if (urb) { | 414 | if (urb) { |
423 | port = urb->context; | ||
424 | kfree(urb->transfer_buffer); | 415 | kfree(urb->transfer_buffer); |
425 | usb_free_urb(urb); | 416 | usb_free_urb(urb); |
426 | } | 417 | } |
@@ -433,7 +424,7 @@ static void sierra_outdat_callback(struct urb *urb) | |||
433 | struct sierra_intf_private *intfdata; | 424 | struct sierra_intf_private *intfdata; |
434 | int status = urb->status; | 425 | int status = urb->status; |
435 | 426 | ||
436 | intfdata = port->serial->private; | 427 | intfdata = usb_get_serial_data(port->serial); |
437 | 428 | ||
438 | /* free up the transfer buffer, as usb_free_urb() does not do this */ | 429 | /* free up the transfer buffer, as usb_free_urb() does not do this */ |
439 | kfree(urb->transfer_buffer); | 430 | kfree(urb->transfer_buffer); |
@@ -470,7 +461,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
470 | return 0; | 461 | return 0; |
471 | 462 | ||
472 | portdata = usb_get_serial_port_data(port); | 463 | portdata = usb_get_serial_port_data(port); |
473 | intfdata = serial->private; | 464 | intfdata = usb_get_serial_data(serial); |
474 | 465 | ||
475 | dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); | 466 | dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); |
476 | spin_lock_irqsave(&portdata->lock, flags); | 467 | spin_lock_irqsave(&portdata->lock, flags); |
@@ -674,6 +665,23 @@ static int sierra_write_room(struct tty_struct *tty) | |||
674 | return 2048; | 665 | return 2048; |
675 | } | 666 | } |
676 | 667 | ||
668 | static int sierra_chars_in_buffer(struct tty_struct *tty) | ||
669 | { | ||
670 | struct usb_serial_port *port = tty->driver_data; | ||
671 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | ||
672 | unsigned long flags; | ||
673 | int chars; | ||
674 | |||
675 | /* NOTE: This overcounts somewhat. */ | ||
676 | spin_lock_irqsave(&portdata->lock, flags); | ||
677 | chars = portdata->outstanding_urbs * MAX_TRANSFER; | ||
678 | spin_unlock_irqrestore(&portdata->lock, flags); | ||
679 | |||
680 | dev_dbg(&port->dev, "%s - %d\n", __func__, chars); | ||
681 | |||
682 | return chars; | ||
683 | } | ||
684 | |||
677 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) | 685 | static void sierra_stop_rx_urbs(struct usb_serial_port *port) |
678 | { | 686 | { |
679 | int i; | 687 | int i; |
@@ -729,9 +737,6 @@ static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, | |||
729 | struct urb *urb; | 737 | struct urb *urb; |
730 | u8 *buf; | 738 | u8 *buf; |
731 | 739 | ||
732 | if (endpoint == -1) | ||
733 | return NULL; | ||
734 | |||
735 | urb = usb_alloc_urb(0, mem_flags); | 740 | urb = usb_alloc_urb(0, mem_flags); |
736 | if (!urb) | 741 | if (!urb) |
737 | return NULL; | 742 | return NULL; |
@@ -758,40 +763,48 @@ static void sierra_close(struct usb_serial_port *port) | |||
758 | int i; | 763 | int i; |
759 | struct usb_serial *serial = port->serial; | 764 | struct usb_serial *serial = port->serial; |
760 | struct sierra_port_private *portdata; | 765 | struct sierra_port_private *portdata; |
761 | struct sierra_intf_private *intfdata = port->serial->private; | 766 | struct sierra_intf_private *intfdata = usb_get_serial_data(serial); |
767 | struct urb *urb; | ||
762 | 768 | ||
763 | portdata = usb_get_serial_port_data(port); | 769 | portdata = usb_get_serial_port_data(port); |
764 | 770 | ||
765 | portdata->rts_state = 0; | 771 | /* |
766 | portdata->dtr_state = 0; | 772 | * Need to take susp_lock to make sure port is not already being |
767 | 773 | * resumed, but no need to hold it due to ASYNC_INITIALIZED. | |
768 | mutex_lock(&serial->disc_mutex); | 774 | */ |
769 | if (!serial->disconnected) { | 775 | spin_lock_irq(&intfdata->susp_lock); |
776 | if (--intfdata->open_ports == 0) | ||
770 | serial->interface->needs_remote_wakeup = 0; | 777 | serial->interface->needs_remote_wakeup = 0; |
771 | /* odd error handling due to pm counters */ | 778 | spin_unlock_irq(&intfdata->susp_lock); |
772 | if (!usb_autopm_get_interface(serial->interface)) | ||
773 | sierra_send_setup(port); | ||
774 | else | ||
775 | usb_autopm_get_interface_no_resume(serial->interface); | ||
776 | 779 | ||
780 | for (;;) { | ||
781 | urb = usb_get_from_anchor(&portdata->delayed); | ||
782 | if (!urb) | ||
783 | break; | ||
784 | kfree(urb->transfer_buffer); | ||
785 | usb_free_urb(urb); | ||
786 | usb_autopm_put_interface_async(serial->interface); | ||
787 | spin_lock(&portdata->lock); | ||
788 | portdata->outstanding_urbs--; | ||
789 | spin_unlock(&portdata->lock); | ||
777 | } | 790 | } |
778 | mutex_unlock(&serial->disc_mutex); | ||
779 | spin_lock_irq(&intfdata->susp_lock); | ||
780 | portdata->opened = 0; | ||
781 | spin_unlock_irq(&intfdata->susp_lock); | ||
782 | 791 | ||
783 | sierra_stop_rx_urbs(port); | 792 | sierra_stop_rx_urbs(port); |
793 | usb_kill_anchored_urbs(&portdata->active); | ||
794 | |||
784 | for (i = 0; i < portdata->num_in_urbs; i++) { | 795 | for (i = 0; i < portdata->num_in_urbs; i++) { |
785 | sierra_release_urb(portdata->in_urbs[i]); | 796 | sierra_release_urb(portdata->in_urbs[i]); |
786 | portdata->in_urbs[i] = NULL; | 797 | portdata->in_urbs[i] = NULL; |
787 | } | 798 | } |
799 | |||
800 | usb_autopm_get_interface_no_resume(serial->interface); | ||
788 | } | 801 | } |
789 | 802 | ||
790 | static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) | 803 | static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) |
791 | { | 804 | { |
792 | struct sierra_port_private *portdata; | 805 | struct sierra_port_private *portdata; |
793 | struct usb_serial *serial = port->serial; | 806 | struct usb_serial *serial = port->serial; |
794 | struct sierra_intf_private *intfdata = serial->private; | 807 | struct sierra_intf_private *intfdata = usb_get_serial_data(serial); |
795 | int i; | 808 | int i; |
796 | int err; | 809 | int err; |
797 | int endpoint; | 810 | int endpoint; |
@@ -799,11 +812,6 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
799 | 812 | ||
800 | portdata = usb_get_serial_port_data(port); | 813 | portdata = usb_get_serial_port_data(port); |
801 | 814 | ||
802 | /* Set some sane defaults */ | ||
803 | portdata->rts_state = 1; | ||
804 | portdata->dtr_state = 1; | ||
805 | |||
806 | |||
807 | endpoint = port->bulk_in_endpointAddress; | 815 | endpoint = port->bulk_in_endpointAddress; |
808 | for (i = 0; i < portdata->num_in_urbs; i++) { | 816 | for (i = 0; i < portdata->num_in_urbs; i++) { |
809 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, | 817 | urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, |
@@ -816,23 +824,26 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
816 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); | 824 | usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN); |
817 | 825 | ||
818 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); | 826 | err = sierra_submit_rx_urbs(port, GFP_KERNEL); |
819 | if (err) { | 827 | if (err) |
820 | /* get rid of everything as in close */ | 828 | goto err_submit; |
821 | sierra_close(port); | ||
822 | /* restore balance for autopm */ | ||
823 | if (!serial->disconnected) | ||
824 | usb_autopm_put_interface(serial->interface); | ||
825 | return err; | ||
826 | } | ||
827 | sierra_send_setup(port); | ||
828 | 829 | ||
829 | serial->interface->needs_remote_wakeup = 1; | ||
830 | spin_lock_irq(&intfdata->susp_lock); | 830 | spin_lock_irq(&intfdata->susp_lock); |
831 | portdata->opened = 1; | 831 | if (++intfdata->open_ports == 1) |
832 | serial->interface->needs_remote_wakeup = 1; | ||
832 | spin_unlock_irq(&intfdata->susp_lock); | 833 | spin_unlock_irq(&intfdata->susp_lock); |
833 | usb_autopm_put_interface(serial->interface); | 834 | usb_autopm_put_interface(serial->interface); |
834 | 835 | ||
835 | return 0; | 836 | return 0; |
837 | |||
838 | err_submit: | ||
839 | sierra_stop_rx_urbs(port); | ||
840 | |||
841 | for (i = 0; i < portdata->num_in_urbs; i++) { | ||
842 | sierra_release_urb(portdata->in_urbs[i]); | ||
843 | portdata->in_urbs[i] = NULL; | ||
844 | } | ||
845 | |||
846 | return err; | ||
836 | } | 847 | } |
837 | 848 | ||
838 | 849 | ||
@@ -928,6 +939,7 @@ static int sierra_port_remove(struct usb_serial_port *port) | |||
928 | struct sierra_port_private *portdata; | 939 | struct sierra_port_private *portdata; |
929 | 940 | ||
930 | portdata = usb_get_serial_port_data(port); | 941 | portdata = usb_get_serial_port_data(port); |
942 | usb_set_serial_port_data(port, NULL); | ||
931 | kfree(portdata); | 943 | kfree(portdata); |
932 | 944 | ||
933 | return 0; | 945 | return 0; |
@@ -944,6 +956,8 @@ static void stop_read_write_urbs(struct usb_serial *serial) | |||
944 | for (i = 0; i < serial->num_ports; ++i) { | 956 | for (i = 0; i < serial->num_ports; ++i) { |
945 | port = serial->port[i]; | 957 | port = serial->port[i]; |
946 | portdata = usb_get_serial_port_data(port); | 958 | portdata = usb_get_serial_port_data(port); |
959 | if (!portdata) | ||
960 | continue; | ||
947 | sierra_stop_rx_urbs(port); | 961 | sierra_stop_rx_urbs(port); |
948 | usb_kill_anchored_urbs(&portdata->active); | 962 | usb_kill_anchored_urbs(&portdata->active); |
949 | } | 963 | } |
@@ -951,58 +965,84 @@ static void stop_read_write_urbs(struct usb_serial *serial) | |||
951 | 965 | ||
952 | static int sierra_suspend(struct usb_serial *serial, pm_message_t message) | 966 | static int sierra_suspend(struct usb_serial *serial, pm_message_t message) |
953 | { | 967 | { |
954 | struct sierra_intf_private *intfdata; | 968 | struct sierra_intf_private *intfdata = usb_get_serial_data(serial); |
955 | int b; | ||
956 | 969 | ||
970 | spin_lock_irq(&intfdata->susp_lock); | ||
957 | if (PMSG_IS_AUTO(message)) { | 971 | if (PMSG_IS_AUTO(message)) { |
958 | intfdata = serial->private; | 972 | if (intfdata->in_flight) { |
959 | spin_lock_irq(&intfdata->susp_lock); | ||
960 | b = intfdata->in_flight; | ||
961 | |||
962 | if (b) { | ||
963 | spin_unlock_irq(&intfdata->susp_lock); | 973 | spin_unlock_irq(&intfdata->susp_lock); |
964 | return -EBUSY; | 974 | return -EBUSY; |
965 | } else { | ||
966 | intfdata->suspended = 1; | ||
967 | spin_unlock_irq(&intfdata->susp_lock); | ||
968 | } | 975 | } |
969 | } | 976 | } |
977 | intfdata->suspended = 1; | ||
978 | spin_unlock_irq(&intfdata->susp_lock); | ||
979 | |||
970 | stop_read_write_urbs(serial); | 980 | stop_read_write_urbs(serial); |
971 | 981 | ||
972 | return 0; | 982 | return 0; |
973 | } | 983 | } |
974 | 984 | ||
985 | /* Caller must hold susp_lock. */ | ||
986 | static int sierra_submit_delayed_urbs(struct usb_serial_port *port) | ||
987 | { | ||
988 | struct sierra_port_private *portdata = usb_get_serial_port_data(port); | ||
989 | struct sierra_intf_private *intfdata; | ||
990 | struct urb *urb; | ||
991 | int ec = 0; | ||
992 | int err; | ||
993 | |||
994 | intfdata = usb_get_serial_data(port->serial); | ||
995 | |||
996 | for (;;) { | ||
997 | urb = usb_get_from_anchor(&portdata->delayed); | ||
998 | if (!urb) | ||
999 | break; | ||
1000 | |||
1001 | usb_anchor_urb(urb, &portdata->active); | ||
1002 | intfdata->in_flight++; | ||
1003 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
1004 | if (err) { | ||
1005 | dev_err(&port->dev, "%s - submit urb failed: %d", | ||
1006 | __func__, err); | ||
1007 | ec++; | ||
1008 | intfdata->in_flight--; | ||
1009 | usb_unanchor_urb(urb); | ||
1010 | kfree(urb->transfer_buffer); | ||
1011 | usb_free_urb(urb); | ||
1012 | |||
1013 | spin_lock(&portdata->lock); | ||
1014 | portdata->outstanding_urbs--; | ||
1015 | spin_unlock(&portdata->lock); | ||
1016 | } | ||
1017 | } | ||
1018 | |||
1019 | if (ec) | ||
1020 | return -EIO; | ||
1021 | |||
1022 | return 0; | ||
1023 | } | ||
1024 | |||
975 | static int sierra_resume(struct usb_serial *serial) | 1025 | static int sierra_resume(struct usb_serial *serial) |
976 | { | 1026 | { |
977 | struct usb_serial_port *port; | 1027 | struct usb_serial_port *port; |
978 | struct sierra_intf_private *intfdata = serial->private; | 1028 | struct sierra_intf_private *intfdata = usb_get_serial_data(serial); |
979 | struct sierra_port_private *portdata; | ||
980 | struct urb *urb; | ||
981 | int ec = 0; | 1029 | int ec = 0; |
982 | int i, err; | 1030 | int i, err; |
983 | 1031 | ||
984 | spin_lock_irq(&intfdata->susp_lock); | 1032 | spin_lock_irq(&intfdata->susp_lock); |
985 | for (i = 0; i < serial->num_ports; i++) { | 1033 | for (i = 0; i < serial->num_ports; i++) { |
986 | port = serial->port[i]; | 1034 | port = serial->port[i]; |
987 | portdata = usb_get_serial_port_data(port); | ||
988 | 1035 | ||
989 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { | 1036 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
990 | usb_anchor_urb(urb, &portdata->active); | 1037 | continue; |
991 | intfdata->in_flight++; | ||
992 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
993 | if (err < 0) { | ||
994 | intfdata->in_flight--; | ||
995 | usb_unanchor_urb(urb); | ||
996 | usb_scuttle_anchored_urbs(&portdata->delayed); | ||
997 | break; | ||
998 | } | ||
999 | } | ||
1000 | 1038 | ||
1001 | if (portdata->opened) { | 1039 | err = sierra_submit_delayed_urbs(port); |
1002 | err = sierra_submit_rx_urbs(port, GFP_ATOMIC); | 1040 | if (err) |
1003 | if (err) | 1041 | ec++; |
1004 | ec++; | 1042 | |
1005 | } | 1043 | err = sierra_submit_rx_urbs(port, GFP_ATOMIC); |
1044 | if (err) | ||
1045 | ec++; | ||
1006 | } | 1046 | } |
1007 | intfdata->suspended = 0; | 1047 | intfdata->suspended = 0; |
1008 | spin_unlock_irq(&intfdata->susp_lock); | 1048 | spin_unlock_irq(&intfdata->susp_lock); |
@@ -1029,7 +1069,7 @@ static struct usb_serial_driver sierra_device = { | |||
1029 | .dtr_rts = sierra_dtr_rts, | 1069 | .dtr_rts = sierra_dtr_rts, |
1030 | .write = sierra_write, | 1070 | .write = sierra_write, |
1031 | .write_room = sierra_write_room, | 1071 | .write_room = sierra_write_room, |
1032 | .set_termios = sierra_set_termios, | 1072 | .chars_in_buffer = sierra_chars_in_buffer, |
1033 | .tiocmget = sierra_tiocmget, | 1073 | .tiocmget = sierra_tiocmget, |
1034 | .tiocmset = sierra_tiocmset, | 1074 | .tiocmset = sierra_tiocmset, |
1035 | .attach = sierra_startup, | 1075 | .attach = sierra_startup, |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 6d40d56378d7..02de3110fe94 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -1060,6 +1060,7 @@ static void usb_serial_disconnect(struct usb_interface *interface) | |||
1060 | struct usb_serial *serial = usb_get_intfdata(interface); | 1060 | struct usb_serial *serial = usb_get_intfdata(interface); |
1061 | struct device *dev = &interface->dev; | 1061 | struct device *dev = &interface->dev; |
1062 | struct usb_serial_port *port; | 1062 | struct usb_serial_port *port; |
1063 | struct tty_struct *tty; | ||
1063 | 1064 | ||
1064 | usb_serial_console_disconnect(serial); | 1065 | usb_serial_console_disconnect(serial); |
1065 | 1066 | ||
@@ -1070,18 +1071,16 @@ static void usb_serial_disconnect(struct usb_interface *interface) | |||
1070 | 1071 | ||
1071 | for (i = 0; i < serial->num_ports; ++i) { | 1072 | for (i = 0; i < serial->num_ports; ++i) { |
1072 | port = serial->port[i]; | 1073 | port = serial->port[i]; |
1073 | if (port) { | 1074 | tty = tty_port_tty_get(&port->port); |
1074 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 1075 | if (tty) { |
1075 | if (tty) { | 1076 | tty_vhangup(tty); |
1076 | tty_vhangup(tty); | 1077 | tty_kref_put(tty); |
1077 | tty_kref_put(tty); | ||
1078 | } | ||
1079 | usb_serial_port_poison_urbs(port); | ||
1080 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
1081 | cancel_work_sync(&port->work); | ||
1082 | if (device_is_registered(&port->dev)) | ||
1083 | device_del(&port->dev); | ||
1084 | } | 1078 | } |
1079 | usb_serial_port_poison_urbs(port); | ||
1080 | wake_up_interruptible(&port->port.delta_msr_wait); | ||
1081 | cancel_work_sync(&port->work); | ||
1082 | if (device_is_registered(&port->dev)) | ||
1083 | device_del(&port->dev); | ||
1085 | } | 1084 | } |
1086 | if (serial->type->disconnect) | 1085 | if (serial->type->disconnect) |
1087 | serial->type->disconnect(serial); | 1086 | serial->type->disconnect(serial); |
@@ -1094,7 +1093,6 @@ static void usb_serial_disconnect(struct usb_interface *interface) | |||
1094 | int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) | 1093 | int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) |
1095 | { | 1094 | { |
1096 | struct usb_serial *serial = usb_get_intfdata(intf); | 1095 | struct usb_serial *serial = usb_get_intfdata(intf); |
1097 | struct usb_serial_port *port; | ||
1098 | int i, r = 0; | 1096 | int i, r = 0; |
1099 | 1097 | ||
1100 | serial->suspending = 1; | 1098 | serial->suspending = 1; |
@@ -1112,12 +1110,8 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) | |||
1112 | } | 1110 | } |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | for (i = 0; i < serial->num_ports; ++i) { | 1113 | for (i = 0; i < serial->num_ports; ++i) |
1116 | port = serial->port[i]; | 1114 | usb_serial_port_poison_urbs(serial->port[i]); |
1117 | if (port) | ||
1118 | usb_serial_port_poison_urbs(port); | ||
1119 | } | ||
1120 | |||
1121 | err_out: | 1115 | err_out: |
1122 | return r; | 1116 | return r; |
1123 | } | 1117 | } |
@@ -1125,14 +1119,10 @@ EXPORT_SYMBOL(usb_serial_suspend); | |||
1125 | 1119 | ||
1126 | static void usb_serial_unpoison_port_urbs(struct usb_serial *serial) | 1120 | static void usb_serial_unpoison_port_urbs(struct usb_serial *serial) |
1127 | { | 1121 | { |
1128 | struct usb_serial_port *port; | ||
1129 | int i; | 1122 | int i; |
1130 | 1123 | ||
1131 | for (i = 0; i < serial->num_ports; ++i) { | 1124 | for (i = 0; i < serial->num_ports; ++i) |
1132 | port = serial->port[i]; | 1125 | usb_serial_port_unpoison_urbs(serial->port[i]); |
1133 | if (port) | ||
1134 | usb_serial_port_unpoison_urbs(port); | ||
1135 | } | ||
1136 | } | 1126 | } |
1137 | 1127 | ||
1138 | int usb_serial_resume(struct usb_interface *intf) | 1128 | int usb_serial_resume(struct usb_interface *intf) |
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h index 684739b8efd0..f22dff58b587 100644 --- a/drivers/usb/serial/usb-wwan.h +++ b/drivers/usb/serial/usb-wwan.h | |||
@@ -11,15 +11,11 @@ extern void usb_wwan_close(struct usb_serial_port *port); | |||
11 | extern int usb_wwan_port_probe(struct usb_serial_port *port); | 11 | extern int usb_wwan_port_probe(struct usb_serial_port *port); |
12 | extern int usb_wwan_port_remove(struct usb_serial_port *port); | 12 | extern int usb_wwan_port_remove(struct usb_serial_port *port); |
13 | extern int usb_wwan_write_room(struct tty_struct *tty); | 13 | extern int usb_wwan_write_room(struct tty_struct *tty); |
14 | extern void usb_wwan_set_termios(struct tty_struct *tty, | ||
15 | struct usb_serial_port *port, | ||
16 | struct ktermios *old); | ||
17 | extern int usb_wwan_tiocmget(struct tty_struct *tty); | 14 | extern int usb_wwan_tiocmget(struct tty_struct *tty); |
18 | extern int usb_wwan_tiocmset(struct tty_struct *tty, | 15 | extern int usb_wwan_tiocmset(struct tty_struct *tty, |
19 | unsigned int set, unsigned int clear); | 16 | unsigned int set, unsigned int clear); |
20 | extern int usb_wwan_ioctl(struct tty_struct *tty, | 17 | extern int usb_wwan_ioctl(struct tty_struct *tty, |
21 | unsigned int cmd, unsigned long arg); | 18 | unsigned int cmd, unsigned long arg); |
22 | extern int usb_wwan_send_setup(struct usb_serial_port *port); | ||
23 | extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | 19 | extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, |
24 | const unsigned char *buf, int count); | 20 | const unsigned char *buf, int count); |
25 | extern int usb_wwan_chars_in_buffer(struct tty_struct *tty); | 21 | extern int usb_wwan_chars_in_buffer(struct tty_struct *tty); |
@@ -39,6 +35,7 @@ struct usb_wwan_intf_private { | |||
39 | spinlock_t susp_lock; | 35 | spinlock_t susp_lock; |
40 | unsigned int suspended:1; | 36 | unsigned int suspended:1; |
41 | int in_flight; | 37 | int in_flight; |
38 | unsigned int open_ports; | ||
42 | int (*send_setup) (struct usb_serial_port *port); | 39 | int (*send_setup) (struct usb_serial_port *port); |
43 | void *private; | 40 | void *private; |
44 | }; | 41 | }; |
@@ -51,7 +48,6 @@ struct usb_wwan_port_private { | |||
51 | struct urb *out_urbs[N_OUT_URB]; | 48 | struct urb *out_urbs[N_OUT_URB]; |
52 | u8 *out_buffer[N_OUT_URB]; | 49 | u8 *out_buffer[N_OUT_URB]; |
53 | unsigned long out_busy; /* Bit vector of URBs in use */ | 50 | unsigned long out_busy; /* Bit vector of URBs in use */ |
54 | int opened; | ||
55 | struct usb_anchor delayed; | 51 | struct usb_anchor delayed; |
56 | 52 | ||
57 | /* Settings for the port */ | 53 | /* Settings for the port */ |
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index b078440e822f..2f805cb386a5 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c | |||
@@ -41,7 +41,7 @@ void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) | |||
41 | struct usb_wwan_port_private *portdata; | 41 | struct usb_wwan_port_private *portdata; |
42 | struct usb_wwan_intf_private *intfdata; | 42 | struct usb_wwan_intf_private *intfdata; |
43 | 43 | ||
44 | intfdata = port->serial->private; | 44 | intfdata = usb_get_serial_data(port->serial); |
45 | 45 | ||
46 | if (!intfdata->send_setup) | 46 | if (!intfdata->send_setup) |
47 | return; | 47 | return; |
@@ -55,20 +55,6 @@ void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) | |||
55 | } | 55 | } |
56 | EXPORT_SYMBOL(usb_wwan_dtr_rts); | 56 | EXPORT_SYMBOL(usb_wwan_dtr_rts); |
57 | 57 | ||
58 | void usb_wwan_set_termios(struct tty_struct *tty, | ||
59 | struct usb_serial_port *port, | ||
60 | struct ktermios *old_termios) | ||
61 | { | ||
62 | struct usb_wwan_intf_private *intfdata = port->serial->private; | ||
63 | |||
64 | /* Doesn't support option setting */ | ||
65 | tty_termios_copy_hw(&tty->termios, old_termios); | ||
66 | |||
67 | if (intfdata->send_setup) | ||
68 | intfdata->send_setup(port); | ||
69 | } | ||
70 | EXPORT_SYMBOL(usb_wwan_set_termios); | ||
71 | |||
72 | int usb_wwan_tiocmget(struct tty_struct *tty) | 58 | int usb_wwan_tiocmget(struct tty_struct *tty) |
73 | { | 59 | { |
74 | struct usb_serial_port *port = tty->driver_data; | 60 | struct usb_serial_port *port = tty->driver_data; |
@@ -96,7 +82,7 @@ int usb_wwan_tiocmset(struct tty_struct *tty, | |||
96 | struct usb_wwan_intf_private *intfdata; | 82 | struct usb_wwan_intf_private *intfdata; |
97 | 83 | ||
98 | portdata = usb_get_serial_port_data(port); | 84 | portdata = usb_get_serial_port_data(port); |
99 | intfdata = port->serial->private; | 85 | intfdata = usb_get_serial_data(port->serial); |
100 | 86 | ||
101 | if (!intfdata->send_setup) | 87 | if (!intfdata->send_setup) |
102 | return -EINVAL; | 88 | return -EINVAL; |
@@ -192,7 +178,6 @@ int usb_wwan_ioctl(struct tty_struct *tty, | |||
192 | } | 178 | } |
193 | EXPORT_SYMBOL(usb_wwan_ioctl); | 179 | EXPORT_SYMBOL(usb_wwan_ioctl); |
194 | 180 | ||
195 | /* Write */ | ||
196 | int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | 181 | int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, |
197 | const unsigned char *buf, int count) | 182 | const unsigned char *buf, int count) |
198 | { | 183 | { |
@@ -205,7 +190,7 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
205 | unsigned long flags; | 190 | unsigned long flags; |
206 | 191 | ||
207 | portdata = usb_get_serial_port_data(port); | 192 | portdata = usb_get_serial_port_data(port); |
208 | intfdata = port->serial->private; | 193 | intfdata = usb_get_serial_data(port->serial); |
209 | 194 | ||
210 | dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count); | 195 | dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count); |
211 | 196 | ||
@@ -228,8 +213,10 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
228 | usb_pipeendpoint(this_urb->pipe), i); | 213 | usb_pipeendpoint(this_urb->pipe), i); |
229 | 214 | ||
230 | err = usb_autopm_get_interface_async(port->serial->interface); | 215 | err = usb_autopm_get_interface_async(port->serial->interface); |
231 | if (err < 0) | 216 | if (err < 0) { |
217 | clear_bit(i, &portdata->out_busy); | ||
232 | break; | 218 | break; |
219 | } | ||
233 | 220 | ||
234 | /* send the data */ | 221 | /* send the data */ |
235 | memcpy(this_urb->transfer_buffer, buf, todo); | 222 | memcpy(this_urb->transfer_buffer, buf, todo); |
@@ -244,9 +231,9 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
244 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); | 231 | spin_unlock_irqrestore(&intfdata->susp_lock, flags); |
245 | err = usb_submit_urb(this_urb, GFP_ATOMIC); | 232 | err = usb_submit_urb(this_urb, GFP_ATOMIC); |
246 | if (err) { | 233 | if (err) { |
247 | dev_dbg(&port->dev, | 234 | dev_err(&port->dev, |
248 | "usb_submit_urb %p (write bulk) failed (%d)\n", | 235 | "%s: submit urb %d failed: %d\n", |
249 | this_urb, err); | 236 | __func__, i, err); |
250 | clear_bit(i, &portdata->out_busy); | 237 | clear_bit(i, &portdata->out_busy); |
251 | spin_lock_irqsave(&intfdata->susp_lock, flags); | 238 | spin_lock_irqsave(&intfdata->susp_lock, flags); |
252 | intfdata->in_flight--; | 239 | intfdata->in_flight--; |
@@ -314,7 +301,7 @@ static void usb_wwan_outdat_callback(struct urb *urb) | |||
314 | int i; | 301 | int i; |
315 | 302 | ||
316 | port = urb->context; | 303 | port = urb->context; |
317 | intfdata = port->serial->private; | 304 | intfdata = usb_get_serial_data(port->serial); |
318 | 305 | ||
319 | usb_serial_port_softint(port); | 306 | usb_serial_port_softint(port); |
320 | usb_autopm_put_interface_async(port->serial->interface); | 307 | usb_autopm_put_interface_async(port->serial->interface); |
@@ -325,7 +312,7 @@ static void usb_wwan_outdat_callback(struct urb *urb) | |||
325 | 312 | ||
326 | for (i = 0; i < N_OUT_URB; ++i) { | 313 | for (i = 0; i < N_OUT_URB; ++i) { |
327 | if (portdata->out_urbs[i] == urb) { | 314 | if (portdata->out_urbs[i] == urb) { |
328 | smp_mb__before_clear_bit(); | 315 | smp_mb__before_atomic(); |
329 | clear_bit(i, &portdata->out_busy); | 316 | clear_bit(i, &portdata->out_busy); |
330 | break; | 317 | break; |
331 | } | 318 | } |
@@ -384,7 +371,15 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
384 | struct urb *urb; | 371 | struct urb *urb; |
385 | 372 | ||
386 | portdata = usb_get_serial_port_data(port); | 373 | portdata = usb_get_serial_port_data(port); |
387 | intfdata = serial->private; | 374 | intfdata = usb_get_serial_data(serial); |
375 | |||
376 | if (port->interrupt_in_urb) { | ||
377 | err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | ||
378 | if (err) { | ||
379 | dev_err(&port->dev, "%s: submit int urb failed: %d\n", | ||
380 | __func__, err); | ||
381 | } | ||
382 | } | ||
388 | 383 | ||
389 | /* Start reading from the IN endpoint */ | 384 | /* Start reading from the IN endpoint */ |
390 | for (i = 0; i < N_IN_URB; i++) { | 385 | for (i = 0; i < N_IN_URB; i++) { |
@@ -393,17 +388,15 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
393 | continue; | 388 | continue; |
394 | err = usb_submit_urb(urb, GFP_KERNEL); | 389 | err = usb_submit_urb(urb, GFP_KERNEL); |
395 | if (err) { | 390 | if (err) { |
396 | dev_dbg(&port->dev, "%s: submit urb %d failed (%d) %d\n", | 391 | dev_err(&port->dev, |
397 | __func__, i, err, urb->transfer_buffer_length); | 392 | "%s: submit read urb %d failed: %d\n", |
393 | __func__, i, err); | ||
398 | } | 394 | } |
399 | } | 395 | } |
400 | 396 | ||
401 | if (intfdata->send_setup) | ||
402 | intfdata->send_setup(port); | ||
403 | |||
404 | serial->interface->needs_remote_wakeup = 1; | ||
405 | spin_lock_irq(&intfdata->susp_lock); | 397 | spin_lock_irq(&intfdata->susp_lock); |
406 | portdata->opened = 1; | 398 | if (++intfdata->open_ports == 1) |
399 | serial->interface->needs_remote_wakeup = 1; | ||
407 | spin_unlock_irq(&intfdata->susp_lock); | 400 | spin_unlock_irq(&intfdata->susp_lock); |
408 | /* this balances a get in the generic USB serial code */ | 401 | /* this balances a get in the generic USB serial code */ |
409 | usb_autopm_put_interface(serial->interface); | 402 | usb_autopm_put_interface(serial->interface); |
@@ -412,32 +405,56 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
412 | } | 405 | } |
413 | EXPORT_SYMBOL(usb_wwan_open); | 406 | EXPORT_SYMBOL(usb_wwan_open); |
414 | 407 | ||
408 | static void unbusy_queued_urb(struct urb *urb, | ||
409 | struct usb_wwan_port_private *portdata) | ||
410 | { | ||
411 | int i; | ||
412 | |||
413 | for (i = 0; i < N_OUT_URB; i++) { | ||
414 | if (urb == portdata->out_urbs[i]) { | ||
415 | clear_bit(i, &portdata->out_busy); | ||
416 | break; | ||
417 | } | ||
418 | } | ||
419 | } | ||
420 | |||
415 | void usb_wwan_close(struct usb_serial_port *port) | 421 | void usb_wwan_close(struct usb_serial_port *port) |
416 | { | 422 | { |
417 | int i; | 423 | int i; |
418 | struct usb_serial *serial = port->serial; | 424 | struct usb_serial *serial = port->serial; |
419 | struct usb_wwan_port_private *portdata; | 425 | struct usb_wwan_port_private *portdata; |
420 | struct usb_wwan_intf_private *intfdata = port->serial->private; | 426 | struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial); |
427 | struct urb *urb; | ||
421 | 428 | ||
422 | portdata = usb_get_serial_port_data(port); | 429 | portdata = usb_get_serial_port_data(port); |
423 | 430 | ||
424 | /* Stop reading/writing urbs */ | 431 | /* |
432 | * Need to take susp_lock to make sure port is not already being | ||
433 | * resumed, but no need to hold it due to ASYNC_INITIALIZED. | ||
434 | */ | ||
425 | spin_lock_irq(&intfdata->susp_lock); | 435 | spin_lock_irq(&intfdata->susp_lock); |
426 | portdata->opened = 0; | 436 | if (--intfdata->open_ports == 0) |
437 | serial->interface->needs_remote_wakeup = 0; | ||
427 | spin_unlock_irq(&intfdata->susp_lock); | 438 | spin_unlock_irq(&intfdata->susp_lock); |
428 | 439 | ||
440 | for (;;) { | ||
441 | urb = usb_get_from_anchor(&portdata->delayed); | ||
442 | if (!urb) | ||
443 | break; | ||
444 | unbusy_queued_urb(urb, portdata); | ||
445 | usb_autopm_put_interface_async(serial->interface); | ||
446 | } | ||
447 | |||
429 | for (i = 0; i < N_IN_URB; i++) | 448 | for (i = 0; i < N_IN_URB; i++) |
430 | usb_kill_urb(portdata->in_urbs[i]); | 449 | usb_kill_urb(portdata->in_urbs[i]); |
431 | for (i = 0; i < N_OUT_URB; i++) | 450 | for (i = 0; i < N_OUT_URB; i++) |
432 | usb_kill_urb(portdata->out_urbs[i]); | 451 | usb_kill_urb(portdata->out_urbs[i]); |
452 | usb_kill_urb(port->interrupt_in_urb); | ||
433 | 453 | ||
434 | /* balancing - important as an error cannot be handled*/ | ||
435 | usb_autopm_get_interface_no_resume(serial->interface); | 454 | usb_autopm_get_interface_no_resume(serial->interface); |
436 | serial->interface->needs_remote_wakeup = 0; | ||
437 | } | 455 | } |
438 | EXPORT_SYMBOL(usb_wwan_close); | 456 | EXPORT_SYMBOL(usb_wwan_close); |
439 | 457 | ||
440 | /* Helper functions used by usb_wwan_setup_urbs */ | ||
441 | static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port, | 458 | static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port, |
442 | int endpoint, | 459 | int endpoint, |
443 | int dir, void *ctx, char *buf, int len, | 460 | int dir, void *ctx, char *buf, int len, |
@@ -450,7 +467,6 @@ static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port, | |||
450 | if (!urb) | 467 | if (!urb) |
451 | return NULL; | 468 | return NULL; |
452 | 469 | ||
453 | /* Fill URB using supplied data. */ | ||
454 | usb_fill_bulk_urb(urb, serial->dev, | 470 | usb_fill_bulk_urb(urb, serial->dev, |
455 | usb_sndbulkpipe(serial->dev, endpoint) | dir, | 471 | usb_sndbulkpipe(serial->dev, endpoint) | dir, |
456 | buf, len, callback, ctx); | 472 | buf, len, callback, ctx); |
@@ -463,7 +479,6 @@ int usb_wwan_port_probe(struct usb_serial_port *port) | |||
463 | struct usb_wwan_port_private *portdata; | 479 | struct usb_wwan_port_private *portdata; |
464 | struct urb *urb; | 480 | struct urb *urb; |
465 | u8 *buffer; | 481 | u8 *buffer; |
466 | int err; | ||
467 | int i; | 482 | int i; |
468 | 483 | ||
469 | if (!port->bulk_in_size || !port->bulk_out_size) | 484 | if (!port->bulk_in_size || !port->bulk_out_size) |
@@ -503,13 +518,6 @@ int usb_wwan_port_probe(struct usb_serial_port *port) | |||
503 | 518 | ||
504 | usb_set_serial_port_data(port, portdata); | 519 | usb_set_serial_port_data(port, portdata); |
505 | 520 | ||
506 | if (port->interrupt_in_urb) { | ||
507 | err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); | ||
508 | if (err) | ||
509 | dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n", | ||
510 | __func__, err); | ||
511 | } | ||
512 | |||
513 | return 0; | 521 | return 0; |
514 | 522 | ||
515 | bail_out_error2: | 523 | bail_out_error2: |
@@ -536,32 +544,28 @@ int usb_wwan_port_remove(struct usb_serial_port *port) | |||
536 | portdata = usb_get_serial_port_data(port); | 544 | portdata = usb_get_serial_port_data(port); |
537 | usb_set_serial_port_data(port, NULL); | 545 | usb_set_serial_port_data(port, NULL); |
538 | 546 | ||
539 | /* Stop reading/writing urbs and free them */ | ||
540 | for (i = 0; i < N_IN_URB; i++) { | 547 | for (i = 0; i < N_IN_URB; i++) { |
541 | usb_kill_urb(portdata->in_urbs[i]); | ||
542 | usb_free_urb(portdata->in_urbs[i]); | 548 | usb_free_urb(portdata->in_urbs[i]); |
543 | free_page((unsigned long)portdata->in_buffer[i]); | 549 | free_page((unsigned long)portdata->in_buffer[i]); |
544 | } | 550 | } |
545 | for (i = 0; i < N_OUT_URB; i++) { | 551 | for (i = 0; i < N_OUT_URB; i++) { |
546 | usb_kill_urb(portdata->out_urbs[i]); | ||
547 | usb_free_urb(portdata->out_urbs[i]); | 552 | usb_free_urb(portdata->out_urbs[i]); |
548 | kfree(portdata->out_buffer[i]); | 553 | kfree(portdata->out_buffer[i]); |
549 | } | 554 | } |
550 | 555 | ||
551 | /* Now free port private data */ | ||
552 | kfree(portdata); | 556 | kfree(portdata); |
557 | |||
553 | return 0; | 558 | return 0; |
554 | } | 559 | } |
555 | EXPORT_SYMBOL(usb_wwan_port_remove); | 560 | EXPORT_SYMBOL(usb_wwan_port_remove); |
556 | 561 | ||
557 | #ifdef CONFIG_PM | 562 | #ifdef CONFIG_PM |
558 | static void stop_read_write_urbs(struct usb_serial *serial) | 563 | static void stop_urbs(struct usb_serial *serial) |
559 | { | 564 | { |
560 | int i, j; | 565 | int i, j; |
561 | struct usb_serial_port *port; | 566 | struct usb_serial_port *port; |
562 | struct usb_wwan_port_private *portdata; | 567 | struct usb_wwan_port_private *portdata; |
563 | 568 | ||
564 | /* Stop reading/writing urbs */ | ||
565 | for (i = 0; i < serial->num_ports; ++i) { | 569 | for (i = 0; i < serial->num_ports; ++i) { |
566 | port = serial->port[i]; | 570 | port = serial->port[i]; |
567 | portdata = usb_get_serial_port_data(port); | 571 | portdata = usb_get_serial_port_data(port); |
@@ -571,123 +575,117 @@ static void stop_read_write_urbs(struct usb_serial *serial) | |||
571 | usb_kill_urb(portdata->in_urbs[j]); | 575 | usb_kill_urb(portdata->in_urbs[j]); |
572 | for (j = 0; j < N_OUT_URB; j++) | 576 | for (j = 0; j < N_OUT_URB; j++) |
573 | usb_kill_urb(portdata->out_urbs[j]); | 577 | usb_kill_urb(portdata->out_urbs[j]); |
578 | usb_kill_urb(port->interrupt_in_urb); | ||
574 | } | 579 | } |
575 | } | 580 | } |
576 | 581 | ||
577 | int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) | 582 | int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) |
578 | { | 583 | { |
579 | struct usb_wwan_intf_private *intfdata = serial->private; | 584 | struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial); |
580 | int b; | ||
581 | 585 | ||
586 | spin_lock_irq(&intfdata->susp_lock); | ||
582 | if (PMSG_IS_AUTO(message)) { | 587 | if (PMSG_IS_AUTO(message)) { |
583 | spin_lock_irq(&intfdata->susp_lock); | 588 | if (intfdata->in_flight) { |
584 | b = intfdata->in_flight; | 589 | spin_unlock_irq(&intfdata->susp_lock); |
585 | spin_unlock_irq(&intfdata->susp_lock); | ||
586 | |||
587 | if (b) | ||
588 | return -EBUSY; | 590 | return -EBUSY; |
591 | } | ||
589 | } | 592 | } |
590 | |||
591 | spin_lock_irq(&intfdata->susp_lock); | ||
592 | intfdata->suspended = 1; | 593 | intfdata->suspended = 1; |
593 | spin_unlock_irq(&intfdata->susp_lock); | 594 | spin_unlock_irq(&intfdata->susp_lock); |
594 | stop_read_write_urbs(serial); | 595 | |
596 | stop_urbs(serial); | ||
595 | 597 | ||
596 | return 0; | 598 | return 0; |
597 | } | 599 | } |
598 | EXPORT_SYMBOL(usb_wwan_suspend); | 600 | EXPORT_SYMBOL(usb_wwan_suspend); |
599 | 601 | ||
600 | static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata) | 602 | /* Caller must hold susp_lock. */ |
603 | static int usb_wwan_submit_delayed_urbs(struct usb_serial_port *port) | ||
601 | { | 604 | { |
602 | int i; | 605 | struct usb_serial *serial = port->serial; |
603 | 606 | struct usb_wwan_intf_private *data = usb_get_serial_data(serial); | |
604 | for (i = 0; i < N_OUT_URB; i++) { | ||
605 | if (urb == portdata->out_urbs[i]) { | ||
606 | clear_bit(i, &portdata->out_busy); | ||
607 | break; | ||
608 | } | ||
609 | } | ||
610 | } | ||
611 | |||
612 | static void play_delayed(struct usb_serial_port *port) | ||
613 | { | ||
614 | struct usb_wwan_intf_private *data; | ||
615 | struct usb_wwan_port_private *portdata; | 607 | struct usb_wwan_port_private *portdata; |
616 | struct urb *urb; | 608 | struct urb *urb; |
609 | int err_count = 0; | ||
617 | int err; | 610 | int err; |
618 | 611 | ||
619 | portdata = usb_get_serial_port_data(port); | 612 | portdata = usb_get_serial_port_data(port); |
620 | data = port->serial->private; | 613 | |
621 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { | 614 | for (;;) { |
622 | err = usb_submit_urb(urb, GFP_ATOMIC); | 615 | urb = usb_get_from_anchor(&portdata->delayed); |
623 | if (!err) { | 616 | if (!urb) |
624 | data->in_flight++; | ||
625 | } else { | ||
626 | /* we have to throw away the rest */ | ||
627 | do { | ||
628 | unbusy_queued_urb(urb, portdata); | ||
629 | usb_autopm_put_interface_no_suspend(port->serial->interface); | ||
630 | } while ((urb = usb_get_from_anchor(&portdata->delayed))); | ||
631 | break; | 617 | break; |
618 | |||
619 | err = usb_submit_urb(urb, GFP_ATOMIC); | ||
620 | if (err) { | ||
621 | dev_err(&port->dev, "%s: submit urb failed: %d\n", | ||
622 | __func__, err); | ||
623 | err_count++; | ||
624 | unbusy_queued_urb(urb, portdata); | ||
625 | usb_autopm_put_interface_async(serial->interface); | ||
626 | continue; | ||
632 | } | 627 | } |
628 | data->in_flight++; | ||
633 | } | 629 | } |
630 | |||
631 | if (err_count) | ||
632 | return -EIO; | ||
633 | |||
634 | return 0; | ||
634 | } | 635 | } |
635 | 636 | ||
636 | int usb_wwan_resume(struct usb_serial *serial) | 637 | int usb_wwan_resume(struct usb_serial *serial) |
637 | { | 638 | { |
638 | int i, j; | 639 | int i, j; |
639 | struct usb_serial_port *port; | 640 | struct usb_serial_port *port; |
640 | struct usb_wwan_intf_private *intfdata = serial->private; | 641 | struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial); |
641 | struct usb_wwan_port_private *portdata; | 642 | struct usb_wwan_port_private *portdata; |
642 | struct urb *urb; | 643 | struct urb *urb; |
643 | int err = 0; | 644 | int err; |
645 | int err_count = 0; | ||
644 | 646 | ||
645 | /* get the interrupt URBs resubmitted unconditionally */ | 647 | spin_lock_irq(&intfdata->susp_lock); |
646 | for (i = 0; i < serial->num_ports; i++) { | 648 | for (i = 0; i < serial->num_ports; i++) { |
647 | port = serial->port[i]; | 649 | port = serial->port[i]; |
648 | if (!port->interrupt_in_urb) { | 650 | |
649 | dev_dbg(&port->dev, "%s: No interrupt URB for port\n", __func__); | 651 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
650 | continue; | 652 | continue; |
651 | } | ||
652 | err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); | ||
653 | dev_dbg(&port->dev, "Submitted interrupt URB for port (result %d)\n", err); | ||
654 | if (err < 0) { | ||
655 | dev_err(&port->dev, "%s: Error %d for interrupt URB\n", | ||
656 | __func__, err); | ||
657 | goto err_out; | ||
658 | } | ||
659 | } | ||
660 | 653 | ||
661 | for (i = 0; i < serial->num_ports; i++) { | ||
662 | /* walk all ports */ | ||
663 | port = serial->port[i]; | ||
664 | portdata = usb_get_serial_port_data(port); | 654 | portdata = usb_get_serial_port_data(port); |
665 | 655 | ||
666 | /* skip closed ports */ | 656 | if (port->interrupt_in_urb) { |
667 | spin_lock_irq(&intfdata->susp_lock); | 657 | err = usb_submit_urb(port->interrupt_in_urb, |
668 | if (!portdata || !portdata->opened) { | 658 | GFP_ATOMIC); |
669 | spin_unlock_irq(&intfdata->susp_lock); | 659 | if (err) { |
670 | continue; | 660 | dev_err(&port->dev, |
661 | "%s: submit int urb failed: %d\n", | ||
662 | __func__, err); | ||
663 | err_count++; | ||
664 | } | ||
671 | } | 665 | } |
672 | 666 | ||
667 | err = usb_wwan_submit_delayed_urbs(port); | ||
668 | if (err) | ||
669 | err_count++; | ||
670 | |||
673 | for (j = 0; j < N_IN_URB; j++) { | 671 | for (j = 0; j < N_IN_URB; j++) { |
674 | urb = portdata->in_urbs[j]; | 672 | urb = portdata->in_urbs[j]; |
675 | err = usb_submit_urb(urb, GFP_ATOMIC); | 673 | err = usb_submit_urb(urb, GFP_ATOMIC); |
676 | if (err < 0) { | 674 | if (err < 0) { |
677 | dev_err(&port->dev, "%s: Error %d for bulk URB %d\n", | 675 | dev_err(&port->dev, |
678 | __func__, err, i); | 676 | "%s: submit read urb %d failed: %d\n", |
679 | spin_unlock_irq(&intfdata->susp_lock); | 677 | __func__, i, err); |
680 | goto err_out; | 678 | err_count++; |
681 | } | 679 | } |
682 | } | 680 | } |
683 | play_delayed(port); | ||
684 | spin_unlock_irq(&intfdata->susp_lock); | ||
685 | } | 681 | } |
686 | spin_lock_irq(&intfdata->susp_lock); | ||
687 | intfdata->suspended = 0; | 682 | intfdata->suspended = 0; |
688 | spin_unlock_irq(&intfdata->susp_lock); | 683 | spin_unlock_irq(&intfdata->susp_lock); |
689 | err_out: | 684 | |
690 | return err; | 685 | if (err_count) |
686 | return -EIO; | ||
687 | |||
688 | return 0; | ||
691 | } | 689 | } |
692 | EXPORT_SYMBOL(usb_wwan_resume); | 690 | EXPORT_SYMBOL(usb_wwan_resume); |
693 | #endif | 691 | #endif |
diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c index 1bfc9a6cab5f..ef6efb55dc31 100644 --- a/drivers/usb/storage/ene_ub6250.c +++ b/drivers/usb/storage/ene_ub6250.c | |||
@@ -1928,11 +1928,10 @@ static int ene_load_bincode(struct us_data *us, unsigned char flag) | |||
1928 | usb_stor_dbg(us, "load firmware %s failed\n", fw_name); | 1928 | usb_stor_dbg(us, "load firmware %s failed\n", fw_name); |
1929 | goto nofw; | 1929 | goto nofw; |
1930 | } | 1930 | } |
1931 | buf = kmalloc(sd_fw->size, GFP_KERNEL); | 1931 | buf = kmemdup(sd_fw->data, sd_fw->size, GFP_KERNEL); |
1932 | if (buf == NULL) | 1932 | if (buf == NULL) |
1933 | goto nofw; | 1933 | goto nofw; |
1934 | 1934 | ||
1935 | memcpy(buf, sd_fw->data, sd_fw->size); | ||
1936 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); | 1935 | memset(bcb, 0, sizeof(struct bulk_cb_wrap)); |
1937 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); | 1936 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); |
1938 | bcb->DataTransferLength = sd_fw->size; | 1937 | bcb->DataTransferLength = sd_fw->size; |
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c index 6d6da127f6de..a80c5d284b59 100644 --- a/drivers/usb/wusbcore/wa-rpipe.c +++ b/drivers/usb/wusbcore/wa-rpipe.c | |||
@@ -524,7 +524,7 @@ void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep) | |||
524 | u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); | 524 | u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); |
525 | 525 | ||
526 | usb_control_msg( | 526 | usb_control_msg( |
527 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), | 527 | wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), |
528 | USB_REQ_RPIPE_ABORT, | 528 | USB_REQ_RPIPE_ABORT, |
529 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 529 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
530 | 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); | 530 | 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); |
@@ -545,7 +545,7 @@ void rpipe_clear_feature_stalled(struct wahc *wa, struct usb_host_endpoint *ep) | |||
545 | u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); | 545 | u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); |
546 | 546 | ||
547 | usb_control_msg( | 547 | usb_control_msg( |
548 | wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), | 548 | wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), |
549 | USB_REQ_CLEAR_FEATURE, | 549 | USB_REQ_CLEAR_FEATURE, |
550 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, | 550 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, |
551 | RPIPE_STALL, index, NULL, 0, USB_CTRL_SET_TIMEOUT); | 551 | RPIPE_STALL, index, NULL, 0, USB_CTRL_SET_TIMEOUT); |