| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * OHCI HCD (Host Controller Driver) for USB. | 
 | 3 |  * | 
 | 4 |  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> | 
 | 5 |  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 6 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  * [ Initialisation is based on Linus'  ] | 
 | 8 |  * [ uhci code and gregs ohci fragments ] | 
 | 9 |  * [ (C) Copyright 1999 Linus Torvalds  ] | 
 | 10 |  * [ (C) Copyright 1999 Gregory P. Smith] | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 11 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 |  * PCI Bus Glue | 
 | 13 |  * | 
 | 14 |  * This file is licenced under the GPL. | 
 | 15 |  */ | 
| David Brownell | dd9048a | 2006-12-05 03:18:31 -0800 | [diff] [blame] | 16 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #ifndef CONFIG_PCI | 
 | 18 | #error "This file is PCI bus glue.  CONFIG_PCI must be defined." | 
 | 19 | #endif | 
 | 20 |  | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 21 | #include <linux/pci.h> | 
 | 22 | #include <linux/io.h> | 
 | 23 |  | 
 | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /*-------------------------------------------------------------------------*/ | 
 | 26 |  | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 27 | static int broken_suspend(struct usb_hcd *hcd) | 
 | 28 | { | 
 | 29 | 	device_init_wakeup(&hcd->self.root_hub->dev, 0); | 
 | 30 | 	return 0; | 
 | 31 | } | 
 | 32 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 33 | /* AMD 756, for most chips (early revs), corrupts register | 
 | 34 |  * values on read ... so enable the vendor workaround. | 
 | 35 |  */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 36 | static int ohci_quirk_amd756(struct usb_hcd *hcd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { | 
 | 38 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 39 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 40 | 	ohci->flags = OHCI_QUIRK_AMD756; | 
 | 41 | 	ohci_dbg (ohci, "AMD756 erratum 4 workaround\n"); | 
 | 42 |  | 
 | 43 | 	/* also erratum 10 (suspend/resume issues) */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 44 | 	return broken_suspend(hcd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } | 
 | 46 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 47 | /* Apple's OHCI driver has a lot of bizarre workarounds | 
 | 48 |  * for this chip.  Evidently control and bulk lists | 
 | 49 |  * can get confused.  (B&W G3 models, and ...) | 
 | 50 |  */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 51 | static int ohci_quirk_opti(struct usb_hcd *hcd) | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 52 | { | 
 | 53 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 54 |  | 
 | 55 | 	ohci_dbg (ohci, "WARNING: OPTi workarounds unavailable\n"); | 
 | 56 |  | 
 | 57 | 	return 0; | 
 | 58 | } | 
 | 59 |  | 
 | 60 | /* Check for NSC87560. We have to look at the bridge (fn1) to | 
 | 61 |  * identify the USB (fn2). This quirk might apply to more or | 
 | 62 |  * even all NSC stuff. | 
 | 63 |  */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 64 | static int ohci_quirk_ns(struct usb_hcd *hcd) | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 65 | { | 
 | 66 | 	struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 
 | 67 | 	struct pci_dev	*b; | 
 | 68 |  | 
 | 69 | 	b  = pci_get_slot (pdev->bus, PCI_DEVFN (PCI_SLOT (pdev->devfn), 1)); | 
 | 70 | 	if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO | 
 | 71 | 	    && b->vendor == PCI_VENDOR_ID_NS) { | 
 | 72 | 		struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 73 |  | 
 | 74 | 		ohci->flags |= OHCI_QUIRK_SUPERIO; | 
 | 75 | 		ohci_dbg (ohci, "Using NSC SuperIO setup\n"); | 
 | 76 | 	} | 
 | 77 | 	pci_dev_put(b); | 
 | 78 |  | 
 | 79 | 	return 0; | 
 | 80 | } | 
 | 81 |  | 
 | 82 | /* Check for Compaq's ZFMicro chipset, which needs short | 
 | 83 |  * delays before control or bulk queues get re-activated | 
 | 84 |  * in finish_unlinks() | 
 | 85 |  */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 86 | static int ohci_quirk_zfmicro(struct usb_hcd *hcd) | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 87 | { | 
 | 88 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 89 |  | 
 | 90 | 	ohci->flags |= OHCI_QUIRK_ZFMICRO; | 
| Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 91 | 	ohci_dbg(ohci, "enabled Compaq ZFMicro chipset quirks\n"); | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 92 |  | 
 | 93 | 	return 0; | 
 | 94 | } | 
 | 95 |  | 
| Benjamin Herrenschmidt | 11d1a4a | 2006-12-15 06:54:03 +1100 | [diff] [blame] | 96 | /* Check for Toshiba SCC OHCI which has big endian registers | 
 | 97 |  * and little endian in memory data structures | 
 | 98 |  */ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 99 | static int ohci_quirk_toshiba_scc(struct usb_hcd *hcd) | 
| Benjamin Herrenschmidt | 11d1a4a | 2006-12-15 06:54:03 +1100 | [diff] [blame] | 100 | { | 
 | 101 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 102 |  | 
 | 103 | 	/* That chip is only present in the southbridge of some | 
 | 104 | 	 * cell based platforms which are supposed to select | 
 | 105 | 	 * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO. We verify here if | 
 | 106 | 	 * that was the case though. | 
 | 107 | 	 */ | 
 | 108 | #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO | 
 | 109 | 	ohci->flags |= OHCI_QUIRK_BE_MMIO; | 
 | 110 | 	ohci_dbg (ohci, "enabled big endian Toshiba quirk\n"); | 
 | 111 | 	return 0; | 
 | 112 | #else | 
 | 113 | 	ohci_err (ohci, "unsupported big endian Toshiba quirk\n"); | 
 | 114 | 	return -ENXIO; | 
 | 115 | #endif | 
 | 116 | } | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 117 |  | 
| Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 118 | /* Check for NEC chip and apply quirk for allegedly lost interrupts. | 
 | 119 |  */ | 
| Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 120 |  | 
 | 121 | static void ohci_quirk_nec_worker(struct work_struct *work) | 
 | 122 | { | 
 | 123 | 	struct ohci_hcd *ohci = container_of(work, struct ohci_hcd, nec_work); | 
 | 124 | 	int status; | 
 | 125 |  | 
 | 126 | 	status = ohci_init(ohci); | 
 | 127 | 	if (status != 0) { | 
 | 128 | 		ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n", | 
 | 129 | 			 "ohci_init", status); | 
 | 130 | 		return; | 
 | 131 | 	} | 
 | 132 |  | 
 | 133 | 	status = ohci_restart(ohci); | 
 | 134 | 	if (status != 0) | 
 | 135 | 		ohci_err(ohci, "Restarting NEC controller failed in %s, %d\n", | 
 | 136 | 			 "ohci_restart", status); | 
 | 137 | } | 
 | 138 |  | 
| Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 139 | static int ohci_quirk_nec(struct usb_hcd *hcd) | 
 | 140 | { | 
 | 141 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 142 |  | 
 | 143 | 	ohci->flags |= OHCI_QUIRK_NEC; | 
| Mike Nuss | 89a0fd1 | 2007-08-01 13:24:30 -0700 | [diff] [blame] | 144 | 	INIT_WORK(&ohci->nec_work, ohci_quirk_nec_worker); | 
| Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 145 | 	ohci_dbg (ohci, "enabled NEC chipset lost interrupt quirk\n"); | 
 | 146 |  | 
 | 147 | 	return 0; | 
 | 148 | } | 
 | 149 |  | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 150 | static int ohci_quirk_amd700(struct usb_hcd *hcd) | 
 | 151 | { | 
 | 152 | 	struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 
| Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 153 | 	struct pci_dev *amd_smbus_dev; | 
| Sergei Shtylyov | fa417c3 | 2011-03-03 21:10:05 +0300 | [diff] [blame] | 154 | 	u8 rev; | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 155 |  | 
| Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 156 | 	if (usb_amd_find_chipset_info()) | 
 | 157 | 		ohci->flags |= OHCI_QUIRK_AMD_PLL; | 
 | 158 |  | 
 | 159 | 	amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, | 
 | 160 | 			PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL); | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 161 | 	if (!amd_smbus_dev) | 
 | 162 | 		return 0; | 
 | 163 |  | 
| Sergei Shtylyov | fa417c3 | 2011-03-03 21:10:05 +0300 | [diff] [blame] | 164 | 	rev = amd_smbus_dev->revision; | 
| Libin Yang | a1f17a87 | 2009-11-04 14:55:18 +0800 | [diff] [blame] | 165 |  | 
 | 166 | 	/* SB800 needs pre-fetch fix */ | 
 | 167 | 	if ((rev >= 0x40) && (rev <= 0x4f)) { | 
 | 168 | 		ohci->flags |= OHCI_QUIRK_AMD_PREFETCH; | 
 | 169 | 		ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); | 
 | 170 | 	} | 
 | 171 |  | 
