Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 1 | /* |
Doug Berger | 856c7cc | 2017-03-29 17:29:09 -0700 | [diff] [blame] | 2 | * Copyright (C) 2014-2017 Broadcom |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/types.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/sysfs.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/of.h> |
| 25 | #include <linux/bitops.h> |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 26 | #include <linux/pm.h> |
Doug Berger | 9eb6088 | 2017-03-29 17:29:11 -0700 | [diff] [blame] | 27 | #include <linux/kernel.h> |
| 28 | #include <linux/kdebug.h> |
| 29 | #include <linux/notifier.h> |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 30 | |
Florian Fainelli | c400d5e | 2016-01-31 12:29:27 -0800 | [diff] [blame] | 31 | #ifdef CONFIG_MIPS |
| 32 | #include <asm/traps.h> |
| 33 | #endif |
| 34 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 35 | #define ARB_ERR_CAP_CLEAR (1 << 0) |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 36 | #define ARB_ERR_CAP_STATUS_TIMEOUT (1 << 12) |
| 37 | #define ARB_ERR_CAP_STATUS_TEA (1 << 11) |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 38 | #define ARB_ERR_CAP_STATUS_WRITE (1 << 1) |
| 39 | #define ARB_ERR_CAP_STATUS_VALID (1 << 0) |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 40 | |
| 41 | enum { |
| 42 | ARB_TIMER, |
| 43 | ARB_ERR_CAP_CLR, |
| 44 | ARB_ERR_CAP_HI_ADDR, |
| 45 | ARB_ERR_CAP_ADDR, |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 46 | ARB_ERR_CAP_STATUS, |
| 47 | ARB_ERR_CAP_MASTER, |
| 48 | }; |
| 49 | |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 50 | static const int gisb_offsets_bcm7038[] = { |
| 51 | [ARB_TIMER] = 0x00c, |
| 52 | [ARB_ERR_CAP_CLR] = 0x0c4, |
| 53 | [ARB_ERR_CAP_HI_ADDR] = -1, |
| 54 | [ARB_ERR_CAP_ADDR] = 0x0c8, |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 55 | [ARB_ERR_CAP_STATUS] = 0x0d0, |
| 56 | [ARB_ERR_CAP_MASTER] = -1, |
| 57 | }; |
| 58 | |
Doug Berger | d523e0c | 2017-03-29 17:29:14 -0700 | [diff] [blame] | 59 | static const int gisb_offsets_bcm7278[] = { |
| 60 | [ARB_TIMER] = 0x008, |
| 61 | [ARB_ERR_CAP_CLR] = 0x7f8, |
| 62 | [ARB_ERR_CAP_HI_ADDR] = -1, |
| 63 | [ARB_ERR_CAP_ADDR] = 0x7e0, |
| 64 | [ARB_ERR_CAP_STATUS] = 0x7f0, |
| 65 | [ARB_ERR_CAP_MASTER] = 0x7f4, |
| 66 | }; |
| 67 | |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 68 | static const int gisb_offsets_bcm7400[] = { |
| 69 | [ARB_TIMER] = 0x00c, |
| 70 | [ARB_ERR_CAP_CLR] = 0x0c8, |
| 71 | [ARB_ERR_CAP_HI_ADDR] = -1, |
| 72 | [ARB_ERR_CAP_ADDR] = 0x0cc, |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 73 | [ARB_ERR_CAP_STATUS] = 0x0d4, |
| 74 | [ARB_ERR_CAP_MASTER] = 0x0d8, |
| 75 | }; |
| 76 | |
| 77 | static const int gisb_offsets_bcm7435[] = { |
| 78 | [ARB_TIMER] = 0x00c, |
| 79 | [ARB_ERR_CAP_CLR] = 0x168, |
| 80 | [ARB_ERR_CAP_HI_ADDR] = -1, |
| 81 | [ARB_ERR_CAP_ADDR] = 0x16c, |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 82 | [ARB_ERR_CAP_STATUS] = 0x174, |
| 83 | [ARB_ERR_CAP_MASTER] = 0x178, |
| 84 | }; |
| 85 | |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 86 | static const int gisb_offsets_bcm7445[] = { |
| 87 | [ARB_TIMER] = 0x008, |
| 88 | [ARB_ERR_CAP_CLR] = 0x7e4, |
| 89 | [ARB_ERR_CAP_HI_ADDR] = 0x7e8, |
| 90 | [ARB_ERR_CAP_ADDR] = 0x7ec, |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 91 | [ARB_ERR_CAP_STATUS] = 0x7f4, |
| 92 | [ARB_ERR_CAP_MASTER] = 0x7f8, |
| 93 | }; |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 94 | |
| 95 | struct brcmstb_gisb_arb_device { |
| 96 | void __iomem *base; |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 97 | const int *gisb_offsets; |
Kevin Cernekee | fbf4e26 | 2014-11-25 16:49:53 -0800 | [diff] [blame] | 98 | bool big_endian; |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 99 | struct mutex lock; |
| 100 | struct list_head next; |
| 101 | u32 valid_mask; |
| 102 | const char *master_names[sizeof(u32) * BITS_PER_BYTE]; |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 103 | u32 saved_timeout; |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static LIST_HEAD(brcmstb_gisb_arb_device_list); |
| 107 | |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 108 | static u32 gisb_read(struct brcmstb_gisb_arb_device *gdev, int reg) |
| 109 | { |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 110 | int offset = gdev->gisb_offsets[reg]; |
| 111 | |
Doug Berger | 0c2aa0e | 2017-03-29 17:29:10 -0700 | [diff] [blame] | 112 | if (offset < 0) { |
| 113 | /* return 1 if the hardware doesn't have ARB_ERR_CAP_MASTER */ |
| 114 | if (reg == ARB_ERR_CAP_MASTER) |
| 115 | return 1; |
| 116 | else |
| 117 | return 0; |
| 118 | } |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 119 | |
Kevin Cernekee | fbf4e26 | 2014-11-25 16:49:53 -0800 | [diff] [blame] | 120 | if (gdev->big_endian) |
| 121 | return ioread32be(gdev->base + offset); |
| 122 | else |
| 123 | return ioread32(gdev->base + offset); |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Doug Berger | 0c2aa0e | 2017-03-29 17:29:10 -0700 | [diff] [blame] | 126 | static u64 gisb_read_address(struct brcmstb_gisb_arb_device *gdev) |
| 127 | { |
| 128 | u64 value; |
| 129 | |
| 130 | value = gisb_read(gdev, ARB_ERR_CAP_ADDR); |
| 131 | value |= (u64)gisb_read(gdev, ARB_ERR_CAP_HI_ADDR) << 32; |
| 132 | |
| 133 | return value; |
| 134 | } |
| 135 | |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 136 | static void gisb_write(struct brcmstb_gisb_arb_device *gdev, u32 val, int reg) |
| 137 | { |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 138 | int offset = gdev->gisb_offsets[reg]; |
| 139 | |
| 140 | if (offset == -1) |
| 141 | return; |
Kevin Cernekee | fbf4e26 | 2014-11-25 16:49:53 -0800 | [diff] [blame] | 142 | |
| 143 | if (gdev->big_endian) |
Doug Berger | 856c7cc | 2017-03-29 17:29:09 -0700 | [diff] [blame] | 144 | iowrite32be(val, gdev->base + offset); |
Kevin Cernekee | fbf4e26 | 2014-11-25 16:49:53 -0800 | [diff] [blame] | 145 | else |
Doug Berger | 856c7cc | 2017-03-29 17:29:09 -0700 | [diff] [blame] | 146 | iowrite32(val, gdev->base + offset); |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 149 | static ssize_t gisb_arb_get_timeout(struct device *dev, |
| 150 | struct device_attribute *attr, |
| 151 | char *buf) |
| 152 | { |
Wolfram Sang | 0810d5c | 2018-10-21 21:59:58 +0200 | [diff] [blame] | 153 | struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 154 | u32 timeout; |
| 155 | |
| 156 | mutex_lock(&gdev->lock); |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 157 | timeout = gisb_read(gdev, ARB_TIMER); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 158 | mutex_unlock(&gdev->lock); |
| 159 | |
| 160 | return sprintf(buf, "%d", timeout); |
| 161 | } |
| 162 | |
| 163 | static ssize_t gisb_arb_set_timeout(struct device *dev, |
| 164 | struct device_attribute *attr, |
| 165 | const char *buf, size_t count) |
| 166 | { |
Wolfram Sang | 0810d5c | 2018-10-21 21:59:58 +0200 | [diff] [blame] | 167 | struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 168 | int val, ret; |
| 169 | |
| 170 | ret = kstrtoint(buf, 10, &val); |
| 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | |
| 174 | if (val == 0 || val >= 0xffffffff) |
| 175 | return -EINVAL; |
| 176 | |
| 177 | mutex_lock(&gdev->lock); |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 178 | gisb_write(gdev, val, ARB_TIMER); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 179 | mutex_unlock(&gdev->lock); |
| 180 | |
| 181 | return count; |
| 182 | } |
| 183 | |
| 184 | static const char * |
| 185 | brcmstb_gisb_master_to_str(struct brcmstb_gisb_arb_device *gdev, |
| 186 | u32 masters) |
| 187 | { |
| 188 | u32 mask = gdev->valid_mask & masters; |
| 189 | |
| 190 | if (hweight_long(mask) != 1) |
| 191 | return NULL; |
| 192 | |
| 193 | return gdev->master_names[ffs(mask) - 1]; |
| 194 | } |
| 195 | |
| 196 | static int brcmstb_gisb_arb_decode_addr(struct brcmstb_gisb_arb_device *gdev, |
| 197 | const char *reason) |
| 198 | { |
| 199 | u32 cap_status; |
Doug Berger | 0c2aa0e | 2017-03-29 17:29:10 -0700 | [diff] [blame] | 200 | u64 arb_addr; |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 201 | u32 master; |
| 202 | const char *m_name; |
| 203 | char m_fmt[11]; |
| 204 | |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 205 | cap_status = gisb_read(gdev, ARB_ERR_CAP_STATUS); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 206 | |
| 207 | /* Invalid captured address, bail out */ |
| 208 | if (!(cap_status & ARB_ERR_CAP_STATUS_VALID)) |
| 209 | return 1; |
| 210 | |
| 211 | /* Read the address and master */ |
Doug Berger | 0c2aa0e | 2017-03-29 17:29:10 -0700 | [diff] [blame] | 212 | arb_addr = gisb_read_address(gdev); |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 213 | master = gisb_read(gdev, ARB_ERR_CAP_MASTER); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 214 | |
| 215 | m_name = brcmstb_gisb_master_to_str(gdev, master); |
| 216 | if (!m_name) { |
| 217 | snprintf(m_fmt, sizeof(m_fmt), "0x%08x", master); |
| 218 | m_name = m_fmt; |
| 219 | } |
| 220 | |
Doug Berger | 0c2aa0e | 2017-03-29 17:29:10 -0700 | [diff] [blame] | 221 | pr_crit("%s: %s at 0x%llx [%c %s], core: %s\n", |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 222 | __func__, reason, arb_addr, |
| 223 | cap_status & ARB_ERR_CAP_STATUS_WRITE ? 'W' : 'R', |
| 224 | cap_status & ARB_ERR_CAP_STATUS_TIMEOUT ? "timeout" : "", |
| 225 | m_name); |
| 226 | |
| 227 | /* clear the GISB error */ |
Kevin Cernekee | 2b53ead | 2014-11-25 16:49:50 -0800 | [diff] [blame] | 228 | gisb_write(gdev, ARB_ERR_CAP_CLEAR, ARB_ERR_CAP_CLR); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
Florian Fainelli | c400d5e | 2016-01-31 12:29:27 -0800 | [diff] [blame] | 233 | #ifdef CONFIG_MIPS |
| 234 | static int brcmstb_bus_error_handler(struct pt_regs *regs, int is_fixup) |
| 235 | { |
| 236 | int ret = 0; |
| 237 | struct brcmstb_gisb_arb_device *gdev; |
| 238 | u32 cap_status; |
| 239 | |
| 240 | list_for_each_entry(gdev, &brcmstb_gisb_arb_device_list, next) { |
| 241 | cap_status = gisb_read(gdev, ARB_ERR_CAP_STATUS); |
| 242 | |
| 243 | /* Invalid captured address, bail out */ |
| 244 | if (!(cap_status & ARB_ERR_CAP_STATUS_VALID)) { |
| 245 | is_fixup = 1; |
| 246 | goto out; |
| 247 | } |
| 248 | |
| 249 | ret |= brcmstb_gisb_arb_decode_addr(gdev, "bus error"); |
| 250 | } |
| 251 | out: |
| 252 | return is_fixup ? MIPS_BE_FIXUP : MIPS_BE_FATAL; |
| 253 | } |
| 254 | #endif |
| 255 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 256 | static irqreturn_t brcmstb_gisb_timeout_handler(int irq, void *dev_id) |
| 257 | { |
| 258 | brcmstb_gisb_arb_decode_addr(dev_id, "timeout"); |
| 259 | |
| 260 | return IRQ_HANDLED; |
| 261 | } |
| 262 | |
| 263 | static irqreturn_t brcmstb_gisb_tea_handler(int irq, void *dev_id) |
| 264 | { |
| 265 | brcmstb_gisb_arb_decode_addr(dev_id, "target abort"); |
| 266 | |
| 267 | return IRQ_HANDLED; |
| 268 | } |
| 269 | |
Doug Berger | 9eb6088 | 2017-03-29 17:29:11 -0700 | [diff] [blame] | 270 | /* |
| 271 | * Dump out gisb errors on die or panic. |
| 272 | */ |
| 273 | static int dump_gisb_error(struct notifier_block *self, unsigned long v, |
| 274 | void *p); |
| 275 | |
| 276 | static struct notifier_block gisb_die_notifier = { |
| 277 | .notifier_call = dump_gisb_error, |
| 278 | }; |
| 279 | |
| 280 | static struct notifier_block gisb_panic_notifier = { |
| 281 | .notifier_call = dump_gisb_error, |
| 282 | }; |
| 283 | |
| 284 | static int dump_gisb_error(struct notifier_block *self, unsigned long v, |
| 285 | void *p) |
| 286 | { |
| 287 | struct brcmstb_gisb_arb_device *gdev; |
| 288 | const char *reason = "panic"; |
| 289 | |
| 290 | if (self == &gisb_die_notifier) |
| 291 | reason = "die"; |
| 292 | |
| 293 | /* iterate over each GISB arb registered handlers */ |
| 294 | list_for_each_entry(gdev, &brcmstb_gisb_arb_device_list, next) |
| 295 | brcmstb_gisb_arb_decode_addr(gdev, reason); |
| 296 | |
| 297 | return NOTIFY_DONE; |
| 298 | } |
| 299 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 300 | static DEVICE_ATTR(gisb_arb_timeout, S_IWUSR | S_IRUGO, |
| 301 | gisb_arb_get_timeout, gisb_arb_set_timeout); |
| 302 | |
| 303 | static struct attribute *gisb_arb_sysfs_attrs[] = { |
| 304 | &dev_attr_gisb_arb_timeout.attr, |
| 305 | NULL, |
| 306 | }; |
| 307 | |
| 308 | static struct attribute_group gisb_arb_sysfs_attr_group = { |
| 309 | .attrs = gisb_arb_sysfs_attrs, |
| 310 | }; |
| 311 | |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 312 | static const struct of_device_id brcmstb_gisb_arb_of_match[] = { |
| 313 | { .compatible = "brcm,gisb-arb", .data = gisb_offsets_bcm7445 }, |
| 314 | { .compatible = "brcm,bcm7445-gisb-arb", .data = gisb_offsets_bcm7445 }, |
| 315 | { .compatible = "brcm,bcm7435-gisb-arb", .data = gisb_offsets_bcm7435 }, |
| 316 | { .compatible = "brcm,bcm7400-gisb-arb", .data = gisb_offsets_bcm7400 }, |
Doug Berger | d523e0c | 2017-03-29 17:29:14 -0700 | [diff] [blame] | 317 | { .compatible = "brcm,bcm7278-gisb-arb", .data = gisb_offsets_bcm7278 }, |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 318 | { .compatible = "brcm,bcm7038-gisb-arb", .data = gisb_offsets_bcm7038 }, |
| 319 | { }, |
| 320 | }; |
| 321 | |
Florian Fainelli | 2e8a29a | 2014-11-20 10:14:46 -0800 | [diff] [blame] | 322 | static int __init brcmstb_gisb_arb_probe(struct platform_device *pdev) |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 323 | { |
| 324 | struct device_node *dn = pdev->dev.of_node; |
| 325 | struct brcmstb_gisb_arb_device *gdev; |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 326 | const struct of_device_id *of_id; |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 327 | struct resource *r; |
| 328 | int err, timeout_irq, tea_irq; |
| 329 | unsigned int num_masters, j = 0; |
| 330 | int i, first, last; |
| 331 | |
| 332 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 333 | timeout_irq = platform_get_irq(pdev, 0); |
| 334 | tea_irq = platform_get_irq(pdev, 1); |
| 335 | |
| 336 | gdev = devm_kzalloc(&pdev->dev, sizeof(*gdev), GFP_KERNEL); |
| 337 | if (!gdev) |
| 338 | return -ENOMEM; |
| 339 | |
| 340 | mutex_init(&gdev->lock); |
| 341 | INIT_LIST_HEAD(&gdev->next); |
| 342 | |
Jingoo Han | c9d53c0 | 2014-06-11 14:00:05 +0900 | [diff] [blame] | 343 | gdev->base = devm_ioremap_resource(&pdev->dev, r); |
| 344 | if (IS_ERR(gdev->base)) |
| 345 | return PTR_ERR(gdev->base); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 346 | |
Kevin Cernekee | d1d6786 | 2014-11-25 16:49:52 -0800 | [diff] [blame] | 347 | of_id = of_match_node(brcmstb_gisb_arb_of_match, dn); |
| 348 | if (!of_id) { |
| 349 | pr_err("failed to look up compatible string\n"); |
| 350 | return -EINVAL; |
| 351 | } |
| 352 | gdev->gisb_offsets = of_id->data; |
Kevin Cernekee | fbf4e26 | 2014-11-25 16:49:53 -0800 | [diff] [blame] | 353 | gdev->big_endian = of_device_is_big_endian(dn); |
Kevin Cernekee | f808358 | 2014-11-25 16:49:51 -0800 | [diff] [blame] | 354 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 355 | err = devm_request_irq(&pdev->dev, timeout_irq, |
| 356 | brcmstb_gisb_timeout_handler, 0, pdev->name, |
| 357 | gdev); |
| 358 | if (err < 0) |
| 359 | return err; |
| 360 | |
| 361 | err = devm_request_irq(&pdev->dev, tea_irq, |
| 362 | brcmstb_gisb_tea_handler, 0, pdev->name, |
| 363 | gdev); |
| 364 | if (err < 0) |
| 365 | return err; |
| 366 | |
| 367 | /* If we do not have a valid mask, assume all masters are enabled */ |
| 368 | if (of_property_read_u32(dn, "brcm,gisb-arb-master-mask", |
| 369 | &gdev->valid_mask)) |
| 370 | gdev->valid_mask = 0xffffffff; |
| 371 | |
| 372 | /* Proceed with reading the litteral names if we agree on the |
| 373 | * number of masters |
| 374 | */ |
| 375 | num_masters = of_property_count_strings(dn, |
| 376 | "brcm,gisb-arb-master-names"); |
| 377 | if (hweight_long(gdev->valid_mask) == num_masters) { |
| 378 | first = ffs(gdev->valid_mask) - 1; |
| 379 | last = fls(gdev->valid_mask) - 1; |
| 380 | |
| 381 | for (i = first; i < last; i++) { |
| 382 | if (!(gdev->valid_mask & BIT(i))) |
| 383 | continue; |
| 384 | |
| 385 | of_property_read_string_index(dn, |
| 386 | "brcm,gisb-arb-master-names", j, |
| 387 | &gdev->master_names[i]); |
| 388 | j++; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | err = sysfs_create_group(&pdev->dev.kobj, &gisb_arb_sysfs_attr_group); |
| 393 | if (err) |
| 394 | return err; |
| 395 | |
| 396 | platform_set_drvdata(pdev, gdev); |
| 397 | |
| 398 | list_add_tail(&gdev->next, &brcmstb_gisb_arb_device_list); |
| 399 | |
Florian Fainelli | c400d5e | 2016-01-31 12:29:27 -0800 | [diff] [blame] | 400 | #ifdef CONFIG_MIPS |
| 401 | board_be_handler = brcmstb_bus_error_handler; |
| 402 | #endif |
Florian Fainelli | f1bee78 | 2014-09-18 12:32:10 -0700 | [diff] [blame] | 403 | |
Doug Berger | 9eb6088 | 2017-03-29 17:29:11 -0700 | [diff] [blame] | 404 | if (list_is_singular(&brcmstb_gisb_arb_device_list)) { |
| 405 | register_die_notifier(&gisb_die_notifier); |
| 406 | atomic_notifier_chain_register(&panic_notifier_list, |
| 407 | &gisb_panic_notifier); |
| 408 | } |
| 409 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 410 | dev_info(&pdev->dev, "registered mem: %p, irqs: %d, %d\n", |
| 411 | gdev->base, timeout_irq, tea_irq); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 416 | #ifdef CONFIG_PM_SLEEP |
| 417 | static int brcmstb_gisb_arb_suspend(struct device *dev) |
| 418 | { |
Wolfram Sang | 0810d5c | 2018-10-21 21:59:58 +0200 | [diff] [blame] | 419 | struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev); |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 420 | |
Arnd Bergmann | 7135466 | 2014-12-08 17:16:03 +0100 | [diff] [blame] | 421 | gdev->saved_timeout = gisb_read(gdev, ARB_TIMER); |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /* Make sure we provide the same timeout value that was configured before, and |
| 427 | * do this before the GISB timeout interrupt handler has any chance to run. |
| 428 | */ |
| 429 | static int brcmstb_gisb_arb_resume_noirq(struct device *dev) |
| 430 | { |
Wolfram Sang | 0810d5c | 2018-10-21 21:59:58 +0200 | [diff] [blame] | 431 | struct brcmstb_gisb_arb_device *gdev = dev_get_drvdata(dev); |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 432 | |
Arnd Bergmann | 7135466 | 2014-12-08 17:16:03 +0100 | [diff] [blame] | 433 | gisb_write(gdev, gdev->saved_timeout, ARB_TIMER); |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | #else |
| 438 | #define brcmstb_gisb_arb_suspend NULL |
| 439 | #define brcmstb_gisb_arb_resume_noirq NULL |
| 440 | #endif |
| 441 | |
| 442 | static const struct dev_pm_ops brcmstb_gisb_arb_pm_ops = { |
| 443 | .suspend = brcmstb_gisb_arb_suspend, |
| 444 | .resume_noirq = brcmstb_gisb_arb_resume_noirq, |
| 445 | }; |
| 446 | |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 447 | static struct platform_driver brcmstb_gisb_arb_driver = { |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 448 | .driver = { |
| 449 | .name = "brcm-gisb-arb", |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 450 | .of_match_table = brcmstb_gisb_arb_of_match, |
Florian Fainelli | 203bb85 | 2014-09-18 12:37:14 -0700 | [diff] [blame] | 451 | .pm = &brcmstb_gisb_arb_pm_ops, |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 452 | }, |
| 453 | }; |
| 454 | |
| 455 | static int __init brcm_gisb_driver_init(void) |
| 456 | { |
Florian Fainelli | 2e8a29a | 2014-11-20 10:14:46 -0800 | [diff] [blame] | 457 | return platform_driver_probe(&brcmstb_gisb_arb_driver, |
| 458 | brcmstb_gisb_arb_probe); |
Florian Fainelli | 44127b7 | 2014-05-19 13:05:59 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | module_init(brcm_gisb_driver_init); |