Skip to content

Commit 10199e9

Browse files
Finn Thaingeertu
authored andcommitted
macintosh/adb-iop: Send correct poll command
The behaviour of the IOP firmware is not well documented but we do know that IOP message reply data can be used to issue new ADB commands. Use the message reply to better control autopoll behaviour by sending a Talk Register 0 command after every ADB response, not unlike the algorithm in the via-macii driver. This poll command is addressed to that device which last received a Talk command (explicit or otherwise). Cc: Joshua Thompson <funaho@jurai.org> Fixes: 32226e8 ("macintosh/adb-iop: Implement idle -> sending state transition") Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Link: https://lore.kernel.org/r/58bba4310da4c29b068345a4b36af8a531397ff7.1605847196.git.fthain@telegraphics.com.au Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent 2c9cfba commit 10199e9

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

‎drivers/macintosh/adb-iop.c‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
static struct adb_request *current_req;
2626
static struct adb_request *last_req;
2727
static unsigned int autopoll_devs;
28+
static u8 autopoll_addr;
2829

2930
static enum adb_iop_state {
3031
idle,
@@ -41,6 +42,11 @@ static int adb_iop_autopoll(int);
4142
static void adb_iop_poll(void);
4243
static int adb_iop_reset_bus(void);
4344

45+
/* ADB command byte structure */
46+
#define ADDR_MASK 0xF0
47+
#define OP_MASK 0x0C
48+
#define TALK 0x0C
49+
4450
struct adb_driver adb_iop_driver = {
4551
.name = "ISM IOP",
4652
.probe = adb_iop_probe,
@@ -94,17 +100,24 @@ static void adb_iop_complete(struct iop_msg *msg)
94100
static void adb_iop_listen(struct iop_msg *msg)
95101
{
96102
struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;
103+
u8 addr = (amsg->cmd & ADDR_MASK) >> 4;
104+
u8 op = amsg->cmd & OP_MASK;
97105
unsigned long flags;
98106
bool req_done = false;
99107

100108
local_irq_save(flags);
101109

102-
/* Handle a timeout. Timeout packets seem to occur even after
103-
* we've gotten a valid reply to a TALK, presumably because of
104-
* autopolling.
110+
/* Responses to Talk commands may be unsolicited as they are
111+
* produced when the IOP polls devices. They are mostly timeouts.
105112
*/
106-
107-
if (amsg->flags & ADB_IOP_EXPLICIT) {
113+
if (op == TALK && ((1 << addr) & autopoll_devs))
114+
autopoll_addr = addr;
115+
116+
switch (amsg->flags & (ADB_IOP_EXPLICIT |
117+
ADB_IOP_AUTOPOLL |
118+
ADB_IOP_TIMEOUT)) {
119+
case ADB_IOP_EXPLICIT:
120+
case ADB_IOP_EXPLICIT | ADB_IOP_TIMEOUT:
108121
if (adb_iop_state == awaiting_reply) {
109122
struct adb_request *req = current_req;
110123

@@ -115,12 +128,16 @@ static void adb_iop_listen(struct iop_msg *msg)
115128

116129
req_done = true;
117130
}
118-
} else if (!(amsg->flags & ADB_IOP_TIMEOUT)) {
119-
adb_input(&amsg->cmd, amsg->count + 1,
120-
amsg->flags & ADB_IOP_AUTOPOLL);
131+
break;
132+
case ADB_IOP_AUTOPOLL:
133+
if (((1 << addr) & autopoll_devs) &&
134+
amsg->cmd == ADB_READREG(addr, 0))
135+
adb_input(&amsg->cmd, amsg->count + 1, 1);
136+
break;
121137
}
122-
123-
msg->reply[0] = autopoll_devs ? ADB_IOP_AUTOPOLL : 0;
138+
msg->reply[0] = autopoll_addr ? ADB_IOP_AUTOPOLL : 0;
139+
msg->reply[1] = 0;
140+
msg->reply[2] = autopoll_addr ? ADB_READREG(autopoll_addr, 0) : 0;
124141
iop_complete_message(msg);
125142

126143
if (req_done)
@@ -233,6 +250,9 @@ static void adb_iop_set_ap_complete(struct iop_msg *msg)
233250
struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;
234251

235252
autopoll_devs = (amsg->data[1] << 8) | amsg->data[0];
253+
if (autopoll_devs & (1 << autopoll_addr))
254+
return;
255+
autopoll_addr = autopoll_devs ? (ffs(autopoll_devs) - 1) : 0;
236256
}
237257

238258
static int adb_iop_autopoll(int devs)

0 commit comments

Comments
 (0)