Commit c57902d5 authored by Finn Thain's avatar Finn Thain Committed by Michael Ellerman

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: default avatarStan Johnson <userm57@yahoo.com>
Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 7ad94699
...@@ -114,6 +114,7 @@ static volatile unsigned char __iomem *via; ...@@ -114,6 +114,7 @@ static volatile unsigned char __iomem *via;
#define CB1_INT 0x10 /* transition on CB1 input */ #define CB1_INT 0x10 /* transition on CB1 input */
static volatile enum pmu_state { static volatile enum pmu_state {
uninitialized = 0,
idle, idle,
sending, sending,
intack, intack,
...@@ -274,7 +275,7 @@ int __init find_via_pmu(void) ...@@ -274,7 +275,7 @@ int __init find_via_pmu(void)
u64 taddr; u64 taddr;
const u32 *reg; const u32 *reg;
if (via) if (pmu_state != uninitialized)
return 1; return 1;
vias = of_find_node_by_name(NULL, "via-pmu"); vias = of_find_node_by_name(NULL, "via-pmu");
if (vias == NULL) if (vias == NULL)
...@@ -369,20 +370,19 @@ int __init find_via_pmu(void) ...@@ -369,20 +370,19 @@ int __init find_via_pmu(void)
fail: fail:
of_node_put(vias); of_node_put(vias);
vias = NULL; vias = NULL;
pmu_state = uninitialized;
return 0; return 0;
} }
#ifdef CONFIG_ADB #ifdef CONFIG_ADB
static int pmu_probe(void) static int pmu_probe(void)
{ {
return vias == NULL? -ENODEV: 0; return pmu_state == uninitialized ? -ENODEV : 0;
} }
static int pmu_init(void) static int pmu_init(void)
{ {
if (vias == NULL) return pmu_state == uninitialized ? -ENODEV : 0;
return -ENODEV;
return 0;
} }
#endif /* CONFIG_ADB */ #endif /* CONFIG_ADB */
...@@ -397,7 +397,7 @@ static int __init via_pmu_start(void) ...@@ -397,7 +397,7 @@ static int __init via_pmu_start(void)
{ {
unsigned int irq; unsigned int irq;
if (vias == NULL) if (pmu_state == uninitialized)
return -ENODEV; return -ENODEV;
batt_req.complete = 1; batt_req.complete = 1;
...@@ -463,7 +463,7 @@ arch_initcall(via_pmu_start); ...@@ -463,7 +463,7 @@ arch_initcall(via_pmu_start);
*/ */
static int __init via_pmu_dev_init(void) static int __init via_pmu_dev_init(void)
{ {
if (vias == NULL) if (pmu_state == uninitialized)
return -ENODEV; return -ENODEV;
#ifdef CONFIG_PMAC_BACKLIGHT #ifdef CONFIG_PMAC_BACKLIGHT
...@@ -929,7 +929,7 @@ static int pmu_send_request(struct adb_request *req, int sync) ...@@ -929,7 +929,7 @@ static int pmu_send_request(struct adb_request *req, int sync)
{ {
int i, ret; int i, ret;
if ((vias == NULL) || (!pmu_fully_inited)) { if (pmu_state == uninitialized || !pmu_fully_inited) {
req->complete = 1; req->complete = 1;
return -ENXIO; return -ENXIO;
} }
...@@ -1023,7 +1023,7 @@ static int __pmu_adb_autopoll(int devs) ...@@ -1023,7 +1023,7 @@ static int __pmu_adb_autopoll(int devs)
static int pmu_adb_autopoll(int devs) static int pmu_adb_autopoll(int devs)
{ {
if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
return -ENXIO; return -ENXIO;
adb_dev_map = devs; adb_dev_map = devs;
...@@ -1036,7 +1036,7 @@ static int pmu_adb_reset_bus(void) ...@@ -1036,7 +1036,7 @@ static int pmu_adb_reset_bus(void)
struct adb_request req; struct adb_request req;
int save_autopoll = adb_dev_map; int save_autopoll = adb_dev_map;
if ((vias == NULL) || (!pmu_fully_inited) || !pmu_has_adb) if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
return -ENXIO; return -ENXIO;
/* anyone got a better idea?? */ /* anyone got a better idea?? */
...@@ -1072,7 +1072,7 @@ pmu_request(struct adb_request *req, void (*done)(struct adb_request *), ...@@ -1072,7 +1072,7 @@ pmu_request(struct adb_request *req, void (*done)(struct adb_request *),
va_list list; va_list list;
int i; int i;
if (vias == NULL) if (pmu_state == uninitialized)
return -ENXIO; return -ENXIO;
if (nbytes < 0 || nbytes > 32) { if (nbytes < 0 || nbytes > 32) {
...@@ -1097,7 +1097,7 @@ pmu_queue_request(struct adb_request *req) ...@@ -1097,7 +1097,7 @@ pmu_queue_request(struct adb_request *req)
unsigned long flags; unsigned long flags;
int nsend; int nsend;
if (via == NULL) { if (pmu_state == uninitialized) {
req->complete = 1; req->complete = 1;
return -ENXIO; return -ENXIO;
} }
...@@ -1210,7 +1210,7 @@ pmu_start(void) ...@@ -1210,7 +1210,7 @@ pmu_start(void)
void void
pmu_poll(void) pmu_poll(void)
{ {
if (!via) if (pmu_state == uninitialized)
return; return;
if (disable_poll) if (disable_poll)
return; return;
...@@ -1220,7 +1220,7 @@ pmu_poll(void) ...@@ -1220,7 +1220,7 @@ pmu_poll(void)
void void
pmu_poll_adb(void) pmu_poll_adb(void)
{ {
if (!via) if (pmu_state == uninitialized)
return; return;
if (disable_poll) if (disable_poll)
return; return;
...@@ -1235,7 +1235,7 @@ pmu_poll_adb(void) ...@@ -1235,7 +1235,7 @@ pmu_poll_adb(void)
void void
pmu_wait_complete(struct adb_request *req) pmu_wait_complete(struct adb_request *req)
{ {
if (!via) if (pmu_state == uninitialized)
return; return;
while((pmu_state != idle && pmu_state != locked) || !req->complete) while((pmu_state != idle && pmu_state != locked) || !req->complete)
via_pmu_interrupt(0, NULL); via_pmu_interrupt(0, NULL);
...@@ -1251,7 +1251,7 @@ pmu_suspend(void) ...@@ -1251,7 +1251,7 @@ pmu_suspend(void)
{ {
unsigned long flags; unsigned long flags;
if (!via) if (pmu_state == uninitialized)
return; return;
spin_lock_irqsave(&pmu_lock, flags); spin_lock_irqsave(&pmu_lock, flags);
...@@ -1282,7 +1282,7 @@ pmu_resume(void) ...@@ -1282,7 +1282,7 @@ pmu_resume(void)
{ {
unsigned long flags; unsigned long flags;
if (!via || (pmu_suspended < 1)) if (pmu_state == uninitialized || pmu_suspended < 1)
return; return;
spin_lock_irqsave(&pmu_lock, flags); spin_lock_irqsave(&pmu_lock, flags);
...@@ -1644,7 +1644,7 @@ pmu_enable_irled(int on) ...@@ -1644,7 +1644,7 @@ pmu_enable_irled(int on)
{ {
struct adb_request req; struct adb_request req;
if (vias == NULL) if (pmu_state == uninitialized)
return ; return ;
if (pmu_kind == PMU_KEYLARGO_BASED) if (pmu_kind == PMU_KEYLARGO_BASED)
return ; return ;
...@@ -1659,7 +1659,7 @@ pmu_restart(void) ...@@ -1659,7 +1659,7 @@ pmu_restart(void)
{ {
struct adb_request req; struct adb_request req;
if (via == NULL) if (pmu_state == uninitialized)
return; return;
local_irq_disable(); local_irq_disable();
...@@ -1684,7 +1684,7 @@ pmu_shutdown(void) ...@@ -1684,7 +1684,7 @@ pmu_shutdown(void)
{ {
struct adb_request req; struct adb_request req;
if (via == NULL) if (pmu_state == uninitialized)
return; return;
local_irq_disable(); local_irq_disable();
...@@ -1712,7 +1712,7 @@ pmu_shutdown(void) ...@@ -1712,7 +1712,7 @@ pmu_shutdown(void)
int int
pmu_present(void) pmu_present(void)
{ {
return via != NULL; return pmu_state != uninitialized;
} }
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32) #if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
...@@ -2378,7 +2378,7 @@ static struct miscdevice pmu_device = { ...@@ -2378,7 +2378,7 @@ static struct miscdevice pmu_device = {
static int pmu_device_init(void) static int pmu_device_init(void)
{ {
if (!via) if (pmu_state == uninitialized)
return 0; return 0;
if (misc_register(&pmu_device) < 0) if (misc_register(&pmu_device) < 0)
printk(KERN_ERR "via-pmu: cannot register misc device.\n"); printk(KERN_ERR "via-pmu: cannot register misc device.\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment