| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Bus & driver management routines for devices within |
|---|
| 3 | 4 | * a MacIO ASIC. Interface to new driver model mostly |
|---|
| 4 | 5 | * stolen from the PCI version. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org) |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or |
|---|
| 9 | | - * modify it under the terms of the GNU General Public License |
|---|
| 10 | | - * as published by the Free Software Foundation; either version |
|---|
| 11 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 12 | 8 | * |
|---|
| 13 | 9 | * TODO: |
|---|
| 14 | 10 | * |
|---|
| .. | .. |
|---|
| 190 | 186 | return 0; |
|---|
| 191 | 187 | |
|---|
| 192 | 188 | /* Grand Central has too large resource 0 on some machines */ |
|---|
| 193 | | - if (index == 0 && !strcmp(np->name, "gc")) |
|---|
| 189 | + if (index == 0 && of_node_name_eq(np, "gc")) |
|---|
| 194 | 190 | res->end = res->start + 0x1ffff; |
|---|
| 195 | 191 | |
|---|
| 196 | 192 | /* Airport has bogus resource 2 */ |
|---|
| 197 | | - if (index >= 2 && !strcmp(np->name, "radio")) |
|---|
| 193 | + if (index >= 2 && of_node_name_eq(np, "radio")) |
|---|
| 198 | 194 | return 1; |
|---|
| 199 | 195 | |
|---|
| 200 | 196 | #ifndef CONFIG_PPC64 |
|---|
| .. | .. |
|---|
| 207 | 203 | * level of hierarchy, but I don't really feel the need |
|---|
| 208 | 204 | * for it |
|---|
| 209 | 205 | */ |
|---|
| 210 | | - if (!strcmp(np->name, "escc")) |
|---|
| 206 | + if (of_node_name_eq(np, "escc")) |
|---|
| 211 | 207 | return 1; |
|---|
| 212 | 208 | |
|---|
| 213 | 209 | /* ESCC has bogus resources >= 3 */ |
|---|
| 214 | | - if (index >= 3 && !(strcmp(np->name, "ch-a") && |
|---|
| 215 | | - strcmp(np->name, "ch-b"))) |
|---|
| 210 | + if (index >= 3 && (of_node_name_eq(np, "ch-a") || |
|---|
| 211 | + of_node_name_eq(np, "ch-b"))) |
|---|
| 216 | 212 | return 1; |
|---|
| 217 | 213 | |
|---|
| 218 | 214 | /* Media bay has too many resources, keep only first one */ |
|---|
| 219 | | - if (index > 0 && !strcmp(np->name, "media-bay")) |
|---|
| 215 | + if (index > 0 && of_node_name_eq(np, "media-bay")) |
|---|
| 220 | 216 | return 1; |
|---|
| 221 | 217 | |
|---|
| 222 | 218 | /* Some older IDE resources have bogus sizes */ |
|---|
| 223 | | - if (!(strcmp(np->name, "IDE") && strcmp(np->name, "ATA") && |
|---|
| 224 | | - strcmp(np->type, "ide") && strcmp(np->type, "ata"))) { |
|---|
| 219 | + if (of_node_name_eq(np, "IDE") || of_node_name_eq(np, "ATA") || |
|---|
| 220 | + of_node_is_type(np, "ide") || of_node_is_type(np, "ata")) { |
|---|
| 225 | 221 | if (index == 0 && (res->end - res->start) > 0xfff) |
|---|
| 226 | 222 | res->end = res->start + 0xfff; |
|---|
| 227 | 223 | if (index == 1 && (res->end - res->start) > 0xff) |
|---|
| .. | .. |
|---|
| 260 | 256 | irq_base = 64; |
|---|
| 261 | 257 | |
|---|
| 262 | 258 | /* Fix SCC */ |
|---|
| 263 | | - if (strcmp(np->name, "ch-a") == 0) { |
|---|
| 259 | + if (of_node_name_eq(np, "ch-a")) { |
|---|
| 264 | 260 | macio_create_fixup_irq(dev, 0, 15 + irq_base); |
|---|
| 265 | 261 | macio_create_fixup_irq(dev, 1, 4 + irq_base); |
|---|
| 266 | 262 | macio_create_fixup_irq(dev, 2, 5 + irq_base); |
|---|
| .. | .. |
|---|
| 268 | 264 | } |
|---|
| 269 | 265 | |
|---|
| 270 | 266 | /* Fix media-bay */ |
|---|
| 271 | | - if (strcmp(np->name, "media-bay") == 0) { |
|---|
| 267 | + if (of_node_name_eq(np, "media-bay")) { |
|---|
| 272 | 268 | macio_create_fixup_irq(dev, 0, 29 + irq_base); |
|---|
| 273 | 269 | printk(KERN_INFO "macio: fixed media-bay irq on gatwick\n"); |
|---|
| 274 | 270 | } |
|---|
| 275 | 271 | |
|---|
| 276 | 272 | /* Fix left media bay childs */ |
|---|
| 277 | | - if (dev->media_bay != NULL && strcmp(np->name, "floppy") == 0) { |
|---|
| 273 | + if (dev->media_bay != NULL && of_node_name_eq(np, "floppy")) { |
|---|
| 278 | 274 | macio_create_fixup_irq(dev, 0, 19 + irq_base); |
|---|
| 279 | 275 | macio_create_fixup_irq(dev, 1, 1 + irq_base); |
|---|
| 280 | 276 | printk(KERN_INFO "macio: fixed left floppy irqs\n"); |
|---|
| 281 | 277 | } |
|---|
| 282 | | - if (dev->media_bay != NULL && strcasecmp(np->name, "ata4") == 0) { |
|---|
| 278 | + if (dev->media_bay != NULL && of_node_name_eq(np, "ata4")) { |
|---|
| 283 | 279 | macio_create_fixup_irq(dev, 0, 14 + irq_base); |
|---|
| 284 | 280 | macio_create_fixup_irq(dev, 0, 3 + irq_base); |
|---|
| 285 | 281 | printk(KERN_INFO "macio: fixed left ide irqs\n"); |
|---|
| .. | .. |
|---|
| 360 | 356 | struct macio_dev *in_bay, |
|---|
| 361 | 357 | struct resource *parent_res) |
|---|
| 362 | 358 | { |
|---|
| 359 | + char name[MAX_NODE_NAME_SIZE + 1]; |
|---|
| 363 | 360 | struct macio_dev *dev; |
|---|
| 364 | 361 | const u32 *reg; |
|---|
| 365 | | - |
|---|
| 362 | + |
|---|
| 366 | 363 | if (np == NULL) |
|---|
| 367 | 364 | return NULL; |
|---|
| 368 | 365 | |
|---|
| .. | .. |
|---|
| 385 | 382 | dma_set_max_seg_size(&dev->ofdev.dev, 65536); |
|---|
| 386 | 383 | dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff); |
|---|
| 387 | 384 | |
|---|
| 388 | | -#ifdef CONFIG_PCI |
|---|
| 385 | +#if defined(CONFIG_PCI) && defined(CONFIG_DMA_OPS) |
|---|
| 389 | 386 | /* Set the DMA ops to the ones from the PCI device, this could be |
|---|
| 390 | 387 | * fishy if we didn't know that on PowerMac it's always direct ops |
|---|
| 391 | 388 | * or iommu ops that will work fine |
|---|
| .. | .. |
|---|
| 394 | 391 | */ |
|---|
| 395 | 392 | dev->ofdev.dev.archdata = chip->lbus.pdev->dev.archdata; |
|---|
| 396 | 393 | dev->ofdev.dev.dma_ops = chip->lbus.pdev->dev.dma_ops; |
|---|
| 397 | | -#endif /* CONFIG_PCI */ |
|---|
| 394 | +#endif /* CONFIG_PCI && CONFIG_DMA_OPS */ |
|---|
| 398 | 395 | |
|---|
| 399 | 396 | #ifdef DEBUG |
|---|
| 400 | 397 | printk("preparing mdev @%p, ofdev @%p, dev @%p, kobj @%p\n", |
|---|
| .. | .. |
|---|
| 402 | 399 | #endif |
|---|
| 403 | 400 | |
|---|
| 404 | 401 | /* MacIO itself has a different reg, we use it's PCI base */ |
|---|
| 402 | + snprintf(name, sizeof(name), "%pOFn", np); |
|---|
| 405 | 403 | if (np == chip->of_node) { |
|---|
| 406 | 404 | dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s", |
|---|
| 407 | 405 | chip->lbus.index, |
|---|
| .. | .. |
|---|
| 410 | 408 | #else |
|---|
| 411 | 409 | 0, /* NuBus may want to do something better here */ |
|---|
| 412 | 410 | #endif |
|---|
| 413 | | - MAX_NODE_NAME_SIZE, np->name); |
|---|
| 411 | + MAX_NODE_NAME_SIZE, name); |
|---|
| 414 | 412 | } else { |
|---|
| 415 | 413 | reg = of_get_property(np, "reg", NULL); |
|---|
| 416 | 414 | dev_set_name(&dev->ofdev.dev, "%1d.%08x:%.*s", |
|---|
| 417 | 415 | chip->lbus.index, |
|---|
| 418 | | - reg ? *reg : 0, MAX_NODE_NAME_SIZE, np->name); |
|---|
| 416 | + reg ? *reg : 0, MAX_NODE_NAME_SIZE, name); |
|---|
| 419 | 417 | } |
|---|
| 420 | 418 | |
|---|
| 421 | 419 | /* Setup interrupts & resources */ |
|---|
| .. | .. |
|---|
| 427 | 425 | if (of_device_register(&dev->ofdev) != 0) { |
|---|
| 428 | 426 | printk(KERN_DEBUG"macio: device registration error for %s!\n", |
|---|
| 429 | 427 | dev_name(&dev->ofdev.dev)); |
|---|
| 430 | | - kfree(dev); |
|---|
| 428 | + put_device(&dev->ofdev.dev); |
|---|
| 431 | 429 | return NULL; |
|---|
| 432 | 430 | } |
|---|
| 433 | 431 | |
|---|
| .. | .. |
|---|
| 436 | 434 | |
|---|
| 437 | 435 | static int macio_skip_device(struct device_node *np) |
|---|
| 438 | 436 | { |
|---|
| 439 | | - if (strncmp(np->name, "battery", 7) == 0) |
|---|
| 440 | | - return 1; |
|---|
| 441 | | - if (strncmp(np->name, "escc-legacy", 11) == 0) |
|---|
| 442 | | - return 1; |
|---|
| 443 | | - return 0; |
|---|
| 437 | + return of_node_name_prefix(np, "battery") || |
|---|
| 438 | + of_node_name_prefix(np, "escc-legacy"); |
|---|
| 444 | 439 | } |
|---|
| 445 | 440 | |
|---|
| 446 | 441 | /** |
|---|
| .. | .. |
|---|
| 487 | 482 | root_res); |
|---|
| 488 | 483 | if (mdev == NULL) |
|---|
| 489 | 484 | of_node_put(np); |
|---|
| 490 | | - else if (strncmp(np->name, "media-bay", 9) == 0) |
|---|
| 485 | + else if (of_node_name_prefix(np, "media-bay")) |
|---|
| 491 | 486 | mbdev = mdev; |
|---|
| 492 | | - else if (strncmp(np->name, "escc", 4) == 0) |
|---|
| 487 | + else if (of_node_name_prefix(np, "escc")) |
|---|
| 493 | 488 | sdev = mdev; |
|---|
| 494 | 489 | } |
|---|
| 495 | 490 | |
|---|