| Vladimir Barinov | 91bc4d3 | 2007-12-30 15:21:11 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * IXP4XX EHCI Host Controller Driver | 
 | 3 |  * | 
 | 4 |  * Author: Vladimir Barinov <vbarinov@ru.mvista.com> | 
 | 5 |  * | 
 | 6 |  * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com> | 
 | 7 |  * | 
 | 8 |  * 2007 (c) MontaVista Software, Inc. This file is licensed under | 
 | 9 |  * the terms of the GNU General Public License version 2. This program | 
 | 10 |  * is licensed "as is" without any warranty of any kind, whether express | 
 | 11 |  * or implied. | 
 | 12 |  */ | 
 | 13 |  | 
 | 14 | #include <linux/platform_device.h> | 
 | 15 |  | 
 | 16 | static int ixp4xx_ehci_init(struct usb_hcd *hcd) | 
 | 17 | { | 
 | 18 | 	struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 
 | 19 | 	int retval = 0; | 
 | 20 |  | 
 | 21 | 	ehci->big_endian_desc = 1; | 
 | 22 | 	ehci->big_endian_mmio = 1; | 
 | 23 |  | 
 | 24 | 	ehci->caps = hcd->regs + 0x100; | 
 | 25 | 	ehci->regs = hcd->regs + 0x100 | 
 | 26 | 		+ HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | 
 | 27 | 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 
 | 28 |  | 
 | 29 | 	ehci->is_tdi_rh_tt = 1; | 
 | 30 | 	ehci_reset(ehci); | 
 | 31 |  | 
 | 32 | 	retval = ehci_init(hcd); | 
 | 33 | 	if (retval) | 
 | 34 | 		return retval; | 
 | 35 |  | 
 | 36 | 	ehci_port_power(ehci, 0); | 
 | 37 |  | 
 | 38 | 	return retval; | 
 | 39 | } | 
 | 40 |  | 
 | 41 | static const struct hc_driver ixp4xx_ehci_hc_driver = { | 
 | 42 | 	.description		= hcd_name, | 
 | 43 | 	.product_desc		= "IXP4XX EHCI Host Controller", | 
 | 44 | 	.hcd_priv_size		= sizeof(struct ehci_hcd), | 
 | 45 | 	.irq			= ehci_irq, | 
 | 46 | 	.flags			= HCD_MEMORY | HCD_USB2, | 
 | 47 | 	.reset			= ixp4xx_ehci_init, | 
 | 48 | 	.start			= ehci_run, | 
 | 49 | 	.stop			= ehci_stop, | 
 | 50 | 	.shutdown		= ehci_shutdown, | 
 | 51 | 	.urb_enqueue		= ehci_urb_enqueue, | 
 | 52 | 	.urb_dequeue		= ehci_urb_dequeue, | 
 | 53 | 	.endpoint_disable	= ehci_endpoint_disable, | 
 | 54 | 	.get_frame_number	= ehci_get_frame, | 
 | 55 | 	.hub_status_data	= ehci_hub_status_data, | 
 | 56 | 	.hub_control		= ehci_hub_control, | 
 | 57 | #if defined(CONFIG_PM) | 
 | 58 | 	.bus_suspend		= ehci_bus_suspend, | 
 | 59 | 	.bus_resume		= ehci_bus_resume, | 
 | 60 | #endif | 
 | 61 | }; | 
 | 62 |  | 
 | 63 | static int ixp4xx_ehci_probe(struct platform_device *pdev) | 
 | 64 | { | 
 | 65 | 	struct usb_hcd *hcd; | 
 | 66 | 	const struct hc_driver *driver = &ixp4xx_ehci_hc_driver; | 
 | 67 | 	struct resource *res; | 
 | 68 | 	int irq; | 
 | 69 | 	int retval; | 
 | 70 |  | 
 | 71 | 	if (usb_disabled()) | 
 | 72 | 		return -ENODEV; | 
 | 73 |  | 
 | 74 | 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | 
 | 75 | 	if (!res) { | 
 | 76 | 		dev_err(&pdev->dev, | 
 | 77 | 			"Found HC with no IRQ. Check %s setup!\n", | 
 | 78 | 			pdev->dev.bus_id); | 
 | 79 | 		return -ENODEV; | 
 | 80 | 	} | 
 | 81 | 	irq = res->start; | 
 | 82 |  | 
 | 83 | 	hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id); | 
 | 84 | 	if (!hcd) { | 
 | 85 | 		retval = -ENOMEM; | 
 | 86 | 		goto fail_create_hcd; | 
 | 87 | 	} | 
 | 88 |  | 
 | 89 | 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 
 | 90 | 	if (!res) { | 
 | 91 | 		dev_err(&pdev->dev, | 
 | 92 | 			"Found HC with no register addr. Check %s setup!\n", | 
 | 93 | 			pdev->dev.bus_id); | 
 | 94 | 		retval = -ENODEV; | 
 | 95 | 		goto fail_request_resource; | 
 | 96 | 	} | 
 | 97 | 	hcd->rsrc_start = res->start; | 
 | 98 | 	hcd->rsrc_len = res->end - res->start + 1; | 
 | 99 |  | 
 | 100 | 	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | 
 | 101 | 				driver->description)) { | 
 | 102 | 		dev_dbg(&pdev->dev, "controller already in use\n"); | 
 | 103 | 		retval = -EBUSY; | 
 | 104 | 		goto fail_request_resource; | 
 | 105 | 	} | 
 | 106 |  | 
 | 107 | 	hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | 
 | 108 | 	if (hcd->regs == NULL) { | 
 | 109 | 		dev_dbg(&pdev->dev, "error mapping memory\n"); | 
 | 110 | 		retval = -EFAULT; | 
 | 111 | 		goto fail_ioremap; | 
 | 112 | 	} | 
 | 113 |  | 
 | 114 | 	retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 
 | 115 | 	if (retval) | 
 | 116 | 		goto fail_add_hcd; | 
 | 117 |  | 
 | 118 | 	return retval; | 
 | 119 |  | 
 | 120 | fail_add_hcd: | 
 | 121 | 	iounmap(hcd->regs); | 
 | 122 | fail_ioremap: | 
 | 123 | 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
 | 124 | fail_request_resource: | 
 | 125 | 	usb_put_hcd(hcd); | 
 | 126 | fail_create_hcd: | 
 | 127 | 	dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval); | 
 | 128 | 	return retval; | 
 | 129 | } | 
 | 130 |  | 
 | 131 | static int ixp4xx_ehci_remove(struct platform_device *pdev) | 
 | 132 | { | 
 | 133 | 	struct usb_hcd *hcd = platform_get_drvdata(pdev); | 
 | 134 |  | 
 | 135 | 	usb_remove_hcd(hcd); | 
 | 136 | 	iounmap(hcd->regs); | 
 | 137 | 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
 | 138 | 	usb_put_hcd(hcd); | 
 | 139 |  | 
 | 140 | 	return 0; | 
 | 141 | } | 
 | 142 |  | 
 | 143 | MODULE_ALIAS("ixp4xx-ehci"); | 
 | 144 |  | 
 | 145 | static struct platform_driver ixp4xx_ehci_driver = { | 
 | 146 | 	.probe = ixp4xx_ehci_probe, | 
 | 147 | 	.remove = ixp4xx_ehci_remove, | 
 | 148 | 	.driver = { | 
 | 149 | 		.name = "ixp4xx-ehci", | 
 | 150 | 		.bus = &platform_bus_type | 
 | 151 | 	}, | 
 | 152 | }; |