| Andiry Xu | ad93562 | 2011-03-01 14:57:05 +0800 | [diff] [blame] | 172 | 	pci_dev_put(amd_smbus_dev); | 
 | 173 | 	amd_smbus_dev = NULL; | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 174 |  | 
 | 175 | 	return 0; | 
 | 176 | } | 
 | 177 |  | 
| Alan Stern | 3df7169 | 2010-09-10 16:37:05 -0400 | [diff] [blame] | 178 | /* nVidia controllers continue to drive Reset signalling on the bus | 
 | 179 |  * even after system shutdown, wasting power.  This flag tells the | 
 | 180 |  * shutdown routine to leave the controller OPERATIONAL instead of RESET. | 
 | 181 |  */ | 
 | 182 | static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd) | 
 | 183 | { | 
 | 184 | 	struct ohci_hcd	*ohci = hcd_to_ohci(hcd); | 
 | 185 |  | 
 | 186 | 	ohci->flags |= OHCI_QUIRK_SHUTDOWN; | 
 | 187 | 	ohci_dbg(ohci, "enabled nVidia shutdown quirk\n"); | 
 | 188 |  | 
 | 189 | 	return 0; | 
 | 190 | } | 
 | 191 |  | 
| Libin Yang | a1f17a87 | 2009-11-04 14:55:18 +0800 | [diff] [blame] | 192 | static void sb800_prefetch(struct ohci_hcd *ohci, int on) | 
 | 193 | { | 
 | 194 | 	struct pci_dev *pdev; | 
 | 195 | 	u16 misc; | 
 | 196 |  | 
 | 197 | 	pdev = to_pci_dev(ohci_to_hcd(ohci)->self.controller); | 
 | 198 | 	pci_read_config_word(pdev, 0x50, &misc); | 
 | 199 | 	if (on == 0) | 
 | 200 | 		pci_write_config_word(pdev, 0x50, misc & 0xfcff); | 
 | 201 | 	else | 
 | 202 | 		pci_write_config_word(pdev, 0x50, misc | 0x0300); | 
 | 203 | } | 
 | 204 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 205 | /* List of quirks for OHCI */ | 
 | 206 | static const struct pci_device_id ohci_pci_quirks[] = { | 
 | 207 | 	{ | 
 | 208 | 		PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x740c), | 
 | 209 | 		.driver_data = (unsigned long)ohci_quirk_amd756, | 
 | 210 | 	}, | 
 | 211 | 	{ | 
 | 212 | 		PCI_DEVICE(PCI_VENDOR_ID_OPTI, 0xc861), | 
 | 213 | 		.driver_data = (unsigned long)ohci_quirk_opti, | 
 | 214 | 	}, | 
 | 215 | 	{ | 
 | 216 | 		PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_ANY_ID), | 
 | 217 | 		.driver_data = (unsigned long)ohci_quirk_ns, | 
 | 218 | 	}, | 
 | 219 | 	{ | 
 | 220 | 		PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xa0f8), | 
 | 221 | 		.driver_data = (unsigned long)ohci_quirk_zfmicro, | 
 | 222 | 	}, | 
