Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux...
[cascardo/linux.git] / drivers / usb / host / ehci-au1xxx.c
1 /*
2  * EHCI HCD (Host Controller Driver) for USB.
3  *
4  * Bus Glue for AMD Alchemy Au1xxx
5  *
6  * Based on "ohci-au1xxx.c" by Matt Porter <mporter@kernel.crashing.org>
7  *
8  * Modified for AMD Alchemy Au1200 EHC
9  *  by K.Boge <karsten.boge@amd.com>
10  *
11  * This file is licenced under the GPL.
12  */
13
14 #include <linux/platform_device.h>
15 #include <asm/mach-au1x00/au1000.h>
16
17
18 extern int usb_disabled(void);
19
20 static int au1xxx_ehci_setup(struct usb_hcd *hcd)
21 {
22         struct ehci_hcd *ehci = hcd_to_ehci(hcd);
23         int ret;
24
25         ehci->caps = hcd->regs;
26         ret = ehci_setup(hcd);
27
28         ehci->need_io_watchdog = 0;
29         return ret;
30 }
31
32 static const struct hc_driver ehci_au1xxx_hc_driver = {
33         .description            = hcd_name,
34         .product_desc           = "Au1xxx EHCI",
35         .hcd_priv_size          = sizeof(struct ehci_hcd),
36
37         /*
38          * generic hardware linkage
39          */
40         .irq                    = ehci_irq,
41         .flags                  = HCD_MEMORY | HCD_USB2,
42
43         /*
44          * basic lifecycle operations
45          *
46          * FIXME -- ehci_init() doesn't do enough here.
47          * See ehci-ppc-soc for a complete implementation.
48          */
49         .reset                  = au1xxx_ehci_setup,
50         .start                  = ehci_run,
51         .stop                   = ehci_stop,
52         .shutdown               = ehci_shutdown,
53
54         /*
55          * managing i/o requests and associated device resources
56          */
57         .urb_enqueue            = ehci_urb_enqueue,
58         .urb_dequeue            = ehci_urb_dequeue,
59         .endpoint_disable       = ehci_endpoint_disable,
60         .endpoint_reset         = ehci_endpoint_reset,
61
62         /*
63          * scheduling support
64          */
65         .get_frame_number       = ehci_get_frame,
66
67         /*
68          * root hub support
69          */
70         .hub_status_data        = ehci_hub_status_data,
71         .hub_control            = ehci_hub_control,
72         .bus_suspend            = ehci_bus_suspend,
73         .bus_resume             = ehci_bus_resume,
74         .relinquish_port        = ehci_relinquish_port,
75         .port_handed_over       = ehci_port_handed_over,
76
77         .clear_tt_buffer_complete       = ehci_clear_tt_buffer_complete,
78 };
79
80 static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
81 {
82         struct usb_hcd *hcd;
83         struct resource *res;
84         int ret;
85
86         if (usb_disabled())
87                 return -ENODEV;
88
89         if (pdev->resource[1].flags != IORESOURCE_IRQ) {
90                 pr_debug("resource[1] is not IORESOURCE_IRQ");
91                 return -ENOMEM;
92         }
93         hcd = usb_create_hcd(&ehci_au1xxx_hc_driver, &pdev->dev, "Au1xxx");
94         if (!hcd)
95                 return -ENOMEM;
96
97         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98         hcd->rsrc_start = res->start;
99         hcd->rsrc_len = resource_size(res);
100
101         if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
102                 pr_debug("request_mem_region failed");
103                 ret = -EBUSY;
104                 goto err1;
105         }
106
107         hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
108         if (!hcd->regs) {
109                 pr_debug("ioremap failed");
110                 ret = -ENOMEM;
111                 goto err2;
112         }
113
114         if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) {
115                 printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
116                 ret = -ENODEV;
117                 goto err3;
118         }
119
120         ret = usb_add_hcd(hcd, pdev->resource[1].start,
121                           IRQF_SHARED);
122         if (ret == 0) {
123                 platform_set_drvdata(pdev, hcd);
124                 return ret;
125         }
126
127         alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
128 err3:
129         iounmap(hcd->regs);
130 err2:
131         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
132 err1:
133         usb_put_hcd(hcd);
134         return ret;
135 }
136
137 static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
138 {
139         struct usb_hcd *hcd = platform_get_drvdata(pdev);
140
141         usb_remove_hcd(hcd);
142         alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
143         iounmap(hcd->regs);
144         release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
145         usb_put_hcd(hcd);
146         platform_set_drvdata(pdev, NULL);
147
148         return 0;
149 }
150
151 #ifdef CONFIG_PM
152 static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
153 {
154         struct usb_hcd *hcd = dev_get_drvdata(dev);
155         bool do_wakeup = device_may_wakeup(dev);
156         int rc;
157
158         rc = ehci_suspend(hcd, do_wakeup);
159         alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
160
161         return rc;
162 }
163
164 static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
165 {
166         struct usb_hcd *hcd = dev_get_drvdata(dev);
167
168         alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
169         ehci_resume(hcd, false);
170
171         return 0;
172 }
173
174 static const struct dev_pm_ops au1xxx_ehci_pmops = {
175         .suspend        = ehci_hcd_au1xxx_drv_suspend,
176         .resume         = ehci_hcd_au1xxx_drv_resume,
177 };
178
179 #define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
180
181 #else
182 #define AU1XXX_EHCI_PMOPS NULL
183 #endif
184
185 static struct platform_driver ehci_hcd_au1xxx_driver = {
186         .probe          = ehci_hcd_au1xxx_drv_probe,
187         .remove         = ehci_hcd_au1xxx_drv_remove,
188         .shutdown       = usb_hcd_platform_shutdown,
189         .driver = {
190                 .name   = "au1xxx-ehci",
191                 .owner  = THIS_MODULE,
192                 .pm     = AU1XXX_EHCI_PMOPS,
193         }
194 };
195
196 MODULE_ALIAS("platform:au1xxx-ehci");