Root/target/linux/brcm63xx/patches-3.3/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@@ -296,6 +296,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 || ARCH_OMAP2)
32--- /dev/null
33+++ b/drivers/usb/host/ohci-bcm63xx.c
34@@ -0,0 +1,175 @@
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+ err("can't start %s", hcd->self.bus_name);
68+ ohci_stop(hcd);
69+ return ret;
70+ }
71+ return 0;
72+}
73+
74+static const struct hc_driver ohci_bcm63xx_hc_driver = {
75+ .description = hcd_name,
76+ .product_desc = "BCM63XX integrated OHCI controller",
77+ .hcd_priv_size = sizeof(struct ohci_hcd),
78+
79+ .irq = ohci_irq,
80+ .flags = HCD_USB11 | HCD_MEMORY,
81+ .start = ohci_bcm63xx_start,
82+ .stop = ohci_stop,
83+ .shutdown = ohci_shutdown,
84+ .urb_enqueue = ohci_urb_enqueue,
85+ .urb_dequeue = ohci_urb_dequeue,
86+ .endpoint_disable = ohci_endpoint_disable,
87+ .get_frame_number = ohci_get_frame,
88+ .hub_status_data = ohci_hub_status_data,
89+ .hub_control = ohci_hub_control,
90+ .start_port_reset = ohci_start_port_reset,
91+};
92+
93+static int __devinit ohci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
94+{
95+ struct resource *res_mem;
96+ struct usb_hcd *hcd;
97+ struct ohci_hcd *ohci;
98+ struct clk *clk;
99+ u32 reg;
100+ int ret, irq;
101+
102+ res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
103+ irq = platform_get_irq(pdev, 0);
104+ if (!res_mem || irq < 0)
105+ return -ENODEV;
106+
107+ /* enable USB host clock */
108+ clk = clk_get(&pdev->dev, "usbh");
109+ if (IS_ERR(clk))
110+ return -ENODEV;
111+
112+ clk_enable(clk);
113+ usb_host_clock = clk;
114+ msleep(100);
115+
116+ if (BCMCPU_IS_6348())
117+ bcm_rset_writel(RSET_OHCI_PRIV, 0, OHCI_PRIV_REG);
118+ else if (BCMCPU_IS_6358()) {
119+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6358_REG);
120+ reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
121+ reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
122+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6358_REG);
123+ /*
124+ * The magic value comes for the original vendor BSP
125+ * and is needed for USB to work. Datasheet does not
126+ * help, so the magic value is used as-is.
127+ */
128+ bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020,
129+ USBH_PRIV_TEST_6358_REG);
130+
131+ } else if (BCMCPU_IS_6368()) {
132+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_6368_REG);
133+ reg &= ~USBH_PRIV_SWAP_OHCI_ENDN_MASK;
134+ reg |= USBH_PRIV_SWAP_OHCI_DATA_MASK;
135+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_6368_REG);
136+
137+ reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SETUP_6368_REG);
138+ reg |= USBH_PRIV_SETUP_IOC_MASK;
139+ bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SETUP_6368_REG);
140+ }
141+
142+ hcd = usb_create_hcd(&ohci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
143+ if (!hcd)
144+ return -ENOMEM;
145+ hcd->rsrc_start = res_mem->start;
146+ hcd->rsrc_len = res_mem->end - res_mem->start + 1;
147+
148+ if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
149+ pr_debug("request_mem_region failed\n");
150+ ret = -EBUSY;
151+ goto out;
152+ }
153+
154+ hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
155+ if (!hcd->regs) {
156+ pr_debug("ioremap failed\n");
157+ ret = -EIO;
158+ goto out1;
159+ }
160+
161+ ohci = hcd_to_ohci(hcd);
162+ ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC |
163+ OHCI_QUIRK_FRAME_NO;
164+ ohci_hcd_init(ohci);
165+
166+ ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
167+ if (ret)
168+ goto out2;
169+
170+ platform_set_drvdata(pdev, hcd);
171+ return 0;
172+
173+out2:
174+ iounmap(hcd->regs);
175+out1:
176+ release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
177+out:
178+ usb_put_hcd(hcd);
179+ return ret;
180+}
181+
182+static int __devexit ohci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
183+{
184+ struct usb_hcd *hcd;
185+
186+ hcd = platform_get_drvdata(pdev);
187+ usb_remove_hcd(hcd);
188+ iounmap(hcd->regs);
189+ usb_put_hcd(hcd);
190+ release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
191+ if (usb_host_clock) {
192+ clk_disable(usb_host_clock);
193+ clk_put(usb_host_clock);
194+ }
195+ platform_set_drvdata(pdev, NULL);
196+ return 0;
197+}
198+
199+static struct platform_driver ohci_hcd_bcm63xx_driver = {
200+ .probe = ohci_hcd_bcm63xx_drv_probe,
201+ .remove = __devexit_p(ohci_hcd_bcm63xx_drv_remove),
202+ .shutdown = usb_hcd_platform_shutdown,
203+ .driver = {
204+ .name = "bcm63xx_ohci",
205+ .owner = THIS_MODULE,
206+ },
207+};
208+
209+MODULE_ALIAS("platform:bcm63xx_ohci");
210--- a/drivers/usb/host/ohci-hcd.c
211+++ b/drivers/usb/host/ohci-hcd.c
212@@ -1121,6 +1121,11 @@ MODULE_LICENSE ("GPL");
213 #define PLATFORM_DRIVER ohci_xls_driver
214 #endif
215 
216+#ifdef CONFIG_USB_OHCI_BCM63XX
217+#include "ohci-bcm63xx.c"
218+#define PLATFORM_DRIVER ohci_hcd_bcm63xx_driver
219+#endif
220+
221 #if !defined(PCI_DRIVER) && \
222     !defined(PLATFORM_DRIVER) && \
223     !defined(OMAP1_PLATFORM_DRIVER) && \
224--- a/drivers/usb/host/ohci.h
225+++ b/drivers/usb/host/ohci.h
226@@ -652,7 +652,7 @@ static inline u32 hc32_to_cpup (const st
227  * some big-endian SOC implementations. Same thing happens with PSW access.
228  */
229 
230-#ifdef CONFIG_PPC_MPC52xx
231+#if defined(CONFIG_PPC_MPC52xx) || defined(CONFIG_BCM63XX)
232 #define big_endian_frame_no_quirk(ohci) (ohci->flags & OHCI_QUIRK_FRAME_NO)
233 #else
234 #define big_endian_frame_no_quirk(ohci) 0
235

Archive Download this file



interactive