Root/target/linux/brcm63xx/patches-3.6/400-ohci-add-driver-for-bcm63xx-integrated-controller.patch

1From 7b510c5754d3c46e1287803f51e8ecb177414438 Mon Sep 17 00:00:00 2001
2From: Maxime Bizon <mbizon@freebox.fr>
3Date: Fri, 10 Jun 2011 19:14:30 +0200
4Subject: [PATCH 23/63] ohci: add driver for bcm63xx integrated controller.
5
6---
7 drivers/usb/host/Kconfig | 9 ++
8 drivers/usb/host/ohci-bcm63xx.c | 175 +++++++++++++++++++++++++++++++++++++++
9 drivers/usb/host/ohci-hcd.c | 5 +
10 drivers/usb/host/ohci.h | 2 +-
11 4 files changed, 190 insertions(+), 1 deletions(-)
12 create mode 100644 drivers/usb/host/ohci-bcm63xx.c
13
14--- a/drivers/usb/host/Kconfig
15+++ b/drivers/usb/host/Kconfig
16@@ -306,6 +306,15 @@ config USB_OHCI_HCD
17       To compile this driver as a module, choose M here: the
18       module will be called ohci-hcd.
19 
20+config USB_OHCI_BCM63XX
21+ bool "Support for Broadcom 63xx on-chip OHCI USB controller"
22+ depends on USB_OHCI_HCD && BCM63XX
23+ select USB_OHCI_BIG_ENDIAN_DESC
24+ select USB_OHCI_BIG_ENDIAN_MMIO
25+ ---help---
26+ Enables support for the on-chip OHCI controller on
27+ BCM63XX chips.
28+
29 config USB_OHCI_HCD_OMAP1
30     bool "OHCI support for OMAP1/2 chips"
31     depends on USB_OHCI_HCD && ARCH_OMAP1
32--- /dev/null
33+++ b/drivers/usb/host/ohci-bcm63xx.c
34@@ -0,0 +1,176 @@
35+/*
36+ * This file is subject to the terms and conditions of the GNU General Public
37+ * License. See the file "COPYING" in the main directory of this archive
38+ * for more details.
39+ *
40+ * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
41+ */
42+
43+#include <linux/init.h>
44+#include <linux/clk.h>
45+#include <linux/platform_device.h>
46+#include <bcm63xx_cpu.h>
47+#include <bcm63xx_regs.h>
48+#include <bcm63xx_io.h>
49+
50+static struct clk *usb_host_clock;
51+
52+static int __devinit ohci_bcm63xx_start(struct usb_hcd *hcd)
53+{
54+ struct ohci_hcd *ohci = hcd_to_ohci(hcd);
55+ int ret;
56+
57+ ohci->num_ports = 1;
58+
59+ ret = ohci_init(ohci);
60+ if (ret < 0)
61+ return ret;
62+
63+ /* FIXME: autodetected port 2 is shared with USB slave */
64+
65+ ret = ohci_run(ohci);
66+ if (ret < 0) {
67+ dev_err(hcd->self.controller, "can't start %s\n",
68+ hcd->self.bus_name);
69+ ohci_stop(hcd);
70+ return ret;
71+ }
72+ return 0;
73+}
74+
75+static const struct hc_driver ohci_bcm63xx_hc_driver = {
76+ .description = hcd_name,
77+ .product_desc = "BCM63XX integrated OHCI controller",
78+ .hcd_priv_size = sizeof(struct ohci_hcd),
79+
80+ .irq = ohci_irq,
81+ .flags = HCD_USB11 | HCD_MEMORY,
82+ .start = ohci_bcm63xx_start,
83+ .stop = ohci_stop,
84+ .shutdown = ohci_shutdown,
85+ .urb_enqueue = ohci_urb_enqueue,
86+ .urb_dequeue = ohci_urb_dequeue,
87+ .endpoint_disable = ohci_endpoint_disable,
88+ .get_frame_number = ohci_get_frame,
89+ .hub_status_data = ohci_hub_status_data,
90+ .hub_control = ohci_hub_control,
91+ .start_port_reset = ohci_start_port_reset,
92+};
93+
94+static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
95+{
96+ struct resource *res_mem;
97+ struct usb_hcd *hcd;
98+ struct ohci_hcd *ohci;
99+ struct clk *clk;
100+ u32 reg;
101+ int ret, irq;
102+
103+ res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104+ irq = platform_get_irq(pdev, 0);
105+ if (!res_mem || irq < 0)
106+ return -ENODEV;
107+
108+ /* enable USB host clock */
109+ clk = clk_get(&pdev->dev, "usbh");
110+ if (IS_ERR(clk))
111+ return -ENODEV;
112+
113+ clk_enable(clk);
114+ usb_host_clock = clk;
115+ msleep(100);
116+
117+ if (BCMCPU_IS_6348())
118+ bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
119+ else if (BCMCPU_IS_6358()) {
120+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6358_REG);
121+ reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
122+ reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
123+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6358_REG);
124+ /*
125+ * The magic value comes for the original vendor BSP
126+ * and is needed for USB to work. Datasheet does not
127+ * help, so the magic value is used as-is.
128+ */
129+ bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
130+ USBH_PRIV_TEST_6358_REG);
131+
132+ } else if (BCMCPU_IS_6368()) {
133+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
134+ reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
135+ reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
136+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6368_REG);
137+
138+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SETUP_6368_REG);
139+ reg |= USBH_PRIV_SETUP_IOC_MASK;
140+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SETUP_6368_REG);
141+ }
142+
143+ hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
144+ if (!hcd)
145+ return -ENOMEM;
146+ hcd->rsrc_start = res_mem->start;
147+ hcd->rsrc_len = res_mem->end - res_mem->start + 1;
148+
149+ if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
150+ pr_debug("request_mem_region failed\n");
151+ ret = -EBUSY;
152+ goto out;
153+ }
154+
155+ hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
156+ if (!hcd->regs) {
157+ pr_debug("ioremap failed\n");
158+ ret = -EIO;
159+ goto out1;
160+ }
161+
162+ ohci = hcd_to_ohci(hcd);
163+ ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
164+ OHCI_QUIRK_FRAME_NO;
165+ ohci_hcd_init(ohci);
166+
167+ ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
168+ if (ret)
169+ goto out2;
170+
171+ platform_set_drvdata(pdev, hcd);
172+ return 0;
173+
174+out2:
175+ iounmap(hcd->regs);
176+out1:
177+ release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
178+out:
179+ usb_put_hcd(hcd);
180+ return ret;
181+}
182+
183+static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
184+{
185+ struct usb_hcd *hcd;
186+
187+ hcd = platform_get_drvdata(pdev);
188+ usb_remove_hcd(hcd);
189+ iounmap(hcd->regs);
190+ usb_put_hcd(hcd);
191+ release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
192+ if (usb_host_clock) {
193+ clk_disable(usb_host_clock);
194+ clk_put(usb_host_clock);
195+ }
196+ platform_set_drvdata(pdev, NULL);
197+ return 0;
198+}
199+
200+static struct platform_driver ohci_hcd_bcm63xx_driver = {
201+ .probe = ohci_hcd_bcm63xx_drv_probe,
202+ .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
203+ .shutdown = usb_hcd_platform_shutdown,
204+ .driver = {
205+ .name = "bcm63xx_ohci",
206+ .owner = THIS_MODULE,
207+ },
208+};
209+
210+MODULE_ALIAS("platform:bcm63xx_ohci");
211--- a/drivers/usb/host/ohci-hcd.c
212+++ b/drivers/usb/host/ohci-hcd.c
213@@ -1120,6 +1120,11 @@ MODULE_LICENSE ("GPL");
214 #define PLATFORM_DRIVER ohci_platform_driver
215 #endif
216 
217+#ifdef CONFIG_USB_OHCI_BCM63XX
218+#include "ohci-bcm63xx.c"
219+#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
220+#endif
221+
222 #if !defined(PCI_DRIVER) && \
223     !defined(PLATFORM_DRIVER) && \
224     !defined(OMAP1_PLATFORM_DRIVER) && \
225--- a/drivers/usb/host/ohci.h
226+++ b/drivers/usb/host/ohci.h
227@@ -647,7 +647,7 @@ static inline u32 hc32_to_cpup (const st
228  * some big-endian SOC implementations. Same thing happens with PSW access.
229  */
230 
231-#ifdef CONFIG_PPC_MPC52xx
232+#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
233 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
234 #else
235 #define big_endian_frame_no_quirk(ohci) 0
236

Archive Download this file



interactive