• 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 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for AMD Alchemy Au1xxx
5 *
6 * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
7 *
8 * Modified for AMD Alchemy Au1200 EHC
9 *  by K.Boge <karsten.boge@amd.com>
10 *
11 * This file is licenced under the GPL.
12 */
13
14#include <linux/platform_device.h>
15#include <asm/mach-au1x00/au1000.h>
16
17#define USB_HOST_CONFIG   (USB_MSR_BASE + USB_MSR_MCFG)
18#define USB_MCFG_PFEN     (1<<31)
19#define USB_MCFG_RDCOMB   (1<<30)
20#define USB_MCFG_SSDEN    (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19)
22#define USB_MCFG_UCECLKEN (1<<18)
23#define USB_MCFG_EHCCLKEN (1<<17)
24#ifdef CONFIG_DMA_COHERENT
25#define USB_MCFG_UCAM     (1<<7)
26#else
27#define USB_MCFG_UCAM     (0)
28#endif
29#define USB_MCFG_EBMEN    (1<<3)
30#define USB_MCFG_EMEMEN   (1<<2)
31
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)
37
38#define USBH_DISABLE      (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39
40extern int usb_disabled(void);
41
42static void au1xxx_start_ehc(void)
43{
44	/* enable clock to EHCI block and HS PHY PLL*/
45	au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
46	au_sync();
47	udelay(1000);
48
49	/* enable EHCI mmio */
50	au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51	au_sync();
52	udelay(1000);
53}
54
55static void au1xxx_stop_ehc(void)
56{
57	unsigned long c;
58
59	/* Disable mem */
60	au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61	au_sync();
62	udelay(1000);
63
64	/* Disable EHC clock. If the HS PHY is unused disable it too. */
65	c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
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();
70}
71
72static int au1xxx_ehci_setup(struct usb_hcd *hcd)
73{
74	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
75	int ret = ehci_init(hcd);
76
77	ehci->need_io_watchdog = 0;
78	return ret;
79}
80
81static const struct hc_driver ehci_au1xxx_hc_driver = {
82	.description		= hcd_name,
83	.product_desc		= "Au1xxx EHCI",
84	.hcd_priv_size		= sizeof(struct ehci_hcd),
85
86	/*
87	 * generic hardware linkage
88	 */
89	.irq			= ehci_irq,
90	.flags			= HCD_MEMORY | HCD_USB2,
91
92	.reset			= au1xxx_ehci_setup,
93	.start			= ehci_run,
94	.stop			= ehci_stop,
95	.shutdown		= ehci_shutdown,
96
97	/*
98	 * managing i/o requests and associated device resources
99	 */
100	.urb_enqueue		= ehci_urb_enqueue,
101	.urb_dequeue		= ehci_urb_dequeue,
102	.endpoint_disable	= ehci_endpoint_disable,
103	.endpoint_reset		= ehci_endpoint_reset,
104
105	/*
106	 * scheduling support
107	 */
108	.get_frame_number	= ehci_get_frame,
109
110	/*
111	 * root hub support
112	 */
113	.hub_status_data	= ehci_hub_status_data,
114	.hub_control		= ehci_hub_control,
115	.bus_suspend		= ehci_bus_suspend,
116	.bus_resume		= ehci_bus_resume,
117	.relinquish_port	= ehci_relinquish_port,
118	.port_handed_over	= ehci_port_handed_over,
119
120	.clear_tt_buffer_complete	= ehci_clear_tt_buffer_complete,
121};
122
123static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
124{
125	struct usb_hcd *hcd;
126	struct ehci_hcd *ehci;
127	struct resource *res;
128	int ret;
129
130	if (usb_disabled())
131		return -ENODEV;
132
133#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
134	/* Au1200 AB USB does not support coherent memory */
135	if (!(read_c0_prid() & 0xff)) {
136		printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
137		printk(KERN_INFO "%s: update your board or re-configure"
138				 " the kernel\n", pdev->name);
139		return -ENODEV;
140	}
141#endif
142
143	if (pdev->resource[1].flags != IORESOURCE_IRQ) {
144		pr_debug("resource[1] is not IORESOURCE_IRQ");
145		return -ENOMEM;
146	}
147	hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
148	if (!hcd)
149		return -ENOMEM;
150
151	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
152	hcd->rsrc_start = res->start;
153	hcd->rsrc_len = resource_size(res);
154
155	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
156		pr_debug("request_mem_region failed");
157		ret = -EBUSY;
158		goto err1;
159	}
160
161	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
162	if (!hcd->regs) {
163		pr_debug("ioremap failed");
164		ret = -ENOMEM;
165		goto err2;
166	}
167
168	au1xxx_start_ehc();
169
170	ehci = hcd_to_ehci(hcd);
171	ehci->caps = hcd->regs;
172	ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
173	/* cache this readonly data; minimize chip reads */
174	ehci->hcs_params = readl(&ehci->caps->hcs_params);
175
176	ret = usb_add_hcd(hcd, pdev->resource[1].start,
177			  IRQF_DISABLED | IRQF_SHARED);
178	if (ret == 0) {
179		platform_set_drvdata(pdev, hcd);
180		return ret;
181	}
182
183	au1xxx_stop_ehc();
184	iounmap(hcd->regs);
185err2:
186	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
187err1:
188	usb_put_hcd(hcd);
189	return ret;
190}
191
192static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
193{
194	struct usb_hcd *hcd = platform_get_drvdata(pdev);
195
196	usb_remove_hcd(hcd);
197	iounmap(hcd->regs);
198	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
199	usb_put_hcd(hcd);
200	au1xxx_stop_ehc();
201	platform_set_drvdata(pdev, NULL);
202
203	return 0;
204}
205
206#ifdef CONFIG_PM
207static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
208{
209	struct usb_hcd *hcd = dev_get_drvdata(dev);
210	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
211	unsigned long flags;
212	int rc;
213
214	return 0;
215	rc = 0;
216
217	if (time_before(jiffies, ehci->next_statechange))
218		msleep(10);
219
220	/* Root hub was already suspended. Disable irq emission and
221	 * mark HW unaccessible.  The PM and USB cores make sure that
222	 * the root hub is either suspended or stopped.
223	 */
224	ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
225	spin_lock_irqsave(&ehci->lock, flags);
226	ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227	(void)ehci_readl(ehci, &ehci->regs->intr_enable);
228
229	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
230
231	au1xxx_stop_ehc();
232	spin_unlock_irqrestore(&ehci->lock, flags);
233
234	// could save FLADJ in case of Vaux power loss
235	// ... we'd only use it to handle clock skew
236
237	return rc;
238}
239
240static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
241{
242	struct usb_hcd *hcd = dev_get_drvdata(dev);
243	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
244
245	au1xxx_start_ehc();
246
247	// maybe restore FLADJ
248
249	if (time_before(jiffies, ehci->next_statechange))
250		msleep(100);
251
252	/* Mark hardware accessible again as we are out of D3 state by now */
253	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
254
255	/* If CF is still set, we maintained PCI Vaux power.
256	 * Just undo the effect of ehci_pci_suspend().
257	 */
258	if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
259		int	mask = INTR_MASK;
260
261		ehci_prepare_ports_for_controller_resume(ehci);
262		if (!hcd->self.root_hub->do_remote_wakeup)
263			mask &= ~STS_PCD;
264		ehci_writel(ehci, mask, &ehci->regs->intr_enable);
265		ehci_readl(ehci, &ehci->regs->intr_enable);
266		return 0;
267	}
268
269	ehci_dbg(ehci, "lost power, restarting\n");
270	usb_root_hub_lost_power(hcd->self.root_hub);
271
272	/* Else reset, to cope with power loss or flush-to-storage
273	 * style "resume" having let BIOS kick in during reboot.
274	 */
275	(void) ehci_halt(ehci);
276	(void) ehci_reset(ehci);
277
278	/* emptying the schedule aborts any urbs */
279	spin_lock_irq(&ehci->lock);
280	if (ehci->reclaim)
281		end_unlink_async(ehci);
282	ehci_work(ehci);
283	spin_unlock_irq(&ehci->lock);
284
285	ehci_writel(ehci, ehci->command, &ehci->regs->command);
286	ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
287	ehci_readl(ehci, &ehci->regs->command);	/* unblock posted writes */
288
289	/* here we "know" root ports should always stay powered */
290	ehci_port_power(ehci, 1);
291
292	hcd->state = HC_STATE_SUSPENDED;
293
294	return 0;
295}
296
297static const struct dev_pm_ops au1xxx_ehci_pmops = {
298	.suspend	= ehci_hcd_au1xxx_drv_suspend,
299	.resume		= ehci_hcd_au1xxx_drv_resume,
300};
301
302#define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
303
304#else
305#define AU1XXX_EHCI_PMOPS NULL
306#endif
307
308static struct platform_driver ehci_hcd_au1xxx_driver = {
309	.probe		= ehci_hcd_au1xxx_drv_probe,
310	.remove		= ehci_hcd_au1xxx_drv_remove,
311	.shutdown	= usb_hcd_platform_shutdown,
312	.driver = {
313		.name	= "au1xxx-ehci",
314		.owner	= THIS_MODULE,
315		.pm	= AU1XXX_EHCI_PMOPS,
316	}
317};
318
319MODULE_ALIAS("platform:au1xxx-ehci");
320