add support for 2.6.32, dropped the SPI patch for now
[openwrt/staging/yousong.git] / target / linux / brcm63xx / patches-2.6.32 / 010-add_bcm63xx_ohci_controller.patch
1 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
2 ---
3 drivers/usb/host/ohci-bcm63xx.c | 166 +++++++++++++++++++++++++++++++++++++++
4 drivers/usb/host/ohci-hcd.c | 5 +
5 drivers/usb/host/ohci.h | 2 +-
6 3 files changed, 172 insertions(+), 1 deletions(-)
7 create mode 100644 drivers/usb/host/ohci-bcm63xx.c
8
9 diff --git a/drivers/usb/host/ohci-bcm63xx.c b/drivers/usb/host/ohci-bcm63xx.c
10 new file mode 100644
11 index 0000000..c9bccec
12 --- /dev/null
13 +++ b/drivers/usb/host/ohci-bcm63xx.c
14 @@ -0,0 +1,166 @@
15 +/*
16 + * This file is subject to the terms and conditions of the GNU General Public
17 + * License. See the file "COPYING" in the main directory of this archive
18 + * for more details.
19 + *
20 + * Copyright (C) 2010 Maxime Bizon <mbizon@freebox.fr>
21 + */
22 +
23 +#include <linux/init.h>
24 +#include <linux/clk.h>
25 +#include <linux/platform_device.h>
26 +#include <bcm63xx_cpu.h>
27 +#include <bcm63xx_regs.h>
28 +#include <bcm63xx_io.h>
29 +
30 +static struct clk *usb_host_clock;
31 +
32 +static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
33 +{
34 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
35 + int ret;
36 +
37 + /*
38 + * port 2 can be shared with USB slave, but all boards seem to
39 + * have only one host port populated, so we can hardcode it
40 + */
41 + ohci->num_ports = 1;
42 +
43 + ret = ohci_init(ohci);
44 + if (ret < 0)
45 + return ret;
46 +
47 + ret = ohci_run(ohci);
48 + if (ret < 0) {
49 + err("can't start %s", hcd->self.bus_name);
50 + ohci_stop(hcd);
51 + return ret;
52 + }
53 + return 0;
54 +}
55 +
56 +static const struct hc_driver ohci_bcm63xx_hc_driver = {
57 + .description = hcd_name,
58 + .product_desc = "BCM63XX integrated OHCI controller",
59 + .hcd_priv_size = sizeof(struct ohci_hcd),
60 +
61 + .irq = ohci_irq,
62 + .flags = HCD_USB11 | HCD_MEMORY,
63 + .start = ohci_bcm63xx_start,
64 + .stop = ohci_stop,
65 + .shutdown = ohci_shutdown,
66 + .urb_enqueue = ohci_urb_enqueue,
67 + .urb_dequeue = ohci_urb_dequeue,
68 + .endpoint_disable = ohci_endpoint_disable,
69 + .get_frame_number = ohci_get_frame,
70 + .hub_status_data = ohci_hub_status_data,
71 + .hub_control = ohci_hub_control,
72 + .start_port_reset = ohci_start_port_reset,
73 +};
74 +
75 +static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
76 +{
77 + struct resource *res_mem;
78 + struct usb_hcd *hcd;
79 + struct ohci_hcd *ohci;
80 + u32 reg;
81 + int ret, irq;
82 +
83 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
84 + irq = platform_get_irq(pdev, 0);
85 + if (!res_mem || irq < 0)
86 + return -ENODEV;
87 +
88 + if (BCMCPU_IS_6348()) {
89 + struct clk *clk;
90 + /* enable USB host clock */
91 + clk = clk_get(&pdev->dev, "usbh");
92 + if (IS_ERR(clk))
93 + return -ENODEV;
94 +
95 + clk_enable(clk);
96 + usb_host_clock = clk;
97 + bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
98 +
99 + } else if (BCMCPU_IS_6358()) {
100 + reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
101 + reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
102 + reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
103 + bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);
104 + /*
105 + * The magic value comes for the original vendor BSP
106 + * and is needed for USB to work. Datasheet does not
107 + * help, so the magic value is used as-is.
108 + */
109 + bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);
110 + } else
111 + return 0;
112 +
113 + hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
114 + if (!hcd)
115 + return -ENOMEM;
116 + hcd->rsrc_start = res_mem->start;
117 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
118 +
119 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
120 + pr_debug("request_mem_region failed\n");
121 + ret = -EBUSY;
122 + goto out;
123 + }
124 +
125 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
126 + if (!hcd->regs) {
127 + pr_debug("ioremap failed\n");
128 + ret = -EIO;
129 + goto out1;
130 + }
131 +
132 + ohci = hcd_to_ohci(hcd);
133 + ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
134 + OHCI_QUIRK_FRAME_NO;
135 + ohci_hcd_init(ohci);
136 +
137 + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
138 + if (ret)
139 + goto out2;
140 +
141 + platform_set_drvdata(pdev, hcd);
142 + return 0;
143 +
144 +out2:
145 + iounmap(hcd->regs);
146 +out1:
147 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
148 +out:
149 + usb_put_hcd(hcd);
150 + return ret;
151 +}
152 +
153 +static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
154 +{
155 + struct usb_hcd *hcd;
156 +
157 + hcd = platform_get_drvdata(pdev);
158 + usb_remove_hcd(hcd);
159 + iounmap(hcd->regs);
160 + usb_put_hcd(hcd);
161 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
162 + if (usb_host_clock) {
163 + clk_disable(usb_host_clock);
164 + clk_put(usb_host_clock);
165 + }
166 + platform_set_drvdata(pdev, NULL);
167 + return 0;
168 +}
169 +
170 +static struct platform_driver ohci_hcd_bcm63xx_driver = {
171 + .probe = ohci_hcd_bcm63xx_drv_probe,
172 + .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
173 + .shutdown = usb_hcd_platform_shutdown,
174 + .driver = {
175 + .name = "bcm63xx_ohci",
176 + .owner = THIS_MODULE,
177 + },
178 +};
179 +
180 +MODULE_ALIAS("platform:bcm63xx_ohci");
181 diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
182 index 24eb747..1c82a60 100644
183 --- a/drivers/usb/host/ohci-hcd.c
184 +++ b/drivers/usb/host/ohci-hcd.c
185 @@ -1051,6 +1051,11 @@ MODULE_LICENSE ("GPL");
186 #define PLATFORM_DRIVER usb_hcd_pnx4008_driver
187 #endif
188
189 +#ifdef CONFIG_BCM63XX
190 +#include "ohci-bcm63xx.c"
191 +#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
192 +#endif
193 +
194 #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
195 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
196 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
197 diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
198 index 5bf15fe..3c54d3e 100644
199 --- a/drivers/usb/host/ohci.h
200 +++ b/drivers/usb/host/ohci.h
201 @@ -655,7 +655,7 @@ static inline u32 hc32_to_cpup (const struct ohci_hcd *ohci, const __hc32 *x)
202 * some big-endian SOC implementations. Same thing happens with PSW access.
203 */
204
205 -#ifdef CONFIG_PPC_MPC52xx
206 +#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
207 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
208 #else
209 #define big_endian_frame_no_quirk(ohci) 0
210 --
211 1.6.3.3
212
213