blob: 69815079a6ddfb78c1a049f86f429fdbd6064c3b [file] [log] [blame]
Hauke Mehrtens21e05342011-07-23 01:20:09 +02001/*
2 * Broadcom specific AMBA
3 * Broadcom MIPS32 74K core driver
4 *
5 * Copyright 2009, Broadcom Corporation
6 * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
7 * Copyright 2010, Bernhard Loos <bernhardloos@googlemail.com>
8 * Copyright 2011, Hauke Mehrtens <hauke@hauke-m.de>
9 *
10 * Licensed under the GNU/GPL. See COPYING for details.
11 */
12
13#include "bcma_private.h"
14
15#include <linux/bcma/bcma.h>
16
17#include <linux/serial.h>
18#include <linux/serial_core.h>
19#include <linux/serial_reg.h>
20#include <linux/time.h>
21
22/* The 47162a0 hangs when reading MIPS DMP registers registers */
23static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
24{
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +020025 return dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM47162 &&
26 dev->bus->chipinfo.rev == 0 && dev->id.id == BCMA_CORE_MIPS_74K;
Hauke Mehrtens21e05342011-07-23 01:20:09 +020027}
28
29/* The 5357b0 hangs when reading USB20H DMP registers */
30static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device *dev)
31{
Hauke Mehrtens4b4f5be2012-06-30 01:44:38 +020032 return (dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
33 dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) &&
Hauke Mehrtens21e05342011-07-23 01:20:09 +020034 dev->bus->chipinfo.pkg == 11 &&
35 dev->id.id == BCMA_CORE_USB20_HOST;
36}
37
38static inline u32 mips_read32(struct bcma_drv_mips *mcore,
39 u16 offset)
40{
41 return bcma_read32(mcore->core, offset);
42}
43
44static inline void mips_write32(struct bcma_drv_mips *mcore,
45 u16 offset,
46 u32 value)
47{
48 bcma_write32(mcore->core, offset, value);
49}
50
51static const u32 ipsflag_irq_mask[] = {
52 0,
53 BCMA_MIPS_IPSFLAG_IRQ1,
54 BCMA_MIPS_IPSFLAG_IRQ2,
55 BCMA_MIPS_IPSFLAG_IRQ3,
56 BCMA_MIPS_IPSFLAG_IRQ4,
57};
58
59static const u32 ipsflag_irq_shift[] = {
60 0,
61 BCMA_MIPS_IPSFLAG_IRQ1_SHIFT,
62 BCMA_MIPS_IPSFLAG_IRQ2_SHIFT,
63 BCMA_MIPS_IPSFLAG_IRQ3_SHIFT,
64 BCMA_MIPS_IPSFLAG_IRQ4_SHIFT,
65};
66
67static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
68{
69 u32 flag;
70
71 if (bcma_core_mips_bcm47162a0_quirk(dev))
72 return dev->core_index;
73 if (bcma_core_mips_bcm5357b0_quirk(dev))
74 return dev->core_index;
75 flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
76
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +010077 if (flag)
78 return flag & 0x1F;
79 else
80 return 0x3f;
Hauke Mehrtens21e05342011-07-23 01:20:09 +020081}
82
83/* Get the MIPS IRQ assignment for a specified device.
84 * If unassigned, 0 is returned.
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +010085 * If disabled, 5 is returned.
86 * If not supported, 6 is returned.
Hauke Mehrtens21e05342011-07-23 01:20:09 +020087 */
88unsigned int bcma_core_mips_irq(struct bcma_device *dev)
89{
90 struct bcma_device *mdev = dev->bus->drv_mips.core;
91 u32 irqflag;
92 unsigned int irq;
93
94 irqflag = bcma_core_mips_irqflag(dev);
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +010095 if (irqflag == 0x3f)
96 return 6;
Hauke Mehrtens21e05342011-07-23 01:20:09 +020097
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +010098 for (irq = 0; irq <= 4; irq++)
Hauke Mehrtens21e05342011-07-23 01:20:09 +020099 if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
100 (1 << irqflag))
101 return irq;
102
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +0100103 return 5;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200104}
105EXPORT_SYMBOL(bcma_core_mips_irq);
106
107static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
108{
109 unsigned int oldirq = bcma_core_mips_irq(dev);
110 struct bcma_bus *bus = dev->bus;
111 struct bcma_device *mdev = bus->drv_mips.core;
112 u32 irqflag;
113
114 irqflag = bcma_core_mips_irqflag(dev);
115 BUG_ON(oldirq == 6);
116
117 dev->irq = irq + 2;
118
119 /* clear the old irq */
120 if (oldirq == 0)
121 bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
122 bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
123 ~(1 << irqflag));
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +0100124 else if (oldirq != 5)
Rafał Miłeckicbbc0132012-12-10 07:53:56 +0100125 bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200126
127 /* assign the new one */
128 if (irq == 0) {
129 bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
130 bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
131 (1 << irqflag));
132 } else {
133 u32 oldirqflag = bcma_read32(mdev,
134 BCMA_MIPS_MIPS74K_INTMASK(irq));
135 if (oldirqflag) {
136 struct bcma_device *core;
137
138 /* backplane irq line is in use, find out who uses
139 * it and set user to irq 0
140 */
Hauke Mehrtensd8f1bd22012-07-26 17:44:12 +0200141 list_for_each_entry(core, &bus->cores, list) {
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200142 if ((1 << bcma_core_mips_irqflag(core)) ==
143 oldirqflag) {
144 bcma_core_mips_set_irq(core, 0);
145 break;
146 }
147 }
148 }
149 bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
150 1 << irqflag);
151 }
152
Hauke Mehrtens7401cb62013-01-04 00:51:22 +0100153 bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
Hauke Mehrtensdb5230d2013-01-04 00:51:23 +0100154 dev->id.id, oldirq <= 4 ? oldirq + 2 : 0, irq + 2);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200155}
156
Hauke Mehrtense3f05a42013-01-04 00:51:21 +0100157static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
158 u16 coreid, u8 unit)
159{
160 struct bcma_device *core;
161
162 core = bcma_find_core_unit(bus, coreid, unit);
163 if (!core) {
164 bcma_warn(bus,
165 "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
166 coreid, unit);
167 return;
168 }
169
170 bcma_core_mips_set_irq(core, irq);
171}
172
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200173static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
174{
175 int i;
176 static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
Hauke Mehrtens7401cb62013-01-04 00:51:22 +0100177 printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200178 for (i = 0; i <= 6; i++)
179 printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
180 printk("\n");
181}
182
183static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
184{
185 struct bcma_device *core;
186
Hauke Mehrtensd8f1bd22012-07-26 17:44:12 +0200187 list_for_each_entry(core, &bus->cores, list) {
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200188 bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
189 }
190}
191
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200192u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
193{
194 struct bcma_bus *bus = mcore->core->bus;
195
196 if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
Rafał Miłecki5b5ac412012-12-07 12:56:56 +0100197 return bcma_pmu_get_cpu_clock(&bus->drv_cc);
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200198
Rafał Miłecki3d9d8af2012-07-05 22:07:32 +0200199 bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
Hauke Mehrtens908debc2011-07-23 01:20:11 +0200200 return 0;
201}
202EXPORT_SYMBOL(bcma_cpu_clock);
203
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200204static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
205{
206 struct bcma_bus *bus = mcore->core->bus;
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200207 struct bcma_drv_cc *cc = &bus->drv_cc;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200208
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200209 switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200210 case BCMA_CC_FLASHT_STSER:
211 case BCMA_CC_FLASHT_ATSER:
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200212 bcma_debug(bus, "Found serial flash\n");
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200213 bcma_sflash_init(cc);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200214 break;
215 case BCMA_CC_FLASHT_PARA:
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200216 bcma_debug(bus, "Found parallel flash\n");
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200217 cc->pflash.present = true;
218 cc->pflash.window = BCMA_SOC_FLASH2;
219 cc->pflash.window_size = BCMA_SOC_FLASH2_SZ;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200220
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200221 if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200222 BCMA_CC_FLASH_CFG_DS) == 0)
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200223 cc->pflash.buswidth = 1;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200224 else
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200225 cc->pflash.buswidth = 2;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200226 break;
227 default:
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200228 bcma_err(bus, "Flash type not supported\n");
229 }
230
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200231 if (cc->core->id.rev == 38 ||
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200232 bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200233 if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200234 bcma_debug(bus, "Found NAND flash\n");
Hauke Mehrtens3c25ddd2012-09-29 20:33:52 +0200235 bcma_nflash_init(cc);
Rafał Miłecki23cb3b22012-07-17 16:26:41 +0200236 }
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200237 }
238}
239
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200240void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
241{
242 struct bcma_bus *bus = mcore->core->bus;
243
244 if (mcore->early_setup_done)
245 return;
246
247 bcma_chipco_serial_init(&bus->drv_cc);
248 bcma_core_mips_flash_detect(mcore);
249
250 mcore->early_setup_done = true;
251}
252
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200253void bcma_core_mips_init(struct bcma_drv_mips *mcore)
254{
255 struct bcma_bus *bus;
256 struct bcma_device *core;
257 bus = mcore->core->bus;
258
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200259 if (mcore->setup_done)
260 return;
261
Hauke Mehrtens7401cb62013-01-04 00:51:22 +0100262 bcma_debug(bus, "Initializing MIPS core...\n");
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200263
Hauke Mehrtens49655bb2012-09-29 20:29:49 +0200264 bcma_core_mips_early_init(mcore);
265
266 mcore->assigned_irqs = 1;
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200267
Hauke Mehrtense3f05a42013-01-04 00:51:21 +0100268 switch (bus->chipinfo.id) {
269 case BCMA_CHIP_ID_BCM4716:
270 case BCMA_CHIP_ID_BCM4748:
271 bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
272 bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
273 bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
274 bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
275 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
276 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
277 break;
278 case BCMA_CHIP_ID_BCM5356:
279 case BCMA_CHIP_ID_BCM47162:
280 case BCMA_CHIP_ID_BCM53572:
281 bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
282 bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
283 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
284 break;
285 case BCMA_CHIP_ID_BCM5357:
286 case BCMA_CHIP_ID_BCM4749:
287 bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
288 bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
289 bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
290 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
291 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
292 break;
293 case BCMA_CHIP_ID_BCM4706:
294 bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
295 bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
296 0);
297 bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
298 bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
299 bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
300 0);
301 break;
302 default:
303 list_for_each_entry(core, &bus->cores, list) {
304 core->irq = bcma_core_irq(core);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200305 }
Hauke Mehrtense3f05a42013-01-04 00:51:21 +0100306 bcma_err(bus,
307 "Unknown device (0x%x) found, can not configure IRQs\n",
308 bus->chipinfo.id);
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200309 }
Hauke Mehrtens7401cb62013-01-04 00:51:22 +0100310 bcma_debug(bus, "IRQ reconfiguration done\n");
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200311 bcma_core_mips_dump_irq(bus);
312
Hauke Mehrtens21e05342011-07-23 01:20:09 +0200313 mcore->setup_done = true;
314}