Skip to content

Commit c57902d

Browse files
Finn Thainmpe
authored andcommitted
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>
1 parent 7ad9469 commit c57902d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

drivers/macintosh/via-pmu.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static volatile unsigned char __iomem *via;
114114
#define CB1_INT 0x10 /* transition on CB1 input */
115115

116116
static volatile enum pmu_state {
117+
uninitialized = 0,
117118
idle,
118119
sending,
119120
intack,
@@ -274,7 +275,7 @@ int __init find_via_pmu(void)
274275
u64 taddr;
275276
const u32 *reg;
276277

277-
if (via)
278+
if (pmu_state != uninitialized)
278279
return 1;
279280
vias = of_find_node_by_name(NULL, "via-pmu");
280281
if (vias == NULL)
@@ -369,20 +370,19 @@ int __init find_via_pmu(void)
369370
fail:
370371
of_node_put(vias);
371372
vias = NULL;
373+
pmu_state = uninitialized;
372374
return 0;
373375
}
374376

375377
#ifdef CONFIG_ADB
376378
static int pmu_probe(void)
377379
{
378-
return vias == NULL? -ENODEV: 0;
380+
return pmu_state == uninitialized ? -ENODEV : 0;
379381
}
380382

381383
static int pmu_init(void)
382384
{
383-
if (vias == NULL)
384-
return -ENODEV;
385-
return 0;
385+
return pmu_state == uninitialized ? -ENODEV : 0;
386386
}
387387
#endif /* CONFIG_ADB */
388388

@@ -397,7 +397,7 @@ static int __init via_pmu_start(void)
397397
{
398398
unsigned int irq;
399399

400-
if (vias == NULL)
400+
if (pmu_state == uninitialized)
401401
return -ENODEV;
402402

403403
batt_req.complete = 1;
@@ -463,7 +463,7 @@ arch_initcall(via_pmu_start);
463463
*/
464464
static int __init via_pmu_dev_init(void)
465465
{
466-
if (vias == NULL)
466+
if (pmu_state == uninitialized)
467467
return -ENODEV;
468468

469469
#ifdef CONFIG_PMAC_BACKLIGHT
@@ -929,7 +929,7 @@ static int pmu_send_request(struct adb_request *req, int sync)
929929
{
930930
int i, ret;
931931

932-
if ((vias == NULL) || (!pmu_fully_inited)) {
932+
if (pmu_state == uninitialized || !pmu_fully_inited) {
933933
req->complete = 1;
934934
return -ENXIO;
935935
}
@@ -1023,7 +1023,7 @@ static int __pmu_adb_autopoll(int devs)
10231023

10241024
static int pmu_adb_autopoll(int devs)
10251025
{
1026-
if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1026+
if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
10271027
return -ENXIO;
10281028

10291029
adb_dev_map = devs;
@@ -1036,7 +1036,7 @@ static int pmu_adb_reset_bus(void)
10361036
struct adb_request req;
10371037
int save_autopoll = adb_dev_map;
10381038

1039-
if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb)
1039+
if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
10401040
return -ENXIO;
10411041

10421042
/* anyone got a better idea?? */
@@ -1072,7 +1072,7 @@ pmu_request(struct adb_request *req, void (*done)(struct adb_request *),
10721072
va_list list;
10731073
int i;
10741074

1075-
if (vias == NULL)
1075+
if (pmu_state == uninitialized)
10761076
return -ENXIO;
10771077

10781078
if (nbytes < 0 || nbytes > 32) {
@@ -1097,7 +1097,7 @@ pmu_queue_request(struct adb_request *req)
10971097
unsigned long flags;
10981098
int nsend;
10991099

1100-
if (via == NULL) {
1100+
if (pmu_state == uninitialized) {
11011101
req->complete = 1;
11021102
return -ENXIO;
11031103
}
@@ -1210,7 +1210,7 @@ pmu_start(void)
12101210
void
12111211
pmu_poll(void)
12121212
{
1213-
if (!via)
1213+
if (pmu_state == uninitialized)
12141214
return;
12151215
if (disable_poll)
12161216
return;
@@ -1220,7 +1220,7 @@ pmu_poll(void)
12201220
void
12211221
pmu_poll_adb(void)
12221222
{
1223-
if (!via)
1223+
if (pmu_state == uninitialized)
12241224
return;
12251225
if (disable_poll)
12261226
return;
@@ -1235,7 +1235,7 @@ pmu_poll_adb(void)
12351235
void
12361236
pmu_wait_complete(struct adb_request *req)
12371237
{
1238-
if (!via)
1238+
if (pmu_state == uninitialized)
12391239
return;
12401240
while((pmu_state != idle && pmu_state != locked) || !req->complete)
12411241
via_pmu_interrupt(0, NULL);
@@ -1251,7 +1251,7 @@ pmu_suspend(void)
12511251
{
12521252
unsigned long flags;
12531253

1254-
if (!via)
1254+
if (pmu_state == uninitialized)
12551255
return;
12561256

12571257
spin_lock_irqsave(&pmu_lock, flags);
@@ -1282,7 +1282,7 @@ pmu_resume(void)
12821282
{
12831283
unsigned long flags;
12841284

1285-
if (!via || (pmu_suspended < 1))
1285+
if (pmu_state == uninitialized || pmu_suspended < 1)
12861286
return;
12871287

12881288
spin_lock_irqsave(&pmu_lock, flags);
@@ -1644,7 +1644,7 @@ pmu_enable_irled(int on)
16441644
{
16451645
struct adb_request req;
16461646

1647-
if (vias == NULL)
1647+
if (pmu_state == uninitialized)
16481648
return ;
16491649
if (pmu_kind == PMU_KEYLARGO_BASED)
16501650
return ;
@@ -1659,7 +1659,7 @@ pmu_restart(void)
16591659
{
16601660
struct adb_request req;
16611661

1662-
if (via == NULL)
1662+
if (pmu_state == uninitialized)
16631663
return;
16641664

16651665
local_irq_disable();
@@ -1684,7 +1684,7 @@ pmu_shutdown(void)
16841684
{
16851685
struct adb_request req;
16861686

1687-
if (via == NULL)
1687+
if (pmu_state == uninitialized)
16881688
return;
16891689

16901690
local_irq_disable();
@@ -1712,7 +1712,7 @@ pmu_shutdown(void)
17121712
int
17131713
pmu_present(void)
17141714
{
1715-
return via != NULL;
1715+
return pmu_state != uninitialized;
17161716
}
17171717

17181718
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
@@ -2378,7 +2378,7 @@ static struct miscdevice pmu_device = {
23782378

23792379
static int pmu_device_init(void)
23802380
{
2381-
if (!via)
2381+
if (pmu_state == uninitialized)
23822382
return 0;
23832383
if (misc_register(&pmu_device) < 0)
23842384
printk(KERN_ERR "via-pmu: cannot register misc device.\n");

0 commit comments

Comments
 (0)