]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/usb/host/ehci-sead3.c
drivers/usb/host/ehci-sead3.c: use devm_ functions
[karo-tx-linux.git] / drivers / usb / host / ehci-sead3.c
1 /*
2  * MIPS CI13320A EHCI Host Controller driver
3  * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
4  *
5  * Copyright (C) 2012 MIPS Technologies, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation; either version 2 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/platform_device.h>
23
24 static int ehci_sead3_setup(struct usb_hcd *hcd)
25 {
26         int ret;
27         struct ehci_hcd *ehci = hcd_to_ehci(hcd);
28
29         ehci->caps = hcd->regs + 0x100;
30
31 #ifdef __BIG_ENDIAN
32         ehci->big_endian_mmio = 1;
33         ehci->big_endian_desc = 1;
34 #endif
35
36         ret = ehci_setup(hcd);
37         if (ret)
38                 return ret;
39
40         ehci->need_io_watchdog = 0;
41
42         /* Set burst length to 16 words. */
43         ehci_writel(ehci, 0x1010, &ehci->regs->reserved[1]);
44
45         return ret;
46 }
47
48 const struct hc_driver ehci_sead3_hc_driver = {
49         .description            = hcd_name,
50         .product_desc           = "SEAD-3 EHCI",
51         .hcd_priv_size          = sizeof(struct ehci_hcd),
52
53         /*
54          * generic hardware linkage
55          */
56         .irq                    = ehci_irq,
57         .flags                  = HCD_MEMORY | HCD_USB2,
58
59         /*
60          * basic lifecycle operations
61          *
62          */
63         .reset                  = ehci_sead3_setup,
64         .start                  = ehci_run,
65         .stop                   = ehci_stop,
66         .shutdown               = ehci_shutdown,
67
68         /*
69          * managing i/o requests and associated device resources
70          */
71         .urb_enqueue            = ehci_urb_enqueue,
72         .urb_dequeue            = ehci_urb_dequeue,
73         .endpoint_disable       = ehci_endpoint_disable,
74         .endpoint_reset         = ehci_endpoint_reset,
75
76         /*
77          * scheduling support
78          */
79         .get_frame_number       = ehci_get_frame,
80
81         /*
82          * root hub support
83          */
84         .hub_status_data        = ehci_hub_status_data,
85         .hub_control            = ehci_hub_control,
86         .bus_suspend            = ehci_bus_suspend,
87         .bus_resume             = ehci_bus_resume,
88         .relinquish_port        = ehci_relinquish_port,
89         .port_handed_over       = ehci_port_handed_over,
90
91         .clear_tt_buffer_complete       = ehci_clear_tt_buffer_complete,
92 };
93
94 static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev)
95 {
96         struct usb_hcd *hcd;
97         struct resource *res;
98         int ret;
99
100         if (usb_disabled())
101                 return -ENODEV;
102
103         if (pdev->resource[1].flags != IORESOURCE_IRQ) {
104                 pr_debug("resource[1] is not IORESOURCE_IRQ");
105                 return -ENOMEM;
106         }
107         hcd = usb_create_hcd(&ehci_sead3_hc_driver, &pdev->dev, "SEAD-3");
108         if (!hcd)
109                 return -ENOMEM;
110
111         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
112         hcd->rsrc_start = res->start;
113         hcd->rsrc_len = resource_size(res);
114
115         hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
116         if (!hcd->regs) {
117                 pr_debug("ioremap failed");
118                 ret = -ENOMEM;
119                 goto err1;
120         }
121
122         /* Root hub has integrated TT. */
123         hcd->has_tt = 1;
124
125         ret = usb_add_hcd(hcd, pdev->resource[1].start,
126                           IRQF_SHARED);
127         if (ret == 0) {
128                 platform_set_drvdata(pdev, hcd);
129                 return ret;
130         }
131
132 err1:
133         usb_put_hcd(hcd);
134         return ret;
135 }
136
137 static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
138 {
139         struct usb_hcd *hcd = platform_get_drvdata(pdev);
140
141         usb_remove_hcd(hcd);
142         usb_put_hcd(hcd);
143         platform_set_drvdata(pdev, NULL);
144
145         return 0;
146 }
147
148 #ifdef CONFIG_PM
149 static int ehci_hcd_sead3_drv_suspend(struct device *dev)
150 {
151         struct usb_hcd *hcd = dev_get_drvdata(dev);
152         bool do_wakeup = device_may_wakeup(dev);
153
154         return ehci_suspend(hcd, do_wakeup);
155 }
156
157 static int ehci_hcd_sead3_drv_resume(struct device *dev)
158 {
159         struct usb_hcd *hcd = dev_get_drvdata(dev);
160
161         ehci_resume(hcd, false);
162         return 0;
163 }
164
165 static const struct dev_pm_ops sead3_ehci_pmops = {
166         .suspend        = ehci_hcd_sead3_drv_suspend,
167         .resume         = ehci_hcd_sead3_drv_resume,
168 };
169
170 #define SEAD3_EHCI_PMOPS (&sead3_ehci_pmops)
171
172 #else
173 #define SEAD3_EHCI_PMOPS NULL
174 #endif
175
176 static struct platform_driver ehci_hcd_sead3_driver = {
177         .probe          = ehci_hcd_sead3_drv_probe,
178         .remove         = ehci_hcd_sead3_drv_remove,
179         .shutdown       = usb_hcd_platform_shutdown,
180         .driver = {
181                 .name   = "sead3-ehci",
182                 .owner  = THIS_MODULE,
183                 .pm     = SEAD3_EHCI_PMOPS,
184         }
185 };
186
187 MODULE_ALIAS("platform:sead3-ehci");