| Benjamin Herrenschmidt | 11d1a4a | 2006-12-15 06:54:03 +1100 | [diff] [blame] | 223 | 	{ | 
 | 224 | 		PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, 0x01b6), | 
 | 225 | 		.driver_data = (unsigned long)ohci_quirk_toshiba_scc, | 
 | 226 | 	}, | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 227 | 	{ | 
| Michael Hanselmann | d576bb9 | 2007-05-31 23:34:27 +0200 | [diff] [blame] | 228 | 		PCI_DEVICE(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB), | 
 | 229 | 		.driver_data = (unsigned long)ohci_quirk_nec, | 
 | 230 | 	}, | 
 | 231 | 	{ | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 232 | 		/* Toshiba portege 4000 */ | 
 | 233 | 		.vendor		= PCI_VENDOR_ID_AL, | 
 | 234 | 		.device		= 0x5237, | 
| Andrey Borzenkov | 8ab5e8c | 2007-05-19 14:23:28 -0700 | [diff] [blame] | 235 | 		.subvendor	= PCI_VENDOR_ID_TOSHIBA, | 
| David Brownell | 931384f | 2007-04-17 13:06:29 -0700 | [diff] [blame] | 236 | 		.subdevice	= 0x0004, | 
 | 237 | 		.driver_data	= (unsigned long) broken_suspend, | 
 | 238 | 	}, | 
