Linux Audio

Check our new training course

Linux BSP development engineering services

Need help to port Linux and bootloaders to your hardware?
Loading...
v3.1
 
  1/*
  2 * I/O Processor (IOP) ADB Driver
  3 * Written and (C) 1999 by Joshua M. Thompson (funaho@jurai.org)
  4 * Based on via-cuda.c by Paul Mackerras.
  5 *
  6 * 1999-07-01 (jmt) - First implementation for new driver architecture.
  7 *
  8 * 1999-07-31 (jmt) - First working version.
  9 *
 10 * TODO:
 11 *
 12 * o Implement SRQ handling.
 13 */
 14
 15#include <linux/types.h>
 16#include <linux/kernel.h>
 17#include <linux/mm.h>
 18#include <linux/delay.h>
 19#include <linux/init.h>
 20#include <linux/proc_fs.h>
 21
 22#include <asm/macintosh.h> 
 23#include <asm/macints.h> 
 24#include <asm/mac_iop.h>
 25#include <asm/mac_oss.h>
 26#include <asm/adb_iop.h>
 27
 28#include <linux/adb.h> 
 29
 30/*#define DEBUG_ADB_IOP*/
 31
 32extern void iop_ism_irq(int, void *);
 33
 34static struct adb_request *current_req;
 35static struct adb_request *last_req;
 36#if 0
 37static unsigned char reply_buff[16];
 38static unsigned char *reply_ptr;
 39#endif
 40
 41static enum adb_iop_state {
 42    idle,
 43    sending,
 44    awaiting_reply
 45} adb_iop_state;
 46
 47static void adb_iop_start(void);
 48static int adb_iop_probe(void);
 49static int adb_iop_init(void);
 50static int adb_iop_send_request(struct adb_request *, int);
 51static int adb_iop_write(struct adb_request *);
 52static int adb_iop_autopoll(int);
 53static void adb_iop_poll(void);
 54static int adb_iop_reset_bus(void);
 55
 56struct adb_driver adb_iop_driver = {
 57	"ISM IOP",
 58	adb_iop_probe,
 59	adb_iop_init,
 60	adb_iop_send_request,
 61	adb_iop_autopoll,
 62	adb_iop_poll,
 63	adb_iop_reset_bus
 64};
 65
 66static void adb_iop_end_req(struct adb_request *req, int state)
 67{
 68	req->complete = 1;
 69	current_req = req->next;
 70	if (req->done) (*req->done)(req);
 71	adb_iop_state = state;
 72}
 73
 74/*
 75 * Completion routine for ADB commands sent to the IOP.
 76 *
 77 * This will be called when a packet has been successfully sent.
 78 */
 79
 80static void adb_iop_complete(struct iop_msg *msg)
 81{
 82	struct adb_request *req;
 83	unsigned long flags;
 84
 85	local_irq_save(flags);
 86
 87	req = current_req;
 88	if ((adb_iop_state == sending) && req && req->reply_expected) {
 89		adb_iop_state = awaiting_reply;
 90	}
 91
 92	local_irq_restore(flags);
 93}
 94
 95/*
 96 * Listen for ADB messages from the IOP.
 97 *
 98 * This will be called when unsolicited messages (usually replies to TALK
 99 * commands or autopoll packets) are received.
100 */
101
102static void adb_iop_listen(struct iop_msg *msg)
103{
104	struct adb_iopmsg *amsg = (struct adb_iopmsg *) msg->message;
105	struct adb_request *req;
106	unsigned long flags;
107#ifdef DEBUG_ADB_IOP
108	int i;
109#endif
110
111	local_irq_save(flags);
112
113	req = current_req;
114
115#ifdef DEBUG_ADB_IOP
116	printk("adb_iop_listen %p: rcvd packet, %d bytes: %02X %02X", req,
117		(uint) amsg->count + 2, (uint) amsg->flags, (uint) amsg->cmd);
118	for (i = 0; i < amsg->count; i++)
119		printk(" %02X", (uint) amsg->data[i]);
120	printk("\n");
121#endif
122
123	/* Handle a timeout. Timeout packets seem to occur even after */
124	/* we've gotten a valid reply to a TALK, so I'm assuming that */
125	/* a "timeout" is actually more like an "end-of-data" signal. */
126	/* We need to send back a timeout packet to the IOP to shut   */
127	/* it up, plus complete the current request, if any.          */
128
129	if (amsg->flags & ADB_IOP_TIMEOUT) {
130		msg->reply[0] = ADB_IOP_TIMEOUT | ADB_IOP_AUTOPOLL;
131		msg->reply[1] = 0;
132		msg->reply[2] = 0;
133		if (req && (adb_iop_state != idle)) {
134			adb_iop_end_req(req, idle);
135		}
136	} else {
137		/* TODO: is it possible for more than one chunk of data  */
138		/*       to arrive before the timeout? If so we need to */
139		/*       use reply_ptr here like the other drivers do.  */
140		if ((adb_iop_state == awaiting_reply) &&
141		    (amsg->flags & ADB_IOP_EXPLICIT)) {
142			req->reply_len = amsg->count + 1;
143			memcpy(req->reply, &amsg->cmd, req->reply_len);
144		} else {
145			adb_input(&amsg->cmd, amsg->count + 1,
146				  amsg->flags & ADB_IOP_AUTOPOLL);
147		}
148		memcpy(msg->reply, msg->message, IOP_MSG_LEN);
149	}
150	iop_complete_message(msg);
151	local_irq_restore(flags);
152}
153
154/*
155 * Start sending an ADB packet, IOP style
156 *
157 * There isn't much to do other than hand the packet over to the IOP
158 * after encapsulating it in an adb_iopmsg.
159 */
160
161static void adb_iop_start(void)
162{
163	unsigned long flags;
164	struct adb_request *req;
165	struct adb_iopmsg amsg;
166#ifdef DEBUG_ADB_IOP
167	int i;
168#endif
169
170	/* get the packet to send */
171	req = current_req;
172	if (!req) return;
173
174	local_irq_save(flags);
175
176#ifdef DEBUG_ADB_IOP
177	printk("adb_iop_start %p: sending packet, %d bytes:", req, req->nbytes);
178	for (i = 0 ; i < req->nbytes ; i++)
179		printk(" %02X", (uint) req->data[i]);
180	printk("\n");
181#endif
182
183	/* The IOP takes MacII-style packets, so */
184	/* strip the initial ADB_PACKET byte.    */
185
186	amsg.flags = ADB_IOP_EXPLICIT;
187	amsg.count = req->nbytes - 2;
188
189	/* amsg.data immediately follows amsg.cmd, effectively making */
190	/* amsg.cmd a pointer to the beginning of a full ADB packet.  */
191	memcpy(&amsg.cmd, req->data + 1, req->nbytes - 1);
192
193	req->sent = 1;
194	adb_iop_state = sending;
195	local_irq_restore(flags);
196
197	/* Now send it. The IOP manager will call adb_iop_complete */
198	/* when the packet has been sent.                          */
199
200	iop_send_message(ADB_IOP, ADB_CHAN, req,
201			 sizeof(amsg), (__u8 *) &amsg, adb_iop_complete);
202}
203
204int adb_iop_probe(void)
205{
206	if (!iop_ism_present) return -ENODEV;
207	return 0;
208}
209
210int adb_iop_init(void)
211{
212	printk("adb: IOP ISM driver v0.4 for Unified ADB.\n");
213	iop_listen(ADB_IOP, ADB_CHAN, adb_iop_listen, "ADB");
214	return 0;
215}
216
217int adb_iop_send_request(struct adb_request *req, int sync)
218{
219	int err;
220
221	err = adb_iop_write(req);
222	if (err) return err;
223
224	if (sync) {
225		while (!req->complete) adb_iop_poll();
226	}
227	return 0;
228}
229
230static int adb_iop_write(struct adb_request *req)
231{
232	unsigned long flags;
233
234	if ((req->nbytes < 2) || (req->data[0] != ADB_PACKET)) {
235		req->complete = 1;
236		return -EINVAL;
237	}
238
239	local_irq_save(flags);
240
241	req->next = NULL;
242	req->sent = 0;
243	req->complete = 0;
244	req->reply_len = 0;
245
246	if (current_req != 0) {
247		last_req->next = req;
248		last_req = req;
249	} else {
250		current_req = req;
251		last_req = req;
252	}
253
254	local_irq_restore(flags);
255	if (adb_iop_state == idle) adb_iop_start();
256	return 0;
257}
258
259int adb_iop_autopoll(int devs)
260{
261	/* TODO: how do we enable/disable autopoll? */
262	return 0;
263}
264
265void adb_iop_poll(void)
266{
267	if (adb_iop_state == idle) adb_iop_start();
268	iop_ism_irq(0, (void *) ADB_IOP);
269}
270
271int adb_iop_reset_bus(void)
272{
273	struct adb_request req = {
274		.reply_expected = 0,
275		.nbytes = 2,
276		.data = { ADB_PACKET, 0 },
277	};
278
279	adb_iop_write(&req);
280	while (!req.complete) {
281		adb_iop_poll();
282		schedule();
283	}
284
285	return 0;
286}
v4.17
  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.
  6 *
  7 * 1999-07-01 (jmt) - First implementation for new driver architecture.
  8 *
  9 * 1999-07-31 (jmt) - First working version.
 10 *
 11 * TODO:
 12 *
 13 * o Implement SRQ handling.
 14 */
 15
 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>
 22
 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>
 28
 29#include <linux/adb.h> 
 30
 31/*#define DEBUG_ADB_IOP*/
 32
 
 
 33static struct adb_request *current_req;
 34static struct adb_request *last_req;
 35#if 0
 36static unsigned char reply_buff[16];
 37static unsigned char *reply_ptr;
 38#endif
 39
 40static enum adb_iop_state {
 41    idle,
 42    sending,
 43    awaiting_reply
 44} adb_iop_state;
 45
 46static void adb_iop_start(void);
 47static int adb_iop_probe(void);
 48static int adb_iop_init(void);
 49static int adb_iop_send_request(struct adb_request *, int);
 50static int adb_iop_write(struct adb_request *);
 51static int adb_iop_autopoll(int);
 52static void adb_iop_poll(void);
 53static int adb_iop_reset_bus(void);
 54
 55struct adb_driver adb_iop_driver = {
 56	.name         = "ISM IOP",
 57	.probe        = adb_iop_probe,
 58	.init         = adb_iop_init,
 59	.send_request = adb_iop_send_request,
 60	.autopoll     = adb_iop_autopoll,
 61	.poll         = adb_iop_poll,
 62	.reset_bus    = adb_iop_reset_bus
 63};
 64
 65static void adb_iop_end_req(struct adb_request *req, int state)
 66{
 67	req->complete = 1;
 68	current_req = req->next;
 69	if (req->done) (*req->done)(req);
 70	adb_iop_state = state;
 71}
 72
 73/*
 74 * Completion routine for ADB commands sent to the IOP.
 75 *
 76 * This will be called when a packet has been successfully sent.
 77 */
 78
 79static void adb_iop_complete(struct iop_msg *msg)
 80{
 81	struct adb_request *req;
 82	unsigned long flags;
 83
 84	local_irq_save(flags);
 85
 86	req = current_req;
 87	if ((adb_iop_state == sending) && req && req->reply_expected) {
 88		adb_iop_state = awaiting_reply;
 89	}
 90
 91	local_irq_restore(flags);
 92}
 93
 94/*
 95 * Listen for ADB messages from the IOP.
 96 *
 97 * This will be called when unsolicited messages (usually replies to TALK
 98 * commands or autopoll packets) are received.
 99 */
