123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224 |
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/delay.h>
- #include <linux/tty.h>
- #include <linux/tty_flip.h>
- #include <linux/major.h>
- #include <linux/string.h>
- #include <linux/ptrace.h>
- #include <linux/ioport.h>
- #include <linux/slab.h>
- #include <linux/circ_buf.h>
- #include <linux/serial.h>
- #include <linux/sysrq.h>
- #include <linux/console.h>
- #include <linux/spinlock.h>
- #include <linux/init.h>
- #include <asm/io.h>
- #include <asm/irq.h>
- #include <asm/sgialib.h>
- #include <asm/sgi/ioc.h>
- #include <asm/sgi/hpc3.h>
- #include <asm/sgi/ip22.h>
- #if defined(CONFIG_SERIAL_IP22_ZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
- #define SUPPORT_SYSRQ
- #endif
- #include <linux/serial_core.h>
- #include "ip22zilog.h"
- #define ZSDELAY() udelay(5)
- #define ZSDELAY_LONG() udelay(20)
- #define ZS_WSYNC(channel) do { } while (0)
- #define NUM_IP22ZILOG 1
- #define NUM_CHANNELS (NUM_IP22ZILOG * 2)
- #define ZS_CLOCK 3672000
- #define ZS_CLOCK_DIVISOR 16
- struct uart_ip22zilog_port {
- struct uart_port port;
-
- struct uart_ip22zilog_port *next;
-
- unsigned char curregs[NUM_ZSREGS];
- unsigned int flags;
- #define IP22ZILOG_FLAG_IS_CONS 0x00000004
- #define IP22ZILOG_FLAG_IS_KGDB 0x00000008
- #define IP22ZILOG_FLAG_MODEM_STATUS 0x00000010
- #define IP22ZILOG_FLAG_IS_CHANNEL_A 0x00000020
- #define IP22ZILOG_FLAG_REGS_HELD 0x00000040
- #define IP22ZILOG_FLAG_TX_STOPPED 0x00000080
- #define IP22ZILOG_FLAG_TX_ACTIVE 0x00000100
- #define IP22ZILOG_FLAG_RESET_DONE 0x00000200
- unsigned int tty_break;
- unsigned char parity_mask;
- unsigned char prev_status;
- };
- #define ZILOG_CHANNEL_FROM_PORT(PORT) ((struct zilog_channel *)((PORT)->membase))
- #define UART_ZILOG(PORT) ((struct uart_ip22zilog_port *)(PORT))
- #define IP22ZILOG_GET_CURR_REG(PORT, REGNUM) \
- (UART_ZILOG(PORT)->curregs[REGNUM])
- #define IP22ZILOG_SET_CURR_REG(PORT, REGNUM, REGVAL) \
- ((UART_ZILOG(PORT)->curregs[REGNUM]) = (REGVAL))
- #define ZS_IS_CONS(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CONS)
- #define ZS_IS_KGDB(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_KGDB)
- #define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & IP22ZILOG_FLAG_MODEM_STATUS)
- #define ZS_IS_CHANNEL_A(UP) ((UP)->flags & IP22ZILOG_FLAG_IS_CHANNEL_A)
- #define ZS_REGS_HELD(UP) ((UP)->flags & IP22ZILOG_FLAG_REGS_HELD)
- #define ZS_TX_STOPPED(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_STOPPED)
- #define ZS_TX_ACTIVE(UP) ((UP)->flags & IP22ZILOG_FLAG_TX_ACTIVE)
- static unsigned char read_zsreg(struct zilog_channel *channel,
- unsigned char reg)
- {
- unsigned char retval;
- writeb(reg, &channel->control);
- ZSDELAY();
- retval = readb(&channel->control);
- ZSDELAY();
- return retval;
- }
- static void write_zsreg(struct zilog_channel *channel,
- unsigned char reg, unsigned char value)
- {
- writeb(reg, &channel->control);
- ZSDELAY();
- writeb(value, &channel->control);
- ZSDELAY();
- }
- static void ip22zilog_clear_fifo(struct zilog_channel *channel)
- {
- int i;
- for (i = 0; i < 32; i++) {
- unsigned char regval;
- regval = readb(&channel->control);
- ZSDELAY();
- if (regval & Rx_CH_AV)
- break;
- regval = read_zsreg(channel, R1);
- readb(&channel->data);
- ZSDELAY();
- if (regval & (PAR_ERR | Rx_OVR | CRC_ERR)) {
- writeb(ERR_RES, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- }
- }
- }
- static void __load_zsregs(struct zilog_channel *channel, unsigned char *regs)
- {
- int i;
-
- for (i = 0; i < 1000; i++) {
- unsigned char stat = read_zsreg(channel, R1);
- if (stat & ALL_SNT)
- break;
- udelay(100);
- }
- writeb(ERR_RES, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- ip22zilog_clear_fifo(channel);
-
- write_zsreg(channel, R1,
- regs[R1] & ~(RxINT_MASK | TxINT_ENAB | EXT_INT_ENAB));
-
- write_zsreg(channel, R4, regs[R4]);
-
- write_zsreg(channel, R10, regs[R10]);
-
- write_zsreg(channel, R3, regs[R3] & ~RxENAB);
- write_zsreg(channel, R5, regs[R5] & ~TxENAB);
-
- write_zsreg(channel, R6, regs[R6]);
- write_zsreg(channel, R7, regs[R7]);
-
-
- write_zsreg(channel, R14, regs[R14] & ~BRENAB);
-
- write_zsreg(channel, R11, regs[R11]);
-
- write_zsreg(channel, R12, regs[R12]);
- write_zsreg(channel, R13, regs[R13]);
-
- write_zsreg(channel, R14, regs[R14]);
-
- write_zsreg(channel, R15, regs[R15]);
-
- write_zsreg(channel, R0, RES_EXT_INT);
- write_zsreg(channel, R0, RES_EXT_INT);
-
- write_zsreg(channel, R3, regs[R3]);
- write_zsreg(channel, R5, regs[R5]);
-
- write_zsreg(channel, R1, regs[R1]);
- }
- static void ip22zilog_maybe_update_regs(struct uart_ip22zilog_port *up,
- struct zilog_channel *channel)
- {
- if (!ZS_REGS_HELD(up)) {
- if (ZS_TX_ACTIVE(up)) {
- up->flags |= IP22ZILOG_FLAG_REGS_HELD;
- } else {
- __load_zsregs(channel, up->curregs);
- }
- }
- }
- #define Rx_BRK 0x0100
- #define Rx_SYS 0x0200
- static bool ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
- struct zilog_channel *channel)
- {
- unsigned char ch, flag;
- unsigned int r1;
- bool push = up->port.state != NULL;
- for (;;) {
- ch = readb(&channel->control);
- ZSDELAY();
- if (!(ch & Rx_CH_AV))
- break;
- r1 = read_zsreg(channel, R1);
- if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
- writeb(ERR_RES, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- }
- ch = readb(&channel->data);
- ZSDELAY();
- ch &= up->parity_mask;
-
- if (!ch)
- r1 |= up->tty_break;
-
- flag = TTY_NORMAL;
- up->port.icount.rx++;
- if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR | Rx_SYS | Rx_BRK)) {
- up->tty_break = 0;
- if (r1 & (Rx_SYS | Rx_BRK)) {
- up->port.icount.brk++;
- if (r1 & Rx_SYS)
- continue;
- r1 &= ~(PAR_ERR | CRC_ERR);
- }
- else if (r1 & PAR_ERR)
- up->port.icount.parity++;
- else if (r1 & CRC_ERR)
- up->port.icount.frame++;
- if (r1 & Rx_OVR)
- up->port.icount.overrun++;
- r1 &= up->port.read_status_mask;
- if (r1 & Rx_BRK)
- flag = TTY_BREAK;
- else if (r1 & PAR_ERR)
- flag = TTY_PARITY;
- else if (r1 & CRC_ERR)
- flag = TTY_FRAME;
- }
- if (uart_handle_sysrq_char(&up->port, ch))
- continue;
- if (push)
- uart_insert_char(&up->port, r1, Rx_OVR, ch, flag);
- }
- return push;
- }
- static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
- struct zilog_channel *channel)
- {
- unsigned char status;
- status = readb(&channel->control);
- ZSDELAY();
- writeb(RES_EXT_INT, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- if (up->curregs[R15] & BRKIE) {
- if ((status & BRK_ABRT) && !(up->prev_status & BRK_ABRT)) {
- if (uart_handle_break(&up->port))
- up->tty_break = Rx_SYS;
- else
- up->tty_break = Rx_BRK;
- }
- }
- if (ZS_WANTS_MODEM_STATUS(up)) {
- if (status & SYNC)
- up->port.icount.dsr++;
-
- if ((status ^ up->prev_status) ^ DCD)
- uart_handle_dcd_change(&up->port,
- (status & DCD));
- if ((status ^ up->prev_status) ^ CTS)
- uart_handle_cts_change(&up->port,
- (status & CTS));
- wake_up_interruptible(&up->port.state->port.delta_msr_wait);
- }
- up->prev_status = status;
- }
- static void ip22zilog_transmit_chars(struct uart_ip22zilog_port *up,
- struct zilog_channel *channel)
- {
- struct circ_buf *xmit;
- if (ZS_IS_CONS(up)) {
- unsigned char status = readb(&channel->control);
- ZSDELAY();
-
- if (!(status & Tx_BUF_EMP))
- return;
- }
- up->flags &= ~IP22ZILOG_FLAG_TX_ACTIVE;
- if (ZS_REGS_HELD(up)) {
- __load_zsregs(channel, up->curregs);
- up->flags &= ~IP22ZILOG_FLAG_REGS_HELD;
- }
- if (ZS_TX_STOPPED(up)) {
- up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
- goto ack_tx_int;
- }
- if (up->port.x_char) {
- up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
- writeb(up->port.x_char, &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
- up->port.icount.tx++;
- up->port.x_char = 0;
- return;
- }
- if (up->port.state == NULL)
- goto ack_tx_int;
- xmit = &up->port.state->xmit;
- if (uart_circ_empty(xmit))
- goto ack_tx_int;
- if (uart_tx_stopped(&up->port))
- goto ack_tx_int;
- up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
- writeb(xmit->buf[xmit->tail], &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
- xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
- up->port.icount.tx++;
- if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
- uart_write_wakeup(&up->port);
- return;
- ack_tx_int:
- writeb(RES_Tx_P, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- }
- static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
- {
- struct uart_ip22zilog_port *up = dev_id;
- while (up) {
- struct zilog_channel *channel
- = ZILOG_CHANNEL_FROM_PORT(&up->port);
- unsigned char r3;
- bool push = false;
- spin_lock(&up->port.lock);
- r3 = read_zsreg(channel, R3);
-
- if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
- writeb(RES_H_IUS, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- if (r3 & CHARxIP)
- push = ip22zilog_receive_chars(up, channel);
- if (r3 & CHAEXT)
- ip22zilog_status_handle(up, channel);
- if (r3 & CHATxIP)
- ip22zilog_transmit_chars(up, channel);
- }
- spin_unlock(&up->port.lock);
- if (push)
- tty_flip_buffer_push(&up->port.state->port);
-
- up = up->next;
- channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
- push = false;
- spin_lock(&up->port.lock);
- if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
- writeb(RES_H_IUS, &channel->control);
- ZSDELAY();
- ZS_WSYNC(channel);
- if (r3 & CHBRxIP)
- push = ip22zilog_receive_chars(up, channel);
- if (r3 & CHBEXT)
- ip22zilog_status_handle(up, channel);
- if (r3 & CHBTxIP)
- ip22zilog_transmit_chars(up, channel);
- }
- spin_unlock(&up->port.lock);
- if (push)
- tty_flip_buffer_push(&up->port.state->port);
- up = up->next;
- }
- return IRQ_HANDLED;
- }
- static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
- {
- struct zilog_channel *channel;
- unsigned char status;
- channel = ZILOG_CHANNEL_FROM_PORT(port);
- status = readb(&channel->control);
- ZSDELAY();
- return status;
- }
- static unsigned int ip22zilog_tx_empty(struct uart_port *port)
- {
- unsigned long flags;
- unsigned char status;
- unsigned int ret;
- spin_lock_irqsave(&port->lock, flags);
- status = ip22zilog_read_channel_status(port);
- spin_unlock_irqrestore(&port->lock, flags);
- if (status & Tx_BUF_EMP)
- ret = TIOCSER_TEMT;
- else
- ret = 0;
- return ret;
- }
- static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
- {
- unsigned char status;
- unsigned int ret;
- status = ip22zilog_read_channel_status(port);
- ret = 0;
- if (status & DCD)
- ret |= TIOCM_CAR;
- if (status & SYNC)
- ret |= TIOCM_DSR;
- if (status & CTS)
- ret |= TIOCM_CTS;
- return ret;
- }
- static void ip22zilog_set_mctrl(struct uart_port *port, unsigned int mctrl)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
- unsigned char set_bits, clear_bits;
- set_bits = clear_bits = 0;
- if (mctrl & TIOCM_RTS)
- set_bits |= RTS;
- else
- clear_bits |= RTS;
- if (mctrl & TIOCM_DTR)
- set_bits |= DTR;
- else
- clear_bits |= DTR;
-
- up->curregs[R5] |= set_bits;
- up->curregs[R5] &= ~clear_bits;
- write_zsreg(channel, R5, up->curregs[R5]);
- }
- static void ip22zilog_stop_tx(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- up->flags |= IP22ZILOG_FLAG_TX_STOPPED;
- }
- static void ip22zilog_start_tx(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
- unsigned char status;
- up->flags |= IP22ZILOG_FLAG_TX_ACTIVE;
- up->flags &= ~IP22ZILOG_FLAG_TX_STOPPED;
- status = readb(&channel->control);
- ZSDELAY();
-
- if (!(status & Tx_BUF_EMP))
- return;
-
- if (port->x_char) {
- writeb(port->x_char, &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
- port->icount.tx++;
- port->x_char = 0;
- } else {
- struct circ_buf *xmit = &port->state->xmit;
- if (uart_circ_empty(xmit))
- return;
- writeb(xmit->buf[xmit->tail], &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
- xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
- port->icount.tx++;
- if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
- uart_write_wakeup(&up->port);
- }
- }
- static void ip22zilog_stop_rx(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up = UART_ZILOG(port);
- struct zilog_channel *channel;
- if (ZS_IS_CONS(up))
- return;
- channel = ZILOG_CHANNEL_FROM_PORT(port);
-
- up->curregs[R1] &= ~RxINT_MASK;
- ip22zilog_maybe_update_regs(up, channel);
- }
- static void ip22zilog_enable_ms(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
- unsigned char new_reg;
- new_reg = up->curregs[R15] | (DCDIE | SYNCIE | CTSIE);
- if (new_reg != up->curregs[R15]) {
- up->curregs[R15] = new_reg;
-
- write_zsreg(channel, R15, up->curregs[R15]);
- }
- }
- static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
- unsigned char set_bits, clear_bits, new_reg;
- unsigned long flags;
- set_bits = clear_bits = 0;
- if (break_state)
- set_bits |= SND_BRK;
- else
- clear_bits |= SND_BRK;
- spin_lock_irqsave(&port->lock, flags);
- new_reg = (up->curregs[R5] | set_bits) & ~clear_bits;
- if (new_reg != up->curregs[R5]) {
- up->curregs[R5] = new_reg;
-
- write_zsreg(channel, R5, up->curregs[R5]);
- }
- spin_unlock_irqrestore(&port->lock, flags);
- }
- static void __ip22zilog_reset(struct uart_ip22zilog_port *up)
- {
- struct zilog_channel *channel;
- int i;
- if (up->flags & IP22ZILOG_FLAG_RESET_DONE)
- return;
-
- channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
- for (i = 0; i < 1000; i++) {
- unsigned char stat = read_zsreg(channel, R1);
- if (stat & ALL_SNT)
- break;
- udelay(100);
- }
- if (!ZS_IS_CHANNEL_A(up)) {
- up++;
- channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
- }
- write_zsreg(channel, R9, FHWRES);
- ZSDELAY_LONG();
- (void) read_zsreg(channel, R0);
- up->flags |= IP22ZILOG_FLAG_RESET_DONE;
- up->next->flags |= IP22ZILOG_FLAG_RESET_DONE;
- }
- static void __ip22zilog_startup(struct uart_ip22zilog_port *up)
- {
- struct zilog_channel *channel;
- channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
- __ip22zilog_reset(up);
- __load_zsregs(channel, up->curregs);
-
- write_zsreg(channel, R9, up->curregs[R9]);
- up->prev_status = readb(&channel->control);
-
- up->curregs[R3] |= RxENAB;
- up->curregs[R5] |= TxENAB;
- up->curregs[R1] |= EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
- ip22zilog_maybe_update_regs(up, channel);
- }
- static int ip22zilog_startup(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up = UART_ZILOG(port);
- unsigned long flags;
- if (ZS_IS_CONS(up))
- return 0;
- spin_lock_irqsave(&port->lock, flags);
- __ip22zilog_startup(up);
- spin_unlock_irqrestore(&port->lock, flags);
- return 0;
- }
- static void ip22zilog_shutdown(struct uart_port *port)
- {
- struct uart_ip22zilog_port *up = UART_ZILOG(port);
- struct zilog_channel *channel;
- unsigned long flags;
- if (ZS_IS_CONS(up))
- return;
- spin_lock_irqsave(&port->lock, flags);
- channel = ZILOG_CHANNEL_FROM_PORT(port);
-
- up->curregs[R3] &= ~RxENAB;
- up->curregs[R5] &= ~TxENAB;
-
- up->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
- up->curregs[R5] &= ~SND_BRK;
- ip22zilog_maybe_update_regs(up, channel);
- spin_unlock_irqrestore(&port->lock, flags);
- }
- static void
- ip22zilog_convert_to_zs(struct uart_ip22zilog_port *up, unsigned int cflag,
- unsigned int iflag, int brg)
- {
- up->curregs[R10] = NRZ;
- up->curregs[R11] = TCBR | RCBR;
-
- up->curregs[R4] &= ~XCLK_MASK;
- up->curregs[R4] |= X16CLK;
- up->curregs[R12] = brg & 0xff;
- up->curregs[R13] = (brg >> 8) & 0xff;
- up->curregs[R14] = BRENAB;
-
- up->curregs[3] &= ~RxN_MASK;
- up->curregs[5] &= ~TxN_MASK;
- switch (cflag & CSIZE) {
- case CS5:
- up->curregs[3] |= Rx5;
- up->curregs[5] |= Tx5;
- up->parity_mask = 0x1f;
- break;
- case CS6:
- up->curregs[3] |= Rx6;
- up->curregs[5] |= Tx6;
- up->parity_mask = 0x3f;
- break;
- case CS7:
- up->curregs[3] |= Rx7;
- up->curregs[5] |= Tx7;
- up->parity_mask = 0x7f;
- break;
- case CS8:
- default:
- up->curregs[3] |= Rx8;
- up->curregs[5] |= Tx8;
- up->parity_mask = 0xff;
- break;
- }
- up->curregs[4] &= ~0x0c;
- if (cflag & CSTOPB)
- up->curregs[4] |= SB2;
- else
- up->curregs[4] |= SB1;
- if (cflag & PARENB)
- up->curregs[4] |= PAR_ENAB;
- else
- up->curregs[4] &= ~PAR_ENAB;
- if (!(cflag & PARODD))
- up->curregs[4] |= PAR_EVEN;
- else
- up->curregs[4] &= ~PAR_EVEN;
- up->port.read_status_mask = Rx_OVR;
- if (iflag & INPCK)
- up->port.read_status_mask |= CRC_ERR | PAR_ERR;
- if (iflag & (IGNBRK | BRKINT | PARMRK))
- up->port.read_status_mask |= BRK_ABRT;
- up->port.ignore_status_mask = 0;
- if (iflag & IGNPAR)
- up->port.ignore_status_mask |= CRC_ERR | PAR_ERR;
- if (iflag & IGNBRK) {
- up->port.ignore_status_mask |= BRK_ABRT;
- if (iflag & IGNPAR)
- up->port.ignore_status_mask |= Rx_OVR;
- }
- if ((cflag & CREAD) == 0)
- up->port.ignore_status_mask = 0xff;
- }
- static void
- ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
- struct ktermios *old)
- {
- struct uart_ip22zilog_port *up =
- container_of(port, struct uart_ip22zilog_port, port);
- unsigned long flags;
- int baud, brg;
- baud = uart_get_baud_rate(port, termios, old, 1200, 76800);
- spin_lock_irqsave(&up->port.lock, flags);
- brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
- ip22zilog_convert_to_zs(up, termios->c_cflag, termios->c_iflag, brg);
- if (UART_ENABLE_MS(&up->port, termios->c_cflag))
- up->flags |= IP22ZILOG_FLAG_MODEM_STATUS;
- else
- up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS;
- ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
- uart_update_timeout(port, termios->c_cflag, baud);
- spin_unlock_irqrestore(&up->port.lock, flags);
- }
- static const char *ip22zilog_type(struct uart_port *port)
- {
- return "IP22-Zilog";
- }
- static void ip22zilog_release_port(struct uart_port *port)
- {
- }
- static int ip22zilog_request_port(struct uart_port *port)
- {
- return 0;
- }
- static void ip22zilog_config_port(struct uart_port *port, int flags)
- {
- }
- static int ip22zilog_verify_port(struct uart_port *port, struct serial_struct *ser)
- {
- return -EINVAL;
- }
- static struct uart_ops ip22zilog_pops = {
- .tx_empty = ip22zilog_tx_empty,
- .set_mctrl = ip22zilog_set_mctrl,
- .get_mctrl = ip22zilog_get_mctrl,
- .stop_tx = ip22zilog_stop_tx,
- .start_tx = ip22zilog_start_tx,
- .stop_rx = ip22zilog_stop_rx,
- .enable_ms = ip22zilog_enable_ms,
- .break_ctl = ip22zilog_break_ctl,
- .startup = ip22zilog_startup,
- .shutdown = ip22zilog_shutdown,
- .set_termios = ip22zilog_set_termios,
- .type = ip22zilog_type,
- .release_port = ip22zilog_release_port,
- .request_port = ip22zilog_request_port,
- .config_port = ip22zilog_config_port,
- .verify_port = ip22zilog_verify_port,
- };
- static struct uart_ip22zilog_port *ip22zilog_port_table;
- static struct zilog_layout **ip22zilog_chip_regs;
- static struct uart_ip22zilog_port *ip22zilog_irq_chain;
- static int zilog_irq = -1;
- static void * __init alloc_one_table(unsigned long size)
- {
- return kzalloc(size, GFP_KERNEL);
- }
- static void __init ip22zilog_alloc_tables(void)
- {
- ip22zilog_port_table = (struct uart_ip22zilog_port *)
- alloc_one_table(NUM_CHANNELS * sizeof(struct uart_ip22zilog_port));
- ip22zilog_chip_regs = (struct zilog_layout **)
- alloc_one_table(NUM_IP22ZILOG * sizeof(struct zilog_layout *));
- if (ip22zilog_port_table == NULL || ip22zilog_chip_regs == NULL) {
- panic("IP22-Zilog: Cannot allocate IP22-Zilog tables.");
- }
- }
- static struct zilog_layout * __init get_zs(int chip)
- {
- unsigned long base;
- if (chip < 0 || chip >= NUM_IP22ZILOG) {
- panic("IP22-Zilog: Illegal chip number %d in get_zs.", chip);
- }
-
- base = (unsigned long) &sgioc->uart;
- zilog_irq = SGI_SERIAL_IRQ;
- request_mem_region(base, 8, "IP22-Zilog");
- return (struct zilog_layout *) base;
- }
- #define ZS_PUT_CHAR_MAX_DELAY 2000
- #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
- static void ip22zilog_put_char(struct uart_port *port, int ch)
- {
- struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(port);
- int loops = ZS_PUT_CHAR_MAX_DELAY;
-
- do {
- unsigned char val = readb(&channel->control);
- if (val & Tx_BUF_EMP) {
- ZSDELAY();
- break;
- }
- udelay(5);
- } while (--loops);
- writeb(ch, &channel->data);
- ZSDELAY();
- ZS_WSYNC(channel);
- }
- static void
- ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
- {
- struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
- unsigned long flags;
- spin_lock_irqsave(&up->port.lock, flags);
- uart_console_write(&up->port, s, count, ip22zilog_put_char);
- udelay(2);
- spin_unlock_irqrestore(&up->port.lock, flags);
- }
- static int __init ip22zilog_console_setup(struct console *con, char *options)
- {
- struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
- unsigned long flags;
- int baud = 9600, bits = 8;
- int parity = 'n';
- int flow = 'n';
- up->flags |= IP22ZILOG_FLAG_IS_CONS;
- printk(KERN_INFO "Console: ttyS%d (IP22-Zilog)\n", con->index);
- spin_lock_irqsave(&up->port.lock, flags);
- up->curregs[R15] |= BRKIE;
- __ip22zilog_startup(up);
- spin_unlock_irqrestore(&up->port.lock, flags);
- if (options)
- uart_parse_options(options, &baud, &parity, &bits, &flow);
- return uart_set_options(&up->port, con, baud, parity, bits, flow);
- }
- static struct uart_driver ip22zilog_reg;
- static struct console ip22zilog_console = {
- .name = "ttyS",
- .write = ip22zilog_console_write,
- .device = uart_console_device,
- .setup = ip22zilog_console_setup,
- .flags = CON_PRINTBUFFER,
- .index = -1,
- .data = &ip22zilog_reg,
- };
- #endif
- static struct uart_driver ip22zilog_reg = {
- .owner = THIS_MODULE,
- .driver_name = "serial",
- .dev_name = "ttyS",
- .major = TTY_MAJOR,
- .minor = 64,
- .nr = NUM_CHANNELS,
- #ifdef CONFIG_SERIAL_IP22_ZILOG_CONSOLE
- .cons = &ip22zilog_console,
- #endif
- };
- static void __init ip22zilog_prepare(void)
- {
- struct uart_ip22zilog_port *up;
- struct zilog_layout *rp;
- int channel, chip;
-
- for (channel = 0; channel < NUM_CHANNELS; channel++)
- spin_lock_init(&ip22zilog_port_table[channel].port.lock);
- ip22zilog_irq_chain = &ip22zilog_port_table[NUM_CHANNELS - 1];
- up = &ip22zilog_port_table[0];
- for (channel = NUM_CHANNELS - 1 ; channel > 0; channel--)
- up[channel].next = &up[channel - 1];
- up[channel].next = NULL;
- for (chip = 0; chip < NUM_IP22ZILOG; chip++) {
- if (!ip22zilog_chip_regs[chip]) {
- ip22zilog_chip_regs[chip] = rp = get_zs(chip);
- up[(chip * 2) + 0].port.membase = (char *) &rp->channelB;
- up[(chip * 2) + 1].port.membase = (char *) &rp->channelA;
-
- up[(chip * 2) + 0].port.mapbase =
- (unsigned long) ioremap((unsigned long) &rp->channelB, 8);
- up[(chip * 2) + 1].port.mapbase =
- (unsigned long) ioremap((unsigned long) &rp->channelA, 8);
- }
-
- up[(chip * 2) + 0].port.iotype = UPIO_MEM;
- up[(chip * 2) + 0].port.irq = zilog_irq;
- up[(chip * 2) + 0].port.uartclk = ZS_CLOCK;
- up[(chip * 2) + 0].port.fifosize = 1;
- up[(chip * 2) + 0].port.ops = &ip22zilog_pops;
- up[(chip * 2) + 0].port.type = PORT_IP22ZILOG;
- up[(chip * 2) + 0].port.flags = 0;
- up[(chip * 2) + 0].port.line = (chip * 2) + 0;
- up[(chip * 2) + 0].flags = 0;
-
- up[(chip * 2) + 1].port.iotype = UPIO_MEM;
- up[(chip * 2) + 1].port.irq = zilog_irq;
- up[(chip * 2) + 1].port.uartclk = ZS_CLOCK;
- up[(chip * 2) + 1].port.fifosize = 1;
- up[(chip * 2) + 1].port.ops = &ip22zilog_pops;
- up[(chip * 2) + 1].port.type = PORT_IP22ZILOG;
- up[(chip * 2) + 1].port.line = (chip * 2) + 1;
- up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
- }
- for (channel = 0; channel < NUM_CHANNELS; channel++) {
- struct uart_ip22zilog_port *up = &ip22zilog_port_table[channel];
- int brg;
-
- up->parity_mask = 0xff;
- up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
- up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
- up->curregs[R3] = RxENAB | Rx8;
- up->curregs[R5] = TxENAB | Tx8;
- up->curregs[R9] = NV | MIE;
- up->curregs[R10] = NRZ;
- up->curregs[R11] = TCBR | RCBR;
- brg = BPS_TO_BRG(9600, ZS_CLOCK / ZS_CLOCK_DIVISOR);
- up->curregs[R12] = (brg & 0xff);
- up->curregs[R13] = (brg >> 8) & 0xff;
- up->curregs[R14] = BRENAB;
- }
- }
- static int __init ip22zilog_ports_init(void)
- {
- int ret;
- printk(KERN_INFO "Serial: IP22 Zilog driver (%d chips).\n", NUM_IP22ZILOG);
- ip22zilog_prepare();
- if (request_irq(zilog_irq, ip22zilog_interrupt, 0,
- "IP22-Zilog", ip22zilog_irq_chain)) {
- panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
- }
- ret = uart_register_driver(&ip22zilog_reg);
- if (ret == 0) {
- int i;
- for (i = 0; i < NUM_CHANNELS; i++) {
- struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
- uart_add_one_port(&ip22zilog_reg, &up->port);
- }
- }
- return ret;
- }
- static int __init ip22zilog_init(void)
- {
-
- ip22zilog_alloc_tables();
- ip22zilog_ports_init();
- return 0;
- }
- static void __exit ip22zilog_exit(void)
- {
- int i;
- struct uart_ip22zilog_port *up;
- for (i = 0; i < NUM_CHANNELS; i++) {
- up = &ip22zilog_port_table[i];
- uart_remove_one_port(&ip22zilog_reg, &up->port);
- }
-
- up = &ip22zilog_port_table[0];
- for (i = 0; i < NUM_IP22ZILOG; i++) {
- if (up[(i * 2) + 0].port.mapbase) {
- iounmap((void*)up[(i * 2) + 0].port.mapbase);
- up[(i * 2) + 0].port.mapbase = 0;
- }
- if (up[(i * 2) + 1].port.mapbase) {
- iounmap((void*)up[(i * 2) + 1].port.mapbase);
- up[(i * 2) + 1].port.mapbase = 0;
- }
- }
- uart_unregister_driver(&ip22zilog_reg);
- }
- module_init(ip22zilog_init);
- module_exit(ip22zilog_exit);
- MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
- MODULE_DESCRIPTION("SGI Zilog serial port driver");
- MODULE_LICENSE("GPL");
|