1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/errno.h>
15#include <linux/tty.h>
16#include <linux/serial.h>
17#include <linux/circ_buf.h>
18#include <linux/serial_reg.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/serial_core.h>
22#include <linux/ioc3.h>
23
24
25
26
27
28#define LOGICAL_PORTS 2
29#define PORTS_PER_CARD 2
30#define LOGICAL_PORTS_PER_CARD (PORTS_PER_CARD * LOGICAL_PORTS)
31#define MAX_CARDS 8
32#define MAX_LOGICAL_PORTS (LOGICAL_PORTS_PER_CARD * MAX_CARDS)
33
34
35#define GET_PORT_FROM_SIO_IR(_x) (_x & SIO_IR_SA) ? 0 : 1
36
37
38
39
40
41
42#define GET_PHYSICAL_PORT(_x) ((_x) >> 1)
43#define GET_LOGICAL_PORT(_x) ((_x) & 1)
44#define IS_PHYSICAL_PORT(_x) !((_x) & 1)
45#define IS_RS232(_x) !((_x) & 1)
46
47static unsigned int Num_of_ioc3_cards;
48static unsigned int Submodule_slot;
49
50
51
52#define DPRINT_CONFIG(_x...) ;
53
54#define NOT_PROGRESS() ;
55
56
57
58#define MAX_CHARS 256
59#define FIFO_SIZE (MAX_CHARS-1)
60
61
62#define DEVICE_NAME "ttySIOC"
63#define DEVICE_MAJOR 204
64#define DEVICE_MINOR 116
65
66
67#define NCS_BREAK 0x1
68#define NCS_PARITY 0x2
69#define NCS_FRAMING 0x4
70#define NCS_OVERRUN 0x8
71
72
73#define MIN_BAUD_SUPPORTED 1200
74#define MAX_BAUD_SUPPORTED 115200
75
76
77#define PROTO_RS232 0
78#define PROTO_RS422 1
79
80
81#define N_DATA_READY 0x01
82#define N_OUTPUT_LOWAT 0x02
83#define N_BREAK 0x04
84#define N_PARITY_ERROR 0x08
85#define N_FRAMING_ERROR 0x10
86#define N_OVERRUN_ERROR 0x20
87#define N_DDCD 0x40
88#define N_DCTS 0x80
89
90#define N_ALL_INPUT (N_DATA_READY | N_BREAK \
91 | N_PARITY_ERROR | N_FRAMING_ERROR \
92 | N_OVERRUN_ERROR | N_DDCD | N_DCTS)
93
94#define N_ALL_OUTPUT N_OUTPUT_LOWAT
95
96#define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR \
97 | N_OVERRUN_ERROR)
98
99#define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK \
100 | N_PARITY_ERROR | N_FRAMING_ERROR \
101 | N_OVERRUN_ERROR | N_DDCD | N_DCTS)
102
103#define SER_CLK_SPEED(prediv) ((22000000 << 1) / prediv)
104#define SER_DIVISOR(x, clk) (((clk) + (x) * 8) / ((x) * 16))
105#define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div))
106
107
108#define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \
109 | UART_LCR_WLEN7 | UART_LCR_WLEN8)
110#define LCR_MASK_STOP_BITS (UART_LCR_STOP)
111
112#define PENDING(_a, _p) (readl(&(_p)->vma->sio_ir) & (_a)->ic_enable)
113
114#define RING_BUF_SIZE 4096
115#define BUF_SIZE_BIT SBBR_L_SIZE
116#define PROD_CONS_MASK PROD_CONS_PTR_4K
117
118#define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4)
119
120
121struct ioc3_card {
122 struct {
123
124 struct uart_port icp_uart_port[LOGICAL_PORTS];
125
126 struct ioc3_port *icp_port;
127 } ic_port[PORTS_PER_CARD];
128
129 uint32_t ic_enable;
130};
131
132
133struct ioc3_port {
134
135 struct uart_port *ip_port;
136 struct ioc3_card *ip_card;
137 struct ioc3_driver_data *ip_idd;
138 struct ioc3_submodule *ip_is;
139
140
141 struct ioc3_serialregs __iomem *ip_serial_regs;
142 struct ioc3_uartregs __iomem *ip_uart_regs;
143
144
145 dma_addr_t ip_dma_ringbuf;
146
147 struct ring_buffer *ip_cpu_ringbuf;
148
149
150 struct ring *ip_inring;
151 struct ring *ip_outring;
152
153
154 struct port_hooks *ip_hooks;
155
156 spinlock_t ip_lock;
157
158
159 int ip_baud;
160 int ip_tx_lowat;
161 int ip_rx_timeout;
162
163
164 int ip_notify;
165
166
167
168
169 uint32_t ip_sscr;
170 uint32_t ip_tx_prod;
171 uint32_t ip_rx_cons;
172 unsigned char ip_flags;
173};
174
175
176
177
178
179
180#define TX_LOWAT_LATENCY 1000
181#define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY)
182#define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ)
183
184
185#define INPUT_HIGH 0x01
186
187
188
189
190#define DCD_ON 0x02
191
192#define LOWAT_WRITTEN 0x04
193#define READ_ABORTED 0x08
194
195
196
197#define INPUT_ENABLE 0x10
198
199
200
201
202
203struct port_hooks {
204 uint32_t intr_delta_dcd;
205 uint32_t intr_delta_cts;
206 uint32_t intr_tx_mt;
207 uint32_t intr_rx_timer;
208 uint32_t intr_rx_high;
209 uint32_t intr_tx_explicit;
210 uint32_t intr_clear;
211 uint32_t intr_all;
212 char rs422_select_pin;
213};
214
215static struct port_hooks hooks_array[PORTS_PER_CARD] = {
216
217 {
218 .intr_delta_dcd = SIO_IR_SA_DELTA_DCD,
219 .intr_delta_cts = SIO_IR_SA_DELTA_CTS,
220 .intr_tx_mt = SIO_IR_SA_TX_MT,
221 .intr_rx_timer = SIO_IR_SA_RX_TIMER,
222 .intr_rx_high = SIO_IR_SA_RX_HIGH,
223 .intr_tx_explicit = SIO_IR_SA_TX_EXPLICIT,
224 .intr_clear = (SIO_IR_SA_TX_MT | SIO_IR_SA_RX_FULL
225 | SIO_IR_SA_RX_HIGH
226 | SIO_IR_SA_RX_TIMER
227 | SIO_IR_SA_DELTA_DCD
228 | SIO_IR_SA_DELTA_CTS
229 | SIO_IR_SA_INT
230 | SIO_IR_SA_TX_EXPLICIT
231 | SIO_IR_SA_MEMERR),
232 .intr_all = SIO_IR_SA,
233 .rs422_select_pin = GPPR_UARTA_MODESEL_PIN,
234 },
235
236
237 {
238 .intr_delta_dcd = SIO_IR_SB_DELTA_DCD,
239 .intr_delta_cts = SIO_IR_SB_DELTA_CTS,
240 .intr_tx_mt = SIO_IR_SB_TX_MT,
241 .intr_rx_timer = SIO_IR_SB_RX_TIMER,
242 .intr_rx_high = SIO_IR_SB_RX_HIGH,
243 .intr_tx_explicit = SIO_IR_SB_TX_EXPLICIT,
244 .intr_clear = (SIO_IR_SB_TX_MT | SIO_IR_SB_RX_FULL
245 | SIO_IR_SB_RX_HIGH
246 | SIO_IR_SB_RX_TIMER
247 | SIO_IR_SB_DELTA_DCD
248 | SIO_IR_SB_DELTA_CTS
249 | SIO_IR_SB_INT
250 | SIO_IR_SB_TX_EXPLICIT
251 | SIO_IR_SB_MEMERR),
252 .intr_all = SIO_IR_SB,
253 .rs422_select_pin = GPPR_UARTB_MODESEL_PIN,
254 }
255};
256
257struct ring_entry {
258 union {
259 struct {
260 uint32_t alldata;
261 uint32_t allsc;
262 } all;
263 struct {
264 char data[4];
265 char sc[4];
266 } s;
267 } u;
268};
269
270
271#define RING_ANY_VALID \
272 ((uint32_t)(RXSB_MODEM_VALID | RXSB_DATA_VALID) * 0x01010101)
273
274#define ring_sc u.s.sc
275#define ring_data u.s.data
276#define ring_allsc u.all.allsc
277
278
279#define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry))
280
281
282struct ring {
283 struct ring_entry entries[ENTRIES_PER_RING];
284};
285
286
287struct ring_buffer {
288 struct ring TX_A;
289 struct ring RX_A;
290 struct ring TX_B;
291 struct ring RX_B;
292};
293
294
295#define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh)
296
297
298#define MAXITER 10000000
299
300
301
302
303
304
305
306static int set_baud(struct ioc3_port *port, int baud)
307{
308 int divisor;
309 int actual_baud;
310 int diff;
311 int lcr, prediv;
312 struct ioc3_uartregs __iomem *uart;
313
314 for (prediv = 6; prediv < 64; prediv++) {
315 divisor = SER_DIVISOR(baud, SER_CLK_SPEED(prediv));
316 if (!divisor)
317 continue;
318 actual_baud = DIVISOR_TO_BAUD(divisor, SER_CLK_SPEED(prediv));
319
320 diff = actual_baud - baud;
321 if (diff < 0)
322 diff = -diff;
323
324
325 if (diff * 100 <= actual_baud)
326 break;
327 }
328
329
330
331
332 if (prediv == 64) {
333 NOT_PROGRESS();
334 return 1;
335 }
336
337 uart = port->ip_uart_regs;
338 lcr = readb(&uart->iu_lcr);
339
340 writeb(lcr | UART_LCR_DLAB, &uart->iu_lcr);
341 writeb((unsigned char)divisor, &uart->iu_dll);
342 writeb((unsigned char)(divisor >> 8), &uart->iu_dlm);
343 writeb((unsigned char)prediv, &uart->iu_scr);
344 writeb((unsigned char)lcr, &uart->iu_lcr);
345
346 return 0;
347}
348
349
350
351
352
353static struct ioc3_port *get_ioc3_port(struct uart_port *the_port)
354{
355 struct ioc3_driver_data *idd = dev_get_drvdata(the_port->dev);
356 struct ioc3_card *card_ptr = idd->data[Submodule_slot];
357 int ii, jj;
358
359 if (!card_ptr) {
360 NOT_PROGRESS();
361 return NULL;
362 }
363 for (ii = 0; ii < PORTS_PER_CARD; ii++) {
364 for (jj = 0; jj < LOGICAL_PORTS; jj++) {
365 if (the_port == &card_ptr->ic_port[ii].icp_uart_port[jj])
366 return card_ptr->ic_port[ii].icp_port;
367 }
368 }
369 NOT_PROGRESS();
370 return NULL;
371}
372
373
374
375
376
377
378static int inline port_init(struct ioc3_port *port)
379{
380 uint32_t sio_cr;
381 struct port_hooks *hooks = port->ip_hooks;
382 struct ioc3_uartregs __iomem *uart;
383 int reset_loop_counter = 0xfffff;
384 struct ioc3_driver_data *idd = port->ip_idd;
385
386
387 writel(SSCR_RESET, &port->ip_serial_regs->sscr);
388
389
390 do {
391 sio_cr = readl(&idd->vma->sio_cr);
392 if (reset_loop_counter-- <= 0) {
393 printk(KERN_WARNING
394 "IOC3 unable to come out of reset"
395 " scr 0x%x\n", sio_cr);
396 return -1;
397 }
398 } while (!(sio_cr & SIO_CR_ARB_DIAG_IDLE) &&
399 (((sio_cr &= SIO_CR_ARB_DIAG) == SIO_CR_ARB_DIAG_TXA)
400 || sio_cr == SIO_CR_ARB_DIAG_TXB
401 || sio_cr == SIO_CR_ARB_DIAG_RXA
402 || sio_cr == SIO_CR_ARB_DIAG_RXB));
403
404
405 writel(0, &port->ip_serial_regs->sscr);
406
407
408
409
410 port->ip_tx_prod = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
411 writel(port->ip_tx_prod, &port->ip_serial_regs->stpir);
412 port->ip_rx_cons = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
413 writel(port->ip_rx_cons | SRCIR_ARM, &port->ip_serial_regs->srcir);
414
415
416 uart = port->ip_uart_regs;
417 writeb(0, &uart->iu_lcr);
418 writeb(0, &uart->iu_ier);
419
420
421 set_baud(port, port->ip_baud);
422
423
424 writeb(UART_LCR_WLEN8 | 0, &uart->iu_lcr);
425
426
427
428 writeb(UART_FCR_ENABLE_FIFO, &uart->iu_fcr);
429
430 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
431 &uart->iu_fcr);
432
433
434 writeb(0, &uart->iu_mcr);
435
436
437 writel(0, &port->ip_serial_regs->shadow);
438
439
440 if (port->ip_hooks == &hooks_array[0]) {
441 unsigned long ring_pci_addr;
442 uint32_t __iomem *sbbr_l, *sbbr_h;
443
444 sbbr_l = &idd->vma->sbbr_l;
445 sbbr_h = &idd->vma->sbbr_h;
446 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf;
447 DPRINT_CONFIG(("%s: ring_pci_addr 0x%p\n",
448 __func__, (void *)ring_pci_addr));
449
450 writel((unsigned int)((uint64_t) ring_pci_addr >> 32), sbbr_h);
451 writel((unsigned int)ring_pci_addr | BUF_SIZE_BIT, sbbr_l);
452 }
453
454
455 writel(SRTR_HZ / 100, &port->ip_serial_regs->srtr);
456
457
458
459 port->ip_sscr = (ENTRIES_PER_RING * 3 / 4);
460
461
462
463
464
465
466 port->ip_sscr |= SSCR_HIGH_SPD;
467
468 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
469
470
471 port->ip_card->ic_enable &= ~hooks->intr_clear;
472 ioc3_disable(port->ip_is, idd, hooks->intr_clear);
473 ioc3_ack(port->ip_is, idd, hooks->intr_clear);
474 return 0;
475}
476
477
478
479
480
481
482static void enable_intrs(struct ioc3_port *port, uint32_t mask)
483{
484 if ((port->ip_card->ic_enable & mask) != mask) {
485 port->ip_card->ic_enable |= mask;
486 ioc3_enable(port->ip_is, port->ip_idd, mask);
487 }
488}
489
490
491
492
493
494static inline int local_open(struct ioc3_port *port)
495{
496 int spiniter = 0;
497
498 port->ip_flags = INPUT_ENABLE;
499
500
501 if (port->ip_sscr & SSCR_DMA_EN) {
502 writel(port->ip_sscr | SSCR_DMA_PAUSE,
503 &port->ip_serial_regs->sscr);
504 while ((readl(&port->ip_serial_regs->sscr)
505 & SSCR_PAUSE_STATE) == 0) {
506 spiniter++;
507 if (spiniter > MAXITER) {
508 NOT_PROGRESS();
509 return -1;
510 }
511 }
512 }
513
514
515
516
517
518
519 writeb(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR,
520 &port->ip_uart_regs->iu_fcr);
521
522 writeb(UART_LCR_WLEN8, &port->ip_uart_regs->iu_lcr);
523
524
525
526
527
528 port->ip_sscr &= ~SSCR_RX_THRESHOLD;
529 port->ip_sscr |= 1;
530
531
532
533
534 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
535 port->ip_tx_lowat = 1;
536 return 0;
537}
538
539
540
541
542
543
544static inline int set_rx_timeout(struct ioc3_port *port, int timeout)
545{
546 int threshold;
547
548 port->ip_rx_timeout = timeout;
549
550
551
552
553
554
555
556
557 threshold = timeout * port->ip_baud / 4000;
558 if (threshold == 0)
559 threshold = 1;
560
561 if ((unsigned)threshold > (unsigned)SSCR_RX_THRESHOLD)
562 return 1;
563
564 port->ip_sscr &= ~SSCR_RX_THRESHOLD;
565 port->ip_sscr |= threshold;
566 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
567
568
569
570
571 timeout = timeout * SRTR_HZ / 100;
572 if (timeout > SRTR_CNT)
573 timeout = SRTR_CNT;
574 writel(timeout, &port->ip_serial_regs->srtr);
575 return 0;
576}
577
578
579
580
581
582
583
584
585
586
587static inline int
588config_port(struct ioc3_port *port,
589 int baud, int byte_size, int stop_bits, int parenb, int parodd)
590{
591 char lcr, sizebits;
592 int spiniter = 0;
593
594 DPRINT_CONFIG(("%s: line %d baud %d byte_size %d stop %d parenb %d "
595 "parodd %d\n",
596 __func__, ((struct uart_port *)port->ip_port)->line,
597 baud, byte_size, stop_bits, parenb, parodd));
598
599 if (set_baud(port, baud))
600 return 1;
601
602 switch (byte_size) {
603 case 5:
604 sizebits = UART_LCR_WLEN5;
605 break;
606 case 6:
607 sizebits = UART_LCR_WLEN6;
608 break;
609 case 7:
610 sizebits = UART_LCR_WLEN7;
611 break;
612 case 8:
613 sizebits = UART_LCR_WLEN8;
614 break;
615 default:
616 return 1;
617 }
618
619
620 if (port->ip_sscr & SSCR_DMA_EN) {
621 writel(port->ip_sscr | SSCR_DMA_PAUSE,
622 &port->ip_serial_regs->sscr);
623 while ((readl(&port->ip_serial_regs->sscr)
624 & SSCR_PAUSE_STATE) == 0) {
625 spiniter++;
626 if (spiniter > MAXITER)
627 return -1;
628 }
629 }
630
631
632 lcr = readb(&port->ip_uart_regs->iu_lcr);
633 lcr &= ~(LCR_MASK_BITS_CHAR | UART_LCR_EPAR |
634 UART_LCR_PARITY | LCR_MASK_STOP_BITS);
635
636
637 lcr |= sizebits;
638
639
640 if (parenb) {
641 lcr |= UART_LCR_PARITY;
642 if (!parodd)
643 lcr |= UART_LCR_EPAR;
644 }
645
646
647 if (stop_bits)
648 lcr |= UART_LCR_STOP ;
649
650 writeb(lcr, &port->ip_uart_regs->iu_lcr);
651
652
653 if (port->ip_sscr & SSCR_DMA_EN) {
654 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
655 }
656 port->ip_baud = baud;
657
658
659
660
661
662 port->ip_tx_lowat = (TX_LOWAT_CHARS(baud) + 3) / 4;
663 if (port->ip_tx_lowat == 0)
664 port->ip_tx_lowat = 1;
665
666 set_rx_timeout(port, 2);
667 return 0;
668}
669
670
671
672
673
674
675
676
677static inline int do_write(struct ioc3_port *port, char *buf, int len)
678{
679 int prod_ptr, cons_ptr, total = 0;
680 struct ring *outring;
681 struct ring_entry *entry;
682 struct port_hooks *hooks = port->ip_hooks;
683
684 BUG_ON(!(len >= 0));
685
686 prod_ptr = port->ip_tx_prod;
687 cons_ptr = readl(&port->ip_serial_regs->stcir) & PROD_CONS_MASK;
688 outring = port->ip_outring;
689
690
691
692
693
694 cons_ptr = (cons_ptr - (int)sizeof(struct ring_entry)) & PROD_CONS_MASK;
695
696
697 while ((prod_ptr != cons_ptr) && (len > 0)) {
698 int xx;
699
700
701 entry = (struct ring_entry *)((caddr_t) outring + prod_ptr);
702
703
704 entry->ring_allsc = 0;
705
706
707 for (xx = 0; (xx < 4) && (len > 0); xx++) {
708 entry->ring_data[xx] = *buf++;
709 entry->ring_sc[xx] = TXCB_VALID;
710 len--;
711 total++;
712 }
713
714
715
716
717
718
719
720 if (!(port->ip_flags & LOWAT_WRITTEN) &&
721 ((cons_ptr - prod_ptr) & PROD_CONS_MASK)
722 <= port->ip_tx_lowat * (int)sizeof(struct ring_entry)) {
723 port->ip_flags |= LOWAT_WRITTEN;
724 entry->ring_sc[0] |= TXCB_INT_WHEN_DONE;
725 }
726
727
728 prod_ptr += sizeof(struct ring_entry);
729 prod_ptr &= PROD_CONS_MASK;
730 }
731
732
733 if (total > 0 && !(port->ip_sscr & SSCR_DMA_EN)) {
734 port->ip_sscr |= SSCR_DMA_EN;
735 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
736 }
737
738
739
740
741 if (!uart_tx_stopped(port->ip_port)) {
742 writel(prod_ptr, &port->ip_serial_regs->stpir);
743
744
745
746
747 if (total > 0)
748 enable_intrs(port, hooks->intr_tx_mt);
749 }
750 port->ip_tx_prod = prod_ptr;
751
752 return total;
753}
754
755
756
757
758
759
760static inline void disable_intrs(struct ioc3_port *port, uint32_t mask)
761{
762 if (port->ip_card->ic_enable & mask) {
763 ioc3_disable(port->ip_is, port->ip_idd, mask);
764 port->ip_card->ic_enable &= ~mask;
765 }
766}
767
768
769
770
771
772
773
774static int set_notification(struct ioc3_port *port, int mask, int set_on)
775{
776 struct port_hooks *hooks = port->ip_hooks;
777 uint32_t intrbits, sscrbits;
778
779 BUG_ON(!mask);
780
781 intrbits = sscrbits = 0;
782
783 if (mask & N_DATA_READY)
784 intrbits |= (hooks->intr_rx_timer | hooks->intr_rx_high);
785 if (mask & N_OUTPUT_LOWAT)
786 intrbits |= hooks->intr_tx_explicit;
787 if (mask & N_DDCD) {
788 intrbits |= hooks->intr_delta_dcd;
789 sscrbits |= SSCR_RX_RING_DCD;
790 }
791 if (mask & N_DCTS)
792 intrbits |= hooks->intr_delta_cts;
793
794 if (set_on) {
795 enable_intrs(port, intrbits);
796 port->ip_notify |= mask;
797 port->ip_sscr |= sscrbits;
798 } else {
799 disable_intrs(port, intrbits);
800 port->ip_notify &= ~mask;
801 port->ip_sscr &= ~sscrbits;
802 }
803
804
805
806
807
808 if (port->ip_notify & (N_DATA_READY | N_DDCD))
809 port->ip_sscr |= SSCR_DMA_EN;
810 else if (!(port->ip_card->ic_enable & hooks->intr_tx_mt))
811 port->ip_sscr &= ~SSCR_DMA_EN;
812
813 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
814 return 0;
815}
816
817
818
819
820
821
822
823static inline int set_mcr(struct uart_port *the_port,
824 int mask1, int mask2)
825{
826 struct ioc3_port *port = get_ioc3_port(the_port);
827 uint32_t shadow;
828 int spiniter = 0;
829 char mcr;
830
831 if (!port)
832 return -1;
833
834
835 if (port->ip_sscr & SSCR_DMA_EN) {
836 writel(port->ip_sscr | SSCR_DMA_PAUSE,
837 &port->ip_serial_regs->sscr);
838 while ((readl(&port->ip_serial_regs->sscr)
839 & SSCR_PAUSE_STATE) == 0) {
840 spiniter++;
841 if (spiniter > MAXITER)
842 return -1;
843 }
844 }
845 shadow = readl(&port->ip_serial_regs->shadow);
846 mcr = (shadow & 0xff000000) >> 24;
847
848
849 mcr |= mask1;
850 shadow |= mask2;
851 writeb(mcr, &port->ip_uart_regs->iu_mcr);
852 writel(shadow, &port->ip_serial_regs->shadow);
853
854
855 if (port->ip_sscr & SSCR_DMA_EN) {
856 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
857 }
858 return 0;
859}
860
861
862
863
864
865
866static int ioc3_set_proto(struct ioc3_port *port, int proto)
867{
868 struct port_hooks *hooks = port->ip_hooks;
869
870 switch (proto) {
871 default:
872 case PROTO_RS232:
873
874 DPRINT_CONFIG(("%s: rs232\n", __func__));
875 writel(0, (&port->ip_idd->vma->gppr[0]
876 + hooks->rs422_select_pin));
877 break;
878
879 case PROTO_RS422:
880
881 DPRINT_CONFIG(("%s: rs422\n", __func__));
882 writel(1, (&port->ip_idd->vma->gppr[0]
883 + hooks->rs422_select_pin));
884 break;
885 }
886 return 0;
887}
888
889
890
891
892
893static void transmit_chars(struct uart_port *the_port)
894{
895 int xmit_count, tail, head;
896 int result;
897 char *start;
898 struct tty_struct *tty;
899 struct ioc3_port *port = get_ioc3_port(the_port);
900 struct uart_info *info;
901
902 if (!the_port)
903 return;
904 if (!port)
905 return;
906
907 info = the_port->info;
908 tty = info->port.tty;
909
910 if (uart_circ_empty(&info->xmit) || uart_tx_stopped(the_port)) {
911
912 set_notification(port, N_ALL_OUTPUT, 0);
913 return;
914 }
915
916 head = info->xmit.head;
917 tail = info->xmit.tail;
918 start = (char *)&info->xmit.buf[tail];
919
920
921 xmit_count = (head < tail) ? (UART_XMIT_SIZE - tail) : (head - tail);
922 if (xmit_count > 0) {
923 result = do_write(port, start, xmit_count);
924 if (result > 0) {
925
926 xmit_count -= result;
927 the_port->icount.tx += result;
928
929 tail += result;
930 tail &= UART_XMIT_SIZE - 1;
931 info->xmit.tail = tail;
932 start = (char *)&info->xmit.buf[tail];
933 }
934 }
935 if (uart_circ_chars_pending(&info->xmit) < WAKEUP_CHARS)
936 uart_write_wakeup(the_port);
937
938 if (uart_circ_empty(&info->xmit)) {
939 set_notification(port, N_OUTPUT_LOWAT, 0);
940 } else {
941 set_notification(port, N_OUTPUT_LOWAT, 1);
942 }
943}
944
945
946
947
948
949
950
951static void
952ioc3_change_speed(struct uart_port *the_port,
953 struct ktermios *new_termios, struct ktermios *old_termios)
954{
955 struct ioc3_port *port = get_ioc3_port(the_port);
956 unsigned int cflag;
957 int baud;
958 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
959 struct uart_info *info = the_port->info;
960
961 cflag = new_termios->c_cflag;
962
963 switch (cflag & CSIZE) {
964 case CS5:
965 new_data = 5;
966 break;
967 case CS6:
968 new_data = 6;
969 break;
970 case CS7:
971 new_data = 7;
972 break;
973 case CS8:
974 new_data = 8;
975 break;
976 default:
977
978 new_data = 5;
979 break;
980 }
981 if (cflag & CSTOPB) {
982 new_stop = 1;
983 }
984 if (cflag & PARENB) {
985 new_parity_enable = 1;
986 if (cflag & PARODD)
987 new_parity = 1;
988 }
989 baud = uart_get_baud_rate(the_port, new_termios, old_termios,
990 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED);
991 DPRINT_CONFIG(("%s: returned baud %d for line %d\n", __func__, baud,
992 the_port->line));
993
994 if (!the_port->fifosize)
995 the_port->fifosize = FIFO_SIZE;
996 uart_update_timeout(the_port, cflag, baud);
997
998 the_port->ignore_status_mask = N_ALL_INPUT;
999
1000 info->port.tty->low_latency = 1;
1001
1002 if (I_IGNPAR(info->port.tty))
1003 the_port->ignore_status_mask &= ~(N_PARITY_ERROR
1004 | N_FRAMING_ERROR);
1005 if (I_IGNBRK(info->port.tty)) {
1006 the_port->ignore_status_mask &= ~N_BREAK;
1007 if (I_IGNPAR(info->port.tty))
1008 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR;
1009 }
1010 if (!(cflag & CREAD)) {
1011
1012 the_port->ignore_status_mask &= ~N_DATA_READY;
1013 }
1014
1015 if (cflag & CRTSCTS) {
1016
1017 port->ip_sscr |= SSCR_HFC_EN;
1018 }
1019 else {
1020
1021 port->ip_sscr &= ~SSCR_HFC_EN;
1022 }
1023 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1024
1025
1026 DPRINT_CONFIG(("%s : port 0x%p line %d cflag 0%o "
1027 "config_port(baud %d data %d stop %d penable %d "
1028 " parity %d), notification 0x%x\n",
1029 __func__, (void *)port, the_port->line, cflag, baud,
1030 new_data, new_stop, new_parity_enable, new_parity,
1031 the_port->ignore_status_mask));
1032
1033 if ((config_port(port, baud,
1034 new_data,
1035 new_stop,
1036 new_parity_enable,
1037 new_parity)) >= 0) {
1038 set_notification(port, the_port->ignore_status_mask, 1);
1039 }
1040}
1041
1042
1043
1044
1045
1046static inline int ic3_startup_local(struct uart_port *the_port)
1047{
1048 struct ioc3_port *port;
1049
1050 if (!the_port) {
1051 NOT_PROGRESS();
1052 return -1;
1053 }
1054
1055 port = get_ioc3_port(the_port);
1056 if (!port) {
1057 NOT_PROGRESS();
1058 return -1;
1059 }
1060
1061 local_open(port);
1062
1063
1064 ioc3_set_proto(port, IS_RS232(the_port->line) ? PROTO_RS232 :
1065 PROTO_RS422);
1066 return 0;
1067}
1068
1069
1070
1071
1072
1073static void ioc3_cb_output_lowat(struct ioc3_port *port)
1074{
1075 unsigned long pflags;
1076
1077
1078 if (port->ip_port) {
1079 spin_lock_irqsave(&port->ip_port->lock, pflags);
1080 transmit_chars(port->ip_port);
1081 spin_unlock_irqrestore(&port->ip_port->lock, pflags);
1082 }
1083}
1084
1085
1086
1087
1088
1089
1090static void ioc3_cb_post_ncs(struct uart_port *the_port, int ncs)
1091{
1092 struct uart_icount *icount;
1093
1094 icount = &the_port->icount;
1095
1096 if (ncs & NCS_BREAK)
1097 icount->brk++;
1098 if (ncs & NCS_FRAMING)
1099 icount->frame++;
1100 if (ncs & NCS_OVERRUN)
1101 icount->overrun++;
1102 if (ncs & NCS_PARITY)
1103 icount->parity++;
1104}
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114static inline int do_read(struct uart_port *the_port, char *buf, int len)
1115{
1116 int prod_ptr, cons_ptr, total;
1117 struct ioc3_port *port = get_ioc3_port(the_port);
1118 struct ring *inring;
1119 struct ring_entry *entry;
1120 struct port_hooks *hooks = port->ip_hooks;
1121 int byte_num;
1122 char *sc;
1123 int loop_counter;
1124
1125 BUG_ON(!(len >= 0));
1126 BUG_ON(!port);
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150 writel(port->ip_rx_cons | SRCIR_ARM, &port->ip_serial_regs->srcir);
1151
1152 prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
1153 cons_ptr = port->ip_rx_cons;
1154
1155 if (prod_ptr == cons_ptr) {
1156 int reset_dma = 0;
1157
1158
1159
1160
1161 if (!(port->ip_sscr & SSCR_DMA_EN)) {
1162 port->ip_sscr |= SSCR_DMA_EN;
1163 reset_dma = 1;
1164 }
1165
1166
1167
1168
1169
1170
1171
1172 writel(port->ip_sscr | SSCR_RX_DRAIN,
1173 &port->ip_serial_regs->sscr);
1174 prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
1175
1176
1177
1178
1179
1180
1181
1182
1183 if (prod_ptr == cons_ptr) {
1184 loop_counter = 0;
1185 while (readl(&port->ip_serial_regs->sscr) &
1186 SSCR_RX_DRAIN) {
1187 loop_counter++;
1188 if (loop_counter > MAXITER)
1189 return -1;
1190 }
1191
1192
1193
1194
1195 prod_ptr = readl(&port->ip_serial_regs->srpir)
1196 & PROD_CONS_MASK;
1197 }
1198 if (reset_dma) {
1199 port->ip_sscr &= ~SSCR_DMA_EN;
1200 writel(port->ip_sscr, &port->ip_serial_regs->sscr);
1201 }
1202 }
1203 inring = port->ip_inring;
1204 port->ip_flags &= ~READ_ABORTED;
1205
1206 total = 0;
1207 loop_counter = 0xfffff;
1208
1209
1210 while ((prod_ptr != cons_ptr) && (len > 0)) {
1211 entry = (struct ring_entry *)((caddr_t) inring + cons_ptr);
1212
1213 if (loop_counter-- <= 0) {
1214 printk(KERN_WARNING "IOC3 serial: "
1215 "possible hang condition/"
1216 "port stuck on read (line %d).\n",
1217 the_port->line);
1218 break;
1219 }
1220
1221
1222
1223
1224
1225
1226 if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
1227
1228
1229
1230
1231 port->ip_flags |= READ_ABORTED;
1232 len = 0;
1233 break;
1234 }
1235
1236
1237 for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) {
1238 sc = &(entry->ring_sc[byte_num]);
1239
1240
1241 if ((*sc & RXSB_MODEM_VALID)
1242 && (port->ip_notify & N_DDCD)) {
1243
1244 if ((port->ip_flags & DCD_ON)
1245 && !(*sc & RXSB_DCD)) {
1246
1247
1248
1249
1250
1251
1252
1253 if (total > 0) {
1254 len = 0;
1255 break;
1256 }
1257 port->ip_flags &= ~DCD_ON;
1258
1259
1260
1261
1262
1263 *sc &= ~RXSB_MODEM_VALID;
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273 if ((entry->ring_allsc & RING_ANY_VALID)
1274 == 0) {
1275 cons_ptr += (int)sizeof
1276 (struct ring_entry);
1277 cons_ptr &= PROD_CONS_MASK;
1278 }
1279 writel(cons_ptr,
1280 &port->ip_serial_regs->srcir);
1281 port->ip_rx_cons = cons_ptr;
1282
1283
1284 if ((port->ip_notify & N_DDCD)
1285 && port->ip_port) {
1286 uart_handle_dcd_change
1287 (port->ip_port, 0);
1288 wake_up_interruptible
1289 (&the_port->info->
1290 delta_msr_wait);
1291 }
1292
1293
1294
1295
1296 return 0;
1297 }
1298 }
1299 if (*sc & RXSB_MODEM_VALID) {
1300
1301 if ((*sc & RXSB_OVERRUN)
1302 && (port->ip_notify & N_OVERRUN_ERROR)) {
1303 ioc3_cb_post_ncs(the_port, NCS_OVERRUN);
1304 }
1305
1306 *sc &= ~RXSB_MODEM_VALID;
1307 }
1308
1309
1310 if ((*sc & RXSB_DATA_VALID) &&
1311 ((*sc & (RXSB_PAR_ERR
1312 | RXSB_FRAME_ERR | RXSB_BREAK))
1313 && (port->ip_notify & (N_PARITY_ERROR
1314 | N_FRAMING_ERROR
1315 | N_BREAK)))) {
1316
1317
1318
1319
1320
1321
1322
1323 if (total > 0) {
1324 len = 0;
1325 break;
1326 } else {
1327 if ((*sc & RXSB_PAR_ERR) &&
1328 (port->
1329 ip_notify & N_PARITY_ERROR)) {
1330 ioc3_cb_post_ncs(the_port,
1331 NCS_PARITY);
1332 }
1333 if ((*sc & RXSB_FRAME_ERR) &&
1334 (port->
1335 ip_notify & N_FRAMING_ERROR)) {
1336 ioc3_cb_post_ncs(the_port,
1337 NCS_FRAMING);
1338 }
1339 if ((*sc & RXSB_BREAK)
1340 && (port->ip_notify & N_BREAK)) {
1341 ioc3_cb_post_ncs
1342 (the_port, NCS_BREAK);
1343 }
1344 len = 1;
1345 }
1346 }
1347 if (*sc & RXSB_DATA_VALID) {
1348 *sc &= ~RXSB_DATA_VALID;
1349 *buf = entry->ring_data[byte_num];
1350 buf++;
1351 len--;
1352 total++;
1353 }
1354 }
1355
1356
1357
1358
1359
1360
1361 if ((entry->ring_allsc & RING_ANY_VALID) == 0) {
1362 cons_ptr += (int)sizeof(struct ring_entry);
1363 cons_ptr &= PROD_CONS_MASK;
1364 }
1365 }
1366
1367
1368 writel(cons_ptr, &port->ip_serial_regs->srcir);
1369 port->ip_rx_cons = cons_ptr;
1370
1371
1372
1373
1374 if ((port->ip_flags & INPUT_HIGH) && (((prod_ptr - cons_ptr)
1375 & PROD_CONS_MASK) <
1376 ((port->
1377 ip_sscr &
1378 SSCR_RX_THRESHOLD)
1379 << PROD_CONS_PTR_OFF))) {
1380 port->ip_flags &= ~INPUT_HIGH;
1381 enable_intrs(port, hooks->intr_rx_high);
1382 }
1383 return total;
1384}
1385
1386
1387
1388
1389
1390static int receive_chars(struct uart_port *the_port)
1391{
1392 struct tty_struct *tty;
1393 unsigned char ch[MAX_CHARS];
1394 int read_count = 0, read_room, flip = 0;
1395 struct uart_info *info = the_port->info;
1396 struct ioc3_port *port = get_ioc3_port(the_port);
1397 unsigned long pflags;
1398
1399
1400 if (!info)
1401 return 0;
1402 if (!info->port.tty)
1403 return 0;
1404
1405 if (!(port->ip_flags & INPUT_ENABLE))
1406 return 0;
1407
1408 spin_lock_irqsave(&the_port->lock, pflags);
1409 tty = info->port.tty;
1410
1411 read_count = do_read(the_port, ch, MAX_CHARS);
1412 if (read_count > 0) {
1413 flip = 1;
1414 read_room = tty_buffer_request_room(tty, read_count);
1415 tty_insert_flip_string(tty, ch, read_room);
1416 the_port->icount.rx += read_count;
1417 }
1418 spin_unlock_irqrestore(&the_port->lock, pflags);
1419
1420 if (flip)
1421 tty_flip_buffer_push(tty);
1422
1423 return read_count;
1424}
1425
1426
1427
1428
1429
1430
1431
1432
1433static int inline
1434ioc3uart_intr_one(struct ioc3_submodule *is,
1435 struct ioc3_driver_data *idd,
1436 unsigned int pending)
1437{
1438 int port_num = GET_PORT_FROM_SIO_IR(pending);
1439 struct port_hooks *hooks;
1440 unsigned int rx_high_rd_aborted = 0;
1441 unsigned long flags;
1442 struct uart_port *the_port;
1443 struct ioc3_port *port;
1444 int loop_counter;
1445 struct ioc3_card *card_ptr;
1446 unsigned int sio_ir;
1447
1448 card_ptr = idd->data[is->id];
1449 port = card_ptr->ic_port[port_num].icp_port;
1450 hooks = port->ip_hooks;
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467 sio_ir = pending & ~(hooks->intr_tx_mt);
1468 spin_lock_irqsave(&port->ip_lock, flags);
1469
1470 loop_counter = MAXITER;
1471
1472 do {
1473 uint32_t shadow;
1474
1475 if (loop_counter-- <= 0) {
1476 printk(KERN_WARNING "IOC3 serial: "
1477 "possible hang condition/"
1478 "port stuck on interrupt (line %d).\n",
1479 ((struct uart_port *)port->ip_port)->line);
1480 break;
1481 }
1482
1483 if (sio_ir & hooks->intr_delta_dcd) {
1484 ioc3_ack(is, idd, hooks->intr_delta_dcd);
1485 shadow = readl(&port->ip_serial_regs->shadow);
1486
1487 if ((port->ip_notify & N_DDCD)
1488 && (shadow & SHADOW_DCD)
1489 && (port->ip_port)) {
1490 the_port = port->ip_port;
1491 uart_handle_dcd_change(the_port,
1492 shadow & SHADOW_DCD);
1493 wake_up_interruptible
1494 (&the_port->info->delta_msr_wait);
1495 } else if ((port->ip_notify & N_DDCD)
1496 && !(shadow & SHADOW_DCD)) {
1497
1498 uart_handle_dcd_change(port->ip_port,
1499 shadow & SHADOW_DCD);
1500 port->ip_flags |= DCD_ON;
1501 }
1502 }
1503
1504
1505 if (sio_ir & hooks->intr_delta_cts) {
1506 ioc3_ack(is, idd, hooks->intr_delta_cts);
1507 shadow = readl(&port->ip_serial_regs->shadow);
1508
1509 if ((port->ip_notify & N_DCTS) && (port->ip_port)) {
1510 the_port = port->ip_port;
1511 uart_handle_cts_change(the_port, shadow
1512 & SHADOW_CTS);
1513 wake_up_interruptible
1514 (&the_port->info->delta_msr_wait);
1515 }
1516 }
1517
1518
1519
1520
1521
1522 if (sio_ir & hooks->intr_rx_timer) {
1523 ioc3_ack(is, idd, hooks->intr_rx_timer);
1524 if ((port->ip_notify & N_DATA_READY)
1525 && (port->ip_port)) {
1526 receive_chars(port->ip_port);
1527 }
1528 }
1529
1530
1531 else if (sio_ir & hooks->intr_rx_high) {
1532
1533 if ((port->ip_notify & N_DATA_READY) && port->ip_port) {
1534 receive_chars(port->ip_port);
1535 }
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546 if ((sio_ir = PENDING(card_ptr, idd))
1547 & hooks->intr_rx_high) {
1548 if (port->ip_flags & READ_ABORTED) {
1549 rx_high_rd_aborted++;
1550 }
1551 else {
1552 card_ptr->ic_enable &= ~hooks->intr_rx_high;
1553 port->ip_flags |= INPUT_HIGH;
1554 }
1555 }
1556 }
1557
1558
1559
1560
1561
1562 if (sio_ir & hooks->intr_tx_explicit) {
1563 port->ip_flags &= ~LOWAT_WRITTEN;
1564 ioc3_ack(is, idd, hooks->intr_tx_explicit);
1565 if (port->ip_notify & N_OUTPUT_LOWAT)
1566 ioc3_cb_output_lowat(port);
1567 }
1568
1569
1570 else if (sio_ir & hooks->intr_tx_mt) {
1571
1572
1573
1574
1575
1576
1577
1578 if (port->ip_notify & N_OUTPUT_LOWAT) {
1579 ioc3_cb_output_lowat(port);
1580
1581
1582
1583
1584
1585 sio_ir = PENDING(card_ptr, idd);
1586 }
1587
1588
1589
1590
1591 if (sio_ir & hooks->intr_tx_mt) {
1592
1593
1594
1595
1596
1597 if (!(port->ip_notify
1598 & (N_DATA_READY | N_DDCD))) {
1599 BUG_ON(!(port->ip_sscr
1600 & SSCR_DMA_EN));
1601 port->ip_sscr &= ~SSCR_DMA_EN;
1602 writel(port->ip_sscr,
1603 &port->ip_serial_regs->sscr);
1604 }
1605
1606 card_ptr->ic_enable &= ~hooks->intr_tx_mt;
1607 }
1608 }
1609 sio_ir = PENDING(card_ptr, idd);
1610
1611
1612
1613
1614
1615 if (rx_high_rd_aborted && (sio_ir == hooks->intr_rx_high)) {
1616 sio_ir &= ~hooks->intr_rx_high;
1617 }
1618 } while (sio_ir & hooks->intr_all);
1619
1620 spin_unlock_irqrestore(&port->ip_lock, flags);
1621 ioc3_enable(is, idd, card_ptr->ic_enable);
1622 return 0;
1623}
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633static int ioc3uart_intr(struct ioc3_submodule *is,
1634 struct ioc3_driver_data *idd,
1635 unsigned int pending)
1636{
1637 int ret = 0;
1638
1639
1640
1641
1642
1643
1644 if (pending & SIO_IR_SA)
1645 ret |= ioc3uart_intr_one(is, idd, pending & SIO_IR_SA);
1646 if (pending & SIO_IR_SB)
1647 ret |= ioc3uart_intr_one(is, idd, pending & SIO_IR_SB);
1648
1649 return ret;
1650}
1651
1652
1653
1654
1655
1656
1657static const char *ic3_type(struct uart_port *the_port)
1658{
1659 if (IS_RS232(the_port->line))
1660 return "SGI IOC3 Serial [rs232]";
1661 else
1662 return "SGI IOC3 Serial [rs422]";
1663}
1664
1665
1666
1667
1668
1669
1670static unsigned int ic3_tx_empty(struct uart_port *the_port)
1671{
1672 unsigned int ret = 0;
1673 struct ioc3_port *port = get_ioc3_port(the_port);
1674
1675 if (readl(&port->ip_serial_regs->shadow) & SHADOW_TEMT)
1676 ret = TIOCSER_TEMT;
1677 return ret;
1678}
1679
1680
1681
1682
1683
1684
1685static void ic3_stop_tx(struct uart_port *the_port)
1686{
1687 struct ioc3_port *port = get_ioc3_port(the_port);
1688
1689 if (port)
1690 set_notification(port, N_OUTPUT_LOWAT, 0);
1691}
1692
1693
1694
1695
1696
1697
1698static void ic3_stop_rx(struct uart_port *the_port)
1699{
1700 struct ioc3_port *port = get_ioc3_port(the_port);
1701
1702 if (port)
1703 port->ip_flags &= ~INPUT_ENABLE;
1704}
1705
1706
1707
1708
1709
1710
1711static void null_void_function(struct uart_port *the_port)
1712{
1713}
1714
1715
1716
1717
1718
1719
1720static void ic3_shutdown(struct uart_port *the_port)
1721{
1722 unsigned long port_flags;
1723 struct ioc3_port *port;
1724 struct uart_info *info;
1725
1726 port = get_ioc3_port(the_port);
1727 if (!port)
1728 return;
1729
1730 info = the_port->info;
1731 wake_up_interruptible(&info->delta_msr_wait);
1732
1733 spin_lock_irqsave(&the_port->lock, port_flags);
1734 set_notification(port, N_ALL, 0);
1735 spin_unlock_irqrestore(&the_port->lock, port_flags);
1736}
1737
1738
1739
1740
1741
1742
1743
1744static void ic3_set_mctrl(struct uart_port *the_port, unsigned int mctrl)
1745{
1746 unsigned char mcr = 0;
1747
1748 if (mctrl & TIOCM_RTS)
1749 mcr |= UART_MCR_RTS;
1750 if (mctrl & TIOCM_DTR)
1751 mcr |= UART_MCR_DTR;
1752 if (mctrl & TIOCM_OUT1)
1753 mcr |= UART_MCR_OUT1;
1754 if (mctrl & TIOCM_OUT2)
1755 mcr |= UART_MCR_OUT2;
1756 if (mctrl & TIOCM_LOOP)
1757 mcr |= UART_MCR_LOOP;
1758
1759 set_mcr(the_port, mcr, SHADOW_DTR);
1760}
1761
1762
1763
1764
1765
1766
1767static unsigned int ic3_get_mctrl(struct uart_port *the_port)
1768{
1769 struct ioc3_port *port = get_ioc3_port(the_port);
1770 uint32_t shadow;
1771 unsigned int ret = 0;
1772
1773 if (!port)
1774 return 0;
1775
1776 shadow = readl(&port->ip_serial_regs->shadow);
1777 if (shadow & SHADOW_DCD)
1778 ret |= TIOCM_CD;
1779 if (shadow & SHADOW_DR)
1780 ret |= TIOCM_DSR;
1781 if (shadow & SHADOW_CTS)
1782 ret |= TIOCM_CTS;
1783 return ret;
1784}
1785
1786
1787
1788
1789
1790
1791static void ic3_start_tx(struct uart_port *the_port)
1792{
1793 struct ioc3_port *port = get_ioc3_port(the_port);
1794
1795 if (port) {
1796 set_notification(port, N_OUTPUT_LOWAT, 1);
1797 enable_intrs(port, port->ip_hooks->intr_tx_mt);
1798 }
1799}
1800
1801
1802
1803
1804
1805
1806
1807static void ic3_break_ctl(struct uart_port *the_port, int break_state)
1808{
1809}
1810
1811
1812
1813
1814
1815
1816static int ic3_startup(struct uart_port *the_port)
1817{
1818 int retval;
1819 struct ioc3_port *port;
1820 struct ioc3_card *card_ptr;
1821 unsigned long port_flags;
1822
1823 if (!the_port) {
1824 NOT_PROGRESS();
1825 return -ENODEV;
1826 }
1827 port = get_ioc3_port(the_port);
1828 if (!port) {
1829 NOT_PROGRESS();
1830 return -ENODEV;
1831 }
1832 card_ptr = port->ip_card;
1833 port->ip_port = the_port;
1834
1835 if (!card_ptr) {
1836 NOT_PROGRESS();
1837 return -ENODEV;
1838 }
1839
1840
1841 spin_lock_irqsave(&the_port->lock, port_flags);
1842 retval = ic3_startup_local(the_port);
1843 spin_unlock_irqrestore(&the_port->lock, port_flags);
1844 return retval;
1845}
1846
1847
1848
1849
1850
1851
1852
1853
1854static void
1855ic3_set_termios(struct uart_port *the_port,
1856 struct ktermios *termios, struct ktermios *old_termios)
1857{
1858 unsigned long port_flags;
1859
1860 spin_lock_irqsave(&the_port->lock, port_flags);
1861 ioc3_change_speed(the_port, termios, old_termios);
1862 spin_unlock_irqrestore(&the_port->lock, port_flags);
1863}
1864
1865
1866
1867
1868
1869
1870static int ic3_request_port(struct uart_port *port)
1871{
1872 return 0;
1873}
1874
1875
1876static struct uart_ops ioc3_ops = {
1877 .tx_empty = ic3_tx_empty,
1878 .set_mctrl = ic3_set_mctrl,
1879 .get_mctrl = ic3_get_mctrl,
1880 .stop_tx = ic3_stop_tx,
1881 .start_tx = ic3_start_tx,
1882 .stop_rx = ic3_stop_rx,
1883 .enable_ms = null_void_function,
1884 .break_ctl = ic3_break_ctl,
1885 .startup = ic3_startup,
1886 .shutdown = ic3_shutdown,
1887 .set_termios = ic3_set_termios,
1888 .type = ic3_type,
1889 .release_port = null_void_function,
1890 .request_port = ic3_request_port,
1891};
1892
1893
1894
1895
1896
1897static struct uart_driver ioc3_uart = {
1898 .owner = THIS_MODULE,
1899 .driver_name = "ioc3_serial",
1900 .dev_name = DEVICE_NAME,
1901 .major = DEVICE_MAJOR,
1902 .minor = DEVICE_MINOR,
1903 .nr = MAX_LOGICAL_PORTS
1904};
1905
1906
1907
1908
1909
1910
1911
1912static inline int ioc3_serial_core_attach( struct ioc3_submodule *is,
1913 struct ioc3_driver_data *idd)
1914{
1915 struct ioc3_port *port;
1916 struct uart_port *the_port;
1917 struct ioc3_card *card_ptr = idd->data[is->id];
1918 int ii, phys_port;
1919 struct pci_dev *pdev = idd->pdev;
1920
1921 DPRINT_CONFIG(("%s: attach pdev 0x%p - card_ptr 0x%p\n",
1922 __func__, pdev, (void *)card_ptr));
1923
1924 if (!card_ptr)
1925 return -ENODEV;
1926
1927
1928 for (ii = 0; ii < LOGICAL_PORTS_PER_CARD; ii++) {
1929 phys_port = GET_PHYSICAL_PORT(ii);
1930 the_port = &card_ptr->ic_port[phys_port].
1931 icp_uart_port[GET_LOGICAL_PORT(ii)];
1932 port = card_ptr->ic_port[phys_port].icp_port;
1933 port->ip_port = the_port;
1934
1935 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p [%d/%d]\n",
1936 __func__, (void *)the_port, (void *)port,
1937 phys_port, ii));
1938
1939
1940 the_port->membase = (unsigned char __iomem *)1;
1941 the_port->iobase = (pdev->bus->number << 16) | ii;
1942 the_port->line = (Num_of_ioc3_cards << 2) | ii;
1943 the_port->mapbase = 1;
1944 the_port->type = PORT_16550A;
1945 the_port->fifosize = FIFO_SIZE;
1946 the_port->ops = &ioc3_ops;
1947 the_port->irq = idd->irq_io;
1948 the_port->dev = &pdev->dev;
1949
1950 if (uart_add_one_port(&ioc3_uart, the_port) < 0) {
1951 printk(KERN_WARNING
1952 "%s: unable to add port %d bus %d\n",
1953 __func__, the_port->line, pdev->bus->number);
1954 } else {
1955 DPRINT_CONFIG(("IOC3 serial port %d irq %d bus %d\n",
1956 the_port->line, the_port->irq, pdev->bus->number));
1957 }
1958
1959
1960 if (IS_PHYSICAL_PORT(ii))
1961 ioc3_set_proto(port, PROTO_RS232);
1962 }
1963 return 0;
1964}
1965
1966
1967
1968
1969
1970
1971
1972static int ioc3uart_remove(struct ioc3_submodule *is,
1973 struct ioc3_driver_data *idd)
1974{
1975 struct ioc3_card *card_ptr = idd->data[is->id];
1976 struct uart_port *the_port;
1977 struct ioc3_port *port;
1978 int ii;
1979
1980 if (card_ptr) {
1981 for (ii = 0; ii < LOGICAL_PORTS_PER_CARD; ii++) {
1982 the_port = &card_ptr->ic_port[GET_PHYSICAL_PORT(ii)].
1983 icp_uart_port[GET_LOGICAL_PORT(ii)];
1984 if (the_port)
1985 uart_remove_one_port(&ioc3_uart, the_port);
1986 port = card_ptr->ic_port[GET_PHYSICAL_PORT(ii)].icp_port;
1987 if (port && IS_PHYSICAL_PORT(ii)
1988 && (GET_PHYSICAL_PORT(ii) == 0)) {
1989 pci_free_consistent(port->ip_idd->pdev,
1990 TOTAL_RING_BUF_SIZE,
1991 (void *)port->ip_cpu_ringbuf,
1992 port->ip_dma_ringbuf);
1993 kfree(port);
1994 card_ptr->ic_port[GET_PHYSICAL_PORT(ii)].
1995 icp_port = NULL;
1996 }
1997 }
1998 kfree(card_ptr);
1999 idd->data[is->id] = NULL;
2000 }
2001 return 0;
2002}
2003
2004
2005
2006
2007
2008
2009
2010static int __devinit
2011ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2012{
2013 struct pci_dev *pdev = idd->pdev;
2014 struct ioc3_card *card_ptr;
2015 int ret = 0;
2016 struct ioc3_port *port;
2017 struct ioc3_port *ports[PORTS_PER_CARD];
2018 int phys_port;
2019
2020 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, is, idd));
2021
2022 card_ptr = kzalloc(sizeof(struct ioc3_card), GFP_KERNEL);
2023 if (!card_ptr) {
2024 printk(KERN_WARNING "ioc3_attach_one"
2025 ": unable to get memory for the IOC3\n");
2026 return -ENOMEM;
2027 }
2028 idd->data[is->id] = card_ptr;
2029 Submodule_slot = is->id;
2030
2031 writel(((UARTA_BASE >> 3) << SIO_CR_SER_A_BASE_SHIFT) |
2032 ((UARTB_BASE >> 3) << SIO_CR_SER_B_BASE_SHIFT) |
2033 (0xf << SIO_CR_CMD_PULSE_SHIFT), &idd->vma->sio_cr);
2034
2035 pci_write_config_dword(pdev, PCI_LAT, 0xff00);
2036
2037
2038 ioc3_gpcr_set(idd, GPCR_UARTA_MODESEL | GPCR_UARTB_MODESEL);
2039
2040
2041 for (phys_port = 0; phys_port < PORTS_PER_CARD; phys_port++) {
2042 port = kzalloc(sizeof(struct ioc3_port), GFP_KERNEL);
2043 if (!port) {
2044 printk(KERN_WARNING
2045 "IOC3 serial memory not available for port\n");
2046 goto out4;
2047 }
2048 spin_lock_init(&port->ip_lock);
2049
2050
2051
2052
2053 ports[phys_port] = port;
2054
2055
2056 card_ptr->ic_port[phys_port].icp_port = port;
2057 port->ip_is = is;
2058 port->ip_idd = idd;
2059 port->ip_baud = 9600;
2060 port->ip_card = card_ptr;
2061 port->ip_hooks = &hooks_array[phys_port];
2062
2063
2064 if (phys_port == 0) {
2065 port->ip_serial_regs = &idd->vma->port_a;
2066 port->ip_uart_regs = &idd->vma->sregs.uarta;
2067
2068 DPRINT_CONFIG(("%s : Port A ip_serial_regs 0x%p "
2069 "ip_uart_regs 0x%p\n",
2070 __func__,
2071 (void *)port->ip_serial_regs,
2072 (void *)port->ip_uart_regs));
2073
2074
2075 port->ip_cpu_ringbuf = pci_alloc_consistent(pdev,
2076 TOTAL_RING_BUF_SIZE, &port->ip_dma_ringbuf);
2077
2078 BUG_ON(!((((int64_t) port->ip_dma_ringbuf) &
2079 (TOTAL_RING_BUF_SIZE - 1)) == 0));
2080 port->ip_inring = RING(port, RX_A);
2081 port->ip_outring = RING(port, TX_A);
2082 DPRINT_CONFIG(("%s : Port A ip_cpu_ringbuf 0x%p "
2083 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2084 "ip_outring 0x%p\n",
2085 __func__,
2086 (void *)port->ip_cpu_ringbuf,
2087 (void *)port->ip_dma_ringbuf,
2088 (void *)port->ip_inring,
2089 (void *)port->ip_outring));
2090 }
2091 else {
2092 port->ip_serial_regs = &idd->vma->port_b;
2093 port->ip_uart_regs = &idd->vma->sregs.uartb;
2094
2095 DPRINT_CONFIG(("%s : Port B ip_serial_regs 0x%p "
2096 "ip_uart_regs 0x%p\n",
2097 __func__,
2098 (void *)port->ip_serial_regs,
2099 (void *)port->ip_uart_regs));
2100
2101
2102 port->ip_dma_ringbuf =
2103 ports[phys_port - 1]->ip_dma_ringbuf;
2104 port->ip_cpu_ringbuf =
2105 ports[phys_port - 1]->ip_cpu_ringbuf;
2106 port->ip_inring = RING(port, RX_B);
2107 port->ip_outring = RING(port, TX_B);
2108 DPRINT_CONFIG(("%s : Port B ip_cpu_ringbuf 0x%p "
2109 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2110 "ip_outring 0x%p\n",
2111 __func__,
2112 (void *)port->ip_cpu_ringbuf,
2113 (void *)port->ip_dma_ringbuf,
2114 (void *)port->ip_inring,
2115 (void *)port->ip_outring));
2116 }
2117
2118 DPRINT_CONFIG(("%s : port %d [addr 0x%p] card_ptr 0x%p",
2119 __func__,
2120 phys_port, (void *)port, (void *)card_ptr));
2121 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n",
2122 (void *)port->ip_serial_regs,
2123 (void *)port->ip_uart_regs));
2124
2125
2126 port_init(port);
2127
2128 DPRINT_CONFIG(("%s: phys_port %d port 0x%p inring 0x%p "
2129 "outring 0x%p\n",
2130 __func__,
2131 phys_port, (void *)port,
2132 (void *)port->ip_inring,
2133 (void *)port->ip_outring));
2134
2135 }
2136
2137
2138
2139 if ((ret = ioc3_serial_core_attach(is, idd)))
2140 goto out4;
2141
2142 Num_of_ioc3_cards++;
2143
2144 return ret;
2145
2146
2147out4:
2148 kfree(card_ptr);
2149 return ret;
2150}
2151
2152static struct ioc3_submodule ioc3uart_ops = {
2153 .name = "IOC3uart",
2154 .probe = ioc3uart_probe,
2155 .remove = ioc3uart_remove,
2156
2157 .irq_mask = SIO_IR_SA | SIO_IR_SB,
2158 .intr = ioc3uart_intr,
2159 .owner = THIS_MODULE,
2160};
2161
2162
2163
2164
2165static int __devinit ioc3uart_init(void)
2166{
2167 int ret;
2168
2169
2170 if ((ret = uart_register_driver(&ioc3_uart)) < 0) {
2171 printk(KERN_WARNING
2172 "%s: Couldn't register IOC3 uart serial driver\n",
2173 __func__);
2174 return ret;
2175 }
2176 ret = ioc3_register_submodule(&ioc3uart_ops);
2177 if (ret)
2178 uart_unregister_driver(&ioc3_uart);
2179 return ret;
2180}
2181
2182static void __devexit ioc3uart_exit(void)
2183{
2184 ioc3_unregister_submodule(&ioc3uart_ops);
2185 uart_unregister_driver(&ioc3_uart);
2186}
2187
2188module_init(ioc3uart_init);
2189module_exit(ioc3uart_exit);
2190
2191MODULE_AUTHOR("Pat Gefre - Silicon Graphics Inc. (SGI) <pfg@sgi.com>");
2192MODULE_DESCRIPTION("Serial PCI driver module for SGI IOC3 card");
2193MODULE_LICENSE("GPL");
2194