1 From 0a1a5fd8aab864e7b531ab88fd317ff7278d884d Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Mon, 6 Jun 2011 00:07:32 +0200
4 Subject: [PATCH 05/14] bcma: add mips driver
6 This adds a mips driver to bcma. This is only found on embedded
7 devices. For now the driver just initializes the irqs used on this
10 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12 drivers/bcma/Kconfig | 11 ++-
13 drivers/bcma/Makefile | 1 +
14 drivers/bcma/driver_mips.c | 234 +++++++++++++++++++++++++++++++++
15 drivers/bcma/main.c | 19 +++
16 include/linux/bcma/bcma.h | 2 +
17 include/linux/bcma/bcma_driver_mips.h | 49 +++++++
18 6 files changed, 315 insertions(+), 1 deletions(-)
19 create mode 100644 drivers/bcma/driver_mips.c
20 create mode 100644 include/linux/bcma/bcma_driver_mips.h
22 --- a/drivers/bcma/Kconfig
23 +++ b/drivers/bcma/Kconfig
24 @@ -29,9 +29,18 @@ config BCMA_HOST_PCI
28 - depends on BCMA && MIPS
29 + depends on BCMA_DRIVER_MIPS
32 +config BCMA_DRIVER_MIPS
33 + bool "BCMA Broadcom MIPS core driver"
34 + depends on BCMA && MIPS
36 + Driver for the Broadcom MIPS core attached to Broadcom specific
37 + Advanced Microcontroller Bus.
44 --- a/drivers/bcma/Makefile
45 +++ b/drivers/bcma/Makefile
47 bcma-y += main.o scan.o core.o sprom.o
48 bcma-y += driver_chipcommon.o driver_chipcommon_pmu.o
49 bcma-y += driver_pci.o
50 +bcma-$(CONFIG_BCMA_DRIVER_MIPS) += driver_mips.o
51 bcma-$(CONFIG_BCMA_HOST_PCI) += host_pci.o
52 bcma-$(CONFIG_BCMA_HOST_SOC) += host_soc.o
53 obj-$(CONFIG_BCMA) += bcma.o
55 +++ b/drivers/bcma/driver_mips.c
58 + * Broadcom specific AMBA
59 + * Broadcom MIPS32 74K core driver
61 + * Copyright 2009, Broadcom Corporation
62 + * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
63 + * Copyright 2010, Bernhard Loos <bernhardloos@googlemail.com>
64 + * Copyright 2011, Hauke Mehrtens <hauke@hauke-m.de>
66 + * Licensed under the GNU/GPL. See COPYING for details.
69 +#include "bcma_private.h"
71 +#include <linux/bcma/bcma.h>
73 +#include <linux/serial.h>
74 +#include <linux/serial_core.h>
75 +#include <linux/serial_reg.h>
76 +#include <linux/time.h>
78 +/* The 47162a0 hangs when reading its registers */
79 +static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
81 + return dev->bus->chipinfo.id == 47162 && dev->bus->chipinfo.rev == 0 &&
82 + dev->id.id == BCMA_CORE_MIPS_74K;
85 +static inline u32 mips_read32(struct bcma_drv_mips *mcore,
88 + return bcma_read32(mcore->core, offset);
91 +static inline void mips_write32(struct bcma_drv_mips *mcore,
95 + bcma_write32(mcore->core, offset, value);
98 +static const u32 ipsflag_irq_mask[] = {
100 + BCMA_MIPS_IPSFLAG_IRQ1,
101 + BCMA_MIPS_IPSFLAG_IRQ2,
102 + BCMA_MIPS_IPSFLAG_IRQ3,
103 + BCMA_MIPS_IPSFLAG_IRQ4,
106 +static const u32 ipsflag_irq_shift[] = {
108 + BCMA_MIPS_IPSFLAG_IRQ1_SHIFT,
109 + BCMA_MIPS_IPSFLAG_IRQ2_SHIFT,
110 + BCMA_MIPS_IPSFLAG_IRQ3_SHIFT,
111 + BCMA_MIPS_IPSFLAG_IRQ4_SHIFT,
114 +static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
118 + if (bcma_core_mips_bcm47162a0_quirk(dev))
119 + return dev->core_index;
120 + flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
122 + return flag & 0x1F;
126 +/* Get the MIPS IRQ assignment for a specified device.
127 + * If unassigned, 0 is returned.
128 + * If disabled, 5 is returned.
130 +unsigned int bcma_core_mips_irq(struct bcma_device *dev)
132 + struct bcma_device *mdev = dev->bus->drv_mips.core;
136 + irqflag = bcma_core_mips_irqflag(dev);
138 + for (irq = 1; irq <= 4; irq++)
139 + if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
145 +EXPORT_SYMBOL(bcma_core_mips_irq);
147 +static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
149 + unsigned int oldirq = bcma_core_mips_irq(dev);
150 + struct bcma_bus *bus = dev->bus;
151 + struct bcma_device *mdev = bus->drv_mips.core;
154 + irqflag = bcma_core_mips_irqflag(dev);
155 + BUG_ON(oldirq == 6);
157 + dev->irq = irq + 2;
159 + /* clear the old irq */
161 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
162 + bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
165 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq), 0);
167 + /* assign the new one */
169 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
170 + bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
173 + u32 oldirqflag = bcma_read32(mdev,
174 + BCMA_MIPS_MIPS74K_INTMASK(irq));
176 + struct bcma_device *core;
178 + /* backplane irq line is in use, find out who uses
179 + * it and set user to irq 0
181 + list_for_each_entry_reverse(core, &bus->cores, list) {
182 + if ((1 << bcma_core_mips_irqflag(core)) ==
184 + bcma_core_mips_set_irq(core, 0);
189 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
193 + pr_info("set_irq: core 0x%04x, irq %d => %d\n",
194 + dev->id.id, oldirq + 2, irq + 2);
197 +static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
200 + static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
201 + printk(KERN_INFO KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
202 + for (i = 0; i <= 6; i++)
203 + printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
207 +static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
209 + struct bcma_device *core;
211 + list_for_each_entry_reverse(core, &bus->cores, list) {
212 + bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
216 +static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
218 + struct bcma_bus *bus = mcore->core->bus;
220 + mcore->flash_buswidth = 2;
221 + if (bus->drv_cc.core) {
222 + mcore->flash_window = 0x1c000000;
223 + mcore->flash_window_size = 0x02000000;
224 + switch (bus->drv_cc.capabilities & BCMA_CC_CAP_FLASHT) {
225 + case BCMA_CC_FLASHT_STSER:
226 + case BCMA_CC_FLASHT_ATSER:
227 + pr_err("Serial flash not supported.\n");
229 + case BCMA_CC_FLASHT_PARA:
230 + if ((bcma_read32(bus->drv_cc.core, BCMA_CC_FLASH_CFG) &
231 + BCMA_CC_OTPS) == 0)
232 + mcore->flash_buswidth = 1;
236 + mcore->flash_window = 0x1fc00000;
237 + mcore->flash_window_size = 0x00400000;
241 +void bcma_core_mips_init(struct bcma_drv_mips *mcore)
243 + struct bcma_bus *bus;
244 + struct bcma_device *core;
245 + bus = mcore->core->bus;
247 + pr_info("Initializing MIPS core...\n");
249 + if (!mcore->setup_done)
250 + mcore->assigned_irqs = 1;
252 + /* Assign IRQs to all cores on the bus */
253 + list_for_each_entry_reverse(core, &bus->cores, list) {
258 + mips_irq = bcma_core_mips_irq(core);
262 + core->irq = mips_irq + 2;
265 + switch (core->id.id) {
266 + case BCMA_CORE_PCI:
267 + case BCMA_CORE_PCIE:
268 + case BCMA_CORE_ETHERNET:
269 + case BCMA_CORE_ETHERNET_GBIT:
270 + case BCMA_CORE_MAC_GBIT:
271 + case BCMA_CORE_80211:
272 + case BCMA_CORE_USB20_HOST:
273 + /* These devices get their own IRQ line if available,
274 + * the rest goes on IRQ0
276 + if (mcore->assigned_irqs <= 4)
277 + bcma_core_mips_set_irq(core,
278 + mcore->assigned_irqs++);
282 + pr_info("IRQ reconfiguration done\n");
283 + bcma_core_mips_dump_irq(bus);
285 + if (mcore->setup_done)
288 + bcma_core_mips_flash_detect(mcore);
289 + mcore->setup_done = true;
291 --- a/drivers/bcma/main.c
292 +++ b/drivers/bcma/main.c
293 @@ -80,6 +80,7 @@ static int bcma_register_cores(struct bc
294 case BCMA_CORE_CHIPCOMMON:
297 + case BCMA_CORE_MIPS_74K:
301 @@ -141,6 +142,15 @@ int bcma_bus_register(struct bcma_bus *b
302 bcma_core_chipcommon_init(&bus->drv_cc);
305 +#ifdef CONFIG_BCMA_DRIVER_MIPS
306 + /* Init MIPS core */
307 + core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
309 + bus->drv_mips.core = core;
310 + bcma_core_mips_init(&bus->drv_mips);
315 core = bcma_find_core(bus, BCMA_CORE_PCIE);
317 @@ -208,6 +218,15 @@ int __init bcma_bus_early_register(struc
318 bcma_core_chipcommon_init(&bus->drv_cc);
321 +#ifdef CONFIG_BCMA_DRIVER_MIPS
322 + /* Init MIPS core */
323 + core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
325 + bus->drv_mips.core = core;
326 + bcma_core_mips_init(&bus->drv_mips);
330 pr_info("Early bus registered\n");
333 --- a/include/linux/bcma/bcma.h
334 +++ b/include/linux/bcma/bcma.h
337 #include <linux/bcma/bcma_driver_chipcommon.h>
338 #include <linux/bcma/bcma_driver_pci.h>
339 +#include <linux/bcma/bcma_driver_mips.h>
340 #include <linux/ssb/ssb.h> /* SPROM sharing */
342 #include "bcma_regs.h"
343 @@ -193,6 +194,7 @@ struct bcma_bus {
345 struct bcma_drv_cc drv_cc;
346 struct bcma_drv_pci drv_pci;
347 + struct bcma_drv_mips drv_mips;
349 /* We decided to share SPROM struct with SSB as long as we do not need
350 * any hacks for BCMA. This simplifies drivers code. */
352 +++ b/include/linux/bcma/bcma_driver_mips.h
354 +#ifndef LINUX_BCMA_DRIVER_MIPS_H_
355 +#define LINUX_BCMA_DRIVER_MIPS_H_
357 +#define BCMA_MIPS_IPSFLAG 0x0F08
358 +/* which sbflags get routed to mips interrupt 1 */
359 +#define BCMA_MIPS_IPSFLAG_IRQ1 0x0000003F
360 +#define BCMA_MIPS_IPSFLAG_IRQ1_SHIFT 0
361 +/* which sbflags get routed to mips interrupt 2 */
362 +#define BCMA_MIPS_IPSFLAG_IRQ2 0x00003F00
363 +#define BCMA_MIPS_IPSFLAG_IRQ2_SHIFT 8
364 +/* which sbflags get routed to mips interrupt 3 */
365 +#define BCMA_MIPS_IPSFLAG_IRQ3 0x003F0000
366 +#define BCMA_MIPS_IPSFLAG_IRQ3_SHIFT 16
367 +/* which sbflags get routed to mips interrupt 4 */
368 +#define BCMA_MIPS_IPSFLAG_IRQ4 0x3F000000
369 +#define BCMA_MIPS_IPSFLAG_IRQ4_SHIFT 24
371 +/* MIPS 74K core registers */
372 +#define BCMA_MIPS_MIPS74K_CORECTL 0x0000
373 +#define BCMA_MIPS_MIPS74K_EXCEPTBASE 0x0004
374 +#define BCMA_MIPS_MIPS74K_BIST 0x000C
375 +#define BCMA_MIPS_MIPS74K_INTMASK_INT0 0x0014
376 +#define BCMA_MIPS_MIPS74K_INTMASK(int) \
377 + ((int) * 4 + BCMA_MIPS_MIPS74K_INTMASK_INT0)
378 +#define BCMA_MIPS_MIPS74K_NMIMASK 0x002C
379 +#define BCMA_MIPS_MIPS74K_GPIOSEL 0x0040
380 +#define BCMA_MIPS_MIPS74K_GPIOOUT 0x0044
381 +#define BCMA_MIPS_MIPS74K_GPIOEN 0x0048
382 +#define BCMA_MIPS_MIPS74K_CLKCTLST 0x01E0
384 +#define BCMA_MIPS_OOBSELOUTA30 0x100
388 +struct bcma_drv_mips {
389 + struct bcma_device *core;
391 + unsigned int assigned_irqs;
395 + u32 flash_window_size;
398 +extern void bcma_core_mips_init(struct bcma_drv_mips *mcore);
400 +extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
402 +#endif /* LINUX_BCMA_DRIVER_MIPS_H_ */