| Raphael Assenat | 33f73e5 | 2007-04-17 13:09:18 -0700 | [diff] [blame] | 239 | 	{ | 
 | 240 | 		PCI_DEVICE(PCI_VENDOR_ID_ITE, 0x8152), | 
 | 241 | 		.driver_data = (unsigned long) broken_suspend, | 
 | 242 | 	}, | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 243 | 	{ | 
 | 244 | 		PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4397), | 
 | 245 | 		.driver_data = (unsigned long)ohci_quirk_amd700, | 
 | 246 | 	}, | 
 | 247 | 	{ | 
 | 248 | 		PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4398), | 
 | 249 | 		.driver_data = (unsigned long)ohci_quirk_amd700, | 
 | 250 | 	}, | 
 | 251 | 	{ | 
 | 252 | 		PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399), | 
 | 253 | 		.driver_data = (unsigned long)ohci_quirk_amd700, | 
 | 254 | 	}, | 
| Alan Stern | 3df7169 | 2010-09-10 16:37:05 -0400 | [diff] [blame] | 255 | 	{ | 
 | 256 | 		PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), | 
 | 257 | 		.driver_data = (unsigned long) ohci_quirk_nvidia_shutdown, | 
 | 258 | 	}, | 
| Libin Yang | ab1666c | 2008-08-08 15:03:31 +0800 | [diff] [blame] | 259 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 260 | 	/* FIXME for some of the early AMD 760 southbridges, OHCI | 
 | 261 | 	 * won't work at all.  blacklist them. | 
 | 262 | 	 */ | 
