drm/amd/display: Update MST edid property every time
[linux/fpc-iii.git] / drivers / macintosh / adb-iop.c
blob15db69d8ba697deb1426eff545c872c8bfc6e62d
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * I/O Processor (IOP) ADB Driver
4 * Written and (C) 1999 by Joshua M. Thompson (funaho@jurai.org)
5 * Based on via-cuda.c by Paul Mackerras.
7 * 1999-07-01 (jmt) - First implementation for new driver architecture.
9 * 1999-07-31 (jmt) - First working version.
11 * TODO:
13 * o Implement SRQ handling.
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/mm.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #include <linux/proc_fs.h>
23 #include <asm/macintosh.h>
24 #include <asm/macints.h>
25 #include <asm/mac_iop.h>
26 #include <asm/mac_oss.h>
27 #include <asm/adb_iop.h>
29 #include <linux/adb.h>
31 /*#define DEBUG_ADB_IOP*/
33 static struct adb_request *current_req;
34 static struct adb_request *last_req;
35 #if 0
36 static unsigned char reply_buff[16];
37 static unsigned char *reply_ptr;
38 #endif
40 static enum adb_iop_state {
41 idle,
42 sending,
43 awaiting_reply
44 } adb_iop_state;
46 static void adb_iop_start(void);
47 static int adb_iop_probe(void);
48 static int adb_iop_init(void);
49 static int adb_iop_send_request(struct adb_request *, int);
50 static int adb_iop_write(struct adb_request *);
51 static int adb_iop_autopoll(int);
52 static void adb_iop_poll(void);
53 static int adb_iop_reset_bus(void);
55 struct adb_driver adb_iop_driver = {
56 "ISM IOP",
57 adb_iop_probe,
58 adb_iop_init,
59 adb_iop_send_request,
60 adb_iop_autopoll,
61 adb_iop_poll,
62 adb_iop_reset_bus
65 static void adb_iop_end_req(struct adb_request *req, int state)
67 req->complete = 1;
68 current_req = req->next;
69 if (req->done) (*req->done)(req);
70 adb_iop_state = state;
74 * Completion routine for ADB commands sent to the IOP.
76 * This will be called when a packet has been successfully sent.
79 static void adb_iop_complete(struct iop_msg *msg)
81 struct adb_request *req;
82 unsigned long flags;
84 local_irq_save(flags);
86 req = current_req;
87 if ((adb_iop_state == sending) && req && req->reply_expected) {
88 adb_iop_state = awaiting_reply;
91 local_irq_restore(flags);
95 * Listen for ADB messages from the IOP.
97 * This will be called when unsolicited messages (usually replies to TALK
98 * commands or autopoll packets) are received.
101 static void adb_iop_listen(struct iop_msg *msg)
103 struct adb_iopmsg *amsg = (struct adb_iopmsg *) msg->message;
104 struct adb_request *req;
105 unsigned long flags;
106 #ifdef DEBUG_ADB_IOP
107 int i;
108 #endif
110 local_irq_save(flags);
112 req = current_req;
114 #ifdef DEBUG_ADB_IOP
115 printk("adb_iop_listen %p: rcvd packet, %d bytes: %02X %02X", req,
116 (uint) amsg->count + 2, (uint) amsg->flags, (uint) amsg->cmd);
117 for (i = 0; i < amsg->count; i++)
118 printk(" %02X", (uint) amsg->data[i]);
119 printk("\n");
120 #endif
122 /* Handle a timeout. Timeout packets seem to occur even after */
123 /* we've gotten a valid reply to a TALK, so I'm assuming that */
124 /* a "timeout" is actually more like an "end-of-data" signal. */
125 /* We need to send back a timeout packet to the IOP to shut */
126 /* it up, plus complete the current request, if any. */
128 if (amsg->flags & ADB_IOP_TIMEOUT) {
129 msg->reply[0] = ADB_IOP_TIMEOUT | ADB_IOP_AUTOPOLL;
130 msg->reply[1] = 0;
131 msg->reply[2] = 0;
132 if (req && (adb_iop_state != idle)) {
133 adb_iop_end_req(req, idle);
135 } else {
136 /* TODO: is it possible for more than one chunk of data */
137 /* to arrive before the timeout? If so we need to */
138 /* use reply_ptr here like the other drivers do. */
139 if ((adb_iop_state == awaiting_reply) &&
140 (amsg->flags & ADB_IOP_EXPLICIT)) {
141 req->reply_len = amsg->count + 1;
142 memcpy(req->reply, &amsg->cmd, req->reply_len);
143 } else {
144 adb_input(&amsg->cmd, amsg->count + 1,
145 amsg->flags & ADB_IOP_AUTOPOLL);
147 memcpy(msg->reply, msg->message, IOP_MSG_LEN);
149 iop_complete_message(msg);
150 local_irq_restore(flags);
154 * Start sending an ADB packet, IOP style
156 * There isn't much to do other than hand the packet over to the IOP
157 * after encapsulating it in an adb_iopmsg.
160 static void adb_iop_start(void)
162 unsigned long flags;
163 struct adb_request *req;
164 struct adb_iopmsg amsg;
165 #ifdef DEBUG_ADB_IOP
166 int i;
167 #endif
169 /* get the packet to send */
170 req = current_req;
171 if (!req) return;
173 local_irq_save(flags);
175 #ifdef DEBUG_ADB_IOP
176 printk("adb_iop_start %p: sending packet, %d bytes:", req, req->nbytes);
177 for (i = 0 ; i < req->nbytes ; i++)
178 printk(" %02X", (uint) req->data[i]);
179 printk("\n");
180 #endif
182 /* The IOP takes MacII-style packets, so */
183 /* strip the initial ADB_PACKET byte. */
185 amsg.flags = ADB_IOP_EXPLICIT;
186 amsg.count = req->nbytes - 2;
188 /* amsg.data immediately follows amsg.cmd, effectively making */
189 /* amsg.cmd a pointer to the beginning of a full ADB packet. */
190 memcpy(&amsg.cmd, req->data + 1, req->nbytes - 1);
192 req->sent = 1;
193 adb_iop_state = sending;
194 local_irq_restore(flags);
196 /* Now send it. The IOP manager will call adb_iop_complete */
197 /* when the packet has been sent. */
199 iop_send_message(ADB_IOP, ADB_CHAN, req,
200 sizeof(amsg), (__u8 *) &amsg, adb_iop_complete);
203 int adb_iop_probe(void)
205 if (!iop_ism_present) return -ENODEV;
206 return 0;
209 int adb_iop_init(void)
211 printk("adb: IOP ISM driver v0.4 for Unified ADB.\n");
212 iop_listen(ADB_IOP, ADB_CHAN, adb_iop_listen, "ADB");
213 return 0;
216 int adb_iop_send_request(struct adb_request *req, int sync)
218 int err;
220 err = adb_iop_write(req);
221 if (err) return err;
223 if (sync) {
224 while (!req->complete) adb_iop_poll();
226 return 0;
229 static int adb_iop_write(struct adb_request *req)
231 unsigned long flags;
233 if ((req->nbytes < 2) || (req->data[0] != ADB_PACKET)) {
234 req->complete = 1;
235 return -EINVAL;
238 local_irq_save(flags);
240 req->next = NULL;
241 req->sent = 0;
242 req->complete = 0;
243 req->reply_len = 0;
245 if (current_req != 0) {
246 last_req->next = req;
247 last_req = req;
248 } else {
249 current_req = req;
250 last_req = req;
253 local_irq_restore(flags);
254 if (adb_iop_state == idle) adb_iop_start();
255 return 0;
258 int adb_iop_autopoll(int devs)
260 /* TODO: how do we enable/disable autopoll? */
261 return 0;
264 void adb_iop_poll(void)
266 if (adb_iop_state == idle) adb_iop_start();
267 iop_ism_irq_poll(ADB_IOP);
270 int adb_iop_reset_bus(void)
272 struct adb_request req = {
273 .reply_expected = 0,
274 .nbytes = 2,
275 .data = { ADB_PACKET, 0 },
278 adb_iop_write(&req);
279 while (!req.complete) {
280 adb_iop_poll();
281 schedule();
284 return 0;