| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/driver/usb/host/ehci-w90x900.c | 
|  | 3 | * | 
|  | 4 | * Copyright (c) 2008 Nuvoton technology corporation. | 
|  | 5 | * | 
|  | 6 | * Wan ZongShun <mcuos.com@gmail.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 | */ | 
|  | 13 |  | 
|  | 14 | #include <linux/platform_device.h> | 
|  | 15 |  | 
|  | 16 | /*ebable phy0 and phy1 for w90p910*/ | 
|  | 17 | #define	ENPHY		(0x01<<8) | 
|  | 18 | #define PHY0_CTR	(0xA4) | 
|  | 19 | #define PHY1_CTR	(0xA8) | 
|  | 20 |  | 
|  | 21 | static int __devinit usb_w90x900_probe(const struct hc_driver *driver, | 
|  | 22 | struct platform_device *pdev) | 
|  | 23 | { | 
|  | 24 | struct usb_hcd *hcd; | 
|  | 25 | struct ehci_hcd *ehci; | 
|  | 26 | struct resource *res; | 
|  | 27 | int retval = 0, irq; | 
|  | 28 | unsigned long val; | 
|  | 29 |  | 
|  | 30 |  | 
|  | 31 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 
|  | 32 | if (!res) { | 
|  | 33 | retval = -ENXIO; | 
|  | 34 | goto err1; | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI"); | 
|  | 38 | if (!hcd) { | 
|  | 39 | retval = -ENOMEM; | 
|  | 40 | goto err1; | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | hcd->rsrc_start = res->start; | 
| Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 44 | hcd->rsrc_len = resource_size(res); | 
| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 45 |  | 
|  | 46 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { | 
|  | 47 | retval = -EBUSY; | 
|  | 48 | goto err2; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); | 
|  | 52 | if (hcd->regs == NULL) { | 
|  | 53 | retval = -EFAULT; | 
|  | 54 | goto err3; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | ehci = hcd_to_ehci(hcd); | 
|  | 58 | ehci->caps = hcd->regs; | 
|  | 59 | ehci->regs = hcd->regs + | 
| Jan Andersson | c430131 | 2011-05-03 20:11:57 +0200 | [diff] [blame] | 60 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); | 
| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 61 |  | 
|  | 62 | /* enable PHY 0,1,the regs only apply to w90p910 | 
|  | 63 | *  0xA4,0xA8 were offsets of PHY0 and PHY1 controller of | 
|  | 64 | *  w90p910 IC relative to ehci->regs. | 
|  | 65 | */ | 
|  | 66 | val = __raw_readl(ehci->regs+PHY0_CTR); | 
|  | 67 | val |= ENPHY; | 
|  | 68 | __raw_writel(val, ehci->regs+PHY0_CTR); | 
|  | 69 |  | 
|  | 70 | val = __raw_readl(ehci->regs+PHY1_CTR); | 
|  | 71 | val |= ENPHY; | 
|  | 72 | __raw_writel(val, ehci->regs+PHY1_CTR); | 
|  | 73 |  | 
|  | 74 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 
|  | 75 | ehci->sbrn = 0x20; | 
|  | 76 |  | 
|  | 77 | irq = platform_get_irq(pdev, 0); | 
|  | 78 | if (irq < 0) | 
|  | 79 | goto err4; | 
|  | 80 |  | 
| Geoff Levand | 876e0df | 2011-11-22 18:04:45 -0800 | [diff] [blame] | 81 | ehci_reset(ehci); | 
|  | 82 |  | 
| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 83 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | 
|  | 84 | if (retval != 0) | 
|  | 85 | goto err4; | 
|  | 86 |  | 
|  | 87 | ehci_writel(ehci, 1, &ehci->regs->configured_flag); | 
|  | 88 |  | 
|  | 89 | return retval; | 
|  | 90 | err4: | 
|  | 91 | iounmap(hcd->regs); | 
|  | 92 | err3: | 
|  | 93 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
|  | 94 | err2: | 
|  | 95 | usb_put_hcd(hcd); | 
|  | 96 | err1: | 
|  | 97 | return retval; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | static | 
|  | 101 | void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) | 
|  | 102 | { | 
|  | 103 | usb_remove_hcd(hcd); | 
|  | 104 | iounmap(hcd->regs); | 
|  | 105 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 
|  | 106 | usb_put_hcd(hcd); | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | static const struct hc_driver ehci_w90x900_hc_driver = { | 
|  | 110 | .description = hcd_name, | 
|  | 111 | .product_desc = "Nuvoton w90x900 EHCI Host Controller", | 
|  | 112 | .hcd_priv_size = sizeof(struct ehci_hcd), | 
|  | 113 |  | 
|  | 114 | /* | 
|  | 115 | * generic hardware linkage | 
|  | 116 | */ | 
|  | 117 | .irq = ehci_irq, | 
|  | 118 | .flags = HCD_USB2|HCD_MEMORY, | 
|  | 119 |  | 
|  | 120 | /* | 
|  | 121 | * basic lifecycle operations | 
|  | 122 | */ | 
|  | 123 | .reset = ehci_init, | 
|  | 124 | .start = ehci_run, | 
|  | 125 |  | 
|  | 126 | .stop = ehci_stop, | 
|  | 127 | .shutdown = ehci_shutdown, | 
|  | 128 |  | 
|  | 129 | /* | 
|  | 130 | * managing i/o requests and associated device resources | 
|  | 131 | */ | 
|  | 132 | .urb_enqueue = ehci_urb_enqueue, | 
|  | 133 | .urb_dequeue = ehci_urb_dequeue, | 
|  | 134 | .endpoint_disable = ehci_endpoint_disable, | 
| Paul Mundt | b48d7f5 | 2010-11-30 17:57:02 +0900 | [diff] [blame] | 135 | .endpoint_reset = ehci_endpoint_reset, | 
| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 136 |  | 
|  | 137 | /* | 
|  | 138 | * scheduling support | 
|  | 139 | */ | 
|  | 140 | .get_frame_number = ehci_get_frame, | 
|  | 141 |  | 
|  | 142 | /* | 
|  | 143 | * root hub support | 
|  | 144 | */ | 
|  | 145 | .hub_status_data = ehci_hub_status_data, | 
|  | 146 | .hub_control = ehci_hub_control, | 
|  | 147 | #ifdef	CONFIG_PM | 
|  | 148 | .bus_suspend = ehci_bus_suspend, | 
|  | 149 | .bus_resume = ehci_bus_resume, | 
|  | 150 | #endif | 
|  | 151 | .relinquish_port	= ehci_relinquish_port, | 
|  | 152 | .port_handed_over	= ehci_port_handed_over, | 
| Paul Mundt | b48d7f5 | 2010-11-30 17:57:02 +0900 | [diff] [blame] | 153 |  | 
|  | 154 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | 
| Wan ZongShun | 586dfc8 | 2009-06-13 09:14:28 +0800 | [diff] [blame] | 155 | }; | 
|  | 156 |  | 
|  | 157 | static int __devinit ehci_w90x900_probe(struct platform_device *pdev) | 
|  | 158 | { | 
|  | 159 | if (usb_disabled()) | 
|  | 160 | return -ENODEV; | 
|  | 161 |  | 
|  | 162 | return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev); | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | static int __devexit ehci_w90x900_remove(struct platform_device *pdev) | 
|  | 166 | { | 
|  | 167 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 
|  | 168 |  | 
|  | 169 | usb_w90x900_remove(hcd, pdev); | 
|  | 170 |  | 
|  | 171 | return 0; | 
|  | 172 | } | 
|  | 173 |  | 
|  | 174 | static struct platform_driver ehci_hcd_w90x900_driver = { | 
|  | 175 | .probe  = ehci_w90x900_probe, | 
|  | 176 | .remove = __devexit_p(ehci_w90x900_remove), | 
|  | 177 | .driver = { | 
|  | 178 | .name = "w90x900-ehci", | 
|  | 179 | .owner = THIS_MODULE, | 
|  | 180 | }, | 
|  | 181 | }; | 
|  | 182 |  | 
|  | 183 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | 
|  | 184 | MODULE_DESCRIPTION("w90p910 usb ehci driver!"); | 
|  | 185 | MODULE_LICENSE("GPL"); | 
|  | 186 | MODULE_ALIAS("platform:w90p910-ehci"); |