| Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -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> | 
 | 6 |  * (C) Copyright 2002 Hewlett-Packard Company | 
 | 7 |  * (C) Copyright 2005 Embedded Alley Solutions, Inc. | 
 | 8 |  * | 
 | 9 |  * Bus Glue for PNX8550 | 
 | 10 |  * | 
 | 11 |  * Written by Christopher Hoover <ch@hpl.hp.com> | 
 | 12 |  * Based on fragments of previous driver by Russell King et al. | 
 | 13 |  * | 
 | 14 |  * Modified for LH7A404 from ohci-sa1111.c | 
 | 15 |  *  by Durgesh Pattamatta <pattamattad@sharpsec.com> | 
 | 16 |  * | 
 | 17 |  * Modified for PNX8550 from ohci-sa1111.c and sa-omap.c | 
 | 18 |  *  by Vitaly Wool <vitalywool@gmail.com> | 
 | 19 |  * | 
 | 20 |  * This file is licenced under the GPL. | 
 | 21 |  */ | 
 | 22 |  | 
 | 23 | #include <linux/device.h> | 
 | 24 | #include <linux/platform_device.h> | 
 | 25 | #include <asm/mach-pnx8550/usb.h> | 
 | 26 | #include <asm/mach-pnx8550/int.h> | 
 | 27 | #include <asm/mach-pnx8550/pci.h> | 
 | 28 |  | 
 | 29 | #ifndef CONFIG_PNX8550 | 
 | 30 | #error "This file is PNX8550 bus glue.  CONFIG_PNX8550 must be defined." | 
 | 31 | #endif | 
 | 32 |  | 
 | 33 | extern int usb_disabled(void); | 
 | 34 |  | 
 | 35 | /*-------------------------------------------------------------------------*/ | 
 | 36 |  | 
 | 37 | static void pnx8550_start_hc(struct platform_device *dev) | 
 | 38 | { | 
 | 39 | 	/* | 
 | 40 | 	 * Set register CLK48CTL to enable and 48MHz | 
 | 41 | 	 */ | 
 | 42 | 	outl(0x00000003, PCI_BASE | 0x0004770c); | 
 | 43 |  | 
 | 44 | 	/* | 
 | 45 | 	 * Set register CLK12CTL to enable and 48MHz | 
 | 46 | 	 */ | 
 | 47 | 	outl(0x00000003, PCI_BASE | 0x00047710); | 
 | 48 |  | 
 | 49 | 	udelay(100); | 
 | 50 | } | 
 | 51 |  | 
 | 52 | static void pnx8550_stop_hc(struct platform_device *dev) | 
 | 53 | { | 
 | 54 | 	udelay(10); | 
 | 55 | } | 
 | 56 |  | 
 | 57 |  | 
 | 58 | /*-------------------------------------------------------------------------*/ | 
 | 59 |  | 
 | 60 | /* configure so an HC device and id are always provided */ | 
 | 61 | /* always called with process context; sleeping is OK */ | 
 | 62 |  | 
 | 63 |  | 
 | 64 | /** | 
 | 65 |  * usb_hcd_pnx8550_probe - initialize pnx8550-based HCDs | 
 | 66 |  * Context: !in_interrupt() | 
 | 67 |  * | 
 | 68 |  * Allocates basic resources for this USB host controller, and | 
 | 69 |  * then invokes the start() method for the HCD associated with it | 
 | 70 |  * through the hotplug entry's driver_data. | 
 | 71 |  * | 
 | 72 |  */ | 
 | 73 | int usb_hcd_pnx8550_probe (const struct hc_driver *driver, | 
 | 74 | 			  struct platform_device *dev) | 
 | 75 | { | 
 | 76 | 	int retval; | 
 | 77 | 	struct usb_hcd *hcd; | 
 | 78 |  | 
 | 79 | 	if (dev->resource[0].flags != IORESOURCE_MEM || | 
 | 80 | 			dev->resource[1].flags != IORESOURCE_IRQ) { | 
 | 81 | 		dev_err (&dev->dev,"invalid resource type\n"); | 
 | 82 | 		return -ENOMEM; | 
 | 83 | 	} | 
 | 84 |  | 
 | 85 | 	hcd = usb_create_hcd (driver, &dev->dev, "pnx8550"); | 
 | 86 | 	if (!hcd) | 
 | 87 | 		return -ENOMEM; | 
 | 88 | 	hcd->rsrc_start = dev->resource[0].start; | 
 | 89 | 	hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; | 
 | 90 |  | 
 | 91 | 	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 
 | 92 | 		dev_err(&dev->dev, "request_mem_region [0x%08llx, 0x%08llx] " | 
 | 93 | 				"failed\n", hcd->rsrc_start, hcd->rsrc_len); | 
 | 94 | 		retval = -EBUSY; | 
 | 95 | 		goto err1; | 
 | 96 | 	} | 
 | 97 |  | 
 | 98 | 	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | 
 | 99 | 	if (!hcd->regs) { | 
 | 100 | 		dev_err(&dev->dev, "ioremap [[0x%08llx, 0x%08llx] failed\n", | 
 | 101 | 				hcd->rsrc_start, hcd->rsrc_len); | 
 | 102 | 		retval = -ENOMEM; | 
 | 103 | 		goto err2; | 
 | 104 | 	} | 
 | 105 |  | 
 | 106 | 	pnx8550_start_hc(dev); | 
 | 107 |  | 
 | 108 | 	ohci_hcd_init(hcd_to_ohci(hcd)); | 
 | 109 |  | 
| Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 110 | 	retval = usb_add_hcd(hcd, dev->resource[1].start, 0); | 
| Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 111 | 	if (retval == 0) | 
 | 112 | 		return retval; | 
 | 113 |  | 
 | 114 | 	pnx8550_stop_hc(dev); | 
 | 115 | 	iounmap(hcd->regs); | 
 | 116 |  err2: | 
 | 117 | 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
 | 118 |  err1: | 
 | 119 | 	usb_put_hcd(hcd); | 
 | 120 | 	return retval; | 
 | 121 | } | 
 | 122 |  | 
 | 123 |  | 
 | 124 | /* may be called without controller electrically present */ | 
 | 125 | /* may be called with controller, bus, and devices active */ | 
 | 126 |  | 
 | 127 | /** | 
 | 128 |  * usb_hcd_pnx8550_remove - shutdown processing for pnx8550-based HCDs | 
 | 129 |  * @dev: USB Host Controller being removed | 
 | 130 |  * Context: !in_interrupt() | 
 | 131 |  * | 
 | 132 |  * Reverses the effect of usb_hcd_pnx8550_probe(), first invoking | 
 | 133 |  * the HCD's stop() method.  It is always called from a thread | 
 | 134 |  * context, normally "rmmod", "apmd", or something similar. | 
 | 135 |  * | 
 | 136 |  */ | 
 | 137 | void usb_hcd_pnx8550_remove (struct usb_hcd *hcd, struct platform_device *dev) | 
 | 138 | { | 
 | 139 | 	usb_remove_hcd(hcd); | 
 | 140 | 	pnx8550_stop_hc(dev); | 
 | 141 | 	iounmap(hcd->regs); | 
 | 142 | 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
 | 143 | 	usb_put_hcd(hcd); | 
 | 144 | } | 
 | 145 |  | 
 | 146 | /*-------------------------------------------------------------------------*/ | 
 | 147 |  | 
 | 148 | static int __devinit | 
 | 149 | ohci_pnx8550_start (struct usb_hcd *hcd) | 
 | 150 | { | 
 | 151 | 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd); | 
 | 152 | 	int		ret; | 
 | 153 |  | 
 | 154 | 	ohci_dbg (ohci, "ohci_pnx8550_start, ohci:%p", ohci); | 
 | 155 |  | 
 | 156 | 	if ((ret = ohci_init(ohci)) < 0) | 
 | 157 | 		return ret; | 
 | 158 |  | 
 | 159 | 	if ((ret = ohci_run (ohci)) < 0) { | 
 | 160 | 		err ("can't start %s", hcd->self.bus_name); | 
 | 161 | 		ohci_stop (hcd); | 
 | 162 | 		return ret; | 
 | 163 | 	} | 
 | 164 |  | 
 | 165 | 	return 0; | 
 | 166 | } | 
 | 167 |  | 
 | 168 | /*-------------------------------------------------------------------------*/ | 
 | 169 |  | 
 | 170 | static const struct hc_driver ohci_pnx8550_hc_driver = { | 
 | 171 | 	.description =		hcd_name, | 
 | 172 | 	.product_desc =		"PNX8550 OHCI", | 
 | 173 | 	.hcd_priv_size =	sizeof(struct ohci_hcd), | 
 | 174 |  | 
 | 175 | 	/* | 
 | 176 | 	 * generic hardware linkage | 
 | 177 | 	 */ | 
 | 178 | 	.irq =			ohci_irq, | 
 | 179 | 	.flags =		HCD_USB11 | HCD_MEMORY, | 
 | 180 |  | 
 | 181 | 	/* | 
 | 182 | 	 * basic lifecycle operations | 
 | 183 | 	 */ | 
 | 184 | 	.start =		ohci_pnx8550_start, | 
 | 185 | 	.stop =			ohci_stop, | 
 | 186 |  | 
 | 187 | 	/* | 
 | 188 | 	 * managing i/o requests and associated device resources | 
 | 189 | 	 */ | 
 | 190 | 	.urb_enqueue =		ohci_urb_enqueue, | 
 | 191 | 	.urb_dequeue =		ohci_urb_dequeue, | 
 | 192 | 	.endpoint_disable =	ohci_endpoint_disable, | 
 | 193 |  | 
 | 194 | 	/* | 
 | 195 | 	 * scheduling support | 
 | 196 | 	 */ | 
 | 197 | 	.get_frame_number =	ohci_get_frame, | 
 | 198 |  | 
 | 199 | 	/* | 
 | 200 | 	 * root hub support | 
 | 201 | 	 */ | 
 | 202 | 	.hub_status_data =	ohci_hub_status_data, | 
 | 203 | 	.hub_control =		ohci_hub_control, | 
| Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 204 | #ifdef	CONFIG_PM | 
 | 205 | 	.bus_suspend =		ohci_bus_suspend, | 
 | 206 | 	.bus_resume =		ohci_bus_resume, | 
 | 207 | #endif | 
 | 208 | 	.start_port_reset =	ohci_start_port_reset, | 
 | 209 | }; | 
 | 210 |  | 
 | 211 | /*-------------------------------------------------------------------------*/ | 
 | 212 |  | 
 | 213 | static int ohci_hcd_pnx8550_drv_probe(struct platform_device *pdev) | 
 | 214 | { | 
 | 215 | 	int ret; | 
 | 216 |  | 
 | 217 | 	if (usb_disabled()) | 
 | 218 | 		return -ENODEV; | 
 | 219 |  | 
 | 220 | 	ret = usb_hcd_pnx8550_probe(&ohci_pnx8550_hc_driver, pdev); | 
 | 221 | 	return ret; | 
 | 222 | } | 
 | 223 |  | 
 | 224 | static int ohci_hcd_pnx8550_drv_remove(struct platform_device *pdev) | 
 | 225 | { | 
 | 226 | 	struct usb_hcd *hcd = platform_get_drvdata(pdev); | 
 | 227 |  | 
 | 228 | 	usb_hcd_pnx8550_remove(hcd, pdev); | 
 | 229 | 	return 0; | 
 | 230 | } | 
 | 231 |  | 
| Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 232 | MODULE_ALIAS("platform:pnx8550-ohci"); | 
| Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 233 |  | 
 | 234 | static struct platform_driver ohci_hcd_pnx8550_driver = { | 
 | 235 | 	.driver = { | 
| Kay Sievers | f4fce61 | 2008-04-10 21:29:22 -0700 | [diff] [blame] | 236 | 		.name	= "pnx8550-ohci", | 
 | 237 | 		.owner	= THIS_MODULE, | 
| Vitaly Wool | 5151d04 | 2006-10-09 01:32:00 -0700 | [diff] [blame] | 238 | 	}, | 
 | 239 | 	.probe		= ohci_hcd_pnx8550_drv_probe, | 
 | 240 | 	.remove		= ohci_hcd_pnx8550_drv_remove, | 
 | 241 | }; | 
 | 242 |  |