blob: 800bcaed205c418d4780ac2cc3fe27e8c52831db [file] [log] [blame]
Felipe Balbid07e8812011-10-12 14:08:26 +03001/**
2 * host.c - DesignWare USB3 DRD Controller Host Glue
3 *
4 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 *
Felipe Balbi5945f782013-06-30 14:15:11 +03008 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
Felipe Balbid07e8812011-10-12 14:08:26 +030011 *
Felipe Balbi5945f782013-06-30 14:15:11 +030012 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Felipe Balbid07e8812011-10-12 14:08:26 +030016 */
17
Felipe Balbid07e8812011-10-12 14:08:26 +030018#include <linux/platform_device.h>
Felipe Balbid07e8812011-10-12 14:08:26 +030019
20#include "core.h"
Felipe Balbid07e8812011-10-12 14:08:26 +030021
Felipe Balbid07e8812011-10-12 14:08:26 +030022int dwc3_host_init(struct dwc3 *dwc)
23{
Heikki Krogerus95b57df2016-06-21 10:58:09 +030024 struct property_entry props[2];
Felipe Balbid07e8812011-10-12 14:08:26 +030025 struct platform_device *xhci;
Roger Quadros322832f2016-06-30 14:54:17 +030026 int ret, irq;
27 struct resource *res;
28 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
29
30 irq = platform_get_irq_byname(dwc3_pdev, "host");
31 if (irq == -EPROBE_DEFER)
32 return irq;
33
34 if (irq <= 0) {
35 irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
36 if (irq == -EPROBE_DEFER)
37 return irq;
38
39 if (irq <= 0) {
40 irq = platform_get_irq(dwc3_pdev, 0);
41 if (irq <= 0) {
42 if (irq != -EPROBE_DEFER) {
43 dev_err(dwc->dev,
44 "missing host IRQ\n");
45 }
46 if (!irq)
47 irq = -EINVAL;
48 return irq;
49 } else {
50 res = platform_get_resource(dwc3_pdev,
51 IORESOURCE_IRQ, 0);
52 }
53 } else {
54 res = platform_get_resource_byname(dwc3_pdev,
55 IORESOURCE_IRQ,
56 "dwc_usb3");
57 }
58
59 } else {
60 res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ,
61 "host");
62 }
63
64 dwc->xhci_resources[1].start = irq;
65 dwc->xhci_resources[1].end = irq;
66 dwc->xhci_resources[1].flags = res->flags;
67 dwc->xhci_resources[1].name = res->name;
Felipe Balbid07e8812011-10-12 14:08:26 +030068
Vivek Gautam52758bc2013-01-25 16:52:02 +053069 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
Felipe Balbid07e8812011-10-12 14:08:26 +030070 if (!xhci) {
71 dev_err(dwc->dev, "couldn't allocate xHCI device\n");
Heikki Krogerus08f871a2014-11-19 17:28:23 +020072 return -ENOMEM;
Felipe Balbid07e8812011-10-12 14:08:26 +030073 }
74
Mayank Ranaa99689a2016-08-10 17:39:47 -070075 arch_setup_dma_ops(&xhci->dev, 0, 0, NULL, 0);
Felipe Balbid07e8812011-10-12 14:08:26 +030076 dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
77
78 xhci->dev.parent = dwc->dev;
79 xhci->dev.dma_mask = dwc->dev->dma_mask;
80 xhci->dev.dma_parms = dwc->dev->dma_parms;
81
82 dwc->xhci = xhci;
83
Ido Shayevitz51249dc2012-04-24 14:18:39 +030084 ret = platform_device_add_resources(xhci, dwc->xhci_resources,
85 DWC3_XHCI_RESOURCES_NUM);
Felipe Balbid07e8812011-10-12 14:08:26 +030086 if (ret) {
87 dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
88 goto err1;
89 }
90
Heikki Krogerus95b57df2016-06-21 10:58:09 +030091 memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
Pratyush Anandb2f463e2014-07-04 17:01:26 +030092
Heikki Krogerus95b57df2016-06-21 10:58:09 +030093 if (dwc->usb3_lpm_capable) {
94 props[0].name = "usb3-lpm-capable";
95 ret = platform_device_add_properties(xhci, props);
96 if (ret) {
97 dev_err(dwc->dev, "failed to add properties to xHCI\n");
98 goto err1;
99 }
Pratyush Anandb2f463e2014-07-04 17:01:26 +0300100 }
101
Heikki Krogerus08f871a2014-11-19 17:28:23 +0200102 phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
103 dev_name(&xhci->dev));
104 phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
105 dev_name(&xhci->dev));
106
Mayank Ranaa99689a2016-08-10 17:39:47 -0700107 /* Platform device gets added as part of state machine */
Felipe Balbid07e8812011-10-12 14:08:26 +0300108
109 return 0;
Felipe Balbid07e8812011-10-12 14:08:26 +0300110err1:
111 platform_device_put(xhci);
Felipe Balbid07e8812011-10-12 14:08:26 +0300112 return ret;
113}
114
115void dwc3_host_exit(struct dwc3 *dwc)
116{
Heikki Krogerus08f871a2014-11-19 17:28:23 +0200117 phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
118 dev_name(&dwc->xhci->dev));
119 phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
120 dev_name(&dwc->xhci->dev));
Mayank Ranaa99689a2016-08-10 17:39:47 -0700121 if (!dwc->is_drd)
122 platform_device_unregister(dwc->xhci);
Felipe Balbid07e8812011-10-12 14:08:26 +0300123}