diff options
author | Jan Andersson <jan@gaisler.com> | 2011-05-06 06:00:15 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-05-06 21:24:00 -0400 |
commit | c31a65f869f7b8a7039007411c76d7b6f9a63323 (patch) | |
tree | a22bc058d1b343e8ac0734c905465030166dc821 /drivers/usb/host/uhci-hcd.c | |
parent | e4d235d800c8d75750a46331298e3473c10651b2 (diff) |
USB: UHCI: Move PCI specific functions to uhci-pci.c
This patch is part of a series that extend the UHCI HCD to support
non-PCI controllers.
This patch moves PCI specific functions to uhci-pci.c and includes
this file in uhci-hcd.c. It also renames the function uhci_init to
uhci_pci_init.
uhci_init/uhci_pci_init is modified so that the port-detection logic
is kept in a new separate function uhci_count_ports() in uhci-hcd.c.
Signed-off-by: Jan Andersson <jan@gaisler.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/uhci-hcd.c')
-rw-r--r-- | drivers/usb/host/uhci-hcd.c | 326 |
1 files changed, 32 insertions, 294 deletions
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index 348174fdfaee..3d2a10563be8 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #include <asm/system.h> | 48 | #include <asm/system.h> |
49 | 49 | ||
50 | #include "uhci-hcd.h" | 50 | #include "uhci-hcd.h" |
51 | #include "pci-quirks.h" | ||
52 | 51 | ||
53 | /* | 52 | /* |
54 | * Version Information | 53 | * Version Information |
@@ -143,15 +142,6 @@ static void finish_reset(struct uhci_hcd *uhci) | |||
143 | } | 142 | } |
144 | 143 | ||
145 | /* | 144 | /* |
146 | * Make sure the controller is completely inactive, unable to | ||
147 | * generate interrupts or do DMA. | ||
148 | */ | ||
149 | static void uhci_pci_reset_hc(struct uhci_hcd *uhci) | ||
150 | { | ||
151 | uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | * Last rites for a defunct/nonfunctional controller | 145 | * Last rites for a defunct/nonfunctional controller |
156 | * or one we don't want to use any more. | 146 | * or one we don't want to use any more. |
157 | */ | 147 | */ |
@@ -167,18 +157,6 @@ static void uhci_hc_died(struct uhci_hcd *uhci) | |||
167 | } | 157 | } |
168 | 158 | ||
169 | /* | 159 | /* |
170 | * Initialize a controller that was newly discovered or has just been | ||
171 | * resumed. In either case we can't be sure of its previous state. | ||
172 | * | ||
173 | * Returns: 1 if the controller was reset, 0 otherwise. | ||
174 | */ | ||
175 | static int uhci_pci_check_and_reset_hc(struct uhci_hcd *uhci) | ||
176 | { | ||
177 | return uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)), | ||
178 | uhci->io_addr); | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * Initialize a controller that was newly discovered or has lost power | 160 | * Initialize a controller that was newly discovered or has lost power |
183 | * or otherwise been reset while it was suspended. In none of these cases | 161 | * or otherwise been reset while it was suspended. In none of these cases |
184 | * can we be sure of its previous state. | 162 | * can we be sure of its previous state. |
@@ -189,18 +167,6 @@ static void check_and_reset_hc(struct uhci_hcd *uhci) | |||
189 | finish_reset(uhci); | 167 | finish_reset(uhci); |
190 | } | 168 | } |
191 | 169 | ||
192 | static void uhci_pci_configure_hc(struct uhci_hcd *uhci) | ||
193 | { | ||
194 | struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci)); | ||
195 | |||
196 | /* Enable PIRQ */ | ||
197 | pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT); | ||
198 | |||
199 | /* Disable platform-specific non-PME# wakeup */ | ||
200 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) | ||
201 | pci_write_config_byte(pdev, USBRES_INTEL, 0); | ||
202 | } | ||
203 | |||
204 | /* | 170 | /* |
205 | * Store the basic register settings needed by the controller. | 171 | * Store the basic register settings needed by the controller. |
206 | */ | 172 | */ |
@@ -221,38 +187,6 @@ static void configure_hc(struct uhci_hcd *uhci) | |||
221 | uhci->configure_hc(uhci); | 187 | uhci->configure_hc(uhci); |
222 | } | 188 | } |
223 | 189 | ||
224 | static int uhci_pci_resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) | ||
225 | { | ||
226 | int port; | ||
227 | |||
228 | switch (to_pci_dev(uhci_dev(uhci))->vendor) { | ||
229 | default: | ||
230 | break; | ||
231 | |||
232 | case PCI_VENDOR_ID_GENESYS: | ||
233 | /* Genesys Logic's GL880S controllers don't generate | ||
234 | * resume-detect interrupts. | ||
235 | */ | ||
236 | return 1; | ||
237 | |||
238 | case PCI_VENDOR_ID_INTEL: | ||
239 | /* Some of Intel's USB controllers have a bug that causes | ||
240 | * resume-detect interrupts if any port has an over-current | ||
241 | * condition. To make matters worse, some motherboards | ||
242 | * hardwire unused USB ports' over-current inputs active! | ||
243 | * To prevent problems, we will not enable resume-detect | ||
244 | * interrupts if any ports are OC. | ||
245 | */ | ||
246 | for (port = 0; port < uhci->rh_numports; ++port) { | ||
247 | if (inw(uhci->io_addr + USBPORTSC1 + port * 2) & | ||
248 | USBPORTSC_OC) | ||
249 | return 1; | ||
250 | } | ||
251 | break; | ||
252 | } | ||
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) | 190 | static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) |
257 | { | 191 | { |
258 | /* If we have to ignore overcurrent events then almost by definition | 192 | /* If we have to ignore overcurrent events then almost by definition |
@@ -264,28 +198,6 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) | |||
264 | uhci->resume_detect_interrupts_are_broken(uhci) : 0; | 198 | uhci->resume_detect_interrupts_are_broken(uhci) : 0; |
265 | } | 199 | } |
266 | 200 | ||
267 | static int uhci_pci_global_suspend_mode_is_broken(struct uhci_hcd *uhci) | ||
268 | { | ||
269 | int port; | ||
270 | const char *sys_info; | ||
271 | static const char bad_Asus_board[] = "A7V8X"; | ||
272 | |||
273 | /* One of Asus's motherboards has a bug which causes it to | ||
274 | * wake up immediately from suspend-to-RAM if any of the ports | ||
275 | * are connected. In such cases we will not set EGSM. | ||
276 | */ | ||
277 | sys_info = dmi_get_system_info(DMI_BOARD_NAME); | ||
278 | if (sys_info && !strcmp(sys_info, bad_Asus_board)) { | ||
279 | for (port = 0; port < uhci->rh_numports; ++port) { | ||
280 | if (inw(uhci->io_addr + USBPORTSC1 + port * 2) & | ||
281 | USBPORTSC_CCS) | ||
282 | return 1; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) | 201 | static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) |
290 | { | 202 | { |
291 | return uhci->global_suspend_mode_is_broken ? | 203 | return uhci->global_suspend_mode_is_broken ? |
@@ -551,82 +463,6 @@ static void release_uhci(struct uhci_hcd *uhci) | |||
551 | uhci->frame, uhci->frame_dma_handle); | 463 | uhci->frame, uhci->frame_dma_handle); |
552 | } | 464 | } |
553 | 465 | ||
554 | static int uhci_init(struct usb_hcd *hcd) | ||
555 | { | ||
556 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | ||
557 | unsigned io_size = (unsigned) hcd->rsrc_len; | ||
558 | int port; | ||
559 | |||
560 | uhci->io_addr = (unsigned long) hcd->rsrc_start; | ||
561 | |||
562 | /* The UHCI spec says devices must have 2 ports, and goes on to say | ||
563 | * they may have more but gives no way to determine how many there | ||
564 | * are. However according to the UHCI spec, Bit 7 of the port | ||
565 | * status and control register is always set to 1. So we try to | ||
566 | * use this to our advantage. Another common failure mode when | ||
567 | * a nonexistent register is addressed is to return all ones, so | ||
568 | * we test for that also. | ||
569 | */ | ||
570 | for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) { | ||
571 | unsigned int portstatus; | ||
572 | |||
573 | portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2)); | ||
574 | if (!(portstatus & 0x0080) || portstatus == 0xffff) | ||
575 | break; | ||
576 | } | ||
577 | if (debug) | ||
578 | dev_info(uhci_dev(uhci), "detected %d ports\n", port); | ||
579 | |||
580 | /* Anything greater than 7 is weird so we'll ignore it. */ | ||
581 | if (port > UHCI_RH_MAXCHILD) { | ||
582 | dev_info(uhci_dev(uhci), "port count misdetected? " | ||
583 | "forcing to 2 ports\n"); | ||
584 | port = 2; | ||
585 | } | ||
586 | uhci->rh_numports = port; | ||
587 | |||
588 | /* Intel controllers report the OverCurrent bit active on. | ||
589 | * VIA controllers report it active off, so we'll adjust the | ||
590 | * bit value. (It's not standardized in the UHCI spec.) | ||
591 | */ | ||
592 | if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA) | ||
593 | uhci->oc_low = 1; | ||
594 | |||
595 | /* HP's server management chip requires a longer port reset delay. */ | ||
596 | if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_HP) | ||
597 | uhci->wait_for_hp = 1; | ||
598 | |||
599 | /* Set up pointers to PCI-specific functions */ | ||
600 | uhci->reset_hc = uhci_pci_reset_hc; | ||
601 | uhci->check_and_reset_hc = uhci_pci_check_and_reset_hc; | ||
602 | uhci->configure_hc = uhci_pci_configure_hc; | ||
603 | uhci->resume_detect_interrupts_are_broken = | ||
604 | uhci_pci_resume_detect_interrupts_are_broken; | ||
605 | uhci->global_suspend_mode_is_broken = | ||
606 | uhci_pci_global_suspend_mode_is_broken; | ||
607 | |||
608 | |||
609 | /* Kick BIOS off this hardware and reset if the controller | ||
610 | * isn't already safely quiescent. | ||
611 | */ | ||
612 | check_and_reset_hc(uhci); | ||
613 | return 0; | ||
614 | } | ||
615 | |||
616 | /* Make sure the controller is quiescent and that we're not using it | ||
617 | * any more. This is mainly for the benefit of programs which, like kexec, | ||
618 | * expect the hardware to be idle: not doing DMA or generating IRQs. | ||
619 | * | ||
620 | * This routine may be called in a damaged or failing kernel. Hence we | ||
621 | * do not acquire the spinlock before shutting down the controller. | ||
622 | */ | ||
623 | static void uhci_shutdown(struct pci_dev *pdev) | ||
624 | { | ||
625 | struct usb_hcd *hcd = pci_get_drvdata(pdev); | ||
626 | |||
627 | uhci_hc_died(hcd_to_uhci(hcd)); | ||
628 | } | ||
629 | |||
630 | /* | 466 | /* |
631 | * Allocate a frame list, and then setup the skeleton | 467 | * Allocate a frame list, and then setup the skeleton |
632 | * | 468 | * |
@@ -843,87 +679,6 @@ static int uhci_rh_resume(struct usb_hcd *hcd) | |||
843 | return rc; | 679 | return rc; |
844 | } | 680 | } |
845 | 681 | ||
846 | static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | ||
847 | { | ||
848 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | ||
849 | struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci)); | ||
850 | int rc = 0; | ||
851 | |||
852 | dev_dbg(uhci_dev(uhci), "%s\n", __func__); | ||
853 | |||
854 | spin_lock_irq(&uhci->lock); | ||
855 | if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) | ||
856 | goto done_okay; /* Already suspended or dead */ | ||
857 | |||
858 | if (uhci->rh_state > UHCI_RH_SUSPENDED) { | ||
859 | dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); | ||
860 | rc = -EBUSY; | ||
861 | goto done; | ||
862 | }; | ||
863 | |||
864 | /* All PCI host controllers are required to disable IRQ generation | ||
865 | * at the source, so we must turn off PIRQ. | ||
866 | */ | ||
867 | pci_write_config_word(pdev, USBLEGSUP, 0); | ||
868 | clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
869 | |||
870 | /* Enable platform-specific non-PME# wakeup */ | ||
871 | if (do_wakeup) { | ||
872 | if (pdev->vendor == PCI_VENDOR_ID_INTEL) | ||
873 | pci_write_config_byte(pdev, USBRES_INTEL, | ||
874 | USBPORT1EN | USBPORT2EN); | ||
875 | } | ||
876 | |||
877 | done_okay: | ||
878 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
879 | done: | ||
880 | spin_unlock_irq(&uhci->lock); | ||
881 | return rc; | ||
882 | } | ||
883 | |||
884 | static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated) | ||
885 | { | ||
886 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | ||
887 | |||
888 | dev_dbg(uhci_dev(uhci), "%s\n", __func__); | ||
889 | |||
890 | /* Since we aren't in D3 any more, it's safe to set this flag | ||
891 | * even if the controller was dead. | ||
892 | */ | ||
893 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
894 | |||
895 | spin_lock_irq(&uhci->lock); | ||
896 | |||
897 | /* Make sure resume from hibernation re-enumerates everything */ | ||
898 | if (hibernated) { | ||
899 | uhci->reset_hc(uhci); | ||
900 | finish_reset(uhci); | ||
901 | } | ||
902 | |||
903 | /* The firmware may have changed the controller settings during | ||
904 | * a system wakeup. Check it and reconfigure to avoid problems. | ||
905 | */ | ||
906 | else { | ||
907 | check_and_reset_hc(uhci); | ||
908 | } | ||
909 | configure_hc(uhci); | ||
910 | |||
911 | /* Tell the core if the controller had to be reset */ | ||
912 | if (uhci->rh_state == UHCI_RH_RESET) | ||
913 | usb_root_hub_lost_power(hcd->self.root_hub); | ||
914 | |||
915 | spin_unlock_irq(&uhci->lock); | ||
916 | |||
917 | /* If interrupts don't work and remote wakeup is enabled then | ||
918 | * the suspended root hub needs to be polled. | ||
919 | */ | ||
920 | if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) | ||
921 | set_bit(HCD_FLAG_POLL_RH, &hcd->flags); | ||
922 | |||
923 | /* Does the root hub have a port wakeup pending? */ | ||
924 | usb_hcd_poll_rh_status(hcd); | ||
925 | return 0; | ||
926 | } | ||
927 | #endif | 682 | #endif |
928 | 683 | ||
929 | /* Wait until a particular device/endpoint's QH is idle, and free it */ | 684 | /* Wait until a particular device/endpoint's QH is idle, and free it */ |
@@ -966,62 +721,45 @@ static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) | |||
966 | return frame_number + delta; | 721 | return frame_number + delta; |
967 | } | 722 | } |
968 | 723 | ||
969 | static const char hcd_name[] = "uhci_hcd"; | 724 | /* Determines number of ports on controller */ |
970 | 725 | static int uhci_count_ports(struct usb_hcd *hcd) | |
971 | static const struct hc_driver uhci_driver = { | 726 | { |
972 | .description = hcd_name, | 727 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
973 | .product_desc = "UHCI Host Controller", | 728 | unsigned io_size = (unsigned) hcd->rsrc_len; |
974 | .hcd_priv_size = sizeof(struct uhci_hcd), | 729 | int port; |
975 | |||
976 | /* Generic hardware linkage */ | ||
977 | .irq = uhci_irq, | ||
978 | .flags = HCD_USB11, | ||
979 | |||
980 | /* Basic lifecycle operations */ | ||
981 | .reset = uhci_init, | ||
982 | .start = uhci_start, | ||
983 | #ifdef CONFIG_PM | ||
984 | .pci_suspend = uhci_pci_suspend, | ||
985 | .pci_resume = uhci_pci_resume, | ||
986 | .bus_suspend = uhci_rh_suspend, | ||
987 | .bus_resume = uhci_rh_resume, | ||
988 | #endif | ||
989 | .stop = uhci_stop, | ||
990 | |||
991 | .urb_enqueue = uhci_urb_enqueue, | ||
992 | .urb_dequeue = uhci_urb_dequeue, | ||
993 | 730 | ||
994 | .endpoint_disable = uhci_hcd_endpoint_disable, | 731 | /* The UHCI spec says devices must have 2 ports, and goes on to say |
995 | .get_frame_number = uhci_hcd_get_frame_number, | 732 | * they may have more but gives no way to determine how many there |
733 | * are. However according to the UHCI spec, Bit 7 of the port | ||
734 | * status and control register is always set to 1. So we try to | ||
735 | * use this to our advantage. Another common failure mode when | ||
736 | * a nonexistent register is addressed is to return all ones, so | ||
737 | * we test for that also. | ||
738 | */ | ||
739 | for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) { | ||
740 | unsigned int portstatus; | ||
996 | 741 | ||
997 | .hub_status_data = uhci_hub_status_data, | 742 | portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2)); |
998 | .hub_control = uhci_hub_control, | 743 | if (!(portstatus & 0x0080) || portstatus == 0xffff) |
999 | }; | 744 | break; |
745 | } | ||
746 | if (debug) | ||
747 | dev_info(uhci_dev(uhci), "detected %d ports\n", port); | ||
1000 | 748 | ||
1001 | static DEFINE_PCI_DEVICE_TABLE(uhci_pci_ids) = { { | 749 | /* Anything greater than 7 is weird so we'll ignore it. */ |
1002 | /* handle any USB UHCI controller */ | 750 | if (port > UHCI_RH_MAXCHILD) { |
1003 | PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0), | 751 | dev_info(uhci_dev(uhci), "port count misdetected? " |
1004 | .driver_data = (unsigned long) &uhci_driver, | 752 | "forcing to 2 ports\n"); |
1005 | }, { /* end: all zeroes */ } | 753 | port = 2; |
1006 | }; | 754 | } |
1007 | 755 | ||
1008 | MODULE_DEVICE_TABLE(pci, uhci_pci_ids); | 756 | return port; |
757 | } | ||
1009 | 758 | ||
1010 | static struct pci_driver uhci_pci_driver = { | 759 | static const char hcd_name[] = "uhci_hcd"; |
1011 | .name = (char *)hcd_name, | ||
1012 | .id_table = uhci_pci_ids, | ||
1013 | 760 | ||
1014 | .probe = usb_hcd_pci_probe, | 761 | #include "uhci-pci.c" |
1015 | .remove = usb_hcd_pci_remove, | ||
1016 | .shutdown = uhci_shutdown, | ||
1017 | 762 | ||
1018 | #ifdef CONFIG_PM_SLEEP | ||
1019 | .driver = { | ||
1020 | .pm = &usb_hcd_pci_pm_ops | ||
1021 | }, | ||
1022 | #endif | ||
1023 | }; | ||
1024 | |||
1025 | static int __init uhci_hcd_init(void) | 763 | static int __init uhci_hcd_init(void) |
1026 | { | 764 | { |
1027 | int retval = -ENOMEM; | 765 | int retval = -ENOMEM; |