Commit a0e34432 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Linus Torvalds

[PATCH] M68k update (part 2)

Mac/m68k ADB updates (from 2.4.x)
 - Add support for m68k Macs
 - Add missing call to VIA CUDA initialization routine
 - Update Mac II VIA support
 - Make local functions static and add their prototypes
 - Add missing defines for Mac/m68k PMUs
parent d045260c
...@@ -64,7 +64,7 @@ static struct adb_driver *adb_driver_list[] = { ...@@ -64,7 +64,7 @@ static struct adb_driver *adb_driver_list[] = {
#ifdef CONFIG_ADB_IOP #ifdef CONFIG_ADB_IOP
&adb_iop_driver, &adb_iop_driver,
#endif #endif
#ifdef CONFIG_ADB_PMU #if defined(CONFIG_ADB_PMU) || defined(CONFIG_ADB_PMU68K)
&via_pmu_driver, &via_pmu_driver,
#endif #endif
#ifdef CONFIG_ADB_MACIO #ifdef CONFIG_ADB_MACIO
...@@ -311,9 +311,11 @@ int __init adb_init(void) ...@@ -311,9 +311,11 @@ int __init adb_init(void)
#ifdef CONFIG_PMAC_PBOOK #ifdef CONFIG_PMAC_PBOOK
pmu_register_sleep_notifier(&adb_sleep_notifier); pmu_register_sleep_notifier(&adb_sleep_notifier);
#endif /* CONFIG_PMAC_PBOOK */ #endif /* CONFIG_PMAC_PBOOK */
#ifdef CONFIG_PPC
if (machine_is_compatible("AAPL,PowerBook1998") || if (machine_is_compatible("AAPL,PowerBook1998") ||
machine_is_compatible("PowerBook1,1")) machine_is_compatible("PowerBook1,1"))
sleepy_trackpad = 1; sleepy_trackpad = 1;
#endif /* CONFIG_PPC */
init_completion(&adb_probe_task_comp); init_completion(&adb_probe_task_comp);
adbdev_init(); adbdev_init();
adb_reset_bus(); adb_reset_bus();
......
...@@ -944,8 +944,10 @@ init_ms_a3(int id) ...@@ -944,8 +944,10 @@ init_ms_a3(int id)
static int __init adbhid_init(void) static int __init adbhid_init(void)
{ {
#ifndef CONFIG_MAC
if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) ) if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) )
return 0; return 0;
#endif
led_request.complete = 1; led_request.complete = 1;
......
...@@ -191,7 +191,9 @@ static int __init via_cuda_start(void) ...@@ -191,7 +191,9 @@ static int __init via_cuda_start(void)
if (via == NULL) if (via == NULL)
return -ENODEV; return -ENODEV;
#ifdef CONFIG_PPC
request_OF_resource(vias, 0, NULL); request_OF_resource(vias, 0, NULL);
#endif
if (request_irq(CUDA_IRQ, cuda_interrupt, 0, "ADB", cuda_interrupt)) { if (request_irq(CUDA_IRQ, cuda_interrupt, 0, "ADB", cuda_interrupt)) {
printk(KERN_ERR "cuda_init: can't get irq %d\n", CUDA_IRQ); printk(KERN_ERR "cuda_init: can't get irq %d\n", CUDA_IRQ);
...@@ -224,12 +226,19 @@ cuda_probe() ...@@ -224,12 +226,19 @@ cuda_probe()
static int __init static int __init
cuda_init(void) cuda_init(void)
{ {
#ifdef CONFIG_PPC
if (via == NULL) if (via == NULL)
return -ENODEV; return -ENODEV;
#ifndef CONFIG_PPC return 0;
#else
int err = cuda_init_via();
if (err) {
printk(KERN_ERR "cuda_init_via() failed\n");
return -ENODEV;
}
return via_cuda_start(); return via_cuda_start();
#endif #endif
return 0;
} }
#endif /* CONFIG_ADB */ #endif /* CONFIG_ADB */
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
* Rewrite for Unified ADB by Joshua M. Thompson (funaho@jurai.org) * Rewrite for Unified ADB by Joshua M. Thompson (funaho@jurai.org)
* *
* 1999-08-02 (jmt) - Initial rewrite for Unified ADB. * 1999-08-02 (jmt) - Initial rewrite for Unified ADB.
* 2000-03-29 Tony Mantler <tonym@mac.linux-m68k.org>
* - Big overhaul, should actually work now.
*/ */
#include <stdarg.h> #include <stdarg.h>
...@@ -98,7 +100,6 @@ struct adb_driver via_macii_driver = { ...@@ -98,7 +100,6 @@ struct adb_driver via_macii_driver = {
static enum macii_state { static enum macii_state {
idle, idle,
sent_first_byte,
sending, sending,
reading, reading,
read_done, read_done,
...@@ -133,7 +134,7 @@ static int macii_probe(void) ...@@ -133,7 +134,7 @@ static int macii_probe(void)
via = via1; via = via1;
printk("adb: Mac II ADB Driver v0.4 for Unified ADB\n"); printk("adb: Mac II ADB Driver v1.0 for Unified ADB\n");
return 0; return 0;
} }
...@@ -256,7 +257,7 @@ static int macii_write(struct adb_request *req) ...@@ -256,7 +257,7 @@ static int macii_write(struct adb_request *req)
{ {
unsigned long flags; unsigned long flags;
if (req->nbytes < 2 || req->data[0] != ADB_PACKET) { if (req->nbytes < 2 || req->data[0] != ADB_PACKET || req->nbytes > 15) {
req->complete = 1; req->complete = 1;
return -EINVAL; return -EINVAL;
} }
...@@ -333,7 +334,9 @@ static void macii_start(void) ...@@ -333,7 +334,9 @@ static void macii_start(void)
* IRQ signaled ?? (means ADB controller wants to send, or might * IRQ signaled ?? (means ADB controller wants to send, or might
* be end of packet if we were reading) * be end of packet if we were reading)
*/ */
#if 0 /* FIXME: This is broke broke broke, for some reason */
if ((via[B] & TREQ) == 0) { if ((via[B] & TREQ) == 0) {
printk("macii_start: weird poll stuff. huh?\n");
/* /*
* FIXME - we need to restart this on a timer * FIXME - we need to restart this on a timer
* or a collision at boot hangs us. * or a collision at boot hangs us.
...@@ -359,6 +362,7 @@ static void macii_start(void) ...@@ -359,6 +362,7 @@ static void macii_start(void)
need_poll = 0; need_poll = 0;
} }
} }
#endif
/* /*
* Another retry pending? (sanity check) * Another retry pending? (sanity check)
*/ */
...@@ -378,7 +382,7 @@ static void macii_start(void) ...@@ -378,7 +382,7 @@ static void macii_start(void)
/* set ADB state to 'command' */ /* set ADB state to 'command' */
via[B] = (via[B] & ~ST_MASK) | ST_CMD; via[B] = (via[B] & ~ST_MASK) | ST_CMD;
macii_state = sent_first_byte; macii_state = sending;
data_index = 2; data_index = 2;
restore_flags(flags); restore_flags(flags);
...@@ -461,15 +465,14 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -461,15 +465,14 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
macii_state = reading; macii_state = reading;
break; break;
case sent_first_byte: case sending:
req = current_req; req = current_req;
/* maybe we're already done (Talk, or Poll)? */
if (data_index >= req->nbytes) { if (data_index >= req->nbytes) {
/* reset to shift in */ /* print an error message if a listen command has no data */
/* If it's a Listen command and we're done, someone's doing weird stuff. */
if (((command_byte & 0x0C) == 0x08) if (((command_byte & 0x0C) == 0x08)
&& (console_loglevel == 10)) /* && (console_loglevel == 10) */
printk("macii_interrupt: listen command with no data: %x!\n", && (data_index == 2))
printk("MacII ADB: listen command with no data: %x!\n",
command_byte); command_byte);
/* reset to shift in */ /* reset to shift in */
via[ACR] &= ~SR_OUT; via[ACR] &= ~SR_OUT;
...@@ -479,38 +482,6 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -479,38 +482,6 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
req->sent = 1; req->sent = 1;
if (req->reply_expected) {
macii_state = awaiting_reply;
} else {
req->complete = 1;
current_req = req->next;
if (req->done) (*req->done)(req);
macii_state = idle;
if (current_req || retry_req)
macii_start();
else
macii_retransmit((command_byte & 0xF0) >> 4);
}
} else {
/* SR already set to shift out; send byte */
via[SR] = current_req->data[data_index++];
/* set state to ST_EVEN (first byte was: ST_CMD) */
via[B] = (via[B] & ~ST_MASK) | ST_EVEN;
macii_state = sending;
}
break;
case sending:
req = current_req;
if (data_index >= req->nbytes) {
/* reset to shift in */
via[ACR] &= ~SR_OUT;
x = via[SR];
/* set ADB state idle - might get SRQ */
via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
req->sent = 1;
if (req->reply_expected) { if (req->reply_expected) {
macii_state = awaiting_reply; macii_state = awaiting_reply;
} else { } else {
...@@ -526,9 +497,14 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -526,9 +497,14 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
} else { } else {
via[SR] = req->data[data_index++]; via[SR] = req->data[data_index++];
if ( (via[B] & ST_MASK) == ST_CMD ) {
/* just sent the command byte, set to EVEN */
via[B] = (via[B] & ~ST_MASK) | ST_EVEN;
} else {
/* invert state bits, toggle ODD/EVEN */ /* invert state bits, toggle ODD/EVEN */
via[B] ^= ST_MASK; via[B] ^= ST_MASK;
} }
}
break; break;
case reading: case reading:
...@@ -551,7 +527,7 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -551,7 +527,7 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
* on /INT, meaning we missed it :-( * on /INT, meaning we missed it :-(
*/ */
x = via[SR]; x = via[SR];
if (x != 0xFF) printk("macii_interrupt: mistaken timeout/SRQ!\n"); if (x != 0xFF) printk("MacII ADB: mistaken timeout/SRQ!\n");
if ((status & TREQ) == (last_status & TREQ)) { if ((status & TREQ) == (last_status & TREQ)) {
/* Not a timeout. Unsolicited SRQ? weird. */ /* Not a timeout. Unsolicited SRQ? weird. */
...@@ -598,7 +574,7 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -598,7 +574,7 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
* byte of timeout packet! * byte of timeout packet!
* Timeouts are signaled by 4x FF. * Timeouts are signaled by 4x FF.
*/ */
if (!(status & TREQ) && (x == 0x00)) { /* != 0xFF */ if (((status & TREQ) == 0) && (x == 0x00)) { /* != 0xFF */
/* invert state bits, toggle ODD/EVEN */ /* invert state bits, toggle ODD/EVEN */
via[B] ^= ST_MASK; via[B] ^= ST_MASK;
...@@ -647,11 +623,11 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs) ...@@ -647,11 +623,11 @@ void macii_interrupt(int irq, void *arg, struct pt_regs *regs)
break; break;
} }
/* /IRQ seen, so the ADB controller has data for us */
if (!(status & TREQ)) {
/* set ADB state to idle */ /* set ADB state to idle */
via[B] = (via[B] & ~ST_MASK) | ST_IDLE; via[B] = (via[B] & ~ST_MASK) | ST_IDLE;
/* /IRQ seen, so the ADB controller has data for us */
if ((via[B] & TREQ) != 0) {
macii_state = reading; macii_state = reading;
reply_buf[0] = command_byte; reply_buf[0] = command_byte;
......
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
* *
* Original sources (c) Alan Cox, Paul Mackerras, and others. * Original sources (c) Alan Cox, Paul Mackerras, and others.
* *
* Rewritten for Unified ADB by David Huggins-Daines <dhd@debian.org> */ * Rewritten for Unified ADB by David Huggins-Daines <dhd@debian.org>
*
* 7/13/2000- extensive changes by Andrew McPherson <andrew@macduff.dhs.org>
* Works about 30% of the time now.
*/
#include <linux/types.h> #include <linux/types.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -56,6 +60,8 @@ static volatile unsigned char *via; ...@@ -56,6 +60,8 @@ static volatile unsigned char *via;
#define ADB_DELAY 150 #define ADB_DELAY 150
#undef DEBUG_MACIISI_ADB
static struct adb_request* current_req = NULL; static struct adb_request* current_req = NULL;
static struct adb_request* last_req = NULL; static struct adb_request* last_req = NULL;
static unsigned char maciisi_rbuf[16]; static unsigned char maciisi_rbuf[16];
...@@ -63,6 +69,8 @@ static unsigned char *reply_ptr = NULL; ...@@ -63,6 +69,8 @@ static unsigned char *reply_ptr = NULL;
static int data_index; static int data_index;
static int reading_reply; static int reading_reply;
static int reply_len; static int reply_len;
static int tmp;
static int need_sync;
static enum maciisi_state { static enum maciisi_state {
idle, idle,
...@@ -73,12 +81,13 @@ static enum maciisi_state { ...@@ -73,12 +81,13 @@ static enum maciisi_state {
static int maciisi_probe(void); static int maciisi_probe(void);
static int maciisi_init(void); static int maciisi_init(void);
static int maciisi_send_request(struct adb_request* req, int sync); static int maciisi_send_request(struct adb_request* req, int sync);
static void maciisi_sync(struct adb_request *req);
static int maciisi_write(struct adb_request* req); static int maciisi_write(struct adb_request* req);
static void maciisi_interrupt(int irq, void* arg, struct pt_regs* regs); static void maciisi_interrupt(int irq, void* arg, struct pt_regs* regs);
static void maciisi_input(unsigned char *buf, int nb, struct pt_regs *regs); static void maciisi_input(unsigned char *buf, int nb, struct pt_regs *regs);
static int maciisi_init_via(void); static int maciisi_init_via(void);
static void maciisi_poll(void); static void maciisi_poll(void);
static void maciisi_start(void); static int maciisi_start(void);
struct adb_driver via_maciisi_driver = { struct adb_driver via_maciisi_driver = {
"Mac IIsi", "Mac IIsi",
...@@ -114,63 +123,105 @@ maciisi_init(void) ...@@ -114,63 +123,105 @@ maciisi_init(void)
return err; return err;
} }
if (request_irq(IRQ_MAC_ADB, maciisi_interrupt, IRQ_FLG_LOCK, if (request_irq(IRQ_MAC_ADB, maciisi_interrupt, IRQ_FLG_LOCK | IRQ_FLG_FAST,
"ADB", maciisi_interrupt)) { "ADB", maciisi_interrupt)) {
printk(KERN_ERR "maciisi_init: can't get irq %d\n", IRQ_MAC_ADB); printk(KERN_ERR "maciisi_init: can't get irq %d\n", IRQ_MAC_ADB);
return -EAGAIN; return -EAGAIN;
} }
printk("adb: Mac IIsi driver v0.1 for Unified ADB.\n"); printk("adb: Mac IIsi driver v0.2 for Unified ADB.\n");
return 0; return 0;
} }
/* Flush data from the ADB controller */
static void static void
maciisi_stfu(void) maciisi_stfu(void)
{ {
int status = via[B] & (TIP|TREQ); int status = via[B] & (TIP|TREQ);
if (status & TREQ) { if (status & TREQ) {
#ifdef DEBUG_MACIISI_ADB
printk (KERN_DEBUG "maciisi_stfu called with TREQ high!\n"); printk (KERN_DEBUG "maciisi_stfu called with TREQ high!\n");
#endif
return; return;
} }
/* start transfer */ udelay(ADB_DELAY);
via[ACR] &= ~SR_OUT;
via[IER] = IER_CLR | SR_INT;
udelay(ADB_DELAY);
status = via[B] & (TIP|TREQ);
if (!(status & TREQ))
{
via[B] |= TIP; via[B] |= TIP;
while (!(status & TREQ)) {
while(1)
{
int poll_timeout = ADB_DELAY * 5; int poll_timeout = ADB_DELAY * 5;
/* Poll for SR interrupt */ /* Poll for SR interrupt */
while (!(via[IFR] & SR_INT) && poll_timeout-- > 0) while (!(via[IFR] & SR_INT) && poll_timeout-- > 0)
status = via[B] & (TIP|TREQ); status = via[B] & (TIP|TREQ);
via[SR]; /* Clear shift register */
printk(KERN_DEBUG "maciisi_stfu: status %x timeout %d\n", tmp = via[SR]; /* Clear shift register */
status, poll_timeout); #ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_stfu: status %x timeout %d data %x\n",
status, poll_timeout, tmp);
#endif
if(via[B] & TREQ)
break;
/* ACK on-off */ /* ACK on-off */
via[B] |= TACK; via[B] |= TACK;
udelay(ADB_DELAY); udelay(ADB_DELAY);
via[B] &= ~TACK; via[B] &= ~TACK;
} }
/* end frame */ /* end frame */
via[B] &= ~TIP; via[B] &= ~TIP;
udelay(ADB_DELAY);
}
via[IER] = IER_SET | SR_INT;
} }
/* All specifically VIA-related initialization goes here */ /* All specifically VIA-related initialization goes here */
static int static int
maciisi_init_via(void) maciisi_init_via(void)
{ {
int i;
/* Set the lines up. We want TREQ as input TACK|TIP as output */ /* Set the lines up. We want TREQ as input TACK|TIP as output */
via[DIRB] = (via[DIRB] | TACK | TIP) & ~TREQ; via[DIRB] = (via[DIRB] | TACK | TIP) & ~TREQ;
/* Shift register on input */ /* Shift register on input */
via[ACR] = (via[ACR] & ~SR_CTRL) | SR_EXT; via[ACR] = (via[ACR] & ~SR_CTRL) | SR_EXT;
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_init_via: initial status %x\n", via[B] & (TIP|TREQ)); printk(KERN_DEBUG "maciisi_init_via: initial status %x\n", via[B] & (TIP|TREQ));
#endif
/* Wipe any pending data and int */
tmp = via[SR];
/* Enable keyboard interrupts */
via[IER] = IER_SET | SR_INT;
/* Set initial state: idle */ /* Set initial state: idle */
via[B] &= ~(TACK|TIP); via[B] &= ~(TACK|TIP);
/* Wipe any pending data and int */ /* Clear interrupt bit */
via[SR]; via[IFR] = SR_INT;
if (!(via[B] & TREQ))
for(i = 0; i < 60; i++) {
udelay(ADB_DELAY);
maciisi_stfu(); maciisi_stfu();
via[IER] = IER_SET | SR_INT; udelay(ADB_DELAY);
if(via[B] & TREQ)
break;
}
if (i == 60)
printk(KERN_ERR "maciisi_init_via: bus jam?\n");
maciisi_state = idle; maciisi_state = idle;
need_sync = 0;
return 0; return 0;
} }
...@@ -179,32 +230,67 @@ static int ...@@ -179,32 +230,67 @@ static int
maciisi_send_request(struct adb_request* req, int sync) maciisi_send_request(struct adb_request* req, int sync)
{ {
int i; int i;
static int dump_packet = 1;
#ifdef DEBUG_MACIISI_ADB
static int dump_packet = 0;
#endif
if (via == NULL) { if (via == NULL) {
req->complete = 1; req->complete = 1;
return -ENXIO; return -ENXIO;
} }
#ifdef DEBUG_MACIISI_ADB
if (dump_packet) { if (dump_packet) {
printk(KERN_DEBUG "maciisi_send_request:"); printk(KERN_DEBUG "maciisi_send_request:");
for (i = 0; i < req->nbytes; i++) { for (i = 0; i < req->nbytes; i++) {
printk(" %.2x", req->data[i]); printk(" %.2x", req->data[i]);
} }
printk("\n"); printk(" sync %d\n", sync);
} }
#endif
req->reply_expected = 1; req->reply_expected = 1;
i = maciisi_write(req); i = maciisi_write(req);
if (i) if (i)
{
/* Normally, if a packet requires syncing, that happens at the end of
* maciisi_send_request. But if the transfer fails, it will be restarted
* by maciisi_interrupt(). We use need_sync to tell maciisi_interrupt
* when to sync a packet that it sends out.
*
* Suggestions on a better way to do this are welcome.
*/
if(i == -EBUSY && sync)
need_sync = 1;
else
need_sync = 0;
return i; return i;
}
if(sync)
maciisi_sync(req);
return 0;
}
if (sync) { /* Poll the ADB chip until the request completes */
while (!req->complete) { static void maciisi_sync(struct adb_request *req)
{
int count = 0;
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_sync called\n");
#endif
/* If for some reason the ADB chip shuts up on us, we want to avoid an endless loop. */
while (!req->complete && count++ < 50) {
maciisi_poll(); maciisi_poll();
} }
} /* This could be BAD... when the ADB controller doesn't respond
return 0; * for this long, it's probably not coming back :-( */
if(count >= 50) /* Hopefully shouldn't happen */
printk(KERN_ERR "maciisi_send_request: poll timed out!\n");
} }
/* Enqueue a request, and run the queue if possible */ /* Enqueue a request, and run the queue if possible */
...@@ -212,8 +298,8 @@ static int ...@@ -212,8 +298,8 @@ static int
maciisi_write(struct adb_request* req) maciisi_write(struct adb_request* req)
{ {
unsigned long flags; unsigned long flags;
int i;
printk(KERN_DEBUG "maciisi_write called, state=%d ifr=%x\n", maciisi_state, via[IFR]);
/* We will accept CUDA packets - the VIA sends them to us, so /* We will accept CUDA packets - the VIA sends them to us, so
it figures that we should be able to send them to it */ it figures that we should be able to send them to it */
if (req->nbytes < 2 || req->data[0] > CUDA_PACKET) { if (req->nbytes < 2 || req->data[0] > CUDA_PACKET) {
...@@ -225,7 +311,9 @@ maciisi_write(struct adb_request* req) ...@@ -225,7 +311,9 @@ maciisi_write(struct adb_request* req)
req->sent = 0; req->sent = 0;
req->complete = 0; req->complete = 0;
req->reply_len = 0; req->reply_len = 0;
save_flags(flags); cli();
save_flags(flags);
cli();
if (current_req) { if (current_req) {
last_req->next = req; last_req->next = req;
...@@ -235,44 +323,68 @@ maciisi_write(struct adb_request* req) ...@@ -235,44 +323,68 @@ maciisi_write(struct adb_request* req)
last_req = req; last_req = req;
} }
if (maciisi_state == idle) if (maciisi_state == idle)
maciisi_start(); {
i = maciisi_start();
if(i != 0)
{
restore_flags(flags);
return i;
}
}
else else
{
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_write: would start, but state is %d\n", maciisi_state); printk(KERN_DEBUG "maciisi_write: would start, but state is %d\n", maciisi_state);
#endif
restore_flags(flags);
return -EBUSY;
}
restore_flags(flags); restore_flags(flags);
return 0; return 0;
} }
static void static int
maciisi_start(void) maciisi_start(void)
{ {
struct adb_request* req; struct adb_request* req;
int status; int status;
printk(KERN_DEBUG "maciisi_start called, state=%d, ifr=%x\n", maciisi_state, via[IFR]); #ifdef DEBUG_MACIISI_ADB
status = via[B] & (TIP | TREQ);
printk(KERN_DEBUG "maciisi_start called, state=%d, status=%x, ifr=%x\n", maciisi_state, status, via[IFR]);
#endif
if (maciisi_state != idle) { if (maciisi_state != idle) {
/* shouldn't happen */ /* shouldn't happen */
printk(KERN_ERR "maciisi_start: maciisi_start called when driver busy!\n"); printk(KERN_ERR "maciisi_start: maciisi_start called when driver busy!\n");
return; return -EBUSY;
} }
req = current_req; req = current_req;
if (req == NULL) if (req == NULL)
return; return -EINVAL;
status = via[B] & (TIP|TREQ); status = via[B] & (TIP|TREQ);
if (!(status & TREQ)) { if (!(status & TREQ)) {
/* Bus is busy, set up for reading */ #ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_start: bus busy - aborting\n"); printk(KERN_DEBUG "maciisi_start: bus busy - aborting\n");
return; #endif
return -EBUSY;
} }
/* Okay, send */ /* Okay, send */
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "maciisi_start: sending\n"); printk(KERN_DEBUG "maciisi_start: sending\n");
#endif
/* Set state to active */ /* Set state to active */
via[B] |= TIP; via[B] |= TIP;
/* ACK off */ /* ACK off */
via[B] &= ~TACK; via[B] &= ~TACK;
/* Delay */
udelay(ADB_DELAY);
/* Shift out and send */ /* Shift out and send */
via[ACR] |= SR_OUT; via[ACR] |= SR_OUT;
via[SR] = req->data[0]; via[SR] = req->data[0];
...@@ -280,6 +392,8 @@ maciisi_start(void) ...@@ -280,6 +392,8 @@ maciisi_start(void)
/* ACK on */ /* ACK on */
via[B] |= TACK; via[B] |= TACK;
maciisi_state = sending; maciisi_state = sending;
return 0;
} }
void void
...@@ -292,6 +406,9 @@ maciisi_poll(void) ...@@ -292,6 +406,9 @@ maciisi_poll(void)
if (via[IFR] & SR_INT) { if (via[IFR] & SR_INT) {
maciisi_interrupt(0, 0, 0); maciisi_interrupt(0, 0, 0);
} }
else /* avoid calling this function too quickly in a loop */
udelay(ADB_DELAY);
restore_flags(flags); restore_flags(flags);
} }
...@@ -303,31 +420,44 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -303,31 +420,44 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
{ {
int status; int status;
struct adb_request *req; struct adb_request *req;
static int dump_reply = 1; #ifdef DEBUG_MACIISI_ADB
static int dump_reply = 0;
#endif
int i;
unsigned long flags;
save_flags(flags);
cli();
status = via[B] & (TIP|TREQ);
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "state %d status %x ifr %x\n", maciisi_state, status, via[IFR]);
#endif
if (!(via[IFR] & SR_INT)) { if (!(via[IFR] & SR_INT)) {
/* Shouldn't happen, we hope */ /* Shouldn't happen, we hope */
printk(KERN_DEBUG "maciisi_interrupt: called without interrupt flag set\n"); printk(KERN_ERR "maciisi_interrupt: called without interrupt flag set\n");
restore_flags(flags);
return; return;
} }
status = via[B] & (TIP|TREQ); /* Clear the interrupt */
printk(KERN_DEBUG "state %d status %x ifr %x\n", maciisi_state, status, via[IFR]); /* via[IFR] = SR_INT; */
switch_start: switch_start:
switch (maciisi_state) { switch (maciisi_state) {
case idle: case idle:
printk(KERN_DEBUG "maciisi_interrupt: state=idle, status %x\n", status);
if (status & TIP) if (status & TIP)
printk(KERN_DEBUG "maciisi_interrupt: state is idle but TIP asserted!\n"); printk(KERN_ERR "maciisi_interrupt: state is idle but TIP asserted!\n");
if(!reading_reply)
udelay(ADB_DELAY); udelay(ADB_DELAY);
/* Shift in */ /* Shift in */
via[ACR] &= ~SR_OUT; via[ACR] &= ~SR_OUT;
/* Signal start of frame */ /* Signal start of frame */
via[B] |= TIP; via[B] |= TIP;
/* Clear the interrupt (throw this value on the floor, it's useless) */ /* Clear the interrupt (throw this value on the floor, it's useless) */
via[SR]; tmp = via[SR];
/* ACK adb chip, high-low */ /* ACK adb chip, high-low */
via[B] |= TACK; via[B] |= TACK;
udelay(ADB_DELAY); udelay(ADB_DELAY);
...@@ -337,37 +467,39 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -337,37 +467,39 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
if (reading_reply) { if (reading_reply) {
reply_ptr = current_req->reply; reply_ptr = current_req->reply;
} else { } else {
printk(KERN_DEBUG "maciisi_interrupt: received unsolicited packet\n");
reply_ptr = maciisi_rbuf; reply_ptr = maciisi_rbuf;
} }
break; break;
case sending: case sending:
printk(KERN_DEBUG "maciisi_interrupt: state=sending, status=%x\n", status); /* via[SR]; */
/* Clear interrupt */
via[SR];
/* Set ACK off */ /* Set ACK off */
via[B] &= ~TACK; via[B] &= ~TACK;
req = current_req; req = current_req;
if (!(status & TREQ)) { if (!(status & TREQ)) {
/* collision */ /* collision */
printk(KERN_DEBUG "maciisi_interrupt: send collision\n"); printk(KERN_ERR "maciisi_interrupt: send collision\n");
/* Set idle and input */ /* Set idle and input */
via[B] &= ~TIP;
via[ACR] &= ~SR_OUT; via[ACR] &= ~SR_OUT;
tmp = via[SR];
via[B] &= ~TIP;
/* Must re-send */ /* Must re-send */
reading_reply = 0; reading_reply = 0;
reply_len = 0; reply_len = 0;
maciisi_state = idle; maciisi_state = idle;
udelay(ADB_DELAY);
/* process this now, because the IFR has been cleared */ /* process this now, because the IFR has been cleared */
goto switch_start; goto switch_start;
} }
udelay(ADB_DELAY);
if (data_index >= req->nbytes) { if (data_index >= req->nbytes) {
/* Sent the whole packet, put the bus back in idle state */ /* Sent the whole packet, put the bus back in idle state */
/* Shift in, we are about to read a reply (hopefully) */ /* Shift in, we are about to read a reply (hopefully) */
via[ACR] &= ~SR_OUT; via[ACR] &= ~SR_OUT;
tmp = via[SR];
/* End of frame */ /* End of frame */
via[B] &= ~TIP; via[B] &= ~TIP;
req->sent = 1; req->sent = 1;
...@@ -380,13 +512,19 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -380,13 +512,19 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
current_req = req->next; current_req = req->next;
if (req->done) if (req->done)
(*req->done)(req); (*req->done)(req);
/* Do any queued requests now */
i = maciisi_start();
if(i == 0 && need_sync) {
/* Packet needs to be synced */
maciisi_sync(current_req);
}
if(i != -EBUSY)
need_sync = 0;
} }
} else { } else {
/* Sending more stuff */ /* Sending more stuff */
/* Shift out */ /* Shift out */
via[ACR] |= SR_OUT; via[ACR] |= SR_OUT;
/* Delay */
udelay(ADB_DELAY);
/* Write */ /* Write */
via[SR] = req->data[data_index++]; via[SR] = req->data[data_index++];
/* Signal 'byte ready' */ /* Signal 'byte ready' */
...@@ -395,18 +533,24 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -395,18 +533,24 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
break; break;
case reading: case reading:
printk(KERN_DEBUG "maciisi_interrupt: state=reading, status=%x\n", status);
/* Shift in */ /* Shift in */
via[ACR] &= ~SR_OUT; /* via[ACR] &= ~SR_OUT; */ /* Not in 2.2 */
if (reply_len++ > 16) { if (reply_len++ > 16) {
printk(KERN_ERR "maciisi_interrupt: reply too long, aborting read\n"); printk(KERN_ERR "maciisi_interrupt: reply too long, aborting read\n");
via[B] |= TACK; via[B] |= TACK;
udelay(ADB_DELAY); udelay(ADB_DELAY);
via[B] &= ~(TACK|TIP); via[B] &= ~(TACK|TIP);
maciisi_state = idle; maciisi_state = idle;
maciisi_start(); i = maciisi_start();
if(i == 0 && need_sync) {
/* Packet needs to be synced */
maciisi_sync(current_req);
}
if(i != -EBUSY)
need_sync = 0;
break; break;
} }
/* Read data */
*reply_ptr++ = via[SR]; *reply_ptr++ = via[SR];
status = via[B] & (TIP|TREQ); status = via[B] & (TIP|TREQ);
/* ACK on/off */ /* ACK on/off */
...@@ -418,6 +562,8 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -418,6 +562,8 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
/* end of frame */ /* end of frame */
via[B] &= ~TIP; via[B] &= ~TIP;
tmp = via[SR]; /* That's what happens in 2.2 */
udelay(ADB_DELAY); /* Give controller time to recover */
/* end of packet, deal with it */ /* end of packet, deal with it */
if (reading_reply) { if (reading_reply) {
...@@ -434,6 +580,7 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -434,6 +580,7 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
memmove(req->reply, req->reply + 2, req->reply_len); memmove(req->reply, req->reply + 2, req->reply_len);
} }
} }
#ifdef DEBUG_MACIISI_ADB
if (dump_reply) { if (dump_reply) {
int i; int i;
printk(KERN_DEBUG "maciisi_interrupt: reply is "); printk(KERN_DEBUG "maciisi_interrupt: reply is ");
...@@ -441,6 +588,7 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -441,6 +588,7 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
printk(" %.2x", req->reply[i]); printk(" %.2x", req->reply[i]);
printk("\n"); printk("\n");
} }
#endif
req->complete = 1; req->complete = 1;
current_req = req->next; current_req = req->next;
if (req->done) if (req->done)
...@@ -453,34 +601,62 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs) ...@@ -453,34 +601,62 @@ maciisi_interrupt(int irq, void* arg, struct pt_regs* regs)
maciisi_state = idle; maciisi_state = idle;
status = via[B] & (TIP|TREQ); status = via[B] & (TIP|TREQ);
if (!(status & TREQ)) { if (!(status & TREQ)) {
/* Timeout?! */ /* Timeout?! More likely, another packet coming in already */
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "extra data after packet: status %x ifr %x\n", printk(KERN_DEBUG "extra data after packet: status %x ifr %x\n",
status, via[IFR]); status, via[IFR]);
maciisi_stfu(); #endif
#if 0
udelay(ADB_DELAY);
via[B] |= TIP;
maciisi_state = reading;
reading_reply = 0;
reply_ptr = maciisi_rbuf;
#else
/* Process the packet now */
reading_reply = 0;
goto switch_start;
#endif
/* We used to do this... but the controller might actually have data for us */
/* maciisi_stfu(); */
} }
else {
/* Do any queued requests now if possible */ /* Do any queued requests now if possible */
maciisi_start(); i = maciisi_start();
if(i == 0 && need_sync) {
/* Packet needs to be synced */
maciisi_sync(current_req);
}
if(i != -EBUSY)
need_sync = 0;
}
break; break;
default: default:
printk("maciisi_interrupt: unknown maciisi_state %d?\n", maciisi_state); printk("maciisi_interrupt: unknown maciisi_state %d?\n", maciisi_state);
} }
restore_flags(flags);
} }
static void static void
maciisi_input(unsigned char *buf, int nb, struct pt_regs *regs) maciisi_input(unsigned char *buf, int nb, struct pt_regs *regs)
{ {
#ifdef DEBUG_MACIISI_ADB
int i; int i;
#endif
switch (buf[0]) { switch (buf[0]) {
case ADB_PACKET: case ADB_PACKET:
adb_input(buf+2, nb-2, regs, buf[1] & 0x40); adb_input(buf+2, nb-2, regs, buf[1] & 0x40);
break; break;
default: default:
#ifdef DEBUG_MACIISI_ADB
printk(KERN_DEBUG "data from IIsi ADB (%d bytes):", nb); printk(KERN_DEBUG "data from IIsi ADB (%d bytes):", nb);
for (i = 0; i < nb; ++i) for (i = 0; i < nb; ++i)
printk(" %.2x", buf[i]); printk(" %.2x", buf[i]);
printk("\n"); printk("\n");
#endif
break;
} }
} }
...@@ -120,6 +120,8 @@ static void pmu_done(struct adb_request *req); ...@@ -120,6 +120,8 @@ static void pmu_done(struct adb_request *req);
static void pmu_handle_data(unsigned char *data, int len, static void pmu_handle_data(unsigned char *data, int len,
struct pt_regs *regs); struct pt_regs *regs);
static void set_volume(int level); static void set_volume(int level);
static void pmu_enable_backlight(int on);
static void pmu_set_brightness(int level);
struct adb_driver via_pmu_driver = { struct adb_driver via_pmu_driver = {
"68K PMU", "68K PMU",
...@@ -746,7 +748,7 @@ int backlight_enabled = 0; ...@@ -746,7 +748,7 @@ int backlight_enabled = 0;
#define LEVEL_TO_BRIGHT(lev) ((lev) < 1? 0x7f: 0x4a - ((lev) << 1)) #define LEVEL_TO_BRIGHT(lev) ((lev) < 1? 0x7f: 0x4a - ((lev) << 1))
void static void
pmu_enable_backlight(int on) pmu_enable_backlight(int on)
{ {
struct adb_request req; struct adb_request req;
...@@ -780,7 +782,7 @@ pmu_enable_backlight(int on) ...@@ -780,7 +782,7 @@ pmu_enable_backlight(int on)
backlight_enabled = on; backlight_enabled = on;
} }
void static void
pmu_set_brightness(int level) pmu_set_brightness(int level)
{ {
int bright; int bright;
......
...@@ -75,6 +75,8 @@ enum { ...@@ -75,6 +75,8 @@ enum {
PMU_HEATHROW_BASED, /* PowerBook G3 series */ PMU_HEATHROW_BASED, /* PowerBook G3 series */
PMU_PADDINGTON_BASED, /* 1999 PowerBook G3 */ PMU_PADDINGTON_BASED, /* 1999 PowerBook G3 */
PMU_KEYLARGO_BASED, /* Core99 motherboard (PMU99) */ PMU_KEYLARGO_BASED, /* Core99 motherboard (PMU99) */
PMU_68K_V1, /* 68K PMU, version 1 */
PMU_68K_V2, /* 68K PMU, version 2 */
}; };
/* PMU PMU_POWER_EVENTS commands */ /* PMU PMU_POWER_EVENTS commands */
......
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