1 From 22573303ad477fa07c948a9944e9c18fea9af724 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 18 Jun 2011 14:31:53 +0200
4 Subject: [PATCH 04/22] bcma: add SOC bus
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This patch adds support for using bcma on a Broadcom SoC as the system
10 bus. An SoC like the bcm4716 could register this bus and use it to
11 searches for the bcma cores and register the devices on this bus.
13 BCMA_HOSTTYPE_NONE was intended for SoCs at first but BCMA_HOSTTYPE_SOC
16 Acked-by: Rafał Miłecki <zajec5@gmail.com>
17 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
19 drivers/bcma/Kconfig | 4 +
20 drivers/bcma/Makefile | 1 +
21 drivers/bcma/host_soc.c | 183 +++++++++++++++++++++++++++++++++++++++++
22 drivers/bcma/main.c | 6 +-
23 drivers/bcma/scan.c | 42 ++++++++-
24 include/linux/bcma/bcma.h | 5 +-
25 include/linux/bcma/bcma_soc.h | 16 ++++
26 7 files changed, 250 insertions(+), 7 deletions(-)
27 create mode 100644 drivers/bcma/host_soc.c
28 create mode 100644 include/linux/bcma/bcma_soc.h
30 --- a/drivers/bcma/Kconfig
31 +++ b/drivers/bcma/Kconfig
32 @@ -34,6 +34,10 @@ config BCMA_DRIVER_PCI_HOSTMODE
34 PCI core hostmode operation (external PCI bus).
38 + depends on BCMA && MIPS
43 --- a/drivers/bcma/Makefile
44 +++ b/drivers/bcma/Makefile
45 @@ -3,6 +3,7 @@ bcma-y += driver_chipcommon.o driver
46 bcma-y += driver_pci.o
47 bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE) += driver_pci_host.o
48 bcma-$(CONFIG_BCMA_HOST_PCI) += host_pci.o
49 +bcma-$(CONFIG_BCMA_HOST_SOC) += host_soc.o
50 obj-$(CONFIG_BCMA) += bcma.o
52 ccflags-$(CONFIG_BCMA_DEBUG) := -DDEBUG
54 +++ b/drivers/bcma/host_soc.c
57 + * Broadcom specific AMBA
58 + * System on Chip (SoC) Host
60 + * Licensed under the GNU/GPL. See COPYING for details.
63 +#include "bcma_private.h"
65 +#include <linux/bcma/bcma.h>
66 +#include <linux/bcma/bcma_soc.h>
68 +static u8 bcma_host_soc_read8(struct bcma_device *core, u16 offset)
70 + return readb(core->io_addr + offset);
73 +static u16 bcma_host_soc_read16(struct bcma_device *core, u16 offset)
75 + return readw(core->io_addr + offset);
78 +static u32 bcma_host_soc_read32(struct bcma_device *core, u16 offset)
80 + return readl(core->io_addr + offset);
83 +static void bcma_host_soc_write8(struct bcma_device *core, u16 offset,
86 + writeb(value, core->io_addr + offset);
89 +static void bcma_host_soc_write16(struct bcma_device *core, u16 offset,
92 + writew(value, core->io_addr + offset);
95 +static void bcma_host_soc_write32(struct bcma_device *core, u16 offset,
98 + writel(value, core->io_addr + offset);
101 +#ifdef CONFIG_BCMA_BLOCKIO
102 +static void bcma_host_soc_block_read(struct bcma_device *core, void *buffer,
103 + size_t count, u16 offset, u8 reg_width)
105 + void __iomem *addr = core->io_addr + offset;
107 + switch (reg_width) {
112 + *buf = __raw_readb(addr);
118 + case sizeof(u16): {
119 + __le16 *buf = buffer;
121 + WARN_ON(count & 1);
123 + *buf = (__force __le16)__raw_readw(addr);
129 + case sizeof(u32): {
130 + __le32 *buf = buffer;
132 + WARN_ON(count & 3);
134 + *buf = (__force __le32)__raw_readl(addr);
145 +static void bcma_host_soc_block_write(struct bcma_device *core,
146 + const void *buffer,
147 + size_t count, u16 offset, u8 reg_width)
149 + void __iomem *addr = core->io_addr + offset;
151 + switch (reg_width) {
153 + const u8 *buf = buffer;
156 + __raw_writeb(*buf, addr);
162 + case sizeof(u16): {
163 + const __le16 *buf = buffer;
165 + WARN_ON(count & 1);
167 + __raw_writew((__force u16)(*buf), addr);
173 + case sizeof(u32): {
174 + const __le32 *buf = buffer;
176 + WARN_ON(count & 3);
178 + __raw_writel((__force u32)(*buf), addr);
188 +#endif /* CONFIG_BCMA_BLOCKIO */
190 +static u32 bcma_host_soc_aread32(struct bcma_device *core, u16 offset)
192 + return readl(core->io_wrap + offset);
195 +static void bcma_host_soc_awrite32(struct bcma_device *core, u16 offset,
198 + writel(value, core->io_wrap + offset);
201 +const struct bcma_host_ops bcma_host_soc_ops = {
202 + .read8 = bcma_host_soc_read8,
203 + .read16 = bcma_host_soc_read16,
204 + .read32 = bcma_host_soc_read32,
205 + .write8 = bcma_host_soc_write8,
206 + .write16 = bcma_host_soc_write16,
207 + .write32 = bcma_host_soc_write32,
208 +#ifdef CONFIG_BCMA_BLOCKIO
209 + .block_read = bcma_host_soc_block_read,
210 + .block_write = bcma_host_soc_block_write,
212 + .aread32 = bcma_host_soc_aread32,
213 + .awrite32 = bcma_host_soc_awrite32,
216 +int __init bcma_host_soc_register(struct bcma_soc *soc)
218 + struct bcma_bus *bus = &soc->bus;
221 + /* iomap only first core. We have to read some register on this core
224 + bus->mmio = ioremap_nocache(BCMA_ADDR_BASE, BCMA_CORE_SIZE * 1);
228 + /* Host specific */
229 + bus->hosttype = BCMA_HOSTTYPE_SOC;
230 + bus->ops = &bcma_host_soc_ops;
233 + err = bcma_bus_early_register(bus, &soc->core_cc, &soc->core_mips);
235 + iounmap(bus->mmio);
239 --- a/drivers/bcma/main.c
240 +++ b/drivers/bcma/main.c
241 @@ -66,6 +66,10 @@ static struct bcma_device *bcma_find_cor
242 static void bcma_release_core_dev(struct device *dev)
244 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
246 + iounmap(core->io_addr);
248 + iounmap(core->io_wrap);
252 @@ -93,8 +97,8 @@ static int bcma_register_cores(struct bc
253 core->dma_dev = &bus->host_pci->dev;
254 core->irq = bus->host_pci->irq;
256 - case BCMA_HOSTTYPE_NONE:
257 case BCMA_HOSTTYPE_SDIO:
258 + case BCMA_HOSTTYPE_SOC:
262 --- a/drivers/bcma/scan.c
263 +++ b/drivers/bcma/scan.c
264 @@ -337,6 +337,16 @@ static int bcma_get_next_core(struct bcm
268 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
269 + core->io_addr = ioremap_nocache(core->addr, BCMA_CORE_SIZE);
270 + if (!core->io_addr)
272 + core->io_wrap = ioremap_nocache(core->wrap, BCMA_CORE_SIZE);
273 + if (!core->io_wrap) {
274 + iounmap(core->io_addr);
281 @@ -369,7 +379,14 @@ int bcma_bus_scan(struct bcma_bus *bus)
284 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
285 - eromptr = bus->mmio;
286 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
287 + eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
291 + eromptr = bus->mmio;
294 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
296 bcma_scan_switch_core(bus, erombase);
297 @@ -404,6 +421,9 @@ int bcma_bus_scan(struct bcma_bus *bus)
298 list_add(&core->list, &bus->cores);
301 + if (bus->hosttype == BCMA_HOSTTYPE_SOC)
307 @@ -414,10 +434,18 @@ int __init bcma_bus_scan_early(struct bc
309 u32 __iomem *eromptr, *eromend;
311 - int err, core_num = 0;
315 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
316 - eromptr = bus->mmio;
317 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
318 + eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
322 + eromptr = bus->mmio;
325 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
327 bcma_scan_switch_core(bus, erombase);
328 @@ -447,8 +475,12 @@ int __init bcma_bus_scan_early(struct bc
331 list_add(&core->list, &bus->cores);
338 + if (bus->hosttype == BCMA_HOSTTYPE_SOC)
343 --- a/include/linux/bcma/bcma.h
344 +++ b/include/linux/bcma/bcma.h
345 @@ -14,9 +14,9 @@ struct bcma_device;
349 - BCMA_HOSTTYPE_NONE,
355 struct bcma_chipinfo {
356 @@ -138,6 +138,9 @@ struct bcma_device {
360 + void __iomem *io_addr;
361 + void __iomem *io_wrap;
364 struct list_head list;
367 +++ b/include/linux/bcma/bcma_soc.h
369 +#ifndef LINUX_BCMA_SOC_H_
370 +#define LINUX_BCMA_SOC_H_
372 +#include <linux/bcma/bcma.h>
375 + struct bcma_bus bus;
376 + struct bcma_device core_cc;
377 + struct bcma_device core_mips;
380 +int __init bcma_host_soc_register(struct bcma_soc *soc);
382 +int bcma_bus_register(struct bcma_bus *bus);
384 +#endif /* LINUX_BCMA_SOC_H_ */