blob: 7355fa2cb4391fd20b25797d7e90840ea2bff65e [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001// SPDX-License-Identifier: GPL-2.0-only
Florian Fainelli44127b72014-05-19 13:05:59 -07002/*
Doug Berger856c7cc2017-03-29 17:29:09 -07003 * Copyright (C) 2014-2017 Broadcom
Florian Fainelli44127b72014-05-19 13:05:59 -07004 */
5
6#include <linux/init.h>
7#include <linux/types.h>
8#include <linux/module.h>
9#include <linux/platform_device.h>
10#include <linux/interrupt.h>
11#include <linux/sysfs.h>
12#include <linux/io.h>
13#include <linux/string.h>
14#include <linux/device.h>
15#include <linux/list.h>
16#include <linux/of.h>
17#include <linux/bitops.h>
Florian Fainelli203bb852014-09-18 12:37:14 -070018#include <linux/pm.h>
Doug Berger9eb60882017-03-29 17:29:11 -070019#include <linux/kernel.h>
20#include <linux/kdebug.h>
21#include <linux/notifier.h>
Florian Fainelli44127b72014-05-19 13:05:59 -070022
Florian Fainellic400d5e2016-01-31 12:29:27 -080023#ifdef CONFIG_MIPS
24#include <asm/traps.h>
25#endif
26
Florian Fainelli44127b72014-05-19 13:05:59 -070027#define ARB_ERR_CAP_CLEAR (1 << 0)
Florian Fainelli44127b72014-05-19 13:05:59 -070028#define ARB_ERR_CAP_STATUS_TIMEOUT (1 << 12)
29#define ARB_ERR_CAP_STATUS_TEA (1 << 11)
Florian Fainelli44127b72014-05-19 13:05:59 -070030#define ARB_ERR_CAP_STATUS_WRITE (1 << 1)
31#define ARB_ERR_CAP_STATUS_VALID (1 << 0)
Kevin Cernekeef8083582014-11-25 16:49:51 -080032
Florian Fainellifb8a0b82020-04-17 17:21:32 -070033#define ARB_BP_CAP_CLEAR (1 << 0)
34#define ARB_BP_CAP_STATUS_PROT_SHIFT 14
35#define ARB_BP_CAP_STATUS_TYPE (1 << 13)
36#define ARB_BP_CAP_STATUS_RSP_SHIFT 10
37#define ARB_BP_CAP_STATUS_MASK GENMASK(1, 0)
38#define ARB_BP_CAP_STATUS_BS_SHIFT 2
39#define ARB_BP_CAP_STATUS_WRITE (1 << 1)
40#define ARB_BP_CAP_STATUS_VALID (1 << 0)
41
Kevin Cernekeef8083582014-11-25 16:49:51 -080042enum {
43 ARB_TIMER,
Florian Fainellifb8a0b82020-04-17 17:21:32 -070044 ARB_BP_CAP_CLR,
45 ARB_BP_CAP_HI_ADDR,
46 ARB_BP_CAP_ADDR,
47 ARB_BP_CAP_STATUS,
48 ARB_BP_CAP_MASTER,
Kevin Cernekeef8083582014-11-25 16:49:51 -080049 ARB_ERR_CAP_CLR,
50 ARB_ERR_CAP_HI_ADDR,
51 ARB_ERR_CAP_ADDR,
Kevin Cernekeef8083582014-11-25 16:49:51 -080052 ARB_ERR_CAP_STATUS,
53 ARB_ERR_CAP_MASTER,
54};
55
Kevin Cernekeed1d67862014-11-25 16:49:52 -080056static const int gisb_offsets_bcm7038[] = {
57 [ARB_TIMER] = 0x00c,
Florian Fainellifb8a0b82020-04-17 17:21:32 -070058 [ARB_BP_CAP_CLR] = 0x014,
59 [ARB_BP_CAP_HI_ADDR] = -1,
60 [ARB_BP_CAP_ADDR] = 0x0b8,
61 [ARB_BP_CAP_STATUS] = 0x0c0,
62 [ARB_BP_CAP_MASTER] = -1,
Kevin Cernekeed1d67862014-11-25 16:49:52 -080063 [ARB_ERR_CAP_CLR] = 0x0c4,
64 [ARB_ERR_CAP_HI_ADDR] = -1,
65 [ARB_ERR_CAP_ADDR] = 0x0c8,
Kevin Cernekeed1d67862014-11-25 16:49:52 -080066 [ARB_ERR_CAP_STATUS] = 0x0d0,
67 [ARB_ERR_CAP_MASTER] = -1,
68};
69
Doug Bergerd523e0c2017-03-29 17:29:14 -070070static const int gisb_offsets_bcm7278[] = {
71 [ARB_TIMER] = 0x008,
Florian Fainellifb8a0b82020-04-17 17:21:32 -070072 [ARB_BP_CAP_CLR] = 0x01c,
73 [ARB_BP_CAP_HI_ADDR] = -1,
74 [ARB_BP_CAP_ADDR] = 0x220,
75 [ARB_BP_CAP_STATUS] = 0x230,
76 [ARB_BP_CAP_MASTER] = 0x234,
Doug Bergerd523e0c2017-03-29 17:29:14 -070077 [ARB_ERR_CAP_CLR] = 0x7f8,
78 [ARB_ERR_CAP_HI_ADDR] = -1,
79 [ARB_ERR_CAP_ADDR] = 0x7e0,
80 [ARB_ERR_CAP_STATUS] = 0x7f0,
81 [ARB_ERR_CAP_MASTER] = 0x7f4,
82};
83
Kevin Cernekeed1d67862014-11-25 16:49:52 -080084static const int gisb_offsets_bcm7400[] = {
85 [ARB_TIMER] = 0x00c,
Florian Fainellifb8a0b82020-04-17 17:21:32 -070086 [ARB_BP_CAP_CLR] = 0x014,
87 [ARB_BP_CAP_HI_ADDR] = -1,
88 [ARB_BP_CAP_ADDR] = 0x0b8,
89 [ARB_BP_CAP_STATUS] = 0x0c0,
90 [ARB_BP_CAP_MASTER] = 0x0c4,
Kevin Cernekeed1d67862014-11-25 16:49:52 -080091 [ARB_ERR_CAP_CLR] = 0x0c8,
92 [ARB_ERR_CAP_HI_ADDR] = -1,
93 [ARB_ERR_CAP_ADDR] = 0x0cc,
Kevin Cernekeed1d67862014-11-25 16:49:52 -080094 [ARB_ERR_CAP_STATUS] = 0x0d4,
95 [ARB_ERR_CAP_MASTER] = 0x0d8,
96};
97
98static const int gisb_offsets_bcm7435[] = {
99 [ARB_TIMER] = 0x00c,
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700100 [ARB_BP_CAP_CLR] = 0x014,
101 [ARB_BP_CAP_HI_ADDR] = -1,
102 [ARB_BP_CAP_ADDR] = 0x158,
103 [ARB_BP_CAP_STATUS] = 0x160,
104 [ARB_BP_CAP_MASTER] = 0x164,
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800105 [ARB_ERR_CAP_CLR] = 0x168,
106 [ARB_ERR_CAP_HI_ADDR] = -1,
107 [ARB_ERR_CAP_ADDR] = 0x16c,
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800108 [ARB_ERR_CAP_STATUS] = 0x174,
109 [ARB_ERR_CAP_MASTER] = 0x178,
110};
111
Kevin Cernekeef8083582014-11-25 16:49:51 -0800112static const int gisb_offsets_bcm7445[] = {
113 [ARB_TIMER] = 0x008,
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700114 [ARB_BP_CAP_CLR] = 0x010,
115 [ARB_BP_CAP_HI_ADDR] = -1,
116 [ARB_BP_CAP_ADDR] = 0x1d8,
117 [ARB_BP_CAP_STATUS] = 0x1e0,
118 [ARB_BP_CAP_MASTER] = 0x1e4,
Kevin Cernekeef8083582014-11-25 16:49:51 -0800119 [ARB_ERR_CAP_CLR] = 0x7e4,
120 [ARB_ERR_CAP_HI_ADDR] = 0x7e8,
121 [ARB_ERR_CAP_ADDR] = 0x7ec,
Kevin Cernekeef8083582014-11-25 16:49:51 -0800122 [ARB_ERR_CAP_STATUS] = 0x7f4,
123 [ARB_ERR_CAP_MASTER] = 0x7f8,
124};
Florian Fainelli44127b72014-05-19 13:05:59 -0700125
126struct brcmstb_gisb_arb_device {
127 void __iomem *base;
Kevin Cernekeef8083582014-11-25 16:49:51 -0800128 const int *gisb_offsets;
Kevin Cernekeefbf4e262014-11-25 16:49:53 -0800129 bool big_endian;
Florian Fainelli44127b72014-05-19 13:05:59 -0700130 struct mutex lock;
131 struct list_head next;
132 u32 valid_mask;
133 const char *master_names[sizeof(u32) * BITS_PER_BYTE];
Florian Fainelli203bb852014-09-18 12:37:14 -0700134 u32 saved_timeout;
Florian Fainelli44127b72014-05-19 13:05:59 -0700135};
136
137static LIST_HEAD(brcmstb_gisb_arb_device_list);
138
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800139static u32 gisb_read(struct brcmstb_gisb_arb_device *gdev, int reg)
140{
Kevin Cernekeef8083582014-11-25 16:49:51 -0800141 int offset = gdev->gisb_offsets[reg];
142
Doug Berger0c2aa0e2017-03-29 17:29:10 -0700143 if (offset < 0) {
144 /* return 1 if the hardware doesn't have ARB_ERR_CAP_MASTER */
145 if (reg == ARB_ERR_CAP_MASTER)
146 return 1;
147 else
148 return 0;
149 }
Kevin Cernekeef8083582014-11-25 16:49:51 -0800150
Kevin Cernekeefbf4e262014-11-25 16:49:53 -0800151 if (gdev->big_endian)
152 return ioread32be(gdev->base + offset);
153 else
154 return ioread32(gdev->base + offset);
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800155}
156
Doug Berger0c2aa0e2017-03-29 17:29:10 -0700157static u64 gisb_read_address(struct brcmstb_gisb_arb_device *gdev)
158{
159 u64 value;
160
161 value = gisb_read(gdev, ARB_ERR_CAP_ADDR);
162 value |= (u64)gisb_read(gdev, ARB_ERR_CAP_HI_ADDR) << 32;
163
164 return value;
165}
166
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700167static u64 gisb_read_bp_address(struct brcmstb_gisb_arb_device *gdev)
168{
169 u64 value;
170
171 value = gisb_read(gdev, ARB_BP_CAP_ADDR);
172 value |= (u64)gisb_read(gdev, ARB_BP_CAP_HI_ADDR) << 32;
173
174 return value;
175}
176
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800177static void gisb_write(struct brcmstb_gisb_arb_device *gdev, u32 val, int reg)
178{
Kevin Cernekeef8083582014-11-25 16:49:51 -0800179 int offset = gdev->gisb_offsets[reg];
180
181 if (offset == -1)
182 return;
Kevin Cernekeefbf4e262014-11-25 16:49:53 -0800183
184 if (gdev->big_endian)
Doug Berger856c7cc2017-03-29 17:29:09 -0700185 iowrite32be(val, gdev->base + offset);
Kevin Cernekeefbf4e262014-11-25 16:49:53 -0800186 else
Doug Berger856c7cc2017-03-29 17:29:09 -0700187 iowrite32(val, gdev->base + offset);
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800188}
189
Florian Fainelli44127b72014-05-19 13:05:59 -0700190static ssize_t gisb_arb_get_timeout(struct device *dev,
191 struct device_attribute *attr,
192 char *buf)
193{
Wolfram Sang0810d5c2018-10-21 21:59:58 +0200194 struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev);
Florian Fainelli44127b72014-05-19 13:05:59 -0700195 u32 timeout;
196
197 mutex_lock(&gdev->lock);
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800198 timeout = gisb_read(gdev, ARB_TIMER);
Florian Fainelli44127b72014-05-19 13:05:59 -0700199 mutex_unlock(&gdev->lock);
200
201 return sprintf(buf, "%d", timeout);
202}
203
204static ssize_t gisb_arb_set_timeout(struct device *dev,
205 struct device_attribute *attr,
206 const char *buf, size_t count)
207{
Wolfram Sang0810d5c2018-10-21 21:59:58 +0200208 struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev);
Florian Fainelli44127b72014-05-19 13:05:59 -0700209 int val, ret;
210
211 ret = kstrtoint(buf, 10, &val);
212 if (ret < 0)
213 return ret;
214
215 if (val == 0 || val >= 0xffffffff)
216 return -EINVAL;
217
218 mutex_lock(&gdev->lock);
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800219 gisb_write(gdev, val, ARB_TIMER);
Florian Fainelli44127b72014-05-19 13:05:59 -0700220 mutex_unlock(&gdev->lock);
221
222 return count;
223}
224
225static const char *
226brcmstb_gisb_master_to_str(struct brcmstb_gisb_arb_device *gdev,
227 u32 masters)
228{
229 u32 mask = gdev->valid_mask & masters;
230
231 if (hweight_long(mask) != 1)
232 return NULL;
233
234 return gdev->master_names[ffs(mask) - 1];
235}
236
237static int brcmstb_gisb_arb_decode_addr(struct brcmstb_gisb_arb_device *gdev,
238 const char *reason)
239{
240 u32 cap_status;
Doug Berger0c2aa0e2017-03-29 17:29:10 -0700241 u64 arb_addr;
Florian Fainelli44127b72014-05-19 13:05:59 -0700242 u32 master;
243 const char *m_name;
244 char m_fmt[11];
245
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800246 cap_status = gisb_read(gdev, ARB_ERR_CAP_STATUS);
Florian Fainelli44127b72014-05-19 13:05:59 -0700247
248 /* Invalid captured address, bail out */
249 if (!(cap_status & ARB_ERR_CAP_STATUS_VALID))
250 return 1;
251
252 /* Read the address and master */
Doug Berger0c2aa0e2017-03-29 17:29:10 -0700253 arb_addr = gisb_read_address(gdev);
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800254 master = gisb_read(gdev, ARB_ERR_CAP_MASTER);
Florian Fainelli44127b72014-05-19 13:05:59 -0700255
256 m_name = brcmstb_gisb_master_to_str(gdev, master);
257 if (!m_name) {
258 snprintf(m_fmt, sizeof(m_fmt), "0x%08x", master);
259 m_name = m_fmt;
260 }
261
Florian Fainellic9864df2017-11-27 12:55:36 -0800262 pr_crit("GISB: %s at 0x%llx [%c %s], core: %s\n",
263 reason, arb_addr,
Florian Fainelli44127b72014-05-19 13:05:59 -0700264 cap_status & ARB_ERR_CAP_STATUS_WRITE ? 'W' : 'R',
265 cap_status & ARB_ERR_CAP_STATUS_TIMEOUT ? "timeout" : "",
266 m_name);
267
268 /* clear the GISB error */
Kevin Cernekee2b53ead2014-11-25 16:49:50 -0800269 gisb_write(gdev, ARB_ERR_CAP_CLEAR, ARB_ERR_CAP_CLR);
Florian Fainelli44127b72014-05-19 13:05:59 -0700270
271 return 0;
272}
273
Florian Fainellic400d5e2016-01-31 12:29:27 -0800274#ifdef CONFIG_MIPS
275static int brcmstb_bus_error_handler(struct pt_regs *regs, int is_fixup)
276{
277 int ret = 0;
278 struct brcmstb_gisb_arb_device *gdev;
279 u32 cap_status;
280
281 list_for_each_entry(gdev, &brcmstb_gisb_arb_device_list, next) {
282 cap_status = gisb_read(gdev, ARB_ERR_CAP_STATUS);
283
284 /* Invalid captured address, bail out */
285 if (!(cap_status & ARB_ERR_CAP_STATUS_VALID)) {
286 is_fixup = 1;
287 goto out;
288 }
289
290 ret |= brcmstb_gisb_arb_decode_addr(gdev, "bus error");
291 }
292out:
293 return is_fixup ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
294}
295#endif
296
Florian Fainelli44127b72014-05-19 13:05:59 -0700297static irqreturn_t brcmstb_gisb_timeout_handler(int irq, void *dev_id)
298{
299 brcmstb_gisb_arb_decode_addr(dev_id, "timeout");
300
301 return IRQ_HANDLED;
302}
303
304static irqreturn_t brcmstb_gisb_tea_handler(int irq, void *dev_id)
305{
306 brcmstb_gisb_arb_decode_addr(dev_id, "target abort");
307
308 return IRQ_HANDLED;
309}
310
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700311static irqreturn_t brcmstb_gisb_bp_handler(int irq, void *dev_id)
312{
313 struct brcmstb_gisb_arb_device *gdev = dev_id;
314 const char *m_name;
315 u32 bp_status;
316 u64 arb_addr;
317 u32 master;
318 char m_fmt[11];
319
320 bp_status = gisb_read(gdev, ARB_BP_CAP_STATUS);
321
322 /* Invalid captured address, bail out */
323 if (!(bp_status & ARB_BP_CAP_STATUS_VALID))
324 return IRQ_HANDLED;
325
326 /* Read the address and master */
327 arb_addr = gisb_read_bp_address(gdev);
328 master = gisb_read(gdev, ARB_BP_CAP_MASTER);
329
330 m_name = brcmstb_gisb_master_to_str(gdev, master);
331 if (!m_name) {
332 snprintf(m_fmt, sizeof(m_fmt), "0x%08x", master);
333 m_name = m_fmt;
334 }
335
336 pr_crit("GISB: breakpoint at 0x%llx [%c], core: %s\n",
337 arb_addr, bp_status & ARB_BP_CAP_STATUS_WRITE ? 'W' : 'R',
338 m_name);
339
340 /* clear the GISB error */
341 gisb_write(gdev, ARB_ERR_CAP_CLEAR, ARB_ERR_CAP_CLR);
342
343 return IRQ_HANDLED;
344}
345
Doug Berger9eb60882017-03-29 17:29:11 -0700346/*
347 * Dump out gisb errors on die or panic.
348 */
349static int dump_gisb_error(struct notifier_block *self, unsigned long v,
350 void *p);
351
352static struct notifier_block gisb_die_notifier = {
353 .notifier_call = dump_gisb_error,
354};
355
356static struct notifier_block gisb_panic_notifier = {
357 .notifier_call = dump_gisb_error,
358};
359
360static int dump_gisb_error(struct notifier_block *self, unsigned long v,
361 void *p)
362{
363 struct brcmstb_gisb_arb_device *gdev;
364 const char *reason = "panic";
365
366 if (self == &gisb_die_notifier)
367 reason = "die";
368
369 /* iterate over each GISB arb registered handlers */
370 list_for_each_entry(gdev, &brcmstb_gisb_arb_device_list, next)
371 brcmstb_gisb_arb_decode_addr(gdev, reason);
372
373 return NOTIFY_DONE;
374}
375
Florian Fainelli44127b72014-05-19 13:05:59 -0700376static DEVICE_ATTR(gisb_arb_timeout, S_IWUSR | S_IRUGO,
377 gisb_arb_get_timeout, gisb_arb_set_timeout);
378
379static struct attribute *gisb_arb_sysfs_attrs[] = {
380 &dev_attr_gisb_arb_timeout.attr,
381 NULL,
382};
383
384static struct attribute_group gisb_arb_sysfs_attr_group = {
385 .attrs = gisb_arb_sysfs_attrs,
386};
387
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800388static const struct of_device_id brcmstb_gisb_arb_of_match[] = {
389 { .compatible = "brcm,gisb-arb", .data = gisb_offsets_bcm7445 },
390 { .compatible = "brcm,bcm7445-gisb-arb", .data = gisb_offsets_bcm7445 },
391 { .compatible = "brcm,bcm7435-gisb-arb", .data = gisb_offsets_bcm7435 },
392 { .compatible = "brcm,bcm7400-gisb-arb", .data = gisb_offsets_bcm7400 },
Doug Bergerd523e0c2017-03-29 17:29:14 -0700393 { .compatible = "brcm,bcm7278-gisb-arb", .data = gisb_offsets_bcm7278 },
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800394 { .compatible = "brcm,bcm7038-gisb-arb", .data = gisb_offsets_bcm7038 },
395 { },
396};
397
Florian Fainelli2e8a29a2014-11-20 10:14:46 -0800398static int __init brcmstb_gisb_arb_probe(struct platform_device *pdev)
Florian Fainelli44127b72014-05-19 13:05:59 -0700399{
400 struct device_node *dn = pdev->dev.of_node;
401 struct brcmstb_gisb_arb_device *gdev;
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800402 const struct of_device_id *of_id;
Florian Fainelli44127b72014-05-19 13:05:59 -0700403 struct resource *r;
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700404 int err, timeout_irq, tea_irq, bp_irq;
Florian Fainelli44127b72014-05-19 13:05:59 -0700405 unsigned int num_masters, j = 0;
406 int i, first, last;
407
408 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
409 timeout_irq = platform_get_irq(pdev, 0);
410 tea_irq = platform_get_irq(pdev, 1);
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700411 bp_irq = platform_get_irq(pdev, 2);
Florian Fainelli44127b72014-05-19 13:05:59 -0700412
413 gdev = devm_kzalloc(&pdev->dev, sizeof(*gdev), GFP_KERNEL);
414 if (!gdev)
415 return -ENOMEM;
416
417 mutex_init(&gdev->lock);
418 INIT_LIST_HEAD(&gdev->next);
419
Jingoo Hanc9d53c02014-06-11 14:00:05 +0900420 gdev->base = devm_ioremap_resource(&pdev->dev, r);
421 if (IS_ERR(gdev->base))
422 return PTR_ERR(gdev->base);
Florian Fainelli44127b72014-05-19 13:05:59 -0700423
Kevin Cernekeed1d67862014-11-25 16:49:52 -0800424 of_id = of_match_node(brcmstb_gisb_arb_of_match, dn);
425 if (!of_id) {
426 pr_err("failed to look up compatible string\n");
427 return -EINVAL;
428 }
429 gdev->gisb_offsets = of_id->data;
Kevin Cernekeefbf4e262014-11-25 16:49:53 -0800430 gdev->big_endian = of_device_is_big_endian(dn);
Kevin Cernekeef8083582014-11-25 16:49:51 -0800431
Florian Fainelli44127b72014-05-19 13:05:59 -0700432 err = devm_request_irq(&pdev->dev, timeout_irq,
433 brcmstb_gisb_timeout_handler, 0, pdev->name,
434 gdev);
435 if (err < 0)
436 return err;
437
438 err = devm_request_irq(&pdev->dev, tea_irq,
439 brcmstb_gisb_tea_handler, 0, pdev->name,
440 gdev);
441 if (err < 0)
442 return err;
443
Florian Fainellifb8a0b82020-04-17 17:21:32 -0700444 /* Interrupt is optional */
445 if (bp_irq > 0) {
446 err = devm_request_irq(&pdev->dev, bp_irq,
447 brcmstb_gisb_bp_handler, 0, pdev->name,
448 gdev);
449 if (err < 0)
450 return err;
451 }
452
Florian Fainelli44127b72014-05-19 13:05:59 -0700453 /* If we do not have a valid mask, assume all masters are enabled */
454 if (of_property_read_u32(dn, "brcm,gisb-arb-master-mask",
455 &gdev->valid_mask))
456 gdev->valid_mask = 0xffffffff;
457
458 /* Proceed with reading the litteral names if we agree on the
459 * number of masters
460 */
461 num_masters = of_property_count_strings(dn,
462 "brcm,gisb-arb-master-names");
463 if (hweight_long(gdev->valid_mask) == num_masters) {
464 first = ffs(gdev->valid_mask) - 1;
465 last = fls(gdev->valid_mask) - 1;
466
467 for (i = first; i < last; i++) {
468 if (!(gdev->valid_mask & BIT(i)))
469 continue;
470
471 of_property_read_string_index(dn,
472 "brcm,gisb-arb-master-names", j,
473 &gdev->master_names[i]);
474 j++;
475 }
476 }
477
478 err = sysfs_create_group(&pdev->dev.kobj, &gisb_arb_sysfs_attr_group);
479 if (err)
480 return err;
481
482 platform_set_drvdata(pdev, gdev);
483
484 list_add_tail(&gdev->next, &brcmstb_gisb_arb_device_list);
485
Florian Fainellic400d5e2016-01-31 12:29:27 -0800486#ifdef CONFIG_MIPS
487 board_be_handler = brcmstb_bus_error_handler;
488#endif
Florian Fainellif1bee782014-09-18 12:32:10 -0700489
Doug Berger9eb60882017-03-29 17:29:11 -0700490 if (list_is_singular(&brcmstb_gisb_arb_device_list)) {
491 register_die_notifier(&gisb_die_notifier);
492 atomic_notifier_chain_register(&panic_notifier_list,
493 &gisb_panic_notifier);
494 }
495
Florian Fainelli30879742019-03-20 12:40:56 -0700496 dev_info(&pdev->dev, "registered irqs: %d, %d\n",
497 timeout_irq, tea_irq);
Florian Fainelli44127b72014-05-19 13:05:59 -0700498
499 return 0;
500}
501
Florian Fainelli203bb852014-09-18 12:37:14 -0700502#ifdef CONFIG_PM_SLEEP
503static int brcmstb_gisb_arb_suspend(struct device *dev)
504{
Wolfram Sang0810d5c2018-10-21 21:59:58 +0200505 struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev);
Florian Fainelli203bb852014-09-18 12:37:14 -0700506
Arnd Bergmann71354662014-12-08 17:16:03 +0100507 gdev->saved_timeout = gisb_read(gdev, ARB_TIMER);
Florian Fainelli203bb852014-09-18 12:37:14 -0700508
509 return 0;
510}
511
512/* Make sure we provide the same timeout value that was configured before, and
513 * do this before the GISB timeout interrupt handler has any chance to run.
514 */
515static int brcmstb_gisb_arb_resume_noirq(struct device *dev)
516{
Wolfram Sang0810d5c2018-10-21 21:59:58 +0200517 struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev);
Florian Fainelli203bb852014-09-18 12:37:14 -0700518
Arnd Bergmann71354662014-12-08 17:16:03 +0100519 gisb_write(gdev, gdev->saved_timeout, ARB_TIMER);
Florian Fainelli203bb852014-09-18 12:37:14 -0700520
521 return 0;
522}
523#else
524#define brcmstb_gisb_arb_suspend NULL
525#define brcmstb_gisb_arb_resume_noirq NULL
526#endif
527
528static const struct dev_pm_ops brcmstb_gisb_arb_pm_ops = {
529 .suspend = brcmstb_gisb_arb_suspend,
530 .resume_noirq = brcmstb_gisb_arb_resume_noirq,
531};
532
Florian Fainelli44127b72014-05-19 13:05:59 -0700533static struct platform_driver brcmstb_gisb_arb_driver = {
Florian Fainelli44127b72014-05-19 13:05:59 -0700534 .driver = {
535 .name = "brcm-gisb-arb",
Florian Fainelli44127b72014-05-19 13:05:59 -0700536 .of_match_table = brcmstb_gisb_arb_of_match,
Florian Fainelli203bb852014-09-18 12:37:14 -0700537 .pm = &brcmstb_gisb_arb_pm_ops,
Florian Fainelli44127b72014-05-19 13:05:59 -0700538 },
539};
540
541static int __init brcm_gisb_driver_init(void)
542{
Florian Fainelli2e8a29a2014-11-20 10:14:46 -0800543 return platform_driver_probe(&brcmstb_gisb_arb_driver,
544 brcmstb_gisb_arb_probe);
Florian Fainelli44127b72014-05-19 13:05:59 -0700545}
546
547module_init(brcm_gisb_driver_init);