···2020#include <linux/init.h>2121#include <linux/proc_fs.h>22222323-#include <asm/macintosh.h> 2424-#include <asm/macints.h> 2323+#include <asm/macintosh.h>2424+#include <asm/macints.h>2525#include <asm/mac_iop.h>2626#include <asm/mac_oss.h>2727#include <asm/adb_iop.h>28282929-#include <linux/adb.h> 2929+#include <linux/adb.h>30303131/*#define DEBUG_ADB_IOP*/3232···3838#endif39394040static enum adb_iop_state {4141- idle,4242- sending,4343- awaiting_reply4141+ idle,4242+ sending,4343+ awaiting_reply4444} adb_iop_state;45454646static void adb_iop_start(void);···6666{6767 req->complete = 1;6868 current_req = req->next;6969- if (req->done) (*req->done)(req);6969+ if (req->done)7070+ (*req->done)(req);7071 adb_iop_state = state;7172}7273···101100102101static void adb_iop_listen(struct iop_msg *msg)103102{104104- struct adb_iopmsg *amsg = (struct adb_iopmsg *) msg->message;103103+ struct adb_iopmsg *amsg = (struct adb_iopmsg *)msg->message;105104 struct adb_request *req;106105 unsigned long flags;107106#ifdef DEBUG_ADB_IOP···114113115114#ifdef DEBUG_ADB_IOP116115 printk("adb_iop_listen %p: rcvd packet, %d bytes: %02X %02X", req,117117- (uint) amsg->count + 2, (uint) amsg->flags, (uint) amsg->cmd);116116+ (uint)amsg->count + 2, (uint)amsg->flags, (uint)amsg->cmd);118117 for (i = 0; i < amsg->count; i++)119119- printk(" %02X", (uint) amsg->data[i]);118118+ printk(" %02X", (uint)amsg->data[i]);120119 printk("\n");121120#endif122121···169168170169 /* get the packet to send */171170 req = current_req;172172- if (!req) return;171171+ if (!req)172172+ return;173173174174 local_irq_save(flags);175175176176#ifdef DEBUG_ADB_IOP177177 printk("adb_iop_start %p: sending packet, %d bytes:", req, req->nbytes);178178- for (i = 0 ; i < req->nbytes ; i++)179179- printk(" %02X", (uint) req->data[i]);178178+ for (i = 0; i < req->nbytes; i++)179179+ printk(" %02X", (uint)req->data[i]);180180 printk("\n");181181#endif182182···198196 /* Now send it. The IOP manager will call adb_iop_complete */199197 /* when the packet has been sent. */200198201201- iop_send_message(ADB_IOP, ADB_CHAN, req,202202- sizeof(amsg), (__u8 *) &amsg, adb_iop_complete);199199+ iop_send_message(ADB_IOP, ADB_CHAN, req, sizeof(amsg), (__u8 *)&amsg,200200+ adb_iop_complete);203201}204202205203int adb_iop_probe(void)206204{207207- if (!iop_ism_present) return -ENODEV;205205+ if (!iop_ism_present)206206+ return -ENODEV;208207 return 0;209208}210209···221218 int err;222219223220 err = adb_iop_write(req);224224- if (err) return err;221221+ if (err)222222+ return err;225223226224 if (sync) {227227- while (!req->complete) adb_iop_poll();225225+ while (!req->complete)226226+ adb_iop_poll();228227 }229228 return 0;230229}···256251 }257252258253 local_irq_restore(flags);259259- if (adb_iop_state == idle) adb_iop_start();254254+255255+ if (adb_iop_state == idle)256256+ adb_iop_start();260257 return 0;261258}262259···270263271264void adb_iop_poll(void)272265{273273- if (adb_iop_state == idle) adb_iop_start();266266+ if (adb_iop_state == idle)267267+ adb_iop_start();274268 iop_ism_irq_poll(ADB_IOP);275269}276270
+151-145
drivers/macintosh/via-macii.c
···1212 *1313 * 1999-08-02 (jmt) - Initial rewrite for Unified ADB.1414 * 2000-03-29 Tony Mantler <tonym@mac.linux-m68k.org>1515- * - Big overhaul, should actually work now.1515+ * - Big overhaul, should actually work now.1616 * 2006-12-31 Finn Thain - Another overhaul.1717 *1818 * Suggested reading:···2323 * Apple's "ADB Analyzer" bus sniffer is invaluable:2424 * ftp://ftp.apple.com/developer/Tool_Chest/Devices_-_Hardware/Apple_Desktop_Bus/2525 */2626-2626+2727#include <stdarg.h>2828#include <linux/types.h>2929#include <linux/errno.h>···7777#define ST_ODD 0x20 /* ADB state: odd data byte */7878#define ST_IDLE 0x30 /* ADB state: idle, nothing to send */79798080-static int macii_init_via(void);8080+static int macii_init_via(void);8181static void macii_start(void);8282static irqreturn_t macii_interrupt(int irq, void *arg);8383static void macii_queue_poll(void);···123123/* Check for MacII style ADB */124124static int macii_probe(void)125125{126126- if (macintosh_config->adb_type != MAC_ADB_II) return -ENODEV;126126+ if (macintosh_config->adb_type != MAC_ADB_II)127127+ return -ENODEV;127128128129 via = via1;129130···137136{138137 unsigned long flags;139138 int err;140140-139139+141140 local_irq_save(flags);142142-141141+143142 err = macii_init_via();144144- if (err) goto out;143143+ if (err)144144+ goto out;145145146146 err = request_irq(IRQ_MAC_ADB, macii_interrupt, 0, "ADB",147147 macii_interrupt);148148- if (err) goto out;148148+ if (err)149149+ goto out;149150150151 macii_state = idle;151152out:···155152 return err;156153}157154158158-/* initialize the hardware */ 155155+/* initialize the hardware */159156static int macii_init_via(void)160157{161158 unsigned char x;···165162166163 /* Set up state: idle */167164 via[B] |= ST_IDLE;168168- last_status = via[B] & (ST_MASK|CTLR_IRQ);165165+ last_status = via[B] & (ST_MASK | CTLR_IRQ);169166170167 /* Shift register on input */171168 via[ACR] = (via[ACR] & ~SR_CTRL) | SR_EXT;···191188 int next_device;192189 static struct adb_request req;193190194194- if (!autopoll_devs) return;191191+ if (!autopoll_devs)192192+ return;195193196194 device_mask = (1 << (((command_byte & 0xF0) >> 4) + 1)) - 1;197195 if (autopoll_devs & ~device_mask)···200196 else201197 next_device = ffs(autopoll_devs) - 1;202198203203- adb_request(&req, NULL, ADBREQ_NOSEND, 1,204204- ADB_READREG(next_device, 0));199199+ adb_request(&req, NULL, ADBREQ_NOSEND, 1, ADB_READREG(next_device, 0));205200206201 req.sent = 0;207202 req.complete = 0;···240237 req->complete = 1;241238 return -EINVAL;242239 }243243-240240+244241 req->next = NULL;245242 req->sent = 0;246243 req->complete = 0;···254251 } else {255252 current_req = req;256253 last_req = req;257257- if (macii_state == idle) macii_start();254254+ if (macii_state == idle)255255+ macii_start();258256 }259257260258 local_irq_restore(flags);···273269 /* bit 1 == device 1, and so on. */274270 autopoll_devs = devs & 0xFFFE;275271276276- if (!autopoll_devs) return 0;272272+ if (!autopoll_devs)273273+ return 0;277274278275 local_irq_save(flags);279276···291286 return err;292287}293288294294-static inline int need_autopoll(void) {289289+static inline int need_autopoll(void)290290+{295291 /* Was the last command Talk Reg 0296292 * and is the target on the autopoll list?297293 */···312306static int macii_reset_bus(void)313307{314308 static struct adb_request req;315315-309309+316310 /* Command = 0, Address = ignored */317311 adb_request(&req, NULL, ADBREQ_NOSEND, 1, ADB_BUSRESET);318312 macii_send_request(&req, 1);···355349 * to be activity on the ADB bus. The chip will poll to achieve this.356350 *357351 * The basic ADB state machine was left unchanged from the original MacII code358358- * by Alan Cox, which was based on the CUDA driver for PowerMac. 352352+ * by Alan Cox, which was based on the CUDA driver for PowerMac.359353 * The syntax of the ADB status lines is totally different on MacII,360354 * though. MacII uses the states Command -> Even -> Odd -> Even ->...-> Idle361355 * for sending and Idle -> Even -> Odd -> Even ->...-> Idle for receiving.···383377 }384378385379 last_status = status;386386- status = via[B] & (ST_MASK|CTLR_IRQ);380380+ status = via[B] & (ST_MASK | CTLR_IRQ);387381388382 switch (macii_state) {389389- case idle:390390- if (reading_reply) {391391- reply_ptr = current_req->reply;392392- } else {393393- WARN_ON(current_req);394394- reply_ptr = reply_buf;395395- }383383+ case idle:384384+ if (reading_reply) {385385+ reply_ptr = current_req->reply;386386+ } else {387387+ WARN_ON(current_req);388388+ reply_ptr = reply_buf;389389+ }396390397397- x = via[SR];391391+ x = via[SR];398392399399- if ((status & CTLR_IRQ) && (x == 0xFF)) {400400- /* Bus timeout without SRQ sequence:401401- * data is "FF" while CTLR_IRQ is "H"402402- */403403- reply_len = 0;404404- srq_asserted = 0;405405- macii_state = read_done;406406- } else {407407- macii_state = reading;408408- *reply_ptr = x;409409- reply_len = 1;410410- }411411-412412- /* set ADB state = even for first data byte */413413- via[B] = (via[B] & ~ST_MASK) | ST_EVEN;414414- break;415415-416416- case sending:417417- req = current_req;418418- if (data_index >= req->nbytes) {419419- req->sent = 1;420420- macii_state = idle;421421-422422- if (req->reply_expected) {423423- reading_reply = 1;424424- } else {425425- req->complete = 1;426426- current_req = req->next;427427- if (req->done) (*req->done)(req);428428-429429- if (current_req)430430- macii_start();431431- else432432- if (need_autopoll())433433- macii_autopoll(autopoll_devs);434434- }435435-436436- if (macii_state == idle) {437437- /* reset to shift in */438438- via[ACR] &= ~SR_OUT;439439- x = via[SR];440440- /* set ADB state idle - might get SRQ */441441- via[B] = (via[B] & ~ST_MASK) | ST_IDLE;442442- }443443- } else {444444- via[SR] = req->data[data_index++];445445-446446- if ( (via[B] & ST_MASK) == ST_CMD ) {447447- /* just sent the command byte, set to EVEN */448448- via[B] = (via[B] & ~ST_MASK) | ST_EVEN;449449- } else {450450- /* invert state bits, toggle ODD/EVEN */451451- via[B] ^= ST_MASK;452452- }453453- }454454- break;455455-456456- case reading:457457- x = via[SR];458458- WARN_ON((status & ST_MASK) == ST_CMD ||459459- (status & ST_MASK) == ST_IDLE);460460-461461- /* Bus timeout with SRQ sequence:462462- * data is "XX FF" while CTLR_IRQ is "L L"463463- * End of packet without SRQ sequence:464464- * data is "XX...YY 00" while CTLR_IRQ is "L...H L"465465- * End of packet SRQ sequence:466466- * data is "XX...YY 00" while CTLR_IRQ is "L...L L"467467- * (where XX is the first response byte and468468- * YY is the last byte of valid response data.)393393+ if ((status & CTLR_IRQ) && (x == 0xFF)) {394394+ /* Bus timeout without SRQ sequence:395395+ * data is "FF" while CTLR_IRQ is "H"469396 */470470-397397+ reply_len = 0;471398 srq_asserted = 0;472472- if (!(status & CTLR_IRQ)) {473473- if (x == 0xFF) {474474- if (!(last_status & CTLR_IRQ)) {475475- macii_state = read_done;476476- reply_len = 0;477477- srq_asserted = 1;478478- }479479- } else if (x == 0x00) {480480- macii_state = read_done;481481- if (!(last_status & CTLR_IRQ))482482- srq_asserted = 1;483483- }484484- }399399+ macii_state = read_done;400400+ } else {401401+ macii_state = reading;402402+ *reply_ptr = x;403403+ reply_len = 1;404404+ }485405486486- if (macii_state == reading &&487487- reply_len < ARRAY_SIZE(reply_buf)) {488488- reply_ptr++;489489- *reply_ptr = x;490490- reply_len++;491491- }406406+ /* set ADB state = even for first data byte */407407+ via[B] = (via[B] & ~ST_MASK) | ST_EVEN;408408+ break;492409493493- /* invert state bits, toggle ODD/EVEN */494494- via[B] ^= ST_MASK;495495- break;496496-497497- case read_done:498498- x = via[SR];499499-500500- if (reading_reply) {501501- reading_reply = 0;502502- req = current_req;503503- req->reply_len = reply_len;504504- req->complete = 1;505505- current_req = req->next;506506- if (req->done) (*req->done)(req);507507- } else if (reply_len && autopoll_devs)508508- adb_input(reply_buf, reply_len, 0);509509-410410+ case sending:411411+ req = current_req;412412+ if (data_index >= req->nbytes) {413413+ req->sent = 1;510414 macii_state = idle;511415512512- /* SRQ seen before, initiate poll now */513513- if (srq_asserted)514514- macii_queue_poll();416416+ if (req->reply_expected) {417417+ reading_reply = 1;418418+ } else {419419+ req->complete = 1;420420+ current_req = req->next;421421+ if (req->done)422422+ (*req->done)(req);515423516516- if (current_req)517517- macii_start();518518- else519519- if (need_autopoll())424424+ if (current_req)425425+ macii_start();426426+ else if (need_autopoll())520427 macii_autopoll(autopoll_devs);428428+ }521429522522- if (macii_state == idle)430430+ if (macii_state == idle) {431431+ /* reset to shift in */432432+ via[ACR] &= ~SR_OUT;433433+ x = via[SR];434434+ /* set ADB state idle - might get SRQ */523435 via[B] = (via[B] & ~ST_MASK) | ST_IDLE;524524- break;436436+ }437437+ } else {438438+ via[SR] = req->data[data_index++];525439526526- default:440440+ if ((via[B] & ST_MASK) == ST_CMD) {441441+ /* just sent the command byte, set to EVEN */442442+ via[B] = (via[B] & ~ST_MASK) | ST_EVEN;443443+ } else {444444+ /* invert state bits, toggle ODD/EVEN */445445+ via[B] ^= ST_MASK;446446+ }447447+ }448448+ break;449449+450450+ case reading:451451+ x = via[SR];452452+ WARN_ON((status & ST_MASK) == ST_CMD ||453453+ (status & ST_MASK) == ST_IDLE);454454+455455+ /* Bus timeout with SRQ sequence:456456+ * data is "XX FF" while CTLR_IRQ is "L L"457457+ * End of packet without SRQ sequence:458458+ * data is "XX...YY 00" while CTLR_IRQ is "L...H L"459459+ * End of packet SRQ sequence:460460+ * data is "XX...YY 00" while CTLR_IRQ is "L...L L"461461+ * (where XX is the first response byte and462462+ * YY is the last byte of valid response data.)463463+ */464464+465465+ srq_asserted = 0;466466+ if (!(status & CTLR_IRQ)) {467467+ if (x == 0xFF) {468468+ if (!(last_status & CTLR_IRQ)) {469469+ macii_state = read_done;470470+ reply_len = 0;471471+ srq_asserted = 1;472472+ }473473+ } else if (x == 0x00) {474474+ macii_state = read_done;475475+ if (!(last_status & CTLR_IRQ))476476+ srq_asserted = 1;477477+ }478478+ }479479+480480+ if (macii_state == reading &&481481+ reply_len < ARRAY_SIZE(reply_buf)) {482482+ reply_ptr++;483483+ *reply_ptr = x;484484+ reply_len++;485485+ }486486+487487+ /* invert state bits, toggle ODD/EVEN */488488+ via[B] ^= ST_MASK;489489+ break;490490+491491+ case read_done:492492+ x = via[SR];493493+494494+ if (reading_reply) {495495+ reading_reply = 0;496496+ req = current_req;497497+ req->reply_len = reply_len;498498+ req->complete = 1;499499+ current_req = req->next;500500+ if (req->done)501501+ (*req->done)(req);502502+ } else if (reply_len && autopoll_devs)503503+ adb_input(reply_buf, reply_len, 0);504504+505505+ macii_state = idle;506506+507507+ /* SRQ seen before, initiate poll now */508508+ if (srq_asserted)509509+ macii_queue_poll();510510+511511+ if (current_req)512512+ macii_start();513513+ else if (need_autopoll())514514+ macii_autopoll(autopoll_devs);515515+516516+ if (macii_state == idle)517517+ via[B] = (via[B] & ~ST_MASK) | ST_IDLE;518518+ break;519519+520520+ default:527521 break;528522 }529523