blob: 63b9d0c67963094f15ba9950c9f85c1126f3a0db [file] [log] [blame]
Wan ZongShun586dfc82009-06-13 09:14:28 +08001/*
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
Manjunath Goudara60f4f82013-09-21 16:44:42 +053014#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>
Wan ZongShun586dfc82009-06-13 09:14:28 +080019#include <linux/platform_device.h>
Manjunath Goudara60f4f82013-09-21 16:44:42 +053020#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
Wan ZongShun586dfc82009-06-13 09:14:28 +080024
Justin P. Mattockbd066ee2012-10-23 07:45:01 -070025/* enable phy0 and phy1 for w90p910 */
Wan ZongShun586dfc82009-06-13 09:14:28 +080026#define ENPHY (0x01<<8)
27#define PHY0_CTR (0xA4)
28#define PHY1_CTR (0xA8)
29
Manjunath Goudara60f4f82013-09-21 16:44:42 +053030#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
Manjunath Goudarfd3ed142016-11-24 21:42:44 +000036static int ehci_w90x900_probe(struct platform_device *pdev)
Wan ZongShun586dfc82009-06-13 09:14:28 +080037{
38 struct usb_hcd *hcd;
39 struct ehci_hcd *ehci;
40 struct resource *res;
41 int retval = 0, irq;
42 unsigned long val;
43
Manjunath Goudarfd3ed142016-11-24 21:42:44 +000044 hcd = usb_create_hcd(&ehci_w90x900_hc_driver,
45 &pdev->dev, "w90x900 EHCI");
Wan ZongShun586dfc82009-06-13 09:14:28 +080046 if (!hcd) {
47 retval = -ENOMEM;
48 goto err1;
49 }
50
Varka Bhadram0af6b072014-11-04 07:51:11 +053051 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Jingoo Han849da2d2013-12-11 16:20:35 +090052 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
53 if (IS_ERR(hcd->regs)) {
54 retval = PTR_ERR(hcd->regs);
Wan ZongShun586dfc82009-06-13 09:14:28 +080055 goto err2;
56 }
Varka Bhadram0af6b072014-11-04 07:51:11 +053057 hcd->rsrc_start = res->start;
58 hcd->rsrc_len = resource_size(res);
Wan ZongShun586dfc82009-06-13 09:14:28 +080059
Wan ZongShun586dfc82009-06-13 09:14:28 +080060 ehci = hcd_to_ehci(hcd);
61 ehci->caps = hcd->regs;
62 ehci->regs = hcd->regs +
Jan Anderssonc4301312011-05-03 20:11:57 +020063 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
Wan ZongShun586dfc82009-06-13 09:14:28 +080064
65 /* enable PHY 0,1,the regs only apply to w90p910
Manjunath Goudarfd3ed142016-11-24 21:42:44 +000066 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
67 * w90p910 IC relative to ehci->regs.
68 */
Wan ZongShun586dfc82009-06-13 09:14:28 +080069 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
Wan ZongShun586dfc82009-06-13 09:14:28 +080077 irq = platform_get_irq(pdev, 0);
Julia Lawall0bfed502014-11-20 18:34:01 +010078 if (irq < 0) {
79 retval = irq;
Jingoo Han849da2d2013-12-11 16:20:35 +090080 goto err2;
Julia Lawall0bfed502014-11-20 18:34:01 +010081 }
Wan ZongShun586dfc82009-06-13 09:14:28 +080082
83 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
84 if (retval != 0)
Jingoo Han849da2d2013-12-11 16:20:35 +090085 goto err2;
Wan ZongShun586dfc82009-06-13 09:14:28 +080086
Peter Chen3c9740a2013-11-05 10:46:02 +080087 device_wakeup_enable(hcd->self.controller);
Wan ZongShun586dfc82009-06-13 09:14:28 +080088 return retval;
Wan ZongShun586dfc82009-06-13 09:14:28 +080089err2:
90 usb_put_hcd(hcd);
91err1:
92 return retval;
93}
94
Bill Pembertonfb4e98a2012-11-19 13:26:20 -050095static int ehci_w90x900_remove(struct platform_device *pdev)
Wan ZongShun586dfc82009-06-13 09:14:28 +080096{
97 struct usb_hcd *hcd = platform_get_drvdata(pdev);
98
Manjunath Goudarfd3ed142016-11-24 21:42:44 +000099 usb_remove_hcd(hcd);
100 usb_put_hcd(hcd);
Wan ZongShun586dfc82009-06-13 09:14:28 +0800101
102 return 0;
103}
104
105static struct platform_driver ehci_hcd_w90x900_driver = {
106 .probe = ehci_w90x900_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500107 .remove = ehci_w90x900_remove,
Wan ZongShun586dfc82009-06-13 09:14:28 +0800108 .driver = {
109 .name = "w90x900-ehci",
Wan ZongShun586dfc82009-06-13 09:14:28 +0800110 },
111};
112
Manjunath Goudara60f4f82013-09-21 16:44:42 +0530113static int __init ehci_w90X900_init(void)
114{
115 if (usb_disabled())
116 return -ENODEV;
117
118 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
119
120 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
121 return platform_driver_register(&ehci_hcd_w90x900_driver);
122}
123module_init(ehci_w90X900_init);
124
125static void __exit ehci_w90X900_cleanup(void)
126{
127 platform_driver_unregister(&ehci_hcd_w90x900_driver);
128}
129module_exit(ehci_w90X900_cleanup);
130
131MODULE_DESCRIPTION(DRIVER_DESC);
Wan ZongShun586dfc82009-06-13 09:14:28 +0800132MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
Wan ZongShun586dfc82009-06-13 09:14:28 +0800133MODULE_ALIAS("platform:w90p910-ehci");
Manjunath Goudara60f4f82013-09-21 16:44:42 +0530134MODULE_LICENSE("GPL v2");