| Benjamin Herrenschmidt | 11d1a4a | 2006-12-15 06:54:03 +1100 | [diff] [blame] | 263 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 264 | 	{}, | 
 | 265 | }; | 
 | 266 |  | 
 | 267 | static int ohci_pci_reset (struct usb_hcd *hcd) | 
 | 268 | { | 
 | 269 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 270 | 	int ret = 0; | 
 | 271 |  | 
 | 272 | 	if (hcd->self.controller) { | 
 | 273 | 		struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 
 | 274 | 		const struct pci_device_id *quirk_id; | 
 | 275 |  | 
 | 276 | 		quirk_id = pci_match_id(ohci_pci_quirks, pdev); | 
 | 277 | 		if (quirk_id != NULL) { | 
 | 278 | 			int (*quirk)(struct usb_hcd *ohci); | 
 | 279 | 			quirk = (void *)quirk_id->driver_data; | 
 | 280 | 			ret = quirk(hcd); | 
 | 281 | 		} | 
 | 282 | 	} | 
 | 283 | 	if (ret == 0) { | 
 | 284 | 		ohci_hcd_init (ohci); | 
 | 285 | 		return ohci_init (ohci); | 
 | 286 | 	} | 
 | 287 | 	return ret; | 
 | 288 | } | 
 | 289 |  | 
 | 290 |  | 
 | 291 | static int __devinit ohci_pci_start (struct usb_hcd *hcd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { | 
 | 293 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 294 | 	int		ret; | 
 | 295 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 296 | #ifdef CONFIG_PM /* avoid warnings about unused pdev */ | 
| David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 297 | 	if (hcd->self.controller) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | 		struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | 
 | 299 |  | 
| David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 300 | 		/* RWC may not be set for add-in PCI cards, since boot | 
 | 301 | 		 * firmware probably ignored them.  This transfers PCI | 
| Alan Stern | 6fd9086 | 2008-12-17 17:20:38 -0500 | [diff] [blame] | 302 | 		 * PM wakeup capabilities. | 
| David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 303 | 		 */ | 
| Alan Stern | 6fd9086 | 2008-12-17 17:20:38 -0500 | [diff] [blame] | 304 | 		if (device_can_wakeup(&pdev->dev)) | 
| David Brownell | 6a9062f | 2006-01-23 15:28:07 -0800 | [diff] [blame] | 305 | 			ohci->hc_control |= OHCI_CTRL_RWC; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 	} | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 307 | #endif /* CONFIG_PM */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |  | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 309 | 	ret = ohci_run (ohci); | 
 | 310 | 	if (ret < 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 		ohci_err (ohci, "can't start\n"); | 
 | 312 | 		ohci_stop (hcd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | 	} | 
| Benjamin Herrenschmidt | 4302a595 | 2006-12-15 06:53:55 +1100 | [diff] [blame] | 314 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } | 
 | 316 |  | 
 | 317 | #ifdef	CONFIG_PM | 
 | 318 |  | 
| Alan Stern | 4147200 | 2010-06-25 14:02:14 -0400 | [diff] [blame] | 319 | static int ohci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { | 
| Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 321 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 322 | 	unsigned long	flags; | 
 | 323 | 	int		rc = 0; | 
 | 324 |  | 
 | 325 | 	/* Root hub was already suspended. Disable irq emission and | 
 | 326 | 	 * mark HW unaccessible, bail out if RH has been resumed. Use | 
 | 327 | 	 * the spinlock to properly synchronize with possible pending | 
 | 328 | 	 * RH suspend or resume activity. | 
 | 329 | 	 * | 
 | 330 | 	 * This is still racy as hcd->state is manipulated outside of | 
 | 331 | 	 * any locks =P But that will be a different fix. | 
 | 332 | 	 */ | 
 | 333 | 	spin_lock_irqsave (&ohci->lock, flags); | 
 | 334 | 	if (hcd->state != HC_STATE_SUSPENDED) { | 
 | 335 | 		rc = -EINVAL; | 
 | 336 | 		goto bail; | 
 | 337 | 	} | 
 | 338 | 	ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); | 
 | 339 | 	(void)ohci_readl(ohci, &ohci->regs->intrdisable); | 
| David Brownell | 1858499 | 2006-08-14 23:11:06 -0700 | [diff] [blame] | 340 |  | 
| Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 341 | 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 
 | 342 |  bail: | 
 | 343 | 	spin_unlock_irqrestore (&ohci->lock, flags); | 
 | 344 |  | 
 | 345 | 	return rc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } | 
 | 347 |  | 
 | 348 |  | 
