cns21xx: add support for 3.10
[openwrt.git] / target / linux / cns21xx / patches-3.10 / 104-cns21xx-usb-ehci-support.patch
1 --- /dev/null
2 +++ b/drivers/usb/host/ehci-cns21xx.c
3 @@ -0,0 +1,130 @@
4 +/*
5 + *  Copyright (c) 2008 Cavium Networks
6 + *  Copyright (c) 2010-2013 Gabor Juhos <juhosg@openwrt.org>
7 + *
8 + *  This file is free software; you can redistribute it and/or modify
9 + *  it under the terms of the GNU General Public License, Version 2, as
10 + *  published by the Free Software Foundation.
11 + */
12 +
13 +#include <linux/kernel.h>
14 +#include <linux/module.h>
15 +#include <linux/io.h>
16 +#include <linux/platform_device.h>
17 +#include <linux/irq.h>
18 +#include <linux/usb.h>
19 +#include <linux/usb/hcd.h>
20 +
21 +#include <mach/cns21xx.h>
22 +
23 +#include "ehci.h"
24 +
25 +#define DRIVER_NAME    "cns21xx-ehci"
26 +
27 +static const char hcd_name[] = "ehci-cns21xx";
28 +static struct hc_driver __read_mostly ehci_cns21xx_hc_driver;
29 +
30 +static void ehci_cns21xx_init_hc(void)
31 +{
32 +       void __iomem *base = (void __iomem *) CNS21XX_EHCI_CONFIG_BASE_VIRT;
33 +
34 +       __raw_writel(0x106, base + 0x04);
35 +       __raw_writel((3 << 5) | 0x2000, base + 0x40);
36 +       msleep(100);
37 +}
38 +
39 +static int ehci_cns21xx_probe(struct platform_device *pdev)
40 +{
41 +       struct usb_hcd *hcd;
42 +       struct ehci_hcd *ehci;
43 +       struct resource *res;
44 +       int irq;
45 +       int ret;
46 +
47 +       irq = platform_get_irq(pdev, 0);
48 +       if (irq < 0) {
49 +               dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
50 +                       dev_name(&pdev->dev));
51 +               return -ENODEV;
52 +       }
53 +
54 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
55 +       if (!res) {
56 +               dev_dbg(&pdev->dev, "no base address specified for %s\n",
57 +                       dev_name(&pdev->dev));
58 +               return -EINVAL;
59 +       }
60 +
61 +       hcd = usb_create_hcd(&ehci_cns21xx_hc_driver, &pdev->dev,
62 +                            dev_name(&pdev->dev));
63 +       if (!hcd)
64 +               return -ENOMEM;
65 +
66 +       hcd->rsrc_start = res->start;
67 +       hcd->rsrc_len   = res->end - res->start + 1;
68 +
69 +       hcd->regs = devm_ioremap_resource(&pdev->dev, res);
70 +       if (IS_ERR(hcd->regs)) {
71 +               ret = PTR_ERR(hcd->regs);
72 +               goto err_put_hcd;
73 +       }
74 +
75 +       ehci_cns21xx_init_hc();
76 +
77 +       ehci = hcd_to_ehci(hcd);
78 +       ehci->caps = hcd->regs;
79 +
80 +       ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
81 +       if (ret)
82 +               goto err_put_hcd;
83 +
84 +       platform_set_drvdata(pdev, hcd);
85 +
86 +       return 0;
87 +
88 +err_put_hcd:
89 +       usb_put_hcd(hcd);
90 +
91 +       return ret;
92 +}
93 +
94 +static int ehci_cns21xx_remove(struct platform_device *pdev)
95 +{
96 +       struct usb_hcd *hcd = platform_get_drvdata(pdev);
97 +
98 +       usb_remove_hcd(hcd);
99 +       usb_put_hcd(hcd);
100 +
101 +       return 0;
102 +}
103 +
104 +static struct platform_driver ehci_cns21xx_driver = {
105 +       .probe          = ehci_cns21xx_probe,
106 +       .remove         = ehci_cns21xx_remove,
107 +       .shutdown       = usb_hcd_platform_shutdown,
108 +       .driver         = {
109 +               .owner  = THIS_MODULE,
110 +               .name   = DRIVER_NAME,
111 +       },
112 +};
113 +
114 +static int __init ehci_cns21xx_init(void)
115 +{
116 +       if (usb_disabled())
117 +               return -ENODEV;
118 +
119 +       ehci_init_driver(&ehci_cns21xx_hc_driver, NULL);
120 +
121 +       return platform_driver_register(&ehci_cns21xx_driver);
122 +}
123 +module_init(ehci_cns21xx_init);
124 +
125 +static void __exit ehci_cns21xx_exit(void)
126 +{
127 +       platform_driver_unregister(&ehci_cns21xx_driver);
128 +}
129 +module_exit(ehci_cns21xx_exit);
130 +
131 +MODULE_DESCRIPTION("Cavium Networks CNS21xx built-in EHCI controller driver");
132 +MODULE_ALIAS("platform:" DRIVER_NAME);
133 +MODULE_LICENSE("GPL v2");
134 --- a/arch/arm/Kconfig
135 +++ b/arch/arm/Kconfig
136 @@ -375,6 +375,7 @@ config ARCH_CNS21XX
137         select ARCH_REQUIRE_GPIOLIB
138         select ARM_L1_CACHE_SHIFT_4
139         select USB_ARCH_HAS_OHCI
140 +       select USB_ARCH_HAS_EHCI
141         help
142           Support for Cavium Networks CNS21xx family.
143  
144 --- a/drivers/usb/host/Kconfig
145 +++ b/drivers/usb/host/Kconfig
146 @@ -249,6 +249,14 @@ config USB_W90X900_EHCI
147         ---help---
148                 Enables support for the W90X900 USB controller
149  
150 +config USB_EHCI_CNS21XX
151 +       tristate "EHCI support for the Cavium CNS21XX SoCs"
152 +       depends on ARCH_CNS21XX
153 +       default y
154 +       help
155 +         Enables support for the built-in EHCI controller of the
156 +         Cavium CNS21xx SoCs.
157 +
158  config USB_CNS3XXX_EHCI
159         bool "Cavium CNS3XXX EHCI Module (DEPRECATED)"
160         depends on ARCH_CNS3XXX
161 --- a/drivers/usb/host/Makefile
162 +++ b/drivers/usb/host/Makefile
163 @@ -33,6 +33,7 @@ obj-$(CONFIG_USB_EHCI_HCD_SPEAR)      += ehci
164  obj-$(CONFIG_USB_EHCI_S5P)     += ehci-s5p.o
165  obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
166  obj-$(CONFIG_USB_EHCI_MSM)     += ehci-msm.o
167 +obj-$(CONFIG_USB_EHCI_CNS21XX) += ehci-cns21xx.o
168  
169  obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
170  obj-$(CONFIG_USB_ISP116X_HCD)  += isp116x-hcd.o