| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au) |
|---|
| 3 | 4 | * Ben. Herrenschmidt (benh@kernel.crashing.org) |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or |
|---|
| 6 | | - * modify it under the terms of the GNU General Public License |
|---|
| 7 | | - * as published by the Free Software Foundation; either version |
|---|
| 8 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 9 | 5 | * |
|---|
| 10 | 6 | * TODO: |
|---|
| 11 | 7 | * |
|---|
| .. | .. |
|---|
| 14 | 10 | * power) |
|---|
| 15 | 11 | * - Refcount some clocks (see darwin) |
|---|
| 16 | 12 | * - Split split split... |
|---|
| 17 | | - * |
|---|
| 18 | 13 | */ |
|---|
| 19 | 14 | #include <linux/types.h> |
|---|
| 20 | 15 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 51 | 46 | #define DBG(fmt...) |
|---|
| 52 | 47 | #endif |
|---|
| 53 | 48 | |
|---|
| 54 | | -#ifdef CONFIG_6xx |
|---|
| 49 | +#ifdef CONFIG_PPC_BOOK3S_32 |
|---|
| 55 | 50 | extern int powersave_lowspeed; |
|---|
| 56 | 51 | #endif |
|---|
| 57 | 52 | |
|---|
| .. | .. |
|---|
| 173 | 168 | macio = macio_find(node, 0); |
|---|
| 174 | 169 | if (!macio) |
|---|
| 175 | 170 | return -ENODEV; |
|---|
| 176 | | - if (!strcmp(node->name, "ch-a")) |
|---|
| 171 | + if (of_node_name_eq(node, "ch-a")) |
|---|
| 177 | 172 | chan_mask = MACIO_FLAG_SCCA_ON; |
|---|
| 178 | | - else if (!strcmp(node->name, "ch-b")) |
|---|
| 173 | + else if (of_node_name_eq(node, "ch-b")) |
|---|
| 179 | 174 | chan_mask = MACIO_FLAG_SCCB_ON; |
|---|
| 180 | 175 | else |
|---|
| 181 | 176 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 610 | 605 | macio = macio_find(node, 0); |
|---|
| 611 | 606 | if (!macio) |
|---|
| 612 | 607 | return -ENODEV; |
|---|
| 613 | | - if (!strcmp(node->name, "ch-a")) |
|---|
| 608 | + if (of_node_name_eq(node, "ch-a")) |
|---|
| 614 | 609 | chan_mask = MACIO_FLAG_SCCA_ON; |
|---|
| 615 | | - else if (!strcmp(node->name, "ch-b")) |
|---|
| 610 | + else if (of_node_name_eq(node, "ch-b")) |
|---|
| 616 | 611 | chan_mask = MACIO_FLAG_SCCB_ON; |
|---|
| 617 | 612 | else |
|---|
| 618 | 613 | return -ENODEV; |
|---|
| .. | .. |
|---|
| 1049 | 1044 | unsigned long flags; |
|---|
| 1050 | 1045 | struct macio_chip *macio; |
|---|
| 1051 | 1046 | struct device_node *np; |
|---|
| 1052 | | - struct device_node *cpus; |
|---|
| 1053 | 1047 | const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0, |
|---|
| 1054 | 1048 | KL_GPIO_RESET_CPU1, |
|---|
| 1055 | 1049 | KL_GPIO_RESET_CPU2, |
|---|
| .. | .. |
|---|
| 1059 | 1053 | if (macio->type != macio_keylargo) |
|---|
| 1060 | 1054 | return -ENODEV; |
|---|
| 1061 | 1055 | |
|---|
| 1062 | | - cpus = of_find_node_by_path("/cpus"); |
|---|
| 1063 | | - if (cpus == NULL) |
|---|
| 1064 | | - return -ENODEV; |
|---|
| 1065 | | - for (np = cpus->child; np != NULL; np = np->sibling) { |
|---|
| 1056 | + for_each_of_cpu_node(np) { |
|---|
| 1066 | 1057 | const u32 *num = of_get_property(np, "reg", NULL); |
|---|
| 1067 | 1058 | const u32 *rst = of_get_property(np, "soft-reset", NULL); |
|---|
| 1068 | 1059 | if (num == NULL || rst == NULL) |
|---|
| .. | .. |
|---|
| 1072 | 1063 | break; |
|---|
| 1073 | 1064 | } |
|---|
| 1074 | 1065 | } |
|---|
| 1075 | | - of_node_put(cpus); |
|---|
| 1076 | 1066 | if (np == NULL || reset_io == 0) |
|---|
| 1077 | 1067 | reset_io = dflt_reset_lines[param]; |
|---|
| 1078 | 1068 | |
|---|
| .. | .. |
|---|
| 1397 | 1387 | |
|---|
| 1398 | 1388 | if (parent == NULL) |
|---|
| 1399 | 1389 | return 0; |
|---|
| 1400 | | - is_u3 = strcmp(parent->name, "u3") == 0 || |
|---|
| 1401 | | - strcmp(parent->name, "u4") == 0; |
|---|
| 1390 | + is_u3 = of_node_name_eq(parent, "u3") || of_node_name_eq(parent, "u4"); |
|---|
| 1402 | 1391 | of_node_put(parent); |
|---|
| 1403 | 1392 | if (!is_u3) |
|---|
| 1404 | 1393 | return 0; |
|---|
| .. | .. |
|---|
| 1476 | 1465 | case 2: |
|---|
| 1477 | 1466 | if (macio->type == macio_shasta) |
|---|
| 1478 | 1467 | break; |
|---|
| 1468 | + fallthrough; |
|---|
| 1479 | 1469 | default: |
|---|
| 1480 | 1470 | return -ENODEV; |
|---|
| 1481 | 1471 | } |
|---|
| .. | .. |
|---|
| 1504 | 1494 | unsigned long flags; |
|---|
| 1505 | 1495 | struct macio_chip *macio; |
|---|
| 1506 | 1496 | struct device_node *np; |
|---|
| 1507 | | - struct device_node *cpus; |
|---|
| 1508 | 1497 | |
|---|
| 1509 | 1498 | macio = &macio_chips[0]; |
|---|
| 1510 | 1499 | if (macio->type != macio_keylargo2 && macio->type != macio_shasta) |
|---|
| 1511 | 1500 | return -ENODEV; |
|---|
| 1512 | 1501 | |
|---|
| 1513 | | - cpus = of_find_node_by_path("/cpus"); |
|---|
| 1514 | | - if (cpus == NULL) |
|---|
| 1515 | | - return -ENODEV; |
|---|
| 1516 | | - for (np = cpus->child; np != NULL; np = np->sibling) { |
|---|
| 1502 | + for_each_of_cpu_node(np) { |
|---|
| 1517 | 1503 | const u32 *num = of_get_property(np, "reg", NULL); |
|---|
| 1518 | 1504 | const u32 *rst = of_get_property(np, "soft-reset", NULL); |
|---|
| 1519 | 1505 | if (num == NULL || rst == NULL) |
|---|
| .. | .. |
|---|
| 1523 | 1509 | break; |
|---|
| 1524 | 1510 | } |
|---|
| 1525 | 1511 | } |
|---|
| 1526 | | - of_node_put(cpus); |
|---|
| 1527 | 1512 | if (np == NULL || reset_io == 0) |
|---|
| 1528 | 1513 | return -ENODEV; |
|---|
| 1529 | 1514 | |
|---|
| .. | .. |
|---|
| 2515 | 2500 | * supposed to be set when not supported, but I'm not very confident |
|---|
| 2516 | 2501 | * that all Apple OF revs did it properly, I do it the paranoid way. |
|---|
| 2517 | 2502 | */ |
|---|
| 2518 | | - while (uninorth_base && uninorth_rev > 3) { |
|---|
| 2519 | | - struct device_node *cpus = of_find_node_by_path("/cpus"); |
|---|
| 2503 | + if (uninorth_base && uninorth_rev > 3) { |
|---|
| 2520 | 2504 | struct device_node *np; |
|---|
| 2521 | 2505 | |
|---|
| 2522 | | - if (!cpus || !cpus->child) { |
|---|
| 2523 | | - printk(KERN_WARNING "Can't find CPU(s) in device tree !\n"); |
|---|
| 2524 | | - of_node_put(cpus); |
|---|
| 2525 | | - break; |
|---|
| 2506 | + for_each_of_cpu_node(np) { |
|---|
| 2507 | + int cpu_count = 1; |
|---|
| 2508 | + |
|---|
| 2509 | + /* Nap mode not supported on SMP */ |
|---|
| 2510 | + if (of_get_property(np, "flush-on-lock", NULL) || |
|---|
| 2511 | + (cpu_count > 1)) { |
|---|
| 2512 | + powersave_nap = 0; |
|---|
| 2513 | + of_node_put(np); |
|---|
| 2514 | + break; |
|---|
| 2515 | + } |
|---|
| 2516 | + |
|---|
| 2517 | + cpu_count++; |
|---|
| 2518 | + powersave_nap = 1; |
|---|
| 2526 | 2519 | } |
|---|
| 2527 | | - np = cpus->child; |
|---|
| 2528 | | - /* Nap mode not supported on SMP */ |
|---|
| 2529 | | - if (np->sibling) { |
|---|
| 2530 | | - of_node_put(cpus); |
|---|
| 2531 | | - break; |
|---|
| 2532 | | - } |
|---|
| 2533 | | - /* Nap mode not supported if flush-on-lock property is present */ |
|---|
| 2534 | | - if (of_get_property(np, "flush-on-lock", NULL)) { |
|---|
| 2535 | | - of_node_put(cpus); |
|---|
| 2536 | | - break; |
|---|
| 2537 | | - } |
|---|
| 2538 | | - of_node_put(cpus); |
|---|
| 2539 | | - powersave_nap = 1; |
|---|
| 2540 | | - printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n"); |
|---|
| 2541 | | - break; |
|---|
| 2542 | 2520 | } |
|---|
| 2521 | + if (powersave_nap) |
|---|
| 2522 | + printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n"); |
|---|
| 2543 | 2523 | |
|---|
| 2544 | 2524 | /* On CPUs that support it (750FX), lowspeed by default during |
|---|
| 2545 | 2525 | * NAP mode |
|---|