Loading...
1/*
2 * linux/driver/usb/host/ehci-w90x900.c
3 *
4 * Copyright (c) 2008 Nuvoton technology corporation.
5 *
6 * Wan ZongShun <mcuos.com@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation;version 2 of the License.
11 *
12 */
13
14#include <linux/dma-mapping.h>
15#include <linux/io.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/platform_device.h>
20#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
24
25/* enable phy0 and phy1 for w90p910 */
26#define ENPHY (0x01<<8)
27#define PHY0_CTR (0xA4)
28#define PHY1_CTR (0xA8)
29
30#define DRIVER_DESC "EHCI w90x900 driver"
31
32static const char hcd_name[] = "ehci-w90x900 ";
33
34static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
35
36static int usb_w90x900_probe(const struct hc_driver *driver,
37 struct platform_device *pdev)
38{
39 struct usb_hcd *hcd;
40 struct ehci_hcd *ehci;
41 struct resource *res;
42 int retval = 0, irq;
43 unsigned long val;
44
45 hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI");
46 if (!hcd) {
47 retval = -ENOMEM;
48 goto err1;
49 }
50
51 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
53 if (IS_ERR(hcd->regs)) {
54 retval = PTR_ERR(hcd->regs);
55 goto err2;
56 }
57 hcd->rsrc_start = res->start;
58 hcd->rsrc_len = resource_size(res);
59
60 ehci = hcd_to_ehci(hcd);
61 ehci->caps = hcd->regs;
62 ehci->regs = hcd->regs +
63 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
64
65 /* enable PHY 0,1,the regs only apply to w90p910
66 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
67 * w90p910 IC relative to ehci->regs.
68 */
69 val = __raw_readl(ehci->regs+PHY0_CTR);
70 val |= ENPHY;
71 __raw_writel(val, ehci->regs+PHY0_CTR);
72
73 val = __raw_readl(ehci->regs+PHY1_CTR);
74 val |= ENPHY;
75 __raw_writel(val, ehci->regs+PHY1_CTR);
76
77 irq = platform_get_irq(pdev, 0);
78 if (irq < 0) {
79 retval = irq;
80 goto err2;
81 }
82
83 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
84 if (retval != 0)
85 goto err2;
86
87 device_wakeup_enable(hcd->self.controller);
88 return retval;
89err2:
90 usb_put_hcd(hcd);
91err1:
92 return retval;
93}
94
95static void usb_w90x900_remove(struct usb_hcd *hcd,
96 struct platform_device *pdev)
97{
98 usb_remove_hcd(hcd);
99 usb_put_hcd(hcd);
100}
101
102static int ehci_w90x900_probe(struct platform_device *pdev)
103{
104 if (usb_disabled())
105 return -ENODEV;
106
107 return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev);
108}
109
110static int ehci_w90x900_remove(struct platform_device *pdev)
111{
112 struct usb_hcd *hcd = platform_get_drvdata(pdev);
113
114 usb_w90x900_remove(hcd, pdev);
115
116 return 0;
117}
118
119static struct platform_driver ehci_hcd_w90x900_driver = {
120 .probe = ehci_w90x900_probe,
121 .remove = ehci_w90x900_remove,
122 .driver = {
123 .name = "w90x900-ehci",
124 },
125};
126
127static int __init ehci_w90X900_init(void)
128{
129 if (usb_disabled())
130 return -ENODEV;
131
132 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
133
134 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
135 return platform_driver_register(&ehci_hcd_w90x900_driver);
136}
137module_init(ehci_w90X900_init);
138
139static void __exit ehci_w90X900_cleanup(void)
140{
141 platform_driver_unregister(&ehci_hcd_w90x900_driver);
142}
143module_exit(ehci_w90X900_cleanup);
144
145MODULE_DESCRIPTION(DRIVER_DESC);
146MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
147MODULE_ALIAS("platform:w90p910-ehci");
148MODULE_LICENSE("GPL v2");
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/driver/usb/host/ehci-w90x900.c
4 *
5 * Copyright (c) 2008 Nuvoton technology corporation.
6 *
7 * Wan ZongShun <mcuos.com@gmail.com>
8 */
9
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>
18
19#include "ehci.h"
20
21/* enable phy0 and phy1 for w90p910 */
22#define ENPHY (0x01<<8)
23#define PHY0_CTR (0xA4)
24#define PHY1_CTR (0xA8)
25
26#define DRIVER_DESC "EHCI w90x900 driver"
27
28static const char hcd_name[] = "ehci-w90x900 ";
29
30static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
31
32static int ehci_w90x900_probe(struct platform_device *pdev)
33{
34 struct usb_hcd *hcd;
35 struct ehci_hcd *ehci;
36 struct resource *res;
37 int retval = 0, irq;
38 unsigned long val;
39
40 hcd = usb_create_hcd(&ehci_w90x900_hc_driver,
41 &pdev->dev, "w90x900 EHCI");
42 if (!hcd) {
43 retval = -ENOMEM;
44 goto err1;
45 }
46
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;
52 }
53 hcd->rsrc_start = res->start;
54 hcd->rsrc_len = resource_size(res);
55
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));
60
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.
64 */
65 val = __raw_readl(ehci->regs+PHY0_CTR);
66 val |= ENPHY;
67 __raw_writel(val, ehci->regs+PHY0_CTR);
68
69 val = __raw_readl(ehci->regs+PHY1_CTR);
70 val |= ENPHY;
71 __raw_writel(val, ehci->regs+PHY1_CTR);
72
73 irq = platform_get_irq(pdev, 0);
74 if (irq < 0) {
75 retval = irq;
76 goto err2;
77 }
78
79 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
80 if (retval != 0)
81 goto err2;
82
83 device_wakeup_enable(hcd->self.controller);
84 return retval;
85err2:
86 usb_put_hcd(hcd);
87err1:
88 return retval;
89}
90
91static int ehci_w90x900_remove(struct platform_device *pdev)
92{
93 struct usb_hcd *hcd = platform_get_drvdata(pdev);
94
95 usb_remove_hcd(hcd);
96 usb_put_hcd(hcd);
97
98 return 0;
99}
100
101static struct platform_driver ehci_hcd_w90x900_driver = {
102 .probe = ehci_w90x900_probe,
103 .remove = ehci_w90x900_remove,
104 .driver = {
105 .name = "w90x900-ehci",
106 },
107};
108
109static int __init ehci_w90X900_init(void)
110{
111 if (usb_disabled())
112 return -ENODEV;
113
114 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
115
116 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
117 return platform_driver_register(&ehci_hcd_w90x900_driver);
118}
119module_init(ehci_w90X900_init);
120
121static void __exit ehci_w90X900_cleanup(void)
122{
123 platform_driver_unregister(&ehci_hcd_w90x900_driver);
124}
125module_exit(ehci_w90X900_cleanup);
126
127MODULE_DESCRIPTION(DRIVER_DESC);
128MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
129MODULE_ALIAS("platform:w90p910-ehci");
130MODULE_LICENSE("GPL v2");