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