1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/errno.h>
16#include <linux/tty.h>
17#include <linux/serial.h>
18#include <linux/serialP.h>
19#include <linux/circ_buf.h>
20#include <linux/serial_reg.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/ioc4.h>
24#include <linux/serial_core.h>
25
26
27
28
29
30#define IOC4_NUM_SERIAL_PORTS 4
31#define IOC4_NUM_CARDS 8
32
33#define GET_SIO_IR(_n) (_n == 0) ? (IOC4_SIO_IR_S0) : \
34 (_n == 1) ? (IOC4_SIO_IR_S1) : \
35 (_n == 2) ? (IOC4_SIO_IR_S2) : \
36 (IOC4_SIO_IR_S3)
37
38#define GET_OTHER_IR(_n) (_n == 0) ? (IOC4_OTHER_IR_S0_MEMERR) : \
39 (_n == 1) ? (IOC4_OTHER_IR_S1_MEMERR) : \
40 (_n == 2) ? (IOC4_OTHER_IR_S2_MEMERR) : \
41 (IOC4_OTHER_IR_S3_MEMERR)
42
43
44
45
46
47
48
49
50
51#define IOC4_PCI_ERR_ADDR_L 0x000
52#define IOC4_PCI_ERR_ADDR_VLD (0x1 << 0)
53#define IOC4_PCI_ERR_ADDR_MST_ID_MSK (0xf << 1)
54#define IOC4_PCI_ERR_ADDR_MST_NUM_MSK (0xe << 1)
55#define IOC4_PCI_ERR_ADDR_MST_TYP_MSK (0x1 << 1)
56#define IOC4_PCI_ERR_ADDR_MUL_ERR (0x1 << 5)
57#define IOC4_PCI_ERR_ADDR_ADDR_MSK (0x3ffffff << 6)
58
59
60#define IOC4_SIO_INTR_TYPE 0
61#define IOC4_OTHER_INTR_TYPE 1
62#define IOC4_NUM_INTR_TYPES 2
63
64
65#define IOC4_SIO_IR_S0_TX_MT 0x00000001
66#define IOC4_SIO_IR_S0_RX_FULL 0x00000002
67#define IOC4_SIO_IR_S0_RX_HIGH 0x00000004
68#define IOC4_SIO_IR_S0_RX_TIMER 0x00000008
69#define IOC4_SIO_IR_S0_DELTA_DCD 0x00000010
70#define IOC4_SIO_IR_S0_DELTA_CTS 0x00000020
71#define IOC4_SIO_IR_S0_INT 0x00000040
72#define IOC4_SIO_IR_S0_TX_EXPLICIT 0x00000080
73#define IOC4_SIO_IR_S1_TX_MT 0x00000100
74#define IOC4_SIO_IR_S1_RX_FULL 0x00000200
75#define IOC4_SIO_IR_S1_RX_HIGH 0x00000400
76#define IOC4_SIO_IR_S1_RX_TIMER 0x00000800
77#define IOC4_SIO_IR_S1_DELTA_DCD 0x00001000
78#define IOC4_SIO_IR_S1_DELTA_CTS 0x00002000
79#define IOC4_SIO_IR_S1_INT 0x00004000
80#define IOC4_SIO_IR_S1_TX_EXPLICIT 0x00008000
81#define IOC4_SIO_IR_S2_TX_MT 0x00010000
82#define IOC4_SIO_IR_S2_RX_FULL 0x00020000
83#define IOC4_SIO_IR_S2_RX_HIGH 0x00040000
84#define IOC4_SIO_IR_S2_RX_TIMER 0x00080000
85#define IOC4_SIO_IR_S2_DELTA_DCD 0x00100000
86#define IOC4_SIO_IR_S2_DELTA_CTS 0x00200000
87#define IOC4_SIO_IR_S2_INT 0x00400000
88#define IOC4_SIO_IR_S2_TX_EXPLICIT 0x00800000
89#define IOC4_SIO_IR_S3_TX_MT 0x01000000
90#define IOC4_SIO_IR_S3_RX_FULL 0x02000000
91#define IOC4_SIO_IR_S3_RX_HIGH 0x04000000
92#define IOC4_SIO_IR_S3_RX_TIMER 0x08000000
93#define IOC4_SIO_IR_S3_DELTA_DCD 0x10000000
94#define IOC4_SIO_IR_S3_DELTA_CTS 0x20000000
95#define IOC4_SIO_IR_S3_INT 0x40000000
96#define IOC4_SIO_IR_S3_TX_EXPLICIT 0x80000000
97
98
99#define IOC4_SIO_IR_S0 (IOC4_SIO_IR_S0_TX_MT | \
100 IOC4_SIO_IR_S0_RX_FULL | \
101 IOC4_SIO_IR_S0_RX_HIGH | \
102 IOC4_SIO_IR_S0_RX_TIMER | \
103 IOC4_SIO_IR_S0_DELTA_DCD | \
104 IOC4_SIO_IR_S0_DELTA_CTS | \
105 IOC4_SIO_IR_S0_INT | \
106 IOC4_SIO_IR_S0_TX_EXPLICIT)
107#define IOC4_SIO_IR_S1 (IOC4_SIO_IR_S1_TX_MT | \
108 IOC4_SIO_IR_S1_RX_FULL | \
109 IOC4_SIO_IR_S1_RX_HIGH | \
110 IOC4_SIO_IR_S1_RX_TIMER | \
111 IOC4_SIO_IR_S1_DELTA_DCD | \
112 IOC4_SIO_IR_S1_DELTA_CTS | \
113 IOC4_SIO_IR_S1_INT | \
114 IOC4_SIO_IR_S1_TX_EXPLICIT)
115#define IOC4_SIO_IR_S2 (IOC4_SIO_IR_S2_TX_MT | \
116 IOC4_SIO_IR_S2_RX_FULL | \
117 IOC4_SIO_IR_S2_RX_HIGH | \
118 IOC4_SIO_IR_S2_RX_TIMER | \
119 IOC4_SIO_IR_S2_DELTA_DCD | \
120 IOC4_SIO_IR_S2_DELTA_CTS | \
121 IOC4_SIO_IR_S2_INT | \
122 IOC4_SIO_IR_S2_TX_EXPLICIT)
123#define IOC4_SIO_IR_S3 (IOC4_SIO_IR_S3_TX_MT | \
124 IOC4_SIO_IR_S3_RX_FULL | \
125 IOC4_SIO_IR_S3_RX_HIGH | \
126 IOC4_SIO_IR_S3_RX_TIMER | \
127 IOC4_SIO_IR_S3_DELTA_DCD | \
128 IOC4_SIO_IR_S3_DELTA_CTS | \
129 IOC4_SIO_IR_S3_INT | \
130 IOC4_SIO_IR_S3_TX_EXPLICIT)
131
132
133#define IOC4_OTHER_IR_ATA_INT 0x00000001
134#define IOC4_OTHER_IR_ATA_MEMERR 0x00000002
135#define IOC4_OTHER_IR_S0_MEMERR 0x00000004
136#define IOC4_OTHER_IR_S1_MEMERR 0x00000008
137#define IOC4_OTHER_IR_S2_MEMERR 0x00000010
138#define IOC4_OTHER_IR_S3_MEMERR 0x00000020
139#define IOC4_OTHER_IR_KBD_INT 0x00000040
140#define IOC4_OTHER_IR_RESERVED 0x007fff80
141#define IOC4_OTHER_IR_RT_INT 0x00800000
142#define IOC4_OTHER_IR_GEN_INT 0xff000000
143
144#define IOC4_OTHER_IR_SER_MEMERR (IOC4_OTHER_IR_S0_MEMERR | IOC4_OTHER_IR_S1_MEMERR | \
145 IOC4_OTHER_IR_S2_MEMERR | IOC4_OTHER_IR_S3_MEMERR)
146
147
148#define IOC4_SIO_CR_CMD_PULSE_SHIFT 0
149#define IOC4_SIO_CR_ARB_DIAG_TX0 0x00000000
150#define IOC4_SIO_CR_ARB_DIAG_RX0 0x00000010
151#define IOC4_SIO_CR_ARB_DIAG_TX1 0x00000020
152#define IOC4_SIO_CR_ARB_DIAG_RX1 0x00000030
153#define IOC4_SIO_CR_ARB_DIAG_TX2 0x00000040
154#define IOC4_SIO_CR_ARB_DIAG_RX2 0x00000050
155#define IOC4_SIO_CR_ARB_DIAG_TX3 0x00000060
156#define IOC4_SIO_CR_ARB_DIAG_RX3 0x00000070
157#define IOC4_SIO_CR_SIO_DIAG_IDLE 0x00000080
158
159
160#define IOC4_GPCR_UART0_MODESEL 0x10
161
162#define IOC4_GPCR_UART1_MODESEL 0x20
163
164#define IOC4_GPCR_UART2_MODESEL 0x40
165
166#define IOC4_GPCR_UART3_MODESEL 0x80
167
168
169#define IOC4_GPPR_UART0_MODESEL_PIN 4
170
171#define IOC4_GPPR_UART1_MODESEL_PIN 5
172
173#define IOC4_GPPR_UART2_MODESEL_PIN 6
174
175#define IOC4_GPPR_UART3_MODESEL_PIN 7
176
177
178
179#define IOC4_RXSB_OVERRUN 0x01
180#define IOC4_RXSB_PAR_ERR 0x02
181#define IOC4_RXSB_FRAME_ERR 0x04
182#define IOC4_RXSB_BREAK 0x08
183#define IOC4_RXSB_CTS 0x10
184#define IOC4_RXSB_DCD 0x20
185#define IOC4_RXSB_MODEM_VALID 0x40
186#define IOC4_RXSB_DATA_VALID 0x80
187
188
189
190#define IOC4_TXCB_INT_WHEN_DONE 0x20
191#define IOC4_TXCB_INVALID 0x00
192#define IOC4_TXCB_VALID 0x40
193#define IOC4_TXCB_MCR 0x80
194#define IOC4_TXCB_DELAY 0xc0
195
196
197#define IOC4_SBBR_L_SIZE 0x00000001
198
199
200#define IOC4_SSCR_RX_THRESHOLD 0x000001ff
201#define IOC4_SSCR_TX_TIMER_BUSY 0x00010000
202#define IOC4_SSCR_HFC_EN 0x00020000
203#define IOC4_SSCR_RX_RING_DCD 0x00040000
204#define IOC4_SSCR_RX_RING_CTS 0x00080000
205#define IOC4_SSCR_DIAG 0x00200000
206#define IOC4_SSCR_RX_DRAIN 0x08000000
207#define IOC4_SSCR_DMA_EN 0x10000000
208#define IOC4_SSCR_DMA_PAUSE 0x20000000
209#define IOC4_SSCR_PAUSE_STATE 0x40000000
210#define IOC4_SSCR_RESET 0x80000000
211
212
213#define IOC4_PROD_CONS_PTR_4K 0x00000ff8
214#define IOC4_PROD_CONS_PTR_1K 0x000003f8
215#define IOC4_PROD_CONS_PTR_OFF 3
216
217
218#define IOC4_SRCIR_ARM 0x80000000
219
220
221#define IOC4_SHADOW_DR 0x00000001
222#define IOC4_SHADOW_OE 0x00000002
223#define IOC4_SHADOW_PE 0x00000004
224#define IOC4_SHADOW_FE 0x00000008
225#define IOC4_SHADOW_BI 0x00000010
226#define IOC4_SHADOW_THRE 0x00000020
227#define IOC4_SHADOW_TEMT 0x00000040
228#define IOC4_SHADOW_RFCE 0x00000080
229#define IOC4_SHADOW_DCTS 0x00010000
230#define IOC4_SHADOW_DDCD 0x00080000
231#define IOC4_SHADOW_CTS 0x00100000
232#define IOC4_SHADOW_DCD 0x00800000
233#define IOC4_SHADOW_DTR 0x01000000
234#define IOC4_SHADOW_RTS 0x02000000
235#define IOC4_SHADOW_OUT1 0x04000000
236#define IOC4_SHADOW_OUT2 0x08000000
237#define IOC4_SHADOW_LOOP 0x10000000
238
239
240#define IOC4_SRTR_CNT 0x00000fff
241#define IOC4_SRTR_CNT_VAL 0x0fff0000
242#define IOC4_SRTR_CNT_VAL_SHIFT 16
243#define IOC4_SRTR_HZ 16000
244
245
246struct ioc4_serialregs {
247 uint32_t sscr;
248 uint32_t stpir;
249 uint32_t stcir;
250 uint32_t srpir;
251 uint32_t srcir;
252 uint32_t srtr;
253 uint32_t shadow;
254};
255
256
257struct ioc4_uartregs {
258 char i4u_lcr;
259 union {
260 char iir;
261 char fcr;
262 } u3;
263 union {
264 char ier;
265 char dlm;
266 } u2;
267 union {
268 char rbr;
269 char thr;
270 char dll;
271 } u1;
272 char i4u_scr;
273 char i4u_msr;
274 char i4u_lsr;
275 char i4u_mcr;
276};
277
278
279#define i4u_dll u1.dll
280#define i4u_ier u2.ier
281#define i4u_dlm u2.dlm
282#define i4u_fcr u3.fcr
283
284
285struct ioc4_serial {
286 uint32_t sbbr01_l;
287 uint32_t sbbr01_h;
288 uint32_t sbbr23_l;
289 uint32_t sbbr23_h;
290
291 struct ioc4_serialregs port_0;
292 struct ioc4_serialregs port_1;
293 struct ioc4_serialregs port_2;
294 struct ioc4_serialregs port_3;
295 struct ioc4_uartregs uart_0;
296 struct ioc4_uartregs uart_1;
297 struct ioc4_uartregs uart_2;
298 struct ioc4_uartregs uart_3;
299} ioc4_serial;
300
301
302#define IOC4_SER_XIN_CLK_66 66666667
303#define IOC4_SER_XIN_CLK_33 33333333
304
305#define IOC4_W_IES 0
306#define IOC4_W_IEC 1
307
308typedef void ioc4_intr_func_f(void *, uint32_t);
309typedef ioc4_intr_func_f *ioc4_intr_func_t;
310
311static unsigned int Num_of_ioc4_cards;
312
313
314
315#define DPRINT_CONFIG(_x...) ;
316
317
318
319#define WAKEUP_CHARS 256
320
321
322#define IOC4_MAX_CHARS 256
323#define IOC4_FIFO_CHARS 255
324
325
326#define DEVICE_NAME_RS232 "ttyIOC"
327#define DEVICE_NAME_RS422 "ttyAIOC"
328#define DEVICE_MAJOR 204
329#define DEVICE_MINOR_RS232 50
330#define DEVICE_MINOR_RS422 84
331
332
333
334#define IOC4_SERIAL_OFFSET 0x300
335
336
337#define NCS_BREAK 0x1
338#define NCS_PARITY 0x2
339#define NCS_FRAMING 0x4
340#define NCS_OVERRUN 0x8
341
342
343#define MIN_BAUD_SUPPORTED 1200
344#define MAX_BAUD_SUPPORTED 115200
345
346
347#define PROTO_RS232 3
348#define PROTO_RS422 7
349
350
351#define N_DATA_READY 0x01
352#define N_OUTPUT_LOWAT 0x02
353#define N_BREAK 0x04
354#define N_PARITY_ERROR 0x08
355#define N_FRAMING_ERROR 0x10
356#define N_OVERRUN_ERROR 0x20
357#define N_DDCD 0x40
358#define N_DCTS 0x80
359
360#define N_ALL_INPUT (N_DATA_READY | N_BREAK | \
361 N_PARITY_ERROR | N_FRAMING_ERROR | \
362 N_OVERRUN_ERROR | N_DDCD | N_DCTS)
363
364#define N_ALL_OUTPUT N_OUTPUT_LOWAT
365
366#define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR | N_OVERRUN_ERROR)
367
368#define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK | \
369 N_PARITY_ERROR | N_FRAMING_ERROR | \
370 N_OVERRUN_ERROR | N_DDCD | N_DCTS)
371
372#define SER_DIVISOR(_x, clk) (((clk) + (_x) * 8) / ((_x) * 16))
373#define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div))
374
375
376#define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \
377 | UART_LCR_WLEN7 | UART_LCR_WLEN8)
378#define LCR_MASK_STOP_BITS (UART_LCR_STOP)
379
380#define PENDING(_p) (readl(&(_p)->ip_mem->sio_ir.raw) & _p->ip_ienb)
381#define READ_SIO_IR(_p) readl(&(_p)->ip_mem->sio_ir.raw)
382
383
384#ifdef IOC4_1K_BUFFERS
385#define RING_BUF_SIZE 1024
386#define IOC4_BUF_SIZE_BIT 0
387#define PROD_CONS_MASK IOC4_PROD_CONS_PTR_1K
388#else
389#define RING_BUF_SIZE 4096
390#define IOC4_BUF_SIZE_BIT IOC4_SBBR_L_SIZE
391#define PROD_CONS_MASK IOC4_PROD_CONS_PTR_4K
392#endif
393
394#define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4)
395
396
397
398
399
400#define UART_PORT_MIN 0
401#define UART_PORT_RS232 UART_PORT_MIN
402#define UART_PORT_RS422 1
403#define UART_PORT_COUNT 2
404
405struct ioc4_control {
406 int ic_irq;
407 struct {
408
409 struct uart_port icp_uart_port[UART_PORT_COUNT];
410
411 struct ioc4_port *icp_port;
412 } ic_port[IOC4_NUM_SERIAL_PORTS];
413 struct ioc4_soft *ic_soft;
414};
415
416
417
418
419#define MAX_IOC4_INTR_ENTS (8 * sizeof(uint32_t))
420struct ioc4_soft {
421 struct ioc4_misc_regs __iomem *is_ioc4_misc_addr;
422 struct ioc4_serial __iomem *is_ioc4_serial_addr;
423
424
425 struct ioc4_intr_type {
426
427
428
429
430
431
432 struct ioc4_intr_info {
433 uint32_t sd_bits;
434 ioc4_intr_func_f *sd_intr;
435 void *sd_info;
436 } is_intr_info[MAX_IOC4_INTR_ENTS];
437
438
439 atomic_t is_num_intrs;
440 } is_intr_type[IOC4_NUM_INTR_TYPES];
441
442
443
444
445
446
447
448 spinlock_t is_ir_lock;
449};
450
451
452struct ioc4_port {
453 struct uart_port *ip_port;
454
455 struct uart_port *ip_all_ports[UART_PORT_COUNT];
456
457 struct ioc4_control *ip_control;
458 struct pci_dev *ip_pdev;
459 struct ioc4_soft *ip_ioc4_soft;
460
461
462 struct ioc4_misc_regs __iomem *ip_mem;
463 struct ioc4_serial __iomem *ip_serial;
464 struct ioc4_serialregs __iomem *ip_serial_regs;
465 struct ioc4_uartregs __iomem *ip_uart_regs;
466
467
468 dma_addr_t ip_dma_ringbuf;
469
470 struct ring_buffer *ip_cpu_ringbuf;
471
472
473 struct ring *ip_inring;
474 struct ring *ip_outring;
475
476
477 struct hooks *ip_hooks;
478
479 spinlock_t ip_lock;
480
481
482 int ip_baud;
483 int ip_tx_lowat;
484 int ip_rx_timeout;
485
486
487 int ip_notify;
488
489
490
491
492 uint32_t ip_ienb;
493 uint32_t ip_sscr;
494 uint32_t ip_tx_prod;
495 uint32_t ip_rx_cons;
496 int ip_pci_bus_speed;
497 unsigned char ip_flags;
498};
499
500
501
502
503
504
505#define TX_LOWAT_LATENCY 1000
506#define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY)
507#define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ)
508
509
510#define INPUT_HIGH 0x01
511#define DCD_ON 0x02
512#define LOWAT_WRITTEN 0x04
513#define READ_ABORTED 0x08
514#define PORT_ACTIVE 0x10
515#define PORT_INACTIVE 0
516
517
518
519
520
521
522struct hooks {
523 uint32_t intr_delta_dcd;
524 uint32_t intr_delta_cts;
525 uint32_t intr_tx_mt;
526 uint32_t intr_rx_timer;
527 uint32_t intr_rx_high;
528 uint32_t intr_tx_explicit;
529 uint32_t intr_dma_error;
530 uint32_t intr_clear;
531 uint32_t intr_all;
532 int rs422_select_pin;
533};
534
535static struct hooks hooks_array[IOC4_NUM_SERIAL_PORTS] = {
536
537 {
538 IOC4_SIO_IR_S0_DELTA_DCD, IOC4_SIO_IR_S0_DELTA_CTS,
539 IOC4_SIO_IR_S0_TX_MT, IOC4_SIO_IR_S0_RX_TIMER,
540 IOC4_SIO_IR_S0_RX_HIGH, IOC4_SIO_IR_S0_TX_EXPLICIT,
541 IOC4_OTHER_IR_S0_MEMERR,
542 (IOC4_SIO_IR_S0_TX_MT | IOC4_SIO_IR_S0_RX_FULL |
543 IOC4_SIO_IR_S0_RX_HIGH | IOC4_SIO_IR_S0_RX_TIMER |
544 IOC4_SIO_IR_S0_DELTA_DCD | IOC4_SIO_IR_S0_DELTA_CTS |
545 IOC4_SIO_IR_S0_INT | IOC4_SIO_IR_S0_TX_EXPLICIT),
546 IOC4_SIO_IR_S0, IOC4_GPPR_UART0_MODESEL_PIN,
547 },
548
549
550 {
551 IOC4_SIO_IR_S1_DELTA_DCD, IOC4_SIO_IR_S1_DELTA_CTS,
552 IOC4_SIO_IR_S1_TX_MT, IOC4_SIO_IR_S1_RX_TIMER,
553 IOC4_SIO_IR_S1_RX_HIGH, IOC4_SIO_IR_S1_TX_EXPLICIT,
554 IOC4_OTHER_IR_S1_MEMERR,
555 (IOC4_SIO_IR_S1_TX_MT | IOC4_SIO_IR_S1_RX_FULL |
556 IOC4_SIO_IR_S1_RX_HIGH | IOC4_SIO_IR_S1_RX_TIMER |
557 IOC4_SIO_IR_S1_DELTA_DCD | IOC4_SIO_IR_S1_DELTA_CTS |
558 IOC4_SIO_IR_S1_INT | IOC4_SIO_IR_S1_TX_EXPLICIT),
559 IOC4_SIO_IR_S1, IOC4_GPPR_UART1_MODESEL_PIN,
560 },
561
562
563 {
564 IOC4_SIO_IR_S2_DELTA_DCD, IOC4_SIO_IR_S2_DELTA_CTS,
565 IOC4_SIO_IR_S2_TX_MT, IOC4_SIO_IR_S2_RX_TIMER,
566 IOC4_SIO_IR_S2_RX_HIGH, IOC4_SIO_IR_S2_TX_EXPLICIT,
567 IOC4_OTHER_IR_S2_MEMERR,
568 (IOC4_SIO_IR_S2_TX_MT | IOC4_SIO_IR_S2_RX_FULL |
569 IOC4_SIO_IR_S2_RX_HIGH | IOC4_SIO_IR_S2_RX_TIMER |
570 IOC4_SIO_IR_S2_DELTA_DCD | IOC4_SIO_IR_S2_DELTA_CTS |
571 IOC4_SIO_IR_S2_INT | IOC4_SIO_IR_S2_TX_EXPLICIT),
572 IOC4_SIO_IR_S2, IOC4_GPPR_UART2_MODESEL_PIN,
573 },
574
575
576 {
577 IOC4_SIO_IR_S3_DELTA_DCD, IOC4_SIO_IR_S3_DELTA_CTS,
578 IOC4_SIO_IR_S3_TX_MT, IOC4_SIO_IR_S3_RX_TIMER,
579 IOC4_SIO_IR_S3_RX_HIGH, IOC4_SIO_IR_S3_TX_EXPLICIT,
580 IOC4_OTHER_IR_S3_MEMERR,
581 (IOC4_SIO_IR_S3_TX_MT | IOC4_SIO_IR_S3_RX_FULL |
582 IOC4_SIO_IR_S3_RX_HIGH | IOC4_SIO_IR_S3_RX_TIMER |
583 IOC4_SIO_IR_S3_DELTA_DCD | IOC4_SIO_IR_S3_DELTA_CTS |
584 IOC4_SIO_IR_S3_INT | IOC4_SIO_IR_S3_TX_EXPLICIT),
585 IOC4_SIO_IR_S3, IOC4_GPPR_UART3_MODESEL_PIN,
586 }
587};
588
589
590struct ring_entry {
591 union {
592 struct {
593 uint32_t alldata;
594 uint32_t allsc;
595 } all;
596 struct {
597 char data[4];
598 char sc[4];
599 } s;
600 } u;
601};
602
603
604#define RING_ANY_VALID \
605 ((uint32_t)(IOC4_RXSB_MODEM_VALID | IOC4_RXSB_DATA_VALID) * 0x01010101)
606
607#define ring_sc u.s.sc
608#define ring_data u.s.data
609#define ring_allsc u.all.allsc
610
611
612#define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry))
613
614
615struct ring {
616 struct ring_entry entries[ENTRIES_PER_RING];
617};
618
619
620struct ring_buffer {
621 struct ring TX_0_OR_2;
622 struct ring RX_0_OR_2;
623 struct ring TX_1_OR_3;
624 struct ring RX_1_OR_3;
625};
626
627
628#define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh)
629
630
631
632#define MAXITER 10000000
633
634
635static void receive_chars(struct uart_port *);
636static void handle_intr(void *arg, uint32_t sio_ir);
637
638
639
640
641
642
643static inline int port_is_active(struct ioc4_port *port,
644 struct uart_port *uart_port)
645{
646 if (port) {
647 if ((port->ip_flags & PORT_ACTIVE)
648 && (port->ip_port == uart_port))
649 return 1;
650 }
651 return 0;
652}
653
654
655
656
657
658
659
660
661
662static inline void
663write_ireg(struct ioc4_soft *ioc4_soft, uint32_t val, int which, int type)
664{
665 struct ioc4_misc_regs __iomem *mem = ioc4_soft->is_ioc4_misc_addr;
666 unsigned long flags;
667
668 spin_lock_irqsave(&ioc4_soft->is_ir_lock, flags);
669
670 switch (type) {
671 case IOC4_SIO_INTR_TYPE:
672 switch (which) {
673 case IOC4_W_IES:
674 writel(val, &mem->sio_ies.raw);
675 break;
676
677 case IOC4_W_IEC:
678 writel(val, &mem->sio_iec.raw);
679 break;
680 }
681 break;
682
683 case IOC4_OTHER_INTR_TYPE:
684 switch (which) {
685 case IOC4_W_IES:
686 writel(val, &mem->other_ies.raw);
687 break;
688
689 case IOC4_W_IEC:
690 writel(val, &mem->other_iec.raw);
691 break;
692 }
693 break;
694
695 default:
696 break;
697 }
698 spin_unlock_irqrestore(&ioc4_soft->is_ir_lock, flags);
699}
700
701
702
703
704
705
706static int set_baud(struct ioc4_port *port, int baud)
707{
708 int actual_baud;
709 int diff;
710 int lcr;
711 unsigned short divisor;
712 struct ioc4_uartregs __iomem *uart;
713
714 divisor = SER_DIVISOR(baud, port->ip_pci_bus_speed);
715 if (!divisor)
716 return 1;
717 actual_baud = DIVISOR_TO_BAUD(divisor, port->ip_pci_bus_speed);
718
719 diff = actual_baud - baud;
720 if (diff < 0)
721 diff = -diff;
722
723
724 if (diff * 100 > actual_baud)
725 return 1;
726
727 uart = port->ip_uart_regs;
728 lcr = readb(&uart->i4u_lcr);
729 writeb(lcr | UART_LCR_DLAB, &uart->i4u_lcr);
730 writeb((unsigned char)divisor, &uart->i4u_dll);
731 writeb((unsigned char)(divisor >> 8), &uart->i4u_dlm);
732 writeb(lcr, &uart->i4u_lcr);
733 return 0;
734}
735
736
737
738
739
740
741
742static struct ioc4_port *get_ioc4_port(struct uart_port *the_port, int set)
743{
744 struct ioc4_driver_data *idd = dev_get_drvdata(the_port->dev);
745 struct ioc4_control *control = idd->idd_serial_data;
746 struct ioc4_port *port;
747 int port_num, port_type;
748
749 if (control) {
750 for ( port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS;
751 port_num++ ) {
752 port = control->ic_port[port_num].icp_port;
753 if (!port)
754 continue;
755 for (port_type = UART_PORT_MIN;
756 port_type < UART_PORT_COUNT;
757 port_type++) {
758 if (the_port == port->ip_all_ports
759 [port_type]) {
760
761 if (set) {
762 port->ip_port = the_port;
763 }
764 return port;
765 }
766 }
767 }
768 }
769 return NULL;
770}
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790static inline uint32_t
791pending_intrs(struct ioc4_soft *soft, int type)
792{
793 struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr;
794 unsigned long flag;
795 uint32_t intrs = 0;
796
797 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
798 || (type == IOC4_OTHER_INTR_TYPE)));
799
800 spin_lock_irqsave(&soft->is_ir_lock, flag);
801
802 switch (type) {
803 case IOC4_SIO_INTR_TYPE:
804 intrs = readl(&mem->sio_ir.raw) & readl(&mem->sio_ies.raw);
805 break;
806
807 case IOC4_OTHER_INTR_TYPE:
808 intrs = readl(&mem->other_ir.raw) & readl(&mem->other_ies.raw);
809
810
811 intrs &= ~(IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR);
812 break;
813
814 default:
815 break;
816 }
817 spin_unlock_irqrestore(&soft->is_ir_lock, flag);
818 return intrs;
819}
820
821
822
823
824
825
826static int inline port_init(struct ioc4_port *port)
827{
828 uint32_t sio_cr;
829 struct hooks *hooks = port->ip_hooks;
830 struct ioc4_uartregs __iomem *uart;
831
832
833 writel(IOC4_SSCR_RESET, &port->ip_serial_regs->sscr);
834
835
836 do
837 sio_cr = readl(&port->ip_mem->sio_cr.raw);
838 while (!(sio_cr & IOC4_SIO_CR_SIO_DIAG_IDLE));
839
840
841 writel(0, &port->ip_serial_regs->sscr);
842
843
844
845
846 port->ip_tx_prod = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
847 writel(port->ip_tx_prod, &port->ip_serial_regs->stpir);
848 port->ip_rx_cons = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
849 writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir);
850
851
852 uart = port->ip_uart_regs;
853 writeb(0, &uart->i4u_lcr);
854 writeb(0, &uart->i4u_ier);
855
856
857 set_baud(port, port->ip_baud);
858
859
860 writeb(UART_LCR_WLEN8 | 0, &uart->i4u_lcr);
861
862
863
864 writeb(UART_FCR_ENABLE_FIFO, &uart->i4u_fcr);
865
866 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
867 &uart->i4u_fcr);
868
869
870 writeb(0, &uart->i4u_mcr);
871
872
873 readb(&uart->i4u_msr);
874
875
876 if (port->ip_hooks == &hooks_array[0]
877 || port->ip_hooks == &hooks_array[2]) {
878 unsigned long ring_pci_addr;
879 uint32_t __iomem *sbbr_l;
880 uint32_t __iomem *sbbr_h;
881
882 if (port->ip_hooks == &hooks_array[0]) {
883 sbbr_l = &port->ip_serial->sbbr01_l;
884 sbbr_h = &port->ip_serial->sbbr01_h;
885 } else {
886 sbbr_l = &port->ip_serial->sbbr23_l;
887 sbbr_h = &port->ip_serial->sbbr23_h;
888 }
889
890 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf;
891 DPRINT_CONFIG(("%s: ring_pci_addr 0x%lx\n",
892 __func__, ring_pci_addr));
893
894 writel((unsigned int)((uint64_t)ring_pci_addr >> 32), sbbr_h);
895 writel((unsigned int)ring_pci_addr | IOC4_BUF_SIZE_BIT, sbbr_l);
896 }
897
898
899 writel(IOC4_SRTR_HZ / 100, &port->ip_serial_regs->srtr);
900
901
902
903 port->ip_sscr = (ENTRIES_PER_RING * 3 / 4);
904 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
905
906
907 write_ireg(port->ip_ioc4_soft, hooks->intr_clear,
908 IOC4_W_IEC, IOC4_SIO_INTR_TYPE);
909 port->ip_ienb &= ~hooks->intr_clear;
910 writel(hooks->intr_clear, &port->ip_mem->sio_ir.raw);
911 return 0;
912}
913
914
915
916
917
918
919
920static void handle_dma_error_intr(void *arg, uint32_t other_ir)
921{
922 struct ioc4_port *port = (struct ioc4_port *)arg;
923 struct hooks *hooks = port->ip_hooks;
924 unsigned long flags;
925
926 spin_lock_irqsave(&port->ip_lock, flags);
927
928
929 writel(hooks->intr_dma_error, &port->ip_mem->other_ir.raw);
930
931 if (readl(&port->ip_mem->pci_err_addr_l.raw) & IOC4_PCI_ERR_ADDR_VLD) {
932 printk(KERN_ERR
933 "PCI error address is 0x%lx, "
934 "master is serial port %c %s\n",
935 (((uint64_t)readl(&port->ip_mem->pci_err_addr_h)
936 << 32)
937 | readl(&port->ip_mem->pci_err_addr_l.raw))
938 & IOC4_PCI_ERR_ADDR_ADDR_MSK, '1' +
939 ((char)(readl(&port->ip_mem->pci_err_addr_l.raw) &
940 IOC4_PCI_ERR_ADDR_MST_NUM_MSK) >> 1),
941 (readl(&port->ip_mem->pci_err_addr_l.raw)
942 & IOC4_PCI_ERR_ADDR_MST_TYP_MSK)
943 ? "RX" : "TX");
944
945 if (readl(&port->ip_mem->pci_err_addr_l.raw)
946 & IOC4_PCI_ERR_ADDR_MUL_ERR) {
947 printk(KERN_ERR
948 "Multiple errors occurred\n");
949 }
950 }
951 spin_unlock_irqrestore(&port->ip_lock, flags);
952
953
954 write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error, IOC4_W_IES,
955 IOC4_OTHER_INTR_TYPE);
956}
957
958
959
960
961
962
963
964
965
966static void
967intr_connect(struct ioc4_soft *soft, int type,
968 uint32_t intrbits, ioc4_intr_func_f * intr, void *info)
969{
970 int i;
971 struct ioc4_intr_info *intr_ptr;
972
973 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
974 || (type == IOC4_OTHER_INTR_TYPE)));
975
976 i = atomic_inc(&soft-> is_intr_type[type].is_num_intrs) - 1;
977 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
978
979
980 intr_ptr = &soft->is_intr_type[type].is_intr_info[i];
981 intr_ptr->sd_bits = intrbits;
982 intr_ptr->sd_intr = intr;
983 intr_ptr->sd_info = info;
984}
985
986
987
988
989
990
991
992static irqreturn_t ioc4_intr(int irq, void *arg)
993{
994 struct ioc4_soft *soft;
995 uint32_t this_ir, this_mir;
996 int xx, num_intrs = 0;
997 int intr_type;
998 int handled = 0;
999 struct ioc4_intr_info *intr_info;
1000
1001 soft = arg;
1002 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
1003 num_intrs = (int)atomic_read(
1004 &soft->is_intr_type[intr_type].is_num_intrs);
1005
1006 this_mir = this_ir = pending_intrs(soft, intr_type);
1007
1008
1009
1010
1011 for (xx = 0; xx < num_intrs; xx++) {
1012 intr_info = &soft->is_intr_type[intr_type].is_intr_info[xx];
1013 if ((this_mir = this_ir & intr_info->sd_bits)) {
1014
1015 handled++;
1016 write_ireg(soft, intr_info->sd_bits, IOC4_W_IEC,
1017 intr_type);
1018 intr_info->sd_intr(intr_info->sd_info, this_mir);
1019 this_ir &= ~this_mir;
1020 }
1021 }
1022 }
1023#ifdef DEBUG_INTERRUPTS
1024 {
1025 struct ioc4_misc_regs __iomem *mem = soft->is_ioc4_misc_addr;
1026 unsigned long flag;
1027
1028 spin_lock_irqsave(&soft->is_ir_lock, flag);
1029 printk ("%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x "
1030 "other_ir 0x%x other_ies 0x%x mask 0x%x\n",
1031 __func__, __LINE__,
1032 (void *)mem, readl(&mem->sio_ir.raw),
1033 readl(&mem->sio_ies.raw),
1034 readl(&mem->other_ir.raw),
1035 readl(&mem->other_ies.raw),
1036 IOC4_OTHER_IR_ATA_INT | IOC4_OTHER_IR_ATA_MEMERR);
1037 spin_unlock_irqrestore(&soft->is_ir_lock, flag);
1038 }
1039#endif
1040 return handled ? IRQ_HANDLED : IRQ_NONE;
1041}
1042
1043
1044
1045
1046
1047
1048
1049static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1050{
1051 struct ioc4_port *port;
1052 struct ioc4_port *ports[IOC4_NUM_SERIAL_PORTS];
1053 int port_number;
1054 uint16_t ioc4_revid_min = 62;
1055 uint16_t ioc4_revid;
1056 struct pci_dev *pdev = idd->idd_pdev;
1057 struct ioc4_control* control = idd->idd_serial_data;
1058 struct ioc4_soft *soft = control->ic_soft;
1059 void __iomem *ioc4_misc = idd->idd_misc_regs;
1060 void __iomem *ioc4_serial = soft->is_ioc4_serial_addr;
1061
1062
1063 pci_read_config_word(pdev, PCI_COMMAND_SPECIAL, &ioc4_revid);
1064
1065 printk(KERN_INFO "IOC4 firmware revision %d\n", ioc4_revid);
1066 if (ioc4_revid < ioc4_revid_min) {
1067 printk(KERN_WARNING
1068 "IOC4 serial not supported on firmware rev %d, "
1069 "please upgrade to rev %d or higher\n",
1070 ioc4_revid, ioc4_revid_min);
1071 return -EPERM;
1072 }
1073 BUG_ON(ioc4_misc == NULL);
1074 BUG_ON(ioc4_serial == NULL);
1075
1076
1077 for (port_number = 0; port_number < IOC4_NUM_SERIAL_PORTS;
1078 port_number++) {
1079 port = kzalloc(sizeof(struct ioc4_port), GFP_KERNEL);
1080 if (!port) {
1081 printk(KERN_WARNING
1082 "IOC4 serial memory not available for port\n");
1083 return -ENOMEM;
1084 }
1085 spin_lock_init(&port->ip_lock);
1086
1087
1088
1089
1090 ports[port_number] = port;
1091
1092
1093 control->ic_port[port_number].icp_port = port;
1094 port->ip_ioc4_soft = soft;
1095 port->ip_pdev = pdev;
1096 port->ip_ienb = 0;
1097
1098
1099
1100
1101 if (idd->count_period/IOC4_EXTINT_COUNT_DIVISOR < 20) {
1102 port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_66;
1103 } else {
1104 port->ip_pci_bus_speed = IOC4_SER_XIN_CLK_33;
1105 }
1106 port->ip_baud = 9600;
1107 port->ip_control = control;
1108 port->ip_mem = ioc4_misc;
1109 port->ip_serial = ioc4_serial;
1110
1111
1112 port->ip_hooks = &hooks_array[port_number];
1113
1114
1115
1116
1117 switch (port_number) {
1118 case 0:
1119 port->ip_serial_regs = &(port->ip_serial->port_0);
1120 port->ip_uart_regs = &(port->ip_serial->uart_0);
1121 break;
1122 case 1:
1123 port->ip_serial_regs = &(port->ip_serial->port_1);
1124 port->ip_uart_regs = &(port->ip_serial->uart_1);
1125 break;
1126 case 2:
1127 port->ip_serial_regs = &(port->ip_serial->port_2);
1128 port->ip_uart_regs = &(port->ip_serial->uart_2);
1129 break;
1130 default:
1131 case 3:
1132 port->ip_serial_regs = &(port->ip_serial->port_3);
1133 port->ip_uart_regs = &(port->ip_serial->uart_3);
1134 break;
1135 }
1136
1137
1138 if (port_number && (port_number & 1)) {
1139
1140 port->ip_dma_ringbuf =
1141 ports[port_number - 1]->ip_dma_ringbuf;
1142 port->ip_cpu_ringbuf =
1143 ports[port_number - 1]->ip_cpu_ringbuf;
1144 port->ip_inring = RING(port, RX_1_OR_3);
1145 port->ip_outring = RING(port, TX_1_OR_3);
1146
1147 } else {
1148 if (port->ip_dma_ringbuf == 0) {
1149 port->ip_cpu_ringbuf = pci_alloc_consistent
1150 (pdev, TOTAL_RING_BUF_SIZE,
1151 &port->ip_dma_ringbuf);
1152
1153 }
1154 BUG_ON(!((((int64_t)port->ip_dma_ringbuf) &
1155 (TOTAL_RING_BUF_SIZE - 1)) == 0));
1156 DPRINT_CONFIG(("%s : ip_cpu_ringbuf 0x%p "
1157 "ip_dma_ringbuf 0x%p\n",
1158 __func__,
1159 (void *)port->ip_cpu_ringbuf,
1160 (void *)port->ip_dma_ringbuf));
1161 port->ip_inring = RING(port, RX_0_OR_2);
1162 port->ip_outring = RING(port, TX_0_OR_2);
1163 }
1164 DPRINT_CONFIG(("%s : port %d [addr 0x%p] control 0x%p",
1165 __func__,
1166 port_number, (void *)port, (void *)control));
1167 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n",
1168 (void *)port->ip_serial_regs,
1169 (void *)port->ip_uart_regs));
1170
1171
1172 port_init(port);
1173
1174 DPRINT_CONFIG(("%s: port_number %d port 0x%p inring 0x%p "
1175 "outring 0x%p\n",
1176 __func__,
1177 port_number, (void *)port,
1178 (void *)port->ip_inring,
1179 (void *)port->ip_outring));
1180
1181
1182 intr_connect(soft, IOC4_SIO_INTR_TYPE,
1183 GET_SIO_IR(port_number),
1184 handle_intr, port);
1185
1186 intr_connect(soft, IOC4_OTHER_INTR_TYPE,
1187 GET_OTHER_IR(port_number),
1188 handle_dma_error_intr, port);
1189 }
1190 return 0;
1191}
1192
1193
1194
1195
1196
1197
1198static void enable_intrs(struct ioc4_port *port, uint32_t mask)
1199{
1200 struct hooks *hooks = port->ip_hooks;
1201
1202 if ((port->ip_ienb & mask) != mask) {
1203 write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IES,
1204 IOC4_SIO_INTR_TYPE);
1205 port->ip_ienb |= mask;
1206 }
1207
1208 if (port->ip_ienb)
1209 write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error,
1210 IOC4_W_IES, IOC4_OTHER_INTR_TYPE);
1211}
1212
1213
1214
1215
1216
1217static inline int local_open(struct ioc4_port *port)
1218{
1219 int spiniter = 0;
1220
1221 port->ip_flags = PORT_ACTIVE;
1222
1223
1224 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
1225 writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
1226 &port->ip_serial_regs->sscr);
1227 while((readl(&port->ip_serial_regs-> sscr)
1228 & IOC4_SSCR_PAUSE_STATE) == 0) {
1229 spiniter++;
1230 if (spiniter > MAXITER) {
1231 port->ip_flags = PORT_INACTIVE;
1232 return -1;
1233 }
1234 }
1235 }
1236
1237
1238
1239
1240
1241
1242 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR,
1243 &port->ip_uart_regs->i4u_fcr);
1244
1245 writeb(UART_LCR_WLEN8, &port->ip_uart_regs->i4u_lcr);
1246
1247
1248
1249
1250
1251 port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD;
1252 port->ip_sscr |= 1;
1253
1254
1255
1256
1257 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1258 port->ip_tx_lowat = 1;
1259 return 0;
1260}
1261
1262
1263
1264
1265
1266
1267static inline int set_rx_timeout(struct ioc4_port *port, int timeout)
1268{
1269 int threshold;
1270
1271 port->ip_rx_timeout = timeout;
1272
1273
1274
1275
1276
1277
1278
1279
1280 threshold = timeout * port->ip_baud / 4000;
1281 if (threshold == 0)
1282 threshold = 1;
1283
1284 if ((unsigned)threshold > (unsigned)IOC4_SSCR_RX_THRESHOLD)
1285 return 1;
1286
1287 port->ip_sscr &= ~IOC4_SSCR_RX_THRESHOLD;
1288 port->ip_sscr |= threshold;
1289
1290 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1291
1292
1293
1294
1295 timeout = timeout * IOC4_SRTR_HZ / 100;
1296 if (timeout > IOC4_SRTR_CNT)
1297 timeout = IOC4_SRTR_CNT;
1298
1299 writel(timeout, &port->ip_serial_regs->srtr);
1300 return 0;
1301}
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312static inline int
1313config_port(struct ioc4_port *port,
1314 int baud, int byte_size, int stop_bits, int parenb, int parodd)
1315{
1316 char lcr, sizebits;
1317 int spiniter = 0;
1318
1319 DPRINT_CONFIG(("%s: baud %d byte_size %d stop %d parenb %d parodd %d\n",
1320 __func__, baud, byte_size, stop_bits, parenb, parodd));
1321
1322 if (set_baud(port, baud))
1323 return 1;
1324
1325 switch (byte_size) {
1326 case 5:
1327 sizebits = UART_LCR_WLEN5;
1328 break;
1329 case 6:
1330 sizebits = UART_LCR_WLEN6;
1331 break;
1332 case 7:
1333 sizebits = UART_LCR_WLEN7;
1334 break;
1335 case 8:
1336 sizebits = UART_LCR_WLEN8;
1337 break;
1338 default:
1339 return 1;
1340 }
1341
1342
1343 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
1344 writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
1345 &port->ip_serial_regs->sscr);
1346 while((readl(&port->ip_serial_regs->sscr)
1347 & IOC4_SSCR_PAUSE_STATE) == 0) {
1348 spiniter++;
1349 if (spiniter > MAXITER)
1350 return -1;
1351 }
1352 }
1353
1354
1355 lcr = readb(&port->ip_uart_regs->i4u_lcr);
1356 lcr &= ~(LCR_MASK_BITS_CHAR | UART_LCR_EPAR |
1357 UART_LCR_PARITY | LCR_MASK_STOP_BITS);
1358
1359
1360 lcr |= sizebits;
1361
1362
1363 if (parenb) {
1364 lcr |= UART_LCR_PARITY;
1365 if (!parodd)
1366 lcr |= UART_LCR_EPAR;
1367 }
1368
1369
1370 if (stop_bits)
1371 lcr |= UART_LCR_STOP ;
1372
1373 writeb(lcr, &port->ip_uart_regs->i4u_lcr);
1374
1375
1376 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
1377 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1378 }
1379 port->ip_baud = baud;
1380
1381
1382
1383
1384
1385 port->ip_tx_lowat = (TX_LOWAT_CHARS(baud) + 3) / 4;
1386 if (port->ip_tx_lowat == 0)
1387 port->ip_tx_lowat = 1;
1388
1389 set_rx_timeout(port, 2);
1390
1391 return 0;
1392}
1393
1394
1395
1396
1397
1398
1399
1400
1401static inline int do_write(struct ioc4_port *port, char *buf, int len)
1402{
1403 int prod_ptr, cons_ptr, total = 0;
1404 struct ring *outring;
1405 struct ring_entry *entry;
1406 struct hooks *hooks = port->ip_hooks;
1407
1408 BUG_ON(!(len >= 0));
1409
1410 prod_ptr = port->ip_tx_prod;
1411 cons_ptr = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
1412 outring = port->ip_outring;
1413
1414
1415
1416
1417
1418 cons_ptr = (cons_ptr - (int)sizeof(struct ring_entry)) & PROD_CONS_MASK;
1419
1420
1421 while ((prod_ptr != cons_ptr) && (len > 0)) {
1422 int xx;
1423
1424
1425 entry = (struct ring_entry *)((caddr_t) outring + prod_ptr);
1426
1427
1428 entry->ring_allsc = 0;
1429
1430
1431 for (xx = 0; (xx < 4) && (len > 0); xx++) {
1432 entry->ring_data[xx] = *buf++;
1433 entry->ring_sc[xx] = IOC4_TXCB_VALID;
1434 len--;
1435 total++;
1436 }
1437
1438
1439
1440
1441
1442
1443
1444 if (!(port->ip_flags & LOWAT_WRITTEN) &&
1445 ((cons_ptr - prod_ptr) & PROD_CONS_MASK)
1446 <= port->ip_tx_lowat
1447 * (int)sizeof(struct ring_entry)) {
1448 port->ip_flags |= LOWAT_WRITTEN;
1449 entry->ring_sc[0] |= IOC4_TXCB_INT_WHEN_DONE;
1450 }
1451
1452
1453 prod_ptr += sizeof(struct ring_entry);
1454 prod_ptr &= PROD_CONS_MASK;
1455 }
1456
1457
1458 if (total > 0 && !(port->ip_sscr & IOC4_SSCR_DMA_EN)) {
1459 port->ip_sscr |= IOC4_SSCR_DMA_EN;
1460 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1461 }
1462
1463
1464
1465
1466 if (!uart_tx_stopped(port->ip_port)) {
1467 writel(prod_ptr, &port->ip_serial_regs->stpir);
1468
1469
1470
1471
1472 if (total > 0)
1473 enable_intrs(port, hooks->intr_tx_mt);
1474 }
1475 port->ip_tx_prod = prod_ptr;
1476 return total;
1477}
1478
1479
1480
1481
1482
1483
1484static void disable_intrs(struct ioc4_port *port, uint32_t mask)
1485{
1486 struct hooks *hooks = port->ip_hooks;
1487
1488 if (port->ip_ienb & mask) {
1489 write_ireg(port->ip_ioc4_soft, mask, IOC4_W_IEC,
1490 IOC4_SIO_INTR_TYPE);
1491 port->ip_ienb &= ~mask;
1492 }
1493
1494 if (!port->ip_ienb)
1495 write_ireg(port->ip_ioc4_soft, hooks->intr_dma_error,
1496 IOC4_W_IEC, IOC4_OTHER_INTR_TYPE);
1497}
1498
1499
1500
1501
1502
1503
1504
1505static int set_notification(struct ioc4_port *port, int mask, int set_on)
1506{
1507 struct hooks *hooks = port->ip_hooks;
1508 uint32_t intrbits, sscrbits;
1509
1510 BUG_ON(!mask);
1511
1512 intrbits = sscrbits = 0;
1513
1514 if (mask & N_DATA_READY)
1515 intrbits |= (hooks->intr_rx_timer | hooks->intr_rx_high);
1516 if (mask & N_OUTPUT_LOWAT)
1517 intrbits |= hooks->intr_tx_explicit;
1518 if (mask & N_DDCD) {
1519 intrbits |= hooks->intr_delta_dcd;
1520 sscrbits |= IOC4_SSCR_RX_RING_DCD;
1521 }
1522 if (mask & N_DCTS)
1523 intrbits |= hooks->intr_delta_cts;
1524
1525 if (set_on) {
1526 enable_intrs(port, intrbits);
1527 port->ip_notify |= mask;
1528 port->ip_sscr |= sscrbits;
1529 } else {
1530 disable_intrs(port, intrbits);
1531 port->ip_notify &= ~mask;
1532 port->ip_sscr &= ~sscrbits;
1533 }
1534
1535
1536
1537
1538
1539 if (port->ip_notify & (N_DATA_READY | N_DDCD))
1540 port->ip_sscr |= IOC4_SSCR_DMA_EN;
1541 else if (!(port->ip_ienb & hooks->intr_tx_mt))
1542 port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
1543
1544 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1545 return 0;
1546}
1547
1548
1549
1550
1551
1552
1553
1554static inline int set_mcr(struct uart_port *the_port,
1555 int mask1, int mask2)
1556{
1557 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1558 uint32_t shadow;
1559 int spiniter = 0;
1560 char mcr;
1561
1562 if (!port)
1563 return -1;
1564
1565
1566 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
1567 writel(port->ip_sscr | IOC4_SSCR_DMA_PAUSE,
1568 &port->ip_serial_regs->sscr);
1569 while ((readl(&port->ip_serial_regs->sscr)
1570 & IOC4_SSCR_PAUSE_STATE) == 0) {
1571 spiniter++;
1572 if (spiniter > MAXITER)
1573 return -1;
1574 }
1575 }
1576 shadow = readl(&port->ip_serial_regs->shadow);
1577 mcr = (shadow & 0xff000000) >> 24;
1578
1579
1580 mcr |= mask1;
1581 shadow |= mask2;
1582
1583 writeb(mcr, &port->ip_uart_regs->i4u_mcr);
1584 writel(shadow, &port->ip_serial_regs->shadow);
1585
1586
1587 if (port->ip_sscr & IOC4_SSCR_DMA_EN) {
1588 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1589 }
1590 return 0;
1591}
1592
1593
1594
1595
1596
1597
1598static int ioc4_set_proto(struct ioc4_port *port, int proto)
1599{
1600 struct hooks *hooks = port->ip_hooks;
1601
1602 switch (proto) {
1603 case PROTO_RS232:
1604
1605 writel(0, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw));
1606 break;
1607
1608 case PROTO_RS422:
1609
1610 writel(1, (&port->ip_mem->gppr[hooks->rs422_select_pin].raw));
1611 break;
1612
1613 default:
1614 return 1;
1615 }
1616 return 0;
1617}
1618
1619
1620
1621
1622
1623static void transmit_chars(struct uart_port *the_port)
1624{
1625 int xmit_count, tail, head;
1626 int result;
1627 char *start;
1628 struct tty_struct *tty;
1629 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1630 struct uart_info *info;
1631
1632 if (!the_port)
1633 return;
1634 if (!port)
1635 return;
1636
1637 info = the_port->info;
1638 tty = info->port.tty;
1639
1640 if (uart_circ_empty(&info->xmit) || uart_tx_stopped(the_port)) {
1641
1642 set_notification(port, N_ALL_OUTPUT, 0);
1643 return;
1644 }
1645
1646 head = info->xmit.head;
1647 tail = info->xmit.tail;
1648 start = (char *)&info->xmit.buf[tail];
1649
1650
1651 xmit_count = (head < tail) ? (UART_XMIT_SIZE - tail) : (head - tail);
1652 if (xmit_count > 0) {
1653 result = do_write(port, start, xmit_count);
1654 if (result > 0) {
1655
1656 xmit_count -= result;
1657 the_port->icount.tx += result;
1658
1659 tail += result;
1660 tail &= UART_XMIT_SIZE - 1;
1661 info->xmit.tail = tail;
1662 start = (char *)&info->xmit.buf[tail];
1663 }
1664 }
1665 if (uart_circ_chars_pending(&info->xmit) < WAKEUP_CHARS)
1666 uart_write_wakeup(the_port);
1667
1668 if (uart_circ_empty(&info->xmit)) {
1669 set_notification(port, N_OUTPUT_LOWAT, 0);
1670 } else {
1671 set_notification(port, N_OUTPUT_LOWAT, 1);
1672 }
1673}
1674
1675
1676
1677
1678
1679
1680
1681static void
1682ioc4_change_speed(struct uart_port *the_port,
1683 struct ktermios *new_termios, struct ktermios *old_termios)
1684{
1685 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1686 int baud, bits;
1687 unsigned cflag;
1688 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
1689 struct uart_info *info = the_port->info;
1690
1691 cflag = new_termios->c_cflag;
1692
1693 switch (cflag & CSIZE) {
1694 case CS5:
1695 new_data = 5;
1696 bits = 7;
1697 break;
1698 case CS6:
1699 new_data = 6;
1700 bits = 8;
1701 break;
1702 case CS7:
1703 new_data = 7;
1704 bits = 9;
1705 break;
1706 case CS8:
1707 new_data = 8;
1708 bits = 10;
1709 break;
1710 default:
1711
1712 new_data = 5;
1713 bits = 7;
1714 break;
1715 }
1716 if (cflag & CSTOPB) {
1717 bits++;
1718 new_stop = 1;
1719 }
1720 if (cflag & PARENB) {
1721 bits++;
1722 new_parity_enable = 1;
1723 if (cflag & PARODD)
1724 new_parity = 1;
1725 }
1726 baud = uart_get_baud_rate(the_port, new_termios, old_termios,
1727 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED);
1728 DPRINT_CONFIG(("%s: returned baud %d\n", __func__, baud));
1729
1730
1731 if (!baud)
1732 baud = 9600;
1733
1734 if (!the_port->fifosize)
1735 the_port->fifosize = IOC4_FIFO_CHARS;
1736 the_port->timeout = ((the_port->fifosize * HZ * bits) / (baud / 10));
1737 the_port->timeout += HZ / 50;
1738
1739 the_port->ignore_status_mask = N_ALL_INPUT;
1740
1741 info->port.tty->low_latency = 1;
1742
1743 if (I_IGNPAR(info->port.tty))
1744 the_port->ignore_status_mask &= ~(N_PARITY_ERROR
1745 | N_FRAMING_ERROR);
1746 if (I_IGNBRK(info->port.tty)) {
1747 the_port->ignore_status_mask &= ~N_BREAK;
1748 if (I_IGNPAR(info->port.tty))
1749 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR;
1750 }
1751 if (!(cflag & CREAD)) {
1752
1753 the_port->ignore_status_mask &= ~N_DATA_READY;
1754 }
1755
1756 if (cflag & CRTSCTS) {
1757 port->ip_sscr |= IOC4_SSCR_HFC_EN;
1758 }
1759 else {
1760 port->ip_sscr &= ~IOC4_SSCR_HFC_EN;
1761 }
1762 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1763
1764
1765 DPRINT_CONFIG(("%s : port 0x%p cflag 0%o "
1766 "config_port(baud %d data %d stop %d p enable %d parity %d),"
1767 " notification 0x%x\n",
1768 __func__, (void *)port, cflag, baud, new_data, new_stop,
1769 new_parity_enable, new_parity, the_port->ignore_status_mask));
1770
1771 if ((config_port(port, baud,
1772 new_data,
1773 new_stop,
1774 new_parity_enable,
1775 new_parity)) >= 0) {
1776 set_notification(port, the_port->ignore_status_mask, 1);
1777 }
1778}
1779
1780
1781
1782
1783
1784static inline int ic4_startup_local(struct uart_port *the_port)
1785{
1786 struct ioc4_port *port;
1787 struct uart_info *info;
1788
1789 if (!the_port)
1790 return -1;
1791
1792 port = get_ioc4_port(the_port, 0);
1793 if (!port)
1794 return -1;
1795
1796 info = the_port->info;
1797
1798 local_open(port);
1799
1800
1801 ioc4_set_proto(port, the_port->mapbase);
1802
1803
1804 ioc4_change_speed(the_port, info->port.tty->termios,
1805 (struct ktermios *)0);
1806
1807 return 0;
1808}
1809
1810
1811
1812
1813
1814static void ioc4_cb_output_lowat(struct uart_port *the_port)
1815{
1816 unsigned long pflags;
1817
1818
1819 if (the_port) {
1820 spin_lock_irqsave(&the_port->lock, pflags);
1821 transmit_chars(the_port);
1822 spin_unlock_irqrestore(&the_port->lock, pflags);
1823 }
1824}
1825
1826
1827
1828
1829
1830
1831
1832static void handle_intr(void *arg, uint32_t sio_ir)
1833{
1834 struct ioc4_port *port = (struct ioc4_port *)arg;
1835 struct hooks *hooks = port->ip_hooks;
1836 unsigned int rx_high_rd_aborted = 0;
1837 unsigned long flags;
1838 struct uart_port *the_port;
1839 int loop_counter;
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855 sio_ir &= ~(hooks->intr_tx_mt);
1856
1857 spin_lock_irqsave(&port->ip_lock, flags);
1858
1859 loop_counter = MAXITER;
1860
1861 do {
1862 uint32_t shadow;
1863
1864 if ( loop_counter-- <= 0 ) {
1865 printk(KERN_WARNING "IOC4 serial: "
1866 "possible hang condition/"
1867 "port stuck on interrupt.\n");
1868 break;
1869 }
1870
1871
1872 if (sio_ir & hooks->intr_delta_dcd) {
1873
1874 writel(hooks->intr_delta_dcd,
1875 &port->ip_mem->sio_ir.raw);
1876
1877 shadow = readl(&port->ip_serial_regs->shadow);
1878
1879 if ((port->ip_notify & N_DDCD)
1880 && (shadow & IOC4_SHADOW_DCD)
1881 && (port->ip_port)) {
1882 the_port = port->ip_port;
1883 the_port->icount.dcd = 1;
1884 wake_up_interruptible
1885 (&the_port-> info->delta_msr_wait);
1886 } else if ((port->ip_notify & N_DDCD)
1887 && !(shadow & IOC4_SHADOW_DCD)) {
1888
1889 port->ip_flags |= DCD_ON;
1890 }
1891 }
1892
1893
1894 if (sio_ir & hooks->intr_delta_cts) {
1895
1896 writel(hooks->intr_delta_cts,
1897 &port->ip_mem->sio_ir.raw);
1898
1899 shadow = readl(&port->ip_serial_regs->shadow);
1900
1901 if ((port->ip_notify & N_DCTS)
1902 && (port->ip_port)) {
1903 the_port = port->ip_port;
1904 the_port->icount.cts =
1905 (shadow & IOC4_SHADOW_CTS) ? 1 : 0;
1906 wake_up_interruptible
1907 (&the_port->info->delta_msr_wait);
1908 }
1909 }
1910
1911
1912
1913
1914
1915 if (sio_ir & hooks->intr_rx_timer) {
1916
1917 writel(hooks->intr_rx_timer,
1918 &port->ip_mem->sio_ir.raw);
1919
1920 if ((port->ip_notify & N_DATA_READY)
1921 && (port->ip_port)) {
1922
1923 receive_chars(port->ip_port);
1924 }
1925 }
1926
1927
1928 else if (sio_ir & hooks->intr_rx_high) {
1929
1930 if ((port->ip_notify & N_DATA_READY)
1931 && port->ip_port) {
1932
1933 receive_chars(port->ip_port);
1934 }
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945 if ((sio_ir = PENDING(port)) & hooks->intr_rx_high) {
1946 if ((port->ip_flags & READ_ABORTED) == 0) {
1947 port->ip_ienb &= ~hooks->intr_rx_high;
1948 port->ip_flags |= INPUT_HIGH;
1949 } else {
1950 rx_high_rd_aborted++;
1951 }
1952 }
1953 }
1954
1955
1956
1957
1958
1959 if (sio_ir & hooks->intr_tx_explicit) {
1960 port->ip_flags &= ~LOWAT_WRITTEN;
1961
1962
1963 writel(hooks->intr_tx_explicit,
1964 &port->ip_mem->sio_ir.raw);
1965
1966 if (port->ip_notify & N_OUTPUT_LOWAT)
1967 ioc4_cb_output_lowat(port->ip_port);
1968 }
1969
1970
1971 else if (sio_ir & hooks->intr_tx_mt) {
1972
1973
1974
1975
1976
1977
1978
1979 if (port->ip_notify & N_OUTPUT_LOWAT) {
1980 ioc4_cb_output_lowat(port->ip_port);
1981
1982
1983
1984
1985
1986 sio_ir = PENDING(port);
1987 }
1988
1989
1990
1991
1992 if (sio_ir & hooks->intr_tx_mt) {
1993
1994
1995
1996
1997
1998
1999 if (!(port->ip_notify
2000 & (N_DATA_READY | N_DDCD))) {
2001 BUG_ON(!(port->ip_sscr
2002 & IOC4_SSCR_DMA_EN));
2003 port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
2004 writel(port->ip_sscr,
2005 &port->ip_serial_regs->sscr);
2006 }
2007
2008
2009 port->ip_ienb &= ~hooks->intr_tx_mt;
2010 }
2011 }
2012 sio_ir = PENDING(port);
2013
2014
2015
2016
2017
2018 if (rx_high_rd_aborted && (sio_ir == hooks->intr_rx_high)) {
2019 sio_ir &= ~hooks->intr_rx_high;
2020 }
2021 } while (sio_ir & hooks->intr_all);
2022
2023 spin_unlock_irqrestore(&port->ip_lock, flags);
2024
2025
2026
2027
2028
2029
2030 write_ireg(port->ip_ioc4_soft, port->ip_ienb, IOC4_W_IES,
2031 IOC4_SIO_INTR_TYPE);
2032}
2033
2034
2035
2036
2037
2038
2039static void ioc4_cb_post_ncs(struct uart_port *the_port, int ncs)
2040{
2041 struct uart_icount *icount;
2042
2043 icount = &the_port->icount;
2044
2045 if (ncs & NCS_BREAK)
2046 icount->brk++;
2047 if (ncs & NCS_FRAMING)
2048 icount->frame++;
2049 if (ncs & NCS_OVERRUN)
2050 icount->overrun++;
2051 if (ncs & NCS_PARITY)
2052 icount->parity++;
2053}
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063static inline int do_read(struct uart_port *the_port, unsigned char *buf,
2064 int len)
2065{
2066 int prod_ptr, cons_ptr, total;
2067 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2068 struct ring *inring;
2069 struct ring_entry *entry;
2070 struct hooks *hooks = port->ip_hooks;
2071 int byte_num;
2072 char *sc;
2073 int loop_counter;
2074
2075 BUG_ON(!(len >= 0));
2076 BUG_ON(!port);
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099 writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir);
2100
2101 prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
2102 cons_ptr = port->ip_rx_cons;
2103
2104 if (prod_ptr == cons_ptr) {
2105 int reset_dma = 0;
2106
2107
2108
2109
2110 if (!(port->ip_sscr & IOC4_SSCR_DMA_EN)) {
2111 port->ip_sscr |= IOC4_SSCR_DMA_EN;
2112 reset_dma = 1;
2113 }
2114
2115
2116
2117
2118
2119
2120
2121 writel(port->ip_sscr | IOC4_SSCR_RX_DRAIN,
2122 &port->ip_serial_regs->sscr);
2123 prod_ptr = readl(&port->ip_serial_regs->srpir)
2124 & PROD_CONS_MASK;
2125
2126
2127
2128
2129
2130
2131
2132
2133 if (prod_ptr == cons_ptr) {
2134 loop_counter = 0;
2135 while (readl(&port->ip_serial_regs->sscr) &
2136 IOC4_SSCR_RX_DRAIN) {
2137 loop_counter++;
2138 if (loop_counter > MAXITER)
2139 return -1;
2140 }
2141
2142
2143
2144
2145 prod_ptr = readl(&port->ip_serial_regs->srpir)
2146 & PROD_CONS_MASK;
2147 }
2148 if (reset_dma) {
2149 port->ip_sscr &= ~IOC4_SSCR_DMA_EN;
2150 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
2151 }
2152 }
2153 inring = port->ip_inring;
2154 port->ip_flags &= ~READ_ABORTED;
2155
2156 total = 0;
2157 loop_counter = 0xfffff;
2158
2159
2160 while ((prod_ptr != cons_ptr) && (len > 0)) {
2161 entry = (struct ring_entry *)((caddr_t)inring + cons_ptr);
2162
2163 if ( loop_counter-- <= 0 ) {
2164 printk(KERN_WARNING "IOC4 serial: "
2165 "possible hang condition/"
2166 "port stuck on read.\n");
2167 break;
2168 }
2169
2170
2171
2172
2173
2174
2175 if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
2176
2177
2178
2179
2180 port->ip_flags |= READ_ABORTED;
2181 len = 0;
2182 break;
2183 }
2184
2185
2186 for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) {
2187 sc = &(entry->ring_sc[byte_num]);
2188
2189
2190 if ((*sc & IOC4_RXSB_MODEM_VALID)
2191 && (port->ip_notify & N_DDCD)) {
2192
2193
2194 if ((port->ip_flags & DCD_ON)
2195 && !(*sc & IOC4_RXSB_DCD)) {
2196
2197
2198
2199
2200
2201
2202
2203
2204 if (total > 0) {
2205 len = 0;
2206 break;
2207 }
2208 port->ip_flags &= ~DCD_ON;
2209
2210
2211
2212
2213
2214 *sc &= ~IOC4_RXSB_MODEM_VALID;
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224 if ((entry->ring_allsc & RING_ANY_VALID)
2225 == 0) {
2226 cons_ptr += (int)sizeof
2227 (struct ring_entry);
2228 cons_ptr &= PROD_CONS_MASK;
2229 }
2230 writel(cons_ptr,
2231 &port->ip_serial_regs->srcir);
2232 port->ip_rx_cons = cons_ptr;
2233
2234
2235 if ((port->ip_notify & N_DDCD)
2236 && port->ip_port) {
2237 the_port->icount.dcd = 0;
2238 wake_up_interruptible
2239 (&the_port->info->
2240 delta_msr_wait);
2241 }
2242
2243
2244
2245
2246 return 0;
2247 }
2248 }
2249 if (*sc & IOC4_RXSB_MODEM_VALID) {
2250
2251 if ((*sc & IOC4_RXSB_OVERRUN)
2252 && (port->ip_notify & N_OVERRUN_ERROR)) {
2253 ioc4_cb_post_ncs(the_port, NCS_OVERRUN);
2254 }
2255
2256 *sc &= ~IOC4_RXSB_MODEM_VALID;
2257 }
2258
2259
2260 if ((*sc & IOC4_RXSB_DATA_VALID) &&
2261 ((*sc & (IOC4_RXSB_PAR_ERR
2262 | IOC4_RXSB_FRAME_ERR
2263 | IOC4_RXSB_BREAK))
2264 && (port->ip_notify & (N_PARITY_ERROR
2265 | N_FRAMING_ERROR
2266 | N_BREAK)))) {
2267
2268
2269
2270
2271
2272
2273
2274 if (total > 0) {
2275 len = 0;
2276 break;
2277 } else {
2278 if ((*sc & IOC4_RXSB_PAR_ERR) &&
2279 (port->ip_notify & N_PARITY_ERROR)) {
2280 ioc4_cb_post_ncs(the_port,
2281 NCS_PARITY);
2282 }
2283 if ((*sc & IOC4_RXSB_FRAME_ERR) &&
2284 (port->ip_notify & N_FRAMING_ERROR)){
2285 ioc4_cb_post_ncs(the_port,
2286 NCS_FRAMING);
2287 }
2288 if ((*sc & IOC4_RXSB_BREAK)
2289 && (port->ip_notify & N_BREAK)) {
2290 ioc4_cb_post_ncs
2291 (the_port,
2292 NCS_BREAK);
2293 }
2294 len = 1;
2295 }
2296 }
2297 if (*sc & IOC4_RXSB_DATA_VALID) {
2298 *sc &= ~IOC4_RXSB_DATA_VALID;
2299 *buf = entry->ring_data[byte_num];
2300 buf++;
2301 len--;
2302 total++;
2303 }
2304 }
2305
2306
2307
2308
2309
2310
2311 if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
2312 cons_ptr += (int)sizeof(struct ring_entry);
2313 cons_ptr &= PROD_CONS_MASK;
2314 }
2315 }
2316
2317
2318 writel(cons_ptr, &port->ip_serial_regs->srcir);
2319 port->ip_rx_cons = cons_ptr;
2320
2321
2322
2323
2324 if ((port->ip_flags & INPUT_HIGH) && (((prod_ptr - cons_ptr)
2325 & PROD_CONS_MASK) < ((port->ip_sscr &
2326 IOC4_SSCR_RX_THRESHOLD)
2327 << IOC4_PROD_CONS_PTR_OFF))) {
2328 port->ip_flags &= ~INPUT_HIGH;
2329 enable_intrs(port, hooks->intr_rx_high);
2330 }
2331 return total;
2332}
2333
2334
2335
2336
2337
2338static void receive_chars(struct uart_port *the_port)
2339{
2340 struct tty_struct *tty;
2341 unsigned char ch[IOC4_MAX_CHARS];
2342 int read_count, request_count = IOC4_MAX_CHARS;
2343 struct uart_icount *icount;
2344 struct uart_info *info = the_port->info;
2345 unsigned long pflags;
2346
2347
2348 if (!info)
2349 return;
2350 if (!info->port.tty)
2351 return;
2352
2353 spin_lock_irqsave(&the_port->lock, pflags);
2354 tty = info->port.tty;
2355
2356 request_count = tty_buffer_request_room(tty, IOC4_MAX_CHARS);
2357
2358 if (request_count > 0) {
2359 icount = &the_port->icount;
2360 read_count = do_read(the_port, ch, request_count);
2361 if (read_count > 0) {
2362 tty_insert_flip_string(tty, ch, read_count);
2363 icount->rx += read_count;
2364 }
2365 }
2366
2367 spin_unlock_irqrestore(&the_port->lock, pflags);
2368
2369 tty_flip_buffer_push(tty);
2370}
2371
2372
2373
2374
2375
2376
2377static const char *ic4_type(struct uart_port *the_port)
2378{
2379 if (the_port->mapbase == PROTO_RS232)
2380 return "SGI IOC4 Serial [rs232]";
2381 else
2382 return "SGI IOC4 Serial [rs422]";
2383}
2384
2385
2386
2387
2388
2389
2390static unsigned int ic4_tx_empty(struct uart_port *the_port)
2391{
2392 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2393 unsigned int ret = 0;
2394
2395 if (port_is_active(port, the_port)) {
2396 if (readl(&port->ip_serial_regs->shadow) & IOC4_SHADOW_TEMT)
2397 ret = TIOCSER_TEMT;
2398 }
2399 return ret;
2400}
2401
2402
2403
2404
2405
2406
2407static void ic4_stop_tx(struct uart_port *the_port)
2408{
2409 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2410
2411 if (port_is_active(port, the_port))
2412 set_notification(port, N_OUTPUT_LOWAT, 0);
2413}
2414
2415
2416
2417
2418
2419
2420static void null_void_function(struct uart_port *the_port)
2421{
2422}
2423
2424
2425
2426
2427
2428
2429static void ic4_shutdown(struct uart_port *the_port)
2430{
2431 unsigned long port_flags;
2432 struct ioc4_port *port;
2433 struct uart_info *info;
2434
2435 port = get_ioc4_port(the_port, 0);
2436 if (!port)
2437 return;
2438
2439 info = the_port->info;
2440 port->ip_port = NULL;
2441
2442 wake_up_interruptible(&info->delta_msr_wait);
2443
2444 if (info->port.tty)
2445 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
2446
2447 spin_lock_irqsave(&the_port->lock, port_flags);
2448 set_notification(port, N_ALL, 0);
2449 port->ip_flags = PORT_INACTIVE;
2450 spin_unlock_irqrestore(&the_port->lock, port_flags);
2451}
2452
2453
2454
2455
2456
2457
2458
2459static void ic4_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
2460{
2461 unsigned char mcr = 0;
2462 struct ioc4_port *port;
2463
2464 port = get_ioc4_port(the_port, 0);
2465 if (!port_is_active(port, the_port))
2466 return;
2467
2468 if (mctrl & TIOCM_RTS)
2469 mcr |= UART_MCR_RTS;
2470 if (mctrl & TIOCM_DTR)
2471 mcr |= UART_MCR_DTR;
2472 if (mctrl & TIOCM_OUT1)
2473 mcr |= UART_MCR_OUT1;
2474 if (mctrl & TIOCM_OUT2)
2475 mcr |= UART_MCR_OUT2;
2476 if (mctrl & TIOCM_LOOP)
2477 mcr |= UART_MCR_LOOP;
2478
2479 set_mcr(the_port, mcr, IOC4_SHADOW_DTR);
2480}
2481
2482
2483
2484
2485
2486
2487static unsigned int ic4_get_mctrl(struct uart_port *the_port)
2488{
2489 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2490 uint32_t shadow;
2491 unsigned int ret = 0;
2492
2493 if (!port_is_active(port, the_port))
2494 return 0;
2495
2496 shadow = readl(&port->ip_serial_regs->shadow);
2497 if (shadow & IOC4_SHADOW_DCD)
2498 ret |= TIOCM_CAR;
2499 if (shadow & IOC4_SHADOW_DR)
2500 ret |= TIOCM_DSR;
2501 if (shadow & IOC4_SHADOW_CTS)
2502 ret |= TIOCM_CTS;
2503 return ret;
2504}
2505
2506
2507
2508
2509
2510
2511static void ic4_start_tx(struct uart_port *the_port)
2512{
2513 struct ioc4_port *port = get_ioc4_port(the_port, 0);
2514
2515 if (port_is_active(port, the_port)) {
2516 set_notification(port, N_OUTPUT_LOWAT, 1);
2517 enable_intrs(port, port->ip_hooks->intr_tx_mt);
2518 }
2519}
2520
2521
2522
2523
2524
2525
2526
2527static void ic4_break_ctl(struct uart_port *the_port, int break_state)
2528{
2529}
2530
2531
2532
2533
2534
2535
2536static int ic4_startup(struct uart_port *the_port)
2537{
2538 int retval;
2539 struct ioc4_port *port;
2540 struct ioc4_control *control;
2541 struct uart_info *info;
2542 unsigned long port_flags;
2543
2544 if (!the_port)
2545 return -ENODEV;
2546 port = get_ioc4_port(the_port, 1);
2547 if (!port)
2548 return -ENODEV;
2549 info = the_port->info;
2550
2551 control = port->ip_control;
2552 if (!control) {
2553 port->ip_port = NULL;
2554 return -ENODEV;
2555 }
2556
2557
2558 spin_lock_irqsave(&the_port->lock, port_flags);
2559 retval = ic4_startup_local(the_port);
2560 spin_unlock_irqrestore(&the_port->lock, port_flags);
2561 return retval;
2562}
2563
2564
2565
2566
2567
2568
2569
2570
2571static void
2572ic4_set_termios(struct uart_port *the_port,
2573 struct ktermios *termios, struct ktermios *old_termios)
2574{
2575 unsigned long port_flags;
2576
2577 spin_lock_irqsave(&the_port->lock, port_flags);
2578 ioc4_change_speed(the_port, termios, old_termios);
2579 spin_unlock_irqrestore(&the_port->lock, port_flags);
2580}
2581
2582
2583
2584
2585
2586
2587static int ic4_request_port(struct uart_port *port)
2588{
2589 return 0;
2590}
2591
2592
2593
2594static struct uart_ops ioc4_ops = {
2595 .tx_empty = ic4_tx_empty,
2596 .set_mctrl = ic4_set_mctrl,
2597 .get_mctrl = ic4_get_mctrl,
2598 .stop_tx = ic4_stop_tx,
2599 .start_tx = ic4_start_tx,
2600 .stop_rx = null_void_function,
2601 .enable_ms = null_void_function,
2602 .break_ctl = ic4_break_ctl,
2603 .startup = ic4_startup,
2604 .shutdown = ic4_shutdown,
2605 .set_termios = ic4_set_termios,
2606 .type = ic4_type,
2607 .release_port = null_void_function,
2608 .request_port = ic4_request_port,
2609};
2610
2611
2612
2613
2614
2615static struct uart_driver ioc4_uart_rs232 = {
2616 .owner = THIS_MODULE,
2617 .driver_name = "ioc4_serial_rs232",
2618 .dev_name = DEVICE_NAME_RS232,
2619 .major = DEVICE_MAJOR,
2620 .minor = DEVICE_MINOR_RS232,
2621 .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS,
2622};
2623
2624static struct uart_driver ioc4_uart_rs422 = {
2625 .owner = THIS_MODULE,
2626 .driver_name = "ioc4_serial_rs422",
2627 .dev_name = DEVICE_NAME_RS422,
2628 .major = DEVICE_MAJOR,
2629 .minor = DEVICE_MINOR_RS422,
2630 .nr = IOC4_NUM_CARDS * IOC4_NUM_SERIAL_PORTS,
2631};
2632
2633
2634
2635
2636
2637
2638
2639
2640static int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
2641{
2642 int port_num, port_type;
2643 struct ioc4_control *control;
2644 struct uart_port *the_port;
2645 struct ioc4_port *port;
2646 struct ioc4_soft *soft;
2647
2648
2649 control = idd->idd_serial_data;
2650 if (!control)
2651 return 0;
2652
2653 for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) {
2654 for (port_type = UART_PORT_MIN;
2655 port_type < UART_PORT_COUNT;
2656 port_type++) {
2657 the_port = &control->ic_port[port_num].icp_uart_port
2658 [port_type];
2659 if (the_port) {
2660 switch (port_type) {
2661 case UART_PORT_RS422:
2662 uart_remove_one_port(&ioc4_uart_rs422,
2663 the_port);
2664 break;
2665 default:
2666 case UART_PORT_RS232:
2667 uart_remove_one_port(&ioc4_uart_rs232,
2668 the_port);
2669 break;
2670 }
2671 }
2672 }
2673 port = control->ic_port[port_num].icp_port;
2674
2675 if (!(port_num & 1) && port) {
2676 pci_free_consistent(port->ip_pdev,
2677 TOTAL_RING_BUF_SIZE,
2678 port->ip_cpu_ringbuf,
2679 port->ip_dma_ringbuf);
2680 kfree(port);
2681 }
2682 }
2683 soft = control->ic_soft;
2684 if (soft) {
2685 free_irq(control->ic_irq, soft);
2686 if (soft->is_ioc4_serial_addr) {
2687 iounmap(soft->is_ioc4_serial_addr);
2688 release_mem_region((unsigned long)
2689 soft->is_ioc4_serial_addr,
2690 sizeof(struct ioc4_serial));
2691 }
2692 kfree(soft);
2693 }
2694 kfree(control);
2695 idd->idd_serial_data = NULL;
2696
2697 return 0;
2698}
2699
2700
2701
2702
2703
2704
2705
2706static inline int
2707ioc4_serial_core_attach(struct pci_dev *pdev, int port_type)
2708{
2709 struct ioc4_port *port;
2710 struct uart_port *the_port;
2711 struct ioc4_driver_data *idd = pci_get_drvdata(pdev);
2712 struct ioc4_control *control = idd->idd_serial_data;
2713 int port_num;
2714 int port_type_idx;
2715 struct uart_driver *u_driver;
2716
2717
2718 DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n",
2719 __func__, pdev, (void *)control));
2720
2721 if (!control)
2722 return -ENODEV;
2723
2724 port_type_idx = (port_type == PROTO_RS232) ? UART_PORT_RS232
2725 : UART_PORT_RS422;
2726
2727 u_driver = (port_type == PROTO_RS232) ? &ioc4_uart_rs232
2728 : &ioc4_uart_rs422;
2729
2730
2731 for (port_num = 0; port_num < IOC4_NUM_SERIAL_PORTS; port_num++) {
2732 the_port = &control->ic_port[port_num].icp_uart_port
2733 [port_type_idx];
2734 port = control->ic_port[port_num].icp_port;
2735 port->ip_all_ports[port_type_idx] = the_port;
2736
2737 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p : type %s\n",
2738 __func__, (void *)the_port,
2739 (void *)port,
2740 port_type == PROTO_RS232 ? "rs232" : "rs422"));
2741
2742
2743 the_port->membase = (unsigned char __iomem *)1;
2744 the_port->iobase = (pdev->bus->number << 16) | port_num;
2745 the_port->line = (Num_of_ioc4_cards << 2) | port_num;
2746 the_port->mapbase = port_type;
2747 the_port->type = PORT_16550A;
2748 the_port->fifosize = IOC4_FIFO_CHARS;
2749 the_port->ops = &ioc4_ops;
2750 the_port->irq = control->ic_irq;
2751 the_port->dev = &pdev->dev;
2752 spin_lock_init(&the_port->lock);
2753 if (uart_add_one_port(u_driver, the_port) < 0) {
2754 printk(KERN_WARNING
2755 "%s: unable to add port %d bus %d\n",
2756 __func__, the_port->line, pdev->bus->number);
2757 } else {
2758 DPRINT_CONFIG(
2759 ("IOC4 serial port %d irq = %d, bus %d\n",
2760 the_port->line, the_port->irq, pdev->bus->number));
2761 }
2762 }
2763 return 0;
2764}
2765
2766
2767
2768
2769
2770
2771int
2772ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2773{
2774 unsigned long tmp_addr1;
2775 struct ioc4_serial __iomem *serial;
2776 struct ioc4_soft *soft;
2777 struct ioc4_control *control;
2778 int ret = 0;
2779
2780
2781 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, idd->idd_pdev,
2782 idd->idd_pci_id));
2783
2784
2785
2786
2787 if (idd->idd_variant == IOC4_VARIANT_PCI_RT)
2788 return 0;
2789
2790
2791 tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET;
2792
2793 if (!request_mem_region(tmp_addr1, sizeof(struct ioc4_serial),
2794 "sioc4_uart")) {
2795 printk(KERN_WARNING
2796 "ioc4 (%p): unable to get request region for "
2797 "uart space\n", (void *)idd->idd_pdev);
2798 ret = -ENODEV;
2799 goto out1;
2800 }
2801 serial = ioremap(tmp_addr1, sizeof(struct ioc4_serial));
2802 if (!serial) {
2803 printk(KERN_WARNING
2804 "ioc4 (%p) : unable to remap ioc4 serial register\n",
2805 (void *)idd->idd_pdev);
2806 ret = -ENODEV;
2807 goto out2;
2808 }
2809 DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n",
2810 __func__, (void *)idd->idd_misc_regs,
2811 (void *)serial));
2812
2813
2814 control = kzalloc(sizeof(struct ioc4_control), GFP_KERNEL);
2815
2816 if (!control) {
2817 printk(KERN_WARNING "ioc4_attach_one"
2818 ": unable to get memory for the IOC4\n");
2819 ret = -ENOMEM;
2820 goto out2;
2821 }
2822 idd->idd_serial_data = control;
2823
2824
2825 soft = kzalloc(sizeof(struct ioc4_soft), GFP_KERNEL);
2826 if (!soft) {
2827 printk(KERN_WARNING
2828 "ioc4 (%p): unable to get memory for the soft struct\n",
2829 (void *)idd->idd_pdev);
2830 ret = -ENOMEM;
2831 goto out3;
2832 }
2833
2834 spin_lock_init(&soft->is_ir_lock);
2835 soft->is_ioc4_misc_addr = idd->idd_misc_regs;
2836 soft->is_ioc4_serial_addr = serial;
2837
2838
2839 writel(0xf << IOC4_SIO_CR_CMD_PULSE_SHIFT,
2840 &idd->idd_misc_regs->sio_cr.raw);
2841
2842
2843 writel(IOC4_GPCR_UART0_MODESEL | IOC4_GPCR_UART1_MODESEL
2844 | IOC4_GPCR_UART2_MODESEL | IOC4_GPCR_UART3_MODESEL,
2845 &idd->idd_misc_regs->gpcr_s.raw);
2846
2847
2848 write_ireg(soft, ~0, IOC4_W_IEC, IOC4_SIO_INTR_TYPE);
2849 writel(~0, &idd->idd_misc_regs->sio_ir.raw);
2850 write_ireg(soft, IOC4_OTHER_IR_SER_MEMERR, IOC4_W_IEC,
2851 IOC4_OTHER_INTR_TYPE);
2852 writel(IOC4_OTHER_IR_SER_MEMERR, &idd->idd_misc_regs->other_ir.raw);
2853 control->ic_soft = soft;
2854
2855
2856 if (!request_irq(idd->idd_pdev->irq, ioc4_intr, IRQF_SHARED,
2857 "sgi-ioc4serial", soft)) {
2858 control->ic_irq = idd->idd_pdev->irq;
2859 } else {
2860 printk(KERN_WARNING
2861 "%s : request_irq fails for IRQ 0x%x\n ",
2862 __func__, idd->idd_pdev->irq);
2863 }
2864 ret = ioc4_attach_local(idd);
2865 if (ret)
2866 goto out4;
2867
2868
2869
2870 if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS232)))
2871 goto out4;
2872
2873 if ((ret = ioc4_serial_core_attach(idd->idd_pdev, PROTO_RS422)))
2874 goto out5;
2875
2876 Num_of_ioc4_cards++;
2877
2878 return ret;
2879
2880
2881out5:
2882 ioc4_serial_remove_one(idd);
2883out4:
2884 kfree(soft);
2885out3:
2886 kfree(control);
2887out2:
2888 if (serial)
2889 iounmap(serial);
2890 release_mem_region(tmp_addr1, sizeof(struct ioc4_serial));
2891out1:
2892
2893 return ret;
2894}
2895
2896
2897static struct ioc4_submodule ioc4_serial_submodule = {
2898 .is_name = "IOC4_serial",
2899 .is_owner = THIS_MODULE,
2900 .is_probe = ioc4_serial_attach_one,
2901 .is_remove = ioc4_serial_remove_one,
2902};
2903
2904
2905
2906
2907int ioc4_serial_init(void)
2908{
2909 int ret;
2910
2911
2912 if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) {
2913 printk(KERN_WARNING
2914 "%s: Couldn't register rs232 IOC4 serial driver\n",
2915 __func__);
2916 return ret;
2917 }
2918 if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) {
2919 printk(KERN_WARNING
2920 "%s: Couldn't register rs422 IOC4 serial driver\n",
2921 __func__);
2922 return ret;
2923 }
2924
2925
2926 return ioc4_register_submodule(&ioc4_serial_submodule);
2927}
2928
2929static void __devexit ioc4_serial_exit(void)
2930{
2931 ioc4_unregister_submodule(&ioc4_serial_submodule);
2932 uart_unregister_driver(&ioc4_uart_rs232);
2933 uart_unregister_driver(&ioc4_uart_rs422);
2934}
2935
2936late_initcall(ioc4_serial_init);
2937module_exit(ioc4_serial_exit);
2938
2939MODULE_AUTHOR("Pat Gefre - Silicon Graphics Inc. (SGI) <pfg@sgi.com>");
2940MODULE_DESCRIPTION("Serial PCI driver module for SGI IOC4 Base-IO Card");
2941MODULE_LICENSE("GPL");
2942