Root/target/linux/brcm47xx/patches-3.0/0004-bcma-add-SOC-bus.patch

1From d743a740b76a6be9e88fe1ae6991682927a7769c Mon Sep 17 00:00:00 2001
2From: Hauke Mehrtens <hauke@hauke-m.de>
3Date: Sat, 18 Jun 2011 14:31:53 +0200
4Subject: [PATCH 04/26] bcma: add SOC bus
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9This patch adds support for using bcma on a Broadcom SoC as the system
10bus. An SoC like the bcm4716 could register this bus and use it to
11searches for the bcma cores and register the devices on this bus.
12
13BCMA_HOSTTYPE_NONE was intended for SoCs at first but BCMA_HOSTTYPE_SOC
14is a better name.
15
16Acked-by: Rafał Miłecki <zajec5@gmail.com>
17Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
18---
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
31
32--- a/drivers/bcma/Kconfig
33+++ b/drivers/bcma/Kconfig
34@@ -34,6 +34,10 @@ config BCMA_DRIVER_PCI_HOSTMODE
35     help
36       PCI core hostmode operation (external PCI bus).
37 
38+config BCMA_HOST_SOC
39+ bool
40+ depends on BCMA && MIPS
41+
42 config BCMA_DEBUG
43     bool "BCMA debugging"
44     depends on BCMA
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
53 
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)
59 {
60     switch (core->bus->hosttype) {
61+ case BCMA_HOSTTYPE_SOC:
62+ return 0;
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
69 {
70     struct pci_dev *pdev = pc->core->bus->host_pci;
71     u32 coremask, tmp;
72- int err;
73+ int err = 0;
74+
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. */
79+ goto out;
80+ }
81 
82     err = pci_read_config_dword(pdev, BCMA_PCI_IRQMASK, &tmp);
83     if (err)
84--- /dev/null
85+++ b/drivers/bcma/host_soc.c
86@@ -0,0 +1,183 @@
87+/*
88+ * Broadcom specific AMBA
89+ * System on Chip (SoC) Host
90+ *
91+ * Licensed under the GNU/GPL. See COPYING for details.
92+ */
93+
94+#include "bcma_private.h"
95+#include "scan.h"
96+#include <linux/bcma/bcma.h>
97+#include <linux/bcma/bcma_soc.h>
98+
99+static u8 bcma_host_soc_read8(struct bcma_device *core, u16 offset)
100+{
101+ return readb(core->io_addr + offset);
102+}
103+
104+static u16 bcma_host_soc_read16(struct bcma_device *core, u16 offset)
105+{
106+ return readw(core->io_addr + offset);
107+}
108+
109+static u32 bcma_host_soc_read32(struct bcma_device *core, u16 offset)
110+{
111+ return readl(core->io_addr + offset);
112+}
113+
114+static void bcma_host_soc_write8(struct bcma_device *core, u16 offset,
115+ u8 value)
116+{
117+ writeb(value, core->io_addr + offset);
118+}
119+
120+static void bcma_host_soc_write16(struct bcma_device *core, u16 offset,
121+ u16 value)
122+{
123+ writew(value, core->io_addr + offset);
124+}
125+
126+static void bcma_host_soc_write32(struct bcma_device *core, u16 offset,
127+ u32 value)
128+{
129+ writel(value, core->io_addr + offset);
130+}
131+
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)
135+{
136+ void __iomem *addr = core->io_addr + offset;
137+
138+ switch (reg_width) {
139+ case sizeof(u8): {
140+ u8 *buf = buffer;
141+
142+ while (count) {
143+ *buf = __raw_readb(addr);
144+ buf++;
145+ count--;
146+ }
147+ break;
148+ }
149+ case sizeof(u16): {
150+ __le16 *buf = buffer;
151+
152+ WARN_ON(count & 1);
153+ while (count) {
154+ *buf = (__force __le16)__raw_readw(addr);
155+ buf++;
156+ count -= 2;
157+ }
158+ break;
159+ }
160+ case sizeof(u32): {
161+ __le32 *buf = buffer;
162+
163+ WARN_ON(count & 3);
164+ while (count) {
165+ *buf = (__force __le32)__raw_readl(addr);
166+ buf++;
167+ count -= 4;
168+ }
169+ break;
170+ }
171+ default:
172+ WARN_ON(1);
173+ }
174+}
175+
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)
179+{
180+ void __iomem *addr = core->io_addr + offset;
181+
182+ switch (reg_width) {
183+ case sizeof(u8): {
184+ const u8 *buf = buffer;
185+
186+ while (count) {
187+ __raw_writeb(*buf, addr);
188+ buf++;
189+ count--;
190+ }
191+ break;
192+ }
193+ case sizeof(u16): {
194+ const __le16 *buf = buffer;
195+
196+ WARN_ON(count & 1);
197+ while (count) {
198+ __raw_writew((__force u16)(*buf), addr);
199+ buf++;
200+ count -= 2;
201+ }
202+ break;
203+ }
204+ case sizeof(u32): {
205+ const __le32 *buf = buffer;
206+
207+ WARN_ON(count & 3);
208+ while (count) {
209+ __raw_writel((__force u32)(*buf), addr);
210+ buf++;
211+ count -= 4;
212+ }
213+ break;
214+ }
215+ default:
216+ WARN_ON(1);
217+ }
218+}
219+#endif /* CONFIG_BCMA_BLOCKIO */
220+
221+static u32 bcma_host_soc_aread32(struct bcma_device *core, u16 offset)
222+{
223+ return readl(core->io_wrap + offset);
224+}
225+
226+static void bcma_host_soc_awrite32(struct bcma_device *core, u16 offset,
227+ u32 value)
228+{
229+ writel(value, core->io_wrap + offset);
230+}
231+
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,
242+#endif
243+ .aread32 = bcma_host_soc_aread32,
244+ .awrite32 = bcma_host_soc_awrite32,
245+};
246+
247+int __init bcma_host_soc_register(struct bcma_soc *soc)
248+{
249+ struct bcma_bus *bus = &soc->bus;
250+ int err;
251+
252+ /* iomap only first core. We have to read some register on this core
253+ * to scan the bus.
254+ */
255+ bus->mmio = ioremap_nocache(BCMA_ADDR_BASE, BCMA_CORE_SIZE * 1);
256+ if (!bus->mmio)
257+ return -ENOMEM;
258+
259+ /* Host specific */
260+ bus->hosttype = BCMA_HOSTTYPE_SOC;
261+ bus->ops = &bcma_host_soc_ops;
262+
263+ /* Register */
264+ err = bcma_bus_early_register(bus, &soc->core_cc, &soc->core_mips);
265+ if (err)
266+ iounmap(bus->mmio);
267+
268+ return err;
269+}
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)
274 {
275     struct bcma_device *core = container_of(dev, struct bcma_device, dev);
276+ if (core->io_addr)
277+ iounmap(core->io_addr);
278+ if (core->io_wrap)
279+ iounmap(core->io_wrap);
280     kfree(core);
281 }
282 
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;
286             break;
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;
291+ break;
292         case BCMA_HOSTTYPE_SDIO:
293             break;
294         }
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
298             }
299         }
300     }
301+ if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
302+ core->io_addr = ioremap_nocache(core->addr, BCMA_CORE_SIZE);
303+ if (!core->io_addr)
304+ return -ENOMEM;
305+ core->io_wrap = ioremap_nocache(core->wrap, BCMA_CORE_SIZE);
306+ if (!core->io_wrap) {
307+ iounmap(core->io_addr);
308+ return -ENOMEM;
309+ }
310+ }
311     return 0;
312 }
313 
314@@ -369,7 +379,14 @@ int bcma_bus_scan(struct bcma_bus *bus)
315     bcma_init_bus(bus);
316 
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);
321+ if (!eromptr)
322+ return -ENOMEM;
323+ } else {
324+ eromptr = bus->mmio;
325+ }
326+
327     eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
328 
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);
332     }
333 
334+ if (bus->hosttype == BCMA_HOSTTYPE_SOC)
335+ iounmap(eromptr);
336+
337     return 0;
338 }
339 
340@@ -414,10 +434,18 @@ int __init bcma_bus_scan_early(struct bc
341     u32 erombase;
342     u32 __iomem *eromptr, *eromend;
343 
344- int err, core_num = 0;
345+ int err = -ENODEV;
346+ int core_num = 0;
347 
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);
352+ if (!eromptr)
353+ return -ENOMEM;
354+ } else {
355+ eromptr = bus->mmio;
356+ }
357+
358     eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
359 
360     bcma_scan_switch_core(bus, erombase);
361@@ -447,8 +475,12 @@ int __init bcma_bus_scan_early(struct bc
362             core->id.class);
363 
364         list_add(&core->list, &bus->cores);
365- return 0;
366+ err = 0;
367+ break;
368     }
369 
370- return -ENODEV;
371+ if (bus->hosttype == BCMA_HOSTTYPE_SOC)
372+ iounmap(eromptr);
373+
374+ return err;
375 }
376--- a/include/linux/bcma/bcma.h
377+++ b/include/linux/bcma/bcma.h
378@@ -14,9 +14,9 @@ struct bcma_device;
379 struct bcma_bus;
380 
381 enum bcma_hosttype {
382- BCMA_HOSTTYPE_NONE,
383     BCMA_HOSTTYPE_PCI,
384     BCMA_HOSTTYPE_SDIO,
385+ BCMA_HOSTTYPE_SOC,
386 };
387 
388 struct bcma_chipinfo {
389@@ -138,6 +138,9 @@ struct bcma_device {
390     u32 addr;
391     u32 wrap;
392 
393+ void __iomem *io_addr;
394+ void __iomem *io_wrap;
395+
396     void *drvdata;
397     struct list_head list;
398 };
399--- /dev/null
400+++ b/include/linux/bcma/bcma_soc.h
401@@ -0,0 +1,16 @@
402+#ifndef LINUX_BCMA_SOC_H_
403+#define LINUX_BCMA_SOC_H_
404+
405+#include <linux/bcma/bcma.h>
406+
407+struct bcma_soc {
408+ struct bcma_bus bus;
409+ struct bcma_device core_cc;
410+ struct bcma_device core_mips;
411+};
412+
413+int __init bcma_host_soc_register(struct bcma_soc *soc);
414+
415+int bcma_bus_register(struct bcma_bus *bus);
416+
417+#endif /* LINUX_BCMA_SOC_H_ */
418

Archive Download this file



interactive