• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/usb/host/
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 *
8 * SA1111 Bus Glue
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * This file is licenced under the GPL.
14 */
15
16#include <mach/hardware.h>
17#include <asm/mach-types.h>
18#include <mach/assabet.h>
19#include <mach/badge4.h>
20#include <asm/hardware/sa1111.h>
21
22#ifndef CONFIG_SA1111
23#error "This file is SA-1111 bus glue.  CONFIG_SA1111 must be defined."
24#endif
25
26extern int usb_disabled(void);
27
28/*-------------------------------------------------------------------------*/
29
30static void sa1111_start_hc(struct sa1111_dev *dev)
31{
32	unsigned int usb_rst = 0;
33
34	printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
35	       __FILE__);
36
37#ifdef CONFIG_SA1100_BADGE4
38	if (machine_is_badge4()) {
39		badge4_set_5V(BADGE4_5V_USB, 1);
40	}
41#endif
42
43	if (machine_is_xp860() ||
44	    machine_has_neponset() ||
45	    machine_is_pfs168() ||
46	    machine_is_badge4())
47		usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
48
49	/*
50	 * Configure the power sense and control lines.  Place the USB
51	 * host controller in reset.
52	 */
53	sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
54		      dev->mapbase + SA1111_USB_RESET);
55
56	/*
57	 * Now, carefully enable the USB clock, and take
58	 * the USB host controller out of reset.
59	 */
60	sa1111_enable_device(dev);
61	udelay(11);
62	sa1111_writel(usb_rst, dev->mapbase + SA1111_USB_RESET);
63}
64
65static void sa1111_stop_hc(struct sa1111_dev *dev)
66{
67	unsigned int usb_rst;
68	printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
69	       __FILE__);
70
71	/*
72	 * Put the USB host controller into reset.
73	 */
74	usb_rst = sa1111_readl(dev->mapbase + SA1111_USB_RESET);
75	sa1111_writel(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
76		      dev->mapbase + SA1111_USB_RESET);
77
78	/*
79	 * Stop the USB clock.
80	 */
81	sa1111_disable_device(dev);
82
83#ifdef CONFIG_SA1100_BADGE4
84	if (machine_is_badge4()) {
85		/* Disable power to the USB bus */
86		badge4_set_5V(BADGE4_5V_USB, 0);
87	}
88#endif
89}
90
91
92/*-------------------------------------------------------------------------*/
93
94
95/*-------------------------------------------------------------------------*/
96
97/* configure so an HC device and id are always provided */
98/* always called with process context; sleeping is OK */
99
100
101/**
102 * usb_hcd_sa1111_probe - initialize SA-1111-based HCDs
103 * Context: !in_interrupt()
104 *
105 * Allocates basic resources for this USB host controller, and
106 * then invokes the start() method for the HCD associated with it
107 * through the hotplug entry's driver_data.
108 *
109 * Store this function in the HCD's struct pci_driver as probe().
110 */
111int usb_hcd_sa1111_probe (const struct hc_driver *driver,
112			  struct sa1111_dev *dev)
113{
114	struct usb_hcd *hcd;
115	int retval;
116
117	hcd = usb_create_hcd (driver, &dev->dev, "sa1111");
118	if (!hcd)
119		return -ENOMEM;
120	hcd->rsrc_start = dev->res.start;
121	hcd->rsrc_len = dev->res.end - dev->res.start + 1;
122
123	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
124		dbg("request_mem_region failed");
125		retval = -EBUSY;
126		goto err1;
127	}
128	hcd->regs = dev->mapbase;
129
130	sa1111_start_hc(dev);
131	ohci_hcd_init(hcd_to_ohci(hcd));
132
133	retval = usb_add_hcd(hcd, dev->irq[1], IRQF_DISABLED);
134	if (retval == 0)
135		return retval;
136
137	sa1111_stop_hc(dev);
138	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
139 err1:
140	usb_put_hcd(hcd);
141	return retval;
142}
143
144
145/* may be called without controller electrically present */
146/* may be called with controller, bus, and devices active */
147
148/**
149 * usb_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
150 * @dev: USB Host Controller being removed
151 * Context: !in_interrupt()
152 *
153 * Reverses the effect of usb_hcd_sa1111_probe(), first invoking
154 * the HCD's stop() method.  It is always called from a thread
155 * context, normally "rmmod", "apmd", or something similar.
156 *
157 */
158void usb_hcd_sa1111_remove (struct usb_hcd *hcd, struct sa1111_dev *dev)
159{
160	usb_remove_hcd(hcd);
161	sa1111_stop_hc(dev);
162	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
163	usb_put_hcd(hcd);
164}
165
166/*-------------------------------------------------------------------------*/
167
168static int __devinit
169ohci_sa1111_start (struct usb_hcd *hcd)
170{
171	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
172	int		ret;
173
174	if ((ret = ohci_init(ohci)) < 0)
175		return ret;
176
177	if ((ret = ohci_run (ohci)) < 0) {
178		err ("can't start %s", hcd->self.bus_name);
179		ohci_stop (hcd);
180		return ret;
181	}
182	return 0;
183}
184
185/*-------------------------------------------------------------------------*/
186
187static const struct hc_driver ohci_sa1111_hc_driver = {
188	.description =		hcd_name,
189	.product_desc =		"SA-1111 OHCI",
190	.hcd_priv_size =	sizeof(struct ohci_hcd),
191
192	/*
193	 * generic hardware linkage
194	 */
195	.irq =			ohci_irq,
196	.flags =		HCD_USB11 | HCD_MEMORY,
197
198	/*
199	 * basic lifecycle operations
200	 */
201	.start =		ohci_sa1111_start,
202	.stop =			ohci_stop,
203
204	/*
205	 * managing i/o requests and associated device resources
206	 */
207	.urb_enqueue =		ohci_urb_enqueue,
208	.urb_dequeue =		ohci_urb_dequeue,
209	.endpoint_disable =	ohci_endpoint_disable,
210
211	/*
212	 * scheduling support
213	 */
214	.get_frame_number =	ohci_get_frame,
215
216	/*
217	 * root hub support
218	 */
219	.hub_status_data =	ohci_hub_status_data,
220	.hub_control =		ohci_hub_control,
221#ifdef	CONFIG_PM
222	.bus_suspend =		ohci_bus_suspend,
223	.bus_resume =		ohci_bus_resume,
224#endif
225	.start_port_reset =	ohci_start_port_reset,
226};
227
228/*-------------------------------------------------------------------------*/
229
230static int ohci_hcd_sa1111_drv_probe(struct sa1111_dev *dev)
231{
232	int ret;
233
234	if (usb_disabled())
235		return -ENODEV;
236
237	ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, dev);
238	return ret;
239}
240
241static int ohci_hcd_sa1111_drv_remove(struct sa1111_dev *dev)
242{
243	struct usb_hcd *hcd = sa1111_get_drvdata(dev);
244
245	usb_hcd_sa1111_remove(hcd, dev);
246	return 0;
247}
248
249static struct sa1111_driver ohci_hcd_sa1111_driver = {
250	.drv = {
251		.name	= "sa1111-ohci",
252	},
253	.devid		= SA1111_DEVID_USB,
254	.probe		= ohci_hcd_sa1111_drv_probe,
255	.remove		= ohci_hcd_sa1111_drv_remove,
256};
257