blob: 3003fefaa9647df17d66168c9f88337c45cfa3ac [file] [log] [blame]
Tony Prisk100d4592012-07-21 22:58:53 +12001/*
2 * Generic UHCI HCD (Host Controller Driver) for Platform Devices
3 *
4 * Copyright (c) 2011 Tony Prisk <linux@prisktech.co.nz>
5 *
6 * This file is based on uhci-grlib.c
7 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
8 */
9
10#include <linux/of.h>
11#include <linux/platform_device.h>
12
13static int uhci_platform_init(struct usb_hcd *hcd)
14{
15 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
16
17 uhci->rh_numports = uhci_count_ports(hcd);
18
19 /* Set up pointers to to generic functions */
20 uhci->reset_hc = uhci_generic_reset_hc;
21 uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
22
23 /* No special actions need to be taken for the functions below */
24 uhci->configure_hc = NULL;
25 uhci->resume_detect_interrupts_are_broken = NULL;
26 uhci->global_suspend_mode_is_broken = NULL;
27
28 /* Reset if the controller isn't already safely quiescent. */
29 check_and_reset_hc(uhci);
30 return 0;
31}
32
33static const struct hc_driver uhci_platform_hc_driver = {
34 .description = hcd_name,
35 .product_desc = "Generic UHCI Host Controller",
36 .hcd_priv_size = sizeof(struct uhci_hcd),
37
38 /* Generic hardware linkage */
39 .irq = uhci_irq,
40 .flags = HCD_MEMORY | HCD_USB11,
41
42 /* Basic lifecycle operations */
43 .reset = uhci_platform_init,
44 .start = uhci_start,
45#ifdef CONFIG_PM
46 .pci_suspend = NULL,
47 .pci_resume = NULL,
48 .bus_suspend = uhci_rh_suspend,
49 .bus_resume = uhci_rh_resume,
50#endif
51 .stop = uhci_stop,
52
53 .urb_enqueue = uhci_urb_enqueue,
54 .urb_dequeue = uhci_urb_dequeue,
55
56 .endpoint_disable = uhci_hcd_endpoint_disable,
57 .get_frame_number = uhci_hcd_get_frame_number,
58
59 .hub_status_data = uhci_hub_status_data,
60 .hub_control = uhci_hub_control,
61};
62
Bill Pemberton41ac7b32012-11-19 13:21:48 -050063static int uhci_hcd_platform_probe(struct platform_device *pdev)
Tony Prisk100d4592012-07-21 22:58:53 +120064{
65 struct usb_hcd *hcd;
66 struct uhci_hcd *uhci;
67 struct resource *res;
68 int ret;
69
70 if (usb_disabled())
71 return -ENODEV;
72
Tony Prisk09eeffb2012-10-14 16:22:34 +130073 /*
74 * Right now device-tree probed devices don't get dma_mask set.
75 * Since shared usb code relies on it, set it here for now.
76 * Once we have dma capability bindings this can go away.
77 */
Russell Kinge1fd7342013-06-27 12:36:37 +010078 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Russell King22d9d8e2013-06-10 16:28:49 +010079 if (ret)
80 return ret;
Tony Prisk09eeffb2012-10-14 16:22:34 +130081
Tony Prisk100d4592012-07-21 22:58:53 +120082 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
83 pdev->name);
84 if (!hcd)
85 return -ENOMEM;
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 hcd->rsrc_start = res->start;
89 hcd->rsrc_len = resource_size(res);
90
91 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
92 pr_err("%s: request_mem_region failed\n", __func__);
93 ret = -EBUSY;
94 goto err_rmr;
95 }
96
97 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
98 if (!hcd->regs) {
99 pr_err("%s: ioremap failed\n", __func__);
100 ret = -ENOMEM;
101 goto err_irq;
102 }
103 uhci = hcd_to_uhci(hcd);
104
105 uhci->regs = hcd->regs;
106
Michael Opdenacker2b4ef832013-10-06 08:47:55 +0200107 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
Tony Prisk100d4592012-07-21 22:58:53 +1200108 if (ret)
109 goto err_uhci;
110
111 return 0;
112
113err_uhci:
114 iounmap(hcd->regs);
115err_irq:
116 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
117err_rmr:
118 usb_put_hcd(hcd);
119
120 return ret;
121}
122
123static int uhci_hcd_platform_remove(struct platform_device *pdev)
124{
125 struct usb_hcd *hcd = platform_get_drvdata(pdev);
126
127 usb_remove_hcd(hcd);
128 iounmap(hcd->regs);
129 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
130 usb_put_hcd(hcd);
Tony Prisk100d4592012-07-21 22:58:53 +1200131
132 return 0;
133}
134
135/* Make sure the controller is quiescent and that we're not using it
136 * any more. This is mainly for the benefit of programs which, like kexec,
137 * expect the hardware to be idle: not doing DMA or generating IRQs.
138 *
139 * This routine may be called in a damaged or failing kernel. Hence we
140 * do not acquire the spinlock before shutting down the controller.
141 */
142static void uhci_hcd_platform_shutdown(struct platform_device *op)
143{
Jingoo Han477527b2013-05-23 19:18:39 +0900144 struct usb_hcd *hcd = platform_get_drvdata(op);
Tony Prisk100d4592012-07-21 22:58:53 +1200145
146 uhci_hc_died(hcd_to_uhci(hcd));
147}
148
149static const struct of_device_id platform_uhci_ids[] = {
150 { .compatible = "platform-uhci", },
151 {}
152};
153
154static struct platform_driver uhci_platform_driver = {
155 .probe = uhci_hcd_platform_probe,
156 .remove = uhci_hcd_platform_remove,
157 .shutdown = uhci_hcd_platform_shutdown,
158 .driver = {
159 .name = "platform-uhci",
160 .owner = THIS_MODULE,
Sachin Kamat5d689162013-05-21 17:17:21 +0530161 .of_match_table = platform_uhci_ids,
Tony Prisk100d4592012-07-21 22:58:53 +1200162 },
163};