diff options
167 files changed, 10850 insertions, 4051 deletions
diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt index 66f92d1194c1..a4efa0462f05 100644 --- a/Documentation/usb/usbmon.txt +++ b/Documentation/usb/usbmon.txt | |||
@@ -12,6 +12,10 @@ Controller Drivers (HCD). So, if HCD is buggy, the traces reported by | |||
12 | usbmon may not correspond to bus transactions precisely. This is the same | 12 | usbmon may not correspond to bus transactions precisely. This is the same |
13 | situation as with tcpdump. | 13 | situation as with tcpdump. |
14 | 14 | ||
15 | Two APIs are currently implemented: "text" and "binary". The binary API | ||
16 | is available through a character device in /dev namespace and is an ABI. | ||
17 | The text API is deprecated since 2.6.35, but available for convenience. | ||
18 | |||
15 | * How to use usbmon to collect raw text traces | 19 | * How to use usbmon to collect raw text traces |
16 | 20 | ||
17 | Unlike the packet socket, usbmon has an interface which provides traces | 21 | Unlike the packet socket, usbmon has an interface which provides traces |
@@ -162,39 +166,11 @@ Here is the list of words, from left to right: | |||
162 | not machine words, but really just a byte stream split into words to make | 166 | not machine words, but really just a byte stream split into words to make |
163 | it easier to read. Thus, the last word may contain from one to four bytes. | 167 | it easier to read. Thus, the last word may contain from one to four bytes. |
164 | The length of collected data is limited and can be less than the data length | 168 | The length of collected data is limited and can be less than the data length |
165 | report in Data Length word. | 169 | reported in the Data Length word. In the case of an Isochronous input (Zi) |
166 | 170 | completion where the received data is sparse in the buffer, the length of | |
167 | Here is an example of code to read the data stream in a well known programming | 171 | the collected data can be greater than the Data Length value (because Data |
168 | language: | 172 | Length counts only the bytes that were received whereas the Data words |
169 | 173 | contain the entire transfer buffer). | |
170 | class ParsedLine { | ||
171 | int data_len; /* Available length of data */ | ||
172 | byte data[]; | ||
173 | |||
174 | void parseData(StringTokenizer st) { | ||
175 | int availwords = st.countTokens(); | ||
176 | data = new byte[availwords * 4]; | ||
177 | data_len = 0; | ||
178 | while (st.hasMoreTokens()) { | ||
179 | String data_str = st.nextToken(); | ||
180 | int len = data_str.length() / 2; | ||
181 | int i; | ||
182 | int b; // byte is signed, apparently?! XXX | ||
183 | for (i = 0; i < len; i++) { | ||
184 | // data[data_len] = Byte.parseByte( | ||
185 | // data_str.substring(i*2, i*2 + 2), | ||
186 | // 16); | ||
187 | b = Integer.parseInt( | ||
188 | data_str.substring(i*2, i*2 + 2), | ||
189 | 16); | ||
190 | if (b >= 128) | ||
191 | b *= -1; | ||
192 | data[data_len] = (byte) b; | ||
193 | data_len++; | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | 174 | ||
199 | Examples: | 175 | Examples: |
200 | 176 | ||
diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile index 1c0c2b02d870..64dc4176407b 100644 --- a/arch/arm/mach-omap2/Makefile +++ b/arch/arm/mach-omap2/Makefile | |||
@@ -229,7 +229,7 @@ usbfs-$(CONFIG_ARCH_OMAP_OTG) := usb-fs.o | |||
229 | obj-y += $(usbfs-m) $(usbfs-y) | 229 | obj-y += $(usbfs-m) $(usbfs-y) |
230 | obj-y += usb-musb.o | 230 | obj-y += usb-musb.o |
231 | obj-$(CONFIG_MACH_OMAP2_TUSB6010) += usb-tusb6010.o | 231 | obj-$(CONFIG_MACH_OMAP2_TUSB6010) += usb-tusb6010.o |
232 | obj-y += usb-ehci.o | 232 | obj-y += usb-host.o |
233 | 233 | ||
234 | onenand-$(CONFIG_MTD_ONENAND_OMAP2) := gpmc-onenand.o | 234 | onenand-$(CONFIG_MTD_ONENAND_OMAP2) := gpmc-onenand.o |
235 | obj-y += $(onenand-m) $(onenand-y) | 235 | obj-y += $(onenand-m) $(onenand-y) |
diff --git a/arch/arm/mach-omap2/board-3430sdp.c b/arch/arm/mach-omap2/board-3430sdp.c index d4e41ef86aa5..7542ba59f2b8 100644 --- a/arch/arm/mach-omap2/board-3430sdp.c +++ b/arch/arm/mach-omap2/board-3430sdp.c | |||
@@ -653,11 +653,11 @@ static void enable_board_wakeup_source(void) | |||
653 | OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP); | 653 | OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP); |
654 | } | 654 | } |
655 | 655 | ||
656 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 656 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
657 | 657 | ||
658 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 658 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
659 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 659 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
660 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 660 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
661 | 661 | ||
662 | .phy_reset = true, | 662 | .phy_reset = true, |
663 | .reset_gpio_port[0] = 57, | 663 | .reset_gpio_port[0] = 57, |
@@ -816,7 +816,7 @@ static void __init omap_3430sdp_init(void) | |||
816 | board_flash_init(sdp_flash_partitions, chip_sel_3430); | 816 | board_flash_init(sdp_flash_partitions, chip_sel_3430); |
817 | sdp3430_display_init(); | 817 | sdp3430_display_init(); |
818 | enable_board_wakeup_source(); | 818 | enable_board_wakeup_source(); |
819 | usb_ehci_init(&ehci_pdata); | 819 | usbhs_init(&usbhs_bdata); |
820 | } | 820 | } |
821 | 821 | ||
822 | MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board") | 822 | MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board") |
diff --git a/arch/arm/mach-omap2/board-3630sdp.c b/arch/arm/mach-omap2/board-3630sdp.c index 62645640f5e4..deed2db32c53 100644 --- a/arch/arm/mach-omap2/board-3630sdp.c +++ b/arch/arm/mach-omap2/board-3630sdp.c | |||
@@ -54,11 +54,11 @@ static void enable_board_wakeup_source(void) | |||
54 | OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP); | 54 | OMAP_WAKEUP_EN | OMAP_PIN_INPUT_PULLUP); |
55 | } | 55 | } |
56 | 56 | ||
57 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 57 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
58 | 58 | ||
59 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 59 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
60 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 60 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
61 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 61 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
62 | 62 | ||
63 | .phy_reset = true, | 63 | .phy_reset = true, |
64 | .reset_gpio_port[0] = 126, | 64 | .reset_gpio_port[0] = 126, |
@@ -211,7 +211,7 @@ static void __init omap_sdp_init(void) | |||
211 | board_smc91x_init(); | 211 | board_smc91x_init(); |
212 | board_flash_init(sdp_flash_partitions, chip_sel_sdp); | 212 | board_flash_init(sdp_flash_partitions, chip_sel_sdp); |
213 | enable_board_wakeup_source(); | 213 | enable_board_wakeup_source(); |
214 | usb_ehci_init(&ehci_pdata); | 214 | usbhs_init(&usbhs_bdata); |
215 | } | 215 | } |
216 | 216 | ||
217 | MACHINE_START(OMAP_3630SDP, "OMAP 3630SDP board") | 217 | MACHINE_START(OMAP_3630SDP, "OMAP 3630SDP board") |
diff --git a/arch/arm/mach-omap2/board-4430sdp.c b/arch/arm/mach-omap2/board-4430sdp.c index 07d1b20b1148..f603f3b04cb8 100644 --- a/arch/arm/mach-omap2/board-4430sdp.c +++ b/arch/arm/mach-omap2/board-4430sdp.c | |||
@@ -44,7 +44,6 @@ | |||
44 | #define ETH_KS8851_IRQ 34 | 44 | #define ETH_KS8851_IRQ 34 |
45 | #define ETH_KS8851_POWER_ON 48 | 45 | #define ETH_KS8851_POWER_ON 48 |
46 | #define ETH_KS8851_QUART 138 | 46 | #define ETH_KS8851_QUART 138 |
47 | #define OMAP4SDP_MDM_PWR_EN_GPIO 157 | ||
48 | #define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 | 47 | #define OMAP4_SFH7741_SENSOR_OUTPUT_GPIO 184 |
49 | #define OMAP4_SFH7741_ENABLE_GPIO 188 | 48 | #define OMAP4_SFH7741_ENABLE_GPIO 188 |
50 | 49 | ||
@@ -251,16 +250,6 @@ static void __init omap_4430sdp_init_irq(void) | |||
251 | gic_init_irq(); | 250 | gic_init_irq(); |
252 | } | 251 | } |
253 | 252 | ||
254 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | ||
255 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | ||
256 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | ||
257 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | ||
258 | .phy_reset = false, | ||
259 | .reset_gpio_port[0] = -EINVAL, | ||
260 | .reset_gpio_port[1] = -EINVAL, | ||
261 | .reset_gpio_port[2] = -EINVAL, | ||
262 | }; | ||
263 | |||
264 | static struct omap_musb_board_data musb_board_data = { | 253 | static struct omap_musb_board_data musb_board_data = { |
265 | .interface_type = MUSB_INTERFACE_UTMI, | 254 | .interface_type = MUSB_INTERFACE_UTMI, |
266 | .mode = MUSB_OTG, | 255 | .mode = MUSB_OTG, |
@@ -272,6 +261,7 @@ static struct twl4030_usb_data omap4_usbphy_data = { | |||
272 | .phy_exit = omap4430_phy_exit, | 261 | .phy_exit = omap4430_phy_exit, |
273 | .phy_power = omap4430_phy_power, | 262 | .phy_power = omap4430_phy_power, |
274 | .phy_set_clock = omap4430_phy_set_clk, | 263 | .phy_set_clock = omap4430_phy_set_clk, |
264 | .phy_suspend = omap4430_phy_suspend, | ||
275 | }; | 265 | }; |
276 | 266 | ||
277 | static struct omap2_hsmmc_info mmc[] = { | 267 | static struct omap2_hsmmc_info mmc[] = { |
@@ -576,14 +566,6 @@ static void __init omap_4430sdp_init(void) | |||
576 | omap_serial_init(); | 566 | omap_serial_init(); |
577 | omap4_twl6030_hsmmc_init(mmc); | 567 | omap4_twl6030_hsmmc_init(mmc); |
578 | 568 | ||
579 | /* Power on the ULPI PHY */ | ||
580 | status = gpio_request(OMAP4SDP_MDM_PWR_EN_GPIO, "USBB1 PHY VMDM_3V3"); | ||
581 | if (status) | ||
582 | pr_err("%s: Could not get USBB1 PHY GPIO\n", __func__); | ||
583 | else | ||
584 | gpio_direction_output(OMAP4SDP_MDM_PWR_EN_GPIO, 1); | ||
585 | |||
586 | usb_ehci_init(&ehci_pdata); | ||
587 | usb_musb_init(&musb_board_data); | 569 | usb_musb_init(&musb_board_data); |
588 | 570 | ||
589 | status = omap_ethernet_init(); | 571 | status = omap_ethernet_init(); |
diff --git a/arch/arm/mach-omap2/board-am3517crane.c b/arch/arm/mach-omap2/board-am3517crane.c index 71acb5ab281c..e3a194f6b13f 100644 --- a/arch/arm/mach-omap2/board-am3517crane.c +++ b/arch/arm/mach-omap2/board-am3517crane.c | |||
@@ -59,10 +59,10 @@ static void __init am3517_crane_init_irq(void) | |||
59 | omap_init_irq(); | 59 | omap_init_irq(); |
60 | } | 60 | } |
61 | 61 | ||
62 | static struct ehci_hcd_omap_platform_data ehci_pdata __initdata = { | 62 | static struct usbhs_omap_board_data usbhs_bdata __initdata = { |
63 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 63 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
64 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 64 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
65 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 65 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
66 | 66 | ||
67 | .phy_reset = true, | 67 | .phy_reset = true, |
68 | .reset_gpio_port[0] = GPIO_USB_NRESET, | 68 | .reset_gpio_port[0] = GPIO_USB_NRESET, |
@@ -103,7 +103,7 @@ static void __init am3517_crane_init(void) | |||
103 | return; | 103 | return; |
104 | } | 104 | } |
105 | 105 | ||
106 | usb_ehci_init(&ehci_pdata); | 106 | usbhs_init(&usbhs_bdata); |
107 | } | 107 | } |
108 | 108 | ||
109 | MACHINE_START(CRANEBOARD, "AM3517/05 CRANEBOARD") | 109 | MACHINE_START(CRANEBOARD, "AM3517/05 CRANEBOARD") |
diff --git a/arch/arm/mach-omap2/board-am3517evm.c b/arch/arm/mach-omap2/board-am3517evm.c index 10d60b7743cf..913538ad17d8 100644 --- a/arch/arm/mach-omap2/board-am3517evm.c +++ b/arch/arm/mach-omap2/board-am3517evm.c | |||
@@ -430,15 +430,15 @@ static __init void am3517_evm_musb_init(void) | |||
430 | usb_musb_init(&musb_board_data); | 430 | usb_musb_init(&musb_board_data); |
431 | } | 431 | } |
432 | 432 | ||
433 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 433 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
434 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 434 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
435 | #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \ | 435 | #if defined(CONFIG_PANEL_SHARP_LQ043T1DG01) || \ |
436 | defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE) | 436 | defined(CONFIG_PANEL_SHARP_LQ043T1DG01_MODULE) |
437 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 437 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
438 | #else | 438 | #else |
439 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 439 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
440 | #endif | 440 | #endif |
441 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 441 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
442 | 442 | ||
443 | .phy_reset = true, | 443 | .phy_reset = true, |
444 | .reset_gpio_port[0] = 57, | 444 | .reset_gpio_port[0] = 57, |
@@ -502,7 +502,7 @@ static void __init am3517_evm_init(void) | |||
502 | 502 | ||
503 | /* Configure GPIO for EHCI port */ | 503 | /* Configure GPIO for EHCI port */ |
504 | omap_mux_init_gpio(57, OMAP_PIN_OUTPUT); | 504 | omap_mux_init_gpio(57, OMAP_PIN_OUTPUT); |
505 | usb_ehci_init(&ehci_pdata); | 505 | usbhs_init(&usbhs_bdata); |
506 | am3517_evm_hecc_init(&am3517_evm_hecc_pdata); | 506 | am3517_evm_hecc_init(&am3517_evm_hecc_pdata); |
507 | /* DSS */ | 507 | /* DSS */ |
508 | am3517_evm_display_init(); | 508 | am3517_evm_display_init(); |
diff --git a/arch/arm/mach-omap2/board-cm-t35.c b/arch/arm/mach-omap2/board-cm-t35.c index dac141610666..9be7289cbb56 100644 --- a/arch/arm/mach-omap2/board-cm-t35.c +++ b/arch/arm/mach-omap2/board-cm-t35.c | |||
@@ -605,10 +605,10 @@ static struct omap2_hsmmc_info mmc[] = { | |||
605 | {} /* Terminator */ | 605 | {} /* Terminator */ |
606 | }; | 606 | }; |
607 | 607 | ||
608 | static struct ehci_hcd_omap_platform_data ehci_pdata __initdata = { | 608 | static struct usbhs_omap_board_data usbhs_bdata __initdata = { |
609 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 609 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
610 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 610 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
611 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 611 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
612 | 612 | ||
613 | .phy_reset = true, | 613 | .phy_reset = true, |
614 | .reset_gpio_port[0] = OMAP_MAX_GPIO_LINES + 6, | 614 | .reset_gpio_port[0] = OMAP_MAX_GPIO_LINES + 6, |
@@ -810,7 +810,7 @@ static void __init cm_t35_init(void) | |||
810 | cm_t35_init_display(); | 810 | cm_t35_init_display(); |
811 | 811 | ||
812 | usb_musb_init(&musb_board_data); | 812 | usb_musb_init(&musb_board_data); |
813 | usb_ehci_init(&ehci_pdata); | 813 | usbhs_init(&usbhs_bdata); |
814 | } | 814 | } |
815 | 815 | ||
816 | MACHINE_START(CM_T35, "Compulab CM-T35") | 816 | MACHINE_START(CM_T35, "Compulab CM-T35") |
diff --git a/arch/arm/mach-omap2/board-cm-t3517.c b/arch/arm/mach-omap2/board-cm-t3517.c index 8f9a64d650ee..8e18dc76b11e 100644 --- a/arch/arm/mach-omap2/board-cm-t3517.c +++ b/arch/arm/mach-omap2/board-cm-t3517.c | |||
@@ -167,10 +167,10 @@ static inline void cm_t3517_init_rtc(void) {} | |||
167 | #define HSUSB2_RESET_GPIO (147) | 167 | #define HSUSB2_RESET_GPIO (147) |
168 | #define USB_HUB_RESET_GPIO (152) | 168 | #define USB_HUB_RESET_GPIO (152) |
169 | 169 | ||
170 | static struct ehci_hcd_omap_platform_data cm_t3517_ehci_pdata __initdata = { | 170 | static struct usbhs_omap_board_data cm_t3517_ehci_pdata __initdata = { |
171 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 171 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
172 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 172 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
173 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 173 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
174 | 174 | ||
175 | .phy_reset = true, | 175 | .phy_reset = true, |
176 | .reset_gpio_port[0] = HSUSB1_RESET_GPIO, | 176 | .reset_gpio_port[0] = HSUSB1_RESET_GPIO, |
@@ -192,7 +192,7 @@ static int cm_t3517_init_usbh(void) | |||
192 | msleep(1); | 192 | msleep(1); |
193 | } | 193 | } |
194 | 194 | ||
195 | usb_ehci_init(&cm_t3517_ehci_pdata); | 195 | usbhs_init(&cm_t3517_ehci_pdata); |
196 | 196 | ||
197 | return 0; | 197 | return 0; |
198 | } | 198 | } |
diff --git a/arch/arm/mach-omap2/board-devkit8000.c b/arch/arm/mach-omap2/board-devkit8000.c index 9a2a31e011ce..bc0141b98694 100644 --- a/arch/arm/mach-omap2/board-devkit8000.c +++ b/arch/arm/mach-omap2/board-devkit8000.c | |||
@@ -620,11 +620,11 @@ static struct omap_musb_board_data musb_board_data = { | |||
620 | .power = 100, | 620 | .power = 100, |
621 | }; | 621 | }; |
622 | 622 | ||
623 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 623 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
624 | 624 | ||
625 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 625 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
626 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 626 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
627 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 627 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
628 | 628 | ||
629 | .phy_reset = true, | 629 | .phy_reset = true, |
630 | .reset_gpio_port[0] = -EINVAL, | 630 | .reset_gpio_port[0] = -EINVAL, |
@@ -803,7 +803,7 @@ static void __init devkit8000_init(void) | |||
803 | devkit8000_ads7846_init(); | 803 | devkit8000_ads7846_init(); |
804 | 804 | ||
805 | usb_musb_init(&musb_board_data); | 805 | usb_musb_init(&musb_board_data); |
806 | usb_ehci_init(&ehci_pdata); | 806 | usbhs_init(&usbhs_bdata); |
807 | devkit8000_flash_init(); | 807 | devkit8000_flash_init(); |
808 | 808 | ||
809 | /* Ensure SDRC pins are mux'd for self-refresh */ | 809 | /* Ensure SDRC pins are mux'd for self-refresh */ |
diff --git a/arch/arm/mach-omap2/board-igep0020.c b/arch/arm/mach-omap2/board-igep0020.c index 3be85a1f55f4..f9f534419311 100644 --- a/arch/arm/mach-omap2/board-igep0020.c +++ b/arch/arm/mach-omap2/board-igep0020.c | |||
@@ -627,10 +627,10 @@ static struct omap_musb_board_data musb_board_data = { | |||
627 | .power = 100, | 627 | .power = 100, |
628 | }; | 628 | }; |
629 | 629 | ||
630 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 630 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
631 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 631 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
632 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 632 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
633 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 633 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
634 | 634 | ||
635 | .phy_reset = true, | 635 | .phy_reset = true, |
636 | .reset_gpio_port[0] = IGEP2_GPIO_USBH_NRESET, | 636 | .reset_gpio_port[0] = IGEP2_GPIO_USBH_NRESET, |
@@ -699,7 +699,7 @@ static void __init igep2_init(void) | |||
699 | platform_add_devices(igep2_devices, ARRAY_SIZE(igep2_devices)); | 699 | platform_add_devices(igep2_devices, ARRAY_SIZE(igep2_devices)); |
700 | omap_serial_init(); | 700 | omap_serial_init(); |
701 | usb_musb_init(&musb_board_data); | 701 | usb_musb_init(&musb_board_data); |
702 | usb_ehci_init(&ehci_pdata); | 702 | usbhs_init(&usbhs_bdata); |
703 | 703 | ||
704 | igep2_flash_init(); | 704 | igep2_flash_init(); |
705 | igep2_leds_init(); | 705 | igep2_leds_init(); |
diff --git a/arch/arm/mach-omap2/board-igep0030.c b/arch/arm/mach-omap2/board-igep0030.c index 4dc62a9b9cb2..579fc2d2525f 100644 --- a/arch/arm/mach-omap2/board-igep0030.c +++ b/arch/arm/mach-omap2/board-igep0030.c | |||
@@ -408,10 +408,10 @@ static void __init igep3_wifi_bt_init(void) | |||
408 | void __init igep3_wifi_bt_init(void) {} | 408 | void __init igep3_wifi_bt_init(void) {} |
409 | #endif | 409 | #endif |
410 | 410 | ||
411 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 411 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
412 | .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 412 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
413 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 413 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
414 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 414 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
415 | 415 | ||
416 | .phy_reset = true, | 416 | .phy_reset = true, |
417 | .reset_gpio_port[0] = -EINVAL, | 417 | .reset_gpio_port[0] = -EINVAL, |
@@ -435,7 +435,7 @@ static void __init igep3_init(void) | |||
435 | platform_add_devices(igep3_devices, ARRAY_SIZE(igep3_devices)); | 435 | platform_add_devices(igep3_devices, ARRAY_SIZE(igep3_devices)); |
436 | omap_serial_init(); | 436 | omap_serial_init(); |
437 | usb_musb_init(&musb_board_data); | 437 | usb_musb_init(&musb_board_data); |
438 | usb_ehci_init(&ehci_pdata); | 438 | usbhs_init(&usbhs_bdata); |
439 | 439 | ||
440 | igep3_flash_init(); | 440 | igep3_flash_init(); |
441 | igep3_leds_init(); | 441 | igep3_leds_init(); |
diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c index 46d814ab5656..f0963b6e4627 100644 --- a/arch/arm/mach-omap2/board-omap3beagle.c +++ b/arch/arm/mach-omap2/board-omap3beagle.c | |||
@@ -586,11 +586,11 @@ static void __init omap3beagle_flash_init(void) | |||
586 | } | 586 | } |
587 | } | 587 | } |
588 | 588 | ||
589 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 589 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
590 | 590 | ||
591 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 591 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
592 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 592 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
593 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 593 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
594 | 594 | ||
595 | .phy_reset = true, | 595 | .phy_reset = true, |
596 | .reset_gpio_port[0] = -EINVAL, | 596 | .reset_gpio_port[0] = -EINVAL, |
@@ -625,7 +625,7 @@ static void __init omap3_beagle_init(void) | |||
625 | gpio_direction_output(170, true); | 625 | gpio_direction_output(170, true); |
626 | 626 | ||
627 | usb_musb_init(&musb_board_data); | 627 | usb_musb_init(&musb_board_data); |
628 | usb_ehci_init(&ehci_pdata); | 628 | usbhs_init(&usbhs_bdata); |
629 | omap3beagle_flash_init(); | 629 | omap3beagle_flash_init(); |
630 | 630 | ||
631 | /* Ensure SDRC pins are mux'd for self-refresh */ | 631 | /* Ensure SDRC pins are mux'd for self-refresh */ |
diff --git a/arch/arm/mach-omap2/board-omap3evm.c b/arch/arm/mach-omap2/board-omap3evm.c index 323c3809ce39..38a2d91790c0 100644 --- a/arch/arm/mach-omap2/board-omap3evm.c +++ b/arch/arm/mach-omap2/board-omap3evm.c | |||
@@ -638,11 +638,11 @@ static struct platform_device *omap3_evm_devices[] __initdata = { | |||
638 | &omap3_evm_dss_device, | 638 | &omap3_evm_dss_device, |
639 | }; | 639 | }; |
640 | 640 | ||
641 | static struct ehci_hcd_omap_platform_data ehci_pdata __initdata = { | 641 | static struct usbhs_omap_board_data usbhs_bdata __initdata = { |
642 | 642 | ||
643 | .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 643 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
644 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 644 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
645 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 645 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
646 | 646 | ||
647 | .phy_reset = true, | 647 | .phy_reset = true, |
648 | /* PHY reset GPIO will be runtime programmed based on EVM version */ | 648 | /* PHY reset GPIO will be runtime programmed based on EVM version */ |
@@ -700,7 +700,7 @@ static void __init omap3_evm_init(void) | |||
700 | 700 | ||
701 | /* setup EHCI phy reset config */ | 701 | /* setup EHCI phy reset config */ |
702 | omap_mux_init_gpio(21, OMAP_PIN_INPUT_PULLUP); | 702 | omap_mux_init_gpio(21, OMAP_PIN_INPUT_PULLUP); |
703 | ehci_pdata.reset_gpio_port[1] = 21; | 703 | usbhs_bdata.reset_gpio_port[1] = 21; |
704 | 704 | ||
705 | /* EVM REV >= E can supply 500mA with EXTVBUS programming */ | 705 | /* EVM REV >= E can supply 500mA with EXTVBUS programming */ |
706 | musb_board_data.power = 500; | 706 | musb_board_data.power = 500; |
@@ -708,10 +708,10 @@ static void __init omap3_evm_init(void) | |||
708 | } else { | 708 | } else { |
709 | /* setup EHCI phy reset on MDC */ | 709 | /* setup EHCI phy reset on MDC */ |
710 | omap_mux_init_gpio(135, OMAP_PIN_OUTPUT); | 710 | omap_mux_init_gpio(135, OMAP_PIN_OUTPUT); |
711 | ehci_pdata.reset_gpio_port[1] = 135; | 711 | usbhs_bdata.reset_gpio_port[1] = 135; |
712 | } | 712 | } |
713 | usb_musb_init(&musb_board_data); | 713 | usb_musb_init(&musb_board_data); |
714 | usb_ehci_init(&ehci_pdata); | 714 | usbhs_init(&usbhs_bdata); |
715 | ads7846_dev_init(); | 715 | ads7846_dev_init(); |
716 | omap3evm_init_smsc911x(); | 716 | omap3evm_init_smsc911x(); |
717 | omap3_evm_display_init(); | 717 | omap3_evm_display_init(); |
diff --git a/arch/arm/mach-omap2/board-omap3pandora.c b/arch/arm/mach-omap2/board-omap3pandora.c index 0b34beded11f..aa05f2e46a61 100644 --- a/arch/arm/mach-omap2/board-omap3pandora.c +++ b/arch/arm/mach-omap2/board-omap3pandora.c | |||
@@ -681,11 +681,11 @@ static struct platform_device *omap3pandora_devices[] __initdata = { | |||
681 | &pandora_vwlan_device, | 681 | &pandora_vwlan_device, |
682 | }; | 682 | }; |
683 | 683 | ||
684 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 684 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
685 | 685 | ||
686 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 686 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
687 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 687 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
688 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 688 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
689 | 689 | ||
690 | .phy_reset = true, | 690 | .phy_reset = true, |
691 | .reset_gpio_port[0] = 16, | 691 | .reset_gpio_port[0] = 16, |
@@ -716,7 +716,7 @@ static void __init omap3pandora_init(void) | |||
716 | spi_register_board_info(omap3pandora_spi_board_info, | 716 | spi_register_board_info(omap3pandora_spi_board_info, |
717 | ARRAY_SIZE(omap3pandora_spi_board_info)); | 717 | ARRAY_SIZE(omap3pandora_spi_board_info)); |
718 | omap3pandora_ads7846_init(); | 718 | omap3pandora_ads7846_init(); |
719 | usb_ehci_init(&ehci_pdata); | 719 | usbhs_init(&usbhs_bdata); |
720 | usb_musb_init(&musb_board_data); | 720 | usb_musb_init(&musb_board_data); |
721 | gpmc_nand_init(&pandora_nand_data); | 721 | gpmc_nand_init(&pandora_nand_data); |
722 | 722 | ||
diff --git a/arch/arm/mach-omap2/board-omap3stalker.c b/arch/arm/mach-omap2/board-omap3stalker.c index 2a2dad447e86..f6c87787cd4f 100644 --- a/arch/arm/mach-omap2/board-omap3stalker.c +++ b/arch/arm/mach-omap2/board-omap3stalker.c | |||
@@ -608,10 +608,10 @@ static struct platform_device *omap3_stalker_devices[] __initdata = { | |||
608 | &keys_gpio, | 608 | &keys_gpio, |
609 | }; | 609 | }; |
610 | 610 | ||
611 | static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 611 | static struct usbhs_omap_board_data usbhs_bdata __initconst = { |
612 | .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 612 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
613 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 613 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
614 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 614 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
615 | 615 | ||
616 | .phy_reset = true, | 616 | .phy_reset = true, |
617 | .reset_gpio_port[0] = -EINVAL, | 617 | .reset_gpio_port[0] = -EINVAL, |
@@ -649,7 +649,7 @@ static void __init omap3_stalker_init(void) | |||
649 | 649 | ||
650 | omap_serial_init(); | 650 | omap_serial_init(); |
651 | usb_musb_init(&musb_board_data); | 651 | usb_musb_init(&musb_board_data); |
652 | usb_ehci_init(&ehci_pdata); | 652 | usbhs_init(&usbhs_bdata); |
653 | ads7846_dev_init(); | 653 | ads7846_dev_init(); |
654 | 654 | ||
655 | omap_mux_init_gpio(21, OMAP_PIN_OUTPUT); | 655 | omap_mux_init_gpio(21, OMAP_PIN_OUTPUT); |
diff --git a/arch/arm/mach-omap2/board-omap3touchbook.c b/arch/arm/mach-omap2/board-omap3touchbook.c index db1f74fe6c4f..84cfddb19a74 100644 --- a/arch/arm/mach-omap2/board-omap3touchbook.c +++ b/arch/arm/mach-omap2/board-omap3touchbook.c | |||
@@ -468,11 +468,11 @@ static void __init omap3touchbook_flash_init(void) | |||
468 | } | 468 | } |
469 | } | 469 | } |
470 | 470 | ||
471 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 471 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
472 | 472 | ||
473 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 473 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
474 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 474 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
475 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 475 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
476 | 476 | ||
477 | .phy_reset = true, | 477 | .phy_reset = true, |
478 | .reset_gpio_port[0] = -EINVAL, | 478 | .reset_gpio_port[0] = -EINVAL, |
@@ -527,7 +527,7 @@ static void __init omap3_touchbook_init(void) | |||
527 | ARRAY_SIZE(omap3_ads7846_spi_board_info)); | 527 | ARRAY_SIZE(omap3_ads7846_spi_board_info)); |
528 | omap3_ads7846_init(); | 528 | omap3_ads7846_init(); |
529 | usb_musb_init(&musb_board_data); | 529 | usb_musb_init(&musb_board_data); |
530 | usb_ehci_init(&ehci_pdata); | 530 | usbhs_init(&usbhs_bdata); |
531 | omap3touchbook_flash_init(); | 531 | omap3touchbook_flash_init(); |
532 | 532 | ||
533 | /* Ensure SDRC pins are mux'd for self-refresh */ | 533 | /* Ensure SDRC pins are mux'd for self-refresh */ |
diff --git a/arch/arm/mach-omap2/board-omap4panda.c b/arch/arm/mach-omap2/board-omap4panda.c index e944025d5ef8..ed61c1f5d5e6 100644 --- a/arch/arm/mach-omap2/board-omap4panda.c +++ b/arch/arm/mach-omap2/board-omap4panda.c | |||
@@ -83,10 +83,10 @@ static void __init omap4_panda_init_irq(void) | |||
83 | gic_init_irq(); | 83 | gic_init_irq(); |
84 | } | 84 | } |
85 | 85 | ||
86 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 86 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
87 | .port_mode[0] = EHCI_HCD_OMAP_MODE_PHY, | 87 | .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY, |
88 | .port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 88 | .port_mode[1] = OMAP_USBHS_PORT_MODE_UNUSED, |
89 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 89 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
90 | .phy_reset = false, | 90 | .phy_reset = false, |
91 | .reset_gpio_port[0] = -EINVAL, | 91 | .reset_gpio_port[0] = -EINVAL, |
92 | .reset_gpio_port[1] = -EINVAL, | 92 | .reset_gpio_port[1] = -EINVAL, |
@@ -128,7 +128,7 @@ static void __init omap4_ehci_init(void) | |||
128 | gpio_set_value(GPIO_HUB_NRESET, 0); | 128 | gpio_set_value(GPIO_HUB_NRESET, 0); |
129 | gpio_set_value(GPIO_HUB_NRESET, 1); | 129 | gpio_set_value(GPIO_HUB_NRESET, 1); |
130 | 130 | ||
131 | usb_ehci_init(&ehci_pdata); | 131 | usbhs_init(&usbhs_bdata); |
132 | 132 | ||
133 | /* enable power to hub */ | 133 | /* enable power to hub */ |
134 | gpio_set_value(GPIO_HUB_POWER, 1); | 134 | gpio_set_value(GPIO_HUB_POWER, 1); |
@@ -153,6 +153,7 @@ static struct twl4030_usb_data omap4_usbphy_data = { | |||
153 | .phy_exit = omap4430_phy_exit, | 153 | .phy_exit = omap4430_phy_exit, |
154 | .phy_power = omap4430_phy_power, | 154 | .phy_power = omap4430_phy_power, |
155 | .phy_set_clock = omap4430_phy_set_clk, | 155 | .phy_set_clock = omap4430_phy_set_clk, |
156 | .phy_suspend = omap4430_phy_suspend, | ||
156 | }; | 157 | }; |
157 | 158 | ||
158 | static struct omap2_hsmmc_info mmc[] = { | 159 | static struct omap2_hsmmc_info mmc[] = { |
diff --git a/arch/arm/mach-omap2/board-overo.c b/arch/arm/mach-omap2/board-overo.c index cb26e5d8268d..08770ccec0f3 100644 --- a/arch/arm/mach-omap2/board-overo.c +++ b/arch/arm/mach-omap2/board-overo.c | |||
@@ -423,10 +423,10 @@ static struct platform_device *overo_devices[] __initdata = { | |||
423 | &overo_lcd_device, | 423 | &overo_lcd_device, |
424 | }; | 424 | }; |
425 | 425 | ||
426 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 426 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
427 | .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 427 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
428 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 428 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
429 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 429 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
430 | 430 | ||
431 | .phy_reset = true, | 431 | .phy_reset = true, |
432 | .reset_gpio_port[0] = -EINVAL, | 432 | .reset_gpio_port[0] = -EINVAL, |
@@ -454,7 +454,7 @@ static void __init overo_init(void) | |||
454 | omap_serial_init(); | 454 | omap_serial_init(); |
455 | overo_flash_init(); | 455 | overo_flash_init(); |
456 | usb_musb_init(&musb_board_data); | 456 | usb_musb_init(&musb_board_data); |
457 | usb_ehci_init(&ehci_pdata); | 457 | usbhs_init(&usbhs_bdata); |
458 | overo_ads7846_init(); | 458 | overo_ads7846_init(); |
459 | overo_init_smsc911x(); | 459 | overo_init_smsc911x(); |
460 | 460 | ||
diff --git a/arch/arm/mach-omap2/board-zoom.c b/arch/arm/mach-omap2/board-zoom.c index e26754c24ee8..1dd195afa396 100644 --- a/arch/arm/mach-omap2/board-zoom.c +++ b/arch/arm/mach-omap2/board-zoom.c | |||
@@ -106,10 +106,10 @@ static struct mtd_partition zoom_nand_partitions[] = { | |||
106 | }, | 106 | }, |
107 | }; | 107 | }; |
108 | 108 | ||
109 | static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { | 109 | static const struct usbhs_omap_board_data usbhs_bdata __initconst = { |
110 | .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 110 | .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, |
111 | .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, | 111 | .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY, |
112 | .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, | 112 | .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED, |
113 | .phy_reset = true, | 113 | .phy_reset = true, |
114 | .reset_gpio_port[0] = -EINVAL, | 114 | .reset_gpio_port[0] = -EINVAL, |
115 | .reset_gpio_port[1] = ZOOM3_EHCI_RESET_GPIO, | 115 | .reset_gpio_port[1] = ZOOM3_EHCI_RESET_GPIO, |
@@ -123,7 +123,7 @@ static void __init omap_zoom_init(void) | |||
123 | } else if (machine_is_omap_zoom3()) { | 123 | } else if (machine_is_omap_zoom3()) { |
124 | omap3_mux_init(board_mux, OMAP_PACKAGE_CBP); | 124 | omap3_mux_init(board_mux, OMAP_PACKAGE_CBP); |
125 | omap_mux_init_gpio(ZOOM3_EHCI_RESET_GPIO, OMAP_PIN_OUTPUT); | 125 | omap_mux_init_gpio(ZOOM3_EHCI_RESET_GPIO, OMAP_PIN_OUTPUT); |
126 | usb_ehci_init(&ehci_pdata); | 126 | usbhs_init(&usbhs_bdata); |
127 | } | 127 | } |
128 | 128 | ||
129 | board_nand_init(zoom_nand_partitions, | 129 | board_nand_init(zoom_nand_partitions, |
diff --git a/arch/arm/mach-omap2/clock3xxx_data.c b/arch/arm/mach-omap2/clock3xxx_data.c index 403a4a1d3f9c..fbb1e30a73dc 100644 --- a/arch/arm/mach-omap2/clock3xxx_data.c +++ b/arch/arm/mach-omap2/clock3xxx_data.c | |||
@@ -3286,7 +3286,7 @@ static struct omap_clk omap3xxx_clks[] = { | |||
3286 | CLK(NULL, "cpefuse_fck", &cpefuse_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3286 | CLK(NULL, "cpefuse_fck", &cpefuse_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3287 | CLK(NULL, "ts_fck", &ts_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3287 | CLK(NULL, "ts_fck", &ts_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3288 | CLK(NULL, "usbtll_fck", &usbtll_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3288 | CLK(NULL, "usbtll_fck", &usbtll_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3289 | CLK("ehci-omap.0", "usbtll_fck", &usbtll_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3289 | CLK("usbhs-omap.0", "usbtll_fck", &usbtll_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3290 | CLK("omap-mcbsp.1", "prcm_fck", &core_96m_fck, CK_3XXX), | 3290 | CLK("omap-mcbsp.1", "prcm_fck", &core_96m_fck, CK_3XXX), |
3291 | CLK("omap-mcbsp.5", "prcm_fck", &core_96m_fck, CK_3XXX), | 3291 | CLK("omap-mcbsp.5", "prcm_fck", &core_96m_fck, CK_3XXX), |
3292 | CLK(NULL, "core_96m_fck", &core_96m_fck, CK_3XXX), | 3292 | CLK(NULL, "core_96m_fck", &core_96m_fck, CK_3XXX), |
@@ -3322,7 +3322,7 @@ static struct omap_clk omap3xxx_clks[] = { | |||
3322 | CLK(NULL, "pka_ick", &pka_ick, CK_34XX | CK_36XX), | 3322 | CLK(NULL, "pka_ick", &pka_ick, CK_34XX | CK_36XX), |
3323 | CLK(NULL, "core_l4_ick", &core_l4_ick, CK_3XXX), | 3323 | CLK(NULL, "core_l4_ick", &core_l4_ick, CK_3XXX), |
3324 | CLK(NULL, "usbtll_ick", &usbtll_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3324 | CLK(NULL, "usbtll_ick", &usbtll_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3325 | CLK("ehci-omap.0", "usbtll_ick", &usbtll_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3325 | CLK("usbhs-omap.0", "usbtll_ick", &usbtll_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3326 | CLK("mmci-omap-hs.2", "ick", &mmchs3_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3326 | CLK("mmci-omap-hs.2", "ick", &mmchs3_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3327 | CLK(NULL, "icr_ick", &icr_ick, CK_34XX | CK_36XX), | 3327 | CLK(NULL, "icr_ick", &icr_ick, CK_34XX | CK_36XX), |
3328 | CLK("omap-aes", "ick", &aes2_ick, CK_34XX | CK_36XX), | 3328 | CLK("omap-aes", "ick", &aes2_ick, CK_34XX | CK_36XX), |
@@ -3368,11 +3368,20 @@ static struct omap_clk omap3xxx_clks[] = { | |||
3368 | CLK(NULL, "cam_ick", &cam_ick, CK_34XX | CK_36XX), | 3368 | CLK(NULL, "cam_ick", &cam_ick, CK_34XX | CK_36XX), |
3369 | CLK(NULL, "csi2_96m_fck", &csi2_96m_fck, CK_34XX | CK_36XX), | 3369 | CLK(NULL, "csi2_96m_fck", &csi2_96m_fck, CK_34XX | CK_36XX), |
3370 | CLK(NULL, "usbhost_120m_fck", &usbhost_120m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3370 | CLK(NULL, "usbhost_120m_fck", &usbhost_120m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3371 | CLK("ehci-omap.0", "hs_fck", &usbhost_120m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3371 | CLK("usbhs-omap.0", "hs_fck", &usbhost_120m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3372 | CLK(NULL, "usbhost_48m_fck", &usbhost_48m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3372 | CLK(NULL, "usbhost_48m_fck", &usbhost_48m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3373 | CLK("ehci-omap.0", "fs_fck", &usbhost_48m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3373 | CLK("usbhs-omap.0", "fs_fck", &usbhost_48m_fck, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3374 | CLK(NULL, "usbhost_ick", &usbhost_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3374 | CLK(NULL, "usbhost_ick", &usbhost_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3375 | CLK("ehci-omap.0", "usbhost_ick", &usbhost_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), | 3375 | CLK("usbhs-omap.0", "usbhost_ick", &usbhost_ick, CK_3430ES2PLUS | CK_AM35XX | CK_36XX), |
3376 | CLK("usbhs-omap.0", "utmi_p1_gfclk", &dummy_ck, CK_3XXX), | ||
3377 | CLK("usbhs-omap.0", "utmi_p2_gfclk", &dummy_ck, CK_3XXX), | ||
3378 | CLK("usbhs-omap.0", "xclk60mhsp1_ck", &dummy_ck, CK_3XXX), | ||
3379 | CLK("usbhs-omap.0", "xclk60mhsp2_ck", &dummy_ck, CK_3XXX), | ||
3380 | CLK("usbhs-omap.0", "usb_host_hs_utmi_p1_clk", &dummy_ck, CK_3XXX), | ||
3381 | CLK("usbhs-omap.0", "usb_host_hs_utmi_p2_clk", &dummy_ck, CK_3XXX), | ||
3382 | CLK("usbhs-omap.0", "usb_tll_hs_usb_ch0_clk", &dummy_ck, CK_3XXX), | ||
3383 | CLK("usbhs-omap.0", "usb_tll_hs_usb_ch1_clk", &dummy_ck, CK_3XXX), | ||
3384 | CLK("usbhs-omap.0", "init_60m_fclk", &dummy_ck, CK_3XXX), | ||
3376 | CLK(NULL, "usim_fck", &usim_fck, CK_3430ES2PLUS | CK_36XX), | 3385 | CLK(NULL, "usim_fck", &usim_fck, CK_3430ES2PLUS | CK_36XX), |
3377 | CLK(NULL, "gpt1_fck", &gpt1_fck, CK_3XXX), | 3386 | CLK(NULL, "gpt1_fck", &gpt1_fck, CK_3XXX), |
3378 | CLK(NULL, "wkup_32k_fck", &wkup_32k_fck, CK_3XXX), | 3387 | CLK(NULL, "wkup_32k_fck", &wkup_32k_fck, CK_3XXX), |
diff --git a/arch/arm/mach-omap2/clock44xx_data.c b/arch/arm/mach-omap2/clock44xx_data.c index de9ec8ddd2ae..46fd3f674cac 100644 --- a/arch/arm/mach-omap2/clock44xx_data.c +++ b/arch/arm/mach-omap2/clock44xx_data.c | |||
@@ -3197,7 +3197,7 @@ static struct omap_clk omap44xx_clks[] = { | |||
3197 | CLK(NULL, "uart3_fck", &uart3_fck, CK_443X), | 3197 | CLK(NULL, "uart3_fck", &uart3_fck, CK_443X), |
3198 | CLK(NULL, "uart4_fck", &uart4_fck, CK_443X), | 3198 | CLK(NULL, "uart4_fck", &uart4_fck, CK_443X), |
3199 | CLK(NULL, "usb_host_fs_fck", &usb_host_fs_fck, CK_443X), | 3199 | CLK(NULL, "usb_host_fs_fck", &usb_host_fs_fck, CK_443X), |
3200 | CLK("ehci-omap.0", "fs_fck", &usb_host_fs_fck, CK_443X), | 3200 | CLK("usbhs-omap.0", "fs_fck", &usb_host_fs_fck, CK_443X), |
3201 | CLK(NULL, "utmi_p1_gfclk", &utmi_p1_gfclk, CK_443X), | 3201 | CLK(NULL, "utmi_p1_gfclk", &utmi_p1_gfclk, CK_443X), |
3202 | CLK(NULL, "usb_host_hs_utmi_p1_clk", &usb_host_hs_utmi_p1_clk, CK_443X), | 3202 | CLK(NULL, "usb_host_hs_utmi_p1_clk", &usb_host_hs_utmi_p1_clk, CK_443X), |
3203 | CLK(NULL, "utmi_p2_gfclk", &utmi_p2_gfclk, CK_443X), | 3203 | CLK(NULL, "utmi_p2_gfclk", &utmi_p2_gfclk, CK_443X), |
@@ -3209,8 +3209,8 @@ static struct omap_clk omap44xx_clks[] = { | |||
3209 | CLK(NULL, "usb_host_hs_hsic480m_p2_clk", &usb_host_hs_hsic480m_p2_clk, CK_443X), | 3209 | CLK(NULL, "usb_host_hs_hsic480m_p2_clk", &usb_host_hs_hsic480m_p2_clk, CK_443X), |
3210 | CLK(NULL, "usb_host_hs_func48mclk", &usb_host_hs_func48mclk, CK_443X), | 3210 | CLK(NULL, "usb_host_hs_func48mclk", &usb_host_hs_func48mclk, CK_443X), |
3211 | CLK(NULL, "usb_host_hs_fck", &usb_host_hs_fck, CK_443X), | 3211 | CLK(NULL, "usb_host_hs_fck", &usb_host_hs_fck, CK_443X), |
3212 | CLK("ehci-omap.0", "hs_fck", &usb_host_hs_fck, CK_443X), | 3212 | CLK("usbhs-omap.0", "hs_fck", &usb_host_hs_fck, CK_443X), |
3213 | CLK("ehci-omap.0", "usbhost_ick", &dummy_ck, CK_443X), | 3213 | CLK("usbhs-omap.0", "usbhost_ick", &dummy_ck, CK_443X), |
3214 | CLK(NULL, "otg_60m_gfclk", &otg_60m_gfclk, CK_443X), | 3214 | CLK(NULL, "otg_60m_gfclk", &otg_60m_gfclk, CK_443X), |
3215 | CLK(NULL, "usb_otg_hs_xclk", &usb_otg_hs_xclk, CK_443X), | 3215 | CLK(NULL, "usb_otg_hs_xclk", &usb_otg_hs_xclk, CK_443X), |
3216 | CLK("musb-omap2430", "ick", &usb_otg_hs_ick, CK_443X), | 3216 | CLK("musb-omap2430", "ick", &usb_otg_hs_ick, CK_443X), |
@@ -3219,8 +3219,8 @@ static struct omap_clk omap44xx_clks[] = { | |||
3219 | CLK(NULL, "usb_tll_hs_usb_ch0_clk", &usb_tll_hs_usb_ch0_clk, CK_443X), | 3219 | CLK(NULL, "usb_tll_hs_usb_ch0_clk", &usb_tll_hs_usb_ch0_clk, CK_443X), |
3220 | CLK(NULL, "usb_tll_hs_usb_ch1_clk", &usb_tll_hs_usb_ch1_clk, CK_443X), | 3220 | CLK(NULL, "usb_tll_hs_usb_ch1_clk", &usb_tll_hs_usb_ch1_clk, CK_443X), |
3221 | CLK(NULL, "usb_tll_hs_ick", &usb_tll_hs_ick, CK_443X), | 3221 | CLK(NULL, "usb_tll_hs_ick", &usb_tll_hs_ick, CK_443X), |
3222 | CLK("ehci-omap.0", "usbtll_ick", &usb_tll_hs_ick, CK_443X), | 3222 | CLK("usbhs-omap.0", "usbtll_ick", &usb_tll_hs_ick, CK_443X), |
3223 | CLK("ehci-omap.0", "usbtll_fck", &dummy_ck, CK_443X), | 3223 | CLK("usbhs-omap.0", "usbtll_fck", &dummy_ck, CK_443X), |
3224 | CLK(NULL, "usim_ck", &usim_ck, CK_443X), | 3224 | CLK(NULL, "usim_ck", &usim_ck, CK_443X), |
3225 | CLK(NULL, "usim_fclk", &usim_fclk, CK_443X), | 3225 | CLK(NULL, "usim_fclk", &usim_fclk, CK_443X), |
3226 | CLK(NULL, "usim_fck", &usim_fck, CK_443X), | 3226 | CLK(NULL, "usim_fck", &usim_fck, CK_443X), |
diff --git a/arch/arm/mach-omap2/omap_phy_internal.c b/arch/arm/mach-omap2/omap_phy_internal.c index 745252c60e32..ebe33df708bd 100644 --- a/arch/arm/mach-omap2/omap_phy_internal.c +++ b/arch/arm/mach-omap2/omap_phy_internal.c | |||
@@ -43,6 +43,7 @@ | |||
43 | 43 | ||
44 | static struct clk *phyclk, *clk48m, *clk32k; | 44 | static struct clk *phyclk, *clk48m, *clk32k; |
45 | static void __iomem *ctrl_base; | 45 | static void __iomem *ctrl_base; |
46 | static int usbotghs_control; | ||
46 | 47 | ||
47 | int omap4430_phy_init(struct device *dev) | 48 | int omap4430_phy_init(struct device *dev) |
48 | { | 49 | { |
@@ -103,13 +104,6 @@ int omap4430_phy_set_clk(struct device *dev, int on) | |||
103 | int omap4430_phy_power(struct device *dev, int ID, int on) | 104 | int omap4430_phy_power(struct device *dev, int ID, int on) |
104 | { | 105 | { |
105 | if (on) { | 106 | if (on) { |
106 | /* enabled the clocks */ | ||
107 | omap4430_phy_set_clk(dev, 1); | ||
108 | /* power on the phy */ | ||
109 | if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) { | ||
110 | __raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF); | ||
111 | mdelay(200); | ||
112 | } | ||
113 | if (ID) | 107 | if (ID) |
114 | /* enable VBUS valid, IDDIG groung */ | 108 | /* enable VBUS valid, IDDIG groung */ |
115 | __raw_writel(AVALID | VBUSVALID, ctrl_base + | 109 | __raw_writel(AVALID | VBUSVALID, ctrl_base + |
@@ -125,10 +119,31 @@ int omap4430_phy_power(struct device *dev, int ID, int on) | |||
125 | /* Enable session END and IDIG to high impedence. */ | 119 | /* Enable session END and IDIG to high impedence. */ |
126 | __raw_writel(SESSEND | IDDIG, ctrl_base + | 120 | __raw_writel(SESSEND | IDDIG, ctrl_base + |
127 | USBOTGHS_CONTROL); | 121 | USBOTGHS_CONTROL); |
122 | } | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | int omap4430_phy_suspend(struct device *dev, int suspend) | ||
127 | { | ||
128 | if (suspend) { | ||
128 | /* Disable the clocks */ | 129 | /* Disable the clocks */ |
129 | omap4430_phy_set_clk(dev, 0); | 130 | omap4430_phy_set_clk(dev, 0); |
130 | /* Power down the phy */ | 131 | /* Power down the phy */ |
131 | __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF); | 132 | __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF); |
133 | |||
134 | /* save the context */ | ||
135 | usbotghs_control = __raw_readl(ctrl_base + USBOTGHS_CONTROL); | ||
136 | } else { | ||
137 | /* Enable the internel phy clcoks */ | ||
138 | omap4430_phy_set_clk(dev, 1); | ||
139 | /* power on the phy */ | ||
140 | if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) { | ||
141 | __raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF); | ||
142 | mdelay(200); | ||
143 | } | ||
144 | |||
145 | /* restore the context */ | ||
146 | __raw_writel(usbotghs_control, ctrl_base + USBOTGHS_CONTROL); | ||
132 | } | 147 | } |
133 | 148 | ||
134 | return 0; | 149 | return 0; |
diff --git a/arch/arm/mach-omap2/usb-ehci.c b/arch/arm/mach-omap2/usb-host.c index 25eeadabc39b..89ae29847c59 100644 --- a/arch/arm/mach-omap2/usb-ehci.c +++ b/arch/arm/mach-omap2/usb-host.c | |||
@@ -1,14 +1,15 @@ | |||
1 | /* | 1 | /* |
2 | * linux/arch/arm/mach-omap2/usb-ehci.c | 2 | * usb-host.c - OMAP USB Host |
3 | * | 3 | * |
4 | * This file will contain the board specific details for the | 4 | * This file will contain the board specific details for the |
5 | * Synopsys EHCI host controller on OMAP3430 | 5 | * Synopsys EHCI/OHCI host controller on OMAP3430 and onwards |
6 | * | 6 | * |
7 | * Copyright (C) 2007 Texas Instruments | 7 | * Copyright (C) 2007-2011 Texas Instruments |
8 | * Author: Vikram Pandita <vikram.pandita@ti.com> | 8 | * Author: Vikram Pandita <vikram.pandita@ti.com> |
9 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> | ||
9 | * | 10 | * |
10 | * Generalization by: | 11 | * Generalization by: |
11 | * Felipe Balbi <felipe.balbi@nokia.com> | 12 | * Felipe Balbi <balbi@ti.com> |
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or modify | 14 | * This program is free software; you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License version 2 as | 15 | * it under the terms of the GNU General Public License version 2 as |
@@ -19,7 +20,7 @@ | |||
19 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
20 | #include <linux/delay.h> | 21 | #include <linux/delay.h> |
21 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
22 | #include <linux/clk.h> | 23 | #include <linux/slab.h> |
23 | #include <linux/dma-mapping.h> | 24 | #include <linux/dma-mapping.h> |
24 | 25 | ||
25 | #include <asm/io.h> | 26 | #include <asm/io.h> |
@@ -30,44 +31,56 @@ | |||
30 | 31 | ||
31 | #include "mux.h" | 32 | #include "mux.h" |
32 | 33 | ||
33 | #if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_EHCI_HCD_MODULE) | 34 | #ifdef CONFIG_MFD_OMAP_USB_HOST |
34 | 35 | ||
35 | static struct resource ehci_resources[] = { | 36 | #define OMAP_USBHS_DEVICE "usbhs-omap" |
37 | |||
38 | static struct resource usbhs_resources[] = { | ||
39 | { | ||
40 | .name = "uhh", | ||
41 | .flags = IORESOURCE_MEM, | ||
42 | }, | ||
36 | { | 43 | { |
44 | .name = "tll", | ||
37 | .flags = IORESOURCE_MEM, | 45 | .flags = IORESOURCE_MEM, |
38 | }, | 46 | }, |
39 | { | 47 | { |
48 | .name = "ehci", | ||
40 | .flags = IORESOURCE_MEM, | 49 | .flags = IORESOURCE_MEM, |
41 | }, | 50 | }, |
42 | { | 51 | { |
52 | .name = "ehci-irq", | ||
53 | .flags = IORESOURCE_IRQ, | ||
54 | }, | ||
55 | { | ||
56 | .name = "ohci", | ||
43 | .flags = IORESOURCE_MEM, | 57 | .flags = IORESOURCE_MEM, |
44 | }, | 58 | }, |
45 | { /* general IRQ */ | 59 | { |
46 | .flags = IORESOURCE_IRQ, | 60 | .name = "ohci-irq", |
61 | .flags = IORESOURCE_IRQ, | ||
47 | } | 62 | } |
48 | }; | 63 | }; |
49 | 64 | ||
50 | static u64 ehci_dmamask = ~(u32)0; | 65 | static struct platform_device usbhs_device = { |
51 | static struct platform_device ehci_device = { | 66 | .name = OMAP_USBHS_DEVICE, |
52 | .name = "ehci-omap", | 67 | .id = 0, |
53 | .id = 0, | 68 | .num_resources = ARRAY_SIZE(usbhs_resources), |
54 | .dev = { | 69 | .resource = usbhs_resources, |
55 | .dma_mask = &ehci_dmamask, | ||
56 | .coherent_dma_mask = 0xffffffff, | ||
57 | .platform_data = NULL, | ||
58 | }, | ||
59 | .num_resources = ARRAY_SIZE(ehci_resources), | ||
60 | .resource = ehci_resources, | ||
61 | }; | 70 | }; |
62 | 71 | ||
72 | static struct usbhs_omap_platform_data usbhs_data; | ||
73 | static struct ehci_hcd_omap_platform_data ehci_data; | ||
74 | static struct ohci_hcd_omap_platform_data ohci_data; | ||
75 | |||
63 | /* MUX settings for EHCI pins */ | 76 | /* MUX settings for EHCI pins */ |
64 | /* | 77 | /* |
65 | * setup_ehci_io_mux - initialize IO pad mux for USBHOST | 78 | * setup_ehci_io_mux - initialize IO pad mux for USBHOST |
66 | */ | 79 | */ |
67 | static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | 80 | static void setup_ehci_io_mux(const enum usbhs_omap_port_mode *port_mode) |
68 | { | 81 | { |
69 | switch (port_mode[0]) { | 82 | switch (port_mode[0]) { |
70 | case EHCI_HCD_OMAP_MODE_PHY: | 83 | case OMAP_EHCI_PORT_MODE_PHY: |
71 | omap_mux_init_signal("hsusb1_stp", OMAP_PIN_OUTPUT); | 84 | omap_mux_init_signal("hsusb1_stp", OMAP_PIN_OUTPUT); |
72 | omap_mux_init_signal("hsusb1_clk", OMAP_PIN_OUTPUT); | 85 | omap_mux_init_signal("hsusb1_clk", OMAP_PIN_OUTPUT); |
73 | omap_mux_init_signal("hsusb1_dir", OMAP_PIN_INPUT_PULLDOWN); | 86 | omap_mux_init_signal("hsusb1_dir", OMAP_PIN_INPUT_PULLDOWN); |
@@ -81,7 +94,7 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
81 | omap_mux_init_signal("hsusb1_data6", OMAP_PIN_INPUT_PULLDOWN); | 94 | omap_mux_init_signal("hsusb1_data6", OMAP_PIN_INPUT_PULLDOWN); |
82 | omap_mux_init_signal("hsusb1_data7", OMAP_PIN_INPUT_PULLDOWN); | 95 | omap_mux_init_signal("hsusb1_data7", OMAP_PIN_INPUT_PULLDOWN); |
83 | break; | 96 | break; |
84 | case EHCI_HCD_OMAP_MODE_TLL: | 97 | case OMAP_EHCI_PORT_MODE_TLL: |
85 | omap_mux_init_signal("hsusb1_tll_stp", | 98 | omap_mux_init_signal("hsusb1_tll_stp", |
86 | OMAP_PIN_INPUT_PULLUP); | 99 | OMAP_PIN_INPUT_PULLUP); |
87 | omap_mux_init_signal("hsusb1_tll_clk", | 100 | omap_mux_init_signal("hsusb1_tll_clk", |
@@ -107,14 +120,14 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
107 | omap_mux_init_signal("hsusb1_tll_data7", | 120 | omap_mux_init_signal("hsusb1_tll_data7", |
108 | OMAP_PIN_INPUT_PULLDOWN); | 121 | OMAP_PIN_INPUT_PULLDOWN); |
109 | break; | 122 | break; |
110 | case EHCI_HCD_OMAP_MODE_UNKNOWN: | 123 | case OMAP_USBHS_PORT_MODE_UNUSED: |
111 | /* FALLTHROUGH */ | 124 | /* FALLTHROUGH */ |
112 | default: | 125 | default: |
113 | break; | 126 | break; |
114 | } | 127 | } |
115 | 128 | ||
116 | switch (port_mode[1]) { | 129 | switch (port_mode[1]) { |
117 | case EHCI_HCD_OMAP_MODE_PHY: | 130 | case OMAP_EHCI_PORT_MODE_PHY: |
118 | omap_mux_init_signal("hsusb2_stp", OMAP_PIN_OUTPUT); | 131 | omap_mux_init_signal("hsusb2_stp", OMAP_PIN_OUTPUT); |
119 | omap_mux_init_signal("hsusb2_clk", OMAP_PIN_OUTPUT); | 132 | omap_mux_init_signal("hsusb2_clk", OMAP_PIN_OUTPUT); |
120 | omap_mux_init_signal("hsusb2_dir", OMAP_PIN_INPUT_PULLDOWN); | 133 | omap_mux_init_signal("hsusb2_dir", OMAP_PIN_INPUT_PULLDOWN); |
@@ -136,7 +149,7 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
136 | omap_mux_init_signal("hsusb2_data7", | 149 | omap_mux_init_signal("hsusb2_data7", |
137 | OMAP_PIN_INPUT_PULLDOWN); | 150 | OMAP_PIN_INPUT_PULLDOWN); |
138 | break; | 151 | break; |
139 | case EHCI_HCD_OMAP_MODE_TLL: | 152 | case OMAP_EHCI_PORT_MODE_TLL: |
140 | omap_mux_init_signal("hsusb2_tll_stp", | 153 | omap_mux_init_signal("hsusb2_tll_stp", |
141 | OMAP_PIN_INPUT_PULLUP); | 154 | OMAP_PIN_INPUT_PULLUP); |
142 | omap_mux_init_signal("hsusb2_tll_clk", | 155 | omap_mux_init_signal("hsusb2_tll_clk", |
@@ -162,17 +175,17 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
162 | omap_mux_init_signal("hsusb2_tll_data7", | 175 | omap_mux_init_signal("hsusb2_tll_data7", |
163 | OMAP_PIN_INPUT_PULLDOWN); | 176 | OMAP_PIN_INPUT_PULLDOWN); |
164 | break; | 177 | break; |
165 | case EHCI_HCD_OMAP_MODE_UNKNOWN: | 178 | case OMAP_USBHS_PORT_MODE_UNUSED: |
166 | /* FALLTHROUGH */ | 179 | /* FALLTHROUGH */ |
167 | default: | 180 | default: |
168 | break; | 181 | break; |
169 | } | 182 | } |
170 | 183 | ||
171 | switch (port_mode[2]) { | 184 | switch (port_mode[2]) { |
172 | case EHCI_HCD_OMAP_MODE_PHY: | 185 | case OMAP_EHCI_PORT_MODE_PHY: |
173 | printk(KERN_WARNING "Port3 can't be used in PHY mode\n"); | 186 | printk(KERN_WARNING "Port3 can't be used in PHY mode\n"); |
174 | break; | 187 | break; |
175 | case EHCI_HCD_OMAP_MODE_TLL: | 188 | case OMAP_EHCI_PORT_MODE_TLL: |
176 | omap_mux_init_signal("hsusb3_tll_stp", | 189 | omap_mux_init_signal("hsusb3_tll_stp", |
177 | OMAP_PIN_INPUT_PULLUP); | 190 | OMAP_PIN_INPUT_PULLUP); |
178 | omap_mux_init_signal("hsusb3_tll_clk", | 191 | omap_mux_init_signal("hsusb3_tll_clk", |
@@ -198,7 +211,7 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
198 | omap_mux_init_signal("hsusb3_tll_data7", | 211 | omap_mux_init_signal("hsusb3_tll_data7", |
199 | OMAP_PIN_INPUT_PULLDOWN); | 212 | OMAP_PIN_INPUT_PULLDOWN); |
200 | break; | 213 | break; |
201 | case EHCI_HCD_OMAP_MODE_UNKNOWN: | 214 | case OMAP_USBHS_PORT_MODE_UNUSED: |
202 | /* FALLTHROUGH */ | 215 | /* FALLTHROUGH */ |
203 | default: | 216 | default: |
204 | break; | 217 | break; |
@@ -207,10 +220,10 @@ static void setup_ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
207 | return; | 220 | return; |
208 | } | 221 | } |
209 | 222 | ||
210 | static void setup_4430ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | 223 | static void setup_4430ehci_io_mux(const enum usbhs_omap_port_mode *port_mode) |
211 | { | 224 | { |
212 | switch (port_mode[0]) { | 225 | switch (port_mode[0]) { |
213 | case EHCI_HCD_OMAP_MODE_PHY: | 226 | case OMAP_EHCI_PORT_MODE_PHY: |
214 | omap_mux_init_signal("usbb1_ulpiphy_stp", | 227 | omap_mux_init_signal("usbb1_ulpiphy_stp", |
215 | OMAP_PIN_OUTPUT); | 228 | OMAP_PIN_OUTPUT); |
216 | omap_mux_init_signal("usbb1_ulpiphy_clk", | 229 | omap_mux_init_signal("usbb1_ulpiphy_clk", |
@@ -236,7 +249,7 @@ static void setup_4430ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
236 | omap_mux_init_signal("usbb1_ulpiphy_dat7", | 249 | omap_mux_init_signal("usbb1_ulpiphy_dat7", |
237 | OMAP_PIN_INPUT_PULLDOWN); | 250 | OMAP_PIN_INPUT_PULLDOWN); |
238 | break; | 251 | break; |
239 | case EHCI_HCD_OMAP_MODE_TLL: | 252 | case OMAP_EHCI_PORT_MODE_TLL: |
240 | omap_mux_init_signal("usbb1_ulpitll_stp", | 253 | omap_mux_init_signal("usbb1_ulpitll_stp", |
241 | OMAP_PIN_INPUT_PULLUP); | 254 | OMAP_PIN_INPUT_PULLUP); |
242 | omap_mux_init_signal("usbb1_ulpitll_clk", | 255 | omap_mux_init_signal("usbb1_ulpitll_clk", |
@@ -262,12 +275,12 @@ static void setup_4430ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
262 | omap_mux_init_signal("usbb1_ulpitll_dat7", | 275 | omap_mux_init_signal("usbb1_ulpitll_dat7", |
263 | OMAP_PIN_INPUT_PULLDOWN); | 276 | OMAP_PIN_INPUT_PULLDOWN); |
264 | break; | 277 | break; |
265 | case EHCI_HCD_OMAP_MODE_UNKNOWN: | 278 | case OMAP_USBHS_PORT_MODE_UNUSED: |
266 | default: | 279 | default: |
267 | break; | 280 | break; |
268 | } | 281 | } |
269 | switch (port_mode[1]) { | 282 | switch (port_mode[1]) { |
270 | case EHCI_HCD_OMAP_MODE_PHY: | 283 | case OMAP_EHCI_PORT_MODE_PHY: |
271 | omap_mux_init_signal("usbb2_ulpiphy_stp", | 284 | omap_mux_init_signal("usbb2_ulpiphy_stp", |
272 | OMAP_PIN_OUTPUT); | 285 | OMAP_PIN_OUTPUT); |
273 | omap_mux_init_signal("usbb2_ulpiphy_clk", | 286 | omap_mux_init_signal("usbb2_ulpiphy_clk", |
@@ -293,7 +306,7 @@ static void setup_4430ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
293 | omap_mux_init_signal("usbb2_ulpiphy_dat7", | 306 | omap_mux_init_signal("usbb2_ulpiphy_dat7", |
294 | OMAP_PIN_INPUT_PULLDOWN); | 307 | OMAP_PIN_INPUT_PULLDOWN); |
295 | break; | 308 | break; |
296 | case EHCI_HCD_OMAP_MODE_TLL: | 309 | case OMAP_EHCI_PORT_MODE_TLL: |
297 | omap_mux_init_signal("usbb2_ulpitll_stp", | 310 | omap_mux_init_signal("usbb2_ulpitll_stp", |
298 | OMAP_PIN_INPUT_PULLUP); | 311 | OMAP_PIN_INPUT_PULLUP); |
299 | omap_mux_init_signal("usbb2_ulpitll_clk", | 312 | omap_mux_init_signal("usbb2_ulpitll_clk", |
@@ -319,90 +332,13 @@ static void setup_4430ehci_io_mux(const enum ehci_hcd_omap_mode *port_mode) | |||
319 | omap_mux_init_signal("usbb2_ulpitll_dat7", | 332 | omap_mux_init_signal("usbb2_ulpitll_dat7", |
320 | OMAP_PIN_INPUT_PULLDOWN); | 333 | OMAP_PIN_INPUT_PULLDOWN); |
321 | break; | 334 | break; |
322 | case EHCI_HCD_OMAP_MODE_UNKNOWN: | 335 | case OMAP_USBHS_PORT_MODE_UNUSED: |
323 | default: | 336 | default: |
324 | break; | 337 | break; |
325 | } | 338 | } |
326 | } | 339 | } |
327 | 340 | ||
328 | void __init usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata) | 341 | static void setup_ohci_io_mux(const enum usbhs_omap_port_mode *port_mode) |
329 | { | ||
330 | platform_device_add_data(&ehci_device, pdata, sizeof(*pdata)); | ||
331 | |||
332 | /* Setup Pin IO MUX for EHCI */ | ||
333 | if (cpu_is_omap34xx()) { | ||
334 | ehci_resources[0].start = OMAP34XX_EHCI_BASE; | ||
335 | ehci_resources[0].end = OMAP34XX_EHCI_BASE + SZ_1K - 1; | ||
336 | ehci_resources[1].start = OMAP34XX_UHH_CONFIG_BASE; | ||
337 | ehci_resources[1].end = OMAP34XX_UHH_CONFIG_BASE + SZ_1K - 1; | ||
338 | ehci_resources[2].start = OMAP34XX_USBTLL_BASE; | ||
339 | ehci_resources[2].end = OMAP34XX_USBTLL_BASE + SZ_4K - 1; | ||
340 | ehci_resources[3].start = INT_34XX_EHCI_IRQ; | ||
341 | setup_ehci_io_mux(pdata->port_mode); | ||
342 | } else if (cpu_is_omap44xx()) { | ||
343 | ehci_resources[0].start = OMAP44XX_HSUSB_EHCI_BASE; | ||
344 | ehci_resources[0].end = OMAP44XX_HSUSB_EHCI_BASE + SZ_1K - 1; | ||
345 | ehci_resources[1].start = OMAP44XX_UHH_CONFIG_BASE; | ||
346 | ehci_resources[1].end = OMAP44XX_UHH_CONFIG_BASE + SZ_2K - 1; | ||
347 | ehci_resources[2].start = OMAP44XX_USBTLL_BASE; | ||
348 | ehci_resources[2].end = OMAP44XX_USBTLL_BASE + SZ_4K - 1; | ||
349 | ehci_resources[3].start = OMAP44XX_IRQ_EHCI; | ||
350 | setup_4430ehci_io_mux(pdata->port_mode); | ||
351 | } | ||
352 | |||
353 | if (platform_device_register(&ehci_device) < 0) { | ||
354 | printk(KERN_ERR "Unable to register HS-USB (EHCI) device\n"); | ||
355 | return; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | #else | ||
360 | |||
361 | void __init usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata) | ||
362 | |||
363 | { | ||
364 | } | ||
365 | |||
366 | #endif /* CONFIG_USB_EHCI_HCD */ | ||
367 | |||
368 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) | ||
369 | |||
370 | static struct resource ohci_resources[] = { | ||
371 | { | ||
372 | .start = OMAP34XX_OHCI_BASE, | ||
373 | .end = OMAP34XX_OHCI_BASE + SZ_1K - 1, | ||
374 | .flags = IORESOURCE_MEM, | ||
375 | }, | ||
376 | { | ||
377 | .start = OMAP34XX_UHH_CONFIG_BASE, | ||
378 | .end = OMAP34XX_UHH_CONFIG_BASE + SZ_1K - 1, | ||
379 | .flags = IORESOURCE_MEM, | ||
380 | }, | ||
381 | { | ||
382 | .start = OMAP34XX_USBTLL_BASE, | ||
383 | .end = OMAP34XX_USBTLL_BASE + SZ_4K - 1, | ||
384 | .flags = IORESOURCE_MEM, | ||
385 | }, | ||
386 | { /* general IRQ */ | ||
387 | .start = INT_34XX_OHCI_IRQ, | ||
388 | .flags = IORESOURCE_IRQ, | ||
389 | } | ||
390 | }; | ||
391 | |||
392 | static u64 ohci_dmamask = DMA_BIT_MASK(32); | ||
393 | |||
394 | static struct platform_device ohci_device = { | ||
395 | .name = "ohci-omap3", | ||
396 | .id = 0, | ||
397 | .dev = { | ||
398 | .dma_mask = &ohci_dmamask, | ||
399 | .coherent_dma_mask = 0xffffffff, | ||
400 | }, | ||
401 | .num_resources = ARRAY_SIZE(ohci_resources), | ||
402 | .resource = ohci_resources, | ||
403 | }; | ||
404 | |||
405 | static void setup_ohci_io_mux(const enum ohci_omap3_port_mode *port_mode) | ||
406 | { | 342 | { |
407 | switch (port_mode[0]) { | 343 | switch (port_mode[0]) { |
408 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | 344 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: |
@@ -430,7 +366,7 @@ static void setup_ohci_io_mux(const enum ohci_omap3_port_mode *port_mode) | |||
430 | omap_mux_init_signal("mm1_txdat", | 366 | omap_mux_init_signal("mm1_txdat", |
431 | OMAP_PIN_INPUT_PULLDOWN); | 367 | OMAP_PIN_INPUT_PULLDOWN); |
432 | break; | 368 | break; |
433 | case OMAP_OHCI_PORT_MODE_UNUSED: | 369 | case OMAP_USBHS_PORT_MODE_UNUSED: |
434 | /* FALLTHROUGH */ | 370 | /* FALLTHROUGH */ |
435 | default: | 371 | default: |
436 | break; | 372 | break; |
@@ -461,7 +397,7 @@ static void setup_ohci_io_mux(const enum ohci_omap3_port_mode *port_mode) | |||
461 | omap_mux_init_signal("mm2_txdat", | 397 | omap_mux_init_signal("mm2_txdat", |
462 | OMAP_PIN_INPUT_PULLDOWN); | 398 | OMAP_PIN_INPUT_PULLDOWN); |
463 | break; | 399 | break; |
464 | case OMAP_OHCI_PORT_MODE_UNUSED: | 400 | case OMAP_USBHS_PORT_MODE_UNUSED: |
465 | /* FALLTHROUGH */ | 401 | /* FALLTHROUGH */ |
466 | default: | 402 | default: |
467 | break; | 403 | break; |
@@ -492,31 +428,147 @@ static void setup_ohci_io_mux(const enum ohci_omap3_port_mode *port_mode) | |||
492 | omap_mux_init_signal("mm3_txdat", | 428 | omap_mux_init_signal("mm3_txdat", |
493 | OMAP_PIN_INPUT_PULLDOWN); | 429 | OMAP_PIN_INPUT_PULLDOWN); |
494 | break; | 430 | break; |
495 | case OMAP_OHCI_PORT_MODE_UNUSED: | 431 | case OMAP_USBHS_PORT_MODE_UNUSED: |
496 | /* FALLTHROUGH */ | 432 | /* FALLTHROUGH */ |
497 | default: | 433 | default: |
498 | break; | 434 | break; |
499 | } | 435 | } |
500 | } | 436 | } |
501 | 437 | ||
502 | void __init usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata) | 438 | static void setup_4430ohci_io_mux(const enum usbhs_omap_port_mode *port_mode) |
503 | { | 439 | { |
504 | platform_device_add_data(&ohci_device, pdata, sizeof(*pdata)); | 440 | switch (port_mode[0]) { |
441 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | ||
442 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | ||
443 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | ||
444 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | ||
445 | omap_mux_init_signal("usbb1_mm_rxdp", | ||
446 | OMAP_PIN_INPUT_PULLDOWN); | ||
447 | omap_mux_init_signal("usbb1_mm_rxdm", | ||
448 | OMAP_PIN_INPUT_PULLDOWN); | ||
505 | 449 | ||
506 | /* Setup Pin IO MUX for OHCI */ | 450 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: |
507 | if (cpu_is_omap34xx()) | 451 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: |
452 | omap_mux_init_signal("usbb1_mm_rxrcv", | ||
453 | OMAP_PIN_INPUT_PULLDOWN); | ||
454 | |||
455 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | ||
456 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | ||
457 | omap_mux_init_signal("usbb1_mm_txen", | ||
458 | OMAP_PIN_INPUT_PULLDOWN); | ||
459 | |||
460 | |||
461 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | ||
462 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | ||
463 | omap_mux_init_signal("usbb1_mm_txdat", | ||
464 | OMAP_PIN_INPUT_PULLDOWN); | ||
465 | omap_mux_init_signal("usbb1_mm_txse0", | ||
466 | OMAP_PIN_INPUT_PULLDOWN); | ||
467 | break; | ||
468 | |||
469 | case OMAP_USBHS_PORT_MODE_UNUSED: | ||
470 | default: | ||
471 | break; | ||
472 | } | ||
473 | |||
474 | switch (port_mode[1]) { | ||
475 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | ||
476 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | ||
477 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | ||
478 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | ||
479 | omap_mux_init_signal("usbb2_mm_rxdp", | ||
480 | OMAP_PIN_INPUT_PULLDOWN); | ||
481 | omap_mux_init_signal("usbb2_mm_rxdm", | ||
482 | OMAP_PIN_INPUT_PULLDOWN); | ||
483 | |||
484 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | ||
485 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | ||
486 | omap_mux_init_signal("usbb2_mm_rxrcv", | ||
487 | OMAP_PIN_INPUT_PULLDOWN); | ||
488 | |||
489 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | ||
490 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | ||
491 | omap_mux_init_signal("usbb2_mm_txen", | ||
492 | OMAP_PIN_INPUT_PULLDOWN); | ||
493 | |||
494 | |||
495 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | ||
496 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | ||
497 | omap_mux_init_signal("usbb2_mm_txdat", | ||
498 | OMAP_PIN_INPUT_PULLDOWN); | ||
499 | omap_mux_init_signal("usbb2_mm_txse0", | ||
500 | OMAP_PIN_INPUT_PULLDOWN); | ||
501 | break; | ||
502 | |||
503 | case OMAP_USBHS_PORT_MODE_UNUSED: | ||
504 | default: | ||
505 | break; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | void __init usbhs_init(const struct usbhs_omap_board_data *pdata) | ||
510 | { | ||
511 | int i; | ||
512 | |||
513 | for (i = 0; i < OMAP3_HS_USB_PORTS; i++) { | ||
514 | usbhs_data.port_mode[i] = pdata->port_mode[i]; | ||
515 | ohci_data.port_mode[i] = pdata->port_mode[i]; | ||
516 | ehci_data.port_mode[i] = pdata->port_mode[i]; | ||
517 | ehci_data.reset_gpio_port[i] = pdata->reset_gpio_port[i]; | ||
518 | ehci_data.regulator[i] = pdata->regulator[i]; | ||
519 | } | ||
520 | ehci_data.phy_reset = pdata->phy_reset; | ||
521 | ohci_data.es2_compatibility = pdata->es2_compatibility; | ||
522 | usbhs_data.ehci_data = &ehci_data; | ||
523 | usbhs_data.ohci_data = &ohci_data; | ||
524 | |||
525 | if (cpu_is_omap34xx()) { | ||
526 | usbhs_resources[0].start = OMAP34XX_UHH_CONFIG_BASE; | ||
527 | usbhs_resources[0].end = OMAP34XX_UHH_CONFIG_BASE + SZ_1K - 1; | ||
528 | usbhs_resources[1].start = OMAP34XX_USBTLL_BASE; | ||
529 | usbhs_resources[1].end = OMAP34XX_USBTLL_BASE + SZ_4K - 1; | ||
530 | usbhs_resources[2].start = OMAP34XX_EHCI_BASE; | ||
531 | usbhs_resources[2].end = OMAP34XX_EHCI_BASE + SZ_1K - 1; | ||
532 | usbhs_resources[3].start = INT_34XX_EHCI_IRQ; | ||
533 | usbhs_resources[4].start = OMAP34XX_OHCI_BASE; | ||
534 | usbhs_resources[4].end = OMAP34XX_OHCI_BASE + SZ_1K - 1; | ||
535 | usbhs_resources[5].start = INT_34XX_OHCI_IRQ; | ||
536 | setup_ehci_io_mux(pdata->port_mode); | ||
508 | setup_ohci_io_mux(pdata->port_mode); | 537 | setup_ohci_io_mux(pdata->port_mode); |
538 | } else if (cpu_is_omap44xx()) { | ||
539 | usbhs_resources[0].start = OMAP44XX_UHH_CONFIG_BASE; | ||
540 | usbhs_resources[0].end = OMAP44XX_UHH_CONFIG_BASE + SZ_1K - 1; | ||
541 | usbhs_resources[1].start = OMAP44XX_USBTLL_BASE; | ||
542 | usbhs_resources[1].end = OMAP44XX_USBTLL_BASE + SZ_4K - 1; | ||
543 | usbhs_resources[2].start = OMAP44XX_HSUSB_EHCI_BASE; | ||
544 | usbhs_resources[2].end = OMAP44XX_HSUSB_EHCI_BASE + SZ_1K - 1; | ||
545 | usbhs_resources[3].start = OMAP44XX_IRQ_EHCI; | ||
546 | usbhs_resources[4].start = OMAP44XX_HSUSB_OHCI_BASE; | ||
547 | usbhs_resources[4].end = OMAP44XX_HSUSB_OHCI_BASE + SZ_1K - 1; | ||
548 | usbhs_resources[5].start = OMAP44XX_IRQ_OHCI; | ||
549 | setup_4430ehci_io_mux(pdata->port_mode); | ||
550 | setup_4430ohci_io_mux(pdata->port_mode); | ||
551 | } | ||
509 | 552 | ||
510 | if (platform_device_register(&ohci_device) < 0) { | 553 | if (platform_device_add_data(&usbhs_device, |
511 | pr_err("Unable to register FS-USB (OHCI) device\n"); | 554 | &usbhs_data, sizeof(usbhs_data)) < 0) { |
512 | return; | 555 | printk(KERN_ERR "USBHS platform_device_add_data failed\n"); |
556 | goto init_end; | ||
513 | } | 557 | } |
558 | |||
559 | if (platform_device_register(&usbhs_device) < 0) | ||
560 | printk(KERN_ERR "USBHS platform_device_register failed\n"); | ||
561 | |||
562 | init_end: | ||
563 | return; | ||
514 | } | 564 | } |
515 | 565 | ||
516 | #else | 566 | #else |
517 | 567 | ||
518 | void __init usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata) | 568 | void __init usbhs_init(const struct usbhs_omap_board_data *pdata) |
519 | { | 569 | { |
520 | } | 570 | } |
521 | 571 | ||
522 | #endif /* CONFIG_USB_OHCI_HCD */ | 572 | #endif |
573 | |||
574 | |||
diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c index 5298949d4b11..241fc94b4116 100644 --- a/arch/arm/mach-omap2/usb-musb.c +++ b/arch/arm/mach-omap2/usb-musb.c | |||
@@ -214,6 +214,10 @@ void __init usb_musb_init(struct omap_musb_board_data *board_data) | |||
214 | 214 | ||
215 | if (platform_device_register(&musb_device) < 0) | 215 | if (platform_device_register(&musb_device) < 0) |
216 | printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n"); | 216 | printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n"); |
217 | |||
218 | if (cpu_is_omap44xx()) | ||
219 | omap4430_phy_init(dev); | ||
220 | |||
217 | } | 221 | } |
218 | 222 | ||
219 | #else | 223 | #else |
diff --git a/arch/arm/mach-s3c2410/mach-h1940.c b/arch/arm/mach-s3c2410/mach-h1940.c index 1a81fe12ccd7..1e93f176c1de 100644 --- a/arch/arm/mach-s3c2410/mach-h1940.c +++ b/arch/arm/mach-s3c2410/mach-h1940.c | |||
@@ -162,29 +162,10 @@ struct gpio_chip h1940_latch_gpiochip = { | |||
162 | .get = h1940_gpiolib_latch_get, | 162 | .get = h1940_gpiolib_latch_get, |
163 | }; | 163 | }; |
164 | 164 | ||
165 | static void h1940_udc_pullup(enum s3c2410_udc_cmd_e cmd) | ||
166 | { | ||
167 | printk(KERN_DEBUG "udc: pullup(%d)\n",cmd); | ||
168 | |||
169 | switch (cmd) | ||
170 | { | ||
171 | case S3C2410_UDC_P_ENABLE : | ||
172 | gpio_set_value(H1940_LATCH_USB_DP, 1); | ||
173 | break; | ||
174 | case S3C2410_UDC_P_DISABLE : | ||
175 | gpio_set_value(H1940_LATCH_USB_DP, 0); | ||
176 | break; | ||
177 | case S3C2410_UDC_P_RESET : | ||
178 | break; | ||
179 | default: | ||
180 | break; | ||
181 | } | ||
182 | } | ||
183 | |||
184 | static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = { | 165 | static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = { |
185 | .udc_command = h1940_udc_pullup, | ||
186 | .vbus_pin = S3C2410_GPG(5), | 166 | .vbus_pin = S3C2410_GPG(5), |
187 | .vbus_pin_inverted = 1, | 167 | .vbus_pin_inverted = 1, |
168 | .pullup_pin = H1940_LATCH_USB_DP, | ||
188 | }; | 169 | }; |
189 | 170 | ||
190 | static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = { | 171 | static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = { |
@@ -475,9 +456,6 @@ static void __init h1940_init(void) | |||
475 | gpio_direction_output(H1940_LATCH_LCD_P4, 0); | 456 | gpio_direction_output(H1940_LATCH_LCD_P4, 0); |
476 | gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0); | 457 | gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0); |
477 | 458 | ||
478 | gpio_request(H1940_LATCH_USB_DP, "USB pullup"); | ||
479 | gpio_direction_output(H1940_LATCH_USB_DP, 0); | ||
480 | |||
481 | gpio_request(H1940_LATCH_SD_POWER, "SD power"); | 459 | gpio_request(H1940_LATCH_SD_POWER, "SD power"); |
482 | gpio_direction_output(H1940_LATCH_SD_POWER, 0); | 460 | gpio_direction_output(H1940_LATCH_SD_POWER, 0); |
483 | 461 | ||
diff --git a/arch/arm/mach-s3c2410/mach-n30.c b/arch/arm/mach-s3c2410/mach-n30.c index 271b9aa6d40a..66f44440d5d3 100644 --- a/arch/arm/mach-s3c2410/mach-n30.c +++ b/arch/arm/mach-s3c2410/mach-n30.c | |||
@@ -84,26 +84,10 @@ static struct s3c2410_uartcfg n30_uartcfgs[] = { | |||
84 | }, | 84 | }, |
85 | }; | 85 | }; |
86 | 86 | ||
87 | static void n30_udc_pullup(enum s3c2410_udc_cmd_e cmd) | ||
88 | { | ||
89 | switch (cmd) { | ||
90 | case S3C2410_UDC_P_ENABLE : | ||
91 | gpio_set_value(S3C2410_GPB(3), 1); | ||
92 | break; | ||
93 | case S3C2410_UDC_P_DISABLE : | ||
94 | gpio_set_value(S3C2410_GPB(3), 0); | ||
95 | break; | ||
96 | case S3C2410_UDC_P_RESET : | ||
97 | break; | ||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | static struct s3c2410_udc_mach_info n30_udc_cfg __initdata = { | 87 | static struct s3c2410_udc_mach_info n30_udc_cfg __initdata = { |
104 | .udc_command = n30_udc_pullup, | ||
105 | .vbus_pin = S3C2410_GPG(1), | 88 | .vbus_pin = S3C2410_GPG(1), |
106 | .vbus_pin_inverted = 0, | 89 | .vbus_pin_inverted = 0, |
90 | .pullup_pin = S3C2410_GPB(3), | ||
107 | }; | 91 | }; |
108 | 92 | ||
109 | static struct gpio_keys_button n30_buttons[] = { | 93 | static struct gpio_keys_button n30_buttons[] = { |
@@ -596,9 +580,6 @@ static void __init n30_init(void) | |||
596 | 580 | ||
597 | platform_add_devices(n35_devices, ARRAY_SIZE(n35_devices)); | 581 | platform_add_devices(n35_devices, ARRAY_SIZE(n35_devices)); |
598 | } | 582 | } |
599 | |||
600 | WARN_ON(gpio_request(S3C2410_GPB(3), "udc pup")); | ||
601 | gpio_direction_output(S3C2410_GPB(3), 0); | ||
602 | } | 583 | } |
603 | 584 | ||
604 | MACHINE_START(N30, "Acer-N30") | 585 | MACHINE_START(N30, "Acer-N30") |
diff --git a/arch/arm/mach-s3c2412/mach-smdk2413.c b/arch/arm/mach-s3c2412/mach-smdk2413.c index 8e5758bdd666..834cfb61bcfe 100644 --- a/arch/arm/mach-s3c2412/mach-smdk2413.c +++ b/arch/arm/mach-s3c2412/mach-smdk2413.c | |||
@@ -78,28 +78,9 @@ static struct s3c2410_uartcfg smdk2413_uartcfgs[] __initdata = { | |||
78 | } | 78 | } |
79 | }; | 79 | }; |
80 | 80 | ||
81 | static void smdk2413_udc_pullup(enum s3c2410_udc_cmd_e cmd) | ||
82 | { | ||
83 | printk(KERN_DEBUG "udc: pullup(%d)\n",cmd); | ||
84 | |||
85 | switch (cmd) | ||
86 | { | ||
87 | case S3C2410_UDC_P_ENABLE : | ||
88 | gpio_set_value(S3C2410_GPF(2), 1); | ||
89 | break; | ||
90 | case S3C2410_UDC_P_DISABLE : | ||
91 | gpio_set_value(S3C2410_GPF(2), 0); | ||
92 | break; | ||
93 | case S3C2410_UDC_P_RESET : | ||
94 | break; | ||
95 | default: | ||
96 | break; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | 81 | ||
101 | static struct s3c2410_udc_mach_info smdk2413_udc_cfg __initdata = { | 82 | static struct s3c2410_udc_mach_info smdk2413_udc_cfg __initdata = { |
102 | .udc_command = smdk2413_udc_pullup, | 83 | .pullup_pin = S3C2410_GPF(2), |
103 | }; | 84 | }; |
104 | 85 | ||
105 | 86 | ||
@@ -133,9 +114,6 @@ static void __init smdk2413_machine_init(void) | |||
133 | { /* Turn off suspend on both USB ports, and switch the | 114 | { /* Turn off suspend on both USB ports, and switch the |
134 | * selectable USB port to USB device mode. */ | 115 | * selectable USB port to USB device mode. */ |
135 | 116 | ||
136 | WARN_ON(gpio_request(S3C2410_GPF(2), "udc pull")); | ||
137 | gpio_direction_output(S3C2410_GPF(2), 0); | ||
138 | |||
139 | s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST | | 117 | s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST | |
140 | S3C2410_MISCCR_USBSUSPND0 | | 118 | S3C2410_MISCCR_USBSUSPND0 | |
141 | S3C2410_MISCCR_USBSUSPND1, 0x0); | 119 | S3C2410_MISCCR_USBSUSPND1, 0x0); |
diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c index 9f2c14ec7181..37405d9abe32 100644 --- a/arch/arm/mach-s3c2440/mach-gta02.c +++ b/arch/arm/mach-s3c2440/mach-gta02.c | |||
@@ -455,28 +455,10 @@ static struct s3c2410_platform_nand __initdata gta02_nand_info = { | |||
455 | }; | 455 | }; |
456 | 456 | ||
457 | 457 | ||
458 | static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd) | ||
459 | { | ||
460 | switch (cmd) { | ||
461 | case S3C2410_UDC_P_ENABLE: | ||
462 | pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__); | ||
463 | gpio_direction_output(GTA02_GPIO_USB_PULLUP, 1); | ||
464 | break; | ||
465 | case S3C2410_UDC_P_DISABLE: | ||
466 | pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__); | ||
467 | gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0); | ||
468 | break; | ||
469 | case S3C2410_UDC_P_RESET: | ||
470 | pr_debug("%s S3C2410_UDC_P_RESET\n", __func__); | ||
471 | /* FIXME: Do something here. */ | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /* Get PMU to set USB current limit accordingly. */ | 458 | /* Get PMU to set USB current limit accordingly. */ |
476 | static struct s3c2410_udc_mach_info gta02_udc_cfg = { | 459 | static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = { |
477 | .vbus_draw = gta02_udc_vbus_draw, | 460 | .vbus_draw = gta02_udc_vbus_draw, |
478 | .udc_command = gta02_udc_command, | 461 | .pullup_pin = GTA02_GPIO_USB_PULLUP, |
479 | |||
480 | }; | 462 | }; |
481 | 463 | ||
482 | /* USB */ | 464 | /* USB */ |
diff --git a/arch/arm/mach-s3c2440/mach-mini2440.c b/arch/arm/mach-s3c2440/mach-mini2440.c index f62bb4c793bd..d80f129bca94 100644 --- a/arch/arm/mach-s3c2440/mach-mini2440.c +++ b/arch/arm/mach-s3c2440/mach-mini2440.c | |||
@@ -97,26 +97,8 @@ static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = { | |||
97 | 97 | ||
98 | /* USB device UDC support */ | 98 | /* USB device UDC support */ |
99 | 99 | ||
100 | static void mini2440_udc_pullup(enum s3c2410_udc_cmd_e cmd) | ||
101 | { | ||
102 | pr_debug("udc: pullup(%d)\n", cmd); | ||
103 | |||
104 | switch (cmd) { | ||
105 | case S3C2410_UDC_P_ENABLE : | ||
106 | gpio_set_value(S3C2410_GPC(5), 1); | ||
107 | break; | ||
108 | case S3C2410_UDC_P_DISABLE : | ||
109 | gpio_set_value(S3C2410_GPC(5), 0); | ||
110 | break; | ||
111 | case S3C2410_UDC_P_RESET : | ||
112 | break; | ||
113 | default: | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = { | 100 | static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = { |
119 | .udc_command = mini2440_udc_pullup, | 101 | .pullup_pin = S3C2410_GPC(5), |
120 | }; | 102 | }; |
121 | 103 | ||
122 | 104 | ||
@@ -644,10 +626,6 @@ static void __init mini2440_init(void) | |||
644 | s3c2410_gpio_setpin(S3C2410_GPB(1), 0); | 626 | s3c2410_gpio_setpin(S3C2410_GPB(1), 0); |
645 | s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPIO_INPUT); | 627 | s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPIO_INPUT); |
646 | 628 | ||
647 | /* Make sure the D+ pullup pin is output */ | ||
648 | WARN_ON(gpio_request(S3C2410_GPC(5), "udc pup")); | ||
649 | gpio_direction_output(S3C2410_GPC(5), 0); | ||
650 | |||
651 | /* mark the key as input, without pullups (there is one on the board) */ | 629 | /* mark the key as input, without pullups (there is one on the board) */ |
652 | for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) { | 630 | for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) { |
653 | s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP); | 631 | s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP); |
diff --git a/arch/arm/mach-s3c2440/mach-rx1950.c b/arch/arm/mach-s3c2440/mach-rx1950.c index eab6ae50683c..86bbc233b31c 100644 --- a/arch/arm/mach-s3c2440/mach-rx1950.c +++ b/arch/arm/mach-s3c2440/mach-rx1950.c | |||
@@ -566,26 +566,10 @@ static struct s3c2410_platform_nand rx1950_nand_info = { | |||
566 | .sets = rx1950_nand_sets, | 566 | .sets = rx1950_nand_sets, |
567 | }; | 567 | }; |
568 | 568 | ||
569 | static void rx1950_udc_pullup(enum s3c2410_udc_cmd_e cmd) | ||
570 | { | ||
571 | switch (cmd) { | ||
572 | case S3C2410_UDC_P_ENABLE: | ||
573 | gpio_direction_output(S3C2410_GPJ(5), 1); | ||
574 | break; | ||
575 | case S3C2410_UDC_P_DISABLE: | ||
576 | gpio_direction_output(S3C2410_GPJ(5), 0); | ||
577 | break; | ||
578 | case S3C2410_UDC_P_RESET: | ||
579 | break; | ||
580 | default: | ||
581 | break; | ||
582 | } | ||
583 | } | ||
584 | |||
585 | static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = { | 569 | static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = { |
586 | .udc_command = rx1950_udc_pullup, | ||
587 | .vbus_pin = S3C2410_GPG(5), | 570 | .vbus_pin = S3C2410_GPG(5), |
588 | .vbus_pin_inverted = 1, | 571 | .vbus_pin_inverted = 1, |
572 | .pullup_pin = S3C2410_GPJ(5), | ||
589 | }; | 573 | }; |
590 | 574 | ||
591 | static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = { | 575 | static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = { |
@@ -750,9 +734,6 @@ static void __init rx1950_init_machine(void) | |||
750 | S3C2410_MISCCR_USBSUSPND0 | | 734 | S3C2410_MISCCR_USBSUSPND0 | |
751 | S3C2410_MISCCR_USBSUSPND1, 0x0); | 735 | S3C2410_MISCCR_USBSUSPND1, 0x0); |
752 | 736 | ||
753 | WARN_ON(gpio_request(S3C2410_GPJ(5), "UDC pullup")); | ||
754 | gpio_direction_output(S3C2410_GPJ(5), 0); | ||
755 | |||
756 | /* mmc power is disabled by default */ | 737 | /* mmc power is disabled by default */ |
757 | WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power")); | 738 | WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power")); |
758 | gpio_direction_output(S3C2410_GPJ(1), 0); | 739 | gpio_direction_output(S3C2410_GPJ(1), 0); |
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig index b94e52df0d8e..622a9ec1ff08 100644 --- a/arch/arm/mach-tegra/Kconfig +++ b/arch/arm/mach-tegra/Kconfig | |||
@@ -10,6 +10,9 @@ config ARCH_TEGRA_2x_SOC | |||
10 | select CPU_V7 | 10 | select CPU_V7 |
11 | select ARM_GIC | 11 | select ARM_GIC |
12 | select ARCH_REQUIRE_GPIOLIB | 12 | select ARCH_REQUIRE_GPIOLIB |
13 | select USB_ARCH_HAS_EHCI if USB_SUPPORT | ||
14 | select USB_ULPI if USB_SUPPORT | ||
15 | select USB_ULPI_VIEWPORT if USB_SUPPORT | ||
13 | help | 16 | help |
14 | Support for NVIDIA Tegra AP20 and T20 processors, based on the | 17 | Support for NVIDIA Tegra AP20 and T20 processors, based on the |
15 | ARM CortexA9MP CPU and the ARM PL310 L2 cache controller | 18 | ARM CortexA9MP CPU and the ARM PL310 L2 cache controller |
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile index 9bf39fa34d85..9f7a7e1e0c38 100644 --- a/arch/arm/mach-tegra/Makefile +++ b/arch/arm/mach-tegra/Makefile | |||
@@ -17,6 +17,7 @@ obj-$(CONFIG_HOTPLUG_CPU) += hotplug.o | |||
17 | obj-$(CONFIG_TEGRA_SYSTEM_DMA) += dma.o | 17 | obj-$(CONFIG_TEGRA_SYSTEM_DMA) += dma.o |
18 | obj-$(CONFIG_CPU_FREQ) += cpu-tegra.o | 18 | obj-$(CONFIG_CPU_FREQ) += cpu-tegra.o |
19 | obj-$(CONFIG_TEGRA_PCI) += pcie.o | 19 | obj-$(CONFIG_TEGRA_PCI) += pcie.o |
20 | obj-$(CONFIG_USB_SUPPORT) += usb_phy.o | ||
20 | 21 | ||
21 | obj-${CONFIG_MACH_HARMONY} += board-harmony.o | 22 | obj-${CONFIG_MACH_HARMONY} += board-harmony.o |
22 | obj-${CONFIG_MACH_HARMONY} += board-harmony-pinmux.o | 23 | obj-${CONFIG_MACH_HARMONY} += board-harmony-pinmux.o |
diff --git a/arch/arm/mach-tegra/include/mach/usb_phy.h b/arch/arm/mach-tegra/include/mach/usb_phy.h new file mode 100644 index 000000000000..d4b8f9e298a8 --- /dev/null +++ b/arch/arm/mach-tegra/include/mach/usb_phy.h | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-tegra/include/mach/usb_phy.h | ||
3 | * | ||
4 | * Copyright (C) 2010 Google, Inc. | ||
5 | * | ||
6 | * This software is licensed under the terms of the GNU General Public | ||
7 | * License version 2, as published by the Free Software Foundation, and | ||
8 | * may be copied, distributed, and modified under those terms. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #ifndef __MACH_USB_PHY_H | ||
18 | #define __MACH_USB_PHY_H | ||
19 | |||
20 | #include <linux/clk.h> | ||
21 | #include <linux/usb/otg.h> | ||
22 | |||
23 | struct tegra_utmip_config { | ||
24 | u8 hssync_start_delay; | ||
25 | u8 elastic_limit; | ||
26 | u8 idle_wait_delay; | ||
27 | u8 term_range_adj; | ||
28 | u8 xcvr_setup; | ||
29 | u8 xcvr_lsfslew; | ||
30 | u8 xcvr_lsrslew; | ||
31 | }; | ||
32 | |||
33 | struct tegra_ulpi_config { | ||
34 | int reset_gpio; | ||
35 | const char *clk; | ||
36 | }; | ||
37 | |||
38 | enum tegra_usb_phy_port_speed { | ||
39 | TEGRA_USB_PHY_PORT_SPEED_FULL = 0, | ||
40 | TEGRA_USB_PHY_PORT_SPEED_LOW, | ||
41 | TEGRA_USB_PHY_PORT_SPEED_HIGH, | ||
42 | }; | ||
43 | |||
44 | enum tegra_usb_phy_mode { | ||
45 | TEGRA_USB_PHY_MODE_DEVICE, | ||
46 | TEGRA_USB_PHY_MODE_HOST, | ||
47 | }; | ||
48 | |||
49 | struct tegra_xtal_freq; | ||
50 | |||
51 | struct tegra_usb_phy { | ||
52 | int instance; | ||
53 | const struct tegra_xtal_freq *freq; | ||
54 | void __iomem *regs; | ||
55 | void __iomem *pad_regs; | ||
56 | struct clk *clk; | ||
57 | struct clk *pll_u; | ||
58 | struct clk *pad_clk; | ||
59 | enum tegra_usb_phy_mode mode; | ||
60 | void *config; | ||
61 | struct otg_transceiver *ulpi; | ||
62 | }; | ||
63 | |||
64 | struct tegra_usb_phy *tegra_usb_phy_open(int instance, void __iomem *regs, | ||
65 | void *config, enum tegra_usb_phy_mode phy_mode); | ||
66 | |||
67 | int tegra_usb_phy_power_on(struct tegra_usb_phy *phy); | ||
68 | |||
69 | void tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy); | ||
70 | |||
71 | void tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy); | ||
72 | |||
73 | void tegra_usb_phy_power_off(struct tegra_usb_phy *phy); | ||
74 | |||
75 | void tegra_usb_phy_preresume(struct tegra_usb_phy *phy); | ||
76 | |||
77 | void tegra_usb_phy_postresume(struct tegra_usb_phy *phy); | ||
78 | |||
79 | void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy, | ||
80 | enum tegra_usb_phy_port_speed port_speed); | ||
81 | |||
82 | void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy); | ||
83 | |||
84 | void tegra_usb_phy_close(struct tegra_usb_phy *phy); | ||
85 | |||
86 | #endif /* __MACH_USB_PHY_H */ | ||
diff --git a/arch/arm/mach-tegra/usb_phy.c b/arch/arm/mach-tegra/usb_phy.c new file mode 100644 index 000000000000..88081bb3ec52 --- /dev/null +++ b/arch/arm/mach-tegra/usb_phy.c | |||
@@ -0,0 +1,795 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-tegra/usb_phy.c | ||
3 | * | ||
4 | * Copyright (C) 2010 Google, Inc. | ||
5 | * | ||
6 | * Author: | ||
7 | * Erik Gilling <konkers@google.com> | ||
8 | * Benoit Goby <benoit@android.com> | ||
9 | * | ||
10 | * This software is licensed under the terms of the GNU General Public | ||
11 | * License version 2, as published by the Free Software Foundation, and | ||
12 | * may be copied, distributed, and modified under those terms. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <linux/resource.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/err.h> | ||
25 | #include <linux/platform_device.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/usb/otg.h> | ||
29 | #include <linux/usb/ulpi.h> | ||
30 | #include <asm/mach-types.h> | ||
31 | #include <mach/usb_phy.h> | ||
32 | #include <mach/iomap.h> | ||
33 | |||
34 | #define ULPI_VIEWPORT 0x170 | ||
35 | |||
36 | #define USB_PORTSC1 0x184 | ||
37 | #define USB_PORTSC1_PTS(x) (((x) & 0x3) << 30) | ||
38 | #define USB_PORTSC1_PSPD(x) (((x) & 0x3) << 26) | ||
39 | #define USB_PORTSC1_PHCD (1 << 23) | ||
40 | #define USB_PORTSC1_WKOC (1 << 22) | ||
41 | #define USB_PORTSC1_WKDS (1 << 21) | ||
42 | #define USB_PORTSC1_WKCN (1 << 20) | ||
43 | #define USB_PORTSC1_PTC(x) (((x) & 0xf) << 16) | ||
44 | #define USB_PORTSC1_PP (1 << 12) | ||
45 | #define USB_PORTSC1_SUSP (1 << 7) | ||
46 | #define USB_PORTSC1_PE (1 << 2) | ||
47 | #define USB_PORTSC1_CCS (1 << 0) | ||
48 | |||
49 | #define USB_SUSP_CTRL 0x400 | ||
50 | #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3) | ||
51 | #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4) | ||
52 | #define USB_SUSP_CLR (1 << 5) | ||
53 | #define USB_PHY_CLK_VALID (1 << 7) | ||
54 | #define UTMIP_RESET (1 << 11) | ||
55 | #define UHSIC_RESET (1 << 11) | ||
56 | #define UTMIP_PHY_ENABLE (1 << 12) | ||
57 | #define ULPI_PHY_ENABLE (1 << 13) | ||
58 | #define USB_SUSP_SET (1 << 14) | ||
59 | #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16) | ||
60 | |||
61 | #define USB1_LEGACY_CTRL 0x410 | ||
62 | #define USB1_NO_LEGACY_MODE (1 << 0) | ||
63 | #define USB1_VBUS_SENSE_CTL_MASK (3 << 1) | ||
64 | #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1) | ||
65 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \ | ||
66 | (1 << 1) | ||
67 | #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1) | ||
68 | #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1) | ||
69 | |||
70 | #define ULPI_TIMING_CTRL_0 0x424 | ||
71 | #define ULPI_OUTPUT_PINMUX_BYP (1 << 10) | ||
72 | #define ULPI_CLKOUT_PINMUX_BYP (1 << 11) | ||
73 | |||
74 | #define ULPI_TIMING_CTRL_1 0x428 | ||
75 | #define ULPI_DATA_TRIMMER_LOAD (1 << 0) | ||
76 | #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1) | ||
77 | #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16) | ||
78 | #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17) | ||
79 | #define ULPI_DIR_TRIMMER_LOAD (1 << 24) | ||
80 | #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25) | ||
81 | |||
82 | #define UTMIP_PLL_CFG1 0x804 | ||
83 | #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) | ||
84 | #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) | ||
85 | |||
86 | #define UTMIP_XCVR_CFG0 0x808 | ||
87 | #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0) | ||
88 | #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8) | ||
89 | #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10) | ||
90 | #define UTMIP_FORCE_PD_POWERDOWN (1 << 14) | ||
91 | #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16) | ||
92 | #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18) | ||
93 | #define UTMIP_XCVR_HSSLEW_MSB(x) (((x) & 0x7f) << 25) | ||
94 | |||
95 | #define UTMIP_BIAS_CFG0 0x80c | ||
96 | #define UTMIP_OTGPD (1 << 11) | ||
97 | #define UTMIP_BIASPD (1 << 10) | ||
98 | |||
99 | #define UTMIP_HSRX_CFG0 0x810 | ||
100 | #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10) | ||
101 | #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15) | ||
102 | |||
103 | #define UTMIP_HSRX_CFG1 0x814 | ||
104 | #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1) | ||
105 | |||
106 | #define UTMIP_TX_CFG0 0x820 | ||
107 | #define UTMIP_FS_PREABMLE_J (1 << 19) | ||
108 | #define UTMIP_HS_DISCON_DISABLE (1 << 8) | ||
109 | |||
110 | #define UTMIP_MISC_CFG0 0x824 | ||
111 | #define UTMIP_DPDM_OBSERVE (1 << 26) | ||
112 | #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27) | ||
113 | #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf) | ||
114 | #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe) | ||
115 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd) | ||
116 | #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc) | ||
117 | #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22) | ||
118 | |||
119 | #define UTMIP_MISC_CFG1 0x828 | ||
120 | #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18) | ||
121 | #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6) | ||
122 | |||
123 | #define UTMIP_DEBOUNCE_CFG0 0x82c | ||
124 | #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0) | ||
125 | |||
126 | #define UTMIP_BAT_CHRG_CFG0 0x830 | ||
127 | #define UTMIP_PD_CHRG (1 << 0) | ||
128 | |||
129 | #define UTMIP_SPARE_CFG0 0x834 | ||
130 | #define FUSE_SETUP_SEL (1 << 3) | ||
131 | |||
132 | #define UTMIP_XCVR_CFG1 0x838 | ||
133 | #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0) | ||
134 | #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2) | ||
135 | #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4) | ||
136 | #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18) | ||
137 | |||
138 | #define UTMIP_BIAS_CFG1 0x83c | ||
139 | #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3) | ||
140 | |||
141 | static DEFINE_SPINLOCK(utmip_pad_lock); | ||
142 | static int utmip_pad_count; | ||
143 | |||
144 | struct tegra_xtal_freq { | ||
145 | int freq; | ||
146 | u8 enable_delay; | ||
147 | u8 stable_count; | ||
148 | u8 active_delay; | ||
149 | u8 xtal_freq_count; | ||
150 | u16 debounce; | ||
151 | }; | ||
152 | |||
153 | static const struct tegra_xtal_freq tegra_freq_table[] = { | ||
154 | { | ||
155 | .freq = 12000000, | ||
156 | .enable_delay = 0x02, | ||
157 | .stable_count = 0x2F, | ||
158 | .active_delay = 0x04, | ||
159 | .xtal_freq_count = 0x76, | ||
160 | .debounce = 0x7530, | ||
161 | }, | ||
162 | { | ||
163 | .freq = 13000000, | ||
164 | .enable_delay = 0x02, | ||
165 | .stable_count = 0x33, | ||
166 | .active_delay = 0x05, | ||
167 | .xtal_freq_count = 0x7F, | ||
168 | .debounce = 0x7EF4, | ||
169 | }, | ||
170 | { | ||
171 | .freq = 19200000, | ||
172 | .enable_delay = 0x03, | ||
173 | .stable_count = 0x4B, | ||
174 | .active_delay = 0x06, | ||
175 | .xtal_freq_count = 0xBB, | ||
176 | .debounce = 0xBB80, | ||
177 | }, | ||
178 | { | ||
179 | .freq = 26000000, | ||
180 | .enable_delay = 0x04, | ||
181 | .stable_count = 0x66, | ||
182 | .active_delay = 0x09, | ||
183 | .xtal_freq_count = 0xFE, | ||
184 | .debounce = 0xFDE8, | ||
185 | }, | ||
186 | }; | ||
187 | |||
188 | static struct tegra_utmip_config utmip_default[] = { | ||
189 | [0] = { | ||
190 | .hssync_start_delay = 9, | ||
191 | .idle_wait_delay = 17, | ||
192 | .elastic_limit = 16, | ||
193 | .term_range_adj = 6, | ||
194 | .xcvr_setup = 9, | ||
195 | .xcvr_lsfslew = 1, | ||
196 | .xcvr_lsrslew = 1, | ||
197 | }, | ||
198 | [2] = { | ||
199 | .hssync_start_delay = 9, | ||
200 | .idle_wait_delay = 17, | ||
201 | .elastic_limit = 16, | ||
202 | .term_range_adj = 6, | ||
203 | .xcvr_setup = 9, | ||
204 | .xcvr_lsfslew = 2, | ||
205 | .xcvr_lsrslew = 2, | ||
206 | }, | ||
207 | }; | ||
208 | |||
209 | static inline bool phy_is_ulpi(struct tegra_usb_phy *phy) | ||
210 | { | ||
211 | return (phy->instance == 1); | ||
212 | } | ||
213 | |||
214 | static int utmip_pad_open(struct tegra_usb_phy *phy) | ||
215 | { | ||
216 | phy->pad_clk = clk_get_sys("utmip-pad", NULL); | ||
217 | if (IS_ERR(phy->pad_clk)) { | ||
218 | pr_err("%s: can't get utmip pad clock\n", __func__); | ||
219 | return PTR_ERR(phy->pad_clk); | ||
220 | } | ||
221 | |||
222 | if (phy->instance == 0) { | ||
223 | phy->pad_regs = phy->regs; | ||
224 | } else { | ||
225 | phy->pad_regs = ioremap(TEGRA_USB_BASE, TEGRA_USB_SIZE); | ||
226 | if (!phy->pad_regs) { | ||
227 | pr_err("%s: can't remap usb registers\n", __func__); | ||
228 | clk_put(phy->pad_clk); | ||
229 | return -ENOMEM; | ||
230 | } | ||
231 | } | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static void utmip_pad_close(struct tegra_usb_phy *phy) | ||
236 | { | ||
237 | if (phy->instance != 0) | ||
238 | iounmap(phy->pad_regs); | ||
239 | clk_put(phy->pad_clk); | ||
240 | } | ||
241 | |||
242 | static void utmip_pad_power_on(struct tegra_usb_phy *phy) | ||
243 | { | ||
244 | unsigned long val, flags; | ||
245 | void __iomem *base = phy->pad_regs; | ||
246 | |||
247 | clk_enable(phy->pad_clk); | ||
248 | |||
249 | spin_lock_irqsave(&utmip_pad_lock, flags); | ||
250 | |||
251 | if (utmip_pad_count++ == 0) { | ||
252 | val = readl(base + UTMIP_BIAS_CFG0); | ||
253 | val &= ~(UTMIP_OTGPD | UTMIP_BIASPD); | ||
254 | writel(val, base + UTMIP_BIAS_CFG0); | ||
255 | } | ||
256 | |||
257 | spin_unlock_irqrestore(&utmip_pad_lock, flags); | ||
258 | |||
259 | clk_disable(phy->pad_clk); | ||
260 | } | ||
261 | |||
262 | static int utmip_pad_power_off(struct tegra_usb_phy *phy) | ||
263 | { | ||
264 | unsigned long val, flags; | ||
265 | void __iomem *base = phy->pad_regs; | ||
266 | |||
267 | if (!utmip_pad_count) { | ||
268 | pr_err("%s: utmip pad already powered off\n", __func__); | ||
269 | return -EINVAL; | ||
270 | } | ||
271 | |||
272 | clk_enable(phy->pad_clk); | ||
273 | |||
274 | spin_lock_irqsave(&utmip_pad_lock, flags); | ||
275 | |||
276 | if (--utmip_pad_count == 0) { | ||
277 | val = readl(base + UTMIP_BIAS_CFG0); | ||
278 | val |= UTMIP_OTGPD | UTMIP_BIASPD; | ||
279 | writel(val, base + UTMIP_BIAS_CFG0); | ||
280 | } | ||
281 | |||
282 | spin_unlock_irqrestore(&utmip_pad_lock, flags); | ||
283 | |||
284 | clk_disable(phy->pad_clk); | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result) | ||
290 | { | ||
291 | unsigned long timeout = 2000; | ||
292 | do { | ||
293 | if ((readl(reg) & mask) == result) | ||
294 | return 0; | ||
295 | udelay(1); | ||
296 | timeout--; | ||
297 | } while (timeout); | ||
298 | return -1; | ||
299 | } | ||
300 | |||
301 | static void utmi_phy_clk_disable(struct tegra_usb_phy *phy) | ||
302 | { | ||
303 | unsigned long val; | ||
304 | void __iomem *base = phy->regs; | ||
305 | |||
306 | if (phy->instance == 0) { | ||
307 | val = readl(base + USB_SUSP_CTRL); | ||
308 | val |= USB_SUSP_SET; | ||
309 | writel(val, base + USB_SUSP_CTRL); | ||
310 | |||
311 | udelay(10); | ||
312 | |||
313 | val = readl(base + USB_SUSP_CTRL); | ||
314 | val &= ~USB_SUSP_SET; | ||
315 | writel(val, base + USB_SUSP_CTRL); | ||
316 | } | ||
317 | |||
318 | if (phy->instance == 2) { | ||
319 | val = readl(base + USB_PORTSC1); | ||
320 | val |= USB_PORTSC1_PHCD; | ||
321 | writel(val, base + USB_PORTSC1); | ||
322 | } | ||
323 | |||
324 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0) | ||
325 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); | ||
326 | } | ||
327 | |||
328 | static void utmi_phy_clk_enable(struct tegra_usb_phy *phy) | ||
329 | { | ||
330 | unsigned long val; | ||
331 | void __iomem *base = phy->regs; | ||
332 | |||
333 | if (phy->instance == 0) { | ||
334 | val = readl(base + USB_SUSP_CTRL); | ||
335 | val |= USB_SUSP_CLR; | ||
336 | writel(val, base + USB_SUSP_CTRL); | ||
337 | |||
338 | udelay(10); | ||
339 | |||
340 | val = readl(base + USB_SUSP_CTRL); | ||
341 | val &= ~USB_SUSP_CLR; | ||
342 | writel(val, base + USB_SUSP_CTRL); | ||
343 | } | ||
344 | |||
345 | if (phy->instance == 2) { | ||
346 | val = readl(base + USB_PORTSC1); | ||
347 | val &= ~USB_PORTSC1_PHCD; | ||
348 | writel(val, base + USB_PORTSC1); | ||
349 | } | ||
350 | |||
351 | if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, | ||
352 | USB_PHY_CLK_VALID)) | ||
353 | pr_err("%s: timeout waiting for phy to stabilize\n", __func__); | ||
354 | } | ||
355 | |||
356 | static int utmi_phy_power_on(struct tegra_usb_phy *phy) | ||
357 | { | ||
358 | unsigned long val; | ||
359 | void __iomem *base = phy->regs; | ||
360 | struct tegra_utmip_config *config = phy->config; | ||
361 | |||
362 | val = readl(base + USB_SUSP_CTRL); | ||
363 | val |= UTMIP_RESET; | ||
364 | writel(val, base + USB_SUSP_CTRL); | ||
365 | |||
366 | if (phy->instance == 0) { | ||
367 | val = readl(base + USB1_LEGACY_CTRL); | ||
368 | val |= USB1_NO_LEGACY_MODE; | ||
369 | writel(val, base + USB1_LEGACY_CTRL); | ||
370 | } | ||
371 | |||
372 | val = readl(base + UTMIP_TX_CFG0); | ||
373 | val &= ~UTMIP_FS_PREABMLE_J; | ||
374 | writel(val, base + UTMIP_TX_CFG0); | ||
375 | |||
376 | val = readl(base + UTMIP_HSRX_CFG0); | ||
377 | val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0)); | ||
378 | val |= UTMIP_IDLE_WAIT(config->idle_wait_delay); | ||
379 | val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit); | ||
380 | writel(val, base + UTMIP_HSRX_CFG0); | ||
381 | |||
382 | val = readl(base + UTMIP_HSRX_CFG1); | ||
383 | val &= ~UTMIP_HS_SYNC_START_DLY(~0); | ||
384 | val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay); | ||
385 | writel(val, base + UTMIP_HSRX_CFG1); | ||
386 | |||
387 | val = readl(base + UTMIP_DEBOUNCE_CFG0); | ||
388 | val &= ~UTMIP_BIAS_DEBOUNCE_A(~0); | ||
389 | val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce); | ||
390 | writel(val, base + UTMIP_DEBOUNCE_CFG0); | ||
391 | |||
392 | val = readl(base + UTMIP_MISC_CFG0); | ||
393 | val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE; | ||
394 | writel(val, base + UTMIP_MISC_CFG0); | ||
395 | |||
396 | val = readl(base + UTMIP_MISC_CFG1); | ||
397 | val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) | UTMIP_PLLU_STABLE_COUNT(~0)); | ||
398 | val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) | | ||
399 | UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count); | ||
400 | writel(val, base + UTMIP_MISC_CFG1); | ||
401 | |||
402 | val = readl(base + UTMIP_PLL_CFG1); | ||
403 | val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) | UTMIP_PLLU_ENABLE_DLY_COUNT(~0)); | ||
404 | val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) | | ||
405 | UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay); | ||
406 | writel(val, base + UTMIP_PLL_CFG1); | ||
407 | |||
408 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { | ||
409 | val = readl(base + USB_SUSP_CTRL); | ||
410 | val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV); | ||
411 | writel(val, base + USB_SUSP_CTRL); | ||
412 | } | ||
413 | |||
414 | utmip_pad_power_on(phy); | ||
415 | |||
416 | val = readl(base + UTMIP_XCVR_CFG0); | ||
417 | val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | | ||
418 | UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_SETUP(~0) | | ||
419 | UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0) | | ||
420 | UTMIP_XCVR_HSSLEW_MSB(~0)); | ||
421 | val |= UTMIP_XCVR_SETUP(config->xcvr_setup); | ||
422 | val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew); | ||
423 | val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew); | ||
424 | writel(val, base + UTMIP_XCVR_CFG0); | ||
425 | |||
426 | val = readl(base + UTMIP_XCVR_CFG1); | ||
427 | val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | | ||
428 | UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0)); | ||
429 | val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj); | ||
430 | writel(val, base + UTMIP_XCVR_CFG1); | ||
431 | |||
432 | val = readl(base + UTMIP_BAT_CHRG_CFG0); | ||
433 | val &= ~UTMIP_PD_CHRG; | ||
434 | writel(val, base + UTMIP_BAT_CHRG_CFG0); | ||
435 | |||
436 | val = readl(base + UTMIP_BIAS_CFG1); | ||
437 | val &= ~UTMIP_BIAS_PDTRK_COUNT(~0); | ||
438 | val |= UTMIP_BIAS_PDTRK_COUNT(0x5); | ||
439 | writel(val, base + UTMIP_BIAS_CFG1); | ||
440 | |||
441 | if (phy->instance == 0) { | ||
442 | val = readl(base + UTMIP_SPARE_CFG0); | ||
443 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) | ||
444 | val &= ~FUSE_SETUP_SEL; | ||
445 | else | ||
446 | val |= FUSE_SETUP_SEL; | ||
447 | writel(val, base + UTMIP_SPARE_CFG0); | ||
448 | } | ||
449 | |||
450 | if (phy->instance == 2) { | ||
451 | val = readl(base + USB_SUSP_CTRL); | ||
452 | val |= UTMIP_PHY_ENABLE; | ||
453 | writel(val, base + USB_SUSP_CTRL); | ||
454 | } | ||
455 | |||
456 | val = readl(base + USB_SUSP_CTRL); | ||
457 | val &= ~UTMIP_RESET; | ||
458 | writel(val, base + USB_SUSP_CTRL); | ||
459 | |||
460 | if (phy->instance == 0) { | ||
461 | val = readl(base + USB1_LEGACY_CTRL); | ||
462 | val &= ~USB1_VBUS_SENSE_CTL_MASK; | ||
463 | val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD; | ||
464 | writel(val, base + USB1_LEGACY_CTRL); | ||
465 | |||
466 | val = readl(base + USB_SUSP_CTRL); | ||
467 | val &= ~USB_SUSP_SET; | ||
468 | writel(val, base + USB_SUSP_CTRL); | ||
469 | } | ||
470 | |||
471 | utmi_phy_clk_enable(phy); | ||
472 | |||
473 | if (phy->instance == 2) { | ||
474 | val = readl(base + USB_PORTSC1); | ||
475 | val &= ~USB_PORTSC1_PTS(~0); | ||
476 | writel(val, base + USB_PORTSC1); | ||
477 | } | ||
478 | |||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | static void utmi_phy_power_off(struct tegra_usb_phy *phy) | ||
483 | { | ||
484 | unsigned long val; | ||
485 | void __iomem *base = phy->regs; | ||
486 | |||
487 | utmi_phy_clk_disable(phy); | ||
488 | |||
489 | if (phy->mode == TEGRA_USB_PHY_MODE_DEVICE) { | ||
490 | val = readl(base + USB_SUSP_CTRL); | ||
491 | val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0); | ||
492 | val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5); | ||
493 | writel(val, base + USB_SUSP_CTRL); | ||
494 | } | ||
495 | |||
496 | val = readl(base + USB_SUSP_CTRL); | ||
497 | val |= UTMIP_RESET; | ||
498 | writel(val, base + USB_SUSP_CTRL); | ||
499 | |||
500 | val = readl(base + UTMIP_BAT_CHRG_CFG0); | ||
501 | val |= UTMIP_PD_CHRG; | ||
502 | writel(val, base + UTMIP_BAT_CHRG_CFG0); | ||
503 | |||
504 | val = readl(base + UTMIP_XCVR_CFG0); | ||
505 | val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN | | ||
506 | UTMIP_FORCE_PDZI_POWERDOWN; | ||
507 | writel(val, base + UTMIP_XCVR_CFG0); | ||
508 | |||
509 | val = readl(base + UTMIP_XCVR_CFG1); | ||
510 | val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN | | ||
511 | UTMIP_FORCE_PDDR_POWERDOWN; | ||
512 | writel(val, base + UTMIP_XCVR_CFG1); | ||
513 | |||
514 | utmip_pad_power_off(phy); | ||
515 | } | ||
516 | |||
517 | static void utmi_phy_preresume(struct tegra_usb_phy *phy) | ||
518 | { | ||
519 | unsigned long val; | ||
520 | void __iomem *base = phy->regs; | ||
521 | |||
522 | val = readl(base + UTMIP_TX_CFG0); | ||
523 | val |= UTMIP_HS_DISCON_DISABLE; | ||
524 | writel(val, base + UTMIP_TX_CFG0); | ||
525 | } | ||
526 | |||
527 | static void utmi_phy_postresume(struct tegra_usb_phy *phy) | ||
528 | { | ||
529 | unsigned long val; | ||
530 | void __iomem *base = phy->regs; | ||
531 | |||
532 | val = readl(base + UTMIP_TX_CFG0); | ||
533 | val &= ~UTMIP_HS_DISCON_DISABLE; | ||
534 | writel(val, base + UTMIP_TX_CFG0); | ||
535 | } | ||
536 | |||
537 | static void utmi_phy_restore_start(struct tegra_usb_phy *phy, | ||
538 | enum tegra_usb_phy_port_speed port_speed) | ||
539 | { | ||
540 | unsigned long val; | ||
541 | void __iomem *base = phy->regs; | ||
542 | |||
543 | val = readl(base + UTMIP_MISC_CFG0); | ||
544 | val &= ~UTMIP_DPDM_OBSERVE_SEL(~0); | ||
545 | if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) | ||
546 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_K; | ||
547 | else | ||
548 | val |= UTMIP_DPDM_OBSERVE_SEL_FS_J; | ||
549 | writel(val, base + UTMIP_MISC_CFG0); | ||
550 | udelay(1); | ||
551 | |||
552 | val = readl(base + UTMIP_MISC_CFG0); | ||
553 | val |= UTMIP_DPDM_OBSERVE; | ||
554 | writel(val, base + UTMIP_MISC_CFG0); | ||
555 | udelay(10); | ||
556 | } | ||
557 | |||
558 | static void utmi_phy_restore_end(struct tegra_usb_phy *phy) | ||
559 | { | ||
560 | unsigned long val; | ||
561 | void __iomem *base = phy->regs; | ||
562 | |||
563 | val = readl(base + UTMIP_MISC_CFG0); | ||
564 | val &= ~UTMIP_DPDM_OBSERVE; | ||
565 | writel(val, base + UTMIP_MISC_CFG0); | ||
566 | udelay(10); | ||
567 | } | ||
568 | |||
569 | static int ulpi_phy_power_on(struct tegra_usb_phy *phy) | ||
570 | { | ||
571 | int ret; | ||
572 | unsigned long val; | ||
573 | void __iomem *base = phy->regs; | ||
574 | struct tegra_ulpi_config *config = phy->config; | ||
575 | |||
576 | gpio_direction_output(config->reset_gpio, 0); | ||
577 | msleep(5); | ||
578 | gpio_direction_output(config->reset_gpio, 1); | ||
579 | |||
580 | clk_enable(phy->clk); | ||
581 | msleep(1); | ||
582 | |||
583 | val = readl(base + USB_SUSP_CTRL); | ||
584 | val |= UHSIC_RESET; | ||
585 | writel(val, base + USB_SUSP_CTRL); | ||
586 | |||
587 | val = readl(base + ULPI_TIMING_CTRL_0); | ||
588 | val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP; | ||
589 | writel(val, base + ULPI_TIMING_CTRL_0); | ||
590 | |||
591 | val = readl(base + USB_SUSP_CTRL); | ||
592 | val |= ULPI_PHY_ENABLE; | ||
593 | writel(val, base + USB_SUSP_CTRL); | ||
594 | |||
595 | val = 0; | ||
596 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
597 | |||
598 | val |= ULPI_DATA_TRIMMER_SEL(4); | ||
599 | val |= ULPI_STPDIRNXT_TRIMMER_SEL(4); | ||
600 | val |= ULPI_DIR_TRIMMER_SEL(4); | ||
601 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
602 | udelay(10); | ||
603 | |||
604 | val |= ULPI_DATA_TRIMMER_LOAD; | ||
605 | val |= ULPI_STPDIRNXT_TRIMMER_LOAD; | ||
606 | val |= ULPI_DIR_TRIMMER_LOAD; | ||
607 | writel(val, base + ULPI_TIMING_CTRL_1); | ||
608 | |||
609 | /* Fix VbusInvalid due to floating VBUS */ | ||
610 | ret = otg_io_write(phy->ulpi, 0x40, 0x08); | ||
611 | if (ret) { | ||
612 | pr_err("%s: ulpi write failed\n", __func__); | ||
613 | return ret; | ||
614 | } | ||
615 | |||
616 | ret = otg_io_write(phy->ulpi, 0x80, 0x0B); | ||
617 | if (ret) { | ||
618 | pr_err("%s: ulpi write failed\n", __func__); | ||
619 | return ret; | ||
620 | } | ||
621 | |||
622 | val = readl(base + USB_PORTSC1); | ||
623 | val |= USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN; | ||
624 | writel(val, base + USB_PORTSC1); | ||
625 | |||
626 | val = readl(base + USB_SUSP_CTRL); | ||
627 | val |= USB_SUSP_CLR; | ||
628 | writel(val, base + USB_SUSP_CTRL); | ||
629 | udelay(100); | ||
630 | |||
631 | val = readl(base + USB_SUSP_CTRL); | ||
632 | val &= ~USB_SUSP_CLR; | ||
633 | writel(val, base + USB_SUSP_CTRL); | ||
634 | |||
635 | return 0; | ||
636 | } | ||
637 | |||
638 | static void ulpi_phy_power_off(struct tegra_usb_phy *phy) | ||
639 | { | ||
640 | unsigned long val; | ||
641 | void __iomem *base = phy->regs; | ||
642 | struct tegra_ulpi_config *config = phy->config; | ||
643 | |||
644 | /* Clear WKCN/WKDS/WKOC wake-on events that can cause the USB | ||
645 | * Controller to immediately bring the ULPI PHY out of low power | ||
646 | */ | ||
647 | val = readl(base + USB_PORTSC1); | ||
648 | val &= ~(USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN); | ||
649 | writel(val, base + USB_PORTSC1); | ||
650 | |||
651 | gpio_direction_output(config->reset_gpio, 0); | ||
652 | clk_disable(phy->clk); | ||
653 | } | ||
654 | |||
655 | struct tegra_usb_phy *tegra_usb_phy_open(int instance, void __iomem *regs, | ||
656 | void *config, enum tegra_usb_phy_mode phy_mode) | ||
657 | { | ||
658 | struct tegra_usb_phy *phy; | ||
659 | struct tegra_ulpi_config *ulpi_config; | ||
660 | unsigned long parent_rate; | ||
661 | int i; | ||
662 | int err; | ||
663 | |||
664 | phy = kmalloc(sizeof(struct tegra_usb_phy), GFP_KERNEL); | ||
665 | if (!phy) | ||
666 | return ERR_PTR(-ENOMEM); | ||
667 | |||
668 | phy->instance = instance; | ||
669 | phy->regs = regs; | ||
670 | phy->config = config; | ||
671 | phy->mode = phy_mode; | ||
672 | |||
673 | if (!phy->config) { | ||
674 | if (phy_is_ulpi(phy)) { | ||
675 | pr_err("%s: ulpi phy configuration missing", __func__); | ||
676 | err = -EINVAL; | ||
677 | goto err0; | ||
678 | } else { | ||
679 | phy->config = &utmip_default[instance]; | ||
680 | } | ||
681 | } | ||
682 | |||
683 | phy->pll_u = clk_get_sys(NULL, "pll_u"); | ||
684 | if (IS_ERR(phy->pll_u)) { | ||
685 | pr_err("Can't get pll_u clock\n"); | ||
686 | err = PTR_ERR(phy->pll_u); | ||
687 | goto err0; | ||
688 | } | ||
689 | clk_enable(phy->pll_u); | ||
690 | |||
691 | parent_rate = clk_get_rate(clk_get_parent(phy->pll_u)); | ||
692 | for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) { | ||
693 | if (tegra_freq_table[i].freq == parent_rate) { | ||
694 | phy->freq = &tegra_freq_table[i]; | ||
695 | break; | ||
696 | } | ||
697 | } | ||
698 | if (!phy->freq) { | ||
699 | pr_err("invalid pll_u parent rate %ld\n", parent_rate); | ||
700 | err = -EINVAL; | ||
701 | goto err1; | ||
702 | } | ||
703 | |||
704 | if (phy_is_ulpi(phy)) { | ||
705 | ulpi_config = config; | ||
706 | phy->clk = clk_get_sys(NULL, ulpi_config->clk); | ||
707 | if (IS_ERR(phy->clk)) { | ||
708 | pr_err("%s: can't get ulpi clock\n", __func__); | ||
709 | err = -ENXIO; | ||
710 | goto err1; | ||
711 | } | ||
712 | tegra_gpio_enable(ulpi_config->reset_gpio); | ||
713 | gpio_request(ulpi_config->reset_gpio, "ulpi_phy_reset_b"); | ||
714 | gpio_direction_output(ulpi_config->reset_gpio, 0); | ||
715 | phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0); | ||
716 | phy->ulpi->io_priv = regs + ULPI_VIEWPORT; | ||
717 | } else { | ||
718 | err = utmip_pad_open(phy); | ||
719 | if (err < 0) | ||
720 | goto err1; | ||
721 | } | ||
722 | |||
723 | return phy; | ||
724 | |||
725 | err1: | ||
726 | clk_disable(phy->pll_u); | ||
727 | clk_put(phy->pll_u); | ||
728 | err0: | ||
729 | kfree(phy); | ||
730 | return ERR_PTR(err); | ||
731 | } | ||
732 | |||
733 | int tegra_usb_phy_power_on(struct tegra_usb_phy *phy) | ||
734 | { | ||
735 | if (phy_is_ulpi(phy)) | ||
736 | return ulpi_phy_power_on(phy); | ||
737 | else | ||
738 | return utmi_phy_power_on(phy); | ||
739 | } | ||
740 | |||
741 | void tegra_usb_phy_power_off(struct tegra_usb_phy *phy) | ||
742 | { | ||
743 | if (phy_is_ulpi(phy)) | ||
744 | ulpi_phy_power_off(phy); | ||
745 | else | ||
746 | utmi_phy_power_off(phy); | ||
747 | } | ||
748 | |||
749 | void tegra_usb_phy_preresume(struct tegra_usb_phy *phy) | ||
750 | { | ||
751 | if (!phy_is_ulpi(phy)) | ||
752 | utmi_phy_preresume(phy); | ||
753 | } | ||
754 | |||
755 | void tegra_usb_phy_postresume(struct tegra_usb_phy *phy) | ||
756 | { | ||
757 | if (!phy_is_ulpi(phy)) | ||
758 | utmi_phy_postresume(phy); | ||
759 | } | ||
760 | |||
761 | void tegra_ehci_phy_restore_start(struct tegra_usb_phy *phy, | ||
762 | enum tegra_usb_phy_port_speed port_speed) | ||
763 | { | ||
764 | if (!phy_is_ulpi(phy)) | ||
765 | utmi_phy_restore_start(phy, port_speed); | ||
766 | } | ||
767 | |||
768 | void tegra_ehci_phy_restore_end(struct tegra_usb_phy *phy) | ||
769 | { | ||
770 | if (!phy_is_ulpi(phy)) | ||
771 | utmi_phy_restore_end(phy); | ||
772 | } | ||
773 | |||
774 | void tegra_usb_phy_clk_disable(struct tegra_usb_phy *phy) | ||
775 | { | ||
776 | if (!phy_is_ulpi(phy)) | ||
777 | utmi_phy_clk_disable(phy); | ||
778 | } | ||
779 | |||
780 | void tegra_usb_phy_clk_enable(struct tegra_usb_phy *phy) | ||
781 | { | ||
782 | if (!phy_is_ulpi(phy)) | ||
783 | utmi_phy_clk_enable(phy); | ||
784 | } | ||
785 | |||
786 | void tegra_usb_phy_close(struct tegra_usb_phy *phy) | ||
787 | { | ||
788 | if (phy_is_ulpi(phy)) | ||
789 | clk_put(phy->clk); | ||
790 | else | ||
791 | utmip_pad_close(phy); | ||
792 | clk_disable(phy->pll_u); | ||
793 | clk_put(phy->pll_u); | ||
794 | kfree(phy); | ||
795 | } | ||
diff --git a/arch/arm/plat-omap/include/plat/usb.h b/arch/arm/plat-omap/include/plat/usb.h index 450a332f1009..fe449f1a1c14 100644 --- a/arch/arm/plat-omap/include/plat/usb.h +++ b/arch/arm/plat-omap/include/plat/usb.h | |||
@@ -7,15 +7,12 @@ | |||
7 | #include <plat/board.h> | 7 | #include <plat/board.h> |
8 | 8 | ||
9 | #define OMAP3_HS_USB_PORTS 3 | 9 | #define OMAP3_HS_USB_PORTS 3 |
10 | enum ehci_hcd_omap_mode { | ||
11 | EHCI_HCD_OMAP_MODE_UNKNOWN, | ||
12 | EHCI_HCD_OMAP_MODE_PHY, | ||
13 | EHCI_HCD_OMAP_MODE_TLL, | ||
14 | EHCI_HCD_OMAP_MODE_HSIC, | ||
15 | }; | ||
16 | 10 | ||
17 | enum ohci_omap3_port_mode { | 11 | enum usbhs_omap_port_mode { |
18 | OMAP_OHCI_PORT_MODE_UNUSED, | 12 | OMAP_USBHS_PORT_MODE_UNUSED, |
13 | OMAP_EHCI_PORT_MODE_PHY, | ||
14 | OMAP_EHCI_PORT_MODE_TLL, | ||
15 | OMAP_EHCI_PORT_MODE_HSIC, | ||
19 | OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0, | 16 | OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0, |
20 | OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM, | 17 | OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM, |
21 | OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0, | 18 | OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0, |
@@ -25,24 +22,45 @@ enum ohci_omap3_port_mode { | |||
25 | OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0, | 22 | OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0, |
26 | OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM, | 23 | OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM, |
27 | OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0, | 24 | OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0, |
28 | OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM, | 25 | OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM |
29 | }; | 26 | }; |
30 | 27 | ||
31 | struct ehci_hcd_omap_platform_data { | 28 | struct usbhs_omap_board_data { |
32 | enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS]; | 29 | enum usbhs_omap_port_mode port_mode[OMAP3_HS_USB_PORTS]; |
33 | unsigned phy_reset:1; | ||
34 | 30 | ||
35 | /* have to be valid if phy_reset is true and portx is in phy mode */ | 31 | /* have to be valid if phy_reset is true and portx is in phy mode */ |
36 | int reset_gpio_port[OMAP3_HS_USB_PORTS]; | 32 | int reset_gpio_port[OMAP3_HS_USB_PORTS]; |
33 | |||
34 | /* Set this to true for ES2.x silicon */ | ||
35 | unsigned es2_compatibility:1; | ||
36 | |||
37 | unsigned phy_reset:1; | ||
38 | |||
39 | /* | ||
40 | * Regulators for USB PHYs. | ||
41 | * Each PHY can have a separate regulator. | ||
42 | */ | ||
43 | struct regulator *regulator[OMAP3_HS_USB_PORTS]; | ||
37 | }; | 44 | }; |
38 | 45 | ||
39 | struct ohci_hcd_omap_platform_data { | 46 | struct ehci_hcd_omap_platform_data { |
40 | enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS]; | 47 | enum usbhs_omap_port_mode port_mode[OMAP3_HS_USB_PORTS]; |
48 | int reset_gpio_port[OMAP3_HS_USB_PORTS]; | ||
49 | struct regulator *regulator[OMAP3_HS_USB_PORTS]; | ||
50 | unsigned phy_reset:1; | ||
51 | }; | ||
41 | 52 | ||
42 | /* Set this to true for ES2.x silicon */ | 53 | struct ohci_hcd_omap_platform_data { |
54 | enum usbhs_omap_port_mode port_mode[OMAP3_HS_USB_PORTS]; | ||
43 | unsigned es2_compatibility:1; | 55 | unsigned es2_compatibility:1; |
44 | }; | 56 | }; |
45 | 57 | ||
58 | struct usbhs_omap_platform_data { | ||
59 | enum usbhs_omap_port_mode port_mode[OMAP3_HS_USB_PORTS]; | ||
60 | |||
61 | struct ehci_hcd_omap_platform_data *ehci_data; | ||
62 | struct ohci_hcd_omap_platform_data *ohci_data; | ||
63 | }; | ||
46 | /*-------------------------------------------------------------------------*/ | 64 | /*-------------------------------------------------------------------------*/ |
47 | 65 | ||
48 | #define OMAP1_OTG_BASE 0xfffb0400 | 66 | #define OMAP1_OTG_BASE 0xfffb0400 |
@@ -80,18 +98,18 @@ enum musb_interface {MUSB_INTERFACE_ULPI, MUSB_INTERFACE_UTMI}; | |||
80 | 98 | ||
81 | extern void usb_musb_init(struct omap_musb_board_data *board_data); | 99 | extern void usb_musb_init(struct omap_musb_board_data *board_data); |
82 | 100 | ||
83 | extern void usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata); | 101 | extern void usbhs_init(const struct usbhs_omap_board_data *pdata); |
84 | 102 | ||
85 | extern void usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata); | 103 | extern int omap_usbhs_enable(struct device *dev); |
104 | extern void omap_usbhs_disable(struct device *dev); | ||
86 | 105 | ||
87 | extern int omap4430_phy_power(struct device *dev, int ID, int on); | 106 | extern int omap4430_phy_power(struct device *dev, int ID, int on); |
88 | extern int omap4430_phy_set_clk(struct device *dev, int on); | 107 | extern int omap4430_phy_set_clk(struct device *dev, int on); |
89 | extern int omap4430_phy_init(struct device *dev); | 108 | extern int omap4430_phy_init(struct device *dev); |
90 | extern int omap4430_phy_exit(struct device *dev); | 109 | extern int omap4430_phy_exit(struct device *dev); |
91 | 110 | extern int omap4430_phy_suspend(struct device *dev, int suspend); | |
92 | #endif | 111 | #endif |
93 | 112 | ||
94 | |||
95 | /* | 113 | /* |
96 | * FIXME correct answer depends on hmc_mode, | 114 | * FIXME correct answer depends on hmc_mode, |
97 | * as does (on omap1) any nonzero value for config->otg port number | 115 | * as does (on omap1) any nonzero value for config->otg port number |
diff --git a/arch/arm/plat-s3c24xx/include/plat/udc.h b/arch/arm/plat-s3c24xx/include/plat/udc.h index 546bb4008f49..80457c6414aa 100644 --- a/arch/arm/plat-s3c24xx/include/plat/udc.h +++ b/arch/arm/plat-s3c24xx/include/plat/udc.h | |||
@@ -27,6 +27,10 @@ enum s3c2410_udc_cmd_e { | |||
27 | struct s3c2410_udc_mach_info { | 27 | struct s3c2410_udc_mach_info { |
28 | void (*udc_command)(enum s3c2410_udc_cmd_e); | 28 | void (*udc_command)(enum s3c2410_udc_cmd_e); |
29 | void (*vbus_draw)(unsigned int ma); | 29 | void (*vbus_draw)(unsigned int ma); |
30 | |||
31 | unsigned int pullup_pin; | ||
32 | unsigned int pullup_pin_inverted; | ||
33 | |||
30 | unsigned int vbus_pin; | 34 | unsigned int vbus_pin; |
31 | unsigned char vbus_pin_inverted; | 35 | unsigned char vbus_pin_inverted; |
32 | }; | 36 | }; |
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index fd018366d670..a6dfa37a674d 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig | |||
@@ -624,6 +624,15 @@ config MFD_WL1273_CORE | |||
624 | driver connects the radio-wl1273 V4L2 module and the wl1273 | 624 | driver connects the radio-wl1273 V4L2 module and the wl1273 |
625 | audio codec. | 625 | audio codec. |
626 | 626 | ||
627 | config MFD_OMAP_USB_HOST | ||
628 | bool "Support OMAP USBHS core driver" | ||
629 | depends on USB_EHCI_HCD_OMAP || USB_OHCI_HCD_OMAP3 | ||
630 | default y | ||
631 | help | ||
632 | This is the core driver for the OAMP EHCI and OHCI drivers. | ||
633 | This MFD driver does the required setup functionalities for | ||
634 | OMAP USB Host drivers. | ||
635 | |||
627 | endif # MFD_SUPPORT | 636 | endif # MFD_SUPPORT |
628 | 637 | ||
629 | menu "Multimedia Capabilities Port drivers" | 638 | menu "Multimedia Capabilities Port drivers" |
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index a54e2c7c6a1c..91fe384459ab 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile | |||
@@ -83,3 +83,4 @@ obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o | |||
83 | obj-$(CONFIG_MFD_VX855) += vx855.o | 83 | obj-$(CONFIG_MFD_VX855) += vx855.o |
84 | obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o | 84 | obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o |
85 | obj-$(CONFIG_MFD_CS5535) += cs5535-mfd.o | 85 | obj-$(CONFIG_MFD_CS5535) += cs5535-mfd.o |
86 | obj-$(CONFIG_MFD_OMAP_USB_HOST) += omap-usb-host.o | ||
diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c new file mode 100644 index 000000000000..cb01209754e0 --- /dev/null +++ b/drivers/mfd/omap-usb-host.c | |||
@@ -0,0 +1,1061 @@ | |||
1 | /** | ||
2 | * omap-usb-host.c - The USBHS core driver for OMAP EHCI & OHCI | ||
3 | * | ||
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com | ||
5 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> | ||
6 | * | ||
7 | * This program is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 of | ||
9 | * the License as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/delay.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/clk.h> | ||
25 | #include <linux/dma-mapping.h> | ||
26 | #include <linux/spinlock.h> | ||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/regulator/consumer.h> | ||
29 | #include <plat/usb.h> | ||
30 | |||
31 | #define USBHS_DRIVER_NAME "usbhs-omap" | ||
32 | #define OMAP_EHCI_DEVICE "ehci-omap" | ||
33 | #define OMAP_OHCI_DEVICE "ohci-omap3" | ||
34 | |||
35 | /* OMAP USBHOST Register addresses */ | ||
36 | |||
37 | /* TLL Register Set */ | ||
38 | #define OMAP_USBTLL_REVISION (0x00) | ||
39 | #define OMAP_USBTLL_SYSCONFIG (0x10) | ||
40 | #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8) | ||
41 | #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3) | ||
42 | #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
43 | #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1) | ||
44 | #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0) | ||
45 | |||
46 | #define OMAP_USBTLL_SYSSTATUS (0x14) | ||
47 | #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0) | ||
48 | |||
49 | #define OMAP_USBTLL_IRQSTATUS (0x18) | ||
50 | #define OMAP_USBTLL_IRQENABLE (0x1C) | ||
51 | |||
52 | #define OMAP_TLL_SHARED_CONF (0x30) | ||
53 | #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6) | ||
54 | #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5) | ||
55 | #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2) | ||
56 | #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1) | ||
57 | #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0) | ||
58 | |||
59 | #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num) | ||
60 | #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24 | ||
61 | #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11) | ||
62 | #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10) | ||
63 | #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9) | ||
64 | #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8) | ||
65 | #define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1) | ||
66 | #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0) | ||
67 | |||
68 | #define OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0 0x0 | ||
69 | #define OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM 0x1 | ||
70 | #define OMAP_TLL_FSLSMODE_3PIN_PHY 0x2 | ||
71 | #define OMAP_TLL_FSLSMODE_4PIN_PHY 0x3 | ||
72 | #define OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0 0x4 | ||
73 | #define OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM 0x5 | ||
74 | #define OMAP_TLL_FSLSMODE_3PIN_TLL 0x6 | ||
75 | #define OMAP_TLL_FSLSMODE_4PIN_TLL 0x7 | ||
76 | #define OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0 0xA | ||
77 | #define OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM 0xB | ||
78 | |||
79 | #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num) | ||
80 | #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num) | ||
81 | #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num) | ||
82 | #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num) | ||
83 | #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num) | ||
84 | #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num) | ||
85 | #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num) | ||
86 | #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num) | ||
87 | #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num) | ||
88 | |||
89 | #define OMAP_TLL_CHANNEL_COUNT 3 | ||
90 | #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0) | ||
91 | #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1) | ||
92 | #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2) | ||
93 | |||
94 | /* UHH Register Set */ | ||
95 | #define OMAP_UHH_REVISION (0x00) | ||
96 | #define OMAP_UHH_SYSCONFIG (0x10) | ||
97 | #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12) | ||
98 | #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8) | ||
99 | #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3) | ||
100 | #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
101 | #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1) | ||
102 | #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0) | ||
103 | |||
104 | #define OMAP_UHH_SYSSTATUS (0x14) | ||
105 | #define OMAP_UHH_HOSTCONFIG (0x40) | ||
106 | #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0) | ||
107 | #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0) | ||
108 | #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11) | ||
109 | #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12) | ||
110 | #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2) | ||
111 | #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3) | ||
112 | #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4) | ||
113 | #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5) | ||
114 | #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8) | ||
115 | #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9) | ||
116 | #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10) | ||
117 | #define OMAP4_UHH_HOSTCONFIG_APP_START_CLK (1 << 31) | ||
118 | |||
119 | /* OMAP4-specific defines */ | ||
120 | #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2) | ||
121 | #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2) | ||
122 | #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4) | ||
123 | #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4) | ||
124 | #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0) | ||
125 | |||
126 | #define OMAP4_P1_MODE_CLEAR (3 << 16) | ||
127 | #define OMAP4_P1_MODE_TLL (1 << 16) | ||
128 | #define OMAP4_P1_MODE_HSIC (3 << 16) | ||
129 | #define OMAP4_P2_MODE_CLEAR (3 << 18) | ||
130 | #define OMAP4_P2_MODE_TLL (1 << 18) | ||
131 | #define OMAP4_P2_MODE_HSIC (3 << 18) | ||
132 | |||
133 | #define OMAP_REV2_TLL_CHANNEL_COUNT 2 | ||
134 | |||
135 | #define OMAP_UHH_DEBUG_CSR (0x44) | ||
136 | |||
137 | /* Values of UHH_REVISION - Note: these are not given in the TRM */ | ||
138 | #define OMAP_USBHS_REV1 0x00000010 /* OMAP3 */ | ||
139 | #define OMAP_USBHS_REV2 0x50700100 /* OMAP4 */ | ||
140 | |||
141 | #define is_omap_usbhs_rev1(x) (x->usbhs_rev == OMAP_USBHS_REV1) | ||
142 | #define is_omap_usbhs_rev2(x) (x->usbhs_rev == OMAP_USBHS_REV2) | ||
143 | |||
144 | #define is_ehci_phy_mode(x) (x == OMAP_EHCI_PORT_MODE_PHY) | ||
145 | #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL) | ||
146 | #define is_ehci_hsic_mode(x) (x == OMAP_EHCI_PORT_MODE_HSIC) | ||
147 | |||
148 | |||
149 | struct usbhs_hcd_omap { | ||
150 | struct clk *usbhost_ick; | ||
151 | struct clk *usbhost_hs_fck; | ||
152 | struct clk *usbhost_fs_fck; | ||
153 | struct clk *xclk60mhsp1_ck; | ||
154 | struct clk *xclk60mhsp2_ck; | ||
155 | struct clk *utmi_p1_fck; | ||
156 | struct clk *usbhost_p1_fck; | ||
157 | struct clk *usbtll_p1_fck; | ||
158 | struct clk *utmi_p2_fck; | ||
159 | struct clk *usbhost_p2_fck; | ||
160 | struct clk *usbtll_p2_fck; | ||
161 | struct clk *init_60m_fclk; | ||
162 | struct clk *usbtll_fck; | ||
163 | struct clk *usbtll_ick; | ||
164 | |||
165 | void __iomem *uhh_base; | ||
166 | void __iomem *tll_base; | ||
167 | |||
168 | struct usbhs_omap_platform_data platdata; | ||
169 | |||
170 | u32 usbhs_rev; | ||
171 | spinlock_t lock; | ||
172 | int count; | ||
173 | }; | ||
174 | /*-------------------------------------------------------------------------*/ | ||
175 | |||
176 | const char usbhs_driver_name[] = USBHS_DRIVER_NAME; | ||
177 | static u64 usbhs_dmamask = ~(u32)0; | ||
178 | |||
179 | /*-------------------------------------------------------------------------*/ | ||
180 | |||
181 | static inline void usbhs_write(void __iomem *base, u32 reg, u32 val) | ||
182 | { | ||
183 | __raw_writel(val, base + reg); | ||
184 | } | ||
185 | |||
186 | static inline u32 usbhs_read(void __iomem *base, u32 reg) | ||
187 | { | ||
188 | return __raw_readl(base + reg); | ||
189 | } | ||
190 | |||
191 | static inline void usbhs_writeb(void __iomem *base, u8 reg, u8 val) | ||
192 | { | ||
193 | __raw_writeb(val, base + reg); | ||
194 | } | ||
195 | |||
196 | static inline u8 usbhs_readb(void __iomem *base, u8 reg) | ||
197 | { | ||
198 | return __raw_readb(base + reg); | ||
199 | } | ||
200 | |||
201 | /*-------------------------------------------------------------------------*/ | ||
202 | |||
203 | static struct platform_device *omap_usbhs_alloc_child(const char *name, | ||
204 | struct resource *res, int num_resources, void *pdata, | ||
205 | size_t pdata_size, struct device *dev) | ||
206 | { | ||
207 | struct platform_device *child; | ||
208 | int ret; | ||
209 | |||
210 | child = platform_device_alloc(name, 0); | ||
211 | |||
212 | if (!child) { | ||
213 | dev_err(dev, "platform_device_alloc %s failed\n", name); | ||
214 | goto err_end; | ||
215 | } | ||
216 | |||
217 | ret = platform_device_add_resources(child, res, num_resources); | ||
218 | if (ret) { | ||
219 | dev_err(dev, "platform_device_add_resources failed\n"); | ||
220 | goto err_alloc; | ||
221 | } | ||
222 | |||
223 | ret = platform_device_add_data(child, pdata, pdata_size); | ||
224 | if (ret) { | ||
225 | dev_err(dev, "platform_device_add_data failed\n"); | ||
226 | goto err_alloc; | ||
227 | } | ||
228 | |||
229 | child->dev.dma_mask = &usbhs_dmamask; | ||
230 | child->dev.coherent_dma_mask = 0xffffffff; | ||
231 | child->dev.parent = dev; | ||
232 | |||
233 | ret = platform_device_add(child); | ||
234 | if (ret) { | ||
235 | dev_err(dev, "platform_device_add failed\n"); | ||
236 | goto err_alloc; | ||
237 | } | ||
238 | |||
239 | return child; | ||
240 | |||
241 | err_alloc: | ||
242 | platform_device_put(child); | ||
243 | |||
244 | err_end: | ||
245 | return NULL; | ||
246 | } | ||
247 | |||
248 | static int omap_usbhs_alloc_children(struct platform_device *pdev) | ||
249 | { | ||
250 | struct device *dev = &pdev->dev; | ||
251 | struct usbhs_hcd_omap *omap; | ||
252 | struct ehci_hcd_omap_platform_data *ehci_data; | ||
253 | struct ohci_hcd_omap_platform_data *ohci_data; | ||
254 | struct platform_device *ehci; | ||
255 | struct platform_device *ohci; | ||
256 | struct resource *res; | ||
257 | struct resource resources[2]; | ||
258 | int ret; | ||
259 | |||
260 | omap = platform_get_drvdata(pdev); | ||
261 | ehci_data = omap->platdata.ehci_data; | ||
262 | ohci_data = omap->platdata.ohci_data; | ||
263 | |||
264 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci"); | ||
265 | if (!res) { | ||
266 | dev_err(dev, "EHCI get resource IORESOURCE_MEM failed\n"); | ||
267 | ret = -ENODEV; | ||
268 | goto err_end; | ||
269 | } | ||
270 | resources[0] = *res; | ||
271 | |||
272 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ehci-irq"); | ||
273 | if (!res) { | ||
274 | dev_err(dev, " EHCI get resource IORESOURCE_IRQ failed\n"); | ||
275 | ret = -ENODEV; | ||
276 | goto err_end; | ||
277 | } | ||
278 | resources[1] = *res; | ||
279 | |||
280 | ehci = omap_usbhs_alloc_child(OMAP_EHCI_DEVICE, resources, 2, ehci_data, | ||
281 | sizeof(*ehci_data), dev); | ||
282 | |||
283 | if (!ehci) { | ||
284 | dev_err(dev, "omap_usbhs_alloc_child failed\n"); | ||
285 | goto err_end; | ||
286 | } | ||
287 | |||
288 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ohci"); | ||
289 | if (!res) { | ||
290 | dev_err(dev, "OHCI get resource IORESOURCE_MEM failed\n"); | ||
291 | ret = -ENODEV; | ||
292 | goto err_ehci; | ||
293 | } | ||
294 | resources[0] = *res; | ||
295 | |||
296 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ohci-irq"); | ||
297 | if (!res) { | ||
298 | dev_err(dev, "OHCI get resource IORESOURCE_IRQ failed\n"); | ||
299 | ret = -ENODEV; | ||
300 | goto err_ehci; | ||
301 | } | ||
302 | resources[1] = *res; | ||
303 | |||
304 | ohci = omap_usbhs_alloc_child(OMAP_OHCI_DEVICE, resources, 2, ohci_data, | ||
305 | sizeof(*ohci_data), dev); | ||
306 | if (!ohci) { | ||
307 | dev_err(dev, "omap_usbhs_alloc_child failed\n"); | ||
308 | goto err_ehci; | ||
309 | } | ||
310 | |||
311 | return 0; | ||
312 | |||
313 | err_ehci: | ||
314 | platform_device_put(ehci); | ||
315 | |||
316 | err_end: | ||
317 | return ret; | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * usbhs_omap_probe - initialize TI-based HCDs | ||
322 | * | ||
323 | * Allocates basic resources for this USB host controller. | ||
324 | */ | ||
325 | static int __devinit usbhs_omap_probe(struct platform_device *pdev) | ||
326 | { | ||
327 | struct device *dev = &pdev->dev; | ||
328 | struct usbhs_omap_platform_data *pdata = dev->platform_data; | ||
329 | struct usbhs_hcd_omap *omap; | ||
330 | struct resource *res; | ||
331 | int ret = 0; | ||
332 | int i; | ||
333 | |||
334 | if (!pdata) { | ||
335 | dev_err(dev, "Missing platfrom data\n"); | ||
336 | ret = -ENOMEM; | ||
337 | goto end_probe; | ||
338 | } | ||
339 | |||
340 | omap = kzalloc(sizeof(*omap), GFP_KERNEL); | ||
341 | if (!omap) { | ||
342 | dev_err(dev, "Memory allocation failed\n"); | ||
343 | ret = -ENOMEM; | ||
344 | goto end_probe; | ||
345 | } | ||
346 | |||
347 | spin_lock_init(&omap->lock); | ||
348 | |||
349 | for (i = 0; i < OMAP3_HS_USB_PORTS; i++) | ||
350 | omap->platdata.port_mode[i] = pdata->port_mode[i]; | ||
351 | |||
352 | omap->platdata.ehci_data = pdata->ehci_data; | ||
353 | omap->platdata.ohci_data = pdata->ohci_data; | ||
354 | |||
355 | omap->usbhost_ick = clk_get(dev, "usbhost_ick"); | ||
356 | if (IS_ERR(omap->usbhost_ick)) { | ||
357 | ret = PTR_ERR(omap->usbhost_ick); | ||
358 | dev_err(dev, "usbhost_ick failed error:%d\n", ret); | ||
359 | goto err_end; | ||
360 | } | ||
361 | |||
362 | omap->usbhost_hs_fck = clk_get(dev, "hs_fck"); | ||
363 | if (IS_ERR(omap->usbhost_hs_fck)) { | ||
364 | ret = PTR_ERR(omap->usbhost_hs_fck); | ||
365 | dev_err(dev, "usbhost_hs_fck failed error:%d\n", ret); | ||
366 | goto err_usbhost_ick; | ||
367 | } | ||
368 | |||
369 | omap->usbhost_fs_fck = clk_get(dev, "fs_fck"); | ||
370 | if (IS_ERR(omap->usbhost_fs_fck)) { | ||
371 | ret = PTR_ERR(omap->usbhost_fs_fck); | ||
372 | dev_err(dev, "usbhost_fs_fck failed error:%d\n", ret); | ||
373 | goto err_usbhost_hs_fck; | ||
374 | } | ||
375 | |||
376 | omap->usbtll_fck = clk_get(dev, "usbtll_fck"); | ||
377 | if (IS_ERR(omap->usbtll_fck)) { | ||
378 | ret = PTR_ERR(omap->usbtll_fck); | ||
379 | dev_err(dev, "usbtll_fck failed error:%d\n", ret); | ||
380 | goto err_usbhost_fs_fck; | ||
381 | } | ||
382 | |||
383 | omap->usbtll_ick = clk_get(dev, "usbtll_ick"); | ||
384 | if (IS_ERR(omap->usbtll_ick)) { | ||
385 | ret = PTR_ERR(omap->usbtll_ick); | ||
386 | dev_err(dev, "usbtll_ick failed error:%d\n", ret); | ||
387 | goto err_usbtll_fck; | ||
388 | } | ||
389 | |||
390 | omap->utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk"); | ||
391 | if (IS_ERR(omap->utmi_p1_fck)) { | ||
392 | ret = PTR_ERR(omap->utmi_p1_fck); | ||
393 | dev_err(dev, "utmi_p1_gfclk failed error:%d\n", ret); | ||
394 | goto err_usbtll_ick; | ||
395 | } | ||
396 | |||
397 | omap->xclk60mhsp1_ck = clk_get(dev, "xclk60mhsp1_ck"); | ||
398 | if (IS_ERR(omap->xclk60mhsp1_ck)) { | ||
399 | ret = PTR_ERR(omap->xclk60mhsp1_ck); | ||
400 | dev_err(dev, "xclk60mhsp1_ck failed error:%d\n", ret); | ||
401 | goto err_utmi_p1_fck; | ||
402 | } | ||
403 | |||
404 | omap->utmi_p2_fck = clk_get(dev, "utmi_p2_gfclk"); | ||
405 | if (IS_ERR(omap->utmi_p2_fck)) { | ||
406 | ret = PTR_ERR(omap->utmi_p2_fck); | ||
407 | dev_err(dev, "utmi_p2_gfclk failed error:%d\n", ret); | ||
408 | goto err_xclk60mhsp1_ck; | ||
409 | } | ||
410 | |||
411 | omap->xclk60mhsp2_ck = clk_get(dev, "xclk60mhsp2_ck"); | ||
412 | if (IS_ERR(omap->xclk60mhsp2_ck)) { | ||
413 | ret = PTR_ERR(omap->xclk60mhsp2_ck); | ||
414 | dev_err(dev, "xclk60mhsp2_ck failed error:%d\n", ret); | ||
415 | goto err_utmi_p2_fck; | ||
416 | } | ||
417 | |||
418 | omap->usbhost_p1_fck = clk_get(dev, "usb_host_hs_utmi_p1_clk"); | ||
419 | if (IS_ERR(omap->usbhost_p1_fck)) { | ||
420 | ret = PTR_ERR(omap->usbhost_p1_fck); | ||
421 | dev_err(dev, "usbhost_p1_fck failed error:%d\n", ret); | ||
422 | goto err_xclk60mhsp2_ck; | ||
423 | } | ||
424 | |||
425 | omap->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk"); | ||
426 | if (IS_ERR(omap->usbtll_p1_fck)) { | ||
427 | ret = PTR_ERR(omap->usbtll_p1_fck); | ||
428 | dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret); | ||
429 | goto err_usbhost_p1_fck; | ||
430 | } | ||
431 | |||
432 | omap->usbhost_p2_fck = clk_get(dev, "usb_host_hs_utmi_p2_clk"); | ||
433 | if (IS_ERR(omap->usbhost_p2_fck)) { | ||
434 | ret = PTR_ERR(omap->usbhost_p2_fck); | ||
435 | dev_err(dev, "usbhost_p2_fck failed error:%d\n", ret); | ||
436 | goto err_usbtll_p1_fck; | ||
437 | } | ||
438 | |||
439 | omap->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk"); | ||
440 | if (IS_ERR(omap->usbtll_p2_fck)) { | ||
441 | ret = PTR_ERR(omap->usbtll_p2_fck); | ||
442 | dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret); | ||
443 | goto err_usbhost_p2_fck; | ||
444 | } | ||
445 | |||
446 | omap->init_60m_fclk = clk_get(dev, "init_60m_fclk"); | ||
447 | if (IS_ERR(omap->init_60m_fclk)) { | ||
448 | ret = PTR_ERR(omap->init_60m_fclk); | ||
449 | dev_err(dev, "init_60m_fclk failed error:%d\n", ret); | ||
450 | goto err_usbtll_p2_fck; | ||
451 | } | ||
452 | |||
453 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh"); | ||
454 | if (!res) { | ||
455 | dev_err(dev, "UHH EHCI get resource failed\n"); | ||
456 | ret = -ENODEV; | ||
457 | goto err_init_60m_fclk; | ||
458 | } | ||
459 | |||
460 | omap->uhh_base = ioremap(res->start, resource_size(res)); | ||
461 | if (!omap->uhh_base) { | ||
462 | dev_err(dev, "UHH ioremap failed\n"); | ||
463 | ret = -ENOMEM; | ||
464 | goto err_init_60m_fclk; | ||
465 | } | ||
466 | |||
467 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll"); | ||
468 | if (!res) { | ||
469 | dev_err(dev, "UHH EHCI get resource failed\n"); | ||
470 | ret = -ENODEV; | ||
471 | goto err_tll; | ||
472 | } | ||
473 | |||
474 | omap->tll_base = ioremap(res->start, resource_size(res)); | ||
475 | if (!omap->tll_base) { | ||
476 | dev_err(dev, "TLL ioremap failed\n"); | ||
477 | ret = -ENOMEM; | ||
478 | goto err_tll; | ||
479 | } | ||
480 | |||
481 | platform_set_drvdata(pdev, omap); | ||
482 | |||
483 | ret = omap_usbhs_alloc_children(pdev); | ||
484 | if (ret) { | ||
485 | dev_err(dev, "omap_usbhs_alloc_children failed\n"); | ||
486 | goto err_alloc; | ||
487 | } | ||
488 | |||
489 | goto end_probe; | ||
490 | |||
491 | err_alloc: | ||
492 | iounmap(omap->tll_base); | ||
493 | |||
494 | err_tll: | ||
495 | iounmap(omap->uhh_base); | ||
496 | |||
497 | err_init_60m_fclk: | ||
498 | clk_put(omap->init_60m_fclk); | ||
499 | |||
500 | err_usbtll_p2_fck: | ||
501 | clk_put(omap->usbtll_p2_fck); | ||
502 | |||
503 | err_usbhost_p2_fck: | ||
504 | clk_put(omap->usbhost_p2_fck); | ||
505 | |||
506 | err_usbtll_p1_fck: | ||
507 | clk_put(omap->usbtll_p1_fck); | ||
508 | |||
509 | err_usbhost_p1_fck: | ||
510 | clk_put(omap->usbhost_p1_fck); | ||
511 | |||
512 | err_xclk60mhsp2_ck: | ||
513 | clk_put(omap->xclk60mhsp2_ck); | ||
514 | |||
515 | err_utmi_p2_fck: | ||
516 | clk_put(omap->utmi_p2_fck); | ||
517 | |||
518 | err_xclk60mhsp1_ck: | ||
519 | clk_put(omap->xclk60mhsp1_ck); | ||
520 | |||
521 | err_utmi_p1_fck: | ||
522 | clk_put(omap->utmi_p1_fck); | ||
523 | |||
524 | err_usbtll_ick: | ||
525 | clk_put(omap->usbtll_ick); | ||
526 | |||
527 | err_usbtll_fck: | ||
528 | clk_put(omap->usbtll_fck); | ||
529 | |||
530 | err_usbhost_fs_fck: | ||
531 | clk_put(omap->usbhost_fs_fck); | ||
532 | |||
533 | err_usbhost_hs_fck: | ||
534 | clk_put(omap->usbhost_hs_fck); | ||
535 | |||
536 | err_usbhost_ick: | ||
537 | clk_put(omap->usbhost_ick); | ||
538 | |||
539 | err_end: | ||
540 | kfree(omap); | ||
541 | |||
542 | end_probe: | ||
543 | return ret; | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * usbhs_omap_remove - shutdown processing for UHH & TLL HCDs | ||
548 | * @pdev: USB Host Controller being removed | ||
549 | * | ||
550 | * Reverses the effect of usbhs_omap_probe(). | ||
551 | */ | ||
552 | static int __devexit usbhs_omap_remove(struct platform_device *pdev) | ||
553 | { | ||
554 | struct usbhs_hcd_omap *omap = platform_get_drvdata(pdev); | ||
555 | |||
556 | if (omap->count != 0) { | ||
557 | dev_err(&pdev->dev, | ||
558 | "Either EHCI or OHCI is still using usbhs core\n"); | ||
559 | return -EBUSY; | ||
560 | } | ||
561 | |||
562 | iounmap(omap->tll_base); | ||
563 | iounmap(omap->uhh_base); | ||
564 | clk_put(omap->init_60m_fclk); | ||
565 | clk_put(omap->usbtll_p2_fck); | ||
566 | clk_put(omap->usbhost_p2_fck); | ||
567 | clk_put(omap->usbtll_p1_fck); | ||
568 | clk_put(omap->usbhost_p1_fck); | ||
569 | clk_put(omap->xclk60mhsp2_ck); | ||
570 | clk_put(omap->utmi_p2_fck); | ||
571 | clk_put(omap->xclk60mhsp1_ck); | ||
572 | clk_put(omap->utmi_p1_fck); | ||
573 | clk_put(omap->usbtll_ick); | ||
574 | clk_put(omap->usbtll_fck); | ||
575 | clk_put(omap->usbhost_fs_fck); | ||
576 | clk_put(omap->usbhost_hs_fck); | ||
577 | clk_put(omap->usbhost_ick); | ||
578 | kfree(omap); | ||
579 | |||
580 | return 0; | ||
581 | } | ||
582 | |||
583 | static bool is_ohci_port(enum usbhs_omap_port_mode pmode) | ||
584 | { | ||
585 | switch (pmode) { | ||
586 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | ||
587 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | ||
588 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | ||
589 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | ||
590 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | ||
591 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | ||
592 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | ||
593 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | ||
594 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | ||
595 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | ||
596 | return true; | ||
597 | |||
598 | default: | ||
599 | return false; | ||
600 | } | ||
601 | } | ||
602 | |||
603 | /* | ||
604 | * convert the port-mode enum to a value we can use in the FSLSMODE | ||
605 | * field of USBTLL_CHANNEL_CONF | ||
606 | */ | ||
607 | static unsigned ohci_omap3_fslsmode(enum usbhs_omap_port_mode mode) | ||
608 | { | ||
609 | switch (mode) { | ||
610 | case OMAP_USBHS_PORT_MODE_UNUSED: | ||
611 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | ||
612 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0; | ||
613 | |||
614 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | ||
615 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DP_DM; | ||
616 | |||
617 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | ||
618 | return OMAP_TLL_FSLSMODE_3PIN_PHY; | ||
619 | |||
620 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | ||
621 | return OMAP_TLL_FSLSMODE_4PIN_PHY; | ||
622 | |||
623 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | ||
624 | return OMAP_TLL_FSLSMODE_6PIN_TLL_DAT_SE0; | ||
625 | |||
626 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | ||
627 | return OMAP_TLL_FSLSMODE_6PIN_TLL_DP_DM; | ||
628 | |||
629 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | ||
630 | return OMAP_TLL_FSLSMODE_3PIN_TLL; | ||
631 | |||
632 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | ||
633 | return OMAP_TLL_FSLSMODE_4PIN_TLL; | ||
634 | |||
635 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | ||
636 | return OMAP_TLL_FSLSMODE_2PIN_TLL_DAT_SE0; | ||
637 | |||
638 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | ||
639 | return OMAP_TLL_FSLSMODE_2PIN_DAT_DP_DM; | ||
640 | default: | ||
641 | pr_warning("Invalid port mode, using default\n"); | ||
642 | return OMAP_TLL_FSLSMODE_6PIN_PHY_DAT_SE0; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | static void usbhs_omap_tll_init(struct device *dev, u8 tll_channel_count) | ||
647 | { | ||
648 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); | ||
649 | struct usbhs_omap_platform_data *pdata = dev->platform_data; | ||
650 | unsigned reg; | ||
651 | int i; | ||
652 | |||
653 | /* Program Common TLL register */ | ||
654 | reg = usbhs_read(omap->tll_base, OMAP_TLL_SHARED_CONF); | ||
655 | reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON | ||
656 | | OMAP_TLL_SHARED_CONF_USB_DIVRATION); | ||
657 | reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN; | ||
658 | reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN; | ||
659 | |||
660 | usbhs_write(omap->tll_base, OMAP_TLL_SHARED_CONF, reg); | ||
661 | |||
662 | /* Enable channels now */ | ||
663 | for (i = 0; i < tll_channel_count; i++) { | ||
664 | reg = usbhs_read(omap->tll_base, | ||
665 | OMAP_TLL_CHANNEL_CONF(i)); | ||
666 | |||
667 | if (is_ohci_port(pdata->port_mode[i])) { | ||
668 | reg |= ohci_omap3_fslsmode(pdata->port_mode[i]) | ||
669 | << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT; | ||
670 | reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS; | ||
671 | } else if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_TLL) { | ||
672 | |||
673 | /* Disable AutoIdle, BitStuffing and use SDR Mode */ | ||
674 | reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE | ||
675 | | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF | ||
676 | | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE); | ||
677 | |||
678 | reg |= (1 << (i + 1)); | ||
679 | } else | ||
680 | continue; | ||
681 | |||
682 | reg |= OMAP_TLL_CHANNEL_CONF_CHANEN; | ||
683 | usbhs_write(omap->tll_base, | ||
684 | OMAP_TLL_CHANNEL_CONF(i), reg); | ||
685 | |||
686 | usbhs_writeb(omap->tll_base, | ||
687 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe); | ||
688 | } | ||
689 | } | ||
690 | |||
691 | static int usbhs_enable(struct device *dev) | ||
692 | { | ||
693 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); | ||
694 | struct usbhs_omap_platform_data *pdata = &omap->platdata; | ||
695 | unsigned long flags = 0; | ||
696 | int ret = 0; | ||
697 | unsigned long timeout; | ||
698 | unsigned reg; | ||
699 | |||
700 | dev_dbg(dev, "starting TI HSUSB Controller\n"); | ||
701 | if (!pdata) { | ||
702 | dev_dbg(dev, "missing platform_data\n"); | ||
703 | ret = -ENODEV; | ||
704 | goto end_enable; | ||
705 | } | ||
706 | |||
707 | spin_lock_irqsave(&omap->lock, flags); | ||
708 | if (omap->count > 0) | ||
709 | goto end_count; | ||
710 | |||
711 | clk_enable(omap->usbhost_ick); | ||
712 | clk_enable(omap->usbhost_hs_fck); | ||
713 | clk_enable(omap->usbhost_fs_fck); | ||
714 | clk_enable(omap->usbtll_fck); | ||
715 | clk_enable(omap->usbtll_ick); | ||
716 | |||
717 | if (pdata->ehci_data->phy_reset) { | ||
718 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) { | ||
719 | gpio_request(pdata->ehci_data->reset_gpio_port[0], | ||
720 | "USB1 PHY reset"); | ||
721 | gpio_direction_output | ||
722 | (pdata->ehci_data->reset_gpio_port[0], 1); | ||
723 | } | ||
724 | |||
725 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) { | ||
726 | gpio_request(pdata->ehci_data->reset_gpio_port[1], | ||
727 | "USB2 PHY reset"); | ||
728 | gpio_direction_output | ||
729 | (pdata->ehci_data->reset_gpio_port[1], 1); | ||
730 | } | ||
731 | |||
732 | /* Hold the PHY in RESET for enough time till DIR is high */ | ||
733 | udelay(10); | ||
734 | } | ||
735 | |||
736 | omap->usbhs_rev = usbhs_read(omap->uhh_base, OMAP_UHH_REVISION); | ||
737 | dev_dbg(dev, "OMAP UHH_REVISION 0x%x\n", omap->usbhs_rev); | ||
738 | |||
739 | /* perform TLL soft reset, and wait until reset is complete */ | ||
740 | usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | ||
741 | OMAP_USBTLL_SYSCONFIG_SOFTRESET); | ||
742 | |||
743 | /* Wait for TLL reset to complete */ | ||
744 | timeout = jiffies + msecs_to_jiffies(1000); | ||
745 | while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
746 | & OMAP_USBTLL_SYSSTATUS_RESETDONE)) { | ||
747 | cpu_relax(); | ||
748 | |||
749 | if (time_after(jiffies, timeout)) { | ||
750 | dev_dbg(dev, "operation timed out\n"); | ||
751 | ret = -EINVAL; | ||
752 | goto err_tll; | ||
753 | } | ||
754 | } | ||
755 | |||
756 | dev_dbg(dev, "TLL RESET DONE\n"); | ||
757 | |||
758 | /* (1<<3) = no idle mode only for initial debugging */ | ||
759 | usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | ||
760 | OMAP_USBTLL_SYSCONFIG_ENAWAKEUP | | ||
761 | OMAP_USBTLL_SYSCONFIG_SIDLEMODE | | ||
762 | OMAP_USBTLL_SYSCONFIG_AUTOIDLE); | ||
763 | |||
764 | /* Put UHH in NoIdle/NoStandby mode */ | ||
765 | reg = usbhs_read(omap->uhh_base, OMAP_UHH_SYSCONFIG); | ||
766 | if (is_omap_usbhs_rev1(omap)) { | ||
767 | reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP | ||
768 | | OMAP_UHH_SYSCONFIG_SIDLEMODE | ||
769 | | OMAP_UHH_SYSCONFIG_CACTIVITY | ||
770 | | OMAP_UHH_SYSCONFIG_MIDLEMODE); | ||
771 | reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE; | ||
772 | |||
773 | |||
774 | } else if (is_omap_usbhs_rev2(omap)) { | ||
775 | reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR; | ||
776 | reg |= OMAP4_UHH_SYSCONFIG_NOIDLE; | ||
777 | reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR; | ||
778 | reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY; | ||
779 | } | ||
780 | |||
781 | usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg); | ||
782 | |||
783 | reg = usbhs_read(omap->uhh_base, OMAP_UHH_HOSTCONFIG); | ||
784 | /* setup ULPI bypass and burst configurations */ | ||
785 | reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN | ||
786 | | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN | ||
787 | | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN); | ||
788 | reg |= OMAP4_UHH_HOSTCONFIG_APP_START_CLK; | ||
789 | reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN; | ||
790 | |||
791 | if (is_omap_usbhs_rev1(omap)) { | ||
792 | if (pdata->port_mode[0] == OMAP_USBHS_PORT_MODE_UNUSED) | ||
793 | reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS; | ||
794 | if (pdata->port_mode[1] == OMAP_USBHS_PORT_MODE_UNUSED) | ||
795 | reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS; | ||
796 | if (pdata->port_mode[2] == OMAP_USBHS_PORT_MODE_UNUSED) | ||
797 | reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; | ||
798 | |||
799 | /* Bypass the TLL module for PHY mode operation */ | ||
800 | if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) { | ||
801 | dev_dbg(dev, "OMAP3 ES version <= ES2.1\n"); | ||
802 | if (is_ehci_phy_mode(pdata->port_mode[0]) || | ||
803 | is_ehci_phy_mode(pdata->port_mode[1]) || | ||
804 | is_ehci_phy_mode(pdata->port_mode[2])) | ||
805 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; | ||
806 | else | ||
807 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; | ||
808 | } else { | ||
809 | dev_dbg(dev, "OMAP3 ES version > ES2.1\n"); | ||
810 | if (is_ehci_phy_mode(pdata->port_mode[0])) | ||
811 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
812 | else | ||
813 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
814 | if (is_ehci_phy_mode(pdata->port_mode[1])) | ||
815 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
816 | else | ||
817 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
818 | if (is_ehci_phy_mode(pdata->port_mode[2])) | ||
819 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
820 | else | ||
821 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
822 | } | ||
823 | } else if (is_omap_usbhs_rev2(omap)) { | ||
824 | /* Clear port mode fields for PHY mode*/ | ||
825 | reg &= ~OMAP4_P1_MODE_CLEAR; | ||
826 | reg &= ~OMAP4_P2_MODE_CLEAR; | ||
827 | |||
828 | if (is_ehci_phy_mode(pdata->port_mode[0])) { | ||
829 | ret = clk_set_parent(omap->utmi_p1_fck, | ||
830 | omap->xclk60mhsp1_ck); | ||
831 | if (ret != 0) { | ||
832 | dev_err(dev, "xclk60mhsp1_ck set parent" | ||
833 | "failed error:%d\n", ret); | ||
834 | goto err_tll; | ||
835 | } | ||
836 | } else if (is_ehci_tll_mode(pdata->port_mode[0])) { | ||
837 | ret = clk_set_parent(omap->utmi_p1_fck, | ||
838 | omap->init_60m_fclk); | ||
839 | if (ret != 0) { | ||
840 | dev_err(dev, "init_60m_fclk set parent" | ||
841 | "failed error:%d\n", ret); | ||
842 | goto err_tll; | ||
843 | } | ||
844 | clk_enable(omap->usbhost_p1_fck); | ||
845 | clk_enable(omap->usbtll_p1_fck); | ||
846 | } | ||
847 | |||
848 | if (is_ehci_phy_mode(pdata->port_mode[1])) { | ||
849 | ret = clk_set_parent(omap->utmi_p2_fck, | ||
850 | omap->xclk60mhsp2_ck); | ||
851 | if (ret != 0) { | ||
852 | dev_err(dev, "xclk60mhsp1_ck set parent" | ||
853 | "failed error:%d\n", ret); | ||
854 | goto err_tll; | ||
855 | } | ||
856 | } else if (is_ehci_tll_mode(pdata->port_mode[1])) { | ||
857 | ret = clk_set_parent(omap->utmi_p2_fck, | ||
858 | omap->init_60m_fclk); | ||
859 | if (ret != 0) { | ||
860 | dev_err(dev, "init_60m_fclk set parent" | ||
861 | "failed error:%d\n", ret); | ||
862 | goto err_tll; | ||
863 | } | ||
864 | clk_enable(omap->usbhost_p2_fck); | ||
865 | clk_enable(omap->usbtll_p2_fck); | ||
866 | } | ||
867 | |||
868 | clk_enable(omap->utmi_p1_fck); | ||
869 | clk_enable(omap->utmi_p2_fck); | ||
870 | |||
871 | if (is_ehci_tll_mode(pdata->port_mode[0]) || | ||
872 | (is_ohci_port(pdata->port_mode[0]))) | ||
873 | reg |= OMAP4_P1_MODE_TLL; | ||
874 | else if (is_ehci_hsic_mode(pdata->port_mode[0])) | ||
875 | reg |= OMAP4_P1_MODE_HSIC; | ||
876 | |||
877 | if (is_ehci_tll_mode(pdata->port_mode[1]) || | ||
878 | (is_ohci_port(pdata->port_mode[1]))) | ||
879 | reg |= OMAP4_P2_MODE_TLL; | ||
880 | else if (is_ehci_hsic_mode(pdata->port_mode[1])) | ||
881 | reg |= OMAP4_P2_MODE_HSIC; | ||
882 | } | ||
883 | |||
884 | usbhs_write(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg); | ||
885 | dev_dbg(dev, "UHH setup done, uhh_hostconfig=%x\n", reg); | ||
886 | |||
887 | if (is_ehci_tll_mode(pdata->port_mode[0]) || | ||
888 | is_ehci_tll_mode(pdata->port_mode[1]) || | ||
889 | is_ehci_tll_mode(pdata->port_mode[2]) || | ||
890 | (is_ohci_port(pdata->port_mode[0])) || | ||
891 | (is_ohci_port(pdata->port_mode[1])) || | ||
892 | (is_ohci_port(pdata->port_mode[2]))) { | ||
893 | |||
894 | /* Enable UTMI mode for required TLL channels */ | ||
895 | if (is_omap_usbhs_rev2(omap)) | ||
896 | usbhs_omap_tll_init(dev, OMAP_REV2_TLL_CHANNEL_COUNT); | ||
897 | else | ||
898 | usbhs_omap_tll_init(dev, OMAP_TLL_CHANNEL_COUNT); | ||
899 | } | ||
900 | |||
901 | if (pdata->ehci_data->phy_reset) { | ||
902 | /* Hold the PHY in RESET for enough time till | ||
903 | * PHY is settled and ready | ||
904 | */ | ||
905 | udelay(10); | ||
906 | |||
907 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) | ||
908 | gpio_set_value | ||
909 | (pdata->ehci_data->reset_gpio_port[0], 0); | ||
910 | |||
911 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) | ||
912 | gpio_set_value | ||
913 | (pdata->ehci_data->reset_gpio_port[1], 0); | ||
914 | } | ||
915 | |||
916 | end_count: | ||
917 | omap->count++; | ||
918 | goto end_enable; | ||
919 | |||
920 | err_tll: | ||
921 | if (pdata->ehci_data->phy_reset) { | ||
922 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) | ||
923 | gpio_free(pdata->ehci_data->reset_gpio_port[0]); | ||
924 | |||
925 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) | ||
926 | gpio_free(pdata->ehci_data->reset_gpio_port[1]); | ||
927 | } | ||
928 | |||
929 | clk_disable(omap->usbtll_ick); | ||
930 | clk_disable(omap->usbtll_fck); | ||
931 | clk_disable(omap->usbhost_fs_fck); | ||
932 | clk_disable(omap->usbhost_hs_fck); | ||
933 | clk_disable(omap->usbhost_ick); | ||
934 | |||
935 | end_enable: | ||
936 | spin_unlock_irqrestore(&omap->lock, flags); | ||
937 | return ret; | ||
938 | } | ||
939 | |||
940 | static void usbhs_disable(struct device *dev) | ||
941 | { | ||
942 | struct usbhs_hcd_omap *omap = dev_get_drvdata(dev); | ||
943 | struct usbhs_omap_platform_data *pdata = &omap->platdata; | ||
944 | unsigned long flags = 0; | ||
945 | unsigned long timeout; | ||
946 | |||
947 | dev_dbg(dev, "stopping TI HSUSB Controller\n"); | ||
948 | |||
949 | spin_lock_irqsave(&omap->lock, flags); | ||
950 | |||
951 | if (omap->count == 0) | ||
952 | goto end_disble; | ||
953 | |||
954 | omap->count--; | ||
955 | |||
956 | if (omap->count != 0) | ||
957 | goto end_disble; | ||
958 | |||
959 | /* Reset OMAP modules for insmod/rmmod to work */ | ||
960 | usbhs_write(omap->uhh_base, OMAP_UHH_SYSCONFIG, | ||
961 | is_omap_usbhs_rev2(omap) ? | ||
962 | OMAP4_UHH_SYSCONFIG_SOFTRESET : | ||
963 | OMAP_UHH_SYSCONFIG_SOFTRESET); | ||
964 | |||
965 | timeout = jiffies + msecs_to_jiffies(100); | ||
966 | while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
967 | & (1 << 0))) { | ||
968 | cpu_relax(); | ||
969 | |||
970 | if (time_after(jiffies, timeout)) | ||
971 | dev_dbg(dev, "operation timed out\n"); | ||
972 | } | ||
973 | |||
974 | while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
975 | & (1 << 1))) { | ||
976 | cpu_relax(); | ||
977 | |||
978 | if (time_after(jiffies, timeout)) | ||
979 | dev_dbg(dev, "operation timed out\n"); | ||
980 | } | ||
981 | |||
982 | while (!(usbhs_read(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
983 | & (1 << 2))) { | ||
984 | cpu_relax(); | ||
985 | |||
986 | if (time_after(jiffies, timeout)) | ||
987 | dev_dbg(dev, "operation timed out\n"); | ||
988 | } | ||
989 | |||
990 | usbhs_write(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1)); | ||
991 | |||
992 | while (!(usbhs_read(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
993 | & (1 << 0))) { | ||
994 | cpu_relax(); | ||
995 | |||
996 | if (time_after(jiffies, timeout)) | ||
997 | dev_dbg(dev, "operation timed out\n"); | ||
998 | } | ||
999 | |||
1000 | if (pdata->ehci_data->phy_reset) { | ||
1001 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[0])) | ||
1002 | gpio_free(pdata->ehci_data->reset_gpio_port[0]); | ||
1003 | |||
1004 | if (gpio_is_valid(pdata->ehci_data->reset_gpio_port[1])) | ||
1005 | gpio_free(pdata->ehci_data->reset_gpio_port[1]); | ||
1006 | } | ||
1007 | |||
1008 | clk_disable(omap->utmi_p2_fck); | ||
1009 | clk_disable(omap->utmi_p1_fck); | ||
1010 | clk_disable(omap->usbtll_ick); | ||
1011 | clk_disable(omap->usbtll_fck); | ||
1012 | clk_disable(omap->usbhost_fs_fck); | ||
1013 | clk_disable(omap->usbhost_hs_fck); | ||
1014 | clk_disable(omap->usbhost_ick); | ||
1015 | |||
1016 | end_disble: | ||
1017 | spin_unlock_irqrestore(&omap->lock, flags); | ||
1018 | } | ||
1019 | |||
1020 | int omap_usbhs_enable(struct device *dev) | ||
1021 | { | ||
1022 | return usbhs_enable(dev->parent); | ||
1023 | } | ||
1024 | EXPORT_SYMBOL_GPL(omap_usbhs_enable); | ||
1025 | |||
1026 | void omap_usbhs_disable(struct device *dev) | ||
1027 | { | ||
1028 | usbhs_disable(dev->parent); | ||
1029 | } | ||
1030 | EXPORT_SYMBOL_GPL(omap_usbhs_disable); | ||
1031 | |||
1032 | static struct platform_driver usbhs_omap_driver = { | ||
1033 | .driver = { | ||
1034 | .name = (char *)usbhs_driver_name, | ||
1035 | .owner = THIS_MODULE, | ||
1036 | }, | ||
1037 | .remove = __exit_p(usbhs_omap_remove), | ||
1038 | }; | ||
1039 | |||
1040 | MODULE_AUTHOR("Keshava Munegowda <keshava_mgowda@ti.com>"); | ||
1041 | MODULE_ALIAS("platform:" USBHS_DRIVER_NAME); | ||
1042 | MODULE_LICENSE("GPL v2"); | ||
1043 | MODULE_DESCRIPTION("usb host common core driver for omap EHCI and OHCI"); | ||
1044 | |||
1045 | static int __init omap_usbhs_drvinit(void) | ||
1046 | { | ||
1047 | return platform_driver_probe(&usbhs_omap_driver, usbhs_omap_probe); | ||
1048 | } | ||
1049 | |||
1050 | /* | ||
1051 | * init before ehci and ohci drivers; | ||
1052 | * The usbhs core driver should be initialized much before | ||
1053 | * the omap ehci and ohci probe functions are called. | ||
1054 | */ | ||
1055 | fs_initcall(omap_usbhs_drvinit); | ||
1056 | |||
1057 | static void __exit omap_usbhs_drvexit(void) | ||
1058 | { | ||
1059 | platform_driver_unregister(&usbhs_omap_driver); | ||
1060 | } | ||
1061 | module_exit(omap_usbhs_drvexit); | ||
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c index a35fe61268de..29ccc0150996 100644 --- a/drivers/staging/usbip/vhci_hcd.c +++ b/drivers/staging/usbip/vhci_hcd.c | |||
@@ -255,8 +255,8 @@ static inline void hub_descriptor(struct usb_hub_descriptor *desc) | |||
255 | desc->wHubCharacteristics = (__force __u16) | 255 | desc->wHubCharacteristics = (__force __u16) |
256 | (__constant_cpu_to_le16(0x0001)); | 256 | (__constant_cpu_to_le16(0x0001)); |
257 | desc->bNbrPorts = VHCI_NPORTS; | 257 | desc->bNbrPorts = VHCI_NPORTS; |
258 | desc->bitmap[0] = 0xff; | 258 | desc->u.hs.DeviceRemovable[0] = 0xff; |
259 | desc->bitmap[1] = 0xff; | 259 | desc->u.hs.DeviceRemovable[1] = 0xff; |
260 | } | 260 | } |
261 | 261 | ||
262 | static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | 262 | static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 99ac70e32556..b268e9fccb47 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c | |||
@@ -168,7 +168,6 @@ struct uea_softc { | |||
168 | union cmv_dsc cmv_dsc; | 168 | union cmv_dsc cmv_dsc; |
169 | 169 | ||
170 | struct work_struct task; | 170 | struct work_struct task; |
171 | struct workqueue_struct *work_q; | ||
172 | u16 pageno; | 171 | u16 pageno; |
173 | u16 ovl; | 172 | u16 ovl; |
174 | 173 | ||
@@ -1879,7 +1878,7 @@ static int uea_start_reset(struct uea_softc *sc) | |||
1879 | /* start loading DSP */ | 1878 | /* start loading DSP */ |
1880 | sc->pageno = 0; | 1879 | sc->pageno = 0; |
1881 | sc->ovl = 0; | 1880 | sc->ovl = 0; |
1882 | queue_work(sc->work_q, &sc->task); | 1881 | schedule_work(&sc->task); |
1883 | 1882 | ||
1884 | /* wait for modem ready CMV */ | 1883 | /* wait for modem ready CMV */ |
1885 | ret = wait_cmv_ack(sc); | 1884 | ret = wait_cmv_ack(sc); |
@@ -2091,14 +2090,14 @@ static void uea_schedule_load_page_e1(struct uea_softc *sc, | |||
2091 | { | 2090 | { |
2092 | sc->pageno = intr->e1_bSwapPageNo; | 2091 | sc->pageno = intr->e1_bSwapPageNo; |
2093 | sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; | 2092 | sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; |
2094 | queue_work(sc->work_q, &sc->task); | 2093 | schedule_work(&sc->task); |
2095 | } | 2094 | } |
2096 | 2095 | ||
2097 | static void uea_schedule_load_page_e4(struct uea_softc *sc, | 2096 | static void uea_schedule_load_page_e4(struct uea_softc *sc, |
2098 | struct intr_pkt *intr) | 2097 | struct intr_pkt *intr) |
2099 | { | 2098 | { |
2100 | sc->pageno = intr->e4_bSwapPageNo; | 2099 | sc->pageno = intr->e4_bSwapPageNo; |
2101 | queue_work(sc->work_q, &sc->task); | 2100 | schedule_work(&sc->task); |
2102 | } | 2101 | } |
2103 | 2102 | ||
2104 | /* | 2103 | /* |
@@ -2170,13 +2169,6 @@ static int uea_boot(struct uea_softc *sc) | |||
2170 | 2169 | ||
2171 | init_waitqueue_head(&sc->sync_q); | 2170 | init_waitqueue_head(&sc->sync_q); |
2172 | 2171 | ||
2173 | sc->work_q = create_workqueue("ueagle-dsp"); | ||
2174 | if (!sc->work_q) { | ||
2175 | uea_err(INS_TO_USBDEV(sc), "cannot allocate workqueue\n"); | ||
2176 | uea_leaves(INS_TO_USBDEV(sc)); | ||
2177 | return -ENOMEM; | ||
2178 | } | ||
2179 | |||
2180 | if (UEA_CHIP_VERSION(sc) == ADI930) | 2172 | if (UEA_CHIP_VERSION(sc) == ADI930) |
2181 | load_XILINX_firmware(sc); | 2173 | load_XILINX_firmware(sc); |
2182 | 2174 | ||
@@ -2225,7 +2217,6 @@ err1: | |||
2225 | sc->urb_int = NULL; | 2217 | sc->urb_int = NULL; |
2226 | kfree(intr); | 2218 | kfree(intr); |
2227 | err0: | 2219 | err0: |
2228 | destroy_workqueue(sc->work_q); | ||
2229 | uea_leaves(INS_TO_USBDEV(sc)); | 2220 | uea_leaves(INS_TO_USBDEV(sc)); |
2230 | return -ENOMEM; | 2221 | return -ENOMEM; |
2231 | } | 2222 | } |
@@ -2246,8 +2237,8 @@ static void uea_stop(struct uea_softc *sc) | |||
2246 | kfree(sc->urb_int->transfer_buffer); | 2237 | kfree(sc->urb_int->transfer_buffer); |
2247 | usb_free_urb(sc->urb_int); | 2238 | usb_free_urb(sc->urb_int); |
2248 | 2239 | ||
2249 | /* stop any pending boot process, when no one can schedule work */ | 2240 | /* flush the work item, when no one can schedule it */ |
2250 | destroy_workqueue(sc->work_q); | 2241 | flush_work_sync(&sc->task); |
2251 | 2242 | ||
2252 | if (sc->dsp_firm) | 2243 | if (sc->dsp_firm) |
2253 | release_firmware(sc->dsp_firm); | 2244 | release_firmware(sc->dsp_firm); |
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c index 2c6965484fe8..b0585e623ba9 100644 --- a/drivers/usb/core/buffer.c +++ b/drivers/usb/core/buffer.c | |||
@@ -10,7 +10,7 @@ | |||
10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
11 | #include <linux/device.h> | 11 | #include <linux/device.h> |
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <asm/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/dma-mapping.h> | 14 | #include <linux/dma-mapping.h> |
15 | #include <linux/dmapool.h> | 15 | #include <linux/dmapool.h> |
16 | #include <linux/usb.h> | 16 | #include <linux/usb.h> |
@@ -22,7 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* FIXME tune these based on pool statistics ... */ | 24 | /* FIXME tune these based on pool statistics ... */ |
25 | static const size_t pool_max [HCD_BUFFER_POOLS] = { | 25 | static const size_t pool_max[HCD_BUFFER_POOLS] = { |
26 | /* platforms without dma-friendly caches might need to | 26 | /* platforms without dma-friendly caches might need to |
27 | * prevent cacheline sharing... | 27 | * prevent cacheline sharing... |
28 | */ | 28 | */ |
@@ -51,7 +51,7 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = { | |||
51 | int hcd_buffer_create(struct usb_hcd *hcd) | 51 | int hcd_buffer_create(struct usb_hcd *hcd) |
52 | { | 52 | { |
53 | char name[16]; | 53 | char name[16]; |
54 | int i, size; | 54 | int i, size; |
55 | 55 | ||
56 | if (!hcd->self.controller->dma_mask && | 56 | if (!hcd->self.controller->dma_mask && |
57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) | 57 | !(hcd->driver->flags & HCD_LOCAL_MEM)) |
@@ -64,7 +64,7 @@ int hcd_buffer_create(struct usb_hcd *hcd) | |||
64 | snprintf(name, sizeof name, "buffer-%d", size); | 64 | snprintf(name, sizeof name, "buffer-%d", size); |
65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, | 65 | hcd->pool[i] = dma_pool_create(name, hcd->self.controller, |
66 | size, size, 0); | 66 | size, size, 0); |
67 | if (!hcd->pool [i]) { | 67 | if (!hcd->pool[i]) { |
68 | hcd_buffer_destroy(hcd); | 68 | hcd_buffer_destroy(hcd); |
69 | return -ENOMEM; | 69 | return -ENOMEM; |
70 | } | 70 | } |
@@ -99,14 +99,14 @@ void hcd_buffer_destroy(struct usb_hcd *hcd) | |||
99 | */ | 99 | */ |
100 | 100 | ||
101 | void *hcd_buffer_alloc( | 101 | void *hcd_buffer_alloc( |
102 | struct usb_bus *bus, | 102 | struct usb_bus *bus, |
103 | size_t size, | 103 | size_t size, |
104 | gfp_t mem_flags, | 104 | gfp_t mem_flags, |
105 | dma_addr_t *dma | 105 | dma_addr_t *dma |
106 | ) | 106 | ) |
107 | { | 107 | { |
108 | struct usb_hcd *hcd = bus_to_hcd(bus); | 108 | struct usb_hcd *hcd = bus_to_hcd(bus); |
109 | int i; | 109 | int i; |
110 | 110 | ||
111 | /* some USB hosts just use PIO */ | 111 | /* some USB hosts just use PIO */ |
112 | if (!bus->controller->dma_mask && | 112 | if (!bus->controller->dma_mask && |
@@ -116,21 +116,21 @@ void *hcd_buffer_alloc( | |||
116 | } | 116 | } |
117 | 117 | ||
118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 118 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
119 | if (size <= pool_max [i]) | 119 | if (size <= pool_max[i]) |
120 | return dma_pool_alloc(hcd->pool [i], mem_flags, dma); | 120 | return dma_pool_alloc(hcd->pool[i], mem_flags, dma); |
121 | } | 121 | } |
122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); | 122 | return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags); |
123 | } | 123 | } |
124 | 124 | ||
125 | void hcd_buffer_free( | 125 | void hcd_buffer_free( |
126 | struct usb_bus *bus, | 126 | struct usb_bus *bus, |
127 | size_t size, | 127 | size_t size, |
128 | void *addr, | 128 | void *addr, |
129 | dma_addr_t dma | 129 | dma_addr_t dma |
130 | ) | 130 | ) |
131 | { | 131 | { |
132 | struct usb_hcd *hcd = bus_to_hcd(bus); | 132 | struct usb_hcd *hcd = bus_to_hcd(bus); |
133 | int i; | 133 | int i; |
134 | 134 | ||
135 | if (!addr) | 135 | if (!addr) |
136 | return; | 136 | return; |
@@ -142,8 +142,8 @@ void hcd_buffer_free( | |||
142 | } | 142 | } |
143 | 143 | ||
144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { | 144 | for (i = 0; i < HCD_BUFFER_POOLS; i++) { |
145 | if (size <= pool_max [i]) { | 145 | if (size <= pool_max[i]) { |
146 | dma_pool_free(hcd->pool [i], addr, dma); | 146 | dma_pool_free(hcd->pool[i], addr, dma); |
147 | return; | 147 | return; |
148 | } | 148 | } |
149 | } | 149 | } |
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index fca61720b873..38072e4e74bd 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c | |||
@@ -1659,6 +1659,11 @@ static int usb_runtime_suspend(struct device *dev) | |||
1659 | return -EAGAIN; | 1659 | return -EAGAIN; |
1660 | 1660 | ||
1661 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); | 1661 | status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); |
1662 | /* The PM core reacts badly unless the return code is 0, | ||
1663 | * -EAGAIN, or -EBUSY, so always return -EBUSY on an error. | ||
1664 | */ | ||
1665 | if (status != 0) | ||
1666 | return -EBUSY; | ||
1662 | return status; | 1667 | return status; |
1663 | } | 1668 | } |
1664 | 1669 | ||
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 64a035ba2eab..ce22f4a84ed0 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -192,13 +192,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
192 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", | 192 | "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", |
193 | pci_name(dev)); | 193 | pci_name(dev)); |
194 | retval = -ENODEV; | 194 | retval = -ENODEV; |
195 | goto err1; | 195 | goto disable_pci; |
196 | } | 196 | } |
197 | 197 | ||
198 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); | 198 | hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); |
199 | if (!hcd) { | 199 | if (!hcd) { |
200 | retval = -ENOMEM; | 200 | retval = -ENOMEM; |
201 | goto err1; | 201 | goto disable_pci; |
202 | } | 202 | } |
203 | 203 | ||
204 | if (driver->flags & HCD_MEMORY) { | 204 | if (driver->flags & HCD_MEMORY) { |
@@ -209,13 +209,13 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
209 | driver->description)) { | 209 | driver->description)) { |
210 | dev_dbg(&dev->dev, "controller already in use\n"); | 210 | dev_dbg(&dev->dev, "controller already in use\n"); |
211 | retval = -EBUSY; | 211 | retval = -EBUSY; |
212 | goto err2; | 212 | goto clear_companion; |
213 | } | 213 | } |
214 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | 214 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
215 | if (hcd->regs == NULL) { | 215 | if (hcd->regs == NULL) { |
216 | dev_dbg(&dev->dev, "error mapping memory\n"); | 216 | dev_dbg(&dev->dev, "error mapping memory\n"); |
217 | retval = -EFAULT; | 217 | retval = -EFAULT; |
218 | goto err3; | 218 | goto release_mem_region; |
219 | } | 219 | } |
220 | 220 | ||
221 | } else { | 221 | } else { |
@@ -236,7 +236,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
236 | if (region == PCI_ROM_RESOURCE) { | 236 | if (region == PCI_ROM_RESOURCE) { |
237 | dev_dbg(&dev->dev, "no i/o regions available\n"); | 237 | dev_dbg(&dev->dev, "no i/o regions available\n"); |
238 | retval = -EBUSY; | 238 | retval = -EBUSY; |
239 | goto err2; | 239 | goto clear_companion; |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
@@ -244,24 +244,24 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
244 | 244 | ||
245 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 245 | retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
246 | if (retval != 0) | 246 | if (retval != 0) |
247 | goto err4; | 247 | goto unmap_registers; |
248 | set_hs_companion(dev, hcd); | 248 | set_hs_companion(dev, hcd); |
249 | 249 | ||
250 | if (pci_dev_run_wake(dev)) | 250 | if (pci_dev_run_wake(dev)) |
251 | pm_runtime_put_noidle(&dev->dev); | 251 | pm_runtime_put_noidle(&dev->dev); |
252 | return retval; | 252 | return retval; |
253 | 253 | ||
254 | err4: | 254 | unmap_registers: |
255 | if (driver->flags & HCD_MEMORY) { | 255 | if (driver->flags & HCD_MEMORY) { |
256 | iounmap(hcd->regs); | 256 | iounmap(hcd->regs); |
257 | err3: | 257 | release_mem_region: |
258 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 258 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
259 | } else | 259 | } else |
260 | release_region(hcd->rsrc_start, hcd->rsrc_len); | 260 | release_region(hcd->rsrc_start, hcd->rsrc_len); |
261 | err2: | 261 | clear_companion: |
262 | clear_hs_companion(dev, hcd); | 262 | clear_hs_companion(dev, hcd); |
263 | usb_put_hcd(hcd); | 263 | usb_put_hcd(hcd); |
264 | err1: | 264 | disable_pci: |
265 | pci_disable_device(dev); | 265 | pci_disable_device(dev); |
266 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); | 266 | dev_err(&dev->dev, "init %s fail, %d\n", pci_name(dev), retval); |
267 | return retval; | 267 | return retval; |
@@ -363,11 +363,17 @@ static int check_root_hub_suspended(struct device *dev) | |||
363 | struct pci_dev *pci_dev = to_pci_dev(dev); | 363 | struct pci_dev *pci_dev = to_pci_dev(dev); |
364 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 364 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
365 | 365 | ||
366 | if (!(hcd->state == HC_STATE_SUSPENDED || | 366 | if (HCD_RH_RUNNING(hcd)) { |
367 | hcd->state == HC_STATE_HALT)) { | ||
368 | dev_warn(dev, "Root hub is not suspended\n"); | 367 | dev_warn(dev, "Root hub is not suspended\n"); |
369 | return -EBUSY; | 368 | return -EBUSY; |
370 | } | 369 | } |
370 | if (hcd->shared_hcd) { | ||
371 | hcd = hcd->shared_hcd; | ||
372 | if (HCD_RH_RUNNING(hcd)) { | ||
373 | dev_warn(dev, "Secondary root hub is not suspended\n"); | ||
374 | return -EBUSY; | ||
375 | } | ||
376 | } | ||
371 | return 0; | 377 | return 0; |
372 | } | 378 | } |
373 | 379 | ||
@@ -386,17 +392,22 @@ static int suspend_common(struct device *dev, bool do_wakeup) | |||
386 | if (retval) | 392 | if (retval) |
387 | return retval; | 393 | return retval; |
388 | 394 | ||
389 | if (hcd->driver->pci_suspend) { | 395 | if (hcd->driver->pci_suspend && !HCD_DEAD(hcd)) { |
390 | /* Optimization: Don't suspend if a root-hub wakeup is | 396 | /* Optimization: Don't suspend if a root-hub wakeup is |
391 | * pending and it would cause the HCD to wake up anyway. | 397 | * pending and it would cause the HCD to wake up anyway. |
392 | */ | 398 | */ |
393 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) | 399 | if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) |
394 | return -EBUSY; | 400 | return -EBUSY; |
401 | if (do_wakeup && hcd->shared_hcd && | ||
402 | HCD_WAKEUP_PENDING(hcd->shared_hcd)) | ||
403 | return -EBUSY; | ||
395 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); | 404 | retval = hcd->driver->pci_suspend(hcd, do_wakeup); |
396 | suspend_report_result(hcd->driver->pci_suspend, retval); | 405 | suspend_report_result(hcd->driver->pci_suspend, retval); |
397 | 406 | ||
398 | /* Check again in case wakeup raced with pci_suspend */ | 407 | /* Check again in case wakeup raced with pci_suspend */ |
399 | if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { | 408 | if ((retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) || |
409 | (retval == 0 && do_wakeup && hcd->shared_hcd && | ||
410 | HCD_WAKEUP_PENDING(hcd->shared_hcd))) { | ||
400 | if (hcd->driver->pci_resume) | 411 | if (hcd->driver->pci_resume) |
401 | hcd->driver->pci_resume(hcd, false); | 412 | hcd->driver->pci_resume(hcd, false); |
402 | retval = -EBUSY; | 413 | retval = -EBUSY; |
@@ -427,7 +438,9 @@ static int resume_common(struct device *dev, int event) | |||
427 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); | 438 | struct usb_hcd *hcd = pci_get_drvdata(pci_dev); |
428 | int retval; | 439 | int retval; |
429 | 440 | ||
430 | if (hcd->state != HC_STATE_SUSPENDED) { | 441 | if (HCD_RH_RUNNING(hcd) || |
442 | (hcd->shared_hcd && | ||
443 | HCD_RH_RUNNING(hcd->shared_hcd))) { | ||
431 | dev_dbg(dev, "can't resume, not suspended!\n"); | 444 | dev_dbg(dev, "can't resume, not suspended!\n"); |
432 | return 0; | 445 | return 0; |
433 | } | 446 | } |
@@ -441,8 +454,10 @@ static int resume_common(struct device *dev, int event) | |||
441 | pci_set_master(pci_dev); | 454 | pci_set_master(pci_dev); |
442 | 455 | ||
443 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 456 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
457 | if (hcd->shared_hcd) | ||
458 | clear_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
444 | 459 | ||
445 | if (hcd->driver->pci_resume) { | 460 | if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { |
446 | if (event != PM_EVENT_AUTO_RESUME) | 461 | if (event != PM_EVENT_AUTO_RESUME) |
447 | wait_for_companions(pci_dev, hcd); | 462 | wait_for_companions(pci_dev, hcd); |
448 | 463 | ||
@@ -450,6 +465,8 @@ static int resume_common(struct device *dev, int event) | |||
450 | event == PM_EVENT_RESTORE); | 465 | event == PM_EVENT_RESTORE); |
451 | if (retval) { | 466 | if (retval) { |
452 | dev_err(dev, "PCI post-resume error %d!\n", retval); | 467 | dev_err(dev, "PCI post-resume error %d!\n", retval); |
468 | if (hcd->shared_hcd) | ||
469 | usb_hc_died(hcd->shared_hcd); | ||
453 | usb_hc_died(hcd); | 470 | usb_hc_died(hcd); |
454 | } | 471 | } |
455 | } | 472 | } |
@@ -475,10 +492,11 @@ static int hcd_pci_suspend_noirq(struct device *dev) | |||
475 | 492 | ||
476 | pci_save_state(pci_dev); | 493 | pci_save_state(pci_dev); |
477 | 494 | ||
478 | /* If the root hub is HALTed rather than SUSPENDed, | 495 | /* If the root hub is dead rather than suspended, disallow remote |
479 | * disallow remote wakeup. | 496 | * wakeup. usb_hc_died() should ensure that both hosts are marked as |
497 | * dying, so we only need to check the primary roothub. | ||
480 | */ | 498 | */ |
481 | if (hcd->state == HC_STATE_HALT) | 499 | if (HCD_DEAD(hcd)) |
482 | device_set_wakeup_enable(dev, 0); | 500 | device_set_wakeup_enable(dev, 0); |
483 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); | 501 | dev_dbg(dev, "wakeup: %d\n", device_may_wakeup(dev)); |
484 | 502 | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index e935f71d7a34..02b4dbfa488a 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -297,7 +297,7 @@ static const u8 ss_rh_config_descriptor[] = { | |||
297 | /* one configuration */ | 297 | /* one configuration */ |
298 | 0x09, /* __u8 bLength; */ | 298 | 0x09, /* __u8 bLength; */ |
299 | 0x02, /* __u8 bDescriptorType; Configuration */ | 299 | 0x02, /* __u8 bDescriptorType; Configuration */ |
300 | 0x19, 0x00, /* __le16 wTotalLength; FIXME */ | 300 | 0x1f, 0x00, /* __le16 wTotalLength; */ |
301 | 0x01, /* __u8 bNumInterfaces; (1) */ | 301 | 0x01, /* __u8 bNumInterfaces; (1) */ |
302 | 0x01, /* __u8 bConfigurationValue; */ | 302 | 0x01, /* __u8 bConfigurationValue; */ |
303 | 0x00, /* __u8 iConfiguration; */ | 303 | 0x00, /* __u8 iConfiguration; */ |
@@ -327,11 +327,14 @@ static const u8 ss_rh_config_descriptor[] = { | |||
327 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) | 327 | /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) |
328 | * see hub.c:hub_configure() for details. */ | 328 | * see hub.c:hub_configure() for details. */ |
329 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, | 329 | (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, |
330 | 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ | 330 | 0x0c, /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */ |
331 | /* | 331 | |
332 | * All 3.0 hubs should have an endpoint companion descriptor, | 332 | /* one SuperSpeed endpoint companion descriptor */ |
333 | * but we're ignoring that for now. FIXME? | 333 | 0x06, /* __u8 ss_bLength */ |
334 | */ | 334 | 0x30, /* __u8 ss_bDescriptorType; SuperSpeed EP Companion */ |
335 | 0x00, /* __u8 ss_bMaxBurst; allows 1 TX between ACKs */ | ||
336 | 0x00, /* __u8 ss_bmAttributes; 1 packet per service interval */ | ||
337 | 0x02, 0x00 /* __le16 ss_wBytesPerInterval; 15 bits for max 15 ports */ | ||
335 | }; | 338 | }; |
336 | 339 | ||
337 | /*-------------------------------------------------------------------------*/ | 340 | /*-------------------------------------------------------------------------*/ |
@@ -504,7 +507,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
504 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | 507 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: |
505 | switch (wValue & 0xff00) { | 508 | switch (wValue & 0xff00) { |
506 | case USB_DT_DEVICE << 8: | 509 | case USB_DT_DEVICE << 8: |
507 | switch (hcd->driver->flags & HCD_MASK) { | 510 | switch (hcd->speed) { |
508 | case HCD_USB3: | 511 | case HCD_USB3: |
509 | bufp = usb3_rh_dev_descriptor; | 512 | bufp = usb3_rh_dev_descriptor; |
510 | break; | 513 | break; |
@@ -522,7 +525,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) | |||
522 | patch_protocol = 1; | 525 | patch_protocol = 1; |
523 | break; | 526 | break; |
524 | case USB_DT_CONFIG << 8: | 527 | case USB_DT_CONFIG << 8: |
525 | switch (hcd->driver->flags & HCD_MASK) { | 528 | switch (hcd->speed) { |
526 | case HCD_USB3: | 529 | case HCD_USB3: |
527 | bufp = ss_rh_config_descriptor; | 530 | bufp = ss_rh_config_descriptor; |
528 | len = sizeof ss_rh_config_descriptor; | 531 | len = sizeof ss_rh_config_descriptor; |
@@ -983,7 +986,7 @@ static int register_root_hub(struct usb_hcd *hcd) | |||
983 | spin_unlock_irq (&hcd_root_hub_lock); | 986 | spin_unlock_irq (&hcd_root_hub_lock); |
984 | 987 | ||
985 | /* Did the HC die before the root hub was registered? */ | 988 | /* Did the HC die before the root hub was registered? */ |
986 | if (hcd->state == HC_STATE_HALT) | 989 | if (HCD_DEAD(hcd) || hcd->state == HC_STATE_HALT) |
987 | usb_hc_died (hcd); /* This time clean up */ | 990 | usb_hc_died (hcd); /* This time clean up */ |
988 | } | 991 | } |
989 | 992 | ||
@@ -1089,13 +1092,10 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) | |||
1089 | * Check the host controller's state and add the URB to the | 1092 | * Check the host controller's state and add the URB to the |
1090 | * endpoint's queue. | 1093 | * endpoint's queue. |
1091 | */ | 1094 | */ |
1092 | switch (hcd->state) { | 1095 | if (HCD_RH_RUNNING(hcd)) { |
1093 | case HC_STATE_RUNNING: | ||
1094 | case HC_STATE_RESUMING: | ||
1095 | urb->unlinked = 0; | 1096 | urb->unlinked = 0; |
1096 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); | 1097 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); |
1097 | break; | 1098 | } else { |
1098 | default: | ||
1099 | rc = -ESHUTDOWN; | 1099 | rc = -ESHUTDOWN; |
1100 | goto done; | 1100 | goto done; |
1101 | } | 1101 | } |
@@ -1153,6 +1153,8 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, | |||
1153 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " | 1153 | dev_warn(hcd->self.controller, "Unlink after no-IRQ? " |
1154 | "Controller is probably using the wrong IRQ.\n"); | 1154 | "Controller is probably using the wrong IRQ.\n"); |
1155 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 1155 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
1156 | if (hcd->shared_hcd) | ||
1157 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
1156 | } | 1158 | } |
1157 | 1159 | ||
1158 | return 0; | 1160 | return 0; |
@@ -1262,7 +1264,7 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle, | |||
1262 | *dma_handle = 0; | 1264 | *dma_handle = 0; |
1263 | } | 1265 | } |
1264 | 1266 | ||
1265 | void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) | 1267 | void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) |
1266 | { | 1268 | { |
1267 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) | 1269 | if (urb->transfer_flags & URB_SETUP_MAP_SINGLE) |
1268 | dma_unmap_single(hcd->self.controller, | 1270 | dma_unmap_single(hcd->self.controller, |
@@ -1279,13 +1281,21 @@ void unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1279 | /* Make it safe to call this routine more than once */ | 1281 | /* Make it safe to call this routine more than once */ |
1280 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); | 1282 | urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL); |
1281 | } | 1283 | } |
1282 | EXPORT_SYMBOL_GPL(unmap_urb_setup_for_dma); | 1284 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_setup_for_dma); |
1283 | 1285 | ||
1284 | void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | 1286 | static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) |
1287 | { | ||
1288 | if (hcd->driver->unmap_urb_for_dma) | ||
1289 | hcd->driver->unmap_urb_for_dma(hcd, urb); | ||
1290 | else | ||
1291 | usb_hcd_unmap_urb_for_dma(hcd, urb); | ||
1292 | } | ||
1293 | |||
1294 | void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
1285 | { | 1295 | { |
1286 | enum dma_data_direction dir; | 1296 | enum dma_data_direction dir; |
1287 | 1297 | ||
1288 | unmap_urb_setup_for_dma(hcd, urb); | 1298 | usb_hcd_unmap_urb_setup_for_dma(hcd, urb); |
1289 | 1299 | ||
1290 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | 1300 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; |
1291 | if (urb->transfer_flags & URB_DMA_MAP_SG) | 1301 | if (urb->transfer_flags & URB_DMA_MAP_SG) |
@@ -1314,11 +1324,20 @@ void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | |||
1314 | urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | | 1324 | urb->transfer_flags &= ~(URB_DMA_MAP_SG | URB_DMA_MAP_PAGE | |
1315 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); | 1325 | URB_DMA_MAP_SINGLE | URB_MAP_LOCAL); |
1316 | } | 1326 | } |
1317 | EXPORT_SYMBOL_GPL(unmap_urb_for_dma); | 1327 | EXPORT_SYMBOL_GPL(usb_hcd_unmap_urb_for_dma); |
1318 | 1328 | ||
1319 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | 1329 | static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, |
1320 | gfp_t mem_flags) | 1330 | gfp_t mem_flags) |
1321 | { | 1331 | { |
1332 | if (hcd->driver->map_urb_for_dma) | ||
1333 | return hcd->driver->map_urb_for_dma(hcd, urb, mem_flags); | ||
1334 | else | ||
1335 | return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
1336 | } | ||
1337 | |||
1338 | int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | ||
1339 | gfp_t mem_flags) | ||
1340 | { | ||
1322 | enum dma_data_direction dir; | 1341 | enum dma_data_direction dir; |
1323 | int ret = 0; | 1342 | int ret = 0; |
1324 | 1343 | ||
@@ -1410,10 +1429,11 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | |||
1410 | } | 1429 | } |
1411 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | | 1430 | if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE | |
1412 | URB_SETUP_MAP_LOCAL))) | 1431 | URB_SETUP_MAP_LOCAL))) |
1413 | unmap_urb_for_dma(hcd, urb); | 1432 | usb_hcd_unmap_urb_for_dma(hcd, urb); |
1414 | } | 1433 | } |
1415 | return ret; | 1434 | return ret; |
1416 | } | 1435 | } |
1436 | EXPORT_SYMBOL_GPL(usb_hcd_map_urb_for_dma); | ||
1417 | 1437 | ||
1418 | /*-------------------------------------------------------------------------*/ | 1438 | /*-------------------------------------------------------------------------*/ |
1419 | 1439 | ||
@@ -1913,7 +1933,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev) | |||
1913 | { | 1933 | { |
1914 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | 1934 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1915 | 1935 | ||
1916 | if (!HC_IS_RUNNING (hcd->state)) | 1936 | if (!HCD_RH_RUNNING(hcd)) |
1917 | return -ESHUTDOWN; | 1937 | return -ESHUTDOWN; |
1918 | return hcd->driver->get_frame_number (hcd); | 1938 | return hcd->driver->get_frame_number (hcd); |
1919 | } | 1939 | } |
@@ -1930,9 +1950,15 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1930 | 1950 | ||
1931 | dev_dbg(&rhdev->dev, "bus %s%s\n", | 1951 | dev_dbg(&rhdev->dev, "bus %s%s\n", |
1932 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); | 1952 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "suspend"); |
1953 | if (HCD_DEAD(hcd)) { | ||
1954 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "suspend"); | ||
1955 | return 0; | ||
1956 | } | ||
1957 | |||
1933 | if (!hcd->driver->bus_suspend) { | 1958 | if (!hcd->driver->bus_suspend) { |
1934 | status = -ENOENT; | 1959 | status = -ENOENT; |
1935 | } else { | 1960 | } else { |
1961 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1936 | hcd->state = HC_STATE_QUIESCING; | 1962 | hcd->state = HC_STATE_QUIESCING; |
1937 | status = hcd->driver->bus_suspend(hcd); | 1963 | status = hcd->driver->bus_suspend(hcd); |
1938 | } | 1964 | } |
@@ -1940,7 +1966,12 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg) | |||
1940 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); | 1966 | usb_set_device_state(rhdev, USB_STATE_SUSPENDED); |
1941 | hcd->state = HC_STATE_SUSPENDED; | 1967 | hcd->state = HC_STATE_SUSPENDED; |
1942 | } else { | 1968 | } else { |
1943 | hcd->state = old_state; | 1969 | spin_lock_irq(&hcd_root_hub_lock); |
1970 | if (!HCD_DEAD(hcd)) { | ||
1971 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
1972 | hcd->state = old_state; | ||
1973 | } | ||
1974 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1944 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 1975 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
1945 | "suspend", status); | 1976 | "suspend", status); |
1946 | } | 1977 | } |
@@ -1955,9 +1986,13 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1955 | 1986 | ||
1956 | dev_dbg(&rhdev->dev, "usb %s%s\n", | 1987 | dev_dbg(&rhdev->dev, "usb %s%s\n", |
1957 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); | 1988 | (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); |
1989 | if (HCD_DEAD(hcd)) { | ||
1990 | dev_dbg(&rhdev->dev, "skipped %s of dead bus\n", "resume"); | ||
1991 | return 0; | ||
1992 | } | ||
1958 | if (!hcd->driver->bus_resume) | 1993 | if (!hcd->driver->bus_resume) |
1959 | return -ENOENT; | 1994 | return -ENOENT; |
1960 | if (hcd->state == HC_STATE_RUNNING) | 1995 | if (HCD_RH_RUNNING(hcd)) |
1961 | return 0; | 1996 | return 0; |
1962 | 1997 | ||
1963 | hcd->state = HC_STATE_RESUMING; | 1998 | hcd->state = HC_STATE_RESUMING; |
@@ -1966,10 +2001,15 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) | |||
1966 | if (status == 0) { | 2001 | if (status == 0) { |
1967 | /* TRSMRCY = 10 msec */ | 2002 | /* TRSMRCY = 10 msec */ |
1968 | msleep(10); | 2003 | msleep(10); |
1969 | usb_set_device_state(rhdev, rhdev->actconfig | 2004 | spin_lock_irq(&hcd_root_hub_lock); |
1970 | ? USB_STATE_CONFIGURED | 2005 | if (!HCD_DEAD(hcd)) { |
1971 | : USB_STATE_ADDRESS); | 2006 | usb_set_device_state(rhdev, rhdev->actconfig |
1972 | hcd->state = HC_STATE_RUNNING; | 2007 | ? USB_STATE_CONFIGURED |
2008 | : USB_STATE_ADDRESS); | ||
2009 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2010 | hcd->state = HC_STATE_RUNNING; | ||
2011 | } | ||
2012 | spin_unlock_irq(&hcd_root_hub_lock); | ||
1973 | } else { | 2013 | } else { |
1974 | hcd->state = old_state; | 2014 | hcd->state = old_state; |
1975 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", | 2015 | dev_dbg(&rhdev->dev, "bus %s fail, err %d\n", |
@@ -2080,12 +2120,14 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd) | |||
2080 | */ | 2120 | */ |
2081 | local_irq_save(flags); | 2121 | local_irq_save(flags); |
2082 | 2122 | ||
2083 | if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { | 2123 | if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) { |
2084 | rc = IRQ_NONE; | 2124 | rc = IRQ_NONE; |
2085 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { | 2125 | } else if (hcd->driver->irq(hcd) == IRQ_NONE) { |
2086 | rc = IRQ_NONE; | 2126 | rc = IRQ_NONE; |
2087 | } else { | 2127 | } else { |
2088 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 2128 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
2129 | if (hcd->shared_hcd) | ||
2130 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->shared_hcd->flags); | ||
2089 | 2131 | ||
2090 | if (unlikely(hcd->state == HC_STATE_HALT)) | 2132 | if (unlikely(hcd->state == HC_STATE_HALT)) |
2091 | usb_hc_died(hcd); | 2133 | usb_hc_died(hcd); |
@@ -2105,7 +2147,9 @@ EXPORT_SYMBOL_GPL(usb_hcd_irq); | |||
2105 | * | 2147 | * |
2106 | * This is called by bus glue to report a USB host controller that died | 2148 | * This is called by bus glue to report a USB host controller that died |
2107 | * while operations may still have been pending. It's called automatically | 2149 | * while operations may still have been pending. It's called automatically |
2108 | * by the PCI glue, so only glue for non-PCI busses should need to call it. | 2150 | * by the PCI glue, so only glue for non-PCI busses should need to call it. |
2151 | * | ||
2152 | * Only call this function with the primary HCD. | ||
2109 | */ | 2153 | */ |
2110 | void usb_hc_died (struct usb_hcd *hcd) | 2154 | void usb_hc_died (struct usb_hcd *hcd) |
2111 | { | 2155 | { |
@@ -2114,6 +2158,8 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2114 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); | 2158 | dev_err (hcd->self.controller, "HC died; cleaning up\n"); |
2115 | 2159 | ||
2116 | spin_lock_irqsave (&hcd_root_hub_lock, flags); | 2160 | spin_lock_irqsave (&hcd_root_hub_lock, flags); |
2161 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2162 | set_bit(HCD_FLAG_DEAD, &hcd->flags); | ||
2117 | if (hcd->rh_registered) { | 2163 | if (hcd->rh_registered) { |
2118 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2164 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2119 | 2165 | ||
@@ -2122,17 +2168,31 @@ void usb_hc_died (struct usb_hcd *hcd) | |||
2122 | USB_STATE_NOTATTACHED); | 2168 | USB_STATE_NOTATTACHED); |
2123 | usb_kick_khubd (hcd->self.root_hub); | 2169 | usb_kick_khubd (hcd->self.root_hub); |
2124 | } | 2170 | } |
2171 | if (usb_hcd_is_primary_hcd(hcd) && hcd->shared_hcd) { | ||
2172 | hcd = hcd->shared_hcd; | ||
2173 | if (hcd->rh_registered) { | ||
2174 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
2175 | |||
2176 | /* make khubd clean up old urbs and devices */ | ||
2177 | usb_set_device_state(hcd->self.root_hub, | ||
2178 | USB_STATE_NOTATTACHED); | ||
2179 | usb_kick_khubd(hcd->self.root_hub); | ||
2180 | } | ||
2181 | } | ||
2125 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); | 2182 | spin_unlock_irqrestore (&hcd_root_hub_lock, flags); |
2183 | /* Make sure that the other roothub is also deallocated. */ | ||
2126 | } | 2184 | } |
2127 | EXPORT_SYMBOL_GPL (usb_hc_died); | 2185 | EXPORT_SYMBOL_GPL (usb_hc_died); |
2128 | 2186 | ||
2129 | /*-------------------------------------------------------------------------*/ | 2187 | /*-------------------------------------------------------------------------*/ |
2130 | 2188 | ||
2131 | /** | 2189 | /** |
2132 | * usb_create_hcd - create and initialize an HCD structure | 2190 | * usb_create_shared_hcd - create and initialize an HCD structure |
2133 | * @driver: HC driver that will use this hcd | 2191 | * @driver: HC driver that will use this hcd |
2134 | * @dev: device for this HC, stored in hcd->self.controller | 2192 | * @dev: device for this HC, stored in hcd->self.controller |
2135 | * @bus_name: value to store in hcd->self.bus_name | 2193 | * @bus_name: value to store in hcd->self.bus_name |
2194 | * @primary_hcd: a pointer to the usb_hcd structure that is sharing the | ||
2195 | * PCI device. Only allocate certain resources for the primary HCD | ||
2136 | * Context: !in_interrupt() | 2196 | * Context: !in_interrupt() |
2137 | * | 2197 | * |
2138 | * Allocate a struct usb_hcd, with extra space at the end for the | 2198 | * Allocate a struct usb_hcd, with extra space at the end for the |
@@ -2141,8 +2201,9 @@ EXPORT_SYMBOL_GPL (usb_hc_died); | |||
2141 | * | 2201 | * |
2142 | * If memory is unavailable, returns NULL. | 2202 | * If memory is unavailable, returns NULL. |
2143 | */ | 2203 | */ |
2144 | struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | 2204 | struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, |
2145 | struct device *dev, const char *bus_name) | 2205 | struct device *dev, const char *bus_name, |
2206 | struct usb_hcd *primary_hcd) | ||
2146 | { | 2207 | { |
2147 | struct usb_hcd *hcd; | 2208 | struct usb_hcd *hcd; |
2148 | 2209 | ||
@@ -2151,7 +2212,24 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2151 | dev_dbg (dev, "hcd alloc failed\n"); | 2212 | dev_dbg (dev, "hcd alloc failed\n"); |
2152 | return NULL; | 2213 | return NULL; |
2153 | } | 2214 | } |
2154 | dev_set_drvdata(dev, hcd); | 2215 | if (primary_hcd == NULL) { |
2216 | hcd->bandwidth_mutex = kmalloc(sizeof(*hcd->bandwidth_mutex), | ||
2217 | GFP_KERNEL); | ||
2218 | if (!hcd->bandwidth_mutex) { | ||
2219 | kfree(hcd); | ||
2220 | dev_dbg(dev, "hcd bandwidth mutex alloc failed\n"); | ||
2221 | return NULL; | ||
2222 | } | ||
2223 | mutex_init(hcd->bandwidth_mutex); | ||
2224 | dev_set_drvdata(dev, hcd); | ||
2225 | } else { | ||
2226 | hcd->bandwidth_mutex = primary_hcd->bandwidth_mutex; | ||
2227 | hcd->primary_hcd = primary_hcd; | ||
2228 | primary_hcd->primary_hcd = primary_hcd; | ||
2229 | hcd->shared_hcd = primary_hcd; | ||
2230 | primary_hcd->shared_hcd = hcd; | ||
2231 | } | ||
2232 | |||
2155 | kref_init(&hcd->kref); | 2233 | kref_init(&hcd->kref); |
2156 | 2234 | ||
2157 | usb_bus_init(&hcd->self); | 2235 | usb_bus_init(&hcd->self); |
@@ -2165,19 +2243,53 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
2165 | #ifdef CONFIG_USB_SUSPEND | 2243 | #ifdef CONFIG_USB_SUSPEND |
2166 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); | 2244 | INIT_WORK(&hcd->wakeup_work, hcd_resume_work); |
2167 | #endif | 2245 | #endif |
2168 | mutex_init(&hcd->bandwidth_mutex); | ||
2169 | 2246 | ||
2170 | hcd->driver = driver; | 2247 | hcd->driver = driver; |
2248 | hcd->speed = driver->flags & HCD_MASK; | ||
2171 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : | 2249 | hcd->product_desc = (driver->product_desc) ? driver->product_desc : |
2172 | "USB Host Controller"; | 2250 | "USB Host Controller"; |
2173 | return hcd; | 2251 | return hcd; |
2174 | } | 2252 | } |
2253 | EXPORT_SYMBOL_GPL(usb_create_shared_hcd); | ||
2254 | |||
2255 | /** | ||
2256 | * usb_create_hcd - create and initialize an HCD structure | ||
2257 | * @driver: HC driver that will use this hcd | ||
2258 | * @dev: device for this HC, stored in hcd->self.controller | ||
2259 | * @bus_name: value to store in hcd->self.bus_name | ||
2260 | * Context: !in_interrupt() | ||
2261 | * | ||
2262 | * Allocate a struct usb_hcd, with extra space at the end for the | ||
2263 | * HC driver's private data. Initialize the generic members of the | ||
2264 | * hcd structure. | ||
2265 | * | ||
2266 | * If memory is unavailable, returns NULL. | ||
2267 | */ | ||
2268 | struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | ||
2269 | struct device *dev, const char *bus_name) | ||
2270 | { | ||
2271 | return usb_create_shared_hcd(driver, dev, bus_name, NULL); | ||
2272 | } | ||
2175 | EXPORT_SYMBOL_GPL(usb_create_hcd); | 2273 | EXPORT_SYMBOL_GPL(usb_create_hcd); |
2176 | 2274 | ||
2275 | /* | ||
2276 | * Roothubs that share one PCI device must also share the bandwidth mutex. | ||
2277 | * Don't deallocate the bandwidth_mutex until the last shared usb_hcd is | ||
2278 | * deallocated. | ||
2279 | * | ||
2280 | * Make sure to only deallocate the bandwidth_mutex when the primary HCD is | ||
2281 | * freed. When hcd_release() is called for the non-primary HCD, set the | ||
2282 | * primary_hcd's shared_hcd pointer to null (since the non-primary HCD will be | ||
2283 | * freed shortly). | ||
2284 | */ | ||
2177 | static void hcd_release (struct kref *kref) | 2285 | static void hcd_release (struct kref *kref) |
2178 | { | 2286 | { |
2179 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | 2287 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); |
2180 | 2288 | ||
2289 | if (usb_hcd_is_primary_hcd(hcd)) | ||
2290 | kfree(hcd->bandwidth_mutex); | ||
2291 | else | ||
2292 | hcd->shared_hcd->shared_hcd = NULL; | ||
2181 | kfree(hcd); | 2293 | kfree(hcd); |
2182 | } | 2294 | } |
2183 | 2295 | ||
@@ -2196,6 +2308,54 @@ void usb_put_hcd (struct usb_hcd *hcd) | |||
2196 | } | 2308 | } |
2197 | EXPORT_SYMBOL_GPL(usb_put_hcd); | 2309 | EXPORT_SYMBOL_GPL(usb_put_hcd); |
2198 | 2310 | ||
2311 | int usb_hcd_is_primary_hcd(struct usb_hcd *hcd) | ||
2312 | { | ||
2313 | if (!hcd->primary_hcd) | ||
2314 | return 1; | ||
2315 | return hcd == hcd->primary_hcd; | ||
2316 | } | ||
2317 | EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd); | ||
2318 | |||
2319 | static int usb_hcd_request_irqs(struct usb_hcd *hcd, | ||
2320 | unsigned int irqnum, unsigned long irqflags) | ||
2321 | { | ||
2322 | int retval; | ||
2323 | |||
2324 | if (hcd->driver->irq) { | ||
2325 | |||
2326 | /* IRQF_DISABLED doesn't work as advertised when used together | ||
2327 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2328 | * interrupts we can remove it here. | ||
2329 | */ | ||
2330 | if (irqflags & IRQF_SHARED) | ||
2331 | irqflags &= ~IRQF_DISABLED; | ||
2332 | |||
2333 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2334 | hcd->driver->description, hcd->self.busnum); | ||
2335 | retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2336 | hcd->irq_descr, hcd); | ||
2337 | if (retval != 0) { | ||
2338 | dev_err(hcd->self.controller, | ||
2339 | "request interrupt %d failed\n", | ||
2340 | irqnum); | ||
2341 | return retval; | ||
2342 | } | ||
2343 | hcd->irq = irqnum; | ||
2344 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2345 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2346 | "io mem" : "io base", | ||
2347 | (unsigned long long)hcd->rsrc_start); | ||
2348 | } else { | ||
2349 | hcd->irq = -1; | ||
2350 | if (hcd->rsrc_start) | ||
2351 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2352 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2353 | "io mem" : "io base", | ||
2354 | (unsigned long long)hcd->rsrc_start); | ||
2355 | } | ||
2356 | return 0; | ||
2357 | } | ||
2358 | |||
2199 | /** | 2359 | /** |
2200 | * usb_add_hcd - finish generic HCD structure initialization and register | 2360 | * usb_add_hcd - finish generic HCD structure initialization and register |
2201 | * @hcd: the usb_hcd structure to initialize | 2361 | * @hcd: the usb_hcd structure to initialize |
@@ -2236,7 +2396,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2236 | } | 2396 | } |
2237 | hcd->self.root_hub = rhdev; | 2397 | hcd->self.root_hub = rhdev; |
2238 | 2398 | ||
2239 | switch (hcd->driver->flags & HCD_MASK) { | 2399 | switch (hcd->speed) { |
2240 | case HCD_USB11: | 2400 | case HCD_USB11: |
2241 | rhdev->speed = USB_SPEED_FULL; | 2401 | rhdev->speed = USB_SPEED_FULL; |
2242 | break; | 2402 | break; |
@@ -2256,6 +2416,12 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2256 | */ | 2416 | */ |
2257 | device_init_wakeup(&rhdev->dev, 1); | 2417 | device_init_wakeup(&rhdev->dev, 1); |
2258 | 2418 | ||
2419 | /* HCD_FLAG_RH_RUNNING doesn't matter until the root hub is | ||
2420 | * registered. But since the controller can die at any time, | ||
2421 | * let's initialize the flag before touching the hardware. | ||
2422 | */ | ||
2423 | set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2424 | |||
2259 | /* "reset" is misnamed; its role is now one-time init. the controller | 2425 | /* "reset" is misnamed; its role is now one-time init. the controller |
2260 | * should already have been reset (and boot firmware kicked off etc). | 2426 | * should already have been reset (and boot firmware kicked off etc). |
2261 | */ | 2427 | */ |
@@ -2271,38 +2437,15 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2271 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); | 2437 | dev_dbg(hcd->self.controller, "supports USB remote wakeup\n"); |
2272 | 2438 | ||
2273 | /* enable irqs just before we start the controller */ | 2439 | /* enable irqs just before we start the controller */ |
2274 | if (hcd->driver->irq) { | 2440 | if (usb_hcd_is_primary_hcd(hcd)) { |
2275 | 2441 | retval = usb_hcd_request_irqs(hcd, irqnum, irqflags); | |
2276 | /* IRQF_DISABLED doesn't work as advertised when used together | 2442 | if (retval) |
2277 | * with IRQF_SHARED. As usb_hcd_irq() will always disable | ||
2278 | * interrupts we can remove it here. | ||
2279 | */ | ||
2280 | if (irqflags & IRQF_SHARED) | ||
2281 | irqflags &= ~IRQF_DISABLED; | ||
2282 | |||
2283 | snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", | ||
2284 | hcd->driver->description, hcd->self.busnum); | ||
2285 | if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags, | ||
2286 | hcd->irq_descr, hcd)) != 0) { | ||
2287 | dev_err(hcd->self.controller, | ||
2288 | "request interrupt %d failed\n", irqnum); | ||
2289 | goto err_request_irq; | 2443 | goto err_request_irq; |
2290 | } | ||
2291 | hcd->irq = irqnum; | ||
2292 | dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum, | ||
2293 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2294 | "io mem" : "io base", | ||
2295 | (unsigned long long)hcd->rsrc_start); | ||
2296 | } else { | ||
2297 | hcd->irq = -1; | ||
2298 | if (hcd->rsrc_start) | ||
2299 | dev_info(hcd->self.controller, "%s 0x%08llx\n", | ||
2300 | (hcd->driver->flags & HCD_MEMORY) ? | ||
2301 | "io mem" : "io base", | ||
2302 | (unsigned long long)hcd->rsrc_start); | ||
2303 | } | 2444 | } |
2304 | 2445 | ||
2305 | if ((retval = hcd->driver->start(hcd)) < 0) { | 2446 | hcd->state = HC_STATE_RUNNING; |
2447 | retval = hcd->driver->start(hcd); | ||
2448 | if (retval < 0) { | ||
2306 | dev_err(hcd->self.controller, "startup error %d\n", retval); | 2449 | dev_err(hcd->self.controller, "startup error %d\n", retval); |
2307 | goto err_hcd_driver_start; | 2450 | goto err_hcd_driver_start; |
2308 | } | 2451 | } |
@@ -2323,6 +2466,7 @@ int usb_add_hcd(struct usb_hcd *hcd, | |||
2323 | return retval; | 2466 | return retval; |
2324 | 2467 | ||
2325 | error_create_attr_group: | 2468 | error_create_attr_group: |
2469 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2326 | if (HC_IS_RUNNING(hcd->state)) | 2470 | if (HC_IS_RUNNING(hcd->state)) |
2327 | hcd->state = HC_STATE_QUIESCING; | 2471 | hcd->state = HC_STATE_QUIESCING; |
2328 | spin_lock_irq(&hcd_root_hub_lock); | 2472 | spin_lock_irq(&hcd_root_hub_lock); |
@@ -2344,7 +2488,7 @@ err_register_root_hub: | |||
2344 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2488 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2345 | del_timer_sync(&hcd->rh_timer); | 2489 | del_timer_sync(&hcd->rh_timer); |
2346 | err_hcd_driver_start: | 2490 | err_hcd_driver_start: |
2347 | if (hcd->irq >= 0) | 2491 | if (usb_hcd_is_primary_hcd(hcd) && hcd->irq >= 0) |
2348 | free_irq(irqnum, hcd); | 2492 | free_irq(irqnum, hcd); |
2349 | err_request_irq: | 2493 | err_request_irq: |
2350 | err_hcd_driver_setup: | 2494 | err_hcd_driver_setup: |
@@ -2375,6 +2519,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2375 | usb_get_dev(rhdev); | 2519 | usb_get_dev(rhdev); |
2376 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); | 2520 | sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); |
2377 | 2521 | ||
2522 | clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags); | ||
2378 | if (HC_IS_RUNNING (hcd->state)) | 2523 | if (HC_IS_RUNNING (hcd->state)) |
2379 | hcd->state = HC_STATE_QUIESCING; | 2524 | hcd->state = HC_STATE_QUIESCING; |
2380 | 2525 | ||
@@ -2407,8 +2552,10 @@ void usb_remove_hcd(struct usb_hcd *hcd) | |||
2407 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | 2552 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); |
2408 | del_timer_sync(&hcd->rh_timer); | 2553 | del_timer_sync(&hcd->rh_timer); |
2409 | 2554 | ||
2410 | if (hcd->irq >= 0) | 2555 | if (usb_hcd_is_primary_hcd(hcd)) { |
2411 | free_irq(hcd->irq, hcd); | 2556 | if (hcd->irq >= 0) |
2557 | free_irq(hcd->irq, hcd); | ||
2558 | } | ||
2412 | 2559 | ||
2413 | usb_put_dev(hcd->self.root_hub); | 2560 | usb_put_dev(hcd->self.root_hub); |
2414 | usb_deregister_bus(&hcd->self); | 2561 | usb_deregister_bus(&hcd->self); |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 19d3435e6140..564eaa5525d7 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -82,6 +82,10 @@ struct usb_hub { | |||
82 | void **port_owners; | 82 | void **port_owners; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | static inline int hub_is_superspeed(struct usb_device *hdev) | ||
86 | { | ||
87 | return (hdev->descriptor.bDeviceProtocol == 3); | ||
88 | } | ||
85 | 89 | ||
86 | /* Protect struct usb_device->state and ->children members | 90 | /* Protect struct usb_device->state and ->children members |
87 | * Note: Both are also protected by ->dev.sem, except that ->state can | 91 | * Note: Both are also protected by ->dev.sem, except that ->state can |
@@ -151,14 +155,14 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); | |||
151 | 155 | ||
152 | static int usb_reset_and_verify_device(struct usb_device *udev); | 156 | static int usb_reset_and_verify_device(struct usb_device *udev); |
153 | 157 | ||
154 | static inline char *portspeed(int portstatus) | 158 | static inline char *portspeed(struct usb_hub *hub, int portstatus) |
155 | { | 159 | { |
160 | if (hub_is_superspeed(hub->hdev)) | ||
161 | return "5.0 Gb/s"; | ||
156 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 162 | if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
157 | return "480 Mb/s"; | 163 | return "480 Mb/s"; |
158 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) | 164 | else if (portstatus & USB_PORT_STAT_LOW_SPEED) |
159 | return "1.5 Mb/s"; | 165 | return "1.5 Mb/s"; |
160 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | ||
161 | return "5.0 Gb/s"; | ||
162 | else | 166 | else |
163 | return "12 Mb/s"; | 167 | return "12 Mb/s"; |
164 | } | 168 | } |
@@ -172,14 +176,23 @@ static struct usb_hub *hdev_to_hub(struct usb_device *hdev) | |||
172 | } | 176 | } |
173 | 177 | ||
174 | /* USB 2.0 spec Section 11.24.4.5 */ | 178 | /* USB 2.0 spec Section 11.24.4.5 */ |
175 | static int get_hub_descriptor(struct usb_device *hdev, void *data, int size) | 179 | static int get_hub_descriptor(struct usb_device *hdev, void *data) |
176 | { | 180 | { |
177 | int i, ret; | 181 | int i, ret, size; |
182 | unsigned dtype; | ||
183 | |||
184 | if (hub_is_superspeed(hdev)) { | ||
185 | dtype = USB_DT_SS_HUB; | ||
186 | size = USB_DT_SS_HUB_SIZE; | ||
187 | } else { | ||
188 | dtype = USB_DT_HUB; | ||
189 | size = sizeof(struct usb_hub_descriptor); | ||
190 | } | ||
178 | 191 | ||
179 | for (i = 0; i < 3; i++) { | 192 | for (i = 0; i < 3; i++) { |
180 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), | 193 | ret = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0), |
181 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, | 194 | USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, |
182 | USB_DT_HUB << 8, 0, data, size, | 195 | dtype << 8, 0, data, size, |
183 | USB_CTRL_GET_TIMEOUT); | 196 | USB_CTRL_GET_TIMEOUT); |
184 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) | 197 | if (ret >= (USB_DT_HUB_NONVAR_SIZE + 2)) |
185 | return ret; | 198 | return ret; |
@@ -365,6 +378,16 @@ static int hub_port_status(struct usb_hub *hub, int port1, | |||
365 | } else { | 378 | } else { |
366 | *status = le16_to_cpu(hub->status->port.wPortStatus); | 379 | *status = le16_to_cpu(hub->status->port.wPortStatus); |
367 | *change = le16_to_cpu(hub->status->port.wPortChange); | 380 | *change = le16_to_cpu(hub->status->port.wPortChange); |
381 | |||
382 | if ((hub->hdev->parent != NULL) && | ||
383 | hub_is_superspeed(hub->hdev)) { | ||
384 | /* Translate the USB 3 port status */ | ||
385 | u16 tmp = *status & USB_SS_PORT_STAT_MASK; | ||
386 | if (*status & USB_SS_PORT_STAT_POWER) | ||
387 | tmp |= USB_PORT_STAT_POWER; | ||
388 | *status = tmp; | ||
389 | } | ||
390 | |||
368 | ret = 0; | 391 | ret = 0; |
369 | } | 392 | } |
370 | mutex_unlock(&hub->status_mutex); | 393 | mutex_unlock(&hub->status_mutex); |
@@ -607,7 +630,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
607 | if (hdev->children[port1-1] && set_state) | 630 | if (hdev->children[port1-1] && set_state) |
608 | usb_set_device_state(hdev->children[port1-1], | 631 | usb_set_device_state(hdev->children[port1-1], |
609 | USB_STATE_NOTATTACHED); | 632 | USB_STATE_NOTATTACHED); |
610 | if (!hub->error) | 633 | if (!hub->error && !hub_is_superspeed(hub->hdev)) |
611 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); | 634 | ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); |
612 | if (ret) | 635 | if (ret) |
613 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", | 636 | dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", |
@@ -616,7 +639,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) | |||
616 | } | 639 | } |
617 | 640 | ||
618 | /* | 641 | /* |
619 | * Disable a port and mark a logical connnect-change event, so that some | 642 | * Disable a port and mark a logical connect-change event, so that some |
620 | * time later khubd will disconnect() any existing usb_device on the port | 643 | * time later khubd will disconnect() any existing usb_device on the port |
621 | * and will re-enumerate if there actually is a device attached. | 644 | * and will re-enumerate if there actually is a device attached. |
622 | */ | 645 | */ |
@@ -769,12 +792,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
769 | * USB3 protocol ports will automatically transition | 792 | * USB3 protocol ports will automatically transition |
770 | * to Enabled state when detect an USB3.0 device attach. | 793 | * to Enabled state when detect an USB3.0 device attach. |
771 | * Do not disable USB3 protocol ports. | 794 | * Do not disable USB3 protocol ports. |
772 | * FIXME: USB3 root hub and external hubs are treated | ||
773 | * differently here. | ||
774 | */ | 795 | */ |
775 | if (hdev->descriptor.bDeviceProtocol != 3 || | 796 | if (!hub_is_superspeed(hdev)) { |
776 | (!hdev->parent && | ||
777 | !(portstatus & USB_PORT_STAT_SUPER_SPEED))) { | ||
778 | clear_port_feature(hdev, port1, | 797 | clear_port_feature(hdev, port1, |
779 | USB_PORT_FEAT_ENABLE); | 798 | USB_PORT_FEAT_ENABLE); |
780 | portstatus &= ~USB_PORT_STAT_ENABLE; | 799 | portstatus &= ~USB_PORT_STAT_ENABLE; |
@@ -795,6 +814,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) | |||
795 | clear_port_feature(hub->hdev, port1, | 814 | clear_port_feature(hub->hdev, port1, |
796 | USB_PORT_FEAT_C_ENABLE); | 815 | USB_PORT_FEAT_C_ENABLE); |
797 | } | 816 | } |
817 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
818 | need_debounce_delay = true; | ||
819 | clear_port_feature(hub->hdev, port1, | ||
820 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
821 | } | ||
798 | 822 | ||
799 | /* We can forget about a "removed" device when there's a | 823 | /* We can forget about a "removed" device when there's a |
800 | * physical disconnect or the connect status changes. | 824 | * physical disconnect or the connect status changes. |
@@ -964,12 +988,23 @@ static int hub_configure(struct usb_hub *hub, | |||
964 | goto fail; | 988 | goto fail; |
965 | } | 989 | } |
966 | 990 | ||
991 | if (hub_is_superspeed(hdev) && (hdev->parent != NULL)) { | ||
992 | ret = usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0), | ||
993 | HUB_SET_DEPTH, USB_RT_HUB, | ||
994 | hdev->level - 1, 0, NULL, 0, | ||
995 | USB_CTRL_SET_TIMEOUT); | ||
996 | |||
997 | if (ret < 0) { | ||
998 | message = "can't set hub depth"; | ||
999 | goto fail; | ||
1000 | } | ||
1001 | } | ||
1002 | |||
967 | /* Request the entire hub descriptor. | 1003 | /* Request the entire hub descriptor. |
968 | * hub->descriptor can handle USB_MAXCHILDREN ports, | 1004 | * hub->descriptor can handle USB_MAXCHILDREN ports, |
969 | * but the hub can/will return fewer bytes here. | 1005 | * but the hub can/will return fewer bytes here. |
970 | */ | 1006 | */ |
971 | ret = get_hub_descriptor(hdev, hub->descriptor, | 1007 | ret = get_hub_descriptor(hdev, hub->descriptor); |
972 | sizeof(*hub->descriptor)); | ||
973 | if (ret < 0) { | 1008 | if (ret < 0) { |
974 | message = "can't read hub descriptor"; | 1009 | message = "can't read hub descriptor"; |
975 | goto fail; | 1010 | goto fail; |
@@ -991,12 +1026,14 @@ static int hub_configure(struct usb_hub *hub, | |||
991 | 1026 | ||
992 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); | 1027 | wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); |
993 | 1028 | ||
994 | if (wHubCharacteristics & HUB_CHAR_COMPOUND) { | 1029 | /* FIXME for USB 3.0, skip for now */ |
1030 | if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && | ||
1031 | !(hub_is_superspeed(hdev))) { | ||
995 | int i; | 1032 | int i; |
996 | char portstr [USB_MAXCHILDREN + 1]; | 1033 | char portstr [USB_MAXCHILDREN + 1]; |
997 | 1034 | ||
998 | for (i = 0; i < hdev->maxchild; i++) | 1035 | for (i = 0; i < hdev->maxchild; i++) |
999 | portstr[i] = hub->descriptor->DeviceRemovable | 1036 | portstr[i] = hub->descriptor->u.hs.DeviceRemovable |
1000 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) | 1037 | [((i + 1) / 8)] & (1 << ((i + 1) % 8)) |
1001 | ? 'F' : 'R'; | 1038 | ? 'F' : 'R'; |
1002 | portstr[hdev->maxchild] = 0; | 1039 | portstr[hdev->maxchild] = 0; |
@@ -1253,8 +1290,14 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
1253 | desc = intf->cur_altsetting; | 1290 | desc = intf->cur_altsetting; |
1254 | hdev = interface_to_usbdev(intf); | 1291 | hdev = interface_to_usbdev(intf); |
1255 | 1292 | ||
1256 | /* Hubs have proper suspend/resume support */ | 1293 | /* Hubs have proper suspend/resume support. USB 3.0 device suspend is |
1257 | usb_enable_autosuspend(hdev); | 1294 | * different from USB 2.0/1.1 device suspend, and unfortunately we |
1295 | * don't support it yet. So leave autosuspend disabled for USB 3.0 | ||
1296 | * external hubs for now. Enable autosuspend for USB 3.0 roothubs, | ||
1297 | * since that isn't a "real" hub. | ||
1298 | */ | ||
1299 | if (!hub_is_superspeed(hdev) || !hdev->parent) | ||
1300 | usb_enable_autosuspend(hdev); | ||
1258 | 1301 | ||
1259 | if (hdev->level == MAX_TOPO_LEVEL) { | 1302 | if (hdev->level == MAX_TOPO_LEVEL) { |
1260 | dev_err(&intf->dev, | 1303 | dev_err(&intf->dev, |
@@ -1501,6 +1544,13 @@ void usb_set_device_state(struct usb_device *udev, | |||
1501 | EXPORT_SYMBOL_GPL(usb_set_device_state); | 1544 | EXPORT_SYMBOL_GPL(usb_set_device_state); |
1502 | 1545 | ||
1503 | /* | 1546 | /* |
1547 | * Choose a device number. | ||
1548 | * | ||
1549 | * Device numbers are used as filenames in usbfs. On USB-1.1 and | ||
1550 | * USB-2.0 buses they are also used as device addresses, however on | ||
1551 | * USB-3.0 buses the address is assigned by the controller hardware | ||
1552 | * and it usually is not the same as the device number. | ||
1553 | * | ||
1504 | * WUSB devices are simple: they have no hubs behind, so the mapping | 1554 | * WUSB devices are simple: they have no hubs behind, so the mapping |
1505 | * device <-> virtual port number becomes 1:1. Why? to simplify the | 1555 | * device <-> virtual port number becomes 1:1. Why? to simplify the |
1506 | * life of the device connection logic in | 1556 | * life of the device connection logic in |
@@ -1522,7 +1572,7 @@ EXPORT_SYMBOL_GPL(usb_set_device_state); | |||
1522 | * the HCD must setup data structures before issuing a set address | 1572 | * the HCD must setup data structures before issuing a set address |
1523 | * command to the hardware. | 1573 | * command to the hardware. |
1524 | */ | 1574 | */ |
1525 | static void choose_address(struct usb_device *udev) | 1575 | static void choose_devnum(struct usb_device *udev) |
1526 | { | 1576 | { |
1527 | int devnum; | 1577 | int devnum; |
1528 | struct usb_bus *bus = udev->bus; | 1578 | struct usb_bus *bus = udev->bus; |
@@ -1547,7 +1597,7 @@ static void choose_address(struct usb_device *udev) | |||
1547 | } | 1597 | } |
1548 | } | 1598 | } |
1549 | 1599 | ||
1550 | static void release_address(struct usb_device *udev) | 1600 | static void release_devnum(struct usb_device *udev) |
1551 | { | 1601 | { |
1552 | if (udev->devnum > 0) { | 1602 | if (udev->devnum > 0) { |
1553 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); | 1603 | clear_bit(udev->devnum, udev->bus->devmap.devicemap); |
@@ -1555,7 +1605,7 @@ static void release_address(struct usb_device *udev) | |||
1555 | } | 1605 | } |
1556 | } | 1606 | } |
1557 | 1607 | ||
1558 | static void update_address(struct usb_device *udev, int devnum) | 1608 | static void update_devnum(struct usb_device *udev, int devnum) |
1559 | { | 1609 | { |
1560 | /* The address for a WUSB device is managed by wusbcore. */ | 1610 | /* The address for a WUSB device is managed by wusbcore. */ |
1561 | if (!udev->wusb) | 1611 | if (!udev->wusb) |
@@ -1602,7 +1652,8 @@ void usb_disconnect(struct usb_device **pdev) | |||
1602 | * this quiesces everyting except pending urbs. | 1652 | * this quiesces everyting except pending urbs. |
1603 | */ | 1653 | */ |
1604 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); | 1654 | usb_set_device_state(udev, USB_STATE_NOTATTACHED); |
1605 | dev_info (&udev->dev, "USB disconnect, address %d\n", udev->devnum); | 1655 | dev_info(&udev->dev, "USB disconnect, device number %d\n", |
1656 | udev->devnum); | ||
1606 | 1657 | ||
1607 | usb_lock_device(udev); | 1658 | usb_lock_device(udev); |
1608 | 1659 | ||
@@ -1632,7 +1683,7 @@ void usb_disconnect(struct usb_device **pdev) | |||
1632 | /* Free the device number and delete the parent's children[] | 1683 | /* Free the device number and delete the parent's children[] |
1633 | * (or root_hub) pointer. | 1684 | * (or root_hub) pointer. |
1634 | */ | 1685 | */ |
1635 | release_address(udev); | 1686 | release_devnum(udev); |
1636 | 1687 | ||
1637 | /* Avoid races with recursively_mark_NOTATTACHED() */ | 1688 | /* Avoid races with recursively_mark_NOTATTACHED() */ |
1638 | spin_lock_irq(&device_state_lock); | 1689 | spin_lock_irq(&device_state_lock); |
@@ -2017,7 +2068,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, | |||
2017 | (portstatus & USB_PORT_STAT_ENABLE)) { | 2068 | (portstatus & USB_PORT_STAT_ENABLE)) { |
2018 | if (hub_is_wusb(hub)) | 2069 | if (hub_is_wusb(hub)) |
2019 | udev->speed = USB_SPEED_WIRELESS; | 2070 | udev->speed = USB_SPEED_WIRELESS; |
2020 | else if (portstatus & USB_PORT_STAT_SUPER_SPEED) | 2071 | else if (hub_is_superspeed(hub->hdev)) |
2021 | udev->speed = USB_SPEED_SUPER; | 2072 | udev->speed = USB_SPEED_SUPER; |
2022 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) | 2073 | else if (portstatus & USB_PORT_STAT_HIGH_SPEED) |
2023 | udev->speed = USB_SPEED_HIGH; | 2074 | udev->speed = USB_SPEED_HIGH; |
@@ -2073,7 +2124,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1, | |||
2073 | case 0: | 2124 | case 0: |
2074 | /* TRSTRCY = 10 ms; plus some extra */ | 2125 | /* TRSTRCY = 10 ms; plus some extra */ |
2075 | msleep(10 + 40); | 2126 | msleep(10 + 40); |
2076 | update_address(udev, 0); | 2127 | update_devnum(udev, 0); |
2077 | if (hcd->driver->reset_device) { | 2128 | if (hcd->driver->reset_device) { |
2078 | status = hcd->driver->reset_device(hcd, udev); | 2129 | status = hcd->driver->reset_device(hcd, udev); |
2079 | if (status < 0) { | 2130 | if (status < 0) { |
@@ -2636,7 +2687,7 @@ static int hub_set_address(struct usb_device *udev, int devnum) | |||
2636 | USB_REQ_SET_ADDRESS, 0, devnum, 0, | 2687 | USB_REQ_SET_ADDRESS, 0, devnum, 0, |
2637 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 2688 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
2638 | if (retval == 0) { | 2689 | if (retval == 0) { |
2639 | update_address(udev, devnum); | 2690 | update_devnum(udev, devnum); |
2640 | /* Device now using proper address. */ | 2691 | /* Device now using proper address. */ |
2641 | usb_set_device_state(udev, USB_STATE_ADDRESS); | 2692 | usb_set_device_state(udev, USB_STATE_ADDRESS); |
2642 | usb_ep0_reinit(udev); | 2693 | usb_ep0_reinit(udev); |
@@ -2741,9 +2792,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2741 | } | 2792 | } |
2742 | if (udev->speed != USB_SPEED_SUPER) | 2793 | if (udev->speed != USB_SPEED_SUPER) |
2743 | dev_info(&udev->dev, | 2794 | dev_info(&udev->dev, |
2744 | "%s %s speed %sUSB device using %s and address %d\n", | 2795 | "%s %s speed %sUSB device number %d using %s\n", |
2745 | (udev->config) ? "reset" : "new", speed, type, | 2796 | (udev->config) ? "reset" : "new", speed, type, |
2746 | udev->bus->controller->driver->name, devnum); | 2797 | devnum, udev->bus->controller->driver->name); |
2747 | 2798 | ||
2748 | /* Set up TT records, if needed */ | 2799 | /* Set up TT records, if needed */ |
2749 | if (hdev->tt) { | 2800 | if (hdev->tt) { |
@@ -2773,10 +2824,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2773 | * value. | 2824 | * value. |
2774 | */ | 2825 | */ |
2775 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { | 2826 | for (i = 0; i < GET_DESCRIPTOR_TRIES; (++i, msleep(100))) { |
2776 | /* | ||
2777 | * An xHCI controller cannot send any packets to a device until | ||
2778 | * a set address command successfully completes. | ||
2779 | */ | ||
2780 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { | 2827 | if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) { |
2781 | struct usb_device_descriptor *buf; | 2828 | struct usb_device_descriptor *buf; |
2782 | int r = 0; | 2829 | int r = 0; |
@@ -2859,9 +2906,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2859 | if (udev->speed == USB_SPEED_SUPER) { | 2906 | if (udev->speed == USB_SPEED_SUPER) { |
2860 | devnum = udev->devnum; | 2907 | devnum = udev->devnum; |
2861 | dev_info(&udev->dev, | 2908 | dev_info(&udev->dev, |
2862 | "%s SuperSpeed USB device using %s and address %d\n", | 2909 | "%s SuperSpeed USB device number %d using %s\n", |
2863 | (udev->config) ? "reset" : "new", | 2910 | (udev->config) ? "reset" : "new", |
2864 | udev->bus->controller->driver->name, devnum); | 2911 | devnum, udev->bus->controller->driver->name); |
2865 | } | 2912 | } |
2866 | 2913 | ||
2867 | /* cope with hardware quirkiness: | 2914 | /* cope with hardware quirkiness: |
@@ -2924,7 +2971,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1, | |||
2924 | fail: | 2971 | fail: |
2925 | if (retval) { | 2972 | if (retval) { |
2926 | hub_port_disable(hub, port1, 0); | 2973 | hub_port_disable(hub, port1, 0); |
2927 | update_address(udev, devnum); /* for disconnect processing */ | 2974 | update_devnum(udev, devnum); /* for disconnect processing */ |
2928 | } | 2975 | } |
2929 | mutex_unlock(&usb_address0_mutex); | 2976 | mutex_unlock(&usb_address0_mutex); |
2930 | return retval; | 2977 | return retval; |
@@ -3015,7 +3062,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3015 | 3062 | ||
3016 | dev_dbg (hub_dev, | 3063 | dev_dbg (hub_dev, |
3017 | "port %d, status %04x, change %04x, %s\n", | 3064 | "port %d, status %04x, change %04x, %s\n", |
3018 | port1, portstatus, portchange, portspeed (portstatus)); | 3065 | port1, portstatus, portchange, portspeed(hub, portstatus)); |
3019 | 3066 | ||
3020 | if (hub->has_indicators) { | 3067 | if (hub->has_indicators) { |
3021 | set_port_led(hub, port1, HUB_LED_AUTO); | 3068 | set_port_led(hub, port1, HUB_LED_AUTO); |
@@ -3116,32 +3163,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1, | |||
3116 | udev->level = hdev->level + 1; | 3163 | udev->level = hdev->level + 1; |
3117 | udev->wusb = hub_is_wusb(hub); | 3164 | udev->wusb = hub_is_wusb(hub); |
3118 | 3165 | ||
3119 | /* | 3166 | /* Only USB 3.0 devices are connected to SuperSpeed hubs. */ |
3120 | * USB 3.0 devices are reset automatically before the connect | 3167 | if (hub_is_superspeed(hub->hdev)) |
3121 | * port status change appears, and the root hub port status | ||
3122 | * shows the correct speed. We also get port change | ||
3123 | * notifications for USB 3.0 devices from the USB 3.0 portion of | ||
3124 | * an external USB 3.0 hub, but this isn't handled correctly yet | ||
3125 | * FIXME. | ||
3126 | */ | ||
3127 | |||
3128 | if (!(hcd->driver->flags & HCD_USB3)) | ||
3129 | udev->speed = USB_SPEED_UNKNOWN; | ||
3130 | else if ((hdev->parent == NULL) && | ||
3131 | (portstatus & USB_PORT_STAT_SUPER_SPEED)) | ||
3132 | udev->speed = USB_SPEED_SUPER; | 3168 | udev->speed = USB_SPEED_SUPER; |
3133 | else | 3169 | else |
3134 | udev->speed = USB_SPEED_UNKNOWN; | 3170 | udev->speed = USB_SPEED_UNKNOWN; |
3135 | 3171 | ||
3136 | /* | 3172 | choose_devnum(udev); |
3137 | * Set the address. | ||
3138 | * Note xHCI needs to issue an address device command later | ||
3139 | * in the hub_port_init sequence for SS/HS/FS/LS devices, | ||
3140 | * and xHC will assign an address to the device. But use | ||
3141 | * kernel assigned address here, to avoid any address conflict | ||
3142 | * issue. | ||
3143 | */ | ||
3144 | choose_address(udev); | ||
3145 | if (udev->devnum <= 0) { | 3173 | if (udev->devnum <= 0) { |
3146 | status = -ENOTCONN; /* Don't retry */ | 3174 | status = -ENOTCONN; /* Don't retry */ |
3147 | goto loop; | 3175 | goto loop; |
@@ -3233,7 +3261,7 @@ loop_disable: | |||
3233 | hub_port_disable(hub, port1, 1); | 3261 | hub_port_disable(hub, port1, 1); |
3234 | loop: | 3262 | loop: |
3235 | usb_ep0_reinit(udev); | 3263 | usb_ep0_reinit(udev); |
3236 | release_address(udev); | 3264 | release_devnum(udev); |
3237 | hub_free_dev(udev); | 3265 | hub_free_dev(udev); |
3238 | usb_put_dev(udev); | 3266 | usb_put_dev(udev); |
3239 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) | 3267 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) |
@@ -3410,12 +3438,19 @@ static void hub_events(void) | |||
3410 | } | 3438 | } |
3411 | 3439 | ||
3412 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { | 3440 | if (portchange & USB_PORT_STAT_C_OVERCURRENT) { |
3413 | dev_err (hub_dev, | 3441 | u16 status = 0; |
3414 | "over-current change on port %d\n", | 3442 | u16 unused; |
3415 | i); | 3443 | |
3444 | dev_dbg(hub_dev, "over-current change on port " | ||
3445 | "%d\n", i); | ||
3416 | clear_port_feature(hdev, i, | 3446 | clear_port_feature(hdev, i, |
3417 | USB_PORT_FEAT_C_OVER_CURRENT); | 3447 | USB_PORT_FEAT_C_OVER_CURRENT); |
3448 | msleep(100); /* Cool down */ | ||
3418 | hub_power_on(hub, true); | 3449 | hub_power_on(hub, true); |
3450 | hub_port_status(hub, i, &status, &unused); | ||
3451 | if (status & USB_PORT_STAT_OVERCURRENT) | ||
3452 | dev_err(hub_dev, "over-current " | ||
3453 | "condition on port %d\n", i); | ||
3419 | } | 3454 | } |
3420 | 3455 | ||
3421 | if (portchange & USB_PORT_STAT_C_RESET) { | 3456 | if (portchange & USB_PORT_STAT_C_RESET) { |
@@ -3425,6 +3460,25 @@ static void hub_events(void) | |||
3425 | clear_port_feature(hdev, i, | 3460 | clear_port_feature(hdev, i, |
3426 | USB_PORT_FEAT_C_RESET); | 3461 | USB_PORT_FEAT_C_RESET); |
3427 | } | 3462 | } |
3463 | if ((portchange & USB_PORT_STAT_C_BH_RESET) && | ||
3464 | hub_is_superspeed(hub->hdev)) { | ||
3465 | dev_dbg(hub_dev, | ||
3466 | "warm reset change on port %d\n", | ||
3467 | i); | ||
3468 | clear_port_feature(hdev, i, | ||
3469 | USB_PORT_FEAT_C_BH_PORT_RESET); | ||
3470 | } | ||
3471 | if (portchange & USB_PORT_STAT_C_LINK_STATE) { | ||
3472 | clear_port_feature(hub->hdev, i, | ||
3473 | USB_PORT_FEAT_C_PORT_LINK_STATE); | ||
3474 | } | ||
3475 | if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) { | ||
3476 | dev_warn(hub_dev, | ||
3477 | "config error on port %d\n", | ||
3478 | i); | ||
3479 | clear_port_feature(hub->hdev, i, | ||
3480 | USB_PORT_FEAT_C_PORT_CONFIG_ERROR); | ||
3481 | } | ||
3428 | 3482 | ||
3429 | if (connect_change) | 3483 | if (connect_change) |
3430 | hub_port_connect_change(hub, i, | 3484 | hub_port_connect_change(hub, i, |
@@ -3447,10 +3501,17 @@ static void hub_events(void) | |||
3447 | hub->limited_power = 0; | 3501 | hub->limited_power = 0; |
3448 | } | 3502 | } |
3449 | if (hubchange & HUB_CHANGE_OVERCURRENT) { | 3503 | if (hubchange & HUB_CHANGE_OVERCURRENT) { |
3450 | dev_dbg (hub_dev, "overcurrent change\n"); | 3504 | u16 status = 0; |
3451 | msleep(500); /* Cool down */ | 3505 | u16 unused; |
3506 | |||
3507 | dev_dbg(hub_dev, "over-current change\n"); | ||
3452 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); | 3508 | clear_hub_feature(hdev, C_HUB_OVER_CURRENT); |
3509 | msleep(500); /* Cool down */ | ||
3453 | hub_power_on(hub, true); | 3510 | hub_power_on(hub, true); |
3511 | hub_hub_status(hub, &status, &unused); | ||
3512 | if (status & HUB_STATUS_OVERCURRENT) | ||
3513 | dev_err(hub_dev, "over-current " | ||
3514 | "condition\n"); | ||
3454 | } | 3515 | } |
3455 | } | 3516 | } |
3456 | 3517 | ||
@@ -3699,13 +3760,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3699 | if (!udev->actconfig) | 3760 | if (!udev->actconfig) |
3700 | goto done; | 3761 | goto done; |
3701 | 3762 | ||
3702 | mutex_lock(&hcd->bandwidth_mutex); | 3763 | mutex_lock(hcd->bandwidth_mutex); |
3703 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); | 3764 | ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL); |
3704 | if (ret < 0) { | 3765 | if (ret < 0) { |
3705 | dev_warn(&udev->dev, | 3766 | dev_warn(&udev->dev, |
3706 | "Busted HC? Not enough HCD resources for " | 3767 | "Busted HC? Not enough HCD resources for " |
3707 | "old configuration.\n"); | 3768 | "old configuration.\n"); |
3708 | mutex_unlock(&hcd->bandwidth_mutex); | 3769 | mutex_unlock(hcd->bandwidth_mutex); |
3709 | goto re_enumerate; | 3770 | goto re_enumerate; |
3710 | } | 3771 | } |
3711 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 3772 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
@@ -3716,10 +3777,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev) | |||
3716 | dev_err(&udev->dev, | 3777 | dev_err(&udev->dev, |
3717 | "can't restore configuration #%d (error=%d)\n", | 3778 | "can't restore configuration #%d (error=%d)\n", |
3718 | udev->actconfig->desc.bConfigurationValue, ret); | 3779 | udev->actconfig->desc.bConfigurationValue, ret); |
3719 | mutex_unlock(&hcd->bandwidth_mutex); | 3780 | mutex_unlock(hcd->bandwidth_mutex); |
3720 | goto re_enumerate; | 3781 | goto re_enumerate; |
3721 | } | 3782 | } |
3722 | mutex_unlock(&hcd->bandwidth_mutex); | 3783 | mutex_unlock(hcd->bandwidth_mutex); |
3723 | usb_set_device_state(udev, USB_STATE_CONFIGURED); | 3784 | usb_set_device_state(udev, USB_STATE_CONFIGURED); |
3724 | 3785 | ||
3725 | /* Put interfaces back into the same altsettings as before. | 3786 | /* Put interfaces back into the same altsettings as before. |
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 832487423826..5701e857392b 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -1284,12 +1284,12 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1284 | /* Make sure we have enough bandwidth for this alternate interface. | 1284 | /* Make sure we have enough bandwidth for this alternate interface. |
1285 | * Remove the current alt setting and add the new alt setting. | 1285 | * Remove the current alt setting and add the new alt setting. |
1286 | */ | 1286 | */ |
1287 | mutex_lock(&hcd->bandwidth_mutex); | 1287 | mutex_lock(hcd->bandwidth_mutex); |
1288 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); | 1288 | ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt); |
1289 | if (ret < 0) { | 1289 | if (ret < 0) { |
1290 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", | 1290 | dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n", |
1291 | alternate); | 1291 | alternate); |
1292 | mutex_unlock(&hcd->bandwidth_mutex); | 1292 | mutex_unlock(hcd->bandwidth_mutex); |
1293 | return ret; | 1293 | return ret; |
1294 | } | 1294 | } |
1295 | 1295 | ||
@@ -1311,10 +1311,10 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) | |||
1311 | } else if (ret < 0) { | 1311 | } else if (ret < 0) { |
1312 | /* Re-instate the old alt setting */ | 1312 | /* Re-instate the old alt setting */ |
1313 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); | 1313 | usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting); |
1314 | mutex_unlock(&hcd->bandwidth_mutex); | 1314 | mutex_unlock(hcd->bandwidth_mutex); |
1315 | return ret; | 1315 | return ret; |
1316 | } | 1316 | } |
1317 | mutex_unlock(&hcd->bandwidth_mutex); | 1317 | mutex_unlock(hcd->bandwidth_mutex); |
1318 | 1318 | ||
1319 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here | 1319 | /* FIXME drivers shouldn't need to replicate/bugfix the logic here |
1320 | * when they implement async or easily-killable versions of this or | 1320 | * when they implement async or easily-killable versions of this or |
@@ -1413,7 +1413,7 @@ int usb_reset_configuration(struct usb_device *dev) | |||
1413 | 1413 | ||
1414 | config = dev->actconfig; | 1414 | config = dev->actconfig; |
1415 | retval = 0; | 1415 | retval = 0; |
1416 | mutex_lock(&hcd->bandwidth_mutex); | 1416 | mutex_lock(hcd->bandwidth_mutex); |
1417 | /* Make sure we have enough bandwidth for each alternate setting 0 */ | 1417 | /* Make sure we have enough bandwidth for each alternate setting 0 */ |
1418 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1418 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
1419 | struct usb_interface *intf = config->interface[i]; | 1419 | struct usb_interface *intf = config->interface[i]; |
@@ -1442,7 +1442,7 @@ reset_old_alts: | |||
1442 | usb_hcd_alloc_bandwidth(dev, NULL, | 1442 | usb_hcd_alloc_bandwidth(dev, NULL, |
1443 | alt, intf->cur_altsetting); | 1443 | alt, intf->cur_altsetting); |
1444 | } | 1444 | } |
1445 | mutex_unlock(&hcd->bandwidth_mutex); | 1445 | mutex_unlock(hcd->bandwidth_mutex); |
1446 | return retval; | 1446 | return retval; |
1447 | } | 1447 | } |
1448 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | 1448 | retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
@@ -1451,7 +1451,7 @@ reset_old_alts: | |||
1451 | NULL, 0, USB_CTRL_SET_TIMEOUT); | 1451 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
1452 | if (retval < 0) | 1452 | if (retval < 0) |
1453 | goto reset_old_alts; | 1453 | goto reset_old_alts; |
1454 | mutex_unlock(&hcd->bandwidth_mutex); | 1454 | mutex_unlock(hcd->bandwidth_mutex); |
1455 | 1455 | ||
1456 | /* re-init hc/hcd interface/endpoint state */ | 1456 | /* re-init hc/hcd interface/endpoint state */ |
1457 | for (i = 0; i < config->desc.bNumInterfaces; i++) { | 1457 | for (i = 0; i < config->desc.bNumInterfaces; i++) { |
@@ -1739,10 +1739,10 @@ free_interfaces: | |||
1739 | * host controller will not allow submissions to dropped endpoints. If | 1739 | * host controller will not allow submissions to dropped endpoints. If |
1740 | * this call fails, the device state is unchanged. | 1740 | * this call fails, the device state is unchanged. |
1741 | */ | 1741 | */ |
1742 | mutex_lock(&hcd->bandwidth_mutex); | 1742 | mutex_lock(hcd->bandwidth_mutex); |
1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); | 1743 | ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL); |
1744 | if (ret < 0) { | 1744 | if (ret < 0) { |
1745 | mutex_unlock(&hcd->bandwidth_mutex); | 1745 | mutex_unlock(hcd->bandwidth_mutex); |
1746 | usb_autosuspend_device(dev); | 1746 | usb_autosuspend_device(dev); |
1747 | goto free_interfaces; | 1747 | goto free_interfaces; |
1748 | } | 1748 | } |
@@ -1761,11 +1761,11 @@ free_interfaces: | |||
1761 | if (!cp) { | 1761 | if (!cp) { |
1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); | 1762 | usb_set_device_state(dev, USB_STATE_ADDRESS); |
1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); | 1763 | usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL); |
1764 | mutex_unlock(&hcd->bandwidth_mutex); | 1764 | mutex_unlock(hcd->bandwidth_mutex); |
1765 | usb_autosuspend_device(dev); | 1765 | usb_autosuspend_device(dev); |
1766 | goto free_interfaces; | 1766 | goto free_interfaces; |
1767 | } | 1767 | } |
1768 | mutex_unlock(&hcd->bandwidth_mutex); | 1768 | mutex_unlock(hcd->bandwidth_mutex); |
1769 | usb_set_device_state(dev, USB_STATE_CONFIGURED); | 1769 | usb_set_device_state(dev, USB_STATE_CONFIGURED); |
1770 | 1770 | ||
1771 | /* Initialize the new interface structures and the | 1771 | /* Initialize the new interface structures and the |
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index c14fc082864f..ae334b067c13 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -366,7 +366,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { | 366 | if (xfertype == USB_ENDPOINT_XFER_ISOC) { |
367 | int n, len; | 367 | int n, len; |
368 | 368 | ||
369 | /* FIXME SuperSpeed isoc endpoints have up to 16 bursts */ | 369 | /* SuperSpeed isoc endpoints have up to 16 bursts of up to |
370 | * 3 packets each | ||
371 | */ | ||
372 | if (dev->speed == USB_SPEED_SUPER) { | ||
373 | int burst = 1 + ep->ss_ep_comp.bMaxBurst; | ||
374 | int mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes); | ||
375 | max *= burst; | ||
376 | max *= mult; | ||
377 | } | ||
378 | |||
370 | /* "high bandwidth" mode, 1-3 packets/uframe? */ | 379 | /* "high bandwidth" mode, 1-3 packets/uframe? */ |
371 | if (dev->speed == USB_SPEED_HIGH) { | 380 | if (dev->speed == USB_SPEED_HIGH) { |
372 | int mult = 1 + ((max >> 11) & 0x03); | 381 | int mult = 1 + ((max >> 11) & 0x03); |
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index b975450f403e..a9cf484ecae4 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h | |||
@@ -122,6 +122,19 @@ static inline int is_usb_device_driver(struct device_driver *drv) | |||
122 | for_devices; | 122 | for_devices; |
123 | } | 123 | } |
124 | 124 | ||
125 | /* translate USB error codes to codes user space understands */ | ||
126 | static inline int usb_translate_errors(int error_code) | ||
127 | { | ||
128 | switch (error_code) { | ||
129 | case 0: | ||
130 | case -ENOMEM: | ||
131 | case -ENODEV: | ||
132 | return error_code; | ||
133 | default: | ||
134 | return -EIO; | ||
135 | } | ||
136 | } | ||
137 | |||
125 | 138 | ||
126 | /* for labeling diagnostics */ | 139 | /* for labeling diagnostics */ |
127 | extern const char *usbcore_name; | 140 | extern const char *usbcore_name; |
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c index 94ecdbc758ce..0bc06e2bcfcb 100644 --- a/drivers/usb/early/ehci-dbgp.c +++ b/drivers/usb/early/ehci-dbgp.c | |||
@@ -601,7 +601,7 @@ try_again: | |||
601 | dbgp_printk("dbgp_bulk_write failed: %d\n", ret); | 601 | dbgp_printk("dbgp_bulk_write failed: %d\n", ret); |
602 | goto err; | 602 | goto err; |
603 | } | 603 | } |
604 | dbgp_printk("small write doned\n"); | 604 | dbgp_printk("small write done\n"); |
605 | dbgp_not_safe = 0; | 605 | dbgp_not_safe = 0; |
606 | 606 | ||
607 | return 0; | 607 | return 0; |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index d50099675f28..bfde50e20b30 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -176,6 +176,18 @@ config USB_FSL_USB2 | |||
176 | default USB_GADGET | 176 | default USB_GADGET |
177 | select USB_GADGET_SELECTED | 177 | select USB_GADGET_SELECTED |
178 | 178 | ||
179 | config USB_GADGET_FUSB300 | ||
180 | boolean "Faraday FUSB300 USB Peripheral Controller" | ||
181 | select USB_GADGET_DUALSPEED | ||
182 | help | ||
183 | Faraday usb device controller FUSB300 driver | ||
184 | |||
185 | config USB_FUSB300 | ||
186 | tristate | ||
187 | depends on USB_GADGET_FUSB300 | ||
188 | default USB_GADGET | ||
189 | select USB_GADGET_SELECTED | ||
190 | |||
179 | config USB_GADGET_LH7A40X | 191 | config USB_GADGET_LH7A40X |
180 | boolean "LH7A40X" | 192 | boolean "LH7A40X" |
181 | depends on ARCH_LH7A40X | 193 | depends on ARCH_LH7A40X |
@@ -540,7 +552,7 @@ config USB_GADGET_CI13XXX_MSM | |||
540 | boolean "MIPS USB CI13xxx for MSM" | 552 | boolean "MIPS USB CI13xxx for MSM" |
541 | depends on ARCH_MSM | 553 | depends on ARCH_MSM |
542 | select USB_GADGET_DUALSPEED | 554 | select USB_GADGET_DUALSPEED |
543 | select USB_MSM_OTG_72K | 555 | select USB_MSM_OTG |
544 | help | 556 | help |
545 | MSM SoC has chipidea USB controller. This driver uses | 557 | MSM SoC has chipidea USB controller. This driver uses |
546 | ci13xxx_udc core. | 558 | ci13xxx_udc core. |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 55f5e8ae5924..305286e181d5 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_EG20T) += pch_udc.o | |||
28 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o | 28 | obj-$(CONFIG_USB_PXA_U2O) += mv_udc.o |
29 | mv_udc-y := mv_udc_core.o mv_udc_phy.o | 29 | mv_udc-y := mv_udc_core.o mv_udc_phy.o |
30 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o | 30 | obj-$(CONFIG_USB_CI13XXX_MSM) += ci13xxx_msm.o |
31 | obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o | ||
31 | 32 | ||
32 | # | 33 | # |
33 | # USB gadget drivers | 34 | # USB gadget drivers |
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index bdec36acd0fa..bb8ddf0469f9 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c | |||
@@ -1798,8 +1798,10 @@ static int __init at91udc_probe(struct platform_device *pdev) | |||
1798 | } | 1798 | } |
1799 | 1799 | ||
1800 | retval = device_register(&udc->gadget.dev); | 1800 | retval = device_register(&udc->gadget.dev); |
1801 | if (retval < 0) | 1801 | if (retval < 0) { |
1802 | put_device(&udc->gadget.dev); | ||
1802 | goto fail0b; | 1803 | goto fail0b; |
1804 | } | ||
1803 | 1805 | ||
1804 | /* don't do anything until we have both gadget driver and VBUS */ | 1806 | /* don't do anything until we have both gadget driver and VBUS */ |
1805 | clk_enable(udc->iclk); | 1807 | clk_enable(udc->iclk); |
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c index a1c67ae1572a..e09178bc1450 100644 --- a/drivers/usb/gadget/ci13xxx_udc.c +++ b/drivers/usb/gadget/ci13xxx_udc.c | |||
@@ -435,20 +435,6 @@ static int hw_ep_get_halt(int num, int dir) | |||
435 | } | 435 | } |
436 | 436 | ||
437 | /** | 437 | /** |
438 | * hw_ep_is_primed: test if endpoint is primed (execute without interruption) | ||
439 | * @num: endpoint number | ||
440 | * @dir: endpoint direction | ||
441 | * | ||
442 | * This function returns true if endpoint primed | ||
443 | */ | ||
444 | static int hw_ep_is_primed(int num, int dir) | ||
445 | { | ||
446 | u32 reg = hw_cread(CAP_ENDPTPRIME, ~0) | hw_cread(CAP_ENDPTSTAT, ~0); | ||
447 | |||
448 | return test_bit(hw_ep_bit(num, dir), (void *)®); | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * hw_test_and_clear_setup_status: test & clear setup status (execute without | 438 | * hw_test_and_clear_setup_status: test & clear setup status (execute without |
453 | * interruption) | 439 | * interruption) |
454 | * @n: bit number (endpoint) | 440 | * @n: bit number (endpoint) |
@@ -472,10 +458,6 @@ static int hw_ep_prime(int num, int dir, int is_ctrl) | |||
472 | { | 458 | { |
473 | int n = hw_ep_bit(num, dir); | 459 | int n = hw_ep_bit(num, dir); |
474 | 460 | ||
475 | /* the caller should flush first */ | ||
476 | if (hw_ep_is_primed(num, dir)) | ||
477 | return -EBUSY; | ||
478 | |||
479 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) | 461 | if (is_ctrl && dir == RX && hw_cread(CAP_ENDPTSETUPSTAT, BIT(num))) |
480 | return -EAGAIN; | 462 | return -EAGAIN; |
481 | 463 | ||
@@ -1434,6 +1416,8 @@ static inline u8 _usb_addr(struct ci13xxx_ep *ep) | |||
1434 | static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | 1416 | static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) |
1435 | { | 1417 | { |
1436 | unsigned i; | 1418 | unsigned i; |
1419 | int ret = 0; | ||
1420 | unsigned length = mReq->req.length; | ||
1437 | 1421 | ||
1438 | trace("%p, %p", mEp, mReq); | 1422 | trace("%p, %p", mEp, mReq); |
1439 | 1423 | ||
@@ -1441,53 +1425,91 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | |||
1441 | if (mReq->req.status == -EALREADY) | 1425 | if (mReq->req.status == -EALREADY) |
1442 | return -EALREADY; | 1426 | return -EALREADY; |
1443 | 1427 | ||
1444 | if (hw_ep_is_primed(mEp->num, mEp->dir)) | ||
1445 | return -EBUSY; | ||
1446 | |||
1447 | mReq->req.status = -EALREADY; | 1428 | mReq->req.status = -EALREADY; |
1448 | 1429 | if (length && !mReq->req.dma) { | |
1449 | if (mReq->req.length && !mReq->req.dma) { | ||
1450 | mReq->req.dma = \ | 1430 | mReq->req.dma = \ |
1451 | dma_map_single(mEp->device, mReq->req.buf, | 1431 | dma_map_single(mEp->device, mReq->req.buf, |
1452 | mReq->req.length, mEp->dir ? | 1432 | length, mEp->dir ? DMA_TO_DEVICE : |
1453 | DMA_TO_DEVICE : DMA_FROM_DEVICE); | 1433 | DMA_FROM_DEVICE); |
1454 | if (mReq->req.dma == 0) | 1434 | if (mReq->req.dma == 0) |
1455 | return -ENOMEM; | 1435 | return -ENOMEM; |
1456 | 1436 | ||
1457 | mReq->map = 1; | 1437 | mReq->map = 1; |
1458 | } | 1438 | } |
1459 | 1439 | ||
1440 | if (mReq->req.zero && length && (length % mEp->ep.maxpacket == 0)) { | ||
1441 | mReq->zptr = dma_pool_alloc(mEp->td_pool, GFP_ATOMIC, | ||
1442 | &mReq->zdma); | ||
1443 | if (mReq->zptr == NULL) { | ||
1444 | if (mReq->map) { | ||
1445 | dma_unmap_single(mEp->device, mReq->req.dma, | ||
1446 | length, mEp->dir ? DMA_TO_DEVICE : | ||
1447 | DMA_FROM_DEVICE); | ||
1448 | mReq->req.dma = 0; | ||
1449 | mReq->map = 0; | ||
1450 | } | ||
1451 | return -ENOMEM; | ||
1452 | } | ||
1453 | memset(mReq->zptr, 0, sizeof(*mReq->zptr)); | ||
1454 | mReq->zptr->next = TD_TERMINATE; | ||
1455 | mReq->zptr->token = TD_STATUS_ACTIVE; | ||
1456 | if (!mReq->req.no_interrupt) | ||
1457 | mReq->zptr->token |= TD_IOC; | ||
1458 | } | ||
1460 | /* | 1459 | /* |
1461 | * TD configuration | 1460 | * TD configuration |
1462 | * TODO - handle requests which spawns into several TDs | 1461 | * TODO - handle requests which spawns into several TDs |
1463 | */ | 1462 | */ |
1464 | memset(mReq->ptr, 0, sizeof(*mReq->ptr)); | 1463 | memset(mReq->ptr, 0, sizeof(*mReq->ptr)); |
1465 | mReq->ptr->next |= TD_TERMINATE; | 1464 | mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES); |
1466 | mReq->ptr->token = mReq->req.length << ffs_nr(TD_TOTAL_BYTES); | ||
1467 | mReq->ptr->token &= TD_TOTAL_BYTES; | 1465 | mReq->ptr->token &= TD_TOTAL_BYTES; |
1468 | mReq->ptr->token |= TD_IOC; | ||
1469 | mReq->ptr->token |= TD_STATUS_ACTIVE; | 1466 | mReq->ptr->token |= TD_STATUS_ACTIVE; |
1467 | if (mReq->zptr) { | ||
1468 | mReq->ptr->next = mReq->zdma; | ||
1469 | } else { | ||
1470 | mReq->ptr->next = TD_TERMINATE; | ||
1471 | if (!mReq->req.no_interrupt) | ||
1472 | mReq->ptr->token |= TD_IOC; | ||
1473 | } | ||
1470 | mReq->ptr->page[0] = mReq->req.dma; | 1474 | mReq->ptr->page[0] = mReq->req.dma; |
1471 | for (i = 1; i < 5; i++) | 1475 | for (i = 1; i < 5; i++) |
1472 | mReq->ptr->page[i] = | 1476 | mReq->ptr->page[i] = |
1473 | (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK; | 1477 | (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK; |
1474 | 1478 | ||
1475 | /* | 1479 | if (!list_empty(&mEp->qh.queue)) { |
1476 | * QH configuration | 1480 | struct ci13xxx_req *mReqPrev; |
1477 | * At this point it's guaranteed exclusive access to qhead | 1481 | int n = hw_ep_bit(mEp->num, mEp->dir); |
1478 | * (endpt is not primed) so it's no need to use tripwire | 1482 | int tmp_stat; |
1479 | */ | 1483 | |
1484 | mReqPrev = list_entry(mEp->qh.queue.prev, | ||
1485 | struct ci13xxx_req, queue); | ||
1486 | if (mReqPrev->zptr) | ||
1487 | mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK; | ||
1488 | else | ||
1489 | mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; | ||
1490 | wmb(); | ||
1491 | if (hw_cread(CAP_ENDPTPRIME, BIT(n))) | ||
1492 | goto done; | ||
1493 | do { | ||
1494 | hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); | ||
1495 | tmp_stat = hw_cread(CAP_ENDPTSTAT, BIT(n)); | ||
1496 | } while (!hw_cread(CAP_USBCMD, USBCMD_ATDTW)); | ||
1497 | hw_cwrite(CAP_USBCMD, USBCMD_ATDTW, 0); | ||
1498 | if (tmp_stat) | ||
1499 | goto done; | ||
1500 | } | ||
1501 | |||
1502 | /* QH configuration */ | ||
1480 | mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ | 1503 | mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ |
1481 | mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ | 1504 | mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ |
1482 | if (mReq->req.zero == 0) | 1505 | mEp->qh.ptr->cap |= QH_ZLT; |
1483 | mEp->qh.ptr->cap |= QH_ZLT; | ||
1484 | else | ||
1485 | mEp->qh.ptr->cap &= ~QH_ZLT; | ||
1486 | 1506 | ||
1487 | wmb(); /* synchronize before ep prime */ | 1507 | wmb(); /* synchronize before ep prime */ |
1488 | 1508 | ||
1489 | return hw_ep_prime(mEp->num, mEp->dir, | 1509 | ret = hw_ep_prime(mEp->num, mEp->dir, |
1490 | mEp->type == USB_ENDPOINT_XFER_CONTROL); | 1510 | mEp->type == USB_ENDPOINT_XFER_CONTROL); |
1511 | done: | ||
1512 | return ret; | ||
1491 | } | 1513 | } |
1492 | 1514 | ||
1493 | /** | 1515 | /** |
@@ -1504,8 +1526,15 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | |||
1504 | if (mReq->req.status != -EALREADY) | 1526 | if (mReq->req.status != -EALREADY) |
1505 | return -EINVAL; | 1527 | return -EINVAL; |
1506 | 1528 | ||
1507 | if (hw_ep_is_primed(mEp->num, mEp->dir)) | 1529 | if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0) |
1508 | hw_ep_flush(mEp->num, mEp->dir); | 1530 | return -EBUSY; |
1531 | |||
1532 | if (mReq->zptr) { | ||
1533 | if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0) | ||
1534 | return -EBUSY; | ||
1535 | dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma); | ||
1536 | mReq->zptr = NULL; | ||
1537 | } | ||
1509 | 1538 | ||
1510 | mReq->req.status = 0; | 1539 | mReq->req.status = 0; |
1511 | 1540 | ||
@@ -1517,9 +1546,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) | |||
1517 | } | 1546 | } |
1518 | 1547 | ||
1519 | mReq->req.status = mReq->ptr->token & TD_STATUS; | 1548 | mReq->req.status = mReq->ptr->token & TD_STATUS; |
1520 | if ((TD_STATUS_ACTIVE & mReq->req.status) != 0) | 1549 | if ((TD_STATUS_HALTED & mReq->req.status) != 0) |
1521 | mReq->req.status = -ECONNRESET; | ||
1522 | else if ((TD_STATUS_HALTED & mReq->req.status) != 0) | ||
1523 | mReq->req.status = -1; | 1550 | mReq->req.status = -1; |
1524 | else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) | 1551 | else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) |
1525 | mReq->req.status = -1; | 1552 | mReq->req.status = -1; |
@@ -1581,12 +1608,19 @@ static int _gadget_stop_activity(struct usb_gadget *gadget) | |||
1581 | { | 1608 | { |
1582 | struct usb_ep *ep; | 1609 | struct usb_ep *ep; |
1583 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); | 1610 | struct ci13xxx *udc = container_of(gadget, struct ci13xxx, gadget); |
1611 | unsigned long flags; | ||
1584 | 1612 | ||
1585 | trace("%p", gadget); | 1613 | trace("%p", gadget); |
1586 | 1614 | ||
1587 | if (gadget == NULL) | 1615 | if (gadget == NULL) |
1588 | return -EINVAL; | 1616 | return -EINVAL; |
1589 | 1617 | ||
1618 | spin_lock_irqsave(udc->lock, flags); | ||
1619 | udc->gadget.speed = USB_SPEED_UNKNOWN; | ||
1620 | udc->remote_wakeup = 0; | ||
1621 | udc->suspended = 0; | ||
1622 | spin_unlock_irqrestore(udc->lock, flags); | ||
1623 | |||
1590 | /* flush all endpoints */ | 1624 | /* flush all endpoints */ |
1591 | gadget_for_each_ep(ep, gadget) { | 1625 | gadget_for_each_ep(ep, gadget) { |
1592 | usb_ep_fifo_flush(ep); | 1626 | usb_ep_fifo_flush(ep); |
@@ -1720,7 +1754,8 @@ __acquires(mEp->lock) | |||
1720 | } | 1754 | } |
1721 | 1755 | ||
1722 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { | 1756 | if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { |
1723 | /* TODO: D1 - Remote Wakeup; D0 - Self Powered */ | 1757 | /* Assume that device is bus powered for now. */ |
1758 | *((u16 *)req->buf) = _udc->remote_wakeup << 1; | ||
1724 | retval = 0; | 1759 | retval = 0; |
1725 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ | 1760 | } else if ((setup->bRequestType & USB_RECIP_MASK) \ |
1726 | == USB_RECIP_ENDPOINT) { | 1761 | == USB_RECIP_ENDPOINT) { |
@@ -1749,6 +1784,28 @@ __acquires(mEp->lock) | |||
1749 | } | 1784 | } |
1750 | 1785 | ||
1751 | /** | 1786 | /** |
1787 | * isr_setup_status_complete: setup_status request complete function | ||
1788 | * @ep: endpoint | ||
1789 | * @req: request handled | ||
1790 | * | ||
1791 | * Caller must release lock. Put the port in test mode if test mode | ||
1792 | * feature is selected. | ||
1793 | */ | ||
1794 | static void | ||
1795 | isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req) | ||
1796 | { | ||
1797 | struct ci13xxx *udc = req->context; | ||
1798 | unsigned long flags; | ||
1799 | |||
1800 | trace("%p, %p", ep, req); | ||
1801 | |||
1802 | spin_lock_irqsave(udc->lock, flags); | ||
1803 | if (udc->test_mode) | ||
1804 | hw_port_test_set(udc->test_mode); | ||
1805 | spin_unlock_irqrestore(udc->lock, flags); | ||
1806 | } | ||
1807 | |||
1808 | /** | ||
1752 | * isr_setup_status_phase: queues the status phase of a setup transation | 1809 | * isr_setup_status_phase: queues the status phase of a setup transation |
1753 | * @udc: udc struct | 1810 | * @udc: udc struct |
1754 | * | 1811 | * |
@@ -1764,6 +1821,8 @@ __acquires(mEp->lock) | |||
1764 | trace("%p", udc); | 1821 | trace("%p", udc); |
1765 | 1822 | ||
1766 | mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in; | 1823 | mEp = (udc->ep0_dir == TX) ? &udc->ep0out : &udc->ep0in; |
1824 | udc->status->context = udc; | ||
1825 | udc->status->complete = isr_setup_status_complete; | ||
1767 | 1826 | ||
1768 | spin_unlock(mEp->lock); | 1827 | spin_unlock(mEp->lock); |
1769 | retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC); | 1828 | retval = usb_ep_queue(&mEp->ep, udc->status, GFP_ATOMIC); |
@@ -1783,7 +1842,7 @@ static int isr_tr_complete_low(struct ci13xxx_ep *mEp) | |||
1783 | __releases(mEp->lock) | 1842 | __releases(mEp->lock) |
1784 | __acquires(mEp->lock) | 1843 | __acquires(mEp->lock) |
1785 | { | 1844 | { |
1786 | struct ci13xxx_req *mReq; | 1845 | struct ci13xxx_req *mReq, *mReqTemp; |
1787 | int retval; | 1846 | int retval; |
1788 | 1847 | ||
1789 | trace("%p", mEp); | 1848 | trace("%p", mEp); |
@@ -1791,34 +1850,25 @@ __acquires(mEp->lock) | |||
1791 | if (list_empty(&mEp->qh.queue)) | 1850 | if (list_empty(&mEp->qh.queue)) |
1792 | return -EINVAL; | 1851 | return -EINVAL; |
1793 | 1852 | ||
1794 | /* pop oldest request */ | 1853 | list_for_each_entry_safe(mReq, mReqTemp, &mEp->qh.queue, |
1795 | mReq = list_entry(mEp->qh.queue.next, | 1854 | queue) { |
1796 | struct ci13xxx_req, queue); | 1855 | retval = _hardware_dequeue(mEp, mReq); |
1797 | list_del_init(&mReq->queue); | 1856 | if (retval < 0) |
1798 | 1857 | break; | |
1799 | retval = _hardware_dequeue(mEp, mReq); | 1858 | list_del_init(&mReq->queue); |
1800 | if (retval < 0) { | 1859 | dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); |
1801 | dbg_event(_usb_addr(mEp), "DONE", retval); | 1860 | if (mReq->req.complete != NULL) { |
1802 | goto done; | 1861 | spin_unlock(mEp->lock); |
1803 | } | 1862 | mReq->req.complete(&mEp->ep, &mReq->req); |
1804 | 1863 | spin_lock(mEp->lock); | |
1805 | dbg_done(_usb_addr(mEp), mReq->ptr->token, retval); | 1864 | } |
1806 | |||
1807 | if (!list_empty(&mEp->qh.queue)) { | ||
1808 | struct ci13xxx_req* mReqEnq; | ||
1809 | |||
1810 | mReqEnq = list_entry(mEp->qh.queue.next, | ||
1811 | struct ci13xxx_req, queue); | ||
1812 | _hardware_enqueue(mEp, mReqEnq); | ||
1813 | } | 1865 | } |
1814 | 1866 | ||
1815 | if (mReq->req.complete != NULL) { | 1867 | if (retval == EBUSY) |
1816 | spin_unlock(mEp->lock); | 1868 | retval = 0; |
1817 | mReq->req.complete(&mEp->ep, &mReq->req); | 1869 | if (retval < 0) |
1818 | spin_lock(mEp->lock); | 1870 | dbg_event(_usb_addr(mEp), "DONE", retval); |
1819 | } | ||
1820 | 1871 | ||
1821 | done: | ||
1822 | return retval; | 1872 | return retval; |
1823 | } | 1873 | } |
1824 | 1874 | ||
@@ -1833,6 +1883,7 @@ __releases(udc->lock) | |||
1833 | __acquires(udc->lock) | 1883 | __acquires(udc->lock) |
1834 | { | 1884 | { |
1835 | unsigned i; | 1885 | unsigned i; |
1886 | u8 tmode = 0; | ||
1836 | 1887 | ||
1837 | trace("%p", udc); | 1888 | trace("%p", udc); |
1838 | 1889 | ||
@@ -1895,22 +1946,32 @@ __acquires(udc->lock) | |||
1895 | 1946 | ||
1896 | switch (req.bRequest) { | 1947 | switch (req.bRequest) { |
1897 | case USB_REQ_CLEAR_FEATURE: | 1948 | case USB_REQ_CLEAR_FEATURE: |
1898 | if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | 1949 | if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && |
1899 | le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) | 1950 | le16_to_cpu(req.wValue) == |
1900 | goto delegate; | 1951 | USB_ENDPOINT_HALT) { |
1901 | if (req.wLength != 0) | 1952 | if (req.wLength != 0) |
1902 | break; | ||
1903 | num = le16_to_cpu(req.wIndex); | ||
1904 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
1905 | if (!udc->ci13xxx_ep[num].wedge) { | ||
1906 | spin_unlock(udc->lock); | ||
1907 | err = usb_ep_clear_halt( | ||
1908 | &udc->ci13xxx_ep[num].ep); | ||
1909 | spin_lock(udc->lock); | ||
1910 | if (err) | ||
1911 | break; | 1953 | break; |
1954 | num = le16_to_cpu(req.wIndex); | ||
1955 | num &= USB_ENDPOINT_NUMBER_MASK; | ||
1956 | if (!udc->ci13xxx_ep[num].wedge) { | ||
1957 | spin_unlock(udc->lock); | ||
1958 | err = usb_ep_clear_halt( | ||
1959 | &udc->ci13xxx_ep[num].ep); | ||
1960 | spin_lock(udc->lock); | ||
1961 | if (err) | ||
1962 | break; | ||
1963 | } | ||
1964 | err = isr_setup_status_phase(udc); | ||
1965 | } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) && | ||
1966 | le16_to_cpu(req.wValue) == | ||
1967 | USB_DEVICE_REMOTE_WAKEUP) { | ||
1968 | if (req.wLength != 0) | ||
1969 | break; | ||
1970 | udc->remote_wakeup = 0; | ||
1971 | err = isr_setup_status_phase(udc); | ||
1972 | } else { | ||
1973 | goto delegate; | ||
1912 | } | 1974 | } |
1913 | err = isr_setup_status_phase(udc); | ||
1914 | break; | 1975 | break; |
1915 | case USB_REQ_GET_STATUS: | 1976 | case USB_REQ_GET_STATUS: |
1916 | if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && | 1977 | if (type != (USB_DIR_IN|USB_RECIP_DEVICE) && |
@@ -1934,20 +1995,48 @@ __acquires(udc->lock) | |||
1934 | err = isr_setup_status_phase(udc); | 1995 | err = isr_setup_status_phase(udc); |
1935 | break; | 1996 | break; |
1936 | case USB_REQ_SET_FEATURE: | 1997 | case USB_REQ_SET_FEATURE: |
1937 | if (type != (USB_DIR_OUT|USB_RECIP_ENDPOINT) && | 1998 | if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && |
1938 | le16_to_cpu(req.wValue) != USB_ENDPOINT_HALT) | 1999 | le16_to_cpu(req.wValue) == |
1939 | goto delegate; | 2000 | USB_ENDPOINT_HALT) { |
1940 | if (req.wLength != 0) | 2001 | if (req.wLength != 0) |
1941 | break; | 2002 | break; |
1942 | num = le16_to_cpu(req.wIndex); | 2003 | num = le16_to_cpu(req.wIndex); |
1943 | num &= USB_ENDPOINT_NUMBER_MASK; | 2004 | num &= USB_ENDPOINT_NUMBER_MASK; |
1944 | 2005 | ||
1945 | spin_unlock(udc->lock); | 2006 | spin_unlock(udc->lock); |
1946 | err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); | 2007 | err = usb_ep_set_halt(&udc->ci13xxx_ep[num].ep); |
1947 | spin_lock(udc->lock); | 2008 | spin_lock(udc->lock); |
1948 | if (err) | 2009 | if (!err) |
1949 | break; | 2010 | isr_setup_status_phase(udc); |
1950 | err = isr_setup_status_phase(udc); | 2011 | } else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) { |
2012 | if (req.wLength != 0) | ||
2013 | break; | ||
2014 | switch (le16_to_cpu(req.wValue)) { | ||
2015 | case USB_DEVICE_REMOTE_WAKEUP: | ||
2016 | udc->remote_wakeup = 1; | ||
2017 | err = isr_setup_status_phase(udc); | ||
2018 | break; | ||
2019 | case USB_DEVICE_TEST_MODE: | ||
2020 | tmode = le16_to_cpu(req.wIndex) >> 8; | ||
2021 | switch (tmode) { | ||
2022 | case TEST_J: | ||
2023 | case TEST_K: | ||
2024 | case TEST_SE0_NAK: | ||
2025 | case TEST_PACKET: | ||
2026 | case TEST_FORCE_EN: | ||
2027 | udc->test_mode = tmode; | ||
2028 | err = isr_setup_status_phase( | ||
2029 | udc); | ||
2030 | break; | ||
2031 | default: | ||
2032 | break; | ||
2033 | } | ||
2034 | default: | ||
2035 | goto delegate; | ||
2036 | } | ||
2037 | } else { | ||
2038 | goto delegate; | ||
2039 | } | ||
1951 | break; | 2040 | break; |
1952 | default: | 2041 | default: |
1953 | delegate: | 2042 | delegate: |
@@ -2178,15 +2267,15 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req, | |||
2178 | /* push request */ | 2267 | /* push request */ |
2179 | mReq->req.status = -EINPROGRESS; | 2268 | mReq->req.status = -EINPROGRESS; |
2180 | mReq->req.actual = 0; | 2269 | mReq->req.actual = 0; |
2181 | list_add_tail(&mReq->queue, &mEp->qh.queue); | ||
2182 | 2270 | ||
2183 | if (list_is_singular(&mEp->qh.queue)) | 2271 | retval = _hardware_enqueue(mEp, mReq); |
2184 | retval = _hardware_enqueue(mEp, mReq); | ||
2185 | 2272 | ||
2186 | if (retval == -EALREADY) { | 2273 | if (retval == -EALREADY) { |
2187 | dbg_event(_usb_addr(mEp), "QUEUE", retval); | 2274 | dbg_event(_usb_addr(mEp), "QUEUE", retval); |
2188 | retval = 0; | 2275 | retval = 0; |
2189 | } | 2276 | } |
2277 | if (!retval) | ||
2278 | list_add_tail(&mReq->queue, &mEp->qh.queue); | ||
2190 | 2279 | ||
2191 | done: | 2280 | done: |
2192 | spin_unlock_irqrestore(mEp->lock, flags); | 2281 | spin_unlock_irqrestore(mEp->lock, flags); |
@@ -2206,19 +2295,25 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) | |||
2206 | 2295 | ||
2207 | trace("%p, %p", ep, req); | 2296 | trace("%p, %p", ep, req); |
2208 | 2297 | ||
2209 | if (ep == NULL || req == NULL || mEp->desc == NULL || | 2298 | if (ep == NULL || req == NULL || mReq->req.status != -EALREADY || |
2210 | list_empty(&mReq->queue) || list_empty(&mEp->qh.queue)) | 2299 | mEp->desc == NULL || list_empty(&mReq->queue) || |
2300 | list_empty(&mEp->qh.queue)) | ||
2211 | return -EINVAL; | 2301 | return -EINVAL; |
2212 | 2302 | ||
2213 | spin_lock_irqsave(mEp->lock, flags); | 2303 | spin_lock_irqsave(mEp->lock, flags); |
2214 | 2304 | ||
2215 | dbg_event(_usb_addr(mEp), "DEQUEUE", 0); | 2305 | dbg_event(_usb_addr(mEp), "DEQUEUE", 0); |
2216 | 2306 | ||
2217 | if (mReq->req.status == -EALREADY) | 2307 | hw_ep_flush(mEp->num, mEp->dir); |
2218 | _hardware_dequeue(mEp, mReq); | ||
2219 | 2308 | ||
2220 | /* pop request */ | 2309 | /* pop request */ |
2221 | list_del_init(&mReq->queue); | 2310 | list_del_init(&mReq->queue); |
2311 | if (mReq->map) { | ||
2312 | dma_unmap_single(mEp->device, mReq->req.dma, mReq->req.length, | ||
2313 | mEp->dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
2314 | mReq->req.dma = 0; | ||
2315 | mReq->map = 0; | ||
2316 | } | ||
2222 | req->status = -ECONNRESET; | 2317 | req->status = -ECONNRESET; |
2223 | 2318 | ||
2224 | if (mReq->req.complete != NULL) { | 2319 | if (mReq->req.complete != NULL) { |
@@ -2377,6 +2472,31 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
2377 | return 0; | 2472 | return 0; |
2378 | } | 2473 | } |
2379 | 2474 | ||
2475 | static int ci13xxx_wakeup(struct usb_gadget *_gadget) | ||
2476 | { | ||
2477 | struct ci13xxx *udc = container_of(_gadget, struct ci13xxx, gadget); | ||
2478 | unsigned long flags; | ||
2479 | int ret = 0; | ||
2480 | |||
2481 | trace(); | ||
2482 | |||
2483 | spin_lock_irqsave(udc->lock, flags); | ||
2484 | if (!udc->remote_wakeup) { | ||
2485 | ret = -EOPNOTSUPP; | ||
2486 | dbg_trace("remote wakeup feature is not enabled\n"); | ||
2487 | goto out; | ||
2488 | } | ||
2489 | if (!hw_cread(CAP_PORTSC, PORTSC_SUSP)) { | ||
2490 | ret = -EINVAL; | ||
2491 | dbg_trace("port is not suspended\n"); | ||
2492 | goto out; | ||
2493 | } | ||
2494 | hw_cwrite(CAP_PORTSC, PORTSC_FPR, PORTSC_FPR); | ||
2495 | out: | ||
2496 | spin_unlock_irqrestore(udc->lock, flags); | ||
2497 | return ret; | ||
2498 | } | ||
2499 | |||
2380 | /** | 2500 | /** |
2381 | * Device operations part of the API to the USB controller hardware, | 2501 | * Device operations part of the API to the USB controller hardware, |
2382 | * which don't involve endpoints (or i/o) | 2502 | * which don't involve endpoints (or i/o) |
@@ -2384,6 +2504,7 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active) | |||
2384 | */ | 2504 | */ |
2385 | static const struct usb_gadget_ops usb_gadget_ops = { | 2505 | static const struct usb_gadget_ops usb_gadget_ops = { |
2386 | .vbus_session = ci13xxx_vbus_session, | 2506 | .vbus_session = ci13xxx_vbus_session, |
2507 | .wakeup = ci13xxx_wakeup, | ||
2387 | }; | 2508 | }; |
2388 | 2509 | ||
2389 | /** | 2510 | /** |
@@ -2626,6 +2747,12 @@ static irqreturn_t udc_irq(void) | |||
2626 | isr_statistics.pci++; | 2747 | isr_statistics.pci++; |
2627 | udc->gadget.speed = hw_port_is_high_speed() ? | 2748 | udc->gadget.speed = hw_port_is_high_speed() ? |
2628 | USB_SPEED_HIGH : USB_SPEED_FULL; | 2749 | USB_SPEED_HIGH : USB_SPEED_FULL; |
2750 | if (udc->suspended) { | ||
2751 | spin_unlock(udc->lock); | ||
2752 | udc->driver->resume(&udc->gadget); | ||
2753 | spin_lock(udc->lock); | ||
2754 | udc->suspended = 0; | ||
2755 | } | ||
2629 | } | 2756 | } |
2630 | if (USBi_UEI & intr) | 2757 | if (USBi_UEI & intr) |
2631 | isr_statistics.uei++; | 2758 | isr_statistics.uei++; |
@@ -2633,8 +2760,15 @@ static irqreturn_t udc_irq(void) | |||
2633 | isr_statistics.ui++; | 2760 | isr_statistics.ui++; |
2634 | isr_tr_complete_handler(udc); | 2761 | isr_tr_complete_handler(udc); |
2635 | } | 2762 | } |
2636 | if (USBi_SLI & intr) | 2763 | if (USBi_SLI & intr) { |
2764 | if (udc->gadget.speed != USB_SPEED_UNKNOWN) { | ||
2765 | udc->suspended = 1; | ||
2766 | spin_unlock(udc->lock); | ||
2767 | udc->driver->suspend(&udc->gadget); | ||
2768 | spin_lock(udc->lock); | ||
2769 | } | ||
2637 | isr_statistics.sli++; | 2770 | isr_statistics.sli++; |
2771 | } | ||
2638 | retval = IRQ_HANDLED; | 2772 | retval = IRQ_HANDLED; |
2639 | } else { | 2773 | } else { |
2640 | isr_statistics.none++; | 2774 | isr_statistics.none++; |
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h index a2492b65f98c..23707775cb43 100644 --- a/drivers/usb/gadget/ci13xxx_udc.h +++ b/drivers/usb/gadget/ci13xxx_udc.h | |||
@@ -33,6 +33,7 @@ struct ci13xxx_td { | |||
33 | /* 0 */ | 33 | /* 0 */ |
34 | u32 next; | 34 | u32 next; |
35 | #define TD_TERMINATE BIT(0) | 35 | #define TD_TERMINATE BIT(0) |
36 | #define TD_ADDR_MASK (0xFFFFFFEUL << 5) | ||
36 | /* 1 */ | 37 | /* 1 */ |
37 | u32 token; | 38 | u32 token; |
38 | #define TD_STATUS (0x00FFUL << 0) | 39 | #define TD_STATUS (0x00FFUL << 0) |
@@ -74,6 +75,8 @@ struct ci13xxx_req { | |||
74 | struct list_head queue; | 75 | struct list_head queue; |
75 | struct ci13xxx_td *ptr; | 76 | struct ci13xxx_td *ptr; |
76 | dma_addr_t dma; | 77 | dma_addr_t dma; |
78 | struct ci13xxx_td *zptr; | ||
79 | dma_addr_t zdma; | ||
77 | }; | 80 | }; |
78 | 81 | ||
79 | /* Extension of usb_ep */ | 82 | /* Extension of usb_ep */ |
@@ -125,6 +128,10 @@ struct ci13xxx { | |||
125 | u32 ep0_dir; /* ep0 direction */ | 128 | u32 ep0_dir; /* ep0 direction */ |
126 | #define ep0out ci13xxx_ep[0] | 129 | #define ep0out ci13xxx_ep[0] |
127 | #define ep0in ci13xxx_ep[16] | 130 | #define ep0in ci13xxx_ep[16] |
131 | u8 remote_wakeup; /* Is remote wakeup feature | ||
132 | enabled by the host? */ | ||
133 | u8 suspended; /* suspended by the host */ | ||
134 | u8 test_mode; /* the selected test mode */ | ||
128 | 135 | ||
129 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ | 136 | struct usb_gadget_driver *driver; /* 3rd party gadget driver */ |
130 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ | 137 | struct ci13xxx_udc_driver *udc_driver; /* device controller driver */ |
@@ -152,6 +159,7 @@ struct ci13xxx { | |||
152 | #define USBCMD_RS BIT(0) | 159 | #define USBCMD_RS BIT(0) |
153 | #define USBCMD_RST BIT(1) | 160 | #define USBCMD_RST BIT(1) |
154 | #define USBCMD_SUTW BIT(13) | 161 | #define USBCMD_SUTW BIT(13) |
162 | #define USBCMD_ATDTW BIT(14) | ||
155 | 163 | ||
156 | /* USBSTS & USBINTR */ | 164 | /* USBSTS & USBINTR */ |
157 | #define USBi_UI BIT(0) | 165 | #define USBi_UI BIT(0) |
@@ -165,6 +173,7 @@ struct ci13xxx { | |||
165 | #define DEVICEADDR_USBADR (0x7FUL << 25) | 173 | #define DEVICEADDR_USBADR (0x7FUL << 25) |
166 | 174 | ||
167 | /* PORTSC */ | 175 | /* PORTSC */ |
176 | #define PORTSC_FPR BIT(6) | ||
168 | #define PORTSC_SUSP BIT(7) | 177 | #define PORTSC_SUSP BIT(7) |
169 | #define PORTSC_HSP BIT(9) | 178 | #define PORTSC_HSP BIT(9) |
170 | #define PORTSC_PTC (0x0FUL << 16) | 179 | #define PORTSC_PTC (0x0FUL << 16) |
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 1ba4befe336b..c2251c40a205 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c | |||
@@ -813,7 +813,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
813 | */ | 813 | */ |
814 | req->zero = 0; | 814 | req->zero = 0; |
815 | req->complete = composite_setup_complete; | 815 | req->complete = composite_setup_complete; |
816 | req->length = USB_BUFSIZ; | 816 | req->length = 0; |
817 | gadget->ep0->driver_data = cdev; | 817 | gadget->ep0->driver_data = cdev; |
818 | 818 | ||
819 | switch (ctrl->bRequest) { | 819 | switch (ctrl->bRequest) { |
@@ -887,7 +887,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
887 | case USB_REQ_SET_INTERFACE: | 887 | case USB_REQ_SET_INTERFACE: |
888 | if (ctrl->bRequestType != USB_RECIP_INTERFACE) | 888 | if (ctrl->bRequestType != USB_RECIP_INTERFACE) |
889 | goto unknown; | 889 | goto unknown; |
890 | if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) | 890 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) |
891 | break; | 891 | break; |
892 | f = cdev->config->interface[intf]; | 892 | f = cdev->config->interface[intf]; |
893 | if (!f) | 893 | if (!f) |
@@ -899,7 +899,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
899 | case USB_REQ_GET_INTERFACE: | 899 | case USB_REQ_GET_INTERFACE: |
900 | if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) | 900 | if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) |
901 | goto unknown; | 901 | goto unknown; |
902 | if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) | 902 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) |
903 | break; | 903 | break; |
904 | f = cdev->config->interface[intf]; | 904 | f = cdev->config->interface[intf]; |
905 | if (!f) | 905 | if (!f) |
@@ -928,7 +928,7 @@ unknown: | |||
928 | */ | 928 | */ |
929 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 929 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
930 | case USB_RECIP_INTERFACE: | 930 | case USB_RECIP_INTERFACE: |
931 | if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) | 931 | if (!cdev->config || intf >= MAX_CONFIG_INTERFACES) |
932 | break; | 932 | break; |
933 | f = cdev->config->interface[intf]; | 933 | f = cdev->config->interface[intf]; |
934 | break; | 934 | break; |
@@ -1258,16 +1258,16 @@ static struct usb_gadget_driver composite_driver = { | |||
1258 | * while it was binding. That would usually be done in order to wait for | 1258 | * while it was binding. That would usually be done in order to wait for |
1259 | * some userspace participation. | 1259 | * some userspace participation. |
1260 | */ | 1260 | */ |
1261 | extern int usb_composite_probe(struct usb_composite_driver *driver, | 1261 | int usb_composite_probe(struct usb_composite_driver *driver, |
1262 | int (*bind)(struct usb_composite_dev *cdev)) | 1262 | int (*bind)(struct usb_composite_dev *cdev)) |
1263 | { | 1263 | { |
1264 | if (!driver || !driver->dev || !bind || composite) | 1264 | if (!driver || !driver->dev || !bind || composite) |
1265 | return -EINVAL; | 1265 | return -EINVAL; |
1266 | 1266 | ||
1267 | if (!driver->iProduct) | ||
1268 | driver->iProduct = driver->name; | ||
1269 | if (!driver->name) | 1267 | if (!driver->name) |
1270 | driver->name = "composite"; | 1268 | driver->name = "composite"; |
1269 | if (!driver->iProduct) | ||
1270 | driver->iProduct = driver->name; | ||
1271 | composite_driver.function = (char *) driver->name; | 1271 | composite_driver.function = (char *) driver->name; |
1272 | composite_driver.driver.name = driver->name; | 1272 | composite_driver.driver.name = driver->name; |
1273 | composite = driver; | 1273 | composite = driver; |
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c index 13b9f47feecd..3214ca375d64 100644 --- a/drivers/usb/gadget/dummy_hcd.c +++ b/drivers/usb/gadget/dummy_hcd.c | |||
@@ -1593,8 +1593,8 @@ hub_descriptor (struct usb_hub_descriptor *desc) | |||
1593 | desc->bDescLength = 9; | 1593 | desc->bDescLength = 9; |
1594 | desc->wHubCharacteristics = cpu_to_le16(0x0001); | 1594 | desc->wHubCharacteristics = cpu_to_le16(0x0001); |
1595 | desc->bNbrPorts = 1; | 1595 | desc->bNbrPorts = 1; |
1596 | desc->bitmap [0] = 0xff; | 1596 | desc->u.hs.DeviceRemovable[0] = 0xff; |
1597 | desc->bitmap [1] = 0xff; | 1597 | desc->u.hs.DeviceRemovable[1] = 0xff; |
1598 | } | 1598 | } |
1599 | 1599 | ||
1600 | static int dummy_hub_control ( | 1600 | static int dummy_hub_control ( |
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index 8a832488ccdd..9b7360ff5aa7 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c | |||
@@ -128,6 +128,13 @@ ep_matches ( | |||
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | /* | ||
132 | * If the protocol driver hasn't yet decided on wMaxPacketSize | ||
133 | * and wants to know the maximum possible, provide the info. | ||
134 | */ | ||
135 | if (desc->wMaxPacketSize == 0) | ||
136 | desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket); | ||
137 | |||
131 | /* endpoint maxpacket size is an input parameter, except for bulk | 138 | /* endpoint maxpacket size is an input parameter, except for bulk |
132 | * where it's an output parameter representing the full speed limit. | 139 | * where it's an output parameter representing the full speed limit. |
133 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. | 140 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. |
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 1499f9e4afa8..19fffccc370d 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -368,6 +368,14 @@ static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len) | |||
368 | req->buf = data; | 368 | req->buf = data; |
369 | req->length = len; | 369 | req->length = len; |
370 | 370 | ||
371 | /* | ||
372 | * UDC layer requires to provide a buffer even for ZLP, but should | ||
373 | * not use it at all. Let's provide some poisoned pointer to catch | ||
374 | * possible bug in the driver. | ||
375 | */ | ||
376 | if (req->buf == NULL) | ||
377 | req->buf = (void *)0xDEADBABE; | ||
378 | |||
371 | INIT_COMPLETION(ffs->ep0req_completion); | 379 | INIT_COMPLETION(ffs->ep0req_completion); |
372 | 380 | ||
373 | ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); | 381 | ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC); |
diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c index 77b1eb577029..43a49ecc1f36 100644 --- a/drivers/usb/gadget/fsl_mxc_udc.c +++ b/drivers/usb/gadget/fsl_mxc_udc.c | |||
@@ -88,15 +88,18 @@ eenahb: | |||
88 | void fsl_udc_clk_finalize(struct platform_device *pdev) | 88 | void fsl_udc_clk_finalize(struct platform_device *pdev) |
89 | { | 89 | { |
90 | struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; | 90 | struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; |
91 | #if defined(CONFIG_ARCH_MX35) | 91 | #if defined(CONFIG_SOC_IMX35) |
92 | unsigned int v; | 92 | if (cpu_is_mx35()) { |
93 | 93 | unsigned int v; | |
94 | /* workaround ENGcm09152 for i.MX35 */ | 94 | |
95 | if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) { | 95 | /* workaround ENGcm09152 for i.MX35 */ |
96 | v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + | 96 | if (pdata->workaround & FLS_USB2_WORKAROUND_ENGCM09152) { |
97 | USBPHYCTRL_OTGBASE_OFFSET)); | 97 | v = readl(MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + |
98 | writel(v | USBPHYCTRL_EVDO, MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + | 98 | USBPHYCTRL_OTGBASE_OFFSET)); |
99 | USBPHYCTRL_OTGBASE_OFFSET)); | 99 | writel(v | USBPHYCTRL_EVDO, |
100 | MX35_IO_ADDRESS(MX35_USB_BASE_ADDR + | ||
101 | USBPHYCTRL_OTGBASE_OFFSET)); | ||
102 | } | ||
100 | } | 103 | } |
101 | #endif | 104 | #endif |
102 | 105 | ||
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c index 4c55eda4bd20..912cb8e63fe3 100644 --- a/drivers/usb/gadget/fsl_udc_core.c +++ b/drivers/usb/gadget/fsl_udc_core.c | |||
@@ -766,7 +766,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
766 | struct fsl_req *req = container_of(_req, struct fsl_req, req); | 766 | struct fsl_req *req = container_of(_req, struct fsl_req, req); |
767 | struct fsl_udc *udc; | 767 | struct fsl_udc *udc; |
768 | unsigned long flags; | 768 | unsigned long flags; |
769 | int is_iso = 0; | ||
770 | 769 | ||
771 | /* catch various bogus parameters */ | 770 | /* catch various bogus parameters */ |
772 | if (!_req || !req->req.complete || !req->req.buf | 771 | if (!_req || !req->req.complete || !req->req.buf |
@@ -781,7 +780,6 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | |||
781 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 780 | if (ep->desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
782 | if (req->req.length > ep->ep.maxpacket) | 781 | if (req->req.length > ep->ep.maxpacket) |
783 | return -EMSGSIZE; | 782 | return -EMSGSIZE; |
784 | is_iso = 1; | ||
785 | } | 783 | } |
786 | 784 | ||
787 | udc = ep->udc; | 785 | udc = ep->udc; |
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c new file mode 100644 index 000000000000..763d462454b9 --- /dev/null +++ b/drivers/usb/gadget/fusb300_udc.c | |||
@@ -0,0 +1,1744 @@ | |||
1 | /* | ||
2 | * Fusb300 UDC (USB gadget) | ||
3 | * | ||
4 | * Copyright (C) 2010 Faraday Technology Corp. | ||
5 | * | ||
6 | * Author : Yuan-hsin Chen <yhchen@faraday-tech.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | #include <linux/dma-mapping.h> | ||
23 | #include <linux/err.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/io.h> | ||
26 | #include <linux/platform_device.h> | ||
27 | #include <linux/usb/ch9.h> | ||
28 | #include <linux/usb/gadget.h> | ||
29 | |||
30 | #include "fusb300_udc.h" | ||
31 | |||
32 | MODULE_DESCRIPTION("FUSB300 USB gadget driver"); | ||
33 | MODULE_LICENSE("GPL"); | ||
34 | MODULE_AUTHOR("Yuan Hsin Chen <yhchen@faraday-tech.com>"); | ||
35 | MODULE_ALIAS("platform:fusb300_udc"); | ||
36 | |||
37 | #define DRIVER_VERSION "20 October 2010" | ||
38 | |||
39 | static const char udc_name[] = "fusb300_udc"; | ||
40 | static const char * const fusb300_ep_name[] = { | ||
41 | "ep0", "ep1", "ep2", "ep3", "ep4", "ep5", "ep6", "ep7", "ep8", "ep9", | ||
42 | "ep10", "ep11", "ep12", "ep13", "ep14", "ep15" | ||
43 | }; | ||
44 | |||
45 | static void done(struct fusb300_ep *ep, struct fusb300_request *req, | ||
46 | int status); | ||
47 | |||
48 | static void fusb300_enable_bit(struct fusb300 *fusb300, u32 offset, | ||
49 | u32 value) | ||
50 | { | ||
51 | u32 reg = ioread32(fusb300->reg + offset); | ||
52 | |||
53 | reg |= value; | ||
54 | iowrite32(reg, fusb300->reg + offset); | ||
55 | } | ||
56 | |||
57 | static void fusb300_disable_bit(struct fusb300 *fusb300, u32 offset, | ||
58 | u32 value) | ||
59 | { | ||
60 | u32 reg = ioread32(fusb300->reg + offset); | ||
61 | |||
62 | reg &= ~value; | ||
63 | iowrite32(reg, fusb300->reg + offset); | ||
64 | } | ||
65 | |||
66 | |||
67 | static void fusb300_ep_setting(struct fusb300_ep *ep, | ||
68 | struct fusb300_ep_info info) | ||
69 | { | ||
70 | ep->epnum = info.epnum; | ||
71 | ep->type = info.type; | ||
72 | } | ||
73 | |||
74 | static int fusb300_ep_release(struct fusb300_ep *ep) | ||
75 | { | ||
76 | if (!ep->epnum) | ||
77 | return 0; | ||
78 | ep->epnum = 0; | ||
79 | ep->stall = 0; | ||
80 | ep->wedged = 0; | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static void fusb300_set_fifo_entry(struct fusb300 *fusb300, | ||
85 | u32 ep) | ||
86 | { | ||
87 | u32 val = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
88 | |||
89 | val &= ~FUSB300_EPSET1_FIFOENTRY_MSK; | ||
90 | val |= FUSB300_EPSET1_FIFOENTRY(FUSB300_FIFO_ENTRY_NUM); | ||
91 | iowrite32(val, fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
92 | } | ||
93 | |||
94 | static void fusb300_set_start_entry(struct fusb300 *fusb300, | ||
95 | u8 ep) | ||
96 | { | ||
97 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
98 | u32 start_entry = fusb300->fifo_entry_num * FUSB300_FIFO_ENTRY_NUM; | ||
99 | |||
100 | reg &= ~FUSB300_EPSET1_START_ENTRY_MSK ; | ||
101 | reg |= FUSB300_EPSET1_START_ENTRY(start_entry); | ||
102 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
103 | if (fusb300->fifo_entry_num == FUSB300_MAX_FIFO_ENTRY) { | ||
104 | fusb300->fifo_entry_num = 0; | ||
105 | fusb300->addrofs = 0; | ||
106 | pr_err("fifo entry is over the maximum number!\n"); | ||
107 | } else | ||
108 | fusb300->fifo_entry_num++; | ||
109 | } | ||
110 | |||
111 | /* set fusb300_set_start_entry first before fusb300_set_epaddrofs */ | ||
112 | static void fusb300_set_epaddrofs(struct fusb300 *fusb300, | ||
113 | struct fusb300_ep_info info) | ||
114 | { | ||
115 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum)); | ||
116 | |||
117 | reg &= ~FUSB300_EPSET2_ADDROFS_MSK; | ||
118 | reg |= FUSB300_EPSET2_ADDROFS(fusb300->addrofs); | ||
119 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum)); | ||
120 | fusb300->addrofs += (info.maxpacket + 7) / 8 * FUSB300_FIFO_ENTRY_NUM; | ||
121 | } | ||
122 | |||
123 | static void ep_fifo_setting(struct fusb300 *fusb300, | ||
124 | struct fusb300_ep_info info) | ||
125 | { | ||
126 | fusb300_set_fifo_entry(fusb300, info.epnum); | ||
127 | fusb300_set_start_entry(fusb300, info.epnum); | ||
128 | fusb300_set_epaddrofs(fusb300, info); | ||
129 | } | ||
130 | |||
131 | static void fusb300_set_eptype(struct fusb300 *fusb300, | ||
132 | struct fusb300_ep_info info) | ||
133 | { | ||
134 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
135 | |||
136 | reg &= ~FUSB300_EPSET1_TYPE_MSK; | ||
137 | reg |= FUSB300_EPSET1_TYPE(info.type); | ||
138 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
139 | } | ||
140 | |||
141 | static void fusb300_set_epdir(struct fusb300 *fusb300, | ||
142 | struct fusb300_ep_info info) | ||
143 | { | ||
144 | u32 reg; | ||
145 | |||
146 | if (!info.dir_in) | ||
147 | return; | ||
148 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
149 | reg &= ~FUSB300_EPSET1_DIR_MSK; | ||
150 | reg |= FUSB300_EPSET1_DIRIN; | ||
151 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
152 | } | ||
153 | |||
154 | static void fusb300_set_ep_active(struct fusb300 *fusb300, | ||
155 | u8 ep) | ||
156 | { | ||
157 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
158 | |||
159 | reg |= FUSB300_EPSET1_ACTEN; | ||
160 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(ep)); | ||
161 | } | ||
162 | |||
163 | static void fusb300_set_epmps(struct fusb300 *fusb300, | ||
164 | struct fusb300_ep_info info) | ||
165 | { | ||
166 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum)); | ||
167 | |||
168 | reg &= ~FUSB300_EPSET2_MPS_MSK; | ||
169 | reg |= FUSB300_EPSET2_MPS(info.maxpacket); | ||
170 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET2(info.epnum)); | ||
171 | } | ||
172 | |||
173 | static void fusb300_set_interval(struct fusb300 *fusb300, | ||
174 | struct fusb300_ep_info info) | ||
175 | { | ||
176 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
177 | |||
178 | reg &= ~FUSB300_EPSET1_INTERVAL(0x7); | ||
179 | reg |= FUSB300_EPSET1_INTERVAL(info.interval); | ||
180 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
181 | } | ||
182 | |||
183 | static void fusb300_set_bwnum(struct fusb300 *fusb300, | ||
184 | struct fusb300_ep_info info) | ||
185 | { | ||
186 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
187 | |||
188 | reg &= ~FUSB300_EPSET1_BWNUM(0x3); | ||
189 | reg |= FUSB300_EPSET1_BWNUM(info.bw_num); | ||
190 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET1(info.epnum)); | ||
191 | } | ||
192 | |||
193 | static void set_ep_reg(struct fusb300 *fusb300, | ||
194 | struct fusb300_ep_info info) | ||
195 | { | ||
196 | fusb300_set_eptype(fusb300, info); | ||
197 | fusb300_set_epdir(fusb300, info); | ||
198 | fusb300_set_epmps(fusb300, info); | ||
199 | |||
200 | if (info.interval) | ||
201 | fusb300_set_interval(fusb300, info); | ||
202 | |||
203 | if (info.bw_num) | ||
204 | fusb300_set_bwnum(fusb300, info); | ||
205 | |||
206 | fusb300_set_ep_active(fusb300, info.epnum); | ||
207 | } | ||
208 | |||
209 | static int config_ep(struct fusb300_ep *ep, | ||
210 | const struct usb_endpoint_descriptor *desc) | ||
211 | { | ||
212 | struct fusb300 *fusb300 = ep->fusb300; | ||
213 | struct fusb300_ep_info info; | ||
214 | |||
215 | ep->desc = desc; | ||
216 | |||
217 | info.interval = 0; | ||
218 | info.addrofs = 0; | ||
219 | info.bw_num = 0; | ||
220 | |||
221 | info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
222 | info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; | ||
223 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); | ||
224 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
225 | |||
226 | if ((info.type == USB_ENDPOINT_XFER_INT) || | ||
227 | (info.type == USB_ENDPOINT_XFER_ISOC)) { | ||
228 | info.interval = desc->bInterval; | ||
229 | if (info.type == USB_ENDPOINT_XFER_ISOC) | ||
230 | info.bw_num = ((desc->wMaxPacketSize & 0x1800) >> 11); | ||
231 | } | ||
232 | |||
233 | ep_fifo_setting(fusb300, info); | ||
234 | |||
235 | set_ep_reg(fusb300, info); | ||
236 | |||
237 | fusb300_ep_setting(ep, info); | ||
238 | |||
239 | fusb300->ep[info.epnum] = ep; | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int fusb300_enable(struct usb_ep *_ep, | ||
245 | const struct usb_endpoint_descriptor *desc) | ||
246 | { | ||
247 | struct fusb300_ep *ep; | ||
248 | |||
249 | ep = container_of(_ep, struct fusb300_ep, ep); | ||
250 | |||
251 | if (ep->fusb300->reenum) { | ||
252 | ep->fusb300->fifo_entry_num = 0; | ||
253 | ep->fusb300->addrofs = 0; | ||
254 | ep->fusb300->reenum = 0; | ||
255 | } | ||
256 | |||
257 | return config_ep(ep, desc); | ||
258 | } | ||
259 | |||
260 | static int fusb300_disable(struct usb_ep *_ep) | ||
261 | { | ||
262 | struct fusb300_ep *ep; | ||
263 | struct fusb300_request *req; | ||
264 | unsigned long flags; | ||
265 | |||
266 | ep = container_of(_ep, struct fusb300_ep, ep); | ||
267 | |||
268 | BUG_ON(!ep); | ||
269 | |||
270 | while (!list_empty(&ep->queue)) { | ||
271 | req = list_entry(ep->queue.next, struct fusb300_request, queue); | ||
272 | spin_lock_irqsave(&ep->fusb300->lock, flags); | ||
273 | done(ep, req, -ECONNRESET); | ||
274 | spin_unlock_irqrestore(&ep->fusb300->lock, flags); | ||
275 | } | ||
276 | |||
277 | return fusb300_ep_release(ep); | ||
278 | } | ||
279 | |||
280 | static struct usb_request *fusb300_alloc_request(struct usb_ep *_ep, | ||
281 | gfp_t gfp_flags) | ||
282 | { | ||
283 | struct fusb300_request *req; | ||
284 | |||
285 | req = kzalloc(sizeof(struct fusb300_request), gfp_flags); | ||
286 | if (!req) | ||
287 | return NULL; | ||
288 | INIT_LIST_HEAD(&req->queue); | ||
289 | |||
290 | return &req->req; | ||
291 | } | ||
292 | |||
293 | static void fusb300_free_request(struct usb_ep *_ep, struct usb_request *_req) | ||
294 | { | ||
295 | struct fusb300_request *req; | ||
296 | |||
297 | req = container_of(_req, struct fusb300_request, req); | ||
298 | kfree(req); | ||
299 | } | ||
300 | |||
301 | static int enable_fifo_int(struct fusb300_ep *ep) | ||
302 | { | ||
303 | struct fusb300 *fusb300 = ep->fusb300; | ||
304 | |||
305 | if (ep->epnum) { | ||
306 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_IGER0, | ||
307 | FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum)); | ||
308 | } else { | ||
309 | pr_err("can't enable_fifo_int ep0\n"); | ||
310 | return -EINVAL; | ||
311 | } | ||
312 | |||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static int disable_fifo_int(struct fusb300_ep *ep) | ||
317 | { | ||
318 | struct fusb300 *fusb300 = ep->fusb300; | ||
319 | |||
320 | if (ep->epnum) { | ||
321 | fusb300_disable_bit(fusb300, FUSB300_OFFSET_IGER0, | ||
322 | FUSB300_IGER0_EEPn_FIFO_INT(ep->epnum)); | ||
323 | } else { | ||
324 | pr_err("can't disable_fifo_int ep0\n"); | ||
325 | return -EINVAL; | ||
326 | } | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | static void fusb300_set_cxlen(struct fusb300 *fusb300, u32 length) | ||
332 | { | ||
333 | u32 reg; | ||
334 | |||
335 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR); | ||
336 | reg &= ~FUSB300_CSR_LEN_MSK; | ||
337 | reg |= FUSB300_CSR_LEN(length); | ||
338 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_CSR); | ||
339 | } | ||
340 | |||
341 | /* write data to cx fifo */ | ||
342 | static void fusb300_wrcxf(struct fusb300_ep *ep, | ||
343 | struct fusb300_request *req) | ||
344 | { | ||
345 | int i = 0; | ||
346 | u8 *tmp; | ||
347 | u32 data; | ||
348 | struct fusb300 *fusb300 = ep->fusb300; | ||
349 | u32 length = req->req.length - req->req.actual; | ||
350 | |||
351 | tmp = req->req.buf + req->req.actual; | ||
352 | |||
353 | if (length > SS_CTL_MAX_PACKET_SIZE) { | ||
354 | fusb300_set_cxlen(fusb300, SS_CTL_MAX_PACKET_SIZE); | ||
355 | for (i = (SS_CTL_MAX_PACKET_SIZE >> 2); i > 0; i--) { | ||
356 | data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 | | ||
357 | *(tmp + 3) << 24; | ||
358 | iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
359 | tmp += 4; | ||
360 | } | ||
361 | req->req.actual += SS_CTL_MAX_PACKET_SIZE; | ||
362 | } else { /* length is less than max packet size */ | ||
363 | fusb300_set_cxlen(fusb300, length); | ||
364 | for (i = length >> 2; i > 0; i--) { | ||
365 | data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16 | | ||
366 | *(tmp + 3) << 24; | ||
367 | printk(KERN_DEBUG " 0x%x\n", data); | ||
368 | iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
369 | tmp = tmp + 4; | ||
370 | } | ||
371 | switch (length % 4) { | ||
372 | case 1: | ||
373 | data = *tmp; | ||
374 | printk(KERN_DEBUG " 0x%x\n", data); | ||
375 | iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
376 | break; | ||
377 | case 2: | ||
378 | data = *tmp | *(tmp + 1) << 8; | ||
379 | printk(KERN_DEBUG " 0x%x\n", data); | ||
380 | iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
381 | break; | ||
382 | case 3: | ||
383 | data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16; | ||
384 | printk(KERN_DEBUG " 0x%x\n", data); | ||
385 | iowrite32(data, fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
386 | break; | ||
387 | default: | ||
388 | break; | ||
389 | } | ||
390 | req->req.actual += length; | ||
391 | } | ||
392 | } | ||
393 | |||
394 | static void fusb300_set_epnstall(struct fusb300 *fusb300, u8 ep) | ||
395 | { | ||
396 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep), | ||
397 | FUSB300_EPSET0_STL); | ||
398 | } | ||
399 | |||
400 | static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep) | ||
401 | { | ||
402 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); | ||
403 | |||
404 | if (reg & FUSB300_EPSET0_STL) { | ||
405 | printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep); | ||
406 | reg &= ~FUSB300_EPSET0_STL; | ||
407 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); | ||
408 | } | ||
409 | } | ||
410 | |||
411 | static void ep0_queue(struct fusb300_ep *ep, struct fusb300_request *req) | ||
412 | { | ||
413 | if (ep->fusb300->ep0_dir) { /* if IN */ | ||
414 | if (req->req.length) { | ||
415 | fusb300_wrcxf(ep, req); | ||
416 | } else | ||
417 | printk(KERN_DEBUG "%s : req->req.length = 0x%x\n", | ||
418 | __func__, req->req.length); | ||
419 | if ((req->req.length == req->req.actual) || | ||
420 | (req->req.actual < ep->ep.maxpacket)) | ||
421 | done(ep, req, 0); | ||
422 | } else { /* OUT */ | ||
423 | if (!req->req.length) | ||
424 | done(ep, req, 0); | ||
425 | else | ||
426 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER1, | ||
427 | FUSB300_IGER1_CX_OUT_INT); | ||
428 | } | ||
429 | } | ||
430 | |||
431 | static int fusb300_queue(struct usb_ep *_ep, struct usb_request *_req, | ||
432 | gfp_t gfp_flags) | ||
433 | { | ||
434 | struct fusb300_ep *ep; | ||
435 | struct fusb300_request *req; | ||
436 | unsigned long flags; | ||
437 | int request = 0; | ||
438 | |||
439 | ep = container_of(_ep, struct fusb300_ep, ep); | ||
440 | req = container_of(_req, struct fusb300_request, req); | ||
441 | |||
442 | if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN) | ||
443 | return -ESHUTDOWN; | ||
444 | |||
445 | spin_lock_irqsave(&ep->fusb300->lock, flags); | ||
446 | |||
447 | if (list_empty(&ep->queue)) | ||
448 | request = 1; | ||
449 | |||
450 | list_add_tail(&req->queue, &ep->queue); | ||
451 | |||
452 | req->req.actual = 0; | ||
453 | req->req.status = -EINPROGRESS; | ||
454 | |||
455 | if (ep->desc == NULL) /* ep0 */ | ||
456 | ep0_queue(ep, req); | ||
457 | else if (request && !ep->stall) | ||
458 | enable_fifo_int(ep); | ||
459 | |||
460 | spin_unlock_irqrestore(&ep->fusb300->lock, flags); | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | static int fusb300_dequeue(struct usb_ep *_ep, struct usb_request *_req) | ||
466 | { | ||
467 | struct fusb300_ep *ep; | ||
468 | struct fusb300_request *req; | ||
469 | unsigned long flags; | ||
470 | |||
471 | ep = container_of(_ep, struct fusb300_ep, ep); | ||
472 | req = container_of(_req, struct fusb300_request, req); | ||
473 | |||
474 | spin_lock_irqsave(&ep->fusb300->lock, flags); | ||
475 | if (!list_empty(&ep->queue)) | ||
476 | done(ep, req, -ECONNRESET); | ||
477 | spin_unlock_irqrestore(&ep->fusb300->lock, flags); | ||
478 | |||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | static int fusb300_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedge) | ||
483 | { | ||
484 | struct fusb300_ep *ep; | ||
485 | struct fusb300 *fusb300; | ||
486 | unsigned long flags; | ||
487 | int ret = 0; | ||
488 | |||
489 | ep = container_of(_ep, struct fusb300_ep, ep); | ||
490 | |||
491 | fusb300 = ep->fusb300; | ||
492 | |||
493 | spin_lock_irqsave(&ep->fusb300->lock, flags); | ||
494 | |||
495 | if (!list_empty(&ep->queue)) { | ||
496 | ret = -EAGAIN; | ||
497 | goto out; | ||
498 | } | ||
499 | |||
500 | if (value) { | ||
501 | fusb300_set_epnstall(fusb300, ep->epnum); | ||
502 | ep->stall = 1; | ||
503 | if (wedge) | ||
504 | ep->wedged = 1; | ||
505 | } else { | ||
506 | fusb300_clear_epnstall(fusb300, ep->epnum); | ||
507 | ep->stall = 0; | ||
508 | ep->wedged = 0; | ||
509 | } | ||
510 | |||
511 | out: | ||
512 | spin_unlock_irqrestore(&ep->fusb300->lock, flags); | ||
513 | return ret; | ||
514 | } | ||
515 | |||
516 | static int fusb300_set_halt(struct usb_ep *_ep, int value) | ||
517 | { | ||
518 | return fusb300_set_halt_and_wedge(_ep, value, 0); | ||
519 | } | ||
520 | |||
521 | static int fusb300_set_wedge(struct usb_ep *_ep) | ||
522 | { | ||
523 | return fusb300_set_halt_and_wedge(_ep, 1, 1); | ||
524 | } | ||
525 | |||
526 | static void fusb300_fifo_flush(struct usb_ep *_ep) | ||
527 | { | ||
528 | } | ||
529 | |||
530 | static struct usb_ep_ops fusb300_ep_ops = { | ||
531 | .enable = fusb300_enable, | ||
532 | .disable = fusb300_disable, | ||
533 | |||
534 | .alloc_request = fusb300_alloc_request, | ||
535 | .free_request = fusb300_free_request, | ||
536 | |||
537 | .queue = fusb300_queue, | ||
538 | .dequeue = fusb300_dequeue, | ||
539 | |||
540 | .set_halt = fusb300_set_halt, | ||
541 | .fifo_flush = fusb300_fifo_flush, | ||
542 | .set_wedge = fusb300_set_wedge, | ||
543 | }; | ||
544 | |||
545 | /*****************************************************************************/ | ||
546 | static void fusb300_clear_int(struct fusb300 *fusb300, u32 offset, | ||
547 | u32 value) | ||
548 | { | ||
549 | iowrite32(value, fusb300->reg + offset); | ||
550 | } | ||
551 | |||
552 | static void fusb300_reset(void) | ||
553 | { | ||
554 | } | ||
555 | |||
556 | static void fusb300_set_cxstall(struct fusb300 *fusb300) | ||
557 | { | ||
558 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR, | ||
559 | FUSB300_CSR_STL); | ||
560 | } | ||
561 | |||
562 | static void fusb300_set_cxdone(struct fusb300 *fusb300) | ||
563 | { | ||
564 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_CSR, | ||
565 | FUSB300_CSR_DONE); | ||
566 | } | ||
567 | |||
568 | /* read data from cx fifo */ | ||
569 | void fusb300_rdcxf(struct fusb300 *fusb300, | ||
570 | u8 *buffer, u32 length) | ||
571 | { | ||
572 | int i = 0; | ||
573 | u8 *tmp; | ||
574 | u32 data; | ||
575 | |||
576 | tmp = buffer; | ||
577 | |||
578 | for (i = (length >> 2); i > 0; i--) { | ||
579 | data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
580 | printk(KERN_DEBUG " 0x%x\n", data); | ||
581 | *tmp = data & 0xFF; | ||
582 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
583 | *(tmp + 2) = (data >> 16) & 0xFF; | ||
584 | *(tmp + 3) = (data >> 24) & 0xFF; | ||
585 | tmp = tmp + 4; | ||
586 | } | ||
587 | |||
588 | switch (length % 4) { | ||
589 | case 1: | ||
590 | data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
591 | printk(KERN_DEBUG " 0x%x\n", data); | ||
592 | *tmp = data & 0xFF; | ||
593 | break; | ||
594 | case 2: | ||
595 | data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
596 | printk(KERN_DEBUG " 0x%x\n", data); | ||
597 | *tmp = data & 0xFF; | ||
598 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
599 | break; | ||
600 | case 3: | ||
601 | data = ioread32(fusb300->reg + FUSB300_OFFSET_CXPORT); | ||
602 | printk(KERN_DEBUG " 0x%x\n", data); | ||
603 | *tmp = data & 0xFF; | ||
604 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
605 | *(tmp + 2) = (data >> 16) & 0xFF; | ||
606 | break; | ||
607 | default: | ||
608 | break; | ||
609 | } | ||
610 | } | ||
611 | |||
612 | #if 0 | ||
613 | static void fusb300_dbg_fifo(struct fusb300_ep *ep, | ||
614 | u8 entry, u16 length) | ||
615 | { | ||
616 | u32 reg; | ||
617 | u32 i = 0; | ||
618 | u32 j = 0; | ||
619 | |||
620 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM); | ||
621 | reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) | | ||
622 | FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG); | ||
623 | reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) | | ||
624 | FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG); | ||
625 | iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM); | ||
626 | |||
627 | for (i = 0; i < (length >> 2); i++) { | ||
628 | if (i * 4 == 1024) | ||
629 | break; | ||
630 | reg = ioread32(ep->fusb300->reg + | ||
631 | FUSB300_OFFSET_BUFDBG_START + i * 4); | ||
632 | printk(KERN_DEBUG" 0x%-8x", reg); | ||
633 | j++; | ||
634 | if ((j % 4) == 0) | ||
635 | printk(KERN_DEBUG "\n"); | ||
636 | } | ||
637 | |||
638 | if (length % 4) { | ||
639 | reg = ioread32(ep->fusb300->reg + | ||
640 | FUSB300_OFFSET_BUFDBG_START + i * 4); | ||
641 | printk(KERN_DEBUG " 0x%x\n", reg); | ||
642 | } | ||
643 | |||
644 | if ((j % 4) != 0) | ||
645 | printk(KERN_DEBUG "\n"); | ||
646 | |||
647 | fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM, | ||
648 | FUSB300_GTM_TST_FIFO_DEG); | ||
649 | } | ||
650 | |||
651 | static void fusb300_cmp_dbg_fifo(struct fusb300_ep *ep, | ||
652 | u8 entry, u16 length, u8 *golden) | ||
653 | { | ||
654 | u32 reg; | ||
655 | u32 i = 0; | ||
656 | u32 golden_value; | ||
657 | u8 *tmp; | ||
658 | |||
659 | tmp = golden; | ||
660 | |||
661 | printk(KERN_DEBUG "fusb300_cmp_dbg_fifo (entry %d) : start\n", entry); | ||
662 | |||
663 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_GTM); | ||
664 | reg &= ~(FUSB300_GTM_TST_EP_ENTRY(0xF) | | ||
665 | FUSB300_GTM_TST_EP_NUM(0xF) | FUSB300_GTM_TST_FIFO_DEG); | ||
666 | reg |= (FUSB300_GTM_TST_EP_ENTRY(entry) | | ||
667 | FUSB300_GTM_TST_EP_NUM(ep->epnum) | FUSB300_GTM_TST_FIFO_DEG); | ||
668 | iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_GTM); | ||
669 | |||
670 | for (i = 0; i < (length >> 2); i++) { | ||
671 | if (i * 4 == 1024) | ||
672 | break; | ||
673 | golden_value = *tmp | *(tmp + 1) << 8 | | ||
674 | *(tmp + 2) << 16 | *(tmp + 3) << 24; | ||
675 | |||
676 | reg = ioread32(ep->fusb300->reg + | ||
677 | FUSB300_OFFSET_BUFDBG_START + i*4); | ||
678 | |||
679 | if (reg != golden_value) { | ||
680 | printk(KERN_DEBUG "0x%x : ", (u32)(ep->fusb300->reg + | ||
681 | FUSB300_OFFSET_BUFDBG_START + i*4)); | ||
682 | printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n", | ||
683 | golden_value, reg); | ||
684 | } | ||
685 | tmp += 4; | ||
686 | } | ||
687 | |||
688 | switch (length % 4) { | ||
689 | case 1: | ||
690 | golden_value = *tmp; | ||
691 | case 2: | ||
692 | golden_value = *tmp | *(tmp + 1) << 8; | ||
693 | case 3: | ||
694 | golden_value = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16; | ||
695 | default: | ||
696 | break; | ||
697 | |||
698 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_BUFDBG_START + i*4); | ||
699 | if (reg != golden_value) { | ||
700 | printk(KERN_DEBUG "0x%x:", (u32)(ep->fusb300->reg + | ||
701 | FUSB300_OFFSET_BUFDBG_START + i*4)); | ||
702 | printk(KERN_DEBUG " golden = 0x%x, reg = 0x%x\n", | ||
703 | golden_value, reg); | ||
704 | } | ||
705 | } | ||
706 | |||
707 | printk(KERN_DEBUG "fusb300_cmp_dbg_fifo : end\n"); | ||
708 | fusb300_disable_bit(ep->fusb300, FUSB300_OFFSET_GTM, | ||
709 | FUSB300_GTM_TST_FIFO_DEG); | ||
710 | } | ||
711 | #endif | ||
712 | |||
713 | static void fusb300_rdfifo(struct fusb300_ep *ep, | ||
714 | struct fusb300_request *req, | ||
715 | u32 length) | ||
716 | { | ||
717 | int i = 0; | ||
718 | u8 *tmp; | ||
719 | u32 data, reg; | ||
720 | struct fusb300 *fusb300 = ep->fusb300; | ||
721 | |||
722 | tmp = req->req.buf + req->req.actual; | ||
723 | req->req.actual += length; | ||
724 | |||
725 | if (req->req.actual > req->req.length) | ||
726 | printk(KERN_DEBUG "req->req.actual > req->req.length\n"); | ||
727 | |||
728 | for (i = (length >> 2); i > 0; i--) { | ||
729 | data = ioread32(fusb300->reg + | ||
730 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
731 | *tmp = data & 0xFF; | ||
732 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
733 | *(tmp + 2) = (data >> 16) & 0xFF; | ||
734 | *(tmp + 3) = (data >> 24) & 0xFF; | ||
735 | tmp = tmp + 4; | ||
736 | } | ||
737 | |||
738 | switch (length % 4) { | ||
739 | case 1: | ||
740 | data = ioread32(fusb300->reg + | ||
741 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
742 | *tmp = data & 0xFF; | ||
743 | break; | ||
744 | case 2: | ||
745 | data = ioread32(fusb300->reg + | ||
746 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
747 | *tmp = data & 0xFF; | ||
748 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
749 | break; | ||
750 | case 3: | ||
751 | data = ioread32(fusb300->reg + | ||
752 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
753 | *tmp = data & 0xFF; | ||
754 | *(tmp + 1) = (data >> 8) & 0xFF; | ||
755 | *(tmp + 2) = (data >> 16) & 0xFF; | ||
756 | break; | ||
757 | default: | ||
758 | break; | ||
759 | } | ||
760 | |||
761 | do { | ||
762 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1); | ||
763 | reg &= FUSB300_IGR1_SYNF0_EMPTY_INT; | ||
764 | if (i) | ||
765 | printk(KERN_INFO "sync fifo is not empty!\n"); | ||
766 | i++; | ||
767 | } while (!reg); | ||
768 | } | ||
769 | |||
770 | /* write data to fifo */ | ||
771 | static void fusb300_wrfifo(struct fusb300_ep *ep, | ||
772 | struct fusb300_request *req) | ||
773 | { | ||
774 | int i = 0; | ||
775 | u8 *tmp; | ||
776 | u32 data, reg; | ||
777 | struct fusb300 *fusb300 = ep->fusb300; | ||
778 | |||
779 | tmp = req->req.buf; | ||
780 | req->req.actual = req->req.length; | ||
781 | |||
782 | for (i = (req->req.length >> 2); i > 0; i--) { | ||
783 | data = *tmp | *(tmp + 1) << 8 | | ||
784 | *(tmp + 2) << 16 | *(tmp + 3) << 24; | ||
785 | |||
786 | iowrite32(data, fusb300->reg + | ||
787 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
788 | tmp += 4; | ||
789 | } | ||
790 | |||
791 | switch (req->req.length % 4) { | ||
792 | case 1: | ||
793 | data = *tmp; | ||
794 | iowrite32(data, fusb300->reg + | ||
795 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
796 | break; | ||
797 | case 2: | ||
798 | data = *tmp | *(tmp + 1) << 8; | ||
799 | iowrite32(data, fusb300->reg + | ||
800 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
801 | break; | ||
802 | case 3: | ||
803 | data = *tmp | *(tmp + 1) << 8 | *(tmp + 2) << 16; | ||
804 | iowrite32(data, fusb300->reg + | ||
805 | FUSB300_OFFSET_EPPORT(ep->epnum)); | ||
806 | break; | ||
807 | default: | ||
808 | break; | ||
809 | } | ||
810 | |||
811 | do { | ||
812 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1); | ||
813 | reg &= FUSB300_IGR1_SYNF0_EMPTY_INT; | ||
814 | if (i) | ||
815 | printk(KERN_INFO"sync fifo is not empty!\n"); | ||
816 | i++; | ||
817 | } while (!reg); | ||
818 | } | ||
819 | |||
820 | static u8 fusb300_get_epnstall(struct fusb300 *fusb300, u8 ep) | ||
821 | { | ||
822 | u8 value; | ||
823 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); | ||
824 | |||
825 | value = reg & FUSB300_EPSET0_STL; | ||
826 | |||
827 | return value; | ||
828 | } | ||
829 | |||
830 | static u8 fusb300_get_cxstall(struct fusb300 *fusb300) | ||
831 | { | ||
832 | u8 value; | ||
833 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_CSR); | ||
834 | |||
835 | value = (reg & FUSB300_CSR_STL) >> 1; | ||
836 | |||
837 | return value; | ||
838 | } | ||
839 | |||
840 | static void request_error(struct fusb300 *fusb300) | ||
841 | { | ||
842 | fusb300_set_cxstall(fusb300); | ||
843 | printk(KERN_DEBUG "request error!!\n"); | ||
844 | } | ||
845 | |||
846 | static void get_status(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | ||
847 | __releases(fusb300->lock) | ||
848 | __acquires(fusb300->lock) | ||
849 | { | ||
850 | u8 ep; | ||
851 | u16 status = 0; | ||
852 | u16 w_index = ctrl->wIndex; | ||
853 | |||
854 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
855 | case USB_RECIP_DEVICE: | ||
856 | status = 1 << USB_DEVICE_SELF_POWERED; | ||
857 | break; | ||
858 | case USB_RECIP_INTERFACE: | ||
859 | status = 0; | ||
860 | break; | ||
861 | case USB_RECIP_ENDPOINT: | ||
862 | ep = w_index & USB_ENDPOINT_NUMBER_MASK; | ||
863 | if (ep) { | ||
864 | if (fusb300_get_epnstall(fusb300, ep)) | ||
865 | status = 1 << USB_ENDPOINT_HALT; | ||
866 | } else { | ||
867 | if (fusb300_get_cxstall(fusb300)) | ||
868 | status = 0; | ||
869 | } | ||
870 | break; | ||
871 | |||
872 | default: | ||
873 | request_error(fusb300); | ||
874 | return; /* exit */ | ||
875 | } | ||
876 | |||
877 | fusb300->ep0_data = cpu_to_le16(status); | ||
878 | fusb300->ep0_req->buf = &fusb300->ep0_data; | ||
879 | fusb300->ep0_req->length = 2; | ||
880 | |||
881 | spin_unlock(&fusb300->lock); | ||
882 | fusb300_queue(fusb300->gadget.ep0, fusb300->ep0_req, GFP_KERNEL); | ||
883 | spin_lock(&fusb300->lock); | ||
884 | } | ||
885 | |||
886 | static void set_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | ||
887 | { | ||
888 | u8 ep; | ||
889 | |||
890 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
891 | case USB_RECIP_DEVICE: | ||
892 | fusb300_set_cxdone(fusb300); | ||
893 | break; | ||
894 | case USB_RECIP_INTERFACE: | ||
895 | fusb300_set_cxdone(fusb300); | ||
896 | break; | ||
897 | case USB_RECIP_ENDPOINT: { | ||
898 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
899 | |||
900 | ep = w_index & USB_ENDPOINT_NUMBER_MASK; | ||
901 | if (ep) | ||
902 | fusb300_set_epnstall(fusb300, ep); | ||
903 | else | ||
904 | fusb300_set_cxstall(fusb300); | ||
905 | fusb300_set_cxdone(fusb300); | ||
906 | } | ||
907 | break; | ||
908 | default: | ||
909 | request_error(fusb300); | ||
910 | break; | ||
911 | } | ||
912 | } | ||
913 | |||
914 | static void fusb300_clear_seqnum(struct fusb300 *fusb300, u8 ep) | ||
915 | { | ||
916 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_EPSET0(ep), | ||
917 | FUSB300_EPSET0_CLRSEQNUM); | ||
918 | } | ||
919 | |||
920 | static void clear_feature(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | ||
921 | { | ||
922 | struct fusb300_ep *ep = | ||
923 | fusb300->ep[ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK]; | ||
924 | |||
925 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | ||
926 | case USB_RECIP_DEVICE: | ||
927 | fusb300_set_cxdone(fusb300); | ||
928 | break; | ||
929 | case USB_RECIP_INTERFACE: | ||
930 | fusb300_set_cxdone(fusb300); | ||
931 | break; | ||
932 | case USB_RECIP_ENDPOINT: | ||
933 | if (ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK) { | ||
934 | if (ep->wedged) { | ||
935 | fusb300_set_cxdone(fusb300); | ||
936 | break; | ||
937 | } | ||
938 | if (ep->stall) { | ||
939 | ep->stall = 0; | ||
940 | fusb300_clear_seqnum(fusb300, ep->epnum); | ||
941 | fusb300_clear_epnstall(fusb300, ep->epnum); | ||
942 | if (!list_empty(&ep->queue)) | ||
943 | enable_fifo_int(ep); | ||
944 | } | ||
945 | } | ||
946 | fusb300_set_cxdone(fusb300); | ||
947 | break; | ||
948 | default: | ||
949 | request_error(fusb300); | ||
950 | break; | ||
951 | } | ||
952 | } | ||
953 | |||
954 | static void fusb300_set_dev_addr(struct fusb300 *fusb300, u16 addr) | ||
955 | { | ||
956 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_DAR); | ||
957 | |||
958 | reg &= ~FUSB300_DAR_DRVADDR_MSK; | ||
959 | reg |= FUSB300_DAR_DRVADDR(addr); | ||
960 | |||
961 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_DAR); | ||
962 | } | ||
963 | |||
964 | static void set_address(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | ||
965 | { | ||
966 | if (ctrl->wValue >= 0x0100) | ||
967 | request_error(fusb300); | ||
968 | else { | ||
969 | fusb300_set_dev_addr(fusb300, ctrl->wValue); | ||
970 | fusb300_set_cxdone(fusb300); | ||
971 | } | ||
972 | } | ||
973 | |||
974 | #define UVC_COPY_DESCRIPTORS(mem, src) \ | ||
975 | do { \ | ||
976 | const struct usb_descriptor_header * const *__src; \ | ||
977 | for (__src = src; *__src; ++__src) { \ | ||
978 | memcpy(mem, *__src, (*__src)->bLength); \ | ||
979 | mem += (*__src)->bLength; \ | ||
980 | } \ | ||
981 | } while (0) | ||
982 | |||
983 | static void fusb300_ep0_complete(struct usb_ep *ep, | ||
984 | struct usb_request *req) | ||
985 | { | ||
986 | } | ||
987 | |||
988 | static int setup_packet(struct fusb300 *fusb300, struct usb_ctrlrequest *ctrl) | ||
989 | { | ||
990 | u8 *p = (u8 *)ctrl; | ||
991 | u8 ret = 0; | ||
992 | u8 i = 0; | ||
993 | |||
994 | fusb300_rdcxf(fusb300, p, 8); | ||
995 | fusb300->ep0_dir = ctrl->bRequestType & USB_DIR_IN; | ||
996 | fusb300->ep0_length = ctrl->wLength; | ||
997 | |||
998 | /* check request */ | ||
999 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { | ||
1000 | switch (ctrl->bRequest) { | ||
1001 | case USB_REQ_GET_STATUS: | ||
1002 | get_status(fusb300, ctrl); | ||
1003 | break; | ||
1004 | case USB_REQ_CLEAR_FEATURE: | ||
1005 | clear_feature(fusb300, ctrl); | ||
1006 | break; | ||
1007 | case USB_REQ_SET_FEATURE: | ||
1008 | set_feature(fusb300, ctrl); | ||
1009 | break; | ||
1010 | case USB_REQ_SET_ADDRESS: | ||
1011 | set_address(fusb300, ctrl); | ||
1012 | break; | ||
1013 | case USB_REQ_SET_CONFIGURATION: | ||
1014 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_DAR, | ||
1015 | FUSB300_DAR_SETCONFG); | ||
1016 | /* clear sequence number */ | ||
1017 | for (i = 1; i <= FUSB300_MAX_NUM_EP; i++) | ||
1018 | fusb300_clear_seqnum(fusb300, i); | ||
1019 | fusb300->reenum = 1; | ||
1020 | ret = 1; | ||
1021 | break; | ||
1022 | default: | ||
1023 | ret = 1; | ||
1024 | break; | ||
1025 | } | ||
1026 | } else | ||
1027 | ret = 1; | ||
1028 | |||
1029 | return ret; | ||
1030 | } | ||
1031 | |||
1032 | static void fusb300_set_ep_bycnt(struct fusb300_ep *ep, u32 bycnt) | ||
1033 | { | ||
1034 | struct fusb300 *fusb300 = ep->fusb300; | ||
1035 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum)); | ||
1036 | |||
1037 | reg &= ~FUSB300_FFR_BYCNT; | ||
1038 | reg |= bycnt & FUSB300_FFR_BYCNT; | ||
1039 | |||
1040 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum)); | ||
1041 | } | ||
1042 | |||
1043 | static void done(struct fusb300_ep *ep, struct fusb300_request *req, | ||
1044 | int status) | ||
1045 | { | ||
1046 | list_del_init(&req->queue); | ||
1047 | |||
1048 | /* don't modify queue heads during completion callback */ | ||
1049 | if (ep->fusb300->gadget.speed == USB_SPEED_UNKNOWN) | ||
1050 | req->req.status = -ESHUTDOWN; | ||
1051 | else | ||
1052 | req->req.status = status; | ||
1053 | |||
1054 | spin_unlock(&ep->fusb300->lock); | ||
1055 | req->req.complete(&ep->ep, &req->req); | ||
1056 | spin_lock(&ep->fusb300->lock); | ||
1057 | |||
1058 | if (ep->epnum) { | ||
1059 | disable_fifo_int(ep); | ||
1060 | if (!list_empty(&ep->queue)) | ||
1061 | enable_fifo_int(ep); | ||
1062 | } else | ||
1063 | fusb300_set_cxdone(ep->fusb300); | ||
1064 | } | ||
1065 | |||
1066 | void fusb300_fill_idma_prdtbl(struct fusb300_ep *ep, | ||
1067 | struct fusb300_request *req) | ||
1068 | { | ||
1069 | u32 value; | ||
1070 | u32 reg; | ||
1071 | |||
1072 | /* wait SW owner */ | ||
1073 | do { | ||
1074 | reg = ioread32(ep->fusb300->reg + | ||
1075 | FUSB300_OFFSET_EPPRD_W0(ep->epnum)); | ||
1076 | reg &= FUSB300_EPPRD0_H; | ||
1077 | } while (reg); | ||
1078 | |||
1079 | iowrite32((u32) req->req.buf, ep->fusb300->reg + | ||
1080 | FUSB300_OFFSET_EPPRD_W1(ep->epnum)); | ||
1081 | |||
1082 | value = FUSB300_EPPRD0_BTC(req->req.length) | FUSB300_EPPRD0_H | | ||
1083 | FUSB300_EPPRD0_F | FUSB300_EPPRD0_L | FUSB300_EPPRD0_I; | ||
1084 | iowrite32(value, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W0(ep->epnum)); | ||
1085 | |||
1086 | iowrite32(0x0, ep->fusb300->reg + FUSB300_OFFSET_EPPRD_W2(ep->epnum)); | ||
1087 | |||
1088 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_EPPRDRDY, | ||
1089 | FUSB300_EPPRDR_EP_PRD_RDY(ep->epnum)); | ||
1090 | } | ||
1091 | |||
1092 | static void fusb300_wait_idma_finished(struct fusb300_ep *ep) | ||
1093 | { | ||
1094 | u32 reg; | ||
1095 | |||
1096 | do { | ||
1097 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR1); | ||
1098 | if ((reg & FUSB300_IGR1_VBUS_CHG_INT) || | ||
1099 | (reg & FUSB300_IGR1_WARM_RST_INT) || | ||
1100 | (reg & FUSB300_IGR1_HOT_RST_INT) || | ||
1101 | (reg & FUSB300_IGR1_USBRST_INT) | ||
1102 | ) | ||
1103 | goto IDMA_RESET; | ||
1104 | reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGR0); | ||
1105 | reg &= FUSB300_IGR0_EPn_PRD_INT(ep->epnum); | ||
1106 | } while (!reg); | ||
1107 | |||
1108 | fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0, | ||
1109 | FUSB300_IGR0_EPn_PRD_INT(ep->epnum)); | ||
1110 | IDMA_RESET: | ||
1111 | fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0, | ||
1112 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); | ||
1113 | } | ||
1114 | |||
1115 | static void fusb300_set_idma(struct fusb300_ep *ep, | ||
1116 | struct fusb300_request *req) | ||
1117 | { | ||
1118 | dma_addr_t d; | ||
1119 | u8 *tmp = NULL; | ||
1120 | |||
1121 | d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE); | ||
1122 | |||
1123 | if (dma_mapping_error(NULL, d)) { | ||
1124 | kfree(req->req.buf); | ||
1125 | printk(KERN_DEBUG "dma_mapping_error\n"); | ||
1126 | } | ||
1127 | |||
1128 | dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE); | ||
1129 | |||
1130 | fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, | ||
1131 | FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); | ||
1132 | |||
1133 | tmp = req->req.buf; | ||
1134 | req->req.buf = (u8 *)d; | ||
1135 | |||
1136 | fusb300_fill_idma_prdtbl(ep, req); | ||
1137 | /* check idma is done */ | ||
1138 | fusb300_wait_idma_finished(ep); | ||
1139 | |||
1140 | req->req.buf = tmp; | ||
1141 | |||
1142 | if (d) | ||
1143 | dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); | ||
1144 | } | ||
1145 | |||
1146 | static void in_ep_fifo_handler(struct fusb300_ep *ep) | ||
1147 | { | ||
1148 | struct fusb300_request *req = list_entry(ep->queue.next, | ||
1149 | struct fusb300_request, queue); | ||
1150 | |||
1151 | if (req->req.length) { | ||
1152 | #if 0 | ||
1153 | fusb300_set_ep_bycnt(ep, req->req.length); | ||
1154 | fusb300_wrfifo(ep, req); | ||
1155 | #else | ||
1156 | fusb300_set_idma(ep, req); | ||
1157 | #endif | ||
1158 | } | ||
1159 | done(ep, req, 0); | ||
1160 | } | ||
1161 | |||
1162 | static void out_ep_fifo_handler(struct fusb300_ep *ep) | ||
1163 | { | ||
1164 | struct fusb300 *fusb300 = ep->fusb300; | ||
1165 | struct fusb300_request *req = list_entry(ep->queue.next, | ||
1166 | struct fusb300_request, queue); | ||
1167 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_EPFFR(ep->epnum)); | ||
1168 | u32 length = reg & FUSB300_FFR_BYCNT; | ||
1169 | |||
1170 | fusb300_rdfifo(ep, req, length); | ||
1171 | |||
1172 | /* finish out transfer */ | ||
1173 | if ((req->req.length == req->req.actual) || (length < ep->ep.maxpacket)) | ||
1174 | done(ep, req, 0); | ||
1175 | } | ||
1176 | |||
1177 | static void check_device_mode(struct fusb300 *fusb300) | ||
1178 | { | ||
1179 | u32 reg = ioread32(fusb300->reg + FUSB300_OFFSET_GCR); | ||
1180 | |||
1181 | switch (reg & FUSB300_GCR_DEVEN_MSK) { | ||
1182 | case FUSB300_GCR_DEVEN_SS: | ||
1183 | fusb300->gadget.speed = USB_SPEED_SUPER; | ||
1184 | break; | ||
1185 | case FUSB300_GCR_DEVEN_HS: | ||
1186 | fusb300->gadget.speed = USB_SPEED_HIGH; | ||
1187 | break; | ||
1188 | case FUSB300_GCR_DEVEN_FS: | ||
1189 | fusb300->gadget.speed = USB_SPEED_FULL; | ||
1190 | break; | ||
1191 | default: | ||
1192 | fusb300->gadget.speed = USB_SPEED_UNKNOWN; | ||
1193 | break; | ||
1194 | } | ||
1195 | printk(KERN_INFO "dev_mode = %d\n", (reg & FUSB300_GCR_DEVEN_MSK)); | ||
1196 | } | ||
1197 | |||
1198 | |||
1199 | static void fusb300_ep0out(struct fusb300 *fusb300) | ||
1200 | { | ||
1201 | struct fusb300_ep *ep = fusb300->ep[0]; | ||
1202 | u32 reg; | ||
1203 | |||
1204 | if (!list_empty(&ep->queue)) { | ||
1205 | struct fusb300_request *req; | ||
1206 | |||
1207 | req = list_first_entry(&ep->queue, | ||
1208 | struct fusb300_request, queue); | ||
1209 | if (req->req.length) | ||
1210 | fusb300_rdcxf(ep->fusb300, req->req.buf, | ||
1211 | req->req.length); | ||
1212 | done(ep, req, 0); | ||
1213 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1); | ||
1214 | reg &= ~FUSB300_IGER1_CX_OUT_INT; | ||
1215 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_IGER1); | ||
1216 | } else | ||
1217 | pr_err("%s : empty queue\n", __func__); | ||
1218 | } | ||
1219 | |||
1220 | static void fusb300_ep0in(struct fusb300 *fusb300) | ||
1221 | { | ||
1222 | struct fusb300_request *req; | ||
1223 | struct fusb300_ep *ep = fusb300->ep[0]; | ||
1224 | |||
1225 | if ((!list_empty(&ep->queue)) && (fusb300->ep0_dir)) { | ||
1226 | req = list_entry(ep->queue.next, | ||
1227 | struct fusb300_request, queue); | ||
1228 | if (req->req.length) | ||
1229 | fusb300_wrcxf(ep, req); | ||
1230 | if ((req->req.length - req->req.actual) < ep->ep.maxpacket) | ||
1231 | done(ep, req, 0); | ||
1232 | } else | ||
1233 | fusb300_set_cxdone(fusb300); | ||
1234 | } | ||
1235 | |||
1236 | static void fusb300_grp2_handler(void) | ||
1237 | { | ||
1238 | } | ||
1239 | |||
1240 | static void fusb300_grp3_handler(void) | ||
1241 | { | ||
1242 | } | ||
1243 | |||
1244 | static void fusb300_grp4_handler(void) | ||
1245 | { | ||
1246 | } | ||
1247 | |||
1248 | static void fusb300_grp5_handler(void) | ||
1249 | { | ||
1250 | } | ||
1251 | |||
1252 | static irqreturn_t fusb300_irq(int irq, void *_fusb300) | ||
1253 | { | ||
1254 | struct fusb300 *fusb300 = _fusb300; | ||
1255 | u32 int_grp1 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR1); | ||
1256 | u32 int_grp1_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER1); | ||
1257 | u32 int_grp0 = ioread32(fusb300->reg + FUSB300_OFFSET_IGR0); | ||
1258 | u32 int_grp0_en = ioread32(fusb300->reg + FUSB300_OFFSET_IGER0); | ||
1259 | struct usb_ctrlrequest ctrl; | ||
1260 | u8 in; | ||
1261 | u32 reg; | ||
1262 | int i; | ||
1263 | |||
1264 | spin_lock(&fusb300->lock); | ||
1265 | |||
1266 | int_grp1 &= int_grp1_en; | ||
1267 | int_grp0 &= int_grp0_en; | ||
1268 | |||
1269 | if (int_grp1 & FUSB300_IGR1_WARM_RST_INT) { | ||
1270 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1271 | FUSB300_IGR1_WARM_RST_INT); | ||
1272 | printk(KERN_INFO"fusb300_warmreset\n"); | ||
1273 | fusb300_reset(); | ||
1274 | } | ||
1275 | |||
1276 | if (int_grp1 & FUSB300_IGR1_HOT_RST_INT) { | ||
1277 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1278 | FUSB300_IGR1_HOT_RST_INT); | ||
1279 | printk(KERN_INFO"fusb300_hotreset\n"); | ||
1280 | fusb300_reset(); | ||
1281 | } | ||
1282 | |||
1283 | if (int_grp1 & FUSB300_IGR1_USBRST_INT) { | ||
1284 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1285 | FUSB300_IGR1_USBRST_INT); | ||
1286 | fusb300_reset(); | ||
1287 | } | ||
1288 | /* COMABT_INT has a highest priority */ | ||
1289 | |||
1290 | if (int_grp1 & FUSB300_IGR1_CX_COMABT_INT) { | ||
1291 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1292 | FUSB300_IGR1_CX_COMABT_INT); | ||
1293 | printk(KERN_INFO"fusb300_ep0abt\n"); | ||
1294 | } | ||
1295 | |||
1296 | if (int_grp1 & FUSB300_IGR1_VBUS_CHG_INT) { | ||
1297 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1298 | FUSB300_IGR1_VBUS_CHG_INT); | ||
1299 | printk(KERN_INFO"fusb300_vbus_change\n"); | ||
1300 | } | ||
1301 | |||
1302 | if (int_grp1 & FUSB300_IGR1_U3_EXIT_FAIL_INT) { | ||
1303 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1304 | FUSB300_IGR1_U3_EXIT_FAIL_INT); | ||
1305 | } | ||
1306 | |||
1307 | if (int_grp1 & FUSB300_IGR1_U2_EXIT_FAIL_INT) { | ||
1308 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1309 | FUSB300_IGR1_U2_EXIT_FAIL_INT); | ||
1310 | } | ||
1311 | |||
1312 | if (int_grp1 & FUSB300_IGR1_U1_EXIT_FAIL_INT) { | ||
1313 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1314 | FUSB300_IGR1_U1_EXIT_FAIL_INT); | ||
1315 | } | ||
1316 | |||
1317 | if (int_grp1 & FUSB300_IGR1_U2_ENTRY_FAIL_INT) { | ||
1318 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1319 | FUSB300_IGR1_U2_ENTRY_FAIL_INT); | ||
1320 | } | ||
1321 | |||
1322 | if (int_grp1 & FUSB300_IGR1_U1_ENTRY_FAIL_INT) { | ||
1323 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1324 | FUSB300_IGR1_U1_ENTRY_FAIL_INT); | ||
1325 | } | ||
1326 | |||
1327 | if (int_grp1 & FUSB300_IGR1_U3_EXIT_INT) { | ||
1328 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1329 | FUSB300_IGR1_U3_EXIT_INT); | ||
1330 | printk(KERN_INFO "FUSB300_IGR1_U3_EXIT_INT\n"); | ||
1331 | } | ||
1332 | |||
1333 | if (int_grp1 & FUSB300_IGR1_U2_EXIT_INT) { | ||
1334 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1335 | FUSB300_IGR1_U2_EXIT_INT); | ||
1336 | printk(KERN_INFO "FUSB300_IGR1_U2_EXIT_INT\n"); | ||
1337 | } | ||
1338 | |||
1339 | if (int_grp1 & FUSB300_IGR1_U1_EXIT_INT) { | ||
1340 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1341 | FUSB300_IGR1_U1_EXIT_INT); | ||
1342 | printk(KERN_INFO "FUSB300_IGR1_U1_EXIT_INT\n"); | ||
1343 | } | ||
1344 | |||
1345 | if (int_grp1 & FUSB300_IGR1_U3_ENTRY_INT) { | ||
1346 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1347 | FUSB300_IGR1_U3_ENTRY_INT); | ||
1348 | printk(KERN_INFO "FUSB300_IGR1_U3_ENTRY_INT\n"); | ||
1349 | fusb300_enable_bit(fusb300, FUSB300_OFFSET_SSCR1, | ||
1350 | FUSB300_SSCR1_GO_U3_DONE); | ||
1351 | } | ||
1352 | |||
1353 | if (int_grp1 & FUSB300_IGR1_U2_ENTRY_INT) { | ||
1354 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1355 | FUSB300_IGR1_U2_ENTRY_INT); | ||
1356 | printk(KERN_INFO "FUSB300_IGR1_U2_ENTRY_INT\n"); | ||
1357 | } | ||
1358 | |||
1359 | if (int_grp1 & FUSB300_IGR1_U1_ENTRY_INT) { | ||
1360 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1361 | FUSB300_IGR1_U1_ENTRY_INT); | ||
1362 | printk(KERN_INFO "FUSB300_IGR1_U1_ENTRY_INT\n"); | ||
1363 | } | ||
1364 | |||
1365 | if (int_grp1 & FUSB300_IGR1_RESM_INT) { | ||
1366 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1367 | FUSB300_IGR1_RESM_INT); | ||
1368 | printk(KERN_INFO "fusb300_resume\n"); | ||
1369 | } | ||
1370 | |||
1371 | if (int_grp1 & FUSB300_IGR1_SUSP_INT) { | ||
1372 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1373 | FUSB300_IGR1_SUSP_INT); | ||
1374 | printk(KERN_INFO "fusb300_suspend\n"); | ||
1375 | } | ||
1376 | |||
1377 | if (int_grp1 & FUSB300_IGR1_HS_LPM_INT) { | ||
1378 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1379 | FUSB300_IGR1_HS_LPM_INT); | ||
1380 | printk(KERN_INFO "fusb300_HS_LPM_INT\n"); | ||
1381 | } | ||
1382 | |||
1383 | if (int_grp1 & FUSB300_IGR1_DEV_MODE_CHG_INT) { | ||
1384 | fusb300_clear_int(fusb300, FUSB300_OFFSET_IGR1, | ||
1385 | FUSB300_IGR1_DEV_MODE_CHG_INT); | ||
1386 | check_device_mode(fusb300); | ||
1387 | } | ||
1388 | |||
1389 | if (int_grp1 & FUSB300_IGR1_CX_COMFAIL_INT) { | ||
1390 | fusb300_set_cxstall(fusb300); | ||
1391 | printk(KERN_INFO "fusb300_ep0fail\n"); | ||
1392 | } | ||
1393 | |||
1394 | if (int_grp1 & FUSB300_IGR1_CX_SETUP_INT) { | ||
1395 | printk(KERN_INFO "fusb300_ep0setup\n"); | ||
1396 | if (setup_packet(fusb300, &ctrl)) { | ||
1397 | spin_unlock(&fusb300->lock); | ||
1398 | if (fusb300->driver->setup(&fusb300->gadget, &ctrl) < 0) | ||
1399 | fusb300_set_cxstall(fusb300); | ||
1400 | spin_lock(&fusb300->lock); | ||
1401 | } | ||
1402 | } | ||
1403 | |||
1404 | if (int_grp1 & FUSB300_IGR1_CX_CMDEND_INT) | ||
1405 | printk(KERN_INFO "fusb300_cmdend\n"); | ||
1406 | |||
1407 | |||
1408 | if (int_grp1 & FUSB300_IGR1_CX_OUT_INT) { | ||
1409 | printk(KERN_INFO "fusb300_cxout\n"); | ||
1410 | fusb300_ep0out(fusb300); | ||
1411 | } | ||
1412 | |||
1413 | if (int_grp1 & FUSB300_IGR1_CX_IN_INT) { | ||
1414 | printk(KERN_INFO "fusb300_cxin\n"); | ||
1415 | fusb300_ep0in(fusb300); | ||
1416 | } | ||
1417 | |||
1418 | if (int_grp1 & FUSB300_IGR1_INTGRP5) | ||
1419 | fusb300_grp5_handler(); | ||
1420 | |||
1421 | if (int_grp1 & FUSB300_IGR1_INTGRP4) | ||
1422 | fusb300_grp4_handler(); | ||
1423 | |||
1424 | if (int_grp1 & FUSB300_IGR1_INTGRP3) | ||
1425 | fusb300_grp3_handler(); | ||
1426 | |||
1427 | if (int_grp1 & FUSB300_IGR1_INTGRP2) | ||
1428 | fusb300_grp2_handler(); | ||
1429 | |||
1430 | if (int_grp0) { | ||
1431 | for (i = 1; i < FUSB300_MAX_NUM_EP; i++) { | ||
1432 | if (int_grp0 & FUSB300_IGR0_EPn_FIFO_INT(i)) { | ||
1433 | reg = ioread32(fusb300->reg + | ||
1434 | FUSB300_OFFSET_EPSET1(i)); | ||
1435 | in = (reg & FUSB300_EPSET1_DIRIN) ? 1 : 0; | ||
1436 | if (in) | ||
1437 | in_ep_fifo_handler(fusb300->ep[i]); | ||
1438 | else | ||
1439 | out_ep_fifo_handler(fusb300->ep[i]); | ||
1440 | } | ||
1441 | } | ||
1442 | } | ||
1443 | |||
1444 | spin_unlock(&fusb300->lock); | ||
1445 | |||
1446 | return IRQ_HANDLED; | ||
1447 | } | ||
1448 | |||
1449 | static void fusb300_set_u2_timeout(struct fusb300 *fusb300, | ||
1450 | u32 time) | ||
1451 | { | ||
1452 | u32 reg; | ||
1453 | |||
1454 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT); | ||
1455 | reg &= ~0xff; | ||
1456 | reg |= FUSB300_SSCR2_U2TIMEOUT(time); | ||
1457 | |||
1458 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT); | ||
1459 | } | ||
1460 | |||
1461 | static void fusb300_set_u1_timeout(struct fusb300 *fusb300, | ||
1462 | u32 time) | ||
1463 | { | ||
1464 | u32 reg; | ||
1465 | |||
1466 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_TT); | ||
1467 | reg &= ~(0xff << 8); | ||
1468 | reg |= FUSB300_SSCR2_U1TIMEOUT(time); | ||
1469 | |||
1470 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_TT); | ||
1471 | } | ||
1472 | |||
1473 | static void init_controller(struct fusb300 *fusb300) | ||
1474 | { | ||
1475 | u32 reg; | ||
1476 | u32 mask = 0; | ||
1477 | u32 val = 0; | ||
1478 | |||
1479 | /* split on */ | ||
1480 | mask = val = FUSB300_AHBBCR_S0_SPLIT_ON | FUSB300_AHBBCR_S1_SPLIT_ON; | ||
1481 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_AHBCR); | ||
1482 | reg &= ~mask; | ||
1483 | reg |= val; | ||
1484 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_AHBCR); | ||
1485 | |||
1486 | /* enable high-speed LPM */ | ||
1487 | mask = val = FUSB300_HSCR_HS_LPM_PERMIT; | ||
1488 | reg = ioread32(fusb300->reg + FUSB300_OFFSET_HSCR); | ||
1489 | reg &= ~mask; | ||
1490 | reg |= val; | ||
1491 | iowrite32(reg, fusb300->reg + FUSB300_OFFSET_HSCR); | ||
1492 | |||
1493 | /*set u1 u2 timmer*/ | ||
1494 | fusb300_set_u2_timeout(fusb300, 0xff); | ||
1495 | fusb300_set_u1_timeout(fusb300, 0xff); | ||
1496 | |||
1497 | /* enable all grp1 interrupt */ | ||
1498 | iowrite32(0xcfffff9f, fusb300->reg + FUSB300_OFFSET_IGER1); | ||
1499 | } | ||
1500 | /*------------------------------------------------------------------------*/ | ||
1501 | static struct fusb300 *the_controller; | ||
1502 | |||
1503 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | ||
1504 | int (*bind)(struct usb_gadget *)) | ||
1505 | { | ||
1506 | struct fusb300 *fusb300 = the_controller; | ||
1507 | int retval; | ||
1508 | |||
1509 | if (!driver | ||
1510 | || driver->speed < USB_SPEED_FULL | ||
1511 | || !bind | ||
1512 | || !driver->setup) | ||
1513 | return -EINVAL; | ||
1514 | |||
1515 | if (!fusb300) | ||
1516 | return -ENODEV; | ||
1517 | |||
1518 | if (fusb300->driver) | ||
1519 | return -EBUSY; | ||
1520 | |||
1521 | /* hook up the driver */ | ||
1522 | driver->driver.bus = NULL; | ||
1523 | fusb300->driver = driver; | ||
1524 | fusb300->gadget.dev.driver = &driver->driver; | ||
1525 | |||
1526 | retval = device_add(&fusb300->gadget.dev); | ||
1527 | if (retval) { | ||
1528 | pr_err("device_add error (%d)\n", retval); | ||
1529 | goto error; | ||
1530 | } | ||
1531 | |||
1532 | retval = bind(&fusb300->gadget); | ||
1533 | if (retval) { | ||
1534 | pr_err("bind to driver error (%d)\n", retval); | ||
1535 | device_del(&fusb300->gadget.dev); | ||
1536 | goto error; | ||
1537 | } | ||
1538 | |||
1539 | return 0; | ||
1540 | |||
1541 | error: | ||
1542 | fusb300->driver = NULL; | ||
1543 | fusb300->gadget.dev.driver = NULL; | ||
1544 | |||
1545 | return retval; | ||
1546 | } | ||
1547 | EXPORT_SYMBOL(usb_gadget_probe_driver); | ||
1548 | |||
1549 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
1550 | { | ||
1551 | struct fusb300 *fusb300 = the_controller; | ||
1552 | |||
1553 | if (driver != fusb300->driver || !driver->unbind) | ||
1554 | return -EINVAL; | ||
1555 | |||
1556 | driver->unbind(&fusb300->gadget); | ||
1557 | fusb300->gadget.dev.driver = NULL; | ||
1558 | |||
1559 | init_controller(fusb300); | ||
1560 | device_del(&fusb300->gadget.dev); | ||
1561 | fusb300->driver = NULL; | ||
1562 | |||
1563 | return 0; | ||
1564 | } | ||
1565 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
1566 | /*--------------------------------------------------------------------------*/ | ||
1567 | |||
1568 | static int fusb300_udc_pullup(struct usb_gadget *_gadget, int is_active) | ||
1569 | { | ||
1570 | return 0; | ||
1571 | } | ||
1572 | |||
1573 | static struct usb_gadget_ops fusb300_gadget_ops = { | ||
1574 | .pullup = fusb300_udc_pullup, | ||
1575 | }; | ||
1576 | |||
1577 | static int __exit fusb300_remove(struct platform_device *pdev) | ||
1578 | { | ||
1579 | struct fusb300 *fusb300 = dev_get_drvdata(&pdev->dev); | ||
1580 | |||
1581 | iounmap(fusb300->reg); | ||
1582 | free_irq(platform_get_irq(pdev, 0), fusb300); | ||
1583 | |||
1584 | fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); | ||
1585 | kfree(fusb300); | ||
1586 | |||
1587 | return 0; | ||
1588 | } | ||
1589 | |||
1590 | static int __init fusb300_probe(struct platform_device *pdev) | ||
1591 | { | ||
1592 | struct resource *res, *ires, *ires1; | ||
1593 | void __iomem *reg = NULL; | ||
1594 | struct fusb300 *fusb300 = NULL; | ||
1595 | struct fusb300_ep *_ep[FUSB300_MAX_NUM_EP]; | ||
1596 | int ret = 0; | ||
1597 | int i; | ||
1598 | |||
1599 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1600 | if (!res) { | ||
1601 | ret = -ENODEV; | ||
1602 | pr_err("platform_get_resource error.\n"); | ||
1603 | goto clean_up; | ||
1604 | } | ||
1605 | |||
1606 | ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
1607 | if (!ires) { | ||
1608 | ret = -ENODEV; | ||
1609 | dev_err(&pdev->dev, | ||
1610 | "platform_get_resource IORESOURCE_IRQ error.\n"); | ||
1611 | goto clean_up; | ||
1612 | } | ||
1613 | |||
1614 | ires1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1); | ||
1615 | if (!ires1) { | ||
1616 | ret = -ENODEV; | ||
1617 | dev_err(&pdev->dev, | ||
1618 | "platform_get_resource IORESOURCE_IRQ 1 error.\n"); | ||
1619 | goto clean_up; | ||
1620 | } | ||
1621 | |||
1622 | reg = ioremap(res->start, resource_size(res)); | ||
1623 | if (reg == NULL) { | ||
1624 | ret = -ENOMEM; | ||
1625 | pr_err("ioremap error.\n"); | ||
1626 | goto clean_up; | ||
1627 | } | ||
1628 | |||
1629 | /* initialize udc */ | ||
1630 | fusb300 = kzalloc(sizeof(struct fusb300), GFP_KERNEL); | ||
1631 | if (fusb300 == NULL) { | ||
1632 | pr_err("kzalloc error\n"); | ||
1633 | goto clean_up; | ||
1634 | } | ||
1635 | |||
1636 | for (i = 0; i < FUSB300_MAX_NUM_EP; i++) { | ||
1637 | _ep[i] = kzalloc(sizeof(struct fusb300_ep), GFP_KERNEL); | ||
1638 | if (_ep[i] == NULL) { | ||
1639 | pr_err("_ep kzalloc error\n"); | ||
1640 | goto clean_up; | ||
1641 | } | ||
1642 | fusb300->ep[i] = _ep[i]; | ||
1643 | } | ||
1644 | |||
1645 | spin_lock_init(&fusb300->lock); | ||
1646 | |||
1647 | dev_set_drvdata(&pdev->dev, fusb300); | ||
1648 | |||
1649 | fusb300->gadget.ops = &fusb300_gadget_ops; | ||
1650 | |||
1651 | device_initialize(&fusb300->gadget.dev); | ||
1652 | |||
1653 | dev_set_name(&fusb300->gadget.dev, "gadget"); | ||
1654 | |||
1655 | fusb300->gadget.is_dualspeed = 1; | ||
1656 | fusb300->gadget.dev.parent = &pdev->dev; | ||
1657 | fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
1658 | fusb300->gadget.dev.release = pdev->dev.release; | ||
1659 | fusb300->gadget.name = udc_name; | ||
1660 | fusb300->reg = reg; | ||
1661 | |||
1662 | ret = request_irq(ires->start, fusb300_irq, IRQF_DISABLED | IRQF_SHARED, | ||
1663 | udc_name, fusb300); | ||
1664 | if (ret < 0) { | ||
1665 | pr_err("request_irq error (%d)\n", ret); | ||
1666 | goto clean_up; | ||
1667 | } | ||
1668 | |||
1669 | ret = request_irq(ires1->start, fusb300_irq, | ||
1670 | IRQF_DISABLED | IRQF_SHARED, udc_name, fusb300); | ||
1671 | if (ret < 0) { | ||
1672 | pr_err("request_irq1 error (%d)\n", ret); | ||
1673 | goto clean_up; | ||
1674 | } | ||
1675 | |||
1676 | INIT_LIST_HEAD(&fusb300->gadget.ep_list); | ||
1677 | |||
1678 | for (i = 0; i < FUSB300_MAX_NUM_EP ; i++) { | ||
1679 | struct fusb300_ep *ep = fusb300->ep[i]; | ||
1680 | |||
1681 | if (i != 0) { | ||
1682 | INIT_LIST_HEAD(&fusb300->ep[i]->ep.ep_list); | ||
1683 | list_add_tail(&fusb300->ep[i]->ep.ep_list, | ||
1684 | &fusb300->gadget.ep_list); | ||
1685 | } | ||
1686 | ep->fusb300 = fusb300; | ||
1687 | INIT_LIST_HEAD(&ep->queue); | ||
1688 | ep->ep.name = fusb300_ep_name[i]; | ||
1689 | ep->ep.ops = &fusb300_ep_ops; | ||
1690 | ep->ep.maxpacket = HS_BULK_MAX_PACKET_SIZE; | ||
1691 | } | ||
1692 | fusb300->ep[0]->ep.maxpacket = HS_CTL_MAX_PACKET_SIZE; | ||
1693 | fusb300->ep[0]->epnum = 0; | ||
1694 | fusb300->gadget.ep0 = &fusb300->ep[0]->ep; | ||
1695 | INIT_LIST_HEAD(&fusb300->gadget.ep0->ep_list); | ||
1696 | |||
1697 | the_controller = fusb300; | ||
1698 | |||
1699 | fusb300->ep0_req = fusb300_alloc_request(&fusb300->ep[0]->ep, | ||
1700 | GFP_KERNEL); | ||
1701 | if (fusb300->ep0_req == NULL) | ||
1702 | goto clean_up3; | ||
1703 | |||
1704 | init_controller(fusb300); | ||
1705 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); | ||
1706 | |||
1707 | return 0; | ||
1708 | |||
1709 | clean_up3: | ||
1710 | free_irq(ires->start, fusb300); | ||
1711 | |||
1712 | clean_up: | ||
1713 | if (fusb300) { | ||
1714 | if (fusb300->ep0_req) | ||
1715 | fusb300_free_request(&fusb300->ep[0]->ep, | ||
1716 | fusb300->ep0_req); | ||
1717 | kfree(fusb300); | ||
1718 | } | ||
1719 | if (reg) | ||
1720 | iounmap(reg); | ||
1721 | |||
1722 | return ret; | ||
1723 | } | ||
1724 | |||
1725 | static struct platform_driver fusb300_driver = { | ||
1726 | .remove = __exit_p(fusb300_remove), | ||
1727 | .driver = { | ||
1728 | .name = (char *) udc_name, | ||
1729 | .owner = THIS_MODULE, | ||
1730 | }, | ||
1731 | }; | ||
1732 | |||
1733 | static int __init fusb300_udc_init(void) | ||
1734 | { | ||
1735 | return platform_driver_probe(&fusb300_driver, fusb300_probe); | ||
1736 | } | ||
1737 | |||
1738 | module_init(fusb300_udc_init); | ||
1739 | |||
1740 | static void __exit fusb300_udc_cleanup(void) | ||
1741 | { | ||
1742 | platform_driver_unregister(&fusb300_driver); | ||
1743 | } | ||
1744 | module_exit(fusb300_udc_cleanup); | ||
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h new file mode 100644 index 000000000000..f51aa2ef1f90 --- /dev/null +++ b/drivers/usb/gadget/fusb300_udc.h | |||
@@ -0,0 +1,687 @@ | |||
1 | /* | ||
2 | * Fusb300 UDC (USB gadget) | ||
3 | * | ||
4 | * Copyright (C) 2010 Faraday Technology Corp. | ||
5 | * | ||
6 | * Author : Yuan-hsin Chen <yhchen@faraday-tech.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; version 2 of the License. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | |||
24 | #ifndef __FUSB300_UDC_H__ | ||
25 | #define __FUSB300_UDC_H_ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | |||
29 | #define FUSB300_OFFSET_GCR 0x00 | ||
30 | #define FUSB300_OFFSET_GTM 0x04 | ||
31 | #define FUSB300_OFFSET_DAR 0x08 | ||
32 | #define FUSB300_OFFSET_CSR 0x0C | ||
33 | #define FUSB300_OFFSET_CXPORT 0x10 | ||
34 | #define FUSB300_OFFSET_EPSET0(n) (0x20 + (n - 1) * 0x30) | ||
35 | #define FUSB300_OFFSET_EPSET1(n) (0x24 + (n - 1) * 0x30) | ||
36 | #define FUSB300_OFFSET_EPSET2(n) (0x28 + (n - 1) * 0x30) | ||
37 | #define FUSB300_OFFSET_EPFFR(n) (0x2c + (n - 1) * 0x30) | ||
38 | #define FUSB300_OFFSET_EPSTRID(n) (0x40 + (n - 1) * 0x30) | ||
39 | #define FUSB300_OFFSET_HSPTM 0x300 | ||
40 | #define FUSB300_OFFSET_HSCR 0x304 | ||
41 | #define FUSB300_OFFSET_SSCR0 0x308 | ||
42 | #define FUSB300_OFFSET_SSCR1 0x30C | ||
43 | #define FUSB300_OFFSET_TT 0x310 | ||
44 | #define FUSB300_OFFSET_DEVNOTF 0x314 | ||
45 | #define FUSB300_OFFSET_DNC1 0x318 | ||
46 | #define FUSB300_OFFSET_CS 0x31C | ||
47 | #define FUSB300_OFFSET_SOF 0x324 | ||
48 | #define FUSB300_OFFSET_EFCS 0x328 | ||
49 | #define FUSB300_OFFSET_IGR0 0x400 | ||
50 | #define FUSB300_OFFSET_IGR1 0x404 | ||
51 | #define FUSB300_OFFSET_IGR2 0x408 | ||
52 | #define FUSB300_OFFSET_IGR3 0x40C | ||
53 | #define FUSB300_OFFSET_IGR4 0x410 | ||
54 | #define FUSB300_OFFSET_IGR5 0x414 | ||
55 | #define FUSB300_OFFSET_IGER0 0x420 | ||
56 | #define FUSB300_OFFSET_IGER1 0x424 | ||
57 | #define FUSB300_OFFSET_IGER2 0x428 | ||
58 | #define FUSB300_OFFSET_IGER3 0x42C | ||
59 | #define FUSB300_OFFSET_IGER4 0x430 | ||
60 | #define FUSB300_OFFSET_IGER5 0x434 | ||
61 | #define FUSB300_OFFSET_DMAHMER 0x500 | ||
62 | #define FUSB300_OFFSET_EPPRDRDY 0x504 | ||
63 | #define FUSB300_OFFSET_DMAEPMR 0x508 | ||
64 | #define FUSB300_OFFSET_DMAENR 0x50C | ||
65 | #define FUSB300_OFFSET_DMAAPR 0x510 | ||
66 | #define FUSB300_OFFSET_AHBCR 0x514 | ||
67 | #define FUSB300_OFFSET_EPPRD_W0(n) (0x520 + (n - 1) * 0x10) | ||
68 | #define FUSB300_OFFSET_EPPRD_W1(n) (0x524 + (n - 1) * 0x10) | ||
69 | #define FUSB300_OFFSET_EPPRD_W2(n) (0x528 + (n - 1) * 0x10) | ||
70 | #define FUSB300_OFFSET_EPRD_PTR(n) (0x52C + (n - 1) * 0x10) | ||
71 | #define FUSB300_OFFSET_BUFDBG_START 0x800 | ||
72 | #define FUSB300_OFFSET_BUFDBG_END 0xBFC | ||
73 | #define FUSB300_OFFSET_EPPORT(n) (0x1010 + (n - 1) * 0x10) | ||
74 | |||
75 | /* | ||
76 | * * Global Control Register (offset = 000H) | ||
77 | * */ | ||
78 | #define FUSB300_GCR_SF_RST (1 << 8) | ||
79 | #define FUSB300_GCR_VBUS_STATUS (1 << 7) | ||
80 | #define FUSB300_GCR_FORCE_HS_SUSP (1 << 6) | ||
81 | #define FUSB300_GCR_SYNC_FIFO1_CLR (1 << 5) | ||
82 | #define FUSB300_GCR_SYNC_FIFO0_CLR (1 << 4) | ||
83 | #define FUSB300_GCR_FIFOCLR (1 << 3) | ||
84 | #define FUSB300_GCR_GLINTEN (1 << 2) | ||
85 | #define FUSB300_GCR_DEVEN_FS 0x3 | ||
86 | #define FUSB300_GCR_DEVEN_HS 0x2 | ||
87 | #define FUSB300_GCR_DEVEN_SS 0x1 | ||
88 | #define FUSB300_GCR_DEVDIS 0x0 | ||
89 | #define FUSB300_GCR_DEVEN_MSK 0x3 | ||
90 | |||
91 | |||
92 | /* | ||
93 | * *Global Test Mode (offset = 004H) | ||
94 | * */ | ||
95 | #define FUSB300_GTM_TST_DIS_SOFGEN (1 << 16) | ||
96 | #define FUSB300_GTM_TST_CUR_EP_ENTRY(n) ((n & 0xF) << 12) | ||
97 | #define FUSB300_GTM_TST_EP_ENTRY(n) ((n & 0xF) << 8) | ||
98 | #define FUSB300_GTM_TST_EP_NUM(n) ((n & 0xF) << 4) | ||
99 | #define FUSB300_GTM_TST_FIFO_DEG (1 << 1) | ||
100 | #define FUSB300_GTM_TSTMODE (1 << 0) | ||
101 | |||
102 | /* | ||
103 | * * Device Address Register (offset = 008H) | ||
104 | * */ | ||
105 | #define FUSB300_DAR_SETCONFG (1 << 7) | ||
106 | #define FUSB300_DAR_DRVADDR(x) (x & 0x7F) | ||
107 | #define FUSB300_DAR_DRVADDR_MSK 0x7F | ||
108 | |||
109 | /* | ||
110 | * *Control Transfer Configuration and Status Register | ||
111 | * (CX_Config_Status, offset = 00CH) | ||
112 | * */ | ||
113 | #define FUSB300_CSR_LEN(x) ((x & 0xFFFF) << 8) | ||
114 | #define FUSB300_CSR_LEN_MSK (0xFFFF << 8) | ||
115 | #define FUSB300_CSR_EMP (1 << 4) | ||
116 | #define FUSB300_CSR_FUL (1 << 3) | ||
117 | #define FUSB300_CSR_CLR (1 << 2) | ||
118 | #define FUSB300_CSR_STL (1 << 1) | ||
119 | #define FUSB300_CSR_DONE (1 << 0) | ||
120 | |||
121 | /* | ||
122 | * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 ) | ||
123 | * */ | ||
124 | #define FUSB300_EPSET0_CLRSEQNUM (1 << 2) | ||
125 | #define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1) | ||
126 | #define FUSB300_EPSET0_STL (1 << 0) | ||
127 | |||
128 | /* | ||
129 | * * EPn Setting 1 (EPn_SET1, offset = 024H+(n-1)*30H, n=1~15) | ||
130 | * */ | ||
131 | #define FUSB300_EPSET1_START_ENTRY(x) ((x & 0xFF) << 24) | ||
132 | #define FUSB300_EPSET1_START_ENTRY_MSK (0xFF << 24) | ||
133 | #define FUSB300_EPSET1_FIFOENTRY(x) ((x & 0x1F) << 12) | ||
134 | #define FUSB300_EPSET1_FIFOENTRY_MSK (0x1f << 12) | ||
135 | #define FUSB300_EPSET1_INTERVAL(x) ((x & 0x7) << 6) | ||
136 | #define FUSB300_EPSET1_BWNUM(x) ((x & 0x3) << 4) | ||
137 | #define FUSB300_EPSET1_TYPEISO (1 << 2) | ||
138 | #define FUSB300_EPSET1_TYPEBLK (2 << 2) | ||
139 | #define FUSB300_EPSET1_TYPEINT (3 << 2) | ||
140 | #define FUSB300_EPSET1_TYPE(x) ((x & 0x3) << 2) | ||
141 | #define FUSB300_EPSET1_TYPE_MSK (0x3 << 2) | ||
142 | #define FUSB300_EPSET1_DIROUT (0 << 1) | ||
143 | #define FUSB300_EPSET1_DIRIN (1 << 1) | ||
144 | #define FUSB300_EPSET1_DIR(x) ((x & 0x1) << 1) | ||
145 | #define FUSB300_EPSET1_DIRIN (1 << 1) | ||
146 | #define FUSB300_EPSET1_DIR_MSK ((0x1) << 1) | ||
147 | #define FUSB300_EPSET1_ACTDIS 0 | ||
148 | #define FUSB300_EPSET1_ACTEN 1 | ||
149 | |||
150 | /* | ||
151 | * *EPn Setting 2 (EPn_SET2, offset = 028H+(n-1)*30H, n=1~15) | ||
152 | * */ | ||
153 | #define FUSB300_EPSET2_ADDROFS(x) ((x & 0x7FFF) << 16) | ||
154 | #define FUSB300_EPSET2_ADDROFS_MSK (0x7fff << 16) | ||
155 | #define FUSB300_EPSET2_MPS(x) (x & 0x7FF) | ||
156 | #define FUSB300_EPSET2_MPS_MSK 0x7FF | ||
157 | |||
158 | /* | ||
159 | * * EPn FIFO Register (offset = 2cH+(n-1)*30H) | ||
160 | * */ | ||
161 | #define FUSB300_FFR_RST (1 << 31) | ||
162 | #define FUSB300_FF_FUL (1 << 30) | ||
163 | #define FUSB300_FF_EMPTY (1 << 29) | ||
164 | #define FUSB300_FFR_BYCNT 0x1FFFF | ||
165 | |||
166 | /* | ||
167 | * *EPn Stream ID (EPn_STR_ID, offset = 040H+(n-1)*30H, n=1~15) | ||
168 | * */ | ||
169 | #define FUSB300_STRID_STREN (1 << 16) | ||
170 | #define FUSB300_STRID_STRID(x) (x & 0xFFFF) | ||
171 | |||
172 | /* | ||
173 | * *HS PHY Test Mode (offset = 300H) | ||
174 | * */ | ||
175 | #define FUSB300_HSPTM_TSTPKDONE (1 << 4) | ||
176 | #define FUSB300_HSPTM_TSTPKT (1 << 3) | ||
177 | #define FUSB300_HSPTM_TSTSET0NAK (1 << 2) | ||
178 | #define FUSB300_HSPTM_TSTKSTA (1 << 1) | ||
179 | #define FUSB300_HSPTM_TSTJSTA (1 << 0) | ||
180 | |||
181 | /* | ||
182 | * *HS Control Register (offset = 304H) | ||
183 | * */ | ||
184 | #define FUSB300_HSCR_HS_LPM_PERMIT (1 << 8) | ||
185 | #define FUSB300_HSCR_HS_LPM_RMWKUP (1 << 7) | ||
186 | #define FUSB300_HSCR_CAP_LPM_RMWKUP (1 << 6) | ||
187 | #define FUSB300_HSCR_HS_GOSUSP (1 << 5) | ||
188 | #define FUSB300_HSCR_HS_GORMWKU (1 << 4) | ||
189 | #define FUSB300_HSCR_CAP_RMWKUP (1 << 3) | ||
190 | #define FUSB300_HSCR_IDLECNT_0MS 0 | ||
191 | #define FUSB300_HSCR_IDLECNT_1MS 1 | ||
192 | #define FUSB300_HSCR_IDLECNT_2MS 2 | ||
193 | #define FUSB300_HSCR_IDLECNT_3MS 3 | ||
194 | #define FUSB300_HSCR_IDLECNT_4MS 4 | ||
195 | #define FUSB300_HSCR_IDLECNT_5MS 5 | ||
196 | #define FUSB300_HSCR_IDLECNT_6MS 6 | ||
197 | #define FUSB300_HSCR_IDLECNT_7MS 7 | ||
198 | |||
199 | /* | ||
200 | * * SS Controller Register 0 (offset = 308H) | ||
201 | * */ | ||
202 | #define FUSB300_SSCR0_MAX_INTERVAL(x) ((x & 0x7) << 4) | ||
203 | #define FUSB300_SSCR0_U2_FUN_EN (1 << 1) | ||
204 | #define FUSB300_SSCR0_U1_FUN_EN (1 << 0) | ||
205 | |||
206 | /* | ||
207 | * * SS Controller Register 1 (offset = 30CH) | ||
208 | * */ | ||
209 | #define FUSB300_SSCR1_GO_U3_DONE (1 << 8) | ||
210 | #define FUSB300_SSCR1_TXDEEMPH_LEVEL (1 << 7) | ||
211 | #define FUSB300_SSCR1_DIS_SCRMB (1 << 6) | ||
212 | #define FUSB300_SSCR1_FORCE_RECOVERY (1 << 5) | ||
213 | #define FUSB300_SSCR1_U3_WAKEUP_EN (1 << 4) | ||
214 | #define FUSB300_SSCR1_U2_EXIT_EN (1 << 3) | ||
215 | #define FUSB300_SSCR1_U1_EXIT_EN (1 << 2) | ||
216 | #define FUSB300_SSCR1_U2_ENTRY_EN (1 << 1) | ||
217 | #define FUSB300_SSCR1_U1_ENTRY_EN (1 << 0) | ||
218 | |||
219 | /* | ||
220 | * *SS Controller Register 2 (offset = 310H) | ||
221 | * */ | ||
222 | #define FUSB300_SSCR2_SS_TX_SWING (1 << 25) | ||
223 | #define FUSB300_SSCR2_FORCE_LINKPM_ACCEPT (1 << 24) | ||
224 | #define FUSB300_SSCR2_U2_INACT_TIMEOUT(x) ((x & 0xFF) << 16) | ||
225 | #define FUSB300_SSCR2_U1TIMEOUT(x) ((x & 0xFF) << 8) | ||
226 | #define FUSB300_SSCR2_U2TIMEOUT(x) (x & 0xFF) | ||
227 | |||
228 | /* | ||
229 | * *SS Device Notification Control (DEV_NOTF, offset = 314H) | ||
230 | * */ | ||
231 | #define FUSB300_DEVNOTF_CONTEXT0(x) ((x & 0xFFFFFF) << 8) | ||
232 | #define FUSB300_DEVNOTF_TYPE_DIS 0 | ||
233 | #define FUSB300_DEVNOTF_TYPE_FUNCWAKE 1 | ||
234 | #define FUSB300_DEVNOTF_TYPE_LTM 2 | ||
235 | #define FUSB300_DEVNOTF_TYPE_BUSINT_ADJMSG 3 | ||
236 | |||
237 | /* | ||
238 | * *BFM Arbiter Priority Register (BFM_ARB offset = 31CH) | ||
239 | * */ | ||
240 | #define FUSB300_BFMARB_ARB_M1 (1 << 3) | ||
241 | #define FUSB300_BFMARB_ARB_M0 (1 << 2) | ||
242 | #define FUSB300_BFMARB_ARB_S1 (1 << 1) | ||
243 | #define FUSB300_BFMARB_ARB_S0 1 | ||
244 | |||
245 | /* | ||
246 | * *Vendor Specific IO Control Register (offset = 320H) | ||
247 | * */ | ||
248 | #define FUSB300_VSIC_VCTLOAD_N (1 << 8) | ||
249 | #define FUSB300_VSIC_VCTL(x) (x & 0x3F) | ||
250 | |||
251 | /* | ||
252 | * *SOF Mask Timer (offset = 324H) | ||
253 | * */ | ||
254 | #define FUSB300_SOF_MASK_TIMER_HS 0x044c | ||
255 | #define FUSB300_SOF_MASK_TIMER_FS 0x2710 | ||
256 | |||
257 | /* | ||
258 | * *Error Flag and Control Status (offset = 328H) | ||
259 | * */ | ||
260 | #define FUSB300_EFCS_PM_STATE_U3 3 | ||
261 | #define FUSB300_EFCS_PM_STATE_U2 2 | ||
262 | #define FUSB300_EFCS_PM_STATE_U1 1 | ||
263 | #define FUSB300_EFCS_PM_STATE_U0 0 | ||
264 | |||
265 | /* | ||
266 | * *Interrupt Group 0 Register (offset = 400H) | ||
267 | * */ | ||
268 | #define FUSB300_IGR0_EP15_PRD_INT (1 << 31) | ||
269 | #define FUSB300_IGR0_EP14_PRD_INT (1 << 30) | ||
270 | #define FUSB300_IGR0_EP13_PRD_INT (1 << 29) | ||
271 | #define FUSB300_IGR0_EP12_PRD_INT (1 << 28) | ||
272 | #define FUSB300_IGR0_EP11_PRD_INT (1 << 27) | ||
273 | #define FUSB300_IGR0_EP10_PRD_INT (1 << 26) | ||
274 | #define FUSB300_IGR0_EP9_PRD_INT (1 << 25) | ||
275 | #define FUSB300_IGR0_EP8_PRD_INT (1 << 24) | ||
276 | #define FUSB300_IGR0_EP7_PRD_INT (1 << 23) | ||
277 | #define FUSB300_IGR0_EP6_PRD_INT (1 << 22) | ||
278 | #define FUSB300_IGR0_EP5_PRD_INT (1 << 21) | ||
279 | #define FUSB300_IGR0_EP4_PRD_INT (1 << 20) | ||
280 | #define FUSB300_IGR0_EP3_PRD_INT (1 << 19) | ||
281 | #define FUSB300_IGR0_EP2_PRD_INT (1 << 18) | ||
282 | #define FUSB300_IGR0_EP1_PRD_INT (1 << 17) | ||
283 | #define FUSB300_IGR0_EPn_PRD_INT(n) (1 << (n + 16)) | ||
284 | |||
285 | #define FUSB300_IGR0_EP15_FIFO_INT (1 << 15) | ||
286 | #define FUSB300_IGR0_EP14_FIFO_INT (1 << 14) | ||
287 | #define FUSB300_IGR0_EP13_FIFO_INT (1 << 13) | ||
288 | #define FUSB300_IGR0_EP12_FIFO_INT (1 << 12) | ||
289 | #define FUSB300_IGR0_EP11_FIFO_INT (1 << 11) | ||
290 | #define FUSB300_IGR0_EP10_FIFO_INT (1 << 10) | ||
291 | #define FUSB300_IGR0_EP9_FIFO_INT (1 << 9) | ||
292 | #define FUSB300_IGR0_EP8_FIFO_INT (1 << 8) | ||
293 | #define FUSB300_IGR0_EP7_FIFO_INT (1 << 7) | ||
294 | #define FUSB300_IGR0_EP6_FIFO_INT (1 << 6) | ||
295 | #define FUSB300_IGR0_EP5_FIFO_INT (1 << 5) | ||
296 | #define FUSB300_IGR0_EP4_FIFO_INT (1 << 4) | ||
297 | #define FUSB300_IGR0_EP3_FIFO_INT (1 << 3) | ||
298 | #define FUSB300_IGR0_EP2_FIFO_INT (1 << 2) | ||
299 | #define FUSB300_IGR0_EP1_FIFO_INT (1 << 1) | ||
300 | #define FUSB300_IGR0_EPn_FIFO_INT(n) (1 << n) | ||
301 | |||
302 | /* | ||
303 | * *Interrupt Group 1 Register (offset = 404H) | ||
304 | * */ | ||
305 | #define FUSB300_IGR1_INTGRP5 (1 << 31) | ||
306 | #define FUSB300_IGR1_VBUS_CHG_INT (1 << 30) | ||
307 | #define FUSB300_IGR1_SYNF1_EMPTY_INT (1 << 29) | ||
308 | #define FUSB300_IGR1_SYNF0_EMPTY_INT (1 << 28) | ||
309 | #define FUSB300_IGR1_U3_EXIT_FAIL_INT (1 << 27) | ||
310 | #define FUSB300_IGR1_U2_EXIT_FAIL_INT (1 << 26) | ||
311 | #define FUSB300_IGR1_U1_EXIT_FAIL_INT (1 << 25) | ||
312 | #define FUSB300_IGR1_U2_ENTRY_FAIL_INT (1 << 24) | ||
313 | #define FUSB300_IGR1_U1_ENTRY_FAIL_INT (1 << 23) | ||
314 | #define FUSB300_IGR1_U3_EXIT_INT (1 << 22) | ||
315 | #define FUSB300_IGR1_U2_EXIT_INT (1 << 21) | ||
316 | #define FUSB300_IGR1_U1_EXIT_INT (1 << 20) | ||
317 | #define FUSB300_IGR1_U3_ENTRY_INT (1 << 19) | ||
318 | #define FUSB300_IGR1_U2_ENTRY_INT (1 << 18) | ||
319 | #define FUSB300_IGR1_U1_ENTRY_INT (1 << 17) | ||
320 | #define FUSB300_IGR1_HOT_RST_INT (1 << 16) | ||
321 | #define FUSB300_IGR1_WARM_RST_INT (1 << 15) | ||
322 | #define FUSB300_IGR1_RESM_INT (1 << 14) | ||
323 | #define FUSB300_IGR1_SUSP_INT (1 << 13) | ||
324 | #define FUSB300_IGR1_HS_LPM_INT (1 << 12) | ||
325 | #define FUSB300_IGR1_USBRST_INT (1 << 11) | ||
326 | #define FUSB300_IGR1_DEV_MODE_CHG_INT (1 << 9) | ||
327 | #define FUSB300_IGR1_CX_COMABT_INT (1 << 8) | ||
328 | #define FUSB300_IGR1_CX_COMFAIL_INT (1 << 7) | ||
329 | #define FUSB300_IGR1_CX_CMDEND_INT (1 << 6) | ||
330 | #define FUSB300_IGR1_CX_OUT_INT (1 << 5) | ||
331 | #define FUSB300_IGR1_CX_IN_INT (1 << 4) | ||
332 | #define FUSB300_IGR1_CX_SETUP_INT (1 << 3) | ||
333 | #define FUSB300_IGR1_INTGRP4 (1 << 2) | ||
334 | #define FUSB300_IGR1_INTGRP3 (1 << 1) | ||
335 | #define FUSB300_IGR1_INTGRP2 (1 << 0) | ||
336 | |||
337 | /* | ||
338 | * *Interrupt Group 2 Register (offset = 408H) | ||
339 | * */ | ||
340 | #define FUSB300_IGR2_EP6_STR_ACCEPT_INT (1 << 29) | ||
341 | #define FUSB300_IGR2_EP6_STR_RESUME_INT (1 << 28) | ||
342 | #define FUSB300_IGR2_EP6_STR_REQ_INT (1 << 27) | ||
343 | #define FUSB300_IGR2_EP6_STR_NOTRDY_INT (1 << 26) | ||
344 | #define FUSB300_IGR2_EP6_STR_PRIME_INT (1 << 25) | ||
345 | #define FUSB300_IGR2_EP5_STR_ACCEPT_INT (1 << 24) | ||
346 | #define FUSB300_IGR2_EP5_STR_RESUME_INT (1 << 23) | ||
347 | #define FUSB300_IGR2_EP5_STR_REQ_INT (1 << 22) | ||
348 | #define FUSB300_IGR2_EP5_STR_NOTRDY_INT (1 << 21) | ||
349 | #define FUSB300_IGR2_EP5_STR_PRIME_INT (1 << 20) | ||
350 | #define FUSB300_IGR2_EP4_STR_ACCEPT_INT (1 << 19) | ||
351 | #define FUSB300_IGR2_EP4_STR_RESUME_INT (1 << 18) | ||
352 | #define FUSB300_IGR2_EP4_STR_REQ_INT (1 << 17) | ||
353 | #define FUSB300_IGR2_EP4_STR_NOTRDY_INT (1 << 16) | ||
354 | #define FUSB300_IGR2_EP4_STR_PRIME_INT (1 << 15) | ||
355 | #define FUSB300_IGR2_EP3_STR_ACCEPT_INT (1 << 14) | ||
356 | #define FUSB300_IGR2_EP3_STR_RESUME_INT (1 << 13) | ||
357 | #define FUSB300_IGR2_EP3_STR_REQ_INT (1 << 12) | ||
358 | #define FUSB300_IGR2_EP3_STR_NOTRDY_INT (1 << 11) | ||
359 | #define FUSB300_IGR2_EP3_STR_PRIME_INT (1 << 10) | ||
360 | #define FUSB300_IGR2_EP2_STR_ACCEPT_INT (1 << 9) | ||
361 | #define FUSB300_IGR2_EP2_STR_RESUME_INT (1 << 8) | ||
362 | #define FUSB300_IGR2_EP2_STR_REQ_INT (1 << 7) | ||
363 | #define FUSB300_IGR2_EP2_STR_NOTRDY_INT (1 << 6) | ||
364 | #define FUSB300_IGR2_EP2_STR_PRIME_INT (1 << 5) | ||
365 | #define FUSB300_IGR2_EP1_STR_ACCEPT_INT (1 << 4) | ||
366 | #define FUSB300_IGR2_EP1_STR_RESUME_INT (1 << 3) | ||
367 | #define FUSB300_IGR2_EP1_STR_REQ_INT (1 << 2) | ||
368 | #define FUSB300_IGR2_EP1_STR_NOTRDY_INT (1 << 1) | ||
369 | #define FUSB300_IGR2_EP1_STR_PRIME_INT (1 << 0) | ||
370 | |||
371 | #define FUSB300_IGR2_EP_STR_ACCEPT_INT(n) (1 << (5 * n - 1)) | ||
372 | #define FUSB300_IGR2_EP_STR_RESUME_INT(n) (1 << (5 * n - 2)) | ||
373 | #define FUSB300_IGR2_EP_STR_REQ_INT(n) (1 << (5 * n - 3)) | ||
374 | #define FUSB300_IGR2_EP_STR_NOTRDY_INT(n) (1 << (5 * n - 4)) | ||
375 | #define FUSB300_IGR2_EP_STR_PRIME_INT(n) (1 << (5 * n - 5)) | ||
376 | |||
377 | /* | ||
378 | * *Interrupt Group 3 Register (offset = 40CH) | ||
379 | * */ | ||
380 | #define FUSB300_IGR3_EP12_STR_ACCEPT_INT (1 << 29) | ||
381 | #define FUSB300_IGR3_EP12_STR_RESUME_INT (1 << 28) | ||
382 | #define FUSB300_IGR3_EP12_STR_REQ_INT (1 << 27) | ||
383 | #define FUSB300_IGR3_EP12_STR_NOTRDY_INT (1 << 26) | ||
384 | #define FUSB300_IGR3_EP12_STR_PRIME_INT (1 << 25) | ||
385 | #define FUSB300_IGR3_EP11_STR_ACCEPT_INT (1 << 24) | ||
386 | #define FUSB300_IGR3_EP11_STR_RESUME_INT (1 << 23) | ||
387 | #define FUSB300_IGR3_EP11_STR_REQ_INT (1 << 22) | ||
388 | #define FUSB300_IGR3_EP11_STR_NOTRDY_INT (1 << 21) | ||
389 | #define FUSB300_IGR3_EP11_STR_PRIME_INT (1 << 20) | ||
390 | #define FUSB300_IGR3_EP10_STR_ACCEPT_INT (1 << 19) | ||
391 | #define FUSB300_IGR3_EP10_STR_RESUME_INT (1 << 18) | ||
392 | #define FUSB300_IGR3_EP10_STR_REQ_INT (1 << 17) | ||
393 | #define FUSB300_IGR3_EP10_STR_NOTRDY_INT (1 << 16) | ||
394 | #define FUSB300_IGR3_EP10_STR_PRIME_INT (1 << 15) | ||
395 | #define FUSB300_IGR3_EP9_STR_ACCEPT_INT (1 << 14) | ||
396 | #define FUSB300_IGR3_EP9_STR_RESUME_INT (1 << 13) | ||
397 | #define FUSB300_IGR3_EP9_STR_REQ_INT (1 << 12) | ||
398 | #define FUSB300_IGR3_EP9_STR_NOTRDY_INT (1 << 11) | ||
399 | #define FUSB300_IGR3_EP9_STR_PRIME_INT (1 << 10) | ||
400 | #define FUSB300_IGR3_EP8_STR_ACCEPT_INT (1 << 9) | ||
401 | #define FUSB300_IGR3_EP8_STR_RESUME_INT (1 << 8) | ||
402 | #define FUSB300_IGR3_EP8_STR_REQ_INT (1 << 7) | ||
403 | #define FUSB300_IGR3_EP8_STR_NOTRDY_INT (1 << 6) | ||
404 | #define FUSB300_IGR3_EP8_STR_PRIME_INT (1 << 5) | ||
405 | #define FUSB300_IGR3_EP7_STR_ACCEPT_INT (1 << 4) | ||
406 | #define FUSB300_IGR3_EP7_STR_RESUME_INT (1 << 3) | ||
407 | #define FUSB300_IGR3_EP7_STR_REQ_INT (1 << 2) | ||
408 | #define FUSB300_IGR3_EP7_STR_NOTRDY_INT (1 << 1) | ||
409 | #define FUSB300_IGR3_EP7_STR_PRIME_INT (1 << 0) | ||
410 | |||
411 | #define FUSB300_IGR3_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1)) | ||
412 | #define FUSB300_IGR3_EP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2)) | ||
413 | #define FUSB300_IGR3_EP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3)) | ||
414 | #define FUSB300_IGR3_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4)) | ||
415 | #define FUSB300_IGR3_EP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5)) | ||
416 | |||
417 | /* | ||
418 | * *Interrupt Group 4 Register (offset = 410H) | ||
419 | * */ | ||
420 | #define FUSB300_IGR4_EP15_RX0_INT (1 << 31) | ||
421 | #define FUSB300_IGR4_EP14_RX0_INT (1 << 30) | ||
422 | #define FUSB300_IGR4_EP13_RX0_INT (1 << 29) | ||
423 | #define FUSB300_IGR4_EP12_RX0_INT (1 << 28) | ||
424 | #define FUSB300_IGR4_EP11_RX0_INT (1 << 27) | ||
425 | #define FUSB300_IGR4_EP10_RX0_INT (1 << 26) | ||
426 | #define FUSB300_IGR4_EP9_RX0_INT (1 << 25) | ||
427 | #define FUSB300_IGR4_EP8_RX0_INT (1 << 24) | ||
428 | #define FUSB300_IGR4_EP7_RX0_INT (1 << 23) | ||
429 | #define FUSB300_IGR4_EP6_RX0_INT (1 << 22) | ||
430 | #define FUSB300_IGR4_EP5_RX0_INT (1 << 21) | ||
431 | #define FUSB300_IGR4_EP4_RX0_INT (1 << 20) | ||
432 | #define FUSB300_IGR4_EP3_RX0_INT (1 << 19) | ||
433 | #define FUSB300_IGR4_EP2_RX0_INT (1 << 18) | ||
434 | #define FUSB300_IGR4_EP1_RX0_INT (1 << 17) | ||
435 | #define FUSB300_IGR4_EP_RX0_INT(x) (1 << (x + 16)) | ||
436 | #define FUSB300_IGR4_EP15_STR_ACCEPT_INT (1 << 14) | ||
437 | #define FUSB300_IGR4_EP15_STR_RESUME_INT (1 << 13) | ||
438 | #define FUSB300_IGR4_EP15_STR_REQ_INT (1 << 12) | ||
439 | #define FUSB300_IGR4_EP15_STR_NOTRDY_INT (1 << 11) | ||
440 | #define FUSB300_IGR4_EP15_STR_PRIME_INT (1 << 10) | ||
441 | #define FUSB300_IGR4_EP14_STR_ACCEPT_INT (1 << 9) | ||
442 | #define FUSB300_IGR4_EP14_STR_RESUME_INT (1 << 8) | ||
443 | #define FUSB300_IGR4_EP14_STR_REQ_INT (1 << 7) | ||
444 | #define FUSB300_IGR4_EP14_STR_NOTRDY_INT (1 << 6) | ||
445 | #define FUSB300_IGR4_EP14_STR_PRIME_INT (1 << 5) | ||
446 | #define FUSB300_IGR4_EP13_STR_ACCEPT_INT (1 << 4) | ||
447 | #define FUSB300_IGR4_EP13_STR_RESUME_INT (1 << 3) | ||
448 | #define FUSB300_IGR4_EP13_STR_REQ_INT (1 << 2) | ||
449 | #define FUSB300_IGR4_EP13_STR_NOTRDY_INT (1 << 1) | ||
450 | #define FUSB300_IGR4_EP13_STR_PRIME_INT (1 << 0) | ||
451 | |||
452 | #define FUSB300_IGR4_EP_STR_ACCEPT_INT(n) (1 << (5 * (n - 12) - 1)) | ||
453 | #define FUSB300_IGR4_EP_STR_RESUME_INT(n) (1 << (5 * (n - 12) - 2)) | ||
454 | #define FUSB300_IGR4_EP_STR_REQ_INT(n) (1 << (5 * (n - 12) - 3)) | ||
455 | #define FUSB300_IGR4_EP_STR_NOTRDY_INT(n) (1 << (5 * (n - 12) - 4)) | ||
456 | #define FUSB300_IGR4_EP_STR_PRIME_INT(n) (1 << (5 * (n - 12) - 5)) | ||
457 | |||
458 | /* | ||
459 | * *Interrupt Group 5 Register (offset = 414H) | ||
460 | * */ | ||
461 | #define FUSB300_IGR5_EP_STL_INT(n) (1 << n) | ||
462 | |||
463 | /* | ||
464 | * *Interrupt Enable Group 0 Register (offset = 420H) | ||
465 | * */ | ||
466 | #define FUSB300_IGER0_EEP15_PRD_INT (1 << 31) | ||
467 | #define FUSB300_IGER0_EEP14_PRD_INT (1 << 30) | ||
468 | #define FUSB300_IGER0_EEP13_PRD_INT (1 << 29) | ||
469 | #define FUSB300_IGER0_EEP12_PRD_INT (1 << 28) | ||
470 | #define FUSB300_IGER0_EEP11_PRD_INT (1 << 27) | ||
471 | #define FUSB300_IGER0_EEP10_PRD_INT (1 << 26) | ||
472 | #define FUSB300_IGER0_EEP9_PRD_INT (1 << 25) | ||
473 | #define FUSB300_IGER0_EP8_PRD_INT (1 << 24) | ||
474 | #define FUSB300_IGER0_EEP7_PRD_INT (1 << 23) | ||
475 | #define FUSB300_IGER0_EEP6_PRD_INT (1 << 22) | ||
476 | #define FUSB300_IGER0_EEP5_PRD_INT (1 << 21) | ||
477 | #define FUSB300_IGER0_EEP4_PRD_INT (1 << 20) | ||
478 | #define FUSB300_IGER0_EEP3_PRD_INT (1 << 19) | ||
479 | #define FUSB300_IGER0_EEP2_PRD_INT (1 << 18) | ||
480 | #define FUSB300_IGER0_EEP1_PRD_INT (1 << 17) | ||
481 | #define FUSB300_IGER0_EEPn_PRD_INT(n) (1 << (n + 16)) | ||
482 | |||
483 | #define FUSB300_IGER0_EEP15_FIFO_INT (1 << 15) | ||
484 | #define FUSB300_IGER0_EEP14_FIFO_INT (1 << 14) | ||
485 | #define FUSB300_IGER0_EEP13_FIFO_INT (1 << 13) | ||
486 | #define FUSB300_IGER0_EEP12_FIFO_INT (1 << 12) | ||
487 | #define FUSB300_IGER0_EEP11_FIFO_INT (1 << 11) | ||
488 | #define FUSB300_IGER0_EEP10_FIFO_INT (1 << 10) | ||
489 | #define FUSB300_IGER0_EEP9_FIFO_INT (1 << 9) | ||
490 | #define FUSB300_IGER0_EEP8_FIFO_INT (1 << 8) | ||
491 | #define FUSB300_IGER0_EEP7_FIFO_INT (1 << 7) | ||
492 | #define FUSB300_IGER0_EEP6_FIFO_INT (1 << 6) | ||
493 | #define FUSB300_IGER0_EEP5_FIFO_INT (1 << 5) | ||
494 | #define FUSB300_IGER0_EEP4_FIFO_INT (1 << 4) | ||
495 | #define FUSB300_IGER0_EEP3_FIFO_INT (1 << 3) | ||
496 | #define FUSB300_IGER0_EEP2_FIFO_INT (1 << 2) | ||
497 | #define FUSB300_IGER0_EEP1_FIFO_INT (1 << 1) | ||
498 | #define FUSB300_IGER0_EEPn_FIFO_INT(n) (1 << n) | ||
499 | |||
500 | /* | ||
501 | * *Interrupt Enable Group 1 Register (offset = 424H) | ||
502 | * */ | ||
503 | #define FUSB300_IGER1_EINT_GRP5 (1 << 31) | ||
504 | #define FUSB300_IGER1_VBUS_CHG_INT (1 << 30) | ||
505 | #define FUSB300_IGER1_SYNF1_EMPTY_INT (1 << 29) | ||
506 | #define FUSB300_IGER1_SYNF0_EMPTY_INT (1 << 28) | ||
507 | #define FUSB300_IGER1_U3_EXIT_FAIL_INT (1 << 27) | ||
508 | #define FUSB300_IGER1_U2_EXIT_FAIL_INT (1 << 26) | ||
509 | #define FUSB300_IGER1_U1_EXIT_FAIL_INT (1 << 25) | ||
510 | #define FUSB300_IGER1_U2_ENTRY_FAIL_INT (1 << 24) | ||
511 | #define FUSB300_IGER1_U1_ENTRY_FAIL_INT (1 << 23) | ||
512 | #define FUSB300_IGER1_U3_EXIT_INT (1 << 22) | ||
513 | #define FUSB300_IGER1_U2_EXIT_INT (1 << 21) | ||
514 | #define FUSB300_IGER1_U1_EXIT_INT (1 << 20) | ||
515 | #define FUSB300_IGER1_U3_ENTRY_INT (1 << 19) | ||
516 | #define FUSB300_IGER1_U2_ENTRY_INT (1 << 18) | ||
517 | #define FUSB300_IGER1_U1_ENTRY_INT (1 << 17) | ||
518 | #define FUSB300_IGER1_HOT_RST_INT (1 << 16) | ||
519 | #define FUSB300_IGER1_WARM_RST_INT (1 << 15) | ||
520 | #define FUSB300_IGER1_RESM_INT (1 << 14) | ||
521 | #define FUSB300_IGER1_SUSP_INT (1 << 13) | ||
522 | #define FUSB300_IGER1_LPM_INT (1 << 12) | ||
523 | #define FUSB300_IGER1_HS_RST_INT (1 << 11) | ||
524 | #define FUSB300_IGER1_EDEV_MODE_CHG_INT (1 << 9) | ||
525 | #define FUSB300_IGER1_CX_COMABT_INT (1 << 8) | ||
526 | #define FUSB300_IGER1_CX_COMFAIL_INT (1 << 7) | ||
527 | #define FUSB300_IGER1_CX_CMDEND_INT (1 << 6) | ||
528 | #define FUSB300_IGER1_CX_OUT_INT (1 << 5) | ||
529 | #define FUSB300_IGER1_CX_IN_INT (1 << 4) | ||
530 | #define FUSB300_IGER1_CX_SETUP_INT (1 << 3) | ||
531 | #define FUSB300_IGER1_INTGRP4 (1 << 2) | ||
532 | #define FUSB300_IGER1_INTGRP3 (1 << 1) | ||
533 | #define FUSB300_IGER1_INTGRP2 (1 << 0) | ||
534 | |||
535 | /* | ||
536 | * *Interrupt Enable Group 2 Register (offset = 428H) | ||
537 | * */ | ||
538 | #define FUSB300_IGER2_EEP_STR_ACCEPT_INT(n) (1 << (5 * n - 1)) | ||
539 | #define FUSB300_IGER2_EEP_STR_RESUME_INT(n) (1 << (5 * n - 2)) | ||
540 | #define FUSB300_IGER2_EEP_STR_REQ_INT(n) (1 << (5 * n - 3)) | ||
541 | #define FUSB300_IGER2_EEP_STR_NOTRDY_INT(n) (1 << (5 * n - 4)) | ||
542 | #define FUSB300_IGER2_EEP_STR_PRIME_INT(n) (1 << (5 * n - 5)) | ||
543 | |||
544 | /* | ||
545 | * *Interrupt Enable Group 3 Register (offset = 42CH) | ||
546 | * */ | ||
547 | |||
548 | #define FUSB300_IGER3_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1)) | ||
549 | #define FUSB300_IGER3_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2)) | ||
550 | #define FUSB300_IGER3_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3)) | ||
551 | #define FUSB300_IGER3_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4)) | ||
552 | #define FUSB300_IGER3_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5)) | ||
553 | |||
554 | /* | ||
555 | * *Interrupt Enable Group 4 Register (offset = 430H) | ||
556 | * */ | ||
557 | |||
558 | #define FUSB300_IGER4_EEP_RX0_INT(n) (1 << (n + 16)) | ||
559 | #define FUSB300_IGER4_EEP_STR_ACCEPT_INT(n) (1 << (5 * (n - 6) - 1)) | ||
560 | #define FUSB300_IGER4_EEP_STR_RESUME_INT(n) (1 << (5 * (n - 6) - 2)) | ||
561 | #define FUSB300_IGER4_EEP_STR_REQ_INT(n) (1 << (5 * (n - 6) - 3)) | ||
562 | #define FUSB300_IGER4_EEP_STR_NOTRDY_INT(n) (1 << (5 * (n - 6) - 4)) | ||
563 | #define FUSB300_IGER4_EEP_STR_PRIME_INT(n) (1 << (5 * (n - 6) - 5)) | ||
564 | |||
565 | /* EP PRD Ready (EP_PRD_RDY, offset = 504H) */ | ||
566 | |||
567 | #define FUSB300_EPPRDR_EP15_PRD_RDY (1 << 15) | ||
568 | #define FUSB300_EPPRDR_EP14_PRD_RDY (1 << 14) | ||
569 | #define FUSB300_EPPRDR_EP13_PRD_RDY (1 << 13) | ||
570 | #define FUSB300_EPPRDR_EP12_PRD_RDY (1 << 12) | ||
571 | #define FUSB300_EPPRDR_EP11_PRD_RDY (1 << 11) | ||
572 | #define FUSB300_EPPRDR_EP10_PRD_RDY (1 << 10) | ||
573 | #define FUSB300_EPPRDR_EP9_PRD_RDY (1 << 9) | ||
574 | #define FUSB300_EPPRDR_EP8_PRD_RDY (1 << 8) | ||
575 | #define FUSB300_EPPRDR_EP7_PRD_RDY (1 << 7) | ||
576 | #define FUSB300_EPPRDR_EP6_PRD_RDY (1 << 6) | ||
577 | #define FUSB300_EPPRDR_EP5_PRD_RDY (1 << 5) | ||
578 | #define FUSB300_EPPRDR_EP4_PRD_RDY (1 << 4) | ||
579 | #define FUSB300_EPPRDR_EP3_PRD_RDY (1 << 3) | ||
580 | #define FUSB300_EPPRDR_EP2_PRD_RDY (1 << 2) | ||
581 | #define FUSB300_EPPRDR_EP1_PRD_RDY (1 << 1) | ||
582 | #define FUSB300_EPPRDR_EP_PRD_RDY(n) (1 << n) | ||
583 | |||
584 | /* AHB Bus Control Register (offset = 514H) */ | ||
585 | #define FUSB300_AHBBCR_S1_SPLIT_ON (1 << 17) | ||
586 | #define FUSB300_AHBBCR_S0_SPLIT_ON (1 << 16) | ||
587 | #define FUSB300_AHBBCR_S1_1entry (0 << 12) | ||
588 | #define FUSB300_AHBBCR_S1_4entry (3 << 12) | ||
589 | #define FUSB300_AHBBCR_S1_8entry (5 << 12) | ||
590 | #define FUSB300_AHBBCR_S1_16entry (7 << 12) | ||
591 | #define FUSB300_AHBBCR_S0_1entry (0 << 8) | ||
592 | #define FUSB300_AHBBCR_S0_4entry (3 << 8) | ||
593 | #define FUSB300_AHBBCR_S0_8entry (5 << 8) | ||
594 | #define FUSB300_AHBBCR_S0_16entry (7 << 8) | ||
595 | #define FUSB300_AHBBCR_M1_BURST_SINGLE (0 << 4) | ||
596 | #define FUSB300_AHBBCR_M1_BURST_INCR (1 << 4) | ||
597 | #define FUSB300_AHBBCR_M1_BURST_INCR4 (3 << 4) | ||
598 | #define FUSB300_AHBBCR_M1_BURST_INCR8 (5 << 4) | ||
599 | #define FUSB300_AHBBCR_M1_BURST_INCR16 (7 << 4) | ||
600 | #define FUSB300_AHBBCR_M0_BURST_SINGLE 0 | ||
601 | #define FUSB300_AHBBCR_M0_BURST_INCR 1 | ||
602 | #define FUSB300_AHBBCR_M0_BURST_INCR4 3 | ||
603 | #define FUSB300_AHBBCR_M0_BURST_INCR8 5 | ||
604 | #define FUSB300_AHBBCR_M0_BURST_INCR16 7 | ||
605 | #define FUSB300_IGER5_EEP_STL_INT(n) (1 << n) | ||
606 | |||
607 | /* WORD 0 Data Structure of PRD Table */ | ||
608 | #define FUSB300_EPPRD0_M (1 << 30) | ||
609 | #define FUSB300_EPPRD0_O (1 << 29) | ||
610 | /* The finished prd */ | ||
611 | #define FUSB300_EPPRD0_F (1 << 28) | ||
612 | #define FUSB300_EPPRD0_I (1 << 27) | ||
613 | #define FUSB300_EPPRD0_A (1 << 26) | ||
614 | /* To decide HW point to first prd at next time */ | ||
615 | #define FUSB300_EPPRD0_L (1 << 25) | ||
616 | #define FUSB300_EPPRD0_H (1 << 24) | ||
617 | #define FUSB300_EPPRD0_BTC(n) (n & 0xFFFFFF) | ||
618 | |||
619 | /*----------------------------------------------------------------------*/ | ||
620 | #define FUSB300_MAX_NUM_EP 16 | ||
621 | |||
622 | #define FUSB300_FIFO_ENTRY_NUM 8 | ||
623 | #define FUSB300_MAX_FIFO_ENTRY 8 | ||
624 | |||
625 | #define SS_CTL_MAX_PACKET_SIZE 0x200 | ||
626 | #define SS_BULK_MAX_PACKET_SIZE 0x400 | ||
627 | #define SS_INT_MAX_PACKET_SIZE 0x400 | ||
628 | #define SS_ISO_MAX_PACKET_SIZE 0x400 | ||
629 | |||
630 | #define HS_BULK_MAX_PACKET_SIZE 0x200 | ||
631 | #define HS_CTL_MAX_PACKET_SIZE 0x40 | ||
632 | #define HS_INT_MAX_PACKET_SIZE 0x400 | ||
633 | #define HS_ISO_MAX_PACKET_SIZE 0x400 | ||
634 | |||
635 | struct fusb300_ep_info { | ||
636 | u8 epnum; | ||
637 | u8 type; | ||
638 | u8 interval; | ||
639 | u8 dir_in; | ||
640 | u16 maxpacket; | ||
641 | u16 addrofs; | ||
642 | u16 bw_num; | ||
643 | }; | ||
644 | |||
645 | struct fusb300_request { | ||
646 | |||
647 | struct usb_request req; | ||
648 | struct list_head queue; | ||
649 | }; | ||
650 | |||
651 | |||
652 | struct fusb300_ep { | ||
653 | struct usb_ep ep; | ||
654 | struct fusb300 *fusb300; | ||
655 | |||
656 | struct list_head queue; | ||
657 | unsigned stall:1; | ||
658 | unsigned wedged:1; | ||
659 | unsigned use_dma:1; | ||
660 | |||
661 | unsigned char epnum; | ||
662 | unsigned char type; | ||
663 | const struct usb_endpoint_descriptor *desc; | ||
664 | }; | ||
665 | |||
666 | struct fusb300 { | ||
667 | spinlock_t lock; | ||
668 | void __iomem *reg; | ||
669 | |||
670 | unsigned long irq_trigger; | ||
671 | |||
672 | struct usb_gadget gadget; | ||
673 | struct usb_gadget_driver *driver; | ||
674 | |||
675 | struct fusb300_ep *ep[FUSB300_MAX_NUM_EP]; | ||
676 | |||
677 | struct usb_request *ep0_req; /* for internal request */ | ||
678 | __le16 ep0_data; | ||
679 | u32 ep0_length; /* for internal request */ | ||
680 | u8 ep0_dir; /* 0/0x80 out/in */ | ||
681 | |||
682 | u8 fifo_entry_num; /* next start fifo entry */ | ||
683 | u32 addrofs; /* next fifo address offset */ | ||
684 | u8 reenum; /* if re-enumeration */ | ||
685 | }; | ||
686 | |||
687 | #endif | ||
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 51b19f3027e7..084aa080a2d5 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -258,7 +258,7 @@ static int pipe_buffer_setting(struct m66592 *m66592, | |||
258 | break; | 258 | break; |
259 | case M66592_BULK: | 259 | case M66592_BULK: |
260 | /* isochronous pipes may be used as bulk pipes */ | 260 | /* isochronous pipes may be used as bulk pipes */ |
261 | if (info->pipe > M66592_BASE_PIPENUM_BULK) | 261 | if (info->pipe >= M66592_BASE_PIPENUM_BULK) |
262 | bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; | 262 | bufnum = info->pipe - M66592_BASE_PIPENUM_BULK; |
263 | else | 263 | else |
264 | bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; | 264 | bufnum = info->pipe - M66592_BASE_PIPENUM_ISOC; |
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c index b120dbb64d0f..3e4b35e50c24 100644 --- a/drivers/usb/gadget/pch_udc.c +++ b/drivers/usb/gadget/pch_udc.c | |||
@@ -367,7 +367,6 @@ struct pch_udc_dev { | |||
367 | static const char ep0_string[] = "ep0in"; | 367 | static const char ep0_string[] = "ep0in"; |
368 | static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ | 368 | static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ |
369 | struct pch_udc_dev *pch_udc; /* pointer to device object */ | 369 | struct pch_udc_dev *pch_udc; /* pointer to device object */ |
370 | |||
371 | static int speed_fs; | 370 | static int speed_fs; |
372 | module_param_named(speed_fs, speed_fs, bool, S_IRUGO); | 371 | module_param_named(speed_fs, speed_fs, bool, S_IRUGO); |
373 | MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); | 372 | MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); |
@@ -383,6 +382,8 @@ MODULE_PARM_DESC(speed_fs, "true for Full speed operation"); | |||
383 | * @dma_mapped: DMA memory mapped for request | 382 | * @dma_mapped: DMA memory mapped for request |
384 | * @dma_done: DMA completed for request | 383 | * @dma_done: DMA completed for request |
385 | * @chain_len: chain length | 384 | * @chain_len: chain length |
385 | * @buf: Buffer memory for align adjustment | ||
386 | * @dma: DMA memory for align adjustment | ||
386 | */ | 387 | */ |
387 | struct pch_udc_request { | 388 | struct pch_udc_request { |
388 | struct usb_request req; | 389 | struct usb_request req; |
@@ -394,6 +395,8 @@ struct pch_udc_request { | |||
394 | dma_mapped:1, | 395 | dma_mapped:1, |
395 | dma_done:1; | 396 | dma_done:1; |
396 | unsigned chain_len; | 397 | unsigned chain_len; |
398 | void *buf; | ||
399 | dma_addr_t dma; | ||
397 | }; | 400 | }; |
398 | 401 | ||
399 | static inline u32 pch_udc_readl(struct pch_udc_dev *dev, unsigned long reg) | 402 | static inline u32 pch_udc_readl(struct pch_udc_dev *dev, unsigned long reg) |
@@ -615,7 +618,7 @@ static inline void pch_udc_ep_set_trfr_type(struct pch_udc_ep *ep, | |||
615 | /** | 618 | /** |
616 | * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint | 619 | * pch_udc_ep_set_bufsz() - Set the maximum packet size for the endpoint |
617 | * @ep: Reference to structure of type pch_udc_ep_regs | 620 | * @ep: Reference to structure of type pch_udc_ep_regs |
618 | * @buf_size: The buffer size | 621 | * @buf_size: The buffer word size |
619 | */ | 622 | */ |
620 | static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep, | 623 | static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep, |
621 | u32 buf_size, u32 ep_in) | 624 | u32 buf_size, u32 ep_in) |
@@ -635,7 +638,7 @@ static void pch_udc_ep_set_bufsz(struct pch_udc_ep *ep, | |||
635 | /** | 638 | /** |
636 | * pch_udc_ep_set_maxpkt() - Set the Max packet size for the endpoint | 639 | * pch_udc_ep_set_maxpkt() - Set the Max packet size for the endpoint |
637 | * @ep: Reference to structure of type pch_udc_ep_regs | 640 | * @ep: Reference to structure of type pch_udc_ep_regs |
638 | * @pkt_size: The packet size | 641 | * @pkt_size: The packet byte size |
639 | */ | 642 | */ |
640 | static void pch_udc_ep_set_maxpkt(struct pch_udc_ep *ep, u32 pkt_size) | 643 | static void pch_udc_ep_set_maxpkt(struct pch_udc_ep *ep, u32 pkt_size) |
641 | { | 644 | { |
@@ -920,25 +923,10 @@ static void pch_udc_ep_clear_nak(struct pch_udc_ep *ep) | |||
920 | */ | 923 | */ |
921 | static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir) | 924 | static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir) |
922 | { | 925 | { |
923 | unsigned int loopcnt = 0; | ||
924 | struct pch_udc_dev *dev = ep->dev; | ||
925 | |||
926 | if (dir) { /* IN ep */ | 926 | if (dir) { /* IN ep */ |
927 | pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F); | 927 | pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_F); |
928 | return; | 928 | return; |
929 | } | 929 | } |
930 | |||
931 | if (pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP) | ||
932 | return; | ||
933 | pch_udc_ep_bit_set(ep, UDC_EPCTL_ADDR, UDC_EPCTL_MRXFLUSH); | ||
934 | /* Wait for RxFIFO Empty */ | ||
935 | loopcnt = 10000; | ||
936 | while (!(pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP) && | ||
937 | --loopcnt) | ||
938 | udelay(5); | ||
939 | if (!loopcnt) | ||
940 | dev_err(&dev->pdev->dev, "RxFIFO not Empty\n"); | ||
941 | pch_udc_ep_bit_clr(ep, UDC_EPCTL_ADDR, UDC_EPCTL_MRXFLUSH); | ||
942 | } | 930 | } |
943 | 931 | ||
944 | /** | 932 | /** |
@@ -1220,14 +1208,31 @@ static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, | |||
1220 | 1208 | ||
1221 | dev = ep->dev; | 1209 | dev = ep->dev; |
1222 | if (req->dma_mapped) { | 1210 | if (req->dma_mapped) { |
1223 | if (ep->in) | 1211 | if (req->dma == DMA_ADDR_INVALID) { |
1224 | dma_unmap_single(&dev->pdev->dev, req->req.dma, | 1212 | if (ep->in) |
1225 | req->req.length, DMA_TO_DEVICE); | 1213 | dma_unmap_single(&dev->pdev->dev, req->req.dma, |
1226 | else | 1214 | req->req.length, |
1227 | dma_unmap_single(&dev->pdev->dev, req->req.dma, | 1215 | DMA_TO_DEVICE); |
1228 | req->req.length, DMA_FROM_DEVICE); | 1216 | else |
1217 | dma_unmap_single(&dev->pdev->dev, req->req.dma, | ||
1218 | req->req.length, | ||
1219 | DMA_FROM_DEVICE); | ||
1220 | req->req.dma = DMA_ADDR_INVALID; | ||
1221 | } else { | ||
1222 | if (ep->in) | ||
1223 | dma_unmap_single(&dev->pdev->dev, req->dma, | ||
1224 | req->req.length, | ||
1225 | DMA_TO_DEVICE); | ||
1226 | else { | ||
1227 | dma_unmap_single(&dev->pdev->dev, req->dma, | ||
1228 | req->req.length, | ||
1229 | DMA_FROM_DEVICE); | ||
1230 | memcpy(req->req.buf, req->buf, req->req.length); | ||
1231 | } | ||
1232 | kfree(req->buf); | ||
1233 | req->dma = DMA_ADDR_INVALID; | ||
1234 | } | ||
1229 | req->dma_mapped = 0; | 1235 | req->dma_mapped = 0; |
1230 | req->req.dma = DMA_ADDR_INVALID; | ||
1231 | } | 1236 | } |
1232 | ep->halted = 1; | 1237 | ep->halted = 1; |
1233 | spin_unlock(&dev->lock); | 1238 | spin_unlock(&dev->lock); |
@@ -1268,12 +1273,18 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev *dev, | |||
1268 | struct pch_udc_data_dma_desc *td = req->td_data; | 1273 | struct pch_udc_data_dma_desc *td = req->td_data; |
1269 | unsigned i = req->chain_len; | 1274 | unsigned i = req->chain_len; |
1270 | 1275 | ||
1276 | dma_addr_t addr2; | ||
1277 | dma_addr_t addr = (dma_addr_t)td->next; | ||
1278 | td->next = 0x00; | ||
1271 | for (; i > 1; --i) { | 1279 | for (; i > 1; --i) { |
1272 | dma_addr_t addr = (dma_addr_t)td->next; | ||
1273 | /* do not free first desc., will be done by free for request */ | 1280 | /* do not free first desc., will be done by free for request */ |
1274 | td = phys_to_virt(addr); | 1281 | td = phys_to_virt(addr); |
1282 | addr2 = (dma_addr_t)td->next; | ||
1275 | pci_pool_free(dev->data_requests, td, addr); | 1283 | pci_pool_free(dev->data_requests, td, addr); |
1284 | td->next = 0x00; | ||
1285 | addr = addr2; | ||
1276 | } | 1286 | } |
1287 | req->chain_len = 1; | ||
1277 | } | 1288 | } |
1278 | 1289 | ||
1279 | /** | 1290 | /** |
@@ -1301,23 +1312,23 @@ static int pch_udc_create_dma_chain(struct pch_udc_ep *ep, | |||
1301 | if (req->chain_len > 1) | 1312 | if (req->chain_len > 1) |
1302 | pch_udc_free_dma_chain(ep->dev, req); | 1313 | pch_udc_free_dma_chain(ep->dev, req); |
1303 | 1314 | ||
1304 | for (; ; bytes -= buf_len, ++len) { | 1315 | if (req->dma == DMA_ADDR_INVALID) |
1305 | if (ep->in) | 1316 | td->dataptr = req->req.dma; |
1306 | td->status = PCH_UDC_BS_HST_BSY | min(buf_len, bytes); | 1317 | else |
1307 | else | 1318 | td->dataptr = req->dma; |
1308 | td->status = PCH_UDC_BS_HST_BSY; | ||
1309 | 1319 | ||
1320 | td->status = PCH_UDC_BS_HST_BSY; | ||
1321 | for (; ; bytes -= buf_len, ++len) { | ||
1322 | td->status = PCH_UDC_BS_HST_BSY | min(buf_len, bytes); | ||
1310 | if (bytes <= buf_len) | 1323 | if (bytes <= buf_len) |
1311 | break; | 1324 | break; |
1312 | |||
1313 | last = td; | 1325 | last = td; |
1314 | td = pci_pool_alloc(ep->dev->data_requests, gfp_flags, | 1326 | td = pci_pool_alloc(ep->dev->data_requests, gfp_flags, |
1315 | &dma_addr); | 1327 | &dma_addr); |
1316 | if (!td) | 1328 | if (!td) |
1317 | goto nomem; | 1329 | goto nomem; |
1318 | |||
1319 | i += buf_len; | 1330 | i += buf_len; |
1320 | td->dataptr = req->req.dma + i; | 1331 | td->dataptr = req->td_data->dataptr + i; |
1321 | last->next = dma_addr; | 1332 | last->next = dma_addr; |
1322 | } | 1333 | } |
1323 | 1334 | ||
@@ -1352,28 +1363,15 @@ static int prepare_dma(struct pch_udc_ep *ep, struct pch_udc_request *req, | |||
1352 | { | 1363 | { |
1353 | int retval; | 1364 | int retval; |
1354 | 1365 | ||
1355 | req->td_data->dataptr = req->req.dma; | ||
1356 | req->td_data->status |= PCH_UDC_DMA_LAST; | ||
1357 | /* Allocate and create a DMA chain */ | 1366 | /* Allocate and create a DMA chain */ |
1358 | retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp); | 1367 | retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp); |
1359 | if (retval) { | 1368 | if (retval) { |
1360 | pr_err("%s: could not create DMA chain: %d\n", | 1369 | pr_err("%s: could not create DMA chain:%d\n", __func__, retval); |
1361 | __func__, retval); | ||
1362 | return retval; | 1370 | return retval; |
1363 | } | 1371 | } |
1364 | if (!ep->in) | 1372 | if (ep->in) |
1365 | return 0; | ||
1366 | if (req->req.length <= ep->ep.maxpacket) | ||
1367 | req->td_data->status = PCH_UDC_DMA_LAST | PCH_UDC_BS_HST_BSY | | ||
1368 | req->req.length; | ||
1369 | /* if bytes < max packet then tx bytes must | ||
1370 | * be written in packet per buffer mode | ||
1371 | */ | ||
1372 | if ((req->req.length < ep->ep.maxpacket) || !ep->num) | ||
1373 | req->td_data->status = (req->td_data->status & | 1373 | req->td_data->status = (req->td_data->status & |
1374 | ~PCH_UDC_RXTX_BYTES) | req->req.length; | 1374 | ~PCH_UDC_BUFF_STS) | PCH_UDC_BS_HST_RDY; |
1375 | req->td_data->status = (req->td_data->status & | ||
1376 | ~PCH_UDC_BUFF_STS) | PCH_UDC_BS_HST_BSY; | ||
1377 | return 0; | 1375 | return 0; |
1378 | } | 1376 | } |
1379 | 1377 | ||
@@ -1529,6 +1527,7 @@ static struct usb_request *pch_udc_alloc_request(struct usb_ep *usbep, | |||
1529 | if (!req) | 1527 | if (!req) |
1530 | return NULL; | 1528 | return NULL; |
1531 | req->req.dma = DMA_ADDR_INVALID; | 1529 | req->req.dma = DMA_ADDR_INVALID; |
1530 | req->dma = DMA_ADDR_INVALID; | ||
1532 | INIT_LIST_HEAD(&req->queue); | 1531 | INIT_LIST_HEAD(&req->queue); |
1533 | if (!ep->dev->dma_addr) | 1532 | if (!ep->dev->dma_addr) |
1534 | return &req->req; | 1533 | return &req->req; |
@@ -1613,16 +1612,33 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq, | |||
1613 | /* map the buffer for dma */ | 1612 | /* map the buffer for dma */ |
1614 | if (usbreq->length && | 1613 | if (usbreq->length && |
1615 | ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) { | 1614 | ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) { |
1616 | if (ep->in) | 1615 | if (!((unsigned long)(usbreq->buf) & 0x03)) { |
1617 | usbreq->dma = dma_map_single(&dev->pdev->dev, | 1616 | if (ep->in) |
1618 | usbreq->buf, | 1617 | usbreq->dma = dma_map_single(&dev->pdev->dev, |
1619 | usbreq->length, | 1618 | usbreq->buf, |
1620 | DMA_TO_DEVICE); | 1619 | usbreq->length, |
1621 | else | 1620 | DMA_TO_DEVICE); |
1622 | usbreq->dma = dma_map_single(&dev->pdev->dev, | 1621 | else |
1623 | usbreq->buf, | 1622 | usbreq->dma = dma_map_single(&dev->pdev->dev, |
1624 | usbreq->length, | 1623 | usbreq->buf, |
1625 | DMA_FROM_DEVICE); | 1624 | usbreq->length, |
1625 | DMA_FROM_DEVICE); | ||
1626 | } else { | ||
1627 | req->buf = kzalloc(usbreq->length, GFP_ATOMIC); | ||
1628 | if (!req->buf) | ||
1629 | return -ENOMEM; | ||
1630 | if (ep->in) { | ||
1631 | memcpy(req->buf, usbreq->buf, usbreq->length); | ||
1632 | req->dma = dma_map_single(&dev->pdev->dev, | ||
1633 | req->buf, | ||
1634 | usbreq->length, | ||
1635 | DMA_TO_DEVICE); | ||
1636 | } else | ||
1637 | req->dma = dma_map_single(&dev->pdev->dev, | ||
1638 | req->buf, | ||
1639 | usbreq->length, | ||
1640 | DMA_FROM_DEVICE); | ||
1641 | } | ||
1626 | req->dma_mapped = 1; | 1642 | req->dma_mapped = 1; |
1627 | } | 1643 | } |
1628 | if (usbreq->length > 0) { | 1644 | if (usbreq->length > 0) { |
@@ -1920,32 +1936,46 @@ static void pch_udc_complete_receiver(struct pch_udc_ep *ep) | |||
1920 | struct pch_udc_request *req; | 1936 | struct pch_udc_request *req; |
1921 | struct pch_udc_dev *dev = ep->dev; | 1937 | struct pch_udc_dev *dev = ep->dev; |
1922 | unsigned int count; | 1938 | unsigned int count; |
1939 | struct pch_udc_data_dma_desc *td; | ||
1940 | dma_addr_t addr; | ||
1923 | 1941 | ||
1924 | if (list_empty(&ep->queue)) | 1942 | if (list_empty(&ep->queue)) |
1925 | return; | 1943 | return; |
1926 | |||
1927 | /* next request */ | 1944 | /* next request */ |
1928 | req = list_entry(ep->queue.next, struct pch_udc_request, queue); | 1945 | req = list_entry(ep->queue.next, struct pch_udc_request, queue); |
1929 | if ((req->td_data_last->status & PCH_UDC_BUFF_STS) != | ||
1930 | PCH_UDC_BS_DMA_DONE) | ||
1931 | return; | ||
1932 | pch_udc_clear_dma(ep->dev, DMA_DIR_RX); | 1946 | pch_udc_clear_dma(ep->dev, DMA_DIR_RX); |
1933 | pch_udc_ep_set_ddptr(ep, 0); | 1947 | pch_udc_ep_set_ddptr(ep, 0); |
1934 | if ((req->td_data_last->status & PCH_UDC_RXTX_STS) != | 1948 | if ((req->td_data_last->status & PCH_UDC_BUFF_STS) == |
1935 | PCH_UDC_RTS_SUCC) { | 1949 | PCH_UDC_BS_DMA_DONE) |
1936 | dev_err(&dev->pdev->dev, "Invalid RXTX status (0x%08x) " | 1950 | td = req->td_data_last; |
1937 | "epstatus=0x%08x\n", | 1951 | else |
1938 | (req->td_data_last->status & PCH_UDC_RXTX_STS), | 1952 | td = req->td_data; |
1939 | (int)(ep->epsts)); | ||
1940 | return; | ||
1941 | } | ||
1942 | count = req->td_data_last->status & PCH_UDC_RXTX_BYTES; | ||
1943 | 1953 | ||
1954 | while (1) { | ||
1955 | if ((td->status & PCH_UDC_RXTX_STS) != PCH_UDC_RTS_SUCC) { | ||
1956 | dev_err(&dev->pdev->dev, "Invalid RXTX status=0x%08x " | ||
1957 | "epstatus=0x%08x\n", | ||
1958 | (req->td_data->status & PCH_UDC_RXTX_STS), | ||
1959 | (int)(ep->epsts)); | ||
1960 | return; | ||
1961 | } | ||
1962 | if ((td->status & PCH_UDC_BUFF_STS) == PCH_UDC_BS_DMA_DONE) | ||
1963 | if (td->status | PCH_UDC_DMA_LAST) { | ||
1964 | count = td->status & PCH_UDC_RXTX_BYTES; | ||
1965 | break; | ||
1966 | } | ||
1967 | if (td == req->td_data_last) { | ||
1968 | dev_err(&dev->pdev->dev, "Not complete RX descriptor"); | ||
1969 | return; | ||
1970 | } | ||
1971 | addr = (dma_addr_t)td->next; | ||
1972 | td = phys_to_virt(addr); | ||
1973 | } | ||
1944 | /* on 64k packets the RXBYTES field is zero */ | 1974 | /* on 64k packets the RXBYTES field is zero */ |
1945 | if (!count && (req->req.length == UDC_DMA_MAXPACKET)) | 1975 | if (!count && (req->req.length == UDC_DMA_MAXPACKET)) |
1946 | count = UDC_DMA_MAXPACKET; | 1976 | count = UDC_DMA_MAXPACKET; |
1947 | req->td_data->status |= PCH_UDC_DMA_LAST; | 1977 | req->td_data->status |= PCH_UDC_DMA_LAST; |
1948 | req->td_data_last->status |= PCH_UDC_BS_HST_BSY; | 1978 | td->status |= PCH_UDC_BS_HST_BSY; |
1949 | 1979 | ||
1950 | req->dma_going = 0; | 1980 | req->dma_going = 0; |
1951 | req->req.actual = count; | 1981 | req->req.actual = count; |
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c index c2448950a8d8..6d8b04061d5d 100644 --- a/drivers/usb/gadget/s3c2410_udc.c +++ b/drivers/usb/gadget/s3c2410_udc.c | |||
@@ -902,7 +902,7 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev) | |||
902 | int pwr_reg; | 902 | int pwr_reg; |
903 | int ep0csr; | 903 | int ep0csr; |
904 | int i; | 904 | int i; |
905 | u32 idx; | 905 | u32 idx, idx2; |
906 | unsigned long flags; | 906 | unsigned long flags; |
907 | 907 | ||
908 | spin_lock_irqsave(&dev->lock, flags); | 908 | spin_lock_irqsave(&dev->lock, flags); |
@@ -1017,6 +1017,20 @@ static irqreturn_t s3c2410_udc_irq(int dummy, void *_dev) | |||
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | /* what else causes this interrupt? a receive! who is it? */ | ||
1021 | if (!usb_status && !usbd_status && !pwr_reg && !ep0csr) { | ||
1022 | for (i = 1; i < S3C2410_ENDPOINTS; i++) { | ||
1023 | idx2 = udc_read(S3C2410_UDC_INDEX_REG); | ||
1024 | udc_write(i, S3C2410_UDC_INDEX_REG); | ||
1025 | |||
1026 | if (udc_read(S3C2410_UDC_OUT_CSR1_REG) & 0x1) | ||
1027 | s3c2410_udc_handle_ep(&dev->ep[i]); | ||
1028 | |||
1029 | /* restore index */ | ||
1030 | udc_write(idx2, S3C2410_UDC_INDEX_REG); | ||
1031 | } | ||
1032 | } | ||
1033 | |||
1020 | dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD); | 1034 | dprintk(DEBUG_VERBOSE, "irq: %d s3c2410_udc_done.\n", IRQ_USBD); |
1021 | 1035 | ||
1022 | /* Restore old index */ | 1036 | /* Restore old index */ |
@@ -1467,7 +1481,9 @@ static int s3c2410_udc_set_pullup(struct s3c2410_udc *udc, int is_on) | |||
1467 | { | 1481 | { |
1468 | dprintk(DEBUG_NORMAL, "%s()\n", __func__); | 1482 | dprintk(DEBUG_NORMAL, "%s()\n", __func__); |
1469 | 1483 | ||
1470 | if (udc_info && udc_info->udc_command) { | 1484 | if (udc_info && (udc_info->udc_command || |
1485 | gpio_is_valid(udc_info->pullup_pin))) { | ||
1486 | |||
1471 | if (is_on) | 1487 | if (is_on) |
1472 | s3c2410_udc_enable(udc); | 1488 | s3c2410_udc_enable(udc); |
1473 | else { | 1489 | else { |
@@ -1544,6 +1560,32 @@ static const struct usb_gadget_ops s3c2410_ops = { | |||
1544 | .vbus_draw = s3c2410_vbus_draw, | 1560 | .vbus_draw = s3c2410_vbus_draw, |
1545 | }; | 1561 | }; |
1546 | 1562 | ||
1563 | static void s3c2410_udc_command(enum s3c2410_udc_cmd_e cmd) | ||
1564 | { | ||
1565 | if (!udc_info) | ||
1566 | return; | ||
1567 | |||
1568 | if (udc_info->udc_command) { | ||
1569 | udc_info->udc_command(S3C2410_UDC_P_DISABLE); | ||
1570 | } else if (gpio_is_valid(udc_info->pullup_pin)) { | ||
1571 | int value; | ||
1572 | |||
1573 | switch (cmd) { | ||
1574 | case S3C2410_UDC_P_ENABLE: | ||
1575 | value = 1; | ||
1576 | break; | ||
1577 | case S3C2410_UDC_P_DISABLE: | ||
1578 | value = 0; | ||
1579 | break; | ||
1580 | default: | ||
1581 | return; | ||
1582 | } | ||
1583 | value ^= udc_info->pullup_pin_inverted; | ||
1584 | |||
1585 | gpio_set_value(udc_info->pullup_pin, value); | ||
1586 | } | ||
1587 | } | ||
1588 | |||
1547 | /*------------------------- gadget driver handling---------------------------*/ | 1589 | /*------------------------- gadget driver handling---------------------------*/ |
1548 | /* | 1590 | /* |
1549 | * s3c2410_udc_disable | 1591 | * s3c2410_udc_disable |
@@ -1565,8 +1607,7 @@ static void s3c2410_udc_disable(struct s3c2410_udc *dev) | |||
1565 | udc_write(0x1F, S3C2410_UDC_EP_INT_REG); | 1607 | udc_write(0x1F, S3C2410_UDC_EP_INT_REG); |
1566 | 1608 | ||
1567 | /* Good bye, cruel world */ | 1609 | /* Good bye, cruel world */ |
1568 | if (udc_info && udc_info->udc_command) | 1610 | s3c2410_udc_command(S3C2410_UDC_P_DISABLE); |
1569 | udc_info->udc_command(S3C2410_UDC_P_DISABLE); | ||
1570 | 1611 | ||
1571 | /* Set speed to unknown */ | 1612 | /* Set speed to unknown */ |
1572 | dev->gadget.speed = USB_SPEED_UNKNOWN; | 1613 | dev->gadget.speed = USB_SPEED_UNKNOWN; |
@@ -1627,8 +1668,7 @@ static void s3c2410_udc_enable(struct s3c2410_udc *dev) | |||
1627 | udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG); | 1668 | udc_write(S3C2410_UDC_INT_EP0, S3C2410_UDC_EP_INT_EN_REG); |
1628 | 1669 | ||
1629 | /* time to say "hello, world" */ | 1670 | /* time to say "hello, world" */ |
1630 | if (udc_info && udc_info->udc_command) | 1671 | s3c2410_udc_command(S3C2410_UDC_P_ENABLE); |
1631 | udc_info->udc_command(S3C2410_UDC_P_ENABLE); | ||
1632 | } | 1672 | } |
1633 | 1673 | ||
1634 | /* | 1674 | /* |
@@ -1903,6 +1943,17 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1903 | udc->vbus = 1; | 1943 | udc->vbus = 1; |
1904 | } | 1944 | } |
1905 | 1945 | ||
1946 | if (udc_info && !udc_info->udc_command && | ||
1947 | gpio_is_valid(udc_info->pullup_pin)) { | ||
1948 | |||
1949 | retval = gpio_request_one(udc_info->pullup_pin, | ||
1950 | udc_info->vbus_pin_inverted ? | ||
1951 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, | ||
1952 | "udc pullup"); | ||
1953 | if (retval) | ||
1954 | goto err_vbus_irq; | ||
1955 | } | ||
1956 | |||
1906 | if (s3c2410_udc_debugfs_root) { | 1957 | if (s3c2410_udc_debugfs_root) { |
1907 | udc->regs_info = debugfs_create_file("registers", S_IRUGO, | 1958 | udc->regs_info = debugfs_create_file("registers", S_IRUGO, |
1908 | s3c2410_udc_debugfs_root, | 1959 | s3c2410_udc_debugfs_root, |
@@ -1915,6 +1966,9 @@ static int s3c2410_udc_probe(struct platform_device *pdev) | |||
1915 | 1966 | ||
1916 | return 0; | 1967 | return 0; |
1917 | 1968 | ||
1969 | err_vbus_irq: | ||
1970 | if (udc_info && udc_info->vbus_pin > 0) | ||
1971 | free_irq(gpio_to_irq(udc_info->vbus_pin), udc); | ||
1918 | err_gpio_claim: | 1972 | err_gpio_claim: |
1919 | if (udc_info && udc_info->vbus_pin > 0) | 1973 | if (udc_info && udc_info->vbus_pin > 0) |
1920 | gpio_free(udc_info->vbus_pin); | 1974 | gpio_free(udc_info->vbus_pin); |
@@ -1942,6 +1996,10 @@ static int s3c2410_udc_remove(struct platform_device *pdev) | |||
1942 | 1996 | ||
1943 | debugfs_remove(udc->regs_info); | 1997 | debugfs_remove(udc->regs_info); |
1944 | 1998 | ||
1999 | if (udc_info && !udc_info->udc_command && | ||
2000 | gpio_is_valid(udc_info->pullup_pin)) | ||
2001 | gpio_free(udc_info->pullup_pin); | ||
2002 | |||
1945 | if (udc_info && udc_info->vbus_pin > 0) { | 2003 | if (udc_info && udc_info->vbus_pin > 0) { |
1946 | irq = gpio_to_irq(udc_info->vbus_pin); | 2004 | irq = gpio_to_irq(udc_info->vbus_pin); |
1947 | free_irq(irq, udc); | 2005 | free_irq(irq, udc); |
@@ -1973,16 +2031,14 @@ static int s3c2410_udc_remove(struct platform_device *pdev) | |||
1973 | #ifdef CONFIG_PM | 2031 | #ifdef CONFIG_PM |
1974 | static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) | 2032 | static int s3c2410_udc_suspend(struct platform_device *pdev, pm_message_t message) |
1975 | { | 2033 | { |
1976 | if (udc_info && udc_info->udc_command) | 2034 | s3c2410_udc_command(S3C2410_UDC_P_DISABLE); |
1977 | udc_info->udc_command(S3C2410_UDC_P_DISABLE); | ||
1978 | 2035 | ||
1979 | return 0; | 2036 | return 0; |
1980 | } | 2037 | } |
1981 | 2038 | ||
1982 | static int s3c2410_udc_resume(struct platform_device *pdev) | 2039 | static int s3c2410_udc_resume(struct platform_device *pdev) |
1983 | { | 2040 | { |
1984 | if (udc_info && udc_info->udc_command) | 2041 | s3c2410_udc_command(S3C2410_UDC_P_ENABLE); |
1985 | udc_info->udc_command(S3C2410_UDC_P_ENABLE); | ||
1986 | 2042 | ||
1987 | return 0; | 2043 | return 0; |
1988 | } | 2044 | } |
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 1eda968b5644..2ac1d2147325 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -241,7 +241,7 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) | |||
241 | size -= size % out->maxpacket; | 241 | size -= size % out->maxpacket; |
242 | 242 | ||
243 | if (dev->port_usb->is_fixed) | 243 | if (dev->port_usb->is_fixed) |
244 | size = max(size, dev->port_usb->fixed_out_len); | 244 | size = max_t(size_t, size, dev->port_usb->fixed_out_len); |
245 | 245 | ||
246 | skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); | 246 | skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags); |
247 | if (skb == NULL) { | 247 | if (skb == NULL) { |
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 0e6afa260ed8..9483acdf2e9e 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
@@ -91,17 +91,28 @@ config USB_EHCI_TT_NEWSCHED | |||
91 | 91 | ||
92 | If unsure, say Y. | 92 | If unsure, say Y. |
93 | 93 | ||
94 | config USB_EHCI_HCD_PMC_MSP | ||
95 | tristate "EHCI support for on-chip PMC MSP71xx USB controller" | ||
96 | depends on USB_EHCI_HCD && MSP_HAS_USB | ||
97 | default n | ||
98 | select USB_EHCI_BIG_ENDIAN_DESC | ||
99 | select USB_EHCI_BIG_ENDIAN_MMIO | ||
100 | ---help--- | ||
101 | Enables support for the onchip USB controller on the PMC_MSP7100 Family SoC's. | ||
102 | If unsure, say N. | ||
103 | |||
94 | config USB_EHCI_BIG_ENDIAN_MMIO | 104 | config USB_EHCI_BIG_ENDIAN_MMIO |
95 | bool | 105 | bool |
96 | depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \ | 106 | depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \ |
97 | ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ | 107 | ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ |
98 | PPC_MPC512x || CPU_CAVIUM_OCTEON) | 108 | PPC_MPC512x || CPU_CAVIUM_OCTEON || \ |
109 | PMC_MSP) | ||
99 | default y | 110 | default y |
100 | 111 | ||
101 | config USB_EHCI_BIG_ENDIAN_DESC | 112 | config USB_EHCI_BIG_ENDIAN_DESC |
102 | bool | 113 | bool |
103 | depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ | 114 | depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ |
104 | PPC_MPC512x) | 115 | PPC_MPC512x || PMC_MSP) |
105 | default y | 116 | default y |
106 | 117 | ||
107 | config XPS_USB_HCD_XILINX | 118 | config XPS_USB_HCD_XILINX |
@@ -145,7 +156,7 @@ config USB_EHCI_MSM | |||
145 | bool "Support for MSM on-chip EHCI USB controller" | 156 | bool "Support for MSM on-chip EHCI USB controller" |
146 | depends on USB_EHCI_HCD && ARCH_MSM | 157 | depends on USB_EHCI_HCD && ARCH_MSM |
147 | select USB_EHCI_ROOT_HUB_TT | 158 | select USB_EHCI_ROOT_HUB_TT |
148 | select USB_MSM_OTG_72K | 159 | select USB_MSM_OTG |
149 | ---help--- | 160 | ---help--- |
150 | Enables support for the USB Host controller present on the | 161 | Enables support for the USB Host controller present on the |
151 | Qualcomm chipsets. Root Hub has inbuilt TT. | 162 | Qualcomm chipsets. Root Hub has inbuilt TT. |
@@ -154,6 +165,14 @@ config USB_EHCI_MSM | |||
154 | This driver is not supported on boards like trout which | 165 | This driver is not supported on boards like trout which |
155 | has an external PHY. | 166 | has an external PHY. |
156 | 167 | ||
168 | config USB_EHCI_TEGRA | ||
169 | boolean "NVIDIA Tegra HCD support" | ||
170 | depends on USB_EHCI_HCD && ARCH_TEGRA | ||
171 | select USB_EHCI_ROOT_HUB_TT | ||
172 | help | ||
173 | This driver enables support for the internal USB Host Controllers | ||
174 | found in NVIDIA Tegra SoCs. The controllers are EHCI compliant. | ||
175 | |||
157 | config USB_EHCI_HCD_PPC_OF | 176 | config USB_EHCI_HCD_PPC_OF |
158 | bool "EHCI support for PPC USB controller on OF platform bus" | 177 | bool "EHCI support for PPC USB controller on OF platform bus" |
159 | depends on USB_EHCI_HCD && PPC_OF | 178 | depends on USB_EHCI_HCD && PPC_OF |
@@ -162,6 +181,13 @@ config USB_EHCI_HCD_PPC_OF | |||
162 | Enables support for the USB controller present on the PowerPC | 181 | Enables support for the USB controller present on the PowerPC |
163 | OpenFirmware platform bus. | 182 | OpenFirmware platform bus. |
164 | 183 | ||
184 | config USB_EHCI_SH | ||
185 | bool "EHCI support for SuperH USB controller" | ||
186 | depends on USB_EHCI_HCD && SUPERH | ||
187 | ---help--- | ||
188 | Enables support for the on-chip EHCI controller on the SuperH. | ||
189 | If you use the PCI EHCI controller, this option is not necessary. | ||
190 | |||
165 | config USB_W90X900_EHCI | 191 | config USB_W90X900_EHCI |
166 | bool "W90X900(W90P910) EHCI support" | 192 | bool "W90X900(W90P910) EHCI support" |
167 | depends on USB_EHCI_HCD && ARCH_W90X900 | 193 | depends on USB_EHCI_HCD && ARCH_W90X900 |
@@ -315,6 +341,13 @@ config USB_OHCI_HCD_SSB | |||
315 | 341 | ||
316 | If unsure, say N. | 342 | If unsure, say N. |
317 | 343 | ||
344 | config USB_OHCI_SH | ||
345 | bool "OHCI support for SuperH USB controller" | ||
346 | depends on USB_OHCI_HCD && SUPERH | ||
347 | ---help--- | ||
348 | Enables support for the on-chip OHCI controller on the SuperH. | ||
349 | If you use the PCI OHCI controller, this option is not necessary. | ||
350 | |||
318 | config USB_CNS3XXX_OHCI | 351 | config USB_CNS3XXX_OHCI |
319 | bool "Cavium CNS3XXX OHCI Module" | 352 | bool "Cavium CNS3XXX OHCI Module" |
320 | depends on USB_OHCI_HCD && ARCH_CNS3XXX | 353 | depends on USB_OHCI_HCD && ARCH_CNS3XXX |
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c index d6a69d514a84..b2ed55cb811d 100644 --- a/drivers/usb/host/ehci-atmel.c +++ b/drivers/usb/host/ehci-atmel.c | |||
@@ -115,7 +115,7 @@ static const struct hc_driver ehci_atmel_hc_driver = { | |||
115 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | 115 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
116 | }; | 116 | }; |
117 | 117 | ||
118 | static int __init ehci_atmel_drv_probe(struct platform_device *pdev) | 118 | static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev) |
119 | { | 119 | { |
120 | struct usb_hcd *hcd; | 120 | struct usb_hcd *hcd; |
121 | const struct hc_driver *driver = &ehci_atmel_hc_driver; | 121 | const struct hc_driver *driver = &ehci_atmel_hc_driver; |
@@ -207,7 +207,7 @@ fail_create_hcd: | |||
207 | return retval; | 207 | return retval; |
208 | } | 208 | } |
209 | 209 | ||
210 | static int __exit ehci_atmel_drv_remove(struct platform_device *pdev) | 210 | static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev) |
211 | { | 211 | { |
212 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 212 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
213 | 213 | ||
@@ -227,7 +227,7 @@ static int __exit ehci_atmel_drv_remove(struct platform_device *pdev) | |||
227 | 227 | ||
228 | static struct platform_driver ehci_atmel_driver = { | 228 | static struct platform_driver ehci_atmel_driver = { |
229 | .probe = ehci_atmel_drv_probe, | 229 | .probe = ehci_atmel_drv_probe, |
230 | .remove = __exit_p(ehci_atmel_drv_remove), | 230 | .remove = __devexit_p(ehci_atmel_drv_remove), |
231 | .shutdown = usb_hcd_platform_shutdown, | 231 | .shutdown = usb_hcd_platform_shutdown, |
232 | .driver.name = "atmel-ehci", | 232 | .driver.name = "atmel-ehci", |
233 | }; | 233 | }; |
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 3be238a24cc5..693c29b30521 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
@@ -28,11 +28,9 @@ | |||
28 | dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args ) | 28 | dev_warn (ehci_to_hcd(ehci)->self.controller , fmt , ## args ) |
29 | 29 | ||
30 | #ifdef VERBOSE_DEBUG | 30 | #ifdef VERBOSE_DEBUG |
31 | # define vdbg dbg | ||
32 | # define ehci_vdbg ehci_dbg | 31 | # define ehci_vdbg ehci_dbg |
33 | #else | 32 | #else |
34 | # define vdbg(fmt,args...) do { } while (0) | 33 | static inline void ehci_vdbg(struct ehci_hcd *ehci, ...) {} |
35 | # define ehci_vdbg(ehci, fmt, args...) do { } while (0) | ||
36 | #endif | 34 | #endif |
37 | 35 | ||
38 | #ifdef DEBUG | 36 | #ifdef DEBUG |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 74dcf49bd015..d30c4e08c137 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
@@ -114,13 +114,11 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n"); | |||
114 | 114 | ||
115 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) | 115 | #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) |
116 | 116 | ||
117 | /* for ASPM quirk of ISOC on AMD SB800 */ | ||
118 | static struct pci_dev *amd_nb_dev; | ||
119 | |||
120 | /*-------------------------------------------------------------------------*/ | 117 | /*-------------------------------------------------------------------------*/ |
121 | 118 | ||
122 | #include "ehci.h" | 119 | #include "ehci.h" |
123 | #include "ehci-dbg.c" | 120 | #include "ehci-dbg.c" |
121 | #include "pci-quirks.h" | ||
124 | 122 | ||
125 | /*-------------------------------------------------------------------------*/ | 123 | /*-------------------------------------------------------------------------*/ |
126 | 124 | ||
@@ -532,10 +530,8 @@ static void ehci_stop (struct usb_hcd *hcd) | |||
532 | spin_unlock_irq (&ehci->lock); | 530 | spin_unlock_irq (&ehci->lock); |
533 | ehci_mem_cleanup (ehci); | 531 | ehci_mem_cleanup (ehci); |
534 | 532 | ||
535 | if (amd_nb_dev) { | 533 | if (ehci->amd_pll_fix == 1) |
536 | pci_dev_put(amd_nb_dev); | 534 | usb_amd_dev_put(); |
537 | amd_nb_dev = NULL; | ||
538 | } | ||
539 | 535 | ||
540 | #ifdef EHCI_STATS | 536 | #ifdef EHCI_STATS |
541 | ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", | 537 | ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", |
@@ -679,7 +675,12 @@ static int ehci_run (struct usb_hcd *hcd) | |||
679 | hcd->uses_new_polling = 1; | 675 | hcd->uses_new_polling = 1; |
680 | 676 | ||
681 | /* EHCI spec section 4.1 */ | 677 | /* EHCI spec section 4.1 */ |
682 | if ((retval = ehci_reset(ehci)) != 0) { | 678 | /* |
679 | * TDI driver does the ehci_reset in their reset callback. | ||
680 | * Don't reset here, because configuration settings will | ||
681 | * vanish. | ||
682 | */ | ||
683 | if (!ehci_is_TDI(ehci) && (retval = ehci_reset(ehci)) != 0) { | ||
683 | ehci_mem_cleanup(ehci); | 684 | ehci_mem_cleanup(ehci); |
684 | return retval; | 685 | return retval; |
685 | } | 686 | } |
@@ -1179,7 +1180,7 @@ MODULE_LICENSE ("GPL"); | |||
1179 | #define PLATFORM_DRIVER ehci_mxc_driver | 1180 | #define PLATFORM_DRIVER ehci_mxc_driver |
1180 | #endif | 1181 | #endif |
1181 | 1182 | ||
1182 | #ifdef CONFIG_CPU_SUBTYPE_SH7786 | 1183 | #ifdef CONFIG_USB_EHCI_SH |
1183 | #include "ehci-sh.c" | 1184 | #include "ehci-sh.c" |
1184 | #define PLATFORM_DRIVER ehci_hcd_sh_driver | 1185 | #define PLATFORM_DRIVER ehci_hcd_sh_driver |
1185 | #endif | 1186 | #endif |
@@ -1254,6 +1255,16 @@ MODULE_LICENSE ("GPL"); | |||
1254 | #define PLATFORM_DRIVER ehci_msm_driver | 1255 | #define PLATFORM_DRIVER ehci_msm_driver |
1255 | #endif | 1256 | #endif |
1256 | 1257 | ||
1258 | #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP | ||
1259 | #include "ehci-pmcmsp.c" | ||
1260 | #define PLATFORM_DRIVER ehci_hcd_msp_driver | ||
1261 | #endif | ||
1262 | |||
1263 | #ifdef CONFIG_USB_EHCI_TEGRA | ||
1264 | #include "ehci-tegra.c" | ||
1265 | #define PLATFORM_DRIVER tegra_ehci_driver | ||
1266 | #endif | ||
1267 | |||
1257 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ | 1268 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
1258 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ | 1269 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ |
1259 | !defined(XILINX_OF_PLATFORM_DRIVER) | 1270 | !defined(XILINX_OF_PLATFORM_DRIVER) |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 8a515f0d5988..d05ea03cfb4d 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
@@ -106,6 +106,27 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci) | |||
106 | ehci->owned_ports = 0; | 106 | ehci->owned_ports = 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | static int ehci_port_change(struct ehci_hcd *ehci) | ||
110 | { | ||
111 | int i = HCS_N_PORTS(ehci->hcs_params); | ||
112 | |||
113 | /* First check if the controller indicates a change event */ | ||
114 | |||
115 | if (ehci_readl(ehci, &ehci->regs->status) & STS_PCD) | ||
116 | return 1; | ||
117 | |||
118 | /* | ||
119 | * Not all controllers appear to update this while going from D3 to D0, | ||
120 | * so check the individual port status registers as well | ||
121 | */ | ||
122 | |||
123 | while (i--) | ||
124 | if (ehci_readl(ehci, &ehci->regs->port_status[i]) & PORT_CSC) | ||
125 | return 1; | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
109 | static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, | 130 | static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, |
110 | bool suspending, bool do_wakeup) | 131 | bool suspending, bool do_wakeup) |
111 | { | 132 | { |
@@ -173,7 +194,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, | |||
173 | } | 194 | } |
174 | 195 | ||
175 | /* Does the root hub have a port wakeup pending? */ | 196 | /* Does the root hub have a port wakeup pending? */ |
176 | if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)) | 197 | if (!suspending && ehci_port_change(ehci)) |
177 | usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); | 198 | usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); |
178 | 199 | ||
179 | spin_unlock_irqrestore(&ehci->lock, flags); | 200 | spin_unlock_irqrestore(&ehci->lock, flags); |
@@ -538,14 +559,15 @@ static ssize_t store_companion(struct device *dev, | |||
538 | } | 559 | } |
539 | static DEVICE_ATTR(companion, 0644, show_companion, store_companion); | 560 | static DEVICE_ATTR(companion, 0644, show_companion, store_companion); |
540 | 561 | ||
541 | static inline void create_companion_file(struct ehci_hcd *ehci) | 562 | static inline int create_companion_file(struct ehci_hcd *ehci) |
542 | { | 563 | { |
543 | int i; | 564 | int i = 0; |
544 | 565 | ||
545 | /* with integrated TT there is no companion! */ | 566 | /* with integrated TT there is no companion! */ |
546 | if (!ehci_is_TDI(ehci)) | 567 | if (!ehci_is_TDI(ehci)) |
547 | i = device_create_file(ehci_to_hcd(ehci)->self.controller, | 568 | i = device_create_file(ehci_to_hcd(ehci)->self.controller, |
548 | &dev_attr_companion); | 569 | &dev_attr_companion); |
570 | return i; | ||
549 | } | 571 | } |
550 | 572 | ||
551 | static inline void remove_companion_file(struct ehci_hcd *ehci) | 573 | static inline void remove_companion_file(struct ehci_hcd *ehci) |
@@ -695,8 +717,8 @@ ehci_hub_descriptor ( | |||
695 | desc->bDescLength = 7 + 2 * temp; | 717 | desc->bDescLength = 7 + 2 * temp; |
696 | 718 | ||
697 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 719 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
698 | memset (&desc->bitmap [0], 0, temp); | 720 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
699 | memset (&desc->bitmap [temp], 0xff, temp); | 721 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
700 | 722 | ||
701 | temp = 0x0008; /* per-port overcurrent reporting */ | 723 | temp = 0x0008; /* per-port overcurrent reporting */ |
702 | if (HCS_PPC (ehci->hcs_params)) | 724 | if (HCS_PPC (ehci->hcs_params)) |
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c index b4d4d63c13ed..2111627a19de 100644 --- a/drivers/usb/host/ehci-lpm.c +++ b/drivers/usb/host/ehci-lpm.c | |||
@@ -17,7 +17,8 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | /* this file is part of ehci-hcd.c */ | 19 | /* this file is part of ehci-hcd.c */ |
20 | static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num) | 20 | static int __maybe_unused ehci_lpm_set_da(struct ehci_hcd *ehci, |
21 | int dev_addr, int port_num) | ||
21 | { | 22 | { |
22 | u32 __iomem portsc; | 23 | u32 __iomem portsc; |
23 | 24 | ||
@@ -37,7 +38,7 @@ static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num) | |||
37 | * this function is used to check if the device support LPM | 38 | * this function is used to check if the device support LPM |
38 | * if yes, mark the PORTSC register with PORT_LPM bit | 39 | * if yes, mark the PORTSC register with PORT_LPM bit |
39 | */ | 40 | */ |
40 | static int ehci_lpm_check(struct ehci_hcd *ehci, int port) | 41 | static int __maybe_unused ehci_lpm_check(struct ehci_hcd *ehci, int port) |
41 | { | 42 | { |
42 | u32 __iomem *portsc ; | 43 | u32 __iomem *portsc ; |
43 | u32 val32; | 44 | u32 val32; |
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c index 413f4deca532..9ce1b0bc186d 100644 --- a/drivers/usb/host/ehci-msm.c +++ b/drivers/usb/host/ehci-msm.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* ehci-msm.c - HSUSB Host Controller Driver Implementation | 1 | /* ehci-msm.c - HSUSB Host Controller Driver Implementation |
2 | * | 2 | * |
3 | * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved. | 3 | * Copyright (c) 2008-2011, Code Aurora Forum. All rights reserved. |
4 | * | 4 | * |
5 | * Partly derived from ehci-fsl.c and ehci-hcd.c | 5 | * Partly derived from ehci-fsl.c and ehci-hcd.c |
6 | * Copyright (c) 2000-2004 by David Brownell | 6 | * Copyright (c) 2000-2004 by David Brownell |
@@ -34,92 +34,6 @@ | |||
34 | 34 | ||
35 | static struct otg_transceiver *otg; | 35 | static struct otg_transceiver *otg; |
36 | 36 | ||
37 | /* | ||
38 | * ehci_run defined in drivers/usb/host/ehci-hcd.c reset the controller and | ||
39 | * the configuration settings in ehci_msm_reset vanish after controller is | ||
40 | * reset. Resetting the controler in ehci_run seems to be un-necessary | ||
41 | * provided HCD reset the controller before calling ehci_run. Most of the HCD | ||
42 | * do but some are not. So this function is same as ehci_run but we don't | ||
43 | * reset the controller here. | ||
44 | */ | ||
45 | static int ehci_msm_run(struct usb_hcd *hcd) | ||
46 | { | ||
47 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
48 | u32 temp; | ||
49 | u32 hcc_params; | ||
50 | |||
51 | hcd->uses_new_polling = 1; | ||
52 | |||
53 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); | ||
54 | ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); | ||
55 | |||
56 | /* | ||
57 | * hcc_params controls whether ehci->regs->segment must (!!!) | ||
58 | * be used; it constrains QH/ITD/SITD and QTD locations. | ||
59 | * pci_pool consistent memory always uses segment zero. | ||
60 | * streaming mappings for I/O buffers, like pci_map_single(), | ||
61 | * can return segments above 4GB, if the device allows. | ||
62 | * | ||
63 | * NOTE: the dma mask is visible through dma_supported(), so | ||
64 | * drivers can pass this info along ... like NETIF_F_HIGHDMA, | ||
65 | * Scsi_Host.highmem_io, and so forth. It's readonly to all | ||
66 | * host side drivers though. | ||
67 | */ | ||
68 | hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); | ||
69 | if (HCC_64BIT_ADDR(hcc_params)) | ||
70 | ehci_writel(ehci, 0, &ehci->regs->segment); | ||
71 | |||
72 | /* | ||
73 | * Philips, Intel, and maybe others need CMD_RUN before the | ||
74 | * root hub will detect new devices (why?); NEC doesn't | ||
75 | */ | ||
76 | ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); | ||
77 | ehci->command |= CMD_RUN; | ||
78 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | ||
79 | dbg_cmd(ehci, "init", ehci->command); | ||
80 | |||
81 | /* | ||
82 | * Start, enabling full USB 2.0 functionality ... usb 1.1 devices | ||
83 | * are explicitly handed to companion controller(s), so no TT is | ||
84 | * involved with the root hub. (Except where one is integrated, | ||
85 | * and there's no companion controller unless maybe for USB OTG.) | ||
86 | * | ||
87 | * Turning on the CF flag will transfer ownership of all ports | ||
88 | * from the companions to the EHCI controller. If any of the | ||
89 | * companions are in the middle of a port reset at the time, it | ||
90 | * could cause trouble. Write-locking ehci_cf_port_reset_rwsem | ||
91 | * guarantees that no resets are in progress. After we set CF, | ||
92 | * a short delay lets the hardware catch up; new resets shouldn't | ||
93 | * be started before the port switching actions could complete. | ||
94 | */ | ||
95 | down_write(&ehci_cf_port_reset_rwsem); | ||
96 | hcd->state = HC_STATE_RUNNING; | ||
97 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | ||
98 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ | ||
99 | usleep_range(5000, 5500); | ||
100 | up_write(&ehci_cf_port_reset_rwsem); | ||
101 | ehci->last_periodic_enable = ktime_get_real(); | ||
102 | |||
103 | temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
104 | ehci_info(ehci, | ||
105 | "USB %x.%x started, EHCI %x.%02x%s\n", | ||
106 | ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f), | ||
107 | temp >> 8, temp & 0xff, | ||
108 | ignore_oc ? ", overcurrent ignored" : ""); | ||
109 | |||
110 | ehci_writel(ehci, INTR_MASK, | ||
111 | &ehci->regs->intr_enable); /* Turn On Interrupts */ | ||
112 | |||
113 | /* GRR this is run-once init(), being done every time the HC starts. | ||
114 | * So long as they're part of class devices, we can't do it init() | ||
115 | * since the class device isn't created that early. | ||
116 | */ | ||
117 | create_debug_files(ehci); | ||
118 | create_companion_file(ehci); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | static int ehci_msm_reset(struct usb_hcd *hcd) | 37 | static int ehci_msm_reset(struct usb_hcd *hcd) |
124 | { | 38 | { |
125 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 39 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
@@ -128,6 +42,8 @@ static int ehci_msm_reset(struct usb_hcd *hcd) | |||
128 | ehci->caps = USB_CAPLENGTH; | 42 | ehci->caps = USB_CAPLENGTH; |
129 | ehci->regs = USB_CAPLENGTH + | 43 | ehci->regs = USB_CAPLENGTH + |
130 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | 44 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); |
45 | dbg_hcs_params(ehci, "reset"); | ||
46 | dbg_hcc_params(ehci, "reset"); | ||
131 | 47 | ||
132 | /* cache the data to minimize the chip reads*/ | 48 | /* cache the data to minimize the chip reads*/ |
133 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 49 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
@@ -135,6 +51,10 @@ static int ehci_msm_reset(struct usb_hcd *hcd) | |||
135 | hcd->has_tt = 1; | 51 | hcd->has_tt = 1; |
136 | ehci->sbrn = HCD_USB2; | 52 | ehci->sbrn = HCD_USB2; |
137 | 53 | ||
54 | retval = ehci_halt(ehci); | ||
55 | if (retval) | ||
56 | return retval; | ||
57 | |||
138 | /* data structure init */ | 58 | /* data structure init */ |
139 | retval = ehci_init(hcd); | 59 | retval = ehci_init(hcd); |
140 | if (retval) | 60 | if (retval) |
@@ -167,7 +87,7 @@ static struct hc_driver msm_hc_driver = { | |||
167 | .flags = HCD_USB2 | HCD_MEMORY, | 87 | .flags = HCD_USB2 | HCD_MEMORY, |
168 | 88 | ||
169 | .reset = ehci_msm_reset, | 89 | .reset = ehci_msm_reset, |
170 | .start = ehci_msm_run, | 90 | .start = ehci_run, |
171 | 91 | ||
172 | .stop = ehci_stop, | 92 | .stop = ehci_stop, |
173 | .shutdown = ehci_shutdown, | 93 | .shutdown = ehci_shutdown, |
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index f784ceb862a3..7e41a95c5ceb 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c | |||
@@ -4,9 +4,10 @@ | |||
4 | * Bus Glue for the EHCI controllers in OMAP3/4 | 4 | * Bus Glue for the EHCI controllers in OMAP3/4 |
5 | * Tested on several OMAP3 boards, and OMAP4 Pandaboard | 5 | * Tested on several OMAP3 boards, and OMAP4 Pandaboard |
6 | * | 6 | * |
7 | * Copyright (C) 2007-2010 Texas Instruments, Inc. | 7 | * Copyright (C) 2007-2011 Texas Instruments, Inc. |
8 | * Author: Vikram Pandita <vikram.pandita@ti.com> | 8 | * Author: Vikram Pandita <vikram.pandita@ti.com> |
9 | * Author: Anand Gadiyar <gadiyar@ti.com> | 9 | * Author: Anand Gadiyar <gadiyar@ti.com> |
10 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> | ||
10 | * | 11 | * |
11 | * Copyright (C) 2009 Nokia Corporation | 12 | * Copyright (C) 2009 Nokia Corporation |
12 | * Contact: Felipe Balbi <felipe.balbi@nokia.com> | 13 | * Contact: Felipe Balbi <felipe.balbi@nokia.com> |
@@ -27,116 +28,19 @@ | |||
27 | * along with this program; if not, write to the Free Software | 28 | * along with this program; if not, write to the Free Software |
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 | * | 30 | * |
30 | * TODO (last updated Nov 21, 2010): | 31 | * TODO (last updated Feb 27, 2010): |
31 | * - add kernel-doc | 32 | * - add kernel-doc |
32 | * - enable AUTOIDLE | 33 | * - enable AUTOIDLE |
33 | * - add suspend/resume | 34 | * - add suspend/resume |
34 | * - move workarounds to board-files | ||
35 | * - factor out code common to OHCI | ||
36 | * - add HSIC and TLL support | 35 | * - add HSIC and TLL support |
37 | * - convert to use hwmod and runtime PM | 36 | * - convert to use hwmod and runtime PM |
38 | */ | 37 | */ |
39 | 38 | ||
40 | #include <linux/platform_device.h> | 39 | #include <linux/platform_device.h> |
41 | #include <linux/clk.h> | ||
42 | #include <linux/gpio.h> | ||
43 | #include <linux/regulator/consumer.h> | ||
44 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
45 | #include <linux/usb/ulpi.h> | 41 | #include <linux/usb/ulpi.h> |
46 | #include <plat/usb.h> | 42 | #include <plat/usb.h> |
47 | 43 | ||
48 | /* | ||
49 | * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES | ||
50 | * Use ehci_omap_readl()/ehci_omap_writel() functions | ||
51 | */ | ||
52 | |||
53 | /* TLL Register Set */ | ||
54 | #define OMAP_USBTLL_REVISION (0x00) | ||
55 | #define OMAP_USBTLL_SYSCONFIG (0x10) | ||
56 | #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8) | ||
57 | #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3) | ||
58 | #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
59 | #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1) | ||
60 | #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0) | ||
61 | |||
62 | #define OMAP_USBTLL_SYSSTATUS (0x14) | ||
63 | #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0) | ||
64 | |||
65 | #define OMAP_USBTLL_IRQSTATUS (0x18) | ||
66 | #define OMAP_USBTLL_IRQENABLE (0x1C) | ||
67 | |||
68 | #define OMAP_TLL_SHARED_CONF (0x30) | ||
69 | #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6) | ||
70 | #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5) | ||
71 | #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2) | ||
72 | #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1) | ||
73 | #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0) | ||
74 | |||
75 | #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num) | ||
76 | #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11) | ||
77 | #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10) | ||
78 | #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9) | ||
79 | #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8) | ||
80 | #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0) | ||
81 | |||
82 | #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num) | ||
83 | #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num) | ||
84 | #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num) | ||
85 | #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num) | ||
86 | #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num) | ||
87 | #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num) | ||
88 | #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num) | ||
89 | #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num) | ||
90 | #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num) | ||
91 | |||
92 | #define OMAP_TLL_CHANNEL_COUNT 3 | ||
93 | #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0) | ||
94 | #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1) | ||
95 | #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2) | ||
96 | |||
97 | /* UHH Register Set */ | ||
98 | #define OMAP_UHH_REVISION (0x00) | ||
99 | #define OMAP_UHH_SYSCONFIG (0x10) | ||
100 | #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12) | ||
101 | #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8) | ||
102 | #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3) | ||
103 | #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
104 | #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1) | ||
105 | #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0) | ||
106 | |||
107 | #define OMAP_UHH_SYSSTATUS (0x14) | ||
108 | #define OMAP_UHH_HOSTCONFIG (0x40) | ||
109 | #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0) | ||
110 | #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0) | ||
111 | #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11) | ||
112 | #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12) | ||
113 | #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2) | ||
114 | #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3) | ||
115 | #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4) | ||
116 | #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5) | ||
117 | #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8) | ||
118 | #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9) | ||
119 | #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10) | ||
120 | |||
121 | /* OMAP4-specific defines */ | ||
122 | #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2) | ||
123 | #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2) | ||
124 | |||
125 | #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4) | ||
126 | #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4) | ||
127 | #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0) | ||
128 | |||
129 | #define OMAP4_P1_MODE_CLEAR (3 << 16) | ||
130 | #define OMAP4_P1_MODE_TLL (1 << 16) | ||
131 | #define OMAP4_P1_MODE_HSIC (3 << 16) | ||
132 | #define OMAP4_P2_MODE_CLEAR (3 << 18) | ||
133 | #define OMAP4_P2_MODE_TLL (1 << 18) | ||
134 | #define OMAP4_P2_MODE_HSIC (3 << 18) | ||
135 | |||
136 | #define OMAP_REV2_TLL_CHANNEL_COUNT 2 | ||
137 | |||
138 | #define OMAP_UHH_DEBUG_CSR (0x44) | ||
139 | |||
140 | /* EHCI Register Set */ | 44 | /* EHCI Register Set */ |
141 | #define EHCI_INSNREG04 (0xA0) | 45 | #define EHCI_INSNREG04 (0xA0) |
142 | #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5) | 46 | #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5) |
@@ -148,137 +52,24 @@ | |||
148 | #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 | 52 | #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 |
149 | #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 | 53 | #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 |
150 | 54 | ||
151 | /* Values of UHH_REVISION - Note: these are not given in the TRM */ | 55 | /*-------------------------------------------------------------------------*/ |
152 | #define OMAP_EHCI_REV1 0x00000010 /* OMAP3 */ | ||
153 | #define OMAP_EHCI_REV2 0x50700100 /* OMAP4 */ | ||
154 | |||
155 | #define is_omap_ehci_rev1(x) (x->omap_ehci_rev == OMAP_EHCI_REV1) | ||
156 | #define is_omap_ehci_rev2(x) (x->omap_ehci_rev == OMAP_EHCI_REV2) | ||
157 | 56 | ||
158 | #define is_ehci_phy_mode(x) (x == EHCI_HCD_OMAP_MODE_PHY) | 57 | static const struct hc_driver ehci_omap_hc_driver; |
159 | #define is_ehci_tll_mode(x) (x == EHCI_HCD_OMAP_MODE_TLL) | ||
160 | #define is_ehci_hsic_mode(x) (x == EHCI_HCD_OMAP_MODE_HSIC) | ||
161 | 58 | ||
162 | /*-------------------------------------------------------------------------*/ | ||
163 | 59 | ||
164 | static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val) | 60 | static inline void ehci_write(void __iomem *base, u32 reg, u32 val) |
165 | { | 61 | { |
166 | __raw_writel(val, base + reg); | 62 | __raw_writel(val, base + reg); |
167 | } | 63 | } |
168 | 64 | ||
169 | static inline u32 ehci_omap_readl(void __iomem *base, u32 reg) | 65 | static inline u32 ehci_read(void __iomem *base, u32 reg) |
170 | { | 66 | { |
171 | return __raw_readl(base + reg); | 67 | return __raw_readl(base + reg); |
172 | } | 68 | } |
173 | 69 | ||
174 | static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val) | 70 | static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port) |
175 | { | ||
176 | __raw_writeb(val, base + reg); | ||
177 | } | ||
178 | |||
179 | static inline u8 ehci_omap_readb(void __iomem *base, u8 reg) | ||
180 | { | ||
181 | return __raw_readb(base + reg); | ||
182 | } | ||
183 | |||
184 | /*-------------------------------------------------------------------------*/ | ||
185 | |||
186 | struct ehci_hcd_omap { | ||
187 | struct ehci_hcd *ehci; | ||
188 | struct device *dev; | ||
189 | |||
190 | struct clk *usbhost_ick; | ||
191 | struct clk *usbhost_hs_fck; | ||
192 | struct clk *usbhost_fs_fck; | ||
193 | struct clk *usbtll_fck; | ||
194 | struct clk *usbtll_ick; | ||
195 | struct clk *xclk60mhsp1_ck; | ||
196 | struct clk *xclk60mhsp2_ck; | ||
197 | struct clk *utmi_p1_fck; | ||
198 | struct clk *utmi_p2_fck; | ||
199 | |||
200 | /* FIXME the following two workarounds are | ||
201 | * board specific not silicon-specific so these | ||
202 | * should be moved to board-file instead. | ||
203 | * | ||
204 | * Maybe someone from TI will know better which | ||
205 | * board is affected and needs the workarounds | ||
206 | * to be applied | ||
207 | */ | ||
208 | |||
209 | /* gpio for resetting phy */ | ||
210 | int reset_gpio_port[OMAP3_HS_USB_PORTS]; | ||
211 | |||
212 | /* phy reset workaround */ | ||
213 | int phy_reset; | ||
214 | |||
215 | /* IP revision */ | ||
216 | u32 omap_ehci_rev; | ||
217 | |||
218 | /* desired phy_mode: TLL, PHY */ | ||
219 | enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS]; | ||
220 | |||
221 | void __iomem *uhh_base; | ||
222 | void __iomem *tll_base; | ||
223 | void __iomem *ehci_base; | ||
224 | |||
225 | /* Regulators for USB PHYs. | ||
226 | * Each PHY can have a separate regulator. | ||
227 | */ | ||
228 | struct regulator *regulator[OMAP3_HS_USB_PORTS]; | ||
229 | }; | ||
230 | |||
231 | /*-------------------------------------------------------------------------*/ | ||
232 | |||
233 | static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask, | ||
234 | u8 tll_channel_count) | ||
235 | { | ||
236 | unsigned reg; | ||
237 | int i; | ||
238 | |||
239 | /* Program the 3 TLL channels upfront */ | ||
240 | for (i = 0; i < tll_channel_count; i++) { | ||
241 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i)); | ||
242 | |||
243 | /* Disable AutoIdle, BitStuffing and use SDR Mode */ | ||
244 | reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE | ||
245 | | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF | ||
246 | | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE); | ||
247 | ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg); | ||
248 | } | ||
249 | |||
250 | /* Program Common TLL register */ | ||
251 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF); | ||
252 | reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON | ||
253 | | OMAP_TLL_SHARED_CONF_USB_DIVRATION | ||
254 | | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN); | ||
255 | reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN; | ||
256 | |||
257 | ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg); | ||
258 | |||
259 | /* Enable channels now */ | ||
260 | for (i = 0; i < tll_channel_count; i++) { | ||
261 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i)); | ||
262 | |||
263 | /* Enable only the reg that is needed */ | ||
264 | if (!(tll_channel_mask & 1<<i)) | ||
265 | continue; | ||
266 | |||
267 | reg |= OMAP_TLL_CHANNEL_CONF_CHANEN; | ||
268 | ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg); | ||
269 | |||
270 | ehci_omap_writeb(omap->tll_base, | ||
271 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe); | ||
272 | dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n", | ||
273 | i+1, ehci_omap_readb(omap->tll_base, | ||
274 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i))); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /*-------------------------------------------------------------------------*/ | ||
279 | |||
280 | static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port) | ||
281 | { | 71 | { |
72 | struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev); | ||
282 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | 73 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
283 | unsigned reg = 0; | 74 | unsigned reg = 0; |
284 | 75 | ||
@@ -292,266 +83,87 @@ static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port) | |||
292 | /* start ULPI access*/ | 83 | /* start ULPI access*/ |
293 | | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); | 84 | | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); |
294 | 85 | ||
295 | ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg); | 86 | ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg); |
296 | 87 | ||
297 | /* Wait for ULPI access completion */ | 88 | /* Wait for ULPI access completion */ |
298 | while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI) | 89 | while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI) |
299 | & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { | 90 | & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { |
300 | cpu_relax(); | 91 | cpu_relax(); |
301 | 92 | ||
302 | if (time_after(jiffies, timeout)) { | 93 | if (time_after(jiffies, timeout)) { |
303 | dev_dbg(omap->dev, "phy reset operation timed out\n"); | 94 | dev_dbg(&pdev->dev, "phy reset operation timed out\n"); |
304 | break; | 95 | break; |
305 | } | 96 | } |
306 | } | 97 | } |
307 | } | 98 | } |
308 | 99 | ||
309 | /* omap_start_ehc | ||
310 | * - Start the TI USBHOST controller | ||
311 | */ | ||
312 | static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd) | ||
313 | { | ||
314 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | ||
315 | u8 tll_ch_mask = 0; | ||
316 | unsigned reg = 0; | ||
317 | int ret = 0; | ||
318 | |||
319 | dev_dbg(omap->dev, "starting TI EHCI USB Controller\n"); | ||
320 | 100 | ||
321 | /* Enable Clocks for USBHOST */ | 101 | /* configure so an HC device and id are always provided */ |
322 | omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick"); | 102 | /* always called with process context; sleeping is OK */ |
323 | if (IS_ERR(omap->usbhost_ick)) { | ||
324 | ret = PTR_ERR(omap->usbhost_ick); | ||
325 | goto err_host_ick; | ||
326 | } | ||
327 | clk_enable(omap->usbhost_ick); | ||
328 | |||
329 | omap->usbhost_hs_fck = clk_get(omap->dev, "hs_fck"); | ||
330 | if (IS_ERR(omap->usbhost_hs_fck)) { | ||
331 | ret = PTR_ERR(omap->usbhost_hs_fck); | ||
332 | goto err_host_120m_fck; | ||
333 | } | ||
334 | clk_enable(omap->usbhost_hs_fck); | ||
335 | 103 | ||
336 | omap->usbhost_fs_fck = clk_get(omap->dev, "fs_fck"); | 104 | /** |
337 | if (IS_ERR(omap->usbhost_fs_fck)) { | 105 | * ehci_hcd_omap_probe - initialize TI-based HCDs |
338 | ret = PTR_ERR(omap->usbhost_fs_fck); | 106 | * |
339 | goto err_host_48m_fck; | 107 | * Allocates basic resources for this USB host controller, and |
340 | } | 108 | * then invokes the start() method for the HCD associated with it |
341 | clk_enable(omap->usbhost_fs_fck); | 109 | * through the hotplug entry's driver_data. |
342 | 110 | */ | |
343 | if (omap->phy_reset) { | 111 | static int ehci_hcd_omap_probe(struct platform_device *pdev) |
344 | /* Refer: ISSUE1 */ | 112 | { |
345 | if (gpio_is_valid(omap->reset_gpio_port[0])) { | 113 | struct device *dev = &pdev->dev; |
346 | gpio_request(omap->reset_gpio_port[0], | 114 | struct ehci_hcd_omap_platform_data *pdata = dev->platform_data; |
347 | "USB1 PHY reset"); | 115 | struct resource *res; |
348 | gpio_direction_output(omap->reset_gpio_port[0], 0); | 116 | struct usb_hcd *hcd; |
349 | } | 117 | void __iomem *regs; |
118 | struct ehci_hcd *omap_ehci; | ||
119 | int ret = -ENODEV; | ||
120 | int irq; | ||
350 | 121 | ||
351 | if (gpio_is_valid(omap->reset_gpio_port[1])) { | 122 | if (usb_disabled()) |
352 | gpio_request(omap->reset_gpio_port[1], | 123 | return -ENODEV; |
353 | "USB2 PHY reset"); | ||
354 | gpio_direction_output(omap->reset_gpio_port[1], 0); | ||
355 | } | ||
356 | 124 | ||
357 | /* Hold the PHY in RESET for enough time till DIR is high */ | 125 | if (!dev->parent) { |
358 | udelay(10); | 126 | dev_err(dev, "Missing parent device\n"); |
127 | return -ENODEV; | ||
359 | } | 128 | } |
360 | 129 | ||
361 | /* Configure TLL for 60Mhz clk for ULPI */ | 130 | irq = platform_get_irq_byname(pdev, "ehci-irq"); |
362 | omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck"); | 131 | if (irq < 0) { |
363 | if (IS_ERR(omap->usbtll_fck)) { | 132 | dev_err(dev, "EHCI irq failed\n"); |
364 | ret = PTR_ERR(omap->usbtll_fck); | 133 | return -ENODEV; |
365 | goto err_tll_fck; | ||
366 | } | 134 | } |
367 | clk_enable(omap->usbtll_fck); | ||
368 | 135 | ||
369 | omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick"); | 136 | res = platform_get_resource_byname(pdev, |
370 | if (IS_ERR(omap->usbtll_ick)) { | 137 | IORESOURCE_MEM, "ehci"); |
371 | ret = PTR_ERR(omap->usbtll_ick); | 138 | if (!res) { |
372 | goto err_tll_ick; | 139 | dev_err(dev, "UHH EHCI get resource failed\n"); |
140 | return -ENODEV; | ||
373 | } | 141 | } |
374 | clk_enable(omap->usbtll_ick); | ||
375 | |||
376 | omap->omap_ehci_rev = ehci_omap_readl(omap->uhh_base, | ||
377 | OMAP_UHH_REVISION); | ||
378 | dev_dbg(omap->dev, "OMAP UHH_REVISION 0x%x\n", | ||
379 | omap->omap_ehci_rev); | ||
380 | 142 | ||
381 | /* | 143 | regs = ioremap(res->start, resource_size(res)); |
382 | * Enable per-port clocks as needed (newer controllers only). | 144 | if (!regs) { |
383 | * - External ULPI clock for PHY mode | 145 | dev_err(dev, "UHH EHCI ioremap failed\n"); |
384 | * - Internal clocks for TLL and HSIC modes (TODO) | 146 | return -ENOMEM; |
385 | */ | ||
386 | if (is_omap_ehci_rev2(omap)) { | ||
387 | switch (omap->port_mode[0]) { | ||
388 | case EHCI_HCD_OMAP_MODE_PHY: | ||
389 | omap->xclk60mhsp1_ck = clk_get(omap->dev, | ||
390 | "xclk60mhsp1_ck"); | ||
391 | if (IS_ERR(omap->xclk60mhsp1_ck)) { | ||
392 | ret = PTR_ERR(omap->xclk60mhsp1_ck); | ||
393 | dev_err(omap->dev, | ||
394 | "Unable to get Port1 ULPI clock\n"); | ||
395 | } | ||
396 | |||
397 | omap->utmi_p1_fck = clk_get(omap->dev, | ||
398 | "utmi_p1_gfclk"); | ||
399 | if (IS_ERR(omap->utmi_p1_fck)) { | ||
400 | ret = PTR_ERR(omap->utmi_p1_fck); | ||
401 | dev_err(omap->dev, | ||
402 | "Unable to get utmi_p1_fck\n"); | ||
403 | } | ||
404 | |||
405 | ret = clk_set_parent(omap->utmi_p1_fck, | ||
406 | omap->xclk60mhsp1_ck); | ||
407 | if (ret != 0) { | ||
408 | dev_err(omap->dev, | ||
409 | "Unable to set P1 f-clock\n"); | ||
410 | } | ||
411 | break; | ||
412 | case EHCI_HCD_OMAP_MODE_TLL: | ||
413 | /* TODO */ | ||
414 | default: | ||
415 | break; | ||
416 | } | ||
417 | switch (omap->port_mode[1]) { | ||
418 | case EHCI_HCD_OMAP_MODE_PHY: | ||
419 | omap->xclk60mhsp2_ck = clk_get(omap->dev, | ||
420 | "xclk60mhsp2_ck"); | ||
421 | if (IS_ERR(omap->xclk60mhsp2_ck)) { | ||
422 | ret = PTR_ERR(omap->xclk60mhsp2_ck); | ||
423 | dev_err(omap->dev, | ||
424 | "Unable to get Port2 ULPI clock\n"); | ||
425 | } | ||
426 | |||
427 | omap->utmi_p2_fck = clk_get(omap->dev, | ||
428 | "utmi_p2_gfclk"); | ||
429 | if (IS_ERR(omap->utmi_p2_fck)) { | ||
430 | ret = PTR_ERR(omap->utmi_p2_fck); | ||
431 | dev_err(omap->dev, | ||
432 | "Unable to get utmi_p2_fck\n"); | ||
433 | } | ||
434 | |||
435 | ret = clk_set_parent(omap->utmi_p2_fck, | ||
436 | omap->xclk60mhsp2_ck); | ||
437 | if (ret != 0) { | ||
438 | dev_err(omap->dev, | ||
439 | "Unable to set P2 f-clock\n"); | ||
440 | } | ||
441 | break; | ||
442 | case EHCI_HCD_OMAP_MODE_TLL: | ||
443 | /* TODO */ | ||
444 | default: | ||
445 | break; | ||
446 | } | ||
447 | } | 147 | } |
448 | 148 | ||
449 | 149 | hcd = usb_create_hcd(&ehci_omap_hc_driver, dev, | |
450 | /* perform TLL soft reset, and wait until reset is complete */ | 150 | dev_name(dev)); |
451 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | 151 | if (!hcd) { |
452 | OMAP_USBTLL_SYSCONFIG_SOFTRESET); | 152 | dev_err(dev, "failed to create hcd with err %d\n", ret); |
453 | 153 | ret = -ENOMEM; | |
454 | /* Wait for TLL reset to complete */ | 154 | goto err_io; |
455 | while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
456 | & OMAP_USBTLL_SYSSTATUS_RESETDONE)) { | ||
457 | cpu_relax(); | ||
458 | |||
459 | if (time_after(jiffies, timeout)) { | ||
460 | dev_dbg(omap->dev, "operation timed out\n"); | ||
461 | ret = -EINVAL; | ||
462 | goto err_sys_status; | ||
463 | } | ||
464 | } | 155 | } |
465 | 156 | ||
466 | dev_dbg(omap->dev, "TLL RESET DONE\n"); | 157 | hcd->rsrc_start = res->start; |
467 | 158 | hcd->rsrc_len = resource_size(res); | |
468 | /* (1<<3) = no idle mode only for initial debugging */ | 159 | hcd->regs = regs; |
469 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | ||
470 | OMAP_USBTLL_SYSCONFIG_ENAWAKEUP | | ||
471 | OMAP_USBTLL_SYSCONFIG_SIDLEMODE | | ||
472 | OMAP_USBTLL_SYSCONFIG_CACTIVITY); | ||
473 | |||
474 | |||
475 | /* Put UHH in NoIdle/NoStandby mode */ | ||
476 | reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG); | ||
477 | if (is_omap_ehci_rev1(omap)) { | ||
478 | reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP | ||
479 | | OMAP_UHH_SYSCONFIG_SIDLEMODE | ||
480 | | OMAP_UHH_SYSCONFIG_CACTIVITY | ||
481 | | OMAP_UHH_SYSCONFIG_MIDLEMODE); | ||
482 | reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE; | ||
483 | |||
484 | 160 | ||
485 | } else if (is_omap_ehci_rev2(omap)) { | 161 | ret = omap_usbhs_enable(dev); |
486 | reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR; | 162 | if (ret) { |
487 | reg |= OMAP4_UHH_SYSCONFIG_NOIDLE; | 163 | dev_err(dev, "failed to start usbhs with err %d\n", ret); |
488 | reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR; | 164 | goto err_enable; |
489 | reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY; | ||
490 | } | ||
491 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg); | ||
492 | |||
493 | reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG); | ||
494 | |||
495 | /* setup ULPI bypass and burst configurations */ | ||
496 | reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN | ||
497 | | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN | ||
498 | | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN); | ||
499 | reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN; | ||
500 | |||
501 | if (is_omap_ehci_rev1(omap)) { | ||
502 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN) | ||
503 | reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS; | ||
504 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN) | ||
505 | reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS; | ||
506 | if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN) | ||
507 | reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; | ||
508 | |||
509 | /* Bypass the TLL module for PHY mode operation */ | ||
510 | if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) { | ||
511 | dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n"); | ||
512 | if (is_ehci_phy_mode(omap->port_mode[0]) || | ||
513 | is_ehci_phy_mode(omap->port_mode[1]) || | ||
514 | is_ehci_phy_mode(omap->port_mode[2])) | ||
515 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; | ||
516 | else | ||
517 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; | ||
518 | } else { | ||
519 | dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n"); | ||
520 | if (is_ehci_phy_mode(omap->port_mode[0])) | ||
521 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
522 | else if (is_ehci_tll_mode(omap->port_mode[0])) | ||
523 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
524 | |||
525 | if (is_ehci_phy_mode(omap->port_mode[1])) | ||
526 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
527 | else if (is_ehci_tll_mode(omap->port_mode[1])) | ||
528 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
529 | |||
530 | if (is_ehci_phy_mode(omap->port_mode[2])) | ||
531 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
532 | else if (is_ehci_tll_mode(omap->port_mode[2])) | ||
533 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
534 | } | ||
535 | } else if (is_omap_ehci_rev2(omap)) { | ||
536 | /* Clear port mode fields for PHY mode*/ | ||
537 | reg &= ~OMAP4_P1_MODE_CLEAR; | ||
538 | reg &= ~OMAP4_P2_MODE_CLEAR; | ||
539 | |||
540 | if (is_ehci_tll_mode(omap->port_mode[0])) | ||
541 | reg |= OMAP4_P1_MODE_TLL; | ||
542 | else if (is_ehci_hsic_mode(omap->port_mode[0])) | ||
543 | reg |= OMAP4_P1_MODE_HSIC; | ||
544 | |||
545 | if (is_ehci_tll_mode(omap->port_mode[1])) | ||
546 | reg |= OMAP4_P2_MODE_TLL; | ||
547 | else if (is_ehci_hsic_mode(omap->port_mode[1])) | ||
548 | reg |= OMAP4_P2_MODE_HSIC; | ||
549 | } | 165 | } |
550 | 166 | ||
551 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg); | ||
552 | dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg); | ||
553 | |||
554 | |||
555 | /* | 167 | /* |
556 | * An undocumented "feature" in the OMAP3 EHCI controller, | 168 | * An undocumented "feature" in the OMAP3 EHCI controller, |
557 | * causes suspended ports to be taken out of suspend when | 169 | * causes suspended ports to be taken out of suspend when |
@@ -561,363 +173,50 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd) | |||
561 | * to suspend. Writing 1 to this undocumented register bit | 173 | * to suspend. Writing 1 to this undocumented register bit |
562 | * disables this feature and restores normal behavior. | 174 | * disables this feature and restores normal behavior. |
563 | */ | 175 | */ |
564 | ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04, | 176 | ehci_write(regs, EHCI_INSNREG04, |
565 | EHCI_INSNREG04_DISABLE_UNSUSPEND); | 177 | EHCI_INSNREG04_DISABLE_UNSUSPEND); |
566 | 178 | ||
567 | if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) || | ||
568 | (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) || | ||
569 | (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) { | ||
570 | |||
571 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) | ||
572 | tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK; | ||
573 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) | ||
574 | tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK; | ||
575 | if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL) | ||
576 | tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK; | ||
577 | |||
578 | /* Enable UTMI mode for required TLL channels */ | ||
579 | omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT); | ||
580 | } | ||
581 | |||
582 | if (omap->phy_reset) { | ||
583 | /* Refer ISSUE1: | ||
584 | * Hold the PHY in RESET for enough time till | ||
585 | * PHY is settled and ready | ||
586 | */ | ||
587 | udelay(10); | ||
588 | |||
589 | if (gpio_is_valid(omap->reset_gpio_port[0])) | ||
590 | gpio_set_value(omap->reset_gpio_port[0], 1); | ||
591 | |||
592 | if (gpio_is_valid(omap->reset_gpio_port[1])) | ||
593 | gpio_set_value(omap->reset_gpio_port[1], 1); | ||
594 | } | ||
595 | |||
596 | /* Soft reset the PHY using PHY reset command over ULPI */ | 179 | /* Soft reset the PHY using PHY reset command over ULPI */ |
597 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) | 180 | if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY) |
598 | omap_ehci_soft_phy_reset(omap, 0); | 181 | omap_ehci_soft_phy_reset(pdev, 0); |
599 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) | 182 | if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY) |
600 | omap_ehci_soft_phy_reset(omap, 1); | 183 | omap_ehci_soft_phy_reset(pdev, 1); |
601 | |||
602 | return 0; | ||
603 | |||
604 | err_sys_status: | ||
605 | clk_disable(omap->utmi_p2_fck); | ||
606 | clk_put(omap->utmi_p2_fck); | ||
607 | clk_disable(omap->xclk60mhsp2_ck); | ||
608 | clk_put(omap->xclk60mhsp2_ck); | ||
609 | clk_disable(omap->utmi_p1_fck); | ||
610 | clk_put(omap->utmi_p1_fck); | ||
611 | clk_disable(omap->xclk60mhsp1_ck); | ||
612 | clk_put(omap->xclk60mhsp1_ck); | ||
613 | clk_disable(omap->usbtll_ick); | ||
614 | clk_put(omap->usbtll_ick); | ||
615 | |||
616 | err_tll_ick: | ||
617 | clk_disable(omap->usbtll_fck); | ||
618 | clk_put(omap->usbtll_fck); | ||
619 | |||
620 | err_tll_fck: | ||
621 | clk_disable(omap->usbhost_fs_fck); | ||
622 | clk_put(omap->usbhost_fs_fck); | ||
623 | |||
624 | if (omap->phy_reset) { | ||
625 | if (gpio_is_valid(omap->reset_gpio_port[0])) | ||
626 | gpio_free(omap->reset_gpio_port[0]); | ||
627 | |||
628 | if (gpio_is_valid(omap->reset_gpio_port[1])) | ||
629 | gpio_free(omap->reset_gpio_port[1]); | ||
630 | } | ||
631 | |||
632 | err_host_48m_fck: | ||
633 | clk_disable(omap->usbhost_hs_fck); | ||
634 | clk_put(omap->usbhost_hs_fck); | ||
635 | 184 | ||
636 | err_host_120m_fck: | 185 | omap_ehci = hcd_to_ehci(hcd); |
637 | clk_disable(omap->usbhost_ick); | 186 | omap_ehci->sbrn = 0x20; |
638 | clk_put(omap->usbhost_ick); | ||
639 | |||
640 | err_host_ick: | ||
641 | return ret; | ||
642 | } | ||
643 | |||
644 | static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd) | ||
645 | { | ||
646 | unsigned long timeout = jiffies + msecs_to_jiffies(100); | ||
647 | |||
648 | dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n"); | ||
649 | |||
650 | /* Reset OMAP modules for insmod/rmmod to work */ | ||
651 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, | ||
652 | is_omap_ehci_rev2(omap) ? | ||
653 | OMAP4_UHH_SYSCONFIG_SOFTRESET : | ||
654 | OMAP_UHH_SYSCONFIG_SOFTRESET); | ||
655 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
656 | & (1 << 0))) { | ||
657 | cpu_relax(); | ||
658 | |||
659 | if (time_after(jiffies, timeout)) | ||
660 | dev_dbg(omap->dev, "operation timed out\n"); | ||
661 | } | ||
662 | |||
663 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
664 | & (1 << 1))) { | ||
665 | cpu_relax(); | ||
666 | |||
667 | if (time_after(jiffies, timeout)) | ||
668 | dev_dbg(omap->dev, "operation timed out\n"); | ||
669 | } | ||
670 | |||
671 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
672 | & (1 << 2))) { | ||
673 | cpu_relax(); | ||
674 | |||
675 | if (time_after(jiffies, timeout)) | ||
676 | dev_dbg(omap->dev, "operation timed out\n"); | ||
677 | } | ||
678 | |||
679 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1)); | ||
680 | |||
681 | while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
682 | & (1 << 0))) { | ||
683 | cpu_relax(); | ||
684 | |||
685 | if (time_after(jiffies, timeout)) | ||
686 | dev_dbg(omap->dev, "operation timed out\n"); | ||
687 | } | ||
688 | |||
689 | if (omap->usbtll_fck != NULL) { | ||
690 | clk_disable(omap->usbtll_fck); | ||
691 | clk_put(omap->usbtll_fck); | ||
692 | omap->usbtll_fck = NULL; | ||
693 | } | ||
694 | |||
695 | if (omap->usbhost_ick != NULL) { | ||
696 | clk_disable(omap->usbhost_ick); | ||
697 | clk_put(omap->usbhost_ick); | ||
698 | omap->usbhost_ick = NULL; | ||
699 | } | ||
700 | |||
701 | if (omap->usbhost_fs_fck != NULL) { | ||
702 | clk_disable(omap->usbhost_fs_fck); | ||
703 | clk_put(omap->usbhost_fs_fck); | ||
704 | omap->usbhost_fs_fck = NULL; | ||
705 | } | ||
706 | |||
707 | if (omap->usbhost_hs_fck != NULL) { | ||
708 | clk_disable(omap->usbhost_hs_fck); | ||
709 | clk_put(omap->usbhost_hs_fck); | ||
710 | omap->usbhost_hs_fck = NULL; | ||
711 | } | ||
712 | |||
713 | if (omap->usbtll_ick != NULL) { | ||
714 | clk_disable(omap->usbtll_ick); | ||
715 | clk_put(omap->usbtll_ick); | ||
716 | omap->usbtll_ick = NULL; | ||
717 | } | ||
718 | |||
719 | if (is_omap_ehci_rev2(omap)) { | ||
720 | if (omap->xclk60mhsp1_ck != NULL) { | ||
721 | clk_disable(omap->xclk60mhsp1_ck); | ||
722 | clk_put(omap->xclk60mhsp1_ck); | ||
723 | omap->xclk60mhsp1_ck = NULL; | ||
724 | } | ||
725 | |||
726 | if (omap->utmi_p1_fck != NULL) { | ||
727 | clk_disable(omap->utmi_p1_fck); | ||
728 | clk_put(omap->utmi_p1_fck); | ||
729 | omap->utmi_p1_fck = NULL; | ||
730 | } | ||
731 | |||
732 | if (omap->xclk60mhsp2_ck != NULL) { | ||
733 | clk_disable(omap->xclk60mhsp2_ck); | ||
734 | clk_put(omap->xclk60mhsp2_ck); | ||
735 | omap->xclk60mhsp2_ck = NULL; | ||
736 | } | ||
737 | |||
738 | if (omap->utmi_p2_fck != NULL) { | ||
739 | clk_disable(omap->utmi_p2_fck); | ||
740 | clk_put(omap->utmi_p2_fck); | ||
741 | omap->utmi_p2_fck = NULL; | ||
742 | } | ||
743 | } | ||
744 | |||
745 | if (omap->phy_reset) { | ||
746 | if (gpio_is_valid(omap->reset_gpio_port[0])) | ||
747 | gpio_free(omap->reset_gpio_port[0]); | ||
748 | |||
749 | if (gpio_is_valid(omap->reset_gpio_port[1])) | ||
750 | gpio_free(omap->reset_gpio_port[1]); | ||
751 | } | ||
752 | |||
753 | dev_dbg(omap->dev, "Clock to USB host has been disabled\n"); | ||
754 | } | ||
755 | |||
756 | /*-------------------------------------------------------------------------*/ | ||
757 | |||
758 | static const struct hc_driver ehci_omap_hc_driver; | ||
759 | |||
760 | /* configure so an HC device and id are always provided */ | ||
761 | /* always called with process context; sleeping is OK */ | ||
762 | |||
763 | /** | ||
764 | * ehci_hcd_omap_probe - initialize TI-based HCDs | ||
765 | * | ||
766 | * Allocates basic resources for this USB host controller, and | ||
767 | * then invokes the start() method for the HCD associated with it | ||
768 | * through the hotplug entry's driver_data. | ||
769 | */ | ||
770 | static int ehci_hcd_omap_probe(struct platform_device *pdev) | ||
771 | { | ||
772 | struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; | ||
773 | struct ehci_hcd_omap *omap; | ||
774 | struct resource *res; | ||
775 | struct usb_hcd *hcd; | ||
776 | |||
777 | int irq = platform_get_irq(pdev, 0); | ||
778 | int ret = -ENODEV; | ||
779 | int i; | ||
780 | char supply[7]; | ||
781 | |||
782 | if (!pdata) { | ||
783 | dev_dbg(&pdev->dev, "missing platform_data\n"); | ||
784 | goto err_pdata; | ||
785 | } | ||
786 | |||
787 | if (usb_disabled()) | ||
788 | goto err_disabled; | ||
789 | |||
790 | omap = kzalloc(sizeof(*omap), GFP_KERNEL); | ||
791 | if (!omap) { | ||
792 | ret = -ENOMEM; | ||
793 | goto err_disabled; | ||
794 | } | ||
795 | |||
796 | hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev, | ||
797 | dev_name(&pdev->dev)); | ||
798 | if (!hcd) { | ||
799 | dev_err(&pdev->dev, "failed to create hcd with err %d\n", ret); | ||
800 | ret = -ENOMEM; | ||
801 | goto err_create_hcd; | ||
802 | } | ||
803 | |||
804 | platform_set_drvdata(pdev, omap); | ||
805 | omap->dev = &pdev->dev; | ||
806 | omap->phy_reset = pdata->phy_reset; | ||
807 | omap->reset_gpio_port[0] = pdata->reset_gpio_port[0]; | ||
808 | omap->reset_gpio_port[1] = pdata->reset_gpio_port[1]; | ||
809 | omap->reset_gpio_port[2] = pdata->reset_gpio_port[2]; | ||
810 | omap->port_mode[0] = pdata->port_mode[0]; | ||
811 | omap->port_mode[1] = pdata->port_mode[1]; | ||
812 | omap->port_mode[2] = pdata->port_mode[2]; | ||
813 | omap->ehci = hcd_to_ehci(hcd); | ||
814 | omap->ehci->sbrn = 0x20; | ||
815 | |||
816 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
817 | |||
818 | hcd->rsrc_start = res->start; | ||
819 | hcd->rsrc_len = resource_size(res); | ||
820 | |||
821 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | ||
822 | if (!hcd->regs) { | ||
823 | dev_err(&pdev->dev, "EHCI ioremap failed\n"); | ||
824 | ret = -ENOMEM; | ||
825 | goto err_ioremap; | ||
826 | } | ||
827 | 187 | ||
828 | /* we know this is the memory we want, no need to ioremap again */ | 188 | /* we know this is the memory we want, no need to ioremap again */ |
829 | omap->ehci->caps = hcd->regs; | 189 | omap_ehci->caps = hcd->regs; |
830 | omap->ehci_base = hcd->regs; | 190 | omap_ehci->regs = hcd->regs |
831 | 191 | + HC_LENGTH(readl(&omap_ehci->caps->hc_capbase)); | |
832 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
833 | omap->uhh_base = ioremap(res->start, resource_size(res)); | ||
834 | if (!omap->uhh_base) { | ||
835 | dev_err(&pdev->dev, "UHH ioremap failed\n"); | ||
836 | ret = -ENOMEM; | ||
837 | goto err_uhh_ioremap; | ||
838 | } | ||
839 | |||
840 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
841 | omap->tll_base = ioremap(res->start, resource_size(res)); | ||
842 | if (!omap->tll_base) { | ||
843 | dev_err(&pdev->dev, "TLL ioremap failed\n"); | ||
844 | ret = -ENOMEM; | ||
845 | goto err_tll_ioremap; | ||
846 | } | ||
847 | |||
848 | /* get ehci regulator and enable */ | ||
849 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { | ||
850 | if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) { | ||
851 | omap->regulator[i] = NULL; | ||
852 | continue; | ||
853 | } | ||
854 | snprintf(supply, sizeof(supply), "hsusb%d", i); | ||
855 | omap->regulator[i] = regulator_get(omap->dev, supply); | ||
856 | if (IS_ERR(omap->regulator[i])) { | ||
857 | omap->regulator[i] = NULL; | ||
858 | dev_dbg(&pdev->dev, | ||
859 | "failed to get ehci port%d regulator\n", i); | ||
860 | } else { | ||
861 | regulator_enable(omap->regulator[i]); | ||
862 | } | ||
863 | } | ||
864 | |||
865 | ret = omap_start_ehc(omap, hcd); | ||
866 | if (ret) { | ||
867 | dev_err(&pdev->dev, "failed to start ehci with err %d\n", ret); | ||
868 | goto err_start; | ||
869 | } | ||
870 | 192 | ||
871 | omap->ehci->regs = hcd->regs | 193 | dbg_hcs_params(omap_ehci, "reset"); |
872 | + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase)); | 194 | dbg_hcc_params(omap_ehci, "reset"); |
873 | |||
874 | dbg_hcs_params(omap->ehci, "reset"); | ||
875 | dbg_hcc_params(omap->ehci, "reset"); | ||
876 | 195 | ||
877 | /* cache this readonly data; minimize chip reads */ | 196 | /* cache this readonly data; minimize chip reads */ |
878 | omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params); | 197 | omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params); |
879 | 198 | ||
880 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 199 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); |
881 | if (ret) { | 200 | if (ret) { |
882 | dev_err(&pdev->dev, "failed to add hcd with err %d\n", ret); | 201 | dev_err(dev, "failed to add hcd with err %d\n", ret); |
883 | goto err_add_hcd; | 202 | goto err_add_hcd; |
884 | } | 203 | } |
885 | 204 | ||
886 | /* root ports should always stay powered */ | 205 | /* root ports should always stay powered */ |
887 | ehci_port_power(omap->ehci, 1); | 206 | ehci_port_power(omap_ehci, 1); |
888 | 207 | ||
889 | return 0; | 208 | return 0; |
890 | 209 | ||
891 | err_add_hcd: | 210 | err_add_hcd: |
892 | omap_stop_ehc(omap, hcd); | 211 | omap_usbhs_disable(dev); |
893 | 212 | ||
894 | err_start: | 213 | err_enable: |
895 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { | ||
896 | if (omap->regulator[i]) { | ||
897 | regulator_disable(omap->regulator[i]); | ||
898 | regulator_put(omap->regulator[i]); | ||
899 | } | ||
900 | } | ||
901 | iounmap(omap->tll_base); | ||
902 | |||
903 | err_tll_ioremap: | ||
904 | iounmap(omap->uhh_base); | ||
905 | |||
906 | err_uhh_ioremap: | ||
907 | iounmap(hcd->regs); | ||
908 | |||
909 | err_ioremap: | ||
910 | usb_put_hcd(hcd); | 214 | usb_put_hcd(hcd); |
911 | 215 | ||
912 | err_create_hcd: | 216 | err_io: |
913 | kfree(omap); | ||
914 | err_disabled: | ||
915 | err_pdata: | ||
916 | return ret; | 217 | return ret; |
917 | } | 218 | } |
918 | 219 | ||
919 | /* may be called without controller electrically present */ | ||
920 | /* may be called with controller, bus, and devices active */ | ||
921 | 220 | ||
922 | /** | 221 | /** |
923 | * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs | 222 | * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs |
@@ -929,31 +228,18 @@ err_pdata: | |||
929 | */ | 228 | */ |
930 | static int ehci_hcd_omap_remove(struct platform_device *pdev) | 229 | static int ehci_hcd_omap_remove(struct platform_device *pdev) |
931 | { | 230 | { |
932 | struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); | 231 | struct device *dev = &pdev->dev; |
933 | struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); | 232 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
934 | int i; | ||
935 | 233 | ||
936 | usb_remove_hcd(hcd); | 234 | usb_remove_hcd(hcd); |
937 | omap_stop_ehc(omap, hcd); | 235 | omap_usbhs_disable(dev); |
938 | iounmap(hcd->regs); | ||
939 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { | ||
940 | if (omap->regulator[i]) { | ||
941 | regulator_disable(omap->regulator[i]); | ||
942 | regulator_put(omap->regulator[i]); | ||
943 | } | ||
944 | } | ||
945 | iounmap(omap->tll_base); | ||
946 | iounmap(omap->uhh_base); | ||
947 | usb_put_hcd(hcd); | 236 | usb_put_hcd(hcd); |
948 | kfree(omap); | ||
949 | |||
950 | return 0; | 237 | return 0; |
951 | } | 238 | } |
952 | 239 | ||
953 | static void ehci_hcd_omap_shutdown(struct platform_device *pdev) | 240 | static void ehci_hcd_omap_shutdown(struct platform_device *pdev) |
954 | { | 241 | { |
955 | struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); | 242 | struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev); |
956 | struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); | ||
957 | 243 | ||
958 | if (hcd->driver->shutdown) | 244 | if (hcd->driver->shutdown) |
959 | hcd->driver->shutdown(hcd); | 245 | hcd->driver->shutdown(hcd); |
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c index 0f87dc72820a..281e094e1c18 100644 --- a/drivers/usb/host/ehci-orion.c +++ b/drivers/usb/host/ehci-orion.c | |||
@@ -105,7 +105,8 @@ static int ehci_orion_setup(struct usb_hcd *hcd) | |||
105 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 105 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
106 | int retval; | 106 | int retval; |
107 | 107 | ||
108 | ehci_reset(ehci); | 108 | hcd->has_tt = 1; |
109 | |||
109 | retval = ehci_halt(ehci); | 110 | retval = ehci_halt(ehci); |
110 | if (retval) | 111 | if (retval) |
111 | return retval; | 112 | return retval; |
@@ -117,7 +118,7 @@ static int ehci_orion_setup(struct usb_hcd *hcd) | |||
117 | if (retval) | 118 | if (retval) |
118 | return retval; | 119 | return retval; |
119 | 120 | ||
120 | hcd->has_tt = 1; | 121 | ehci_reset(ehci); |
121 | 122 | ||
122 | ehci_port_power(ehci, 0); | 123 | ehci_port_power(ehci, 0); |
123 | 124 | ||
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 07bb982e59f6..d5eaea7caf89 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -44,42 +44,6 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) | |||
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | static int ehci_quirk_amd_hudson(struct ehci_hcd *ehci) | ||
48 | { | ||
49 | struct pci_dev *amd_smbus_dev; | ||
50 | u8 rev = 0; | ||
51 | |||
52 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); | ||
53 | if (amd_smbus_dev) { | ||
54 | pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); | ||
55 | if (rev < 0x40) { | ||
56 | pci_dev_put(amd_smbus_dev); | ||
57 | amd_smbus_dev = NULL; | ||
58 | return 0; | ||
59 | } | ||
60 | } else { | ||
61 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x780b, NULL); | ||
62 | if (!amd_smbus_dev) | ||
63 | return 0; | ||
64 | pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); | ||
65 | if (rev < 0x11 || rev > 0x18) { | ||
66 | pci_dev_put(amd_smbus_dev); | ||
67 | amd_smbus_dev = NULL; | ||
68 | return 0; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | if (!amd_nb_dev) | ||
73 | amd_nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL); | ||
74 | |||
75 | ehci_info(ehci, "QUIRK: Enable exception for AMD Hudson ASPM\n"); | ||
76 | |||
77 | pci_dev_put(amd_smbus_dev); | ||
78 | amd_smbus_dev = NULL; | ||
79 | |||
80 | return 1; | ||
81 | } | ||
82 | |||
83 | /* called during probe() after chip reset completes */ | 47 | /* called during probe() after chip reset completes */ |
84 | static int ehci_pci_setup(struct usb_hcd *hcd) | 48 | static int ehci_pci_setup(struct usb_hcd *hcd) |
85 | { | 49 | { |
@@ -138,9 +102,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
138 | /* cache this readonly data; minimize chip reads */ | 102 | /* cache this readonly data; minimize chip reads */ |
139 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 103 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
140 | 104 | ||
141 | if (ehci_quirk_amd_hudson(ehci)) | ||
142 | ehci->amd_l1_fix = 1; | ||
143 | |||
144 | retval = ehci_halt(ehci); | 105 | retval = ehci_halt(ehci); |
145 | if (retval) | 106 | if (retval) |
146 | return retval; | 107 | return retval; |
@@ -191,6 +152,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
191 | } | 152 | } |
192 | break; | 153 | break; |
193 | case PCI_VENDOR_ID_AMD: | 154 | case PCI_VENDOR_ID_AMD: |
155 | /* AMD PLL quirk */ | ||
156 | if (usb_amd_find_chipset_info()) | ||
157 | ehci->amd_pll_fix = 1; | ||
194 | /* AMD8111 EHCI doesn't work, according to AMD errata */ | 158 | /* AMD8111 EHCI doesn't work, according to AMD errata */ |
195 | if (pdev->device == 0x7463) { | 159 | if (pdev->device == 0x7463) { |
196 | ehci_info(ehci, "ignoring AMD8111 (errata)\n"); | 160 | ehci_info(ehci, "ignoring AMD8111 (errata)\n"); |
@@ -236,6 +200,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
236 | } | 200 | } |
237 | break; | 201 | break; |
238 | case PCI_VENDOR_ID_ATI: | 202 | case PCI_VENDOR_ID_ATI: |
203 | /* AMD PLL quirk */ | ||
204 | if (usb_amd_find_chipset_info()) | ||
205 | ehci->amd_pll_fix = 1; | ||
239 | /* SB600 and old version of SB700 have a bug in EHCI controller, | 206 | /* SB600 and old version of SB700 have a bug in EHCI controller, |
240 | * which causes usb devices lose response in some cases. | 207 | * which causes usb devices lose response in some cases. |
241 | */ | 208 | */ |
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c new file mode 100644 index 000000000000..a2168642175b --- /dev/null +++ b/drivers/usb/host/ehci-pmcmsp.c | |||
@@ -0,0 +1,383 @@ | |||
1 | /* | ||
2 | * PMC MSP EHCI (Host Controller Driver) for USB. | ||
3 | * | ||
4 | * (C) Copyright 2006-2010 PMC-Sierra Inc | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file "COPYING" in the main directory of this archive | ||
8 | * for more details. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* includes */ | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/gpio.h> | ||
15 | #include <linux/usb.h> | ||
16 | #include <msp_usb.h> | ||
17 | |||
18 | /* stream disable*/ | ||
19 | #define USB_CTRL_MODE_STREAM_DISABLE 0x10 | ||
20 | |||
21 | /* threshold */ | ||
22 | #define USB_CTRL_FIFO_THRESH 0x00300000 | ||
23 | |||
24 | /* register offset for usb_mode */ | ||
25 | #define USB_EHCI_REG_USB_MODE 0x68 | ||
26 | |||
27 | /* register offset for usb fifo */ | ||
28 | #define USB_EHCI_REG_USB_FIFO 0x24 | ||
29 | |||
30 | /* register offset for usb status */ | ||
31 | #define USB_EHCI_REG_USB_STATUS 0x44 | ||
32 | |||
33 | /* serial/parallel transceiver */ | ||
34 | #define USB_EHCI_REG_BIT_STAT_STS (1<<29) | ||
35 | |||
36 | /* TWI USB0 host device pin */ | ||
37 | #define MSP_PIN_USB0_HOST_DEV 49 | ||
38 | |||
39 | /* TWI USB1 host device pin */ | ||
40 | #define MSP_PIN_USB1_HOST_DEV 50 | ||
41 | |||
42 | |||
43 | static void usb_hcd_tdi_set_mode(struct ehci_hcd *ehci) | ||
44 | { | ||
45 | u8 *base; | ||
46 | u8 *statreg; | ||
47 | u8 *fiforeg; | ||
48 | u32 val; | ||
49 | struct ehci_regs *reg_base = ehci->regs; | ||
50 | |||
51 | /* get register base */ | ||
52 | base = (u8 *)reg_base + USB_EHCI_REG_USB_MODE; | ||
53 | statreg = (u8 *)reg_base + USB_EHCI_REG_USB_STATUS; | ||
54 | fiforeg = (u8 *)reg_base + USB_EHCI_REG_USB_FIFO; | ||
55 | |||
56 | /* Disable controller mode stream */ | ||
57 | val = ehci_readl(ehci, (u32 *)base); | ||
58 | ehci_writel(ehci, (val | USB_CTRL_MODE_STREAM_DISABLE), | ||
59 | (u32 *)base); | ||
60 | |||
61 | /* clear STS to select parallel transceiver interface */ | ||
62 | val = ehci_readl(ehci, (u32 *)statreg); | ||
63 | val = val & ~USB_EHCI_REG_BIT_STAT_STS; | ||
64 | ehci_writel(ehci, val, (u32 *)statreg); | ||
65 | |||
66 | /* write to set the proper fifo threshold */ | ||
67 | ehci_writel(ehci, USB_CTRL_FIFO_THRESH, (u32 *)fiforeg); | ||
68 | |||
69 | /* set TWI GPIO USB_HOST_DEV pin high */ | ||
70 | gpio_direction_output(MSP_PIN_USB0_HOST_DEV, 1); | ||
71 | #ifdef CONFIG_MSP_HAS_DUAL_USB | ||
72 | gpio_direction_output(MSP_PIN_USB1_HOST_DEV, 1); | ||
73 | #endif | ||
74 | } | ||
75 | |||
76 | /* called during probe() after chip reset completes */ | ||
77 | static int ehci_msp_setup(struct usb_hcd *hcd) | ||
78 | { | ||
79 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
80 | int retval; | ||
81 | ehci->big_endian_mmio = 1; | ||
82 | ehci->big_endian_desc = 1; | ||
83 | |||
84 | ehci->caps = hcd->regs; | ||
85 | ehci->regs = hcd->regs + | ||
86 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
87 | dbg_hcs_params(ehci, "reset"); | ||
88 | dbg_hcc_params(ehci, "reset"); | ||
89 | |||
90 | /* cache this readonly data; minimize chip reads */ | ||
91 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
92 | hcd->has_tt = 1; | ||
93 | |||
94 | retval = ehci_halt(ehci); | ||
95 | if (retval) | ||
96 | return retval; | ||
97 | |||
98 | ehci_reset(ehci); | ||
99 | |||
100 | /* data structure init */ | ||
101 | retval = ehci_init(hcd); | ||
102 | if (retval) | ||
103 | return retval; | ||
104 | |||
105 | usb_hcd_tdi_set_mode(ehci); | ||
106 | ehci_port_power(ehci, 0); | ||
107 | |||
108 | return retval; | ||
109 | } | ||
110 | |||
111 | |||
112 | /* configure so an HC device and id are always provided | ||
113 | * always called with process context; sleeping is OK | ||
114 | */ | ||
115 | |||
116 | static int usb_hcd_msp_map_regs(struct mspusb_device *dev) | ||
117 | { | ||
118 | struct resource *res; | ||
119 | struct platform_device *pdev = &dev->dev; | ||
120 | u32 res_len; | ||
121 | int retval; | ||
122 | |||
123 | /* MAB register space */ | ||
124 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
125 | if (res == NULL) | ||
126 | return -ENOMEM; | ||
127 | res_len = res->end - res->start + 1; | ||
128 | if (!request_mem_region(res->start, res_len, "mab regs")) | ||
129 | return -EBUSY; | ||
130 | |||
131 | dev->mab_regs = ioremap_nocache(res->start, res_len); | ||
132 | if (dev->mab_regs == NULL) { | ||
133 | retval = -ENOMEM; | ||
134 | goto err1; | ||
135 | } | ||
136 | |||
137 | /* MSP USB register space */ | ||
138 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
139 | if (res == NULL) { | ||
140 | retval = -ENOMEM; | ||
141 | goto err2; | ||
142 | } | ||
143 | res_len = res->end - res->start + 1; | ||
144 | if (!request_mem_region(res->start, res_len, "usbid regs")) { | ||
145 | retval = -EBUSY; | ||
146 | goto err2; | ||
147 | } | ||
148 | dev->usbid_regs = ioremap_nocache(res->start, res_len); | ||
149 | if (dev->usbid_regs == NULL) { | ||
150 | retval = -ENOMEM; | ||
151 | goto err3; | ||
152 | } | ||
153 | |||
154 | return 0; | ||
155 | err3: | ||
156 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
157 | res_len = res->end - res->start + 1; | ||
158 | release_mem_region(res->start, res_len); | ||
159 | err2: | ||
160 | iounmap(dev->mab_regs); | ||
161 | err1: | ||
162 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
163 | res_len = res->end - res->start + 1; | ||
164 | release_mem_region(res->start, res_len); | ||
165 | dev_err(&pdev->dev, "Failed to map non-EHCI regs.\n"); | ||
166 | return retval; | ||
167 | } | ||
168 | |||
169 | /** | ||
170 | * usb_hcd_msp_probe - initialize PMC MSP-based HCDs | ||
171 | * Context: !in_interrupt() | ||
172 | * | ||
173 | * Allocates basic resources for this USB host controller, and | ||
174 | * then invokes the start() method for the HCD associated with it | ||
175 | * through the hotplug entry's driver_data. | ||
176 | * | ||
177 | */ | ||
178 | int usb_hcd_msp_probe(const struct hc_driver *driver, | ||
179 | struct platform_device *dev) | ||
180 | { | ||
181 | int retval; | ||
182 | struct usb_hcd *hcd; | ||
183 | struct resource *res; | ||
184 | struct ehci_hcd *ehci ; | ||
185 | |||
186 | hcd = usb_create_hcd(driver, &dev->dev, "pmcmsp"); | ||
187 | if (!hcd) | ||
188 | return -ENOMEM; | ||
189 | |||
190 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
191 | if (res == NULL) { | ||
192 | pr_debug("No IOMEM resource info for %s.\n", dev->name); | ||
193 | retval = -ENOMEM; | ||
194 | goto err1; | ||
195 | } | ||
196 | hcd->rsrc_start = res->start; | ||
197 | hcd->rsrc_len = res->end - res->start + 1; | ||
198 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, dev->name)) { | ||
199 | retval = -EBUSY; | ||
200 | goto err1; | ||
201 | } | ||
202 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | ||
203 | if (!hcd->regs) { | ||
204 | pr_debug("ioremap failed"); | ||
205 | retval = -ENOMEM; | ||
206 | goto err2; | ||
207 | } | ||
208 | |||
209 | res = platform_get_resource(dev, IORESOURCE_IRQ, 0); | ||
210 | if (res == NULL) { | ||
211 | dev_err(&dev->dev, "No IRQ resource info for %s.\n", dev->name); | ||
212 | retval = -ENOMEM; | ||
213 | goto err3; | ||
214 | } | ||
215 | |||
216 | /* Map non-EHCI register spaces */ | ||
217 | retval = usb_hcd_msp_map_regs(to_mspusb_device(dev)); | ||
218 | if (retval != 0) | ||
219 | goto err3; | ||
220 | |||
221 | ehci = hcd_to_ehci(hcd); | ||
222 | ehci->big_endian_mmio = 1; | ||
223 | ehci->big_endian_desc = 1; | ||
224 | |||
225 | |||
226 | retval = usb_add_hcd(hcd, res->start, IRQF_SHARED); | ||
227 | if (retval == 0) | ||
228 | return 0; | ||
229 | |||
230 | usb_remove_hcd(hcd); | ||
231 | err3: | ||
232 | iounmap(hcd->regs); | ||
233 | err2: | ||
234 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
235 | err1: | ||
236 | usb_put_hcd(hcd); | ||
237 | |||
238 | return retval; | ||
239 | } | ||
240 | |||
241 | |||
242 | |||
243 | /** | ||
244 | * usb_hcd_msp_remove - shutdown processing for PMC MSP-based HCDs | ||
245 | * @dev: USB Host Controller being removed | ||
246 | * Context: !in_interrupt() | ||
247 | * | ||
248 | * Reverses the effect of usb_hcd_msp_probe(), first invoking | ||
249 | * the HCD's stop() method. It is always called from a thread | ||
250 | * context, normally "rmmod", "apmd", or something similar. | ||
251 | * | ||
252 | * may be called without controller electrically present | ||
253 | * may be called with controller, bus, and devices active | ||
254 | */ | ||
255 | void usb_hcd_msp_remove(struct usb_hcd *hcd, struct platform_device *dev) | ||
256 | { | ||
257 | usb_remove_hcd(hcd); | ||
258 | iounmap(hcd->regs); | ||
259 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
260 | usb_put_hcd(hcd); | ||
261 | } | ||
262 | |||
263 | #ifdef CONFIG_MSP_HAS_DUAL_USB | ||
264 | /* | ||
265 | * Wrapper around the main ehci_irq. Since both USB host controllers are | ||
266 | * sharing the same IRQ, need to first determine whether we're the intended | ||
267 | * recipient of this interrupt. | ||
268 | */ | ||
269 | static irqreturn_t ehci_msp_irq(struct usb_hcd *hcd) | ||
270 | { | ||
271 | u32 int_src; | ||
272 | struct device *dev = hcd->self.controller; | ||
273 | struct platform_device *pdev; | ||
274 | struct mspusb_device *mdev; | ||
275 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
276 | /* need to reverse-map a couple of containers to get our device */ | ||
277 | pdev = to_platform_device(dev); | ||
278 | mdev = to_mspusb_device(pdev); | ||
279 | |||
280 | /* Check to see if this interrupt is for this host controller */ | ||
281 | int_src = ehci_readl(ehci, &mdev->mab_regs->int_stat); | ||
282 | if (int_src & (1 << pdev->id)) | ||
283 | return ehci_irq(hcd); | ||
284 | |||
285 | /* Not for this device */ | ||
286 | return IRQ_NONE; | ||
287 | } | ||
288 | #endif /* DUAL_USB */ | ||
289 | |||
290 | static const struct hc_driver ehci_msp_hc_driver = { | ||
291 | .description = hcd_name, | ||
292 | .product_desc = "PMC MSP EHCI", | ||
293 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
294 | |||
295 | /* | ||
296 | * generic hardware linkage | ||
297 | */ | ||
298 | #ifdef CONFIG_MSP_HAS_DUAL_USB | ||
299 | .irq = ehci_msp_irq, | ||
300 | #else | ||
301 | .irq = ehci_irq, | ||
302 | #endif | ||
303 | .flags = HCD_MEMORY | HCD_USB2, | ||
304 | |||
305 | /* | ||
306 | * basic lifecycle operations | ||
307 | */ | ||
308 | .reset = ehci_msp_setup, | ||
309 | .start = ehci_run, | ||
310 | .shutdown = ehci_shutdown, | ||
311 | .start = ehci_run, | ||
312 | .stop = ehci_stop, | ||
313 | |||
314 | /* | ||
315 | * managing i/o requests and associated device resources | ||
316 | */ | ||
317 | .urb_enqueue = ehci_urb_enqueue, | ||
318 | .urb_dequeue = ehci_urb_dequeue, | ||
319 | .endpoint_disable = ehci_endpoint_disable, | ||
320 | .endpoint_reset = ehci_endpoint_reset, | ||
321 | |||
322 | /* | ||
323 | * scheduling support | ||
324 | */ | ||
325 | .get_frame_number = ehci_get_frame, | ||
326 | |||
327 | /* | ||
328 | * root hub support | ||
329 | */ | ||
330 | .hub_status_data = ehci_hub_status_data, | ||
331 | .hub_control = ehci_hub_control, | ||
332 | .bus_suspend = ehci_bus_suspend, | ||
333 | .bus_resume = ehci_bus_resume, | ||
334 | .relinquish_port = ehci_relinquish_port, | ||
335 | .port_handed_over = ehci_port_handed_over, | ||
336 | |||
337 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
338 | }; | ||
339 | |||
340 | static int ehci_hcd_msp_drv_probe(struct platform_device *pdev) | ||
341 | { | ||
342 | int ret; | ||
343 | |||
344 | pr_debug("In ehci_hcd_msp_drv_probe"); | ||
345 | |||
346 | if (usb_disabled()) | ||
347 | return -ENODEV; | ||
348 | |||
349 | gpio_request(MSP_PIN_USB0_HOST_DEV, "USB0_HOST_DEV_GPIO"); | ||
350 | #ifdef CONFIG_MSP_HAS_DUAL_USB | ||
351 | gpio_request(MSP_PIN_USB1_HOST_DEV, "USB1_HOST_DEV_GPIO"); | ||
352 | #endif | ||
353 | |||
354 | ret = usb_hcd_msp_probe(&ehci_msp_hc_driver, pdev); | ||
355 | |||
356 | return ret; | ||
357 | } | ||
358 | |||
359 | static int ehci_hcd_msp_drv_remove(struct platform_device *pdev) | ||
360 | { | ||
361 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
362 | |||
363 | usb_hcd_msp_remove(hcd, pdev); | ||
364 | |||
365 | /* free TWI GPIO USB_HOST_DEV pin */ | ||
366 | gpio_free(MSP_PIN_USB0_HOST_DEV); | ||
367 | #ifdef CONFIG_MSP_HAS_DUAL_USB | ||
368 | gpio_free(MSP_PIN_USB1_HOST_DEV); | ||
369 | #endif | ||
370 | |||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | MODULE_ALIAS("pmcmsp-ehci"); | ||
375 | |||
376 | static struct platform_driver ehci_hcd_msp_driver = { | ||
377 | .probe = ehci_hcd_msp_drv_probe, | ||
378 | .remove = ehci_hcd_msp_drv_remove, | ||
379 | .driver = { | ||
380 | .name = "pmcmsp-ehci", | ||
381 | .owner = THIS_MODULE, | ||
382 | }, | ||
383 | }; | ||
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index 233c288e3f93..fe99895fb098 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -1107,22 +1107,24 @@ submit_async ( | |||
1107 | struct list_head *qtd_list, | 1107 | struct list_head *qtd_list, |
1108 | gfp_t mem_flags | 1108 | gfp_t mem_flags |
1109 | ) { | 1109 | ) { |
1110 | struct ehci_qtd *qtd; | ||
1111 | int epnum; | 1110 | int epnum; |
1112 | unsigned long flags; | 1111 | unsigned long flags; |
1113 | struct ehci_qh *qh = NULL; | 1112 | struct ehci_qh *qh = NULL; |
1114 | int rc; | 1113 | int rc; |
1115 | 1114 | ||
1116 | qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list); | ||
1117 | epnum = urb->ep->desc.bEndpointAddress; | 1115 | epnum = urb->ep->desc.bEndpointAddress; |
1118 | 1116 | ||
1119 | #ifdef EHCI_URB_TRACE | 1117 | #ifdef EHCI_URB_TRACE |
1120 | ehci_dbg (ehci, | 1118 | { |
1121 | "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", | 1119 | struct ehci_qtd *qtd; |
1122 | __func__, urb->dev->devpath, urb, | 1120 | qtd = list_entry(qtd_list->next, struct ehci_qtd, qtd_list); |
1123 | epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", | 1121 | ehci_dbg(ehci, |
1124 | urb->transfer_buffer_length, | 1122 | "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", |
1125 | qtd, urb->ep->hcpriv); | 1123 | __func__, urb->dev->devpath, urb, |
1124 | epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", | ||
1125 | urb->transfer_buffer_length, | ||
1126 | qtd, urb->ep->hcpriv); | ||
1127 | } | ||
1126 | #endif | 1128 | #endif |
1127 | 1129 | ||
1128 | spin_lock_irqsave (&ehci->lock, flags); | 1130 | spin_lock_irqsave (&ehci->lock, flags); |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index aa46f57f9ec8..1543c838b3d1 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -1048,8 +1048,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream) | |||
1048 | * not like a QH -- no persistent state (toggle, halt) | 1048 | * not like a QH -- no persistent state (toggle, halt) |
1049 | */ | 1049 | */ |
1050 | if (stream->refcount == 1) { | 1050 | if (stream->refcount == 1) { |
1051 | int is_in; | ||
1052 | |||
1053 | // BUG_ON (!list_empty(&stream->td_list)); | 1051 | // BUG_ON (!list_empty(&stream->td_list)); |
1054 | 1052 | ||
1055 | while (!list_empty (&stream->free_list)) { | 1053 | while (!list_empty (&stream->free_list)) { |
@@ -1076,7 +1074,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream) | |||
1076 | } | 1074 | } |
1077 | } | 1075 | } |
1078 | 1076 | ||
1079 | is_in = (stream->bEndpointAddress & USB_DIR_IN) ? 0x10 : 0; | ||
1080 | stream->bEndpointAddress &= 0x0f; | 1077 | stream->bEndpointAddress &= 0x0f; |
1081 | if (stream->ep) | 1078 | if (stream->ep) |
1082 | stream->ep->hcpriv = NULL; | 1079 | stream->ep->hcpriv = NULL; |
@@ -1590,63 +1587,6 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd) | |||
1590 | *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); | 1587 | *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); |
1591 | } | 1588 | } |
1592 | 1589 | ||
1593 | #define AB_REG_BAR_LOW 0xe0 | ||
1594 | #define AB_REG_BAR_HIGH 0xe1 | ||
1595 | #define AB_INDX(addr) ((addr) + 0x00) | ||
1596 | #define AB_DATA(addr) ((addr) + 0x04) | ||
1597 | #define NB_PCIE_INDX_ADDR 0xe0 | ||
1598 | #define NB_PCIE_INDX_DATA 0xe4 | ||
1599 | #define NB_PIF0_PWRDOWN_0 0x01100012 | ||
1600 | #define NB_PIF0_PWRDOWN_1 0x01100013 | ||
1601 | |||
1602 | static void ehci_quirk_amd_L1(struct ehci_hcd *ehci, int disable) | ||
1603 | { | ||
1604 | u32 addr, addr_low, addr_high, val; | ||
1605 | |||
1606 | outb_p(AB_REG_BAR_LOW, 0xcd6); | ||
1607 | addr_low = inb_p(0xcd7); | ||
1608 | outb_p(AB_REG_BAR_HIGH, 0xcd6); | ||
1609 | addr_high = inb_p(0xcd7); | ||
1610 | addr = addr_high << 8 | addr_low; | ||
1611 | outl_p(0x30, AB_INDX(addr)); | ||
1612 | outl_p(0x40, AB_DATA(addr)); | ||
1613 | outl_p(0x34, AB_INDX(addr)); | ||
1614 | val = inl_p(AB_DATA(addr)); | ||
1615 | |||
1616 | if (disable) { | ||
1617 | val &= ~0x8; | ||
1618 | val |= (1 << 4) | (1 << 9); | ||
1619 | } else { | ||
1620 | val |= 0x8; | ||
1621 | val &= ~((1 << 4) | (1 << 9)); | ||
1622 | } | ||
1623 | outl_p(val, AB_DATA(addr)); | ||
1624 | |||
1625 | if (amd_nb_dev) { | ||
1626 | addr = NB_PIF0_PWRDOWN_0; | ||
1627 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr); | ||
1628 | pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val); | ||
1629 | if (disable) | ||
1630 | val &= ~(0x3f << 7); | ||
1631 | else | ||
1632 | val |= 0x3f << 7; | ||
1633 | |||
1634 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val); | ||
1635 | |||
1636 | addr = NB_PIF0_PWRDOWN_1; | ||
1637 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_ADDR, addr); | ||
1638 | pci_read_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, &val); | ||
1639 | if (disable) | ||
1640 | val &= ~(0x3f << 7); | ||
1641 | else | ||
1642 | val |= 0x3f << 7; | ||
1643 | |||
1644 | pci_write_config_dword(amd_nb_dev, NB_PCIE_INDX_DATA, val); | ||
1645 | } | ||
1646 | |||
1647 | return; | ||
1648 | } | ||
1649 | |||
1650 | /* fit urb's itds into the selected schedule slot; activate as needed */ | 1590 | /* fit urb's itds into the selected schedule slot; activate as needed */ |
1651 | static int | 1591 | static int |
1652 | itd_link_urb ( | 1592 | itd_link_urb ( |
@@ -1675,8 +1615,8 @@ itd_link_urb ( | |||
1675 | } | 1615 | } |
1676 | 1616 | ||
1677 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | 1617 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { |
1678 | if (ehci->amd_l1_fix == 1) | 1618 | if (ehci->amd_pll_fix == 1) |
1679 | ehci_quirk_amd_L1(ehci, 1); | 1619 | usb_amd_quirk_pll_disable(); |
1680 | } | 1620 | } |
1681 | 1621 | ||
1682 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 1622 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
@@ -1804,8 +1744,8 @@ itd_complete ( | |||
1804 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 1744 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
1805 | 1745 | ||
1806 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | 1746 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { |
1807 | if (ehci->amd_l1_fix == 1) | 1747 | if (ehci->amd_pll_fix == 1) |
1808 | ehci_quirk_amd_L1(ehci, 0); | 1748 | usb_amd_quirk_pll_enable(); |
1809 | } | 1749 | } |
1810 | 1750 | ||
1811 | if (unlikely(list_is_singular(&stream->td_list))) { | 1751 | if (unlikely(list_is_singular(&stream->td_list))) { |
@@ -2095,8 +2035,8 @@ sitd_link_urb ( | |||
2095 | } | 2035 | } |
2096 | 2036 | ||
2097 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | 2037 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { |
2098 | if (ehci->amd_l1_fix == 1) | 2038 | if (ehci->amd_pll_fix == 1) |
2099 | ehci_quirk_amd_L1(ehci, 1); | 2039 | usb_amd_quirk_pll_disable(); |
2100 | } | 2040 | } |
2101 | 2041 | ||
2102 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; | 2042 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; |
@@ -2200,8 +2140,8 @@ sitd_complete ( | |||
2200 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; | 2140 | ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--; |
2201 | 2141 | ||
2202 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { | 2142 | if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { |
2203 | if (ehci->amd_l1_fix == 1) | 2143 | if (ehci->amd_pll_fix == 1) |
2204 | ehci_quirk_amd_L1(ehci, 0); | 2144 | usb_amd_quirk_pll_enable(); |
2205 | } | 2145 | } |
2206 | 2146 | ||
2207 | if (list_is_singular(&stream->td_list)) { | 2147 | if (list_is_singular(&stream->td_list)) { |
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c new file mode 100644 index 000000000000..a516af28c29b --- /dev/null +++ b/drivers/usb/host/ehci-tegra.c | |||
@@ -0,0 +1,715 @@ | |||
1 | /* | ||
2 | * EHCI-compliant USB host controller driver for NVIDIA Tegra SoCs | ||
3 | * | ||
4 | * Copyright (C) 2010 Google, Inc. | ||
5 | * Copyright (C) 2009 NVIDIA Corporation | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
10 | * option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/clk.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/platform_data/tegra_usb.h> | ||
22 | #include <linux/irq.h> | ||
23 | #include <linux/usb/otg.h> | ||
24 | #include <mach/usb_phy.h> | ||
25 | |||
26 | #define TEGRA_USB_DMA_ALIGN 32 | ||
27 | |||
28 | struct tegra_ehci_hcd { | ||
29 | struct ehci_hcd *ehci; | ||
30 | struct tegra_usb_phy *phy; | ||
31 | struct clk *clk; | ||
32 | struct clk *emc_clk; | ||
33 | struct otg_transceiver *transceiver; | ||
34 | int host_resumed; | ||
35 | int bus_suspended; | ||
36 | int port_resuming; | ||
37 | int power_down_on_bus_suspend; | ||
38 | enum tegra_usb_phy_port_speed port_speed; | ||
39 | }; | ||
40 | |||
41 | static void tegra_ehci_power_up(struct usb_hcd *hcd) | ||
42 | { | ||
43 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
44 | |||
45 | clk_enable(tegra->emc_clk); | ||
46 | clk_enable(tegra->clk); | ||
47 | tegra_usb_phy_power_on(tegra->phy); | ||
48 | tegra->host_resumed = 1; | ||
49 | } | ||
50 | |||
51 | static void tegra_ehci_power_down(struct usb_hcd *hcd) | ||
52 | { | ||
53 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
54 | |||
55 | tegra->host_resumed = 0; | ||
56 | tegra_usb_phy_power_off(tegra->phy); | ||
57 | clk_disable(tegra->clk); | ||
58 | clk_disable(tegra->emc_clk); | ||
59 | } | ||
60 | |||
61 | static int tegra_ehci_hub_control( | ||
62 | struct usb_hcd *hcd, | ||
63 | u16 typeReq, | ||
64 | u16 wValue, | ||
65 | u16 wIndex, | ||
66 | char *buf, | ||
67 | u16 wLength | ||
68 | ) | ||
69 | { | ||
70 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
71 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
72 | u32 __iomem *status_reg; | ||
73 | u32 temp; | ||
74 | unsigned long flags; | ||
75 | int retval = 0; | ||
76 | |||
77 | status_reg = &ehci->regs->port_status[(wIndex & 0xff) - 1]; | ||
78 | |||
79 | spin_lock_irqsave(&ehci->lock, flags); | ||
80 | |||
81 | /* | ||
82 | * In ehci_hub_control() for USB_PORT_FEAT_ENABLE clears the other bits | ||
83 | * that are write on clear, by writing back the register read value, so | ||
84 | * USB_PORT_FEAT_ENABLE is handled by masking the set on clear bits | ||
85 | */ | ||
86 | if (typeReq == ClearPortFeature && wValue == USB_PORT_FEAT_ENABLE) { | ||
87 | temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS; | ||
88 | ehci_writel(ehci, temp & ~PORT_PE, status_reg); | ||
89 | goto done; | ||
90 | } | ||
91 | |||
92 | else if (typeReq == GetPortStatus) { | ||
93 | temp = ehci_readl(ehci, status_reg); | ||
94 | if (tegra->port_resuming && !(temp & PORT_SUSPEND)) { | ||
95 | /* Resume completed, re-enable disconnect detection */ | ||
96 | tegra->port_resuming = 0; | ||
97 | tegra_usb_phy_postresume(tegra->phy); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | else if (typeReq == SetPortFeature && wValue == USB_PORT_FEAT_SUSPEND) { | ||
102 | temp = ehci_readl(ehci, status_reg); | ||
103 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) != 0) { | ||
104 | retval = -EPIPE; | ||
105 | goto done; | ||
106 | } | ||
107 | |||
108 | temp &= ~PORT_WKCONN_E; | ||
109 | temp |= PORT_WKDISC_E | PORT_WKOC_E; | ||
110 | ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); | ||
111 | |||
112 | /* | ||
113 | * If a transaction is in progress, there may be a delay in | ||
114 | * suspending the port. Poll until the port is suspended. | ||
115 | */ | ||
116 | if (handshake(ehci, status_reg, PORT_SUSPEND, | ||
117 | PORT_SUSPEND, 5000)) | ||
118 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); | ||
119 | |||
120 | set_bit((wIndex & 0xff) - 1, &ehci->suspended_ports); | ||
121 | goto done; | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * Tegra host controller will time the resume operation to clear the bit | ||
126 | * when the port control state switches to HS or FS Idle. This behavior | ||
127 | * is different from EHCI where the host controller driver is required | ||
128 | * to set this bit to a zero after the resume duration is timed in the | ||
129 | * driver. | ||
130 | */ | ||
131 | else if (typeReq == ClearPortFeature && | ||
132 | wValue == USB_PORT_FEAT_SUSPEND) { | ||
133 | temp = ehci_readl(ehci, status_reg); | ||
134 | if ((temp & PORT_RESET) || !(temp & PORT_PE)) { | ||
135 | retval = -EPIPE; | ||
136 | goto done; | ||
137 | } | ||
138 | |||
139 | if (!(temp & PORT_SUSPEND)) | ||
140 | goto done; | ||
141 | |||
142 | /* Disable disconnect detection during port resume */ | ||
143 | tegra_usb_phy_preresume(tegra->phy); | ||
144 | |||
145 | ehci->reset_done[wIndex-1] = jiffies + msecs_to_jiffies(25); | ||
146 | |||
147 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); | ||
148 | /* start resume signalling */ | ||
149 | ehci_writel(ehci, temp | PORT_RESUME, status_reg); | ||
150 | |||
151 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
152 | msleep(20); | ||
153 | spin_lock_irqsave(&ehci->lock, flags); | ||
154 | |||
155 | /* Poll until the controller clears RESUME and SUSPEND */ | ||
156 | if (handshake(ehci, status_reg, PORT_RESUME, 0, 2000)) | ||
157 | pr_err("%s: timeout waiting for RESUME\n", __func__); | ||
158 | if (handshake(ehci, status_reg, PORT_SUSPEND, 0, 2000)) | ||
159 | pr_err("%s: timeout waiting for SUSPEND\n", __func__); | ||
160 | |||
161 | ehci->reset_done[wIndex-1] = 0; | ||
162 | |||
163 | tegra->port_resuming = 1; | ||
164 | goto done; | ||
165 | } | ||
166 | |||
167 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
168 | |||
169 | /* Handle the hub control events here */ | ||
170 | return ehci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | ||
171 | done: | ||
172 | spin_unlock_irqrestore(&ehci->lock, flags); | ||
173 | return retval; | ||
174 | } | ||
175 | |||
176 | static void tegra_ehci_restart(struct usb_hcd *hcd) | ||
177 | { | ||
178 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
179 | |||
180 | ehci_reset(ehci); | ||
181 | |||
182 | /* setup the frame list and Async q heads */ | ||
183 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); | ||
184 | ehci_writel(ehci, (u32)ehci->async->qh_dma, &ehci->regs->async_next); | ||
185 | /* setup the command register and set the controller in RUN mode */ | ||
186 | ehci->command &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); | ||
187 | ehci->command |= CMD_RUN; | ||
188 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | ||
189 | |||
190 | down_write(&ehci_cf_port_reset_rwsem); | ||
191 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | ||
192 | /* flush posted writes */ | ||
193 | ehci_readl(ehci, &ehci->regs->command); | ||
194 | up_write(&ehci_cf_port_reset_rwsem); | ||
195 | } | ||
196 | |||
197 | static int tegra_usb_suspend(struct usb_hcd *hcd) | ||
198 | { | ||
199 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
200 | struct ehci_regs __iomem *hw = tegra->ehci->regs; | ||
201 | unsigned long flags; | ||
202 | |||
203 | spin_lock_irqsave(&tegra->ehci->lock, flags); | ||
204 | |||
205 | tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3; | ||
206 | ehci_halt(tegra->ehci); | ||
207 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
208 | |||
209 | spin_unlock_irqrestore(&tegra->ehci->lock, flags); | ||
210 | |||
211 | tegra_ehci_power_down(hcd); | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static int tegra_usb_resume(struct usb_hcd *hcd) | ||
216 | { | ||
217 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
218 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
219 | struct ehci_regs __iomem *hw = ehci->regs; | ||
220 | unsigned long val; | ||
221 | |||
222 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
223 | tegra_ehci_power_up(hcd); | ||
224 | |||
225 | if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) { | ||
226 | /* Wait for the phy to detect new devices | ||
227 | * before we restart the controller */ | ||
228 | msleep(10); | ||
229 | goto restart; | ||
230 | } | ||
231 | |||
232 | /* Force the phy to keep data lines in suspend state */ | ||
233 | tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed); | ||
234 | |||
235 | /* Enable host mode */ | ||
236 | tdi_reset(ehci); | ||
237 | |||
238 | /* Enable Port Power */ | ||
239 | val = readl(&hw->port_status[0]); | ||
240 | val |= PORT_POWER; | ||
241 | writel(val, &hw->port_status[0]); | ||
242 | udelay(10); | ||
243 | |||
244 | /* Check if the phy resume from LP0. When the phy resume from LP0 | ||
245 | * USB register will be reset. */ | ||
246 | if (!readl(&hw->async_next)) { | ||
247 | /* Program the field PTC based on the saved speed mode */ | ||
248 | val = readl(&hw->port_status[0]); | ||
249 | val &= ~PORT_TEST(~0); | ||
250 | if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH) | ||
251 | val |= PORT_TEST_FORCE; | ||
252 | else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL) | ||
253 | val |= PORT_TEST(6); | ||
254 | else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW) | ||
255 | val |= PORT_TEST(7); | ||
256 | writel(val, &hw->port_status[0]); | ||
257 | udelay(10); | ||
258 | |||
259 | /* Disable test mode by setting PTC field to NORMAL_OP */ | ||
260 | val = readl(&hw->port_status[0]); | ||
261 | val &= ~PORT_TEST(~0); | ||
262 | writel(val, &hw->port_status[0]); | ||
263 | udelay(10); | ||
264 | } | ||
265 | |||
266 | /* Poll until CCS is enabled */ | ||
267 | if (handshake(ehci, &hw->port_status[0], PORT_CONNECT, | ||
268 | PORT_CONNECT, 2000)) { | ||
269 | pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__); | ||
270 | goto restart; | ||
271 | } | ||
272 | |||
273 | /* Poll until PE is enabled */ | ||
274 | if (handshake(ehci, &hw->port_status[0], PORT_PE, | ||
275 | PORT_PE, 2000)) { | ||
276 | pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__); | ||
277 | goto restart; | ||
278 | } | ||
279 | |||
280 | /* Clear the PCI status, to avoid an interrupt taken upon resume */ | ||
281 | val = readl(&hw->status); | ||
282 | val |= STS_PCD; | ||
283 | writel(val, &hw->status); | ||
284 | |||
285 | /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */ | ||
286 | val = readl(&hw->port_status[0]); | ||
287 | if ((val & PORT_POWER) && (val & PORT_PE)) { | ||
288 | val |= PORT_SUSPEND; | ||
289 | writel(val, &hw->port_status[0]); | ||
290 | |||
291 | /* Wait until port suspend completes */ | ||
292 | if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND, | ||
293 | PORT_SUSPEND, 1000)) { | ||
294 | pr_err("%s: timeout waiting for PORT_SUSPEND\n", | ||
295 | __func__); | ||
296 | goto restart; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | tegra_ehci_phy_restore_end(tegra->phy); | ||
301 | return 0; | ||
302 | |||
303 | restart: | ||
304 | if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH) | ||
305 | tegra_ehci_phy_restore_end(tegra->phy); | ||
306 | |||
307 | tegra_ehci_restart(hcd); | ||
308 | return 0; | ||
309 | } | ||
310 | |||
311 | static void tegra_ehci_shutdown(struct usb_hcd *hcd) | ||
312 | { | ||
313 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
314 | |||
315 | /* ehci_shutdown touches the USB controller registers, make sure | ||
316 | * controller has clocks to it */ | ||
317 | if (!tegra->host_resumed) | ||
318 | tegra_ehci_power_up(hcd); | ||
319 | |||
320 | ehci_shutdown(hcd); | ||
321 | } | ||
322 | |||
323 | static int tegra_ehci_setup(struct usb_hcd *hcd) | ||
324 | { | ||
325 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
326 | int retval; | ||
327 | |||
328 | /* EHCI registers start at offset 0x100 */ | ||
329 | ehci->caps = hcd->regs + 0x100; | ||
330 | ehci->regs = hcd->regs + 0x100 + | ||
331 | HC_LENGTH(readl(&ehci->caps->hc_capbase)); | ||
332 | |||
333 | dbg_hcs_params(ehci, "reset"); | ||
334 | dbg_hcc_params(ehci, "reset"); | ||
335 | |||
336 | /* cache this readonly data; minimize chip reads */ | ||
337 | ehci->hcs_params = readl(&ehci->caps->hcs_params); | ||
338 | |||
339 | /* switch to host mode */ | ||
340 | hcd->has_tt = 1; | ||
341 | ehci_reset(ehci); | ||
342 | |||
343 | retval = ehci_halt(ehci); | ||
344 | if (retval) | ||
345 | return retval; | ||
346 | |||
347 | /* data structure init */ | ||
348 | retval = ehci_init(hcd); | ||
349 | if (retval) | ||
350 | return retval; | ||
351 | |||
352 | ehci->sbrn = 0x20; | ||
353 | |||
354 | ehci_port_power(ehci, 1); | ||
355 | return retval; | ||
356 | } | ||
357 | |||
358 | #ifdef CONFIG_PM | ||
359 | static int tegra_ehci_bus_suspend(struct usb_hcd *hcd) | ||
360 | { | ||
361 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
362 | int error_status = 0; | ||
363 | |||
364 | error_status = ehci_bus_suspend(hcd); | ||
365 | if (!error_status && tegra->power_down_on_bus_suspend) { | ||
366 | tegra_usb_suspend(hcd); | ||
367 | tegra->bus_suspended = 1; | ||
368 | } | ||
369 | |||
370 | return error_status; | ||
371 | } | ||
372 | |||
373 | static int tegra_ehci_bus_resume(struct usb_hcd *hcd) | ||
374 | { | ||
375 | struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); | ||
376 | |||
377 | if (tegra->bus_suspended && tegra->power_down_on_bus_suspend) { | ||
378 | tegra_usb_resume(hcd); | ||
379 | tegra->bus_suspended = 0; | ||
380 | } | ||
381 | |||
382 | tegra_usb_phy_preresume(tegra->phy); | ||
383 | tegra->port_resuming = 1; | ||
384 | return ehci_bus_resume(hcd); | ||
385 | } | ||
386 | #endif | ||
387 | |||
388 | struct temp_buffer { | ||
389 | void *kmalloc_ptr; | ||
390 | void *old_xfer_buffer; | ||
391 | u8 data[0]; | ||
392 | }; | ||
393 | |||
394 | static void free_temp_buffer(struct urb *urb) | ||
395 | { | ||
396 | enum dma_data_direction dir; | ||
397 | struct temp_buffer *temp; | ||
398 | |||
399 | if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) | ||
400 | return; | ||
401 | |||
402 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | ||
403 | |||
404 | temp = container_of(urb->transfer_buffer, struct temp_buffer, | ||
405 | data); | ||
406 | |||
407 | if (dir == DMA_FROM_DEVICE) | ||
408 | memcpy(temp->old_xfer_buffer, temp->data, | ||
409 | urb->transfer_buffer_length); | ||
410 | urb->transfer_buffer = temp->old_xfer_buffer; | ||
411 | kfree(temp->kmalloc_ptr); | ||
412 | |||
413 | urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER; | ||
414 | } | ||
415 | |||
416 | static int alloc_temp_buffer(struct urb *urb, gfp_t mem_flags) | ||
417 | { | ||
418 | enum dma_data_direction dir; | ||
419 | struct temp_buffer *temp, *kmalloc_ptr; | ||
420 | size_t kmalloc_size; | ||
421 | |||
422 | if (urb->num_sgs || urb->sg || | ||
423 | urb->transfer_buffer_length == 0 || | ||
424 | !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1))) | ||
425 | return 0; | ||
426 | |||
427 | dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; | ||
428 | |||
429 | /* Allocate a buffer with enough padding for alignment */ | ||
430 | kmalloc_size = urb->transfer_buffer_length + | ||
431 | sizeof(struct temp_buffer) + TEGRA_USB_DMA_ALIGN - 1; | ||
432 | |||
433 | kmalloc_ptr = kmalloc(kmalloc_size, mem_flags); | ||
434 | if (!kmalloc_ptr) | ||
435 | return -ENOMEM; | ||
436 | |||
437 | /* Position our struct temp_buffer such that data is aligned */ | ||
438 | temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1; | ||
439 | |||
440 | temp->kmalloc_ptr = kmalloc_ptr; | ||
441 | temp->old_xfer_buffer = urb->transfer_buffer; | ||
442 | if (dir == DMA_TO_DEVICE) | ||
443 | memcpy(temp->data, urb->transfer_buffer, | ||
444 | urb->transfer_buffer_length); | ||
445 | urb->transfer_buffer = temp->data; | ||
446 | |||
447 | urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER; | ||
448 | |||
449 | return 0; | ||
450 | } | ||
451 | |||
452 | static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, | ||
453 | gfp_t mem_flags) | ||
454 | { | ||
455 | int ret; | ||
456 | |||
457 | ret = alloc_temp_buffer(urb, mem_flags); | ||
458 | if (ret) | ||
459 | return ret; | ||
460 | |||
461 | ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); | ||
462 | if (ret) | ||
463 | free_temp_buffer(urb); | ||
464 | |||
465 | return ret; | ||
466 | } | ||
467 | |||
468 | static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) | ||
469 | { | ||
470 | usb_hcd_unmap_urb_for_dma(hcd, urb); | ||
471 | free_temp_buffer(urb); | ||
472 | } | ||
473 | |||
474 | static const struct hc_driver tegra_ehci_hc_driver = { | ||
475 | .description = hcd_name, | ||
476 | .product_desc = "Tegra EHCI Host Controller", | ||
477 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
478 | |||
479 | .flags = HCD_USB2 | HCD_MEMORY, | ||
480 | |||
481 | .reset = tegra_ehci_setup, | ||
482 | .irq = ehci_irq, | ||
483 | |||
484 | .start = ehci_run, | ||
485 | .stop = ehci_stop, | ||
486 | .shutdown = tegra_ehci_shutdown, | ||
487 | .urb_enqueue = ehci_urb_enqueue, | ||
488 | .urb_dequeue = ehci_urb_dequeue, | ||
489 | .map_urb_for_dma = tegra_ehci_map_urb_for_dma, | ||
490 | .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma, | ||
491 | .endpoint_disable = ehci_endpoint_disable, | ||
492 | .endpoint_reset = ehci_endpoint_reset, | ||
493 | .get_frame_number = ehci_get_frame, | ||
494 | .hub_status_data = ehci_hub_status_data, | ||
495 | .hub_control = tegra_ehci_hub_control, | ||
496 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
497 | #ifdef CONFIG_PM | ||
498 | .bus_suspend = tegra_ehci_bus_suspend, | ||
499 | .bus_resume = tegra_ehci_bus_resume, | ||
500 | #endif | ||
501 | .relinquish_port = ehci_relinquish_port, | ||
502 | .port_handed_over = ehci_port_handed_over, | ||
503 | }; | ||
504 | |||
505 | static int tegra_ehci_probe(struct platform_device *pdev) | ||
506 | { | ||
507 | struct resource *res; | ||
508 | struct usb_hcd *hcd; | ||
509 | struct tegra_ehci_hcd *tegra; | ||
510 | struct tegra_ehci_platform_data *pdata; | ||
511 | int err = 0; | ||
512 | int irq; | ||
513 | int instance = pdev->id; | ||
514 | |||
515 | pdata = pdev->dev.platform_data; | ||
516 | if (!pdata) { | ||
517 | dev_err(&pdev->dev, "Platform data missing\n"); | ||
518 | return -EINVAL; | ||
519 | } | ||
520 | |||
521 | tegra = kzalloc(sizeof(struct tegra_ehci_hcd), GFP_KERNEL); | ||
522 | if (!tegra) | ||
523 | return -ENOMEM; | ||
524 | |||
525 | hcd = usb_create_hcd(&tegra_ehci_hc_driver, &pdev->dev, | ||
526 | dev_name(&pdev->dev)); | ||
527 | if (!hcd) { | ||
528 | dev_err(&pdev->dev, "Unable to create HCD\n"); | ||
529 | err = -ENOMEM; | ||
530 | goto fail_hcd; | ||
531 | } | ||
532 | |||
533 | platform_set_drvdata(pdev, tegra); | ||
534 | |||
535 | tegra->clk = clk_get(&pdev->dev, NULL); | ||
536 | if (IS_ERR(tegra->clk)) { | ||
537 | dev_err(&pdev->dev, "Can't get ehci clock\n"); | ||
538 | err = PTR_ERR(tegra->clk); | ||
539 | goto fail_clk; | ||
540 | } | ||
541 | |||
542 | err = clk_enable(tegra->clk); | ||
543 | if (err) | ||
544 | goto fail_clken; | ||
545 | |||
546 | tegra->emc_clk = clk_get(&pdev->dev, "emc"); | ||
547 | if (IS_ERR(tegra->emc_clk)) { | ||
548 | dev_err(&pdev->dev, "Can't get emc clock\n"); | ||
549 | err = PTR_ERR(tegra->emc_clk); | ||
550 | goto fail_emc_clk; | ||
551 | } | ||
552 | |||
553 | clk_enable(tegra->emc_clk); | ||
554 | clk_set_rate(tegra->emc_clk, 400000000); | ||
555 | |||
556 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
557 | if (!res) { | ||
558 | dev_err(&pdev->dev, "Failed to get I/O memory\n"); | ||
559 | err = -ENXIO; | ||
560 | goto fail_io; | ||
561 | } | ||
562 | hcd->rsrc_start = res->start; | ||
563 | hcd->rsrc_len = resource_size(res); | ||
564 | hcd->regs = ioremap(res->start, resource_size(res)); | ||
565 | if (!hcd->regs) { | ||
566 | dev_err(&pdev->dev, "Failed to remap I/O memory\n"); | ||
567 | err = -ENOMEM; | ||
568 | goto fail_io; | ||
569 | } | ||
570 | |||
571 | tegra->phy = tegra_usb_phy_open(instance, hcd->regs, pdata->phy_config, | ||
572 | TEGRA_USB_PHY_MODE_HOST); | ||
573 | if (IS_ERR(tegra->phy)) { | ||
574 | dev_err(&pdev->dev, "Failed to open USB phy\n"); | ||
575 | err = -ENXIO; | ||
576 | goto fail_phy; | ||
577 | } | ||
578 | |||
579 | err = tegra_usb_phy_power_on(tegra->phy); | ||
580 | if (err) { | ||
581 | dev_err(&pdev->dev, "Failed to power on the phy\n"); | ||
582 | goto fail; | ||
583 | } | ||
584 | |||
585 | tegra->host_resumed = 1; | ||
586 | tegra->power_down_on_bus_suspend = pdata->power_down_on_bus_suspend; | ||
587 | tegra->ehci = hcd_to_ehci(hcd); | ||
588 | |||
589 | irq = platform_get_irq(pdev, 0); | ||
590 | if (!irq) { | ||
591 | dev_err(&pdev->dev, "Failed to get IRQ\n"); | ||
592 | err = -ENODEV; | ||
593 | goto fail; | ||
594 | } | ||
595 | set_irq_flags(irq, IRQF_VALID); | ||
596 | |||
597 | #ifdef CONFIG_USB_OTG_UTILS | ||
598 | if (pdata->operating_mode == TEGRA_USB_OTG) { | ||
599 | tegra->transceiver = otg_get_transceiver(); | ||
600 | if (tegra->transceiver) | ||
601 | otg_set_host(tegra->transceiver, &hcd->self); | ||
602 | } | ||
603 | #endif | ||
604 | |||
605 | err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | ||
606 | if (err) { | ||
607 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | ||
608 | goto fail; | ||
609 | } | ||
610 | |||
611 | return err; | ||
612 | |||
613 | fail: | ||
614 | #ifdef CONFIG_USB_OTG_UTILS | ||
615 | if (tegra->transceiver) { | ||
616 | otg_set_host(tegra->transceiver, NULL); | ||
617 | otg_put_transceiver(tegra->transceiver); | ||
618 | } | ||
619 | #endif | ||
620 | tegra_usb_phy_close(tegra->phy); | ||
621 | fail_phy: | ||
622 | iounmap(hcd->regs); | ||
623 | fail_io: | ||
624 | clk_disable(tegra->emc_clk); | ||
625 | clk_put(tegra->emc_clk); | ||
626 | fail_emc_clk: | ||
627 | clk_disable(tegra->clk); | ||
628 | fail_clken: | ||
629 | clk_put(tegra->clk); | ||
630 | fail_clk: | ||
631 | usb_put_hcd(hcd); | ||
632 | fail_hcd: | ||
633 | kfree(tegra); | ||
634 | return err; | ||
635 | } | ||
636 | |||
637 | #ifdef CONFIG_PM | ||
638 | static int tegra_ehci_resume(struct platform_device *pdev) | ||
639 | { | ||
640 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | ||
641 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
642 | |||
643 | if (tegra->bus_suspended) | ||
644 | return 0; | ||
645 | |||
646 | return tegra_usb_resume(hcd); | ||
647 | } | ||
648 | |||
649 | static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state) | ||
650 | { | ||
651 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | ||
652 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
653 | |||
654 | if (tegra->bus_suspended) | ||
655 | return 0; | ||
656 | |||
657 | if (time_before(jiffies, tegra->ehci->next_statechange)) | ||
658 | msleep(10); | ||
659 | |||
660 | return tegra_usb_suspend(hcd); | ||
661 | } | ||
662 | #endif | ||
663 | |||
664 | static int tegra_ehci_remove(struct platform_device *pdev) | ||
665 | { | ||
666 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | ||
667 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
668 | |||
669 | if (tegra == NULL || hcd == NULL) | ||
670 | return -EINVAL; | ||
671 | |||
672 | #ifdef CONFIG_USB_OTG_UTILS | ||
673 | if (tegra->transceiver) { | ||
674 | otg_set_host(tegra->transceiver, NULL); | ||
675 | otg_put_transceiver(tegra->transceiver); | ||
676 | } | ||
677 | #endif | ||
678 | |||
679 | usb_remove_hcd(hcd); | ||
680 | usb_put_hcd(hcd); | ||
681 | |||
682 | tegra_usb_phy_close(tegra->phy); | ||
683 | iounmap(hcd->regs); | ||
684 | |||
685 | clk_disable(tegra->clk); | ||
686 | clk_put(tegra->clk); | ||
687 | |||
688 | clk_disable(tegra->emc_clk); | ||
689 | clk_put(tegra->emc_clk); | ||
690 | |||
691 | kfree(tegra); | ||
692 | return 0; | ||
693 | } | ||
694 | |||
695 | static void tegra_ehci_hcd_shutdown(struct platform_device *pdev) | ||
696 | { | ||
697 | struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); | ||
698 | struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci); | ||
699 | |||
700 | if (hcd->driver->shutdown) | ||
701 | hcd->driver->shutdown(hcd); | ||
702 | } | ||
703 | |||
704 | static struct platform_driver tegra_ehci_driver = { | ||
705 | .probe = tegra_ehci_probe, | ||
706 | .remove = tegra_ehci_remove, | ||
707 | #ifdef CONFIG_PM | ||
708 | .suspend = tegra_ehci_suspend, | ||
709 | .resume = tegra_ehci_resume, | ||
710 | #endif | ||
711 | .shutdown = tegra_ehci_hcd_shutdown, | ||
712 | .driver = { | ||
713 | .name = "tegra-ehci", | ||
714 | } | ||
715 | }; | ||
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 799ac16a54b4..f86d3fa20214 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
@@ -131,7 +131,7 @@ struct ehci_hcd { /* one per controller */ | |||
131 | unsigned has_amcc_usb23:1; | 131 | unsigned has_amcc_usb23:1; |
132 | unsigned need_io_watchdog:1; | 132 | unsigned need_io_watchdog:1; |
133 | unsigned broken_periodic:1; | 133 | unsigned broken_periodic:1; |
134 | unsigned amd_l1_fix:1; | 134 | unsigned amd_pll_fix:1; |
135 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ | 135 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ |
136 | unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ | 136 | unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ |
137 | 137 | ||
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c index f90d003f2302..2562e92e3178 100644 --- a/drivers/usb/host/imx21-hcd.c +++ b/drivers/usb/host/imx21-hcd.c | |||
@@ -927,7 +927,8 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb) | |||
927 | if (state == US_CTRL_SETUP) { | 927 | if (state == US_CTRL_SETUP) { |
928 | dir = TD_DIR_SETUP; | 928 | dir = TD_DIR_SETUP; |
929 | if (unsuitable_for_dma(urb->setup_dma)) | 929 | if (unsuitable_for_dma(urb->setup_dma)) |
930 | unmap_urb_setup_for_dma(imx21->hcd, urb); | 930 | usb_hcd_unmap_urb_setup_for_dma(imx21->hcd, |
931 | urb); | ||
931 | etd->dma_handle = urb->setup_dma; | 932 | etd->dma_handle = urb->setup_dma; |
932 | etd->cpu_buffer = urb->setup_packet; | 933 | etd->cpu_buffer = urb->setup_packet; |
933 | bufround = 0; | 934 | bufround = 0; |
@@ -943,7 +944,7 @@ static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb) | |||
943 | dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN; | 944 | dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN; |
944 | bufround = (dir == TD_DIR_IN) ? 1 : 0; | 945 | bufround = (dir == TD_DIR_IN) ? 1 : 0; |
945 | if (unsuitable_for_dma(urb->transfer_dma)) | 946 | if (unsuitable_for_dma(urb->transfer_dma)) |
946 | unmap_urb_for_dma(imx21->hcd, urb); | 947 | usb_hcd_unmap_urb_for_dma(imx21->hcd, urb); |
947 | 948 | ||
948 | etd->dma_handle = urb->transfer_dma; | 949 | etd->dma_handle = urb->transfer_dma; |
949 | etd->cpu_buffer = urb->transfer_buffer; | 950 | etd->cpu_buffer = urb->transfer_buffer; |
@@ -1471,8 +1472,8 @@ static int get_hub_descriptor(struct usb_hcd *hcd, | |||
1471 | 0x0010 | /* No over current protection */ | 1472 | 0x0010 | /* No over current protection */ |
1472 | 0); | 1473 | 0); |
1473 | 1474 | ||
1474 | desc->bitmap[0] = 1 << 1; | 1475 | desc->u.hs.DeviceRemovable[0] = 1 << 1; |
1475 | desc->bitmap[1] = ~0; | 1476 | desc->u.hs.DeviceRemovable[1] = ~0; |
1476 | return 0; | 1477 | return 0; |
1477 | } | 1478 | } |
1478 | 1479 | ||
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 0da7fc05f453..c0e22f26da19 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
@@ -951,9 +951,9 @@ static void isp116x_hub_descriptor(struct isp116x *isp116x, | |||
951 | /* Power switching, device type, overcurrent. */ | 951 | /* Power switching, device type, overcurrent. */ |
952 | desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f)); | 952 | desc->wHubCharacteristics = cpu_to_le16((u16) ((reg >> 8) & 0x1f)); |
953 | desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff); | 953 | desc->bPwrOn2PwrGood = (u8) ((reg >> 24) & 0xff); |
954 | /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ | 954 | /* ports removable, and legacy PortPwrCtrlMask */ |
955 | desc->bitmap[0] = 0; | 955 | desc->u.hs.DeviceRemovable[0] = 0; |
956 | desc->bitmap[1] = ~0; | 956 | desc->u.hs.DeviceRemovable[1] = ~0; |
957 | } | 957 | } |
958 | 958 | ||
959 | /* Perform reset of a given port. | 959 | /* Perform reset of a given port. |
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index 43a39eb56cc6..662cd002adfc 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c | |||
@@ -226,7 +226,6 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq, | |||
226 | 226 | ||
227 | static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) | 227 | static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep) |
228 | { | 228 | { |
229 | int index = ep->ptd_index; | ||
230 | int last = ep->ptd_index + ep->num_ptds; | 229 | int last = ep->ptd_index + ep->num_ptds; |
231 | 230 | ||
232 | if (last > epq->buf_count) | 231 | if (last > epq->buf_count) |
@@ -236,10 +235,8 @@ static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1 | |||
236 | epq->buf_map, epq->skip_map); | 235 | epq->buf_map, epq->skip_map); |
237 | BUG_ON(last > epq->buf_count); | 236 | BUG_ON(last > epq->buf_count); |
238 | 237 | ||
239 | for (; index < last; index++) { | 238 | bitmap_clear(&epq->buf_map, ep->ptd_index, ep->num_ptds); |
240 | __clear_bit(index, &epq->buf_map); | 239 | bitmap_set(&epq->skip_map, ep->ptd_index, ep->num_ptds); |
241 | __set_bit(index, &epq->skip_map); | ||
242 | } | ||
243 | epq->buf_avail += ep->num_ptds; | 240 | epq->buf_avail += ep->num_ptds; |
244 | epq->ptd_count--; | 241 | epq->ptd_count--; |
245 | 242 | ||
@@ -1555,9 +1552,9 @@ static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd, | |||
1555 | desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f); | 1552 | desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f); |
1556 | DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f)); | 1553 | DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f)); |
1557 | desc->bPwrOn2PwrGood = (reg >> 24) & 0xff; | 1554 | desc->bPwrOn2PwrGood = (reg >> 24) & 0xff; |
1558 | /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ | 1555 | /* ports removable, and legacy PortPwrCtrlMask */ |
1559 | desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; | 1556 | desc->u.hs.DeviceRemovable[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1; |
1560 | desc->bitmap[1] = ~0; | 1557 | desc->u.hs.DeviceRemovable[1] = ~0; |
1561 | 1558 | ||
1562 | DBG(3, "%s: exit\n", __func__); | 1559 | DBG(3, "%s: exit\n", __func__); |
1563 | } | 1560 | } |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index bdba8c5d844a..f50e84ac570a 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
@@ -33,6 +33,7 @@ struct isp1760_hcd { | |||
33 | struct inter_packet_info atl_ints[32]; | 33 | struct inter_packet_info atl_ints[32]; |
34 | struct inter_packet_info int_ints[32]; | 34 | struct inter_packet_info int_ints[32]; |
35 | struct memory_chunk memory_pool[BLOCKS]; | 35 | struct memory_chunk memory_pool[BLOCKS]; |
36 | u32 atl_queued; | ||
36 | 37 | ||
37 | /* periodic schedule support */ | 38 | /* periodic schedule support */ |
38 | #define DEFAULT_I_TDPS 1024 | 39 | #define DEFAULT_I_TDPS 1024 |
@@ -47,10 +48,6 @@ static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) | |||
47 | { | 48 | { |
48 | return (struct isp1760_hcd *) (hcd->hcd_priv); | 49 | return (struct isp1760_hcd *) (hcd->hcd_priv); |
49 | } | 50 | } |
50 | static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv) | ||
51 | { | ||
52 | return container_of((void *) priv, struct usb_hcd, hcd_priv); | ||
53 | } | ||
54 | 51 | ||
55 | /* Section 2.2 Host Controller Capability Registers */ | 52 | /* Section 2.2 Host Controller Capability Registers */ |
56 | #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ | 53 | #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */ |
@@ -80,11 +77,10 @@ static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv) | |||
80 | #define PORT_RWC_BITS (PORT_CSC) | 77 | #define PORT_RWC_BITS (PORT_CSC) |
81 | 78 | ||
82 | struct isp1760_qtd { | 79 | struct isp1760_qtd { |
83 | struct isp1760_qtd *hw_next; | ||
84 | u8 packet_type; | 80 | u8 packet_type; |
85 | u8 toggle; | ||
86 | |||
87 | void *data_buffer; | 81 | void *data_buffer; |
82 | u32 payload_addr; | ||
83 | |||
88 | /* the rest is HCD-private */ | 84 | /* the rest is HCD-private */ |
89 | struct list_head qtd_list; | 85 | struct list_head qtd_list; |
90 | struct urb *urb; | 86 | struct urb *urb; |
@@ -92,205 +88,267 @@ struct isp1760_qtd { | |||
92 | 88 | ||
93 | /* isp special*/ | 89 | /* isp special*/ |
94 | u32 status; | 90 | u32 status; |
95 | #define URB_COMPLETE_NOTIFY (1 << 0) | ||
96 | #define URB_ENQUEUED (1 << 1) | 91 | #define URB_ENQUEUED (1 << 1) |
97 | #define URB_TYPE_ATL (1 << 2) | ||
98 | #define URB_TYPE_INT (1 << 3) | ||
99 | }; | 92 | }; |
100 | 93 | ||
101 | struct isp1760_qh { | 94 | struct isp1760_qh { |
102 | /* first part defined by EHCI spec */ | 95 | /* first part defined by EHCI spec */ |
103 | struct list_head qtd_list; | 96 | struct list_head qtd_list; |
104 | struct isp1760_hcd *priv; | ||
105 | |||
106 | /* periodic schedule info */ | ||
107 | unsigned short period; /* polling interval */ | ||
108 | struct usb_device *dev; | ||
109 | 97 | ||
110 | u32 toggle; | 98 | u32 toggle; |
111 | u32 ping; | 99 | u32 ping; |
112 | }; | 100 | }; |
113 | 101 | ||
114 | #define ehci_port_speed(priv, portsc) USB_PORT_STAT_HIGH_SPEED | 102 | /* |
115 | 103 | * Access functions for isp176x registers (addresses 0..0x03FF). | |
116 | static unsigned int isp1760_readl(__u32 __iomem *regs) | 104 | */ |
105 | static u32 reg_read32(void __iomem *base, u32 reg) | ||
117 | { | 106 | { |
118 | return readl(regs); | 107 | return readl(base + reg); |
119 | } | 108 | } |
120 | 109 | ||
121 | static void isp1760_writel(const unsigned int val, __u32 __iomem *regs) | 110 | static void reg_write32(void __iomem *base, u32 reg, u32 val) |
122 | { | 111 | { |
123 | writel(val, regs); | 112 | writel(val, base + reg); |
124 | } | 113 | } |
125 | 114 | ||
126 | /* | 115 | /* |
127 | * The next two copy via MMIO data to/from the device. memcpy_{to|from}io() | 116 | * Access functions for isp176x memory (offset >= 0x0400). |
117 | * | ||
118 | * bank_reads8() reads memory locations prefetched by an earlier write to | ||
119 | * HC_MEMORY_REG (see isp176x datasheet). Unless you want to do fancy multi- | ||
120 | * bank optimizations, you should use the more generic mem_reads8() below. | ||
121 | * | ||
122 | * For access to ptd memory, use the specialized ptd_read() and ptd_write() | ||
123 | * below. | ||
124 | * | ||
125 | * These functions copy via MMIO data to/from the device. memcpy_{to|from}io() | ||
128 | * doesn't quite work because some people have to enforce 32-bit access | 126 | * doesn't quite work because some people have to enforce 32-bit access |
129 | */ | 127 | */ |
130 | static void priv_read_copy(struct isp1760_hcd *priv, u32 *src, | 128 | static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr, |
131 | __u32 __iomem *dst, u32 len) | 129 | __u32 *dst, u32 bytes) |
132 | { | 130 | { |
131 | __u32 __iomem *src; | ||
133 | u32 val; | 132 | u32 val; |
134 | u8 *buff8; | 133 | __u8 *src_byteptr; |
134 | __u8 *dst_byteptr; | ||
135 | 135 | ||
136 | if (!src) { | 136 | src = src_base + (bank_addr | src_offset); |
137 | printk(KERN_ERR "ERROR: buffer: %p len: %d\n", src, len); | ||
138 | return; | ||
139 | } | ||
140 | 137 | ||
141 | while (len >= 4) { | 138 | if (src_offset < PAYLOAD_OFFSET) { |
142 | *src = __raw_readl(dst); | 139 | while (bytes >= 4) { |
143 | len -= 4; | 140 | *dst = le32_to_cpu(__raw_readl(src)); |
144 | src++; | 141 | bytes -= 4; |
145 | dst++; | 142 | src++; |
143 | dst++; | ||
144 | } | ||
145 | } else { | ||
146 | while (bytes >= 4) { | ||
147 | *dst = __raw_readl(src); | ||
148 | bytes -= 4; | ||
149 | src++; | ||
150 | dst++; | ||
151 | } | ||
146 | } | 152 | } |
147 | 153 | ||
148 | if (!len) | 154 | if (!bytes) |
149 | return; | 155 | return; |
150 | 156 | ||
151 | /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully | 157 | /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully |
152 | * allocated. | 158 | * allocated. |
153 | */ | 159 | */ |
154 | val = isp1760_readl(dst); | 160 | if (src_offset < PAYLOAD_OFFSET) |
155 | 161 | val = le32_to_cpu(__raw_readl(src)); | |
156 | buff8 = (u8 *)src; | 162 | else |
157 | while (len) { | 163 | val = __raw_readl(src); |
158 | 164 | ||
159 | *buff8 = val; | 165 | dst_byteptr = (void *) dst; |
160 | val >>= 8; | 166 | src_byteptr = (void *) &val; |
161 | len--; | 167 | while (bytes > 0) { |
162 | buff8++; | 168 | *dst_byteptr = *src_byteptr; |
169 | dst_byteptr++; | ||
170 | src_byteptr++; | ||
171 | bytes--; | ||
163 | } | 172 | } |
164 | } | 173 | } |
165 | 174 | ||
166 | static void priv_write_copy(const struct isp1760_hcd *priv, const u32 *src, | 175 | static void mem_reads8(void __iomem *src_base, u32 src_offset, void *dst, |
167 | __u32 __iomem *dst, u32 len) | 176 | u32 bytes) |
168 | { | 177 | { |
169 | while (len >= 4) { | 178 | reg_write32(src_base, HC_MEMORY_REG, src_offset + ISP_BANK(0)); |
170 | __raw_writel(*src, dst); | 179 | ndelay(90); |
171 | len -= 4; | 180 | bank_reads8(src_base, src_offset, ISP_BANK(0), dst, bytes); |
172 | src++; | 181 | } |
173 | dst++; | 182 | |
183 | static void mem_writes8(void __iomem *dst_base, u32 dst_offset, | ||
184 | __u32 const *src, u32 bytes) | ||
185 | { | ||
186 | __u32 __iomem *dst; | ||
187 | |||
188 | dst = dst_base + dst_offset; | ||
189 | |||
190 | if (dst_offset < PAYLOAD_OFFSET) { | ||
191 | while (bytes >= 4) { | ||
192 | __raw_writel(cpu_to_le32(*src), dst); | ||
193 | bytes -= 4; | ||
194 | src++; | ||
195 | dst++; | ||
196 | } | ||
197 | } else { | ||
198 | while (bytes >= 4) { | ||
199 | __raw_writel(*src, dst); | ||
200 | bytes -= 4; | ||
201 | src++; | ||
202 | dst++; | ||
203 | } | ||
174 | } | 204 | } |
175 | 205 | ||
176 | if (!len) | 206 | if (!bytes) |
177 | return; | 207 | return; |
178 | /* in case we have 3, 2 or 1 by left. The buffer is allocated and the | 208 | /* in case we have 3, 2 or 1 bytes left. The buffer is allocated and the |
179 | * extra bytes should not be read by the HW | 209 | * extra bytes should not be read by the HW. |
180 | */ | 210 | */ |
181 | 211 | ||
182 | __raw_writel(*src, dst); | 212 | if (dst_offset < PAYLOAD_OFFSET) |
213 | __raw_writel(cpu_to_le32(*src), dst); | ||
214 | else | ||
215 | __raw_writel(*src, dst); | ||
216 | } | ||
217 | |||
218 | /* | ||
219 | * Read and write ptds. 'ptd_offset' should be one of ISO_PTD_OFFSET, | ||
220 | * INT_PTD_OFFSET, and ATL_PTD_OFFSET. 'slot' should be less than 32. | ||
221 | */ | ||
222 | static void ptd_read(void __iomem *base, u32 ptd_offset, u32 slot, | ||
223 | struct ptd *ptd) | ||
224 | { | ||
225 | reg_write32(base, HC_MEMORY_REG, | ||
226 | ISP_BANK(0) + ptd_offset + slot*sizeof(*ptd)); | ||
227 | ndelay(90); | ||
228 | bank_reads8(base, ptd_offset + slot*sizeof(*ptd), ISP_BANK(0), | ||
229 | (void *) ptd, sizeof(*ptd)); | ||
230 | } | ||
231 | |||
232 | static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot, | ||
233 | struct ptd *ptd) | ||
234 | { | ||
235 | mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0), | ||
236 | &ptd->dw1, 7*sizeof(ptd->dw1)); | ||
237 | /* Make sure dw0 gets written last (after other dw's and after payload) | ||
238 | since it contains the enable bit */ | ||
239 | wmb(); | ||
240 | mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0, | ||
241 | sizeof(ptd->dw0)); | ||
183 | } | 242 | } |
184 | 243 | ||
244 | |||
185 | /* memory management of the 60kb on the chip from 0x1000 to 0xffff */ | 245 | /* memory management of the 60kb on the chip from 0x1000 to 0xffff */ |
186 | static void init_memory(struct isp1760_hcd *priv) | 246 | static void init_memory(struct isp1760_hcd *priv) |
187 | { | 247 | { |
188 | int i; | 248 | int i, curr; |
189 | u32 payload; | 249 | u32 payload_addr; |
190 | 250 | ||
191 | payload = 0x1000; | 251 | payload_addr = PAYLOAD_OFFSET; |
192 | for (i = 0; i < BLOCK_1_NUM; i++) { | 252 | for (i = 0; i < BLOCK_1_NUM; i++) { |
193 | priv->memory_pool[i].start = payload; | 253 | priv->memory_pool[i].start = payload_addr; |
194 | priv->memory_pool[i].size = BLOCK_1_SIZE; | 254 | priv->memory_pool[i].size = BLOCK_1_SIZE; |
195 | priv->memory_pool[i].free = 1; | 255 | priv->memory_pool[i].free = 1; |
196 | payload += priv->memory_pool[i].size; | 256 | payload_addr += priv->memory_pool[i].size; |
197 | } | 257 | } |
198 | 258 | ||
199 | 259 | curr = i; | |
200 | for (i = BLOCK_1_NUM; i < BLOCK_1_NUM + BLOCK_2_NUM; i++) { | 260 | for (i = 0; i < BLOCK_2_NUM; i++) { |
201 | priv->memory_pool[i].start = payload; | 261 | priv->memory_pool[curr + i].start = payload_addr; |
202 | priv->memory_pool[i].size = BLOCK_2_SIZE; | 262 | priv->memory_pool[curr + i].size = BLOCK_2_SIZE; |
203 | priv->memory_pool[i].free = 1; | 263 | priv->memory_pool[curr + i].free = 1; |
204 | payload += priv->memory_pool[i].size; | 264 | payload_addr += priv->memory_pool[curr + i].size; |
205 | } | 265 | } |
206 | 266 | ||
207 | 267 | curr = i; | |
208 | for (i = BLOCK_1_NUM + BLOCK_2_NUM; i < BLOCKS; i++) { | 268 | for (i = 0; i < BLOCK_3_NUM; i++) { |
209 | priv->memory_pool[i].start = payload; | 269 | priv->memory_pool[curr + i].start = payload_addr; |
210 | priv->memory_pool[i].size = BLOCK_3_SIZE; | 270 | priv->memory_pool[curr + i].size = BLOCK_3_SIZE; |
211 | priv->memory_pool[i].free = 1; | 271 | priv->memory_pool[curr + i].free = 1; |
212 | payload += priv->memory_pool[i].size; | 272 | payload_addr += priv->memory_pool[curr + i].size; |
213 | } | 273 | } |
214 | 274 | ||
215 | BUG_ON(payload - priv->memory_pool[i - 1].size > PAYLOAD_SIZE); | 275 | BUG_ON(payload_addr - priv->memory_pool[0].start > PAYLOAD_AREA_SIZE); |
216 | } | 276 | } |
217 | 277 | ||
218 | static u32 alloc_mem(struct isp1760_hcd *priv, u32 size) | 278 | static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
219 | { | 279 | { |
280 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
220 | int i; | 281 | int i; |
221 | 282 | ||
222 | if (!size) | 283 | BUG_ON(qtd->payload_addr); |
223 | return ISP1760_NULL_POINTER; | 284 | |
285 | if (!qtd->length) | ||
286 | return; | ||
224 | 287 | ||
225 | for (i = 0; i < BLOCKS; i++) { | 288 | for (i = 0; i < BLOCKS; i++) { |
226 | if (priv->memory_pool[i].size >= size && | 289 | if (priv->memory_pool[i].size >= qtd->length && |
227 | priv->memory_pool[i].free) { | 290 | priv->memory_pool[i].free) { |
228 | |||
229 | priv->memory_pool[i].free = 0; | 291 | priv->memory_pool[i].free = 0; |
230 | return priv->memory_pool[i].start; | 292 | qtd->payload_addr = priv->memory_pool[i].start; |
293 | return; | ||
231 | } | 294 | } |
232 | } | 295 | } |
233 | 296 | ||
234 | printk(KERN_ERR "ISP1760 MEM: can not allocate %d bytes of memory\n", | 297 | dev_err(hcd->self.controller, |
235 | size); | 298 | "%s: Can not allocate %lu bytes of memory\n" |
236 | printk(KERN_ERR "Current memory map:\n"); | 299 | "Current memory map:\n", |
300 | __func__, qtd->length); | ||
237 | for (i = 0; i < BLOCKS; i++) { | 301 | for (i = 0; i < BLOCKS; i++) { |
238 | printk(KERN_ERR "Pool %2d size %4d status: %d\n", | 302 | dev_err(hcd->self.controller, "Pool %2d size %4d status: %d\n", |
239 | i, priv->memory_pool[i].size, | 303 | i, priv->memory_pool[i].size, |
240 | priv->memory_pool[i].free); | 304 | priv->memory_pool[i].free); |
241 | } | 305 | } |
242 | /* XXX maybe -ENOMEM could be possible */ | 306 | /* XXX maybe -ENOMEM could be possible */ |
243 | BUG(); | 307 | BUG(); |
244 | return 0; | 308 | return; |
245 | } | 309 | } |
246 | 310 | ||
247 | static void free_mem(struct isp1760_hcd *priv, u32 mem) | 311 | static void free_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
248 | { | 312 | { |
313 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
249 | int i; | 314 | int i; |
250 | 315 | ||
251 | if (mem == ISP1760_NULL_POINTER) | 316 | if (!qtd->payload_addr) |
252 | return; | 317 | return; |
253 | 318 | ||
254 | for (i = 0; i < BLOCKS; i++) { | 319 | for (i = 0; i < BLOCKS; i++) { |
255 | if (priv->memory_pool[i].start == mem) { | 320 | if (priv->memory_pool[i].start == qtd->payload_addr) { |
256 | |||
257 | BUG_ON(priv->memory_pool[i].free); | 321 | BUG_ON(priv->memory_pool[i].free); |
258 | |||
259 | priv->memory_pool[i].free = 1; | 322 | priv->memory_pool[i].free = 1; |
260 | return ; | 323 | qtd->payload_addr = 0; |
324 | return; | ||
261 | } | 325 | } |
262 | } | 326 | } |
263 | 327 | ||
264 | printk(KERN_ERR "Trying to free not-here-allocated memory :%08x\n", | 328 | dev_err(hcd->self.controller, "%s: Invalid pointer: %08x\n", |
265 | mem); | 329 | __func__, qtd->payload_addr); |
266 | BUG(); | 330 | BUG(); |
267 | } | 331 | } |
268 | 332 | ||
269 | static void isp1760_init_regs(struct usb_hcd *hcd) | 333 | static void isp1760_init_regs(struct usb_hcd *hcd) |
270 | { | 334 | { |
271 | isp1760_writel(0, hcd->regs + HC_BUFFER_STATUS_REG); | 335 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 0); |
272 | isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + | 336 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
273 | HC_ATL_PTD_SKIPMAP_REG); | 337 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
274 | isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + | 338 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, NO_TRANSFER_ACTIVE); |
275 | HC_INT_PTD_SKIPMAP_REG); | 339 | |
276 | isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs + | 340 | reg_write32(hcd->regs, HC_ATL_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); |
277 | HC_ISO_PTD_SKIPMAP_REG); | 341 | reg_write32(hcd->regs, HC_INT_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); |
278 | 342 | reg_write32(hcd->regs, HC_ISO_PTD_DONEMAP_REG, ~NO_TRANSFER_ACTIVE); | |
279 | isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs + | ||
280 | HC_ATL_PTD_DONEMAP_REG); | ||
281 | isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs + | ||
282 | HC_INT_PTD_DONEMAP_REG); | ||
283 | isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs + | ||
284 | HC_ISO_PTD_DONEMAP_REG); | ||
285 | } | 343 | } |
286 | 344 | ||
287 | static int handshake(struct isp1760_hcd *priv, void __iomem *ptr, | 345 | static int handshake(struct usb_hcd *hcd, u32 reg, |
288 | u32 mask, u32 done, int usec) | 346 | u32 mask, u32 done, int usec) |
289 | { | 347 | { |
290 | u32 result; | 348 | u32 result; |
291 | 349 | ||
292 | do { | 350 | do { |
293 | result = isp1760_readl(ptr); | 351 | result = reg_read32(hcd->regs, reg); |
294 | if (result == ~0) | 352 | if (result == ~0) |
295 | return -ENODEV; | 353 | return -ENODEV; |
296 | result &= mask; | 354 | result &= mask; |
@@ -303,17 +361,18 @@ static int handshake(struct isp1760_hcd *priv, void __iomem *ptr, | |||
303 | } | 361 | } |
304 | 362 | ||
305 | /* reset a non-running (STS_HALT == 1) controller */ | 363 | /* reset a non-running (STS_HALT == 1) controller */ |
306 | static int ehci_reset(struct isp1760_hcd *priv) | 364 | static int ehci_reset(struct usb_hcd *hcd) |
307 | { | 365 | { |
308 | int retval; | 366 | int retval; |
309 | struct usb_hcd *hcd = priv_to_hcd(priv); | 367 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
310 | u32 command = isp1760_readl(hcd->regs + HC_USBCMD); | 368 | |
369 | u32 command = reg_read32(hcd->regs, HC_USBCMD); | ||
311 | 370 | ||
312 | command |= CMD_RESET; | 371 | command |= CMD_RESET; |
313 | isp1760_writel(command, hcd->regs + HC_USBCMD); | 372 | reg_write32(hcd->regs, HC_USBCMD, command); |
314 | hcd->state = HC_STATE_HALT; | 373 | hcd->state = HC_STATE_HALT; |
315 | priv->next_statechange = jiffies; | 374 | priv->next_statechange = jiffies; |
316 | retval = handshake(priv, hcd->regs + HC_USBCMD, | 375 | retval = handshake(hcd, HC_USBCMD, |
317 | CMD_RESET, 0, 250 * 1000); | 376 | CMD_RESET, 0, 250 * 1000); |
318 | return retval; | 377 | return retval; |
319 | } | 378 | } |
@@ -324,8 +383,7 @@ static void qh_destroy(struct isp1760_qh *qh) | |||
324 | kmem_cache_free(qh_cachep, qh); | 383 | kmem_cache_free(qh_cachep, qh); |
325 | } | 384 | } |
326 | 385 | ||
327 | static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv, | 386 | static struct isp1760_qh *isp1760_qh_alloc(gfp_t flags) |
328 | gfp_t flags) | ||
329 | { | 387 | { |
330 | struct isp1760_qh *qh; | 388 | struct isp1760_qh *qh; |
331 | 389 | ||
@@ -334,7 +392,6 @@ static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv, | |||
334 | return qh; | 392 | return qh; |
335 | 393 | ||
336 | INIT_LIST_HEAD(&qh->qtd_list); | 394 | INIT_LIST_HEAD(&qh->qtd_list); |
337 | qh->priv = priv; | ||
338 | return qh; | 395 | return qh; |
339 | } | 396 | } |
340 | 397 | ||
@@ -361,7 +418,7 @@ static int priv_init(struct usb_hcd *hcd) | |||
361 | priv->periodic_size = DEFAULT_I_TDPS; | 418 | priv->periodic_size = DEFAULT_I_TDPS; |
362 | 419 | ||
363 | /* controllers may cache some of the periodic schedule ... */ | 420 | /* controllers may cache some of the periodic schedule ... */ |
364 | hcc_params = isp1760_readl(hcd->regs + HC_HCCPARAMS); | 421 | hcc_params = reg_read32(hcd->regs, HC_HCCPARAMS); |
365 | /* full frame cache */ | 422 | /* full frame cache */ |
366 | if (HCC_ISOC_CACHE(hcc_params)) | 423 | if (HCC_ISOC_CACHE(hcc_params)) |
367 | priv->i_thresh = 8; | 424 | priv->i_thresh = 8; |
@@ -398,15 +455,15 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
398 | * Write it twice to ensure correct upper bits if switching | 455 | * Write it twice to ensure correct upper bits if switching |
399 | * to 16-bit mode. | 456 | * to 16-bit mode. |
400 | */ | 457 | */ |
401 | isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); | 458 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
402 | isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); | 459 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
403 | 460 | ||
404 | isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG); | 461 | reg_write32(hcd->regs, HC_SCRATCH_REG, 0xdeadbabe); |
405 | /* Change bus pattern */ | 462 | /* Change bus pattern */ |
406 | scratch = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); | 463 | scratch = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
407 | scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG); | 464 | scratch = reg_read32(hcd->regs, HC_SCRATCH_REG); |
408 | if (scratch != 0xdeadbabe) { | 465 | if (scratch != 0xdeadbabe) { |
409 | printk(KERN_ERR "ISP1760: Scratch test failed.\n"); | 466 | dev_err(hcd->self.controller, "Scratch test failed.\n"); |
410 | return -ENODEV; | 467 | return -ENODEV; |
411 | } | 468 | } |
412 | 469 | ||
@@ -414,30 +471,30 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
414 | isp1760_init_regs(hcd); | 471 | isp1760_init_regs(hcd); |
415 | 472 | ||
416 | /* reset */ | 473 | /* reset */ |
417 | isp1760_writel(SW_RESET_RESET_ALL, hcd->regs + HC_RESET_REG); | 474 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_ALL); |
418 | mdelay(100); | 475 | mdelay(100); |
419 | 476 | ||
420 | isp1760_writel(SW_RESET_RESET_HC, hcd->regs + HC_RESET_REG); | 477 | reg_write32(hcd->regs, HC_RESET_REG, SW_RESET_RESET_HC); |
421 | mdelay(100); | 478 | mdelay(100); |
422 | 479 | ||
423 | result = ehci_reset(priv); | 480 | result = ehci_reset(hcd); |
424 | if (result) | 481 | if (result) |
425 | return result; | 482 | return result; |
426 | 483 | ||
427 | /* Step 11 passed */ | 484 | /* Step 11 passed */ |
428 | 485 | ||
429 | isp1760_info(priv, "bus width: %d, oc: %s\n", | 486 | dev_info(hcd->self.controller, "bus width: %d, oc: %s\n", |
430 | (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? | 487 | (priv->devflags & ISP1760_FLAG_BUS_WIDTH_16) ? |
431 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? | 488 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? |
432 | "analog" : "digital"); | 489 | "analog" : "digital"); |
433 | 490 | ||
434 | /* ATL reset */ | 491 | /* ATL reset */ |
435 | isp1760_writel(hwmode | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL); | 492 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); |
436 | mdelay(10); | 493 | mdelay(10); |
437 | isp1760_writel(hwmode, hcd->regs + HC_HW_MODE_CTRL); | 494 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode); |
438 | 495 | ||
439 | isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG); | 496 | reg_write32(hcd->regs, HC_INTERRUPT_REG, INTERRUPT_ENABLE_MASK); |
440 | isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE); | 497 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, INTERRUPT_ENABLE_MASK); |
441 | 498 | ||
442 | /* | 499 | /* |
443 | * PORT 1 Control register of the ISP1760 is the OTG control | 500 | * PORT 1 Control register of the ISP1760 is the OTG control |
@@ -445,11 +502,10 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
445 | * support in this driver, we use port 1 as a "normal" USB host port on | 502 | * support in this driver, we use port 1 as a "normal" USB host port on |
446 | * both chips. | 503 | * both chips. |
447 | */ | 504 | */ |
448 | isp1760_writel(PORT1_POWER | PORT1_INIT2, | 505 | reg_write32(hcd->regs, HC_PORT1_CTRL, PORT1_POWER | PORT1_INIT2); |
449 | hcd->regs + HC_PORT1_CTRL); | ||
450 | mdelay(10); | 506 | mdelay(10); |
451 | 507 | ||
452 | priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS); | 508 | priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS); |
453 | 509 | ||
454 | return priv_init(hcd); | 510 | return priv_init(hcd); |
455 | } | 511 | } |
@@ -457,25 +513,24 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
457 | static void isp1760_init_maps(struct usb_hcd *hcd) | 513 | static void isp1760_init_maps(struct usb_hcd *hcd) |
458 | { | 514 | { |
459 | /*set last maps, for iso its only 1, else 32 tds bitmap*/ | 515 | /*set last maps, for iso its only 1, else 32 tds bitmap*/ |
460 | isp1760_writel(0x80000000, hcd->regs + HC_ATL_PTD_LASTPTD_REG); | 516 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); |
461 | isp1760_writel(0x80000000, hcd->regs + HC_INT_PTD_LASTPTD_REG); | 517 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); |
462 | isp1760_writel(0x00000001, hcd->regs + HC_ISO_PTD_LASTPTD_REG); | 518 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); |
463 | } | 519 | } |
464 | 520 | ||
465 | static void isp1760_enable_interrupts(struct usb_hcd *hcd) | 521 | static void isp1760_enable_interrupts(struct usb_hcd *hcd) |
466 | { | 522 | { |
467 | isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_AND_REG); | 523 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); |
468 | isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_OR_REG); | 524 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0); |
469 | isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_AND_REG); | 525 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); |
470 | isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_OR_REG); | 526 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0); |
471 | isp1760_writel(0, hcd->regs + HC_ISO_IRQ_MASK_AND_REG); | 527 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); |
472 | isp1760_writel(0xffffffff, hcd->regs + HC_ISO_IRQ_MASK_OR_REG); | 528 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); |
473 | /* step 23 passed */ | 529 | /* step 23 passed */ |
474 | } | 530 | } |
475 | 531 | ||
476 | static int isp1760_run(struct usb_hcd *hcd) | 532 | static int isp1760_run(struct usb_hcd *hcd) |
477 | { | 533 | { |
478 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
479 | int retval; | 534 | int retval; |
480 | u32 temp; | 535 | u32 temp; |
481 | u32 command; | 536 | u32 command; |
@@ -485,15 +540,15 @@ static int isp1760_run(struct usb_hcd *hcd) | |||
485 | 540 | ||
486 | hcd->state = HC_STATE_RUNNING; | 541 | hcd->state = HC_STATE_RUNNING; |
487 | isp1760_enable_interrupts(hcd); | 542 | isp1760_enable_interrupts(hcd); |
488 | temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); | 543 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
489 | isp1760_writel(temp | HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); | 544 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); |
490 | 545 | ||
491 | command = isp1760_readl(hcd->regs + HC_USBCMD); | 546 | command = reg_read32(hcd->regs, HC_USBCMD); |
492 | command &= ~(CMD_LRESET|CMD_RESET); | 547 | command &= ~(CMD_LRESET|CMD_RESET); |
493 | command |= CMD_RUN; | 548 | command |= CMD_RUN; |
494 | isp1760_writel(command, hcd->regs + HC_USBCMD); | 549 | reg_write32(hcd->regs, HC_USBCMD, command); |
495 | 550 | ||
496 | retval = handshake(priv, hcd->regs + HC_USBCMD, CMD_RUN, CMD_RUN, | 551 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, |
497 | 250 * 1000); | 552 | 250 * 1000); |
498 | if (retval) | 553 | if (retval) |
499 | return retval; | 554 | return retval; |
@@ -504,17 +559,16 @@ static int isp1760_run(struct usb_hcd *hcd) | |||
504 | * the semaphore while doing so. | 559 | * the semaphore while doing so. |
505 | */ | 560 | */ |
506 | down_write(&ehci_cf_port_reset_rwsem); | 561 | down_write(&ehci_cf_port_reset_rwsem); |
507 | isp1760_writel(FLAG_CF, hcd->regs + HC_CONFIGFLAG); | 562 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); |
508 | 563 | ||
509 | retval = handshake(priv, hcd->regs + HC_CONFIGFLAG, FLAG_CF, FLAG_CF, | 564 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); |
510 | 250 * 1000); | ||
511 | up_write(&ehci_cf_port_reset_rwsem); | 565 | up_write(&ehci_cf_port_reset_rwsem); |
512 | if (retval) | 566 | if (retval) |
513 | return retval; | 567 | return retval; |
514 | 568 | ||
515 | chipid = isp1760_readl(hcd->regs + HC_CHIP_ID_REG); | 569 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); |
516 | isp1760_info(priv, "USB ISP %04x HW rev. %d started\n", chipid & 0xffff, | 570 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", |
517 | chipid >> 16); | 571 | chipid & 0xffff, chipid >> 16); |
518 | 572 | ||
519 | /* PTD Register Init Part 2, Step 28 */ | 573 | /* PTD Register Init Part 2, Step 28 */ |
520 | /* enable INTs */ | 574 | /* enable INTs */ |
@@ -532,160 +586,156 @@ static u32 base_to_chip(u32 base) | |||
532 | return ((base - 0x400) >> 3); | 586 | return ((base - 0x400) >> 3); |
533 | } | 587 | } |
534 | 588 | ||
535 | static void transform_into_atl(struct isp1760_hcd *priv, struct isp1760_qh *qh, | 589 | static int last_qtd_of_urb(struct isp1760_qtd *qtd, struct isp1760_qh *qh) |
536 | struct isp1760_qtd *qtd, struct urb *urb, | 590 | { |
537 | u32 payload, struct ptd *ptd) | 591 | struct urb *urb; |
592 | |||
593 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) | ||
594 | return 1; | ||
595 | |||
596 | urb = qtd->urb; | ||
597 | qtd = list_entry(qtd->qtd_list.next, typeof(*qtd), qtd_list); | ||
598 | return (qtd->urb != urb); | ||
599 | } | ||
600 | |||
601 | static void transform_into_atl(struct isp1760_qh *qh, | ||
602 | struct isp1760_qtd *qtd, struct ptd *ptd) | ||
538 | { | 603 | { |
539 | u32 dw0; | ||
540 | u32 dw1; | ||
541 | u32 dw2; | ||
542 | u32 dw3; | ||
543 | u32 maxpacket; | 604 | u32 maxpacket; |
544 | u32 multi; | 605 | u32 multi; |
545 | u32 pid_code; | 606 | u32 pid_code; |
546 | u32 rl = RL_COUNTER; | 607 | u32 rl = RL_COUNTER; |
547 | u32 nak = NAK_COUNTER; | 608 | u32 nak = NAK_COUNTER; |
548 | 609 | ||
610 | memset(ptd, 0, sizeof(*ptd)); | ||
611 | |||
549 | /* according to 3.6.2, max packet len can not be > 0x400 */ | 612 | /* according to 3.6.2, max packet len can not be > 0x400 */ |
550 | maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | 613 | maxpacket = usb_maxpacket(qtd->urb->dev, qtd->urb->pipe, |
614 | usb_pipeout(qtd->urb->pipe)); | ||
551 | multi = 1 + ((maxpacket >> 11) & 0x3); | 615 | multi = 1 + ((maxpacket >> 11) & 0x3); |
552 | maxpacket &= 0x7ff; | 616 | maxpacket &= 0x7ff; |
553 | 617 | ||
554 | /* DW0 */ | 618 | /* DW0 */ |
555 | dw0 = PTD_VALID; | 619 | ptd->dw0 = PTD_VALID; |
556 | dw0 |= PTD_LENGTH(qtd->length); | 620 | ptd->dw0 |= PTD_LENGTH(qtd->length); |
557 | dw0 |= PTD_MAXPACKET(maxpacket); | 621 | ptd->dw0 |= PTD_MAXPACKET(maxpacket); |
558 | dw0 |= PTD_ENDPOINT(usb_pipeendpoint(urb->pipe)); | 622 | ptd->dw0 |= PTD_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe)); |
559 | dw1 = usb_pipeendpoint(urb->pipe) >> 1; | ||
560 | 623 | ||
561 | /* DW1 */ | 624 | /* DW1 */ |
562 | dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(urb->pipe)); | 625 | ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1; |
626 | ptd->dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe)); | ||
563 | 627 | ||
564 | pid_code = qtd->packet_type; | 628 | pid_code = qtd->packet_type; |
565 | dw1 |= PTD_PID_TOKEN(pid_code); | 629 | ptd->dw1 |= PTD_PID_TOKEN(pid_code); |
566 | 630 | ||
567 | if (usb_pipebulk(urb->pipe)) | 631 | if (usb_pipebulk(qtd->urb->pipe)) |
568 | dw1 |= PTD_TRANS_BULK; | 632 | ptd->dw1 |= PTD_TRANS_BULK; |
569 | else if (usb_pipeint(urb->pipe)) | 633 | else if (usb_pipeint(qtd->urb->pipe)) |
570 | dw1 |= PTD_TRANS_INT; | 634 | ptd->dw1 |= PTD_TRANS_INT; |
571 | 635 | ||
572 | if (urb->dev->speed != USB_SPEED_HIGH) { | 636 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) { |
573 | /* split transaction */ | 637 | /* split transaction */ |
574 | 638 | ||
575 | dw1 |= PTD_TRANS_SPLIT; | 639 | ptd->dw1 |= PTD_TRANS_SPLIT; |
576 | if (urb->dev->speed == USB_SPEED_LOW) | 640 | if (qtd->urb->dev->speed == USB_SPEED_LOW) |
577 | dw1 |= PTD_SE_USB_LOSPEED; | 641 | ptd->dw1 |= PTD_SE_USB_LOSPEED; |
578 | 642 | ||
579 | dw1 |= PTD_PORT_NUM(urb->dev->ttport); | 643 | ptd->dw1 |= PTD_PORT_NUM(qtd->urb->dev->ttport); |
580 | dw1 |= PTD_HUB_NUM(urb->dev->tt->hub->devnum); | 644 | ptd->dw1 |= PTD_HUB_NUM(qtd->urb->dev->tt->hub->devnum); |
581 | 645 | ||
582 | /* SE bit for Split INT transfers */ | 646 | /* SE bit for Split INT transfers */ |
583 | if (usb_pipeint(urb->pipe) && | 647 | if (usb_pipeint(qtd->urb->pipe) && |
584 | (urb->dev->speed == USB_SPEED_LOW)) | 648 | (qtd->urb->dev->speed == USB_SPEED_LOW)) |
585 | dw1 |= 2 << 16; | 649 | ptd->dw1 |= 2 << 16; |
586 | 650 | ||
587 | dw3 = 0; | 651 | ptd->dw3 = 0; |
588 | rl = 0; | 652 | rl = 0; |
589 | nak = 0; | 653 | nak = 0; |
590 | } else { | 654 | } else { |
591 | dw0 |= PTD_MULTI(multi); | 655 | ptd->dw0 |= PTD_MULTI(multi); |
592 | if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe)) | 656 | if (usb_pipecontrol(qtd->urb->pipe) || |
593 | dw3 = qh->ping; | 657 | usb_pipebulk(qtd->urb->pipe)) |
658 | ptd->dw3 = qh->ping; | ||
594 | else | 659 | else |
595 | dw3 = 0; | 660 | ptd->dw3 = 0; |
596 | } | 661 | } |
597 | /* DW2 */ | 662 | /* DW2 */ |
598 | dw2 = 0; | 663 | ptd->dw2 = 0; |
599 | dw2 |= PTD_DATA_START_ADDR(base_to_chip(payload)); | 664 | ptd->dw2 |= PTD_DATA_START_ADDR(base_to_chip(qtd->payload_addr)); |
600 | dw2 |= PTD_RL_CNT(rl); | 665 | ptd->dw2 |= PTD_RL_CNT(rl); |
601 | dw3 |= PTD_NAC_CNT(nak); | 666 | ptd->dw3 |= PTD_NAC_CNT(nak); |
602 | 667 | ||
603 | /* DW3 */ | 668 | /* DW3 */ |
604 | if (usb_pipecontrol(urb->pipe)) | 669 | ptd->dw3 |= qh->toggle; |
605 | dw3 |= PTD_DATA_TOGGLE(qtd->toggle); | 670 | if (usb_pipecontrol(qtd->urb->pipe)) { |
606 | else | 671 | if (qtd->data_buffer == qtd->urb->setup_packet) |
607 | dw3 |= qh->toggle; | 672 | ptd->dw3 &= ~PTD_DATA_TOGGLE(1); |
608 | 673 | else if (last_qtd_of_urb(qtd, qh)) | |
674 | ptd->dw3 |= PTD_DATA_TOGGLE(1); | ||
675 | } | ||
609 | 676 | ||
610 | dw3 |= PTD_ACTIVE; | 677 | ptd->dw3 |= PTD_ACTIVE; |
611 | /* Cerr */ | 678 | /* Cerr */ |
612 | dw3 |= PTD_CERR(ERR_COUNTER); | 679 | ptd->dw3 |= PTD_CERR(ERR_COUNTER); |
613 | |||
614 | memset(ptd, 0, sizeof(*ptd)); | ||
615 | |||
616 | ptd->dw0 = cpu_to_le32(dw0); | ||
617 | ptd->dw1 = cpu_to_le32(dw1); | ||
618 | ptd->dw2 = cpu_to_le32(dw2); | ||
619 | ptd->dw3 = cpu_to_le32(dw3); | ||
620 | } | 680 | } |
621 | 681 | ||
622 | static void transform_add_int(struct isp1760_hcd *priv, struct isp1760_qh *qh, | 682 | static void transform_add_int(struct isp1760_qh *qh, |
623 | struct isp1760_qtd *qtd, struct urb *urb, | 683 | struct isp1760_qtd *qtd, struct ptd *ptd) |
624 | u32 payload, struct ptd *ptd) | ||
625 | { | 684 | { |
626 | u32 maxpacket; | 685 | u32 usof; |
627 | u32 multi; | ||
628 | u32 numberofusofs; | ||
629 | u32 i; | ||
630 | u32 usofmask, usof; | ||
631 | u32 period; | 686 | u32 period; |
632 | 687 | ||
633 | maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); | 688 | /* |
634 | multi = 1 + ((maxpacket >> 11) & 0x3); | 689 | * Most of this is guessing. ISP1761 datasheet is quite unclear, and |
635 | maxpacket &= 0x7ff; | 690 | * the algorithm from the original Philips driver code, which was |
636 | /* length of the data per uframe */ | 691 | * pretty much used in this driver before as well, is quite horrendous |
637 | maxpacket = multi * maxpacket; | 692 | * and, i believe, incorrect. The code below follows the datasheet and |
638 | 693 | * USB2.0 spec as far as I can tell, and plug/unplug seems to be much | |
639 | numberofusofs = urb->transfer_buffer_length / maxpacket; | 694 | * more reliable this way (fingers crossed...). |
640 | if (urb->transfer_buffer_length % maxpacket) | 695 | */ |
641 | numberofusofs += 1; | ||
642 | |||
643 | usofmask = 1; | ||
644 | usof = 0; | ||
645 | for (i = 0; i < numberofusofs; i++) { | ||
646 | usof |= usofmask; | ||
647 | usofmask <<= 1; | ||
648 | } | ||
649 | |||
650 | if (urb->dev->speed != USB_SPEED_HIGH) { | ||
651 | /* split */ | ||
652 | ptd->dw5 = cpu_to_le32(0x1c); | ||
653 | 696 | ||
654 | if (qh->period >= 32) | 697 | if (qtd->urb->dev->speed == USB_SPEED_HIGH) { |
655 | period = qh->period / 2; | 698 | /* urb->interval is in units of microframes (1/8 ms) */ |
699 | period = qtd->urb->interval >> 3; | ||
700 | |||
701 | if (qtd->urb->interval > 4) | ||
702 | usof = 0x01; /* One bit set => | ||
703 | interval 1 ms * uFrame-match */ | ||
704 | else if (qtd->urb->interval > 2) | ||
705 | usof = 0x22; /* Two bits set => interval 1/2 ms */ | ||
706 | else if (qtd->urb->interval > 1) | ||
707 | usof = 0x55; /* Four bits set => interval 1/4 ms */ | ||
656 | else | 708 | else |
657 | period = qh->period; | 709 | usof = 0xff; /* All bits set => interval 1/8 ms */ |
658 | |||
659 | } else { | 710 | } else { |
711 | /* urb->interval is in units of frames (1 ms) */ | ||
712 | period = qtd->urb->interval; | ||
713 | usof = 0x0f; /* Execute Start Split on any of the | ||
714 | four first uFrames */ | ||
660 | 715 | ||
661 | if (qh->period >= 8) | 716 | /* |
662 | period = qh->period/8; | 717 | * First 8 bits in dw5 is uSCS and "specifies which uSOF the |
663 | else | 718 | * complete split needs to be sent. Valid only for IN." Also, |
664 | period = qh->period; | 719 | * "All bits can be set to one for every transfer." (p 82, |
665 | 720 | * ISP1761 data sheet.) 0x1c is from Philips driver. Where did | |
666 | if (period >= 32) | 721 | * that number come from? 0xff seems to work fine... |
667 | period = 16; | 722 | */ |
668 | 723 | /* ptd->dw5 = 0x1c; */ | |
669 | if (qh->period >= 8) { | 724 | ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */ |
670 | /* millisecond period */ | ||
671 | period = (period << 3); | ||
672 | } else { | ||
673 | /* usof based tranmsfers */ | ||
674 | /* minimum 4 usofs */ | ||
675 | usof = 0x11; | ||
676 | } | ||
677 | } | 725 | } |
678 | 726 | ||
679 | ptd->dw2 |= cpu_to_le32(period); | 727 | period = period >> 1;/* Ensure equal or shorter period than requested */ |
680 | ptd->dw4 = cpu_to_le32(usof); | 728 | period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */ |
729 | |||
730 | ptd->dw2 |= period; | ||
731 | ptd->dw4 = usof; | ||
681 | } | 732 | } |
682 | 733 | ||
683 | static void transform_into_int(struct isp1760_hcd *priv, struct isp1760_qh *qh, | 734 | static void transform_into_int(struct isp1760_qh *qh, |
684 | struct isp1760_qtd *qtd, struct urb *urb, | 735 | struct isp1760_qtd *qtd, struct ptd *ptd) |
685 | u32 payload, struct ptd *ptd) | ||
686 | { | 736 | { |
687 | transform_into_atl(priv, qh, qtd, urb, payload, ptd); | 737 | transform_into_atl(qh, qtd, ptd); |
688 | transform_add_int(priv, qh, qtd, urb, payload, ptd); | 738 | transform_add_int(qh, qtd, ptd); |
689 | } | 739 | } |
690 | 740 | ||
691 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, | 741 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, |
@@ -695,10 +745,9 @@ static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, | |||
695 | 745 | ||
696 | qtd->data_buffer = databuffer; | 746 | qtd->data_buffer = databuffer; |
697 | qtd->packet_type = GET_QTD_TOKEN_TYPE(token); | 747 | qtd->packet_type = GET_QTD_TOKEN_TYPE(token); |
698 | qtd->toggle = GET_DATA_TOGGLE(token); | ||
699 | 748 | ||
700 | if (len > HC_ATL_PL_SIZE) | 749 | if (len > MAX_PAYLOAD_SIZE) |
701 | count = HC_ATL_PL_SIZE; | 750 | count = MAX_PAYLOAD_SIZE; |
702 | else | 751 | else |
703 | count = len; | 752 | count = len; |
704 | 753 | ||
@@ -706,29 +755,27 @@ static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len, | |||
706 | return count; | 755 | return count; |
707 | } | 756 | } |
708 | 757 | ||
709 | static int check_error(struct ptd *ptd) | 758 | static int check_error(struct usb_hcd *hcd, struct ptd *ptd) |
710 | { | 759 | { |
711 | int error = 0; | 760 | int error = 0; |
712 | u32 dw3; | ||
713 | 761 | ||
714 | dw3 = le32_to_cpu(ptd->dw3); | 762 | if (ptd->dw3 & DW3_HALT_BIT) { |
715 | if (dw3 & DW3_HALT_BIT) { | ||
716 | error = -EPIPE; | 763 | error = -EPIPE; |
717 | 764 | ||
718 | if (dw3 & DW3_ERROR_BIT) | 765 | if (ptd->dw3 & DW3_ERROR_BIT) |
719 | pr_err("error bit is set in DW3\n"); | 766 | pr_err("error bit is set in DW3\n"); |
720 | } | 767 | } |
721 | 768 | ||
722 | if (dw3 & DW3_QTD_ACTIVE) { | 769 | if (ptd->dw3 & DW3_QTD_ACTIVE) { |
723 | printk(KERN_ERR "transfer active bit is set DW3\n"); | 770 | dev_err(hcd->self.controller, "Transfer active bit is set DW3\n" |
724 | printk(KERN_ERR "nak counter: %d, rl: %d\n", (dw3 >> 19) & 0xf, | 771 | "nak counter: %d, rl: %d\n", |
725 | (le32_to_cpu(ptd->dw2) >> 25) & 0xf); | 772 | (ptd->dw3 >> 19) & 0xf, (ptd->dw2 >> 25) & 0xf); |
726 | } | 773 | } |
727 | 774 | ||
728 | return error; | 775 | return error; |
729 | } | 776 | } |
730 | 777 | ||
731 | static void check_int_err_status(u32 dw4) | 778 | static void check_int_err_status(struct usb_hcd *hcd, u32 dw4) |
732 | { | 779 | { |
733 | u32 i; | 780 | u32 i; |
734 | 781 | ||
@@ -737,79 +784,67 @@ static void check_int_err_status(u32 dw4) | |||
737 | for (i = 0; i < 8; i++) { | 784 | for (i = 0; i < 8; i++) { |
738 | switch (dw4 & 0x7) { | 785 | switch (dw4 & 0x7) { |
739 | case INT_UNDERRUN: | 786 | case INT_UNDERRUN: |
740 | printk(KERN_ERR "ERROR: under run , %d\n", i); | 787 | dev_err(hcd->self.controller, "Underrun (%d)\n", i); |
741 | break; | 788 | break; |
742 | 789 | ||
743 | case INT_EXACT: | 790 | case INT_EXACT: |
744 | printk(KERN_ERR "ERROR: transaction error, %d\n", i); | 791 | dev_err(hcd->self.controller, |
792 | "Transaction error (%d)\n", i); | ||
745 | break; | 793 | break; |
746 | 794 | ||
747 | case INT_BABBLE: | 795 | case INT_BABBLE: |
748 | printk(KERN_ERR "ERROR: babble error, %d\n", i); | 796 | dev_err(hcd->self.controller, "Babble error (%d)\n", i); |
749 | break; | 797 | break; |
750 | } | 798 | } |
751 | dw4 >>= 3; | 799 | dw4 >>= 3; |
752 | } | 800 | } |
753 | } | 801 | } |
754 | 802 | ||
755 | static void enqueue_one_qtd(struct isp1760_qtd *qtd, struct isp1760_hcd *priv, | 803 | static void enqueue_one_qtd(struct usb_hcd *hcd, struct isp1760_qtd *qtd) |
756 | u32 payload) | ||
757 | { | 804 | { |
758 | u32 token; | 805 | if (qtd->length && (qtd->length <= MAX_PAYLOAD_SIZE)) { |
759 | struct usb_hcd *hcd = priv_to_hcd(priv); | 806 | switch (qtd->packet_type) { |
760 | |||
761 | token = qtd->packet_type; | ||
762 | |||
763 | if (qtd->length && (qtd->length <= HC_ATL_PL_SIZE)) { | ||
764 | switch (token) { | ||
765 | case IN_PID: | 807 | case IN_PID: |
766 | break; | 808 | break; |
767 | case OUT_PID: | 809 | case OUT_PID: |
768 | case SETUP_PID: | 810 | case SETUP_PID: |
769 | priv_write_copy(priv, qtd->data_buffer, | 811 | mem_writes8(hcd->regs, qtd->payload_addr, |
770 | hcd->regs + payload, | 812 | qtd->data_buffer, qtd->length); |
771 | qtd->length); | ||
772 | } | 813 | } |
773 | } | 814 | } |
774 | } | 815 | } |
775 | 816 | ||
776 | static void enqueue_one_atl_qtd(u32 atl_regs, u32 payload, | 817 | static void enqueue_one_atl_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, |
777 | struct isp1760_hcd *priv, struct isp1760_qh *qh, | 818 | u32 slot, struct isp1760_qtd *qtd) |
778 | struct urb *urb, u32 slot, struct isp1760_qtd *qtd) | ||
779 | { | 819 | { |
820 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
780 | struct ptd ptd; | 821 | struct ptd ptd; |
781 | struct usb_hcd *hcd = priv_to_hcd(priv); | ||
782 | 822 | ||
783 | transform_into_atl(priv, qh, qtd, urb, payload, &ptd); | 823 | alloc_mem(hcd, qtd); |
784 | priv_write_copy(priv, (u32 *)&ptd, hcd->regs + atl_regs, sizeof(ptd)); | 824 | transform_into_atl(qh, qtd, &ptd); |
785 | enqueue_one_qtd(qtd, priv, payload); | 825 | ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
826 | enqueue_one_qtd(hcd, qtd); | ||
786 | 827 | ||
787 | priv->atl_ints[slot].urb = urb; | ||
788 | priv->atl_ints[slot].qh = qh; | 828 | priv->atl_ints[slot].qh = qh; |
789 | priv->atl_ints[slot].qtd = qtd; | 829 | priv->atl_ints[slot].qtd = qtd; |
790 | priv->atl_ints[slot].data_buffer = qtd->data_buffer; | 830 | qtd->status |= URB_ENQUEUED; |
791 | priv->atl_ints[slot].payload = payload; | ||
792 | qtd->status |= URB_ENQUEUED | URB_TYPE_ATL; | ||
793 | qtd->status |= slot << 16; | 831 | qtd->status |= slot << 16; |
794 | } | 832 | } |
795 | 833 | ||
796 | static void enqueue_one_int_qtd(u32 int_regs, u32 payload, | 834 | static void enqueue_one_int_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, |
797 | struct isp1760_hcd *priv, struct isp1760_qh *qh, | 835 | u32 slot, struct isp1760_qtd *qtd) |
798 | struct urb *urb, u32 slot, struct isp1760_qtd *qtd) | ||
799 | { | 836 | { |
837 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
800 | struct ptd ptd; | 838 | struct ptd ptd; |
801 | struct usb_hcd *hcd = priv_to_hcd(priv); | ||
802 | 839 | ||
803 | transform_into_int(priv, qh, qtd, urb, payload, &ptd); | 840 | alloc_mem(hcd, qtd); |
804 | priv_write_copy(priv, (u32 *)&ptd, hcd->regs + int_regs, sizeof(ptd)); | 841 | transform_into_int(qh, qtd, &ptd); |
805 | enqueue_one_qtd(qtd, priv, payload); | 842 | ptd_write(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
843 | enqueue_one_qtd(hcd, qtd); | ||
806 | 844 | ||
807 | priv->int_ints[slot].urb = urb; | ||
808 | priv->int_ints[slot].qh = qh; | 845 | priv->int_ints[slot].qh = qh; |
809 | priv->int_ints[slot].qtd = qtd; | 846 | priv->int_ints[slot].qtd = qtd; |
810 | priv->int_ints[slot].data_buffer = qtd->data_buffer; | 847 | qtd->status |= URB_ENQUEUED; |
811 | priv->int_ints[slot].payload = payload; | ||
812 | qtd->status |= URB_ENQUEUED | URB_TYPE_INT; | ||
813 | qtd->status |= slot << 16; | 848 | qtd->status |= slot << 16; |
814 | } | 849 | } |
815 | 850 | ||
@@ -818,9 +853,7 @@ static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
818 | { | 853 | { |
819 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 854 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
820 | u32 skip_map, or_map; | 855 | u32 skip_map, or_map; |
821 | u32 queue_entry; | ||
822 | u32 slot; | 856 | u32 slot; |
823 | u32 atl_regs, payload; | ||
824 | u32 buffstatus; | 857 | u32 buffstatus; |
825 | 858 | ||
826 | /* | 859 | /* |
@@ -831,38 +864,35 @@ static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
831 | */ | 864 | */ |
832 | mmiowb(); | 865 | mmiowb(); |
833 | ndelay(195); | 866 | ndelay(195); |
834 | skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG); | 867 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
835 | 868 | ||
836 | BUG_ON(!skip_map); | 869 | BUG_ON(!skip_map); |
837 | slot = __ffs(skip_map); | 870 | slot = __ffs(skip_map); |
838 | queue_entry = 1 << slot; | ||
839 | |||
840 | atl_regs = ATL_REGS_OFFSET + slot * sizeof(struct ptd); | ||
841 | 871 | ||
842 | payload = alloc_mem(priv, qtd->length); | 872 | enqueue_one_atl_qtd(hcd, qh, slot, qtd); |
843 | 873 | ||
844 | enqueue_one_atl_qtd(atl_regs, payload, priv, qh, qtd->urb, slot, qtd); | 874 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
875 | or_map |= (1 << slot); | ||
876 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); | ||
845 | 877 | ||
846 | or_map = isp1760_readl(hcd->regs + HC_ATL_IRQ_MASK_OR_REG); | 878 | skip_map &= ~(1 << slot); |
847 | or_map |= queue_entry; | 879 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
848 | isp1760_writel(or_map, hcd->regs + HC_ATL_IRQ_MASK_OR_REG); | ||
849 | 880 | ||
850 | skip_map &= ~queue_entry; | 881 | priv->atl_queued++; |
851 | isp1760_writel(skip_map, hcd->regs + HC_ATL_PTD_SKIPMAP_REG); | 882 | if (priv->atl_queued == 2) |
883 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, | ||
884 | INTERRUPT_ENABLE_SOT_MASK); | ||
852 | 885 | ||
853 | buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG); | 886 | buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG); |
854 | buffstatus |= ATL_BUFFER; | 887 | buffstatus |= ATL_BUFFER; |
855 | isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG); | 888 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus); |
856 | } | 889 | } |
857 | 890 | ||
858 | static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, | 891 | static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, |
859 | struct isp1760_qtd *qtd) | 892 | struct isp1760_qtd *qtd) |
860 | { | 893 | { |
861 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
862 | u32 skip_map, or_map; | 894 | u32 skip_map, or_map; |
863 | u32 queue_entry; | ||
864 | u32 slot; | 895 | u32 slot; |
865 | u32 int_regs, payload; | ||
866 | u32 buffstatus; | 896 | u32 buffstatus; |
867 | 897 | ||
868 | /* | 898 | /* |
@@ -873,37 +903,34 @@ static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
873 | */ | 903 | */ |
874 | mmiowb(); | 904 | mmiowb(); |
875 | ndelay(195); | 905 | ndelay(195); |
876 | skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG); | 906 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
877 | 907 | ||
878 | BUG_ON(!skip_map); | 908 | BUG_ON(!skip_map); |
879 | slot = __ffs(skip_map); | 909 | slot = __ffs(skip_map); |
880 | queue_entry = 1 << slot; | ||
881 | |||
882 | int_regs = INT_REGS_OFFSET + slot * sizeof(struct ptd); | ||
883 | 910 | ||
884 | payload = alloc_mem(priv, qtd->length); | 911 | enqueue_one_int_qtd(hcd, qh, slot, qtd); |
885 | 912 | ||
886 | enqueue_one_int_qtd(int_regs, payload, priv, qh, qtd->urb, slot, qtd); | 913 | or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG); |
914 | or_map |= (1 << slot); | ||
915 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map); | ||
887 | 916 | ||
888 | or_map = isp1760_readl(hcd->regs + HC_INT_IRQ_MASK_OR_REG); | 917 | skip_map &= ~(1 << slot); |
889 | or_map |= queue_entry; | 918 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
890 | isp1760_writel(or_map, hcd->regs + HC_INT_IRQ_MASK_OR_REG); | ||
891 | 919 | ||
892 | skip_map &= ~queue_entry; | 920 | buffstatus = reg_read32(hcd->regs, HC_BUFFER_STATUS_REG); |
893 | isp1760_writel(skip_map, hcd->regs + HC_INT_PTD_SKIPMAP_REG); | ||
894 | |||
895 | buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG); | ||
896 | buffstatus |= INT_BUFFER; | 921 | buffstatus |= INT_BUFFER; |
897 | isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG); | 922 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, buffstatus); |
898 | } | 923 | } |
899 | 924 | ||
900 | static void isp1760_urb_done(struct isp1760_hcd *priv, struct urb *urb, int status) | 925 | static void isp1760_urb_done(struct usb_hcd *hcd, struct urb *urb) |
901 | __releases(priv->lock) | 926 | __releases(priv->lock) |
902 | __acquires(priv->lock) | 927 | __acquires(priv->lock) |
903 | { | 928 | { |
929 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
930 | |||
904 | if (!urb->unlinked) { | 931 | if (!urb->unlinked) { |
905 | if (status == -EINPROGRESS) | 932 | if (urb->status == -EINPROGRESS) |
906 | status = 0; | 933 | urb->status = 0; |
907 | } | 934 | } |
908 | 935 | ||
909 | if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { | 936 | if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) { |
@@ -915,22 +942,28 @@ __acquires(priv->lock) | |||
915 | } | 942 | } |
916 | 943 | ||
917 | /* complete() can reenter this HCD */ | 944 | /* complete() can reenter this HCD */ |
918 | usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); | 945 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
919 | spin_unlock(&priv->lock); | 946 | spin_unlock(&priv->lock); |
920 | usb_hcd_giveback_urb(priv_to_hcd(priv), urb, status); | 947 | usb_hcd_giveback_urb(hcd, urb, urb->status); |
921 | spin_lock(&priv->lock); | 948 | spin_lock(&priv->lock); |
922 | } | 949 | } |
923 | 950 | ||
924 | static void isp1760_qtd_free(struct isp1760_qtd *qtd) | 951 | static void isp1760_qtd_free(struct isp1760_qtd *qtd) |
925 | { | 952 | { |
953 | BUG_ON(qtd->payload_addr); | ||
926 | kmem_cache_free(qtd_cachep, qtd); | 954 | kmem_cache_free(qtd_cachep, qtd); |
927 | } | 955 | } |
928 | 956 | ||
929 | static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd) | 957 | static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd, |
958 | struct isp1760_qh *qh) | ||
930 | { | 959 | { |
931 | struct isp1760_qtd *tmp_qtd; | 960 | struct isp1760_qtd *tmp_qtd; |
932 | 961 | ||
933 | tmp_qtd = qtd->hw_next; | 962 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) |
963 | tmp_qtd = NULL; | ||
964 | else | ||
965 | tmp_qtd = list_entry(qtd->qtd_list.next, struct isp1760_qtd, | ||
966 | qtd_list); | ||
934 | list_del(&qtd->qtd_list); | 967 | list_del(&qtd->qtd_list); |
935 | isp1760_qtd_free(qtd); | 968 | isp1760_qtd_free(qtd); |
936 | return tmp_qtd; | 969 | return tmp_qtd; |
@@ -941,32 +974,26 @@ static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd) | |||
941 | * isn't the last one than remove also his successor(s). | 974 | * isn't the last one than remove also his successor(s). |
942 | * Returns the QTD which is part of an new URB and should be enqueued. | 975 | * Returns the QTD which is part of an new URB and should be enqueued. |
943 | */ | 976 | */ |
944 | static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd) | 977 | static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd, |
978 | struct isp1760_qh *qh) | ||
945 | { | 979 | { |
946 | struct isp1760_qtd *tmp_qtd; | 980 | struct urb *urb; |
947 | int last_one; | ||
948 | 981 | ||
982 | urb = qtd->urb; | ||
949 | do { | 983 | do { |
950 | tmp_qtd = qtd->hw_next; | 984 | qtd = clean_this_qtd(qtd, qh); |
951 | last_one = qtd->status & URB_COMPLETE_NOTIFY; | 985 | } while (qtd && (qtd->urb == urb)); |
952 | list_del(&qtd->qtd_list); | ||
953 | isp1760_qtd_free(qtd); | ||
954 | qtd = tmp_qtd; | ||
955 | } while (!last_one && qtd); | ||
956 | 986 | ||
957 | return qtd; | 987 | return qtd; |
958 | } | 988 | } |
959 | 989 | ||
960 | static void do_atl_int(struct usb_hcd *usb_hcd) | 990 | static void do_atl_int(struct usb_hcd *hcd) |
961 | { | 991 | { |
962 | struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); | 992 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
963 | u32 done_map, skip_map; | 993 | u32 done_map, skip_map; |
964 | struct ptd ptd; | 994 | struct ptd ptd; |
965 | struct urb *urb = NULL; | 995 | struct urb *urb; |
966 | u32 atl_regs_base; | 996 | u32 slot; |
967 | u32 atl_regs; | ||
968 | u32 queue_entry; | ||
969 | u32 payload; | ||
970 | u32 length; | 997 | u32 length; |
971 | u32 or_map; | 998 | u32 or_map; |
972 | u32 status = -EINVAL; | 999 | u32 status = -EINVAL; |
@@ -976,62 +1003,36 @@ static void do_atl_int(struct usb_hcd *usb_hcd) | |||
976 | u32 rl; | 1003 | u32 rl; |
977 | u32 nakcount; | 1004 | u32 nakcount; |
978 | 1005 | ||
979 | done_map = isp1760_readl(usb_hcd->regs + | 1006 | done_map = reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); |
980 | HC_ATL_PTD_DONEMAP_REG); | 1007 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
981 | skip_map = isp1760_readl(usb_hcd->regs + | ||
982 | HC_ATL_PTD_SKIPMAP_REG); | ||
983 | 1008 | ||
984 | or_map = isp1760_readl(usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG); | 1009 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
985 | or_map &= ~done_map; | 1010 | or_map &= ~done_map; |
986 | isp1760_writel(or_map, usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG); | 1011 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); |
987 | 1012 | ||
988 | atl_regs_base = ATL_REGS_OFFSET; | ||
989 | while (done_map) { | 1013 | while (done_map) { |
990 | u32 dw1; | ||
991 | u32 dw2; | ||
992 | u32 dw3; | ||
993 | |||
994 | status = 0; | 1014 | status = 0; |
1015 | priv->atl_queued--; | ||
995 | 1016 | ||
996 | queue_entry = __ffs(done_map); | 1017 | slot = __ffs(done_map); |
997 | done_map &= ~(1 << queue_entry); | 1018 | done_map &= ~(1 << slot); |
998 | skip_map |= 1 << queue_entry; | 1019 | skip_map |= (1 << slot); |
999 | |||
1000 | atl_regs = atl_regs_base + queue_entry * sizeof(struct ptd); | ||
1001 | 1020 | ||
1002 | urb = priv->atl_ints[queue_entry].urb; | 1021 | qtd = priv->atl_ints[slot].qtd; |
1003 | qtd = priv->atl_ints[queue_entry].qtd; | 1022 | qh = priv->atl_ints[slot].qh; |
1004 | qh = priv->atl_ints[queue_entry].qh; | ||
1005 | payload = priv->atl_ints[queue_entry].payload; | ||
1006 | 1023 | ||
1007 | if (!qh) { | 1024 | if (!qh) { |
1008 | printk(KERN_ERR "qh is 0\n"); | 1025 | dev_err(hcd->self.controller, "qh is 0\n"); |
1009 | continue; | 1026 | continue; |
1010 | } | 1027 | } |
1011 | isp1760_writel(atl_regs + ISP_BANK(0), usb_hcd->regs + | 1028 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); |
1012 | HC_MEMORY_REG); | ||
1013 | isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs + | ||
1014 | HC_MEMORY_REG); | ||
1015 | /* | ||
1016 | * write bank1 address twice to ensure the 90ns delay (time | ||
1017 | * between BANK0 write and the priv_read_copy() call is at | ||
1018 | * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 109ns) | ||
1019 | */ | ||
1020 | isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs + | ||
1021 | HC_MEMORY_REG); | ||
1022 | 1029 | ||
1023 | priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + atl_regs + | 1030 | rl = (ptd.dw2 >> 25) & 0x0f; |
1024 | ISP_BANK(0), sizeof(ptd)); | 1031 | nakcount = (ptd.dw3 >> 19) & 0xf; |
1025 | |||
1026 | dw1 = le32_to_cpu(ptd.dw1); | ||
1027 | dw2 = le32_to_cpu(ptd.dw2); | ||
1028 | dw3 = le32_to_cpu(ptd.dw3); | ||
1029 | rl = (dw2 >> 25) & 0x0f; | ||
1030 | nakcount = (dw3 >> 19) & 0xf; | ||
1031 | 1032 | ||
1032 | /* Transfer Error, *but* active and no HALT -> reload */ | 1033 | /* Transfer Error, *but* active and no HALT -> reload */ |
1033 | if ((dw3 & DW3_ERROR_BIT) && (dw3 & DW3_QTD_ACTIVE) && | 1034 | if ((ptd.dw3 & DW3_ERROR_BIT) && (ptd.dw3 & DW3_QTD_ACTIVE) && |
1034 | !(dw3 & DW3_HALT_BIT)) { | 1035 | !(ptd.dw3 & DW3_HALT_BIT)) { |
1035 | 1036 | ||
1036 | /* according to ppriv code, we have to | 1037 | /* according to ppriv code, we have to |
1037 | * reload this one if trasfered bytes != requested bytes | 1038 | * reload this one if trasfered bytes != requested bytes |
@@ -1040,13 +1041,14 @@ static void do_atl_int(struct usb_hcd *usb_hcd) | |||
1040 | * triggered so far. | 1041 | * triggered so far. |
1041 | */ | 1042 | */ |
1042 | 1043 | ||
1043 | length = PTD_XFERRED_LENGTH(dw3); | 1044 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
1044 | printk(KERN_ERR "Should reload now.... transfered %d " | 1045 | dev_err(hcd->self.controller, |
1046 | "Should reload now... transferred %d " | ||
1045 | "of %zu\n", length, qtd->length); | 1047 | "of %zu\n", length, qtd->length); |
1046 | BUG(); | 1048 | BUG(); |
1047 | } | 1049 | } |
1048 | 1050 | ||
1049 | if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) { | 1051 | if (!nakcount && (ptd.dw3 & DW3_QTD_ACTIVE)) { |
1050 | u32 buffstatus; | 1052 | u32 buffstatus; |
1051 | 1053 | ||
1052 | /* | 1054 | /* |
@@ -1054,52 +1056,45 @@ static void do_atl_int(struct usb_hcd *usb_hcd) | |||
1054 | * device is not able to send data fast enough. | 1056 | * device is not able to send data fast enough. |
1055 | * This happens mostly on slower hardware. | 1057 | * This happens mostly on slower hardware. |
1056 | */ | 1058 | */ |
1057 | printk(KERN_NOTICE "Reloading ptd %p/%p... qh %p read: " | ||
1058 | "%d of %zu done: %08x cur: %08x\n", qtd, | ||
1059 | urb, qh, PTD_XFERRED_LENGTH(dw3), | ||
1060 | qtd->length, done_map, | ||
1061 | (1 << queue_entry)); | ||
1062 | 1059 | ||
1063 | /* RL counter = ERR counter */ | 1060 | /* RL counter = ERR counter */ |
1064 | dw3 &= ~(0xf << 19); | 1061 | ptd.dw3 &= ~(0xf << 19); |
1065 | dw3 |= rl << 19; | 1062 | ptd.dw3 |= rl << 19; |
1066 | dw3 &= ~(3 << (55 - 32)); | 1063 | ptd.dw3 &= ~(3 << (55 - 32)); |
1067 | dw3 |= ERR_COUNTER << (55 - 32); | 1064 | ptd.dw3 |= ERR_COUNTER << (55 - 32); |
1068 | 1065 | ||
1069 | /* | 1066 | /* |
1070 | * It is not needed to write skip map back because it | 1067 | * It is not needed to write skip map back because it |
1071 | * is unchanged. Just make sure that this entry is | 1068 | * is unchanged. Just make sure that this entry is |
1072 | * unskipped once it gets written to the HW. | 1069 | * unskipped once it gets written to the HW. |
1073 | */ | 1070 | */ |
1074 | skip_map &= ~(1 << queue_entry); | 1071 | skip_map &= ~(1 << slot); |
1075 | or_map = isp1760_readl(usb_hcd->regs + | 1072 | or_map = reg_read32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG); |
1076 | HC_ATL_IRQ_MASK_OR_REG); | 1073 | or_map |= 1 << slot; |
1077 | or_map |= 1 << queue_entry; | 1074 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, or_map); |
1078 | isp1760_writel(or_map, usb_hcd->regs + | 1075 | |
1079 | HC_ATL_IRQ_MASK_OR_REG); | 1076 | ptd.dw0 |= PTD_VALID; |
1080 | 1077 | ptd_write(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); | |
1081 | ptd.dw3 = cpu_to_le32(dw3); | 1078 | |
1082 | priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + | 1079 | priv->atl_queued++; |
1083 | atl_regs, sizeof(ptd)); | 1080 | if (priv->atl_queued == 2) |
1084 | 1081 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, | |
1085 | ptd.dw0 |= cpu_to_le32(PTD_VALID); | 1082 | INTERRUPT_ENABLE_SOT_MASK); |
1086 | priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + | 1083 | |
1087 | atl_regs, sizeof(ptd)); | 1084 | buffstatus = reg_read32(hcd->regs, |
1088 | 1085 | HC_BUFFER_STATUS_REG); | |
1089 | buffstatus = isp1760_readl(usb_hcd->regs + | ||
1090 | HC_BUFFER_STATUS_REG); | ||
1091 | buffstatus |= ATL_BUFFER; | 1086 | buffstatus |= ATL_BUFFER; |
1092 | isp1760_writel(buffstatus, usb_hcd->regs + | 1087 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, |
1093 | HC_BUFFER_STATUS_REG); | 1088 | buffstatus); |
1094 | continue; | 1089 | continue; |
1095 | } | 1090 | } |
1096 | 1091 | ||
1097 | error = check_error(&ptd); | 1092 | error = check_error(hcd, &ptd); |
1098 | if (error) { | 1093 | if (error) { |
1099 | status = error; | 1094 | status = error; |
1100 | priv->atl_ints[queue_entry].qh->toggle = 0; | 1095 | priv->atl_ints[slot].qh->toggle = 0; |
1101 | priv->atl_ints[queue_entry].qh->ping = 0; | 1096 | priv->atl_ints[slot].qh->ping = 0; |
1102 | urb->status = -EPIPE; | 1097 | qtd->urb->status = -EPIPE; |
1103 | 1098 | ||
1104 | #if 0 | 1099 | #if 0 |
1105 | printk(KERN_ERR "Error in %s().\n", __func__); | 1100 | printk(KERN_ERR "Error in %s().\n", __func__); |
@@ -1110,154 +1105,123 @@ static void do_atl_int(struct usb_hcd *usb_hcd) | |||
1110 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); | 1105 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); |
1111 | #endif | 1106 | #endif |
1112 | } else { | 1107 | } else { |
1113 | if (usb_pipetype(urb->pipe) == PIPE_BULK) { | 1108 | priv->atl_ints[slot].qh->toggle = ptd.dw3 & (1 << 25); |
1114 | priv->atl_ints[queue_entry].qh->toggle = dw3 & | 1109 | priv->atl_ints[slot].qh->ping = ptd.dw3 & (1 << 26); |
1115 | (1 << 25); | ||
1116 | priv->atl_ints[queue_entry].qh->ping = dw3 & | ||
1117 | (1 << 26); | ||
1118 | } | ||
1119 | } | 1110 | } |
1120 | 1111 | ||
1121 | length = PTD_XFERRED_LENGTH(dw3); | 1112 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
1122 | if (length) { | 1113 | if (length) { |
1123 | switch (DW1_GET_PID(dw1)) { | 1114 | switch (DW1_GET_PID(ptd.dw1)) { |
1124 | case IN_PID: | 1115 | case IN_PID: |
1125 | priv_read_copy(priv, | 1116 | mem_reads8(hcd->regs, qtd->payload_addr, |
1126 | priv->atl_ints[queue_entry].data_buffer, | 1117 | qtd->data_buffer, length); |
1127 | usb_hcd->regs + payload + ISP_BANK(1), | ||
1128 | length); | ||
1129 | 1118 | ||
1130 | case OUT_PID: | 1119 | case OUT_PID: |
1131 | 1120 | ||
1132 | urb->actual_length += length; | 1121 | qtd->urb->actual_length += length; |
1133 | 1122 | ||
1134 | case SETUP_PID: | 1123 | case SETUP_PID: |
1135 | break; | 1124 | break; |
1136 | } | 1125 | } |
1137 | } | 1126 | } |
1138 | 1127 | ||
1139 | priv->atl_ints[queue_entry].data_buffer = NULL; | 1128 | priv->atl_ints[slot].qtd = NULL; |
1140 | priv->atl_ints[queue_entry].urb = NULL; | 1129 | priv->atl_ints[slot].qh = NULL; |
1141 | priv->atl_ints[queue_entry].qtd = NULL; | ||
1142 | priv->atl_ints[queue_entry].qh = NULL; | ||
1143 | 1130 | ||
1144 | free_mem(priv, payload); | 1131 | free_mem(hcd, qtd); |
1145 | 1132 | ||
1146 | isp1760_writel(skip_map, usb_hcd->regs + | 1133 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
1147 | HC_ATL_PTD_SKIPMAP_REG); | ||
1148 | 1134 | ||
1149 | if (urb->status == -EPIPE) { | 1135 | if (qtd->urb->status == -EPIPE) { |
1150 | /* HALT was received */ | 1136 | /* HALT was received */ |
1151 | 1137 | ||
1152 | qtd = clean_up_qtdlist(qtd); | 1138 | urb = qtd->urb; |
1153 | isp1760_urb_done(priv, urb, urb->status); | 1139 | qtd = clean_up_qtdlist(qtd, qh); |
1140 | isp1760_urb_done(hcd, urb); | ||
1154 | 1141 | ||
1155 | } else if (usb_pipebulk(urb->pipe) && (length < qtd->length)) { | 1142 | } else if (usb_pipebulk(qtd->urb->pipe) && |
1143 | (length < qtd->length)) { | ||
1156 | /* short BULK received */ | 1144 | /* short BULK received */ |
1157 | 1145 | ||
1158 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | 1146 | if (qtd->urb->transfer_flags & URB_SHORT_NOT_OK) { |
1159 | urb->status = -EREMOTEIO; | 1147 | qtd->urb->status = -EREMOTEIO; |
1160 | isp1760_dbg(priv, "short bulk, %d instead %zu " | 1148 | dev_dbg(hcd->self.controller, |
1161 | "with URB_SHORT_NOT_OK flag.\n", | 1149 | "short bulk, %d instead %zu " |
1162 | length, qtd->length); | 1150 | "with URB_SHORT_NOT_OK flag.\n", |
1151 | length, qtd->length); | ||
1163 | } | 1152 | } |
1164 | 1153 | ||
1165 | if (urb->status == -EINPROGRESS) | 1154 | if (qtd->urb->status == -EINPROGRESS) |
1166 | urb->status = 0; | 1155 | qtd->urb->status = 0; |
1167 | |||
1168 | qtd = clean_up_qtdlist(qtd); | ||
1169 | 1156 | ||
1170 | isp1760_urb_done(priv, urb, urb->status); | 1157 | urb = qtd->urb; |
1158 | qtd = clean_up_qtdlist(qtd, qh); | ||
1159 | isp1760_urb_done(hcd, urb); | ||
1171 | 1160 | ||
1172 | } else if (qtd->status & URB_COMPLETE_NOTIFY) { | 1161 | } else if (last_qtd_of_urb(qtd, qh)) { |
1173 | /* that was the last qtd of that URB */ | 1162 | /* that was the last qtd of that URB */ |
1174 | 1163 | ||
1175 | if (urb->status == -EINPROGRESS) | 1164 | if (qtd->urb->status == -EINPROGRESS) |
1176 | urb->status = 0; | 1165 | qtd->urb->status = 0; |
1177 | 1166 | ||
1178 | qtd = clean_this_qtd(qtd); | 1167 | urb = qtd->urb; |
1179 | isp1760_urb_done(priv, urb, urb->status); | 1168 | qtd = clean_up_qtdlist(qtd, qh); |
1169 | isp1760_urb_done(hcd, urb); | ||
1180 | 1170 | ||
1181 | } else { | 1171 | } else { |
1182 | /* next QTD of this URB */ | 1172 | /* next QTD of this URB */ |
1183 | 1173 | ||
1184 | qtd = clean_this_qtd(qtd); | 1174 | qtd = clean_this_qtd(qtd, qh); |
1185 | BUG_ON(!qtd); | 1175 | BUG_ON(!qtd); |
1186 | } | 1176 | } |
1187 | 1177 | ||
1188 | if (qtd) | 1178 | if (qtd) |
1189 | enqueue_an_ATL_packet(usb_hcd, qh, qtd); | 1179 | enqueue_an_ATL_packet(hcd, qh, qtd); |
1190 | 1180 | ||
1191 | skip_map = isp1760_readl(usb_hcd->regs + | 1181 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
1192 | HC_ATL_PTD_SKIPMAP_REG); | ||
1193 | } | 1182 | } |
1183 | if (priv->atl_queued <= 1) | ||
1184 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, | ||
1185 | INTERRUPT_ENABLE_MASK); | ||
1194 | } | 1186 | } |
1195 | 1187 | ||
1196 | static void do_intl_int(struct usb_hcd *usb_hcd) | 1188 | static void do_intl_int(struct usb_hcd *hcd) |
1197 | { | 1189 | { |
1198 | struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); | 1190 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
1199 | u32 done_map, skip_map; | 1191 | u32 done_map, skip_map; |
1200 | struct ptd ptd; | 1192 | struct ptd ptd; |
1201 | struct urb *urb = NULL; | 1193 | struct urb *urb; |
1202 | u32 int_regs; | ||
1203 | u32 int_regs_base; | ||
1204 | u32 payload; | ||
1205 | u32 length; | 1194 | u32 length; |
1206 | u32 or_map; | 1195 | u32 or_map; |
1207 | int error; | 1196 | int error; |
1208 | u32 queue_entry; | 1197 | u32 slot; |
1209 | struct isp1760_qtd *qtd; | 1198 | struct isp1760_qtd *qtd; |
1210 | struct isp1760_qh *qh; | 1199 | struct isp1760_qh *qh; |
1211 | 1200 | ||
1212 | done_map = isp1760_readl(usb_hcd->regs + | 1201 | done_map = reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); |
1213 | HC_INT_PTD_DONEMAP_REG); | 1202 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
1214 | skip_map = isp1760_readl(usb_hcd->regs + | ||
1215 | HC_INT_PTD_SKIPMAP_REG); | ||
1216 | 1203 | ||
1217 | or_map = isp1760_readl(usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG); | 1204 | or_map = reg_read32(hcd->regs, HC_INT_IRQ_MASK_OR_REG); |
1218 | or_map &= ~done_map; | 1205 | or_map &= ~done_map; |
1219 | isp1760_writel(or_map, usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG); | 1206 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, or_map); |
1220 | |||
1221 | int_regs_base = INT_REGS_OFFSET; | ||
1222 | 1207 | ||
1223 | while (done_map) { | 1208 | while (done_map) { |
1224 | u32 dw1; | 1209 | slot = __ffs(done_map); |
1225 | u32 dw3; | 1210 | done_map &= ~(1 << slot); |
1211 | skip_map |= (1 << slot); | ||
1226 | 1212 | ||
1227 | queue_entry = __ffs(done_map); | 1213 | qtd = priv->int_ints[slot].qtd; |
1228 | done_map &= ~(1 << queue_entry); | 1214 | qh = priv->int_ints[slot].qh; |
1229 | skip_map |= 1 << queue_entry; | ||
1230 | |||
1231 | int_regs = int_regs_base + queue_entry * sizeof(struct ptd); | ||
1232 | urb = priv->int_ints[queue_entry].urb; | ||
1233 | qtd = priv->int_ints[queue_entry].qtd; | ||
1234 | qh = priv->int_ints[queue_entry].qh; | ||
1235 | payload = priv->int_ints[queue_entry].payload; | ||
1236 | 1215 | ||
1237 | if (!qh) { | 1216 | if (!qh) { |
1238 | printk(KERN_ERR "(INT) qh is 0\n"); | 1217 | dev_err(hcd->self.controller, "(INT) qh is 0\n"); |
1239 | continue; | 1218 | continue; |
1240 | } | 1219 | } |
1241 | 1220 | ||
1242 | isp1760_writel(int_regs + ISP_BANK(0), usb_hcd->regs + | 1221 | ptd_read(hcd->regs, INT_PTD_OFFSET, slot, &ptd); |
1243 | HC_MEMORY_REG); | 1222 | check_int_err_status(hcd, ptd.dw4); |
1244 | isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs + | ||
1245 | HC_MEMORY_REG); | ||
1246 | /* | ||
1247 | * write bank1 address twice to ensure the 90ns delay (time | ||
1248 | * between BANK0 write and the priv_read_copy() call is at | ||
1249 | * least 3*t_WHWL + 2*t_w11 = 3*25ns + 2*17ns = 92ns) | ||
1250 | */ | ||
1251 | isp1760_writel(payload + ISP_BANK(1), usb_hcd->regs + | ||
1252 | HC_MEMORY_REG); | ||
1253 | 1223 | ||
1254 | priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + int_regs + | 1224 | error = check_error(hcd, &ptd); |
1255 | ISP_BANK(0), sizeof(ptd)); | ||
1256 | dw1 = le32_to_cpu(ptd.dw1); | ||
1257 | dw3 = le32_to_cpu(ptd.dw3); | ||
1258 | check_int_err_status(le32_to_cpu(ptd.dw4)); | ||
1259 | |||
1260 | error = check_error(&ptd); | ||
1261 | if (error) { | 1225 | if (error) { |
1262 | #if 0 | 1226 | #if 0 |
1263 | printk(KERN_ERR "Error in %s().\n", __func__); | 1227 | printk(KERN_ERR "Error in %s().\n", __func__); |
@@ -1267,83 +1231,77 @@ static void do_intl_int(struct usb_hcd *usb_hcd) | |||
1267 | ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3, | 1231 | ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3, |
1268 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); | 1232 | ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7); |
1269 | #endif | 1233 | #endif |
1270 | urb->status = -EPIPE; | 1234 | qtd->urb->status = -EPIPE; |
1271 | priv->int_ints[queue_entry].qh->toggle = 0; | 1235 | priv->int_ints[slot].qh->toggle = 0; |
1272 | priv->int_ints[queue_entry].qh->ping = 0; | 1236 | priv->int_ints[slot].qh->ping = 0; |
1273 | 1237 | ||
1274 | } else { | 1238 | } else { |
1275 | priv->int_ints[queue_entry].qh->toggle = | 1239 | priv->int_ints[slot].qh->toggle = ptd.dw3 & (1 << 25); |
1276 | dw3 & (1 << 25); | 1240 | priv->int_ints[slot].qh->ping = ptd.dw3 & (1 << 26); |
1277 | priv->int_ints[queue_entry].qh->ping = dw3 & (1 << 26); | ||
1278 | } | 1241 | } |
1279 | 1242 | ||
1280 | if (urb->dev->speed != USB_SPEED_HIGH) | 1243 | if (qtd->urb->dev->speed != USB_SPEED_HIGH) |
1281 | length = PTD_XFERRED_LENGTH_LO(dw3); | 1244 | length = PTD_XFERRED_LENGTH_LO(ptd.dw3); |
1282 | else | 1245 | else |
1283 | length = PTD_XFERRED_LENGTH(dw3); | 1246 | length = PTD_XFERRED_LENGTH(ptd.dw3); |
1284 | 1247 | ||
1285 | if (length) { | 1248 | if (length) { |
1286 | switch (DW1_GET_PID(dw1)) { | 1249 | switch (DW1_GET_PID(ptd.dw1)) { |
1287 | case IN_PID: | 1250 | case IN_PID: |
1288 | priv_read_copy(priv, | 1251 | mem_reads8(hcd->regs, qtd->payload_addr, |
1289 | priv->int_ints[queue_entry].data_buffer, | 1252 | qtd->data_buffer, length); |
1290 | usb_hcd->regs + payload + ISP_BANK(1), | ||
1291 | length); | ||
1292 | case OUT_PID: | 1253 | case OUT_PID: |
1293 | 1254 | ||
1294 | urb->actual_length += length; | 1255 | qtd->urb->actual_length += length; |
1295 | 1256 | ||
1296 | case SETUP_PID: | 1257 | case SETUP_PID: |
1297 | break; | 1258 | break; |
1298 | } | 1259 | } |
1299 | } | 1260 | } |
1300 | 1261 | ||
1301 | priv->int_ints[queue_entry].data_buffer = NULL; | 1262 | priv->int_ints[slot].qtd = NULL; |
1302 | priv->int_ints[queue_entry].urb = NULL; | 1263 | priv->int_ints[slot].qh = NULL; |
1303 | priv->int_ints[queue_entry].qtd = NULL; | ||
1304 | priv->int_ints[queue_entry].qh = NULL; | ||
1305 | 1264 | ||
1306 | isp1760_writel(skip_map, usb_hcd->regs + | 1265 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
1307 | HC_INT_PTD_SKIPMAP_REG); | 1266 | free_mem(hcd, qtd); |
1308 | free_mem(priv, payload); | ||
1309 | 1267 | ||
1310 | if (urb->status == -EPIPE) { | 1268 | if (qtd->urb->status == -EPIPE) { |
1311 | /* HALT received */ | 1269 | /* HALT received */ |
1312 | 1270 | ||
1313 | qtd = clean_up_qtdlist(qtd); | 1271 | urb = qtd->urb; |
1314 | isp1760_urb_done(priv, urb, urb->status); | 1272 | qtd = clean_up_qtdlist(qtd, qh); |
1273 | isp1760_urb_done(hcd, urb); | ||
1315 | 1274 | ||
1316 | } else if (qtd->status & URB_COMPLETE_NOTIFY) { | 1275 | } else if (last_qtd_of_urb(qtd, qh)) { |
1317 | 1276 | ||
1318 | if (urb->status == -EINPROGRESS) | 1277 | if (qtd->urb->status == -EINPROGRESS) |
1319 | urb->status = 0; | 1278 | qtd->urb->status = 0; |
1320 | 1279 | ||
1321 | qtd = clean_this_qtd(qtd); | 1280 | urb = qtd->urb; |
1322 | isp1760_urb_done(priv, urb, urb->status); | 1281 | qtd = clean_up_qtdlist(qtd, qh); |
1282 | isp1760_urb_done(hcd, urb); | ||
1323 | 1283 | ||
1324 | } else { | 1284 | } else { |
1325 | /* next QTD of this URB */ | 1285 | /* next QTD of this URB */ |
1326 | 1286 | ||
1327 | qtd = clean_this_qtd(qtd); | 1287 | qtd = clean_this_qtd(qtd, qh); |
1328 | BUG_ON(!qtd); | 1288 | BUG_ON(!qtd); |
1329 | } | 1289 | } |
1330 | 1290 | ||
1331 | if (qtd) | 1291 | if (qtd) |
1332 | enqueue_an_INT_packet(usb_hcd, qh, qtd); | 1292 | enqueue_an_INT_packet(hcd, qh, qtd); |
1333 | 1293 | ||
1334 | skip_map = isp1760_readl(usb_hcd->regs + | 1294 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
1335 | HC_INT_PTD_SKIPMAP_REG); | ||
1336 | } | 1295 | } |
1337 | } | 1296 | } |
1338 | 1297 | ||
1339 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) | 1298 | static struct isp1760_qh *qh_make(struct usb_hcd *hcd, struct urb *urb, |
1340 | static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb, | ||
1341 | gfp_t flags) | 1299 | gfp_t flags) |
1342 | { | 1300 | { |
1343 | struct isp1760_qh *qh; | 1301 | struct isp1760_qh *qh; |
1344 | int is_input, type; | 1302 | int is_input, type; |
1345 | 1303 | ||
1346 | qh = isp1760_qh_alloc(priv, flags); | 1304 | qh = isp1760_qh_alloc(flags); |
1347 | if (!qh) | 1305 | if (!qh) |
1348 | return qh; | 1306 | return qh; |
1349 | 1307 | ||
@@ -1353,29 +1311,6 @@ static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb, | |||
1353 | is_input = usb_pipein(urb->pipe); | 1311 | is_input = usb_pipein(urb->pipe); |
1354 | type = usb_pipetype(urb->pipe); | 1312 | type = usb_pipetype(urb->pipe); |
1355 | 1313 | ||
1356 | if (type == PIPE_INTERRUPT) { | ||
1357 | |||
1358 | if (urb->dev->speed == USB_SPEED_HIGH) { | ||
1359 | |||
1360 | qh->period = urb->interval >> 3; | ||
1361 | if (qh->period == 0 && urb->interval != 1) { | ||
1362 | /* NOTE interval 2 or 4 uframes could work. | ||
1363 | * But interval 1 scheduling is simpler, and | ||
1364 | * includes high bandwidth. | ||
1365 | */ | ||
1366 | printk(KERN_ERR "intr period %d uframes, NYET!", | ||
1367 | urb->interval); | ||
1368 | qh_destroy(qh); | ||
1369 | return NULL; | ||
1370 | } | ||
1371 | } else { | ||
1372 | qh->period = urb->interval; | ||
1373 | } | ||
1374 | } | ||
1375 | |||
1376 | /* support for tt scheduling, and access to toggles */ | ||
1377 | qh->dev = urb->dev; | ||
1378 | |||
1379 | if (!usb_pipecontrol(urb->pipe)) | 1314 | if (!usb_pipecontrol(urb->pipe)) |
1380 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, | 1315 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input, |
1381 | 1); | 1316 | 1); |
@@ -1388,43 +1323,27 @@ static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb, | |||
1388 | * Returns null if it can't allocate a QH it needs to. | 1323 | * Returns null if it can't allocate a QH it needs to. |
1389 | * If the QH has TDs (urbs) already, that's great. | 1324 | * If the QH has TDs (urbs) already, that's great. |
1390 | */ | 1325 | */ |
1391 | static struct isp1760_qh *qh_append_tds(struct isp1760_hcd *priv, | 1326 | static struct isp1760_qh *qh_append_tds(struct usb_hcd *hcd, |
1392 | struct urb *urb, struct list_head *qtd_list, int epnum, | 1327 | struct urb *urb, struct list_head *qtd_list, int epnum, |
1393 | void **ptr) | 1328 | void **ptr) |
1394 | { | 1329 | { |
1395 | struct isp1760_qh *qh; | 1330 | struct isp1760_qh *qh; |
1396 | struct isp1760_qtd *qtd; | ||
1397 | struct isp1760_qtd *prev_qtd; | ||
1398 | 1331 | ||
1399 | qh = (struct isp1760_qh *)*ptr; | 1332 | qh = (struct isp1760_qh *)*ptr; |
1400 | if (!qh) { | 1333 | if (!qh) { |
1401 | /* can't sleep here, we have priv->lock... */ | 1334 | /* can't sleep here, we have priv->lock... */ |
1402 | qh = qh_make(priv, urb, GFP_ATOMIC); | 1335 | qh = qh_make(hcd, urb, GFP_ATOMIC); |
1403 | if (!qh) | 1336 | if (!qh) |
1404 | return qh; | 1337 | return qh; |
1405 | *ptr = qh; | 1338 | *ptr = qh; |
1406 | } | 1339 | } |
1407 | 1340 | ||
1408 | qtd = list_entry(qtd_list->next, struct isp1760_qtd, | ||
1409 | qtd_list); | ||
1410 | if (!list_empty(&qh->qtd_list)) | ||
1411 | prev_qtd = list_entry(qh->qtd_list.prev, | ||
1412 | struct isp1760_qtd, qtd_list); | ||
1413 | else | ||
1414 | prev_qtd = NULL; | ||
1415 | |||
1416 | list_splice(qtd_list, qh->qtd_list.prev); | 1341 | list_splice(qtd_list, qh->qtd_list.prev); |
1417 | if (prev_qtd) { | ||
1418 | BUG_ON(prev_qtd->hw_next); | ||
1419 | prev_qtd->hw_next = qtd; | ||
1420 | } | ||
1421 | 1342 | ||
1422 | urb->hcpriv = qh; | ||
1423 | return qh; | 1343 | return qh; |
1424 | } | 1344 | } |
1425 | 1345 | ||
1426 | static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb, | 1346 | static void qtd_list_free(struct urb *urb, struct list_head *qtd_list) |
1427 | struct list_head *qtd_list) | ||
1428 | { | 1347 | { |
1429 | struct list_head *entry, *temp; | 1348 | struct list_head *entry, *temp; |
1430 | 1349 | ||
@@ -1437,9 +1356,10 @@ static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb, | |||
1437 | } | 1356 | } |
1438 | } | 1357 | } |
1439 | 1358 | ||
1440 | static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb, | 1359 | static int isp1760_prepare_enqueue(struct usb_hcd *hcd, struct urb *urb, |
1441 | struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p) | 1360 | struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p) |
1442 | { | 1361 | { |
1362 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
1443 | struct isp1760_qtd *qtd; | 1363 | struct isp1760_qtd *qtd; |
1444 | int epnum; | 1364 | int epnum; |
1445 | unsigned long flags; | 1365 | unsigned long flags; |
@@ -1451,11 +1371,11 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb, | |||
1451 | epnum = urb->ep->desc.bEndpointAddress; | 1371 | epnum = urb->ep->desc.bEndpointAddress; |
1452 | 1372 | ||
1453 | spin_lock_irqsave(&priv->lock, flags); | 1373 | spin_lock_irqsave(&priv->lock, flags); |
1454 | if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) { | 1374 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
1455 | rc = -ESHUTDOWN; | 1375 | rc = -ESHUTDOWN; |
1456 | goto done; | 1376 | goto done; |
1457 | } | 1377 | } |
1458 | rc = usb_hcd_link_urb_to_ep(priv_to_hcd(priv), urb); | 1378 | rc = usb_hcd_link_urb_to_ep(hcd, urb); |
1459 | if (rc) | 1379 | if (rc) |
1460 | goto done; | 1380 | goto done; |
1461 | 1381 | ||
@@ -1465,25 +1385,24 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb, | |||
1465 | else | 1385 | else |
1466 | qh_busy = 0; | 1386 | qh_busy = 0; |
1467 | 1387 | ||
1468 | qh = qh_append_tds(priv, urb, qtd_list, epnum, &urb->ep->hcpriv); | 1388 | qh = qh_append_tds(hcd, urb, qtd_list, epnum, &urb->ep->hcpriv); |
1469 | if (!qh) { | 1389 | if (!qh) { |
1470 | usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); | 1390 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
1471 | rc = -ENOMEM; | 1391 | rc = -ENOMEM; |
1472 | goto done; | 1392 | goto done; |
1473 | } | 1393 | } |
1474 | 1394 | ||
1475 | if (!qh_busy) | 1395 | if (!qh_busy) |
1476 | p(priv_to_hcd(priv), qh, qtd); | 1396 | p(hcd, qh, qtd); |
1477 | 1397 | ||
1478 | done: | 1398 | done: |
1479 | spin_unlock_irqrestore(&priv->lock, flags); | 1399 | spin_unlock_irqrestore(&priv->lock, flags); |
1480 | if (!qh) | 1400 | if (!qh) |
1481 | qtd_list_free(priv, urb, qtd_list); | 1401 | qtd_list_free(urb, qtd_list); |
1482 | return rc; | 1402 | return rc; |
1483 | } | 1403 | } |
1484 | 1404 | ||
1485 | static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv, | 1405 | static struct isp1760_qtd *isp1760_qtd_alloc(gfp_t flags) |
1486 | gfp_t flags) | ||
1487 | { | 1406 | { |
1488 | struct isp1760_qtd *qtd; | 1407 | struct isp1760_qtd *qtd; |
1489 | 1408 | ||
@@ -1497,10 +1416,11 @@ static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv, | |||
1497 | /* | 1416 | /* |
1498 | * create a list of filled qtds for this URB; won't link into qh. | 1417 | * create a list of filled qtds for this URB; won't link into qh. |
1499 | */ | 1418 | */ |
1500 | static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | 1419 | #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) |
1420 | static struct list_head *qh_urb_transaction(struct usb_hcd *hcd, | ||
1501 | struct urb *urb, struct list_head *head, gfp_t flags) | 1421 | struct urb *urb, struct list_head *head, gfp_t flags) |
1502 | { | 1422 | { |
1503 | struct isp1760_qtd *qtd, *qtd_prev; | 1423 | struct isp1760_qtd *qtd; |
1504 | void *buf; | 1424 | void *buf; |
1505 | int len, maxpacket; | 1425 | int len, maxpacket; |
1506 | int is_input; | 1426 | int is_input; |
@@ -1509,7 +1429,7 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1509 | /* | 1429 | /* |
1510 | * URBs map to sequences of QTDs: one logical transaction | 1430 | * URBs map to sequences of QTDs: one logical transaction |
1511 | */ | 1431 | */ |
1512 | qtd = isp1760_qtd_alloc(priv, flags); | 1432 | qtd = isp1760_qtd_alloc(flags); |
1513 | if (!qtd) | 1433 | if (!qtd) |
1514 | return NULL; | 1434 | return NULL; |
1515 | 1435 | ||
@@ -1529,13 +1449,10 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1529 | token | SETUP_PID); | 1449 | token | SETUP_PID); |
1530 | 1450 | ||
1531 | /* ... and always at least one more pid */ | 1451 | /* ... and always at least one more pid */ |
1532 | token ^= DATA_TOGGLE; | 1452 | qtd = isp1760_qtd_alloc(flags); |
1533 | qtd_prev = qtd; | ||
1534 | qtd = isp1760_qtd_alloc(priv, flags); | ||
1535 | if (!qtd) | 1453 | if (!qtd) |
1536 | goto cleanup; | 1454 | goto cleanup; |
1537 | qtd->urb = urb; | 1455 | qtd->urb = urb; |
1538 | qtd_prev->hw_next = qtd; | ||
1539 | list_add_tail(&qtd->qtd_list, head); | 1456 | list_add_tail(&qtd->qtd_list, head); |
1540 | 1457 | ||
1541 | /* for zero length DATA stages, STATUS is always IN */ | 1458 | /* for zero length DATA stages, STATUS is always IN */ |
@@ -1565,7 +1482,7 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1565 | 1482 | ||
1566 | if (!buf && len) { | 1483 | if (!buf && len) { |
1567 | /* XXX This looks like usb storage / SCSI bug */ | 1484 | /* XXX This looks like usb storage / SCSI bug */ |
1568 | printk(KERN_ERR "buf is null, dma is %08lx len is %d\n", | 1485 | dev_err(hcd->self.controller, "buf is null, dma is %08lx len is %d\n", |
1569 | (long unsigned)urb->transfer_dma, len); | 1486 | (long unsigned)urb->transfer_dma, len); |
1570 | WARN_ON(1); | 1487 | WARN_ON(1); |
1571 | } | 1488 | } |
@@ -1574,19 +1491,13 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1574 | len -= this_qtd_len; | 1491 | len -= this_qtd_len; |
1575 | buf += this_qtd_len; | 1492 | buf += this_qtd_len; |
1576 | 1493 | ||
1577 | /* qh makes control packets use qtd toggle; maybe switch it */ | ||
1578 | if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) | ||
1579 | token ^= DATA_TOGGLE; | ||
1580 | |||
1581 | if (len <= 0) | 1494 | if (len <= 0) |
1582 | break; | 1495 | break; |
1583 | 1496 | ||
1584 | qtd_prev = qtd; | 1497 | qtd = isp1760_qtd_alloc(flags); |
1585 | qtd = isp1760_qtd_alloc(priv, flags); | ||
1586 | if (!qtd) | 1498 | if (!qtd) |
1587 | goto cleanup; | 1499 | goto cleanup; |
1588 | qtd->urb = urb; | 1500 | qtd->urb = urb; |
1589 | qtd_prev->hw_next = qtd; | ||
1590 | list_add_tail(&qtd->qtd_list, head); | 1501 | list_add_tail(&qtd->qtd_list, head); |
1591 | } | 1502 | } |
1592 | 1503 | ||
@@ -1601,20 +1512,16 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1601 | one_more = 1; | 1512 | one_more = 1; |
1602 | /* "in" <--> "out" */ | 1513 | /* "in" <--> "out" */ |
1603 | token ^= IN_PID; | 1514 | token ^= IN_PID; |
1604 | /* force DATA1 */ | ||
1605 | token |= DATA_TOGGLE; | ||
1606 | } else if (usb_pipebulk(urb->pipe) | 1515 | } else if (usb_pipebulk(urb->pipe) |
1607 | && (urb->transfer_flags & URB_ZERO_PACKET) | 1516 | && (urb->transfer_flags & URB_ZERO_PACKET) |
1608 | && !(urb->transfer_buffer_length % maxpacket)) { | 1517 | && !(urb->transfer_buffer_length % maxpacket)) { |
1609 | one_more = 1; | 1518 | one_more = 1; |
1610 | } | 1519 | } |
1611 | if (one_more) { | 1520 | if (one_more) { |
1612 | qtd_prev = qtd; | 1521 | qtd = isp1760_qtd_alloc(flags); |
1613 | qtd = isp1760_qtd_alloc(priv, flags); | ||
1614 | if (!qtd) | 1522 | if (!qtd) |
1615 | goto cleanup; | 1523 | goto cleanup; |
1616 | qtd->urb = urb; | 1524 | qtd->urb = urb; |
1617 | qtd_prev->hw_next = qtd; | ||
1618 | list_add_tail(&qtd->qtd_list, head); | 1525 | list_add_tail(&qtd->qtd_list, head); |
1619 | 1526 | ||
1620 | /* never any data in such packets */ | 1527 | /* never any data in such packets */ |
@@ -1622,18 +1529,17 @@ static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv, | |||
1622 | } | 1529 | } |
1623 | } | 1530 | } |
1624 | 1531 | ||
1625 | qtd->status = URB_COMPLETE_NOTIFY; | 1532 | qtd->status = 0; |
1626 | return head; | 1533 | return head; |
1627 | 1534 | ||
1628 | cleanup: | 1535 | cleanup: |
1629 | qtd_list_free(priv, urb, head); | 1536 | qtd_list_free(urb, head); |
1630 | return NULL; | 1537 | return NULL; |
1631 | } | 1538 | } |
1632 | 1539 | ||
1633 | static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | 1540 | static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
1634 | gfp_t mem_flags) | 1541 | gfp_t mem_flags) |
1635 | { | 1542 | { |
1636 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
1637 | struct list_head qtd_list; | 1543 | struct list_head qtd_list; |
1638 | packet_enqueue *pe; | 1544 | packet_enqueue *pe; |
1639 | 1545 | ||
@@ -1642,29 +1548,27 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | |||
1642 | switch (usb_pipetype(urb->pipe)) { | 1548 | switch (usb_pipetype(urb->pipe)) { |
1643 | case PIPE_CONTROL: | 1549 | case PIPE_CONTROL: |
1644 | case PIPE_BULK: | 1550 | case PIPE_BULK: |
1645 | 1551 | if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags)) | |
1646 | if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags)) | ||
1647 | return -ENOMEM; | 1552 | return -ENOMEM; |
1648 | pe = enqueue_an_ATL_packet; | 1553 | pe = enqueue_an_ATL_packet; |
1649 | break; | 1554 | break; |
1650 | 1555 | ||
1651 | case PIPE_INTERRUPT: | 1556 | case PIPE_INTERRUPT: |
1652 | if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags)) | 1557 | if (!qh_urb_transaction(hcd, urb, &qtd_list, mem_flags)) |
1653 | return -ENOMEM; | 1558 | return -ENOMEM; |
1654 | pe = enqueue_an_INT_packet; | 1559 | pe = enqueue_an_INT_packet; |
1655 | break; | 1560 | break; |
1656 | 1561 | ||
1657 | case PIPE_ISOCHRONOUS: | 1562 | case PIPE_ISOCHRONOUS: |
1658 | printk(KERN_ERR "PIPE_ISOCHRONOUS ain't supported\n"); | 1563 | dev_err(hcd->self.controller, "PIPE_ISOCHRONOUS ain't supported\n"); |
1659 | default: | 1564 | default: |
1660 | return -EPIPE; | 1565 | return -EPIPE; |
1661 | } | 1566 | } |
1662 | 1567 | ||
1663 | return isp1760_prepare_enqueue(priv, urb, &qtd_list, mem_flags, pe); | 1568 | return isp1760_prepare_enqueue(hcd, urb, &qtd_list, mem_flags, pe); |
1664 | } | 1569 | } |
1665 | 1570 | ||
1666 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | 1571 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) |
1667 | int status) | ||
1668 | { | 1572 | { |
1669 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 1573 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
1670 | struct inter_packet_info *ints; | 1574 | struct inter_packet_info *ints; |
@@ -1681,7 +1585,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1681 | 1585 | ||
1682 | case PIPE_INTERRUPT: | 1586 | case PIPE_INTERRUPT: |
1683 | ints = priv->int_ints; | 1587 | ints = priv->int_ints; |
1684 | reg_base = INT_REGS_OFFSET; | 1588 | reg_base = INT_PTD_OFFSET; |
1685 | or_reg = HC_INT_IRQ_MASK_OR_REG; | 1589 | or_reg = HC_INT_IRQ_MASK_OR_REG; |
1686 | skip_reg = HC_INT_PTD_SKIPMAP_REG; | 1590 | skip_reg = HC_INT_PTD_SKIPMAP_REG; |
1687 | pe = enqueue_an_INT_packet; | 1591 | pe = enqueue_an_INT_packet; |
@@ -1689,7 +1593,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1689 | 1593 | ||
1690 | default: | 1594 | default: |
1691 | ints = priv->atl_ints; | 1595 | ints = priv->atl_ints; |
1692 | reg_base = ATL_REGS_OFFSET; | 1596 | reg_base = ATL_PTD_OFFSET; |
1693 | or_reg = HC_ATL_IRQ_MASK_OR_REG; | 1597 | or_reg = HC_ATL_IRQ_MASK_OR_REG; |
1694 | skip_reg = HC_ATL_PTD_SKIPMAP_REG; | 1598 | skip_reg = HC_ATL_PTD_SKIPMAP_REG; |
1695 | pe = enqueue_an_ATL_packet; | 1599 | pe = enqueue_an_ATL_packet; |
@@ -1700,81 +1604,84 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
1700 | spin_lock_irqsave(&priv->lock, flags); | 1604 | spin_lock_irqsave(&priv->lock, flags); |
1701 | 1605 | ||
1702 | for (i = 0; i < 32; i++) { | 1606 | for (i = 0; i < 32; i++) { |
1703 | if (ints->urb == urb) { | 1607 | if (!ints[i].qh) |
1608 | continue; | ||
1609 | BUG_ON(!ints[i].qtd); | ||
1610 | |||
1611 | if (ints[i].qtd->urb == urb) { | ||
1704 | u32 skip_map; | 1612 | u32 skip_map; |
1705 | u32 or_map; | 1613 | u32 or_map; |
1706 | struct isp1760_qtd *qtd; | 1614 | struct isp1760_qtd *qtd; |
1707 | struct isp1760_qh *qh = ints->qh; | 1615 | struct isp1760_qh *qh; |
1708 | 1616 | ||
1709 | skip_map = isp1760_readl(hcd->regs + skip_reg); | 1617 | skip_map = reg_read32(hcd->regs, skip_reg); |
1710 | skip_map |= 1 << i; | 1618 | skip_map |= 1 << i; |
1711 | isp1760_writel(skip_map, hcd->regs + skip_reg); | 1619 | reg_write32(hcd->regs, skip_reg, skip_map); |
1712 | 1620 | ||
1713 | or_map = isp1760_readl(hcd->regs + or_reg); | 1621 | or_map = reg_read32(hcd->regs, or_reg); |
1714 | or_map &= ~(1 << i); | 1622 | or_map &= ~(1 << i); |
1715 | isp1760_writel(or_map, hcd->regs + or_reg); | 1623 | reg_write32(hcd->regs, or_reg, or_map); |
1624 | |||
1625 | ptd_write(hcd->regs, reg_base, i, &ptd); | ||
1716 | 1626 | ||
1717 | priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base | 1627 | qtd = ints[i].qtd; |
1718 | + i * sizeof(ptd), sizeof(ptd)); | 1628 | qh = ints[i].qh; |
1719 | qtd = ints->qtd; | ||
1720 | qtd = clean_up_qtdlist(qtd); | ||
1721 | 1629 | ||
1722 | free_mem(priv, ints->payload); | 1630 | free_mem(hcd, qtd); |
1631 | qtd = clean_up_qtdlist(qtd, qh); | ||
1723 | 1632 | ||
1724 | ints->urb = NULL; | 1633 | ints[i].qh = NULL; |
1725 | ints->qh = NULL; | 1634 | ints[i].qtd = NULL; |
1726 | ints->qtd = NULL; | ||
1727 | ints->data_buffer = NULL; | ||
1728 | ints->payload = 0; | ||
1729 | 1635 | ||
1730 | isp1760_urb_done(priv, urb, status); | 1636 | isp1760_urb_done(hcd, urb); |
1731 | if (qtd) | 1637 | if (qtd) |
1732 | pe(hcd, qh, qtd); | 1638 | pe(hcd, qh, qtd); |
1733 | break; | 1639 | break; |
1734 | 1640 | ||
1735 | } else if (ints->qtd) { | 1641 | } else { |
1736 | struct isp1760_qtd *qtd, *prev_qtd = ints->qtd; | 1642 | struct isp1760_qtd *qtd; |
1737 | 1643 | ||
1738 | for (qtd = ints->qtd->hw_next; qtd; qtd = qtd->hw_next) { | 1644 | list_for_each_entry(qtd, &ints[i].qtd->qtd_list, |
1645 | qtd_list) { | ||
1739 | if (qtd->urb == urb) { | 1646 | if (qtd->urb == urb) { |
1740 | prev_qtd->hw_next = clean_up_qtdlist(qtd); | 1647 | clean_up_qtdlist(qtd, ints[i].qh); |
1741 | isp1760_urb_done(priv, urb, status); | 1648 | isp1760_urb_done(hcd, urb); |
1649 | qtd = NULL; | ||
1742 | break; | 1650 | break; |
1743 | } | 1651 | } |
1744 | prev_qtd = qtd; | ||
1745 | } | 1652 | } |
1746 | /* we found the urb before the end of the list */ | 1653 | |
1747 | if (qtd) | 1654 | /* We found the urb before the last slot */ |
1655 | if (!qtd) | ||
1748 | break; | 1656 | break; |
1749 | } | 1657 | } |
1750 | ints++; | ||
1751 | } | 1658 | } |
1752 | 1659 | ||
1753 | spin_unlock_irqrestore(&priv->lock, flags); | 1660 | spin_unlock_irqrestore(&priv->lock, flags); |
1754 | return 0; | 1661 | return 0; |
1755 | } | 1662 | } |
1756 | 1663 | ||
1757 | static irqreturn_t isp1760_irq(struct usb_hcd *usb_hcd) | 1664 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) |
1758 | { | 1665 | { |
1759 | struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); | 1666 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
1760 | u32 imask; | 1667 | u32 imask; |
1761 | irqreturn_t irqret = IRQ_NONE; | 1668 | irqreturn_t irqret = IRQ_NONE; |
1762 | 1669 | ||
1763 | spin_lock(&priv->lock); | 1670 | spin_lock(&priv->lock); |
1764 | 1671 | ||
1765 | if (!(usb_hcd->state & HC_STATE_RUNNING)) | 1672 | if (!(hcd->state & HC_STATE_RUNNING)) |
1766 | goto leave; | 1673 | goto leave; |
1767 | 1674 | ||
1768 | imask = isp1760_readl(usb_hcd->regs + HC_INTERRUPT_REG); | 1675 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); |
1769 | if (unlikely(!imask)) | 1676 | if (unlikely(!imask)) |
1770 | goto leave; | 1677 | goto leave; |
1771 | 1678 | ||
1772 | isp1760_writel(imask, usb_hcd->regs + HC_INTERRUPT_REG); | 1679 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); |
1773 | if (imask & HC_ATL_INT) | 1680 | if (imask & (HC_ATL_INT | HC_SOT_INT)) |
1774 | do_atl_int(usb_hcd); | 1681 | do_atl_int(hcd); |
1775 | 1682 | ||
1776 | if (imask & HC_INTL_INT) | 1683 | if (imask & HC_INTL_INT) |
1777 | do_intl_int(usb_hcd); | 1684 | do_intl_int(hcd); |
1778 | 1685 | ||
1779 | irqret = IRQ_HANDLED; | 1686 | irqret = IRQ_HANDLED; |
1780 | leave: | 1687 | leave: |
@@ -1799,12 +1706,12 @@ static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
1799 | mask = PORT_CSC; | 1706 | mask = PORT_CSC; |
1800 | 1707 | ||
1801 | spin_lock_irqsave(&priv->lock, flags); | 1708 | spin_lock_irqsave(&priv->lock, flags); |
1802 | temp = isp1760_readl(hcd->regs + HC_PORTSC1); | 1709 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
1803 | 1710 | ||
1804 | if (temp & PORT_OWNER) { | 1711 | if (temp & PORT_OWNER) { |
1805 | if (temp & PORT_CSC) { | 1712 | if (temp & PORT_CSC) { |
1806 | temp &= ~PORT_CSC; | 1713 | temp &= ~PORT_CSC; |
1807 | isp1760_writel(temp, hcd->regs + HC_PORTSC1); | 1714 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
1808 | goto done; | 1715 | goto done; |
1809 | } | 1716 | } |
1810 | } | 1717 | } |
@@ -1844,9 +1751,9 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv, | |||
1844 | temp = 1 + (ports / 8); | 1751 | temp = 1 + (ports / 8); |
1845 | desc->bDescLength = 7 + 2 * temp; | 1752 | desc->bDescLength = 7 + 2 * temp; |
1846 | 1753 | ||
1847 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 1754 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
1848 | memset(&desc->bitmap[0], 0, temp); | 1755 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
1849 | memset(&desc->bitmap[temp], 0xff, temp); | 1756 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
1850 | 1757 | ||
1851 | /* per-port overcurrent reporting */ | 1758 | /* per-port overcurrent reporting */ |
1852 | temp = 0x0008; | 1759 | temp = 0x0008; |
@@ -1861,8 +1768,8 @@ static void isp1760_hub_descriptor(struct isp1760_hcd *priv, | |||
1861 | 1768 | ||
1862 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) | 1769 | #define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E) |
1863 | 1770 | ||
1864 | static int check_reset_complete(struct isp1760_hcd *priv, int index, | 1771 | static int check_reset_complete(struct usb_hcd *hcd, int index, |
1865 | u32 __iomem *status_reg, int port_status) | 1772 | int port_status) |
1866 | { | 1773 | { |
1867 | if (!(port_status & PORT_CONNECT)) | 1774 | if (!(port_status & PORT_CONNECT)) |
1868 | return port_status; | 1775 | return port_status; |
@@ -1870,15 +1777,17 @@ static int check_reset_complete(struct isp1760_hcd *priv, int index, | |||
1870 | /* if reset finished and it's still not enabled -- handoff */ | 1777 | /* if reset finished and it's still not enabled -- handoff */ |
1871 | if (!(port_status & PORT_PE)) { | 1778 | if (!(port_status & PORT_PE)) { |
1872 | 1779 | ||
1873 | printk(KERN_ERR "port %d full speed --> companion\n", | 1780 | dev_err(hcd->self.controller, |
1874 | index + 1); | 1781 | "port %d full speed --> companion\n", |
1782 | index + 1); | ||
1875 | 1783 | ||
1876 | port_status |= PORT_OWNER; | 1784 | port_status |= PORT_OWNER; |
1877 | port_status &= ~PORT_RWC_BITS; | 1785 | port_status &= ~PORT_RWC_BITS; |
1878 | isp1760_writel(port_status, status_reg); | 1786 | reg_write32(hcd->regs, HC_PORTSC1, port_status); |
1879 | 1787 | ||
1880 | } else | 1788 | } else |
1881 | printk(KERN_ERR "port %d high speed\n", index + 1); | 1789 | dev_err(hcd->self.controller, "port %d high speed\n", |
1790 | index + 1); | ||
1882 | 1791 | ||
1883 | return port_status; | 1792 | return port_status; |
1884 | } | 1793 | } |
@@ -1888,7 +1797,6 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1888 | { | 1797 | { |
1889 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 1798 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
1890 | int ports = HCS_N_PORTS(priv->hcs_params); | 1799 | int ports = HCS_N_PORTS(priv->hcs_params); |
1891 | u32 __iomem *status_reg = hcd->regs + HC_PORTSC1; | ||
1892 | u32 temp, status; | 1800 | u32 temp, status; |
1893 | unsigned long flags; | 1801 | unsigned long flags; |
1894 | int retval = 0; | 1802 | int retval = 0; |
@@ -1917,7 +1825,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1917 | if (!wIndex || wIndex > ports) | 1825 | if (!wIndex || wIndex > ports) |
1918 | goto error; | 1826 | goto error; |
1919 | wIndex--; | 1827 | wIndex--; |
1920 | temp = isp1760_readl(status_reg); | 1828 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
1921 | 1829 | ||
1922 | /* | 1830 | /* |
1923 | * Even if OWNER is set, so the port is owned by the | 1831 | * Even if OWNER is set, so the port is owned by the |
@@ -1928,7 +1836,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1928 | 1836 | ||
1929 | switch (wValue) { | 1837 | switch (wValue) { |
1930 | case USB_PORT_FEAT_ENABLE: | 1838 | case USB_PORT_FEAT_ENABLE: |
1931 | isp1760_writel(temp & ~PORT_PE, status_reg); | 1839 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_PE); |
1932 | break; | 1840 | break; |
1933 | case USB_PORT_FEAT_C_ENABLE: | 1841 | case USB_PORT_FEAT_C_ENABLE: |
1934 | /* XXX error? */ | 1842 | /* XXX error? */ |
@@ -1942,8 +1850,8 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1942 | goto error; | 1850 | goto error; |
1943 | /* resume signaling for 20 msec */ | 1851 | /* resume signaling for 20 msec */ |
1944 | temp &= ~(PORT_RWC_BITS); | 1852 | temp &= ~(PORT_RWC_BITS); |
1945 | isp1760_writel(temp | PORT_RESUME, | 1853 | reg_write32(hcd->regs, HC_PORTSC1, |
1946 | status_reg); | 1854 | temp | PORT_RESUME); |
1947 | priv->reset_done = jiffies + | 1855 | priv->reset_done = jiffies + |
1948 | msecs_to_jiffies(20); | 1856 | msecs_to_jiffies(20); |
1949 | } | 1857 | } |
@@ -1953,11 +1861,11 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1953 | break; | 1861 | break; |
1954 | case USB_PORT_FEAT_POWER: | 1862 | case USB_PORT_FEAT_POWER: |
1955 | if (HCS_PPC(priv->hcs_params)) | 1863 | if (HCS_PPC(priv->hcs_params)) |
1956 | isp1760_writel(temp & ~PORT_POWER, status_reg); | 1864 | reg_write32(hcd->regs, HC_PORTSC1, |
1865 | temp & ~PORT_POWER); | ||
1957 | break; | 1866 | break; |
1958 | case USB_PORT_FEAT_C_CONNECTION: | 1867 | case USB_PORT_FEAT_C_CONNECTION: |
1959 | isp1760_writel(temp | PORT_CSC, | 1868 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_CSC); |
1960 | status_reg); | ||
1961 | break; | 1869 | break; |
1962 | case USB_PORT_FEAT_C_OVER_CURRENT: | 1870 | case USB_PORT_FEAT_C_OVER_CURRENT: |
1963 | /* XXX error ?*/ | 1871 | /* XXX error ?*/ |
@@ -1968,7 +1876,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1968 | default: | 1876 | default: |
1969 | goto error; | 1877 | goto error; |
1970 | } | 1878 | } |
1971 | isp1760_readl(hcd->regs + HC_USBCMD); | 1879 | reg_read32(hcd->regs, HC_USBCMD); |
1972 | break; | 1880 | break; |
1973 | case GetHubDescriptor: | 1881 | case GetHubDescriptor: |
1974 | isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) | 1882 | isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *) |
@@ -1983,7 +1891,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1983 | goto error; | 1891 | goto error; |
1984 | wIndex--; | 1892 | wIndex--; |
1985 | status = 0; | 1893 | status = 0; |
1986 | temp = isp1760_readl(status_reg); | 1894 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
1987 | 1895 | ||
1988 | /* wPortChange bits */ | 1896 | /* wPortChange bits */ |
1989 | if (temp & PORT_CSC) | 1897 | if (temp & PORT_CSC) |
@@ -1992,7 +1900,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
1992 | 1900 | ||
1993 | /* whoever resumes must GetPortStatus to complete it!! */ | 1901 | /* whoever resumes must GetPortStatus to complete it!! */ |
1994 | if (temp & PORT_RESUME) { | 1902 | if (temp & PORT_RESUME) { |
1995 | printk(KERN_ERR "Port resume should be skipped.\n"); | 1903 | dev_err(hcd->self.controller, "Port resume should be skipped.\n"); |
1996 | 1904 | ||
1997 | /* Remote Wakeup received? */ | 1905 | /* Remote Wakeup received? */ |
1998 | if (!priv->reset_done) { | 1906 | if (!priv->reset_done) { |
@@ -2000,8 +1908,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2000 | priv->reset_done = jiffies | 1908 | priv->reset_done = jiffies |
2001 | + msecs_to_jiffies(20); | 1909 | + msecs_to_jiffies(20); |
2002 | /* check the port again */ | 1910 | /* check the port again */ |
2003 | mod_timer(&priv_to_hcd(priv)->rh_timer, | 1911 | mod_timer(&hcd->rh_timer, priv->reset_done); |
2004 | priv->reset_done); | ||
2005 | } | 1912 | } |
2006 | 1913 | ||
2007 | /* resume completed? */ | 1914 | /* resume completed? */ |
@@ -2011,14 +1918,13 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2011 | priv->reset_done = 0; | 1918 | priv->reset_done = 0; |
2012 | 1919 | ||
2013 | /* stop resume signaling */ | 1920 | /* stop resume signaling */ |
2014 | temp = isp1760_readl(status_reg); | 1921 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
2015 | isp1760_writel( | 1922 | reg_write32(hcd->regs, HC_PORTSC1, |
2016 | temp & ~(PORT_RWC_BITS | PORT_RESUME), | 1923 | temp & ~(PORT_RWC_BITS | PORT_RESUME)); |
2017 | status_reg); | 1924 | retval = handshake(hcd, HC_PORTSC1, |
2018 | retval = handshake(priv, status_reg, | ||
2019 | PORT_RESUME, 0, 2000 /* 2msec */); | 1925 | PORT_RESUME, 0, 2000 /* 2msec */); |
2020 | if (retval != 0) { | 1926 | if (retval != 0) { |
2021 | isp1760_err(priv, | 1927 | dev_err(hcd->self.controller, |
2022 | "port %d resume error %d\n", | 1928 | "port %d resume error %d\n", |
2023 | wIndex + 1, retval); | 1929 | wIndex + 1, retval); |
2024 | goto error; | 1930 | goto error; |
@@ -2035,22 +1941,21 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2035 | priv->reset_done = 0; | 1941 | priv->reset_done = 0; |
2036 | 1942 | ||
2037 | /* force reset to complete */ | 1943 | /* force reset to complete */ |
2038 | isp1760_writel(temp & ~PORT_RESET, | 1944 | reg_write32(hcd->regs, HC_PORTSC1, temp & ~PORT_RESET); |
2039 | status_reg); | ||
2040 | /* REVISIT: some hardware needs 550+ usec to clear | 1945 | /* REVISIT: some hardware needs 550+ usec to clear |
2041 | * this bit; seems too long to spin routinely... | 1946 | * this bit; seems too long to spin routinely... |
2042 | */ | 1947 | */ |
2043 | retval = handshake(priv, status_reg, | 1948 | retval = handshake(hcd, HC_PORTSC1, |
2044 | PORT_RESET, 0, 750); | 1949 | PORT_RESET, 0, 750); |
2045 | if (retval != 0) { | 1950 | if (retval != 0) { |
2046 | isp1760_err(priv, "port %d reset error %d\n", | 1951 | dev_err(hcd->self.controller, "port %d reset error %d\n", |
2047 | wIndex + 1, retval); | 1952 | wIndex + 1, retval); |
2048 | goto error; | 1953 | goto error; |
2049 | } | 1954 | } |
2050 | 1955 | ||
2051 | /* see what we found out */ | 1956 | /* see what we found out */ |
2052 | temp = check_reset_complete(priv, wIndex, status_reg, | 1957 | temp = check_reset_complete(hcd, wIndex, |
2053 | isp1760_readl(status_reg)); | 1958 | reg_read32(hcd->regs, HC_PORTSC1)); |
2054 | } | 1959 | } |
2055 | /* | 1960 | /* |
2056 | * Even if OWNER is set, there's no harm letting khubd | 1961 | * Even if OWNER is set, there's no harm letting khubd |
@@ -2059,12 +1964,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2059 | */ | 1964 | */ |
2060 | 1965 | ||
2061 | if (temp & PORT_OWNER) | 1966 | if (temp & PORT_OWNER) |
2062 | printk(KERN_ERR "Warning: PORT_OWNER is set\n"); | 1967 | dev_err(hcd->self.controller, "PORT_OWNER is set\n"); |
2063 | 1968 | ||
2064 | if (temp & PORT_CONNECT) { | 1969 | if (temp & PORT_CONNECT) { |
2065 | status |= USB_PORT_STAT_CONNECTION; | 1970 | status |= USB_PORT_STAT_CONNECTION; |
2066 | /* status may be from integrated TT */ | 1971 | /* status may be from integrated TT */ |
2067 | status |= ehci_port_speed(priv, temp); | 1972 | status |= USB_PORT_STAT_HIGH_SPEED; |
2068 | } | 1973 | } |
2069 | if (temp & PORT_PE) | 1974 | if (temp & PORT_PE) |
2070 | status |= USB_PORT_STAT_ENABLE; | 1975 | status |= USB_PORT_STAT_ENABLE; |
@@ -2093,14 +1998,14 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2093 | if (!wIndex || wIndex > ports) | 1998 | if (!wIndex || wIndex > ports) |
2094 | goto error; | 1999 | goto error; |
2095 | wIndex--; | 2000 | wIndex--; |
2096 | temp = isp1760_readl(status_reg); | 2001 | temp = reg_read32(hcd->regs, HC_PORTSC1); |
2097 | if (temp & PORT_OWNER) | 2002 | if (temp & PORT_OWNER) |
2098 | break; | 2003 | break; |
2099 | 2004 | ||
2100 | /* temp &= ~PORT_RWC_BITS; */ | 2005 | /* temp &= ~PORT_RWC_BITS; */ |
2101 | switch (wValue) { | 2006 | switch (wValue) { |
2102 | case USB_PORT_FEAT_ENABLE: | 2007 | case USB_PORT_FEAT_ENABLE: |
2103 | isp1760_writel(temp | PORT_PE, status_reg); | 2008 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_PE); |
2104 | break; | 2009 | break; |
2105 | 2010 | ||
2106 | case USB_PORT_FEAT_SUSPEND: | 2011 | case USB_PORT_FEAT_SUSPEND: |
@@ -2108,12 +2013,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2108 | || (temp & PORT_RESET) != 0) | 2013 | || (temp & PORT_RESET) != 0) |
2109 | goto error; | 2014 | goto error; |
2110 | 2015 | ||
2111 | isp1760_writel(temp | PORT_SUSPEND, status_reg); | 2016 | reg_write32(hcd->regs, HC_PORTSC1, temp | PORT_SUSPEND); |
2112 | break; | 2017 | break; |
2113 | case USB_PORT_FEAT_POWER: | 2018 | case USB_PORT_FEAT_POWER: |
2114 | if (HCS_PPC(priv->hcs_params)) | 2019 | if (HCS_PPC(priv->hcs_params)) |
2115 | isp1760_writel(temp | PORT_POWER, | 2020 | reg_write32(hcd->regs, HC_PORTSC1, |
2116 | status_reg); | 2021 | temp | PORT_POWER); |
2117 | break; | 2022 | break; |
2118 | case USB_PORT_FEAT_RESET: | 2023 | case USB_PORT_FEAT_RESET: |
2119 | if (temp & PORT_RESUME) | 2024 | if (temp & PORT_RESUME) |
@@ -2136,12 +2041,12 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq, | |||
2136 | priv->reset_done = jiffies + | 2041 | priv->reset_done = jiffies + |
2137 | msecs_to_jiffies(50); | 2042 | msecs_to_jiffies(50); |
2138 | } | 2043 | } |
2139 | isp1760_writel(temp, status_reg); | 2044 | reg_write32(hcd->regs, HC_PORTSC1, temp); |
2140 | break; | 2045 | break; |
2141 | default: | 2046 | default: |
2142 | goto error; | 2047 | goto error; |
2143 | } | 2048 | } |
2144 | isp1760_readl(hcd->regs + HC_USBCMD); | 2049 | reg_read32(hcd->regs, HC_USBCMD); |
2145 | break; | 2050 | break; |
2146 | 2051 | ||
2147 | default: | 2052 | default: |
@@ -2153,10 +2058,10 @@ error: | |||
2153 | return retval; | 2058 | return retval; |
2154 | } | 2059 | } |
2155 | 2060 | ||
2156 | static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd, | 2061 | static void isp1760_endpoint_disable(struct usb_hcd *hcd, |
2157 | struct usb_host_endpoint *ep) | 2062 | struct usb_host_endpoint *ep) |
2158 | { | 2063 | { |
2159 | struct isp1760_hcd *priv = hcd_to_priv(usb_hcd); | 2064 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
2160 | struct isp1760_qh *qh; | 2065 | struct isp1760_qh *qh; |
2161 | struct isp1760_qtd *qtd; | 2066 | struct isp1760_qtd *qtd; |
2162 | unsigned long flags; | 2067 | unsigned long flags; |
@@ -2176,16 +2081,16 @@ static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd, | |||
2176 | qtd_list); | 2081 | qtd_list); |
2177 | 2082 | ||
2178 | if (qtd->status & URB_ENQUEUED) { | 2083 | if (qtd->status & URB_ENQUEUED) { |
2179 | |||
2180 | spin_unlock_irqrestore(&priv->lock, flags); | 2084 | spin_unlock_irqrestore(&priv->lock, flags); |
2181 | isp1760_urb_dequeue(usb_hcd, qtd->urb, -ECONNRESET); | 2085 | isp1760_urb_dequeue(hcd, qtd->urb, -ECONNRESET); |
2182 | spin_lock_irqsave(&priv->lock, flags); | 2086 | spin_lock_irqsave(&priv->lock, flags); |
2183 | } else { | 2087 | } else { |
2184 | struct urb *urb; | 2088 | struct urb *urb; |
2185 | 2089 | ||
2186 | urb = qtd->urb; | 2090 | urb = qtd->urb; |
2187 | clean_up_qtdlist(qtd); | 2091 | clean_up_qtdlist(qtd, qh); |
2188 | isp1760_urb_done(priv, urb, -ECONNRESET); | 2092 | urb->status = -ECONNRESET; |
2093 | isp1760_urb_done(hcd, urb); | ||
2189 | } | 2094 | } |
2190 | } while (1); | 2095 | } while (1); |
2191 | 2096 | ||
@@ -2203,7 +2108,7 @@ static int isp1760_get_frame(struct usb_hcd *hcd) | |||
2203 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 2108 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
2204 | u32 fr; | 2109 | u32 fr; |
2205 | 2110 | ||
2206 | fr = isp1760_readl(hcd->regs + HC_FRINDEX); | 2111 | fr = reg_read32(hcd->regs, HC_FRINDEX); |
2207 | return (fr >> 3) % priv->periodic_size; | 2112 | return (fr >> 3) % priv->periodic_size; |
2208 | } | 2113 | } |
2209 | 2114 | ||
@@ -2217,13 +2122,13 @@ static void isp1760_stop(struct usb_hcd *hcd) | |||
2217 | mdelay(20); | 2122 | mdelay(20); |
2218 | 2123 | ||
2219 | spin_lock_irq(&priv->lock); | 2124 | spin_lock_irq(&priv->lock); |
2220 | ehci_reset(priv); | 2125 | ehci_reset(hcd); |
2221 | /* Disable IRQ */ | 2126 | /* Disable IRQ */ |
2222 | temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); | 2127 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
2223 | isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); | 2128 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN); |
2224 | spin_unlock_irq(&priv->lock); | 2129 | spin_unlock_irq(&priv->lock); |
2225 | 2130 | ||
2226 | isp1760_writel(0, hcd->regs + HC_CONFIGFLAG); | 2131 | reg_write32(hcd->regs, HC_CONFIGFLAG, 0); |
2227 | } | 2132 | } |
2228 | 2133 | ||
2229 | static void isp1760_shutdown(struct usb_hcd *hcd) | 2134 | static void isp1760_shutdown(struct usb_hcd *hcd) |
@@ -2231,12 +2136,12 @@ static void isp1760_shutdown(struct usb_hcd *hcd) | |||
2231 | u32 command, temp; | 2136 | u32 command, temp; |
2232 | 2137 | ||
2233 | isp1760_stop(hcd); | 2138 | isp1760_stop(hcd); |
2234 | temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL); | 2139 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); |
2235 | isp1760_writel(temp &= ~HW_GLOBAL_INTR_EN, hcd->regs + HC_HW_MODE_CTRL); | 2140 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp &= ~HW_GLOBAL_INTR_EN); |
2236 | 2141 | ||
2237 | command = isp1760_readl(hcd->regs + HC_USBCMD); | 2142 | command = reg_read32(hcd->regs, HC_USBCMD); |
2238 | command &= ~CMD_RUN; | 2143 | command &= ~CMD_RUN; |
2239 | isp1760_writel(command, hcd->regs + HC_USBCMD); | 2144 | reg_write32(hcd->regs, HC_USBCMD, command); |
2240 | } | 2145 | } |
2241 | 2146 | ||
2242 | static const struct hc_driver isp1760_hc_driver = { | 2147 | static const struct hc_driver isp1760_hc_driver = { |
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h index 6931ef5c9650..870507690607 100644 --- a/drivers/usb/host/isp1760-hcd.h +++ b/drivers/usb/host/isp1760-hcd.h | |||
@@ -69,6 +69,7 @@ void deinit_kmem_cache(void); | |||
69 | 69 | ||
70 | #define HC_INTERRUPT_ENABLE 0x314 | 70 | #define HC_INTERRUPT_ENABLE 0x314 |
71 | #define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT) | 71 | #define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT) |
72 | #define INTERRUPT_ENABLE_SOT_MASK (HC_INTL_INT | HC_SOT_INT | HC_EOT_INT) | ||
72 | 73 | ||
73 | #define HC_ISO_INT (1 << 9) | 74 | #define HC_ISO_INT (1 << 9) |
74 | #define HC_ATL_INT (1 << 8) | 75 | #define HC_ATL_INT (1 << 8) |
@@ -83,37 +84,29 @@ void deinit_kmem_cache(void); | |||
83 | #define HC_INT_IRQ_MASK_AND_REG 0x328 | 84 | #define HC_INT_IRQ_MASK_AND_REG 0x328 |
84 | #define HC_ATL_IRQ_MASK_AND_REG 0x32C | 85 | #define HC_ATL_IRQ_MASK_AND_REG 0x32C |
85 | 86 | ||
86 | /* Register sets */ | ||
87 | #define HC_BEGIN_OF_ATL 0x0c00 | ||
88 | #define HC_BEGIN_OF_INT 0x0800 | ||
89 | #define HC_BEGIN_OF_ISO 0x0400 | ||
90 | #define HC_BEGIN_OF_PAYLOAD 0x1000 | ||
91 | |||
92 | /* urb state*/ | 87 | /* urb state*/ |
93 | #define DELETE_URB (0x0008) | 88 | #define DELETE_URB (0x0008) |
94 | #define NO_TRANSFER_ACTIVE (0xffffffff) | 89 | #define NO_TRANSFER_ACTIVE (0xffffffff) |
95 | 90 | ||
96 | #define ATL_REGS_OFFSET (0xc00) | 91 | /* Philips Proprietary Transfer Descriptor (PTD) */ |
97 | #define INT_REGS_OFFSET (0x800) | 92 | typedef __u32 __bitwise __dw; |
98 | |||
99 | /* Philips Transfer Descriptor (PTD) */ | ||
100 | struct ptd { | 93 | struct ptd { |
101 | __le32 dw0; | 94 | __dw dw0; |
102 | __le32 dw1; | 95 | __dw dw1; |
103 | __le32 dw2; | 96 | __dw dw2; |
104 | __le32 dw3; | 97 | __dw dw3; |
105 | __le32 dw4; | 98 | __dw dw4; |
106 | __le32 dw5; | 99 | __dw dw5; |
107 | __le32 dw6; | 100 | __dw dw6; |
108 | __le32 dw7; | 101 | __dw dw7; |
109 | }; | 102 | }; |
103 | #define PTD_OFFSET 0x0400 | ||
104 | #define ISO_PTD_OFFSET 0x0400 | ||
105 | #define INT_PTD_OFFSET 0x0800 | ||
106 | #define ATL_PTD_OFFSET 0x0c00 | ||
107 | #define PAYLOAD_OFFSET 0x1000 | ||
110 | 108 | ||
111 | struct inter_packet_info { | 109 | struct inter_packet_info { |
112 | void *data_buffer; | ||
113 | u32 payload; | ||
114 | #define PTD_FIRE_NEXT (1 << 0) | ||
115 | #define PTD_URB_FINISHED (1 << 1) | ||
116 | struct urb *urb; | ||
117 | struct isp1760_qh *qh; | 110 | struct isp1760_qh *qh; |
118 | struct isp1760_qtd *qtd; | 111 | struct isp1760_qtd *qtd; |
119 | }; | 112 | }; |
@@ -122,15 +115,6 @@ struct inter_packet_info { | |||
122 | typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, | 115 | typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, |
123 | struct isp1760_qtd *qtd); | 116 | struct isp1760_qtd *qtd); |
124 | 117 | ||
125 | #define isp1760_dbg(priv, fmt, args...) \ | ||
126 | dev_dbg(priv_to_hcd(priv)->self.controller, fmt, ##args) | ||
127 | |||
128 | #define isp1760_info(priv, fmt, args...) \ | ||
129 | dev_info(priv_to_hcd(priv)->self.controller, fmt, ##args) | ||
130 | |||
131 | #define isp1760_err(priv, fmt, args...) \ | ||
132 | dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args) | ||
133 | |||
134 | /* | 118 | /* |
135 | * Device flags that can vary from board to board. All of these | 119 | * Device flags that can vary from board to board. All of these |
136 | * indicate the most "atypical" case, so that a devflags of 0 is | 120 | * indicate the most "atypical" case, so that a devflags of 0 is |
@@ -167,10 +151,8 @@ struct memory_chunk { | |||
167 | #define BLOCK_2_SIZE 1024 | 151 | #define BLOCK_2_SIZE 1024 |
168 | #define BLOCK_3_SIZE 8192 | 152 | #define BLOCK_3_SIZE 8192 |
169 | #define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM) | 153 | #define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM) |
170 | #define PAYLOAD_SIZE 0xf000 | 154 | #define MAX_PAYLOAD_SIZE BLOCK_3_SIZE |
171 | 155 | #define PAYLOAD_AREA_SIZE 0xf000 | |
172 | /* I saw if some reloads if the pointer was negative */ | ||
173 | #define ISP1760_NULL_POINTER (0x400) | ||
174 | 156 | ||
175 | /* ATL */ | 157 | /* ATL */ |
176 | /* DW0 */ | 158 | /* DW0 */ |
@@ -224,6 +206,4 @@ struct memory_chunk { | |||
224 | #define NAK_COUNTER (0) | 206 | #define NAK_COUNTER (0) |
225 | #define ERR_COUNTER (2) | 207 | #define ERR_COUNTER (2) |
226 | 208 | ||
227 | #define HC_ATL_PL_SIZE (8192) | ||
228 | |||
229 | #endif | 209 | #endif |
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index 759a12ff8048..fb035751e4b2 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
@@ -75,6 +75,7 @@ static const char hcd_name [] = "ohci_hcd"; | |||
75 | #define STATECHANGE_DELAY msecs_to_jiffies(300) | 75 | #define STATECHANGE_DELAY msecs_to_jiffies(300) |
76 | 76 | ||
77 | #include "ohci.h" | 77 | #include "ohci.h" |
78 | #include "pci-quirks.h" | ||
78 | 79 | ||
79 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); | 80 | static void ohci_dump (struct ohci_hcd *ohci, int verbose); |
80 | static int ohci_init (struct ohci_hcd *ohci); | 81 | static int ohci_init (struct ohci_hcd *ohci); |
@@ -85,18 +86,8 @@ static int ohci_restart (struct ohci_hcd *ohci); | |||
85 | #endif | 86 | #endif |
86 | 87 | ||
87 | #ifdef CONFIG_PCI | 88 | #ifdef CONFIG_PCI |
88 | static void quirk_amd_pll(int state); | ||
89 | static void amd_iso_dev_put(void); | ||
90 | static void sb800_prefetch(struct ohci_hcd *ohci, int on); | 89 | static void sb800_prefetch(struct ohci_hcd *ohci, int on); |
91 | #else | 90 | #else |
92 | static inline void quirk_amd_pll(int state) | ||
93 | { | ||
94 | return; | ||
95 | } | ||
96 | static inline void amd_iso_dev_put(void) | ||
97 | { | ||
98 | return; | ||
99 | } | ||
100 | static inline void sb800_prefetch(struct ohci_hcd *ohci, int on) | 91 | static inline void sb800_prefetch(struct ohci_hcd *ohci, int on) |
101 | { | 92 | { |
102 | return; | 93 | return; |
@@ -912,7 +903,7 @@ static void ohci_stop (struct usb_hcd *hcd) | |||
912 | if (quirk_zfmicro(ohci)) | 903 | if (quirk_zfmicro(ohci)) |
913 | del_timer(&ohci->unlink_watchdog); | 904 | del_timer(&ohci->unlink_watchdog); |
914 | if (quirk_amdiso(ohci)) | 905 | if (quirk_amdiso(ohci)) |
915 | amd_iso_dev_put(); | 906 | usb_amd_dev_put(); |
916 | 907 | ||
917 | remove_debug_files (ohci); | 908 | remove_debug_files (ohci); |
918 | ohci_mem_cleanup (ohci); | 909 | ohci_mem_cleanup (ohci); |
@@ -1068,10 +1059,7 @@ MODULE_LICENSE ("GPL"); | |||
1068 | #define PLATFORM_DRIVER ohci_hcd_da8xx_driver | 1059 | #define PLATFORM_DRIVER ohci_hcd_da8xx_driver |
1069 | #endif | 1060 | #endif |
1070 | 1061 | ||
1071 | #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ | 1062 | #ifdef CONFIG_USB_OHCI_SH |
1072 | defined(CONFIG_CPU_SUBTYPE_SH7721) || \ | ||
1073 | defined(CONFIG_CPU_SUBTYPE_SH7763) || \ | ||
1074 | defined(CONFIG_CPU_SUBTYPE_SH7786) | ||
1075 | #include "ohci-sh.c" | 1063 | #include "ohci-sh.c" |
1076 | #define PLATFORM_DRIVER ohci_hcd_sh_driver | 1064 | #define PLATFORM_DRIVER ohci_hcd_sh_driver |
1077 | #endif | 1065 | #endif |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index cddcda95b579..9154615292db 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
@@ -580,15 +580,16 @@ ohci_hub_descriptor ( | |||
580 | temp |= 0x0008; | 580 | temp |= 0x0008; |
581 | desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); | 581 | desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); |
582 | 582 | ||
583 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 583 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
584 | rh = roothub_b (ohci); | 584 | rh = roothub_b (ohci); |
585 | memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); | 585 | memset(desc->u.hs.DeviceRemovable, 0xff, |
586 | desc->bitmap [0] = rh & RH_B_DR; | 586 | sizeof(desc->u.hs.DeviceRemovable)); |
587 | desc->u.hs.DeviceRemovable[0] = rh & RH_B_DR; | ||
587 | if (ohci->num_ports > 7) { | 588 | if (ohci->num_ports > 7) { |
588 | desc->bitmap [1] = (rh & RH_B_DR) >> 8; | 589 | desc->u.hs.DeviceRemovable[1] = (rh & RH_B_DR) >> 8; |
589 | desc->bitmap [2] = 0xff; | 590 | desc->u.hs.DeviceRemovable[2] = 0xff; |
590 | } else | 591 | } else |
591 | desc->bitmap [1] = 0xff; | 592 | desc->u.hs.DeviceRemovable[1] = 0xff; |
592 | } | 593 | } |
593 | 594 | ||
594 | /*-------------------------------------------------------------------------*/ | 595 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c index a37d5993e4e3..6048f2f64f73 100644 --- a/drivers/usb/host/ohci-omap3.c +++ b/drivers/usb/host/ohci-omap3.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Copyright (C) 2007-2010 Texas Instruments, Inc. | 7 | * Copyright (C) 2007-2010 Texas Instruments, Inc. |
8 | * Author: Vikram Pandita <vikram.pandita@ti.com> | 8 | * Author: Vikram Pandita <vikram.pandita@ti.com> |
9 | * Author: Anand Gadiyar <gadiyar@ti.com> | 9 | * Author: Anand Gadiyar <gadiyar@ti.com> |
10 | * Author: Keshava Munegowda <keshava_mgowda@ti.com> | ||
10 | * | 11 | * |
11 | * Based on ehci-omap.c and some other ohci glue layers | 12 | * Based on ehci-omap.c and some other ohci glue layers |
12 | * | 13 | * |
@@ -24,150 +25,15 @@ | |||
24 | * along with this program; if not, write to the Free Software | 25 | * along with this program; if not, write to the Free Software |
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
26 | * | 27 | * |
27 | * TODO (last updated Mar 10th, 2010): | 28 | * TODO (last updated Feb 27, 2011): |
28 | * - add kernel-doc | 29 | * - add kernel-doc |
29 | * - Factor out code common to EHCI to a separate file | ||
30 | * - Make EHCI and OHCI coexist together | ||
31 | * - needs newer silicon versions to actually work | ||
32 | * - the last one to be loaded currently steps on the other's toes | ||
33 | * - Add hooks for configuring transceivers, etc. at init/exit | ||
34 | * - Add aggressive clock-management code | ||
35 | */ | 30 | */ |
36 | 31 | ||
37 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
38 | #include <linux/clk.h> | ||
39 | |||
40 | #include <plat/usb.h> | 33 | #include <plat/usb.h> |
41 | 34 | ||
42 | /* | ||
43 | * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES | ||
44 | * Use ohci_omap_readl()/ohci_omap_writel() functions | ||
45 | */ | ||
46 | |||
47 | /* TLL Register Set */ | ||
48 | #define OMAP_USBTLL_REVISION (0x00) | ||
49 | #define OMAP_USBTLL_SYSCONFIG (0x10) | ||
50 | #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8) | ||
51 | #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3) | ||
52 | #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
53 | #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1) | ||
54 | #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0) | ||
55 | |||
56 | #define OMAP_USBTLL_SYSSTATUS (0x14) | ||
57 | #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0) | ||
58 | |||
59 | #define OMAP_USBTLL_IRQSTATUS (0x18) | ||
60 | #define OMAP_USBTLL_IRQENABLE (0x1C) | ||
61 | |||
62 | #define OMAP_TLL_SHARED_CONF (0x30) | ||
63 | #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6) | ||
64 | #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5) | ||
65 | #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2) | ||
66 | #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1) | ||
67 | #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0) | ||
68 | |||
69 | #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num) | ||
70 | #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24 | ||
71 | #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11) | ||
72 | #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10) | ||
73 | #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9) | ||
74 | #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8) | ||
75 | #define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1) | ||
76 | #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0) | ||
77 | |||
78 | #define OMAP_TLL_CHANNEL_COUNT 3 | ||
79 | |||
80 | /* UHH Register Set */ | ||
81 | #define OMAP_UHH_REVISION (0x00) | ||
82 | #define OMAP_UHH_SYSCONFIG (0x10) | ||
83 | #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12) | ||
84 | #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8) | ||
85 | #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3) | ||
86 | #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2) | ||
87 | #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1) | ||
88 | #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0) | ||
89 | |||
90 | #define OMAP_UHH_SYSSTATUS (0x14) | ||
91 | #define OMAP_UHH_SYSSTATUS_UHHRESETDONE (1 << 0) | ||
92 | #define OMAP_UHH_SYSSTATUS_OHCIRESETDONE (1 << 1) | ||
93 | #define OMAP_UHH_SYSSTATUS_EHCIRESETDONE (1 << 2) | ||
94 | #define OMAP_UHH_HOSTCONFIG (0x40) | ||
95 | #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0) | ||
96 | #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0) | ||
97 | #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11) | ||
98 | #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12) | ||
99 | #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2) | ||
100 | #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3) | ||
101 | #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4) | ||
102 | #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5) | ||
103 | #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8) | ||
104 | #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9) | ||
105 | #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10) | ||
106 | |||
107 | #define OMAP_UHH_DEBUG_CSR (0x44) | ||
108 | |||
109 | /*-------------------------------------------------------------------------*/ | 35 | /*-------------------------------------------------------------------------*/ |
110 | 36 | ||
111 | static inline void ohci_omap_writel(void __iomem *base, u32 reg, u32 val) | ||
112 | { | ||
113 | __raw_writel(val, base + reg); | ||
114 | } | ||
115 | |||
116 | static inline u32 ohci_omap_readl(void __iomem *base, u32 reg) | ||
117 | { | ||
118 | return __raw_readl(base + reg); | ||
119 | } | ||
120 | |||
121 | static inline void ohci_omap_writeb(void __iomem *base, u8 reg, u8 val) | ||
122 | { | ||
123 | __raw_writeb(val, base + reg); | ||
124 | } | ||
125 | |||
126 | static inline u8 ohci_omap_readb(void __iomem *base, u8 reg) | ||
127 | { | ||
128 | return __raw_readb(base + reg); | ||
129 | } | ||
130 | |||
131 | /*-------------------------------------------------------------------------*/ | ||
132 | |||
133 | struct ohci_hcd_omap3 { | ||
134 | struct ohci_hcd *ohci; | ||
135 | struct device *dev; | ||
136 | |||
137 | struct clk *usbhost_ick; | ||
138 | struct clk *usbhost2_120m_fck; | ||
139 | struct clk *usbhost1_48m_fck; | ||
140 | struct clk *usbtll_fck; | ||
141 | struct clk *usbtll_ick; | ||
142 | |||
143 | /* port_mode: TLL/PHY, 2/3/4/6-PIN, DP-DM/DAT-SE0 */ | ||
144 | enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS]; | ||
145 | void __iomem *uhh_base; | ||
146 | void __iomem *tll_base; | ||
147 | void __iomem *ohci_base; | ||
148 | |||
149 | unsigned es2_compatibility:1; | ||
150 | }; | ||
151 | |||
152 | /*-------------------------------------------------------------------------*/ | ||
153 | |||
154 | static void ohci_omap3_clock_power(struct ohci_hcd_omap3 *omap, int on) | ||
155 | { | ||
156 | if (on) { | ||
157 | clk_enable(omap->usbtll_ick); | ||
158 | clk_enable(omap->usbtll_fck); | ||
159 | clk_enable(omap->usbhost_ick); | ||
160 | clk_enable(omap->usbhost1_48m_fck); | ||
161 | clk_enable(omap->usbhost2_120m_fck); | ||
162 | } else { | ||
163 | clk_disable(omap->usbhost2_120m_fck); | ||
164 | clk_disable(omap->usbhost1_48m_fck); | ||
165 | clk_disable(omap->usbhost_ick); | ||
166 | clk_disable(omap->usbtll_fck); | ||
167 | clk_disable(omap->usbtll_ick); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | static int ohci_omap3_init(struct usb_hcd *hcd) | 37 | static int ohci_omap3_init(struct usb_hcd *hcd) |
172 | { | 38 | { |
173 | dev_dbg(hcd->self.controller, "starting OHCI controller\n"); | 39 | dev_dbg(hcd->self.controller, "starting OHCI controller\n"); |
@@ -175,7 +41,6 @@ static int ohci_omap3_init(struct usb_hcd *hcd) | |||
175 | return ohci_init(hcd_to_ohci(hcd)); | 41 | return ohci_init(hcd_to_ohci(hcd)); |
176 | } | 42 | } |
177 | 43 | ||
178 | |||
179 | /*-------------------------------------------------------------------------*/ | 44 | /*-------------------------------------------------------------------------*/ |
180 | 45 | ||
181 | static int ohci_omap3_start(struct usb_hcd *hcd) | 46 | static int ohci_omap3_start(struct usb_hcd *hcd) |
@@ -202,325 +67,6 @@ static int ohci_omap3_start(struct usb_hcd *hcd) | |||
202 | 67 | ||
203 | /*-------------------------------------------------------------------------*/ | 68 | /*-------------------------------------------------------------------------*/ |
204 | 69 | ||
205 | /* | ||
206 | * convert the port-mode enum to a value we can use in the FSLSMODE | ||
207 | * field of USBTLL_CHANNEL_CONF | ||
208 | */ | ||
209 | static unsigned ohci_omap3_fslsmode(enum ohci_omap3_port_mode mode) | ||
210 | { | ||
211 | switch (mode) { | ||
212 | case OMAP_OHCI_PORT_MODE_UNUSED: | ||
213 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0: | ||
214 | return 0x0; | ||
215 | |||
216 | case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM: | ||
217 | return 0x1; | ||
218 | |||
219 | case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0: | ||
220 | return 0x2; | ||
221 | |||
222 | case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM: | ||
223 | return 0x3; | ||
224 | |||
225 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0: | ||
226 | return 0x4; | ||
227 | |||
228 | case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM: | ||
229 | return 0x5; | ||
230 | |||
231 | case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0: | ||
232 | return 0x6; | ||
233 | |||
234 | case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM: | ||
235 | return 0x7; | ||
236 | |||
237 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0: | ||
238 | return 0xA; | ||
239 | |||
240 | case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM: | ||
241 | return 0xB; | ||
242 | default: | ||
243 | pr_warning("Invalid port mode, using default\n"); | ||
244 | return 0x0; | ||
245 | } | ||
246 | } | ||
247 | |||
248 | static void ohci_omap3_tll_config(struct ohci_hcd_omap3 *omap) | ||
249 | { | ||
250 | u32 reg; | ||
251 | int i; | ||
252 | |||
253 | /* Program TLL SHARED CONF */ | ||
254 | reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF); | ||
255 | reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN; | ||
256 | reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN; | ||
257 | reg |= OMAP_TLL_SHARED_CONF_USB_DIVRATION; | ||
258 | reg |= OMAP_TLL_SHARED_CONF_FCLK_IS_ON; | ||
259 | ohci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg); | ||
260 | |||
261 | /* Program each TLL channel */ | ||
262 | /* | ||
263 | * REVISIT: Only the 3-pin and 4-pin PHY modes have | ||
264 | * actually been tested. | ||
265 | */ | ||
266 | for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) { | ||
267 | |||
268 | /* Enable only those channels that are actually used */ | ||
269 | if (omap->port_mode[i] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
270 | continue; | ||
271 | |||
272 | reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i)); | ||
273 | reg |= ohci_omap3_fslsmode(omap->port_mode[i]) | ||
274 | << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT; | ||
275 | reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS; | ||
276 | reg |= OMAP_TLL_CHANNEL_CONF_CHANEN; | ||
277 | ohci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg); | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /* omap3_start_ohci | ||
282 | * - Start the TI USBHOST controller | ||
283 | */ | ||
284 | static int omap3_start_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd) | ||
285 | { | ||
286 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | ||
287 | u32 reg = 0; | ||
288 | int ret = 0; | ||
289 | |||
290 | dev_dbg(omap->dev, "starting TI OHCI USB Controller\n"); | ||
291 | |||
292 | /* Get all the clock handles we need */ | ||
293 | omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick"); | ||
294 | if (IS_ERR(omap->usbhost_ick)) { | ||
295 | dev_err(omap->dev, "could not get usbhost_ick\n"); | ||
296 | ret = PTR_ERR(omap->usbhost_ick); | ||
297 | goto err_host_ick; | ||
298 | } | ||
299 | |||
300 | omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck"); | ||
301 | if (IS_ERR(omap->usbhost2_120m_fck)) { | ||
302 | dev_err(omap->dev, "could not get usbhost_120m_fck\n"); | ||
303 | ret = PTR_ERR(omap->usbhost2_120m_fck); | ||
304 | goto err_host_120m_fck; | ||
305 | } | ||
306 | |||
307 | omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck"); | ||
308 | if (IS_ERR(omap->usbhost1_48m_fck)) { | ||
309 | dev_err(omap->dev, "could not get usbhost_48m_fck\n"); | ||
310 | ret = PTR_ERR(omap->usbhost1_48m_fck); | ||
311 | goto err_host_48m_fck; | ||
312 | } | ||
313 | |||
314 | omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck"); | ||
315 | if (IS_ERR(omap->usbtll_fck)) { | ||
316 | dev_err(omap->dev, "could not get usbtll_fck\n"); | ||
317 | ret = PTR_ERR(omap->usbtll_fck); | ||
318 | goto err_tll_fck; | ||
319 | } | ||
320 | |||
321 | omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick"); | ||
322 | if (IS_ERR(omap->usbtll_ick)) { | ||
323 | dev_err(omap->dev, "could not get usbtll_ick\n"); | ||
324 | ret = PTR_ERR(omap->usbtll_ick); | ||
325 | goto err_tll_ick; | ||
326 | } | ||
327 | |||
328 | /* Now enable all the clocks in the correct order */ | ||
329 | ohci_omap3_clock_power(omap, 1); | ||
330 | |||
331 | /* perform TLL soft reset, and wait until reset is complete */ | ||
332 | ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | ||
333 | OMAP_USBTLL_SYSCONFIG_SOFTRESET); | ||
334 | |||
335 | /* Wait for TLL reset to complete */ | ||
336 | while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
337 | & OMAP_USBTLL_SYSSTATUS_RESETDONE)) { | ||
338 | cpu_relax(); | ||
339 | |||
340 | if (time_after(jiffies, timeout)) { | ||
341 | dev_dbg(omap->dev, "operation timed out\n"); | ||
342 | ret = -EINVAL; | ||
343 | goto err_sys_status; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | dev_dbg(omap->dev, "TLL reset done\n"); | ||
348 | |||
349 | /* (1<<3) = no idle mode only for initial debugging */ | ||
350 | ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, | ||
351 | OMAP_USBTLL_SYSCONFIG_ENAWAKEUP | | ||
352 | OMAP_USBTLL_SYSCONFIG_SIDLEMODE | | ||
353 | OMAP_USBTLL_SYSCONFIG_CACTIVITY); | ||
354 | |||
355 | |||
356 | /* Put UHH in NoIdle/NoStandby mode */ | ||
357 | reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG); | ||
358 | reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP | ||
359 | | OMAP_UHH_SYSCONFIG_SIDLEMODE | ||
360 | | OMAP_UHH_SYSCONFIG_CACTIVITY | ||
361 | | OMAP_UHH_SYSCONFIG_MIDLEMODE); | ||
362 | reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE; | ||
363 | reg &= ~OMAP_UHH_SYSCONFIG_SOFTRESET; | ||
364 | |||
365 | ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg); | ||
366 | |||
367 | reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG); | ||
368 | |||
369 | /* setup ULPI bypass and burst configurations */ | ||
370 | reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN | ||
371 | | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN | ||
372 | | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN); | ||
373 | reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN; | ||
374 | |||
375 | /* | ||
376 | * REVISIT: Pi_CONNECT_STATUS controls MStandby | ||
377 | * assertion and Swakeup generation - let us not | ||
378 | * worry about this for now. OMAP HWMOD framework | ||
379 | * might take care of this later. If not, we can | ||
380 | * update these registers when adding aggressive | ||
381 | * clock management code. | ||
382 | * | ||
383 | * For now, turn off all the Pi_CONNECT_STATUS bits | ||
384 | * | ||
385 | if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
386 | reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS; | ||
387 | if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
388 | reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS; | ||
389 | if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
390 | reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; | ||
391 | */ | ||
392 | reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS; | ||
393 | reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS; | ||
394 | reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; | ||
395 | |||
396 | if (omap->es2_compatibility) { | ||
397 | /* | ||
398 | * All OHCI modes need to go through the TLL, | ||
399 | * unlike in the EHCI case. So use UTMI mode | ||
400 | * for all ports for OHCI, on ES2.x silicon | ||
401 | */ | ||
402 | dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n"); | ||
403 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; | ||
404 | } else { | ||
405 | dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n"); | ||
406 | if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
407 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
408 | else | ||
409 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; | ||
410 | |||
411 | if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
412 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
413 | else | ||
414 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; | ||
415 | |||
416 | if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED) | ||
417 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
418 | else | ||
419 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; | ||
420 | |||
421 | } | ||
422 | ohci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg); | ||
423 | dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg); | ||
424 | |||
425 | ohci_omap3_tll_config(omap); | ||
426 | |||
427 | return 0; | ||
428 | |||
429 | err_sys_status: | ||
430 | ohci_omap3_clock_power(omap, 0); | ||
431 | clk_put(omap->usbtll_ick); | ||
432 | |||
433 | err_tll_ick: | ||
434 | clk_put(omap->usbtll_fck); | ||
435 | |||
436 | err_tll_fck: | ||
437 | clk_put(omap->usbhost1_48m_fck); | ||
438 | |||
439 | err_host_48m_fck: | ||
440 | clk_put(omap->usbhost2_120m_fck); | ||
441 | |||
442 | err_host_120m_fck: | ||
443 | clk_put(omap->usbhost_ick); | ||
444 | |||
445 | err_host_ick: | ||
446 | return ret; | ||
447 | } | ||
448 | |||
449 | static void omap3_stop_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd) | ||
450 | { | ||
451 | unsigned long timeout = jiffies + msecs_to_jiffies(100); | ||
452 | |||
453 | dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n"); | ||
454 | |||
455 | /* Reset USBHOST for insmod/rmmod to work */ | ||
456 | ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, | ||
457 | OMAP_UHH_SYSCONFIG_SOFTRESET); | ||
458 | while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
459 | & OMAP_UHH_SYSSTATUS_UHHRESETDONE)) { | ||
460 | cpu_relax(); | ||
461 | |||
462 | if (time_after(jiffies, timeout)) | ||
463 | dev_dbg(omap->dev, "operation timed out\n"); | ||
464 | } | ||
465 | |||
466 | while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
467 | & OMAP_UHH_SYSSTATUS_OHCIRESETDONE)) { | ||
468 | cpu_relax(); | ||
469 | |||
470 | if (time_after(jiffies, timeout)) | ||
471 | dev_dbg(omap->dev, "operation timed out\n"); | ||
472 | } | ||
473 | |||
474 | while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) | ||
475 | & OMAP_UHH_SYSSTATUS_EHCIRESETDONE)) { | ||
476 | cpu_relax(); | ||
477 | |||
478 | if (time_after(jiffies, timeout)) | ||
479 | dev_dbg(omap->dev, "operation timed out\n"); | ||
480 | } | ||
481 | |||
482 | ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1)); | ||
483 | |||
484 | while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) | ||
485 | & (1 << 0))) { | ||
486 | cpu_relax(); | ||
487 | |||
488 | if (time_after(jiffies, timeout)) | ||
489 | dev_dbg(omap->dev, "operation timed out\n"); | ||
490 | } | ||
491 | |||
492 | ohci_omap3_clock_power(omap, 0); | ||
493 | |||
494 | if (omap->usbtll_fck != NULL) { | ||
495 | clk_put(omap->usbtll_fck); | ||
496 | omap->usbtll_fck = NULL; | ||
497 | } | ||
498 | |||
499 | if (omap->usbhost_ick != NULL) { | ||
500 | clk_put(omap->usbhost_ick); | ||
501 | omap->usbhost_ick = NULL; | ||
502 | } | ||
503 | |||
504 | if (omap->usbhost1_48m_fck != NULL) { | ||
505 | clk_put(omap->usbhost1_48m_fck); | ||
506 | omap->usbhost1_48m_fck = NULL; | ||
507 | } | ||
508 | |||
509 | if (omap->usbhost2_120m_fck != NULL) { | ||
510 | clk_put(omap->usbhost2_120m_fck); | ||
511 | omap->usbhost2_120m_fck = NULL; | ||
512 | } | ||
513 | |||
514 | if (omap->usbtll_ick != NULL) { | ||
515 | clk_put(omap->usbtll_ick); | ||
516 | omap->usbtll_ick = NULL; | ||
517 | } | ||
518 | |||
519 | dev_dbg(omap->dev, "Clock to USB host has been disabled\n"); | ||
520 | } | ||
521 | |||
522 | /*-------------------------------------------------------------------------*/ | ||
523 | |||
524 | static const struct hc_driver ohci_omap3_hc_driver = { | 70 | static const struct hc_driver ohci_omap3_hc_driver = { |
525 | .description = hcd_name, | 71 | .description = hcd_name, |
526 | .product_desc = "OMAP3 OHCI Host Controller", | 72 | .product_desc = "OMAP3 OHCI Host Controller", |
@@ -580,107 +126,77 @@ static const struct hc_driver ohci_omap3_hc_driver = { | |||
580 | */ | 126 | */ |
581 | static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) | 127 | static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) |
582 | { | 128 | { |
583 | struct ohci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; | 129 | struct device *dev = &pdev->dev; |
584 | struct ohci_hcd_omap3 *omap; | 130 | struct usb_hcd *hcd = NULL; |
585 | struct resource *res; | 131 | void __iomem *regs = NULL; |
586 | struct usb_hcd *hcd; | 132 | struct resource *res; |
587 | int ret = -ENODEV; | 133 | int ret = -ENODEV; |
588 | int irq; | 134 | int irq; |
589 | 135 | ||
590 | if (usb_disabled()) | 136 | if (usb_disabled()) |
591 | goto err_disabled; | 137 | goto err_end; |
592 | 138 | ||
593 | if (!pdata) { | 139 | if (!dev->parent) { |
594 | dev_dbg(&pdev->dev, "missing platform_data\n"); | 140 | dev_err(dev, "Missing parent device\n"); |
595 | goto err_pdata; | 141 | return -ENODEV; |
596 | } | 142 | } |
597 | 143 | ||
598 | irq = platform_get_irq(pdev, 0); | 144 | irq = platform_get_irq_byname(pdev, "ohci-irq"); |
145 | if (irq < 0) { | ||
146 | dev_err(dev, "OHCI irq failed\n"); | ||
147 | return -ENODEV; | ||
148 | } | ||
599 | 149 | ||
600 | omap = kzalloc(sizeof(*omap), GFP_KERNEL); | 150 | res = platform_get_resource_byname(pdev, |
601 | if (!omap) { | 151 | IORESOURCE_MEM, "ohci"); |
602 | ret = -ENOMEM; | 152 | if (!ret) { |
603 | goto err_disabled; | 153 | dev_err(dev, "UHH OHCI get resource failed\n"); |
154 | return -ENOMEM; | ||
604 | } | 155 | } |
605 | 156 | ||
606 | hcd = usb_create_hcd(&ohci_omap3_hc_driver, &pdev->dev, | 157 | regs = ioremap(res->start, resource_size(res)); |
607 | dev_name(&pdev->dev)); | 158 | if (!regs) { |
608 | if (!hcd) { | 159 | dev_err(dev, "UHH OHCI ioremap failed\n"); |
609 | ret = -ENOMEM; | 160 | return -ENOMEM; |
610 | goto err_create_hcd; | ||
611 | } | 161 | } |
612 | 162 | ||
613 | platform_set_drvdata(pdev, omap); | ||
614 | omap->dev = &pdev->dev; | ||
615 | omap->port_mode[0] = pdata->port_mode[0]; | ||
616 | omap->port_mode[1] = pdata->port_mode[1]; | ||
617 | omap->port_mode[2] = pdata->port_mode[2]; | ||
618 | omap->es2_compatibility = pdata->es2_compatibility; | ||
619 | omap->ohci = hcd_to_ohci(hcd); | ||
620 | 163 | ||
621 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 164 | hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev, |
165 | dev_name(dev)); | ||
166 | if (!hcd) { | ||
167 | dev_err(dev, "usb_create_hcd failed\n"); | ||
168 | goto err_io; | ||
169 | } | ||
622 | 170 | ||
623 | hcd->rsrc_start = res->start; | 171 | hcd->rsrc_start = res->start; |
624 | hcd->rsrc_len = resource_size(res); | 172 | hcd->rsrc_len = resource_size(res); |
173 | hcd->regs = regs; | ||
625 | 174 | ||
626 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | 175 | ret = omap_usbhs_enable(dev); |
627 | if (!hcd->regs) { | ||
628 | dev_err(&pdev->dev, "OHCI ioremap failed\n"); | ||
629 | ret = -ENOMEM; | ||
630 | goto err_ioremap; | ||
631 | } | ||
632 | |||
633 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
634 | omap->uhh_base = ioremap(res->start, resource_size(res)); | ||
635 | if (!omap->uhh_base) { | ||
636 | dev_err(&pdev->dev, "UHH ioremap failed\n"); | ||
637 | ret = -ENOMEM; | ||
638 | goto err_uhh_ioremap; | ||
639 | } | ||
640 | |||
641 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); | ||
642 | omap->tll_base = ioremap(res->start, resource_size(res)); | ||
643 | if (!omap->tll_base) { | ||
644 | dev_err(&pdev->dev, "TLL ioremap failed\n"); | ||
645 | ret = -ENOMEM; | ||
646 | goto err_tll_ioremap; | ||
647 | } | ||
648 | |||
649 | ret = omap3_start_ohci(omap, hcd); | ||
650 | if (ret) { | 176 | if (ret) { |
651 | dev_dbg(&pdev->dev, "failed to start ohci\n"); | 177 | dev_dbg(dev, "failed to start ohci\n"); |
652 | goto err_start; | 178 | goto err_end; |
653 | } | 179 | } |
654 | 180 | ||
655 | ohci_hcd_init(omap->ohci); | 181 | ohci_hcd_init(hcd_to_ohci(hcd)); |
656 | 182 | ||
657 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 183 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); |
658 | if (ret) { | 184 | if (ret) { |
659 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); | 185 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); |
660 | goto err_add_hcd; | 186 | goto err_add_hcd; |
661 | } | 187 | } |
662 | 188 | ||
663 | return 0; | 189 | return 0; |
664 | 190 | ||
665 | err_add_hcd: | 191 | err_add_hcd: |
666 | omap3_stop_ohci(omap, hcd); | 192 | omap_usbhs_disable(dev); |
667 | |||
668 | err_start: | ||
669 | iounmap(omap->tll_base); | ||
670 | |||
671 | err_tll_ioremap: | ||
672 | iounmap(omap->uhh_base); | ||
673 | |||
674 | err_uhh_ioremap: | ||
675 | iounmap(hcd->regs); | ||
676 | 193 | ||
677 | err_ioremap: | 194 | err_end: |
678 | usb_put_hcd(hcd); | 195 | usb_put_hcd(hcd); |
679 | 196 | ||
680 | err_create_hcd: | 197 | err_io: |
681 | kfree(omap); | 198 | iounmap(regs); |
682 | err_pdata: | 199 | |
683 | err_disabled: | ||
684 | return ret; | 200 | return ret; |
685 | } | 201 | } |
686 | 202 | ||
@@ -699,24 +215,20 @@ err_disabled: | |||
699 | */ | 215 | */ |
700 | static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev) | 216 | static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev) |
701 | { | 217 | { |
702 | struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); | 218 | struct device *dev = &pdev->dev; |
703 | struct usb_hcd *hcd = ohci_to_hcd(omap->ohci); | 219 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
704 | 220 | ||
705 | usb_remove_hcd(hcd); | ||
706 | omap3_stop_ohci(omap, hcd); | ||
707 | iounmap(hcd->regs); | 221 | iounmap(hcd->regs); |
708 | iounmap(omap->tll_base); | 222 | usb_remove_hcd(hcd); |
709 | iounmap(omap->uhh_base); | 223 | omap_usbhs_disable(dev); |
710 | usb_put_hcd(hcd); | 224 | usb_put_hcd(hcd); |
711 | kfree(omap); | ||
712 | 225 | ||
713 | return 0; | 226 | return 0; |
714 | } | 227 | } |
715 | 228 | ||
716 | static void ohci_hcd_omap3_shutdown(struct platform_device *pdev) | 229 | static void ohci_hcd_omap3_shutdown(struct platform_device *pdev) |
717 | { | 230 | { |
718 | struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev); | 231 | struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev); |
719 | struct usb_hcd *hcd = ohci_to_hcd(omap->ohci); | ||
720 | 232 | ||
721 | if (hcd->driver->shutdown) | 233 | if (hcd->driver->shutdown) |
722 | hcd->driver->shutdown(hcd); | 234 | hcd->driver->shutdown(hcd); |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index 36ee9a666e93..d84d6f0314f9 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -22,24 +22,6 @@ | |||
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | 23 | ||
24 | 24 | ||
25 | /* constants used to work around PM-related transfer | ||
26 | * glitches in some AMD 700 series southbridges | ||
27 | */ | ||
28 | #define AB_REG_BAR 0xf0 | ||
29 | #define AB_INDX(addr) ((addr) + 0x00) | ||
30 | #define AB_DATA(addr) ((addr) + 0x04) | ||
31 | #define AX_INDXC 0X30 | ||
32 | #define AX_DATAC 0x34 | ||
33 | |||
34 | #define NB_PCIE_INDX_ADDR 0xe0 | ||
35 | #define NB_PCIE_INDX_DATA 0xe4 | ||
36 | #define PCIE_P_CNTL 0x10040 | ||
37 | #define BIF_NB 0x10002 | ||
38 | |||
39 | static struct pci_dev *amd_smbus_dev; | ||
40 | static struct pci_dev *amd_hb_dev; | ||
41 | static int amd_ohci_iso_count; | ||
42 | |||
43 | /*-------------------------------------------------------------------------*/ | 25 | /*-------------------------------------------------------------------------*/ |
44 | 26 | ||
45 | static int broken_suspend(struct usb_hcd *hcd) | 27 | static int broken_suspend(struct usb_hcd *hcd) |
@@ -168,15 +150,18 @@ static int ohci_quirk_nec(struct usb_hcd *hcd) | |||
168 | static int ohci_quirk_amd700(struct usb_hcd *hcd) | 150 | static int ohci_quirk_amd700(struct usb_hcd *hcd) |
169 | { | 151 | { |
170 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 152 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
171 | u8 rev = 0; | 153 | struct pci_dev *amd_smbus_dev; |
154 | u8 rev; | ||
172 | 155 | ||
173 | if (!amd_smbus_dev) | 156 | if (usb_amd_find_chipset_info()) |
174 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, | 157 | ohci->flags |= OHCI_QUIRK_AMD_PLL; |
175 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); | 158 | |
159 | amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, | ||
160 | PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); | ||
176 | if (!amd_smbus_dev) | 161 | if (!amd_smbus_dev) |
177 | return 0; | 162 | return 0; |
178 | 163 | ||
179 | pci_read_config_byte(amd_smbus_dev, PCI_REVISION_ID, &rev); | 164 | rev = amd_smbus_dev->revision; |
180 | 165 | ||
181 | /* SB800 needs pre-fetch fix */ | 166 | /* SB800 needs pre-fetch fix */ |
182 | if ((rev >= 0x40) && (rev <= 0x4f)) { | 167 | if ((rev >= 0x40) && (rev <= 0x4f)) { |
@@ -184,19 +169,8 @@ static int ohci_quirk_amd700(struct usb_hcd *hcd) | |||
184 | ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); | 169 | ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); |
185 | } | 170 | } |
186 | 171 | ||
187 | if ((rev > 0x3b) || (rev < 0x30)) { | 172 | pci_dev_put(amd_smbus_dev); |
188 | pci_dev_put(amd_smbus_dev); | 173 | amd_smbus_dev = NULL; |
189 | amd_smbus_dev = NULL; | ||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | amd_ohci_iso_count++; | ||
194 | |||
195 | if (!amd_hb_dev) | ||
196 | amd_hb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9600, NULL); | ||
197 | |||
198 | ohci->flags |= OHCI_QUIRK_AMD_ISO; | ||
199 | ohci_dbg(ohci, "enabled AMD ISO transfers quirk\n"); | ||
200 | 174 | ||
201 | return 0; | 175 | return 0; |
202 | } | 176 | } |
@@ -215,74 +189,6 @@ static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd) | |||
215 | return 0; | 189 | return 0; |
216 | } | 190 | } |
217 | 191 | ||
218 | /* | ||
219 | * The hardware normally enables the A-link power management feature, which | ||
220 | * lets the system lower the power consumption in idle states. | ||
221 | * | ||
222 | * Assume the system is configured to have USB 1.1 ISO transfers going | ||
223 | * to or from a USB device. Without this quirk, that stream may stutter | ||
224 | * or have breaks occasionally. For transfers going to speakers, this | ||
225 | * makes a very audible mess... | ||
226 | * | ||
227 | * That audio playback corruption is due to the audio stream getting | ||
228 | * interrupted occasionally when the link goes in lower power state | ||
229 | * This USB quirk prevents the link going into that lower power state | ||
230 | * during audio playback or other ISO operations. | ||
231 | */ | ||
232 | static void quirk_amd_pll(int on) | ||
233 | { | ||
234 | u32 addr; | ||
235 | u32 val; | ||
236 | u32 bit = (on > 0) ? 1 : 0; | ||
237 | |||
238 | pci_read_config_dword(amd_smbus_dev, AB_REG_BAR, &addr); | ||
239 | |||
240 | /* BIT names/meanings are NDA-protected, sorry ... */ | ||
241 | |||
242 | outl(AX_INDXC, AB_INDX(addr)); | ||
243 | outl(0x40, AB_DATA(addr)); | ||
244 | outl(AX_DATAC, AB_INDX(addr)); | ||
245 | val = inl(AB_DATA(addr)); | ||
246 | val &= ~((1 << 3) | (1 << 4) | (1 << 9)); | ||
247 | val |= (bit << 3) | ((!bit) << 4) | ((!bit) << 9); | ||
248 | outl(val, AB_DATA(addr)); | ||
249 | |||
250 | if (amd_hb_dev) { | ||
251 | addr = PCIE_P_CNTL; | ||
252 | pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr); | ||
253 | |||
254 | pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val); | ||
255 | val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12)); | ||
256 | val |= bit | (bit << 3) | (bit << 12); | ||
257 | val |= ((!bit) << 4) | ((!bit) << 9); | ||
258 | pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val); | ||
259 | |||
260 | addr = BIF_NB; | ||
261 | pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_ADDR, addr); | ||
262 | |||
263 | pci_read_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, &val); | ||
264 | val &= ~(1 << 8); | ||
265 | val |= bit << 8; | ||
266 | pci_write_config_dword(amd_hb_dev, NB_PCIE_INDX_DATA, val); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | static void amd_iso_dev_put(void) | ||
271 | { | ||
272 | amd_ohci_iso_count--; | ||
273 | if (amd_ohci_iso_count == 0) { | ||
274 | if (amd_smbus_dev) { | ||
275 | pci_dev_put(amd_smbus_dev); | ||
276 | amd_smbus_dev = NULL; | ||
277 | } | ||
278 | if (amd_hb_dev) { | ||
279 | pci_dev_put(amd_hb_dev); | ||
280 | amd_hb_dev = NULL; | ||
281 | } | ||
282 | } | ||
283 | |||
284 | } | ||
285 | |||
286 | static void sb800_prefetch(struct ohci_hcd *ohci, int on) | 192 | static void sb800_prefetch(struct ohci_hcd *ohci, int on) |
287 | { | 193 | { |
288 | struct pci_dev *pdev; | 194 | struct pci_dev *pdev; |
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c index 83094d067e0f..dd24fc115e48 100644 --- a/drivers/usb/host/ohci-q.c +++ b/drivers/usb/host/ohci-q.c | |||
@@ -52,7 +52,7 @@ __acquires(ohci->lock) | |||
52 | ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--; | 52 | ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--; |
53 | if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { | 53 | if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { |
54 | if (quirk_amdiso(ohci)) | 54 | if (quirk_amdiso(ohci)) |
55 | quirk_amd_pll(1); | 55 | usb_amd_quirk_pll_enable(); |
56 | if (quirk_amdprefetch(ohci)) | 56 | if (quirk_amdprefetch(ohci)) |
57 | sb800_prefetch(ohci, 0); | 57 | sb800_prefetch(ohci, 0); |
58 | } | 58 | } |
@@ -686,7 +686,7 @@ static void td_submit_urb ( | |||
686 | } | 686 | } |
687 | if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { | 687 | if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { |
688 | if (quirk_amdiso(ohci)) | 688 | if (quirk_amdiso(ohci)) |
689 | quirk_amd_pll(0); | 689 | usb_amd_quirk_pll_disable(); |
690 | if (quirk_amdprefetch(ohci)) | 690 | if (quirk_amdprefetch(ohci)) |
691 | sb800_prefetch(ohci, 1); | 691 | sb800_prefetch(ohci, 1); |
692 | } | 692 | } |
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index 51facb985c84..bad11a72c202 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h | |||
@@ -401,7 +401,7 @@ struct ohci_hcd { | |||
401 | #define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ | 401 | #define OHCI_QUIRK_NEC 0x40 /* lost interrupts */ |
402 | #define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */ | 402 | #define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */ |
403 | #define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ | 403 | #define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ |
404 | #define OHCI_QUIRK_AMD_ISO 0x200 /* ISO transfers*/ | 404 | #define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/ |
405 | #define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ | 405 | #define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ |
406 | #define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */ | 406 | #define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */ |
407 | // there are also chip quirks/bugs in init logic | 407 | // there are also chip quirks/bugs in init logic |
@@ -433,7 +433,7 @@ static inline int quirk_zfmicro(struct ohci_hcd *ohci) | |||
433 | } | 433 | } |
434 | static inline int quirk_amdiso(struct ohci_hcd *ohci) | 434 | static inline int quirk_amdiso(struct ohci_hcd *ohci) |
435 | { | 435 | { |
436 | return ohci->flags & OHCI_QUIRK_AMD_ISO; | 436 | return ohci->flags & OHCI_QUIRK_AMD_PLL; |
437 | } | 437 | } |
438 | static inline int quirk_amdprefetch(struct ohci_hcd *ohci) | 438 | static inline int quirk_amdprefetch(struct ohci_hcd *ohci) |
439 | { | 439 | { |
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c index e0cb12b573f9..38193f4e980e 100644 --- a/drivers/usb/host/oxu210hp-hcd.c +++ b/drivers/usb/host/oxu210hp-hcd.c | |||
@@ -451,9 +451,9 @@ static void ehci_hub_descriptor(struct oxu_hcd *oxu, | |||
451 | temp = 1 + (ports / 8); | 451 | temp = 1 + (ports / 8); |
452 | desc->bDescLength = 7 + 2 * temp; | 452 | desc->bDescLength = 7 + 2 * temp; |
453 | 453 | ||
454 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 454 | /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
455 | memset(&desc->bitmap[0], 0, temp); | 455 | memset(&desc->u.hs.DeviceRemovable[0], 0, temp); |
456 | memset(&desc->bitmap[temp], 0xff, temp); | 456 | memset(&desc->u.hs.DeviceRemovable[temp], 0xff, temp); |
457 | 457 | ||
458 | temp = 0x0008; /* per-port overcurrent reporting */ | 458 | temp = 0x0008; /* per-port overcurrent reporting */ |
459 | if (HCS_PPC(oxu->hcs_params)) | 459 | if (HCS_PPC(oxu->hcs_params)) |
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index 4c502c890ebd..1d586d4f7b56 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
@@ -52,6 +52,264 @@ | |||
52 | #define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ | 52 | #define EHCI_USBLEGCTLSTS 4 /* legacy control/status */ |
53 | #define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */ | 53 | #define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */ |
54 | 54 | ||
55 | /* AMD quirk use */ | ||
56 | #define AB_REG_BAR_LOW 0xe0 | ||
57 | #define AB_REG_BAR_HIGH 0xe1 | ||
58 | #define AB_REG_BAR_SB700 0xf0 | ||
59 | #define AB_INDX(addr) ((addr) + 0x00) | ||
60 | #define AB_DATA(addr) ((addr) + 0x04) | ||
61 | #define AX_INDXC 0x30 | ||
62 | #define AX_DATAC 0x34 | ||
63 | |||
64 | #define NB_PCIE_INDX_ADDR 0xe0 | ||
65 | #define NB_PCIE_INDX_DATA 0xe4 | ||
66 | #define PCIE_P_CNTL 0x10040 | ||
67 | #define BIF_NB 0x10002 | ||
68 | #define NB_PIF0_PWRDOWN_0 0x01100012 | ||
69 | #define NB_PIF0_PWRDOWN_1 0x01100013 | ||
70 | |||
71 | static struct amd_chipset_info { | ||
72 | struct pci_dev *nb_dev; | ||
73 | struct pci_dev *smbus_dev; | ||
74 | int nb_type; | ||
75 | int sb_type; | ||
76 | int isoc_reqs; | ||
77 | int probe_count; | ||
78 | int probe_result; | ||
79 | } amd_chipset; | ||
80 | |||
81 | static DEFINE_SPINLOCK(amd_lock); | ||
82 | |||
83 | int usb_amd_find_chipset_info(void) | ||
84 | { | ||
85 | u8 rev = 0; | ||
86 | unsigned long flags; | ||
87 | |||
88 | spin_lock_irqsave(&amd_lock, flags); | ||
89 | |||
90 | amd_chipset.probe_count++; | ||
91 | /* probe only once */ | ||
92 | if (amd_chipset.probe_count > 1) { | ||
93 | spin_unlock_irqrestore(&amd_lock, flags); | ||
94 | return amd_chipset.probe_result; | ||
95 | } | ||
96 | |||
97 | amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); | ||
98 | if (amd_chipset.smbus_dev) { | ||
99 | rev = amd_chipset.smbus_dev->revision; | ||
100 | if (rev >= 0x40) | ||
101 | amd_chipset.sb_type = 1; | ||
102 | else if (rev >= 0x30 && rev <= 0x3b) | ||
103 | amd_chipset.sb_type = 3; | ||
104 | } else { | ||
105 | amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
106 | 0x780b, NULL); | ||
107 | if (!amd_chipset.smbus_dev) { | ||
108 | spin_unlock_irqrestore(&amd_lock, flags); | ||
109 | return 0; | ||
110 | } | ||
111 | rev = amd_chipset.smbus_dev->revision; | ||
112 | if (rev >= 0x11 && rev <= 0x18) | ||
113 | amd_chipset.sb_type = 2; | ||
114 | } | ||
115 | |||
116 | if (amd_chipset.sb_type == 0) { | ||
117 | if (amd_chipset.smbus_dev) { | ||
118 | pci_dev_put(amd_chipset.smbus_dev); | ||
119 | amd_chipset.smbus_dev = NULL; | ||
120 | } | ||
121 | spin_unlock_irqrestore(&amd_lock, flags); | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL); | ||
126 | if (amd_chipset.nb_dev) { | ||
127 | amd_chipset.nb_type = 1; | ||
128 | } else { | ||
129 | amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
130 | 0x1510, NULL); | ||
131 | if (amd_chipset.nb_dev) { | ||
132 | amd_chipset.nb_type = 2; | ||
133 | } else { | ||
134 | amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, | ||
135 | 0x9600, NULL); | ||
136 | if (amd_chipset.nb_dev) | ||
137 | amd_chipset.nb_type = 3; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | amd_chipset.probe_result = 1; | ||
142 | printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n"); | ||
143 | |||
144 | spin_unlock_irqrestore(&amd_lock, flags); | ||
145 | return amd_chipset.probe_result; | ||
146 | } | ||
147 | EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); | ||
148 | |||
149 | /* | ||
150 | * The hardware normally enables the A-link power management feature, which | ||
151 | * lets the system lower the power consumption in idle states. | ||
152 | * | ||
153 | * This USB quirk prevents the link going into that lower power state | ||
154 | * during isochronous transfers. | ||
155 | * | ||
156 | * Without this quirk, isochronous stream on OHCI/EHCI/xHCI controllers of | ||
157 | * some AMD platforms may stutter or have breaks occasionally. | ||
158 | */ | ||
159 | static void usb_amd_quirk_pll(int disable) | ||
160 | { | ||
161 | u32 addr, addr_low, addr_high, val; | ||
162 | u32 bit = disable ? 0 : 1; | ||
163 | unsigned long flags; | ||
164 | |||
165 | spin_lock_irqsave(&amd_lock, flags); | ||
166 | |||
167 | if (disable) { | ||
168 | amd_chipset.isoc_reqs++; | ||
169 | if (amd_chipset.isoc_reqs > 1) { | ||
170 | spin_unlock_irqrestore(&amd_lock, flags); | ||
171 | return; | ||
172 | } | ||
173 | } else { | ||
174 | amd_chipset.isoc_reqs--; | ||
175 | if (amd_chipset.isoc_reqs > 0) { | ||
176 | spin_unlock_irqrestore(&amd_lock, flags); | ||
177 | return; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) { | ||
182 | outb_p(AB_REG_BAR_LOW, 0xcd6); | ||
183 | addr_low = inb_p(0xcd7); | ||
184 | outb_p(AB_REG_BAR_HIGH, 0xcd6); | ||
185 | addr_high = inb_p(0xcd7); | ||
186 | addr = addr_high << 8 | addr_low; | ||
187 | |||
188 | outl_p(0x30, AB_INDX(addr)); | ||
189 | outl_p(0x40, AB_DATA(addr)); | ||
190 | outl_p(0x34, AB_INDX(addr)); | ||
191 | val = inl_p(AB_DATA(addr)); | ||
192 | } else if (amd_chipset.sb_type == 3) { | ||
193 | pci_read_config_dword(amd_chipset.smbus_dev, | ||
194 | AB_REG_BAR_SB700, &addr); | ||
195 | outl(AX_INDXC, AB_INDX(addr)); | ||
196 | outl(0x40, AB_DATA(addr)); | ||
197 | outl(AX_DATAC, AB_INDX(addr)); | ||
198 | val = inl(AB_DATA(addr)); | ||
199 | } else { | ||
200 | spin_unlock_irqrestore(&amd_lock, flags); | ||
201 | return; | ||
202 | } | ||
203 | |||
204 | if (disable) { | ||
205 | val &= ~0x08; | ||
206 | val |= (1 << 4) | (1 << 9); | ||
207 | } else { | ||
208 | val |= 0x08; | ||
209 | val &= ~((1 << 4) | (1 << 9)); | ||
210 | } | ||
211 | outl_p(val, AB_DATA(addr)); | ||
212 | |||
213 | if (!amd_chipset.nb_dev) { | ||
214 | spin_unlock_irqrestore(&amd_lock, flags); | ||
215 | return; | ||
216 | } | ||
217 | |||
218 | if (amd_chipset.nb_type == 1 || amd_chipset.nb_type == 3) { | ||
219 | addr = PCIE_P_CNTL; | ||
220 | pci_write_config_dword(amd_chipset.nb_dev, | ||
221 | NB_PCIE_INDX_ADDR, addr); | ||
222 | pci_read_config_dword(amd_chipset.nb_dev, | ||
223 | NB_PCIE_INDX_DATA, &val); | ||
224 | |||
225 | val &= ~(1 | (1 << 3) | (1 << 4) | (1 << 9) | (1 << 12)); | ||
226 | val |= bit | (bit << 3) | (bit << 12); | ||
227 | val |= ((!bit) << 4) | ((!bit) << 9); | ||
228 | pci_write_config_dword(amd_chipset.nb_dev, | ||
229 | NB_PCIE_INDX_DATA, val); | ||
230 | |||
231 | addr = BIF_NB; | ||
232 | pci_write_config_dword(amd_chipset.nb_dev, | ||
233 | NB_PCIE_INDX_ADDR, addr); | ||
234 | pci_read_config_dword(amd_chipset.nb_dev, | ||
235 | NB_PCIE_INDX_DATA, &val); | ||
236 | val &= ~(1 << 8); | ||
237 | val |= bit << 8; | ||
238 | |||
239 | pci_write_config_dword(amd_chipset.nb_dev, | ||
240 | NB_PCIE_INDX_DATA, val); | ||
241 | } else if (amd_chipset.nb_type == 2) { | ||
242 | addr = NB_PIF0_PWRDOWN_0; | ||
243 | pci_write_config_dword(amd_chipset.nb_dev, | ||
244 | NB_PCIE_INDX_ADDR, addr); | ||
245 | pci_read_config_dword(amd_chipset.nb_dev, | ||
246 | NB_PCIE_INDX_DATA, &val); | ||
247 | if (disable) | ||
248 | val &= ~(0x3f << 7); | ||
249 | else | ||
250 | val |= 0x3f << 7; | ||
251 | |||
252 | pci_write_config_dword(amd_chipset.nb_dev, | ||
253 | NB_PCIE_INDX_DATA, val); | ||
254 | |||
255 | addr = NB_PIF0_PWRDOWN_1; | ||
256 | pci_write_config_dword(amd_chipset.nb_dev, | ||
257 | NB_PCIE_INDX_ADDR, addr); | ||
258 | pci_read_config_dword(amd_chipset.nb_dev, | ||
259 | NB_PCIE_INDX_DATA, &val); | ||
260 | if (disable) | ||
261 | val &= ~(0x3f << 7); | ||
262 | else | ||
263 | val |= 0x3f << 7; | ||
264 | |||
265 | pci_write_config_dword(amd_chipset.nb_dev, | ||
266 | NB_PCIE_INDX_DATA, val); | ||
267 | } | ||
268 | |||
269 | spin_unlock_irqrestore(&amd_lock, flags); | ||
270 | return; | ||
271 | } | ||
272 | |||
273 | void usb_amd_quirk_pll_disable(void) | ||
274 | { | ||
275 | usb_amd_quirk_pll(1); | ||
276 | } | ||
277 | EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_disable); | ||
278 | |||
279 | void usb_amd_quirk_pll_enable(void) | ||
280 | { | ||
281 | usb_amd_quirk_pll(0); | ||
282 | } | ||
283 | EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable); | ||
284 | |||
285 | void usb_amd_dev_put(void) | ||
286 | { | ||
287 | unsigned long flags; | ||
288 | |||
289 | spin_lock_irqsave(&amd_lock, flags); | ||
290 | |||
291 | amd_chipset.probe_count--; | ||
292 | if (amd_chipset.probe_count > 0) { | ||
293 | spin_unlock_irqrestore(&amd_lock, flags); | ||
294 | return; | ||
295 | } | ||
296 | |||
297 | if (amd_chipset.nb_dev) { | ||
298 | pci_dev_put(amd_chipset.nb_dev); | ||
299 | amd_chipset.nb_dev = NULL; | ||
300 | } | ||
301 | if (amd_chipset.smbus_dev) { | ||
302 | pci_dev_put(amd_chipset.smbus_dev); | ||
303 | amd_chipset.smbus_dev = NULL; | ||
304 | } | ||
305 | amd_chipset.nb_type = 0; | ||
306 | amd_chipset.sb_type = 0; | ||
307 | amd_chipset.isoc_reqs = 0; | ||
308 | amd_chipset.probe_result = 0; | ||
309 | |||
310 | spin_unlock_irqrestore(&amd_lock, flags); | ||
311 | } | ||
312 | EXPORT_SYMBOL_GPL(usb_amd_dev_put); | ||
55 | 313 | ||
56 | /* | 314 | /* |
57 | * Make sure the controller is completely inactive, unable to | 315 | * Make sure the controller is completely inactive, unable to |
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h index 1564edfff6fe..6ae9f78e9938 100644 --- a/drivers/usb/host/pci-quirks.h +++ b/drivers/usb/host/pci-quirks.h | |||
@@ -1,7 +1,17 @@ | |||
1 | #ifndef __LINUX_USB_PCI_QUIRKS_H | 1 | #ifndef __LINUX_USB_PCI_QUIRKS_H |
2 | #define __LINUX_USB_PCI_QUIRKS_H | 2 | #define __LINUX_USB_PCI_QUIRKS_H |
3 | 3 | ||
4 | #ifdef CONFIG_PCI | ||
4 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); | 5 | void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); |
5 | 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); | ||
8 | void usb_amd_dev_put(void); | ||
9 | void usb_amd_quirk_pll_disable(void); | ||
10 | void usb_amd_quirk_pll_enable(void); | ||
11 | #else | ||
12 | static inline void usb_amd_quirk_pll_disable(void) {} | ||
13 | static inline void usb_amd_quirk_pll_enable(void) {} | ||
14 | static inline void usb_amd_dev_put(void) {} | ||
15 | #endif /* CONFIG_PCI */ | ||
6 | 16 | ||
7 | #endif /* __LINUX_USB_PCI_QUIRKS_H */ | 17 | #endif /* __LINUX_USB_PCI_QUIRKS_H */ |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index 3076b1cc05df..db6f8b9c19b6 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -2150,8 +2150,9 @@ static void r8a66597_hub_descriptor(struct r8a66597 *r8a66597, | |||
2150 | desc->bDescLength = 9; | 2150 | desc->bDescLength = 9; |
2151 | desc->bPwrOn2PwrGood = 0; | 2151 | desc->bPwrOn2PwrGood = 0; |
2152 | desc->wHubCharacteristics = cpu_to_le16(0x0011); | 2152 | desc->wHubCharacteristics = cpu_to_le16(0x0011); |
2153 | desc->bitmap[0] = ((1 << r8a66597->max_root_hub) - 1) << 1; | 2153 | desc->u.hs.DeviceRemovable[0] = |
2154 | desc->bitmap[1] = ~0; | 2154 | ((1 << r8a66597->max_root_hub) - 1) << 1; |
2155 | desc->u.hs.DeviceRemovable[1] = ~0; | ||
2155 | } | 2156 | } |
2156 | 2157 | ||
2157 | static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | 2158 | static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 2e9602a10e9b..18b7099a8125 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -1111,9 +1111,9 @@ sl811h_hub_descriptor ( | |||
1111 | 1111 | ||
1112 | desc->wHubCharacteristics = cpu_to_le16(temp); | 1112 | desc->wHubCharacteristics = cpu_to_le16(temp); |
1113 | 1113 | ||
1114 | /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */ | 1114 | /* ports removable, and legacy PortPwrCtrlMask */ |
1115 | desc->bitmap[0] = 0 << 1; | 1115 | desc->u.hs.DeviceRemovable[0] = 0 << 1; |
1116 | desc->bitmap[1] = ~0; | 1116 | desc->u.hs.DeviceRemovable[1] = ~0; |
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | static void | 1119 | static void |
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c index fab764946c74..b4785934e091 100644 --- a/drivers/usb/host/u132-hcd.c +++ b/drivers/usb/host/u132-hcd.c | |||
@@ -2604,13 +2604,14 @@ static int u132_roothub_descriptor(struct u132 *u132, | |||
2604 | retval = u132_read_pcimem(u132, roothub.b, &rh_b); | 2604 | retval = u132_read_pcimem(u132, roothub.b, &rh_b); |
2605 | if (retval) | 2605 | if (retval) |
2606 | return retval; | 2606 | return retval; |
2607 | memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); | 2607 | memset(desc->u.hs.DeviceRemovable, 0xff, |
2608 | desc->bitmap[0] = rh_b & RH_B_DR; | 2608 | sizeof(desc->u.hs.DeviceRemovable)); |
2609 | desc->u.hs.DeviceRemovable[0] = rh_b & RH_B_DR; | ||
2609 | if (u132->num_ports > 7) { | 2610 | if (u132->num_ports > 7) { |
2610 | desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; | 2611 | desc->u.hs.DeviceRemovable[1] = (rh_b & RH_B_DR) >> 8; |
2611 | desc->bitmap[2] = 0xff; | 2612 | desc->u.hs.DeviceRemovable[2] = 0xff; |
2612 | } else | 2613 | } else |
2613 | desc->bitmap[1] = 0xff; | 2614 | desc->u.hs.DeviceRemovable[1] = 0xff; |
2614 | return 0; | 2615 | return 0; |
2615 | } | 2616 | } |
2616 | 2617 | ||
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index cee867829ec9..4f65b14e5e08 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -471,7 +471,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd) | |||
471 | 471 | ||
472 | /* | 472 | /* |
473 | * Store the current frame number in uhci->frame_number if the controller | 473 | * Store the current frame number in uhci->frame_number if the controller |
474 | * is runnning. Expand from 11 bits (of which we use only 10) to a | 474 | * is running. Expand from 11 bits (of which we use only 10) to a |
475 | * full-sized integer. | 475 | * full-sized integer. |
476 | * | 476 | * |
477 | * Like many other parts of the driver, this code relies on being polled | 477 | * Like many other parts of the driver, this code relies on being polled |
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h index 78c4edac1db1..ce5c9e51748e 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h | |||
@@ -19,8 +19,8 @@ | |||
19 | * along with this program; if not, write to the Free Software Foundation, | 19 | * along with this program; if not, write to the Free Software Foundation, |
20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | */ | 21 | */ |
22 | /* Up to 16 microframes to halt an HC - one microframe is 125 microsectonds */ | 22 | /* Up to 16 ms to halt an HC */ |
23 | #define XHCI_MAX_HALT_USEC (16*125) | 23 | #define XHCI_MAX_HALT_USEC (16*1000) |
24 | /* HC not running - set to 1 when run/stop bit is cleared. */ | 24 | /* HC not running - set to 1 when run/stop bit is cleared. */ |
25 | #define XHCI_STS_HALT (1<<0) | 25 | #define XHCI_STS_HALT (1<<0) |
26 | 26 | ||
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 5d963e350494..a78f2ebd11b7 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
@@ -28,27 +28,15 @@ | |||
28 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ | 28 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ |
29 | PORT_RC | PORT_PLC | PORT_PE) | 29 | PORT_RC | PORT_PLC | PORT_PE) |
30 | 30 | ||
31 | static void xhci_hub_descriptor(struct xhci_hcd *xhci, | 31 | static void xhci_common_hub_descriptor(struct xhci_hcd *xhci, |
32 | struct usb_hub_descriptor *desc) | 32 | struct usb_hub_descriptor *desc, int ports) |
33 | { | 33 | { |
34 | int ports; | ||
35 | u16 temp; | 34 | u16 temp; |
36 | 35 | ||
37 | ports = HCS_MAX_PORTS(xhci->hcs_params1); | ||
38 | |||
39 | /* USB 3.0 hubs have a different descriptor, but we fake this for now */ | ||
40 | desc->bDescriptorType = 0x29; | ||
41 | desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */ | 36 | desc->bPwrOn2PwrGood = 10; /* xhci section 5.4.9 says 20ms max */ |
42 | desc->bHubContrCurrent = 0; | 37 | desc->bHubContrCurrent = 0; |
43 | 38 | ||
44 | desc->bNbrPorts = ports; | 39 | desc->bNbrPorts = ports; |
45 | temp = 1 + (ports / 8); | ||
46 | desc->bDescLength = 7 + 2 * temp; | ||
47 | |||
48 | /* Why does core/hcd.h define bitmap? It's just confusing. */ | ||
49 | memset(&desc->DeviceRemovable[0], 0, temp); | ||
50 | memset(&desc->DeviceRemovable[temp], 0xff, temp); | ||
51 | |||
52 | /* Ugh, these should be #defines, FIXME */ | 40 | /* Ugh, these should be #defines, FIXME */ |
53 | /* Using table 11-13 in USB 2.0 spec. */ | 41 | /* Using table 11-13 in USB 2.0 spec. */ |
54 | temp = 0; | 42 | temp = 0; |
@@ -65,14 +53,108 @@ static void xhci_hub_descriptor(struct xhci_hcd *xhci, | |||
65 | desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp); | 53 | desc->wHubCharacteristics = (__force __u16) cpu_to_le16(temp); |
66 | } | 54 | } |
67 | 55 | ||
56 | /* Fill in the USB 2.0 roothub descriptor */ | ||
57 | static void xhci_usb2_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, | ||
58 | struct usb_hub_descriptor *desc) | ||
59 | { | ||
60 | int ports; | ||
61 | u16 temp; | ||
62 | __u8 port_removable[(USB_MAXCHILDREN + 1 + 7) / 8]; | ||
63 | u32 portsc; | ||
64 | unsigned int i; | ||
65 | |||
66 | ports = xhci->num_usb2_ports; | ||
67 | |||
68 | xhci_common_hub_descriptor(xhci, desc, ports); | ||
69 | desc->bDescriptorType = 0x29; | ||
70 | temp = 1 + (ports / 8); | ||
71 | desc->bDescLength = 7 + 2 * temp; | ||
72 | |||
73 | /* The Device Removable bits are reported on a byte granularity. | ||
74 | * If the port doesn't exist within that byte, the bit is set to 0. | ||
75 | */ | ||
76 | memset(port_removable, 0, sizeof(port_removable)); | ||
77 | for (i = 0; i < ports; i++) { | ||
78 | portsc = xhci_readl(xhci, xhci->usb3_ports[i]); | ||
79 | /* If a device is removable, PORTSC reports a 0, same as in the | ||
80 | * hub descriptor DeviceRemovable bits. | ||
81 | */ | ||
82 | if (portsc & PORT_DEV_REMOVE) | ||
83 | /* This math is hairy because bit 0 of DeviceRemovable | ||
84 | * is reserved, and bit 1 is for port 1, etc. | ||
85 | */ | ||
86 | port_removable[(i + 1) / 8] |= 1 << ((i + 1) % 8); | ||
87 | } | ||
88 | |||
89 | /* ch11.h defines a hub descriptor that has room for USB_MAXCHILDREN | ||
90 | * ports on it. The USB 2.0 specification says that there are two | ||
91 | * variable length fields at the end of the hub descriptor: | ||
92 | * DeviceRemovable and PortPwrCtrlMask. But since we can have less than | ||
93 | * USB_MAXCHILDREN ports, we may need to use the DeviceRemovable array | ||
94 | * to set PortPwrCtrlMask bits. PortPwrCtrlMask must always be set to | ||
95 | * 0xFF, so we initialize the both arrays (DeviceRemovable and | ||
96 | * PortPwrCtrlMask) to 0xFF. Then we set the DeviceRemovable for each | ||
97 | * set of ports that actually exist. | ||
98 | */ | ||
99 | memset(desc->u.hs.DeviceRemovable, 0xff, | ||
100 | sizeof(desc->u.hs.DeviceRemovable)); | ||
101 | memset(desc->u.hs.PortPwrCtrlMask, 0xff, | ||
102 | sizeof(desc->u.hs.PortPwrCtrlMask)); | ||
103 | |||
104 | for (i = 0; i < (ports + 1 + 7) / 8; i++) | ||
105 | memset(&desc->u.hs.DeviceRemovable[i], port_removable[i], | ||
106 | sizeof(__u8)); | ||
107 | } | ||
108 | |||
109 | /* Fill in the USB 3.0 roothub descriptor */ | ||
110 | static void xhci_usb3_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, | ||
111 | struct usb_hub_descriptor *desc) | ||
112 | { | ||
113 | int ports; | ||
114 | u16 port_removable; | ||
115 | u32 portsc; | ||
116 | unsigned int i; | ||
117 | |||
118 | ports = xhci->num_usb3_ports; | ||
119 | xhci_common_hub_descriptor(xhci, desc, ports); | ||
120 | desc->bDescriptorType = 0x2a; | ||
121 | desc->bDescLength = 12; | ||
122 | |||
123 | /* header decode latency should be zero for roothubs, | ||
124 | * see section 4.23.5.2. | ||
125 | */ | ||
126 | desc->u.ss.bHubHdrDecLat = 0; | ||
127 | desc->u.ss.wHubDelay = 0; | ||
128 | |||
129 | port_removable = 0; | ||
130 | /* bit 0 is reserved, bit 1 is for port 1, etc. */ | ||
131 | for (i = 0; i < ports; i++) { | ||
132 | portsc = xhci_readl(xhci, xhci->usb3_ports[i]); | ||
133 | if (portsc & PORT_DEV_REMOVE) | ||
134 | port_removable |= 1 << (i + 1); | ||
135 | } | ||
136 | memset(&desc->u.ss.DeviceRemovable, | ||
137 | (__force __u16) cpu_to_le16(port_removable), | ||
138 | sizeof(__u16)); | ||
139 | } | ||
140 | |||
141 | static void xhci_hub_descriptor(struct usb_hcd *hcd, struct xhci_hcd *xhci, | ||
142 | struct usb_hub_descriptor *desc) | ||
143 | { | ||
144 | |||
145 | if (hcd->speed == HCD_USB3) | ||
146 | xhci_usb3_hub_descriptor(hcd, xhci, desc); | ||
147 | else | ||
148 | xhci_usb2_hub_descriptor(hcd, xhci, desc); | ||
149 | |||
150 | } | ||
151 | |||
68 | static unsigned int xhci_port_speed(unsigned int port_status) | 152 | static unsigned int xhci_port_speed(unsigned int port_status) |
69 | { | 153 | { |
70 | if (DEV_LOWSPEED(port_status)) | 154 | if (DEV_LOWSPEED(port_status)) |
71 | return USB_PORT_STAT_LOW_SPEED; | 155 | return USB_PORT_STAT_LOW_SPEED; |
72 | if (DEV_HIGHSPEED(port_status)) | 156 | if (DEV_HIGHSPEED(port_status)) |
73 | return USB_PORT_STAT_HIGH_SPEED; | 157 | return USB_PORT_STAT_HIGH_SPEED; |
74 | if (DEV_SUPERSPEED(port_status)) | ||
75 | return USB_PORT_STAT_SUPER_SPEED; | ||
76 | /* | 158 | /* |
77 | * FIXME: Yes, we should check for full speed, but the core uses that as | 159 | * FIXME: Yes, we should check for full speed, but the core uses that as |
78 | * a default in portspeed() in usb/core/hub.c (which is the only place | 160 | * a default in portspeed() in usb/core/hub.c (which is the only place |
@@ -135,17 +217,22 @@ u32 xhci_port_state_to_neutral(u32 state) | |||
135 | 217 | ||
136 | /* | 218 | /* |
137 | * find slot id based on port number. | 219 | * find slot id based on port number. |
220 | * @port: The one-based port number from one of the two split roothubs. | ||
138 | */ | 221 | */ |
139 | int xhci_find_slot_id_by_port(struct xhci_hcd *xhci, u16 port) | 222 | int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
223 | u16 port) | ||
140 | { | 224 | { |
141 | int slot_id; | 225 | int slot_id; |
142 | int i; | 226 | int i; |
227 | enum usb_device_speed speed; | ||
143 | 228 | ||
144 | slot_id = 0; | 229 | slot_id = 0; |
145 | for (i = 0; i < MAX_HC_SLOTS; i++) { | 230 | for (i = 0; i < MAX_HC_SLOTS; i++) { |
146 | if (!xhci->devs[i]) | 231 | if (!xhci->devs[i]) |
147 | continue; | 232 | continue; |
148 | if (xhci->devs[i]->port == port) { | 233 | speed = xhci->devs[i]->udev->speed; |
234 | if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3)) | ||
235 | && xhci->devs[i]->port == port) { | ||
149 | slot_id = i; | 236 | slot_id = i; |
150 | break; | 237 | break; |
151 | } | 238 | } |
@@ -226,11 +313,11 @@ void xhci_ring_device(struct xhci_hcd *xhci, int slot_id) | |||
226 | return; | 313 | return; |
227 | } | 314 | } |
228 | 315 | ||
229 | static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex, | 316 | static void xhci_disable_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
230 | u32 __iomem *addr, u32 port_status) | 317 | u16 wIndex, u32 __iomem *addr, u32 port_status) |
231 | { | 318 | { |
232 | /* Don't allow the USB core to disable SuperSpeed ports. */ | 319 | /* Don't allow the USB core to disable SuperSpeed ports. */ |
233 | if (xhci->port_array[wIndex] == 0x03) { | 320 | if (hcd->speed == HCD_USB3) { |
234 | xhci_dbg(xhci, "Ignoring request to disable " | 321 | xhci_dbg(xhci, "Ignoring request to disable " |
235 | "SuperSpeed port.\n"); | 322 | "SuperSpeed port.\n"); |
236 | return; | 323 | return; |
@@ -289,10 +376,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
289 | unsigned long flags; | 376 | unsigned long flags; |
290 | u32 temp, temp1, status; | 377 | u32 temp, temp1, status; |
291 | int retval = 0; | 378 | int retval = 0; |
292 | u32 __iomem *addr; | 379 | u32 __iomem **port_array; |
293 | int slot_id; | 380 | int slot_id; |
294 | 381 | struct xhci_bus_state *bus_state; | |
295 | ports = HCS_MAX_PORTS(xhci->hcs_params1); | 382 | |
383 | if (hcd->speed == HCD_USB3) { | ||
384 | ports = xhci->num_usb3_ports; | ||
385 | port_array = xhci->usb3_ports; | ||
386 | } else { | ||
387 | ports = xhci->num_usb2_ports; | ||
388 | port_array = xhci->usb2_ports; | ||
389 | } | ||
390 | bus_state = &xhci->bus_state[hcd_index(hcd)]; | ||
296 | 391 | ||
297 | spin_lock_irqsave(&xhci->lock, flags); | 392 | spin_lock_irqsave(&xhci->lock, flags); |
298 | switch (typeReq) { | 393 | switch (typeReq) { |
@@ -301,17 +396,35 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
301 | memset(buf, 0, 4); | 396 | memset(buf, 0, 4); |
302 | break; | 397 | break; |
303 | case GetHubDescriptor: | 398 | case GetHubDescriptor: |
304 | xhci_hub_descriptor(xhci, (struct usb_hub_descriptor *) buf); | 399 | /* Check to make sure userspace is asking for the USB 3.0 hub |
400 | * descriptor for the USB 3.0 roothub. If not, we stall the | ||
401 | * endpoint, like external hubs do. | ||
402 | */ | ||
403 | if (hcd->speed == HCD_USB3 && | ||
404 | (wLength < USB_DT_SS_HUB_SIZE || | ||
405 | wValue != (USB_DT_SS_HUB << 8))) { | ||
406 | xhci_dbg(xhci, "Wrong hub descriptor type for " | ||
407 | "USB 3.0 roothub.\n"); | ||
408 | goto error; | ||
409 | } | ||
410 | xhci_hub_descriptor(hcd, xhci, | ||
411 | (struct usb_hub_descriptor *) buf); | ||
305 | break; | 412 | break; |
306 | case GetPortStatus: | 413 | case GetPortStatus: |
307 | if (!wIndex || wIndex > ports) | 414 | if (!wIndex || wIndex > ports) |
308 | goto error; | 415 | goto error; |
309 | wIndex--; | 416 | wIndex--; |
310 | status = 0; | 417 | status = 0; |
311 | addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); | 418 | temp = xhci_readl(xhci, port_array[wIndex]); |
312 | temp = xhci_readl(xhci, addr); | 419 | if (temp == 0xffffffff) { |
420 | retval = -ENODEV; | ||
421 | break; | ||
422 | } | ||
313 | xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); | 423 | xhci_dbg(xhci, "get port status, actual port %d status = 0x%x\n", wIndex, temp); |
314 | 424 | ||
425 | /* FIXME - should we return a port status value like the USB | ||
426 | * 3.0 external hubs do? | ||
427 | */ | ||
315 | /* wPortChange bits */ | 428 | /* wPortChange bits */ |
316 | if (temp & PORT_CSC) | 429 | if (temp & PORT_CSC) |
317 | status |= USB_PORT_STAT_C_CONNECTION << 16; | 430 | status |= USB_PORT_STAT_C_CONNECTION << 16; |
@@ -330,38 +443,33 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
330 | if ((temp & PORT_RESET) || !(temp & PORT_PE)) | 443 | if ((temp & PORT_RESET) || !(temp & PORT_PE)) |
331 | goto error; | 444 | goto error; |
332 | if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies, | 445 | if (!DEV_SUPERSPEED(temp) && time_after_eq(jiffies, |
333 | xhci->resume_done[wIndex])) { | 446 | bus_state->resume_done[wIndex])) { |
334 | xhci_dbg(xhci, "Resume USB2 port %d\n", | 447 | xhci_dbg(xhci, "Resume USB2 port %d\n", |
335 | wIndex + 1); | 448 | wIndex + 1); |
336 | xhci->resume_done[wIndex] = 0; | 449 | bus_state->resume_done[wIndex] = 0; |
337 | temp1 = xhci_port_state_to_neutral(temp); | 450 | temp1 = xhci_port_state_to_neutral(temp); |
338 | temp1 &= ~PORT_PLS_MASK; | 451 | temp1 &= ~PORT_PLS_MASK; |
339 | temp1 |= PORT_LINK_STROBE | XDEV_U0; | 452 | temp1 |= PORT_LINK_STROBE | XDEV_U0; |
340 | xhci_writel(xhci, temp1, addr); | 453 | xhci_writel(xhci, temp1, port_array[wIndex]); |
341 | 454 | ||
342 | xhci_dbg(xhci, "set port %d resume\n", | 455 | xhci_dbg(xhci, "set port %d resume\n", |
343 | wIndex + 1); | 456 | wIndex + 1); |
344 | slot_id = xhci_find_slot_id_by_port(xhci, | 457 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
345 | wIndex + 1); | 458 | wIndex + 1); |
346 | if (!slot_id) { | 459 | if (!slot_id) { |
347 | xhci_dbg(xhci, "slot_id is zero\n"); | 460 | xhci_dbg(xhci, "slot_id is zero\n"); |
348 | goto error; | 461 | goto error; |
349 | } | 462 | } |
350 | xhci_ring_device(xhci, slot_id); | 463 | xhci_ring_device(xhci, slot_id); |
351 | xhci->port_c_suspend[wIndex >> 5] |= | 464 | bus_state->port_c_suspend |= 1 << wIndex; |
352 | 1 << (wIndex & 31); | 465 | bus_state->suspended_ports &= ~(1 << wIndex); |
353 | xhci->suspended_ports[wIndex >> 5] &= | ||
354 | ~(1 << (wIndex & 31)); | ||
355 | } | 466 | } |
356 | } | 467 | } |
357 | if ((temp & PORT_PLS_MASK) == XDEV_U0 | 468 | if ((temp & PORT_PLS_MASK) == XDEV_U0 |
358 | && (temp & PORT_POWER) | 469 | && (temp & PORT_POWER) |
359 | && (xhci->suspended_ports[wIndex >> 5] & | 470 | && (bus_state->suspended_ports & (1 << wIndex))) { |
360 | (1 << (wIndex & 31)))) { | 471 | bus_state->suspended_ports &= ~(1 << wIndex); |
361 | xhci->suspended_ports[wIndex >> 5] &= | 472 | bus_state->port_c_suspend |= 1 << wIndex; |
362 | ~(1 << (wIndex & 31)); | ||
363 | xhci->port_c_suspend[wIndex >> 5] |= | ||
364 | 1 << (wIndex & 31); | ||
365 | } | 473 | } |
366 | if (temp & PORT_CONNECT) { | 474 | if (temp & PORT_CONNECT) { |
367 | status |= USB_PORT_STAT_CONNECTION; | 475 | status |= USB_PORT_STAT_CONNECTION; |
@@ -375,7 +483,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
375 | status |= USB_PORT_STAT_RESET; | 483 | status |= USB_PORT_STAT_RESET; |
376 | if (temp & PORT_POWER) | 484 | if (temp & PORT_POWER) |
377 | status |= USB_PORT_STAT_POWER; | 485 | status |= USB_PORT_STAT_POWER; |
378 | if (xhci->port_c_suspend[wIndex >> 5] & (1 << (wIndex & 31))) | 486 | if (bus_state->port_c_suspend & (1 << wIndex)) |
379 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; | 487 | status |= 1 << USB_PORT_FEAT_C_SUSPEND; |
380 | xhci_dbg(xhci, "Get port status returned 0x%x\n", status); | 488 | xhci_dbg(xhci, "Get port status returned 0x%x\n", status); |
381 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); | 489 | put_unaligned(cpu_to_le32(status), (__le32 *) buf); |
@@ -385,12 +493,16 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
385 | if (!wIndex || wIndex > ports) | 493 | if (!wIndex || wIndex > ports) |
386 | goto error; | 494 | goto error; |
387 | wIndex--; | 495 | wIndex--; |
388 | addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS*(wIndex & 0xff); | 496 | temp = xhci_readl(xhci, port_array[wIndex]); |
389 | temp = xhci_readl(xhci, addr); | 497 | if (temp == 0xffffffff) { |
498 | retval = -ENODEV; | ||
499 | break; | ||
500 | } | ||
390 | temp = xhci_port_state_to_neutral(temp); | 501 | temp = xhci_port_state_to_neutral(temp); |
502 | /* FIXME: What new port features do we need to support? */ | ||
391 | switch (wValue) { | 503 | switch (wValue) { |
392 | case USB_PORT_FEAT_SUSPEND: | 504 | case USB_PORT_FEAT_SUSPEND: |
393 | temp = xhci_readl(xhci, addr); | 505 | temp = xhci_readl(xhci, port_array[wIndex]); |
394 | /* In spec software should not attempt to suspend | 506 | /* In spec software should not attempt to suspend |
395 | * a port unless the port reports that it is in the | 507 | * a port unless the port reports that it is in the |
396 | * enabled (PED = ‘1’,PLS < ‘3’) state. | 508 | * enabled (PED = ‘1’,PLS < ‘3’) state. |
@@ -402,7 +514,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
402 | goto error; | 514 | goto error; |
403 | } | 515 | } |
404 | 516 | ||
405 | slot_id = xhci_find_slot_id_by_port(xhci, wIndex + 1); | 517 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
518 | wIndex + 1); | ||
406 | if (!slot_id) { | 519 | if (!slot_id) { |
407 | xhci_warn(xhci, "slot_id is zero\n"); | 520 | xhci_warn(xhci, "slot_id is zero\n"); |
408 | goto error; | 521 | goto error; |
@@ -415,15 +528,14 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
415 | temp = xhci_port_state_to_neutral(temp); | 528 | temp = xhci_port_state_to_neutral(temp); |
416 | temp &= ~PORT_PLS_MASK; | 529 | temp &= ~PORT_PLS_MASK; |
417 | temp |= PORT_LINK_STROBE | XDEV_U3; | 530 | temp |= PORT_LINK_STROBE | XDEV_U3; |
418 | xhci_writel(xhci, temp, addr); | 531 | xhci_writel(xhci, temp, port_array[wIndex]); |
419 | 532 | ||
420 | spin_unlock_irqrestore(&xhci->lock, flags); | 533 | spin_unlock_irqrestore(&xhci->lock, flags); |
421 | msleep(10); /* wait device to enter */ | 534 | msleep(10); /* wait device to enter */ |
422 | spin_lock_irqsave(&xhci->lock, flags); | 535 | spin_lock_irqsave(&xhci->lock, flags); |
423 | 536 | ||
424 | temp = xhci_readl(xhci, addr); | 537 | temp = xhci_readl(xhci, port_array[wIndex]); |
425 | xhci->suspended_ports[wIndex >> 5] |= | 538 | bus_state->suspended_ports |= 1 << wIndex; |
426 | 1 << (wIndex & (31)); | ||
427 | break; | 539 | break; |
428 | case USB_PORT_FEAT_POWER: | 540 | case USB_PORT_FEAT_POWER: |
429 | /* | 541 | /* |
@@ -432,34 +544,39 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
432 | * However, khubd will ignore the roothub events until | 544 | * However, khubd will ignore the roothub events until |
433 | * the roothub is registered. | 545 | * the roothub is registered. |
434 | */ | 546 | */ |
435 | xhci_writel(xhci, temp | PORT_POWER, addr); | 547 | xhci_writel(xhci, temp | PORT_POWER, |
548 | port_array[wIndex]); | ||
436 | 549 | ||
437 | temp = xhci_readl(xhci, addr); | 550 | temp = xhci_readl(xhci, port_array[wIndex]); |
438 | xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); | 551 | xhci_dbg(xhci, "set port power, actual port %d status = 0x%x\n", wIndex, temp); |
439 | break; | 552 | break; |
440 | case USB_PORT_FEAT_RESET: | 553 | case USB_PORT_FEAT_RESET: |
441 | temp = (temp | PORT_RESET); | 554 | temp = (temp | PORT_RESET); |
442 | xhci_writel(xhci, temp, addr); | 555 | xhci_writel(xhci, temp, port_array[wIndex]); |
443 | 556 | ||
444 | temp = xhci_readl(xhci, addr); | 557 | temp = xhci_readl(xhci, port_array[wIndex]); |
445 | xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); | 558 | xhci_dbg(xhci, "set port reset, actual port %d status = 0x%x\n", wIndex, temp); |
446 | break; | 559 | break; |
447 | default: | 560 | default: |
448 | goto error; | 561 | goto error; |
449 | } | 562 | } |
450 | temp = xhci_readl(xhci, addr); /* unblock any posted writes */ | 563 | /* unblock any posted writes */ |
564 | temp = xhci_readl(xhci, port_array[wIndex]); | ||
451 | break; | 565 | break; |
452 | case ClearPortFeature: | 566 | case ClearPortFeature: |
453 | if (!wIndex || wIndex > ports) | 567 | if (!wIndex || wIndex > ports) |
454 | goto error; | 568 | goto error; |
455 | wIndex--; | 569 | wIndex--; |
456 | addr = &xhci->op_regs->port_status_base + | 570 | temp = xhci_readl(xhci, port_array[wIndex]); |
457 | NUM_PORT_REGS*(wIndex & 0xff); | 571 | if (temp == 0xffffffff) { |
458 | temp = xhci_readl(xhci, addr); | 572 | retval = -ENODEV; |
573 | break; | ||
574 | } | ||
575 | /* FIXME: What new port features do we need to support? */ | ||
459 | temp = xhci_port_state_to_neutral(temp); | 576 | temp = xhci_port_state_to_neutral(temp); |
460 | switch (wValue) { | 577 | switch (wValue) { |
461 | case USB_PORT_FEAT_SUSPEND: | 578 | case USB_PORT_FEAT_SUSPEND: |
462 | temp = xhci_readl(xhci, addr); | 579 | temp = xhci_readl(xhci, port_array[wIndex]); |
463 | xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); | 580 | xhci_dbg(xhci, "clear USB_PORT_FEAT_SUSPEND\n"); |
464 | xhci_dbg(xhci, "PORTSC %04x\n", temp); | 581 | xhci_dbg(xhci, "PORTSC %04x\n", temp); |
465 | if (temp & PORT_RESET) | 582 | if (temp & PORT_RESET) |
@@ -471,30 +588,34 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
471 | temp = xhci_port_state_to_neutral(temp); | 588 | temp = xhci_port_state_to_neutral(temp); |
472 | temp &= ~PORT_PLS_MASK; | 589 | temp &= ~PORT_PLS_MASK; |
473 | temp |= PORT_LINK_STROBE | XDEV_U0; | 590 | temp |= PORT_LINK_STROBE | XDEV_U0; |
474 | xhci_writel(xhci, temp, addr); | 591 | xhci_writel(xhci, temp, |
475 | xhci_readl(xhci, addr); | 592 | port_array[wIndex]); |
593 | xhci_readl(xhci, port_array[wIndex]); | ||
476 | } else { | 594 | } else { |
477 | temp = xhci_port_state_to_neutral(temp); | 595 | temp = xhci_port_state_to_neutral(temp); |
478 | temp &= ~PORT_PLS_MASK; | 596 | temp &= ~PORT_PLS_MASK; |
479 | temp |= PORT_LINK_STROBE | XDEV_RESUME; | 597 | temp |= PORT_LINK_STROBE | XDEV_RESUME; |
480 | xhci_writel(xhci, temp, addr); | 598 | xhci_writel(xhci, temp, |
599 | port_array[wIndex]); | ||
481 | 600 | ||
482 | spin_unlock_irqrestore(&xhci->lock, | 601 | spin_unlock_irqrestore(&xhci->lock, |
483 | flags); | 602 | flags); |
484 | msleep(20); | 603 | msleep(20); |
485 | spin_lock_irqsave(&xhci->lock, flags); | 604 | spin_lock_irqsave(&xhci->lock, flags); |
486 | 605 | ||
487 | temp = xhci_readl(xhci, addr); | 606 | temp = xhci_readl(xhci, |
607 | port_array[wIndex]); | ||
488 | temp = xhci_port_state_to_neutral(temp); | 608 | temp = xhci_port_state_to_neutral(temp); |
489 | temp &= ~PORT_PLS_MASK; | 609 | temp &= ~PORT_PLS_MASK; |
490 | temp |= PORT_LINK_STROBE | XDEV_U0; | 610 | temp |= PORT_LINK_STROBE | XDEV_U0; |
491 | xhci_writel(xhci, temp, addr); | 611 | xhci_writel(xhci, temp, |
612 | port_array[wIndex]); | ||
492 | } | 613 | } |
493 | xhci->port_c_suspend[wIndex >> 5] |= | 614 | bus_state->port_c_suspend |= 1 << wIndex; |
494 | 1 << (wIndex & 31); | ||
495 | } | 615 | } |
496 | 616 | ||
497 | slot_id = xhci_find_slot_id_by_port(xhci, wIndex + 1); | 617 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
618 | wIndex + 1); | ||
498 | if (!slot_id) { | 619 | if (!slot_id) { |
499 | xhci_dbg(xhci, "slot_id is zero\n"); | 620 | xhci_dbg(xhci, "slot_id is zero\n"); |
500 | goto error; | 621 | goto error; |
@@ -502,17 +623,17 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
502 | xhci_ring_device(xhci, slot_id); | 623 | xhci_ring_device(xhci, slot_id); |
503 | break; | 624 | break; |
504 | case USB_PORT_FEAT_C_SUSPEND: | 625 | case USB_PORT_FEAT_C_SUSPEND: |
505 | xhci->port_c_suspend[wIndex >> 5] &= | 626 | bus_state->port_c_suspend &= ~(1 << wIndex); |
506 | ~(1 << (wIndex & 31)); | ||
507 | case USB_PORT_FEAT_C_RESET: | 627 | case USB_PORT_FEAT_C_RESET: |
508 | case USB_PORT_FEAT_C_CONNECTION: | 628 | case USB_PORT_FEAT_C_CONNECTION: |
509 | case USB_PORT_FEAT_C_OVER_CURRENT: | 629 | case USB_PORT_FEAT_C_OVER_CURRENT: |
510 | case USB_PORT_FEAT_C_ENABLE: | 630 | case USB_PORT_FEAT_C_ENABLE: |
511 | xhci_clear_port_change_bit(xhci, wValue, wIndex, | 631 | xhci_clear_port_change_bit(xhci, wValue, wIndex, |
512 | addr, temp); | 632 | port_array[wIndex], temp); |
513 | break; | 633 | break; |
514 | case USB_PORT_FEAT_ENABLE: | 634 | case USB_PORT_FEAT_ENABLE: |
515 | xhci_disable_port(xhci, wIndex, addr, temp); | 635 | xhci_disable_port(hcd, xhci, wIndex, |
636 | port_array[wIndex], temp); | ||
516 | break; | 637 | break; |
517 | default: | 638 | default: |
518 | goto error; | 639 | goto error; |
@@ -543,9 +664,17 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
543 | int i, retval; | 664 | int i, retval; |
544 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 665 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
545 | int ports; | 666 | int ports; |
546 | u32 __iomem *addr; | 667 | u32 __iomem **port_array; |
547 | 668 | struct xhci_bus_state *bus_state; | |
548 | ports = HCS_MAX_PORTS(xhci->hcs_params1); | 669 | |
670 | if (hcd->speed == HCD_USB3) { | ||
671 | ports = xhci->num_usb3_ports; | ||
672 | port_array = xhci->usb3_ports; | ||
673 | } else { | ||
674 | ports = xhci->num_usb2_ports; | ||
675 | port_array = xhci->usb2_ports; | ||
676 | } | ||
677 | bus_state = &xhci->bus_state[hcd_index(hcd)]; | ||
549 | 678 | ||
550 | /* Initial status is no changes */ | 679 | /* Initial status is no changes */ |
551 | retval = (ports + 8) / 8; | 680 | retval = (ports + 8) / 8; |
@@ -557,13 +686,15 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
557 | spin_lock_irqsave(&xhci->lock, flags); | 686 | spin_lock_irqsave(&xhci->lock, flags); |
558 | /* For each port, did anything change? If so, set that bit in buf. */ | 687 | /* For each port, did anything change? If so, set that bit in buf. */ |
559 | for (i = 0; i < ports; i++) { | 688 | for (i = 0; i < ports; i++) { |
560 | addr = &xhci->op_regs->port_status_base + | 689 | temp = xhci_readl(xhci, port_array[i]); |
561 | NUM_PORT_REGS*i; | 690 | if (temp == 0xffffffff) { |
562 | temp = xhci_readl(xhci, addr); | 691 | retval = -ENODEV; |
692 | break; | ||
693 | } | ||
563 | if ((temp & mask) != 0 || | 694 | if ((temp & mask) != 0 || |
564 | (xhci->port_c_suspend[i >> 5] & 1 << (i & 31)) || | 695 | (bus_state->port_c_suspend & 1 << i) || |
565 | (xhci->resume_done[i] && time_after_eq( | 696 | (bus_state->resume_done[i] && time_after_eq( |
566 | jiffies, xhci->resume_done[i]))) { | 697 | jiffies, bus_state->resume_done[i]))) { |
567 | buf[(i + 1) / 8] |= 1 << (i + 1) % 8; | 698 | buf[(i + 1) / 8] |= 1 << (i + 1) % 8; |
568 | status = 1; | 699 | status = 1; |
569 | } | 700 | } |
@@ -577,42 +708,51 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
577 | int xhci_bus_suspend(struct usb_hcd *hcd) | 708 | int xhci_bus_suspend(struct usb_hcd *hcd) |
578 | { | 709 | { |
579 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 710 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
580 | int port; | 711 | int max_ports, port_index; |
712 | u32 __iomem **port_array; | ||
713 | struct xhci_bus_state *bus_state; | ||
581 | unsigned long flags; | 714 | unsigned long flags; |
582 | 715 | ||
583 | xhci_dbg(xhci, "suspend root hub\n"); | 716 | if (hcd->speed == HCD_USB3) { |
717 | max_ports = xhci->num_usb3_ports; | ||
718 | port_array = xhci->usb3_ports; | ||
719 | xhci_dbg(xhci, "suspend USB 3.0 root hub\n"); | ||
720 | } else { | ||
721 | max_ports = xhci->num_usb2_ports; | ||
722 | port_array = xhci->usb2_ports; | ||
723 | xhci_dbg(xhci, "suspend USB 2.0 root hub\n"); | ||
724 | } | ||
725 | bus_state = &xhci->bus_state[hcd_index(hcd)]; | ||
584 | 726 | ||
585 | spin_lock_irqsave(&xhci->lock, flags); | 727 | spin_lock_irqsave(&xhci->lock, flags); |
586 | 728 | ||
587 | if (hcd->self.root_hub->do_remote_wakeup) { | 729 | if (hcd->self.root_hub->do_remote_wakeup) { |
588 | port = HCS_MAX_PORTS(xhci->hcs_params1); | 730 | port_index = max_ports; |
589 | while (port--) { | 731 | while (port_index--) { |
590 | if (xhci->resume_done[port] != 0) { | 732 | if (bus_state->resume_done[port_index] != 0) { |
591 | spin_unlock_irqrestore(&xhci->lock, flags); | 733 | spin_unlock_irqrestore(&xhci->lock, flags); |
592 | xhci_dbg(xhci, "suspend failed because " | 734 | xhci_dbg(xhci, "suspend failed because " |
593 | "port %d is resuming\n", | 735 | "port %d is resuming\n", |
594 | port + 1); | 736 | port_index + 1); |
595 | return -EBUSY; | 737 | return -EBUSY; |
596 | } | 738 | } |
597 | } | 739 | } |
598 | } | 740 | } |
599 | 741 | ||
600 | port = HCS_MAX_PORTS(xhci->hcs_params1); | 742 | port_index = max_ports; |
601 | xhci->bus_suspended = 0; | 743 | bus_state->bus_suspended = 0; |
602 | while (port--) { | 744 | while (port_index--) { |
603 | /* suspend the port if the port is not suspended */ | 745 | /* suspend the port if the port is not suspended */ |
604 | u32 __iomem *addr; | ||
605 | u32 t1, t2; | 746 | u32 t1, t2; |
606 | int slot_id; | 747 | int slot_id; |
607 | 748 | ||
608 | addr = &xhci->op_regs->port_status_base + | 749 | t1 = xhci_readl(xhci, port_array[port_index]); |
609 | NUM_PORT_REGS * (port & 0xff); | ||
610 | t1 = xhci_readl(xhci, addr); | ||
611 | t2 = xhci_port_state_to_neutral(t1); | 750 | t2 = xhci_port_state_to_neutral(t1); |
612 | 751 | ||
613 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { | 752 | if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) { |
614 | xhci_dbg(xhci, "port %d not suspended\n", port); | 753 | xhci_dbg(xhci, "port %d not suspended\n", port_index); |
615 | slot_id = xhci_find_slot_id_by_port(xhci, port + 1); | 754 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
755 | port_index + 1); | ||
616 | if (slot_id) { | 756 | if (slot_id) { |
617 | spin_unlock_irqrestore(&xhci->lock, flags); | 757 | spin_unlock_irqrestore(&xhci->lock, flags); |
618 | xhci_stop_device(xhci, slot_id, 1); | 758 | xhci_stop_device(xhci, slot_id, 1); |
@@ -620,7 +760,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd) | |||
620 | } | 760 | } |
621 | t2 &= ~PORT_PLS_MASK; | 761 | t2 &= ~PORT_PLS_MASK; |
622 | t2 |= PORT_LINK_STROBE | XDEV_U3; | 762 | t2 |= PORT_LINK_STROBE | XDEV_U3; |
623 | set_bit(port, &xhci->bus_suspended); | 763 | set_bit(port_index, &bus_state->bus_suspended); |
624 | } | 764 | } |
625 | if (hcd->self.root_hub->do_remote_wakeup) { | 765 | if (hcd->self.root_hub->do_remote_wakeup) { |
626 | if (t1 & PORT_CONNECT) { | 766 | if (t1 & PORT_CONNECT) { |
@@ -635,22 +775,24 @@ int xhci_bus_suspend(struct usb_hcd *hcd) | |||
635 | 775 | ||
636 | t1 = xhci_port_state_to_neutral(t1); | 776 | t1 = xhci_port_state_to_neutral(t1); |
637 | if (t1 != t2) | 777 | if (t1 != t2) |
638 | xhci_writel(xhci, t2, addr); | 778 | xhci_writel(xhci, t2, port_array[port_index]); |
639 | 779 | ||
640 | if (DEV_HIGHSPEED(t1)) { | 780 | if (DEV_HIGHSPEED(t1)) { |
641 | /* enable remote wake up for USB 2.0 */ | 781 | /* enable remote wake up for USB 2.0 */ |
642 | u32 __iomem *addr; | 782 | u32 __iomem *addr; |
643 | u32 tmp; | 783 | u32 tmp; |
644 | 784 | ||
645 | addr = &xhci->op_regs->port_power_base + | 785 | /* Add one to the port status register address to get |
646 | NUM_PORT_REGS * (port & 0xff); | 786 | * the port power control register address. |
787 | */ | ||
788 | addr = port_array[port_index] + 1; | ||
647 | tmp = xhci_readl(xhci, addr); | 789 | tmp = xhci_readl(xhci, addr); |
648 | tmp |= PORT_RWE; | 790 | tmp |= PORT_RWE; |
649 | xhci_writel(xhci, tmp, addr); | 791 | xhci_writel(xhci, tmp, addr); |
650 | } | 792 | } |
651 | } | 793 | } |
652 | hcd->state = HC_STATE_SUSPENDED; | 794 | hcd->state = HC_STATE_SUSPENDED; |
653 | xhci->next_statechange = jiffies + msecs_to_jiffies(10); | 795 | bus_state->next_statechange = jiffies + msecs_to_jiffies(10); |
654 | spin_unlock_irqrestore(&xhci->lock, flags); | 796 | spin_unlock_irqrestore(&xhci->lock, flags); |
655 | return 0; | 797 | return 0; |
656 | } | 798 | } |
@@ -658,13 +800,24 @@ int xhci_bus_suspend(struct usb_hcd *hcd) | |||
658 | int xhci_bus_resume(struct usb_hcd *hcd) | 800 | int xhci_bus_resume(struct usb_hcd *hcd) |
659 | { | 801 | { |
660 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 802 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
661 | int port; | 803 | int max_ports, port_index; |
804 | u32 __iomem **port_array; | ||
805 | struct xhci_bus_state *bus_state; | ||
662 | u32 temp; | 806 | u32 temp; |
663 | unsigned long flags; | 807 | unsigned long flags; |
664 | 808 | ||
665 | xhci_dbg(xhci, "resume root hub\n"); | 809 | if (hcd->speed == HCD_USB3) { |
810 | max_ports = xhci->num_usb3_ports; | ||
811 | port_array = xhci->usb3_ports; | ||
812 | xhci_dbg(xhci, "resume USB 3.0 root hub\n"); | ||
813 | } else { | ||
814 | max_ports = xhci->num_usb2_ports; | ||
815 | port_array = xhci->usb2_ports; | ||
816 | xhci_dbg(xhci, "resume USB 2.0 root hub\n"); | ||
817 | } | ||
818 | bus_state = &xhci->bus_state[hcd_index(hcd)]; | ||
666 | 819 | ||
667 | if (time_before(jiffies, xhci->next_statechange)) | 820 | if (time_before(jiffies, bus_state->next_statechange)) |
668 | msleep(5); | 821 | msleep(5); |
669 | 822 | ||
670 | spin_lock_irqsave(&xhci->lock, flags); | 823 | spin_lock_irqsave(&xhci->lock, flags); |
@@ -678,57 +831,57 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
678 | temp &= ~CMD_EIE; | 831 | temp &= ~CMD_EIE; |
679 | xhci_writel(xhci, temp, &xhci->op_regs->command); | 832 | xhci_writel(xhci, temp, &xhci->op_regs->command); |
680 | 833 | ||
681 | port = HCS_MAX_PORTS(xhci->hcs_params1); | 834 | port_index = max_ports; |
682 | while (port--) { | 835 | while (port_index--) { |
683 | /* Check whether need resume ports. If needed | 836 | /* Check whether need resume ports. If needed |
684 | resume port and disable remote wakeup */ | 837 | resume port and disable remote wakeup */ |
685 | u32 __iomem *addr; | ||
686 | u32 temp; | 838 | u32 temp; |
687 | int slot_id; | 839 | int slot_id; |
688 | 840 | ||
689 | addr = &xhci->op_regs->port_status_base + | 841 | temp = xhci_readl(xhci, port_array[port_index]); |
690 | NUM_PORT_REGS * (port & 0xff); | ||
691 | temp = xhci_readl(xhci, addr); | ||
692 | if (DEV_SUPERSPEED(temp)) | 842 | if (DEV_SUPERSPEED(temp)) |
693 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); | 843 | temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); |
694 | else | 844 | else |
695 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); | 845 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
696 | if (test_bit(port, &xhci->bus_suspended) && | 846 | if (test_bit(port_index, &bus_state->bus_suspended) && |
697 | (temp & PORT_PLS_MASK)) { | 847 | (temp & PORT_PLS_MASK)) { |
698 | if (DEV_SUPERSPEED(temp)) { | 848 | if (DEV_SUPERSPEED(temp)) { |
699 | temp = xhci_port_state_to_neutral(temp); | 849 | temp = xhci_port_state_to_neutral(temp); |
700 | temp &= ~PORT_PLS_MASK; | 850 | temp &= ~PORT_PLS_MASK; |
701 | temp |= PORT_LINK_STROBE | XDEV_U0; | 851 | temp |= PORT_LINK_STROBE | XDEV_U0; |
702 | xhci_writel(xhci, temp, addr); | 852 | xhci_writel(xhci, temp, port_array[port_index]); |
703 | } else { | 853 | } else { |
704 | temp = xhci_port_state_to_neutral(temp); | 854 | temp = xhci_port_state_to_neutral(temp); |
705 | temp &= ~PORT_PLS_MASK; | 855 | temp &= ~PORT_PLS_MASK; |
706 | temp |= PORT_LINK_STROBE | XDEV_RESUME; | 856 | temp |= PORT_LINK_STROBE | XDEV_RESUME; |
707 | xhci_writel(xhci, temp, addr); | 857 | xhci_writel(xhci, temp, port_array[port_index]); |
708 | 858 | ||
709 | spin_unlock_irqrestore(&xhci->lock, flags); | 859 | spin_unlock_irqrestore(&xhci->lock, flags); |
710 | msleep(20); | 860 | msleep(20); |
711 | spin_lock_irqsave(&xhci->lock, flags); | 861 | spin_lock_irqsave(&xhci->lock, flags); |
712 | 862 | ||
713 | temp = xhci_readl(xhci, addr); | 863 | temp = xhci_readl(xhci, port_array[port_index]); |
714 | temp = xhci_port_state_to_neutral(temp); | 864 | temp = xhci_port_state_to_neutral(temp); |
715 | temp &= ~PORT_PLS_MASK; | 865 | temp &= ~PORT_PLS_MASK; |
716 | temp |= PORT_LINK_STROBE | XDEV_U0; | 866 | temp |= PORT_LINK_STROBE | XDEV_U0; |
717 | xhci_writel(xhci, temp, addr); | 867 | xhci_writel(xhci, temp, port_array[port_index]); |
718 | } | 868 | } |
719 | slot_id = xhci_find_slot_id_by_port(xhci, port + 1); | 869 | slot_id = xhci_find_slot_id_by_port(hcd, |
870 | xhci, port_index + 1); | ||
720 | if (slot_id) | 871 | if (slot_id) |
721 | xhci_ring_device(xhci, slot_id); | 872 | xhci_ring_device(xhci, slot_id); |
722 | } else | 873 | } else |
723 | xhci_writel(xhci, temp, addr); | 874 | xhci_writel(xhci, temp, port_array[port_index]); |
724 | 875 | ||
725 | if (DEV_HIGHSPEED(temp)) { | 876 | if (DEV_HIGHSPEED(temp)) { |
726 | /* disable remote wake up for USB 2.0 */ | 877 | /* disable remote wake up for USB 2.0 */ |
727 | u32 __iomem *addr; | 878 | u32 __iomem *addr; |
728 | u32 tmp; | 879 | u32 tmp; |
729 | 880 | ||
730 | addr = &xhci->op_regs->port_power_base + | 881 | /* Add one to the port status register address to get |
731 | NUM_PORT_REGS * (port & 0xff); | 882 | * the port power control register address. |
883 | */ | ||
884 | addr = port_array[port_index] + 1; | ||
732 | tmp = xhci_readl(xhci, addr); | 885 | tmp = xhci_readl(xhci, addr); |
733 | tmp &= ~PORT_RWE; | 886 | tmp &= ~PORT_RWE; |
734 | xhci_writel(xhci, tmp, addr); | 887 | xhci_writel(xhci, tmp, addr); |
@@ -737,8 +890,7 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
737 | 890 | ||
738 | (void) xhci_readl(xhci, &xhci->op_regs->command); | 891 | (void) xhci_readl(xhci, &xhci->op_regs->command); |
739 | 892 | ||
740 | xhci->next_statechange = jiffies + msecs_to_jiffies(5); | 893 | bus_state->next_statechange = jiffies + msecs_to_jiffies(5); |
741 | hcd->state = HC_STATE_RUNNING; | ||
742 | /* re-enable irqs */ | 894 | /* re-enable irqs */ |
743 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 895 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
744 | temp |= CMD_EIE; | 896 | temp |= CMD_EIE; |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index a9534396e85b..a003e79aacdc 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -814,14 +814,64 @@ void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci, | |||
814 | ep0_ctx->deq |= ep_ring->cycle_state; | 814 | ep0_ctx->deq |= ep_ring->cycle_state; |
815 | } | 815 | } |
816 | 816 | ||
817 | /* | ||
818 | * The xHCI roothub may have ports of differing speeds in any order in the port | ||
819 | * status registers. xhci->port_array provides an array of the port speed for | ||
820 | * each offset into the port status registers. | ||
821 | * | ||
822 | * The xHCI hardware wants to know the roothub port number that the USB device | ||
823 | * is attached to (or the roothub port its ancestor hub is attached to). All we | ||
824 | * know is the index of that port under either the USB 2.0 or the USB 3.0 | ||
825 | * roothub, but that doesn't give us the real index into the HW port status | ||
826 | * registers. Scan through the xHCI roothub port array, looking for the Nth | ||
827 | * entry of the correct port speed. Return the port number of that entry. | ||
828 | */ | ||
829 | static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, | ||
830 | struct usb_device *udev) | ||
831 | { | ||
832 | struct usb_device *top_dev; | ||
833 | unsigned int num_similar_speed_ports; | ||
834 | unsigned int faked_port_num; | ||
835 | int i; | ||
836 | |||
837 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; | ||
838 | top_dev = top_dev->parent) | ||
839 | /* Found device below root hub */; | ||
840 | faked_port_num = top_dev->portnum; | ||
841 | for (i = 0, num_similar_speed_ports = 0; | ||
842 | i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { | ||
843 | u8 port_speed = xhci->port_array[i]; | ||
844 | |||
845 | /* | ||
846 | * Skip ports that don't have known speeds, or have duplicate | ||
847 | * Extended Capabilities port speed entries. | ||
848 | */ | ||
849 | if (port_speed == 0 || port_speed == -1) | ||
850 | continue; | ||
851 | |||
852 | /* | ||
853 | * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and | ||
854 | * 1.1 ports are under the USB 2.0 hub. If the port speed | ||
855 | * matches the device speed, it's a similar speed port. | ||
856 | */ | ||
857 | if ((port_speed == 0x03) == (udev->speed == USB_SPEED_SUPER)) | ||
858 | num_similar_speed_ports++; | ||
859 | if (num_similar_speed_ports == faked_port_num) | ||
860 | /* Roothub ports are numbered from 1 to N */ | ||
861 | return i+1; | ||
862 | } | ||
863 | return 0; | ||
864 | } | ||
865 | |||
817 | /* Setup an xHCI virtual device for a Set Address command */ | 866 | /* Setup an xHCI virtual device for a Set Address command */ |
818 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) | 867 | int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev) |
819 | { | 868 | { |
820 | struct xhci_virt_device *dev; | 869 | struct xhci_virt_device *dev; |
821 | struct xhci_ep_ctx *ep0_ctx; | 870 | struct xhci_ep_ctx *ep0_ctx; |
822 | struct usb_device *top_dev; | ||
823 | struct xhci_slot_ctx *slot_ctx; | 871 | struct xhci_slot_ctx *slot_ctx; |
824 | struct xhci_input_control_ctx *ctrl_ctx; | 872 | struct xhci_input_control_ctx *ctrl_ctx; |
873 | u32 port_num; | ||
874 | struct usb_device *top_dev; | ||
825 | 875 | ||
826 | dev = xhci->devs[udev->slot_id]; | 876 | dev = xhci->devs[udev->slot_id]; |
827 | /* Slot ID 0 is reserved */ | 877 | /* Slot ID 0 is reserved */ |
@@ -863,16 +913,20 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
863 | BUG(); | 913 | BUG(); |
864 | } | 914 | } |
865 | /* Find the root hub port this device is under */ | 915 | /* Find the root hub port this device is under */ |
916 | port_num = xhci_find_real_port_number(xhci, udev); | ||
917 | if (!port_num) | ||
918 | return -EINVAL; | ||
919 | slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(port_num); | ||
920 | /* Set the port number in the virtual_device to the faked port number */ | ||
866 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; | 921 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; |
867 | top_dev = top_dev->parent) | 922 | top_dev = top_dev->parent) |
868 | /* Found device below root hub */; | 923 | /* Found device below root hub */; |
869 | slot_ctx->dev_info2 |= (u32) ROOT_HUB_PORT(top_dev->portnum); | ||
870 | dev->port = top_dev->portnum; | 924 | dev->port = top_dev->portnum; |
871 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); | 925 | xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); |
926 | xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->port); | ||
872 | 927 | ||
873 | /* Is this a LS/FS device under a HS hub? */ | 928 | /* Is this a LS/FS device under an external HS hub? */ |
874 | if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && | 929 | if (udev->tt && udev->tt->hub->parent) { |
875 | udev->tt) { | ||
876 | slot_ctx->tt_info = udev->tt->hub->slot_id; | 930 | slot_ctx->tt_info = udev->tt->hub->slot_id; |
877 | slot_ctx->tt_info |= udev->ttport << 8; | 931 | slot_ctx->tt_info |= udev->ttport << 8; |
878 | if (udev->tt->multi) | 932 | if (udev->tt->multi) |
@@ -1452,7 +1506,8 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
1452 | 1506 | ||
1453 | xhci->page_size = 0; | 1507 | xhci->page_size = 0; |
1454 | xhci->page_shift = 0; | 1508 | xhci->page_shift = 0; |
1455 | xhci->bus_suspended = 0; | 1509 | xhci->bus_state[0].bus_suspended = 0; |
1510 | xhci->bus_state[1].bus_suspended = 0; | ||
1456 | } | 1511 | } |
1457 | 1512 | ||
1458 | static int xhci_test_trb_in_td(struct xhci_hcd *xhci, | 1513 | static int xhci_test_trb_in_td(struct xhci_hcd *xhci, |
@@ -1748,6 +1803,20 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
1748 | } | 1803 | } |
1749 | xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n", | 1804 | xhci_dbg(xhci, "Found %u USB 2.0 ports and %u USB 3.0 ports.\n", |
1750 | xhci->num_usb2_ports, xhci->num_usb3_ports); | 1805 | xhci->num_usb2_ports, xhci->num_usb3_ports); |
1806 | |||
1807 | /* Place limits on the number of roothub ports so that the hub | ||
1808 | * descriptors aren't longer than the USB core will allocate. | ||
1809 | */ | ||
1810 | if (xhci->num_usb3_ports > 15) { | ||
1811 | xhci_dbg(xhci, "Limiting USB 3.0 roothub ports to 15.\n"); | ||
1812 | xhci->num_usb3_ports = 15; | ||
1813 | } | ||
1814 | if (xhci->num_usb2_ports > USB_MAXCHILDREN) { | ||
1815 | xhci_dbg(xhci, "Limiting USB 2.0 roothub ports to %u.\n", | ||
1816 | USB_MAXCHILDREN); | ||
1817 | xhci->num_usb2_ports = USB_MAXCHILDREN; | ||
1818 | } | ||
1819 | |||
1751 | /* | 1820 | /* |
1752 | * Note we could have all USB 3.0 ports, or all USB 2.0 ports. | 1821 | * Note we could have all USB 3.0 ports, or all USB 2.0 ports. |
1753 | * Not sure how the USB core will handle a hub with no ports... | 1822 | * Not sure how the USB core will handle a hub with no ports... |
@@ -1772,6 +1841,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
1772 | "addr = %p\n", i, | 1841 | "addr = %p\n", i, |
1773 | xhci->usb2_ports[port_index]); | 1842 | xhci->usb2_ports[port_index]); |
1774 | port_index++; | 1843 | port_index++; |
1844 | if (port_index == xhci->num_usb2_ports) | ||
1845 | break; | ||
1775 | } | 1846 | } |
1776 | } | 1847 | } |
1777 | if (xhci->num_usb3_ports) { | 1848 | if (xhci->num_usb3_ports) { |
@@ -1790,6 +1861,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
1790 | "addr = %p\n", i, | 1861 | "addr = %p\n", i, |
1791 | xhci->usb3_ports[port_index]); | 1862 | xhci->usb3_ports[port_index]); |
1792 | port_index++; | 1863 | port_index++; |
1864 | if (port_index == xhci->num_usb3_ports) | ||
1865 | break; | ||
1793 | } | 1866 | } |
1794 | } | 1867 | } |
1795 | return 0; | 1868 | return 0; |
@@ -1971,8 +2044,10 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
1971 | init_completion(&xhci->addr_dev); | 2044 | init_completion(&xhci->addr_dev); |
1972 | for (i = 0; i < MAX_HC_SLOTS; ++i) | 2045 | for (i = 0; i < MAX_HC_SLOTS; ++i) |
1973 | xhci->devs[i] = NULL; | 2046 | xhci->devs[i] = NULL; |
1974 | for (i = 0; i < MAX_HC_PORTS; ++i) | 2047 | for (i = 0; i < USB_MAXCHILDREN; ++i) { |
1975 | xhci->resume_done[i] = 0; | 2048 | xhci->bus_state[0].resume_done[i] = 0; |
2049 | xhci->bus_state[1].resume_done[i] = 0; | ||
2050 | } | ||
1976 | 2051 | ||
1977 | if (scratchpad_alloc(xhci, flags)) | 2052 | if (scratchpad_alloc(xhci, flags)) |
1978 | goto fail; | 2053 | goto fail; |
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index bb668a894ab9..ceea9f33491c 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
@@ -50,13 +50,45 @@ static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) | |||
50 | /* called during probe() after chip reset completes */ | 50 | /* called during probe() after chip reset completes */ |
51 | static int xhci_pci_setup(struct usb_hcd *hcd) | 51 | static int xhci_pci_setup(struct usb_hcd *hcd) |
52 | { | 52 | { |
53 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 53 | struct xhci_hcd *xhci; |
54 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 54 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); |
55 | int retval; | 55 | int retval; |
56 | u32 temp; | 56 | u32 temp; |
57 | 57 | ||
58 | hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; | 58 | hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; |
59 | 59 | ||
60 | if (usb_hcd_is_primary_hcd(hcd)) { | ||
61 | xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL); | ||
62 | if (!xhci) | ||
63 | return -ENOMEM; | ||
64 | *((struct xhci_hcd **) hcd->hcd_priv) = xhci; | ||
65 | xhci->main_hcd = hcd; | ||
66 | /* Mark the first roothub as being USB 2.0. | ||
67 | * The xHCI driver will register the USB 3.0 roothub. | ||
68 | */ | ||
69 | hcd->speed = HCD_USB2; | ||
70 | hcd->self.root_hub->speed = USB_SPEED_HIGH; | ||
71 | /* | ||
72 | * USB 2.0 roothub under xHCI has an integrated TT, | ||
73 | * (rate matching hub) as opposed to having an OHCI/UHCI | ||
74 | * companion controller. | ||
75 | */ | ||
76 | hcd->has_tt = 1; | ||
77 | } else { | ||
78 | /* xHCI private pointer was set in xhci_pci_probe for the second | ||
79 | * registered roothub. | ||
80 | */ | ||
81 | xhci = hcd_to_xhci(hcd); | ||
82 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
83 | if (HCC_64BIT_ADDR(temp)) { | ||
84 | xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); | ||
85 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); | ||
86 | } else { | ||
87 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); | ||
88 | } | ||
89 | return 0; | ||
90 | } | ||
91 | |||
60 | xhci->cap_regs = hcd->regs; | 92 | xhci->cap_regs = hcd->regs; |
61 | xhci->op_regs = hcd->regs + | 93 | xhci->op_regs = hcd->regs + |
62 | HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); | 94 | HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); |
@@ -85,13 +117,13 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
85 | /* Make sure the HC is halted. */ | 117 | /* Make sure the HC is halted. */ |
86 | retval = xhci_halt(xhci); | 118 | retval = xhci_halt(xhci); |
87 | if (retval) | 119 | if (retval) |
88 | return retval; | 120 | goto error; |
89 | 121 | ||
90 | xhci_dbg(xhci, "Resetting HCD\n"); | 122 | xhci_dbg(xhci, "Resetting HCD\n"); |
91 | /* Reset the internal HC memory state and registers. */ | 123 | /* Reset the internal HC memory state and registers. */ |
92 | retval = xhci_reset(xhci); | 124 | retval = xhci_reset(xhci); |
93 | if (retval) | 125 | if (retval) |
94 | return retval; | 126 | goto error; |
95 | xhci_dbg(xhci, "Reset complete\n"); | 127 | xhci_dbg(xhci, "Reset complete\n"); |
96 | 128 | ||
97 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | 129 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); |
@@ -106,14 +138,85 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
106 | /* Initialize HCD and host controller data structures. */ | 138 | /* Initialize HCD and host controller data structures. */ |
107 | retval = xhci_init(hcd); | 139 | retval = xhci_init(hcd); |
108 | if (retval) | 140 | if (retval) |
109 | return retval; | 141 | goto error; |
110 | xhci_dbg(xhci, "Called HCD init\n"); | 142 | xhci_dbg(xhci, "Called HCD init\n"); |
111 | 143 | ||
112 | pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); | 144 | pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); |
113 | xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); | 145 | xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); |
114 | 146 | ||
115 | /* Find any debug ports */ | 147 | /* Find any debug ports */ |
116 | return xhci_pci_reinit(xhci, pdev); | 148 | retval = xhci_pci_reinit(xhci, pdev); |
149 | if (!retval) | ||
150 | return retval; | ||
151 | |||
152 | error: | ||
153 | kfree(xhci); | ||
154 | return retval; | ||
155 | } | ||
156 | |||
157 | /* | ||
158 | * We need to register our own PCI probe function (instead of the USB core's | ||
159 | * function) in order to create a second roothub under xHCI. | ||
160 | */ | ||
161 | static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | ||
162 | { | ||
163 | int retval; | ||
164 | struct xhci_hcd *xhci; | ||
165 | struct hc_driver *driver; | ||
166 | struct usb_hcd *hcd; | ||
167 | |||
168 | driver = (struct hc_driver *)id->driver_data; | ||
169 | /* Register the USB 2.0 roothub. | ||
170 | * FIXME: USB core must know to register the USB 2.0 roothub first. | ||
171 | * This is sort of silly, because we could just set the HCD driver flags | ||
172 | * to say USB 2.0, but I'm not sure what the implications would be in | ||
173 | * the other parts of the HCD code. | ||
174 | */ | ||
175 | retval = usb_hcd_pci_probe(dev, id); | ||
176 | |||
177 | if (retval) | ||
178 | return retval; | ||
179 | |||
180 | /* USB 2.0 roothub is stored in the PCI device now. */ | ||
181 | hcd = dev_get_drvdata(&dev->dev); | ||
182 | xhci = hcd_to_xhci(hcd); | ||
183 | xhci->shared_hcd = usb_create_shared_hcd(driver, &dev->dev, | ||
184 | pci_name(dev), hcd); | ||
185 | if (!xhci->shared_hcd) { | ||
186 | retval = -ENOMEM; | ||
187 | goto dealloc_usb2_hcd; | ||
188 | } | ||
189 | |||
190 | /* Set the xHCI pointer before xhci_pci_setup() (aka hcd_driver.reset) | ||
191 | * is called by usb_add_hcd(). | ||
192 | */ | ||
193 | *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci; | ||
194 | |||
195 | retval = usb_add_hcd(xhci->shared_hcd, dev->irq, | ||
196 | IRQF_DISABLED | IRQF_SHARED); | ||
197 | if (retval) | ||
198 | goto put_usb3_hcd; | ||
199 | /* Roothub already marked as USB 3.0 speed */ | ||
200 | return 0; | ||
201 | |||
202 | put_usb3_hcd: | ||
203 | usb_put_hcd(xhci->shared_hcd); | ||
204 | dealloc_usb2_hcd: | ||
205 | usb_hcd_pci_remove(dev); | ||
206 | return retval; | ||
207 | } | ||
208 | |||
209 | static void xhci_pci_remove(struct pci_dev *dev) | ||
210 | { | ||
211 | struct xhci_hcd *xhci; | ||
212 | |||
213 | xhci = hcd_to_xhci(pci_get_drvdata(dev)); | ||
214 | if (xhci->shared_hcd) { | ||
215 | usb_remove_hcd(xhci->shared_hcd); | ||
216 | usb_put_hcd(xhci->shared_hcd); | ||
217 | } | ||
218 | usb_hcd_pci_remove(dev); | ||
219 | kfree(xhci); | ||
117 | } | 220 | } |
118 | 221 | ||
119 | #ifdef CONFIG_PM | 222 | #ifdef CONFIG_PM |
@@ -122,7 +225,8 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | |||
122 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 225 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
123 | int retval = 0; | 226 | int retval = 0; |
124 | 227 | ||
125 | if (hcd->state != HC_STATE_SUSPENDED) | 228 | if (hcd->state != HC_STATE_SUSPENDED || |
229 | xhci->shared_hcd->state != HC_STATE_SUSPENDED) | ||
126 | return -EINVAL; | 230 | return -EINVAL; |
127 | 231 | ||
128 | retval = xhci_suspend(xhci); | 232 | retval = xhci_suspend(xhci); |
@@ -143,13 +247,13 @@ static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) | |||
143 | static const struct hc_driver xhci_pci_hc_driver = { | 247 | static const struct hc_driver xhci_pci_hc_driver = { |
144 | .description = hcd_name, | 248 | .description = hcd_name, |
145 | .product_desc = "xHCI Host Controller", | 249 | .product_desc = "xHCI Host Controller", |
146 | .hcd_priv_size = sizeof(struct xhci_hcd), | 250 | .hcd_priv_size = sizeof(struct xhci_hcd *), |
147 | 251 | ||
148 | /* | 252 | /* |
149 | * generic hardware linkage | 253 | * generic hardware linkage |
150 | */ | 254 | */ |
151 | .irq = xhci_irq, | 255 | .irq = xhci_irq, |
152 | .flags = HCD_MEMORY | HCD_USB3, | 256 | .flags = HCD_MEMORY | HCD_USB3 | HCD_SHARED, |
153 | 257 | ||
154 | /* | 258 | /* |
155 | * basic lifecycle operations | 259 | * basic lifecycle operations |
@@ -210,8 +314,8 @@ static struct pci_driver xhci_pci_driver = { | |||
210 | .name = (char *) hcd_name, | 314 | .name = (char *) hcd_name, |
211 | .id_table = pci_ids, | 315 | .id_table = pci_ids, |
212 | 316 | ||
213 | .probe = usb_hcd_pci_probe, | 317 | .probe = xhci_pci_probe, |
214 | .remove = usb_hcd_pci_remove, | 318 | .remove = xhci_pci_remove, |
215 | /* suspend and resume implemented later */ | 319 | /* suspend and resume implemented later */ |
216 | 320 | ||
217 | .shutdown = usb_hcd_pci_shutdown, | 321 | .shutdown = usb_hcd_pci_shutdown, |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 3289bf4832c9..cfc1ad92473f 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
@@ -380,10 +380,8 @@ static struct xhci_segment *find_trb_seg( | |||
380 | while (cur_seg->trbs > trb || | 380 | while (cur_seg->trbs > trb || |
381 | &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { | 381 | &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { |
382 | generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; | 382 | generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; |
383 | if ((generic_trb->field[3] & TRB_TYPE_BITMASK) == | 383 | if (generic_trb->field[3] & LINK_TOGGLE) |
384 | TRB_TYPE(TRB_LINK) && | 384 | *cycle_state ^= 0x1; |
385 | (generic_trb->field[3] & LINK_TOGGLE)) | ||
386 | *cycle_state = ~(*cycle_state) & 0x1; | ||
387 | cur_seg = cur_seg->next; | 385 | cur_seg = cur_seg->next; |
388 | if (cur_seg == start_seg) | 386 | if (cur_seg == start_seg) |
389 | /* Looped over the entire list. Oops! */ | 387 | /* Looped over the entire list. Oops! */ |
@@ -497,18 +495,29 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, | |||
497 | trb = &state->new_deq_ptr->generic; | 495 | trb = &state->new_deq_ptr->generic; |
498 | if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) && | 496 | if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) && |
499 | (trb->field[3] & LINK_TOGGLE)) | 497 | (trb->field[3] & LINK_TOGGLE)) |
500 | state->new_cycle_state = ~(state->new_cycle_state) & 0x1; | 498 | state->new_cycle_state ^= 0x1; |
501 | next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); | 499 | next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); |
502 | 500 | ||
501 | /* | ||
502 | * If there is only one segment in a ring, find_trb_seg()'s while loop | ||
503 | * will not run, and it will return before it has a chance to see if it | ||
504 | * needs to toggle the cycle bit. It can't tell if the stalled transfer | ||
505 | * ended just before the link TRB on a one-segment ring, or if the TD | ||
506 | * wrapped around the top of the ring, because it doesn't have the TD in | ||
507 | * question. Look for the one-segment case where stalled TRB's address | ||
508 | * is greater than the new dequeue pointer address. | ||
509 | */ | ||
510 | if (ep_ring->first_seg == ep_ring->first_seg->next && | ||
511 | state->new_deq_ptr < dev->eps[ep_index].stopped_trb) | ||
512 | state->new_cycle_state ^= 0x1; | ||
513 | xhci_dbg(xhci, "Cycle state = 0x%x\n", state->new_cycle_state); | ||
514 | |||
503 | /* Don't update the ring cycle state for the producer (us). */ | 515 | /* Don't update the ring cycle state for the producer (us). */ |
504 | xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", | 516 | xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", |
505 | state->new_deq_seg); | 517 | state->new_deq_seg); |
506 | addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); | 518 | addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); |
507 | xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", | 519 | xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", |
508 | (unsigned long long) addr); | 520 | (unsigned long long) addr); |
509 | xhci_dbg(xhci, "Setting dequeue pointer in internal ring state.\n"); | ||
510 | ep_ring->dequeue = state->new_deq_ptr; | ||
511 | ep_ring->deq_seg = state->new_deq_seg; | ||
512 | } | 521 | } |
513 | 522 | ||
514 | static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | 523 | static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, |
@@ -599,13 +608,14 @@ static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, | |||
599 | static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, | 608 | static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, |
600 | struct xhci_td *cur_td, int status, char *adjective) | 609 | struct xhci_td *cur_td, int status, char *adjective) |
601 | { | 610 | { |
602 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 611 | struct usb_hcd *hcd; |
603 | struct urb *urb; | 612 | struct urb *urb; |
604 | struct urb_priv *urb_priv; | 613 | struct urb_priv *urb_priv; |
605 | 614 | ||
606 | urb = cur_td->urb; | 615 | urb = cur_td->urb; |
607 | urb_priv = urb->hcpriv; | 616 | urb_priv = urb->hcpriv; |
608 | urb_priv->td_cnt++; | 617 | urb_priv->td_cnt++; |
618 | hcd = bus_to_hcd(urb->dev->bus); | ||
609 | 619 | ||
610 | /* Only giveback urb when this is the last td in urb */ | 620 | /* Only giveback urb when this is the last td in urb */ |
611 | if (urb_priv->td_cnt == urb_priv->length) { | 621 | if (urb_priv->td_cnt == urb_priv->length) { |
@@ -824,8 +834,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
824 | if (ret < 0) { | 834 | if (ret < 0) { |
825 | /* This is bad; the host is not responding to commands and it's | 835 | /* This is bad; the host is not responding to commands and it's |
826 | * not allowing itself to be halted. At least interrupts are | 836 | * not allowing itself to be halted. At least interrupts are |
827 | * disabled, so we can set HC_STATE_HALT and notify the | 837 | * disabled. If we call usb_hc_died(), it will attempt to |
828 | * USB core. But if we call usb_hc_died(), it will attempt to | ||
829 | * disconnect all device drivers under this host. Those | 838 | * disconnect all device drivers under this host. Those |
830 | * disconnect() methods will wait for all URBs to be unlinked, | 839 | * disconnect() methods will wait for all URBs to be unlinked, |
831 | * so we must complete them. | 840 | * so we must complete them. |
@@ -870,9 +879,8 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
870 | } | 879 | } |
871 | } | 880 | } |
872 | spin_unlock(&xhci->lock); | 881 | spin_unlock(&xhci->lock); |
873 | xhci_to_hcd(xhci)->state = HC_STATE_HALT; | ||
874 | xhci_dbg(xhci, "Calling usb_hc_died()\n"); | 882 | xhci_dbg(xhci, "Calling usb_hc_died()\n"); |
875 | usb_hc_died(xhci_to_hcd(xhci)); | 883 | usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); |
876 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); | 884 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); |
877 | } | 885 | } |
878 | 886 | ||
@@ -951,9 +959,26 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci, | |||
951 | } else { | 959 | } else { |
952 | xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n", | 960 | xhci_dbg(xhci, "Successful Set TR Deq Ptr cmd, deq = @%08llx\n", |
953 | ep_ctx->deq); | 961 | ep_ctx->deq); |
962 | if (xhci_trb_virt_to_dma(dev->eps[ep_index].queued_deq_seg, | ||
963 | dev->eps[ep_index].queued_deq_ptr) == | ||
964 | (ep_ctx->deq & ~(EP_CTX_CYCLE_MASK))) { | ||
965 | /* Update the ring's dequeue segment and dequeue pointer | ||
966 | * to reflect the new position. | ||
967 | */ | ||
968 | ep_ring->deq_seg = dev->eps[ep_index].queued_deq_seg; | ||
969 | ep_ring->dequeue = dev->eps[ep_index].queued_deq_ptr; | ||
970 | } else { | ||
971 | xhci_warn(xhci, "Mismatch between completed Set TR Deq " | ||
972 | "Ptr command & xHCI internal state.\n"); | ||
973 | xhci_warn(xhci, "ep deq seg = %p, deq ptr = %p\n", | ||
974 | dev->eps[ep_index].queued_deq_seg, | ||
975 | dev->eps[ep_index].queued_deq_ptr); | ||
976 | } | ||
954 | } | 977 | } |
955 | 978 | ||
956 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; | 979 | dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; |
980 | dev->eps[ep_index].queued_deq_seg = NULL; | ||
981 | dev->eps[ep_index].queued_deq_ptr = NULL; | ||
957 | /* Restart any rings with pending URBs */ | 982 | /* Restart any rings with pending URBs */ |
958 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); | 983 | ring_doorbell_for_active_rings(xhci, slot_id, ep_index); |
959 | } | 984 | } |
@@ -1118,7 +1143,6 @@ bandwidth_change: | |||
1118 | handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); | 1143 | handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); |
1119 | break; | 1144 | break; |
1120 | case TRB_TYPE(TRB_CMD_NOOP): | 1145 | case TRB_TYPE(TRB_CMD_NOOP): |
1121 | ++xhci->noops_handled; | ||
1122 | break; | 1146 | break; |
1123 | case TRB_TYPE(TRB_RESET_EP): | 1147 | case TRB_TYPE(TRB_RESET_EP): |
1124 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); | 1148 | handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); |
@@ -1162,15 +1186,55 @@ static void handle_vendor_event(struct xhci_hcd *xhci, | |||
1162 | handle_cmd_completion(xhci, &event->event_cmd); | 1186 | handle_cmd_completion(xhci, &event->event_cmd); |
1163 | } | 1187 | } |
1164 | 1188 | ||
1189 | /* @port_id: the one-based port ID from the hardware (indexed from array of all | ||
1190 | * port registers -- USB 3.0 and USB 2.0). | ||
1191 | * | ||
1192 | * Returns a zero-based port number, which is suitable for indexing into each of | ||
1193 | * the split roothubs' port arrays and bus state arrays. | ||
1194 | */ | ||
1195 | static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd, | ||
1196 | struct xhci_hcd *xhci, u32 port_id) | ||
1197 | { | ||
1198 | unsigned int i; | ||
1199 | unsigned int num_similar_speed_ports = 0; | ||
1200 | |||
1201 | /* port_id from the hardware is 1-based, but port_array[], usb3_ports[], | ||
1202 | * and usb2_ports are 0-based indexes. Count the number of similar | ||
1203 | * speed ports, up to 1 port before this port. | ||
1204 | */ | ||
1205 | for (i = 0; i < (port_id - 1); i++) { | ||
1206 | u8 port_speed = xhci->port_array[i]; | ||
1207 | |||
1208 | /* | ||
1209 | * Skip ports that don't have known speeds, or have duplicate | ||
1210 | * Extended Capabilities port speed entries. | ||
1211 | */ | ||
1212 | if (port_speed == 0 || port_speed == -1) | ||
1213 | continue; | ||
1214 | |||
1215 | /* | ||
1216 | * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and | ||
1217 | * 1.1 ports are under the USB 2.0 hub. If the port speed | ||
1218 | * matches the device speed, it's a similar speed port. | ||
1219 | */ | ||
1220 | if ((port_speed == 0x03) == (hcd->speed == HCD_USB3)) | ||
1221 | num_similar_speed_ports++; | ||
1222 | } | ||
1223 | return num_similar_speed_ports; | ||
1224 | } | ||
1225 | |||
1165 | static void handle_port_status(struct xhci_hcd *xhci, | 1226 | static void handle_port_status(struct xhci_hcd *xhci, |
1166 | union xhci_trb *event) | 1227 | union xhci_trb *event) |
1167 | { | 1228 | { |
1168 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 1229 | struct usb_hcd *hcd; |
1169 | u32 port_id; | 1230 | u32 port_id; |
1170 | u32 temp, temp1; | 1231 | u32 temp, temp1; |
1171 | u32 __iomem *addr; | 1232 | int max_ports; |
1172 | int ports; | ||
1173 | int slot_id; | 1233 | int slot_id; |
1234 | unsigned int faked_port_index; | ||
1235 | u8 major_revision; | ||
1236 | struct xhci_bus_state *bus_state; | ||
1237 | u32 __iomem **port_array; | ||
1174 | 1238 | ||
1175 | /* Port status change events always have a successful completion code */ | 1239 | /* Port status change events always have a successful completion code */ |
1176 | if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { | 1240 | if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { |
@@ -1180,14 +1244,50 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
1180 | port_id = GET_PORT_ID(event->generic.field[0]); | 1244 | port_id = GET_PORT_ID(event->generic.field[0]); |
1181 | xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id); | 1245 | xhci_dbg(xhci, "Port Status Change Event for port %d\n", port_id); |
1182 | 1246 | ||
1183 | ports = HCS_MAX_PORTS(xhci->hcs_params1); | 1247 | max_ports = HCS_MAX_PORTS(xhci->hcs_params1); |
1184 | if ((port_id <= 0) || (port_id > ports)) { | 1248 | if ((port_id <= 0) || (port_id > max_ports)) { |
1185 | xhci_warn(xhci, "Invalid port id %d\n", port_id); | 1249 | xhci_warn(xhci, "Invalid port id %d\n", port_id); |
1186 | goto cleanup; | 1250 | goto cleanup; |
1187 | } | 1251 | } |
1188 | 1252 | ||
1189 | addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS * (port_id - 1); | 1253 | /* Figure out which usb_hcd this port is attached to: |
1190 | temp = xhci_readl(xhci, addr); | 1254 | * is it a USB 3.0 port or a USB 2.0/1.1 port? |
1255 | */ | ||
1256 | major_revision = xhci->port_array[port_id - 1]; | ||
1257 | if (major_revision == 0) { | ||
1258 | xhci_warn(xhci, "Event for port %u not in " | ||
1259 | "Extended Capabilities, ignoring.\n", | ||
1260 | port_id); | ||
1261 | goto cleanup; | ||
1262 | } | ||
1263 | if (major_revision == (u8) -1) { | ||
1264 | xhci_warn(xhci, "Event for port %u duplicated in" | ||
1265 | "Extended Capabilities, ignoring.\n", | ||
1266 | port_id); | ||
1267 | goto cleanup; | ||
1268 | } | ||
1269 | |||
1270 | /* | ||
1271 | * Hardware port IDs reported by a Port Status Change Event include USB | ||
1272 | * 3.0 and USB 2.0 ports. We want to check if the port has reported a | ||
1273 | * resume event, but we first need to translate the hardware port ID | ||
1274 | * into the index into the ports on the correct split roothub, and the | ||
1275 | * correct bus_state structure. | ||
1276 | */ | ||
1277 | /* Find the right roothub. */ | ||
1278 | hcd = xhci_to_hcd(xhci); | ||
1279 | if ((major_revision == 0x03) != (hcd->speed == HCD_USB3)) | ||
1280 | hcd = xhci->shared_hcd; | ||
1281 | bus_state = &xhci->bus_state[hcd_index(hcd)]; | ||
1282 | if (hcd->speed == HCD_USB3) | ||
1283 | port_array = xhci->usb3_ports; | ||
1284 | else | ||
1285 | port_array = xhci->usb2_ports; | ||
1286 | /* Find the faked port hub number */ | ||
1287 | faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci, | ||
1288 | port_id); | ||
1289 | |||
1290 | temp = xhci_readl(xhci, port_array[faked_port_index]); | ||
1191 | if (hcd->state == HC_STATE_SUSPENDED) { | 1291 | if (hcd->state == HC_STATE_SUSPENDED) { |
1192 | xhci_dbg(xhci, "resume root hub\n"); | 1292 | xhci_dbg(xhci, "resume root hub\n"); |
1193 | usb_hcd_resume_root_hub(hcd); | 1293 | usb_hcd_resume_root_hub(hcd); |
@@ -1207,8 +1307,9 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
1207 | temp = xhci_port_state_to_neutral(temp); | 1307 | temp = xhci_port_state_to_neutral(temp); |
1208 | temp &= ~PORT_PLS_MASK; | 1308 | temp &= ~PORT_PLS_MASK; |
1209 | temp |= PORT_LINK_STROBE | XDEV_U0; | 1309 | temp |= PORT_LINK_STROBE | XDEV_U0; |
1210 | xhci_writel(xhci, temp, addr); | 1310 | xhci_writel(xhci, temp, port_array[faked_port_index]); |
1211 | slot_id = xhci_find_slot_id_by_port(xhci, port_id); | 1311 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
1312 | faked_port_index); | ||
1212 | if (!slot_id) { | 1313 | if (!slot_id) { |
1213 | xhci_dbg(xhci, "slot_id is zero\n"); | 1314 | xhci_dbg(xhci, "slot_id is zero\n"); |
1214 | goto cleanup; | 1315 | goto cleanup; |
@@ -1216,16 +1317,16 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
1216 | xhci_ring_device(xhci, slot_id); | 1317 | xhci_ring_device(xhci, slot_id); |
1217 | xhci_dbg(xhci, "resume SS port %d finished\n", port_id); | 1318 | xhci_dbg(xhci, "resume SS port %d finished\n", port_id); |
1218 | /* Clear PORT_PLC */ | 1319 | /* Clear PORT_PLC */ |
1219 | temp = xhci_readl(xhci, addr); | 1320 | temp = xhci_readl(xhci, port_array[faked_port_index]); |
1220 | temp = xhci_port_state_to_neutral(temp); | 1321 | temp = xhci_port_state_to_neutral(temp); |
1221 | temp |= PORT_PLC; | 1322 | temp |= PORT_PLC; |
1222 | xhci_writel(xhci, temp, addr); | 1323 | xhci_writel(xhci, temp, port_array[faked_port_index]); |
1223 | } else { | 1324 | } else { |
1224 | xhci_dbg(xhci, "resume HS port %d\n", port_id); | 1325 | xhci_dbg(xhci, "resume HS port %d\n", port_id); |
1225 | xhci->resume_done[port_id - 1] = jiffies + | 1326 | bus_state->resume_done[faked_port_index] = jiffies + |
1226 | msecs_to_jiffies(20); | 1327 | msecs_to_jiffies(20); |
1227 | mod_timer(&hcd->rh_timer, | 1328 | mod_timer(&hcd->rh_timer, |
1228 | xhci->resume_done[port_id - 1]); | 1329 | bus_state->resume_done[faked_port_index]); |
1229 | /* Do the rest in GetPortStatus */ | 1330 | /* Do the rest in GetPortStatus */ |
1230 | } | 1331 | } |
1231 | } | 1332 | } |
@@ -1236,7 +1337,7 @@ cleanup: | |||
1236 | 1337 | ||
1237 | spin_unlock(&xhci->lock); | 1338 | spin_unlock(&xhci->lock); |
1238 | /* Pass this up to the core */ | 1339 | /* Pass this up to the core */ |
1239 | usb_hcd_poll_rh_status(xhci_to_hcd(xhci)); | 1340 | usb_hcd_poll_rh_status(hcd); |
1240 | spin_lock(&xhci->lock); | 1341 | spin_lock(&xhci->lock); |
1241 | } | 1342 | } |
1242 | 1343 | ||
@@ -1990,12 +2091,12 @@ cleanup: | |||
1990 | trb_comp_code != COMP_BABBLE)) | 2091 | trb_comp_code != COMP_BABBLE)) |
1991 | xhci_urb_free_priv(xhci, urb_priv); | 2092 | xhci_urb_free_priv(xhci, urb_priv); |
1992 | 2093 | ||
1993 | usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); | 2094 | usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); |
1994 | xhci_dbg(xhci, "Giveback URB %p, len = %d, " | 2095 | xhci_dbg(xhci, "Giveback URB %p, len = %d, " |
1995 | "status = %d\n", | 2096 | "status = %d\n", |
1996 | urb, urb->actual_length, status); | 2097 | urb, urb->actual_length, status); |
1997 | spin_unlock(&xhci->lock); | 2098 | spin_unlock(&xhci->lock); |
1998 | usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); | 2099 | usb_hcd_giveback_urb(bus_to_hcd(urb->dev->bus), urb, status); |
1999 | spin_lock(&xhci->lock); | 2100 | spin_lock(&xhci->lock); |
2000 | } | 2101 | } |
2001 | 2102 | ||
@@ -2119,7 +2220,6 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) | |||
2119 | xhci_warn(xhci, "WARNING: Host System Error\n"); | 2220 | xhci_warn(xhci, "WARNING: Host System Error\n"); |
2120 | xhci_halt(xhci); | 2221 | xhci_halt(xhci); |
2121 | hw_died: | 2222 | hw_died: |
2122 | xhci_to_hcd(xhci)->state = HC_STATE_HALT; | ||
2123 | spin_unlock(&xhci->lock); | 2223 | spin_unlock(&xhci->lock); |
2124 | return -ESHUTDOWN; | 2224 | return -ESHUTDOWN; |
2125 | } | 2225 | } |
@@ -2187,8 +2287,12 @@ hw_died: | |||
2187 | irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) | 2287 | irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) |
2188 | { | 2288 | { |
2189 | irqreturn_t ret; | 2289 | irqreturn_t ret; |
2290 | struct xhci_hcd *xhci; | ||
2190 | 2291 | ||
2292 | xhci = hcd_to_xhci(hcd); | ||
2191 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 2293 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
2294 | if (xhci->shared_hcd) | ||
2295 | set_bit(HCD_FLAG_SAW_IRQ, &xhci->shared_hcd->flags); | ||
2192 | 2296 | ||
2193 | ret = xhci_irq(hcd); | 2297 | ret = xhci_irq(hcd); |
2194 | 2298 | ||
@@ -2332,7 +2436,7 @@ static int prepare_transfer(struct xhci_hcd *xhci, | |||
2332 | INIT_LIST_HEAD(&td->cancelled_td_list); | 2436 | INIT_LIST_HEAD(&td->cancelled_td_list); |
2333 | 2437 | ||
2334 | if (td_index == 0) { | 2438 | if (td_index == 0) { |
2335 | ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); | 2439 | ret = usb_hcd_link_urb_to_ep(bus_to_hcd(urb->dev->bus), urb); |
2336 | if (unlikely(ret)) { | 2440 | if (unlikely(ret)) { |
2337 | xhci_urb_free_priv(xhci, urb_priv); | 2441 | xhci_urb_free_priv(xhci, urb_priv); |
2338 | urb->hcpriv = NULL; | 2442 | urb->hcpriv = NULL; |
@@ -3131,24 +3235,6 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | |||
3131 | return 0; | 3235 | return 0; |
3132 | } | 3236 | } |
3133 | 3237 | ||
3134 | /* Queue a no-op command on the command ring */ | ||
3135 | static int queue_cmd_noop(struct xhci_hcd *xhci) | ||
3136 | { | ||
3137 | return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false); | ||
3138 | } | ||
3139 | |||
3140 | /* | ||
3141 | * Place a no-op command on the command ring to test the command and | ||
3142 | * event ring. | ||
3143 | */ | ||
3144 | void *xhci_setup_one_noop(struct xhci_hcd *xhci) | ||
3145 | { | ||
3146 | if (queue_cmd_noop(xhci) < 0) | ||
3147 | return NULL; | ||
3148 | xhci->noops_submitted++; | ||
3149 | return xhci_ring_cmd_db; | ||
3150 | } | ||
3151 | |||
3152 | /* Queue a slot enable or disable request on the command ring */ | 3238 | /* Queue a slot enable or disable request on the command ring */ |
3153 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) | 3239 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) |
3154 | { | 3240 | { |
@@ -3229,6 +3315,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
3229 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); | 3315 | u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); |
3230 | u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id); | 3316 | u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id); |
3231 | u32 type = TRB_TYPE(TRB_SET_DEQ); | 3317 | u32 type = TRB_TYPE(TRB_SET_DEQ); |
3318 | struct xhci_virt_ep *ep; | ||
3232 | 3319 | ||
3233 | addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); | 3320 | addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); |
3234 | if (addr == 0) { | 3321 | if (addr == 0) { |
@@ -3237,6 +3324,14 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
3237 | deq_seg, deq_ptr); | 3324 | deq_seg, deq_ptr); |
3238 | return 0; | 3325 | return 0; |
3239 | } | 3326 | } |
3327 | ep = &xhci->devs[slot_id]->eps[ep_index]; | ||
3328 | if ((ep->ep_state & SET_DEQ_PENDING)) { | ||
3329 | xhci_warn(xhci, "WARN Cannot submit Set TR Deq Ptr\n"); | ||
3330 | xhci_warn(xhci, "A Set TR Deq Ptr command is pending.\n"); | ||
3331 | return 0; | ||
3332 | } | ||
3333 | ep->queued_deq_seg = deq_seg; | ||
3334 | ep->queued_deq_ptr = deq_ptr; | ||
3240 | return queue_command(xhci, lower_32_bits(addr) | cycle_state, | 3335 | return queue_command(xhci, lower_32_bits(addr) | cycle_state, |
3241 | upper_32_bits(addr), trb_stream_id, | 3336 | upper_32_bits(addr), trb_stream_id, |
3242 | trb_slot_id | trb_ep_index | type, false); | 3337 | trb_slot_id | trb_ep_index | type, false); |
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 2083fc2179b2..9a3645fd759b 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
@@ -93,17 +93,20 @@ void xhci_quiesce(struct xhci_hcd *xhci) | |||
93 | * | 93 | * |
94 | * Disable any IRQs and clear the run/stop bit. | 94 | * Disable any IRQs and clear the run/stop bit. |
95 | * HC will complete any current and actively pipelined transactions, and | 95 | * HC will complete any current and actively pipelined transactions, and |
96 | * should halt within 16 microframes of the run/stop bit being cleared. | 96 | * should halt within 16 ms of the run/stop bit being cleared. |
97 | * Read HC Halted bit in the status register to see when the HC is finished. | 97 | * Read HC Halted bit in the status register to see when the HC is finished. |
98 | * XXX: shouldn't we set HC_STATE_HALT here somewhere? | ||
99 | */ | 98 | */ |
100 | int xhci_halt(struct xhci_hcd *xhci) | 99 | int xhci_halt(struct xhci_hcd *xhci) |
101 | { | 100 | { |
101 | int ret; | ||
102 | xhci_dbg(xhci, "// Halt the HC\n"); | 102 | xhci_dbg(xhci, "// Halt the HC\n"); |
103 | xhci_quiesce(xhci); | 103 | xhci_quiesce(xhci); |
104 | 104 | ||
105 | return handshake(xhci, &xhci->op_regs->status, | 105 | ret = handshake(xhci, &xhci->op_regs->status, |
106 | STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); | 106 | STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); |
107 | if (!ret) | ||
108 | xhci->xhc_state |= XHCI_STATE_HALTED; | ||
109 | return ret; | ||
107 | } | 110 | } |
108 | 111 | ||
109 | /* | 112 | /* |
@@ -130,11 +133,13 @@ static int xhci_start(struct xhci_hcd *xhci) | |||
130 | xhci_err(xhci, "Host took too long to start, " | 133 | xhci_err(xhci, "Host took too long to start, " |
131 | "waited %u microseconds.\n", | 134 | "waited %u microseconds.\n", |
132 | XHCI_MAX_HALT_USEC); | 135 | XHCI_MAX_HALT_USEC); |
136 | if (!ret) | ||
137 | xhci->xhc_state &= ~XHCI_STATE_HALTED; | ||
133 | return ret; | 138 | return ret; |
134 | } | 139 | } |
135 | 140 | ||
136 | /* | 141 | /* |
137 | * Reset a halted HC, and set the internal HC state to HC_STATE_HALT. | 142 | * Reset a halted HC. |
138 | * | 143 | * |
139 | * This resets pipelines, timers, counters, state machines, etc. | 144 | * This resets pipelines, timers, counters, state machines, etc. |
140 | * Transactions will be terminated immediately, and operational registers | 145 | * Transactions will be terminated immediately, and operational registers |
@@ -156,8 +161,6 @@ int xhci_reset(struct xhci_hcd *xhci) | |||
156 | command = xhci_readl(xhci, &xhci->op_regs->command); | 161 | command = xhci_readl(xhci, &xhci->op_regs->command); |
157 | command |= CMD_RESET; | 162 | command |= CMD_RESET; |
158 | xhci_writel(xhci, command, &xhci->op_regs->command); | 163 | xhci_writel(xhci, command, &xhci->op_regs->command); |
159 | /* XXX: Why does EHCI set this here? Shouldn't other code do this? */ | ||
160 | xhci_to_hcd(xhci)->state = HC_STATE_HALT; | ||
161 | 164 | ||
162 | ret = handshake(xhci, &xhci->op_regs->command, | 165 | ret = handshake(xhci, &xhci->op_regs->command, |
163 | CMD_RESET, 0, 250 * 1000); | 166 | CMD_RESET, 0, 250 * 1000); |
@@ -350,7 +353,6 @@ static void xhci_event_ring_work(unsigned long arg) | |||
350 | 353 | ||
351 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); | 354 | temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); |
352 | xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); | 355 | xhci_dbg(xhci, "ir_set 0 pending = 0x%x\n", temp); |
353 | xhci_dbg(xhci, "No-op commands handled = %d\n", xhci->noops_handled); | ||
354 | xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); | 356 | xhci_dbg(xhci, "HC error bitmask = 0x%x\n", xhci->error_bitmask); |
355 | xhci->error_bitmask = 0; | 357 | xhci->error_bitmask = 0; |
356 | xhci_dbg(xhci, "Event ring:\n"); | 358 | xhci_dbg(xhci, "Event ring:\n"); |
@@ -370,10 +372,6 @@ static void xhci_event_ring_work(unsigned long arg) | |||
370 | xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]); | 372 | xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]); |
371 | } | 373 | } |
372 | } | 374 | } |
373 | |||
374 | if (xhci->noops_submitted != NUM_TEST_NOOPS) | ||
375 | if (xhci_setup_one_noop(xhci)) | ||
376 | xhci_ring_cmd_db(xhci); | ||
377 | spin_unlock_irqrestore(&xhci->lock, flags); | 375 | spin_unlock_irqrestore(&xhci->lock, flags); |
378 | 376 | ||
379 | if (!xhci->zombie) | 377 | if (!xhci->zombie) |
@@ -383,6 +381,21 @@ static void xhci_event_ring_work(unsigned long arg) | |||
383 | } | 381 | } |
384 | #endif | 382 | #endif |
385 | 383 | ||
384 | static int xhci_run_finished(struct xhci_hcd *xhci) | ||
385 | { | ||
386 | if (xhci_start(xhci)) { | ||
387 | xhci_halt(xhci); | ||
388 | return -ENODEV; | ||
389 | } | ||
390 | xhci->shared_hcd->state = HC_STATE_RUNNING; | ||
391 | |||
392 | if (xhci->quirks & XHCI_NEC_HOST) | ||
393 | xhci_ring_cmd_db(xhci); | ||
394 | |||
395 | xhci_dbg(xhci, "Finished xhci_run for USB3 roothub\n"); | ||
396 | return 0; | ||
397 | } | ||
398 | |||
386 | /* | 399 | /* |
387 | * Start the HC after it was halted. | 400 | * Start the HC after it was halted. |
388 | * | 401 | * |
@@ -402,9 +415,14 @@ int xhci_run(struct usb_hcd *hcd) | |||
402 | u32 ret; | 415 | u32 ret; |
403 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 416 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
404 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 417 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
405 | void (*doorbell)(struct xhci_hcd *) = NULL; | 418 | |
419 | /* Start the xHCI host controller running only after the USB 2.0 roothub | ||
420 | * is setup. | ||
421 | */ | ||
406 | 422 | ||
407 | hcd->uses_new_polling = 1; | 423 | hcd->uses_new_polling = 1; |
424 | if (!usb_hcd_is_primary_hcd(hcd)) | ||
425 | return xhci_run_finished(xhci); | ||
408 | 426 | ||
409 | xhci_dbg(xhci, "xhci_run\n"); | 427 | xhci_dbg(xhci, "xhci_run\n"); |
410 | /* unregister the legacy interrupt */ | 428 | /* unregister the legacy interrupt */ |
@@ -461,7 +479,6 @@ int xhci_run(struct usb_hcd *hcd) | |||
461 | xhci_writel(xhci, temp, &xhci->ir_set->irq_control); | 479 | xhci_writel(xhci, temp, &xhci->ir_set->irq_control); |
462 | 480 | ||
463 | /* Set the HCD state before we enable the irqs */ | 481 | /* Set the HCD state before we enable the irqs */ |
464 | hcd->state = HC_STATE_RUNNING; | ||
465 | temp = xhci_readl(xhci, &xhci->op_regs->command); | 482 | temp = xhci_readl(xhci, &xhci->op_regs->command); |
466 | temp |= (CMD_EIE); | 483 | temp |= (CMD_EIE); |
467 | xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", | 484 | xhci_dbg(xhci, "// Enable interrupts, cmd = 0x%x.\n", |
@@ -475,24 +492,27 @@ int xhci_run(struct usb_hcd *hcd) | |||
475 | &xhci->ir_set->irq_pending); | 492 | &xhci->ir_set->irq_pending); |
476 | xhci_print_ir_set(xhci, 0); | 493 | xhci_print_ir_set(xhci, 0); |
477 | 494 | ||
478 | if (NUM_TEST_NOOPS > 0) | ||
479 | doorbell = xhci_setup_one_noop(xhci); | ||
480 | if (xhci->quirks & XHCI_NEC_HOST) | 495 | if (xhci->quirks & XHCI_NEC_HOST) |
481 | xhci_queue_vendor_command(xhci, 0, 0, 0, | 496 | xhci_queue_vendor_command(xhci, 0, 0, 0, |
482 | TRB_TYPE(TRB_NEC_GET_FW)); | 497 | TRB_TYPE(TRB_NEC_GET_FW)); |
483 | 498 | ||
484 | if (xhci_start(xhci)) { | 499 | xhci_dbg(xhci, "Finished xhci_run for USB2 roothub\n"); |
485 | xhci_halt(xhci); | 500 | return 0; |
486 | return -ENODEV; | 501 | } |
487 | } | ||
488 | 502 | ||
489 | if (doorbell) | 503 | static void xhci_only_stop_hcd(struct usb_hcd *hcd) |
490 | (*doorbell)(xhci); | 504 | { |
491 | if (xhci->quirks & XHCI_NEC_HOST) | 505 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
492 | xhci_ring_cmd_db(xhci); | ||
493 | 506 | ||
494 | xhci_dbg(xhci, "Finished xhci_run\n"); | 507 | spin_lock_irq(&xhci->lock); |
495 | return 0; | 508 | xhci_halt(xhci); |
509 | |||
510 | /* The shared_hcd is going to be deallocated shortly (the USB core only | ||
511 | * calls this function when allocation fails in usb_add_hcd(), or | ||
512 | * usb_remove_hcd() is called). So we need to unset xHCI's pointer. | ||
513 | */ | ||
514 | xhci->shared_hcd = NULL; | ||
515 | spin_unlock_irq(&xhci->lock); | ||
496 | } | 516 | } |
497 | 517 | ||
498 | /* | 518 | /* |
@@ -509,7 +529,15 @@ void xhci_stop(struct usb_hcd *hcd) | |||
509 | u32 temp; | 529 | u32 temp; |
510 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 530 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
511 | 531 | ||
532 | if (!usb_hcd_is_primary_hcd(hcd)) { | ||
533 | xhci_only_stop_hcd(xhci->shared_hcd); | ||
534 | return; | ||
535 | } | ||
536 | |||
512 | spin_lock_irq(&xhci->lock); | 537 | spin_lock_irq(&xhci->lock); |
538 | /* Make sure the xHC is halted for a USB3 roothub | ||
539 | * (xhci_stop() could be called as part of failed init). | ||
540 | */ | ||
513 | xhci_halt(xhci); | 541 | xhci_halt(xhci); |
514 | xhci_reset(xhci); | 542 | xhci_reset(xhci); |
515 | spin_unlock_irq(&xhci->lock); | 543 | spin_unlock_irq(&xhci->lock); |
@@ -542,6 +570,8 @@ void xhci_stop(struct usb_hcd *hcd) | |||
542 | * This is called when the machine is rebooting or halting. We assume that the | 570 | * This is called when the machine is rebooting or halting. We assume that the |
543 | * machine will be powered off, and the HC's internal state will be reset. | 571 | * machine will be powered off, and the HC's internal state will be reset. |
544 | * Don't bother to free memory. | 572 | * Don't bother to free memory. |
573 | * | ||
574 | * This will only ever be called with the main usb_hcd (the USB3 roothub). | ||
545 | */ | 575 | */ |
546 | void xhci_shutdown(struct usb_hcd *hcd) | 576 | void xhci_shutdown(struct usb_hcd *hcd) |
547 | { | 577 | { |
@@ -657,6 +687,7 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
657 | 687 | ||
658 | spin_lock_irq(&xhci->lock); | 688 | spin_lock_irq(&xhci->lock); |
659 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 689 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
690 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); | ||
660 | /* step 1: stop endpoint */ | 691 | /* step 1: stop endpoint */ |
661 | /* skipped assuming that port suspend has done */ | 692 | /* skipped assuming that port suspend has done */ |
662 | 693 | ||
@@ -706,10 +737,15 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
706 | { | 737 | { |
707 | u32 command, temp = 0; | 738 | u32 command, temp = 0; |
708 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 739 | struct usb_hcd *hcd = xhci_to_hcd(xhci); |
709 | int old_state, retval; | 740 | struct usb_hcd *secondary_hcd; |
741 | int retval; | ||
710 | 742 | ||
711 | old_state = hcd->state; | 743 | /* Wait a bit if either of the roothubs need to settle from the |
712 | if (time_before(jiffies, xhci->next_statechange)) | 744 | * transistion into bus suspend. |
745 | */ | ||
746 | if (time_before(jiffies, xhci->bus_state[0].next_statechange) || | ||
747 | time_before(jiffies, | ||
748 | xhci->bus_state[1].next_statechange)) | ||
713 | msleep(100); | 749 | msleep(100); |
714 | 750 | ||
715 | spin_lock_irq(&xhci->lock); | 751 | spin_lock_irq(&xhci->lock); |
@@ -762,16 +798,34 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
762 | xhci_dbg(xhci, "xhci_stop completed - status = %x\n", | 798 | xhci_dbg(xhci, "xhci_stop completed - status = %x\n", |
763 | xhci_readl(xhci, &xhci->op_regs->status)); | 799 | xhci_readl(xhci, &xhci->op_regs->status)); |
764 | 800 | ||
765 | xhci_dbg(xhci, "Initialize the HCD\n"); | 801 | /* USB core calls the PCI reinit and start functions twice: |
766 | retval = xhci_init(hcd); | 802 | * first with the primary HCD, and then with the secondary HCD. |
803 | * If we don't do the same, the host will never be started. | ||
804 | */ | ||
805 | if (!usb_hcd_is_primary_hcd(hcd)) | ||
806 | secondary_hcd = hcd; | ||
807 | else | ||
808 | secondary_hcd = xhci->shared_hcd; | ||
809 | |||
810 | xhci_dbg(xhci, "Initialize the xhci_hcd\n"); | ||
811 | retval = xhci_init(hcd->primary_hcd); | ||
767 | if (retval) | 812 | if (retval) |
768 | return retval; | 813 | return retval; |
814 | xhci_dbg(xhci, "Start the primary HCD\n"); | ||
815 | retval = xhci_run(hcd->primary_hcd); | ||
816 | if (retval) | ||
817 | goto failed_restart; | ||
769 | 818 | ||
770 | xhci_dbg(xhci, "Start the HCD\n"); | 819 | xhci_dbg(xhci, "Start the secondary HCD\n"); |
771 | retval = xhci_run(hcd); | 820 | retval = xhci_run(secondary_hcd); |
772 | if (!retval) | 821 | if (!retval) { |
773 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 822 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
823 | set_bit(HCD_FLAG_HW_ACCESSIBLE, | ||
824 | &xhci->shared_hcd->flags); | ||
825 | } | ||
826 | failed_restart: | ||
774 | hcd->state = HC_STATE_SUSPENDED; | 827 | hcd->state = HC_STATE_SUSPENDED; |
828 | xhci->shared_hcd->state = HC_STATE_SUSPENDED; | ||
775 | return retval; | 829 | return retval; |
776 | } | 830 | } |
777 | 831 | ||
@@ -792,10 +846,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
792 | */ | 846 | */ |
793 | 847 | ||
794 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 848 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
795 | if (!hibernated) | 849 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); |
796 | hcd->state = old_state; | ||
797 | else | ||
798 | hcd->state = HC_STATE_SUSPENDED; | ||
799 | 850 | ||
800 | spin_unlock_irq(&xhci->lock); | 851 | spin_unlock_irq(&xhci->lock); |
801 | return 0; | 852 | return 0; |
@@ -1167,13 +1218,13 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) | |||
1167 | if (ret || !urb->hcpriv) | 1218 | if (ret || !urb->hcpriv) |
1168 | goto done; | 1219 | goto done; |
1169 | temp = xhci_readl(xhci, &xhci->op_regs->status); | 1220 | temp = xhci_readl(xhci, &xhci->op_regs->status); |
1170 | if (temp == 0xffffffff) { | 1221 | if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_HALTED)) { |
1171 | xhci_dbg(xhci, "HW died, freeing TD.\n"); | 1222 | xhci_dbg(xhci, "HW died, freeing TD.\n"); |
1172 | urb_priv = urb->hcpriv; | 1223 | urb_priv = urb->hcpriv; |
1173 | 1224 | ||
1174 | usb_hcd_unlink_urb_from_ep(hcd, urb); | 1225 | usb_hcd_unlink_urb_from_ep(hcd, urb); |
1175 | spin_unlock_irqrestore(&xhci->lock, flags); | 1226 | spin_unlock_irqrestore(&xhci->lock, flags); |
1176 | usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); | 1227 | usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN); |
1177 | xhci_urb_free_priv(xhci, urb_priv); | 1228 | xhci_urb_free_priv(xhci, urb_priv); |
1178 | return ret; | 1229 | return ret; |
1179 | } | 1230 | } |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 7f127df6dd55..711de253bc0f 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
@@ -644,6 +644,9 @@ struct xhci_ep_ctx { | |||
644 | #define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) | 644 | #define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) |
645 | #define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) | 645 | #define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) |
646 | 646 | ||
647 | /* deq bitmasks */ | ||
648 | #define EP_CTX_CYCLE_MASK (1 << 0) | ||
649 | |||
647 | 650 | ||
648 | /** | 651 | /** |
649 | * struct xhci_input_control_context | 652 | * struct xhci_input_control_context |
@@ -746,6 +749,12 @@ struct xhci_virt_ep { | |||
746 | struct timer_list stop_cmd_timer; | 749 | struct timer_list stop_cmd_timer; |
747 | int stop_cmds_pending; | 750 | int stop_cmds_pending; |
748 | struct xhci_hcd *xhci; | 751 | struct xhci_hcd *xhci; |
752 | /* Dequeue pointer and dequeue segment for a submitted Set TR Dequeue | ||
753 | * command. We'll need to update the ring's dequeue segment and dequeue | ||
754 | * pointer after the command completes. | ||
755 | */ | ||
756 | struct xhci_segment *queued_deq_seg; | ||
757 | union xhci_trb *queued_deq_ptr; | ||
749 | /* | 758 | /* |
750 | * Sometimes the xHC can not process isochronous endpoint ring quickly | 759 | * Sometimes the xHC can not process isochronous endpoint ring quickly |
751 | * enough, and it will miss some isoc tds on the ring and generate | 760 | * enough, and it will miss some isoc tds on the ring and generate |
@@ -1161,8 +1170,29 @@ struct s3_save { | |||
1161 | u64 erst_dequeue; | 1170 | u64 erst_dequeue; |
1162 | }; | 1171 | }; |
1163 | 1172 | ||
1173 | struct xhci_bus_state { | ||
1174 | unsigned long bus_suspended; | ||
1175 | unsigned long next_statechange; | ||
1176 | |||
1177 | /* Port suspend arrays are indexed by the portnum of the fake roothub */ | ||
1178 | /* ports suspend status arrays - max 31 ports for USB2, 15 for USB3 */ | ||
1179 | u32 port_c_suspend; | ||
1180 | u32 suspended_ports; | ||
1181 | unsigned long resume_done[USB_MAXCHILDREN]; | ||
1182 | }; | ||
1183 | |||
1184 | static inline unsigned int hcd_index(struct usb_hcd *hcd) | ||
1185 | { | ||
1186 | if (hcd->speed == HCD_USB3) | ||
1187 | return 0; | ||
1188 | else | ||
1189 | return 1; | ||
1190 | } | ||
1191 | |||
1164 | /* There is one ehci_hci structure per controller */ | 1192 | /* There is one ehci_hci structure per controller */ |
1165 | struct xhci_hcd { | 1193 | struct xhci_hcd { |
1194 | struct usb_hcd *main_hcd; | ||
1195 | struct usb_hcd *shared_hcd; | ||
1166 | /* glue to PCI and HCD framework */ | 1196 | /* glue to PCI and HCD framework */ |
1167 | struct xhci_cap_regs __iomem *cap_regs; | 1197 | struct xhci_cap_regs __iomem *cap_regs; |
1168 | struct xhci_op_regs __iomem *op_regs; | 1198 | struct xhci_op_regs __iomem *op_regs; |
@@ -1224,9 +1254,6 @@ struct xhci_hcd { | |||
1224 | /* Host controller watchdog timer structures */ | 1254 | /* Host controller watchdog timer structures */ |
1225 | unsigned int xhc_state; | 1255 | unsigned int xhc_state; |
1226 | 1256 | ||
1227 | unsigned long bus_suspended; | ||
1228 | unsigned long next_statechange; | ||
1229 | |||
1230 | u32 command; | 1257 | u32 command; |
1231 | struct s3_save s3; | 1258 | struct s3_save s3; |
1232 | /* Host controller is dying - not responding to commands. "I'm not dead yet!" | 1259 | /* Host controller is dying - not responding to commands. "I'm not dead yet!" |
@@ -1242,18 +1269,15 @@ struct xhci_hcd { | |||
1242 | * There are no reports of xHCI host controllers that display this issue. | 1269 | * There are no reports of xHCI host controllers that display this issue. |
1243 | */ | 1270 | */ |
1244 | #define XHCI_STATE_DYING (1 << 0) | 1271 | #define XHCI_STATE_DYING (1 << 0) |
1272 | #define XHCI_STATE_HALTED (1 << 1) | ||
1245 | /* Statistics */ | 1273 | /* Statistics */ |
1246 | int noops_submitted; | ||
1247 | int noops_handled; | ||
1248 | int error_bitmask; | 1274 | int error_bitmask; |
1249 | unsigned int quirks; | 1275 | unsigned int quirks; |
1250 | #define XHCI_LINK_TRB_QUIRK (1 << 0) | 1276 | #define XHCI_LINK_TRB_QUIRK (1 << 0) |
1251 | #define XHCI_RESET_EP_QUIRK (1 << 1) | 1277 | #define XHCI_RESET_EP_QUIRK (1 << 1) |
1252 | #define XHCI_NEC_HOST (1 << 2) | 1278 | #define XHCI_NEC_HOST (1 << 2) |
1253 | u32 port_c_suspend[8]; /* port suspend change*/ | 1279 | /* There are two roothubs to keep track of bus suspend info for */ |
1254 | u32 suspended_ports[8]; /* which ports are | 1280 | struct xhci_bus_state bus_state[2]; |
1255 | suspended */ | ||
1256 | unsigned long resume_done[MAX_HC_PORTS]; | ||
1257 | /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */ | 1281 | /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */ |
1258 | u8 *port_array; | 1282 | u8 *port_array; |
1259 | /* Array of pointers to USB 3.0 PORTSC registers */ | 1283 | /* Array of pointers to USB 3.0 PORTSC registers */ |
@@ -1264,18 +1288,15 @@ struct xhci_hcd { | |||
1264 | unsigned int num_usb2_ports; | 1288 | unsigned int num_usb2_ports; |
1265 | }; | 1289 | }; |
1266 | 1290 | ||
1267 | /* For testing purposes */ | ||
1268 | #define NUM_TEST_NOOPS 0 | ||
1269 | |||
1270 | /* convert between an HCD pointer and the corresponding EHCI_HCD */ | 1291 | /* convert between an HCD pointer and the corresponding EHCI_HCD */ |
1271 | static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd) | 1292 | static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd) |
1272 | { | 1293 | { |
1273 | return (struct xhci_hcd *) (hcd->hcd_priv); | 1294 | return *((struct xhci_hcd **) (hcd->hcd_priv)); |
1274 | } | 1295 | } |
1275 | 1296 | ||
1276 | static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci) | 1297 | static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci) |
1277 | { | 1298 | { |
1278 | return container_of((void *) xhci, struct usb_hcd, hcd_priv); | 1299 | return xhci->main_hcd; |
1279 | } | 1300 | } |
1280 | 1301 | ||
1281 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING | 1302 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING |
@@ -1471,7 +1492,6 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg, | |||
1471 | dma_addr_t suspect_dma); | 1492 | dma_addr_t suspect_dma); |
1472 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); | 1493 | int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); |
1473 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); | 1494 | void xhci_ring_cmd_db(struct xhci_hcd *xhci); |
1474 | void *xhci_setup_one_noop(struct xhci_hcd *xhci); | ||
1475 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); | 1495 | int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); |
1476 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, | 1496 | int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, |
1477 | u32 slot_id); | 1497 | u32 slot_id); |
@@ -1525,7 +1545,8 @@ int xhci_bus_resume(struct usb_hcd *hcd); | |||
1525 | #endif /* CONFIG_PM */ | 1545 | #endif /* CONFIG_PM */ |
1526 | 1546 | ||
1527 | u32 xhci_port_state_to_neutral(u32 state); | 1547 | u32 xhci_port_state_to_neutral(u32 state); |
1528 | int xhci_find_slot_id_by_port(struct xhci_hcd *xhci, u16 port); | 1548 | int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, |
1549 | u16 port); | ||
1529 | void xhci_ring_device(struct xhci_hcd *xhci, int slot_id); | 1550 | void xhci_ring_device(struct xhci_hcd *xhci, int slot_id); |
1530 | 1551 | ||
1531 | /* xHCI contexts */ | 1552 | /* xHCI contexts */ |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index a35b427c0bac..388cc128072a 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -83,6 +83,8 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test) | |||
83 | #define WARNING(tdev, fmt, args...) \ | 83 | #define WARNING(tdev, fmt, args...) \ |
84 | dev_warn(&(tdev)->intf->dev , fmt , ## args) | 84 | dev_warn(&(tdev)->intf->dev , fmt , ## args) |
85 | 85 | ||
86 | #define GUARD_BYTE 0xA5 | ||
87 | |||
86 | /*-------------------------------------------------------------------------*/ | 88 | /*-------------------------------------------------------------------------*/ |
87 | 89 | ||
88 | static int | 90 | static int |
@@ -186,11 +188,12 @@ static void simple_callback(struct urb *urb) | |||
186 | complete(urb->context); | 188 | complete(urb->context); |
187 | } | 189 | } |
188 | 190 | ||
189 | static struct urb *simple_alloc_urb( | 191 | static struct urb *usbtest_alloc_urb( |
190 | struct usb_device *udev, | 192 | struct usb_device *udev, |
191 | int pipe, | 193 | int pipe, |
192 | unsigned long bytes | 194 | unsigned long bytes, |
193 | ) | 195 | unsigned transfer_flags, |
196 | unsigned offset) | ||
194 | { | 197 | { |
195 | struct urb *urb; | 198 | struct urb *urb; |
196 | 199 | ||
@@ -201,19 +204,46 @@ static struct urb *simple_alloc_urb( | |||
201 | urb->interval = (udev->speed == USB_SPEED_HIGH) | 204 | urb->interval = (udev->speed == USB_SPEED_HIGH) |
202 | ? (INTERRUPT_RATE << 3) | 205 | ? (INTERRUPT_RATE << 3) |
203 | : INTERRUPT_RATE; | 206 | : INTERRUPT_RATE; |
204 | urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; | 207 | urb->transfer_flags = transfer_flags; |
205 | if (usb_pipein(pipe)) | 208 | if (usb_pipein(pipe)) |
206 | urb->transfer_flags |= URB_SHORT_NOT_OK; | 209 | urb->transfer_flags |= URB_SHORT_NOT_OK; |
207 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes, GFP_KERNEL, | 210 | |
208 | &urb->transfer_dma); | 211 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) |
212 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, | ||
213 | GFP_KERNEL, &urb->transfer_dma); | ||
214 | else | ||
215 | urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL); | ||
216 | |||
209 | if (!urb->transfer_buffer) { | 217 | if (!urb->transfer_buffer) { |
210 | usb_free_urb(urb); | 218 | usb_free_urb(urb); |
211 | urb = NULL; | 219 | return NULL; |
212 | } else | 220 | } |
213 | memset(urb->transfer_buffer, 0, bytes); | 221 | |
222 | /* To test unaligned transfers add an offset and fill the | ||
223 | unused memory with a guard value */ | ||
224 | if (offset) { | ||
225 | memset(urb->transfer_buffer, GUARD_BYTE, offset); | ||
226 | urb->transfer_buffer += offset; | ||
227 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) | ||
228 | urb->transfer_dma += offset; | ||
229 | } | ||
230 | |||
231 | /* For inbound transfers use guard byte so that test fails if | ||
232 | data not correctly copied */ | ||
233 | memset(urb->transfer_buffer, | ||
234 | usb_pipein(urb->pipe) ? GUARD_BYTE : 0, | ||
235 | bytes); | ||
214 | return urb; | 236 | return urb; |
215 | } | 237 | } |
216 | 238 | ||
239 | static struct urb *simple_alloc_urb( | ||
240 | struct usb_device *udev, | ||
241 | int pipe, | ||
242 | unsigned long bytes) | ||
243 | { | ||
244 | return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0); | ||
245 | } | ||
246 | |||
217 | static unsigned pattern; | 247 | static unsigned pattern; |
218 | static unsigned mod_pattern; | 248 | static unsigned mod_pattern; |
219 | module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); | 249 | module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); |
@@ -238,13 +268,38 @@ static inline void simple_fill_buf(struct urb *urb) | |||
238 | } | 268 | } |
239 | } | 269 | } |
240 | 270 | ||
241 | static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) | 271 | static inline unsigned buffer_offset(void *buf) |
272 | { | ||
273 | return (unsigned)buf & (ARCH_KMALLOC_MINALIGN - 1); | ||
274 | } | ||
275 | |||
276 | static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb) | ||
277 | { | ||
278 | u8 *buf = urb->transfer_buffer; | ||
279 | u8 *guard = buf - buffer_offset(buf); | ||
280 | unsigned i; | ||
281 | |||
282 | for (i = 0; guard < buf; i++, guard++) { | ||
283 | if (*guard != GUARD_BYTE) { | ||
284 | ERROR(tdev, "guard byte[%d] %d (not %d)\n", | ||
285 | i, *guard, GUARD_BYTE); | ||
286 | return -EINVAL; | ||
287 | } | ||
288 | } | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) | ||
242 | { | 293 | { |
243 | unsigned i; | 294 | unsigned i; |
244 | u8 expected; | 295 | u8 expected; |
245 | u8 *buf = urb->transfer_buffer; | 296 | u8 *buf = urb->transfer_buffer; |
246 | unsigned len = urb->actual_length; | 297 | unsigned len = urb->actual_length; |
247 | 298 | ||
299 | int ret = check_guard_bytes(tdev, urb); | ||
300 | if (ret) | ||
301 | return ret; | ||
302 | |||
248 | for (i = 0; i < len; i++, buf++) { | 303 | for (i = 0; i < len; i++, buf++) { |
249 | switch (pattern) { | 304 | switch (pattern) { |
250 | /* all-zeroes has no synchronization issues */ | 305 | /* all-zeroes has no synchronization issues */ |
@@ -274,8 +329,16 @@ static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) | |||
274 | 329 | ||
275 | static void simple_free_urb(struct urb *urb) | 330 | static void simple_free_urb(struct urb *urb) |
276 | { | 331 | { |
277 | usb_free_coherent(urb->dev, urb->transfer_buffer_length, | 332 | unsigned offset = buffer_offset(urb->transfer_buffer); |
278 | urb->transfer_buffer, urb->transfer_dma); | 333 | |
334 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) | ||
335 | usb_free_coherent( | ||
336 | urb->dev, | ||
337 | urb->transfer_buffer_length + offset, | ||
338 | urb->transfer_buffer - offset, | ||
339 | urb->transfer_dma - offset); | ||
340 | else | ||
341 | kfree(urb->transfer_buffer - offset); | ||
279 | usb_free_urb(urb); | 342 | usb_free_urb(urb); |
280 | } | 343 | } |
281 | 344 | ||
@@ -1256,7 +1319,7 @@ done: | |||
1256 | * try whatever we're told to try. | 1319 | * try whatever we're told to try. |
1257 | */ | 1320 | */ |
1258 | static int ctrl_out(struct usbtest_dev *dev, | 1321 | static int ctrl_out(struct usbtest_dev *dev, |
1259 | unsigned count, unsigned length, unsigned vary) | 1322 | unsigned count, unsigned length, unsigned vary, unsigned offset) |
1260 | { | 1323 | { |
1261 | unsigned i, j, len; | 1324 | unsigned i, j, len; |
1262 | int retval; | 1325 | int retval; |
@@ -1267,10 +1330,11 @@ static int ctrl_out(struct usbtest_dev *dev, | |||
1267 | if (length < 1 || length > 0xffff || vary >= length) | 1330 | if (length < 1 || length > 0xffff || vary >= length) |
1268 | return -EINVAL; | 1331 | return -EINVAL; |
1269 | 1332 | ||
1270 | buf = kmalloc(length, GFP_KERNEL); | 1333 | buf = kmalloc(length + offset, GFP_KERNEL); |
1271 | if (!buf) | 1334 | if (!buf) |
1272 | return -ENOMEM; | 1335 | return -ENOMEM; |
1273 | 1336 | ||
1337 | buf += offset; | ||
1274 | udev = testdev_to_usbdev(dev); | 1338 | udev = testdev_to_usbdev(dev); |
1275 | len = length; | 1339 | len = length; |
1276 | retval = 0; | 1340 | retval = 0; |
@@ -1337,7 +1401,7 @@ static int ctrl_out(struct usbtest_dev *dev, | |||
1337 | ERROR(dev, "ctrl_out %s failed, code %d, count %d\n", | 1401 | ERROR(dev, "ctrl_out %s failed, code %d, count %d\n", |
1338 | what, retval, i); | 1402 | what, retval, i); |
1339 | 1403 | ||
1340 | kfree(buf); | 1404 | kfree(buf - offset); |
1341 | return retval; | 1405 | return retval; |
1342 | } | 1406 | } |
1343 | 1407 | ||
@@ -1373,6 +1437,8 @@ static void iso_callback(struct urb *urb) | |||
1373 | ctx->errors += urb->number_of_packets; | 1437 | ctx->errors += urb->number_of_packets; |
1374 | else if (urb->actual_length != urb->transfer_buffer_length) | 1438 | else if (urb->actual_length != urb->transfer_buffer_length) |
1375 | ctx->errors++; | 1439 | ctx->errors++; |
1440 | else if (check_guard_bytes(ctx->dev, urb) != 0) | ||
1441 | ctx->errors++; | ||
1376 | 1442 | ||
1377 | if (urb->status == 0 && ctx->count > (ctx->pending - 1) | 1443 | if (urb->status == 0 && ctx->count > (ctx->pending - 1) |
1378 | && !ctx->submit_error) { | 1444 | && !ctx->submit_error) { |
@@ -1408,7 +1474,8 @@ static struct urb *iso_alloc_urb( | |||
1408 | struct usb_device *udev, | 1474 | struct usb_device *udev, |
1409 | int pipe, | 1475 | int pipe, |
1410 | struct usb_endpoint_descriptor *desc, | 1476 | struct usb_endpoint_descriptor *desc, |
1411 | long bytes | 1477 | long bytes, |
1478 | unsigned offset | ||
1412 | ) | 1479 | ) |
1413 | { | 1480 | { |
1414 | struct urb *urb; | 1481 | struct urb *urb; |
@@ -1428,13 +1495,24 @@ static struct urb *iso_alloc_urb( | |||
1428 | 1495 | ||
1429 | urb->number_of_packets = packets; | 1496 | urb->number_of_packets = packets; |
1430 | urb->transfer_buffer_length = bytes; | 1497 | urb->transfer_buffer_length = bytes; |
1431 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes, GFP_KERNEL, | 1498 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, |
1432 | &urb->transfer_dma); | 1499 | GFP_KERNEL, |
1500 | &urb->transfer_dma); | ||
1433 | if (!urb->transfer_buffer) { | 1501 | if (!urb->transfer_buffer) { |
1434 | usb_free_urb(urb); | 1502 | usb_free_urb(urb); |
1435 | return NULL; | 1503 | return NULL; |
1436 | } | 1504 | } |
1437 | memset(urb->transfer_buffer, 0, bytes); | 1505 | if (offset) { |
1506 | memset(urb->transfer_buffer, GUARD_BYTE, offset); | ||
1507 | urb->transfer_buffer += offset; | ||
1508 | urb->transfer_dma += offset; | ||
1509 | } | ||
1510 | /* For inbound transfers use guard byte so that test fails if | ||
1511 | data not correctly copied */ | ||
1512 | memset(urb->transfer_buffer, | ||
1513 | usb_pipein(urb->pipe) ? GUARD_BYTE : 0, | ||
1514 | bytes); | ||
1515 | |||
1438 | for (i = 0; i < packets; i++) { | 1516 | for (i = 0; i < packets; i++) { |
1439 | /* here, only the last packet will be short */ | 1517 | /* here, only the last packet will be short */ |
1440 | urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp); | 1518 | urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp); |
@@ -1452,7 +1530,7 @@ static struct urb *iso_alloc_urb( | |||
1452 | 1530 | ||
1453 | static int | 1531 | static int |
1454 | test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, | 1532 | test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, |
1455 | int pipe, struct usb_endpoint_descriptor *desc) | 1533 | int pipe, struct usb_endpoint_descriptor *desc, unsigned offset) |
1456 | { | 1534 | { |
1457 | struct iso_context context; | 1535 | struct iso_context context; |
1458 | struct usb_device *udev; | 1536 | struct usb_device *udev; |
@@ -1480,7 +1558,7 @@ test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, | |||
1480 | 1558 | ||
1481 | for (i = 0; i < param->sglen; i++) { | 1559 | for (i = 0; i < param->sglen; i++) { |
1482 | urbs[i] = iso_alloc_urb(udev, pipe, desc, | 1560 | urbs[i] = iso_alloc_urb(udev, pipe, desc, |
1483 | param->length); | 1561 | param->length, offset); |
1484 | if (!urbs[i]) { | 1562 | if (!urbs[i]) { |
1485 | status = -ENOMEM; | 1563 | status = -ENOMEM; |
1486 | goto fail; | 1564 | goto fail; |
@@ -1542,6 +1620,26 @@ fail: | |||
1542 | return status; | 1620 | return status; |
1543 | } | 1621 | } |
1544 | 1622 | ||
1623 | static int test_unaligned_bulk( | ||
1624 | struct usbtest_dev *tdev, | ||
1625 | int pipe, | ||
1626 | unsigned length, | ||
1627 | int iterations, | ||
1628 | unsigned transfer_flags, | ||
1629 | const char *label) | ||
1630 | { | ||
1631 | int retval; | ||
1632 | struct urb *urb = usbtest_alloc_urb( | ||
1633 | testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1); | ||
1634 | |||
1635 | if (!urb) | ||
1636 | return -ENOMEM; | ||
1637 | |||
1638 | retval = simple_io(tdev, urb, iterations, 0, 0, label); | ||
1639 | simple_free_urb(urb); | ||
1640 | return retval; | ||
1641 | } | ||
1642 | |||
1545 | /*-------------------------------------------------------------------------*/ | 1643 | /*-------------------------------------------------------------------------*/ |
1546 | 1644 | ||
1547 | /* We only have this one interface to user space, through usbfs. | 1645 | /* We only have this one interface to user space, through usbfs. |
@@ -1843,7 +1941,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
1843 | realworld ? 1 : 0, param->length, | 1941 | realworld ? 1 : 0, param->length, |
1844 | param->vary); | 1942 | param->vary); |
1845 | retval = ctrl_out(dev, param->iterations, | 1943 | retval = ctrl_out(dev, param->iterations, |
1846 | param->length, param->vary); | 1944 | param->length, param->vary, 0); |
1847 | break; | 1945 | break; |
1848 | 1946 | ||
1849 | /* iso write tests */ | 1947 | /* iso write tests */ |
@@ -1856,7 +1954,7 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
1856 | param->sglen, param->length); | 1954 | param->sglen, param->length); |
1857 | /* FIRMWARE: iso sink */ | 1955 | /* FIRMWARE: iso sink */ |
1858 | retval = test_iso_queue(dev, param, | 1956 | retval = test_iso_queue(dev, param, |
1859 | dev->out_iso_pipe, dev->iso_out); | 1957 | dev->out_iso_pipe, dev->iso_out, 0); |
1860 | break; | 1958 | break; |
1861 | 1959 | ||
1862 | /* iso read tests */ | 1960 | /* iso read tests */ |
@@ -1869,13 +1967,103 @@ usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) | |||
1869 | param->sglen, param->length); | 1967 | param->sglen, param->length); |
1870 | /* FIRMWARE: iso source */ | 1968 | /* FIRMWARE: iso source */ |
1871 | retval = test_iso_queue(dev, param, | 1969 | retval = test_iso_queue(dev, param, |
1872 | dev->in_iso_pipe, dev->iso_in); | 1970 | dev->in_iso_pipe, dev->iso_in, 0); |
1873 | break; | 1971 | break; |
1874 | 1972 | ||
1875 | /* FIXME unlink from queue (ring with N urbs) */ | 1973 | /* FIXME unlink from queue (ring with N urbs) */ |
1876 | 1974 | ||
1877 | /* FIXME scatterlist cancel (needs helper thread) */ | 1975 | /* FIXME scatterlist cancel (needs helper thread) */ |
1878 | 1976 | ||
1977 | /* Tests for bulk I/O using DMA mapping by core and odd address */ | ||
1978 | case 17: | ||
1979 | if (dev->out_pipe == 0) | ||
1980 | break; | ||
1981 | dev_info(&intf->dev, | ||
1982 | "TEST 17: write odd addr %d bytes %u times core map\n", | ||
1983 | param->length, param->iterations); | ||
1984 | |||
1985 | retval = test_unaligned_bulk( | ||
1986 | dev, dev->out_pipe, | ||
1987 | param->length, param->iterations, | ||
1988 | 0, "test17"); | ||
1989 | break; | ||
1990 | |||
1991 | case 18: | ||
1992 | if (dev->in_pipe == 0) | ||
1993 | break; | ||
1994 | dev_info(&intf->dev, | ||
1995 | "TEST 18: read odd addr %d bytes %u times core map\n", | ||
1996 | param->length, param->iterations); | ||
1997 | |||
1998 | retval = test_unaligned_bulk( | ||
1999 | dev, dev->in_pipe, | ||
2000 | param->length, param->iterations, | ||
2001 | 0, "test18"); | ||
2002 | break; | ||
2003 | |||
2004 | /* Tests for bulk I/O using premapped coherent buffer and odd address */ | ||
2005 | case 19: | ||
2006 | if (dev->out_pipe == 0) | ||
2007 | break; | ||
2008 | dev_info(&intf->dev, | ||
2009 | "TEST 19: write odd addr %d bytes %u times premapped\n", | ||
2010 | param->length, param->iterations); | ||
2011 | |||
2012 | retval = test_unaligned_bulk( | ||
2013 | dev, dev->out_pipe, | ||
2014 | param->length, param->iterations, | ||
2015 | URB_NO_TRANSFER_DMA_MAP, "test19"); | ||
2016 | break; | ||
2017 | |||
2018 | case 20: | ||
2019 | if (dev->in_pipe == 0) | ||
2020 | break; | ||
2021 | dev_info(&intf->dev, | ||
2022 | "TEST 20: read odd addr %d bytes %u times premapped\n", | ||
2023 | param->length, param->iterations); | ||
2024 | |||
2025 | retval = test_unaligned_bulk( | ||
2026 | dev, dev->in_pipe, | ||
2027 | param->length, param->iterations, | ||
2028 | URB_NO_TRANSFER_DMA_MAP, "test20"); | ||
2029 | break; | ||
2030 | |||
2031 | /* control write tests with unaligned buffer */ | ||
2032 | case 21: | ||
2033 | if (!dev->info->ctrl_out) | ||
2034 | break; | ||
2035 | dev_info(&intf->dev, | ||
2036 | "TEST 21: %d ep0out odd addr, %d..%d vary %d\n", | ||
2037 | param->iterations, | ||
2038 | realworld ? 1 : 0, param->length, | ||
2039 | param->vary); | ||
2040 | retval = ctrl_out(dev, param->iterations, | ||
2041 | param->length, param->vary, 1); | ||
2042 | break; | ||
2043 | |||
2044 | /* unaligned iso tests */ | ||
2045 | case 22: | ||
2046 | if (dev->out_iso_pipe == 0 || param->sglen == 0) | ||
2047 | break; | ||
2048 | dev_info(&intf->dev, | ||
2049 | "TEST 22: write %d iso odd, %d entries of %d bytes\n", | ||
2050 | param->iterations, | ||
2051 | param->sglen, param->length); | ||
2052 | retval = test_iso_queue(dev, param, | ||
2053 | dev->out_iso_pipe, dev->iso_out, 1); | ||
2054 | break; | ||
2055 | |||
2056 | case 23: | ||
2057 | if (dev->in_iso_pipe == 0 || param->sglen == 0) | ||
2058 | break; | ||
2059 | dev_info(&intf->dev, | ||
2060 | "TEST 23: read %d iso odd, %d entries of %d bytes\n", | ||
2061 | param->iterations, | ||
2062 | param->sglen, param->length); | ||
2063 | retval = test_iso_queue(dev, param, | ||
2064 | dev->in_iso_pipe, dev->iso_in, 1); | ||
2065 | break; | ||
2066 | |||
1879 | } | 2067 | } |
1880 | do_gettimeofday(¶m->duration); | 2068 | do_gettimeofday(¶m->duration); |
1881 | param->duration.tv_sec -= start.tv_sec; | 2069 | param->duration.tv_sec -= start.tv_sec; |
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index a545d65f6e57..c302e1983c70 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -236,6 +236,9 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, | |||
236 | fp++; | 236 | fp++; |
237 | dp++; | 237 | dp++; |
238 | } | 238 | } |
239 | /* Wasteful, but simple to understand: ISO 'C' is sparse. */ | ||
240 | if (ev_type == 'C') | ||
241 | ep->length = urb->transfer_buffer_length; | ||
239 | } | 242 | } |
240 | 243 | ||
241 | ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); | 244 | ep->setup_flag = mon_text_get_setup(ep, urb, ev_type, rp->r.m_bus); |
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index c292d5c499e7..a914010d9d12 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -1950,31 +1950,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl) | |||
1950 | goto fail0; | 1950 | goto fail0; |
1951 | } | 1951 | } |
1952 | 1952 | ||
1953 | switch (plat->mode) { | ||
1954 | case MUSB_HOST: | ||
1955 | #ifdef CONFIG_USB_MUSB_HDRC_HCD | ||
1956 | break; | ||
1957 | #else | ||
1958 | goto bad_config; | ||
1959 | #endif | ||
1960 | case MUSB_PERIPHERAL: | ||
1961 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | ||
1962 | break; | ||
1963 | #else | ||
1964 | goto bad_config; | ||
1965 | #endif | ||
1966 | case MUSB_OTG: | ||
1967 | #ifdef CONFIG_USB_MUSB_OTG | ||
1968 | break; | ||
1969 | #else | ||
1970 | bad_config: | ||
1971 | #endif | ||
1972 | default: | ||
1973 | dev_err(dev, "incompatible Kconfig role setting\n"); | ||
1974 | status = -EINVAL; | ||
1975 | goto fail0; | ||
1976 | } | ||
1977 | |||
1978 | /* allocate */ | 1953 | /* allocate */ |
1979 | musb = allocate_instance(dev, plat->config, ctrl); | 1954 | musb = allocate_instance(dev, plat->config, ctrl); |
1980 | if (!musb) { | 1955 | if (!musb) { |
@@ -1982,6 +1957,10 @@ bad_config: | |||
1982 | goto fail0; | 1957 | goto fail0; |
1983 | } | 1958 | } |
1984 | 1959 | ||
1960 | pm_runtime_use_autosuspend(musb->controller); | ||
1961 | pm_runtime_set_autosuspend_delay(musb->controller, 200); | ||
1962 | pm_runtime_enable(musb->controller); | ||
1963 | |||
1985 | spin_lock_init(&musb->lock); | 1964 | spin_lock_init(&musb->lock); |
1986 | musb->board_mode = plat->mode; | 1965 | musb->board_mode = plat->mode; |
1987 | musb->board_set_power = plat->set_power; | 1966 | musb->board_set_power = plat->set_power; |
@@ -2117,6 +2096,8 @@ bad_config: | |||
2117 | if (status < 0) | 2096 | if (status < 0) |
2118 | goto fail3; | 2097 | goto fail3; |
2119 | 2098 | ||
2099 | pm_runtime_put(musb->controller); | ||
2100 | |||
2120 | status = musb_init_debugfs(musb); | 2101 | status = musb_init_debugfs(musb); |
2121 | if (status < 0) | 2102 | if (status < 0) |
2122 | goto fail4; | 2103 | goto fail4; |
@@ -2216,9 +2197,11 @@ static int __exit musb_remove(struct platform_device *pdev) | |||
2216 | * - Peripheral mode: peripheral is deactivated (or never-activated) | 2197 | * - Peripheral mode: peripheral is deactivated (or never-activated) |
2217 | * - OTG mode: both roles are deactivated (or never-activated) | 2198 | * - OTG mode: both roles are deactivated (or never-activated) |
2218 | */ | 2199 | */ |
2200 | pm_runtime_get_sync(musb->controller); | ||
2219 | musb_exit_debugfs(musb); | 2201 | musb_exit_debugfs(musb); |
2220 | musb_shutdown(pdev); | 2202 | musb_shutdown(pdev); |
2221 | 2203 | ||
2204 | pm_runtime_put(musb->controller); | ||
2222 | musb_free(musb); | 2205 | musb_free(musb); |
2223 | iounmap(ctrl_base); | 2206 | iounmap(ctrl_base); |
2224 | device_init_wakeup(&pdev->dev, 0); | 2207 | device_init_wakeup(&pdev->dev, 0); |
@@ -2404,9 +2387,41 @@ static int musb_resume_noirq(struct device *dev) | |||
2404 | return 0; | 2387 | return 0; |
2405 | } | 2388 | } |
2406 | 2389 | ||
2390 | static int musb_runtime_suspend(struct device *dev) | ||
2391 | { | ||
2392 | struct musb *musb = dev_to_musb(dev); | ||
2393 | |||
2394 | musb_save_context(musb); | ||
2395 | |||
2396 | return 0; | ||
2397 | } | ||
2398 | |||
2399 | static int musb_runtime_resume(struct device *dev) | ||
2400 | { | ||
2401 | struct musb *musb = dev_to_musb(dev); | ||
2402 | static int first = 1; | ||
2403 | |||
2404 | /* | ||
2405 | * When pm_runtime_get_sync called for the first time in driver | ||
2406 | * init, some of the structure is still not initialized which is | ||
2407 | * used in restore function. But clock needs to be | ||
2408 | * enabled before any register access, so | ||
2409 | * pm_runtime_get_sync has to be called. | ||
2410 | * Also context restore without save does not make | ||
2411 | * any sense | ||
2412 | */ | ||
2413 | if (!first) | ||
2414 | musb_restore_context(musb); | ||
2415 | first = 0; | ||
2416 | |||
2417 | return 0; | ||
2418 | } | ||
2419 | |||
2407 | static const struct dev_pm_ops musb_dev_pm_ops = { | 2420 | static const struct dev_pm_ops musb_dev_pm_ops = { |
2408 | .suspend = musb_suspend, | 2421 | .suspend = musb_suspend, |
2409 | .resume_noirq = musb_resume_noirq, | 2422 | .resume_noirq = musb_resume_noirq, |
2423 | .runtime_suspend = musb_runtime_suspend, | ||
2424 | .runtime_resume = musb_runtime_resume, | ||
2410 | }; | 2425 | }; |
2411 | 2426 | ||
2412 | #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops) | 2427 | #define MUSB_DEV_PM_OPS (&musb_dev_pm_ops) |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index e6400be8a0f8..4f0dd2ed3964 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -328,7 +328,7 @@ struct musb_hw_ep { | |||
328 | #endif | 328 | #endif |
329 | }; | 329 | }; |
330 | 330 | ||
331 | static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep) | 331 | static inline struct musb_request *next_in_request(struct musb_hw_ep *hw_ep) |
332 | { | 332 | { |
333 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | 333 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC |
334 | return next_request(&hw_ep->ep_in); | 334 | return next_request(&hw_ep->ep_in); |
@@ -337,7 +337,7 @@ static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep) | |||
337 | #endif | 337 | #endif |
338 | } | 338 | } |
339 | 339 | ||
340 | static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep) | 340 | static inline struct musb_request *next_out_request(struct musb_hw_ep *hw_ep) |
341 | { | 341 | { |
342 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | 342 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC |
343 | return next_request(&hw_ep->ep_out); | 343 | return next_request(&hw_ep->ep_out); |
@@ -358,10 +358,6 @@ struct musb_csr_regs { | |||
358 | 358 | ||
359 | struct musb_context_registers { | 359 | struct musb_context_registers { |
360 | 360 | ||
361 | #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \ | ||
362 | defined(CONFIG_ARCH_OMAP4) | ||
363 | u32 otg_sysconfig, otg_forcestandby; | ||
364 | #endif | ||
365 | u8 power; | 361 | u8 power; |
366 | u16 intrtxe, intrrxe; | 362 | u16 intrtxe, intrrxe; |
367 | u8 intrusbe; | 363 | u8 intrusbe; |
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 2fe304611dcf..5c7b321d3959 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c | |||
@@ -189,7 +189,7 @@ __acquires(ep->musb->lock) | |||
189 | 189 | ||
190 | req = to_musb_request(request); | 190 | req = to_musb_request(request); |
191 | 191 | ||
192 | list_del(&request->list); | 192 | list_del(&req->list); |
193 | if (req->request.status == -EINPROGRESS) | 193 | if (req->request.status == -EINPROGRESS) |
194 | req->request.status = status; | 194 | req->request.status = status; |
195 | musb = req->musb; | 195 | musb = req->musb; |
@@ -251,9 +251,8 @@ static void nuke(struct musb_ep *ep, const int status) | |||
251 | ep->dma = NULL; | 251 | ep->dma = NULL; |
252 | } | 252 | } |
253 | 253 | ||
254 | while (!list_empty(&(ep->req_list))) { | 254 | while (!list_empty(&ep->req_list)) { |
255 | req = container_of(ep->req_list.next, struct musb_request, | 255 | req = list_first_entry(&ep->req_list, struct musb_request, list); |
256 | request.list); | ||
257 | musb_g_giveback(ep, &req->request, status); | 256 | musb_g_giveback(ep, &req->request, status); |
258 | } | 257 | } |
259 | } | 258 | } |
@@ -485,6 +484,7 @@ static void txstate(struct musb *musb, struct musb_request *req) | |||
485 | void musb_g_tx(struct musb *musb, u8 epnum) | 484 | void musb_g_tx(struct musb *musb, u8 epnum) |
486 | { | 485 | { |
487 | u16 csr; | 486 | u16 csr; |
487 | struct musb_request *req; | ||
488 | struct usb_request *request; | 488 | struct usb_request *request; |
489 | u8 __iomem *mbase = musb->mregs; | 489 | u8 __iomem *mbase = musb->mregs; |
490 | struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in; | 490 | struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_in; |
@@ -492,7 +492,8 @@ void musb_g_tx(struct musb *musb, u8 epnum) | |||
492 | struct dma_channel *dma; | 492 | struct dma_channel *dma; |
493 | 493 | ||
494 | musb_ep_select(mbase, epnum); | 494 | musb_ep_select(mbase, epnum); |
495 | request = next_request(musb_ep); | 495 | req = next_request(musb_ep); |
496 | request = &req->request; | ||
496 | 497 | ||
497 | csr = musb_readw(epio, MUSB_TXCSR); | 498 | csr = musb_readw(epio, MUSB_TXCSR); |
498 | DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr); | 499 | DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr); |
@@ -571,15 +572,15 @@ void musb_g_tx(struct musb *musb, u8 epnum) | |||
571 | 572 | ||
572 | if (request->actual == request->length) { | 573 | if (request->actual == request->length) { |
573 | musb_g_giveback(musb_ep, request, 0); | 574 | musb_g_giveback(musb_ep, request, 0); |
574 | request = musb_ep->desc ? next_request(musb_ep) : NULL; | 575 | req = musb_ep->desc ? next_request(musb_ep) : NULL; |
575 | if (!request) { | 576 | if (!req) { |
576 | DBG(4, "%s idle now\n", | 577 | DBG(4, "%s idle now\n", |
577 | musb_ep->end_point.name); | 578 | musb_ep->end_point.name); |
578 | return; | 579 | return; |
579 | } | 580 | } |
580 | } | 581 | } |
581 | 582 | ||
582 | txstate(musb, to_musb_request(request)); | 583 | txstate(musb, req); |
583 | } | 584 | } |
584 | } | 585 | } |
585 | 586 | ||
@@ -821,6 +822,7 @@ static void rxstate(struct musb *musb, struct musb_request *req) | |||
821 | void musb_g_rx(struct musb *musb, u8 epnum) | 822 | void musb_g_rx(struct musb *musb, u8 epnum) |
822 | { | 823 | { |
823 | u16 csr; | 824 | u16 csr; |
825 | struct musb_request *req; | ||
824 | struct usb_request *request; | 826 | struct usb_request *request; |
825 | void __iomem *mbase = musb->mregs; | 827 | void __iomem *mbase = musb->mregs; |
826 | struct musb_ep *musb_ep; | 828 | struct musb_ep *musb_ep; |
@@ -835,10 +837,12 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
835 | 837 | ||
836 | musb_ep_select(mbase, epnum); | 838 | musb_ep_select(mbase, epnum); |
837 | 839 | ||
838 | request = next_request(musb_ep); | 840 | req = next_request(musb_ep); |
839 | if (!request) | 841 | if (!req) |
840 | return; | 842 | return; |
841 | 843 | ||
844 | request = &req->request; | ||
845 | |||
842 | csr = musb_readw(epio, MUSB_RXCSR); | 846 | csr = musb_readw(epio, MUSB_RXCSR); |
843 | dma = is_dma_capable() ? musb_ep->dma : NULL; | 847 | dma = is_dma_capable() ? musb_ep->dma : NULL; |
844 | 848 | ||
@@ -914,15 +918,15 @@ void musb_g_rx(struct musb *musb, u8 epnum) | |||
914 | #endif | 918 | #endif |
915 | musb_g_giveback(musb_ep, request, 0); | 919 | musb_g_giveback(musb_ep, request, 0); |
916 | 920 | ||
917 | request = next_request(musb_ep); | 921 | req = next_request(musb_ep); |
918 | if (!request) | 922 | if (!req) |
919 | return; | 923 | return; |
920 | } | 924 | } |
921 | #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) | 925 | #if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_TUSB_OMAP_DMA) |
922 | exit: | 926 | exit: |
923 | #endif | 927 | #endif |
924 | /* Analyze request */ | 928 | /* Analyze request */ |
925 | rxstate(musb, to_musb_request(request)); | 929 | rxstate(musb, req); |
926 | } | 930 | } |
927 | 931 | ||
928 | /* ------------------------------------------------------------ */ | 932 | /* ------------------------------------------------------------ */ |
@@ -974,7 +978,7 @@ static int musb_gadget_enable(struct usb_ep *ep, | |||
974 | ok = musb->hb_iso_rx; | 978 | ok = musb->hb_iso_rx; |
975 | 979 | ||
976 | if (!ok) { | 980 | if (!ok) { |
977 | DBG(4, "%s: not support ISO high bandwidth\n", __func__); | 981 | DBG(4, "no support for high bandwidth ISO\n"); |
978 | goto fail; | 982 | goto fail; |
979 | } | 983 | } |
980 | musb_ep->hb_mult = (tmp >> 11) & 3; | 984 | musb_ep->hb_mult = (tmp >> 11) & 3; |
@@ -998,7 +1002,7 @@ static int musb_gadget_enable(struct usb_ep *ep, | |||
998 | goto fail; | 1002 | goto fail; |
999 | 1003 | ||
1000 | if (tmp > hw_ep->max_packet_sz_tx) { | 1004 | if (tmp > hw_ep->max_packet_sz_tx) { |
1001 | DBG(4, "%s: packet size beyond hw fifo size\n", __func__); | 1005 | DBG(4, "packet size beyond hardware FIFO size\n"); |
1002 | goto fail; | 1006 | goto fail; |
1003 | } | 1007 | } |
1004 | 1008 | ||
@@ -1038,7 +1042,7 @@ static int musb_gadget_enable(struct usb_ep *ep, | |||
1038 | goto fail; | 1042 | goto fail; |
1039 | 1043 | ||
1040 | if (tmp > hw_ep->max_packet_sz_rx) { | 1044 | if (tmp > hw_ep->max_packet_sz_rx) { |
1041 | DBG(4, "%s: packet size beyond hw fifo size\n", __func__); | 1045 | DBG(4, "packet size beyond hardware FIFO size\n"); |
1042 | goto fail; | 1046 | goto fail; |
1043 | } | 1047 | } |
1044 | 1048 | ||
@@ -1171,7 +1175,6 @@ struct usb_request *musb_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | |||
1171 | return NULL; | 1175 | return NULL; |
1172 | } | 1176 | } |
1173 | 1177 | ||
1174 | INIT_LIST_HEAD(&request->request.list); | ||
1175 | request->request.dma = DMA_ADDR_INVALID; | 1178 | request->request.dma = DMA_ADDR_INVALID; |
1176 | request->epnum = musb_ep->current_epnum; | 1179 | request->epnum = musb_ep->current_epnum; |
1177 | request->ep = musb_ep; | 1180 | request->ep = musb_ep; |
@@ -1257,10 +1260,10 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req, | |||
1257 | } | 1260 | } |
1258 | 1261 | ||
1259 | /* add request to the list */ | 1262 | /* add request to the list */ |
1260 | list_add_tail(&(request->request.list), &(musb_ep->req_list)); | 1263 | list_add_tail(&request->list, &musb_ep->req_list); |
1261 | 1264 | ||
1262 | /* it this is the head of the queue, start i/o ... */ | 1265 | /* it this is the head of the queue, start i/o ... */ |
1263 | if (!musb_ep->busy && &request->request.list == musb_ep->req_list.next) | 1266 | if (!musb_ep->busy && &request->list == musb_ep->req_list.next) |
1264 | musb_ep_restart(musb, request); | 1267 | musb_ep_restart(musb, request); |
1265 | 1268 | ||
1266 | cleanup: | 1269 | cleanup: |
@@ -1271,7 +1274,8 @@ cleanup: | |||
1271 | static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) | 1274 | static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) |
1272 | { | 1275 | { |
1273 | struct musb_ep *musb_ep = to_musb_ep(ep); | 1276 | struct musb_ep *musb_ep = to_musb_ep(ep); |
1274 | struct usb_request *r; | 1277 | struct musb_request *req = to_musb_request(request); |
1278 | struct musb_request *r; | ||
1275 | unsigned long flags; | 1279 | unsigned long flags; |
1276 | int status = 0; | 1280 | int status = 0; |
1277 | struct musb *musb = musb_ep->musb; | 1281 | struct musb *musb = musb_ep->musb; |
@@ -1282,10 +1286,10 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) | |||
1282 | spin_lock_irqsave(&musb->lock, flags); | 1286 | spin_lock_irqsave(&musb->lock, flags); |
1283 | 1287 | ||
1284 | list_for_each_entry(r, &musb_ep->req_list, list) { | 1288 | list_for_each_entry(r, &musb_ep->req_list, list) { |
1285 | if (r == request) | 1289 | if (r == req) |
1286 | break; | 1290 | break; |
1287 | } | 1291 | } |
1288 | if (r != request) { | 1292 | if (r != req) { |
1289 | DBG(3, "request %p not queued to %s\n", request, ep->name); | 1293 | DBG(3, "request %p not queued to %s\n", request, ep->name); |
1290 | status = -EINVAL; | 1294 | status = -EINVAL; |
1291 | goto done; | 1295 | goto done; |
@@ -1349,7 +1353,7 @@ static int musb_gadget_set_halt(struct usb_ep *ep, int value) | |||
1349 | 1353 | ||
1350 | musb_ep_select(mbase, epnum); | 1354 | musb_ep_select(mbase, epnum); |
1351 | 1355 | ||
1352 | request = to_musb_request(next_request(musb_ep)); | 1356 | request = next_request(musb_ep); |
1353 | if (value) { | 1357 | if (value) { |
1354 | if (request) { | 1358 | if (request) { |
1355 | DBG(3, "request in progress, cannot halt %s\n", | 1359 | DBG(3, "request in progress, cannot halt %s\n", |
@@ -1801,90 +1805,105 @@ void musb_gadget_cleanup(struct musb *musb) | |||
1801 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, | 1805 | int usb_gadget_probe_driver(struct usb_gadget_driver *driver, |
1802 | int (*bind)(struct usb_gadget *)) | 1806 | int (*bind)(struct usb_gadget *)) |
1803 | { | 1807 | { |
1804 | int retval; | 1808 | struct musb *musb = the_gadget; |
1805 | unsigned long flags; | 1809 | unsigned long flags; |
1806 | struct musb *musb = the_gadget; | 1810 | int retval = -EINVAL; |
1807 | 1811 | ||
1808 | if (!driver | 1812 | if (!driver |
1809 | || driver->speed != USB_SPEED_HIGH | 1813 | || driver->speed != USB_SPEED_HIGH |
1810 | || !bind || !driver->setup) | 1814 | || !bind || !driver->setup) |
1811 | return -EINVAL; | 1815 | goto err0; |
1812 | 1816 | ||
1813 | /* driver must be initialized to support peripheral mode */ | 1817 | /* driver must be initialized to support peripheral mode */ |
1814 | if (!musb) { | 1818 | if (!musb) { |
1815 | DBG(1, "%s, no dev??\n", __func__); | 1819 | DBG(1, "no dev??\n"); |
1816 | return -ENODEV; | 1820 | retval = -ENODEV; |
1821 | goto err0; | ||
1817 | } | 1822 | } |
1818 | 1823 | ||
1824 | pm_runtime_get_sync(musb->controller); | ||
1825 | |||
1819 | DBG(3, "registering driver %s\n", driver->function); | 1826 | DBG(3, "registering driver %s\n", driver->function); |
1820 | spin_lock_irqsave(&musb->lock, flags); | ||
1821 | 1827 | ||
1822 | if (musb->gadget_driver) { | 1828 | if (musb->gadget_driver) { |
1823 | DBG(1, "%s is already bound to %s\n", | 1829 | DBG(1, "%s is already bound to %s\n", |
1824 | musb_driver_name, | 1830 | musb_driver_name, |
1825 | musb->gadget_driver->driver.name); | 1831 | musb->gadget_driver->driver.name); |
1826 | retval = -EBUSY; | 1832 | retval = -EBUSY; |
1827 | } else { | 1833 | goto err0; |
1828 | musb->gadget_driver = driver; | ||
1829 | musb->g.dev.driver = &driver->driver; | ||
1830 | driver->driver.bus = NULL; | ||
1831 | musb->softconnect = 1; | ||
1832 | retval = 0; | ||
1833 | } | 1834 | } |
1834 | 1835 | ||
1836 | spin_lock_irqsave(&musb->lock, flags); | ||
1837 | musb->gadget_driver = driver; | ||
1838 | musb->g.dev.driver = &driver->driver; | ||
1839 | driver->driver.bus = NULL; | ||
1840 | musb->softconnect = 1; | ||
1835 | spin_unlock_irqrestore(&musb->lock, flags); | 1841 | spin_unlock_irqrestore(&musb->lock, flags); |
1836 | 1842 | ||
1837 | if (retval == 0) { | 1843 | retval = bind(&musb->g); |
1838 | retval = bind(&musb->g); | 1844 | if (retval) { |
1839 | if (retval != 0) { | 1845 | DBG(3, "bind to driver %s failed --> %d\n", |
1840 | DBG(3, "bind to driver %s failed --> %d\n", | 1846 | driver->driver.name, retval); |
1841 | driver->driver.name, retval); | 1847 | goto err1; |
1842 | musb->gadget_driver = NULL; | 1848 | } |
1843 | musb->g.dev.driver = NULL; | ||
1844 | } | ||
1845 | 1849 | ||
1846 | spin_lock_irqsave(&musb->lock, flags); | 1850 | spin_lock_irqsave(&musb->lock, flags); |
1847 | 1851 | ||
1848 | otg_set_peripheral(musb->xceiv, &musb->g); | 1852 | otg_set_peripheral(musb->xceiv, &musb->g); |
1849 | musb->xceiv->state = OTG_STATE_B_IDLE; | 1853 | musb->xceiv->state = OTG_STATE_B_IDLE; |
1850 | musb->is_active = 1; | 1854 | musb->is_active = 1; |
1851 | 1855 | ||
1852 | /* FIXME this ignores the softconnect flag. Drivers are | 1856 | /* |
1853 | * allowed hold the peripheral inactive until for example | 1857 | * FIXME this ignores the softconnect flag. Drivers are |
1854 | * userspace hooks up printer hardware or DSP codecs, so | 1858 | * allowed hold the peripheral inactive until for example |
1855 | * hosts only see fully functional devices. | 1859 | * userspace hooks up printer hardware or DSP codecs, so |
1856 | */ | 1860 | * hosts only see fully functional devices. |
1861 | */ | ||
1857 | 1862 | ||
1858 | if (!is_otg_enabled(musb)) | 1863 | if (!is_otg_enabled(musb)) |
1859 | musb_start(musb); | 1864 | musb_start(musb); |
1860 | 1865 | ||
1861 | otg_set_peripheral(musb->xceiv, &musb->g); | 1866 | otg_set_peripheral(musb->xceiv, &musb->g); |
1862 | 1867 | ||
1863 | spin_unlock_irqrestore(&musb->lock, flags); | 1868 | spin_unlock_irqrestore(&musb->lock, flags); |
1864 | 1869 | ||
1865 | if (is_otg_enabled(musb)) { | 1870 | if (is_otg_enabled(musb)) { |
1866 | struct usb_hcd *hcd = musb_to_hcd(musb); | 1871 | struct usb_hcd *hcd = musb_to_hcd(musb); |
1867 | 1872 | ||
1868 | DBG(3, "OTG startup...\n"); | 1873 | DBG(3, "OTG startup...\n"); |
1869 | 1874 | ||
1870 | /* REVISIT: funcall to other code, which also | 1875 | /* REVISIT: funcall to other code, which also |
1871 | * handles power budgeting ... this way also | 1876 | * handles power budgeting ... this way also |
1872 | * ensures HdrcStart is indirectly called. | 1877 | * ensures HdrcStart is indirectly called. |
1873 | */ | 1878 | */ |
1874 | retval = usb_add_hcd(musb_to_hcd(musb), -1, 0); | 1879 | retval = usb_add_hcd(musb_to_hcd(musb), -1, 0); |
1875 | if (retval < 0) { | 1880 | if (retval < 0) { |
1876 | DBG(1, "add_hcd failed, %d\n", retval); | 1881 | DBG(1, "add_hcd failed, %d\n", retval); |
1877 | spin_lock_irqsave(&musb->lock, flags); | 1882 | goto err2; |
1878 | otg_set_peripheral(musb->xceiv, NULL); | 1883 | |
1879 | musb->gadget_driver = NULL; | 1884 | if ((musb->xceiv->last_event == USB_EVENT_ID) |
1880 | musb->g.dev.driver = NULL; | 1885 | && musb->xceiv->set_vbus) |
1881 | spin_unlock_irqrestore(&musb->lock, flags); | 1886 | otg_set_vbus(musb->xceiv, 1); |
1882 | } else { | ||
1883 | hcd->self.uses_pio_for_control = 1; | ||
1884 | } | ||
1885 | } | 1887 | } |
1888 | |||
1889 | hcd->self.uses_pio_for_control = 1; | ||
1890 | |||
1891 | if (musb->xceiv->last_event == USB_EVENT_NONE) | ||
1892 | pm_runtime_put(musb->controller); | ||
1893 | |||
1886 | } | 1894 | } |
1887 | 1895 | ||
1896 | return 0; | ||
1897 | |||
1898 | err2: | ||
1899 | if (!is_otg_enabled(musb)) | ||
1900 | musb_stop(musb); | ||
1901 | |||
1902 | err1: | ||
1903 | musb->gadget_driver = NULL; | ||
1904 | musb->g.dev.driver = NULL; | ||
1905 | |||
1906 | err0: | ||
1888 | return retval; | 1907 | return retval; |
1889 | } | 1908 | } |
1890 | EXPORT_SYMBOL(usb_gadget_probe_driver); | 1909 | EXPORT_SYMBOL(usb_gadget_probe_driver); |
@@ -1939,14 +1958,20 @@ static void stop_activity(struct musb *musb, struct usb_gadget_driver *driver) | |||
1939 | */ | 1958 | */ |
1940 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | 1959 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) |
1941 | { | 1960 | { |
1942 | unsigned long flags; | ||
1943 | int retval = 0; | ||
1944 | struct musb *musb = the_gadget; | 1961 | struct musb *musb = the_gadget; |
1962 | unsigned long flags; | ||
1945 | 1963 | ||
1946 | if (!driver || !driver->unbind || !musb) | 1964 | if (!driver || !driver->unbind || !musb) |
1947 | return -EINVAL; | 1965 | return -EINVAL; |
1948 | 1966 | ||
1949 | /* REVISIT always use otg_set_peripheral() here too; | 1967 | if (!musb->gadget_driver) |
1968 | return -EINVAL; | ||
1969 | |||
1970 | if (musb->xceiv->last_event == USB_EVENT_NONE) | ||
1971 | pm_runtime_get_sync(musb->controller); | ||
1972 | |||
1973 | /* | ||
1974 | * REVISIT always use otg_set_peripheral() here too; | ||
1950 | * this needs to shut down the OTG engine. | 1975 | * this needs to shut down the OTG engine. |
1951 | */ | 1976 | */ |
1952 | 1977 | ||
@@ -1956,29 +1981,26 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1956 | musb_hnp_stop(musb); | 1981 | musb_hnp_stop(musb); |
1957 | #endif | 1982 | #endif |
1958 | 1983 | ||
1959 | if (musb->gadget_driver == driver) { | 1984 | (void) musb_gadget_vbus_draw(&musb->g, 0); |
1960 | 1985 | ||
1961 | (void) musb_gadget_vbus_draw(&musb->g, 0); | 1986 | musb->xceiv->state = OTG_STATE_UNDEFINED; |
1987 | stop_activity(musb, driver); | ||
1988 | otg_set_peripheral(musb->xceiv, NULL); | ||
1962 | 1989 | ||
1963 | musb->xceiv->state = OTG_STATE_UNDEFINED; | 1990 | DBG(3, "unregistering driver %s\n", driver->function); |
1964 | stop_activity(musb, driver); | ||
1965 | otg_set_peripheral(musb->xceiv, NULL); | ||
1966 | 1991 | ||
1967 | DBG(3, "unregistering driver %s\n", driver->function); | 1992 | spin_unlock_irqrestore(&musb->lock, flags); |
1968 | spin_unlock_irqrestore(&musb->lock, flags); | 1993 | driver->unbind(&musb->g); |
1969 | driver->unbind(&musb->g); | 1994 | spin_lock_irqsave(&musb->lock, flags); |
1970 | spin_lock_irqsave(&musb->lock, flags); | ||
1971 | 1995 | ||
1972 | musb->gadget_driver = NULL; | 1996 | musb->gadget_driver = NULL; |
1973 | musb->g.dev.driver = NULL; | 1997 | musb->g.dev.driver = NULL; |
1974 | 1998 | ||
1975 | musb->is_active = 0; | 1999 | musb->is_active = 0; |
1976 | musb_platform_try_idle(musb, 0); | 2000 | musb_platform_try_idle(musb, 0); |
1977 | } else | ||
1978 | retval = -EINVAL; | ||
1979 | spin_unlock_irqrestore(&musb->lock, flags); | 2001 | spin_unlock_irqrestore(&musb->lock, flags); |
1980 | 2002 | ||
1981 | if (is_otg_enabled(musb) && retval == 0) { | 2003 | if (is_otg_enabled(musb)) { |
1982 | usb_remove_hcd(musb_to_hcd(musb)); | 2004 | usb_remove_hcd(musb_to_hcd(musb)); |
1983 | /* FIXME we need to be able to register another | 2005 | /* FIXME we need to be able to register another |
1984 | * gadget driver here and have everything work; | 2006 | * gadget driver here and have everything work; |
@@ -1986,7 +2008,12 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1986 | */ | 2008 | */ |
1987 | } | 2009 | } |
1988 | 2010 | ||
1989 | return retval; | 2011 | if (!is_otg_enabled(musb)) |
2012 | musb_stop(musb); | ||
2013 | |||
2014 | pm_runtime_put(musb->controller); | ||
2015 | |||
2016 | return 0; | ||
1990 | } | 2017 | } |
1991 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | 2018 | EXPORT_SYMBOL(usb_gadget_unregister_driver); |
1992 | 2019 | ||
diff --git a/drivers/usb/musb/musb_gadget.h b/drivers/usb/musb/musb_gadget.h index a55354fbccf5..66b7c5e0fb44 100644 --- a/drivers/usb/musb/musb_gadget.h +++ b/drivers/usb/musb/musb_gadget.h | |||
@@ -35,6 +35,8 @@ | |||
35 | #ifndef __MUSB_GADGET_H | 35 | #ifndef __MUSB_GADGET_H |
36 | #define __MUSB_GADGET_H | 36 | #define __MUSB_GADGET_H |
37 | 37 | ||
38 | #include <linux/list.h> | ||
39 | |||
38 | enum buffer_map_state { | 40 | enum buffer_map_state { |
39 | UN_MAPPED = 0, | 41 | UN_MAPPED = 0, |
40 | PRE_MAPPED, | 42 | PRE_MAPPED, |
@@ -43,6 +45,7 @@ enum buffer_map_state { | |||
43 | 45 | ||
44 | struct musb_request { | 46 | struct musb_request { |
45 | struct usb_request request; | 47 | struct usb_request request; |
48 | struct list_head list; | ||
46 | struct musb_ep *ep; | 49 | struct musb_ep *ep; |
47 | struct musb *musb; | 50 | struct musb *musb; |
48 | u8 tx; /* endpoint direction */ | 51 | u8 tx; /* endpoint direction */ |
@@ -94,13 +97,13 @@ static inline struct musb_ep *to_musb_ep(struct usb_ep *ep) | |||
94 | return ep ? container_of(ep, struct musb_ep, end_point) : NULL; | 97 | return ep ? container_of(ep, struct musb_ep, end_point) : NULL; |
95 | } | 98 | } |
96 | 99 | ||
97 | static inline struct usb_request *next_request(struct musb_ep *ep) | 100 | static inline struct musb_request *next_request(struct musb_ep *ep) |
98 | { | 101 | { |
99 | struct list_head *queue = &ep->req_list; | 102 | struct list_head *queue = &ep->req_list; |
100 | 103 | ||
101 | if (list_empty(queue)) | 104 | if (list_empty(queue)) |
102 | return NULL; | 105 | return NULL; |
103 | return container_of(queue->next, struct usb_request, list); | 106 | return container_of(queue->next, struct musb_request, list); |
104 | } | 107 | } |
105 | 108 | ||
106 | extern void musb_g_tx(struct musb *musb, u8 epnum); | 109 | extern void musb_g_tx(struct musb *musb, u8 epnum); |
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c index 6dd03f4c5f49..75a542e42fdf 100644 --- a/drivers/usb/musb/musb_gadget_ep0.c +++ b/drivers/usb/musb/musb_gadget_ep0.c | |||
@@ -304,8 +304,7 @@ __acquires(musb->lock) | |||
304 | } | 304 | } |
305 | 305 | ||
306 | /* Maybe start the first request in the queue */ | 306 | /* Maybe start the first request in the queue */ |
307 | request = to_musb_request( | 307 | request = next_request(musb_ep); |
308 | next_request(musb_ep)); | ||
309 | if (!musb_ep->busy && request) { | 308 | if (!musb_ep->busy && request) { |
310 | DBG(3, "restarting the request\n"); | 309 | DBG(3, "restarting the request\n"); |
311 | musb_ep_restart(musb, request); | 310 | musb_ep_restart(musb, request); |
@@ -491,10 +490,12 @@ stall: | |||
491 | static void ep0_rxstate(struct musb *musb) | 490 | static void ep0_rxstate(struct musb *musb) |
492 | { | 491 | { |
493 | void __iomem *regs = musb->control_ep->regs; | 492 | void __iomem *regs = musb->control_ep->regs; |
493 | struct musb_request *request; | ||
494 | struct usb_request *req; | 494 | struct usb_request *req; |
495 | u16 count, csr; | 495 | u16 count, csr; |
496 | 496 | ||
497 | req = next_ep0_request(musb); | 497 | request = next_ep0_request(musb); |
498 | req = &request->request; | ||
498 | 499 | ||
499 | /* read packet and ack; or stall because of gadget driver bug: | 500 | /* read packet and ack; or stall because of gadget driver bug: |
500 | * should have provided the rx buffer before setup() returned. | 501 | * should have provided the rx buffer before setup() returned. |
@@ -544,17 +545,20 @@ static void ep0_rxstate(struct musb *musb) | |||
544 | static void ep0_txstate(struct musb *musb) | 545 | static void ep0_txstate(struct musb *musb) |
545 | { | 546 | { |
546 | void __iomem *regs = musb->control_ep->regs; | 547 | void __iomem *regs = musb->control_ep->regs; |
547 | struct usb_request *request = next_ep0_request(musb); | 548 | struct musb_request *req = next_ep0_request(musb); |
549 | struct usb_request *request; | ||
548 | u16 csr = MUSB_CSR0_TXPKTRDY; | 550 | u16 csr = MUSB_CSR0_TXPKTRDY; |
549 | u8 *fifo_src; | 551 | u8 *fifo_src; |
550 | u8 fifo_count; | 552 | u8 fifo_count; |
551 | 553 | ||
552 | if (!request) { | 554 | if (!req) { |
553 | /* WARN_ON(1); */ | 555 | /* WARN_ON(1); */ |
554 | DBG(2, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0)); | 556 | DBG(2, "odd; csr0 %04x\n", musb_readw(regs, MUSB_CSR0)); |
555 | return; | 557 | return; |
556 | } | 558 | } |
557 | 559 | ||
560 | request = &req->request; | ||
561 | |||
558 | /* load the data */ | 562 | /* load the data */ |
559 | fifo_src = (u8 *) request->buf + request->actual; | 563 | fifo_src = (u8 *) request->buf + request->actual; |
560 | fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE, | 564 | fifo_count = min((unsigned) MUSB_EP0_FIFOSIZE, |
@@ -598,7 +602,7 @@ static void ep0_txstate(struct musb *musb) | |||
598 | static void | 602 | static void |
599 | musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req) | 603 | musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req) |
600 | { | 604 | { |
601 | struct usb_request *r; | 605 | struct musb_request *r; |
602 | void __iomem *regs = musb->control_ep->regs; | 606 | void __iomem *regs = musb->control_ep->regs; |
603 | 607 | ||
604 | musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req); | 608 | musb_read_fifo(&musb->endpoints[0], sizeof *req, (u8 *)req); |
@@ -616,7 +620,7 @@ musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req) | |||
616 | /* clean up any leftover transfers */ | 620 | /* clean up any leftover transfers */ |
617 | r = next_ep0_request(musb); | 621 | r = next_ep0_request(musb); |
618 | if (r) | 622 | if (r) |
619 | musb_g_ep0_giveback(musb, r); | 623 | musb_g_ep0_giveback(musb, &r->request); |
620 | 624 | ||
621 | /* For zero-data requests we want to delay the STATUS stage to | 625 | /* For zero-data requests we want to delay the STATUS stage to |
622 | * avoid SETUPEND errors. If we read data (OUT), delay accepting | 626 | * avoid SETUPEND errors. If we read data (OUT), delay accepting |
@@ -758,11 +762,11 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb) | |||
758 | case MUSB_EP0_STAGE_STATUSOUT: | 762 | case MUSB_EP0_STAGE_STATUSOUT: |
759 | /* end of sequence #1: write to host (TX state) */ | 763 | /* end of sequence #1: write to host (TX state) */ |
760 | { | 764 | { |
761 | struct usb_request *req; | 765 | struct musb_request *req; |
762 | 766 | ||
763 | req = next_ep0_request(musb); | 767 | req = next_ep0_request(musb); |
764 | if (req) | 768 | if (req) |
765 | musb_g_ep0_giveback(musb, req); | 769 | musb_g_ep0_giveback(musb, &req->request); |
766 | } | 770 | } |
767 | 771 | ||
768 | /* | 772 | /* |
@@ -961,7 +965,7 @@ musb_g_ep0_queue(struct usb_ep *e, struct usb_request *r, gfp_t gfp_flags) | |||
961 | } | 965 | } |
962 | 966 | ||
963 | /* add request to the list */ | 967 | /* add request to the list */ |
964 | list_add_tail(&(req->request.list), &(ep->req_list)); | 968 | list_add_tail(&req->list, &ep->req_list); |
965 | 969 | ||
966 | DBG(3, "queue to %s (%s), length=%d\n", | 970 | DBG(3, "queue to %s (%s), length=%d\n", |
967 | ep->name, ep->is_in ? "IN/TX" : "OUT/RX", | 971 | ep->name, ep->is_in ? "IN/TX" : "OUT/RX", |
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c index 0f523d7db57b..5eef4a8847db 100644 --- a/drivers/usb/musb/musb_host.c +++ b/drivers/usb/musb/musb_host.c | |||
@@ -1335,7 +1335,7 @@ void musb_host_tx(struct musb *musb, u8 epnum) | |||
1335 | if (length > qh->maxpacket) | 1335 | if (length > qh->maxpacket) |
1336 | length = qh->maxpacket; | 1336 | length = qh->maxpacket; |
1337 | /* Unmap the buffer so that CPU can use it */ | 1337 | /* Unmap the buffer so that CPU can use it */ |
1338 | unmap_urb_for_dma(musb_to_hcd(musb), urb); | 1338 | usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); |
1339 | musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset); | 1339 | musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset); |
1340 | qh->segsize = length; | 1340 | qh->segsize = length; |
1341 | 1341 | ||
@@ -1757,7 +1757,7 @@ void musb_host_rx(struct musb *musb, u8 epnum) | |||
1757 | 1757 | ||
1758 | if (!dma) { | 1758 | if (!dma) { |
1759 | /* Unmap the buffer so that CPU can use it */ | 1759 | /* Unmap the buffer so that CPU can use it */ |
1760 | unmap_urb_for_dma(musb_to_hcd(musb), urb); | 1760 | usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); |
1761 | done = musb_host_packet_rx(musb, urb, | 1761 | done = musb_host_packet_rx(musb, urb, |
1762 | epnum, iso_err); | 1762 | epnum, iso_err); |
1763 | DBG(6, "read %spacket\n", done ? "last " : ""); | 1763 | DBG(6, "read %spacket\n", done ? "last " : ""); |
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c index b46d1877e28e..489104a5ae14 100644 --- a/drivers/usb/musb/musb_virthub.c +++ b/drivers/usb/musb/musb_virthub.c | |||
@@ -305,8 +305,8 @@ int musb_hub_control( | |||
305 | desc->bHubContrCurrent = 0; | 305 | desc->bHubContrCurrent = 0; |
306 | 306 | ||
307 | /* workaround bogus struct definition */ | 307 | /* workaround bogus struct definition */ |
308 | desc->DeviceRemovable[0] = 0x02; /* port 1 */ | 308 | desc->u.hs.DeviceRemovable[0] = 0x02; /* port 1 */ |
309 | desc->DeviceRemovable[1] = 0xff; | 309 | desc->u.hs.DeviceRemovable[1] = 0xff; |
310 | } | 310 | } |
311 | break; | 311 | break; |
312 | case GetHubStatus: | 312 | case GetHubStatus: |
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index bc8badd16897..25cb8b0003b1 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -33,6 +33,8 @@ | |||
33 | #include <linux/io.h> | 33 | #include <linux/io.h> |
34 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/pm_runtime.h> | ||
37 | #include <linux/err.h> | ||
36 | 38 | ||
37 | #include "musb_core.h" | 39 | #include "musb_core.h" |
38 | #include "omap2430.h" | 40 | #include "omap2430.h" |
@@ -40,7 +42,6 @@ | |||
40 | struct omap2430_glue { | 42 | struct omap2430_glue { |
41 | struct device *dev; | 43 | struct device *dev; |
42 | struct platform_device *musb; | 44 | struct platform_device *musb; |
43 | struct clk *clk; | ||
44 | }; | 45 | }; |
45 | #define glue_to_musb(g) platform_get_drvdata(g->musb) | 46 | #define glue_to_musb(g) platform_get_drvdata(g->musb) |
46 | 47 | ||
@@ -216,20 +217,12 @@ static inline void omap2430_low_level_exit(struct musb *musb) | |||
216 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); | 217 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
217 | l |= ENABLEFORCE; /* enable MSTANDBY */ | 218 | l |= ENABLEFORCE; /* enable MSTANDBY */ |
218 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | 219 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
219 | |||
220 | l = musb_readl(musb->mregs, OTG_SYSCONFIG); | ||
221 | l |= ENABLEWAKEUP; /* enable wakeup */ | ||
222 | musb_writel(musb->mregs, OTG_SYSCONFIG, l); | ||
223 | } | 220 | } |
224 | 221 | ||
225 | static inline void omap2430_low_level_init(struct musb *musb) | 222 | static inline void omap2430_low_level_init(struct musb *musb) |
226 | { | 223 | { |
227 | u32 l; | 224 | u32 l; |
228 | 225 | ||
229 | l = musb_readl(musb->mregs, OTG_SYSCONFIG); | ||
230 | l &= ~ENABLEWAKEUP; /* disable wakeup */ | ||
231 | musb_writel(musb->mregs, OTG_SYSCONFIG, l); | ||
232 | |||
233 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); | 226 | l = musb_readl(musb->mregs, OTG_FORCESTDBY); |
234 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ | 227 | l &= ~ENABLEFORCE; /* disable MSTANDBY */ |
235 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); | 228 | musb_writel(musb->mregs, OTG_FORCESTDBY, l); |
@@ -251,31 +244,39 @@ static int musb_otg_notifications(struct notifier_block *nb, | |||
251 | if (is_otg_enabled(musb)) { | 244 | if (is_otg_enabled(musb)) { |
252 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | 245 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC |
253 | if (musb->gadget_driver) { | 246 | if (musb->gadget_driver) { |
247 | pm_runtime_get_sync(musb->controller); | ||
254 | otg_init(musb->xceiv); | 248 | otg_init(musb->xceiv); |
255 | 249 | omap2430_musb_set_vbus(musb, 1); | |
256 | if (data->interface_type == | ||
257 | MUSB_INTERFACE_UTMI) | ||
258 | omap2430_musb_set_vbus(musb, 1); | ||
259 | |||
260 | } | 250 | } |
261 | #endif | 251 | #endif |
262 | } else { | 252 | } else { |
253 | pm_runtime_get_sync(musb->controller); | ||
263 | otg_init(musb->xceiv); | 254 | otg_init(musb->xceiv); |
264 | if (data->interface_type == | 255 | omap2430_musb_set_vbus(musb, 1); |
265 | MUSB_INTERFACE_UTMI) | ||
266 | omap2430_musb_set_vbus(musb, 1); | ||
267 | } | 256 | } |
268 | break; | 257 | break; |
269 | 258 | ||
270 | case USB_EVENT_VBUS: | 259 | case USB_EVENT_VBUS: |
271 | DBG(4, "VBUS Connect\n"); | 260 | DBG(4, "VBUS Connect\n"); |
272 | 261 | ||
262 | if (musb->gadget_driver) | ||
263 | pm_runtime_get_sync(musb->controller); | ||
264 | |||
273 | otg_init(musb->xceiv); | 265 | otg_init(musb->xceiv); |
274 | break; | 266 | break; |
275 | 267 | ||
276 | case USB_EVENT_NONE: | 268 | case USB_EVENT_NONE: |
277 | DBG(4, "VBUS Disconnect\n"); | 269 | DBG(4, "VBUS Disconnect\n"); |
278 | 270 | ||
271 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC | ||
272 | if (is_otg_enabled(musb)) | ||
273 | if (musb->gadget_driver) | ||
274 | #endif | ||
275 | { | ||
276 | pm_runtime_mark_last_busy(musb->controller); | ||
277 | pm_runtime_put_autosuspend(musb->controller); | ||
278 | } | ||
279 | |||
279 | if (data->interface_type == MUSB_INTERFACE_UTMI) { | 280 | if (data->interface_type == MUSB_INTERFACE_UTMI) { |
280 | if (musb->xceiv->set_vbus) | 281 | if (musb->xceiv->set_vbus) |
281 | otg_set_vbus(musb->xceiv, 0); | 282 | otg_set_vbus(musb->xceiv, 0); |
@@ -307,22 +308,11 @@ static int omap2430_musb_init(struct musb *musb) | |||
307 | return -ENODEV; | 308 | return -ENODEV; |
308 | } | 309 | } |
309 | 310 | ||
310 | omap2430_low_level_init(musb); | 311 | status = pm_runtime_get_sync(dev); |
311 | 312 | if (status < 0) { | |
312 | l = musb_readl(musb->mregs, OTG_SYSCONFIG); | 313 | dev_err(dev, "pm_runtime_get_sync FAILED"); |
313 | l &= ~ENABLEWAKEUP; /* disable wakeup */ | 314 | goto err1; |
314 | l &= ~NOSTDBY; /* remove possible nostdby */ | 315 | } |
315 | l |= SMARTSTDBY; /* enable smart standby */ | ||
316 | l &= ~AUTOIDLE; /* disable auto idle */ | ||
317 | l &= ~NOIDLE; /* remove possible noidle */ | ||
318 | l |= SMARTIDLE; /* enable smart idle */ | ||
319 | /* | ||
320 | * MUSB AUTOIDLE don't work in 3430. | ||
321 | * Workaround by Richard Woodruff/TI | ||
322 | */ | ||
323 | if (!cpu_is_omap3430()) | ||
324 | l |= AUTOIDLE; /* enable auto idle */ | ||
325 | musb_writel(musb->mregs, OTG_SYSCONFIG, l); | ||
326 | 316 | ||
327 | l = musb_readl(musb->mregs, OTG_INTERFSEL); | 317 | l = musb_readl(musb->mregs, OTG_INTERFSEL); |
328 | 318 | ||
@@ -350,14 +340,58 @@ static int omap2430_musb_init(struct musb *musb) | |||
350 | if (status) | 340 | if (status) |
351 | DBG(1, "notification register failed\n"); | 341 | DBG(1, "notification register failed\n"); |
352 | 342 | ||
353 | /* check whether cable is already connected */ | ||
354 | if (musb->xceiv->state ==OTG_STATE_B_IDLE) | ||
355 | musb_otg_notifications(&musb->nb, 1, | ||
356 | musb->xceiv->gadget); | ||
357 | |||
358 | setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); | 343 | setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); |
359 | 344 | ||
360 | return 0; | 345 | return 0; |
346 | |||
347 | err1: | ||
348 | pm_runtime_disable(dev); | ||
349 | return status; | ||
350 | } | ||
351 | |||
352 | static void omap2430_musb_enable(struct musb *musb) | ||
353 | { | ||
354 | u8 devctl; | ||
355 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); | ||
356 | struct device *dev = musb->controller; | ||
357 | struct musb_hdrc_platform_data *pdata = dev->platform_data; | ||
358 | struct omap_musb_board_data *data = pdata->board_data; | ||
359 | |||
360 | switch (musb->xceiv->last_event) { | ||
361 | |||
362 | case USB_EVENT_ID: | ||
363 | otg_init(musb->xceiv); | ||
364 | if (data->interface_type == MUSB_INTERFACE_UTMI) { | ||
365 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); | ||
366 | /* start the session */ | ||
367 | devctl |= MUSB_DEVCTL_SESSION; | ||
368 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); | ||
369 | while (musb_readb(musb->mregs, MUSB_DEVCTL) & | ||
370 | MUSB_DEVCTL_BDEVICE) { | ||
371 | cpu_relax(); | ||
372 | |||
373 | if (time_after(jiffies, timeout)) { | ||
374 | dev_err(musb->controller, | ||
375 | "configured as A device timeout"); | ||
376 | break; | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | break; | ||
381 | |||
382 | case USB_EVENT_VBUS: | ||
383 | otg_init(musb->xceiv); | ||
384 | break; | ||
385 | |||
386 | default: | ||
387 | break; | ||
388 | } | ||
389 | } | ||
390 | |||
391 | static void omap2430_musb_disable(struct musb *musb) | ||
392 | { | ||
393 | if (musb->xceiv->last_event) | ||
394 | otg_shutdown(musb->xceiv); | ||
361 | } | 395 | } |
362 | 396 | ||
363 | static int omap2430_musb_exit(struct musb *musb) | 397 | static int omap2430_musb_exit(struct musb *musb) |
@@ -378,6 +412,9 @@ static const struct musb_platform_ops omap2430_ops = { | |||
378 | .try_idle = omap2430_musb_try_idle, | 412 | .try_idle = omap2430_musb_try_idle, |
379 | 413 | ||
380 | .set_vbus = omap2430_musb_set_vbus, | 414 | .set_vbus = omap2430_musb_set_vbus, |
415 | |||
416 | .enable = omap2430_musb_enable, | ||
417 | .disable = omap2430_musb_disable, | ||
381 | }; | 418 | }; |
382 | 419 | ||
383 | static u64 omap2430_dmamask = DMA_BIT_MASK(32); | 420 | static u64 omap2430_dmamask = DMA_BIT_MASK(32); |
@@ -387,8 +424,6 @@ static int __init omap2430_probe(struct platform_device *pdev) | |||
387 | struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; | 424 | struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; |
388 | struct platform_device *musb; | 425 | struct platform_device *musb; |
389 | struct omap2430_glue *glue; | 426 | struct omap2430_glue *glue; |
390 | struct clk *clk; | ||
391 | |||
392 | int ret = -ENOMEM; | 427 | int ret = -ENOMEM; |
393 | 428 | ||
394 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); | 429 | glue = kzalloc(sizeof(*glue), GFP_KERNEL); |
@@ -403,26 +438,12 @@ static int __init omap2430_probe(struct platform_device *pdev) | |||
403 | goto err1; | 438 | goto err1; |
404 | } | 439 | } |
405 | 440 | ||
406 | clk = clk_get(&pdev->dev, "ick"); | ||
407 | if (IS_ERR(clk)) { | ||
408 | dev_err(&pdev->dev, "failed to get clock\n"); | ||
409 | ret = PTR_ERR(clk); | ||
410 | goto err2; | ||
411 | } | ||
412 | |||
413 | ret = clk_enable(clk); | ||
414 | if (ret) { | ||
415 | dev_err(&pdev->dev, "failed to enable clock\n"); | ||
416 | goto err3; | ||
417 | } | ||
418 | |||
419 | musb->dev.parent = &pdev->dev; | 441 | musb->dev.parent = &pdev->dev; |
420 | musb->dev.dma_mask = &omap2430_dmamask; | 442 | musb->dev.dma_mask = &omap2430_dmamask; |
421 | musb->dev.coherent_dma_mask = omap2430_dmamask; | 443 | musb->dev.coherent_dma_mask = omap2430_dmamask; |
422 | 444 | ||
423 | glue->dev = &pdev->dev; | 445 | glue->dev = &pdev->dev; |
424 | glue->musb = musb; | 446 | glue->musb = musb; |
425 | glue->clk = clk; | ||
426 | 447 | ||
427 | pdata->platform_ops = &omap2430_ops; | 448 | pdata->platform_ops = &omap2430_ops; |
428 | 449 | ||
@@ -432,28 +453,24 @@ static int __init omap2430_probe(struct platform_device *pdev) | |||
432 | pdev->num_resources); | 453 | pdev->num_resources); |
433 | if (ret) { | 454 | if (ret) { |
434 | dev_err(&pdev->dev, "failed to add resources\n"); | 455 | dev_err(&pdev->dev, "failed to add resources\n"); |
435 | goto err4; | 456 | goto err2; |
436 | } | 457 | } |
437 | 458 | ||
438 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); | 459 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
439 | if (ret) { | 460 | if (ret) { |
440 | dev_err(&pdev->dev, "failed to add platform_data\n"); | 461 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
441 | goto err4; | 462 | goto err2; |
442 | } | 463 | } |
443 | 464 | ||
444 | ret = platform_device_add(musb); | 465 | ret = platform_device_add(musb); |
445 | if (ret) { | 466 | if (ret) { |
446 | dev_err(&pdev->dev, "failed to register musb device\n"); | 467 | dev_err(&pdev->dev, "failed to register musb device\n"); |
447 | goto err4; | 468 | goto err2; |
448 | } | 469 | } |
449 | 470 | ||
450 | return 0; | 471 | pm_runtime_enable(&pdev->dev); |
451 | |||
452 | err4: | ||
453 | clk_disable(clk); | ||
454 | 472 | ||
455 | err3: | 473 | return 0; |
456 | clk_put(clk); | ||
457 | 474 | ||
458 | err2: | 475 | err2: |
459 | platform_device_put(musb); | 476 | platform_device_put(musb); |
@@ -471,61 +488,40 @@ static int __exit omap2430_remove(struct platform_device *pdev) | |||
471 | 488 | ||
472 | platform_device_del(glue->musb); | 489 | platform_device_del(glue->musb); |
473 | platform_device_put(glue->musb); | 490 | platform_device_put(glue->musb); |
474 | clk_disable(glue->clk); | 491 | pm_runtime_put(&pdev->dev); |
475 | clk_put(glue->clk); | 492 | pm_runtime_disable(&pdev->dev); |
476 | kfree(glue); | 493 | kfree(glue); |
477 | 494 | ||
478 | return 0; | 495 | return 0; |
479 | } | 496 | } |
480 | 497 | ||
481 | #ifdef CONFIG_PM | 498 | #ifdef CONFIG_PM |
482 | static void omap2430_save_context(struct musb *musb) | ||
483 | { | ||
484 | musb->context.otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG); | ||
485 | musb->context.otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY); | ||
486 | } | ||
487 | 499 | ||
488 | static void omap2430_restore_context(struct musb *musb) | 500 | static int omap2430_runtime_suspend(struct device *dev) |
489 | { | ||
490 | musb_writel(musb->mregs, OTG_SYSCONFIG, musb->context.otg_sysconfig); | ||
491 | musb_writel(musb->mregs, OTG_FORCESTDBY, musb->context.otg_forcestandby); | ||
492 | } | ||
493 | |||
494 | static int omap2430_suspend(struct device *dev) | ||
495 | { | 501 | { |
496 | struct omap2430_glue *glue = dev_get_drvdata(dev); | 502 | struct omap2430_glue *glue = dev_get_drvdata(dev); |
497 | struct musb *musb = glue_to_musb(glue); | 503 | struct musb *musb = glue_to_musb(glue); |
498 | 504 | ||
499 | omap2430_low_level_exit(musb); | 505 | omap2430_low_level_exit(musb); |
500 | otg_set_suspend(musb->xceiv, 1); | 506 | otg_set_suspend(musb->xceiv, 1); |
501 | omap2430_save_context(musb); | ||
502 | clk_disable(glue->clk); | ||
503 | 507 | ||
504 | return 0; | 508 | return 0; |
505 | } | 509 | } |
506 | 510 | ||
507 | static int omap2430_resume(struct device *dev) | 511 | static int omap2430_runtime_resume(struct device *dev) |
508 | { | 512 | { |
509 | struct omap2430_glue *glue = dev_get_drvdata(dev); | 513 | struct omap2430_glue *glue = dev_get_drvdata(dev); |
510 | struct musb *musb = glue_to_musb(glue); | 514 | struct musb *musb = glue_to_musb(glue); |
511 | int ret; | ||
512 | |||
513 | ret = clk_enable(glue->clk); | ||
514 | if (ret) { | ||
515 | dev_err(dev, "faled to enable clock\n"); | ||
516 | return ret; | ||
517 | } | ||
518 | 515 | ||
519 | omap2430_low_level_init(musb); | 516 | omap2430_low_level_init(musb); |
520 | omap2430_restore_context(musb); | ||
521 | otg_set_suspend(musb->xceiv, 0); | 517 | otg_set_suspend(musb->xceiv, 0); |
522 | 518 | ||
523 | return 0; | 519 | return 0; |
524 | } | 520 | } |
525 | 521 | ||
526 | static struct dev_pm_ops omap2430_pm_ops = { | 522 | static struct dev_pm_ops omap2430_pm_ops = { |
527 | .suspend = omap2430_suspend, | 523 | .runtime_suspend = omap2430_runtime_suspend, |
528 | .resume = omap2430_resume, | 524 | .runtime_resume = omap2430_runtime_resume, |
529 | }; | 525 | }; |
530 | 526 | ||
531 | #define DEV_PM_OPS (&omap2430_pm_ops) | 527 | #define DEV_PM_OPS (&omap2430_pm_ops) |
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c index c061a88f2b0f..99cb541e4ef0 100644 --- a/drivers/usb/musb/tusb6010_omap.c +++ b/drivers/usb/musb/tusb6010_omap.c | |||
@@ -680,7 +680,7 @@ dma_controller_create(struct musb *musb, void __iomem *base) | |||
680 | 680 | ||
681 | tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); | 681 | tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); |
682 | if (!tusb_dma) | 682 | if (!tusb_dma) |
683 | goto cleanup; | 683 | goto out; |
684 | 684 | ||
685 | tusb_dma->musb = musb; | 685 | tusb_dma->musb = musb; |
686 | tusb_dma->tbase = musb->ctrl_base; | 686 | tusb_dma->tbase = musb->ctrl_base; |
@@ -721,6 +721,6 @@ dma_controller_create(struct musb *musb, void __iomem *base) | |||
721 | 721 | ||
722 | cleanup: | 722 | cleanup: |
723 | dma_controller_destroy(&tusb_dma->controller); | 723 | dma_controller_destroy(&tusb_dma->controller); |
724 | 724 | out: | |
725 | return NULL; | 725 | return NULL; |
726 | } | 726 | } |
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig index 9ffc8237fb4b..daf3e5f1a0e7 100644 --- a/drivers/usb/otg/Kconfig +++ b/drivers/usb/otg/Kconfig | |||
@@ -49,6 +49,13 @@ config USB_ULPI | |||
49 | Enable this to support ULPI connected USB OTG transceivers which | 49 | Enable this to support ULPI connected USB OTG transceivers which |
50 | are likely found on embedded boards. | 50 | are likely found on embedded boards. |
51 | 51 | ||
52 | config USB_ULPI_VIEWPORT | ||
53 | bool | ||
54 | depends on USB_ULPI | ||
55 | help | ||
56 | Provides read/write operations to the ULPI phy register set for | ||
57 | controllers with a viewport register (e.g. Chipidea/ARC controllers). | ||
58 | |||
52 | config TWL4030_USB | 59 | config TWL4030_USB |
53 | tristate "TWL4030 USB Transceiver Driver" | 60 | tristate "TWL4030 USB Transceiver Driver" |
54 | depends on TWL4030_CORE && REGULATOR_TWL4030 | 61 | depends on TWL4030_CORE && REGULATOR_TWL4030 |
@@ -93,7 +100,7 @@ config USB_LANGWELL_OTG | |||
93 | To compile this driver as a module, choose M here: the | 100 | To compile this driver as a module, choose M here: the |
94 | module will be called langwell_otg. | 101 | module will be called langwell_otg. |
95 | 102 | ||
96 | config USB_MSM_OTG_72K | 103 | config USB_MSM_OTG |
97 | tristate "OTG support for Qualcomm on-chip USB controller" | 104 | tristate "OTG support for Qualcomm on-chip USB controller" |
98 | depends on (USB || USB_GADGET) && ARCH_MSM | 105 | depends on (USB || USB_GADGET) && ARCH_MSM |
99 | select USB_OTG_UTILS | 106 | select USB_OTG_UTILS |
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile index a520e715cfd6..e22d917de017 100644 --- a/drivers/usb/otg/Makefile +++ b/drivers/usb/otg/Makefile | |||
@@ -16,5 +16,6 @@ obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o | |||
16 | obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o | 16 | obj-$(CONFIG_USB_LANGWELL_OTG) += langwell_otg.o |
17 | obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o | 17 | obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o |
18 | obj-$(CONFIG_USB_ULPI) += ulpi.o | 18 | obj-$(CONFIG_USB_ULPI) += ulpi.o |
19 | obj-$(CONFIG_USB_MSM_OTG_72K) += msm72k_otg.o | 19 | obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o |
20 | obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o | ||
20 | obj-$(CONFIG_AB8500_USB) += ab8500-usb.o | 21 | obj-$(CONFIG_AB8500_USB) += ab8500-usb.o |
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c index d14736b3107b..07ccea9ada40 100644 --- a/drivers/usb/otg/ab8500-usb.c +++ b/drivers/usb/otg/ab8500-usb.c | |||
@@ -212,7 +212,7 @@ static int ab8500_usb_link_status_update(struct ab8500_usb *ab) | |||
212 | break; | 212 | break; |
213 | } | 213 | } |
214 | 214 | ||
215 | blocking_notifier_call_chain(&ab->otg.notifier, event, v); | 215 | atomic_notifier_call_chain(&ab->otg.notifier, event, v); |
216 | 216 | ||
217 | return 0; | 217 | return 0; |
218 | } | 218 | } |
@@ -281,7 +281,7 @@ static int ab8500_usb_set_power(struct otg_transceiver *otg, unsigned mA) | |||
281 | ab->vbus_draw = mA; | 281 | ab->vbus_draw = mA; |
282 | 282 | ||
283 | if (mA) | 283 | if (mA) |
284 | blocking_notifier_call_chain(&ab->otg.notifier, | 284 | atomic_notifier_call_chain(&ab->otg.notifier, |
285 | USB_EVENT_ENUMERATED, ab->otg.gadget); | 285 | USB_EVENT_ENUMERATED, ab->otg.gadget); |
286 | return 0; | 286 | return 0; |
287 | } | 287 | } |
@@ -500,7 +500,7 @@ static int __devinit ab8500_usb_probe(struct platform_device *pdev) | |||
500 | 500 | ||
501 | platform_set_drvdata(pdev, ab); | 501 | platform_set_drvdata(pdev, ab); |
502 | 502 | ||
503 | BLOCKING_INIT_NOTIFIER_HEAD(&ab->otg.notifier); | 503 | ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier); |
504 | 504 | ||
505 | /* v1: Wait for link status to become stable. | 505 | /* v1: Wait for link status to become stable. |
506 | * all: Updates form set_host and set_peripheral as they are atomic. | 506 | * all: Updates form set_host and set_peripheral as they are atomic. |
diff --git a/drivers/usb/otg/langwell_otg.c b/drivers/usb/otg/langwell_otg.c index 9fea48264fa2..7f9b8cd4514b 100644 --- a/drivers/usb/otg/langwell_otg.c +++ b/drivers/usb/otg/langwell_otg.c | |||
@@ -174,50 +174,24 @@ static int langwell_otg_set_power(struct otg_transceiver *otg, | |||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | 176 | ||
177 | /* A-device drives vbus, controlled through PMIC CHRGCNTL register*/ | 177 | /* A-device drives vbus, controlled through IPC commands */ |
178 | static int langwell_otg_set_vbus(struct otg_transceiver *otg, bool enabled) | 178 | static int langwell_otg_set_vbus(struct otg_transceiver *otg, bool enabled) |
179 | { | 179 | { |
180 | struct langwell_otg *lnw = the_transceiver; | 180 | struct langwell_otg *lnw = the_transceiver; |
181 | u8 r; | 181 | u8 sub_id; |
182 | 182 | ||
183 | dev_dbg(lnw->dev, "%s <--- %s\n", __func__, enabled ? "on" : "off"); | 183 | dev_dbg(lnw->dev, "%s <--- %s\n", __func__, enabled ? "on" : "off"); |
184 | 184 | ||
185 | /* FIXME: surely we should cache this on the first read. If not use | 185 | if (enabled) |
186 | readv to avoid two transactions */ | 186 | sub_id = 0x8; /* Turn on the VBus */ |
187 | if (intel_scu_ipc_ioread8(0x00, &r) < 0) { | 187 | else |
188 | dev_dbg(lnw->dev, "Failed to read PMIC register 0xD2"); | 188 | sub_id = 0x9; /* Turn off the VBus */ |
189 | return -EBUSY; | ||
190 | } | ||
191 | if ((r & 0x03) != 0x02) { | ||
192 | dev_dbg(lnw->dev, "not NEC PMIC attached\n"); | ||
193 | return -EBUSY; | ||
194 | } | ||
195 | |||
196 | if (intel_scu_ipc_ioread8(0x20, &r) < 0) { | ||
197 | dev_dbg(lnw->dev, "Failed to read PMIC register 0xD2"); | ||
198 | return -EBUSY; | ||
199 | } | ||
200 | |||
201 | if ((r & 0x20) == 0) { | ||
202 | dev_dbg(lnw->dev, "no battery attached\n"); | ||
203 | return -EBUSY; | ||
204 | } | ||
205 | 189 | ||
206 | /* Workaround for battery attachment issue */ | 190 | if (intel_scu_ipc_simple_command(0xef, sub_id)) { |
207 | if (r == 0x34) { | 191 | dev_dbg(lnw->dev, "Failed to set Vbus via IPC commands\n"); |
208 | dev_dbg(lnw->dev, "no battery attached on SH\n"); | ||
209 | return -EBUSY; | 192 | return -EBUSY; |
210 | } | 193 | } |
211 | 194 | ||
212 | dev_dbg(lnw->dev, "battery attached. 2 reg = %x\n", r); | ||
213 | |||
214 | /* workaround: FW detect writing 0x20/0xc0 to d4 event. | ||
215 | * this is only for NEC PMIC. | ||
216 | */ | ||
217 | |||
218 | if (intel_scu_ipc_iowrite8(0xD4, enabled ? 0x20 : 0xC0)) | ||
219 | dev_dbg(lnw->dev, "Failed to write PMIC.\n"); | ||
220 | |||
221 | dev_dbg(lnw->dev, "%s --->\n", __func__); | 195 | dev_dbg(lnw->dev, "%s --->\n", __func__); |
222 | 196 | ||
223 | return 0; | 197 | return 0; |
@@ -394,14 +368,14 @@ static void langwell_otg_phy_low_power(int on) | |||
394 | dev_dbg(lnw->dev, "%s <--- done\n", __func__); | 368 | dev_dbg(lnw->dev, "%s <--- done\n", __func__); |
395 | } | 369 | } |
396 | 370 | ||
397 | /* After drv vbus, add 2 ms delay to set PHCD */ | 371 | /* After drv vbus, add 5 ms delay to set PHCD */ |
398 | static void langwell_otg_phy_low_power_wait(int on) | 372 | static void langwell_otg_phy_low_power_wait(int on) |
399 | { | 373 | { |
400 | struct langwell_otg *lnw = the_transceiver; | 374 | struct langwell_otg *lnw = the_transceiver; |
401 | 375 | ||
402 | dev_dbg(lnw->dev, "add 2ms delay before programing PHCD\n"); | 376 | dev_dbg(lnw->dev, "add 5ms delay before programing PHCD\n"); |
403 | 377 | ||
404 | mdelay(2); | 378 | mdelay(5); |
405 | langwell_otg_phy_low_power(on); | 379 | langwell_otg_phy_low_power(on); |
406 | } | 380 | } |
407 | 381 | ||
diff --git a/drivers/usb/otg/msm72k_otg.c b/drivers/usb/otg/msm_otg.c index 1cd52edcd0c2..296598628b85 100644 --- a/drivers/usb/otg/msm72k_otg.c +++ b/drivers/usb/otg/msm_otg.c | |||
@@ -253,6 +253,9 @@ static int msm_otg_reset(struct otg_transceiver *otg) | |||
253 | } | 253 | } |
254 | 254 | ||
255 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) | 255 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
256 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) | ||
257 | |||
258 | #ifdef CONFIG_PM_SLEEP | ||
256 | static int msm_otg_suspend(struct msm_otg *motg) | 259 | static int msm_otg_suspend(struct msm_otg *motg) |
257 | { | 260 | { |
258 | struct otg_transceiver *otg = &motg->otg; | 261 | struct otg_transceiver *otg = &motg->otg; |
@@ -334,7 +337,6 @@ static int msm_otg_suspend(struct msm_otg *motg) | |||
334 | return 0; | 337 | return 0; |
335 | } | 338 | } |
336 | 339 | ||
337 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) | ||
338 | static int msm_otg_resume(struct msm_otg *motg) | 340 | static int msm_otg_resume(struct msm_otg *motg) |
339 | { | 341 | { |
340 | struct otg_transceiver *otg = &motg->otg; | 342 | struct otg_transceiver *otg = &motg->otg; |
@@ -399,6 +401,7 @@ skip_phy_resume: | |||
399 | 401 | ||
400 | return 0; | 402 | return 0; |
401 | } | 403 | } |
404 | #endif | ||
402 | 405 | ||
403 | static void msm_otg_start_host(struct otg_transceiver *otg, int on) | 406 | static void msm_otg_start_host(struct otg_transceiver *otg, int on) |
404 | { | 407 | { |
@@ -720,7 +723,8 @@ static int msm_otg_mode_open(struct inode *inode, struct file *file) | |||
720 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, | 723 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, |
721 | size_t count, loff_t *ppos) | 724 | size_t count, loff_t *ppos) |
722 | { | 725 | { |
723 | struct msm_otg *motg = file->private_data; | 726 | struct seq_file *s = file->private_data; |
727 | struct msm_otg *motg = s->private; | ||
724 | char buf[16]; | 728 | char buf[16]; |
725 | struct otg_transceiver *otg = &motg->otg; | 729 | struct otg_transceiver *otg = &motg->otg; |
726 | int status = count; | 730 | int status = count; |
@@ -972,7 +976,7 @@ static int __devexit msm_otg_remove(struct platform_device *pdev) | |||
972 | msm_otg_debugfs_cleanup(); | 976 | msm_otg_debugfs_cleanup(); |
973 | cancel_work_sync(&motg->sm_work); | 977 | cancel_work_sync(&motg->sm_work); |
974 | 978 | ||
975 | msm_otg_resume(motg); | 979 | pm_runtime_resume(&pdev->dev); |
976 | 980 | ||
977 | device_init_wakeup(&pdev->dev, 0); | 981 | device_init_wakeup(&pdev->dev, 0); |
978 | pm_runtime_disable(&pdev->dev); | 982 | pm_runtime_disable(&pdev->dev); |
@@ -1050,13 +1054,9 @@ static int msm_otg_runtime_resume(struct device *dev) | |||
1050 | dev_dbg(dev, "OTG runtime resume\n"); | 1054 | dev_dbg(dev, "OTG runtime resume\n"); |
1051 | return msm_otg_resume(motg); | 1055 | return msm_otg_resume(motg); |
1052 | } | 1056 | } |
1053 | #else | ||
1054 | #define msm_otg_runtime_idle NULL | ||
1055 | #define msm_otg_runtime_suspend NULL | ||
1056 | #define msm_otg_runtime_resume NULL | ||
1057 | #endif | 1057 | #endif |
1058 | 1058 | ||
1059 | #ifdef CONFIG_PM | 1059 | #ifdef CONFIG_PM_SLEEP |
1060 | static int msm_otg_pm_suspend(struct device *dev) | 1060 | static int msm_otg_pm_suspend(struct device *dev) |
1061 | { | 1061 | { |
1062 | struct msm_otg *motg = dev_get_drvdata(dev); | 1062 | struct msm_otg *motg = dev_get_drvdata(dev); |
@@ -1086,25 +1086,24 @@ static int msm_otg_pm_resume(struct device *dev) | |||
1086 | 1086 | ||
1087 | return 0; | 1087 | return 0; |
1088 | } | 1088 | } |
1089 | #else | ||
1090 | #define msm_otg_pm_suspend NULL | ||
1091 | #define msm_otg_pm_resume NULL | ||
1092 | #endif | 1089 | #endif |
1093 | 1090 | ||
1091 | #ifdef CONFIG_PM | ||
1094 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { | 1092 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { |
1095 | .runtime_suspend = msm_otg_runtime_suspend, | 1093 | SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) |
1096 | .runtime_resume = msm_otg_runtime_resume, | 1094 | SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, |
1097 | .runtime_idle = msm_otg_runtime_idle, | 1095 | msm_otg_runtime_idle) |
1098 | .suspend = msm_otg_pm_suspend, | ||
1099 | .resume = msm_otg_pm_resume, | ||
1100 | }; | 1096 | }; |
1097 | #endif | ||
1101 | 1098 | ||
1102 | static struct platform_driver msm_otg_driver = { | 1099 | static struct platform_driver msm_otg_driver = { |
1103 | .remove = __devexit_p(msm_otg_remove), | 1100 | .remove = __devexit_p(msm_otg_remove), |
1104 | .driver = { | 1101 | .driver = { |
1105 | .name = DRIVER_NAME, | 1102 | .name = DRIVER_NAME, |
1106 | .owner = THIS_MODULE, | 1103 | .owner = THIS_MODULE, |
1104 | #ifdef CONFIG_PM | ||
1107 | .pm = &msm_otg_dev_pm_ops, | 1105 | .pm = &msm_otg_dev_pm_ops, |
1106 | #endif | ||
1108 | }, | 1107 | }, |
1109 | }; | 1108 | }; |
1110 | 1109 | ||
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c index 8acf165fe13b..c1e360046435 100644 --- a/drivers/usb/otg/nop-usb-xceiv.c +++ b/drivers/usb/otg/nop-usb-xceiv.c | |||
@@ -132,7 +132,7 @@ static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev) | |||
132 | 132 | ||
133 | platform_set_drvdata(pdev, nop); | 133 | platform_set_drvdata(pdev, nop); |
134 | 134 | ||
135 | BLOCKING_INIT_NOTIFIER_HEAD(&nop->otg.notifier); | 135 | ATOMIC_INIT_NOTIFIER_HEAD(&nop->otg.notifier); |
136 | 136 | ||
137 | return 0; | 137 | return 0; |
138 | exit: | 138 | exit: |
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c index 6ca505f333e4..e01b073cc489 100644 --- a/drivers/usb/otg/twl4030-usb.c +++ b/drivers/usb/otg/twl4030-usb.c | |||
@@ -275,6 +275,8 @@ static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl) | |||
275 | dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", | 275 | dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", |
276 | status, status, linkstat); | 276 | status, status, linkstat); |
277 | 277 | ||
278 | twl->otg.last_event = linkstat; | ||
279 | |||
278 | /* REVISIT this assumes host and peripheral controllers | 280 | /* REVISIT this assumes host and peripheral controllers |
279 | * are registered, and that both are active... | 281 | * are registered, and that both are active... |
280 | */ | 282 | */ |
@@ -512,7 +514,7 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) | |||
512 | else | 514 | else |
513 | twl4030_phy_resume(twl); | 515 | twl4030_phy_resume(twl); |
514 | 516 | ||
515 | blocking_notifier_call_chain(&twl->otg.notifier, status, | 517 | atomic_notifier_call_chain(&twl->otg.notifier, status, |
516 | twl->otg.gadget); | 518 | twl->otg.gadget); |
517 | } | 519 | } |
518 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 520 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
@@ -534,7 +536,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl) | |||
534 | twl->asleep = 0; | 536 | twl->asleep = 0; |
535 | } | 537 | } |
536 | 538 | ||
537 | blocking_notifier_call_chain(&twl->otg.notifier, status, | 539 | atomic_notifier_call_chain(&twl->otg.notifier, status, |
538 | twl->otg.gadget); | 540 | twl->otg.gadget); |
539 | } | 541 | } |
540 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 542 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
@@ -623,7 +625,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev) | |||
623 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) | 625 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) |
624 | dev_warn(&pdev->dev, "could not create sysfs file\n"); | 626 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
625 | 627 | ||
626 | BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier); | 628 | ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier); |
627 | 629 | ||
628 | /* Our job is to use irqs and status from the power module | 630 | /* Our job is to use irqs and status from the power module |
629 | * to keep the transceiver disabled when nothing's connected. | 631 | * to keep the transceiver disabled when nothing's connected. |
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/otg/twl6030-usb.c index 28f770103640..8a91b4b832a1 100644 --- a/drivers/usb/otg/twl6030-usb.c +++ b/drivers/usb/otg/twl6030-usb.c | |||
@@ -149,7 +149,6 @@ static int twl6030_set_phy_clk(struct otg_transceiver *x, int on) | |||
149 | 149 | ||
150 | static int twl6030_phy_init(struct otg_transceiver *x) | 150 | static int twl6030_phy_init(struct otg_transceiver *x) |
151 | { | 151 | { |
152 | u8 hw_state; | ||
153 | struct twl6030_usb *twl; | 152 | struct twl6030_usb *twl; |
154 | struct device *dev; | 153 | struct device *dev; |
155 | struct twl4030_usb_data *pdata; | 154 | struct twl4030_usb_data *pdata; |
@@ -158,11 +157,7 @@ static int twl6030_phy_init(struct otg_transceiver *x) | |||
158 | dev = twl->dev; | 157 | dev = twl->dev; |
159 | pdata = dev->platform_data; | 158 | pdata = dev->platform_data; |
160 | 159 | ||
161 | regulator_enable(twl->usb3v3); | 160 | if (twl->linkstat == USB_EVENT_ID) |
162 | |||
163 | hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); | ||
164 | |||
165 | if (hw_state & STS_USB_ID) | ||
166 | pdata->phy_power(twl->dev, 1, 1); | 161 | pdata->phy_power(twl->dev, 1, 1); |
167 | else | 162 | else |
168 | pdata->phy_power(twl->dev, 0, 1); | 163 | pdata->phy_power(twl->dev, 0, 1); |
@@ -180,7 +175,17 @@ static void twl6030_phy_shutdown(struct otg_transceiver *x) | |||
180 | dev = twl->dev; | 175 | dev = twl->dev; |
181 | pdata = dev->platform_data; | 176 | pdata = dev->platform_data; |
182 | pdata->phy_power(twl->dev, 0, 0); | 177 | pdata->phy_power(twl->dev, 0, 0); |
183 | regulator_disable(twl->usb3v3); | 178 | } |
179 | |||
180 | static int twl6030_phy_suspend(struct otg_transceiver *x, int suspend) | ||
181 | { | ||
182 | struct twl6030_usb *twl = xceiv_to_twl(x); | ||
183 | struct device *dev = twl->dev; | ||
184 | struct twl4030_usb_data *pdata = dev->platform_data; | ||
185 | |||
186 | pdata->phy_suspend(dev, suspend); | ||
187 | |||
188 | return 0; | ||
184 | } | 189 | } |
185 | 190 | ||
186 | static int twl6030_usb_ldo_init(struct twl6030_usb *twl) | 191 | static int twl6030_usb_ldo_init(struct twl6030_usb *twl) |
@@ -199,16 +204,6 @@ static int twl6030_usb_ldo_init(struct twl6030_usb *twl) | |||
199 | if (IS_ERR(twl->usb3v3)) | 204 | if (IS_ERR(twl->usb3v3)) |
200 | return -ENODEV; | 205 | return -ENODEV; |
201 | 206 | ||
202 | regulator_enable(twl->usb3v3); | ||
203 | |||
204 | /* Program the VUSB_CFG_TRANS for ACTIVE state. */ | ||
205 | twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0x3F, | ||
206 | VUSB_CFG_TRANS); | ||
207 | |||
208 | /* Program the VUSB_CFG_STATE register to ON on all groups. */ | ||
209 | twl6030_writeb(twl, TWL_MODULE_PM_RECEIVER, 0xE1, | ||
210 | VUSB_CFG_STATE); | ||
211 | |||
212 | /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */ | 207 | /* Program the USB_VBUS_CTRL_SET and set VBUS_ACT_COMP bit */ |
213 | twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET); | 208 | twl6030_writeb(twl, TWL_MODULE_USB, 0x4, USB_VBUS_CTRL_SET); |
214 | 209 | ||
@@ -261,16 +256,25 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl) | |||
261 | CONTROLLER_STAT1); | 256 | CONTROLLER_STAT1); |
262 | if (!(hw_state & STS_USB_ID)) { | 257 | if (!(hw_state & STS_USB_ID)) { |
263 | if (vbus_state & VBUS_DET) { | 258 | if (vbus_state & VBUS_DET) { |
259 | regulator_enable(twl->usb3v3); | ||
260 | twl->asleep = 1; | ||
264 | status = USB_EVENT_VBUS; | 261 | status = USB_EVENT_VBUS; |
265 | twl->otg.default_a = false; | 262 | twl->otg.default_a = false; |
266 | twl->otg.state = OTG_STATE_B_IDLE; | 263 | twl->otg.state = OTG_STATE_B_IDLE; |
264 | twl->linkstat = status; | ||
265 | twl->otg.last_event = status; | ||
266 | atomic_notifier_call_chain(&twl->otg.notifier, | ||
267 | status, twl->otg.gadget); | ||
267 | } else { | 268 | } else { |
268 | status = USB_EVENT_NONE; | 269 | status = USB_EVENT_NONE; |
269 | } | ||
270 | if (status >= 0) { | ||
271 | twl->linkstat = status; | 270 | twl->linkstat = status; |
272 | blocking_notifier_call_chain(&twl->otg.notifier, | 271 | twl->otg.last_event = status; |
272 | atomic_notifier_call_chain(&twl->otg.notifier, | ||
273 | status, twl->otg.gadget); | 273 | status, twl->otg.gadget); |
274 | if (twl->asleep) { | ||
275 | regulator_disable(twl->usb3v3); | ||
276 | twl->asleep = 0; | ||
277 | } | ||
274 | } | 278 | } |
275 | } | 279 | } |
276 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); | 280 | sysfs_notify(&twl->dev->kobj, NULL, "vbus"); |
@@ -288,13 +292,17 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) | |||
288 | 292 | ||
289 | if (hw_state & STS_USB_ID) { | 293 | if (hw_state & STS_USB_ID) { |
290 | 294 | ||
295 | regulator_enable(twl->usb3v3); | ||
296 | twl->asleep = 1; | ||
291 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1); | 297 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, 0x1); |
292 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, | 298 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_SET, |
293 | 0x10); | 299 | 0x10); |
294 | status = USB_EVENT_ID; | 300 | status = USB_EVENT_ID; |
295 | twl->otg.default_a = true; | 301 | twl->otg.default_a = true; |
296 | twl->otg.state = OTG_STATE_A_IDLE; | 302 | twl->otg.state = OTG_STATE_A_IDLE; |
297 | blocking_notifier_call_chain(&twl->otg.notifier, status, | 303 | twl->linkstat = status; |
304 | twl->otg.last_event = status; | ||
305 | atomic_notifier_call_chain(&twl->otg.notifier, status, | ||
298 | twl->otg.gadget); | 306 | twl->otg.gadget); |
299 | } else { | 307 | } else { |
300 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, | 308 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_EN_HI_CLR, |
@@ -303,7 +311,6 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) | |||
303 | 0x1); | 311 | 0x1); |
304 | } | 312 | } |
305 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_LATCH_CLR, status); | 313 | twl6030_writeb(twl, TWL_MODULE_USB, USB_ID_INT_LATCH_CLR, status); |
306 | twl->linkstat = status; | ||
307 | 314 | ||
308 | return IRQ_HANDLED; | 315 | return IRQ_HANDLED; |
309 | } | 316 | } |
@@ -395,6 +402,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev) | |||
395 | twl->otg.set_vbus = twl6030_set_vbus; | 402 | twl->otg.set_vbus = twl6030_set_vbus; |
396 | twl->otg.init = twl6030_phy_init; | 403 | twl->otg.init = twl6030_phy_init; |
397 | twl->otg.shutdown = twl6030_phy_shutdown; | 404 | twl->otg.shutdown = twl6030_phy_shutdown; |
405 | twl->otg.set_suspend = twl6030_phy_suspend; | ||
398 | 406 | ||
399 | /* init spinlock for workqueue */ | 407 | /* init spinlock for workqueue */ |
400 | spin_lock_init(&twl->lock); | 408 | spin_lock_init(&twl->lock); |
@@ -411,7 +419,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev) | |||
411 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) | 419 | if (device_create_file(&pdev->dev, &dev_attr_vbus)) |
412 | dev_warn(&pdev->dev, "could not create sysfs file\n"); | 420 | dev_warn(&pdev->dev, "could not create sysfs file\n"); |
413 | 421 | ||
414 | BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier); | 422 | ATOMIC_INIT_NOTIFIER_HEAD(&twl->otg.notifier); |
415 | 423 | ||
416 | twl->irq_enabled = true; | 424 | twl->irq_enabled = true; |
417 | status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, | 425 | status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, |
@@ -437,7 +445,9 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev) | |||
437 | return status; | 445 | return status; |
438 | } | 446 | } |
439 | 447 | ||
448 | twl->asleep = 0; | ||
440 | pdata->phy_init(dev); | 449 | pdata->phy_init(dev); |
450 | twl6030_phy_suspend(&twl->otg, 0); | ||
441 | twl6030_enable_irq(&twl->otg); | 451 | twl6030_enable_irq(&twl->otg); |
442 | dev_info(&pdev->dev, "Initialized TWL6030 USB module\n"); | 452 | dev_info(&pdev->dev, "Initialized TWL6030 USB module\n"); |
443 | 453 | ||
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/otg/ulpi_viewport.c new file mode 100644 index 000000000000..e9a37f90994f --- /dev/null +++ b/drivers/usb/otg/ulpi_viewport.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Google, Inc. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/usb.h> | ||
17 | #include <linux/io.h> | ||
18 | #include <linux/usb/otg.h> | ||
19 | #include <linux/usb/ulpi.h> | ||
20 | |||
21 | #define ULPI_VIEW_WAKEUP (1 << 31) | ||
22 | #define ULPI_VIEW_RUN (1 << 30) | ||
23 | #define ULPI_VIEW_WRITE (1 << 29) | ||
24 | #define ULPI_VIEW_READ (0 << 29) | ||
25 | #define ULPI_VIEW_ADDR(x) (((x) & 0xff) << 16) | ||
26 | #define ULPI_VIEW_DATA_READ(x) (((x) >> 8) & 0xff) | ||
27 | #define ULPI_VIEW_DATA_WRITE(x) ((x) & 0xff) | ||
28 | |||
29 | static int ulpi_viewport_wait(void __iomem *view, u32 mask) | ||
30 | { | ||
31 | unsigned long usec = 2000; | ||
32 | |||
33 | while (usec--) { | ||
34 | if (!(readl(view) & mask)) | ||
35 | return 0; | ||
36 | |||
37 | udelay(1); | ||
38 | }; | ||
39 | |||
40 | return -ETIMEDOUT; | ||
41 | } | ||
42 | |||
43 | static int ulpi_viewport_read(struct otg_transceiver *otg, u32 reg) | ||
44 | { | ||
45 | int ret; | ||
46 | void __iomem *view = otg->io_priv; | ||
47 | |||
48 | writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view); | ||
49 | ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP); | ||
50 | if (ret) | ||
51 | return ret; | ||
52 | |||
53 | writel(ULPI_VIEW_RUN | ULPI_VIEW_READ | ULPI_VIEW_ADDR(reg), view); | ||
54 | ret = ulpi_viewport_wait(view, ULPI_VIEW_RUN); | ||
55 | if (ret) | ||
56 | return ret; | ||
57 | |||
58 | return ULPI_VIEW_DATA_READ(readl(view)); | ||
59 | } | ||
60 | |||
61 | static int ulpi_viewport_write(struct otg_transceiver *otg, u32 val, u32 reg) | ||
62 | { | ||
63 | int ret; | ||
64 | void __iomem *view = otg->io_priv; | ||
65 | |||
66 | writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view); | ||
67 | ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP); | ||
68 | if (ret) | ||
69 | return ret; | ||
70 | |||
71 | writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) | | ||
72 | ULPI_VIEW_ADDR(reg), view); | ||
73 | |||
74 | return ulpi_viewport_wait(view, ULPI_VIEW_RUN); | ||
75 | } | ||
76 | |||
77 | struct otg_io_access_ops ulpi_viewport_access_ops = { | ||
78 | .read = ulpi_viewport_read, | ||
79 | .write = ulpi_viewport_write, | ||
80 | }; | ||
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 7b8815ddf368..14ac87ee9251 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c | |||
@@ -75,6 +75,7 @@ static int debug; | |||
75 | static const struct usb_device_id id_table[] = { | 75 | static const struct usb_device_id id_table[] = { |
76 | { USB_DEVICE(0x4348, 0x5523) }, | 76 | { USB_DEVICE(0x4348, 0x5523) }, |
77 | { USB_DEVICE(0x1a86, 0x7523) }, | 77 | { USB_DEVICE(0x1a86, 0x7523) }, |
78 | { USB_DEVICE(0x1a86, 0x5523) }, | ||
78 | { }, | 79 | { }, |
79 | }; | 80 | }; |
80 | MODULE_DEVICE_TABLE(usb, id_table); | 81 | MODULE_DEVICE_TABLE(usb, id_table); |
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index f349a3629d00..a75f9298d88f 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c | |||
@@ -722,6 +722,8 @@ static struct usb_device_id id_table_combined [] = { | |||
722 | { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, | 722 | { USB_DEVICE(FTDI_VID, FTDI_PROPOX_JTAGCABLEII_PID) }, |
723 | { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), | 723 | { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_PID), |
724 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | 724 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, |
725 | { USB_DEVICE(OLIMEX_VID, OLIMEX_ARM_USB_OCD_H_PID), | ||
726 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | ||
725 | { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID), | 727 | { USB_DEVICE(FIC_VID, FIC_NEO1973_DEBUG_PID), |
726 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, | 728 | .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, |
727 | { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID), | 729 | { USB_DEVICE(FTDI_VID, FTDI_OOCDLINK_PID), |
@@ -973,7 +975,7 @@ static __u32 ftdi_2232h_baud_base_to_divisor(int baud, int base) | |||
973 | int divisor3; | 975 | int divisor3; |
974 | 976 | ||
975 | /* hi-speed baud rate is 10-bit sampling instead of 16-bit */ | 977 | /* hi-speed baud rate is 10-bit sampling instead of 16-bit */ |
976 | divisor3 = (base / 10 / baud) * 8; | 978 | divisor3 = base * 8 / (baud * 10); |
977 | 979 | ||
978 | divisor = divisor3 >> 3; | 980 | divisor = divisor3 >> 3; |
979 | divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; | 981 | divisor |= (__u32)divfrac[divisor3 & 0x7] << 14; |
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h index 117e8e6f93c6..c543e55bafba 100644 --- a/drivers/usb/serial/ftdi_sio_ids.h +++ b/drivers/usb/serial/ftdi_sio_ids.h | |||
@@ -730,6 +730,7 @@ | |||
730 | /* Olimex */ | 730 | /* Olimex */ |
731 | #define OLIMEX_VID 0x15BA | 731 | #define OLIMEX_VID 0x15BA |
732 | #define OLIMEX_ARM_USB_OCD_PID 0x0003 | 732 | #define OLIMEX_ARM_USB_OCD_PID 0x0003 |
733 | #define OLIMEX_ARM_USB_OCD_H_PID 0x002b | ||
733 | 734 | ||
734 | /* | 735 | /* |
735 | * Telldus Technologies | 736 | * Telldus Technologies |
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 3b246d93cf22..76e3e502c23d 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c | |||
@@ -2343,7 +2343,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port, | |||
2343 | usb_get_serial_data(edge_port->port->serial); | 2343 | usb_get_serial_data(edge_port->port->serial); |
2344 | int status = 0; | 2344 | int status = 0; |
2345 | struct urb *urb; | 2345 | struct urb *urb; |
2346 | int timeout; | ||
2347 | 2346 | ||
2348 | usb_serial_debug_data(debug, &edge_port->port->dev, | 2347 | usb_serial_debug_data(debug, &edge_port->port->dev, |
2349 | __func__, length, buffer); | 2348 | __func__, length, buffer); |
@@ -2376,8 +2375,6 @@ static int write_cmd_usb(struct edgeport_port *edge_port, | |||
2376 | return status; | 2375 | return status; |
2377 | } | 2376 | } |
2378 | 2377 | ||
2379 | /* wait for command to finish */ | ||
2380 | timeout = COMMAND_TIMEOUT; | ||
2381 | #if 0 | 2378 | #if 0 |
2382 | wait_event(&edge_port->wait_command, !edge_port->commandPending); | 2379 | wait_event(&edge_port->wait_command, !edge_port->commandPending); |
2383 | 2380 | ||
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c index 0791778a66f3..67f41b526570 100644 --- a/drivers/usb/serial/keyspan.c +++ b/drivers/usb/serial/keyspan.c | |||
@@ -2121,16 +2121,16 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial, | |||
2121 | /* Work out which port within the device is being setup */ | 2121 | /* Work out which port within the device is being setup */ |
2122 | device_port = port->number - port->serial->minor; | 2122 | device_port = port->number - port->serial->minor; |
2123 | 2123 | ||
2124 | dbg("%s - endpoint %d port %d (%d)", | 2124 | /* Make sure we have an urb then send the message */ |
2125 | __func__, usb_pipeendpoint(this_urb->pipe), | ||
2126 | port->number, device_port); | ||
2127 | |||
2128 | /* Make sure we have an urb then send the message */ | ||
2129 | if (this_urb == NULL) { | 2125 | if (this_urb == NULL) { |
2130 | dbg("%s - oops no urb for port %d.", __func__, port->number); | 2126 | dbg("%s - oops no urb for port %d.", __func__, port->number); |
2131 | return -1; | 2127 | return -1; |
2132 | } | 2128 | } |
2133 | 2129 | ||
2130 | dbg("%s - endpoint %d port %d (%d)", | ||
2131 | __func__, usb_pipeendpoint(this_urb->pipe), | ||
2132 | port->number, device_port); | ||
2133 | |||
2134 | /* Save reset port val for resend. | 2134 | /* Save reset port val for resend. |
2135 | Don't overwrite resend for open/close condition. */ | 2135 | Don't overwrite resend for open/close condition. */ |
2136 | if ((reset_port + 1) > p_priv->resend_cont) | 2136 | if ((reset_port + 1) > p_priv->resend_cont) |
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c index 554a8693a463..7b690f3282a2 100644 --- a/drivers/usb/serial/keyspan_pda.c +++ b/drivers/usb/serial/keyspan_pda.c | |||
@@ -173,7 +173,8 @@ static void keyspan_pda_wakeup_write(struct work_struct *work) | |||
173 | container_of(work, struct keyspan_pda_private, wakeup_work); | 173 | container_of(work, struct keyspan_pda_private, wakeup_work); |
174 | struct usb_serial_port *port = priv->port; | 174 | struct usb_serial_port *port = priv->port; |
175 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 175 | struct tty_struct *tty = tty_port_tty_get(&port->port); |
176 | tty_wakeup(tty); | 176 | if (tty) |
177 | tty_wakeup(tty); | ||
177 | tty_kref_put(tty); | 178 | tty_kref_put(tty); |
178 | } | 179 | } |
179 | 180 | ||
@@ -206,7 +207,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work) | |||
206 | static void keyspan_pda_rx_interrupt(struct urb *urb) | 207 | static void keyspan_pda_rx_interrupt(struct urb *urb) |
207 | { | 208 | { |
208 | struct usb_serial_port *port = urb->context; | 209 | struct usb_serial_port *port = urb->context; |
209 | struct tty_struct *tty = tty_port_tty_get(&port->port); | 210 | struct tty_struct *tty; |
210 | unsigned char *data = urb->transfer_buffer; | 211 | unsigned char *data = urb->transfer_buffer; |
211 | int retval; | 212 | int retval; |
212 | int status = urb->status; | 213 | int status = urb->status; |
@@ -223,7 +224,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) | |||
223 | /* this urb is terminated, clean up */ | 224 | /* this urb is terminated, clean up */ |
224 | dbg("%s - urb shutting down with status: %d", | 225 | dbg("%s - urb shutting down with status: %d", |
225 | __func__, status); | 226 | __func__, status); |
226 | goto out; | 227 | return; |
227 | default: | 228 | default: |
228 | dbg("%s - nonzero urb status received: %d", | 229 | dbg("%s - nonzero urb status received: %d", |
229 | __func__, status); | 230 | __func__, status); |
@@ -233,12 +234,14 @@ static void keyspan_pda_rx_interrupt(struct urb *urb) | |||
233 | /* see if the message is data or a status interrupt */ | 234 | /* see if the message is data or a status interrupt */ |
234 | switch (data[0]) { | 235 | switch (data[0]) { |
235 | case 0: | 236 | case 0: |
236 | /* rest of message is rx data */ | 237 | tty = tty_port_tty_get(&port->port); |
237 | if (urb->actual_length) { | 238 | /* rest of message is rx data */ |
239 | if (tty && urb->actual_length) { | ||
238 | tty_insert_flip_string(tty, data + 1, | 240 | tty_insert_flip_string(tty, data + 1, |
239 | urb->actual_length - 1); | 241 | urb->actual_length - 1); |
240 | tty_flip_buffer_push(tty); | 242 | tty_flip_buffer_push(tty); |
241 | } | 243 | } |
244 | tty_kref_put(tty); | ||
242 | break; | 245 | break; |
243 | case 1: | 246 | case 1: |
244 | /* status interrupt */ | 247 | /* status interrupt */ |
@@ -265,8 +268,6 @@ exit: | |||
265 | dev_err(&port->dev, | 268 | dev_err(&port->dev, |
266 | "%s - usb_submit_urb failed with result %d", | 269 | "%s - usb_submit_urb failed with result %d", |
267 | __func__, retval); | 270 | __func__, retval); |
268 | out: | ||
269 | tty_kref_put(tty); | ||
270 | } | 271 | } |
271 | 272 | ||
272 | 273 | ||
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index bd5bd8589e04..b382d9a0274d 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -372,7 +372,7 @@ static void kobil_read_int_callback(struct urb *urb) | |||
372 | } | 372 | } |
373 | 373 | ||
374 | tty = tty_port_tty_get(&port->port); | 374 | tty = tty_port_tty_get(&port->port); |
375 | if (urb->actual_length) { | 375 | if (tty && urb->actual_length) { |
376 | 376 | ||
377 | /* BEGIN DEBUG */ | 377 | /* BEGIN DEBUG */ |
378 | /* | 378 | /* |
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c index 2849f8c32015..1e225aacf46e 100644 --- a/drivers/usb/serial/mct_u232.c +++ b/drivers/usb/serial/mct_u232.c | |||
@@ -78,6 +78,8 @@ | |||
78 | #include <asm/unaligned.h> | 78 | #include <asm/unaligned.h> |
79 | #include <linux/usb.h> | 79 | #include <linux/usb.h> |
80 | #include <linux/usb/serial.h> | 80 | #include <linux/usb/serial.h> |
81 | #include <linux/serial.h> | ||
82 | #include <linux/ioctl.h> | ||
81 | #include "mct_u232.h" | 83 | #include "mct_u232.h" |
82 | 84 | ||
83 | /* | 85 | /* |
@@ -104,6 +106,10 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state); | |||
104 | static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file); | 106 | static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file); |
105 | static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file, | 107 | static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file, |
106 | unsigned int set, unsigned int clear); | 108 | unsigned int set, unsigned int clear); |
109 | static int mct_u232_ioctl(struct tty_struct *tty, struct file *file, | ||
110 | unsigned int cmd, unsigned long arg); | ||
111 | static int mct_u232_get_icount(struct tty_struct *tty, | ||
112 | struct serial_icounter_struct *icount); | ||
107 | static void mct_u232_throttle(struct tty_struct *tty); | 113 | static void mct_u232_throttle(struct tty_struct *tty); |
108 | static void mct_u232_unthrottle(struct tty_struct *tty); | 114 | static void mct_u232_unthrottle(struct tty_struct *tty); |
109 | 115 | ||
@@ -150,9 +156,10 @@ static struct usb_serial_driver mct_u232_device = { | |||
150 | .tiocmset = mct_u232_tiocmset, | 156 | .tiocmset = mct_u232_tiocmset, |
151 | .attach = mct_u232_startup, | 157 | .attach = mct_u232_startup, |
152 | .release = mct_u232_release, | 158 | .release = mct_u232_release, |
159 | .ioctl = mct_u232_ioctl, | ||
160 | .get_icount = mct_u232_get_icount, | ||
153 | }; | 161 | }; |
154 | 162 | ||
155 | |||
156 | struct mct_u232_private { | 163 | struct mct_u232_private { |
157 | spinlock_t lock; | 164 | spinlock_t lock; |
158 | unsigned int control_state; /* Modem Line Setting (TIOCM) */ | 165 | unsigned int control_state; /* Modem Line Setting (TIOCM) */ |
@@ -160,6 +167,9 @@ struct mct_u232_private { | |||
160 | unsigned char last_lsr; /* Line Status Register */ | 167 | unsigned char last_lsr; /* Line Status Register */ |
161 | unsigned char last_msr; /* Modem Status Register */ | 168 | unsigned char last_msr; /* Modem Status Register */ |
162 | unsigned int rx_flags; /* Throttling flags */ | 169 | unsigned int rx_flags; /* Throttling flags */ |
170 | struct async_icount icount; | ||
171 | wait_queue_head_t msr_wait; /* for handling sleeping while waiting | ||
172 | for msr change to happen */ | ||
163 | }; | 173 | }; |
164 | 174 | ||
165 | #define THROTTLED 0x01 | 175 | #define THROTTLED 0x01 |
@@ -386,6 +396,20 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial, | |||
386 | return rc; | 396 | return rc; |
387 | } /* mct_u232_get_modem_stat */ | 397 | } /* mct_u232_get_modem_stat */ |
388 | 398 | ||
399 | static void mct_u232_msr_to_icount(struct async_icount *icount, | ||
400 | unsigned char msr) | ||
401 | { | ||
402 | /* Translate Control Line states */ | ||
403 | if (msr & MCT_U232_MSR_DDSR) | ||
404 | icount->dsr++; | ||
405 | if (msr & MCT_U232_MSR_DCTS) | ||
406 | icount->cts++; | ||
407 | if (msr & MCT_U232_MSR_DRI) | ||
408 | icount->rng++; | ||
409 | if (msr & MCT_U232_MSR_DCD) | ||
410 | icount->dcd++; | ||
411 | } /* mct_u232_msr_to_icount */ | ||
412 | |||
389 | static void mct_u232_msr_to_state(unsigned int *control_state, | 413 | static void mct_u232_msr_to_state(unsigned int *control_state, |
390 | unsigned char msr) | 414 | unsigned char msr) |
391 | { | 415 | { |
@@ -422,6 +446,7 @@ static int mct_u232_startup(struct usb_serial *serial) | |||
422 | if (!priv) | 446 | if (!priv) |
423 | return -ENOMEM; | 447 | return -ENOMEM; |
424 | spin_lock_init(&priv->lock); | 448 | spin_lock_init(&priv->lock); |
449 | init_waitqueue_head(&priv->msr_wait); | ||
425 | usb_set_serial_port_data(serial->port[0], priv); | 450 | usb_set_serial_port_data(serial->port[0], priv); |
426 | 451 | ||
427 | init_waitqueue_head(&serial->port[0]->write_wait); | 452 | init_waitqueue_head(&serial->port[0]->write_wait); |
@@ -621,6 +646,8 @@ static void mct_u232_read_int_callback(struct urb *urb) | |||
621 | /* Record Control Line states */ | 646 | /* Record Control Line states */ |
622 | mct_u232_msr_to_state(&priv->control_state, priv->last_msr); | 647 | mct_u232_msr_to_state(&priv->control_state, priv->last_msr); |
623 | 648 | ||
649 | mct_u232_msr_to_icount(&priv->icount, priv->last_msr); | ||
650 | |||
624 | #if 0 | 651 | #if 0 |
625 | /* Not yet handled. See belkin_sa.c for further information */ | 652 | /* Not yet handled. See belkin_sa.c for further information */ |
626 | /* Now to report any errors */ | 653 | /* Now to report any errors */ |
@@ -647,6 +674,7 @@ static void mct_u232_read_int_callback(struct urb *urb) | |||
647 | tty_kref_put(tty); | 674 | tty_kref_put(tty); |
648 | } | 675 | } |
649 | #endif | 676 | #endif |
677 | wake_up_interruptible(&priv->msr_wait); | ||
650 | spin_unlock_irqrestore(&priv->lock, flags); | 678 | spin_unlock_irqrestore(&priv->lock, flags); |
651 | exit: | 679 | exit: |
652 | retval = usb_submit_urb(urb, GFP_ATOMIC); | 680 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
@@ -826,7 +854,6 @@ static void mct_u232_throttle(struct tty_struct *tty) | |||
826 | } | 854 | } |
827 | } | 855 | } |
828 | 856 | ||
829 | |||
830 | static void mct_u232_unthrottle(struct tty_struct *tty) | 857 | static void mct_u232_unthrottle(struct tty_struct *tty) |
831 | { | 858 | { |
832 | struct usb_serial_port *port = tty->driver_data; | 859 | struct usb_serial_port *port = tty->driver_data; |
@@ -847,6 +874,82 @@ static void mct_u232_unthrottle(struct tty_struct *tty) | |||
847 | } | 874 | } |
848 | } | 875 | } |
849 | 876 | ||
877 | static int mct_u232_ioctl(struct tty_struct *tty, struct file *file, | ||
878 | unsigned int cmd, unsigned long arg) | ||
879 | { | ||
880 | DEFINE_WAIT(wait); | ||
881 | struct usb_serial_port *port = tty->driver_data; | ||
882 | struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port); | ||
883 | struct async_icount cnow, cprev; | ||
884 | unsigned long flags; | ||
885 | |||
886 | dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); | ||
887 | |||
888 | switch (cmd) { | ||
889 | |||
890 | case TIOCMIWAIT: | ||
891 | |||
892 | dbg("%s (%d) TIOCMIWAIT", __func__, port->number); | ||
893 | |||
894 | spin_lock_irqsave(&mct_u232_port->lock, flags); | ||
895 | cprev = mct_u232_port->icount; | ||
896 | spin_unlock_irqrestore(&mct_u232_port->lock, flags); | ||
897 | for ( ; ; ) { | ||
898 | prepare_to_wait(&mct_u232_port->msr_wait, | ||
899 | &wait, TASK_INTERRUPTIBLE); | ||
900 | schedule(); | ||
901 | finish_wait(&mct_u232_port->msr_wait, &wait); | ||
902 | /* see if a signal did it */ | ||
903 | if (signal_pending(current)) | ||
904 | return -ERESTARTSYS; | ||
905 | spin_lock_irqsave(&mct_u232_port->lock, flags); | ||
906 | cnow = mct_u232_port->icount; | ||
907 | spin_unlock_irqrestore(&mct_u232_port->lock, flags); | ||
908 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && | ||
909 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) | ||
910 | return -EIO; /* no change => error */ | ||
911 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || | ||
912 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || | ||
913 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || | ||
914 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { | ||
915 | return 0; | ||
916 | } | ||
917 | cprev = cnow; | ||
918 | } | ||
919 | |||
920 | } | ||
921 | return -ENOIOCTLCMD; | ||
922 | } | ||
923 | |||
924 | static int mct_u232_get_icount(struct tty_struct *tty, | ||
925 | struct serial_icounter_struct *icount) | ||
926 | { | ||
927 | struct usb_serial_port *port = tty->driver_data; | ||
928 | struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port); | ||
929 | struct async_icount *ic = &mct_u232_port->icount; | ||
930 | unsigned long flags; | ||
931 | |||
932 | spin_lock_irqsave(&mct_u232_port->lock, flags); | ||
933 | |||
934 | icount->cts = ic->cts; | ||
935 | icount->dsr = ic->dsr; | ||
936 | icount->rng = ic->rng; | ||
937 | icount->dcd = ic->dcd; | ||
938 | icount->rx = ic->rx; | ||
939 | icount->tx = ic->tx; | ||
940 | icount->frame = ic->frame; | ||
941 | icount->overrun = ic->overrun; | ||
942 | icount->parity = ic->parity; | ||
943 | icount->brk = ic->brk; | ||
944 | icount->buf_overrun = ic->buf_overrun; | ||
945 | |||
946 | spin_unlock_irqrestore(&mct_u232_port->lock, flags); | ||
947 | |||
948 | dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", | ||
949 | __func__, port->number, icount->rx, icount->tx); | ||
950 | return 0; | ||
951 | } | ||
952 | |||
850 | static int __init mct_u232_init(void) | 953 | static int __init mct_u232_init(void) |
851 | { | 954 | { |
852 | int retval; | 955 | int retval; |
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 7d3bc9a3e2b6..ae506f4ee29d 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -2052,7 +2052,7 @@ static int mos7720_startup(struct usb_serial *serial) | |||
2052 | struct usb_device *dev; | 2052 | struct usb_device *dev; |
2053 | int i; | 2053 | int i; |
2054 | char data; | 2054 | char data; |
2055 | u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); | 2055 | u16 product; |
2056 | int ret_val; | 2056 | int ret_val; |
2057 | 2057 | ||
2058 | dbg("%s: Entering ..........", __func__); | 2058 | dbg("%s: Entering ..........", __func__); |
@@ -2062,6 +2062,7 @@ static int mos7720_startup(struct usb_serial *serial) | |||
2062 | return -ENODEV; | 2062 | return -ENODEV; |
2063 | } | 2063 | } |
2064 | 2064 | ||
2065 | product = le16_to_cpu(serial->dev->descriptor.idProduct); | ||
2065 | dev = serial->dev; | 2066 | dev = serial->dev; |
2066 | 2067 | ||
2067 | /* | 2068 | /* |
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c index eda1f9266c4e..ce82396fc4e8 100644 --- a/drivers/usb/serial/opticon.c +++ b/drivers/usb/serial/opticon.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Opticon USB barcode to serial driver | 2 | * Opticon USB barcode to serial driver |
3 | * | 3 | * |
4 | * Copyright (C) 2011 Martin Jansen <martin.jansen@opticon.com> | ||
4 | * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de> | 5 | * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de> |
5 | * Copyright (C) 2008 - 2009 Novell Inc. | 6 | * Copyright (C) 2008 - 2009 Novell Inc. |
6 | * | 7 | * |
@@ -21,6 +22,16 @@ | |||
21 | #include <linux/usb/serial.h> | 22 | #include <linux/usb/serial.h> |
22 | #include <linux/uaccess.h> | 23 | #include <linux/uaccess.h> |
23 | 24 | ||
25 | #define CONTROL_RTS 0x02 | ||
26 | #define RESEND_CTS_STATE 0x03 | ||
27 | |||
28 | /* max number of write urbs in flight */ | ||
29 | #define URB_UPPER_LIMIT 8 | ||
30 | |||
31 | /* This driver works for the Opticon 1D barcode reader | ||
32 | * an examples of 1D barcode types are EAN, UPC, Code39, IATA etc.. */ | ||
33 | #define DRIVER_DESC "Opticon USB barcode to serial driver (1D)" | ||
34 | |||
24 | static int debug; | 35 | static int debug; |
25 | 36 | ||
26 | static const struct usb_device_id id_table[] = { | 37 | static const struct usb_device_id id_table[] = { |
@@ -42,13 +53,13 @@ struct opticon_private { | |||
42 | bool throttled; | 53 | bool throttled; |
43 | bool actually_throttled; | 54 | bool actually_throttled; |
44 | bool rts; | 55 | bool rts; |
56 | bool cts; | ||
45 | int outstanding_urbs; | 57 | int outstanding_urbs; |
46 | }; | 58 | }; |
47 | 59 | ||
48 | /* max number of write urbs in flight */ | ||
49 | #define URB_UPPER_LIMIT 4 | ||
50 | 60 | ||
51 | static void opticon_bulk_callback(struct urb *urb) | 61 | |
62 | static void opticon_read_bulk_callback(struct urb *urb) | ||
52 | { | 63 | { |
53 | struct opticon_private *priv = urb->context; | 64 | struct opticon_private *priv = urb->context; |
54 | unsigned char *data = urb->transfer_buffer; | 65 | unsigned char *data = urb->transfer_buffer; |
@@ -57,6 +68,7 @@ static void opticon_bulk_callback(struct urb *urb) | |||
57 | struct tty_struct *tty; | 68 | struct tty_struct *tty; |
58 | int result; | 69 | int result; |
59 | int data_length; | 70 | int data_length; |
71 | unsigned long flags; | ||
60 | 72 | ||
61 | dbg("%s - port %d", __func__, port->number); | 73 | dbg("%s - port %d", __func__, port->number); |
62 | 74 | ||
@@ -87,10 +99,10 @@ static void opticon_bulk_callback(struct urb *urb) | |||
87 | * Data from the device comes with a 2 byte header: | 99 | * Data from the device comes with a 2 byte header: |
88 | * | 100 | * |
89 | * <0x00><0x00>data... | 101 | * <0x00><0x00>data... |
90 | * This is real data to be sent to the tty layer | 102 | * This is real data to be sent to the tty layer |
91 | * <0x00><0x01)level | 103 | * <0x00><0x01)level |
92 | * This is a RTS level change, the third byte is the RTS | 104 | * This is a CTS level change, the third byte is the CTS |
93 | * value (0 for low, 1 for high). | 105 | * value (0 for low, 1 for high). |
94 | */ | 106 | */ |
95 | if ((data[0] == 0x00) && (data[1] == 0x00)) { | 107 | if ((data[0] == 0x00) && (data[1] == 0x00)) { |
96 | /* real data, send it to the tty layer */ | 108 | /* real data, send it to the tty layer */ |
@@ -103,10 +115,13 @@ static void opticon_bulk_callback(struct urb *urb) | |||
103 | } | 115 | } |
104 | } else { | 116 | } else { |
105 | if ((data[0] == 0x00) && (data[1] == 0x01)) { | 117 | if ((data[0] == 0x00) && (data[1] == 0x01)) { |
118 | spin_lock_irqsave(&priv->lock, flags); | ||
119 | /* CTS status infomation package */ | ||
106 | if (data[2] == 0x00) | 120 | if (data[2] == 0x00) |
107 | priv->rts = false; | 121 | priv->cts = false; |
108 | else | 122 | else |
109 | priv->rts = true; | 123 | priv->cts = true; |
124 | spin_unlock_irqrestore(&priv->lock, flags); | ||
110 | } else { | 125 | } else { |
111 | dev_dbg(&priv->udev->dev, | 126 | dev_dbg(&priv->udev->dev, |
112 | "Unknown data packet received from the device:" | 127 | "Unknown data packet received from the device:" |
@@ -129,7 +144,7 @@ exit: | |||
129 | usb_rcvbulkpipe(priv->udev, | 144 | usb_rcvbulkpipe(priv->udev, |
130 | priv->bulk_address), | 145 | priv->bulk_address), |
131 | priv->bulk_in_buffer, priv->buffer_size, | 146 | priv->bulk_in_buffer, priv->buffer_size, |
132 | opticon_bulk_callback, priv); | 147 | opticon_read_bulk_callback, priv); |
133 | result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC); | 148 | result = usb_submit_urb(priv->bulk_read_urb, GFP_ATOMIC); |
134 | if (result) | 149 | if (result) |
135 | dev_err(&port->dev, | 150 | dev_err(&port->dev, |
@@ -140,6 +155,24 @@ exit: | |||
140 | spin_unlock(&priv->lock); | 155 | spin_unlock(&priv->lock); |
141 | } | 156 | } |
142 | 157 | ||
158 | static int send_control_msg(struct usb_serial_port *port, u8 requesttype, | ||
159 | u8 val) | ||
160 | { | ||
161 | struct usb_serial *serial = port->serial; | ||
162 | int retval; | ||
163 | u8 buffer[2]; | ||
164 | |||
165 | buffer[0] = val; | ||
166 | /* Send the message to the vendor control endpoint | ||
167 | * of the connected device */ | ||
168 | retval = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), | ||
169 | requesttype, | ||
170 | USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE, | ||
171 | 0, 0, buffer, 1, 0); | ||
172 | |||
173 | return retval; | ||
174 | } | ||
175 | |||
143 | static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) | 176 | static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) |
144 | { | 177 | { |
145 | struct opticon_private *priv = usb_get_serial_data(port->serial); | 178 | struct opticon_private *priv = usb_get_serial_data(port->serial); |
@@ -152,19 +185,30 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
152 | priv->throttled = false; | 185 | priv->throttled = false; |
153 | priv->actually_throttled = false; | 186 | priv->actually_throttled = false; |
154 | priv->port = port; | 187 | priv->port = port; |
188 | priv->rts = false; | ||
155 | spin_unlock_irqrestore(&priv->lock, flags); | 189 | spin_unlock_irqrestore(&priv->lock, flags); |
156 | 190 | ||
157 | /* Start reading from the device */ | 191 | /* Clear RTS line */ |
192 | send_control_msg(port, CONTROL_RTS, 0); | ||
193 | |||
194 | /* Setup the read URB and start reading from the device */ | ||
158 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, | 195 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, |
159 | usb_rcvbulkpipe(priv->udev, | 196 | usb_rcvbulkpipe(priv->udev, |
160 | priv->bulk_address), | 197 | priv->bulk_address), |
161 | priv->bulk_in_buffer, priv->buffer_size, | 198 | priv->bulk_in_buffer, priv->buffer_size, |
162 | opticon_bulk_callback, priv); | 199 | opticon_read_bulk_callback, priv); |
200 | |||
201 | /* clear the halt status of the enpoint */ | ||
202 | usb_clear_halt(priv->udev, priv->bulk_read_urb->pipe); | ||
203 | |||
163 | result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL); | 204 | result = usb_submit_urb(priv->bulk_read_urb, GFP_KERNEL); |
164 | if (result) | 205 | if (result) |
165 | dev_err(&port->dev, | 206 | dev_err(&port->dev, |
166 | "%s - failed resubmitting read urb, error %d\n", | 207 | "%s - failed resubmitting read urb, error %d\n", |
167 | __func__, result); | 208 | __func__, result); |
209 | /* Request CTS line state, sometimes during opening the current | ||
210 | * CTS state can be missed. */ | ||
211 | send_control_msg(port, RESEND_CTS_STATE, 1); | ||
168 | return result; | 212 | return result; |
169 | } | 213 | } |
170 | 214 | ||
@@ -178,7 +222,7 @@ static void opticon_close(struct usb_serial_port *port) | |||
178 | usb_kill_urb(priv->bulk_read_urb); | 222 | usb_kill_urb(priv->bulk_read_urb); |
179 | } | 223 | } |
180 | 224 | ||
181 | static void opticon_write_bulk_callback(struct urb *urb) | 225 | static void opticon_write_control_callback(struct urb *urb) |
182 | { | 226 | { |
183 | struct opticon_private *priv = urb->context; | 227 | struct opticon_private *priv = urb->context; |
184 | int status = urb->status; | 228 | int status = urb->status; |
@@ -210,6 +254,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
210 | unsigned char *buffer; | 254 | unsigned char *buffer; |
211 | unsigned long flags; | 255 | unsigned long flags; |
212 | int status; | 256 | int status; |
257 | struct usb_ctrlrequest *dr; | ||
213 | 258 | ||
214 | dbg("%s - port %d", __func__, port->number); | 259 | dbg("%s - port %d", __func__, port->number); |
215 | 260 | ||
@@ -226,6 +271,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
226 | if (!buffer) { | 271 | if (!buffer) { |
227 | dev_err(&port->dev, "out of memory\n"); | 272 | dev_err(&port->dev, "out of memory\n"); |
228 | count = -ENOMEM; | 273 | count = -ENOMEM; |
274 | |||
229 | goto error_no_buffer; | 275 | goto error_no_buffer; |
230 | } | 276 | } |
231 | 277 | ||
@@ -240,35 +286,28 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
240 | 286 | ||
241 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); | 287 | usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); |
242 | 288 | ||
243 | if (port->bulk_out_endpointAddress) { | 289 | /* The conncected devices do not have a bulk write endpoint, |
244 | usb_fill_bulk_urb(urb, serial->dev, | 290 | * to transmit data to de barcode device the control endpoint is used */ |
245 | usb_sndbulkpipe(serial->dev, | 291 | dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); |
246 | port->bulk_out_endpointAddress), | 292 | if (!dr) |
247 | buffer, count, opticon_write_bulk_callback, priv); | 293 | return -ENOMEM; |
248 | } else { | 294 | |
249 | struct usb_ctrlrequest *dr; | 295 | dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT; |
250 | 296 | dr->bRequest = 0x01; | |
251 | dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); | 297 | dr->wValue = 0; |
252 | if (!dr) | 298 | dr->wIndex = 0; |
253 | return -ENOMEM; | 299 | dr->wLength = cpu_to_le16(count); |
254 | 300 | ||
255 | dr->bRequestType = USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT; | 301 | usb_fill_control_urb(urb, serial->dev, |
256 | dr->bRequest = 0x01; | 302 | usb_sndctrlpipe(serial->dev, 0), |
257 | dr->wValue = 0; | 303 | (unsigned char *)dr, buffer, count, |
258 | dr->wIndex = 0; | 304 | opticon_write_control_callback, priv); |
259 | dr->wLength = cpu_to_le16(count); | ||
260 | |||
261 | usb_fill_control_urb(urb, serial->dev, | ||
262 | usb_sndctrlpipe(serial->dev, 0), | ||
263 | (unsigned char *)dr, buffer, count, | ||
264 | opticon_write_bulk_callback, priv); | ||
265 | } | ||
266 | 305 | ||
267 | /* send it down the pipe */ | 306 | /* send it down the pipe */ |
268 | status = usb_submit_urb(urb, GFP_ATOMIC); | 307 | status = usb_submit_urb(urb, GFP_ATOMIC); |
269 | if (status) { | 308 | if (status) { |
270 | dev_err(&port->dev, | 309 | dev_err(&port->dev, |
271 | "%s - usb_submit_urb(write bulk) failed with status = %d\n", | 310 | "%s - usb_submit_urb(write endpoint) failed status = %d\n", |
272 | __func__, status); | 311 | __func__, status); |
273 | count = status; | 312 | count = status; |
274 | goto error; | 313 | goto error; |
@@ -360,16 +399,49 @@ static int opticon_tiocmget(struct tty_struct *tty, struct file *file) | |||
360 | int result = 0; | 399 | int result = 0; |
361 | 400 | ||
362 | dbg("%s - port %d", __func__, port->number); | 401 | dbg("%s - port %d", __func__, port->number); |
402 | if (!usb_get_intfdata(port->serial->interface)) | ||
403 | return -ENODEV; | ||
363 | 404 | ||
364 | spin_lock_irqsave(&priv->lock, flags); | 405 | spin_lock_irqsave(&priv->lock, flags); |
365 | if (priv->rts) | 406 | if (priv->rts) |
366 | result = TIOCM_RTS; | 407 | result |= TIOCM_RTS; |
408 | if (priv->cts) | ||
409 | result |= TIOCM_CTS; | ||
367 | spin_unlock_irqrestore(&priv->lock, flags); | 410 | spin_unlock_irqrestore(&priv->lock, flags); |
368 | 411 | ||
369 | dbg("%s - %x", __func__, result); | 412 | dbg("%s - %x", __func__, result); |
370 | return result; | 413 | return result; |
371 | } | 414 | } |
372 | 415 | ||
416 | static int opticon_tiocmset(struct tty_struct *tty, struct file *file, | ||
417 | unsigned int set, unsigned int clear) | ||
418 | { | ||
419 | struct usb_serial_port *port = tty->driver_data; | ||
420 | struct opticon_private *priv = usb_get_serial_data(port->serial); | ||
421 | unsigned long flags; | ||
422 | bool rts; | ||
423 | bool changed = false; | ||
424 | |||
425 | if (!usb_get_intfdata(port->serial->interface)) | ||
426 | return -ENODEV; | ||
427 | /* We only support RTS so we only handle that */ | ||
428 | spin_lock_irqsave(&priv->lock, flags); | ||
429 | |||
430 | rts = priv->rts; | ||
431 | if (set & TIOCM_RTS) | ||
432 | priv->rts = true; | ||
433 | if (clear & TIOCM_RTS) | ||
434 | priv->rts = false; | ||
435 | changed = rts ^ priv->rts; | ||
436 | spin_unlock_irqrestore(&priv->lock, flags); | ||
437 | |||
438 | if (!changed) | ||
439 | return 0; | ||
440 | |||
441 | /* Send the new RTS state to the connected device */ | ||
442 | return send_control_msg(port, CONTROL_RTS, !rts); | ||
443 | } | ||
444 | |||
373 | static int get_serial_info(struct opticon_private *priv, | 445 | static int get_serial_info(struct opticon_private *priv, |
374 | struct serial_struct __user *serial) | 446 | struct serial_struct __user *serial) |
375 | { | 447 | { |
@@ -431,6 +503,7 @@ static int opticon_startup(struct usb_serial *serial) | |||
431 | priv->serial = serial; | 503 | priv->serial = serial; |
432 | priv->port = serial->port[0]; | 504 | priv->port = serial->port[0]; |
433 | priv->udev = serial->dev; | 505 | priv->udev = serial->dev; |
506 | priv->outstanding_urbs = 0; /* Init the outstanding urbs */ | ||
434 | 507 | ||
435 | /* find our bulk endpoint */ | 508 | /* find our bulk endpoint */ |
436 | intf = serial->interface->altsetting; | 509 | intf = serial->interface->altsetting; |
@@ -456,13 +529,6 @@ static int opticon_startup(struct usb_serial *serial) | |||
456 | 529 | ||
457 | priv->bulk_address = endpoint->bEndpointAddress; | 530 | priv->bulk_address = endpoint->bEndpointAddress; |
458 | 531 | ||
459 | /* set up our bulk urb */ | ||
460 | usb_fill_bulk_urb(priv->bulk_read_urb, priv->udev, | ||
461 | usb_rcvbulkpipe(priv->udev, | ||
462 | endpoint->bEndpointAddress), | ||
463 | priv->bulk_in_buffer, priv->buffer_size, | ||
464 | opticon_bulk_callback, priv); | ||
465 | |||
466 | bulk_in_found = true; | 532 | bulk_in_found = true; |
467 | break; | 533 | break; |
468 | } | 534 | } |
@@ -558,6 +624,7 @@ static struct usb_serial_driver opticon_device = { | |||
558 | .unthrottle = opticon_unthrottle, | 624 | .unthrottle = opticon_unthrottle, |
559 | .ioctl = opticon_ioctl, | 625 | .ioctl = opticon_ioctl, |
560 | .tiocmget = opticon_tiocmget, | 626 | .tiocmget = opticon_tiocmget, |
627 | .tiocmset = opticon_tiocmset, | ||
561 | }; | 628 | }; |
562 | 629 | ||
563 | static int __init opticon_init(void) | 630 | static int __init opticon_init(void) |
@@ -581,6 +648,7 @@ static void __exit opticon_exit(void) | |||
581 | 648 | ||
582 | module_init(opticon_init); | 649 | module_init(opticon_init); |
583 | module_exit(opticon_exit); | 650 | module_exit(opticon_exit); |
651 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
584 | MODULE_LICENSE("GPL"); | 652 | MODULE_LICENSE("GPL"); |
585 | 653 | ||
586 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 654 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 5f46838dfee5..75c7f456eed5 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c | |||
@@ -652,7 +652,8 @@ static const struct usb_device_id option_ids[] = { | |||
652 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) }, | 652 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0028, 0xff, 0xff, 0xff) }, |
653 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) }, | 653 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0029, 0xff, 0xff, 0xff) }, |
654 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) }, | 654 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0030, 0xff, 0xff, 0xff) }, |
655 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff, 0xff, 0xff) }, | 655 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF626, 0xff, |
656 | 0xff, 0xff), .driver_info = (kernel_ulong_t)&four_g_w14_blacklist }, | ||
656 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) }, | 657 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0032, 0xff, 0xff, 0xff) }, |
657 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) }, | 658 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0033, 0xff, 0xff, 0xff) }, |
658 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0034, 0xff, 0xff, 0xff) }, | 659 | { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0034, 0xff, 0xff, 0xff) }, |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index 0457813eebee..5b88b6836a81 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -376,7 +376,10 @@ static int sierra_send_setup(struct usb_serial_port *port) | |||
376 | if (!do_send) | 376 | if (!do_send) |
377 | return 0; | 377 | return 0; |
378 | 378 | ||
379 | usb_autopm_get_interface(serial->interface); | 379 | retval = usb_autopm_get_interface(serial->interface); |
380 | if (retval < 0) | ||
381 | return retval; | ||
382 | |||
380 | retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 383 | retval = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), |
381 | 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); | 384 | 0x22, 0x21, val, interface, NULL, 0, USB_CTRL_SET_TIMEOUT); |
382 | usb_autopm_put_interface(serial->interface); | 385 | usb_autopm_put_interface(serial->interface); |
@@ -811,8 +814,12 @@ static void sierra_close(struct usb_serial_port *port) | |||
811 | mutex_lock(&serial->disc_mutex); | 814 | mutex_lock(&serial->disc_mutex); |
812 | if (!serial->disconnected) { | 815 | if (!serial->disconnected) { |
813 | serial->interface->needs_remote_wakeup = 0; | 816 | serial->interface->needs_remote_wakeup = 0; |
814 | usb_autopm_get_interface(serial->interface); | 817 | /* odd error handling due to pm counters */ |
815 | sierra_send_setup(port); | 818 | if (!usb_autopm_get_interface(serial->interface)) |
819 | sierra_send_setup(port); | ||
820 | else | ||
821 | usb_autopm_get_interface_no_resume(serial->interface); | ||
822 | |||
816 | } | 823 | } |
817 | mutex_unlock(&serial->disc_mutex); | 824 | mutex_unlock(&serial->disc_mutex); |
818 | spin_lock_irq(&intfdata->susp_lock); | 825 | spin_lock_irq(&intfdata->susp_lock); |
@@ -865,7 +872,8 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
865 | /* get rid of everything as in close */ | 872 | /* get rid of everything as in close */ |
866 | sierra_close(port); | 873 | sierra_close(port); |
867 | /* restore balance for autopm */ | 874 | /* restore balance for autopm */ |
868 | usb_autopm_put_interface(serial->interface); | 875 | if (!serial->disconnected) |
876 | usb_autopm_put_interface(serial->interface); | ||
869 | return err; | 877 | return err; |
870 | } | 878 | } |
871 | sierra_send_setup(port); | 879 | sierra_send_setup(port); |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 546a52179bec..2ff90a9c8f47 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -911,9 +911,8 @@ int usb_serial_probe(struct usb_interface *interface, | |||
911 | dev_err(&interface->dev, "No free urbs available\n"); | 911 | dev_err(&interface->dev, "No free urbs available\n"); |
912 | goto probe_error; | 912 | goto probe_error; |
913 | } | 913 | } |
914 | buffer_size = serial->type->bulk_in_size; | 914 | buffer_size = max_t(int, serial->type->bulk_in_size, |
915 | if (!buffer_size) | 915 | le16_to_cpu(endpoint->wMaxPacketSize)); |
916 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | ||
917 | port->bulk_in_size = buffer_size; | 916 | port->bulk_in_size = buffer_size; |
918 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; | 917 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; |
919 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); | 918 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); |
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c index 9c014e2ecd68..eb95aecc0015 100644 --- a/drivers/usb/serial/usb_wwan.c +++ b/drivers/usb/serial/usb_wwan.c | |||
@@ -261,7 +261,8 @@ int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
261 | intfdata->in_flight--; | 261 | intfdata->in_flight--; |
262 | spin_unlock_irqrestore(&intfdata->susp_lock, | 262 | spin_unlock_irqrestore(&intfdata->susp_lock, |
263 | flags); | 263 | flags); |
264 | continue; | 264 | usb_autopm_put_interface_async(port->serial->interface); |
265 | break; | ||
265 | } | 266 | } |
266 | } | 267 | } |
267 | 268 | ||
@@ -308,11 +309,16 @@ static void usb_wwan_indat_callback(struct urb *urb) | |||
308 | /* Resubmit urb so we continue receiving */ | 309 | /* Resubmit urb so we continue receiving */ |
309 | if (status != -ESHUTDOWN) { | 310 | if (status != -ESHUTDOWN) { |
310 | err = usb_submit_urb(urb, GFP_ATOMIC); | 311 | err = usb_submit_urb(urb, GFP_ATOMIC); |
311 | if (err && err != -EPERM) | 312 | if (err) { |
312 | printk(KERN_ERR "%s: resubmit read urb failed. " | 313 | if (err != -EPERM) { |
313 | "(%d)", __func__, err); | 314 | printk(KERN_ERR "%s: resubmit read urb failed. " |
314 | else | 315 | "(%d)", __func__, err); |
316 | /* busy also in error unless we are killed */ | ||
317 | usb_mark_last_busy(port->serial->dev); | ||
318 | } | ||
319 | } else { | ||
315 | usb_mark_last_busy(port->serial->dev); | 320 | usb_mark_last_busy(port->serial->dev); |
321 | } | ||
316 | } | 322 | } |
317 | 323 | ||
318 | } | 324 | } |
@@ -421,6 +427,7 @@ int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
421 | spin_lock_irq(&intfdata->susp_lock); | 427 | spin_lock_irq(&intfdata->susp_lock); |
422 | portdata->opened = 1; | 428 | portdata->opened = 1; |
423 | spin_unlock_irq(&intfdata->susp_lock); | 429 | spin_unlock_irq(&intfdata->susp_lock); |
430 | /* this balances a get in the generic USB serial code */ | ||
424 | usb_autopm_put_interface(serial->interface); | 431 | usb_autopm_put_interface(serial->interface); |
425 | 432 | ||
426 | return 0; | 433 | return 0; |
@@ -447,7 +454,8 @@ void usb_wwan_close(struct usb_serial_port *port) | |||
447 | usb_kill_urb(portdata->in_urbs[i]); | 454 | usb_kill_urb(portdata->in_urbs[i]); |
448 | for (i = 0; i < N_OUT_URB; i++) | 455 | for (i = 0; i < N_OUT_URB; i++) |
449 | usb_kill_urb(portdata->out_urbs[i]); | 456 | usb_kill_urb(portdata->out_urbs[i]); |
450 | usb_autopm_get_interface(serial->interface); | 457 | /* balancing - important as an error cannot be handled*/ |
458 | usb_autopm_get_interface_no_resume(serial->interface); | ||
451 | serial->interface->needs_remote_wakeup = 0; | 459 | serial->interface->needs_remote_wakeup = 0; |
452 | } | 460 | } |
453 | } | 461 | } |
@@ -661,6 +669,18 @@ int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) | |||
661 | } | 669 | } |
662 | EXPORT_SYMBOL(usb_wwan_suspend); | 670 | EXPORT_SYMBOL(usb_wwan_suspend); |
663 | 671 | ||
672 | static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata) | ||
673 | { | ||
674 | int i; | ||
675 | |||
676 | for (i = 0; i < N_OUT_URB; i++) { | ||
677 | if (urb == portdata->out_urbs[i]) { | ||
678 | clear_bit(i, &portdata->out_busy); | ||
679 | break; | ||
680 | } | ||
681 | } | ||
682 | } | ||
683 | |||
664 | static void play_delayed(struct usb_serial_port *port) | 684 | static void play_delayed(struct usb_serial_port *port) |
665 | { | 685 | { |
666 | struct usb_wwan_intf_private *data; | 686 | struct usb_wwan_intf_private *data; |
@@ -672,8 +692,17 @@ static void play_delayed(struct usb_serial_port *port) | |||
672 | data = port->serial->private; | 692 | data = port->serial->private; |
673 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { | 693 | while ((urb = usb_get_from_anchor(&portdata->delayed))) { |
674 | err = usb_submit_urb(urb, GFP_ATOMIC); | 694 | err = usb_submit_urb(urb, GFP_ATOMIC); |
675 | if (!err) | 695 | if (!err) { |
676 | data->in_flight++; | 696 | data->in_flight++; |
697 | } else { | ||
698 | /* we have to throw away the rest */ | ||
699 | do { | ||
700 | unbusy_queued_urb(urb, portdata); | ||
701 | //extremely dirty | ||
702 | atomic_dec(&port->serial->interface->dev.power.usage_count); | ||
703 | } while ((urb = usb_get_from_anchor(&portdata->delayed))); | ||
704 | break; | ||
705 | } | ||
677 | } | 706 | } |
678 | } | 707 | } |
679 | 708 | ||
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig index 49a489e03716..353aeb44da6a 100644 --- a/drivers/usb/storage/Kconfig +++ b/drivers/usb/storage/Kconfig | |||
@@ -31,6 +31,16 @@ config USB_STORAGE_DEBUG | |||
31 | Say Y here in order to have the USB Mass Storage code generate | 31 | Say Y here in order to have the USB Mass Storage code generate |
32 | verbose debugging messages. | 32 | verbose debugging messages. |
33 | 33 | ||
34 | config USB_STORAGE_REALTEK | ||
35 | tristate "Realtek Card Reader support" | ||
36 | depends on USB_STORAGE | ||
37 | help | ||
38 | Say Y here to include additional code to support the power-saving function | ||
39 | for Realtek RTS51xx USB card readers. | ||
40 | |||
41 | If this driver is compiled as a module, it will be named ums-realtek. | ||
42 | |||
43 | |||
34 | config USB_STORAGE_DATAFAB | 44 | config USB_STORAGE_DATAFAB |
35 | tristate "Datafab Compact Flash Reader support" | 45 | tristate "Datafab Compact Flash Reader support" |
36 | depends on USB_STORAGE | 46 | depends on USB_STORAGE |
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile index fcf14cdc4a04..0d2de971bd91 100644 --- a/drivers/usb/storage/Makefile +++ b/drivers/usb/storage/Makefile | |||
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o | |||
30 | obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o | 30 | obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o |
31 | obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o | 31 | obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o |
32 | obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o | 32 | obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o |
33 | obj-$(CONFIG_USB_STORAGE_REALTEK) += ums-realtek.o | ||
33 | obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o | 34 | obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o |
34 | obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o | 35 | obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o |
35 | obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o | 36 | obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o |
@@ -42,6 +43,7 @@ ums-isd200-y := isd200.o | |||
42 | ums-jumpshot-y := jumpshot.o | 43 | ums-jumpshot-y := jumpshot.o |
43 | ums-karma-y := karma.o | 44 | ums-karma-y := karma.o |
44 | ums-onetouch-y := onetouch.o | 45 | ums-onetouch-y := onetouch.o |
46 | ums-realtek-y := realtek_cr.o | ||
45 | ums-sddr09-y := sddr09.o | 47 | ums-sddr09-y := sddr09.o |
46 | ums-sddr55-y := sddr55.o | 48 | ums-sddr55-y := sddr55.o |
47 | ums-usbat-y := shuttle_usbat.o | 49 | ums-usbat-y := shuttle_usbat.o |
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c new file mode 100644 index 000000000000..d509a4a7d74f --- /dev/null +++ b/drivers/usb/storage/realtek_cr.c | |||
@@ -0,0 +1,675 @@ | |||
1 | /* Driver for Realtek RTS51xx USB card reader | ||
2 | * | ||
3 | * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2, or (at your option) any | ||
8 | * later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * Author: | ||
19 | * wwang (wei_wang@realsil.com.cn) | ||
20 | * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/blkdev.h> | ||
25 | #include <linux/kthread.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/workqueue.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/version.h> | ||
30 | |||
31 | #include <scsi/scsi.h> | ||
32 | #include <scsi/scsi_cmnd.h> | ||
33 | #include <scsi/scsi_device.h> | ||
34 | #include <linux/cdrom.h> | ||
35 | |||
36 | #include <linux/usb.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/usb_usual.h> | ||
39 | |||
40 | #include "usb.h" | ||
41 | #include "transport.h" | ||
42 | #include "protocol.h" | ||
43 | #include "debug.h" | ||
44 | |||
45 | MODULE_DESCRIPTION("Driver for Realtek USB Card Reader"); | ||
46 | MODULE_AUTHOR("wwang <wei_wang@realsil.com.cn>"); | ||
47 | MODULE_LICENSE("GPL"); | ||
48 | MODULE_VERSION("1.03"); | ||
49 | |||
50 | static int auto_delink_en = 1; | ||
51 | module_param(auto_delink_en, int, S_IRUGO | S_IWUSR); | ||
52 | MODULE_PARM_DESC(auto_delink_en, "enable auto delink"); | ||
53 | |||
54 | struct rts51x_status { | ||
55 | u16 vid; | ||
56 | u16 pid; | ||
57 | u8 cur_lun; | ||
58 | u8 card_type; | ||
59 | u8 total_lun; | ||
60 | u16 fw_ver; | ||
61 | u8 phy_exist; | ||
62 | u8 multi_flag; | ||
63 | u8 multi_card; | ||
64 | u8 log_exist; | ||
65 | union { | ||
66 | u8 detailed_type1; | ||
67 | u8 detailed_type2; | ||
68 | } detailed_type; | ||
69 | u8 function[2]; | ||
70 | }; | ||
71 | |||
72 | struct rts51x_chip { | ||
73 | u16 vendor_id; | ||
74 | u16 product_id; | ||
75 | char max_lun; | ||
76 | |||
77 | struct rts51x_status *status; | ||
78 | int status_len; | ||
79 | |||
80 | u32 flag; | ||
81 | }; | ||
82 | |||
83 | /* flag definition */ | ||
84 | #define FLIDX_AUTO_DELINK 0x01 | ||
85 | |||
86 | #define SCSI_LUN(srb) ((srb)->device->lun) | ||
87 | |||
88 | /* Bit Operation */ | ||
89 | #define SET_BIT(data, idx) ((data) |= 1 << (idx)) | ||
90 | #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx))) | ||
91 | #define CHK_BIT(data, idx) ((data) & (1 << (idx))) | ||
92 | |||
93 | #define SET_AUTO_DELINK(chip) ((chip)->flag |= FLIDX_AUTO_DELINK) | ||
94 | #define CLR_AUTO_DELINK(chip) ((chip)->flag &= ~FLIDX_AUTO_DELINK) | ||
95 | #define CHK_AUTO_DELINK(chip) ((chip)->flag & FLIDX_AUTO_DELINK) | ||
96 | |||
97 | #define RTS51X_GET_VID(chip) ((chip)->vendor_id) | ||
98 | #define RTS51X_GET_PID(chip) ((chip)->product_id) | ||
99 | |||
100 | #define FW_VERSION(chip) ((chip)->status[0].fw_ver) | ||
101 | #define STATUS_LEN(chip) ((chip)->status_len) | ||
102 | |||
103 | /* Check card reader function */ | ||
104 | #define SUPPORT_DETAILED_TYPE1(chip) \ | ||
105 | CHK_BIT((chip)->status[0].function[0], 1) | ||
106 | #define SUPPORT_OT(chip) \ | ||
107 | CHK_BIT((chip)->status[0].function[0], 2) | ||
108 | #define SUPPORT_OC(chip) \ | ||
109 | CHK_BIT((chip)->status[0].function[0], 3) | ||
110 | #define SUPPORT_AUTO_DELINK(chip) \ | ||
111 | CHK_BIT((chip)->status[0].function[0], 4) | ||
112 | #define SUPPORT_SDIO(chip) \ | ||
113 | CHK_BIT((chip)->status[0].function[1], 0) | ||
114 | #define SUPPORT_DETAILED_TYPE2(chip) \ | ||
115 | CHK_BIT((chip)->status[0].function[1], 1) | ||
116 | |||
117 | #define CHECK_PID(chip, pid) (RTS51X_GET_PID(chip) == (pid)) | ||
118 | #define CHECK_FW_VER(chip, fw_ver) (FW_VERSION(chip) == (fw_ver)) | ||
119 | #define CHECK_ID(chip, pid, fw_ver) \ | ||
120 | (CHECK_PID((chip), (pid)) && CHECK_FW_VER((chip), (fw_ver))) | ||
121 | |||
122 | #define wait_timeout_x(task_state, msecs) \ | ||
123 | do { \ | ||
124 | set_current_state((task_state)); \ | ||
125 | schedule_timeout((msecs) * HZ / 1000); \ | ||
126 | } while (0) | ||
127 | |||
128 | #define wait_timeout(msecs) \ | ||
129 | wait_timeout_x(TASK_INTERRUPTIBLE, (msecs)) | ||
130 | |||
131 | static int init_realtek_cr(struct us_data *us); | ||
132 | |||
133 | /* | ||
134 | * The table of devices | ||
135 | */ | ||
136 | #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ | ||
137 | vendorName, productName, useProtocol, useTransport, \ | ||
138 | initFunction, flags) \ | ||
139 | {\ | ||
140 | USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ | ||
141 | .driver_info = (flags)|(USB_US_TYPE_STOR<<24)\ | ||
142 | } | ||
143 | |||
144 | static const struct usb_device_id realtek_cr_ids[] = { | ||
145 | # include "unusual_realtek.h" | ||
146 | { } /* Terminating entry */ | ||
147 | }; | ||
148 | MODULE_DEVICE_TABLE(usb, realtek_cr_ids); | ||
149 | |||
150 | #undef UNUSUAL_DEV | ||
151 | |||
152 | /* | ||
153 | * The flags table | ||
154 | */ | ||
155 | #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \ | ||
156 | vendor_name, product_name, use_protocol, use_transport, \ | ||
157 | init_function, Flags) \ | ||
158 | { \ | ||
159 | .vendorName = vendor_name, \ | ||
160 | .productName = product_name, \ | ||
161 | .useProtocol = use_protocol, \ | ||
162 | .useTransport = use_transport, \ | ||
163 | .initFunction = init_function, \ | ||
164 | } | ||
165 | |||
166 | static struct us_unusual_dev realtek_cr_unusual_dev_list[] = { | ||
167 | # include "unusual_realtek.h" | ||
168 | { } /* Terminating entry */ | ||
169 | }; | ||
170 | |||
171 | #undef UNUSUAL_DEV | ||
172 | |||
173 | static int rts51x_bulk_transport(struct us_data *us, u8 lun, | ||
174 | u8 *cmd, int cmd_len, u8 *buf, int buf_len, | ||
175 | enum dma_data_direction dir, int *act_len) | ||
176 | { | ||
177 | struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; | ||
178 | struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; | ||
179 | int result; | ||
180 | unsigned int residue; | ||
181 | unsigned int cswlen; | ||
182 | unsigned int cbwlen = US_BULK_CB_WRAP_LEN; | ||
183 | |||
184 | /* set up the command wrapper */ | ||
185 | bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); | ||
186 | bcb->DataTransferLength = cpu_to_le32(buf_len); | ||
187 | bcb->Flags = (dir == DMA_FROM_DEVICE) ? 1 << 7 : 0; | ||
188 | bcb->Tag = ++us->tag; | ||
189 | bcb->Lun = lun; | ||
190 | bcb->Length = cmd_len; | ||
191 | |||
192 | /* copy the command payload */ | ||
193 | memset(bcb->CDB, 0, sizeof(bcb->CDB)); | ||
194 | memcpy(bcb->CDB, cmd, bcb->Length); | ||
195 | |||
196 | /* send it to out endpoint */ | ||
197 | result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, | ||
198 | bcb, cbwlen, NULL); | ||
199 | if (result != USB_STOR_XFER_GOOD) | ||
200 | return USB_STOR_TRANSPORT_ERROR; | ||
201 | |||
202 | /* DATA STAGE */ | ||
203 | /* send/receive data payload, if there is any */ | ||
204 | |||
205 | if (buf && buf_len) { | ||
206 | unsigned int pipe = (dir == DMA_FROM_DEVICE) ? | ||
207 | us->recv_bulk_pipe : us->send_bulk_pipe; | ||
208 | result = usb_stor_bulk_transfer_buf(us, pipe, | ||
209 | buf, buf_len, NULL); | ||
210 | if (result == USB_STOR_XFER_ERROR) | ||
211 | return USB_STOR_TRANSPORT_ERROR; | ||
212 | } | ||
213 | |||
214 | /* get CSW for device status */ | ||
215 | result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, | ||
216 | bcs, US_BULK_CS_WRAP_LEN, &cswlen); | ||
217 | if (result != USB_STOR_XFER_GOOD) | ||
218 | return USB_STOR_TRANSPORT_ERROR; | ||
219 | |||
220 | /* check bulk status */ | ||
221 | if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) { | ||
222 | US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n", | ||
223 | le32_to_cpu(bcs->Signature), | ||
224 | US_BULK_CS_SIGN); | ||
225 | return USB_STOR_TRANSPORT_ERROR; | ||
226 | } | ||
227 | |||
228 | residue = bcs->Residue; | ||
229 | if (bcs->Tag != us->tag) | ||
230 | return USB_STOR_TRANSPORT_ERROR; | ||
231 | |||
232 | /* try to compute the actual residue, based on how much data | ||
233 | * was really transferred and what the device tells us */ | ||
234 | if (residue) | ||
235 | residue = residue < buf_len ? residue : buf_len; | ||
236 | |||
237 | if (act_len) | ||
238 | *act_len = buf_len - residue; | ||
239 | |||
240 | /* based on the status code, we report good or bad */ | ||
241 | switch (bcs->Status) { | ||
242 | case US_BULK_STAT_OK: | ||
243 | /* command good -- note that data could be short */ | ||
244 | return USB_STOR_TRANSPORT_GOOD; | ||
245 | |||
246 | case US_BULK_STAT_FAIL: | ||
247 | /* command failed */ | ||
248 | return USB_STOR_TRANSPORT_FAILED; | ||
249 | |||
250 | case US_BULK_STAT_PHASE: | ||
251 | /* phase error -- note that a transport reset will be | ||
252 | * invoked by the invoke_transport() function | ||
253 | */ | ||
254 | return USB_STOR_TRANSPORT_ERROR; | ||
255 | } | ||
256 | |||
257 | /* we should never get here, but if we do, we're in trouble */ | ||
258 | return USB_STOR_TRANSPORT_ERROR; | ||
259 | } | ||
260 | |||
261 | /* Determine what the maximum LUN supported is */ | ||
262 | static int rts51x_get_max_lun(struct us_data *us) | ||
263 | { | ||
264 | int result; | ||
265 | |||
266 | /* issue the command */ | ||
267 | us->iobuf[0] = 0; | ||
268 | result = usb_stor_control_msg(us, us->recv_ctrl_pipe, | ||
269 | US_BULK_GET_MAX_LUN, | ||
270 | USB_DIR_IN | USB_TYPE_CLASS | | ||
271 | USB_RECIP_INTERFACE, | ||
272 | 0, us->ifnum, us->iobuf, 1, 10*HZ); | ||
273 | |||
274 | US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", | ||
275 | result, us->iobuf[0]); | ||
276 | |||
277 | /* if we have a successful request, return the result */ | ||
278 | if (result > 0) | ||
279 | return us->iobuf[0]; | ||
280 | |||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len) | ||
285 | { | ||
286 | int retval; | ||
287 | u8 cmnd[12] = {0}; | ||
288 | |||
289 | US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); | ||
290 | |||
291 | cmnd[0] = 0xF0; | ||
292 | cmnd[1] = 0x0D; | ||
293 | cmnd[2] = (u8)(addr >> 8); | ||
294 | cmnd[3] = (u8)addr; | ||
295 | cmnd[4] = (u8)(len >> 8); | ||
296 | cmnd[5] = (u8)len; | ||
297 | |||
298 | retval = rts51x_bulk_transport(us, 0, cmnd, 12, | ||
299 | data, len, DMA_FROM_DEVICE, NULL); | ||
300 | if (retval != USB_STOR_TRANSPORT_GOOD) | ||
301 | return -EIO; | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len) | ||
307 | { | ||
308 | int retval; | ||
309 | u8 cmnd[12] = {0}; | ||
310 | |||
311 | US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); | ||
312 | |||
313 | cmnd[0] = 0xF0; | ||
314 | cmnd[1] = 0x0E; | ||
315 | cmnd[2] = (u8)(addr >> 8); | ||
316 | cmnd[3] = (u8)addr; | ||
317 | cmnd[4] = (u8)(len >> 8); | ||
318 | cmnd[5] = (u8)len; | ||
319 | |||
320 | retval = rts51x_bulk_transport(us, 0, cmnd, 12, | ||
321 | data, len, DMA_TO_DEVICE, NULL); | ||
322 | if (retval != USB_STOR_TRANSPORT_GOOD) | ||
323 | return -EIO; | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static int rts51x_read_status(struct us_data *us, | ||
329 | u8 lun, u8 *status, int len, int *actlen) | ||
330 | { | ||
331 | int retval; | ||
332 | u8 cmnd[12] = {0}; | ||
333 | |||
334 | US_DEBUGP("%s, lun = %d\n", __func__, lun); | ||
335 | |||
336 | cmnd[0] = 0xF0; | ||
337 | cmnd[1] = 0x09; | ||
338 | |||
339 | retval = rts51x_bulk_transport(us, lun, cmnd, 12, | ||
340 | status, len, DMA_FROM_DEVICE, actlen); | ||
341 | if (retval != USB_STOR_TRANSPORT_GOOD) | ||
342 | return -EIO; | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | static int rts51x_check_status(struct us_data *us, u8 lun) | ||
348 | { | ||
349 | struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra); | ||
350 | int retval; | ||
351 | u8 buf[16]; | ||
352 | |||
353 | retval = rts51x_read_status(us, lun, buf, 16, &(chip->status_len)); | ||
354 | if (retval < 0) | ||
355 | return -EIO; | ||
356 | |||
357 | US_DEBUGP("chip->status_len = %d\n", chip->status_len); | ||
358 | |||
359 | chip->status[lun].vid = ((u16)buf[0] << 8) | buf[1]; | ||
360 | chip->status[lun].pid = ((u16)buf[2] << 8) | buf[3]; | ||
361 | chip->status[lun].cur_lun = buf[4]; | ||
362 | chip->status[lun].card_type = buf[5]; | ||
363 | chip->status[lun].total_lun = buf[6]; | ||
364 | chip->status[lun].fw_ver = ((u16)buf[7] << 8) | buf[8]; | ||
365 | chip->status[lun].phy_exist = buf[9]; | ||
366 | chip->status[lun].multi_flag = buf[10]; | ||
367 | chip->status[lun].multi_card = buf[11]; | ||
368 | chip->status[lun].log_exist = buf[12]; | ||
369 | if (chip->status_len == 16) { | ||
370 | chip->status[lun].detailed_type.detailed_type1 = buf[13]; | ||
371 | chip->status[lun].function[0] = buf[14]; | ||
372 | chip->status[lun].function[1] = buf[15]; | ||
373 | } | ||
374 | |||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | static int enable_oscillator(struct us_data *us) | ||
379 | { | ||
380 | int retval; | ||
381 | u8 value; | ||
382 | |||
383 | retval = rts51x_read_mem(us, 0xFE77, &value, 1); | ||
384 | if (retval < 0) | ||
385 | return -EIO; | ||
386 | |||
387 | value |= 0x04; | ||
388 | retval = rts51x_write_mem(us, 0xFE77, &value, 1); | ||
389 | if (retval < 0) | ||
390 | return -EIO; | ||
391 | |||
392 | retval = rts51x_read_mem(us, 0xFE77, &value, 1); | ||
393 | if (retval < 0) | ||
394 | return -EIO; | ||
395 | |||
396 | if (!(value & 0x04)) | ||
397 | return -EIO; | ||
398 | |||
399 | return 0; | ||
400 | } | ||
401 | |||
402 | static int do_config_autodelink(struct us_data *us, int enable, int force) | ||
403 | { | ||
404 | int retval; | ||
405 | u8 value; | ||
406 | |||
407 | retval = rts51x_read_mem(us, 0xFE47, &value, 1); | ||
408 | if (retval < 0) | ||
409 | return -EIO; | ||
410 | |||
411 | if (enable) { | ||
412 | if (force) | ||
413 | value |= 0x03; | ||
414 | else | ||
415 | value |= 0x01; | ||
416 | } else { | ||
417 | value &= ~0x03; | ||
418 | } | ||
419 | |||
420 | US_DEBUGP("In %s,set 0xfe47 to 0x%x\n", __func__, value); | ||
421 | |||
422 | retval = rts51x_write_mem(us, 0xFE47, &value, 1); | ||
423 | if (retval < 0) | ||
424 | return -EIO; | ||
425 | |||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | static int config_autodelink_after_power_on(struct us_data *us) | ||
430 | { | ||
431 | struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra); | ||
432 | int retval; | ||
433 | u8 value; | ||
434 | |||
435 | if (!CHK_AUTO_DELINK(chip)) | ||
436 | return 0; | ||
437 | |||
438 | retval = rts51x_read_mem(us, 0xFE47, &value, 1); | ||
439 | if (retval < 0) | ||
440 | return -EIO; | ||
441 | |||
442 | if (auto_delink_en) { | ||
443 | CLR_BIT(value, 0); | ||
444 | CLR_BIT(value, 1); | ||
445 | SET_BIT(value, 2); | ||
446 | |||
447 | if (CHECK_ID(chip, 0x0138, 0x3882)) | ||
448 | CLR_BIT(value, 2); | ||
449 | |||
450 | SET_BIT(value, 7); | ||
451 | |||
452 | retval = rts51x_write_mem(us, 0xFE47, &value, 1); | ||
453 | if (retval < 0) | ||
454 | return -EIO; | ||
455 | |||
456 | retval = enable_oscillator(us); | ||
457 | if (retval == 0) | ||
458 | (void)do_config_autodelink(us, 1, 0); | ||
459 | } else { | ||
460 | /* Autodelink controlled by firmware */ | ||
461 | |||
462 | SET_BIT(value, 2); | ||
463 | |||
464 | if (CHECK_ID(chip, 0x0138, 0x3882)) | ||
465 | CLR_BIT(value, 2); | ||
466 | |||
467 | if (CHECK_ID(chip, 0x0159, 0x5889) || | ||
468 | CHECK_ID(chip, 0x0138, 0x3880)) { | ||
469 | CLR_BIT(value, 0); | ||
470 | CLR_BIT(value, 7); | ||
471 | } | ||
472 | |||
473 | retval = rts51x_write_mem(us, 0xFE47, &value, 1); | ||
474 | if (retval < 0) | ||
475 | return -EIO; | ||
476 | |||
477 | if (CHECK_ID(chip, 0x0159, 0x5888)) { | ||
478 | value = 0xFF; | ||
479 | retval = rts51x_write_mem(us, 0xFE79, &value, 1); | ||
480 | if (retval < 0) | ||
481 | return -EIO; | ||
482 | |||
483 | value = 0x01; | ||
484 | retval = rts51x_write_mem(us, 0x48, &value, 1); | ||
485 | if (retval < 0) | ||
486 | return -EIO; | ||
487 | } | ||
488 | } | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | static int config_autodelink_before_power_down(struct us_data *us) | ||
494 | { | ||
495 | struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra); | ||
496 | int retval; | ||
497 | u8 value; | ||
498 | |||
499 | if (!CHK_AUTO_DELINK(chip)) | ||
500 | return 0; | ||
501 | |||
502 | if (auto_delink_en) { | ||
503 | retval = rts51x_read_mem(us, 0xFE77, &value, 1); | ||
504 | if (retval < 0) | ||
505 | return -EIO; | ||
506 | |||
507 | SET_BIT(value, 2); | ||
508 | retval = rts51x_write_mem(us, 0xFE77, &value, 1); | ||
509 | if (retval < 0) | ||
510 | return -EIO; | ||
511 | |||
512 | if (CHECK_ID(chip, 0x0159, 0x5888)) { | ||
513 | value = 0x01; | ||
514 | retval = rts51x_write_mem(us, 0x48, &value, 1); | ||
515 | if (retval < 0) | ||
516 | return -EIO; | ||
517 | } | ||
518 | |||
519 | retval = rts51x_read_mem(us, 0xFE47, &value, 1); | ||
520 | if (retval < 0) | ||
521 | return -EIO; | ||
522 | |||
523 | SET_BIT(value, 0); | ||
524 | if (CHECK_ID(chip, 0x0138, 0x3882)) | ||
525 | SET_BIT(value, 2); | ||
526 | retval = rts51x_write_mem(us, 0xFE77, &value, 1); | ||
527 | if (retval < 0) | ||
528 | return -EIO; | ||
529 | } else { | ||
530 | if (CHECK_ID(chip, 0x0159, 0x5889) || | ||
531 | CHECK_ID(chip, 0x0138, 0x3880) || | ||
532 | CHECK_ID(chip, 0x0138, 0x3882)) { | ||
533 | retval = rts51x_read_mem(us, 0xFE47, &value, 1); | ||
534 | if (retval < 0) | ||
535 | return -EIO; | ||
536 | |||
537 | if (CHECK_ID(chip, 0x0159, 0x5889) || | ||
538 | CHECK_ID(chip, 0x0138, 0x3880)) { | ||
539 | SET_BIT(value, 0); | ||
540 | SET_BIT(value, 7); | ||
541 | } | ||
542 | |||
543 | if (CHECK_ID(chip, 0x0138, 0x3882)) | ||
544 | SET_BIT(value, 2); | ||
545 | |||
546 | retval = rts51x_write_mem(us, 0xFE47, &value, 1); | ||
547 | if (retval < 0) | ||
548 | return -EIO; | ||
549 | } | ||
550 | |||
551 | if (CHECK_ID(chip, 0x0159, 0x5888)) { | ||
552 | value = 0x01; | ||
553 | retval = rts51x_write_mem(us, 0x48, &value, 1); | ||
554 | if (retval < 0) | ||
555 | return -EIO; | ||
556 | } | ||
557 | } | ||
558 | |||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static void realtek_cr_destructor(void *extra) | ||
563 | { | ||
564 | struct rts51x_chip *chip = (struct rts51x_chip *)extra; | ||
565 | |||
566 | if (!chip) | ||
567 | return; | ||
568 | |||
569 | kfree(chip->status); | ||
570 | } | ||
571 | |||
572 | #ifdef CONFIG_PM | ||
573 | static void realtek_pm_hook(struct us_data *us, int pm_state) | ||
574 | { | ||
575 | if (pm_state == US_SUSPEND) | ||
576 | (void)config_autodelink_before_power_down(us); | ||
577 | } | ||
578 | #endif | ||
579 | |||
580 | static int init_realtek_cr(struct us_data *us) | ||
581 | { | ||
582 | struct rts51x_chip *chip; | ||
583 | int size, i, retval; | ||
584 | |||
585 | chip = kzalloc(sizeof(struct rts51x_chip), GFP_KERNEL); | ||
586 | if (!chip) | ||
587 | return -ENOMEM; | ||
588 | |||
589 | us->extra = chip; | ||
590 | us->extra_destructor = realtek_cr_destructor; | ||
591 | #ifdef CONFIG_PM | ||
592 | us->suspend_resume_hook = realtek_pm_hook; | ||
593 | #endif | ||
594 | |||
595 | us->max_lun = chip->max_lun = rts51x_get_max_lun(us); | ||
596 | |||
597 | US_DEBUGP("chip->max_lun = %d\n", chip->max_lun); | ||
598 | |||
599 | size = (chip->max_lun + 1) * sizeof(struct rts51x_status); | ||
600 | chip->status = kzalloc(size, GFP_KERNEL); | ||
601 | if (!chip->status) | ||
602 | goto INIT_FAIL; | ||
603 | |||
604 | for (i = 0; i <= (int)(chip->max_lun); i++) { | ||
605 | retval = rts51x_check_status(us, (u8)i); | ||
606 | if (retval < 0) | ||
607 | goto INIT_FAIL; | ||
608 | } | ||
609 | |||
610 | if (CHECK_FW_VER(chip, 0x5888) || CHECK_FW_VER(chip, 0x5889) || | ||
611 | CHECK_FW_VER(chip, 0x5901)) | ||
612 | SET_AUTO_DELINK(chip); | ||
613 | if (STATUS_LEN(chip) == 16) { | ||
614 | if (SUPPORT_AUTO_DELINK(chip)) | ||
615 | SET_AUTO_DELINK(chip); | ||
616 | } | ||
617 | |||
618 | US_DEBUGP("chip->flag = 0x%x\n", chip->flag); | ||
619 | |||
620 | (void)config_autodelink_after_power_on(us); | ||
621 | |||
622 | return 0; | ||
623 | |||
624 | INIT_FAIL: | ||
625 | if (us->extra) { | ||
626 | kfree(chip->status); | ||
627 | kfree(us->extra); | ||
628 | us->extra = NULL; | ||
629 | } | ||
630 | |||
631 | return -EIO; | ||
632 | } | ||
633 | |||
634 | static int realtek_cr_probe(struct usb_interface *intf, | ||
635 | const struct usb_device_id *id) | ||
636 | { | ||
637 | struct us_data *us; | ||
638 | int result; | ||
639 | |||
640 | US_DEBUGP("Probe Realtek Card Reader!\n"); | ||
641 | |||
642 | result = usb_stor_probe1(&us, intf, id, | ||
643 | (id - realtek_cr_ids) + realtek_cr_unusual_dev_list); | ||
644 | if (result) | ||
645 | return result; | ||
646 | |||
647 | result = usb_stor_probe2(us); | ||
648 | return result; | ||
649 | } | ||
650 | |||
651 | static struct usb_driver realtek_cr_driver = { | ||
652 | .name = "ums-realtek", | ||
653 | .probe = realtek_cr_probe, | ||
654 | .disconnect = usb_stor_disconnect, | ||
655 | .suspend = usb_stor_suspend, | ||
656 | .resume = usb_stor_resume, | ||
657 | .reset_resume = usb_stor_reset_resume, | ||
658 | .pre_reset = usb_stor_pre_reset, | ||
659 | .post_reset = usb_stor_post_reset, | ||
660 | .id_table = realtek_cr_ids, | ||
661 | .soft_unbind = 1, | ||
662 | }; | ||
663 | |||
664 | static int __init realtek_cr_init(void) | ||
665 | { | ||
666 | return usb_register(&realtek_cr_driver); | ||
667 | } | ||
668 | |||
669 | static void __exit realtek_cr_exit(void) | ||
670 | { | ||
671 | usb_deregister(&realtek_cr_driver); | ||
672 | } | ||
673 | |||
674 | module_init(realtek_cr_init); | ||
675 | module_exit(realtek_cr_exit); | ||
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c index ceba512f84d0..1deca07c8265 100644 --- a/drivers/usb/storage/sierra_ms.c +++ b/drivers/usb/storage/sierra_ms.c | |||
@@ -126,13 +126,11 @@ static DEVICE_ATTR(truinst, S_IRUGO, show_truinst, NULL); | |||
126 | int sierra_ms_init(struct us_data *us) | 126 | int sierra_ms_init(struct us_data *us) |
127 | { | 127 | { |
128 | int result, retries; | 128 | int result, retries; |
129 | signed long delay_t; | ||
130 | struct swoc_info *swocInfo; | 129 | struct swoc_info *swocInfo; |
131 | struct usb_device *udev; | 130 | struct usb_device *udev; |
132 | struct Scsi_Host *sh; | 131 | struct Scsi_Host *sh; |
133 | struct scsi_device *sd; | 132 | struct scsi_device *sd; |
134 | 133 | ||
135 | delay_t = 2; | ||
136 | retries = 3; | 134 | retries = 3; |
137 | result = 0; | 135 | result = 0; |
138 | udev = us->pusb_dev; | 136 | udev = us->pusb_dev; |
diff --git a/drivers/usb/storage/unusual_realtek.h b/drivers/usb/storage/unusual_realtek.h new file mode 100644 index 000000000000..3236e0328516 --- /dev/null +++ b/drivers/usb/storage/unusual_realtek.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* Driver for Realtek RTS51xx USB card reader | ||
2 | * | ||
3 | * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License as published by the | ||
7 | * Free Software Foundation; either version 2, or (at your option) any | ||
8 | * later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * Author: | ||
19 | * wwang (wei_wang@realsil.com.cn) | ||
20 | * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China | ||
21 | */ | ||
22 | |||
23 | #if defined(CONFIG_USB_STORAGE_REALTEK) || \ | ||
24 | defined(CONFIG_USB_STORAGE_REALTEK_MODULE) | ||
25 | |||
26 | UNUSUAL_DEV(0x0bda, 0x0159, 0x0000, 0x9999, | ||
27 | "Realtek", | ||
28 | "USB Card Reader", | ||
29 | USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0), | ||
30 | |||
31 | UNUSUAL_DEV(0x0bda, 0x0158, 0x0000, 0x9999, | ||
32 | "Realtek", | ||
33 | "USB Card Reader", | ||
34 | USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0), | ||
35 | |||
36 | UNUSUAL_DEV(0x0bda, 0x0138, 0x0000, 0x9999, | ||
37 | "Realtek", | ||
38 | "USB Card Reader", | ||
39 | USB_SC_SCSI, USB_PR_BULK, init_realtek_cr, 0), | ||
40 | |||
41 | #endif /* defined(CONFIG_USB_STORAGE_REALTEK) || ... */ | ||
diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c index 468bde7d1971..4293077c01aa 100644 --- a/drivers/usb/storage/usual-tables.c +++ b/drivers/usb/storage/usual-tables.c | |||
@@ -85,6 +85,7 @@ static struct ignore_entry ignore_ids[] = { | |||
85 | # include "unusual_jumpshot.h" | 85 | # include "unusual_jumpshot.h" |
86 | # include "unusual_karma.h" | 86 | # include "unusual_karma.h" |
87 | # include "unusual_onetouch.h" | 87 | # include "unusual_onetouch.h" |
88 | # include "unusual_realtek.h" | ||
88 | # include "unusual_sddr09.h" | 89 | # include "unusual_sddr09.h" |
89 | # include "unusual_sddr55.h" | 90 | # include "unusual_sddr55.h" |
90 | # include "unusual_usbat.h" | 91 | # include "unusual_usbat.h" |
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c index a68ad7aa0b59..c175b7300c73 100644 --- a/drivers/usb/wusbcore/rh.c +++ b/drivers/usb/wusbcore/rh.c | |||
@@ -156,7 +156,7 @@ int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf) | |||
156 | EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); | 156 | EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); |
157 | 157 | ||
158 | /* | 158 | /* |
159 | * Return the hub's desciptor | 159 | * Return the hub's descriptor |
160 | * | 160 | * |
161 | * NOTE: almost cut and paste from ehci-hub.c | 161 | * NOTE: almost cut and paste from ehci-hub.c |
162 | * | 162 | * |
@@ -184,8 +184,8 @@ static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue, | |||
184 | descr->bPwrOn2PwrGood = 0; | 184 | descr->bPwrOn2PwrGood = 0; |
185 | descr->bHubContrCurrent = 0; | 185 | descr->bHubContrCurrent = 0; |
186 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ | 186 | /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ |
187 | memset(&descr->bitmap[0], 0, temp); | 187 | memset(&descr->u.hs.DeviceRemovable[0], 0, temp); |
188 | memset(&descr->bitmap[temp], 0xff, temp); | 188 | memset(&descr->u.hs.DeviceRemovable[temp], 0xff, temp); |
189 | return 0; | 189 | return 0; |
190 | } | 190 | } |
191 | 191 | ||
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c index 2054d4ee9774..0faca16df765 100644 --- a/drivers/usb/wusbcore/wusbhc.c +++ b/drivers/usb/wusbcore/wusbhc.c | |||
@@ -320,7 +320,7 @@ u8 wusb_cluster_id_get(void) | |||
320 | u8 id; | 320 | u8 id; |
321 | spin_lock(&wusb_cluster_ids_lock); | 321 | spin_lock(&wusb_cluster_ids_lock); |
322 | id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); | 322 | id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); |
323 | if (id > CLUSTER_IDS) { | 323 | if (id >= CLUSTER_IDS) { |
324 | id = 0; | 324 | id = 0; |
325 | goto out; | 325 | goto out; |
326 | } | 326 | } |
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h index 3d94c4247f46..6bd426b7ec07 100644 --- a/drivers/usb/wusbcore/wusbhc.h +++ b/drivers/usb/wusbcore/wusbhc.h | |||
@@ -132,7 +132,7 @@ static inline void wusb_dev_put(struct wusb_dev *wusb_dev) | |||
132 | } | 132 | } |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Wireless USB Host Controlller root hub "fake" ports | 135 | * Wireless USB Host Controller root hub "fake" ports |
136 | * (state and device information) | 136 | * (state and device information) |
137 | * | 137 | * |
138 | * Wireless USB is wireless, so there are no ports; but we | 138 | * Wireless USB is wireless, so there are no ports; but we |
diff --git a/drivers/uwb/scan.c b/drivers/uwb/scan.c index 76a1a1ed7d3e..367aa12786b9 100644 --- a/drivers/uwb/scan.c +++ b/drivers/uwb/scan.c | |||
@@ -42,7 +42,7 @@ | |||
42 | /** | 42 | /** |
43 | * Start/stop scanning in a radio controller | 43 | * Start/stop scanning in a radio controller |
44 | * | 44 | * |
45 | * @rc: UWB Radio Controlller | 45 | * @rc: UWB Radio Controller |
46 | * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12] | 46 | * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12] |
47 | * @type: Type of scanning to do. | 47 | * @type: Type of scanning to do. |
48 | * @bpst_offset: value at which to start scanning (if type == | 48 | * @bpst_offset: value at which to start scanning (if type == |
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h index 61b9609e55f2..a4bd05b7bd22 100644 --- a/include/linux/i2c/twl.h +++ b/include/linux/i2c/twl.h | |||
@@ -600,6 +600,8 @@ struct twl4030_usb_data { | |||
600 | int (*phy_power)(struct device *dev, int iD, int on); | 600 | int (*phy_power)(struct device *dev, int iD, int on); |
601 | /* enable/disable phy clocks */ | 601 | /* enable/disable phy clocks */ |
602 | int (*phy_set_clock)(struct device *dev, int on); | 602 | int (*phy_set_clock)(struct device *dev, int on); |
603 | /* suspend/resume of phy */ | ||
604 | int (*phy_suspend)(struct device *dev, int suspend); | ||
603 | }; | 605 | }; |
604 | 606 | ||
605 | struct twl4030_ins { | 607 | struct twl4030_ins { |
diff --git a/include/linux/platform_data/tegra_usb.h b/include/linux/platform_data/tegra_usb.h new file mode 100644 index 000000000000..6bca5b569acb --- /dev/null +++ b/include/linux/platform_data/tegra_usb.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Google, Inc. | ||
3 | * | ||
4 | * This software is licensed under the terms of the GNU General Public | ||
5 | * License version 2, as published by the Free Software Foundation, and | ||
6 | * may be copied, distributed, and modified under those terms. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #ifndef _TEGRA_USB_H_ | ||
16 | #define _TEGRA_USB_H_ | ||
17 | |||
18 | enum tegra_usb_operating_modes { | ||
19 | TEGRA_USB_DEVICE, | ||
20 | TEGRA_USB_HOST, | ||
21 | TEGRA_USB_OTG, | ||
22 | }; | ||
23 | |||
24 | struct tegra_ehci_platform_data { | ||
25 | enum tegra_usb_operating_modes operating_mode; | ||
26 | /* power down the phy on bus suspend */ | ||
27 | int power_down_on_bus_suspend; | ||
28 | void *phy_config; | ||
29 | }; | ||
30 | |||
31 | #endif /* _TEGRA_USB_H_ */ | ||
diff --git a/include/linux/usb.h b/include/linux/usb.h index bd69b65f3356..e63efeb378e3 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -976,6 +976,7 @@ extern int usb_disabled(void); | |||
976 | #define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */ | 976 | #define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */ |
977 | #define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */ | 977 | #define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */ |
978 | #define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */ | 978 | #define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */ |
979 | #define URB_ALIGNED_TEMP_BUFFER 0x00800000 /* Temp buffer was alloc'd */ | ||
979 | 980 | ||
980 | struct usb_iso_packet_descriptor { | 981 | struct usb_iso_packet_descriptor { |
981 | unsigned int offset; | 982 | unsigned int offset; |
diff --git a/include/linux/usb/Kbuild b/include/linux/usb/Kbuild index 51410e0200cf..ed91fb62674b 100644 --- a/include/linux/usb/Kbuild +++ b/include/linux/usb/Kbuild | |||
@@ -2,6 +2,7 @@ header-y += audio.h | |||
2 | header-y += cdc.h | 2 | header-y += cdc.h |
3 | header-y += ch9.h | 3 | header-y += ch9.h |
4 | header-y += ch11.h | 4 | header-y += ch11.h |
5 | header-y += functionfs.h | ||
5 | header-y += gadgetfs.h | 6 | header-y += gadgetfs.h |
6 | header-y += midi.h | 7 | header-y += midi.h |
7 | header-y += g_printer.h | 8 | header-y += g_printer.h |
diff --git a/include/linux/usb/ch11.h b/include/linux/usb/ch11.h index 10ec0699bea4..4ebaf0824179 100644 --- a/include/linux/usb/ch11.h +++ b/include/linux/usb/ch11.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #define HUB_RESET_TT 9 | 26 | #define HUB_RESET_TT 9 |
27 | #define HUB_GET_TT_STATE 10 | 27 | #define HUB_GET_TT_STATE 10 |
28 | #define HUB_STOP_TT 11 | 28 | #define HUB_STOP_TT 11 |
29 | #define HUB_SET_DEPTH 12 | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | * Hub class additional requests defined by USB 3.0 spec | 32 | * Hub class additional requests defined by USB 3.0 spec |
@@ -61,6 +62,12 @@ | |||
61 | #define USB_PORT_FEAT_TEST 21 | 62 | #define USB_PORT_FEAT_TEST 21 |
62 | #define USB_PORT_FEAT_INDICATOR 22 | 63 | #define USB_PORT_FEAT_INDICATOR 22 |
63 | #define USB_PORT_FEAT_C_PORT_L1 23 | 64 | #define USB_PORT_FEAT_C_PORT_L1 23 |
65 | #define USB_PORT_FEAT_C_PORT_LINK_STATE 25 | ||
66 | #define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 26 | ||
67 | #define USB_PORT_FEAT_PORT_REMOTE_WAKE_MASK 27 | ||
68 | #define USB_PORT_FEAT_BH_PORT_RESET 28 | ||
69 | #define USB_PORT_FEAT_C_BH_PORT_RESET 29 | ||
70 | #define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30 | ||
64 | 71 | ||
65 | /* | 72 | /* |
66 | * Port feature selectors added by USB 3.0 spec. | 73 | * Port feature selectors added by USB 3.0 spec. |
@@ -102,7 +109,6 @@ struct usb_port_status { | |||
102 | #define USB_PORT_STAT_TEST 0x0800 | 109 | #define USB_PORT_STAT_TEST 0x0800 |
103 | #define USB_PORT_STAT_INDICATOR 0x1000 | 110 | #define USB_PORT_STAT_INDICATOR 0x1000 |
104 | /* bits 13 to 15 are reserved */ | 111 | /* bits 13 to 15 are reserved */ |
105 | #define USB_PORT_STAT_SUPER_SPEED 0x8000 /* Linux-internal */ | ||
106 | 112 | ||
107 | /* | 113 | /* |
108 | * Additions to wPortStatus bit field from USB 3.0 | 114 | * Additions to wPortStatus bit field from USB 3.0 |
@@ -110,8 +116,14 @@ struct usb_port_status { | |||
110 | */ | 116 | */ |
111 | #define USB_PORT_STAT_LINK_STATE 0x01e0 | 117 | #define USB_PORT_STAT_LINK_STATE 0x01e0 |
112 | #define USB_SS_PORT_STAT_POWER 0x0200 | 118 | #define USB_SS_PORT_STAT_POWER 0x0200 |
119 | #define USB_SS_PORT_STAT_SPEED 0x1c00 | ||
113 | #define USB_PORT_STAT_SPEED_5GBPS 0x0000 | 120 | #define USB_PORT_STAT_SPEED_5GBPS 0x0000 |
114 | /* Valid only if port is enabled */ | 121 | /* Valid only if port is enabled */ |
122 | /* Bits that are the same from USB 2.0 */ | ||
123 | #define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \ | ||
124 | USB_PORT_STAT_ENABLE | \ | ||
125 | USB_PORT_STAT_OVERCURRENT | \ | ||
126 | USB_PORT_STAT_RESET) | ||
115 | 127 | ||
116 | /* | 128 | /* |
117 | * Definitions for PORT_LINK_STATE values | 129 | * Definitions for PORT_LINK_STATE values |
@@ -132,8 +144,8 @@ struct usb_port_status { | |||
132 | 144 | ||
133 | /* | 145 | /* |
134 | * wPortChange bit field | 146 | * wPortChange bit field |
135 | * See USB 2.0 spec Table 11-22 | 147 | * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10 |
136 | * Bits 0 to 4 shown, bits 5 to 15 are reserved | 148 | * Bits 0 to 5 shown, bits 6 to 15 are reserved |
137 | */ | 149 | */ |
138 | #define USB_PORT_STAT_C_CONNECTION 0x0001 | 150 | #define USB_PORT_STAT_C_CONNECTION 0x0001 |
139 | #define USB_PORT_STAT_C_ENABLE 0x0002 | 151 | #define USB_PORT_STAT_C_ENABLE 0x0002 |
@@ -141,6 +153,13 @@ struct usb_port_status { | |||
141 | #define USB_PORT_STAT_C_OVERCURRENT 0x0008 | 153 | #define USB_PORT_STAT_C_OVERCURRENT 0x0008 |
142 | #define USB_PORT_STAT_C_RESET 0x0010 | 154 | #define USB_PORT_STAT_C_RESET 0x0010 |
143 | #define USB_PORT_STAT_C_L1 0x0020 | 155 | #define USB_PORT_STAT_C_L1 0x0020 |
156 | /* | ||
157 | * USB 3.0 wPortChange bit fields | ||
158 | * See USB 3.0 spec Table 10-11 | ||
159 | */ | ||
160 | #define USB_PORT_STAT_C_BH_RESET 0x0020 | ||
161 | #define USB_PORT_STAT_C_LINK_STATE 0x0040 | ||
162 | #define USB_PORT_STAT_C_CONFIG_ERROR 0x0080 | ||
144 | 163 | ||
145 | /* | 164 | /* |
146 | * wHubCharacteristics (masks) | 165 | * wHubCharacteristics (masks) |
@@ -175,7 +194,9 @@ struct usb_hub_status { | |||
175 | */ | 194 | */ |
176 | 195 | ||
177 | #define USB_DT_HUB (USB_TYPE_CLASS | 0x09) | 196 | #define USB_DT_HUB (USB_TYPE_CLASS | 0x09) |
197 | #define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a) | ||
178 | #define USB_DT_HUB_NONVAR_SIZE 7 | 198 | #define USB_DT_HUB_NONVAR_SIZE 7 |
199 | #define USB_DT_SS_HUB_SIZE 12 | ||
179 | 200 | ||
180 | struct usb_hub_descriptor { | 201 | struct usb_hub_descriptor { |
181 | __u8 bDescLength; | 202 | __u8 bDescLength; |
@@ -184,11 +205,22 @@ struct usb_hub_descriptor { | |||
184 | __le16 wHubCharacteristics; | 205 | __le16 wHubCharacteristics; |
185 | __u8 bPwrOn2PwrGood; | 206 | __u8 bPwrOn2PwrGood; |
186 | __u8 bHubContrCurrent; | 207 | __u8 bHubContrCurrent; |
187 | /* add 1 bit for hub status change; round to bytes */ | ||
188 | __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; | ||
189 | __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; | ||
190 | } __attribute__ ((packed)); | ||
191 | 208 | ||
209 | /* 2.0 and 3.0 hubs differ here */ | ||
210 | union { | ||
211 | struct { | ||
212 | /* add 1 bit for hub status change; round to bytes */ | ||
213 | __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; | ||
214 | __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; | ||
215 | } __attribute__ ((packed)) hs; | ||
216 | |||
217 | struct { | ||
218 | __u8 bHubHdrDecLat; | ||
219 | __u16 wHubDelay; | ||
220 | __u16 DeviceRemovable; | ||
221 | } __attribute__ ((packed)) ss; | ||
222 | } u; | ||
223 | } __attribute__ ((packed)); | ||
192 | 224 | ||
193 | /* port indicator status selectors, tables 11-7 and 11-25 */ | 225 | /* port indicator status selectors, tables 11-7 and 11-25 */ |
194 | #define HUB_LED_AUTO 0 | 226 | #define HUB_LED_AUTO 0 |
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index ab461948b579..b72f305ce6bd 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h | |||
@@ -584,7 +584,9 @@ struct usb_ss_ep_comp_descriptor { | |||
584 | 584 | ||
585 | #define USB_DT_SS_EP_COMP_SIZE 6 | 585 | #define USB_DT_SS_EP_COMP_SIZE 6 |
586 | /* Bits 4:0 of bmAttributes if this is a bulk endpoint */ | 586 | /* Bits 4:0 of bmAttributes if this is a bulk endpoint */ |
587 | #define USB_SS_MAX_STREAMS(p) (1 << (p & 0x1f)) | 587 | #define USB_SS_MAX_STREAMS(p) (1 << ((p) & 0x1f)) |
588 | /* Bits 1:0 of bmAttributes if this is an isoc endpoint */ | ||
589 | #define USB_SS_MULT(p) (1 + ((p) & 0x3)) | ||
588 | 590 | ||
589 | /*-------------------------------------------------------------------------*/ | 591 | /*-------------------------------------------------------------------------*/ |
590 | 592 | ||
diff --git a/include/linux/usb/ehci_def.h b/include/linux/usb/ehci_def.h index 2e262cb15425..656380245198 100644 --- a/include/linux/usb/ehci_def.h +++ b/include/linux/usb/ehci_def.h | |||
@@ -127,7 +127,9 @@ struct ehci_regs { | |||
127 | #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ | 127 | #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ |
128 | #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ | 128 | #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ |
129 | /* 19:16 for port testing */ | 129 | /* 19:16 for port testing */ |
130 | #define PORT_TEST_PKT (0x4<<16) /* Port Test Control - packet test */ | 130 | #define PORT_TEST(x) (((x)&0xf)<<16) /* Port Test Control */ |
131 | #define PORT_TEST_PKT PORT_TEST(0x4) /* Port Test Control - packet test */ | ||
132 | #define PORT_TEST_FORCE PORT_TEST(0x5) /* Port Test Control - force enable */ | ||
131 | #define PORT_LED_OFF (0<<14) | 133 | #define PORT_LED_OFF (0<<14) |
132 | #define PORT_LED_AMBER (1<<14) | 134 | #define PORT_LED_AMBER (1<<14) |
133 | #define PORT_LED_GREEN (2<<14) | 135 | #define PORT_LED_GREEN (2<<14) |
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index a854fe89484e..0097136ba45d 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h | |||
@@ -76,6 +76,10 @@ struct usb_hcd { | |||
76 | struct kref kref; /* reference counter */ | 76 | struct kref kref; /* reference counter */ |
77 | 77 | ||
78 | const char *product_desc; /* product/vendor string */ | 78 | const char *product_desc; /* product/vendor string */ |
79 | int speed; /* Speed for this roothub. | ||
80 | * May be different from | ||
81 | * hcd->driver->flags & HCD_MASK | ||
82 | */ | ||
79 | char irq_descr[24]; /* driver + bus # */ | 83 | char irq_descr[24]; /* driver + bus # */ |
80 | 84 | ||
81 | struct timer_list rh_timer; /* drives root-hub polling */ | 85 | struct timer_list rh_timer; /* drives root-hub polling */ |
@@ -99,6 +103,8 @@ struct usb_hcd { | |||
99 | #define HCD_FLAG_POLL_RH 2 /* poll for rh status? */ | 103 | #define HCD_FLAG_POLL_RH 2 /* poll for rh status? */ |
100 | #define HCD_FLAG_POLL_PENDING 3 /* status has changed? */ | 104 | #define HCD_FLAG_POLL_PENDING 3 /* status has changed? */ |
101 | #define HCD_FLAG_WAKEUP_PENDING 4 /* root hub is resuming? */ | 105 | #define HCD_FLAG_WAKEUP_PENDING 4 /* root hub is resuming? */ |
106 | #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ | ||
107 | #define HCD_FLAG_DEAD 6 /* controller has died? */ | ||
102 | 108 | ||
103 | /* The flags can be tested using these macros; they are likely to | 109 | /* The flags can be tested using these macros; they are likely to |
104 | * be slightly faster than test_bit(). | 110 | * be slightly faster than test_bit(). |
@@ -108,6 +114,8 @@ struct usb_hcd { | |||
108 | #define HCD_POLL_RH(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_RH)) | 114 | #define HCD_POLL_RH(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_RH)) |
109 | #define HCD_POLL_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING)) | 115 | #define HCD_POLL_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING)) |
110 | #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) | 116 | #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) |
117 | #define HCD_RH_RUNNING(hcd) ((hcd)->flags & (1U << HCD_FLAG_RH_RUNNING)) | ||
118 | #define HCD_DEAD(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEAD)) | ||
111 | 119 | ||
112 | /* Flags that get set only during HCD registration or removal. */ | 120 | /* Flags that get set only during HCD registration or removal. */ |
113 | unsigned rh_registered:1;/* is root hub registered? */ | 121 | unsigned rh_registered:1;/* is root hub registered? */ |
@@ -138,7 +146,9 @@ struct usb_hcd { | |||
138 | * bandwidth_mutex should be dropped after a successful control message | 146 | * bandwidth_mutex should be dropped after a successful control message |
139 | * to the device, or resetting the bandwidth after a failed attempt. | 147 | * to the device, or resetting the bandwidth after a failed attempt. |
140 | */ | 148 | */ |
141 | struct mutex bandwidth_mutex; | 149 | struct mutex *bandwidth_mutex; |
150 | struct usb_hcd *shared_hcd; | ||
151 | struct usb_hcd *primary_hcd; | ||
142 | 152 | ||
143 | 153 | ||
144 | #define HCD_BUFFER_POOLS 4 | 154 | #define HCD_BUFFER_POOLS 4 |
@@ -201,6 +211,7 @@ struct hc_driver { | |||
201 | int flags; | 211 | int flags; |
202 | #define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ | 212 | #define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ |
203 | #define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ | 213 | #define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ |
214 | #define HCD_SHARED 0x0004 /* Two (or more) usb_hcds share HW */ | ||
204 | #define HCD_USB11 0x0010 /* USB 1.1 */ | 215 | #define HCD_USB11 0x0010 /* USB 1.1 */ |
205 | #define HCD_USB2 0x0020 /* USB 2.0 */ | 216 | #define HCD_USB2 0x0020 /* USB 2.0 */ |
206 | #define HCD_USB3 0x0040 /* USB 3.0 */ | 217 | #define HCD_USB3 0x0040 /* USB 3.0 */ |
@@ -234,6 +245,19 @@ struct hc_driver { | |||
234 | int (*urb_dequeue)(struct usb_hcd *hcd, | 245 | int (*urb_dequeue)(struct usb_hcd *hcd, |
235 | struct urb *urb, int status); | 246 | struct urb *urb, int status); |
236 | 247 | ||
248 | /* | ||
249 | * (optional) these hooks allow an HCD to override the default DMA | ||
250 | * mapping and unmapping routines. In general, they shouldn't be | ||
251 | * necessary unless the host controller has special DMA requirements, | ||
252 | * such as alignment contraints. If these are not specified, the | ||
253 | * general usb_hcd_(un)?map_urb_for_dma functions will be used instead | ||
254 | * (and it may be a good idea to call these functions in your HCD | ||
255 | * implementation) | ||
256 | */ | ||
257 | int (*map_urb_for_dma)(struct usb_hcd *hcd, struct urb *urb, | ||
258 | gfp_t mem_flags); | ||
259 | void (*unmap_urb_for_dma)(struct usb_hcd *hcd, struct urb *urb); | ||
260 | |||
237 | /* hw synch, freeing endpoint resources that urb_dequeue can't */ | 261 | /* hw synch, freeing endpoint resources that urb_dequeue can't */ |
238 | void (*endpoint_disable)(struct usb_hcd *hcd, | 262 | void (*endpoint_disable)(struct usb_hcd *hcd, |
239 | struct usb_host_endpoint *ep); | 263 | struct usb_host_endpoint *ep); |
@@ -330,8 +354,10 @@ extern int usb_hcd_submit_urb(struct urb *urb, gfp_t mem_flags); | |||
330 | extern int usb_hcd_unlink_urb(struct urb *urb, int status); | 354 | extern int usb_hcd_unlink_urb(struct urb *urb, int status); |
331 | extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, | 355 | extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, |
332 | int status); | 356 | int status); |
333 | extern void unmap_urb_setup_for_dma(struct usb_hcd *, struct urb *); | 357 | extern int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, |
334 | extern void unmap_urb_for_dma(struct usb_hcd *, struct urb *); | 358 | gfp_t mem_flags); |
359 | extern void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *, struct urb *); | ||
360 | extern void usb_hcd_unmap_urb_for_dma(struct usb_hcd *, struct urb *); | ||
335 | extern void usb_hcd_flush_endpoint(struct usb_device *udev, | 361 | extern void usb_hcd_flush_endpoint(struct usb_device *udev, |
336 | struct usb_host_endpoint *ep); | 362 | struct usb_host_endpoint *ep); |
337 | extern void usb_hcd_disable_endpoint(struct usb_device *udev, | 363 | extern void usb_hcd_disable_endpoint(struct usb_device *udev, |
@@ -347,8 +373,12 @@ extern int usb_hcd_get_frame_number(struct usb_device *udev); | |||
347 | 373 | ||
348 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, | 374 | extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, |
349 | struct device *dev, const char *bus_name); | 375 | struct device *dev, const char *bus_name); |
376 | extern struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver, | ||
377 | struct device *dev, const char *bus_name, | ||
378 | struct usb_hcd *shared_hcd); | ||
350 | extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd); | 379 | extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd); |
351 | extern void usb_put_hcd(struct usb_hcd *hcd); | 380 | extern void usb_put_hcd(struct usb_hcd *hcd); |
381 | extern int usb_hcd_is_primary_hcd(struct usb_hcd *hcd); | ||
352 | extern int usb_add_hcd(struct usb_hcd *hcd, | 382 | extern int usb_add_hcd(struct usb_hcd *hcd, |
353 | unsigned int irqnum, unsigned long irqflags); | 383 | unsigned int irqnum, unsigned long irqflags); |
354 | extern void usb_remove_hcd(struct usb_hcd *hcd); | 384 | extern void usb_remove_hcd(struct usb_hcd *hcd); |
@@ -622,13 +652,6 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, | |||
622 | 652 | ||
623 | /*-------------------------------------------------------------------------*/ | 653 | /*-------------------------------------------------------------------------*/ |
624 | 654 | ||
625 | /* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ | ||
626 | /* bleech -- resurfaced in 2.4.11 or 2.4.12 */ | ||
627 | #define bitmap DeviceRemovable | ||
628 | |||
629 | |||
630 | /*-------------------------------------------------------------------------*/ | ||
631 | |||
632 | /* random stuff */ | 655 | /* random stuff */ |
633 | 656 | ||
634 | #define RUN_CONTEXT (in_irq() ? "in_irq" \ | 657 | #define RUN_CONTEXT (in_irq() ? "in_irq" \ |
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h index 3675e03b1539..3657403eac18 100644 --- a/include/linux/usb/msm_hsusb.h +++ b/include/linux/usb/msm_hsusb.h | |||
@@ -55,7 +55,7 @@ enum otg_control_type { | |||
55 | 55 | ||
56 | /** | 56 | /** |
57 | * struct msm_otg_platform_data - platform device data | 57 | * struct msm_otg_platform_data - platform device data |
58 | * for msm72k_otg driver. | 58 | * for msm_otg driver. |
59 | * @phy_init_seq: PHY configuration sequence. val, reg pairs | 59 | * @phy_init_seq: PHY configuration sequence. val, reg pairs |
60 | * terminated by -1. | 60 | * terminated by -1. |
61 | * @vbus_power: VBUS power on/off routine. | 61 | * @vbus_power: VBUS power on/off routine. |
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index a1a1e7a73ec9..6e40718f5abe 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h | |||
@@ -66,6 +66,7 @@ struct otg_transceiver { | |||
66 | 66 | ||
67 | u8 default_a; | 67 | u8 default_a; |
68 | enum usb_otg_state state; | 68 | enum usb_otg_state state; |
69 | enum usb_xceiv_events last_event; | ||
69 | 70 | ||
70 | struct usb_bus *host; | 71 | struct usb_bus *host; |
71 | struct usb_gadget *gadget; | 72 | struct usb_gadget *gadget; |
@@ -74,7 +75,7 @@ struct otg_transceiver { | |||
74 | void __iomem *io_priv; | 75 | void __iomem *io_priv; |
75 | 76 | ||
76 | /* for notification of usb_xceiv_events */ | 77 | /* for notification of usb_xceiv_events */ |
77 | struct blocking_notifier_head notifier; | 78 | struct atomic_notifier_head notifier; |
78 | 79 | ||
79 | /* to pass extra port status to the root hub */ | 80 | /* to pass extra port status to the root hub */ |
80 | u16 port_status; | 81 | u16 port_status; |
@@ -234,13 +235,13 @@ otg_start_srp(struct otg_transceiver *otg) | |||
234 | static inline int | 235 | static inline int |
235 | otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | 236 | otg_register_notifier(struct otg_transceiver *otg, struct notifier_block *nb) |
236 | { | 237 | { |
237 | return blocking_notifier_chain_register(&otg->notifier, nb); | 238 | return atomic_notifier_chain_register(&otg->notifier, nb); |
238 | } | 239 | } |
239 | 240 | ||
240 | static inline void | 241 | static inline void |
241 | otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb) | 242 | otg_unregister_notifier(struct otg_transceiver *otg, struct notifier_block *nb) |
242 | { | 243 | { |
243 | blocking_notifier_chain_unregister(&otg->notifier, nb); | 244 | atomic_notifier_chain_unregister(&otg->notifier, nb); |
244 | } | 245 | } |
245 | 246 | ||
246 | /* for OTG controller drivers (and maybe other stuff) */ | 247 | /* for OTG controller drivers (and maybe other stuff) */ |
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h index c9049139a7a5..45f3b9db4258 100644 --- a/include/linux/usb/serial.h +++ b/include/linux/usb/serial.h | |||
@@ -191,7 +191,8 @@ static inline void usb_set_serial_data(struct usb_serial *serial, void *data) | |||
191 | * @id_table: pointer to a list of usb_device_id structures that define all | 191 | * @id_table: pointer to a list of usb_device_id structures that define all |
192 | * of the devices this structure can support. | 192 | * of the devices this structure can support. |
193 | * @num_ports: the number of different ports this device will have. | 193 | * @num_ports: the number of different ports this device will have. |
194 | * @bulk_in_size: bytes to allocate for bulk-in buffer (0 = end-point size) | 194 | * @bulk_in_size: minimum number of bytes to allocate for bulk-in buffer |
195 | * (0 = end-point size) | ||
195 | * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size) | 196 | * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size) |
196 | * @calc_num_ports: pointer to a function to determine how many ports this | 197 | * @calc_num_ports: pointer to a function to determine how many ports this |
197 | * device has dynamically. It will be called after the probe() | 198 | * device has dynamically. It will be called after the probe() |
diff --git a/include/linux/usb/ulpi.h b/include/linux/usb/ulpi.h index 82b1507f4735..9595796d62ed 100644 --- a/include/linux/usb/ulpi.h +++ b/include/linux/usb/ulpi.h | |||
@@ -184,4 +184,9 @@ | |||
184 | struct otg_transceiver *otg_ulpi_create(struct otg_io_access_ops *ops, | 184 | struct otg_transceiver *otg_ulpi_create(struct otg_io_access_ops *ops, |
185 | unsigned int flags); | 185 | unsigned int flags); |
186 | 186 | ||
187 | #ifdef CONFIG_USB_ULPI_VIEWPORT | ||
188 | /* access ops for controllers with a viewport register */ | ||
189 | extern struct otg_io_access_ops ulpi_viewport_access_ops; | ||
190 | #endif | ||
191 | |||
187 | #endif /* __LINUX_USB_ULPI_H */ | 192 | #endif /* __LINUX_USB_ULPI_H */ |
diff --git a/tools/usb/Makefile b/tools/usb/Makefile new file mode 100644 index 000000000000..8b704af14349 --- /dev/null +++ b/tools/usb/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # Makefile for USB tools | ||
2 | |||
3 | CC = $(CROSS_COMPILE)gcc | ||
4 | PTHREAD_LIBS = -lpthread | ||
5 | WARNINGS = -Wall -Wextra | ||
6 | CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) | ||
7 | |||
8 | all: testusb ffs-test | ||
9 | %: %.c | ||
10 | $(CC) $(CFLAGS) -o $@ $^ | ||
11 | |||
12 | clean: | ||
13 | $(RM) testusb ffs-test | ||
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c index bbe2e3a2ea62..b9c798631699 100644 --- a/tools/usb/ffs-test.c +++ b/tools/usb/ffs-test.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include <sys/types.h> | 37 | #include <sys/types.h> |
38 | #include <unistd.h> | 38 | #include <unistd.h> |
39 | 39 | ||
40 | #include <linux/usb/functionfs.h> | 40 | #include "../../include/linux/usb/functionfs.h" |
41 | 41 | ||
42 | 42 | ||
43 | /******************** Little Endian Handling ********************************/ | 43 | /******************** Little Endian Handling ********************************/ |
@@ -450,7 +450,7 @@ invalid: | |||
450 | len, expected, *p); | 450 | len, expected, *p); |
451 | for (p = buf, len = 0; len < nbytes; ++p, ++len) { | 451 | for (p = buf, len = 0; len < nbytes; ++p, ++len) { |
452 | if (0 == (len % 32)) | 452 | if (0 == (len % 32)) |
453 | fprintf(stderr, "%4d:", len); | 453 | fprintf(stderr, "%4zd:", len); |
454 | fprintf(stderr, " %02x", *p); | 454 | fprintf(stderr, " %02x", *p); |
455 | if (31 == (len % 32)) | 455 | if (31 == (len % 32)) |
456 | fprintf(stderr, "\n"); | 456 | fprintf(stderr, "\n"); |
diff --git a/tools/usb/hcd-tests.sh b/tools/usb/hcd-tests.sh new file mode 100644 index 000000000000..b30b3dc4c788 --- /dev/null +++ b/tools/usb/hcd-tests.sh | |||
@@ -0,0 +1,275 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # test types can be passed on the command line: | ||
4 | # | ||
5 | # - control: any device can do this | ||
6 | # - out, in: out needs 'bulk sink' firmware, in needs 'bulk src' | ||
7 | # - iso-out, iso-in: out needs 'iso sink' firmware, in needs 'iso src' | ||
8 | # - halt: needs bulk sink+src, tests halt set/clear from host | ||
9 | # - unlink: needs bulk sink and/or src, test HCD unlink processing | ||
10 | # - loop: needs firmware that will buffer N transfers | ||
11 | # | ||
12 | # run it for hours, days, weeks. | ||
13 | # | ||
14 | |||
15 | # | ||
16 | # this default provides a steady test load for a bulk device | ||
17 | # | ||
18 | TYPES='control out in' | ||
19 | #TYPES='control out in halt' | ||
20 | |||
21 | # | ||
22 | # to test HCD code | ||
23 | # | ||
24 | # - include unlink tests | ||
25 | # - add some ${RANDOM}ness | ||
26 | # - connect several devices concurrently (same HC) | ||
27 | # - keep HC's IRQ lines busy with unrelated traffic (IDE, net, ...) | ||
28 | # - add other concurrent system loads | ||
29 | # | ||
30 | |||
31 | declare -i COUNT BUFLEN | ||
32 | |||
33 | COUNT=50000 | ||
34 | BUFLEN=2048 | ||
35 | |||
36 | # NOTE: the 'in' and 'out' cases are usually bulk, but can be | ||
37 | # set up to use interrupt transfers by 'usbtest' module options | ||
38 | |||
39 | |||
40 | if [ "$DEVICE" = "" ]; then | ||
41 | echo "testing ALL recognized usbtest devices" | ||
42 | echo "" | ||
43 | TEST_ARGS="-a" | ||
44 | else | ||
45 | TEST_ARGS="" | ||
46 | fi | ||
47 | |||
48 | do_test () | ||
49 | { | ||
50 | if ! ./testusb $TEST_ARGS -s $BUFLEN -c $COUNT $* 2>/dev/null | ||
51 | then | ||
52 | echo "FAIL" | ||
53 | exit 1 | ||
54 | fi | ||
55 | } | ||
56 | |||
57 | ARGS="$*" | ||
58 | |||
59 | if [ "$ARGS" = "" ]; | ||
60 | then | ||
61 | ARGS="$TYPES" | ||
62 | fi | ||
63 | |||
64 | # FIXME use /sys/bus/usb/device/$THIS/bConfigurationValue to | ||
65 | # check and change configs | ||
66 | |||
67 | CONFIG='' | ||
68 | |||
69 | check_config () | ||
70 | { | ||
71 | if [ "$CONFIG" = "" ]; then | ||
72 | CONFIG=$1 | ||
73 | echo "assuming $CONFIG configuration" | ||
74 | return | ||
75 | fi | ||
76 | if [ "$CONFIG" = $1 ]; then | ||
77 | return | ||
78 | fi | ||
79 | |||
80 | echo "** device must be in $1 config, but it's $CONFIG instead" | ||
81 | exit 1 | ||
82 | } | ||
83 | |||
84 | |||
85 | echo "TESTING: $ARGS" | ||
86 | |||
87 | while : true | ||
88 | do | ||
89 | echo $(date) | ||
90 | |||
91 | for TYPE in $ARGS | ||
92 | do | ||
93 | # restore defaults | ||
94 | COUNT=5000 | ||
95 | BUFLEN=2048 | ||
96 | |||
97 | # FIXME automatically multiply COUNT by 10 when | ||
98 | # /sys/bus/usb/device/$THIS/speed == "480" | ||
99 | |||
100 | # COUNT=50000 | ||
101 | |||
102 | case $TYPE in | ||
103 | control) | ||
104 | # any device, in any configuration, can use this. | ||
105 | echo '** Control test cases:' | ||
106 | |||
107 | echo "test 9: ch9 postconfig" | ||
108 | do_test -t 9 -c 5000 | ||
109 | echo "test 10: control queueing" | ||
110 | do_test -t 10 -c 5000 | ||
111 | |||
112 | # this relies on some vendor-specific commands | ||
113 | echo "test 14: control writes" | ||
114 | do_test -t 14 -c 15000 -s 256 -v 1 | ||
115 | |||
116 | echo "test 21: control writes, unaligned" | ||
117 | do_test -t 21 -c 100 -s 256 -v 1 | ||
118 | |||
119 | ;; | ||
120 | |||
121 | out) | ||
122 | check_config sink-src | ||
123 | echo '** Host Write (OUT) test cases:' | ||
124 | |||
125 | echo "test 1: $COUNT transfers, same size" | ||
126 | do_test -t 1 | ||
127 | echo "test 3: $COUNT transfers, variable/short size" | ||
128 | do_test -t 3 -v 421 | ||
129 | |||
130 | COUNT=100 | ||
131 | echo "test 17: $COUNT transfers, unaligned DMA map by core" | ||
132 | do_test -t 17 | ||
133 | |||
134 | echo "test 19: $COUNT transfers, unaligned DMA map by usb_alloc_coherent" | ||
135 | do_test -t 19 | ||
136 | |||
137 | COUNT=2000 | ||
138 | echo "test 5: $COUNT scatterlists, same size entries" | ||
139 | do_test -t 5 | ||
140 | |||
141 | # try to trigger short OUT processing bugs | ||
142 | echo "test 7a: $COUNT scatterlists, variable size/short entries" | ||
143 | do_test -t 7 -v 579 | ||
144 | BUFLEN=4096 | ||
145 | echo "test 7b: $COUNT scatterlists, variable size/bigger entries" | ||
146 | do_test -t 7 -v 41 | ||
147 | BUFLEN=64 | ||
148 | echo "test 7c: $COUNT scatterlists, variable size/micro entries" | ||
149 | do_test -t 7 -v 63 | ||
150 | ;; | ||
151 | |||
152 | iso-out) | ||
153 | check_config sink-src | ||
154 | echo '** Host ISOCHRONOUS Write (OUT) test cases:' | ||
155 | |||
156 | # at peak iso transfer rates: | ||
157 | # - usb 2.0 high bandwidth, this is one frame. | ||
158 | # - usb 1.1, it's twenty-four frames. | ||
159 | BUFLEN=24500 | ||
160 | |||
161 | COUNT=1000 | ||
162 | |||
163 | # COUNT=10000 | ||
164 | |||
165 | echo "test 15: $COUNT transfers, same size" | ||
166 | # do_test -t 15 -g 3 -v 0 | ||
167 | BUFLEN=32768 | ||
168 | do_test -t 15 -g 8 -v 0 | ||
169 | |||
170 | # FIXME it'd make sense to have an iso OUT test issuing | ||
171 | # short writes on more packets than the last one | ||
172 | |||
173 | COUNT=100 | ||
174 | echo "test 22: $COUNT transfers, non aligned" | ||
175 | do_test -t 22 -g 8 -v 0 | ||
176 | |||
177 | ;; | ||
178 | |||
179 | in) | ||
180 | check_config sink-src | ||
181 | echo '** Host Read (IN) test cases:' | ||
182 | |||
183 | # NOTE: these "variable size" reads are just multiples | ||
184 | # of 512 bytes, no EOVERFLOW testing is done yet | ||
185 | |||
186 | echo "test 2: $COUNT transfers, same size" | ||
187 | do_test -t 2 | ||
188 | echo "test 4: $COUNT transfers, variable size" | ||
189 | do_test -t 4 | ||
190 | |||
191 | COUNT=100 | ||
192 | echo "test 18: $COUNT transfers, unaligned DMA map by core" | ||
193 | do_test -t 18 | ||
194 | |||
195 | echo "test 20: $COUNT transfers, unaligned DMA map by usb_alloc_coherent" | ||
196 | do_test -t 20 | ||
197 | |||
198 | COUNT=2000 | ||
199 | echo "test 6: $COUNT scatterlists, same size entries" | ||
200 | do_test -t 6 | ||
201 | echo "test 8: $COUNT scatterlists, variable size entries" | ||
202 | do_test -t 8 | ||
203 | ;; | ||
204 | |||
205 | iso-in) | ||
206 | check_config sink-src | ||
207 | echo '** Host ISOCHRONOUS Read (IN) test cases:' | ||
208 | |||
209 | # at peak iso transfer rates: | ||
210 | # - usb 2.0 high bandwidth, this is one frame. | ||
211 | # - usb 1.1, it's twenty-four frames. | ||
212 | BUFLEN=24500 | ||
213 | |||
214 | COUNT=1000 | ||
215 | |||
216 | # COUNT=10000 | ||
217 | |||
218 | echo "test 16: $COUNT transfers, same size" | ||
219 | # do_test -t 16 -g 3 -v 0 | ||
220 | BUFLEN=32768 | ||
221 | do_test -t 16 -g 8 -v 0 | ||
222 | |||
223 | # FIXME since iso expects faults, it'd make sense | ||
224 | # to have an iso IN test issuing short reads ... | ||
225 | |||
226 | COUNT=100 | ||
227 | echo "test 23: $COUNT transfers, unaligned" | ||
228 | do_test -t 23 -g 8 -v 0 | ||
229 | |||
230 | ;; | ||
231 | |||
232 | halt) | ||
233 | # NOTE: sometimes hardware doesn't cooperate well with halting | ||
234 | # endpoints from the host side. so long as mass-storage class | ||
235 | # firmware can halt them from the device, don't worry much if | ||
236 | # you can't make this test work on your device. | ||
237 | COUNT=2000 | ||
238 | echo "test 13: $COUNT halt set/clear" | ||
239 | do_test -t 13 | ||
240 | ;; | ||
241 | |||
242 | unlink) | ||
243 | COUNT=2000 | ||
244 | echo "test 11: $COUNT read unlinks" | ||
245 | do_test -t 11 | ||
246 | |||
247 | echo "test 12: $COUNT write unlinks" | ||
248 | do_test -t 12 | ||
249 | ;; | ||
250 | |||
251 | loop) | ||
252 | # defaults need too much buffering for ez-usb devices | ||
253 | BUFLEN=2048 | ||
254 | COUNT=32 | ||
255 | |||
256 | # modprobe g_zero qlen=$COUNT buflen=$BUFLEN loopdefault | ||
257 | check_config loopback | ||
258 | |||
259 | # FIXME someone needs to write and merge a version of this | ||
260 | |||
261 | echo "write $COUNT buffers of $BUFLEN bytes, read them back" | ||
262 | |||
263 | echo "write $COUNT variable size buffers, read them back" | ||
264 | |||
265 | ;; | ||
266 | |||
267 | *) | ||
268 | echo "Don't understand test type $TYPE" | ||
269 | exit 1; | ||
270 | esac | ||
271 | echo '' | ||
272 | done | ||
273 | done | ||
274 | |||
275 | # vim: sw=4 | ||