aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ohci-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/ohci-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/ohci-au1xxx.c')
-rw-r--r--drivers/usb/host/ohci-au1xxx.c268
1 files changed, 99 insertions, 169 deletions
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 68c17f5ea8ea..29c970ad487a 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -34,7 +34,8 @@
34#ifdef __LITTLE_ENDIAN 34#ifdef __LITTLE_ENDIAN
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C) 35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
36#elif __BIG_ENDIAN 36#elif __BIG_ENDIAN
37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | USBH_ENABLE_BE) 37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
38 USBH_ENABLE_BE)
38#else 39#else
39#error not byte order defined 40#error not byte order defined
40#endif 41#endif
@@ -46,213 +47,87 @@
46#define USB_MCFG_RDCOMB (1<<30) 47#define USB_MCFG_RDCOMB (1<<30)
47#define USB_MCFG_SSDEN (1<<23) 48#define USB_MCFG_SSDEN (1<<23)
48#define USB_MCFG_OHCCLKEN (1<<16) 49#define USB_MCFG_OHCCLKEN (1<<16)
50#ifdef CONFIG_DMA_COHERENT
49#define USB_MCFG_UCAM (1<<7) 51#define USB_MCFG_UCAM (1<<7)
52#else
53#define USB_MCFG_UCAM (0)
54#endif
50#define USB_MCFG_OBMEN (1<<1) 55#define USB_MCFG_OBMEN (1<<1)
51#define USB_MCFG_OMEMEN (1<<0) 56#define USB_MCFG_OMEMEN (1<<0)
52 57
53#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN 58#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
54#ifdef CONFIG_DMA_COHERENT 59
55#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \ 60#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
56 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \ 61 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
57 | USB_MCFG_SSDEN | USB_MCFG_UCAM \ 62 USB_MCFG_UCAM | \
58 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN) 63 USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
59#else 64
60#define USBH_ENABLE_INIT (USB_MCFG_OHCCLKEN \
61 | USB_MCFG_PFEN | USB_MCFG_RDCOMB \
62 | USB_MCFG_SSDEN \
63 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64#endif
65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN) 65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
66 66
67#endif /* Au1200 */ 67#endif /* Au1200 */
68 68
69extern int usb_disabled(void); 69extern int usb_disabled(void);
70 70
71/*-------------------------------------------------------------------------*/ 71static void au1xxx_start_ohc(void)
72
73static void au1xxx_start_ohc(struct platform_device *dev)
74{ 72{
75 printk(KERN_DEBUG __FILE__
76 ": starting Au1xxx OHCI USB Controller\n");
77
78 /* enable host controller */ 73 /* enable host controller */
79
80#ifndef CONFIG_SOC_AU1200 74#ifndef CONFIG_SOC_AU1200
81
82 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG); 75 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
83 udelay(1000); 76 au_sync();
84 au_writel(USBH_ENABLE_INIT, USB_HOST_CONFIG);
85 udelay(1000); 77 udelay(1000);
86 78
87#else /* Au1200 */ 79 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
88 80 au_sync();
89 /* write HW defaults again in case Yamon cleared them */
90 if (au_readl(USB_HOST_CONFIG) == 0) {
91 au_writel(0x00d02000, USB_HOST_CONFIG);
92 au_readl(USB_HOST_CONFIG);
93 udelay(1000);
94 }
95 au_writel(USBH_ENABLE_CE | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
96 au_readl(USB_HOST_CONFIG);
97 udelay(1000); 81 udelay(1000);
98 au_writel(USBH_ENABLE_INIT | au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
99 au_readl(USB_HOST_CONFIG);
100 udelay(1000);
101
102#endif /* Au1200 */
103 82
104#ifndef CONFIG_SOC_AU1200
105 /* wait for reset complete (read register twice; see au1500 errata) */ 83 /* wait for reset complete (read register twice; see au1500 errata) */
106 while (au_readl(USB_HOST_CONFIG), 84 while (au_readl(USB_HOST_CONFIG),
107 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD)) 85 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
108#endif
109 udelay(1000); 86 udelay(1000);
110 87
111 printk(KERN_DEBUG __FILE__
112 ": Clock to USB host has been enabled \n");
113}
114
115static void au1xxx_stop_ohc(struct platform_device *dev)
116{
117 printk(KERN_DEBUG __FILE__
118 ": stopping Au1xxx OHCI USB Controller\n");
119
120#ifndef CONFIG_SOC_AU1200
121
122 /* Disable clock */
123 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
124
125#else /* Au1200 */ 88#else /* Au1200 */
126 89 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
127 /* Disable mem */ 90 au_sync();
128 au_writel(~USBH_DISABLE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG);
129 udelay(1000); 91 udelay(1000);
130 /* Disable clock */ 92
131 au_writel(~USBH_ENABLE_CE & au_readl(USB_HOST_CONFIG), USB_HOST_CONFIG); 93 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
132 au_readl(USB_HOST_CONFIG); 94 au_sync();
95 udelay(2000);
133#endif /* Au1200 */ 96#endif /* Au1200 */
134} 97}
135 98
136 99static void au1xxx_stop_ohc(void)
137/*-------------------------------------------------------------------------*/
138
139/* configure so an HC device and id are always provided */
140/* always called with process context; sleeping is OK */
141
142
143/**
144 * usb_ohci_au1xxx_probe - initialize Au1xxx-based HCDs
145 * Context: !in_interrupt()
146 *
147 * Allocates basic resources for this USB host controller, and
148 * then invokes the start() method for the HCD associated with it
149 * through the hotplug entry's driver_data.
150 *
151 */
152static int usb_ohci_au1xxx_probe(const struct hc_driver *driver,
153 struct platform_device *dev)
154{ 100{
155 int retval; 101#ifdef CONFIG_SOC_AU1200
156 struct usb_hcd *hcd; 102 /* Disable mem */
157 103 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
158#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) 104 au_sync();
159 /* Au1200 AB USB does not support coherent memory */ 105 udelay(1000);
160 if (!(read_c0_prid() & 0xff)) {
161 pr_info("%s: this is chip revision AB !!\n",
162 dev->name);
163 pr_info("%s: update your board or re-configure the kernel\n",
164 dev->name);
165 return -ENODEV;
166 }
167#endif 106#endif
168 107 /* Disable clock */
169 if (dev->resource[1].flags != IORESOURCE_IRQ) { 108 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
170 pr_debug("resource[1] is not IORESOURCE_IRQ\n"); 109 au_sync();
171 return -ENOMEM;
172 }
173
174 hcd = usb_create_hcd(driver, &dev->dev, "au1xxx");
175 if (!hcd)
176 return -ENOMEM;
177 hcd->rsrc_start = dev->resource[0].start;
178 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
179
180 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
181 pr_debug("request_mem_region failed\n");
182 retval = -EBUSY;
183 goto err1;
184 }
185
186 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
187 if (!hcd->regs) {
188 pr_debug("ioremap failed\n");
189 retval = -ENOMEM;
190 goto err2;
191 }
192
193 au1xxx_start_ohc(dev);
194 ohci_hcd_init(hcd_to_ohci(hcd));
195
196 retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED | IRQF_SHARED);
197 if (retval == 0)
198 return retval;
199
200 au1xxx_stop_ohc(dev);
201 iounmap(hcd->regs);
202 err2:
203 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
204 err1:
205 usb_put_hcd(hcd);
206 return retval;
207}
208
209
210/* may be called without controller electrically present */
211/* may be called with controller, bus, and devices active */
212
213/**
214 * usb_hcd_au1xxx_remove - shutdown processing for Au1xxx-based HCDs
215 * @dev: USB Host Controller being removed
216 * Context: !in_interrupt()
217 *
218 * Reverses the effect of usb_hcd_au1xxx_probe(), first invoking
219 * the HCD's stop() method. It is always called from a thread
220 * context, normally "rmmod", "apmd", or something similar.
221 *
222 */
223static void usb_ohci_au1xxx_remove(struct usb_hcd *hcd, struct platform_device *dev)
224{
225 usb_remove_hcd(hcd);
226 au1xxx_stop_ohc(dev);
227 iounmap(hcd->regs);
228 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
229 usb_put_hcd(hcd);
230} 110}
231 111
232/*-------------------------------------------------------------------------*/ 112static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
233
234static int __devinit
235ohci_au1xxx_start (struct usb_hcd *hcd)
236{ 113{
237 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 114 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
238 int ret; 115 int ret;
239 116
240 ohci_dbg (ohci, "ohci_au1xxx_start, ohci:%p", ohci); 117 ohci_dbg(ohci, "ohci_au1xxx_start, ohci:%p", ohci);
241 118
242 if ((ret = ohci_init (ohci)) < 0) 119 if ((ret = ohci_init(ohci)) < 0)
243 return ret; 120 return ret;
244 121
245 if ((ret = ohci_run (ohci)) < 0) { 122 if ((ret = ohci_run(ohci)) < 0) {
246 err ("can't start %s", hcd->self.bus_name); 123 err ("can't start %s", hcd->self.bus_name);
247 ohci_stop (hcd); 124 ohci_stop(hcd);
248 return ret; 125 return ret;
249 } 126 }
250 127
251 return 0; 128 return 0;
252} 129}
253 130
254/*-------------------------------------------------------------------------*/
255
256static const struct hc_driver ohci_au1xxx_hc_driver = { 131static const struct hc_driver ohci_au1xxx_hc_driver = {
257 .description = hcd_name, 132 .description = hcd_name,
258 .product_desc = "Au1xxx OHCI", 133 .product_desc = "Au1xxx OHCI",
@@ -296,18 +171,66 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
296 .start_port_reset = ohci_start_port_reset, 171 .start_port_reset = ohci_start_port_reset,
297}; 172};
298 173
299/*-------------------------------------------------------------------------*/
300
301static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) 174static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
302{ 175{
303 int ret; 176 int ret;
304 177 struct usb_hcd *hcd;
305 pr_debug ("In ohci_hcd_au1xxx_drv_probe");
306 178
307 if (usb_disabled()) 179 if (usb_disabled())
308 return -ENODEV; 180 return -ENODEV;
309 181
310 ret = usb_ohci_au1xxx_probe(&ohci_au1xxx_hc_driver, pdev); 182#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
183 /* Au1200 AB USB does not support coherent memory */
184 if (!(read_c0_prid() & 0xff)) {
185 printk(KERN_INFO "%s: this is chip revision AB !!\n",
186 pdev->name);
187 printk(KERN_INFO "%s: update your board or re-configure "
188 "the kernel\n", pdev->name);
189 return -ENODEV;
190 }
191#endif
192
193 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
194 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
195 return -ENOMEM;
196 }
197
198 hcd = usb_create_hcd(&ohci_au1xxx_hc_driver, &pdev->dev, "au1xxx");
199 if (!hcd)
200 return -ENOMEM;
201
202 hcd->rsrc_start = pdev->resource[0].start;
203 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1;
204
205 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
206 pr_debug("request_mem_region failed\n");
207 ret = -EBUSY;
208 goto err1;
209 }
210
211 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
212 if (!hcd->regs) {
213 pr_debug("ioremap failed\n");
214 ret = -ENOMEM;
215 goto err2;
216 }
217
218 au1xxx_start_ohc();
219 ohci_hcd_init(hcd_to_ohci(hcd));
220
221 ret = usb_add_hcd(hcd, pdev->resource[1].start,
222 IRQF_DISABLED | IRQF_SHARED);
223 if (ret == 0) {
224 platform_set_drvdata(pdev, hcd);
225 return ret;
226 }
227
228 au1xxx_stop_ohc();
229 iounmap(hcd->regs);
230err2:
231 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
232err1:
233 usb_put_hcd(hcd);
311 return ret; 234 return ret;
312} 235}
313 236
@@ -315,9 +238,16 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
315{ 238{
316 struct usb_hcd *hcd = platform_get_drvdata(pdev); 239 struct usb_hcd *hcd = platform_get_drvdata(pdev);
317 240
318 usb_ohci_au1xxx_remove(hcd, pdev); 241 usb_remove_hcd(hcd);
242 au1xxx_stop_ohc();
243 iounmap(hcd->regs);
244 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
245 usb_put_hcd(hcd);
246 platform_set_drvdata(pdev, NULL);
247
319 return 0; 248 return 0;
320} 249}
250
321 /*TBD*/ 251 /*TBD*/
322/*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev) 252/*static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *dev)
323{ 253{