[brcm63xx] add preliminary support for 3.6 kernel
[openwrt.git] / target / linux / brcm63xx / patches-3.6 / 402-ehci-add-driver-for-bcm63xx-integrated-controller.patch
1 From db58271d5152aa1d3894fdef13ca04379139d5d9 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Fri, 10 Jun 2011 19:15:47 +0200
4 Subject: [PATCH 25/63] ehci: add driver for bcm63xx integrated controller.
5
6 ---
7  drivers/usb/host/Kconfig        |   10 ++-
8  drivers/usb/host/ehci-bcm63xx.c |  186 +++++++++++++++++++++++++++++++++++++++
9  drivers/usb/host/ehci-hcd.c     |    5 +
10  3 files changed, 199 insertions(+), 1 deletions(-)
11  create mode 100644 drivers/usb/host/ehci-bcm63xx.c
12
13 --- a/drivers/usb/host/Kconfig
14 +++ b/drivers/usb/host/Kconfig
15 @@ -110,7 +110,8 @@ config USB_EHCI_BIG_ENDIAN_MMIO
16         depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
17                                     ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
18                                     PPC_MPC512x || CPU_CAVIUM_OCTEON || \
19 -                                   PMC_MSP || SPARC_LEON || MIPS_SEAD3)
20 +                                   PMC_MSP || SPARC_LEON || MIPS_SEAD3 || \
21 +                                   BCM63XX)
22         default y
23  
24  config USB_EHCI_BIG_ENDIAN_DESC
25 @@ -134,6 +135,14 @@ config XPS_USB_HCD_XILINX
26  config USB_FSL_MPH_DR_OF
27         tristate
28  
29 +config USB_EHCI_BCM63XX
30 +       bool "Support for Broadcom 63xx on-chip EHCI USB controller"
31 +       depends on USB_EHCI_HCD && BCM63XX
32 +       select USB_EHCI_BIG_ENDIAN_MMIO
33 +       ---help---
34 +         Enables support for the on-chip EHCI controller on
35 +         BCM6358 and later chips.
36 +
37  config USB_EHCI_FSL
38         bool "Support for Freescale PPC on-chip EHCI USB controller"
39         depends on USB_EHCI_HCD && FSL_SOC
40 --- /dev/null
41 +++ b/drivers/usb/host/ehci-bcm63xx.c
42 @@ -0,0 +1,186 @@
43 +/*
44 + * This file is subject to the terms and conditions of the GNU General Public
45 + * License.  See the file "COPYING" in the main directory of this archive
46 + * for more details.
47 + *
48 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
49 + */
50 +
51 +#include <linux/init.h>
52 +#include <linux/clk.h>
53 +#include <linux/platform_device.h>
54 +#include <bcm63xx_cpu.h>
55 +#include <bcm63xx_regs.h>
56 +#include <bcm63xx_io.h>
57 +
58 +static struct clk *usb_host_clock;
59 +
60 +static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
61 +{
62 +       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
63 +       int retval;
64 +
65 +       retval = ehci_halt(ehci);
66 +       if (retval)
67 +               return retval;
68 +
69 +       retval = ehci_init(hcd);
70 +       if (retval)
71 +               return retval;
72 +
73 +       ehci_reset(ehci);
74 +       ehci_port_power(ehci, 0);
75 +
76 +       return retval;
77 +}
78 +
79 +
80 +static const struct hc_driver ehci_bcm63xx_hc_driver = {
81 +       .description =          hcd_name,
82 +       .product_desc =         "BCM63XX integrated EHCI controller",
83 +       .hcd_priv_size =        sizeof(struct ehci_hcd),
84 +
85 +       .irq =                  ehci_irq,
86 +       .flags =                HCD_MEMORY | HCD_USB2,
87 +
88 +       .reset =                ehci_bcm63xx_setup,
89 +       .start =                ehci_run,
90 +       .stop =                 ehci_stop,
91 +       .shutdown =             ehci_shutdown,
92 +
93 +       .urb_enqueue =          ehci_urb_enqueue,
94 +       .urb_dequeue =          ehci_urb_dequeue,
95 +       .endpoint_disable =     ehci_endpoint_disable,
96 +
97 +       .get_frame_number =     ehci_get_frame,
98 +
99 +       .hub_status_data =      ehci_hub_status_data,
100 +       .hub_control =          ehci_hub_control,
101 +       .bus_suspend =          ehci_bus_suspend,
102 +       .bus_resume =           ehci_bus_resume,
103 +       .relinquish_port =      ehci_relinquish_port,
104 +       .port_handed_over =     ehci_port_handed_over,
105 +};
106 +
107 +static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
108 +{
109 +       struct resource *res_mem;
110 +       struct usb_hcd *hcd;
111 +       struct ehci_hcd *ehci;
112 +       struct clk *clk;
113 +       u32 reg;
114 +       int ret, irq;
115 +
116 +       res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
117 +       irq = platform_get_irq(pdev, 0);;
118 +       if (!res_mem || irq < 0)
119 +               return -ENODEV;
120 +
121 +       /* enable USB host clock */
122 +       clk = clk_get(&pdev->dev, "usbh");
123 +       if (IS_ERR(clk))
124 +               return -ENODEV;
125 +
126 +       clk_enable(clk);
127 +       usb_host_clock = clk;
128 +       msleep(100);
129 +
130 +       if (BCMCPU_IS_6358()) {
131 +               reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6358_REG);
132 +               reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
133 +               reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
134 +               bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6358_REG);
135 +
136 +               /*
137 +                * The magic value comes for the original vendor BSP
138 +                * and is needed for USB to work. Datasheet does not
139 +                * help, so the magic value is used as-is.
140 +                */
141 +               bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
142 +                               USBH_PRIV_TEST_6358_REG);
143 +
144 +       } else if (BCMCPU_IS_6368()) {
145 +
146 +               reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
147 +               reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
148 +               reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
149 +               bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6368_REG);
150 +
151 +               reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SETUP_6368_REG);
152 +               reg |= USBH_PRIV_SETUP_IOC_MASK;
153 +               bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SETUP_6368_REG);
154 +       }
155 +
156 +       hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
157 +       if (!hcd)
158 +               return -ENOMEM;
159 +       hcd->rsrc_start = res_mem->start;
160 +       hcd->rsrc_len = res_mem->end - res_mem->start + 1;
161 +
162 +       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
163 +               pr_debug("request_mem_region failed\n");
164 +               ret = -EBUSY;
165 +               goto out;
166 +       }
167 +
168 +       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
169 +       if (!hcd->regs) {
170 +               pr_debug("ioremap failed\n");
171 +               ret = -EIO;
172 +               goto out1;
173 +       }
174 +
175 +       ehci = hcd_to_ehci(hcd);
176 +       ehci->big_endian_mmio = 1;
177 +       ehci->big_endian_desc = 0;
178 +       ehci->caps = hcd->regs;
179 +       ehci->regs = hcd->regs +
180 +               HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
181 +       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
182 +       ehci->sbrn = 0x20;
183 +       ehci->ignore_oc = 1;
184 +
185 +       ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
186 +       if (ret)
187 +               goto out2;
188 +
189 +       platform_set_drvdata(pdev, hcd);
190 +       return 0;
191 +
192 +out2:
193 +       iounmap(hcd->regs);
194 +out1:
195 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
196 +out:
197 +       usb_put_hcd(hcd);
198 +       return ret;
199 +}
200 +
201 +static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
202 +{
203 +       struct usb_hcd *hcd;
204 +
205 +       hcd = platform_get_drvdata(pdev);
206 +       usb_remove_hcd(hcd);
207 +       iounmap(hcd->regs);
208 +       usb_put_hcd(hcd);
209 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
210 +       if (usb_host_clock) {
211 +               clk_disable(usb_host_clock);
212 +               clk_put(usb_host_clock);
213 +       }
214 +       platform_set_drvdata(pdev, NULL);
215 +       return 0;
216 +}
217 +
218 +static struct platform_driver ehci_hcd_bcm63xx_driver = {
219 +       .probe          = ehci_hcd_bcm63xx_drv_probe,
220 +       .remove         = __devexit_p(ehci_hcd_bcm63xx_drv_remove),
221 +       .shutdown       = usb_hcd_platform_shutdown,
222 +       .driver         = {
223 +               .name   = "bcm63xx_ehci",
224 +               .owner  = THIS_MODULE,
225 +       },
226 +};
227 +
228 +MODULE_ALIAS("platform:bcm63xx_ehci");
229 --- a/drivers/usb/host/ehci-hcd.c
230 +++ b/drivers/usb/host/ehci-hcd.c
231 @@ -1339,6 +1339,11 @@ MODULE_LICENSE ("GPL");
232  #define PLATFORM_DRIVER                ehci_platform_driver
233  #endif
234  
235 +#ifdef CONFIG_USB_EHCI_BCM63XX
236 +#include "ehci-bcm63xx.c"
237 +#define        PLATFORM_DRIVER         ehci_hcd_bcm63xx_driver
238 +#endif
239 +
240  #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
241      !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
242      !defined(XILINX_OF_PLATFORM_DRIVER)