Linux 4.16.11
[linux/fpc-iii.git] / drivers / usb / host / ehci-w90x900.c
blob6d77ace1697ba97f2cf52a505170f45415213bd7
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/driver/usb/host/ehci-w90x900.c
5 * Copyright (c) 2008 Nuvoton technology corporation.
7 * Wan ZongShun <mcuos.com@gmail.com>
8 */
10 #include <linux/dma-mapping.h>
11 #include <linux/io.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/of.h>
15 #include <linux/platform_device.h>
16 #include <linux/usb.h>
17 #include <linux/usb/hcd.h>
19 #include "ehci.h"
21 /* enable phy0 and phy1 for w90p910 */
22 #define ENPHY (0x01<<8)
23 #define PHY0_CTR (0xA4)
24 #define PHY1_CTR (0xA8)
26 #define DRIVER_DESC "EHCI w90x900 driver"
28 static const char hcd_name[] = "ehci-w90x900 ";
30 static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
32 static int ehci_w90x900_probe(struct platform_device *pdev)
34 struct usb_hcd *hcd;
35 struct ehci_hcd *ehci;
36 struct resource *res;
37 int retval = 0, irq;
38 unsigned long val;
40 hcd = usb_create_hcd(&ehci_w90x900_hc_driver,
41 &pdev->dev, "w90x900 EHCI");
42 if (!hcd) {
43 retval = -ENOMEM;
44 goto err1;
47 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
48 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
49 if (IS_ERR(hcd->regs)) {
50 retval = PTR_ERR(hcd->regs);
51 goto err2;
53 hcd->rsrc_start = res->start;
54 hcd->rsrc_len = resource_size(res);
56 ehci = hcd_to_ehci(hcd);
57 ehci->caps = hcd->regs;
58 ehci->regs = hcd->regs +
59 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
61 /* enable PHY 0,1,the regs only apply to w90p910
62 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
63 * w90p910 IC relative to ehci->regs.
65 val = __raw_readl(ehci->regs+PHY0_CTR);
66 val |= ENPHY;
67 __raw_writel(val, ehci->regs+PHY0_CTR);
69 val = __raw_readl(ehci->regs+PHY1_CTR);
70 val |= ENPHY;
71 __raw_writel(val, ehci->regs+PHY1_CTR);
73 irq = platform_get_irq(pdev, 0);
74 if (irq < 0) {
75 retval = irq;
76 goto err2;
79 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
80 if (retval != 0)
81 goto err2;
83 device_wakeup_enable(hcd->self.controller);
84 return retval;
85 err2:
86 usb_put_hcd(hcd);
87 err1:
88 return retval;
91 static int ehci_w90x900_remove(struct platform_device *pdev)
93 struct usb_hcd *hcd = platform_get_drvdata(pdev);
95 usb_remove_hcd(hcd);
96 usb_put_hcd(hcd);
98 return 0;
101 static struct platform_driver ehci_hcd_w90x900_driver = {
102 .probe = ehci_w90x900_probe,
103 .remove = ehci_w90x900_remove,
104 .driver = {
105 .name = "w90x900-ehci",
109 static int __init ehci_w90X900_init(void)
111 if (usb_disabled())
112 return -ENODEV;
114 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
116 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
117 return platform_driver_register(&ehci_hcd_w90x900_driver);
119 module_init(ehci_w90X900_init);
121 static void __exit ehci_w90X900_cleanup(void)
123 platform_driver_unregister(&ehci_hcd_w90x900_driver);
125 module_exit(ehci_w90X900_cleanup);
127 MODULE_DESCRIPTION(DRIVER_DESC);
128 MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
129 MODULE_ALIAS("platform:w90p910-ehci");
130 MODULE_LICENSE("GPL v2");