1 From 3be3bbe24a1d49283864a1e1ea1d88a2e1700b50 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/26] 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 | 9 +
13 drivers/bcma/Makefile | 1 +
14 drivers/bcma/driver_mips.c | 243 +++++++++++++++++++++++++++
15 drivers/bcma/main.c | 15 ++
16 include/linux/bcma/bcma.h | 3 +
17 include/linux/bcma/bcma_driver_chipcommon.h | 13 ++
18 include/linux/bcma/bcma_driver_mips.h | 49 ++++++
19 7 files changed, 333 insertions(+), 0 deletions(-)
20 create mode 100644 drivers/bcma/driver_mips.c
21 create mode 100644 include/linux/bcma/bcma_driver_mips.h
23 --- a/drivers/bcma/Kconfig
24 +++ b/drivers/bcma/Kconfig
25 @@ -36,7 +36,16 @@ config BCMA_DRIVER_PCI_HOSTMODE
29 + depends on BCMA_DRIVER_MIPS
31 +config BCMA_DRIVER_MIPS
32 + bool "BCMA Broadcom MIPS core driver"
33 depends on BCMA && MIPS
35 + Driver for the Broadcom MIPS core attached to Broadcom specific
36 + Advanced Microcontroller Bus.
42 --- a/drivers/bcma/Makefile
43 +++ b/drivers/bcma/Makefile
44 @@ -2,6 +2,7 @@ bcma-y += main.o scan.o core.o sprom
45 bcma-y += driver_chipcommon.o driver_chipcommon_pmu.o
46 bcma-y += driver_pci.o
47 bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE) += driver_pci_host.o
48 +bcma-$(CONFIG_BCMA_DRIVER_MIPS) += driver_mips.o
49 bcma-$(CONFIG_BCMA_HOST_PCI) += host_pci.o
50 bcma-$(CONFIG_BCMA_HOST_SOC) += host_soc.o
51 obj-$(CONFIG_BCMA) += bcma.o
53 +++ b/drivers/bcma/driver_mips.c
56 + * Broadcom specific AMBA
57 + * Broadcom MIPS32 74K core driver
59 + * Copyright 2009, Broadcom Corporation
60 + * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
61 + * Copyright 2010, Bernhard Loos <bernhardloos@googlemail.com>
62 + * Copyright 2011, Hauke Mehrtens <hauke@hauke-m.de>
64 + * Licensed under the GNU/GPL. See COPYING for details.
67 +#include "bcma_private.h"
69 +#include <linux/bcma/bcma.h>
71 +#include <linux/serial.h>
72 +#include <linux/serial_core.h>
73 +#include <linux/serial_reg.h>
74 +#include <linux/time.h>
76 +/* The 47162a0 hangs when reading MIPS DMP registers registers */
77 +static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
79 + return dev->bus->chipinfo.id == 47162 && dev->bus->chipinfo.rev == 0 &&
80 + dev->id.id == BCMA_CORE_MIPS_74K;
83 +/* The 5357b0 hangs when reading USB20H DMP registers */
84 +static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device *dev)
86 + return (dev->bus->chipinfo.id == 0x5357 ||
87 + dev->bus->chipinfo.id == 0x4749) &&
88 + dev->bus->chipinfo.pkg == 11 &&
89 + dev->id.id == BCMA_CORE_USB20_HOST;
92 +static inline u32 mips_read32(struct bcma_drv_mips *mcore,
95 + return bcma_read32(mcore->core, offset);
98 +static inline void mips_write32(struct bcma_drv_mips *mcore,
102 + bcma_write32(mcore->core, offset, value);
105 +static const u32 ipsflag_irq_mask[] = {
107 + BCMA_MIPS_IPSFLAG_IRQ1,
108 + BCMA_MIPS_IPSFLAG_IRQ2,
109 + BCMA_MIPS_IPSFLAG_IRQ3,
110 + BCMA_MIPS_IPSFLAG_IRQ4,
113 +static const u32 ipsflag_irq_shift[] = {
115 + BCMA_MIPS_IPSFLAG_IRQ1_SHIFT,
116 + BCMA_MIPS_IPSFLAG_IRQ2_SHIFT,
117 + BCMA_MIPS_IPSFLAG_IRQ3_SHIFT,
118 + BCMA_MIPS_IPSFLAG_IRQ4_SHIFT,
121 +static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
125 + if (bcma_core_mips_bcm47162a0_quirk(dev))
126 + return dev->core_index;
127 + if (bcma_core_mips_bcm5357b0_quirk(dev))
128 + return dev->core_index;
129 + flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
131 + return flag & 0x1F;
134 +/* Get the MIPS IRQ assignment for a specified device.
135 + * If unassigned, 0 is returned.
137 +unsigned int bcma_core_mips_irq(struct bcma_device *dev)
139 + struct bcma_device *mdev = dev->bus->drv_mips.core;
143 + irqflag = bcma_core_mips_irqflag(dev);
145 + for (irq = 1; irq <= 4; irq++)
146 + if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
152 +EXPORT_SYMBOL(bcma_core_mips_irq);
154 +static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
156 + unsigned int oldirq = bcma_core_mips_irq(dev);
157 + struct bcma_bus *bus = dev->bus;
158 + struct bcma_device *mdev = bus->drv_mips.core;
161 + irqflag = bcma_core_mips_irqflag(dev);
162 + BUG_ON(oldirq == 6);
164 + dev->irq = irq + 2;
166 + /* clear the old irq */
168 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
169 + bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
172 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq), 0);
174 + /* assign the new one */
176 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
177 + bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
180 + u32 oldirqflag = bcma_read32(mdev,
181 + BCMA_MIPS_MIPS74K_INTMASK(irq));
183 + struct bcma_device *core;
185 + /* backplane irq line is in use, find out who uses
186 + * it and set user to irq 0
188 + list_for_each_entry_reverse(core, &bus->cores, list) {
189 + if ((1 << bcma_core_mips_irqflag(core)) ==
191 + bcma_core_mips_set_irq(core, 0);
196 + bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
200 + pr_info("set_irq: core 0x%04x, irq %d => %d\n",
201 + dev->id.id, oldirq + 2, irq + 2);
204 +static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
207 + static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
208 + printk(KERN_INFO KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
209 + for (i = 0; i <= 6; i++)
210 + printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
214 +static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
216 + struct bcma_device *core;
218 + list_for_each_entry_reverse(core, &bus->cores, list) {
219 + bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
223 +static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
225 + struct bcma_bus *bus = mcore->core->bus;
227 + switch (bus->drv_cc.capabilities & BCMA_CC_CAP_FLASHT) {
228 + case BCMA_CC_FLASHT_STSER:
229 + case BCMA_CC_FLASHT_ATSER:
230 + pr_err("Serial flash not supported.\n");
232 + case BCMA_CC_FLASHT_PARA:
233 + pr_info("found parallel flash.\n");
234 + bus->drv_cc.pflash.window = 0x1c000000;
235 + bus->drv_cc.pflash.window_size = 0x02000000;
237 + if ((bcma_read32(bus->drv_cc.core, BCMA_CC_FLASH_CFG) &
238 + BCMA_CC_FLASH_CFG_DS) == 0)
239 + bus->drv_cc.pflash.buswidth = 1;
241 + bus->drv_cc.pflash.buswidth = 2;
244 + pr_err("flash not supported.\n");
248 +void bcma_core_mips_init(struct bcma_drv_mips *mcore)
250 + struct bcma_bus *bus;
251 + struct bcma_device *core;
252 + bus = mcore->core->bus;
254 + pr_info("Initializing MIPS core...\n");
256 + if (!mcore->setup_done)
257 + mcore->assigned_irqs = 1;
259 + /* Assign IRQs to all cores on the bus */
260 + list_for_each_entry_reverse(core, &bus->cores, list) {
265 + mips_irq = bcma_core_mips_irq(core);
269 + core->irq = mips_irq + 2;
272 + switch (core->id.id) {
273 + case BCMA_CORE_PCI:
274 + case BCMA_CORE_PCIE:
275 + case BCMA_CORE_ETHERNET:
276 + case BCMA_CORE_ETHERNET_GBIT:
277 + case BCMA_CORE_MAC_GBIT:
278 + case BCMA_CORE_80211:
279 + case BCMA_CORE_USB20_HOST:
280 + /* These devices get their own IRQ line if available,
281 + * the rest goes on IRQ0
283 + if (mcore->assigned_irqs <= 4)
284 + bcma_core_mips_set_irq(core,
285 + mcore->assigned_irqs++);
289 + pr_info("IRQ reconfiguration done\n");
290 + bcma_core_mips_dump_irq(bus);
292 + if (mcore->setup_done)
295 + bcma_core_mips_flash_detect(mcore);
296 + mcore->setup_done = true;
298 --- a/drivers/bcma/main.c
299 +++ b/drivers/bcma/main.c
300 @@ -84,6 +84,7 @@ static int bcma_register_cores(struct bc
301 case BCMA_CORE_CHIPCOMMON:
304 + case BCMA_CORE_MIPS_74K:
308 @@ -147,6 +148,13 @@ int bcma_bus_register(struct bcma_bus *b
309 bcma_core_chipcommon_init(&bus->drv_cc);
312 + /* Init MIPS core */
313 + core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
315 + bus->drv_mips.core = core;
316 + bcma_core_mips_init(&bus->drv_mips);
320 core = bcma_find_core(bus, BCMA_CORE_PCIE);
322 @@ -217,6 +225,13 @@ int __init bcma_bus_early_register(struc
323 bcma_core_chipcommon_init(&bus->drv_cc);
326 + /* Init MIPS core */
327 + core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
329 + bus->drv_mips.core = core;
330 + bcma_core_mips_init(&bus->drv_mips);
333 pr_info("Early bus registered\n");
336 --- a/include/linux/bcma/bcma.h
337 +++ b/include/linux/bcma/bcma.h
340 #include <linux/bcma/bcma_driver_chipcommon.h>
341 #include <linux/bcma/bcma_driver_pci.h>
342 +#include <linux/bcma/bcma_driver_mips.h>
343 #include <linux/ssb/ssb.h> /* SPROM sharing */
345 #include "bcma_regs.h"
346 @@ -130,6 +131,7 @@ struct bcma_device {
349 struct device *dma_dev;
354 @@ -197,6 +199,7 @@ struct bcma_bus {
356 struct bcma_drv_cc drv_cc;
357 struct bcma_drv_pci drv_pci;
358 + struct bcma_drv_mips drv_mips;
360 /* We decided to share SPROM struct with SSB as long as we do not need
361 * any hacks for BCMA. This simplifies drivers code. */
362 --- a/include/linux/bcma/bcma_driver_chipcommon.h
363 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
365 #define BCMA_CC_FLASHT_NONE 0x00000000 /* No flash */
366 #define BCMA_CC_FLASHT_STSER 0x00000100 /* ST serial flash */
367 #define BCMA_CC_FLASHT_ATSER 0x00000200 /* Atmel serial flash */
368 +#define BCMA_CC_FLASHT_NFLASH 0x00000200
369 #define BCMA_CC_FLASHT_PARA 0x00000700 /* Parallel flash */
370 #define BCMA_CC_CAP_PLLT 0x00038000 /* PLL Type */
371 #define BCMA_PLLTYPE_NONE 0x00000000
373 #define BCMA_CC_PROG_CFG 0x0120
374 #define BCMA_CC_PROG_WAITCNT 0x0124
375 #define BCMA_CC_FLASH_CFG 0x0128
376 +#define BCMA_CC_FLASH_CFG_DS 0x0010 /* Data size, 0=8bit, 1=16bit */
377 #define BCMA_CC_FLASH_WAITCNT 0x012C
378 /* 0x1E0 is defined as shared BCMA_CLKCTLST */
379 #define BCMA_CC_HW_WORKAROUND 0x01E4 /* Hardware workaround (rev >= 20) */
380 @@ -247,6 +249,14 @@ struct bcma_chipcommon_pmu {
381 u32 crystalfreq; /* The active crystal frequency (in kHz) */
384 +#ifdef CONFIG_BCMA_DRIVER_MIPS
385 +struct bcma_pflash {
390 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
393 struct bcma_device *core;
395 @@ -256,6 +266,9 @@ struct bcma_drv_cc {
396 /* Fast Powerup Delay constant */
397 u16 fast_pwrup_delay;
398 struct bcma_chipcommon_pmu pmu;
399 +#ifdef CONFIG_BCMA_DRIVER_MIPS
400 + struct bcma_pflash pflash;
401 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
404 /* Register access */
406 +++ b/include/linux/bcma/bcma_driver_mips.h
408 +#ifndef LINUX_BCMA_DRIVER_MIPS_H_
409 +#define LINUX_BCMA_DRIVER_MIPS_H_
411 +#define BCMA_MIPS_IPSFLAG 0x0F08
412 +/* which sbflags get routed to mips interrupt 1 */
413 +#define BCMA_MIPS_IPSFLAG_IRQ1 0x0000003F
414 +#define BCMA_MIPS_IPSFLAG_IRQ1_SHIFT 0
415 +/* which sbflags get routed to mips interrupt 2 */
416 +#define BCMA_MIPS_IPSFLAG_IRQ2 0x00003F00
417 +#define BCMA_MIPS_IPSFLAG_IRQ2_SHIFT 8
418 +/* which sbflags get routed to mips interrupt 3 */
419 +#define BCMA_MIPS_IPSFLAG_IRQ3 0x003F0000
420 +#define BCMA_MIPS_IPSFLAG_IRQ3_SHIFT 16
421 +/* which sbflags get routed to mips interrupt 4 */
422 +#define BCMA_MIPS_IPSFLAG_IRQ4 0x3F000000
423 +#define BCMA_MIPS_IPSFLAG_IRQ4_SHIFT 24
425 +/* MIPS 74K core registers */
426 +#define BCMA_MIPS_MIPS74K_CORECTL 0x0000
427 +#define BCMA_MIPS_MIPS74K_EXCEPTBASE 0x0004
428 +#define BCMA_MIPS_MIPS74K_BIST 0x000C
429 +#define BCMA_MIPS_MIPS74K_INTMASK_INT0 0x0014
430 +#define BCMA_MIPS_MIPS74K_INTMASK(int) \
431 + ((int) * 4 + BCMA_MIPS_MIPS74K_INTMASK_INT0)
432 +#define BCMA_MIPS_MIPS74K_NMIMASK 0x002C
433 +#define BCMA_MIPS_MIPS74K_GPIOSEL 0x0040
434 +#define BCMA_MIPS_MIPS74K_GPIOOUT 0x0044
435 +#define BCMA_MIPS_MIPS74K_GPIOEN 0x0048
436 +#define BCMA_MIPS_MIPS74K_CLKCTLST 0x01E0
438 +#define BCMA_MIPS_OOBSELOUTA30 0x100
442 +struct bcma_drv_mips {
443 + struct bcma_device *core;
445 + unsigned int assigned_irqs;
448 +#ifdef CONFIG_BCMA_DRIVER_MIPS
449 +extern void bcma_core_mips_init(struct bcma_drv_mips *mcore);
451 +static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { }
454 +extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
456 +#endif /* LINUX_BCMA_DRIVER_MIPS_H_ */