1/* drivers/char/ser_a2232.c */ 2 3/* $Id: ser_a2232.c,v 0.4 2000/01/25 12:00:00 Exp $ */ 4 5/* Linux serial driver for the Amiga A2232 board */ 6 7/* This driver is MAINTAINED. Before applying any changes, please contact 8 * the author. 9 */ 10 11/* Copyright (c) 2000-2001 Enver Haase <ehaase@inf.fu-berlin.de> 12 * alias The A2232 driver project <A2232@gmx.net> 13 * All rights reserved. 14 * 15 * This program is free software; you can redistribute it and/or modify 16 * it under the terms of the GNU General Public License as published by 17 * the Free Software Foundation; either version 2 of the License, or 18 * (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU General Public License for more details. 24 * 25 * You should have received a copy of the GNU General Public License 26 * along with this program; if not, write to the Free Software 27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 28 * 29 */ 30/***************************** Documentation ************************/ 31/* 32 * This driver is in EXPERIMENTAL state. That means I could not find 33 * someone with five A2232 boards with 35 ports running at 19200 bps 34 * at the same time and test the machine's behaviour. 35 * However, I know that you can performance-tweak this driver (see 36 * the source code). 37 * One thing to consider is the time this driver consumes during the 38 * Amiga's vertical blank interrupt. Everything that is to be done 39 * _IS DONE_ when entering the vertical blank interrupt handler of 40 * this driver. 41 * However, it would be more sane to only do the job for only ONE card 42 * instead of ALL cards at a time; or, more generally, to handle only 43 * SOME ports instead of ALL ports at a time. 44 * However, as long as no-one runs into problems I guess I shouldn't 45 * change the driver as it runs fine for me :) . 46 * 47 * Version history of this file: 48 * 0.4 Resolved licensing issues. 49 * 0.3 Inclusion in the Linux/m68k tree, small fixes. 50 * 0.2 Added documentation, minor typo fixes. 51 * 0.1 Initial release. 52 * 53 * TO DO: 54 * - Handle incoming BREAK events. I guess "Stevens: Advanced 55 * Programming in the UNIX(R) Environment" is a good reference 56 * on what is to be done. 57 * - When installing as a module, don't simply 'printk' text, but 58 * send it to the TTY used by the user. 59 * 60 * THANKS TO: 61 * - Jukka Marin (65EC02 code). 62 * - The other NetBSD developers on whose A2232 driver I had a 63 * pretty close look. However, I didn't copy any code so it 64 * is okay to put my code under the GPL and include it into 65 * Linux. 66 */ 67/***************************** End of Documentation *****************/ 68 69/***************************** Defines ******************************/ 70/* 71 * Enables experimental 115200 (normal) 230400 (turbo) baud rate. 72 * The A2232 specification states it can only operate at speeds up to 73 * 19200 bits per second, and I was not able to send a file via 74 * "sz"/"rz" and a null-modem cable from one A2232 port to another 75 * at 115200 bits per second. 76 * However, this might work for you. 77 */ 78#undef A2232_SPEEDHACK 79/* 80 * Default is not to use RTS/CTS so you could be talked to death. 81 */ 82#define A2232_SUPPRESS_RTSCTS_WARNING 83/************************* End of Defines ***************************/ 84 85/***************************** Includes *****************************/ 86#include <linux/module.h> 87 88#include <linux/types.h> 89#include <linux/interrupt.h> 90#include <linux/kernel.h> 91#include <linux/errno.h> 92#include <linux/sched.h> 93#include <linux/tty.h> 94 95#include <asm/setup.h> 96#include <asm/amigaints.h> 97#include <asm/amigahw.h> 98#include <linux/zorro.h> 99#include <asm/irq.h> 100#include <linux/mutex.h> 101 102#include <linux/delay.h> 103 104#include <linux/serial.h> 105#include <linux/generic_serial.h> 106#include <linux/tty_flip.h> 107 108#include "ser_a2232.h" 109#include "ser_a2232fw.h" 110/************************* End of Includes **************************/ 111 112/***************************** Prototypes ***************************/ 113/* The interrupt service routine */ 114static irqreturn_t a2232_vbl_inter(int irq, void *data); 115/* Initialize the port structures */ 116static void a2232_init_portstructs(void); 117/* Initialize and register TTY drivers. */ 118/* returns 0 IFF successful */ 119static int a2232_init_drivers(void); 120 121/* BEGIN GENERIC_SERIAL PROTOTYPES */ 122static void a2232_disable_tx_interrupts(void *ptr); 123static void a2232_enable_tx_interrupts(void *ptr); 124static void a2232_disable_rx_interrupts(void *ptr); 125static void a2232_enable_rx_interrupts(void *ptr); 126static int a2232_carrier_raised(struct tty_port *port); 127static void a2232_shutdown_port(void *ptr); 128static int a2232_set_real_termios(void *ptr); 129static int a2232_chars_in_buffer(void *ptr); 130static void a2232_close(void *ptr); 131static void a2232_hungup(void *ptr); 132/* static void a2232_getserial (void *ptr, struct serial_struct *sp); */ 133/* END GENERIC_SERIAL PROTOTYPES */ 134 135/* Functions that the TTY driver struct expects */ 136static int a2232_ioctl(struct tty_struct *tty, struct file *file, 137 unsigned int cmd, unsigned long arg); 138static void a2232_throttle(struct tty_struct *tty); 139static void a2232_unthrottle(struct tty_struct *tty); 140static int a2232_open(struct tty_struct * tty, struct file * filp); 141/************************* End of Prototypes ************************/ 142 143/***************************** Global variables *********************/ 144/*--------------------------------------------------------------------------- 145 * Interface from generic_serial.c back here 146 *--------------------------------------------------------------------------*/ 147static struct real_driver a2232_real_driver = { 148 a2232_disable_tx_interrupts, 149 a2232_enable_tx_interrupts, 150 a2232_disable_rx_interrupts, 151 a2232_enable_rx_interrupts, 152 a2232_shutdown_port, 153 a2232_set_real_termios, 154 a2232_chars_in_buffer, 155 a2232_close, 156 a2232_hungup, 157 NULL /* a2232_getserial */ 158}; 159 160static void *a2232_driver_ID = &a2232_driver_ID; // Some memory address WE own. 161 162/* Ports structs */ 163static struct a2232_port a2232_ports[MAX_A2232_BOARDS*NUMLINES]; 164 165/* TTY driver structs */ 166static struct tty_driver *a2232_driver; 167 168/* nr of cards completely (all ports) and correctly configured */ 169static int nr_a2232; 170 171/* zorro_dev structs for the A2232's */ 172static struct zorro_dev *zd_a2232[MAX_A2232_BOARDS]; 173/***************************** End of Global variables **************/ 174 175/* Helper functions */ 176 177static inline volatile struct a2232memory *a2232mem(unsigned int board) 178{ 179 return (volatile struct a2232memory *)ZTWO_VADDR(zd_a2232[board]->resource.start); 180} 181 182static inline volatile struct a2232status *a2232stat(unsigned int board, 183 unsigned int portonboard) 184{ 185 volatile struct a2232memory *mem = a2232mem(board); 186 return &(mem->Status[portonboard]); 187} 188 189static inline void a2232_receive_char(struct a2232_port *port, int ch, int err) 190{ 191/* Mostly stolen from other drivers. 192 Maybe one could implement a more efficient version by not only 193 transferring one character at a time. 194*/ 195 struct tty_struct *tty = port->gs.port.tty; 196 197 198 tty_insert_flip_char(tty, ch, err); 199 tty_flip_buffer_push(tty); 200} 201 202/***************************** Functions ****************************/ 203/*** BEGIN OF REAL_DRIVER FUNCTIONS ***/ 204 205static void a2232_disable_tx_interrupts(void *ptr) 206{ 207 struct a2232_port *port; 208 volatile struct a2232status *stat; 209 unsigned long flags; 210 211 port = ptr; 212 stat = a2232stat(port->which_a2232, port->which_port_on_a2232); 213 stat->OutDisable = -1; 214 215 /* Does this here really have to be? */ 216 local_irq_save(flags); 217 port->gs.port.flags &= ~GS_TX_INTEN; 218 local_irq_restore(flags); 219} 220 221static void a2232_enable_tx_interrupts(void *ptr) 222{ 223 struct a2232_port *port; 224 volatile struct a2232status *stat; 225 unsigned long flags; 226 227 port = ptr; 228 stat = a2232stat(port->which_a2232, port->which_port_on_a2232); 229 stat->OutDisable = 0; 230 231 /* Does this here really have to be? */ 232 local_irq_save(flags); 233 port->gs.port.flags |= GS_TX_INTEN; 234 local_irq_restore(flags); 235} 236 237static void a2232_disable_rx_interrupts(void *ptr) 238{ 239 struct a2232_port *port; 240 port = ptr; 241 port->disable_rx = -1; 242} 243 244static void a2232_enable_rx_interrupts(void *ptr) 245{ 246 struct a2232_port *port; 247 port = ptr; 248 port->disable_rx = 0; 249} 250 251static int a2232_carrier_raised(struct tty_port *port) 252{ 253 struct a2232_port *ap = container_of(port, struct a2232_port, gs.port); 254 return ap->cd_status; 255} 256 257static void a2232_shutdown_port(void *ptr) 258{ 259 struct a2232_port *port; 260 volatile struct a2232status *stat; 261 unsigned long flags; 262 263 port = ptr; 264 stat = a2232stat(port->which_a2232, port->which_port_on_a2232); 265 266 local_irq_save(flags); 267 268 port->gs.port.flags &= ~GS_ACTIVE; 269 270 if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) { 271 /* Set DTR and RTS to Low, flush output. 272 The NetBSD driver "msc.c" does it this way. */ 273 stat->Command = ( (stat->Command & ~A2232CMD_CMask) | 274 A2232CMD_Close ); 275 stat->OutFlush = -1; 276 stat->Setup = -1; 277 } 278 279 local_irq_restore(flags); 280 281 /* After analyzing control flow, I think a2232_shutdown_port 282 is actually the last call from the system when at application 283 level someone issues a "echo Hello >>/dev/ttyY0". 284 Therefore I think the MOD_DEC_USE_COUNT should be here and 285 not in "a2232_close()". See the comment in "sx.c", too. 286 If you run into problems, compile this driver into the 287 kernel instead of compiling it as a module. */ 288} 289 290static int a2232_set_real_termios(void *ptr) 291{ 292 unsigned int cflag, baud, chsize, stopb, parity, softflow; 293 int rate; 294 int a2232_param, a2232_cmd; 295 unsigned long flags; 296 unsigned int i; 297 struct a2232_port *port = ptr; 298 volatile struct a2232status *status; 299 volatile struct a2232memory *mem; 300 301 if (!port->gs.port.tty || !port->gs.port.tty->termios) return 0; 302 303 status = a2232stat(port->which_a2232, port->which_port_on_a2232); 304 mem = a2232mem(port->which_a2232); 305 306 a2232_param = a2232_cmd = 0; 307 308 // get baud rate 309 baud = port->gs.baud; 310 if (baud == 0) { 311 /* speed == 0 -> drop DTR, do nothing else */ 312 local_irq_save(flags); 313 // Clear DTR (and RTS... mhhh). 314 status->Command = ( (status->Command & ~A2232CMD_CMask) | 315 A2232CMD_Close ); 316 status->OutFlush = -1; 317 status->Setup = -1; 318 319 local_irq_restore(flags); 320 return 0; 321 } 322 323 rate = A2232_BAUD_TABLE_NOAVAIL; 324 for (i=0; i < A2232_BAUD_TABLE_NUM_RATES * 3; i += 3){ 325 if (a2232_baud_table[i] == baud){ 326 if (mem->Common.Crystal == A2232_TURBO) rate = a2232_baud_table[i+2]; 327 else rate = a2232_baud_table[i+1]; 328 } 329 } 330 if (rate == A2232_BAUD_TABLE_NOAVAIL){ 331 printk("a2232: Board %d Port %d unsupported baud rate: %d baud. Using another.\n",port->which_a2232,port->which_port_on_a2232,baud); 332 // This is useful for both (turbo or normal) Crystal versions. 333 rate = A2232PARAM_B9600; 334 } 335 a2232_param |= rate; 336 337 cflag = port->gs.port.tty->termios->c_cflag; 338 339 // get character size 340 chsize = cflag & CSIZE; 341 switch (chsize){ 342 case CS8: a2232_param |= A2232PARAM_8Bit; break; 343 case CS7: a2232_param |= A2232PARAM_7Bit; break; 344 case CS6: a2232_param |= A2232PARAM_6Bit; break; 345 case CS5: a2232_param |= A2232PARAM_5Bit; break; 346 default: printk("a2232: Board %d Port %d unsupported character size: %d. Using 8 data bits.\n", 347 port->which_a2232,port->which_port_on_a2232,chsize); 348 a2232_param |= A2232PARAM_8Bit; break; 349 } 350 351 // get number of stop bits 352 stopb = cflag & CSTOPB; 353 if (stopb){ // two stop bits instead of one 354 printk("a2232: Board %d Port %d 2 stop bits unsupported. Using 1 stop bit.\n", 355 port->which_a2232,port->which_port_on_a2232); 356 } 357 358 // Warn if RTS/CTS not wanted 359 if (!(cflag & CRTSCTS)){ 360#ifndef A2232_SUPPRESS_RTSCTS_WARNING 361 printk("a2232: Board %d Port %d cannot switch off firmware-implemented RTS/CTS hardware flow control.\n", 362 port->which_a2232,port->which_port_on_a2232); 363#endif 364 } 365 366 /* I think this is correct. 367 However, IXOFF means _input_ flow control and I wonder 368 if one should care about IXON _output_ flow control, 369 too. If this makes problems, one should turn the A2232 370 firmware XON/XOFF "SoftFlow" flow control off and use 371 the conventional way of inserting START/STOP characters 372 by hand in throttle()/unthrottle(). 373 */ 374 softflow = !!( port->gs.port.tty->termios->c_iflag & IXOFF ); 375 376 // get Parity (Enabled/Disabled? If Enabled, Odd or Even?) 377 parity = cflag & (PARENB | PARODD); 378 if (parity & PARENB){ 379 if (parity & PARODD){ 380 a2232_cmd |= A2232CMD_OddParity; 381 } 382 else{ 383 a2232_cmd |= A2232CMD_EvenParity; 384 } 385 } 386 else a2232_cmd |= A2232CMD_NoParity; 387 388 389 /* Hmm. Maybe an own a2232_port structure 390 member would be cleaner? */ 391 if (cflag & CLOCAL) 392 port->gs.port.flags &= ~ASYNC_CHECK_CD; 393 else 394 port->gs.port.flags |= ASYNC_CHECK_CD; 395 396 397 /* Now we have all parameters and can go to set them: */ 398 local_irq_save(flags); 399 400 status->Param = a2232_param | A2232PARAM_RcvBaud; 401 status->Command = a2232_cmd | A2232CMD_Open | A2232CMD_Enable; 402 status->SoftFlow = softflow; 403 status->OutDisable = 0; 404 status->Setup = -1; 405 406 local_irq_restore(flags); 407 return 0; 408} 409 410static int a2232_chars_in_buffer(void *ptr) 411{ 412 struct a2232_port *port; 413 volatile struct a2232status *status; 414 unsigned char ret; /* we need modulo-256 arithmetics */ 415 port = ptr; 416 status = a2232stat(port->which_a2232, port->which_port_on_a2232); 417#if A2232_IOBUFLEN != 256 418#error "Re-Implement a2232_chars_in_buffer()!" 419#endif 420 ret = (status->OutHead - status->OutTail); 421 return ret; 422} 423 424static void a2232_close(void *ptr) 425{ 426 a2232_disable_tx_interrupts(ptr); 427 a2232_disable_rx_interrupts(ptr); 428 /* see the comment in a2232_shutdown_port above. */ 429} 430 431static void a2232_hungup(void *ptr) 432{ 433 a2232_close(ptr); 434} 435/*** END OF REAL_DRIVER FUNCTIONS ***/ 436 437/*** BEGIN FUNCTIONS EXPECTED BY TTY DRIVER STRUCTS ***/ 438static int a2232_ioctl( struct tty_struct *tty, struct file *file, 439 unsigned int cmd, unsigned long arg) 440{ 441 return -ENOIOCTLCMD; 442} 443 444static void a2232_throttle(struct tty_struct *tty) 445{ 446/* Throttle: System cannot take another chars: Drop RTS or 447 send the STOP char or whatever. 448 The A2232 firmware does RTS/CTS anyway, and XON/XOFF 449 if switched on. So the only thing we can do at this 450 layer here is not taking any characters out of the 451 A2232 buffer any more. */ 452 struct a2232_port *port = tty->driver_data; 453 port->throttle_input = -1; 454} 455 456static void a2232_unthrottle(struct tty_struct *tty) 457{ 458/* Unthrottle: dual to "throttle()" above. */ 459 struct a2232_port *port = tty->driver_data; 460 port->throttle_input = 0; 461} 462 463static int a2232_open(struct tty_struct * tty, struct file * filp) 464{ 465/* More or less stolen from other drivers. */ 466 int line; 467 int retval; 468 struct a2232_port *port; 469 470 line = tty->index; 471 port = &a2232_ports[line]; 472 473 tty->driver_data = port; 474 port->gs.port.tty = tty; 475 port->gs.port.count++; 476 retval = gs_init_port(&port->gs); 477 if (retval) { 478 port->gs.port.count--; 479 return retval; 480 } 481 port->gs.port.flags |= GS_ACTIVE; 482 retval = gs_block_til_ready(port, filp); 483 484 if (retval) { 485 port->gs.port.count--; 486 return retval; 487 } 488 489 a2232_enable_rx_interrupts(port); 490 491 return 0; 492} 493/*** END OF FUNCTIONS EXPECTED BY TTY DRIVER STRUCTS ***/ 494 495static irqreturn_t a2232_vbl_inter(int irq, void *data) 496{ 497#if A2232_IOBUFLEN != 256 498#error "Re-Implement a2232_vbl_inter()!" 499#endif 500 501struct a2232_port *port; 502volatile struct a2232memory *mem; 503volatile struct a2232status *status; 504unsigned char newhead; 505unsigned char bufpos; /* Must be unsigned char. We need the modulo-256 arithmetics */ 506unsigned char ncd, ocd, ccd; /* names consistent with the NetBSD driver */ 507volatile u_char *ibuf, *cbuf, *obuf; 508int ch, err, n, p; 509 for (n = 0; n < nr_a2232; n++){ /* for every completely initialized A2232 board */ 510 mem = a2232mem(n); 511 for (p = 0; p < NUMLINES; p++){ /* for every port on this board */ 512 err = 0; 513 port = &a2232_ports[n*NUMLINES+p]; 514 if ( port->gs.port.flags & GS_ACTIVE ){ /* if the port is used */ 515 516 status = a2232stat(n,p); 517 518 if (!port->disable_rx && !port->throttle_input){ /* If input is not disabled */ 519 newhead = status->InHead; /* 65EC02 write pointer */ 520 bufpos = status->InTail; 521 522 /* check for input for this port */ 523 if (newhead != bufpos) { 524 /* buffer for input chars/events */ 525 ibuf = mem->InBuf[p]; 526 527 /* data types of bytes in ibuf */ 528 cbuf = mem->InCtl[p]; 529 530 /* do for all chars */ 531 while (bufpos != newhead) { 532 /* which type of input data? */ 533 switch (cbuf[bufpos]) { 534 /* switch on input event (CD, BREAK, etc.) */ 535 case A2232INCTL_EVENT: 536 switch (ibuf[bufpos++]) { 537 case A2232EVENT_Break: 538 /* TODO: Handle BREAK signal */ 539 break; 540 /* A2232EVENT_CarrierOn and A2232EVENT_CarrierOff are 541 handled in a separate queue and should not occur here. */ 542 case A2232EVENT_Sync: 543 printk("A2232: 65EC02 software sent SYNC event, don't know what to do. Ignoring."); 544 break; 545 default: 546 printk("A2232: 65EC02 software broken, unknown event type %d occurred.\n",ibuf[bufpos-1]); 547 } /* event type switch */ 548 break; 549 case A2232INCTL_CHAR: 550 /* Receive incoming char */ 551 a2232_receive_char(port, ibuf[bufpos], err); 552 bufpos++; 553 break; 554 default: 555 printk("A2232: 65EC02 software broken, unknown data type %d occurred.\n",cbuf[bufpos]); 556 bufpos++; 557 } /* switch on input data type */ 558 } /* while there's something in the buffer */ 559 560 status->InTail = bufpos; /* tell 65EC02 what we've read */ 561 562 } /* if there was something in the buffer */ 563 } /* If input is not disabled */ 564 565 /* Now check if there's something to output */ 566 obuf = mem->OutBuf[p]; 567 bufpos = status->OutHead; 568 while ( (port->gs.xmit_cnt > 0) && 569 (!port->gs.port.tty->stopped) && 570 (!port->gs.port.tty->hw_stopped) ){ /* While there are chars to transmit */ 571 if (((bufpos+1) & A2232_IOBUFLENMASK) != status->OutTail) { /* If the A2232 buffer is not full */ 572 ch = port->gs.xmit_buf[port->gs.xmit_tail]; /* get the next char to transmit */ 573 port->gs.xmit_tail = (port->gs.xmit_tail+1) & (SERIAL_XMIT_SIZE-1); /* modulo-addition for the gs.xmit_buf ring-buffer */ 574 obuf[bufpos++] = ch; /* put it into the A2232 buffer */ 575 port->gs.xmit_cnt--; 576 } 577 else{ /* If A2232 the buffer is full */ 578 break; /* simply stop filling it. */ 579 } 580 } 581 status->OutHead = bufpos; 582 583 /* WakeUp if output buffer runs low */ 584 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.port.tty) { 585 tty_wakeup(port->gs.port.tty); 586 } 587 } // if the port is used 588 } // for every port on the board 589 590 /* Now check the CD message queue */ 591 newhead = mem->Common.CDHead; 592 bufpos = mem->Common.CDTail; 593 if (newhead != bufpos){ /* There are CD events in queue */ 594 ocd = mem->Common.CDStatus; /* get old status bits */ 595 while (newhead != bufpos){ /* read all events */ 596 ncd = mem->CDBuf[bufpos++]; /* get one event */ 597 ccd = ncd ^ ocd; /* mask of changed lines */ 598 ocd = ncd; /* save new status bits */ 599 for(p=0; p < NUMLINES; p++){ /* for all ports */ 600 if (ccd & 1){ /* this one changed */ 601 602 struct a2232_port *port = &a2232_ports[n*7+p]; 603 port->cd_status = !(ncd & 1); /* ncd&1 <=> CD is now off */ 604 605 if (!(port->gs.port.flags & ASYNC_CHECK_CD)) 606 ; /* Don't report DCD changes */ 607 else if (port->cd_status) { // if DCD on: DCD went UP! 608 609 /* Are we blocking in open?*/ 610 wake_up_interruptible(&port->gs.port.open_wait); 611 } 612 else { // if DCD off: DCD went DOWN! 613 if (port->gs.port.tty) 614 tty_hangup (port->gs.port.tty); 615 } 616 617 } // if CD changed for this port 618 ccd >>= 1; 619 ncd >>= 1; /* Shift bits for next line */ 620 } // for every port 621 } // while CD events in queue 622 mem->Common.CDStatus = ocd; /* save new status */ 623 mem->Common.CDTail = bufpos; /* remove events */ 624 } // if events in CD queue 625 626 } // for every completely initialized A2232 board 627 return IRQ_HANDLED; 628} 629 630static const struct tty_port_operations a2232_port_ops = { 631 .carrier_raised = a2232_carrier_raised, 632}; 633 634static void a2232_init_portstructs(void) 635{ 636 struct a2232_port *port; 637 int i; 638 639 for (i = 0; i < MAX_A2232_BOARDS*NUMLINES; i++) { 640 port = a2232_ports + i; 641 tty_port_init(&port->gs.port); 642 port->gs.port.ops = &a2232_port_ops; 643 port->which_a2232 = i/NUMLINES; 644 port->which_port_on_a2232 = i%NUMLINES; 645 port->disable_rx = port->throttle_input = port->cd_status = 0; 646 port->gs.magic = A2232_MAGIC; 647 port->gs.close_delay = HZ/2; 648 port->gs.closing_wait = 30 * HZ; 649 port->gs.rd = &a2232_real_driver; 650 } 651} 652 653static const struct tty_operations a2232_ops = { 654 .open = a2232_open, 655 .close = gs_close, 656 .write = gs_write, 657 .put_char = gs_put_char, 658 .flush_chars = gs_flush_chars, 659 .write_room = gs_write_room, 660 .chars_in_buffer = gs_chars_in_buffer, 661 .flush_buffer = gs_flush_buffer, 662 .ioctl = a2232_ioctl, 663 .throttle = a2232_throttle, 664 .unthrottle = a2232_unthrottle, 665 .set_termios = gs_set_termios, 666 .stop = gs_stop, 667 .start = gs_start, 668 .hangup = gs_hangup, 669}; 670 671static int a2232_init_drivers(void) 672{ 673 int error; 674 675 a2232_driver = alloc_tty_driver(NUMLINES * nr_a2232); 676 if (!a2232_driver) 677 return -ENOMEM; 678 a2232_driver->owner = THIS_MODULE; 679 a2232_driver->driver_name = "commodore_a2232"; 680 a2232_driver->name = "ttyY"; 681 a2232_driver->major = A2232_NORMAL_MAJOR; 682 a2232_driver->type = TTY_DRIVER_TYPE_SERIAL; 683 a2232_driver->subtype = SERIAL_TYPE_NORMAL; 684 a2232_driver->init_termios = tty_std_termios; 685 a2232_driver->init_termios.c_cflag = 686 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 687 a2232_driver->init_termios.c_ispeed = 9600; 688 a2232_driver->init_termios.c_ospeed = 9600; 689 a2232_driver->flags = TTY_DRIVER_REAL_RAW; 690 tty_set_operations(a2232_driver, &a2232_ops); 691 if ((error = tty_register_driver(a2232_driver))) { 692 printk(KERN_ERR "A2232: Couldn't register A2232 driver, error = %d\n", 693 error); 694 put_tty_driver(a2232_driver); 695 return 1; 696 } 697 return 0; 698} 699 700static int __init a2232board_init(void) 701{ 702 struct zorro_dev *z; 703 704 unsigned int boardaddr; 705 int bcount; 706 short start; 707 u_char *from; 708 volatile u_char *to; 709 volatile struct a2232memory *mem; 710 int error, i; 711 712#ifdef CONFIG_SMP 713 return -ENODEV; /* This driver is not SMP aware. Is there an SMP ZorroII-bus-machine? */ 714#endif 715 716 if (!MACH_IS_AMIGA){ 717 return -ENODEV; 718 } 719 720 printk("Commodore A2232 driver initializing.\n"); /* Say that we're alive. */ 721 722 z = NULL; 723 nr_a2232 = 0; 724 while ( (z = zorro_find_device(ZORRO_WILDCARD, z)) ){ 725 if ( (z->id != ZORRO_PROD_CBM_A2232_PROTOTYPE) && 726 (z->id != ZORRO_PROD_CBM_A2232) ){ 727 continue; // The board found was no A2232 728 } 729 if (!zorro_request_device(z,"A2232 driver")) 730 continue; 731 732 printk("Commodore A2232 found (#%d).\n",nr_a2232); 733 734 zd_a2232[nr_a2232] = z; 735 736 boardaddr = ZTWO_VADDR( z->resource.start ); 737 printk("Board is located at address 0x%x, size is 0x%x.\n", boardaddr, (unsigned int) ((z->resource.end+1) - (z->resource.start))); 738 739 mem = (volatile struct a2232memory *) boardaddr; 740 741 (void) mem->Enable6502Reset; /* copy the code across to the board */ 742 to = (u_char *)mem; from = a2232_65EC02code; bcount = sizeof(a2232_65EC02code) - 2; 743 start = *(short *)from; 744 from += sizeof(start); 745 to += start; 746 while(bcount--) *to++ = *from++; 747 printk("65EC02 software uploaded to the A2232 memory.\n"); 748 749 mem->Common.Crystal = A2232_UNKNOWN; /* use automatic speed check */ 750 751 /* start 6502 running */ 752 (void) mem->ResetBoard; 753 printk("A2232's 65EC02 CPU up and running.\n"); 754 755 /* wait until speed detector has finished */ 756 for (bcount = 0; bcount < 2000; bcount++) { 757 udelay(1000); 758 if (mem->Common.Crystal) 759 break; 760 } 761 printk((mem->Common.Crystal?"A2232 oscillator crystal detected by 65EC02 software: ":"65EC02 software could not determine A2232 oscillator crystal: ")); 762 switch (mem->Common.Crystal){ 763 case A2232_UNKNOWN: 764 printk("Unknown crystal.\n"); 765 break; 766 case A2232_NORMAL: 767 printk ("Normal crystal.\n"); 768 break; 769 case A2232_TURBO: 770 printk ("Turbo crystal.\n"); 771 break; 772 default: 773 printk ("0x%x. Huh?\n",mem->Common.Crystal); 774 } 775 776 nr_a2232++; 777 778 } 779 780 printk("Total: %d A2232 boards initialized.\n", nr_a2232); /* Some status report if no card was found */ 781 782 a2232_init_portstructs(); 783 784 /* 785 a2232_init_drivers also registers the drivers. Must be here because all boards 786 have to be detected first. 787 */ 788 if (a2232_init_drivers()) return -ENODEV; // maybe we should use a different -Exxx? 789 790 error = request_irq(IRQ_AMIGA_VERTB, a2232_vbl_inter, 0, 791 "A2232 serial VBL", a2232_driver_ID); 792 if (error) { 793 for (i = 0; i < nr_a2232; i++) 794 zorro_release_device(zd_a2232[i]); 795 tty_unregister_driver(a2232_driver); 796 put_tty_driver(a2232_driver); 797 } 798 return error; 799} 800 801static void __exit a2232board_exit(void) 802{ 803 int i; 804 805 for (i = 0; i < nr_a2232; i++) { 806 zorro_release_device(zd_a2232[i]); 807 } 808 809 tty_unregister_driver(a2232_driver); 810 put_tty_driver(a2232_driver); 811 free_irq(IRQ_AMIGA_VERTB, a2232_driver_ID); 812} 813 814module_init(a2232board_init); 815module_exit(a2232board_exit); 816 817MODULE_AUTHOR("Enver Haase"); 818MODULE_DESCRIPTION("Amiga A2232 multi-serial board driver"); 819MODULE_LICENSE("GPL"); 820