2 * Broadcom specific AMBA
3 * System on Chip (SoC) Host
5 * Licensed under the GNU/GPL. See COPYING for details.
8 #include "bcma_private.h"
10 #include <linux/slab.h>
11 #include <linux/module.h>
12 #include <linux/of_address.h>
13 #include <linux/bcma/bcma.h>
14 #include <linux/bcma/bcma_soc.h>
16 static u8 bcma_host_soc_read8(struct bcma_device *core, u16 offset)
18 return readb(core->io_addr + offset);
21 static u16 bcma_host_soc_read16(struct bcma_device *core, u16 offset)
23 return readw(core->io_addr + offset);
26 static u32 bcma_host_soc_read32(struct bcma_device *core, u16 offset)
28 return readl(core->io_addr + offset);
31 static void bcma_host_soc_write8(struct bcma_device *core, u16 offset,
34 writeb(value, core->io_addr + offset);
37 static void bcma_host_soc_write16(struct bcma_device *core, u16 offset,
40 writew(value, core->io_addr + offset);
43 static void bcma_host_soc_write32(struct bcma_device *core, u16 offset,
46 writel(value, core->io_addr + offset);
49 #ifdef CONFIG_BCMA_BLOCKIO
50 static void bcma_host_soc_block_read(struct bcma_device *core, void *buffer,
51 size_t count, u16 offset, u8 reg_width)
53 void __iomem *addr = core->io_addr + offset;
60 *buf = __raw_readb(addr);
71 *buf = (__force __le16)__raw_readw(addr);
82 *buf = (__force __le32)__raw_readl(addr);
93 static void bcma_host_soc_block_write(struct bcma_device *core,
95 size_t count, u16 offset, u8 reg_width)
97 void __iomem *addr = core->io_addr + offset;
101 const u8 *buf = buffer;
104 __raw_writeb(*buf, addr);
111 const __le16 *buf = buffer;
115 __raw_writew((__force u16)(*buf), addr);
122 const __le32 *buf = buffer;
126 __raw_writel((__force u32)(*buf), addr);
136 #endif /* CONFIG_BCMA_BLOCKIO */
138 static u32 bcma_host_soc_aread32(struct bcma_device *core, u16 offset)
140 if (WARN_ONCE(!core->io_wrap, "Accessed core has no wrapper/agent\n"))
142 return readl(core->io_wrap + offset);
145 static void bcma_host_soc_awrite32(struct bcma_device *core, u16 offset,
148 if (WARN_ONCE(!core->io_wrap, "Accessed core has no wrapper/agent\n"))
150 writel(value, core->io_wrap + offset);
153 static const struct bcma_host_ops bcma_host_soc_ops = {
154 .read8 = bcma_host_soc_read8,
155 .read16 = bcma_host_soc_read16,
156 .read32 = bcma_host_soc_read32,
157 .write8 = bcma_host_soc_write8,
158 .write16 = bcma_host_soc_write16,
159 .write32 = bcma_host_soc_write32,
160 #ifdef CONFIG_BCMA_BLOCKIO
161 .block_read = bcma_host_soc_block_read,
162 .block_write = bcma_host_soc_block_write,
164 .aread32 = bcma_host_soc_aread32,
165 .awrite32 = bcma_host_soc_awrite32,
168 int __init bcma_host_soc_register(struct bcma_soc *soc)
170 struct bcma_bus *bus = &soc->bus;
172 /* iomap only first core. We have to read some register on this core
175 bus->mmio = ioremap_nocache(BCMA_ADDR_BASE, BCMA_CORE_SIZE * 1);
180 bus->hosttype = BCMA_HOSTTYPE_SOC;
181 bus->ops = &bcma_host_soc_ops;
182 bus->host_pdev = NULL;
184 /* Initialize struct, detect chip */
190 int __init bcma_host_soc_init(struct bcma_soc *soc)
192 struct bcma_bus *bus = &soc->bus;
195 /* Scan bus and initialize it */
196 err = bcma_bus_early_register(bus);
204 static int bcma_host_soc_probe(struct platform_device *pdev)
206 struct device *dev = &pdev->dev;
207 struct device_node *np = dev->of_node;
208 struct bcma_bus *bus;
212 bus = devm_kzalloc(dev, sizeof(*bus), GFP_KERNEL);
217 bus->mmio = of_iomap(np, 0);
222 bus->hosttype = BCMA_HOSTTYPE_SOC;
223 bus->ops = &bcma_host_soc_ops;
224 bus->host_pdev = pdev;
226 /* Initialize struct, detect chip */
230 err = bcma_bus_register(bus);
234 platform_set_drvdata(pdev, bus);
243 static int bcma_host_soc_remove(struct platform_device *pdev)
245 struct bcma_bus *bus = platform_get_drvdata(pdev);
247 bcma_bus_unregister(bus);
249 platform_set_drvdata(pdev, NULL);
254 static const struct of_device_id bcma_host_soc_of_match[] = {
255 { .compatible = "brcm,bus-axi", },
258 MODULE_DEVICE_TABLE(of, bcma_host_soc_of_match);
260 static struct platform_driver bcma_host_soc_driver = {
262 .name = "bcma-host-soc",
263 .of_match_table = bcma_host_soc_of_match,
265 .probe = bcma_host_soc_probe,
266 .remove = bcma_host_soc_remove,
269 int __init bcma_host_soc_register_driver(void)
271 return platform_driver_register(&bcma_host_soc_driver);
274 void __exit bcma_host_soc_unregister_driver(void)
276 platform_driver_unregister(&bcma_host_soc_driver);
278 #endif /* CONFIG_OF */