1 From d743a740b76a6be9e88fe1ae6991682927a7769c 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/26] 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/core.c | 2 +
22 drivers/bcma/driver_pci.c | 9 ++-
23 drivers/bcma/host_soc.c | 183 +++++++++++++++++++++++++++++++++++++++++
24 drivers/bcma/main.c | 9 ++-
25 drivers/bcma/scan.c | 42 ++++++++-
26 include/linux/bcma/bcma.h | 5 +-
27 include/linux/bcma/bcma_soc.h | 16 ++++
28 9 files changed, 263 insertions(+), 8 deletions(-)
29 create mode 100644 drivers/bcma/host_soc.c
30 create mode 100644 include/linux/bcma/bcma_soc.h
32 --- a/drivers/bcma/Kconfig
33 +++ b/drivers/bcma/Kconfig
34 @@ -34,6 +34,10 @@ config BCMA_DRIVER_PCI_HOSTMODE
36 PCI core hostmode operation (external PCI bus).
40 + depends on BCMA && MIPS
45 --- a/drivers/bcma/Makefile
46 +++ b/drivers/bcma/Makefile
47 @@ -3,6 +3,7 @@ bcma-y += driver_chipcommon.o driver
48 bcma-y += driver_pci.o
49 bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE) += driver_pci_host.o
50 bcma-$(CONFIG_BCMA_HOST_PCI) += host_pci.o
51 +bcma-$(CONFIG_BCMA_HOST_SOC) += host_soc.o
52 obj-$(CONFIG_BCMA) += bcma.o
54 ccflags-$(CONFIG_BCMA_DEBUG) := -DDEBUG
55 --- a/drivers/bcma/core.c
56 +++ b/drivers/bcma/core.c
57 @@ -110,6 +110,8 @@ EXPORT_SYMBOL_GPL(bcma_core_pll_ctl);
58 u32 bcma_core_dma_translation(struct bcma_device *core)
60 switch (core->bus->hosttype) {
61 + case BCMA_HOSTTYPE_SOC:
63 case BCMA_HOSTTYPE_PCI:
64 if (bcma_aread32(core, BCMA_IOST) & BCMA_IOST_DMA64)
65 return BCMA_DMA_TRANSLATION_DMA64_CMT;
66 --- a/drivers/bcma/driver_pci.c
67 +++ b/drivers/bcma/driver_pci.c
68 @@ -208,7 +208,14 @@ int bcma_core_pci_irq_ctl(struct bcma_dr
70 struct pci_dev *pdev = pc->core->bus->host_pci;
75 + if (core->bus->hosttype != BCMA_HOSTTYPE_PCI) {
76 + /* This bcma device is not on a PCI host-bus. So the IRQs are
77 + * not routed through the PCI core.
78 + * So we must not enable routing through the PCI core. */
82 err = pci_read_config_dword(pdev, BCMA_PCI_IRQMASK, &tmp);
85 +++ b/drivers/bcma/host_soc.c
88 + * Broadcom specific AMBA
89 + * System on Chip (SoC) Host
91 + * Licensed under the GNU/GPL. See COPYING for details.
94 +#include "bcma_private.h"
96 +#include <linux/bcma/bcma.h>
97 +#include <linux/bcma/bcma_soc.h>
99 +static u8 bcma_host_soc_read8(struct bcma_device *core, u16 offset)
101 + return readb(core->io_addr + offset);
104 +static u16 bcma_host_soc_read16(struct bcma_device *core, u16 offset)
106 + return readw(core->io_addr + offset);
109 +static u32 bcma_host_soc_read32(struct bcma_device *core, u16 offset)
111 + return readl(core->io_addr + offset);
114 +static void bcma_host_soc_write8(struct bcma_device *core, u16 offset,
117 + writeb(value, core->io_addr + offset);
120 +static void bcma_host_soc_write16(struct bcma_device *core, u16 offset,
123 + writew(value, core->io_addr + offset);
126 +static void bcma_host_soc_write32(struct bcma_device *core, u16 offset,
129 + writel(value, core->io_addr + offset);
132 +#ifdef CONFIG_BCMA_BLOCKIO
133 +static void bcma_host_soc_block_read(struct bcma_device *core, void *buffer,
134 + size_t count, u16 offset, u8 reg_width)
136 + void __iomem *addr = core->io_addr + offset;
138 + switch (reg_width) {
143 + *buf = __raw_readb(addr);
149 + case sizeof(u16): {
150 + __le16 *buf = buffer;
152 + WARN_ON(count & 1);
154 + *buf = (__force __le16)__raw_readw(addr);
160 + case sizeof(u32): {
161 + __le32 *buf = buffer;
163 + WARN_ON(count & 3);
165 + *buf = (__force __le32)__raw_readl(addr);
176 +static void bcma_host_soc_block_write(struct bcma_device *core,
177 + const void *buffer,
178 + size_t count, u16 offset, u8 reg_width)
180 + void __iomem *addr = core->io_addr + offset;
182 + switch (reg_width) {
184 + const u8 *buf = buffer;
187 + __raw_writeb(*buf, addr);
193 + case sizeof(u16): {
194 + const __le16 *buf = buffer;
196 + WARN_ON(count & 1);
198 + __raw_writew((__force u16)(*buf), addr);
204 + case sizeof(u32): {
205 + const __le32 *buf = buffer;
207 + WARN_ON(count & 3);
209 + __raw_writel((__force u32)(*buf), addr);
219 +#endif /* CONFIG_BCMA_BLOCKIO */
221 +static u32 bcma_host_soc_aread32(struct bcma_device *core, u16 offset)
223 + return readl(core->io_wrap + offset);
226 +static void bcma_host_soc_awrite32(struct bcma_device *core, u16 offset,
229 + writel(value, core->io_wrap + offset);
232 +const struct bcma_host_ops bcma_host_soc_ops = {
233 + .read8 = bcma_host_soc_read8,
234 + .read16 = bcma_host_soc_read16,
235 + .read32 = bcma_host_soc_read32,
236 + .write8 = bcma_host_soc_write8,
237 + .write16 = bcma_host_soc_write16,
238 + .write32 = bcma_host_soc_write32,
239 +#ifdef CONFIG_BCMA_BLOCKIO
240 + .block_read = bcma_host_soc_block_read,
241 + .block_write = bcma_host_soc_block_write,
243 + .aread32 = bcma_host_soc_aread32,
244 + .awrite32 = bcma_host_soc_awrite32,
247 +int __init bcma_host_soc_register(struct bcma_soc *soc)
249 + struct bcma_bus *bus = &soc->bus;
252 + /* iomap only first core. We have to read some register on this core
255 + bus->mmio = ioremap_nocache(BCMA_ADDR_BASE, BCMA_CORE_SIZE * 1);
259 + /* Host specific */
260 + bus->hosttype = BCMA_HOSTTYPE_SOC;
261 + bus->ops = &bcma_host_soc_ops;
264 + err = bcma_bus_early_register(bus, &soc->core_cc, &soc->core_mips);
266 + iounmap(bus->mmio);
270 --- a/drivers/bcma/main.c
271 +++ b/drivers/bcma/main.c
272 @@ -66,6 +66,10 @@ static struct bcma_device *bcma_find_cor
273 static void bcma_release_core_dev(struct device *dev)
275 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
277 + iounmap(core->io_addr);
279 + iounmap(core->io_wrap);
283 @@ -93,7 +97,10 @@ static int bcma_register_cores(struct bc
284 core->dma_dev = &bus->host_pci->dev;
285 core->irq = bus->host_pci->irq;
287 - case BCMA_HOSTTYPE_NONE:
288 + case BCMA_HOSTTYPE_SOC:
289 + core->dev.dma_mask = &core->dev.coherent_dma_mask;
290 + core->dma_dev = &core->dev;
292 case BCMA_HOSTTYPE_SDIO:
295 --- a/drivers/bcma/scan.c
296 +++ b/drivers/bcma/scan.c
297 @@ -337,6 +337,16 @@ static int bcma_get_next_core(struct bcm
301 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
302 + core->io_addr = ioremap_nocache(core->addr, BCMA_CORE_SIZE);
303 + if (!core->io_addr)
305 + core->io_wrap = ioremap_nocache(core->wrap, BCMA_CORE_SIZE);
306 + if (!core->io_wrap) {
307 + iounmap(core->io_addr);
314 @@ -369,7 +379,14 @@ int bcma_bus_scan(struct bcma_bus *bus)
317 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
318 - eromptr = bus->mmio;
319 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
320 + eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
324 + eromptr = bus->mmio;
327 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
329 bcma_scan_switch_core(bus, erombase);
330 @@ -404,6 +421,9 @@ int bcma_bus_scan(struct bcma_bus *bus)
331 list_add(&core->list, &bus->cores);
334 + if (bus->hosttype == BCMA_HOSTTYPE_SOC)
340 @@ -414,10 +434,18 @@ int __init bcma_bus_scan_early(struct bc
342 u32 __iomem *eromptr, *eromend;
344 - int err, core_num = 0;
348 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
349 - eromptr = bus->mmio;
350 + if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
351 + eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
355 + eromptr = bus->mmio;
358 eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
360 bcma_scan_switch_core(bus, erombase);
361 @@ -447,8 +475,12 @@ int __init bcma_bus_scan_early(struct bc
364 list_add(&core->list, &bus->cores);
371 + if (bus->hosttype == BCMA_HOSTTYPE_SOC)
376 --- a/include/linux/bcma/bcma.h
377 +++ b/include/linux/bcma/bcma.h
378 @@ -14,9 +14,9 @@ struct bcma_device;
382 - BCMA_HOSTTYPE_NONE,
388 struct bcma_chipinfo {
389 @@ -138,6 +138,9 @@ struct bcma_device {
393 + void __iomem *io_addr;
394 + void __iomem *io_wrap;
397 struct list_head list;
400 +++ b/include/linux/bcma/bcma_soc.h
402 +#ifndef LINUX_BCMA_SOC_H_
403 +#define LINUX_BCMA_SOC_H_
405 +#include <linux/bcma/bcma.h>
408 + struct bcma_bus bus;
409 + struct bcma_device core_cc;
410 + struct bcma_device core_mips;
413 +int __init bcma_host_soc_register(struct bcma_soc *soc);
415 +int bcma_bus_register(struct bcma_bus *bus);
417 +#endif /* LINUX_BCMA_SOC_H_ */