brcm63xx: add preliminary support for 3.13
[openwrt.git] / target / linux / brcm63xx / patches-3.13 / 105-MIPS-BCM63XX-add-support-for-the-on-chip-OHCI-contro.patch
1 From 30d22baef255c99a12c4858ce4ab0d45f0d8c9ae Mon Sep 17 00:00:00 2001
2 From: Florian Fainelli <florian@openwrt.org>
3 Date: Mon, 28 Jan 2013 20:06:24 +0100
4 Subject: [PATCH 06/11] MIPS: BCM63XX: add support for the on-chip OHCI
5  controller
6
7 Broadcom BCM63XX SoCs include an on-chip OHCI controller which can be
8 driven by the ohci-platform generic driver by using specific power
9 on/off/suspend callback to manage clocks and hardware specific
10 configuration.
11
12 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
13 Signed-off-by: Florian Fainelli <florian@openwrt.org>
14 ---
15  arch/mips/bcm63xx/Makefile                         |    2 +-
16  arch/mips/bcm63xx/dev-usb-ohci.c                   |   94 ++++++++++++++++++++
17  .../asm/mach-bcm63xx/bcm63xx_dev_usb_ohci.h        |    6 ++
18  3 files changed, 101 insertions(+), 1 deletion(-)
19  create mode 100644 arch/mips/bcm63xx/dev-usb-ohci.c
20  create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
21
22 --- a/arch/mips/bcm63xx/Makefile
23 +++ b/arch/mips/bcm63xx/Makefile
24 @@ -1,7 +1,7 @@
25  obj-y          += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o reset.o \
26                    setup.o timer.o dev-dsp.o dev-enet.o dev-flash.o \
27                    dev-pcmcia.o dev-rng.o dev-spi.o dev-hsspi.o dev-uart.o \
28 -                  dev-wdt.o dev-usb-usbd.o usb-common.o
29 +                  dev-wdt.o dev-usb-ohci.o dev-usb-usbd.o usb-common.o
30  obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
31  
32  obj-y          += boards/
33 --- /dev/null
34 +++ b/arch/mips/bcm63xx/dev-usb-ohci.c
35 @@ -0,0 +1,94 @@
36 +/*
37 + * This file is subject to the terms and conditions of the GNU General Public
38 + * License.  See the file "COPYING" in the main directory of this archive
39 + * for more details.
40 + *
41 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
42 + * Copyright (C) 2013 Florian Fainelli <florian@openwrt.org>
43 + */
44 +
45 +#include <linux/init.h>
46 +#include <linux/kernel.h>
47 +#include <linux/platform_device.h>
48 +#include <linux/usb/ohci_pdriver.h>
49 +#include <linux/dma-mapping.h>
50 +#include <linux/clk.h>
51 +#include <linux/delay.h>
52 +
53 +#include <bcm63xx_cpu.h>
54 +#include <bcm63xx_regs.h>
55 +#include <bcm63xx_io.h>
56 +#include <bcm63xx_usb_priv.h>
57 +#include <bcm63xx_dev_usb_ohci.h>
58 +
59 +static struct resource ohci_resources[] = {
60 +       {
61 +               .start          = -1, /* filled at runtime */
62 +               .end            = -1, /* filled at runtime */
63 +               .flags          = IORESOURCE_MEM,
64 +       },
65 +       {
66 +               .start          = -1, /* filled at runtime */
67 +               .flags          = IORESOURCE_IRQ,
68 +       },
69 +};
70 +
71 +static u64 ohci_dmamask = DMA_BIT_MASK(32);
72 +
73 +static struct clk *usb_host_clock;
74 +
75 +static int bcm63xx_ohci_power_on(struct platform_device *pdev)
76 +{
77 +       usb_host_clock = clk_get(&pdev->dev, "usbh");
78 +       if (IS_ERR_OR_NULL(usb_host_clock))
79 +               return -ENODEV;
80 +
81 +       clk_prepare_enable(usb_host_clock);
82 +
83 +       bcm63xx_usb_priv_ohci_cfg_set();
84 +
85 +       return 0;
86 +}
87 +
88 +static void bcm63xx_ohci_power_off(struct platform_device *pdev)
89 +{
90 +       if (!IS_ERR_OR_NULL(usb_host_clock)) {
91 +               clk_disable_unprepare(usb_host_clock);
92 +               clk_put(usb_host_clock);
93 +       }
94 +}
95 +
96 +static struct usb_ohci_pdata bcm63xx_ohci_pdata = {
97 +       .big_endian_desc        = 1,
98 +       .big_endian_mmio        = 1,
99 +       .no_big_frame_no        = 1,
100 +       .num_ports              = 1,
101 +       .power_on               = bcm63xx_ohci_power_on,
102 +       .power_off              = bcm63xx_ohci_power_off,
103 +       .power_suspend          = bcm63xx_ohci_power_off,
104 +};
105 +
106 +static struct platform_device bcm63xx_ohci_device = {
107 +       .name           = "ohci-platform",
108 +       .id             = -1,
109 +       .num_resources  = ARRAY_SIZE(ohci_resources),
110 +       .resource       = ohci_resources,
111 +       .dev            = {
112 +               .platform_data          = &bcm63xx_ohci_pdata,
113 +               .dma_mask               = &ohci_dmamask,
114 +               .coherent_dma_mask      = DMA_BIT_MASK(32),
115 +       },
116 +};
117 +
118 +int __init bcm63xx_ohci_register(void)
119 +{
120 +       if (BCMCPU_IS_6345() || BCMCPU_IS_6338())
121 +               return -ENODEV;
122 +
123 +       ohci_resources[0].start = bcm63xx_regset_address(RSET_OHCI0);
124 +       ohci_resources[0].end = ohci_resources[0].start;
125 +       ohci_resources[0].end += RSET_OHCI_SIZE - 1;
126 +       ohci_resources[1].start = bcm63xx_get_irq_number(IRQ_OHCI0);
127 +
128 +       return platform_device_register(&bcm63xx_ohci_device);
129 +}
130 --- /dev/null
131 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_usb_ohci.h
132 @@ -0,0 +1,6 @@
133 +#ifndef BCM63XX_DEV_USB_OHCI_H_
134 +#define BCM63XX_DEV_USB_OHCI_H_
135 +
136 +int bcm63xx_ohci_register(void);
137 +
138 +#endif /* BCM63XX_DEV_USB_OHCI_H_ */