forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcfserial.c
1975 lines (1704 loc) · 48.5 KB
/
mcfserial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* mcfserial.c -- serial driver for ColdFire internal UARTS.
*
* Copyright (C) 1999-2003 Greg Ungerer <[email protected]>
* Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
* Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
*
* Based on code from 68332serial.c which was:
*
* Copyright (C) 1995 David S. Miller ([email protected])
* Copyright (C) 1998 TSHG
* Copyright (c) 1999 Rt-Control Inc. <[email protected]>
*
* Changes:
* 08/07/2003 Daniele Bellucci <[email protected]>
* some cleanups in mcfrs_write.
*
*/
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/wait.h>
#include <linux/interrupt.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/string.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <linux/serial.h>
#include <linux/serialP.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
#include <asm/semaphore.h>
#include <asm/delay.h>
#include <asm/coldfire.h>
#include <asm/mcfsim.h>
#include <asm/mcfuart.h>
#include <asm/nettel.h>
#include <asm/uaccess.h>
#include "mcfserial.h"
struct timer_list mcfrs_timer_struct;
/*
* Default console baud rate, we use this as the default
* for all ports so init can just open /dev/console and
* keep going. Perhaps one day the cflag settings for the
* console can be used instead.
*/
#if defined(CONFIG_HW_FEITH)
#define CONSOLE_BAUD_RATE 38400
#define DEFAULT_CBAUD B38400
#elif defined(CONFIG_MOD5272) || defined(CONFIG_M5208EVB) || \
defined(CONFIG_M5329EVB) || defined(CONFIG_GILBARCO)
#define CONSOLE_BAUD_RATE 115200
#define DEFAULT_CBAUD B115200
#elif defined(CONFIG_ARNEWSH) || defined(CONFIG_FREESCALE) || \
defined(CONFIG_senTec) || defined(CONFIG_SNEHA) || defined(CONFIG_AVNET)
#define CONSOLE_BAUD_RATE 19200
#define DEFAULT_CBAUD B19200
#endif
#ifndef CONSOLE_BAUD_RATE
#define CONSOLE_BAUD_RATE 9600
#define DEFAULT_CBAUD B9600
#endif
int mcfrs_console_inited = 0;
int mcfrs_console_port = -1;
int mcfrs_console_baud = CONSOLE_BAUD_RATE;
int mcfrs_console_cbaud = DEFAULT_CBAUD;
/*
* Driver data structures.
*/
static struct tty_driver *mcfrs_serial_driver;
/* number of characters left in xmit buffer before we ask for more */
#define WAKEUP_CHARS 256
/* Debugging...
*/
#undef SERIAL_DEBUG_OPEN
#undef SERIAL_DEBUG_FLOW
#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
defined(CONFIG_M520x) || defined(CONFIG_M532x)
#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
#else
#define IRQBASE 73
#endif
/*
* Configuration table, UARTs to look for at startup.
*/
static struct mcf_serial mcfrs_table[] = {
{ /* ttyS0 */
.magic = 0,
.addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
.irq = IRQBASE,
.flags = ASYNC_BOOT_AUTOCONF,
},
#ifdef MCFUART_BASE2
{ /* ttyS1 */
.magic = 0,
.addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
.irq = IRQBASE+1,
.flags = ASYNC_BOOT_AUTOCONF,
},
#endif
#ifdef MCFUART_BASE3
{ /* ttyS2 */
.magic = 0,
.addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE3),
.irq = IRQBASE+2,
.flags = ASYNC_BOOT_AUTOCONF,
},
#endif
#ifdef MCFUART_BASE4
{ /* ttyS3 */
.magic = 0,
.addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE4),
.irq = IRQBASE+3,
.flags = ASYNC_BOOT_AUTOCONF,
},
#endif
};
#define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
/*
* This is used to figure out the divisor speeds and the timeouts.
*/
static int mcfrs_baud_table[] = {
0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
};
#define MCFRS_BAUD_TABLE_SIZE \
(sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
#ifdef CONFIG_MAGIC_SYSRQ
/*
* Magic system request keys. Used for debugging...
*/
extern int magic_sysrq_key(int ch);
#endif
/*
* Forware declarations...
*/
static void mcfrs_change_speed(struct mcf_serial *info);
static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
static inline int serial_paranoia_check(struct mcf_serial *info,
char *name, const char *routine)
{
#ifdef SERIAL_PARANOIA_CHECK
static const char badmagic[] =
"MCFRS(warning): bad magic number for serial struct %s in %s\n";
static const char badinfo[] =
"MCFRS(warning): null mcf_serial for %s in %s\n";
if (!info) {
printk(badinfo, name, routine);
return 1;
}
if (info->magic != SERIAL_MAGIC) {
printk(badmagic, name, routine);
return 1;
}
#endif
return 0;
}
/*
* Sets or clears DTR and RTS on the requested line.
*/
static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
{
volatile unsigned char *uartp;
unsigned long flags;
#if 0
printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
__FILE__, __LINE__, info, dtr, rts);
#endif
local_irq_save(flags);
if (dtr >= 0) {
#ifdef MCFPP_DTR0
if (info->line)
mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
else
mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
#endif
}
if (rts >= 0) {
uartp = info->addr;
if (rts) {
info->sigs |= TIOCM_RTS;
uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
} else {
info->sigs &= ~TIOCM_RTS;
uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
}
}
local_irq_restore(flags);
return;
}
/*
* Gets values of serial signals.
*/
static int mcfrs_getsignals(struct mcf_serial *info)
{
volatile unsigned char *uartp;
unsigned long flags;
int sigs;
#if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
unsigned short ppdata;
#endif
#if 0
printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
#endif
local_irq_save(flags);
uartp = info->addr;
sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
sigs |= (info->sigs & TIOCM_RTS);
#ifdef MCFPP_DCD0
{
unsigned int ppdata;
ppdata = mcf_getppdata();
if (info->line == 0) {
sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
} else if (info->line == 1) {
sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
}
}
#endif
local_irq_restore(flags);
return(sigs);
}
/*
* ------------------------------------------------------------
* mcfrs_stop() and mcfrs_start()
*
* This routines are called before setting or resetting tty->stopped.
* They enable or disable transmitter interrupts, as necessary.
* ------------------------------------------------------------
*/
static void mcfrs_stop(struct tty_struct *tty)
{
volatile unsigned char *uartp;
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
return;
local_irq_save(flags);
uartp = info->addr;
info->imr &= ~MCFUART_UIR_TXREADY;
uartp[MCFUART_UIMR] = info->imr;
local_irq_restore(flags);
}
static void mcfrs_start(struct tty_struct *tty)
{
volatile unsigned char *uartp;
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
return;
local_irq_save(flags);
if (info->xmit_cnt && info->xmit_buf) {
uartp = info->addr;
info->imr |= MCFUART_UIR_TXREADY;
uartp[MCFUART_UIMR] = info->imr;
}
local_irq_restore(flags);
}
/*
* ----------------------------------------------------------------------
*
* Here starts the interrupt handling routines. All of the following
* subroutines are declared as inline and are folded into
* mcfrs_interrupt(). They were separated out for readability's sake.
*
* Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
* runs with interrupts turned off. People who may want to modify
* mcfrs_interrupt() should try to keep the interrupt handler as fast as
* possible. After you are done making modifications, it is not a bad
* idea to do:
*
* gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
*
* and look at the resulting assemble code in serial.s.
*
* - Ted Ts'o ([email protected]), 7-Mar-93
* -----------------------------------------------------------------------
*/
static inline void receive_chars(struct mcf_serial *info)
{
volatile unsigned char *uartp;
struct tty_struct *tty = info->tty;
unsigned char status, ch, flag;
if (!tty)
return;
uartp = info->addr;
while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
ch = uartp[MCFUART_URB];
info->stats.rx++;
#ifdef CONFIG_MAGIC_SYSRQ
if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
if (magic_sysrq_key(ch))
continue;
}
#endif
flag = TTY_NORMAL;
if (status & MCFUART_USR_RXERR) {
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
if (status & MCFUART_USR_RXBREAK) {
info->stats.rxbreak++;
flag = TTY_BREAK;
} else if (status & MCFUART_USR_RXPARITY) {
info->stats.rxparity++;
flag = TTY_PARITY;
} else if (status & MCFUART_USR_RXOVERRUN) {
info->stats.rxoverrun++;
flag = TTY_OVERRUN;
} else if (status & MCFUART_USR_RXFRAMING) {
info->stats.rxframing++;
flag = TTY_FRAME;
}
}
tty_insert_flip_char(tty, ch, flag);
}
tty_schedule_flip(tty);
return;
}
static inline void transmit_chars(struct mcf_serial *info)
{
volatile unsigned char *uartp;
uartp = info->addr;
if (info->x_char) {
/* Send special char - probably flow control */
uartp[MCFUART_UTB] = info->x_char;
info->x_char = 0;
info->stats.tx++;
}
if ((info->xmit_cnt <= 0) || info->tty->stopped) {
info->imr &= ~MCFUART_UIR_TXREADY;
uartp[MCFUART_UIMR] = info->imr;
return;
}
while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
info->stats.tx++;
if (--info->xmit_cnt <= 0)
break;
}
if (info->xmit_cnt < WAKEUP_CHARS)
schedule_work(&info->tqueue);
return;
}
/*
* This is the serial driver's generic interrupt routine
*/
irqreturn_t mcfrs_interrupt(int irq, void *dev_id)
{
struct mcf_serial *info;
unsigned char isr;
info = &mcfrs_table[(irq - IRQBASE)];
isr = info->addr[MCFUART_UISR] & info->imr;
if (isr & MCFUART_UIR_RXREADY)
receive_chars(info);
if (isr & MCFUART_UIR_TXREADY)
transmit_chars(info);
return IRQ_HANDLED;
}
/*
* -------------------------------------------------------------------
* Here ends the serial interrupt routines.
* -------------------------------------------------------------------
*/
static void mcfrs_offintr(struct work_struct *work)
{
struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue);
struct tty_struct *tty = info->tty;
if (tty)
tty_wakeup(tty);
}
/*
* Change of state on a DCD line.
*/
void mcfrs_modem_change(struct mcf_serial *info, int dcd)
{
if (info->count == 0)
return;
if (info->flags & ASYNC_CHECK_CD) {
if (dcd)
wake_up_interruptible(&info->open_wait);
else
schedule_work(&info->tqueue_hangup);
}
}
#ifdef MCFPP_DCD0
unsigned short mcfrs_ppstatus;
/*
* This subroutine is called when the RS_TIMER goes off. It is used
* to monitor the state of the DCD lines - since they have no edge
* sensors and interrupt generators.
*/
static void mcfrs_timer(void)
{
unsigned int ppstatus, dcdval, i;
ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
if (ppstatus != mcfrs_ppstatus) {
for (i = 0; (i < 2); i++) {
dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
mcfrs_modem_change(&mcfrs_table[i],
((ppstatus & dcdval) ? 0 : 1));
}
}
}
mcfrs_ppstatus = ppstatus;
/* Re-arm timer */
mcfrs_timer_struct.expires = jiffies + HZ/25;
add_timer(&mcfrs_timer_struct);
}
#endif /* MCFPP_DCD0 */
/*
* This routine is called from the scheduler tqueue when the interrupt
* routine has signalled that a hangup has occurred. The path of
* hangup processing is:
*
* serial interrupt routine -> (scheduler tqueue) ->
* do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
*
*/
static void do_serial_hangup(struct work_struct *work)
{
struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue_hangup);
struct tty_struct *tty = info->tty;
if (tty)
tty_hangup(tty);
}
static int startup(struct mcf_serial * info)
{
volatile unsigned char *uartp;
unsigned long flags;
if (info->flags & ASYNC_INITIALIZED)
return 0;
if (!info->xmit_buf) {
info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
if (!info->xmit_buf)
return -ENOMEM;
}
local_irq_save(flags);
#ifdef SERIAL_DEBUG_OPEN
printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
#endif
/*
* Reset UART, get it into known state...
*/
uartp = info->addr;
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
mcfrs_setsignals(info, 1, 1);
if (info->tty)
clear_bit(TTY_IO_ERROR, &info->tty->flags);
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
/*
* and set the speed of the serial port
*/
mcfrs_change_speed(info);
/*
* Lastly enable the UART transmitter and receiver, and
* interrupt enables.
*/
info->imr = MCFUART_UIR_RXREADY;
uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
uartp[MCFUART_UIMR] = info->imr;
info->flags |= ASYNC_INITIALIZED;
local_irq_restore(flags);
return 0;
}
/*
* This routine will shutdown a serial port; interrupts are disabled, and
* DTR is dropped if the hangup on close termio flag is on.
*/
static void shutdown(struct mcf_serial * info)
{
volatile unsigned char *uartp;
unsigned long flags;
if (!(info->flags & ASYNC_INITIALIZED))
return;
#ifdef SERIAL_DEBUG_OPEN
printk("Shutting down serial port %d (irq %d)....\n", info->line,
info->irq);
#endif
local_irq_save(flags);
uartp = info->addr;
uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
mcfrs_setsignals(info, 0, 0);
if (info->xmit_buf) {
free_page((unsigned long) info->xmit_buf);
info->xmit_buf = 0;
}
if (info->tty)
set_bit(TTY_IO_ERROR, &info->tty->flags);
info->flags &= ~ASYNC_INITIALIZED;
local_irq_restore(flags);
}
/*
* This routine is called to set the UART divisor registers to match
* the specified baud rate for a serial port.
*/
static void mcfrs_change_speed(struct mcf_serial *info)
{
volatile unsigned char *uartp;
unsigned int baudclk, cflag;
unsigned long flags;
unsigned char mr1, mr2;
int i;
#ifdef CONFIG_M5272
unsigned int fraction;
#endif
if (!info->tty || !info->tty->termios)
return;
cflag = info->tty->termios->c_cflag;
if (info->addr == 0)
return;
#if 0
printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
#endif
i = cflag & CBAUD;
if (i & CBAUDEX) {
i &= ~CBAUDEX;
if (i < 1 || i > 4)
info->tty->termios->c_cflag &= ~CBAUDEX;
else
i += 15;
}
if (i == 0) {
mcfrs_setsignals(info, 0, -1);
return;
}
/* compute the baudrate clock */
#ifdef CONFIG_M5272
/*
* For the MCF5272, also compute the baudrate fraction.
*/
baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
fraction *= 16;
fraction /= (32 * mcfrs_baud_table[i]);
#else
baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
#endif
info->baud = mcfrs_baud_table[i];
mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
mr2 = 0;
switch (cflag & CSIZE) {
case CS5: mr1 |= MCFUART_MR1_CS5; break;
case CS6: mr1 |= MCFUART_MR1_CS6; break;
case CS7: mr1 |= MCFUART_MR1_CS7; break;
case CS8:
default: mr1 |= MCFUART_MR1_CS8; break;
}
if (cflag & PARENB) {
if (cflag & CMSPAR) {
if (cflag & PARODD)
mr1 |= MCFUART_MR1_PARITYMARK;
else
mr1 |= MCFUART_MR1_PARITYSPACE;
} else {
if (cflag & PARODD)
mr1 |= MCFUART_MR1_PARITYODD;
else
mr1 |= MCFUART_MR1_PARITYEVEN;
}
} else {
mr1 |= MCFUART_MR1_PARITYNONE;
}
if (cflag & CSTOPB)
mr2 |= MCFUART_MR2_STOP2;
else
mr2 |= MCFUART_MR2_STOP1;
if (cflag & CRTSCTS) {
mr1 |= MCFUART_MR1_RXRTS;
mr2 |= MCFUART_MR2_TXCTS;
}
if (cflag & CLOCAL)
info->flags &= ~ASYNC_CHECK_CD;
else
info->flags |= ASYNC_CHECK_CD;
uartp = info->addr;
local_irq_save(flags);
#if 0
printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
mr1, mr2, baudclk);
#endif
/*
Note: pg 12-16 of MCF5206e User's Manual states that a
software reset should be performed prior to changing
UMR1,2, UCSR, UACR, bit 7
*/
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
uartp[MCFUART_UMR] = mr1;
uartp[MCFUART_UMR] = mr2;
uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
#ifdef CONFIG_M5272
uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
#endif
uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
mcfrs_setsignals(info, 1, -1);
local_irq_restore(flags);
return;
}
static void mcfrs_flush_chars(struct tty_struct *tty)
{
volatile unsigned char *uartp;
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
return;
uartp = (volatile unsigned char *) info->addr;
/*
* re-enable receiver interrupt
*/
local_irq_save(flags);
if ((!(info->imr & MCFUART_UIR_RXREADY)) &&
(info->flags & ASYNC_INITIALIZED) ) {
info->imr |= MCFUART_UIR_RXREADY;
uartp[MCFUART_UIMR] = info->imr;
}
local_irq_restore(flags);
if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
!info->xmit_buf)
return;
/* Enable transmitter */
local_irq_save(flags);
info->imr |= MCFUART_UIR_TXREADY;
uartp[MCFUART_UIMR] = info->imr;
local_irq_restore(flags);
}
static int mcfrs_write(struct tty_struct * tty,
const unsigned char *buf, int count)
{
volatile unsigned char *uartp;
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
unsigned long flags;
int c, total = 0;
#if 0
printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
__FILE__, __LINE__, (int)tty, (int)buf, count);
#endif
if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
return 0;
if (!tty || !info->xmit_buf)
return 0;
local_save_flags(flags);
while (1) {
local_irq_disable();
c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
((int)SERIAL_XMIT_SIZE) - info->xmit_head));
local_irq_restore(flags);
if (c <= 0)
break;
memcpy(info->xmit_buf + info->xmit_head, buf, c);
local_irq_disable();
info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
info->xmit_cnt += c;
local_irq_restore(flags);
buf += c;
count -= c;
total += c;
}
local_irq_disable();
uartp = info->addr;
info->imr |= MCFUART_UIR_TXREADY;
uartp[MCFUART_UIMR] = info->imr;
local_irq_restore(flags);
return total;
}
static int mcfrs_write_room(struct tty_struct *tty)
{
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
int ret;
if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
return 0;
ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
if (ret < 0)
ret = 0;
return ret;
}
static int mcfrs_chars_in_buffer(struct tty_struct *tty)
{
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
return 0;
return info->xmit_cnt;
}
static void mcfrs_flush_buffer(struct tty_struct *tty)
{
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
return;
local_irq_save(flags);
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
local_irq_restore(flags);
tty_wakeup(tty);
}
/*
* ------------------------------------------------------------
* mcfrs_throttle()
*
* This routine is called by the upper-layer tty layer to signal that
* incoming characters should be throttled.
* ------------------------------------------------------------
*/
static void mcfrs_throttle(struct tty_struct * tty)
{
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];
printk("throttle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif
if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
return;
if (I_IXOFF(tty))
info->x_char = STOP_CHAR(tty);
/* Turn off RTS line (do this atomic) */
}
static void mcfrs_unthrottle(struct tty_struct * tty)
{
struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];
printk("unthrottle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif
if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
return;
if (I_IXOFF(tty)) {
if (info->x_char)
info->x_char = 0;
else
info->x_char = START_CHAR(tty);
}
/* Assert RTS line (do this atomic) */
}
/*
* ------------------------------------------------------------
* mcfrs_ioctl() and friends
* ------------------------------------------------------------
*/
static int get_serial_info(struct mcf_serial * info,
struct serial_struct * retinfo)
{
struct serial_struct tmp;
if (!retinfo)
return -EFAULT;
memset(&tmp, 0, sizeof(tmp));
tmp.type = info->type;
tmp.line = info->line;
tmp.port = (unsigned int) info->addr;
tmp.irq = info->irq;
tmp.flags = info->flags;
tmp.baud_base = info->baud_base;
tmp.close_delay = info->close_delay;
tmp.closing_wait = info->closing_wait;
tmp.custom_divisor = info->custom_divisor;
return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
}
static int set_serial_info(struct mcf_serial * info,
struct serial_struct * new_info)
{
struct serial_struct new_serial;
struct mcf_serial old_info;
int retval = 0;
if (!new_info)
return -EFAULT;
if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
return -EFAULT;
old_info = *info;
if (!capable(CAP_SYS_ADMIN)) {
if ((new_serial.baud_base != info->baud_base) ||
(new_serial.type != info->type) ||
(new_serial.close_delay != info->close_delay) ||
((new_serial.flags & ~ASYNC_USR_MASK) !=
(info->flags & ~ASYNC_USR_MASK)))
return -EPERM;
info->flags = ((info->flags & ~ASYNC_USR_MASK) |
(new_serial.flags & ASYNC_USR_MASK));
info->custom_divisor = new_serial.custom_divisor;
goto check_and_exit;
}
if (info->count > 1)
return -EBUSY;
/*
* OK, past this point, all the error checking has been done.
* At this point, we start making changes.....
*/
info->baud_base = new_serial.baud_base;
info->flags = ((info->flags & ~ASYNC_FLAGS) |
(new_serial.flags & ASYNC_FLAGS));
info->type = new_serial.type;
info->close_delay = new_serial.close_delay;
info->closing_wait = new_serial.closing_wait;
check_and_exit:
retval = startup(info);
return retval;
}
/*
* get_lsr_info - get line status register info
*
* Purpose: Let user call ioctl() to get info when the UART physically
* is emptied. On bus types like RS485, the transmitter must
* release the bus after transmitting. This must be done when
* the transmit shift register is empty, not be done when the
* transmit holding register is empty. This functionality
* allows an RS485 driver to be written in user space.
*/
static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
{
volatile unsigned char *uartp;
unsigned long flags;
unsigned char status;
local_irq_save(flags);
uartp = info->addr;
status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
local_irq_restore(flags);
return put_user(status,value);
}
/*
* This routine sends a break character out the serial port.
*/
static void send_break( struct mcf_serial * info, int duration)
{
volatile unsigned char *uartp;
unsigned long flags;
if (!info->addr)
return;
set_current_state(TASK_INTERRUPTIBLE);
uartp = info->addr;
local_irq_save(flags);