blob: 32a6f3d8deecf54abd4deaaa330bcd44f752cc11 [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>
Himangi Saraogi96ae5712014-06-12 00:48:44 +053011#include <linux/device.h>
Tony Prisk100d4592012-07-21 22:58:53 +120012#include <linux/platform_device.h>
13
14static int uhci_platform_init(struct usb_hcd *hcd)
15{
16 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
17
18 uhci->rh_numports = uhci_count_ports(hcd);
19
20 /* Set up pointers to to generic functions */
21 uhci->reset_hc = uhci_generic_reset_hc;
22 uhci->check_and_reset_hc = uhci_generic_check_and_reset_hc;
23
24 /* No special actions need to be taken for the functions below */
25 uhci->configure_hc = NULL;
26 uhci->resume_detect_interrupts_are_broken = NULL;
27 uhci->global_suspend_mode_is_broken = NULL;
28
29 /* Reset if the controller isn't already safely quiescent. */
30 check_and_reset_hc(uhci);
31 return 0;
32}
33
34static const struct hc_driver uhci_platform_hc_driver = {
35 .description = hcd_name,
36 .product_desc = "Generic UHCI Host Controller",
37 .hcd_priv_size = sizeof(struct uhci_hcd),
38
39 /* Generic hardware linkage */
40 .irq = uhci_irq,
41 .flags = HCD_MEMORY | HCD_USB11,
42
43 /* Basic lifecycle operations */
44 .reset = uhci_platform_init,
45 .start = uhci_start,
46#ifdef CONFIG_PM
47 .pci_suspend = NULL,
48 .pci_resume = NULL,
49 .bus_suspend = uhci_rh_suspend,
50 .bus_resume = uhci_rh_resume,
51#endif
52 .stop = uhci_stop,
53
54 .urb_enqueue = uhci_urb_enqueue,
55 .urb_dequeue = uhci_urb_dequeue,
56
57 .endpoint_disable = uhci_hcd_endpoint_disable,
58 .get_frame_number = uhci_hcd_get_frame_number,
59
60 .hub_status_data = uhci_hub_status_data,
61 .hub_control = uhci_hub_control,
62};
63
Bill Pemberton41ac7b32012-11-19 13:21:48 -050064static int uhci_hcd_platform_probe(struct platform_device *pdev)
Tony Prisk100d4592012-07-21 22:58:53 +120065{
66 struct usb_hcd *hcd;
67 struct uhci_hcd *uhci;
68 struct resource *res;
69 int ret;
70
71 if (usb_disabled())
72 return -ENODEV;
73
Tony Prisk09eeffb2012-10-14 16:22:34 +130074 /*
75 * Right now device-tree probed devices don't get dma_mask set.
76 * Since shared usb code relies on it, set it here for now.
77 * Once we have dma capability bindings this can go away.
78 */
Russell Kinge1fd7342013-06-27 12:36:37 +010079 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Russell King22d9d8e2013-06-10 16:28:49 +010080 if (ret)
81 return ret;
Tony Prisk09eeffb2012-10-14 16:22:34 +130082
Tony Prisk100d4592012-07-21 22:58:53 +120083 hcd = usb_create_hcd(&uhci_platform_hc_driver, &pdev->dev,
84 pdev->name);
85 if (!hcd)
86 return -ENOMEM;
87
88 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Himangi Saraogi96ae5712014-06-12 00:48:44 +053089 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
90 if (IS_ERR(hcd->regs)) {
91 ret = PTR_ERR(hcd->regs);
Tony Prisk100d4592012-07-21 22:58:53 +120092 goto err_rmr;
93 }
Varka Bhadram6827f7e2014-11-04 07:17:10 +053094 hcd->rsrc_start = res->start;
95 hcd->rsrc_len = resource_size(res);
96
Tony Prisk100d4592012-07-21 22:58:53 +120097 uhci = hcd_to_uhci(hcd);
98
99 uhci->regs = hcd->regs;
100
Michael Opdenacker2b4ef832013-10-06 08:47:55 +0200101 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
Tony Prisk100d4592012-07-21 22:58:53 +1200102 if (ret)
Himangi Saraogi96ae5712014-06-12 00:48:44 +0530103 goto err_rmr;
Tony Prisk100d4592012-07-21 22:58:53 +1200104
Peter Chen3c9740a2013-11-05 10:46:02 +0800105 device_wakeup_enable(hcd->self.controller);
Tony Prisk100d4592012-07-21 22:58:53 +1200106 return 0;
107
Tony Prisk100d4592012-07-21 22:58:53 +1200108err_rmr:
109 usb_put_hcd(hcd);
110
111 return ret;
112}
113
114static int uhci_hcd_platform_remove(struct platform_device *pdev)
115{
116 struct usb_hcd *hcd = platform_get_drvdata(pdev);
117
118 usb_remove_hcd(hcd);
Tony Prisk100d4592012-07-21 22:58:53 +1200119 usb_put_hcd(hcd);
Tony Prisk100d4592012-07-21 22:58:53 +1200120
121 return 0;
122}
123
124/* Make sure the controller is quiescent and that we're not using it
125 * any more. This is mainly for the benefit of programs which, like kexec,
126 * expect the hardware to be idle: not doing DMA or generating IRQs.
127 *
128 * This routine may be called in a damaged or failing kernel. Hence we
129 * do not acquire the spinlock before shutting down the controller.
130 */
131static void uhci_hcd_platform_shutdown(struct platform_device *op)
132{
Jingoo Han477527b2013-05-23 19:18:39 +0900133 struct usb_hcd *hcd = platform_get_drvdata(op);
Tony Prisk100d4592012-07-21 22:58:53 +1200134
135 uhci_hc_died(hcd_to_uhci(hcd));
136}
137
138static const struct of_device_id platform_uhci_ids[] = {
Hans de Goedee16fa442014-02-11 17:54:45 +0100139 { .compatible = "generic-uhci", },
Tony Prisk100d4592012-07-21 22:58:53 +1200140 { .compatible = "platform-uhci", },
141 {}
142};
Luis de Bethencourte2f39512015-09-19 14:10:59 +0100143MODULE_DEVICE_TABLE(of, platform_uhci_ids);
Tony Prisk100d4592012-07-21 22:58:53 +1200144
145static struct platform_driver uhci_platform_driver = {
146 .probe = uhci_hcd_platform_probe,
147 .remove = uhci_hcd_platform_remove,
148 .shutdown = uhci_hcd_platform_shutdown,
149 .driver = {
150 .name = "platform-uhci",
Sachin Kamat5d689162013-05-21 17:17:21 +0530151 .of_match_table = platform_uhci_ids,
Tony Prisk100d4592012-07-21 22:58:53 +1200152 },
153};