aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-au1xxx.c
diff options
context:
space:
mode:
authorManuel Lauss <mano@roarinelk.homelinux.net>2008-06-23 03:08:29 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-07-21 18:16:44 -0400
commit53c81a348fa1d21dd042d9c9a9f91795f83fed66 (patch)
treec4be28f2bf245dabf9031a3ef56e7d56f27630bb /drivers/usb/host/ehci-au1xxx.c
parente04199b2167e88f0e2d0410fafaa2c35ff7ba8c1 (diff)
USB: Au1xxx-usb: clean up ohci/ehci bus glue sources.
- Fold multiple probe/remove callbacks into one function; - minor style fixes, no functional changes. Tested on Au1200. Signed-off-by: Manuel Lauss <mano@roarinelk.homelinux.net> Cc: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/ehci-au1xxx.c')
-rw-r--r--drivers/usb/host/ehci-au1xxx.c276
1 files changed, 111 insertions, 165 deletions
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 08a4335401a9..12ed80684ad1 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -19,236 +19,179 @@
19#define USB_MCFG_RDCOMB (1<<30) 19#define USB_MCFG_RDCOMB (1<<30)
20#define USB_MCFG_SSDEN (1<<23) 20#define USB_MCFG_SSDEN (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19) 21#define USB_MCFG_PHYPLLEN (1<<19)
22#define USB_MCFG_UCECLKEN (1<<18)
22#define USB_MCFG_EHCCLKEN (1<<17) 23#define USB_MCFG_EHCCLKEN (1<<17)
24#ifdef CONFIG_DMA_COHERENT
23#define USB_MCFG_UCAM (1<<7) 25#define USB_MCFG_UCAM (1<<7)
26#else
27#define USB_MCFG_UCAM (0)
28#endif
24#define USB_MCFG_EBMEN (1<<3) 29#define USB_MCFG_EBMEN (1<<3)
25#define USB_MCFG_EMEMEN (1<<2) 30#define USB_MCFG_EMEMEN (1<<2)
26 31
27#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN) 32#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
33#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
34 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
35 USB_MCFG_UCAM | USB_MCFG_EBMEN | \
36 USB_MCFG_EMEMEN)
28 37
29#ifdef CONFIG_DMA_COHERENT
30#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
31 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
32 | USB_MCFG_SSDEN | USB_MCFG_UCAM \
33 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
34#else
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE \
36 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
37 | USB_MCFG_SSDEN \
38 | USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39#endif
40#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) 38#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
41 39
42extern int usb_disabled(void); 40extern int usb_disabled(void);
43 41
44/*-------------------------------------------------------------------------*/ 42static void au1xxx_start_ehc(void)
45
46static void au1xxx_start_ehc(struct platform_device *dev)
47{ 43{
48 pr_debug(__FILE__ ": starting Au1xxx EHCI USB Controller\n"); 44 /* enable clock to EHCI block and HS PHY PLL*/
49 45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
50 /* write HW defaults again in case Yamon cleared them */ 46 au_sync();
51 if (au_readl(USB_HOST_CONFIG) == 0) {
52 au_writel(0x00d02000, USB_HOST_CONFIG);
53 au_readl(USB_HOST_CONFIG);
54 udelay(1000);
55 }
56 /* enable host controller */
57 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
58 au_readl(USB_HOST_CONFIG);
59 udelay(1000);
60 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG),
61 USB_HOST_CONFIG);
62 au_readl(USB_HOST_CONFIG);
63 udelay(1000); 47 udelay(1000);
64 48
65 pr_debug(__FILE__ ": Clock to USB host has been enabled\n"); 49 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
66} 53}
67 54
68static void au1xxx_stop_ehc(struct platform_device *dev) 55static void au1xxx_stop_ehc(void)
69{ 56{
70 pr_debug(__FILE__ ": stopping Au1xxx EHCI USB Controller\n"); 57 unsigned long c;
71 58
72 /* Disable mem */ 59 /* Disable mem */
73 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); 60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
74 udelay(1000); 62 udelay(1000);
75 /* Disable clock */ 63
76 au_writel(~USB_MCFG_EHCCLKEN & au_readl(USB_HOST_CONFIG), 64 /* Disable EHC clock. If the HS PHY is unused disable it too. */
77 USB_HOST_CONFIG); 65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
78 au_readl(USB_HOST_CONFIG); 66 if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
67 c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
79} 70}
80 71
81/*-------------------------------------------------------------------------*/ 72static const struct hc_driver ehci_au1xxx_hc_driver = {
73 .description = hcd_name,
74 .product_desc = "Au1xxx EHCI",
75 .hcd_priv_size = sizeof(struct ehci_hcd),
82 76
83/* configure so an HC device and id are always provided */ 77 /*
84/* always called with process context; sleeping is OK */ 78 * generic hardware linkage
79 */
80 .irq = ehci_irq,
81 .flags = HCD_MEMORY | HCD_USB2,
85 82
86/** 83 /*
87 * usb_ehci_au1xxx_probe - initialize Au1xxx-based HCDs 84 * basic lifecycle operations
88 * Context: !in_interrupt() 85 *
89 * 86 * FIXME -- ehci_init() doesn't do enough here.
90 * Allocates basic resources for this USB host controller, and 87 * See ehci-ppc-soc for a complete implementation.
91 * then invokes the start() method for the HCD associated with it 88 */
92 * through the hotplug entry's driver_data. 89 .reset = ehci_init,
93 * 90 .start = ehci_run,
94 */ 91 .stop = ehci_stop,
95int usb_ehci_au1xxx_probe(const struct hc_driver *driver, 92 .shutdown = ehci_shutdown,
96 struct usb_hcd **hcd_out, struct platform_device *dev) 93
94 /*
95 * managing i/o requests and associated device resources
96 */
97 .urb_enqueue = ehci_urb_enqueue,
98 .urb_dequeue = ehci_urb_dequeue,
99 .endpoint_disable = ehci_endpoint_disable,
100
101 /*
102 * scheduling support
103 */
104 .get_frame_number = ehci_get_frame,
105
106 /*
107 * root hub support
108 */
109 .hub_status_data = ehci_hub_status_data,
110 .hub_control = ehci_hub_control,
111 .bus_suspend = ehci_bus_suspend,
112 .bus_resume = ehci_bus_resume,
113 .relinquish_port = ehci_relinquish_port,
114 .port_handed_over = ehci_port_handed_over,
115};
116
117static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
97{ 118{
98 int retval;
99 struct usb_hcd *hcd; 119 struct usb_hcd *hcd;
100 struct ehci_hcd *ehci; 120 struct ehci_hcd *ehci;
121 int ret;
101 122
102#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) 123 if (usb_disabled())
124 return -ENODEV;
103 125
126#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
104 /* Au1200 AB USB does not support coherent memory */ 127 /* Au1200 AB USB does not support coherent memory */
105 if (!(read_c0_prid() & 0xff)) { 128 if (!(read_c0_prid() & 0xff)) {
106 pr_info("%s: this is chip revision AB!\n", dev->name); 129 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
107 pr_info("%s: update your board or re-configure the kernel\n", 130 printk(KERN_INFO "%s: update your board or re-configure"
108 dev->name); 131 " the kernel\n", pdev->name);
109 return -ENODEV; 132 return -ENODEV;
110 } 133 }
111#endif 134#endif
112 135
113 au1xxx_start_ehc(dev); 136 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
114
115 if (dev->resource[1].flags != IORESOURCE_IRQ) {
116 pr_debug("resource[1] is not IORESOURCE_IRQ"); 137 pr_debug("resource[1] is not IORESOURCE_IRQ");
117 retval = -ENOMEM; 138 return -ENOMEM;
118 } 139 }
119 hcd = usb_create_hcd(driver, &dev->dev, "Au1xxx"); 140 hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
120 if (!hcd) 141 if (!hcd)
121 return -ENOMEM; 142 return -ENOMEM;
122 hcd->rsrc_start = dev->resource[0].start; 143
123 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; 144 hcd->rsrc_start = pdev->resource[0].start;
145 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
124 146
125 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 147 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
126 pr_debug("request_mem_region failed"); 148 pr_debug("request_mem_region failed");
127 retval = -EBUSY; 149 ret = -EBUSY;
128 goto err1; 150 goto err1;
129 } 151 }
130 152
131 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 153 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
132 if (!hcd->regs) { 154 if (!hcd->regs) {
133 pr_debug("ioremap failed"); 155 pr_debug("ioremap failed");
134 retval = -ENOMEM; 156 ret = -ENOMEM;
135 goto err2; 157 goto err2;
136 } 158 }
137 159
160 au1xxx_start_ehc();
161
138 ehci = hcd_to_ehci(hcd); 162 ehci = hcd_to_ehci(hcd);
139 ehci->caps = hcd->regs; 163 ehci->caps = hcd->regs;
140 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); 164 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
141 /* cache this readonly data; minimize chip reads */ 165 /* cache this readonly data; minimize chip reads */
142 ehci->hcs_params = readl(&ehci->caps->hcs_params); 166 ehci->hcs_params = readl(&ehci->caps->hcs_params);
143 167
144 /* ehci_hcd_init(hcd_to_ehci(hcd)); */ 168 ret = usb_add_hcd(hcd, pdev->resource[1].start,
145 169 IRQF_DISABLED | IRQF_SHARED);
146 retval = 170 if (ret == 0) {
147 usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED); 171 platform_set_drvdata(pdev, hcd);
148 if (retval == 0) 172 return ret;
149 return retval; 173 }
150 174
151 au1xxx_stop_ehc(dev); 175 au1xxx_stop_ehc();
152 iounmap(hcd->regs); 176 iounmap(hcd->regs);
153err2: 177err2:
154 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 178 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
155err1: 179err1:
156 usb_put_hcd(hcd); 180 usb_put_hcd(hcd);
157 return retval; 181 return ret;
158} 182}
159 183
160/* may be called without controller electrically present */ 184static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
161/* may be called with controller, bus, and devices active */
162
163/**
164 * usb_ehci_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
165 * @dev: USB Host Controller being removed
166 * Context: !in_interrupt()
167 *
168 * Reverses the effect of usb_ehci_hcd_au1xxx_probe(), first invoking
169 * the HCD's stop() method. It is always called from a thread
170 * context, normally "rmmod", "apmd", or something similar.
171 *
172 */
173void usb_ehci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
174{ 185{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187
175 usb_remove_hcd(hcd); 188 usb_remove_hcd(hcd);
176 iounmap(hcd->regs); 189 iounmap(hcd->regs);
177 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 190 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
178 usb_put_hcd(hcd); 191 usb_put_hcd(hcd);
179 au1xxx_stop_ehc(dev); 192 au1xxx_stop_ehc();
180} 193 platform_set_drvdata(pdev, NULL);
181
182/*-------------------------------------------------------------------------*/
183 194
184static const struct hc_driver ehci_au1xxx_hc_driver = {
185 .description = hcd_name,
186 .product_desc = "Au1xxx EHCI",
187 .hcd_priv_size = sizeof(struct ehci_hcd),
188
189 /*
190 * generic hardware linkage
191 */
192 .irq = ehci_irq,
193 .flags = HCD_MEMORY | HCD_USB2,
194
195 /*
196 * basic lifecycle operations
197 *
198 * FIXME -- ehci_init() doesn't do enough here.
199 * See ehci-ppc-soc for a complete implementation.
200 */
201 .reset = ehci_init,
202 .start = ehci_run,
203 .stop = ehci_stop,
204 .shutdown = ehci_shutdown,
205
206 /*
207 * managing i/o requests and associated device resources
208 */
209 .urb_enqueue = ehci_urb_enqueue,
210 .urb_dequeue = ehci_urb_dequeue,
211 .endpoint_disable = ehci_endpoint_disable,
212
213 /*
214 * scheduling support
215 */
216 .get_frame_number = ehci_get_frame,
217
218 /*
219 * root hub support
220 */
221 .hub_status_data = ehci_hub_status_data,
222 .hub_control = ehci_hub_control,
223 .bus_suspend = ehci_bus_suspend,
224 .bus_resume = ehci_bus_resume,
225 .relinquish_port = ehci_relinquish_port,
226 .port_handed_over = ehci_port_handed_over,
227};
228
229/*-------------------------------------------------------------------------*/
230
231static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
232{
233 struct usb_hcd *hcd = NULL;
234 int ret;
235
236 pr_debug("In ehci_hcd_au1xxx_drv_probe\n");
237
238 if (usb_disabled())
239 return -ENODEV;
240
241 /* FIXME we only want one one probe() not two */
242 ret = usb_ehci_au1xxx_probe(&ehci_au1xxx_hc_driver, &hcd, pdev);
243 return ret;
244}
245
246static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
247{
248 struct usb_hcd *hcd = platform_get_drvdata(pdev);
249
250 /* FIXME we only want one one remove() not two */
251 usb_ehci_au1xxx_remove(hcd, pdev);
252 return 0; 195 return 0;
253} 196}
254 197
@@ -268,14 +211,17 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
268 return 0; 211 return 0;
269} 212}
270*/ 213*/
271MODULE_ALIAS("platform:au1xxx-ehci"); 214
272static struct platform_driver ehci_hcd_au1xxx_driver = { 215static struct platform_driver ehci_hcd_au1xxx_driver = {
273 .probe = ehci_hcd_au1xxx_drv_probe, 216 .probe = ehci_hcd_au1xxx_drv_probe,
274 .remove = ehci_hcd_au1xxx_drv_remove, 217 .remove = ehci_hcd_au1xxx_drv_remove,
275 .shutdown = usb_hcd_platform_shutdown, 218 .shutdown = usb_hcd_platform_shutdown,
276 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */ 219 /*.suspend = ehci_hcd_au1xxx_drv_suspend, */
277 /*.resume = ehci_hcd_au1xxx_drv_resume, */ 220 /*.resume = ehci_hcd_au1xxx_drv_resume, */
278 .driver = { 221 .driver = {
279 .name = "au1xxx-ehci", 222 .name = "au1xxx-ehci",
223 .owner = THIS_MODULE,
280 } 224 }
281}; 225};
226
227MODULE_ALIAS("platform:au1xxx-ehci");