15 #include <linux/errno.h>
16 #include <linux/tty.h>
18 #include <linux/serial.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
24 #include <linux/serial_core.h>
25 #include <linux/slab.h>
31 #define IOC4_NUM_SERIAL_PORTS 4
32 #define IOC4_NUM_CARDS 8
34 #define GET_SIO_IR(_n) (_n == 0) ? (IOC4_SIO_IR_S0) : \
35 (_n == 1) ? (IOC4_SIO_IR_S1) : \
36 (_n == 2) ? (IOC4_SIO_IR_S2) : \
39 #define GET_OTHER_IR(_n) (_n == 0) ? (IOC4_OTHER_IR_S0_MEMERR) : \
40 (_n == 1) ? (IOC4_OTHER_IR_S1_MEMERR) : \
41 (_n == 2) ? (IOC4_OTHER_IR_S2_MEMERR) : \
42 (IOC4_OTHER_IR_S3_MEMERR)
52 #define IOC4_PCI_ERR_ADDR_L 0x000
53 #define IOC4_PCI_ERR_ADDR_VLD (0x1 << 0)
54 #define IOC4_PCI_ERR_ADDR_MST_ID_MSK (0xf << 1)
55 #define IOC4_PCI_ERR_ADDR_MST_NUM_MSK (0xe << 1)
56 #define IOC4_PCI_ERR_ADDR_MST_TYP_MSK (0x1 << 1)
57 #define IOC4_PCI_ERR_ADDR_MUL_ERR (0x1 << 5)
58 #define IOC4_PCI_ERR_ADDR_ADDR_MSK (0x3ffffff << 6)
61 #define IOC4_SIO_INTR_TYPE 0
62 #define IOC4_OTHER_INTR_TYPE 1
63 #define IOC4_NUM_INTR_TYPES 2
66 #define IOC4_SIO_IR_S0_TX_MT 0x00000001
67 #define IOC4_SIO_IR_S0_RX_FULL 0x00000002
68 #define IOC4_SIO_IR_S0_RX_HIGH 0x00000004
69 #define IOC4_SIO_IR_S0_RX_TIMER 0x00000008
70 #define IOC4_SIO_IR_S0_DELTA_DCD 0x00000010
71 #define IOC4_SIO_IR_S0_DELTA_CTS 0x00000020
72 #define IOC4_SIO_IR_S0_INT 0x00000040
73 #define IOC4_SIO_IR_S0_TX_EXPLICIT 0x00000080
74 #define IOC4_SIO_IR_S1_TX_MT 0x00000100
75 #define IOC4_SIO_IR_S1_RX_FULL 0x00000200
76 #define IOC4_SIO_IR_S1_RX_HIGH 0x00000400
77 #define IOC4_SIO_IR_S1_RX_TIMER 0x00000800
78 #define IOC4_SIO_IR_S1_DELTA_DCD 0x00001000
79 #define IOC4_SIO_IR_S1_DELTA_CTS 0x00002000
80 #define IOC4_SIO_IR_S1_INT 0x00004000
81 #define IOC4_SIO_IR_S1_TX_EXPLICIT 0x00008000
82 #define IOC4_SIO_IR_S2_TX_MT 0x00010000
83 #define IOC4_SIO_IR_S2_RX_FULL 0x00020000
84 #define IOC4_SIO_IR_S2_RX_HIGH 0x00040000
85 #define IOC4_SIO_IR_S2_RX_TIMER 0x00080000
86 #define IOC4_SIO_IR_S2_DELTA_DCD 0x00100000
87 #define IOC4_SIO_IR_S2_DELTA_CTS 0x00200000
88 #define IOC4_SIO_IR_S2_INT 0x00400000
89 #define IOC4_SIO_IR_S2_TX_EXPLICIT 0x00800000
90 #define IOC4_SIO_IR_S3_TX_MT 0x01000000
91 #define IOC4_SIO_IR_S3_RX_FULL 0x02000000
92 #define IOC4_SIO_IR_S3_RX_HIGH 0x04000000
93 #define IOC4_SIO_IR_S3_RX_TIMER 0x08000000
94 #define IOC4_SIO_IR_S3_DELTA_DCD 0x10000000
95 #define IOC4_SIO_IR_S3_DELTA_CTS 0x20000000
96 #define IOC4_SIO_IR_S3_INT 0x40000000
97 #define IOC4_SIO_IR_S3_TX_EXPLICIT 0x80000000
100 #define IOC4_SIO_IR_S0 (IOC4_SIO_IR_S0_TX_MT | \
101 IOC4_SIO_IR_S0_RX_FULL | \
102 IOC4_SIO_IR_S0_RX_HIGH | \
103 IOC4_SIO_IR_S0_RX_TIMER | \
104 IOC4_SIO_IR_S0_DELTA_DCD | \
105 IOC4_SIO_IR_S0_DELTA_CTS | \
106 IOC4_SIO_IR_S0_INT | \
107 IOC4_SIO_IR_S0_TX_EXPLICIT)
108 #define IOC4_SIO_IR_S1 (IOC4_SIO_IR_S1_TX_MT | \
109 IOC4_SIO_IR_S1_RX_FULL | \
110 IOC4_SIO_IR_S1_RX_HIGH | \
111 IOC4_SIO_IR_S1_RX_TIMER | \
112 IOC4_SIO_IR_S1_DELTA_DCD | \
113 IOC4_SIO_IR_S1_DELTA_CTS | \
114 IOC4_SIO_IR_S1_INT | \
115 IOC4_SIO_IR_S1_TX_EXPLICIT)
116 #define IOC4_SIO_IR_S2 (IOC4_SIO_IR_S2_TX_MT | \
117 IOC4_SIO_IR_S2_RX_FULL | \
118 IOC4_SIO_IR_S2_RX_HIGH | \
119 IOC4_SIO_IR_S2_RX_TIMER | \
120 IOC4_SIO_IR_S2_DELTA_DCD | \
121 IOC4_SIO_IR_S2_DELTA_CTS | \
122 IOC4_SIO_IR_S2_INT | \
123 IOC4_SIO_IR_S2_TX_EXPLICIT)
124 #define IOC4_SIO_IR_S3 (IOC4_SIO_IR_S3_TX_MT | \
125 IOC4_SIO_IR_S3_RX_FULL | \
126 IOC4_SIO_IR_S3_RX_HIGH | \
127 IOC4_SIO_IR_S3_RX_TIMER | \
128 IOC4_SIO_IR_S3_DELTA_DCD | \
129 IOC4_SIO_IR_S3_DELTA_CTS | \
130 IOC4_SIO_IR_S3_INT | \
131 IOC4_SIO_IR_S3_TX_EXPLICIT)
134 #define IOC4_OTHER_IR_ATA_INT 0x00000001
135 #define IOC4_OTHER_IR_ATA_MEMERR 0x00000002
136 #define IOC4_OTHER_IR_S0_MEMERR 0x00000004
137 #define IOC4_OTHER_IR_S1_MEMERR 0x00000008
138 #define IOC4_OTHER_IR_S2_MEMERR 0x00000010
139 #define IOC4_OTHER_IR_S3_MEMERR 0x00000020
140 #define IOC4_OTHER_IR_KBD_INT 0x00000040
141 #define IOC4_OTHER_IR_RESERVED 0x007fff80
142 #define IOC4_OTHER_IR_RT_INT 0x00800000
143 #define IOC4_OTHER_IR_GEN_INT 0xff000000
145 #define IOC4_OTHER_IR_SER_MEMERR (IOC4_OTHER_IR_S0_MEMERR | IOC4_OTHER_IR_S1_MEMERR | \
146 IOC4_OTHER_IR_S2_MEMERR | IOC4_OTHER_IR_S3_MEMERR)
149 #define IOC4_SIO_CR_CMD_PULSE_SHIFT 0
150 #define IOC4_SIO_CR_ARB_DIAG_TX0 0x00000000
151 #define IOC4_SIO_CR_ARB_DIAG_RX0 0x00000010
152 #define IOC4_SIO_CR_ARB_DIAG_TX1 0x00000020
153 #define IOC4_SIO_CR_ARB_DIAG_RX1 0x00000030
154 #define IOC4_SIO_CR_ARB_DIAG_TX2 0x00000040
155 #define IOC4_SIO_CR_ARB_DIAG_RX2 0x00000050
156 #define IOC4_SIO_CR_ARB_DIAG_TX3 0x00000060
157 #define IOC4_SIO_CR_ARB_DIAG_RX3 0x00000070
158 #define IOC4_SIO_CR_SIO_DIAG_IDLE 0x00000080
161 #define IOC4_GPCR_UART0_MODESEL 0x10
163 #define IOC4_GPCR_UART1_MODESEL 0x20
165 #define IOC4_GPCR_UART2_MODESEL 0x40
167 #define IOC4_GPCR_UART3_MODESEL 0x80
170 #define IOC4_GPPR_UART0_MODESEL_PIN 4
172 #define IOC4_GPPR_UART1_MODESEL_PIN 5
174 #define IOC4_GPPR_UART2_MODESEL_PIN 6
176 #define IOC4_GPPR_UART3_MODESEL_PIN 7
180 #define IOC4_RXSB_OVERRUN 0x01
181 #define IOC4_RXSB_PAR_ERR 0x02
182 #define IOC4_RXSB_FRAME_ERR 0x04
183 #define IOC4_RXSB_BREAK 0x08
184 #define IOC4_RXSB_CTS 0x10
185 #define IOC4_RXSB_DCD 0x20
186 #define IOC4_RXSB_MODEM_VALID 0x40
187 #define IOC4_RXSB_DATA_VALID 0x80
191 #define IOC4_TXCB_INT_WHEN_DONE 0x20
192 #define IOC4_TXCB_INVALID 0x00
193 #define IOC4_TXCB_VALID 0x40
194 #define IOC4_TXCB_MCR 0x80
195 #define IOC4_TXCB_DELAY 0xc0
198 #define IOC4_SBBR_L_SIZE 0x00000001
201 #define IOC4_SSCR_RX_THRESHOLD 0x000001ff
202 #define IOC4_SSCR_TX_TIMER_BUSY 0x00010000
203 #define IOC4_SSCR_HFC_EN 0x00020000
204 #define IOC4_SSCR_RX_RING_DCD 0x00040000
205 #define IOC4_SSCR_RX_RING_CTS 0x00080000
206 #define IOC4_SSCR_DIAG 0x00200000
207 #define IOC4_SSCR_RX_DRAIN 0x08000000
208 #define IOC4_SSCR_DMA_EN 0x10000000
209 #define IOC4_SSCR_DMA_PAUSE 0x20000000
210 #define IOC4_SSCR_PAUSE_STATE 0x40000000
211 #define IOC4_SSCR_RESET 0x80000000
214 #define IOC4_PROD_CONS_PTR_4K 0x00000ff8
215 #define IOC4_PROD_CONS_PTR_1K 0x000003f8
216 #define IOC4_PROD_CONS_PTR_OFF 3
219 #define IOC4_SRCIR_ARM 0x80000000
222 #define IOC4_SHADOW_DR 0x00000001
223 #define IOC4_SHADOW_OE 0x00000002
224 #define IOC4_SHADOW_PE 0x00000004
225 #define IOC4_SHADOW_FE 0x00000008
226 #define IOC4_SHADOW_BI 0x00000010
227 #define IOC4_SHADOW_THRE 0x00000020
228 #define IOC4_SHADOW_TEMT 0x00000040
229 #define IOC4_SHADOW_RFCE 0x00000080
230 #define IOC4_SHADOW_DCTS 0x00010000
231 #define IOC4_SHADOW_DDCD 0x00080000
232 #define IOC4_SHADOW_CTS 0x00100000
233 #define IOC4_SHADOW_DCD 0x00800000
234 #define IOC4_SHADOW_DTR 0x01000000
235 #define IOC4_SHADOW_RTS 0x02000000
236 #define IOC4_SHADOW_OUT1 0x04000000
237 #define IOC4_SHADOW_OUT2 0x08000000
238 #define IOC4_SHADOW_LOOP 0x10000000
241 #define IOC4_SRTR_CNT 0x00000fff
242 #define IOC4_SRTR_CNT_VAL 0x0fff0000
243 #define IOC4_SRTR_CNT_VAL_SHIFT 16
244 #define IOC4_SRTR_HZ 16000
280 #define i4u_dll u1.dll
281 #define i4u_ier u2.ier
282 #define i4u_dlm u2.dlm
283 #define i4u_fcr u3.fcr
303 #define IOC4_SER_XIN_CLK_66 66666667
304 #define IOC4_SER_XIN_CLK_33 33333333
312 static unsigned int Num_of_ioc4_cards;
316 #define DPRINT_CONFIG(_x...) ;
320 #define WAKEUP_CHARS 256
323 #define IOC4_MAX_CHARS 256
324 #define IOC4_FIFO_CHARS 255
327 #define DEVICE_NAME_RS232 "ttyIOC"
328 #define DEVICE_NAME_RS422 "ttyAIOC"
329 #define DEVICE_MAJOR 204
330 #define DEVICE_MINOR_RS232 50
331 #define DEVICE_MINOR_RS422 84
335 #define IOC4_SERIAL_OFFSET 0x300
338 #define NCS_BREAK 0x1
339 #define NCS_PARITY 0x2
340 #define NCS_FRAMING 0x4
341 #define NCS_OVERRUN 0x8
344 #define MIN_BAUD_SUPPORTED 1200
345 #define MAX_BAUD_SUPPORTED 115200
348 #define PROTO_RS232 3
349 #define PROTO_RS422 7
352 #define N_DATA_READY 0x01
353 #define N_OUTPUT_LOWAT 0x02
355 #define N_PARITY_ERROR 0x08
356 #define N_FRAMING_ERROR 0x10
357 #define N_OVERRUN_ERROR 0x20
361 #define N_ALL_INPUT (N_DATA_READY | N_BREAK | \
362 N_PARITY_ERROR | N_FRAMING_ERROR | \
363 N_OVERRUN_ERROR | N_DDCD | N_DCTS)
365 #define N_ALL_OUTPUT N_OUTPUT_LOWAT
367 #define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR | N_OVERRUN_ERROR)
369 #define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK | \
370 N_PARITY_ERROR | N_FRAMING_ERROR | \
371 N_OVERRUN_ERROR | N_DDCD | N_DCTS)
373 #define SER_DIVISOR(_x, clk) (((clk) + (_x) * 8) / ((_x) * 16))
374 #define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div))
377 #define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \
378 | UART_LCR_WLEN7 | UART_LCR_WLEN8)
379 #define LCR_MASK_STOP_BITS (UART_LCR_STOP)
381 #define PENDING(_p) (readl(&(_p)->ip_mem->sio_ir.raw) & _p->ip_ienb)
382 #define READ_SIO_IR(_p) readl(&(_p)->ip_mem->sio_ir.raw)
385 #ifdef IOC4_1K_BUFFERS
386 #define RING_BUF_SIZE 1024
387 #define IOC4_BUF_SIZE_BIT 0
388 #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_1K
390 #define RING_BUF_SIZE 4096
391 #define IOC4_BUF_SIZE_BIT IOC4_SBBR_L_SIZE
392 #define PROD_CONS_MASK IOC4_PROD_CONS_PTR_4K
395 #define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4)
401 #define UART_PORT_MIN 0
402 #define UART_PORT_RS232 UART_PORT_MIN
403 #define UART_PORT_RS422 1
404 #define UART_PORT_COUNT 2
420 #define MAX_IOC4_INTR_ENTS (8 * sizeof(uint32_t))
506 #define TX_LOWAT_LATENCY 1000
507 #define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY)
508 #define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ)
511 #define INPUT_HIGH 0x01
513 #define LOWAT_WRITTEN 0x04
514 #define READ_ABORTED 0x08
515 #define PORT_ACTIVE 0x10
516 #define PORT_INACTIVE 0
544 IOC4_SIO_IR_S0_RX_HIGH | IOC4_SIO_IR_S0_RX_TIMER |
557 IOC4_SIO_IR_S1_RX_HIGH | IOC4_SIO_IR_S1_RX_TIMER |
570 IOC4_SIO_IR_S2_RX_HIGH | IOC4_SIO_IR_S2_RX_TIMER |
583 IOC4_SIO_IR_S3_RX_HIGH | IOC4_SIO_IR_S3_RX_TIMER |
605 #define RING_ANY_VALID \
606 ((uint32_t)(IOC4_RXSB_MODEM_VALID | IOC4_RXSB_DATA_VALID) * 0x01010101)
608 #define ring_sc u.s.sc
609 #define ring_data u.s.data
610 #define ring_allsc u.all.allsc
613 #define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry))
622 struct ring TX_0_OR_2;
629 #define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh)
633 #define MAXITER 10000000
636 static void receive_chars(
struct uart_port *);
637 static void handle_intr(
void *
arg,
uint32_t sio_ir);
649 && (port->
ip_port == uart_port))
699 spin_unlock_irqrestore(&ioc4_soft->
is_ir_lock, flags);
720 diff = actual_baud -
baud;
725 if (diff * 100 > actual_baud)
731 writeb((
unsigned char)divisor, &uart->i4u_dll);
732 writeb((
unsigned char)(divisor >> 8), &uart->i4u_dlm);
743 static struct ioc4_port *get_ioc4_port(
struct uart_port *the_port,
int set)
792 pending_intrs(
struct ioc4_soft *
soft,
int type)
818 spin_unlock_irqrestore(&soft->
is_ir_lock, flag);
855 writeb(0, &uart->i4u_ier);
877 if (port->
ip_hooks == &hooks_array[0]
878 || port->
ip_hooks == &hooks_array[2]) {
879 unsigned long ring_pci_addr;
883 if (port->
ip_hooks == &hooks_array[0]) {
893 __func__, ring_pci_addr));
921 static void handle_dma_error_intr(
void *
arg,
uint32_t other_ir)
924 struct hooks *hooks = port->
ip_hooks;
934 "PCI error address is 0x%llx, "
935 "master is serial port %c %s\n",
949 "Multiple errors occurred\n");
952 spin_unlock_irqrestore(&port->
ip_lock, flags);
968 intr_connect(
struct ioc4_soft *soft,
int type,
972 struct ioc4_intr_info *intr_ptr;
982 intr_ptr->sd_bits = intrbits;
983 intr_ptr->sd_intr =
intr;
984 intr_ptr->sd_info =
info;
995 struct ioc4_soft *
soft;
997 int xx, num_intrs = 0;
1007 this_mir = this_ir = pending_intrs(soft, intr_type);
1012 for (xx = 0; xx < num_intrs; xx++) {
1014 if ((this_mir = this_ir & intr_info->sd_bits)) {
1017 write_ireg(soft, intr_info->sd_bits,
IOC4_W_IEC,
1019 intr_info->sd_intr(intr_info->sd_info, this_mir);
1020 this_ir &= ~this_mir;
1024 #ifdef DEBUG_INTERRUPTS
1030 printk (
"%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x "
1031 "other_ir 0x%x other_ies 0x%x mask 0x%x\n",
1038 spin_unlock_irqrestore(&soft->
is_ir_lock, flag);
1059 struct ioc4_soft *soft = control->
ic_soft;
1067 if (ioc4_revid < ioc4_revid_min) {
1069 "IOC4 serial not supported on firmware rev %d, "
1070 "please upgrade to rev %d or higher\n",
1071 ioc4_revid, ioc4_revid_min);
1083 "IOC4 serial memory not available for port\n");
1109 port->
ip_mem = ioc4_misc;
1118 switch (port_number) {
1139 if (port_number && (port_number & 1)) {
1158 "ip_dma_ringbuf 0x%p\n",
1167 port_number, (
void *)port, (
void *)control));
1178 port_number, (
void *)port,
1189 handle_dma_error_intr, port);
1201 struct hooks *hooks = port->
ip_hooks;
1203 if ((port->
ip_ienb & mask) != mask) {
1218 static inline int local_open(
struct ioc4_port *port)
1268 static inline int set_rx_timeout(
struct ioc4_port *port,
int timeout)
1281 threshold = timeout * port->
ip_baud / 4000;
1288 port->
ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD;
1315 int baud,
int byte_size,
int stop_bits,
int parenb,
int parodd)
1320 DPRINT_CONFIG((
"%s: baud %d byte_size %d stop %d parenb %d parodd %d\n",
1321 __func__, baud, byte_size, stop_bits, parenb, parodd));
1323 if (set_baud(port, baud))
1326 switch (byte_size) {
1390 set_rx_timeout(port, 2);
1404 int prod_ptr, cons_ptr, total = 0;
1405 struct ring *outring;
1407 struct hooks *hooks = port->
ip_hooks;
1422 while ((prod_ptr != cons_ptr) && (len > 0)) {
1429 entry->ring_allsc = 0;
1432 for (xx = 0; (xx < 4) && (len > 0); xx++) {
1433 entry->ring_data[
xx] = *buf++;
1467 if (!uart_tx_stopped(port->
ip_port)) {
1487 struct hooks *hooks = port->
ip_hooks;
1506 static int set_notification(
struct ioc4_port *port,
int mask,
int set_on)
1508 struct hooks *hooks = port->
ip_hooks;
1513 intrbits = sscrbits = 0;
1527 enable_intrs(port, intrbits);
1531 disable_intrs(port, intrbits);
1540 if (port->
ip_notify & (N_DATA_READY | N_DDCD))
1555 static inline int set_mcr(
struct uart_port *the_port,
1556 int mask1,
int mask2)
1558 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1578 mcr = (shadow & 0xff000000) >> 24;
1601 struct hooks *hooks = port->
ip_hooks;
1624 static void transmit_chars(
struct uart_port *the_port)
1630 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1638 state = the_port->
state;
1639 tty = state->
port.tty;
1647 head = state->
xmit.head;
1648 tail = state->
xmit.tail;
1649 start = (
char *)&state->
xmit.buf[tail];
1653 if (xmit_count > 0) {
1654 result =
do_write(port, start, xmit_count);
1663 start = (
char *)&state->
xmit.buf[tail];
1670 set_notification(port, N_OUTPUT_LOWAT, 0);
1672 set_notification(port, N_OUTPUT_LOWAT, 1);
1683 ioc4_change_speed(
struct uart_port *the_port,
1686 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1688 unsigned cflag, iflag;
1689 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
1695 switch (cflag &
CSIZE) {
1724 new_parity_enable = 1;
1743 state->
port.tty->low_latency = 1;
1753 if (!(cflag &
CREAD)) {
1768 "config_port(baud %d data %d stop %d p enable %d parity %d),"
1769 " notification 0x%x\n",
1770 __func__, (
void *)port, cflag, baud, new_data, new_stop,
1773 if ((config_port(port, baud,
1777 new_parity)) >= 0) {
1786 static inline int ic4_startup_local(
struct uart_port *the_port)
1794 port = get_ioc4_port(the_port, 0);
1798 state = the_port->
state;
1803 ioc4_set_proto(port, the_port->
mapbase);
1806 ioc4_change_speed(the_port, &state->
port.tty->termios,
1816 static void ioc4_cb_output_lowat(
struct uart_port *the_port)
1818 unsigned long pflags;
1823 transmit_chars(the_port);
1824 spin_unlock_irqrestore(&the_port->
lock, pflags);
1834 static void handle_intr(
void *arg,
uint32_t sio_ir)
1837 struct hooks *hooks = port->
ip_hooks;
1838 unsigned int rx_high_rd_aborted = 0;
1839 unsigned long flags;
1840 struct uart_port *the_port;
1866 if ( loop_counter-- <= 0 ) {
1868 "possible hang condition/"
1869 "port stuck on interrupt.\n");
1877 &port->
ip_mem->sio_ir.raw);
1885 the_port->
icount.dcd = 1;
1887 (&the_port->
state->port.delta_msr_wait);
1889 && !(shadow & IOC4_SHADOW_DCD)) {
1899 &port->
ip_mem->sio_ir.raw);
1909 (&the_port->
state->port.delta_msr_wait);
1920 &port->
ip_mem->sio_ir.raw);
1952 rx_high_rd_aborted++;
1966 &port->
ip_mem->sio_ir.raw);
1969 ioc4_cb_output_lowat(port->
ip_port);
1982 ioc4_cb_output_lowat(port->
ip_port);
2002 & (N_DATA_READY | N_DDCD))) {
2020 if (rx_high_rd_aborted && (sio_ir == hooks->
intr_rx_high)) {
2023 }
while (sio_ir & hooks->
intr_all);
2025 spin_unlock_irqrestore(&port->
ip_lock, flags);
2041 static void ioc4_cb_post_ncs(
struct uart_port *the_port,
int ncs)
2045 icount = &the_port->
icount;
2065 static inline int do_read(
struct uart_port *the_port,
unsigned char *buf,
2068 int prod_ptr, cons_ptr, total;
2069 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2070 struct ring *inring;
2072 struct hooks *hooks;
2107 if (prod_ptr == cons_ptr) {
2136 if (prod_ptr == cons_ptr) {
2160 loop_counter = 0xfffff;
2163 while ((prod_ptr != cons_ptr) && (len > 0)) {
2166 if ( loop_counter-- <= 0 ) {
2168 "possible hang condition/"
2169 "port stuck on read.\n");
2189 for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) {
2190 sc = &(entry->ring_sc[byte_num]);
2217 *sc &= ~IOC4_RXSB_MODEM_VALID;
2229 cons_ptr += (
int)
sizeof
2240 the_port->
icount.dcd = 0;
2243 port.delta_msr_wait);
2252 if (*sc & IOC4_RXSB_MODEM_VALID) {
2256 ioc4_cb_post_ncs(the_port, NCS_OVERRUN);
2259 *sc &= ~IOC4_RXSB_MODEM_VALID;
2283 ioc4_cb_post_ncs(the_port,
2288 ioc4_cb_post_ncs(the_port,
2300 if (*sc & IOC4_RXSB_DATA_VALID) {
2301 *sc &= ~IOC4_RXSB_DATA_VALID;
2302 *buf = entry->ring_data[byte_num];
2328 & PROD_CONS_MASK) < ((port->
ip_sscr &
2329 IOC4_SSCR_RX_THRESHOLD)
2341 static void receive_chars(
struct uart_port *the_port)
2348 unsigned long pflags;
2353 if (!state->
port.tty)
2357 tty = state->
port.tty;
2361 if (request_count > 0) {
2362 icount = &the_port->
icount;
2363 read_count =
do_read(the_port, ch, request_count);
2364 if (read_count > 0) {
2365 tty_insert_flip_string(tty, ch, read_count);
2366 icount->
rx += read_count;
2370 spin_unlock_irqrestore(&the_port->
lock, pflags);
2380 static const char *ic4_type(
struct uart_port *the_port)
2383 return "SGI IOC4 Serial [rs232]";
2385 return "SGI IOC4 Serial [rs422]";
2393 static unsigned int ic4_tx_empty(
struct uart_port *the_port)
2395 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2396 unsigned int ret = 0;
2398 if (port_is_active(port, the_port)) {
2410 static void ic4_stop_tx(
struct uart_port *the_port)
2412 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2414 if (port_is_active(port, the_port))
2415 set_notification(port, N_OUTPUT_LOWAT, 0);
2423 static void null_void_function(
struct uart_port *the_port)
2432 static void ic4_shutdown(
struct uart_port *the_port)
2434 unsigned long port_flags;
2438 port = get_ioc4_port(the_port, 0);
2442 state = the_port->
state;
2447 if (state->
port.tty)
2451 set_notification(port,
N_ALL, 0);
2453 spin_unlock_irqrestore(&the_port->
lock, port_flags);
2462 static void ic4_set_mctrl(
struct uart_port *the_port,
unsigned int mctrl)
2464 unsigned char mcr = 0;
2467 port = get_ioc4_port(the_port, 0);
2468 if (!port_is_active(port, the_port))
2490 static unsigned int ic4_get_mctrl(
struct uart_port *the_port)
2492 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2494 unsigned int ret = 0;
2496 if (!port_is_active(port, the_port))
2500 if (shadow & IOC4_SHADOW_DCD)
2514 static void ic4_start_tx(
struct uart_port *the_port)
2516 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2518 if (port_is_active(port, the_port)) {
2519 set_notification(port, N_OUTPUT_LOWAT, 1);
2520 enable_intrs(port, port->
ip_hooks->intr_tx_mt);
2530 static void ic4_break_ctl(
struct uart_port *the_port,
int break_state)
2539 static int ic4_startup(
struct uart_port *the_port)
2545 unsigned long port_flags;
2549 port = get_ioc4_port(the_port, 1);
2552 state = the_port->
state;
2562 retval = ic4_startup_local(the_port);
2563 spin_unlock_irqrestore(&the_port->
lock, port_flags);
2575 ic4_set_termios(
struct uart_port *the_port,
2578 unsigned long port_flags;
2581 ioc4_change_speed(the_port, termios, old_termios);
2582 spin_unlock_irqrestore(&the_port->
lock, port_flags);
2590 static int ic4_request_port(
struct uart_port *port)
2597 static struct uart_ops ioc4_ops = {
2598 .tx_empty = ic4_tx_empty,
2599 .set_mctrl = ic4_set_mctrl,
2600 .get_mctrl = ic4_get_mctrl,
2601 .stop_tx = ic4_stop_tx,
2602 .start_tx = ic4_start_tx,
2603 .stop_rx = null_void_function,
2604 .enable_ms = null_void_function,
2605 .break_ctl = ic4_break_ctl,
2606 .startup = ic4_startup,
2607 .shutdown = ic4_shutdown,
2608 .set_termios = ic4_set_termios,
2610 .release_port = null_void_function,
2611 .request_port = ic4_request_port,
2620 .driver_name =
"ioc4_serial_rs232",
2629 .driver_name =
"ioc4_serial_rs422",
2647 struct uart_port *the_port;
2649 struct ioc4_soft *
soft;
2663 switch (port_type) {
2678 if (!(port_num & 1) && port) {
2693 sizeof(
struct ioc4_serial));
2710 ioc4_serial_core_attach(
struct pci_dev *pdev,
int port_type)
2713 struct uart_port *the_port;
2722 __func__, pdev, (
void *)control));
2730 u_driver = (port_type ==
PROTO_RS232) ? &ioc4_uart_rs232
2740 DPRINT_CONFIG((
"%s: attach the_port 0x%p / port 0x%p : type %s\n",
2741 __func__, (
void *)the_port,
2747 the_port->
iobase = (pdev->
bus->number << 16) | port_num;
2748 the_port->
line = (Num_of_ioc4_cards << 2) | port_num;
2752 the_port->
ops = &ioc4_ops;
2754 the_port->
dev = &pdev->
dev;
2758 "%s: unable to add port %d bus %d\n",
2759 __func__, the_port->
line, pdev->
bus->number);
2762 (
"IOC4 serial port %d irq = %d, bus %d\n",
2763 the_port->
line, the_port->
irq, pdev->
bus->number));
2777 unsigned long tmp_addr1;
2778 struct ioc4_serial __iomem *
serial;
2779 struct ioc4_soft *
soft;
2799 "ioc4 (%p): unable to get request region for "
2800 "uart space\n", (
void *)idd->
idd_pdev);
2804 serial =
ioremap(tmp_addr1,
sizeof(
struct ioc4_serial));
2807 "ioc4 (%p) : unable to remap ioc4 serial register\n",
2821 ": unable to get memory for the IOC4\n");
2828 soft = kzalloc(
sizeof(
struct ioc4_soft),
GFP_KERNEL);
2831 "ioc4 (%p): unable to get memory for the soft struct\n",
2860 "sgi-ioc4serial", soft)) {
2864 "%s : request_irq fails for IRQ 0x%x\n ",
2867 ret = ioc4_attach_local(idd);
2879 Num_of_ioc4_cards++;
2885 ioc4_serial_remove_one(idd);
2901 .is_name =
"IOC4_serial",
2904 .is_remove = ioc4_serial_remove_one,
2910 static int __init ioc4_serial_init(
void)
2917 "%s: Couldn't register rs232 IOC4 serial driver\n",
2923 "%s: Couldn't register rs422 IOC4 serial driver\n",
2925 goto out_uart_rs232;
2931 goto out_uart_rs422;
2942 static void __exit ioc4_serial_exit(
void)