forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/powerpc/platforms/powermac/feature.c
....@@ -1,11 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 1996-2001 Paul Mackerras (paulus@cs.anu.edu.au)
34 * 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.
95 *
106 * TODO:
117 *
....@@ -14,7 +10,6 @@
1410 * power)
1511 * - Refcount some clocks (see darwin)
1612 * - Split split split...
17
- *
1813 */
1914 #include <linux/types.h>
2015 #include <linux/init.h>
....@@ -51,7 +46,7 @@
5146 #define DBG(fmt...)
5247 #endif
5348
54
-#ifdef CONFIG_6xx
49
+#ifdef CONFIG_PPC_BOOK3S_32
5550 extern int powersave_lowspeed;
5651 #endif
5752
....@@ -173,9 +168,9 @@
173168 macio = macio_find(node, 0);
174169 if (!macio)
175170 return -ENODEV;
176
- if (!strcmp(node->name, "ch-a"))
171
+ if (of_node_name_eq(node, "ch-a"))
177172 chan_mask = MACIO_FLAG_SCCA_ON;
178
- else if (!strcmp(node->name, "ch-b"))
173
+ else if (of_node_name_eq(node, "ch-b"))
179174 chan_mask = MACIO_FLAG_SCCB_ON;
180175 else
181176 return -ENODEV;
....@@ -610,9 +605,9 @@
610605 macio = macio_find(node, 0);
611606 if (!macio)
612607 return -ENODEV;
613
- if (!strcmp(node->name, "ch-a"))
608
+ if (of_node_name_eq(node, "ch-a"))
614609 chan_mask = MACIO_FLAG_SCCA_ON;
615
- else if (!strcmp(node->name, "ch-b"))
610
+ else if (of_node_name_eq(node, "ch-b"))
616611 chan_mask = MACIO_FLAG_SCCB_ON;
617612 else
618613 return -ENODEV;
....@@ -1049,7 +1044,6 @@
10491044 unsigned long flags;
10501045 struct macio_chip *macio;
10511046 struct device_node *np;
1052
- struct device_node *cpus;
10531047 const int dflt_reset_lines[] = { KL_GPIO_RESET_CPU0,
10541048 KL_GPIO_RESET_CPU1,
10551049 KL_GPIO_RESET_CPU2,
....@@ -1059,10 +1053,7 @@
10591053 if (macio->type != macio_keylargo)
10601054 return -ENODEV;
10611055
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) {
10661057 const u32 *num = of_get_property(np, "reg", NULL);
10671058 const u32 *rst = of_get_property(np, "soft-reset", NULL);
10681059 if (num == NULL || rst == NULL)
....@@ -1072,7 +1063,6 @@
10721063 break;
10731064 }
10741065 }
1075
- of_node_put(cpus);
10761066 if (np == NULL || reset_io == 0)
10771067 reset_io = dflt_reset_lines[param];
10781068
....@@ -1397,8 +1387,7 @@
13971387
13981388 if (parent == NULL)
13991389 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");
14021391 of_node_put(parent);
14031392 if (!is_u3)
14041393 return 0;
....@@ -1476,6 +1465,7 @@
14761465 case 2:
14771466 if (macio->type == macio_shasta)
14781467 break;
1468
+ fallthrough;
14791469 default:
14801470 return -ENODEV;
14811471 }
....@@ -1504,16 +1494,12 @@
15041494 unsigned long flags;
15051495 struct macio_chip *macio;
15061496 struct device_node *np;
1507
- struct device_node *cpus;
15081497
15091498 macio = &macio_chips[0];
15101499 if (macio->type != macio_keylargo2 && macio->type != macio_shasta)
15111500 return -ENODEV;
15121501
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) {
15171503 const u32 *num = of_get_property(np, "reg", NULL);
15181504 const u32 *rst = of_get_property(np, "soft-reset", NULL);
15191505 if (num == NULL || rst == NULL)
....@@ -1523,7 +1509,6 @@
15231509 break;
15241510 }
15251511 }
1526
- of_node_put(cpus);
15271512 if (np == NULL || reset_io == 0)
15281513 return -ENODEV;
15291514
....@@ -2515,31 +2500,26 @@
25152500 * supposed to be set when not supported, but I'm not very confident
25162501 * that all Apple OF revs did it properly, I do it the paranoid way.
25172502 */
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) {
25202504 struct device_node *np;
25212505
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;
25262519 }
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;
25422520 }
2521
+ if (powersave_nap)
2522
+ printk(KERN_DEBUG "Processor NAP mode on idle enabled.\n");
25432523
25442524 /* On CPUs that support it (750FX), lowspeed by default during
25452525 * NAP mode