100
101static void adb_iop_listen(struct iop_msg *msg)
102{
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
109
110	local_irq_save(flags);
111
112	req = current_req;
113
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
121
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.          */
127
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);
134		}
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);
146		}
147		memcpy(msg->reply, msg->message, IOP_MSG_LEN);
148	}
149	iop_complete_message(msg);
150	local_irq_restore(flags);
151}
152
153/*
154 * Start sending an ADB packet, IOP style
155 *
156 * There isn't much to do other than hand the packet over to the IOP
157 * after encapsulating it in an adb_iopmsg.
158 */
159
160static void adb_iop_start(void)
161{
162	unsigned long flags;
163	struct adb_request *req;
164	struct adb_iopmsg amsg;
165#ifdef DEBUG_ADB_IOP
166	int i;
167#endif
168
169	/* get the packet to send */
170	req = current_req;
171	if (!req) return;
172
173	local_irq_save(flags);
174
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
181
182	/* The IOP takes MacII-style packets, so */
183	/* strip the initial ADB_PACKET byte.    */
184
185	amsg.flags = ADB_IOP_EXPLICIT;
186	amsg.count = req->nbytes - 2;
187
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);
191
192	req->sent = 1;
193	adb_iop_state = sending;
194	local_irq_restore(flags);
195
196	/* Now send it. The IOP manager will call adb_iop_complete */
197	/* when the packet has been sent.                          */
198
199	iop_send_message(ADB_IOP, ADB_CHAN, req,
200			 sizeof(amsg), (__u8 *) &amsg, adb_iop_complete);
201}
202
203int adb_iop_probe(void)
204{
205	if (!iop_ism_present) return -ENODEV;
206	return 0;
207}
208
209int adb_iop_init(void)
210{
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;
214}
215
216int adb_iop_send_request(struct adb_request *req, int sync)
217{
218	int err;
219
220	err = adb_iop_write(req);
221	if (err) return err;
222
223	if (sync) {
224		while (!req->complete) adb_iop_poll();
225	}
226	return 0;
227}
228
229static int adb_iop_write(struct adb_request *req)
230{
231	unsigned long flags;
232
233	if ((req->nbytes < 2) || (req->data[0] != ADB_PACKET)) {
234		req->complete = 1;
235		return -EINVAL;
236	}
237
238	local_irq_save(flags);
239
240	req->next = NULL;
241	req->sent = 0;
242	req->complete = 0;
243	req->reply_len = 0;
244
245	if (current_req != 0) {
246		last_req->next = req;
247		last_req = req;
248	} else {
249		current_req = req;
250		last_req = req;
251	}
252
253	local_irq_restore(flags);
254	if (adb_iop_state == idle) adb_iop_start();
255	return 0;
256}
257
258int adb_iop_autopoll(int devs)
259{
260	/* TODO: how do we enable/disable autopoll? */
261	return 0;
262}
263
264void adb_iop_poll(void)
265{
266	if (adb_iop_state == idle) adb_iop_start();
267	iop_ism_irq_poll(ADB_IOP);
268}
269
270int adb_iop_reset_bus(void)
271{
272	struct adb_request req = {
273		.reply_expected = 0,
274		.nbytes = 2,
275		.data = { ADB_PACKET, 0 },
276	};
277
278	adb_iop_write(&req);
279	while (!req.complete) {
280		adb_iop_poll();
281		schedule();
282	}
283
284	return 0;
285}