blob: d41b3d21725398557fb90ce82bc0ce8187317e9b [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Chris Metcalf47fc28b2012-05-09 13:58:14 -04002/*
3 * Copyright 2012 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/*
17 * Tilera TILE-Gx USB EHCI host controller driver.
18 */
19
20#include <linux/irq.h>
21#include <linux/platform_device.h>
22#include <linux/usb/tilegx.h>
23#include <linux/usb.h>
24
25#include <asm/homecache.h>
26
27#include <gxio/iorpc_usb_host.h>
28#include <gxio/usb_host.h>
29
30static void tilegx_start_ehc(void)
31{
32}
33
34static void tilegx_stop_ehc(void)
35{
36}
37
38static int tilegx_ehci_setup(struct usb_hcd *hcd)
39{
40 int ret = ehci_init(hcd);
41
42 /*
43 * Some drivers do:
44 *
45 * struct ehci_hcd *ehci = hcd_to_ehci(hcd);
46 * ehci->need_io_watchdog = 0;
47 *
48 * here, but since this is a new driver we're going to leave the
49 * watchdog enabled. Later we may try to turn it off and see
50 * whether we run into any problems.
51 */
52
53 return ret;
54}
55
56static const struct hc_driver ehci_tilegx_hc_driver = {
57 .description = hcd_name,
58 .product_desc = "Tile-Gx EHCI",
59 .hcd_priv_size = sizeof(struct ehci_hcd),
60
61 /*
62 * Generic hardware linkage.
63 */
64 .irq = ehci_irq,
Greg Kroah-Hartmanc04ee4b2013-09-23 13:32:51 -070065 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
Chris Metcalf47fc28b2012-05-09 13:58:14 -040066
67 /*
68 * Basic lifecycle operations.
69 */
70 .reset = tilegx_ehci_setup,
71 .start = ehci_run,
72 .stop = ehci_stop,
73 .shutdown = ehci_shutdown,
74
75 /*
76 * Managing I/O requests and associated device resources.
77 */
78 .urb_enqueue = ehci_urb_enqueue,
79 .urb_dequeue = ehci_urb_dequeue,
80 .endpoint_disable = ehci_endpoint_disable,
81 .endpoint_reset = ehci_endpoint_reset,
82
83 /*
84 * Scheduling support.
85 */
86 .get_frame_number = ehci_get_frame,
87
88 /*
89 * Root hub support.
90 */
91 .hub_status_data = ehci_hub_status_data,
92 .hub_control = ehci_hub_control,
93 .bus_suspend = ehci_bus_suspend,
94 .bus_resume = ehci_bus_resume,
95 .relinquish_port = ehci_relinquish_port,
96 .port_handed_over = ehci_port_handed_over,
97
98 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
99};
100
101static int ehci_hcd_tilegx_drv_probe(struct platform_device *pdev)
102{
103 struct usb_hcd *hcd;
104 struct ehci_hcd *ehci;
Jingoo Hand4f09e22013-07-30 19:59:40 +0900105 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400106 pte_t pte = { 0 };
107 int my_cpu = smp_processor_id();
108 int ret;
109
110 if (usb_disabled())
111 return -ENODEV;
112
113 /*
114 * Try to initialize our GXIO context; if we can't, the device
115 * doesn't exist.
116 */
117 if (gxio_usb_host_init(&pdata->usb_ctx, pdata->dev_index, 1) != 0)
118 return -ENXIO;
119
120 hcd = usb_create_hcd(&ehci_tilegx_hc_driver, &pdev->dev,
121 dev_name(&pdev->dev));
Libo Chenabab8762013-05-09 02:08:33 -0400122 if (!hcd) {
123 ret = -ENOMEM;
124 goto err_hcd;
125 }
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400126
127 /*
128 * We don't use rsrc_start to map in our registers, but seems like
129 * we ought to set it to something, so we use the register VA.
130 */
131 hcd->rsrc_start =
132 (ulong) gxio_usb_host_get_reg_start(&pdata->usb_ctx);
133 hcd->rsrc_len = gxio_usb_host_get_reg_len(&pdata->usb_ctx);
134 hcd->regs = gxio_usb_host_get_reg_start(&pdata->usb_ctx);
135
136 tilegx_start_ehc();
137
138 ehci = hcd_to_ehci(hcd);
139 ehci->caps = hcd->regs;
140 ehci->regs =
141 hcd->regs + HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
142 /* cache this readonly data; minimize chip reads */
143 ehci->hcs_params = readl(&ehci->caps->hcs_params);
144
145 /* Create our IRQs and register them. */
Thomas Gleixner7e5f01b2014-05-07 15:44:13 +0000146 pdata->irq = irq_alloc_hwirq(-1);
147 if (!pdata->irq) {
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400148 ret = -ENXIO;
149 goto err_no_irq;
150 }
151
152 tile_irq_activate(pdata->irq, TILE_IRQ_PERCPU);
153
154 /* Configure interrupts. */
155 ret = gxio_usb_host_cfg_interrupt(&pdata->usb_ctx,
156 cpu_x(my_cpu), cpu_y(my_cpu),
157 KERNEL_PL, pdata->irq);
158 if (ret) {
159 ret = -ENXIO;
160 goto err_have_irq;
161 }
162
163 /* Register all of our memory. */
164 pte = pte_set_home(pte, PAGE_HOME_HASH);
165 ret = gxio_usb_host_register_client_memory(&pdata->usb_ctx, pte, 0);
166 if (ret) {
167 ret = -ENXIO;
168 goto err_have_irq;
169 }
170
171 ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED);
172 if (ret == 0) {
173 platform_set_drvdata(pdev, hcd);
Peter Chen3c9740a2013-11-05 10:46:02 +0800174 device_wakeup_enable(hcd->self.controller);
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400175 return ret;
176 }
177
178err_have_irq:
Thomas Gleixner7e5f01b2014-05-07 15:44:13 +0000179 irq_free_hwirq(pdata->irq);
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400180err_no_irq:
181 tilegx_stop_ehc();
182 usb_put_hcd(hcd);
Libo Chenabab8762013-05-09 02:08:33 -0400183err_hcd:
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400184 gxio_usb_host_destroy(&pdata->usb_ctx);
185 return ret;
186}
187
188static int ehci_hcd_tilegx_drv_remove(struct platform_device *pdev)
189{
190 struct usb_hcd *hcd = platform_get_drvdata(pdev);
Jingoo Hand4f09e22013-07-30 19:59:40 +0900191 struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400192
193 usb_remove_hcd(hcd);
194 usb_put_hcd(hcd);
195 tilegx_stop_ehc();
196 gxio_usb_host_destroy(&pdata->usb_ctx);
Thomas Gleixner7e5f01b2014-05-07 15:44:13 +0000197 irq_free_hwirq(pdata->irq);
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400198
199 return 0;
200}
201
202static void ehci_hcd_tilegx_drv_shutdown(struct platform_device *pdev)
203{
204 usb_hcd_platform_shutdown(pdev);
205 ehci_hcd_tilegx_drv_remove(pdev);
206}
207
208static struct platform_driver ehci_hcd_tilegx_driver = {
209 .probe = ehci_hcd_tilegx_drv_probe,
210 .remove = ehci_hcd_tilegx_drv_remove,
211 .shutdown = ehci_hcd_tilegx_drv_shutdown,
212 .driver = {
213 .name = "tilegx-ehci",
Chris Metcalf47fc28b2012-05-09 13:58:14 -0400214 }
215};
216
217MODULE_ALIAS("platform:tilegx-ehci");