ef059f9b75a16cbef412e72dd9e7903b654bdda4
[openwrt.git] / target / linux / brcm63xx / patches-3.0 / 011-add_bcm63xx_ehci_controller.patch
1 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
2 ---
3  drivers/usb/host/ehci-bcm63xx.c |  154 +++++++++++++++++++++++++++++++++++++++
4  drivers/usb/host/ehci-hcd.c     |    5 +
5  2 files changed, 159 insertions(+), 0 deletions(-)
6  create mode 100644 drivers/usb/host/ehci-bcm63xx.c
7
8 --- /dev/null
9 +++ b/drivers/usb/host/ehci-bcm63xx.c
10 @@ -0,0 +1,155 @@
11 +/*
12 + * This file is subject to the terms and conditions of the GNU General Public
13 + * License.  See the file "COPYING" in the main directory of this archive
14 + * for more details.
15 + *
16 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
17 + */
18 +
19 +#include <linux/init.h>
20 +#include <linux/platform_device.h>
21 +#include <bcm63xx_cpu.h>
22 +#include <bcm63xx_regs.h>
23 +#include <bcm63xx_io.h>
24 +
25 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
26 +{
27 +       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
28 +       int retval;
29 +
30 +       retval = ehci_halt(ehci);
31 +       if (retval)
32 +               return retval;
33 +
34 +       retval = ehci_init(hcd);
35 +       if (retval)
36 +               return retval;
37 +
38 +       ehci_reset(ehci);
39 +       ehci_port_power(ehci, 0);
40 +
41 +       return retval;
42 +}
43 +
44 +
45 +static const struct hc_driver ehci_bcm63xx_hc_driver = {
46 +       .description =          hcd_name,
47 +       .product_desc =         "BCM63XX integrated EHCI controller",
48 +       .hcd_priv_size =        sizeof(struct ehci_hcd),
49 +
50 +       .irq =                  ehci_irq,
51 +       .flags =                HCD_MEMORY | HCD_USB2,
52 +
53 +       .reset =                ehci_bcm63xx_setup,
54 +       .start =                ehci_run,
55 +       .stop =                 ehci_stop,
56 +       .shutdown =             ehci_shutdown,
57 +
58 +       .urb_enqueue =          ehci_urb_enqueue,
59 +       .urb_dequeue =          ehci_urb_dequeue,
60 +       .endpoint_disable =     ehci_endpoint_disable,
61 +
62 +       .get_frame_number =     ehci_get_frame,
63 +
64 +       .hub_status_data =      ehci_hub_status_data,
65 +       .hub_control =          ehci_hub_control,
66 +       .bus_suspend =          ehci_bus_suspend,
67 +       .bus_resume =           ehci_bus_resume,
68 +       .relinquish_port =      ehci_relinquish_port,
69 +       .port_handed_over =     ehci_port_handed_over,
70 +};
71 +
72 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
73 +{
74 +       struct resource *res_mem;
75 +       struct usb_hcd *hcd;
76 +       struct ehci_hcd *ehci;
77 +       u32 reg;
78 +       int ret, irq;
79 +
80 +       res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
81 +       irq = platform_get_irq(pdev, 0);;
82 +       if (!res_mem || irq < 0)
83 +               return -ENODEV;
84 +
85 +       reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
86 +       reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
87 +       reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
88 +       bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);
89 +
90 +       /*
91 +        * The magic value comes for the original vendor BSP and is
92 +        * needed for USB to work. Datasheet does not help, so the
93 +        * magic value is used as-is.
94 +        */
95 +       bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
96 +
97 +       hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
98 +       if (!hcd)
99 +               return -ENOMEM;
100 +       hcd->rsrc_start = res_mem->start;
101 +       hcd->rsrc_len = res_mem->end - res_mem->start + 1;
102 +
103 +       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
104 +               pr_debug("request_mem_region failed\n");
105 +               ret = -EBUSY;
106 +               goto out;
107 +       }
108 +
109 +       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
110 +       if (!hcd->regs) {
111 +               pr_debug("ioremap failed\n");
112 +               ret = -EIO;
113 +               goto out1;
114 +       }
115 +
116 +       ehci = hcd_to_ehci(hcd);
117 +       ehci->big_endian_mmio = 1;
118 +       ehci->big_endian_desc = 0;
119 +       ehci->caps = hcd->regs;
120 +       ehci->regs = hcd->regs +
121 +               HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
122 +       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
123 +       ehci->sbrn = 0x20;
124 +       ehci->ignore_oc = 1;
125 +
126 +       ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
127 +       if (ret)
128 +               goto out2;
129 +
130 +       platform_set_drvdata(pdev, hcd);
131 +       return 0;
132 +
133 +out2:
134 +       iounmap(hcd->regs);
135 +out1:
136 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
137 +out:
138 +       usb_put_hcd(hcd);
139 +       return ret;
140 +}
141 +
142 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
143 +{
144 +       struct usb_hcd *hcd;
145 +
146 +       hcd = platform_get_drvdata(pdev);
147 +       usb_remove_hcd(hcd);
148 +       iounmap(hcd->regs);
149 +       usb_put_hcd(hcd);
150 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
151 +       platform_set_drvdata(pdev, NULL);
152 +       return 0;
153 +}
154 +
155 +static struct platform_driver ehci_hcd_bcm63xx_driver = {
156 +       .probe          = ehci_hcd_bcm63xx_drv_probe,
157 +       .remove         = __devexit_p(ehci_hcd_bcm63xx_drv_remove),
158 +       .shutdown       = usb_hcd_platform_shutdown,
159 +       .driver         = {
160 +               .name   = "bcm63xx_ehci",
161 +               .owner  = THIS_MODULE,
162 +       },
163 +};
164 +
165 +MODULE_ALIAS("platform:bcm63xx_ehci");
166 --- a/drivers/usb/host/ehci-hcd.c
167 +++ b/drivers/usb/host/ehci-hcd.c
168 @@ -1284,6 +1284,11 @@ MODULE_LICENSE ("GPL");
169  #define PLATFORM_DRIVER                ehci_grlib_driver
170  #endif
171  
172 +#ifdef CONFIG_BCM63XX
173 +#include "ehci-bcm63xx.c"
174 +#define PLATFORM_DRIVER                ehci_hcd_bcm63xx_driver
175 +#endif
176 +
177  #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
178      !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
179      !defined(XILINX_OF_PLATFORM_DRIVER)