Replace via-maciisi with via-cuda driver
cover Replace via-maciisi with via-cuda driver
This patch series has some improvements for the the Cuda driver: cleanup, bug fixes and new functionality.
The broken via-maciisi driver is then replaced by via-cuda. This eliminates over 600 LoC.
Thanks to Stan Johnson for testing these patches on a Mac LC III and a PowerMac G3.
Finn Thain (10):
via-cuda: Cleanup printk calls
via-cuda: Remove redundant temporary variable
via-cuda: Add TREQ, TIP and TACK signal helpers
via-cuda: Prevent read buffer overflow
via-cuda: Fix re-initialization of reply_ptr and reading_reply
via-cuda: Avoid TREQ race condition
via-cuda: Use spinlock_irq_save/restore instead of enable/disable_irq
via-cuda: Initialize data_index early and increment consistently
via-cuda: Add support for Egret system controller m68k/mac: Replace via-maciisi driver with via-cuda driver
arch/m68k/include/asm/macintosh.h | 2 +- arch/m68k/mac/config.c | 18 +- arch/m68k/mac/misc.c | 72 +--- drivers/macintosh/Kconfig | 24 +- drivers/macintosh/Makefile | 1 - drivers/macintosh/adb.c | 4 - drivers/macintosh/via-cuda.c | 294 ++++++++++++----- drivers/macintosh/via-maciisi.c | 677 -------------------------------------- 8 files changed, 235 insertions(+), 857 deletions(-) delete mode 100644 drivers/macintosh/via-maciisi.c
Signature · 1 line
2.10.2
PATCH RESEND 1/10 via-cuda: Cleanup printk calls
Add missing log message severity, remove old debug messages and replace printk() loop with print_hex_dump() call.
--- drivers/macintosh/via-cuda.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-)
drivers/macintosh/via-cuda.c +6 -20
@@ -221,7 +221,7 @@ static int __init via_cuda_start(void)return -EAGAIN ; } -printk ("Macintosh CUDA driver v0.5 for Unified ADB.\n" ); +pr_info ("Macintosh CUDA driver v0.5 for Unified ADB.\n" ); cuda_fully_inited =1 ;return 0 ;
@@ -251,7 +251,7 @@ cuda_probe(void)int x; \for (x =1000 ; !(cond); --x) { \if (x ==0 ) { \ -printk ("Timeout waiting for " what"\n" ); \ +pr_err ("Timeout waiting for " what"\n" ); \return -ENXIO ; \ } \udelay (100 ); \
@@ -357,6 +357,7 @@ cuda_reset_adb_bus(void)return 0 ; }#endif /* CONFIG_ADB */ +/* Construct and send a cuda request */ int cuda_request(struct adb_request *req, void (*done)(struct adb_request *),
@@ -474,12 +475,9 @@ cuda_interrupt(int irq, void *arg) } status = (~in_8 (&via[B ]) & (TIP |TREQ )) | (in_8 (&via[ACR ]) &SR_OUT ); -/* printk("cuda_interrupt: state=%d status=%x\n", cuda_state, status); */ switch (cuda_state) {case idle:/* CUDA has sent us the first byte of data - unsolicited */ -if (status !=TREQ ) -printk ("cuda: state=idle, status=%x\n" , status); (void )in_8 (&via[SR ]);out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); cuda_state = reading;
@@ -489,8 +487,6 @@ cuda_interrupt(int irq, void *arg)case awaiting_reply:/* CUDA has sent us the first byte of data of a reply */ -if (status !=TREQ ) -printk ("cuda: state=awaiting_reply, status=%x\n" , status); (void )in_8 (&via[SR ]);out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); cuda_state = reading;
@@ -506,9 +502,6 @@ cuda_interrupt(int irq, void *arg)out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); cuda_state = idle; }else { -/* assert status == TIP + SR_OUT */ -if (status !=TIP +SR_OUT ) -printk ("cuda: state=sent_first_byte status=%x\n" , status);out_8 (&via[SR ], current_req->data[1 ]);out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); data_index =2 ;
@@ -545,9 +538,6 @@ cuda_interrupt(int irq, void *arg)out_8 (&via[B ],in_8 (&via[B ]) |TACK |TIP ); cuda_state = read_done; }else { -/* assert status == TIP | TREQ */ -if (status !=TIP +TREQ ) -printk ("cuda: state=reading status=%x\n" , status);out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); }break ;
@@ -593,7 +583,7 @@ cuda_interrupt(int irq, void *arg)break ;default : -printk ("cuda_interrupt: unknown cuda_state %d?\n" , cuda_state); +pr_err ("cuda_interrupt: unknown cuda_state %d?\n" , cuda_state); }spin_unlock (&cuda_lock);if (complete && req) {
@@ -614,8 +604,6 @@ cuda_interrupt(int irq, void *arg)static void cuda_input (unsigned char *buf,int nb) { -int i; -switch (buf[0 ]) {case ADB_PACKET :#ifdef CONFIG_XMON
@@ -633,9 +621,7 @@ cuda_input(unsigned char *buf, int nb)break ;default : -printk ("data from cuda (%d bytes):" , nb); -for (i =0 ; i < nb; ++i) -printk (" %.2x" , buf[i]); -printk ("\n" ); +print_hex_dump (KERN_INFO ,"cuda_input: " ,DUMP_PREFIX_NONE ,32 ,1 , + buf, nb, false); } }
Signature · 1 line
2.10.2
Re: [RESEND,01/10] via-cuda: Cleanup printk calls
Quoted 5 lines · Finn Thain
Add missing log message severity, remove old debug messages and replace
printk()loop withprint_hex_dump()call.Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/523717d1496c794e8380d0e3de5ca6
cheers
PATCH RESEND 2/10 via-cuda: Remove redundant temporary variable
In reply to Finn ThainThere is no possibility that current_req can change during execution of cuda_start(). This can be confirmed by inspection: cuda_lock is always held whenever cuda_start() is called or current_req is modified.
--- drivers/macintosh/via-cuda.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/macintosh/via-cuda.c +2 -6
@@ -414,19 +414,15 @@ cuda_write(struct adb_request *req)static void cuda_start (void ) { -struct adb_request *req; -/* assert cuda_state == idle */ -/* get the packet to send */ - req = current_req; -if (req ==0 ) +if (current_req ==NULL )return ;if ((in_8 (&via[B ]) &TREQ ) ==0 )return ;/* a byte is coming in from the CUDA */ /* set the shift register to shift out and send a byte */ out_8 (&via[ACR ],in_8 (&via[ACR ]) |SR_OUT ); -out_8 (&via[SR ], req->data[0 ]); +out_8 (&via[SR ], current_req->data[0 ]);out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); cuda_state = sent_first_byte; }
Signature · 1 line
2.10.2
PATCH RESEND 3/10 via-cuda: Add TREQ, TIP and TACK signal helpers
In reply to Finn ThainIntroduce some helpers for handling the signalling between VIA and Cuda. This abstraction will be used to add support for Egret devices, which utilize slightly different signalling.
Don't invert the sense of the Cuda's active-low signals when storing them in the 'status' variable. Just assert, negate and test those signals using the helpers.
The state machine does not need to test its own output signals to figure out what to do next: the next state depends on the Cuda's TREQ output. Just call the TREQ_asserted() helper function to test for that.
Similarly, there is no need to store pin directions in the 'status' variable. That was only useful for debugging messages.
--- drivers/macintosh/via-cuda.c | 76 ++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 23 deletions(-)
drivers/macintosh/via-cuda.c +53 -23
@@ -65,6 +65,36 @@ static DEFINE_SPINLOCK(cuda_lock);#define IER_CLR 0/* clear bits in IER */ #define SR_INT 0x04/* Shift register full/empty */ +static inline bool TREQ_asserted (u8 portb) +{ +return !(portb &TREQ ); +} + +static inline void assert_TIP (void ) +{ +out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +} + +static inline void assert_TACK (void ) +{ +out_8 (&via[B ],in_8 (&via[B ]) & ~TACK ); +} + +static inline void toggle_TACK (void ) +{ +out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); +} + +static inline void negate_TACK (void ) +{ +out_8 (&via[B ],in_8 (&via[B ]) |TACK ); +} + +static inline void negate_TIP_and_TACK (void ) +{ +out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); +} + static enum cuda_state { idle, sent_first_byte,
@@ -262,7 +292,7 @@ static int__init cuda_init_via (void) {out_8 (&via[DIRB ], (in_8 (&via[DIRB ]) |TACK |TIP ) & ~TREQ );/* TACK & TIP out */ -out_8 (&via[B ],in_8 (&via[B ]) |TACK |TIP );/* negate them */ +negate_TIP_and_TACK ();out_8 (&via[ACR ] ,(in_8 (&via[ACR ]) & ~SR_CTRL ) |SR_EXT );/* SR data in */ (void )in_8 (&via[SR ]);/* clear any left-over data */ #ifdef CONFIG_PPC
@@ -278,10 +308,10 @@ __init cuda_init_via(void)out_8 (&via[IFR ],SR_INT );/* sync with the CUDA - assert TACK without TIP */ -out_8 (&via[B ],in_8 (&via[B ]) & ~TACK ); +assert_TACK ();/* wait for the CUDA to assert TREQ in response */ -WAIT_FOR ((in_8 (&via[B ]) &TREQ ) ==0 ,"CUDA response to sync" ); +WAIT_FOR (TREQ_asserted (in_8 (&via[B ])),"CUDA response to sync" );/* wait for the interrupt and then clear it */ WAIT_FOR (in_8 (&via[IFR ]) &SR_INT ,"CUDA response to sync (2)" );
@@ -289,14 +319,13 @@ __init cuda_init_via(void)out_8 (&via[IFR ],SR_INT );/* finish the sync by negating TACK */ -out_8 (&via[B ],in_8 (&via[B ]) |TACK ); +negate_TACK ();/* wait for the CUDA to negate TREQ and the corresponding interrupt */ -WAIT_FOR (in_8 (&via[B ]) &TREQ ,"CUDA response to sync (3)" ); +WAIT_FOR (!TREQ_asserted (in_8 (&via[B ])),"CUDA response to sync (3)" );WAIT_FOR (in_8 (&via[IFR ]) &SR_INT ,"CUDA response to sync (4)" ); (void )in_8 (&via[SR ]);out_8 (&via[IFR ],SR_INT ); -out_8 (&via[B ],in_8 (&via[B ]) |TIP );/* should be unnecessary */ return 0 ; }
@@ -417,13 +446,13 @@ cuda_start(void)/* assert cuda_state == idle */ if (current_req ==NULL )return ; -if ((in_8 (&via[B ]) &TREQ ) ==0 ) +if (TREQ_asserted (in_8 (&via[B ])))return ;/* a byte is coming in from the CUDA */ /* set the shift register to shift out and send a byte */ out_8 (&via[ACR ],in_8 (&via[ACR ]) |SR_OUT );out_8 (&via[SR ], current_req->data[0 ]); -out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +assert_TIP (); cuda_state = sent_first_byte; }
@@ -444,7 +473,7 @@ EXPORT_SYMBOL(cuda_poll);static irqreturn_t cuda_interrupt (int irq,void *arg) { -int status; +u8 status;struct adb_request *req =NULL ;unsigned char ibuf[16 ];int ibuf_len =0 ;
@@ -469,13 +498,14 @@ cuda_interrupt(int irq, void *arg)out_8 (&via[IFR ],SR_INT ); } } - - status = (~in_8 (&via[B ]) & (TIP |TREQ )) | (in_8 (&via[ACR ]) &SR_OUT ); + + status =in_8 (&via[B ]) & (TIP |TACK |TREQ ); +switch (cuda_state) {case idle:/* CUDA has sent us the first byte of data - unsolicited */ (void )in_8 (&via[SR ]); -out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +assert_TIP (); cuda_state = reading; reply_ptr = cuda_rbuf; reading_reply =0 ;
@@ -484,22 +514,22 @@ cuda_interrupt(int irq, void *arg)case awaiting_reply:/* CUDA has sent us the first byte of data of a reply */ (void )in_8 (&via[SR ]); -out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +assert_TIP (); cuda_state = reading; reply_ptr = current_req->reply; reading_reply =1 ;break ;case sent_first_byte: -if (status ==TREQ +TIP +SR_OUT ) { +if (TREQ_asserted (status)) {/* collision */ out_8 (&via[ACR ],in_8 (&via[ACR ]) & ~SR_OUT ); (void )in_8 (&via[SR ]); -out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); +negate_TIP_and_TACK (); cuda_state = idle; }else {out_8 (&via[SR ], current_req->data[1 ]); -out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); +toggle_TACK (); data_index =2 ; cuda_state = sending; }
@@ -510,7 +540,7 @@ cuda_interrupt(int irq, void *arg)if (data_index >= req->nbytes) {out_8 (&via[ACR ],in_8 (&via[ACR ]) & ~SR_OUT ); (void )in_8 (&via[SR ]); -out_8 (&via[B ],in_8 (&via[B ]) |TACK |TIP ); +negate_TIP_and_TACK (); req->sent =1 ;if (req->reply_expected) { cuda_state = awaiting_reply;
@@ -523,18 +553,18 @@ cuda_interrupt(int irq, void *arg) } }else {out_8 (&via[SR ], req->data[data_index++]); -out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); +toggle_TACK (); }break ;case reading: *reply_ptr++ =in_8 (&via[SR ]); -if (status ==TIP ) { +if (!TREQ_asserted (status)) {/* that's all folks */ -out_8 (&via[B ],in_8 (&via[B ]) |TACK |TIP ); +negate_TIP_and_TACK (); cuda_state = read_done; }else { -out_8 (&via[B ],in_8 (&via[B ]) ^TACK ); +toggle_TACK (); }break ;
@@ -567,8 +597,8 @@ cuda_interrupt(int irq, void *arg) ibuf_len = reply_ptr - cuda_rbuf;memcpy (ibuf, cuda_rbuf, ibuf_len); } -if (status ==TREQ ) { -out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +if (TREQ_asserted (status)) { +assert_TIP (); cuda_state = reading; reply_ptr = cuda_rbuf; reading_reply =0 ;
Signature · 1 line
2.10.2
PATCH RESEND 4/10 via-cuda: Prevent read buffer overflow
In reply to Finn ThainIf the Cuda driver does not enter the 'read_done' state for some reason, it may continue in the 'reading' state until the buffer overflows. Add a bounds check to prevent this.
--- drivers/macintosh/via-cuda.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/macintosh/via-cuda.c +7 -1
@@ -470,6 +470,8 @@ cuda_poll(void) }EXPORT_SYMBOL (cuda_poll); +#define ARRAY_FULL (a, p) ((p) - (a) == ARRAY_SIZE(a)) +static irqreturn_t cuda_interrupt (int irq,void *arg) {
@@ -558,7 +560,11 @@ cuda_interrupt(int irq, void *arg)break ;case reading: - *reply_ptr++ =in_8 (&via[SR ]); +if (reading_reply ?ARRAY_FULL (current_req->reply, reply_ptr) + :ARRAY_FULL (cuda_rbuf, reply_ptr)) + (void )in_8 (&via[SR ]); +else + *reply_ptr++ =in_8 (&via[SR ]);if (!TREQ_asserted (status)) {/* that's all folks */ negate_TIP_and_TACK ();
Signature · 1 line
2.10.2
PATCH RESEND 5/10 via-cuda: Fix re-initialization of reply_ptr and reading_reply
In reply to Finn ThainWhen reading_reply is set, reply_ptr points into an adb_request struct. Conversely, when reply_ptr instead points into the global cuda_rbuf, reading_reply must be false.
Unfortunately, this rule can be violated because re-initialization of reply_ptr and reading_reply presently depends on the TREQ input.
Fix this by re-initializing reply_ptr and reading_reply as soon as they are known to be invalid.
--- drivers/macintosh/via-cuda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/macintosh/via-cuda.c +2 -2
@@ -592,6 +592,7 @@ cuda_interrupt(int irq, void *arg) } current_req = req->next; complete =1 ; + reading_reply =0 ; }else {/* This is tricky. We must break the spinlock to call * cuda_input. However, doing so means we might get
@@ -603,11 +604,10 @@ cuda_interrupt(int irq, void *arg) ibuf_len = reply_ptr - cuda_rbuf;memcpy (ibuf, cuda_rbuf, ibuf_len); } + reply_ptr = cuda_rbuf;if (TREQ_asserted (status)) {assert_TIP (); cuda_state = reading; - reply_ptr = cuda_rbuf; - reading_reply =0 ; }else { cuda_state = idle;cuda_start ();
Signature · 1 line
2.10.2
PATCH RESEND 6/10 via-cuda: Avoid TREQ race condition
In reply to Finn ThainWhen a read transaction completes, one of several things will happen:
a new transfer is started by the driver, a new transfer request is raised by the Cuda (i.e. TREQ asserted), or both happen at once.
When both happen at once, there is a race condition between the TREQ test in the read_done state and the same test in cuda_start(). Moreover, the former test uses a stale TREQ value.
Theoretically, this can result in the undesirable outcome that the interrupt handler completes with the state machine 'idle' when it should instead start the next transaction.
Avoid this race by calling cuda_start() first and then confirming that it succeeded. If not, test the current TREQ value before entering the 'reading' state.
--- drivers/macintosh/via-cuda.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/macintosh/via-cuda.c +3 -4
@@ -605,12 +605,11 @@ cuda_interrupt(int irq, void *arg)memcpy (ibuf, cuda_rbuf, ibuf_len); } reply_ptr = cuda_rbuf; -if (TREQ_asserted (status)) { + cuda_state = idle; +cuda_start (); +if (cuda_state == idle &&TREQ_asserted (in_8 (&via[B ]))) {assert_TIP (); cuda_state = reading; - }else { - cuda_state = idle; -cuda_start (); }break ;
Signature · 1 line
2.10.2
PATCH RESEND 7/10 via-cuda: Use spinlock_irq_save/restore instead of enable/disable_irq
In reply to Finn ThainThe cuda_start() function uses spinlock_irq_save/restore for mutual exclusion. Let's have cuda_poll() do the same when polling the VIA interrupt.
The benefit to disabling local irqs when the interrupt is being polled is that the interrupt handler now has the same timing properties regardless of whether it is invoked normally or from cuda_poll().
This driver was written back when local irqs remained enabled during execution of interrupt handlers and cuda_poll() was probably trying to achieve the same effect by use of enable/disable_irq.
---
I wondered whether the use of enable/disable_irq was an attempt to reduce interrupt latency given that VIA register accesses are slow. But if the interrupt has not yet fired, only one VIA access will take place, which imposes neglible latency anyway. If the interrupt has fired, we should execute the handler under the usual context, i.e. local irqs disabled.
--- drivers/macintosh/via-cuda.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/macintosh/via-cuda.c +5 -11
@@ -459,14 +459,7 @@ cuda_start(void)void cuda_poll (void ) { -/* cuda_interrupt only takes a normal lock, we disable -* interrupts here to avoid re-entering and thus deadlocking. -*/ -if (cuda_irq) -disable_irq (cuda_irq); -cuda_interrupt (0 ,NULL ); -if (cuda_irq) -enable_irq (cuda_irq); +cuda_interrupt (0 ,NULL ); }EXPORT_SYMBOL (cuda_poll);
@@ -475,13 +468,14 @@ EXPORT_SYMBOL(cuda_poll);static irqreturn_t cuda_interrupt (int irq,void *arg) { +unsigned long flags;u8 status;struct adb_request *req =NULL ;unsigned char ibuf[16 ];int ibuf_len =0 ;int complete =0 ; -spin_lock (&cuda_lock); +spin_lock_irqsave (&cuda_lock, flags);/* On powermacs, this handler is registered for the VIA IRQ. But they use * just the shift register IRQ -- other VIA interrupt sources are disabled.
@@ -494,7 +488,7 @@ cuda_interrupt(int irq, void *arg)#endif {if ((in_8 (&via[IFR ]) &SR_INT ) ==0 ) { -spin_unlock (&cuda_lock); +spin_unlock_irqrestore (&cuda_lock, flags);return IRQ_NONE ; }else {out_8 (&via[IFR ],SR_INT );
@@ -616,7 +610,7 @@ cuda_interrupt(int irq, void *arg)default :pr_err ("cuda_interrupt: unknown cuda_state %d?\n" , cuda_state); } -spin_unlock (&cuda_lock); +spin_unlock_irqrestore (&cuda_lock, flags);if (complete && req) {void (*done)(struct adb_request *) = req->done;mb ();
Signature · 1 line
2.10.2
PATCH RESEND 8/10 via-cuda: Initialize data_index early and increment consistently
In reply to Finn ThainInitialize data_index where appropriate to improve readability and assist debugging. This change doesn't affect driver behaviour.
I prefer to see
current_req->data[data_index++] in place of current_req->data[0] or current_req->data[1]
inasmuchas it becomes obvious what the data_index variable does.
Moreover, the actual value of data_index when examined at any given moment tells me something about prior events, which did prove helpful.
--- drivers/macintosh/via-cuda.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/macintosh/via-cuda.c +3 -3
@@ -446,12 +446,13 @@ cuda_start(void)/* assert cuda_state == idle */ if (current_req ==NULL )return ; + data_index =0 ;if (TREQ_asserted (in_8 (&via[B ])))return ;/* a byte is coming in from the CUDA */ /* set the shift register to shift out and send a byte */ out_8 (&via[ACR ],in_8 (&via[ACR ]) |SR_OUT ); -out_8 (&via[SR ], current_req->data[0 ]); +out_8 (&via[SR ], current_req->data[data_index++]);assert_TIP (); cuda_state = sent_first_byte; }
@@ -524,9 +525,8 @@ cuda_interrupt(int irq, void *arg)negate_TIP_and_TACK (); cuda_state = idle; }else { -out_8 (&via[SR ], current_req->data[1 ]); +out_8 (&via[SR ], current_req->data[data_index++]);toggle_TACK (); - data_index =2 ; cuda_state = sending; }break ;
Signature · 1 line
2.10.2
PATCH RESEND 9/10 via-cuda: Add support for Egret system controller
In reply to Finn ThainThe Egret system controller was the predecessor to the Cuda and the differences are minor.
On Cuda, byte acknowledgement requires one transition of the TACK signal; on Egret two are needed. On Cuda, TIP is active low; on Egret it is active high. And Cuda raises certain interrupts that Egret omits.
Accomodating these differences complicates the Cuda driver slightly but avoids a lot of duplication (see next patch).
--- drivers/macintosh/via-cuda.c | 155 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 134 insertions(+), 21 deletions(-)
drivers/macintosh/via-cuda.c +134 -21
@@ -1,10 +1,10 @@/* -* Device driver for the via-cuda on Apple Powermacs. +* Device driver for the Cuda and Egret system controllers found on PowerMacs +* and 68k Macs. * -* The VIA (versatile interface adapter) interfaces to the CUDA, -* a 6805 microprocessor core which controls the ADB (Apple Desktop -* Bus) which connects to the keyboard and mouse. The CUDA also -* controls system power and the RTC (real time clock) chip. +* The Cuda or Egret is a 6805 microcontroller interfaced to the 6522 VIA. +* This MCU controls system power, Parameter RAM, Real Time Clock and the +* Apple Desktop Bus (ADB) that connects to the keyboard and mouse. * * Copyright (C) 1996 Paul Mackerras. */
@@ -50,10 +50,27 @@ static DEFINE_SPINLOCK(cuda_lock);#define IER (14*RS)/* Interrupt enable register */ #define ANH (15*RS)/* A-side data, no handshake */ -/* Bits in B data register: all active low */ -#define TREQ 0x08/* Transfer request (input) */ -#define TACK 0x10/* Transfer acknowledge (output) */ -#define TIP 0x20/* Transfer in progress (output) */ +/* +* When the Cuda design replaced the Egret, some signal names and +* logic sense changed. They all serve the same purposes, however. +* +* VIA pin | Egret pin +* ----------------+------------------------------------------ +* PB3 (input) | Transceiver session (active low) +* PB4 (output) | VIA full (active high) +* PB5 (output) | System session (active high) +* +* VIA pin | Cuda pin +* ----------------+------------------------------------------ +* PB3 (input) | Transfer request (active low) +* PB4 (output) | Byte acknowledge (active low) +* PB5 (output) | Transfer in progress (active low) +*/ + +/* Bits in Port B data register */ +#define TREQ 0x08/* Transfer request */ +#define TACK 0x10/* Transfer acknowledge */ +#define TIP 0x20/* Transfer in progress */ /* Bits in ACR */ #define SR_CTRL 0x1c/* Shift register control bits */
@@ -65,6 +82,19 @@ static DEFINE_SPINLOCK(cuda_lock);#define IER_CLR 0/* clear bits in IER */ #define SR_INT 0x04/* Shift register full/empty */ +/* Duration of byte acknowledgement pulse (us) */ +#define EGRET_TACK_ASSERTED_DELAY 300 +#define EGRET_TACK_NEGATED_DELAY 400 + +/* Interval from interrupt to start of session (us) */ +#define EGRET_SESSION_DELAY 450 + +#ifdef CONFIG_PPC +#define mcu_is_egret false +#else +static bool mcu_is_egret; +#endif +static inline bool TREQ_asserted (u8 portb) {return !(portb &TREQ );
@@ -72,12 +102,29 @@ static inline bool TREQ_asserted(u8 portb)static inline void assert_TIP (void ) { -out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +if (mcu_is_egret) { +udelay (EGRET_SESSION_DELAY ); +out_8 (&via[B ],in_8 (&via[B ]) |TIP ); + }else +out_8 (&via[B ],in_8 (&via[B ]) & ~TIP ); +} + +static inline void assert_TIP_and_TACK (void ) +{ +if (mcu_is_egret) { +udelay (EGRET_SESSION_DELAY ); +out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); + }else +out_8 (&via[B ],in_8 (&via[B ]) & ~(TIP |TACK )); }static inline void assert_TACK (void ) { -out_8 (&via[B ],in_8 (&via[B ]) & ~TACK ); +if (mcu_is_egret) { +udelay (EGRET_TACK_NEGATED_DELAY ); +out_8 (&via[B ],in_8 (&via[B ]) |TACK ); + }else +out_8 (&via[B ],in_8 (&via[B ]) & ~TACK ); }static inline void toggle_TACK (void )
@@ -87,12 +134,20 @@ static inline void toggle_TACK(void)static inline void negate_TACK (void ) { -out_8 (&via[B ],in_8 (&via[B ]) |TACK ); +if (mcu_is_egret) { +udelay (EGRET_TACK_ASSERTED_DELAY ); +out_8 (&via[B ],in_8 (&via[B ]) & ~TACK ); + }else +out_8 (&via[B ],in_8 (&via[B ]) |TACK ); }static inline void negate_TIP_and_TACK (void ) { -out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); +if (mcu_is_egret) { +udelay (EGRET_TACK_ASSERTED_DELAY ); +out_8 (&via[B ],in_8 (&via[B ]) & ~(TIP |TACK )); + }else +out_8 (&via[B ],in_8 (&via[B ]) |TIP |TACK ); } static enum cuda_state {
@@ -155,6 +210,7 @@ int __init find_via_cuda(void) via = via1; cuda_state = idle; + mcu_is_egret = false; err =cuda_init_via ();if (err) {
@@ -251,7 +307,7 @@ static int __init via_cuda_start(void)return -EAGAIN ; } -pr_info ("Macintosh CUDA driver v0.5 for Unified ADB.\n" ); +pr_info ("Macintosh Cuda and Egret driver.\n" ); cuda_fully_inited =1 ;return 0 ;
@@ -276,6 +332,33 @@ cuda_probe(void) }#endif /* CONFIG_ADB */ +static int __init sync_egret (void ) +{ +if (TREQ_asserted (in_8 (&via[B ]))) { +/* Complete the inbound transfer */ +assert_TIP_and_TACK (); +while (1 ) { +negate_TACK (); +mdelay (1 ); + (void )in_8 (&via[SR ]); +assert_TACK (); +if (!TREQ_asserted (in_8 (&via[B ]))) +break ; + } +negate_TIP_and_TACK (); + }else if (in_8 (&via[B ]) &TIP ) { +/* Terminate the outbound transfer */ +negate_TACK (); +assert_TACK (); +mdelay (1 ); +negate_TIP_and_TACK (); + } +/* Clear shift register interrupt */ +if (in_8 (&via[IFR ]) &SR_INT ) + (void )in_8 (&via[SR ]); +return 0 ; +} +#define WAIT_FOR (cond, what) \ do { \ int x; \
@@ -291,10 +374,6 @@ cuda_probe(void)static int __init cuda_init_via (void ) { -out_8 (&via[DIRB ], (in_8 (&via[DIRB ]) |TACK |TIP ) & ~TREQ );/* TACK & TIP out */ -negate_TIP_and_TACK (); -out_8 (&via[ACR ] ,(in_8 (&via[ACR ]) & ~SR_CTRL ) |SR_EXT );/* SR data in */ - (void )in_8 (&via[SR ]);/* clear any left-over data */ #ifdef CONFIG_PPC out_8 (&via[IER ],0x7f );/* disable interrupts from VIA */ (void )in_8 (&via[IER ]);
@@ -302,6 +381,15 @@ __init cuda_init_via(void)out_8 (&via[IER ],SR_INT );/* disable SR interrupt from VIA */ #endif +out_8 (&via[DIRB ], (in_8 (&via[DIRB ]) |TACK |TIP ) & ~TREQ );/* TACK & TIP out */ +out_8 (&via[ACR ], (in_8 (&via[ACR ]) & ~SR_CTRL ) |SR_EXT );/* SR data in */ + (void )in_8 (&via[SR ]);/* clear any left-over data */ + +if (mcu_is_egret) +return sync_egret (); + +negate_TIP_and_TACK (); +/* delay 4ms and then clear any pending interrupt */ mdelay (4 ); (void )in_8 (&via[SR ]);
@@ -453,7 +541,10 @@ cuda_start(void)/* set the shift register to shift out and send a byte */ out_8 (&via[ACR ],in_8 (&via[ACR ]) |SR_OUT );out_8 (&via[SR ], current_req->data[data_index++]); -assert_TIP (); +if (mcu_is_egret) +assert_TIP_and_TACK (); +else +assert_TIP (); cuda_state = sent_first_byte; }
@@ -500,8 +591,9 @@ cuda_interrupt(int irq, void *arg)switch (cuda_state) {case idle: -/* CUDA has sent us the first byte of data - unsolicited */ +/* System controller has unsolicited data for us */ (void )in_8 (&via[SR ]); +idle_state:assert_TIP (); cuda_state = reading; reply_ptr = cuda_rbuf;
@@ -509,7 +601,7 @@ cuda_interrupt(int irq, void *arg)break ;case awaiting_reply: -/* CUDA has sent us the first byte of data of a reply */ +/* System controller has reply data for us */ (void )in_8 (&via[SR ]);assert_TIP (); cuda_state = reading;
@@ -524,9 +616,14 @@ cuda_interrupt(int irq, void *arg) (void )in_8 (&via[SR ]);negate_TIP_and_TACK (); cuda_state = idle; +/* Egret does not raise an "aborted" interrupt */ +if (mcu_is_egret) + goto idle_state; }else {out_8 (&via[SR ], current_req->data[data_index++]);toggle_TACK (); +if (mcu_is_egret) +assert_TACK (); cuda_state = sending; }break ;
@@ -550,6 +647,8 @@ cuda_interrupt(int irq, void *arg) }else {out_8 (&via[SR ], req->data[data_index++]);toggle_TACK (); +if (mcu_is_egret) +assert_TACK (); }break ;
@@ -560,16 +659,24 @@ cuda_interrupt(int irq, void *arg)else *reply_ptr++ =in_8 (&via[SR ]);if (!TREQ_asserted (status)) { +if (mcu_is_egret) +assert_TACK ();/* that's all folks */ negate_TIP_and_TACK (); cuda_state = read_done; +/* Egret does not raise a "read done" interrupt */ +if (mcu_is_egret) + goto read_done_state; }else {toggle_TACK (); +if (mcu_is_egret) +negate_TACK (); }break ;case read_done: (void )in_8 (&via[SR ]); +read_done_state:if (reading_reply) { req = current_req; req->reply_len = reply_ptr - req->reply;
@@ -645,6 +752,12 @@ cuda_input(unsigned char *buf, int nb)#endif /* CONFIG_ADB */ break ; +case TIMER_PACKET : +/* Egret sends these periodically. Might be useful as a 'heartbeat' +* to trigger a recovery for the VIA shift register errata. +*/ +break ; +default :print_hex_dump (KERN_INFO ,"cuda_input: " ,DUMP_PREFIX_NONE ,32 ,1 , buf, nb, false);
Signature · 1 line
2.10.2
PATCH RESEND 10/10 m68k/mac: Replace via-maciisi driver with via-cuda driver
In reply to Finn ThainChange the device probe test in the via-cuda.c driver so it will load on Egret-based machines too. Remove the now redundant via-maciisi.c driver.
--- arch/m68k/include/asm/macintosh.h | 2 +- arch/m68k/mac/config.c | 18 +- arch/m68k/mac/misc.c | 72 +--- drivers/macintosh/Kconfig | 24 +- drivers/macintosh/Makefile | 1 - drivers/macintosh/adb.c | 4 - drivers/macintosh/via-cuda.c | 8 +- drivers/macintosh/via-maciisi.c | 677 -------------------------------------- 8 files changed, 30 insertions(+), 776 deletions(-) delete mode 100644 drivers/macintosh/via-maciisi.c
arch/m68k/include/asm/macintosh.h +1 -1
@@ -38,7 +38,7 @@ struct mac_model#define MAC_ADB_NONE 0#define MAC_ADB_II 1 -#define MAC_ADB_IISI 2 +#define MAC_ADB_EGRET 2#define MAC_ADB_CUDA 3#define MAC_ADB_PB1 4#define MAC_ADB_PB2 5
arch/m68k/mac/config.c +9 -9
@@ -286,7 +286,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_IISI, .name = "IIsi", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_OLD, .scc_type = MAC_SCC_II,
@@ -295,7 +295,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_IIVI, .name = "IIvi", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -304,7 +304,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_IIVX, .name = "IIvx", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -319,7 +319,7 @@ static struct mac_model mac_data_table[] = { { .ident = MAC_MODEL_CLII, .name = "Classic II", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -352,7 +352,7 @@ static struct mac_model mac_data_table[] = { { .ident = MAC_MODEL_LC, .name = "LC", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -361,7 +361,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_LCII, .name = "LC II", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -370,7 +370,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_LCIII, .name = "LC III", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -498,7 +498,7 @@ static struct mac_model mac_data_table[] = { { .ident = MAC_MODEL_P460, .name = "Performa 460", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
@@ -575,7 +575,7 @@ static struct mac_model mac_data_table[] = { }, { .ident = MAC_MODEL_P600, .name = "Performa 600", - .adb_type = MAC_ADB_IISI, + .adb_type = MAC_ADB_EGRET, .via_type = MAC_VIA_IICI, .scsi_type = MAC_SCSI_LC, .scc_type = MAC_SCC_II,
arch/m68k/mac/misc.c +8 -64
135 lines not on this page · raw message
drivers/macintosh/Kconfig +7 -17
@@ -30,14 +30,6 @@ config ADB_MACII Quadra 610, Quadra 650, Quadra 700, Quadra 800, Centris 610 and Centris 650. -config ADB_MACIISI - bool "Include Mac IIsi ADB driver" - depends on ADB && MAC && BROKEN - help - Say Y here if want your kernel to support Macintosh systems that use - the Mac IIsi style ADB. This includes the IIsi, IIvi, IIvx, Classic - II, LC, LC II, LC III, Performa 460, and the Performa 600. - config ADB_IOP bool "Include IOP (IIfx/Quadra 9x0) ADB driver" depends on ADB && MAC
@@ -60,17 +52,15 @@ config ADB_PMU68K # we want to change this to something like CONFIG_SYSCTRL_CUDA/PMU config ADB_CUDA - bool "Support for CUDA based Macs and PowerMacs" + bool "Support for Cuda/Egret based Macs and PowerMacs" depends on (ADB || PPC_PMAC) && !PPC_PMAC64 help - This provides support for CUDA based Macintosh and Power Macintosh - systems. This includes many m68k based Macs (Color Classic, Mac TV, - Performa 475, Performa 520, Performa 550, Performa 575, - Performa 588, Quadra 605, Quadra 630, Quadra/Centris 660AV, and - Quadra 840AV), most OldWorld PowerMacs, the first generation iMacs, - the Blue&White G3 and the "Yikes" G4 (PCI Graphics). All later - models should use CONFIG_ADB_PMU instead. It is safe to say Y here - even if your machine doesn't have a CUDA. + This provides support for Cuda/Egret based Macintosh and + Power Macintosh systems. This includes most m68k based Macs, + most Old World PowerMacs, the first generation iMacs, the + Blue & White G3 and the "Yikes" G4 (PCI Graphics). All later + models should use CONFIG_ADB_PMU instead. It is safe to say Y + here even if your machine doesn't have a Cuda or Egret device. If unsure say Y.
drivers/macintosh/Makefile +0 -1
@@ -20,7 +20,6 @@ obj-$(CONFIG_PMAC_SMU) += smu.o obj-$(CONFIG_ADB) += adb.o obj-$(CONFIG_ADB_MACII) += via-macii.o -obj-$(CONFIG_ADB_MACIISI) += via-maciisi.o obj-$(CONFIG_ADB_IOP) += adb-iop.o obj-$(CONFIG_ADB_PMU68K) += via-pmu68k.o obj-$(CONFIG_ADB_MACIO) += macio-adb.o
drivers/macintosh/adb.c +0 -4
@@ -48,7 +48,6 @@EXPORT_SYMBOL (adb_client_list);extern struct adb_driver via_macii_driver; -extern struct adb_driver via_maciisi_driver;extern struct adb_driver via_cuda_driver;extern struct adb_driver adb_iop_driver;extern struct adb_driver via_pmu_driver;
@@ -59,9 +58,6 @@ static struct adb_driver *adb_driver_list[] = {#ifdef CONFIG_ADB_MACII &via_macii_driver,#endif -#ifdef CONFIG_ADB_MACIISI - &via_maciisi_driver, -#endif #ifdef CONFIG_ADB_CUDA &via_cuda_driver,#endif
drivers/macintosh/via-cuda.c +5 -3
@@ -205,12 +205,13 @@ int __init find_via_cuda(void)struct adb_request req;int err; -if (macintosh_config->adb_type !=MAC_ADB_CUDA ) +if (macintosh_config->adb_type !=MAC_ADB_CUDA && + macintosh_config->adb_type !=MAC_ADB_EGRET )return 0 ; via = via1; cuda_state = idle; - mcu_is_egret = false; + mcu_is_egret = macintosh_config->adb_type ==MAC_ADB_EGRET ; err =cuda_init_via ();if (err) {
@@ -323,7 +324,8 @@ cuda_probe(void)if (sys_ctrler !=SYS_CTRLER_CUDA )return -ENODEV ;#else -if (macintosh_config->adb_type !=MAC_ADB_CUDA ) +if (macintosh_config->adb_type !=MAC_ADB_CUDA && + macintosh_config->adb_type !=MAC_ADB_EGRET )return -ENODEV ;#endif if (via ==NULL )
drivers/macintosh/via-maciisi.c deleted +0 -677
677 lines not on this page · raw message
Signature · 1 line
2.10.2
Re: [PATCH RESEND 10/10] m68k/mac: Replace via-maciisi driver with via-cuda driver
Hi Finn, Ben,
Quoted 5 lines · Finn Thain
Change the device probe test in the
via-cuda.cdriver so it will load on Egret-based machines too. Remove the now redundantvia-maciisi.cdriver.Tested-by Stan Johnson <[email protected]>Signed-off-by Finn Thain <[email protected]>
I guess this will go in with the rest of the series through Ben's macintosh tree?
Quoted 11 lines
--- arch/m68k/include/asm/macintosh.h | 2 +- arch/m68k/mac/config.c | 18 +- arch/m68k/mac/misc.c | 72 +--- drivers/macintosh/Kconfig | 24 +- drivers/macintosh/Makefile | 1 - drivers/macintosh/adb.c | 4 - drivers/macintosh/via-cuda.c | 8 +- drivers/macintosh/via-maciisi.c | 677 -------------------------------------- 8 files changed, 30 insertions(+), 776 deletions(-) delete mode 100644 drivers/macintosh/via-maciisi.c
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH RESEND 10/10] m68k/mac: Replace via-maciisi driver with via-cuda driver
Quoted 4 lines · Geert Uytterhoeven
Hi Finn, Ben,
On Sun, Jan 1, 2017 at 1:56 AM, Finn Thain <[email protected]> wrote:
Quoted 9 lines
Quoted 6 lines
Change the device probe test in the
via-cuda.cdriver so it will load on Egret-based machines too. Remove the now redundantvia-maciisi.cdriver.
Thanks for your review.
Quoted 3 lines
I guess this will go in with the rest of the series through Ben's macintosh tree?
Most of the recent patches in drivers/macintosh, including my 2015 submission, commit 2dc710e93c ("macintosh/nvram: Remove as unused"), went through Michael's tree. But either tree would be fine with me.
BTW, to my knowledge there is no programmer's reference material for Cuda or Egret system controllers (excepting that which seems to be confined to Apple Inc). AIUI, Cuda was not part of CHRP. But one could observe all of the signalling between CPU and MCU by tracing the VIA I/O lines or doing the equivalent in a good emulator -- theoretically, of course. Would this be useful to reviewers?
Quoted 22 lines
Quoted 11 lines
--- arch/m68k/include/asm/macintosh.h | 2 +- arch/m68k/mac/config.c | 18 +- arch/m68k/mac/misc.c | 72 +--- drivers/macintosh/Kconfig | 24 +- drivers/macintosh/Makefile | 1 - drivers/macintosh/adb.c | 4 - drivers/macintosh/via-cuda.c | 8 +- drivers/macintosh/via-maciisi.c | 677 -------------------------------------- 8 files changed, 30 insertions(+), 776 deletions(-) delete mode 100644 drivers/macintosh/via-maciisi.cGr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds