diff options
author | Finn Thain <fthain@telegraphics.com.au> | 2018-07-02 04:21:18 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2018-07-31 05:56:40 -0400 |
commit | c57902d52e2d61299872ddc89645d3aa299f1b91 (patch) | |
tree | 2ee789150109b1c10726a4ef36b8aee63ea95cf7 /drivers/macintosh | |
parent | 7ad94699a94b388780e40158e6954a22b68e9d20 (diff) |
macintosh/via-pmu: Enhance state machine with new 'uninitialized' state
On 68k Macs, the via/vias pointer can't be used to determine whether
the PMU driver has been initialized. For portability, add a new state
to indicate that via_find_pmu() succeeded.
After via_find_pmu() executes, testing vias == NULL is equivalent to
testing via == NULL. Replace these tests with pmu_state == uninitialized
which is simpler and more consistent. No functional change.
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/via-pmu.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index c313ddfdb17a..6a6f1666712e 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c | |||
@@ -114,6 +114,7 @@ static volatile unsigned char __iomem *via; | |||
114 | #define CB1_INT 0x10 /* transition on CB1 input */ | 114 | #define CB1_INT 0x10 /* transition on CB1 input */ |
115 | 115 | ||
116 | static volatile enum pmu_state { | 116 | static volatile enum pmu_state { |
117 | uninitialized = 0, | ||
117 | idle, | 118 | idle, |
118 | sending, | 119 | sending, |
119 | intack, | 120 | intack, |
@@ -274,7 +275,7 @@ int __init find_via_pmu(void) | |||
274 | u64 taddr; | 275 | u64 taddr; |
275 | const u32 *reg; | 276 | const u32 *reg; |
276 | 277 | ||
277 | if (via) | 278 | if (pmu_state != uninitialized) |
278 | return 1; | 279 | return 1; |
279 | vias = of_find_node_by_name(NULL, "via-pmu"); | 280 | vias = of_find_node_by_name(NULL, "via-pmu"); |
280 | if (vias == NULL) | 281 | if (vias == NULL) |
@@ -369,20 +370,19 @@ int __init find_via_pmu(void) | |||
369 | fail: | 370 | fail: |
370 | of_node_put(vias); | 371 | of_node_put(vias); |
371 | vias = NULL; | 372 | vias = NULL; |
373 | pmu_state = uninitialized; | ||
372 | return 0; | 374 | return 0; |
373 | } | 375 | } |
374 | 376 | ||
375 | #ifdef CONFIG_ADB | 377 | #ifdef CONFIG_ADB |
376 | static int pmu_probe(void) | 378 | static int pmu_probe(void) |
377 | { | 379 | { |
378 | return vias == NULL? -ENODEV: 0; | 380 | return pmu_state == uninitialized ? -ENODEV : 0; |
379 | } | 381 | } |
380 | 382 | ||
381 | static int pmu_init(void) | 383 | static int pmu_init(void) |
382 | { | 384 | { |
383 | if (vias == NULL) | 385 | return pmu_state == uninitialized ? -ENODEV : 0; |
384 | return -ENODEV; | ||
385 | return 0; | ||
386 | } | 386 | } |
387 | #endif /* CONFIG_ADB */ | 387 | #endif /* CONFIG_ADB */ |
388 | 388 | ||
@@ -397,7 +397,7 @@ static int __init via_pmu_start(void) | |||
397 | { | 397 | { |
398 | unsigned int irq; | 398 | unsigned int irq; |
399 | 399 | ||
400 | if (vias == NULL) | 400 | if (pmu_state == uninitialized) |
401 | return -ENODEV; | 401 | return -ENODEV; |
402 | 402 | ||
403 | batt_req.complete = 1; | 403 | batt_req.complete = 1; |
@@ -463,7 +463,7 @@ arch_initcall(via_pmu_start); | |||
463 | */ | 463 | */ |
464 | static int __init via_pmu_dev_init(void) | 464 | static int __init via_pmu_dev_init(void) |
465 | { | 465 | { |
466 | if (vias == NULL) | 466 | if (pmu_state == uninitialized) |
467 | return -ENODEV; | 467 | return -ENODEV; |
468 | 468 | ||
469 | #ifdef CONFIG_PMAC_BACKLIGHT | 469 | #ifdef CONFIG_PMAC_BACKLIGHT |
@@ -929,7 +929,7 @@ static int pmu_send_request(struct adb_request *req, int sync) | |||
929 | { | 929 | { |
930 | int i, ret; | 930 | int i, ret; |
931 | 931 | ||
932 | if ((vias == NULL) || (!pmu_fully_inited)) { | 932 | if (pmu_state == uninitialized || !pmu_fully_inited) { |
933 | req->complete = 1; | 933 | req->complete = 1; |
934 | return -ENXIO; | 934 | return -ENXIO; |
935 | } | 935 | } |
@@ -1023,7 +1023,7 @@ static int __pmu_adb_autopoll(int devs) | |||
1023 | 1023 | ||
1024 | static int pmu_adb_autopoll(int devs) | 1024 | static int pmu_adb_autopoll(int devs) |
1025 | { | 1025 | { |
1026 | if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) | 1026 | if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb) |
1027 | return -ENXIO; | 1027 | return -ENXIO; |
1028 | 1028 | ||
1029 | adb_dev_map = devs; | 1029 | adb_dev_map = devs; |
@@ -1036,7 +1036,7 @@ static int pmu_adb_reset_bus(void) | |||
1036 | struct adb_request req; | 1036 | struct adb_request req; |
1037 | int save_autopoll = adb_dev_map; | 1037 | int save_autopoll = adb_dev_map; |
1038 | 1038 | ||
1039 | if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) | 1039 | if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb) |
1040 | return -ENXIO; | 1040 | return -ENXIO; |
1041 | 1041 | ||
1042 | /* anyone got a better idea?? */ | 1042 | /* anyone got a better idea?? */ |
@@ -1072,7 +1072,7 @@ pmu_request(struct adb_request *req, void (*done)(struct adb_request *), | |||
1072 | va_list list; | 1072 | va_list list; |
1073 | int i; | 1073 | int i; |
1074 | 1074 | ||
1075 | if (vias == NULL) | 1075 | if (pmu_state == uninitialized) |
1076 | return -ENXIO; | 1076 | return -ENXIO; |
1077 | 1077 | ||
1078 | if (nbytes < 0 || nbytes > 32) { | 1078 | if (nbytes < 0 || nbytes > 32) { |
@@ -1097,7 +1097,7 @@ pmu_queue_request(struct adb_request *req) | |||
1097 | unsigned long flags; | 1097 | unsigned long flags; |
1098 | int nsend; | 1098 | int nsend; |
1099 | 1099 | ||
1100 | if (via == NULL) { | 1100 | if (pmu_state == uninitialized) { |
1101 | req->complete = 1; | 1101 | req->complete = 1; |
1102 | return -ENXIO; | 1102 | return -ENXIO; |
1103 | } | 1103 | } |
@@ -1210,7 +1210,7 @@ pmu_start(void) | |||
1210 | void | 1210 | void |
1211 | pmu_poll(void) | 1211 | pmu_poll(void) |
1212 | { | 1212 | { |
1213 | if (!via) | 1213 | if (pmu_state == uninitialized) |
1214 | return; | 1214 | return; |
1215 | if (disable_poll) | 1215 | if (disable_poll) |
1216 | return; | 1216 | return; |
@@ -1220,7 +1220,7 @@ pmu_poll(void) | |||
1220 | void | 1220 | void |
1221 | pmu_poll_adb(void) | 1221 | pmu_poll_adb(void) |
1222 | { | 1222 | { |
1223 | if (!via) | 1223 | if (pmu_state == uninitialized) |
1224 | return; | 1224 | return; |
1225 | if (disable_poll) | 1225 | if (disable_poll) |
1226 | return; | 1226 | return; |
@@ -1235,7 +1235,7 @@ pmu_poll_adb(void) | |||
1235 | void | 1235 | void |
1236 | pmu_wait_complete(struct adb_request *req) | 1236 | pmu_wait_complete(struct adb_request *req) |
1237 | { | 1237 | { |
1238 | if (!via) | 1238 | if (pmu_state == uninitialized) |
1239 | return; | 1239 | return; |
1240 | while((pmu_state != idle && pmu_state != locked) || !req->complete) | 1240 | while((pmu_state != idle && pmu_state != locked) || !req->complete) |
1241 | via_pmu_interrupt(0, NULL); | 1241 | via_pmu_interrupt(0, NULL); |
@@ -1251,7 +1251,7 @@ pmu_suspend(void) | |||
1251 | { | 1251 | { |
1252 | unsigned long flags; | 1252 | unsigned long flags; |
1253 | 1253 | ||
1254 | if (!via) | 1254 | if (pmu_state == uninitialized) |
1255 | return; | 1255 | return; |
1256 | 1256 | ||
1257 | spin_lock_irqsave(&pmu_lock, flags); | 1257 | spin_lock_irqsave(&pmu_lock, flags); |
@@ -1282,7 +1282,7 @@ pmu_resume(void) | |||
1282 | { | 1282 | { |
1283 | unsigned long flags; | 1283 | unsigned long flags; |
1284 | 1284 | ||
1285 | if (!via || (pmu_suspended < 1)) | 1285 | if (pmu_state == uninitialized || pmu_suspended < 1) |
1286 | return; | 1286 | return; |
1287 | 1287 | ||
1288 | spin_lock_irqsave(&pmu_lock, flags); | 1288 | spin_lock_irqsave(&pmu_lock, flags); |
@@ -1644,7 +1644,7 @@ pmu_enable_irled(int on) | |||
1644 | { | 1644 | { |
1645 | struct adb_request req; | 1645 | struct adb_request req; |
1646 | 1646 | ||
1647 | if (vias == NULL) | 1647 | if (pmu_state == uninitialized) |
1648 | return ; | 1648 | return ; |
1649 | if (pmu_kind == PMU_KEYLARGO_BASED) | 1649 | if (pmu_kind == PMU_KEYLARGO_BASED) |
1650 | return ; | 1650 | return ; |
@@ -1659,7 +1659,7 @@ pmu_restart(void) | |||
1659 | { | 1659 | { |
1660 | struct adb_request req; | 1660 | struct adb_request req; |
1661 | 1661 | ||
1662 | if (via == NULL) | 1662 | if (pmu_state == uninitialized) |
1663 | return; | 1663 | return; |
1664 | 1664 | ||
1665 | local_irq_disable(); | 1665 | local_irq_disable(); |
@@ -1684,7 +1684,7 @@ pmu_shutdown(void) | |||
1684 | { | 1684 | { |
1685 | struct adb_request req; | 1685 | struct adb_request req; |
1686 | 1686 | ||
1687 | if (via == NULL) | 1687 | if (pmu_state == uninitialized) |
1688 | return; | 1688 | return; |
1689 | 1689 | ||
1690 | local_irq_disable(); | 1690 | local_irq_disable(); |
@@ -1712,7 +1712,7 @@ pmu_shutdown(void) | |||
1712 | int | 1712 | int |
1713 | pmu_present(void) | 1713 | pmu_present(void) |
1714 | { | 1714 | { |
1715 | return via != NULL; | 1715 | return pmu_state != uninitialized; |
1716 | } | 1716 | } |
1717 | 1717 | ||
1718 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) | 1718 | #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) |
@@ -2378,7 +2378,7 @@ static struct miscdevice pmu_device = { | |||
2378 | 2378 | ||
2379 | static int pmu_device_init(void) | 2379 | static int pmu_device_init(void) |
2380 | { | 2380 | { |
2381 | if (!via) | 2381 | if (pmu_state == uninitialized) |
2382 | return 0; | 2382 | return 0; |
2383 | if (misc_register(&pmu_device) < 0) | 2383 | if (misc_register(&pmu_device) < 0) |
2384 | printk(KERN_ERR "via-pmu: cannot register misc device.\n"); | 2384 | printk(KERN_ERR "via-pmu: cannot register misc device.\n"); |