| Alan Stern | 6ec4beb | 2009-04-27 13:33:41 -0400 | [diff] [blame] | 349 | static int ohci_pci_resume(struct usb_hcd *hcd, bool hibernated) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { | 
| Benjamin Herrenschmidt | 8de9840 | 2005-11-25 09:59:46 +1100 | [diff] [blame] | 351 | 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 
| Alan Stern | 6ec4beb | 2009-04-27 13:33:41 -0400 | [diff] [blame] | 352 |  | 
 | 353 | 	/* Make sure resume from hibernation re-enumerates everything */ | 
 | 354 | 	if (hibernated) | 
 | 355 | 		ohci_usb_reset(hcd_to_ohci(hcd)); | 
 | 356 |  | 
| Alan Stern | 43bbb7e | 2008-04-03 18:03:17 -0400 | [diff] [blame] | 357 | 	ohci_finish_controller_resume(hcd); | 
| David Brownell | f197b2c | 2005-09-22 22:42:53 -0700 | [diff] [blame] | 358 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } | 
 | 360 |  | 
 | 361 | #endif	/* CONFIG_PM */ | 
 | 362 |  | 
 | 363 |  | 
 | 364 | /*-------------------------------------------------------------------------*/ | 
 | 365 |  | 
 | 366 | static const struct hc_driver ohci_pci_hc_driver = { | 
 | 367 | 	.description =		hcd_name, | 
 | 368 | 	.product_desc =		"OHCI Host Controller", | 
 | 369 | 	.hcd_priv_size =	sizeof(struct ohci_hcd), | 
 | 370 |  | 
 | 371 | 	/* | 
 | 372 | 	 * generic hardware linkage | 
 | 373 | 	 */ | 
 | 374 | 	.irq =			ohci_irq, | 
 | 375 | 	.flags =		HCD_MEMORY | HCD_USB11, | 
 | 376 |  | 
 | 377 | 	/* | 
 | 378 | 	 * basic lifecycle operations | 
 | 379 | 	 */ | 
 | 380 | 	.reset =		ohci_pci_reset, | 
 | 381 | 	.start =		ohci_pci_start, | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 382 | 	.stop =			ohci_stop, | 
| Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 383 | 	.shutdown =		ohci_shutdown, | 
| David Brownell | d413984 | 2006-08-04 11:31:55 -0700 | [diff] [blame] | 384 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | #ifdef	CONFIG_PM | 
| Alan Stern | 7be7d74 | 2008-04-03 18:03:06 -0400 | [diff] [blame] | 386 | 	.pci_suspend =		ohci_pci_suspend, | 
 | 387 | 	.pci_resume =		ohci_pci_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 |  | 
 | 390 | 	/* | 
 | 391 | 	 * managing i/o requests and associated device resources | 
 | 392 | 	 */ | 
 | 393 | 	.urb_enqueue =		ohci_urb_enqueue, | 
 | 394 | 	.urb_dequeue =		ohci_urb_dequeue, | 
 | 395 | 	.endpoint_disable =	ohci_endpoint_disable, | 
 | 396 |  | 
 | 397 | 	/* | 
 | 398 | 	 * scheduling support | 
 | 399 | 	 */ | 
 | 400 | 	.get_frame_number =	ohci_get_frame, | 
 | 401 |  | 
 | 402 | 	/* | 
 | 403 | 	 * root hub support | 
 | 404 | 	 */ | 
 | 405 | 	.hub_status_data =	ohci_hub_status_data, | 
 | 406 | 	.hub_control =		ohci_hub_control, | 
| David Brownell | 8ad7fe1 | 2005-09-13 19:59:11 -0700 | [diff] [blame] | 407 | #ifdef	CONFIG_PM | 
| Alan Stern | 0c0382e | 2005-10-13 17:08:02 -0400 | [diff] [blame] | 408 | 	.bus_suspend =		ohci_bus_suspend, | 
 | 409 | 	.bus_resume =		ohci_bus_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | #endif | 
 | 411 | 	.start_port_reset =	ohci_start_port_reset, | 
 | 412 | }; | 
 | 413 |  | 
 | 414 | /*-------------------------------------------------------------------------*/ | 
 | 415 |  | 
 | 416 |  | 
 | 417 | static const struct pci_device_id pci_ids [] = { { | 
 | 418 | 	/* handle any USB OHCI controller */ | 
| Jean Delvare | c67808e | 2006-04-09 20:07:35 +0200 | [diff] [blame] | 419 | 	PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_OHCI, ~0), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | 	.driver_data =	(unsigned long) &ohci_pci_hc_driver, | 
 | 421 | 	}, { /* end: all zeroes */ } | 
 | 422 | }; | 
 | 423 | MODULE_DEVICE_TABLE (pci, pci_ids); | 
 | 424 |  | 
 | 425 | /* pci driver glue; this is a "new style" PCI driver module */ | 
 | 426 | static struct pci_driver ohci_pci_driver = { | 
 | 427 | 	.name =		(char *) hcd_name, | 
 | 428 | 	.id_table =	pci_ids, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 |  | 
 | 430 | 	.probe =	usb_hcd_pci_probe, | 
 | 431 | 	.remove =	usb_hcd_pci_remove, | 
| Aleksey Gorelov | 64a21d0 | 2006-08-08 17:24:08 -0700 | [diff] [blame] | 432 | 	.shutdown =	usb_hcd_pci_shutdown, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 |  | 
| Alan Stern | abb3064 | 2009-04-27 13:33:24 -0400 | [diff] [blame] | 434 | #ifdef CONFIG_PM_SLEEP | 
 | 435 | 	.driver =	{ | 
 | 436 | 		.pm =	&usb_hcd_pci_pm_ops | 
 | 437 | 	}, | 
 | 438 | #endif | 
 | 439 | }; |