Commit b4746d8bf9f4ed6dc8a76c5d52db669604aff84b
Committed by
Wolfgang Denk
1 parent
6bcb4b806c
Exists in
master
and in
54 other branches
drivers/serial/ns16550: move ifdef into Makefile COBJS-$(...)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Showing 3 changed files with 3 additions and 11 deletions Inline Diff
drivers/serial/Makefile
1 | # | 1 | # |
2 | # (C) Copyright 2006 | 2 | # (C) Copyright 2006 |
3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. | 3 | # Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
4 | # | 4 | # |
5 | # See file CREDITS for list of people who contributed to this | 5 | # See file CREDITS for list of people who contributed to this |
6 | # project. | 6 | # project. |
7 | # | 7 | # |
8 | # This program is free software; you can redistribute it and/or | 8 | # This program is free software; you can redistribute it and/or |
9 | # modify it under the terms of the GNU General Public License as | 9 | # modify it under the terms of the GNU General Public License as |
10 | # published by the Free Software Foundation; either version 2 of | 10 | # published by the Free Software Foundation; either version 2 of |
11 | # the License, or (at your option) any later version. | 11 | # the License, or (at your option) any later version. |
12 | # | 12 | # |
13 | # This program is distributed in the hope that it will be useful, | 13 | # This program is distributed in the hope that it will be useful, |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | # GNU General Public License for more details. | 16 | # GNU General Public License for more details. |
17 | # | 17 | # |
18 | # You should have received a copy of the GNU General Public License | 18 | # You should have received a copy of the GNU General Public License |
19 | # along with this program; if not, write to the Free Software | 19 | # along with this program; if not, write to the Free Software |
20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
21 | # MA 02111-1307 USA | 21 | # MA 02111-1307 USA |
22 | # | 22 | # |
23 | 23 | ||
24 | include $(TOPDIR)/config.mk | 24 | include $(TOPDIR)/config.mk |
25 | 25 | ||
26 | LIB := $(obj)libserial.a | 26 | LIB := $(obj)libserial.a |
27 | 27 | ||
28 | COBJS-$(CONFIG_ATMEL_USART) += atmel_usart.o | 28 | COBJS-$(CONFIG_ATMEL_USART) += atmel_usart.o |
29 | COBJS-$(CONFIG_MCFUART) += mcfuart.o | 29 | COBJS-$(CONFIG_MCFUART) += mcfuart.o |
30 | COBJS-$(CONFIG_NS9750_UART) += ns9750_serial.o | 30 | COBJS-$(CONFIG_NS9750_UART) += ns9750_serial.o |
31 | COBJS-y += ns16550.o | 31 | COBJS-$(CONFIG_SYS_NS16550) += ns16550.o |
32 | COBJS-$(CONFIG_DRIVER_S3C4510_UART) += s3c4510b_uart.o | 32 | COBJS-$(CONFIG_DRIVER_S3C4510_UART) += s3c4510b_uart.o |
33 | COBJS-$(CONFIG_S3C64XX) += s3c64xx.o | 33 | COBJS-$(CONFIG_S3C64XX) += s3c64xx.o |
34 | COBJS-y += serial.o | 34 | COBJS-$(CONFIG_SYS_NS16550_SERIAL) += serial.o |
35 | COBJS-$(CONFIG_IXP_SERIAL) += serial_ixp.o | 35 | COBJS-$(CONFIG_IXP_SERIAL) += serial_ixp.o |
36 | COBJS-$(CONFIG_MAX3100_SERIAL) += serial_max3100.o | 36 | COBJS-$(CONFIG_MAX3100_SERIAL) += serial_max3100.o |
37 | COBJS-$(CONFIG_PL010_SERIAL) += serial_pl01x.o | 37 | COBJS-$(CONFIG_PL010_SERIAL) += serial_pl01x.o |
38 | COBJS-$(CONFIG_PL011_SERIAL) += serial_pl01x.o | 38 | COBJS-$(CONFIG_PL011_SERIAL) += serial_pl01x.o |
39 | COBJS-$(CONFIG_XILINX_UARTLITE) += serial_xuartlite.o | 39 | COBJS-$(CONFIG_XILINX_UARTLITE) += serial_xuartlite.o |
40 | COBJS-$(CONFIG_SCIF_CONSOLE) += serial_sh.o | 40 | COBJS-$(CONFIG_SCIF_CONSOLE) += serial_sh.o |
41 | COBJS-$(CONFIG_USB_TTY) += usbtty.o | 41 | COBJS-$(CONFIG_USB_TTY) += usbtty.o |
42 | COBJS-$(CONFIG_VCT_SERIAL) += vct.o | 42 | COBJS-$(CONFIG_VCT_SERIAL) += vct.o |
43 | 43 | ||
44 | COBJS := $(sort $(COBJS-y)) | 44 | COBJS := $(sort $(COBJS-y)) |
45 | SRCS := $(COBJS:.o=.c) | 45 | SRCS := $(COBJS:.o=.c) |
46 | OBJS := $(addprefix $(obj),$(COBJS)) | 46 | OBJS := $(addprefix $(obj),$(COBJS)) |
47 | 47 | ||
48 | all: $(LIB) | 48 | all: $(LIB) |
49 | 49 | ||
50 | $(LIB): $(obj).depend $(OBJS) | 50 | $(LIB): $(obj).depend $(OBJS) |
51 | $(AR) $(ARFLAGS) $@ $(OBJS) | 51 | $(AR) $(ARFLAGS) $@ $(OBJS) |
52 | 52 | ||
53 | ######################################################################### | 53 | ######################################################################### |
54 | 54 | ||
55 | # defines $(obj).depend target | 55 | # defines $(obj).depend target |
56 | include $(SRCTREE)/rules.mk | 56 | include $(SRCTREE)/rules.mk |
57 | 57 | ||
58 | sinclude $(obj).depend | 58 | sinclude $(obj).depend |
59 | 59 | ||
60 | ######################################################################### | 60 | ######################################################################### |
61 | 61 |
drivers/serial/ns16550.c
1 | /* | 1 | /* |
2 | * COM1 NS16550 support | 2 | * COM1 NS16550 support |
3 | * originally from linux source (arch/ppc/boot/ns16550.c) | 3 | * originally from linux source (arch/ppc/boot/ns16550.c) |
4 | * modified to use CONFIG_SYS_ISA_MEM and new defines | 4 | * modified to use CONFIG_SYS_ISA_MEM and new defines |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <config.h> | 7 | #include <config.h> |
8 | |||
9 | #ifdef CONFIG_SYS_NS16550 | ||
10 | |||
11 | #include <ns16550.h> | 8 | #include <ns16550.h> |
12 | 9 | ||
13 | #define LCRVAL LCR_8N1 /* 8 data, 1 stop, no parity */ | 10 | #define LCRVAL LCR_8N1 /* 8 data, 1 stop, no parity */ |
14 | #define MCRVAL (MCR_DTR | MCR_RTS) /* RTS/DTR */ | 11 | #define MCRVAL (MCR_DTR | MCR_RTS) /* RTS/DTR */ |
15 | #define FCRVAL (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR) /* Clear & enable FIFOs */ | 12 | #define FCRVAL (FCR_FIFO_EN | FCR_RXSR | FCR_TXSR) /* Clear & enable FIFOs */ |
16 | 13 | ||
17 | void NS16550_init (NS16550_t com_port, int baud_divisor) | 14 | void NS16550_init (NS16550_t com_port, int baud_divisor) |
18 | { | 15 | { |
19 | com_port->ier = 0x00; | 16 | com_port->ier = 0x00; |
20 | #ifdef CONFIG_OMAP | 17 | #ifdef CONFIG_OMAP |
21 | com_port->mdr1 = 0x7; /* mode select reset TL16C750*/ | 18 | com_port->mdr1 = 0x7; /* mode select reset TL16C750*/ |
22 | #endif | 19 | #endif |
23 | com_port->lcr = LCR_BKSE | LCRVAL; | 20 | com_port->lcr = LCR_BKSE | LCRVAL; |
24 | com_port->dll = 0; | 21 | com_port->dll = 0; |
25 | com_port->dlm = 0; | 22 | com_port->dlm = 0; |
26 | com_port->lcr = LCRVAL; | 23 | com_port->lcr = LCRVAL; |
27 | com_port->mcr = MCRVAL; | 24 | com_port->mcr = MCRVAL; |
28 | com_port->fcr = FCRVAL; | 25 | com_port->fcr = FCRVAL; |
29 | com_port->lcr = LCR_BKSE | LCRVAL; | 26 | com_port->lcr = LCR_BKSE | LCRVAL; |
30 | com_port->dll = baud_divisor & 0xff; | 27 | com_port->dll = baud_divisor & 0xff; |
31 | com_port->dlm = (baud_divisor >> 8) & 0xff; | 28 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
32 | com_port->lcr = LCRVAL; | 29 | com_port->lcr = LCRVAL; |
33 | #if defined(CONFIG_OMAP) | 30 | #if defined(CONFIG_OMAP) |
34 | #if defined(CONFIG_APTIX) | 31 | #if defined(CONFIG_APTIX) |
35 | com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */ | 32 | com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */ |
36 | #else | 33 | #else |
37 | com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */ | 34 | com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */ |
38 | #endif | 35 | #endif |
39 | #endif | 36 | #endif /* CONFIG_OMAP */ |
40 | } | 37 | } |
41 | 38 | ||
42 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS | 39 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
43 | void NS16550_reinit (NS16550_t com_port, int baud_divisor) | 40 | void NS16550_reinit (NS16550_t com_port, int baud_divisor) |
44 | { | 41 | { |
45 | com_port->ier = 0x00; | 42 | com_port->ier = 0x00; |
46 | com_port->lcr = LCR_BKSE | LCRVAL; | 43 | com_port->lcr = LCR_BKSE | LCRVAL; |
47 | com_port->dll = 0; | 44 | com_port->dll = 0; |
48 | com_port->dlm = 0; | 45 | com_port->dlm = 0; |
49 | com_port->lcr = LCRVAL; | 46 | com_port->lcr = LCRVAL; |
50 | com_port->mcr = MCRVAL; | 47 | com_port->mcr = MCRVAL; |
51 | com_port->fcr = FCRVAL; | 48 | com_port->fcr = FCRVAL; |
52 | com_port->lcr = LCR_BKSE; | 49 | com_port->lcr = LCR_BKSE; |
53 | com_port->dll = baud_divisor & 0xff; | 50 | com_port->dll = baud_divisor & 0xff; |
54 | com_port->dlm = (baud_divisor >> 8) & 0xff; | 51 | com_port->dlm = (baud_divisor >> 8) & 0xff; |
55 | com_port->lcr = LCRVAL; | 52 | com_port->lcr = LCRVAL; |
56 | } | 53 | } |
57 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 54 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
58 | 55 | ||
59 | void NS16550_putc (NS16550_t com_port, char c) | 56 | void NS16550_putc (NS16550_t com_port, char c) |
60 | { | 57 | { |
61 | while ((com_port->lsr & LSR_THRE) == 0); | 58 | while ((com_port->lsr & LSR_THRE) == 0); |
62 | com_port->thr = c; | 59 | com_port->thr = c; |
63 | } | 60 | } |
64 | 61 | ||
65 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS | 62 | #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
66 | char NS16550_getc (NS16550_t com_port) | 63 | char NS16550_getc (NS16550_t com_port) |
67 | { | 64 | { |
68 | while ((com_port->lsr & LSR_DR) == 0) { | 65 | while ((com_port->lsr & LSR_DR) == 0) { |
69 | #ifdef CONFIG_USB_TTY | 66 | #ifdef CONFIG_USB_TTY |
70 | extern void usbtty_poll(void); | 67 | extern void usbtty_poll(void); |
71 | usbtty_poll(); | 68 | usbtty_poll(); |
72 | #endif | 69 | #endif |
73 | } | 70 | } |
74 | return (com_port->rbr); | 71 | return (com_port->rbr); |
75 | } | 72 | } |
76 | 73 | ||
77 | int NS16550_tstc (NS16550_t com_port) | 74 | int NS16550_tstc (NS16550_t com_port) |
78 | { | 75 | { |
79 | return ((com_port->lsr & LSR_DR) != 0); | 76 | return ((com_port->lsr & LSR_DR) != 0); |
80 | } | 77 | } |
81 | 78 | ||
82 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 79 | #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
83 | #endif | ||
84 | 80 |
drivers/serial/serial.c
1 | /* | 1 | /* |
2 | * (C) Copyright 2000 | 2 | * (C) Copyright 2000 |
3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. | 3 | * Rob Taylor, Flying Pig Systems. robt@flyingpig.com. |
4 | * | 4 | * |
5 | * See file CREDITS for list of people who contributed to this | 5 | * See file CREDITS for list of people who contributed to this |
6 | * project. | 6 | * project. |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or | 8 | * This program is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU General Public License as | 9 | * modify it under the terms of the GNU General Public License as |
10 | * published by the Free Software Foundation; either version 2 of | 10 | * published by the Free Software Foundation; either version 2 of |
11 | * the License, or (at your option) any later version. | 11 | * the License, or (at your option) any later version. |
12 | * | 12 | * |
13 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | * | 17 | * |
18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software | 19 | * along with this program; if not, write to the Free Software |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
21 | * MA 02111-1307 USA | 21 | * MA 02111-1307 USA |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <common.h> | 24 | #include <common.h> |
25 | 25 | ||
26 | #ifdef CONFIG_SYS_NS16550_SERIAL | ||
27 | |||
28 | #include <ns16550.h> | 26 | #include <ns16550.h> |
29 | #ifdef CONFIG_NS87308 | 27 | #ifdef CONFIG_NS87308 |
30 | #include <ns87308.h> | 28 | #include <ns87308.h> |
31 | #endif | 29 | #endif |
32 | 30 | ||
33 | #if defined (CONFIG_SERIAL_MULTI) | 31 | #if defined (CONFIG_SERIAL_MULTI) |
34 | #include <serial.h> | 32 | #include <serial.h> |
35 | #endif | 33 | #endif |
36 | 34 | ||
37 | DECLARE_GLOBAL_DATA_PTR; | 35 | DECLARE_GLOBAL_DATA_PTR; |
38 | 36 | ||
39 | #if !defined(CONFIG_CONS_INDEX) | 37 | #if !defined(CONFIG_CONS_INDEX) |
40 | #if defined (CONFIG_SERIAL_MULTI) | 38 | #if defined (CONFIG_SERIAL_MULTI) |
41 | /* with CONFIG_SERIAL_MULTI we might have no console | 39 | /* with CONFIG_SERIAL_MULTI we might have no console |
42 | * on these devices | 40 | * on these devices |
43 | */ | 41 | */ |
44 | #else | 42 | #else |
45 | #error "No console index specified." | 43 | #error "No console index specified." |
46 | #endif /* CONFIG_SERIAL_MULTI */ | 44 | #endif /* CONFIG_SERIAL_MULTI */ |
47 | #elif (CONFIG_CONS_INDEX < 1) || (CONFIG_CONS_INDEX > 4) | 45 | #elif (CONFIG_CONS_INDEX < 1) || (CONFIG_CONS_INDEX > 4) |
48 | #error "Invalid console index value." | 46 | #error "Invalid console index value." |
49 | #endif | 47 | #endif |
50 | 48 | ||
51 | #if CONFIG_CONS_INDEX == 1 && !defined(CONFIG_SYS_NS16550_COM1) | 49 | #if CONFIG_CONS_INDEX == 1 && !defined(CONFIG_SYS_NS16550_COM1) |
52 | #error "Console port 1 defined but not configured." | 50 | #error "Console port 1 defined but not configured." |
53 | #elif CONFIG_CONS_INDEX == 2 && !defined(CONFIG_SYS_NS16550_COM2) | 51 | #elif CONFIG_CONS_INDEX == 2 && !defined(CONFIG_SYS_NS16550_COM2) |
54 | #error "Console port 2 defined but not configured." | 52 | #error "Console port 2 defined but not configured." |
55 | #elif CONFIG_CONS_INDEX == 3 && !defined(CONFIG_SYS_NS16550_COM3) | 53 | #elif CONFIG_CONS_INDEX == 3 && !defined(CONFIG_SYS_NS16550_COM3) |
56 | #error "Console port 3 defined but not configured." | 54 | #error "Console port 3 defined but not configured." |
57 | #elif CONFIG_CONS_INDEX == 4 && !defined(CONFIG_SYS_NS16550_COM4) | 55 | #elif CONFIG_CONS_INDEX == 4 && !defined(CONFIG_SYS_NS16550_COM4) |
58 | #error "Console port 4 defined but not configured." | 56 | #error "Console port 4 defined but not configured." |
59 | #endif | 57 | #endif |
60 | 58 | ||
61 | /* Note: The port number specified in the functions is 1 based. | 59 | /* Note: The port number specified in the functions is 1 based. |
62 | * the array is 0 based. | 60 | * the array is 0 based. |
63 | */ | 61 | */ |
64 | static NS16550_t serial_ports[4] = { | 62 | static NS16550_t serial_ports[4] = { |
65 | #ifdef CONFIG_SYS_NS16550_COM1 | 63 | #ifdef CONFIG_SYS_NS16550_COM1 |
66 | (NS16550_t)CONFIG_SYS_NS16550_COM1, | 64 | (NS16550_t)CONFIG_SYS_NS16550_COM1, |
67 | #else | 65 | #else |
68 | NULL, | 66 | NULL, |
69 | #endif | 67 | #endif |
70 | #ifdef CONFIG_SYS_NS16550_COM2 | 68 | #ifdef CONFIG_SYS_NS16550_COM2 |
71 | (NS16550_t)CONFIG_SYS_NS16550_COM2, | 69 | (NS16550_t)CONFIG_SYS_NS16550_COM2, |
72 | #else | 70 | #else |
73 | NULL, | 71 | NULL, |
74 | #endif | 72 | #endif |
75 | #ifdef CONFIG_SYS_NS16550_COM3 | 73 | #ifdef CONFIG_SYS_NS16550_COM3 |
76 | (NS16550_t)CONFIG_SYS_NS16550_COM3, | 74 | (NS16550_t)CONFIG_SYS_NS16550_COM3, |
77 | #else | 75 | #else |
78 | NULL, | 76 | NULL, |
79 | #endif | 77 | #endif |
80 | #ifdef CONFIG_SYS_NS16550_COM4 | 78 | #ifdef CONFIG_SYS_NS16550_COM4 |
81 | (NS16550_t)CONFIG_SYS_NS16550_COM4 | 79 | (NS16550_t)CONFIG_SYS_NS16550_COM4 |
82 | #else | 80 | #else |
83 | NULL | 81 | NULL |
84 | #endif | 82 | #endif |
85 | }; | 83 | }; |
86 | 84 | ||
87 | #define PORT serial_ports[port-1] | 85 | #define PORT serial_ports[port-1] |
88 | #if defined(CONFIG_CONS_INDEX) | 86 | #if defined(CONFIG_CONS_INDEX) |
89 | #define CONSOLE (serial_ports[CONFIG_CONS_INDEX-1]) | 87 | #define CONSOLE (serial_ports[CONFIG_CONS_INDEX-1]) |
90 | #endif | 88 | #endif |
91 | 89 | ||
92 | #if defined(CONFIG_SERIAL_MULTI) | 90 | #if defined(CONFIG_SERIAL_MULTI) |
93 | 91 | ||
94 | /* Multi serial device functions */ | 92 | /* Multi serial device functions */ |
95 | #define DECLARE_ESERIAL_FUNCTIONS(port) \ | 93 | #define DECLARE_ESERIAL_FUNCTIONS(port) \ |
96 | int eserial##port##_init (void) {\ | 94 | int eserial##port##_init (void) {\ |
97 | int clock_divisor; \ | 95 | int clock_divisor; \ |
98 | clock_divisor = calc_divisor(serial_ports[port-1]); \ | 96 | clock_divisor = calc_divisor(serial_ports[port-1]); \ |
99 | NS16550_init(serial_ports[port-1], clock_divisor); \ | 97 | NS16550_init(serial_ports[port-1], clock_divisor); \ |
100 | return(0);}\ | 98 | return(0);}\ |
101 | void eserial##port##_setbrg (void) {\ | 99 | void eserial##port##_setbrg (void) {\ |
102 | serial_setbrg_dev(port);}\ | 100 | serial_setbrg_dev(port);}\ |
103 | int eserial##port##_getc (void) {\ | 101 | int eserial##port##_getc (void) {\ |
104 | return serial_getc_dev(port);}\ | 102 | return serial_getc_dev(port);}\ |
105 | int eserial##port##_tstc (void) {\ | 103 | int eserial##port##_tstc (void) {\ |
106 | return serial_tstc_dev(port);}\ | 104 | return serial_tstc_dev(port);}\ |
107 | void eserial##port##_putc (const char c) {\ | 105 | void eserial##port##_putc (const char c) {\ |
108 | serial_putc_dev(port, c);}\ | 106 | serial_putc_dev(port, c);}\ |
109 | void eserial##port##_puts (const char *s) {\ | 107 | void eserial##port##_puts (const char *s) {\ |
110 | serial_puts_dev(port, s);} | 108 | serial_puts_dev(port, s);} |
111 | 109 | ||
112 | /* Serial device descriptor */ | 110 | /* Serial device descriptor */ |
113 | #define INIT_ESERIAL_STRUCTURE(port,name,bus) {\ | 111 | #define INIT_ESERIAL_STRUCTURE(port,name,bus) {\ |
114 | name,\ | 112 | name,\ |
115 | bus,\ | 113 | bus,\ |
116 | eserial##port##_init,\ | 114 | eserial##port##_init,\ |
117 | eserial##port##_setbrg,\ | 115 | eserial##port##_setbrg,\ |
118 | eserial##port##_getc,\ | 116 | eserial##port##_getc,\ |
119 | eserial##port##_tstc,\ | 117 | eserial##port##_tstc,\ |
120 | eserial##port##_putc,\ | 118 | eserial##port##_putc,\ |
121 | eserial##port##_puts, } | 119 | eserial##port##_puts, } |
122 | 120 | ||
123 | #endif /* CONFIG_SERIAL_MULTI */ | 121 | #endif /* CONFIG_SERIAL_MULTI */ |
124 | 122 | ||
125 | static int calc_divisor (NS16550_t port) | 123 | static int calc_divisor (NS16550_t port) |
126 | { | 124 | { |
127 | #ifdef CONFIG_OMAP1510 | 125 | #ifdef CONFIG_OMAP1510 |
128 | /* If can't cleanly clock 115200 set div to 1 */ | 126 | /* If can't cleanly clock 115200 set div to 1 */ |
129 | if ((CONFIG_SYS_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { | 127 | if ((CONFIG_SYS_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { |
130 | port->osc_12m_sel = OSC_12M_SEL; /* enable 6.5 * divisor */ | 128 | port->osc_12m_sel = OSC_12M_SEL; /* enable 6.5 * divisor */ |
131 | return (1); /* return 1 for base divisor */ | 129 | return (1); /* return 1 for base divisor */ |
132 | } | 130 | } |
133 | port->osc_12m_sel = 0; /* clear if previsouly set */ | 131 | port->osc_12m_sel = 0; /* clear if previsouly set */ |
134 | #endif | 132 | #endif |
135 | #ifdef CONFIG_OMAP1610 | 133 | #ifdef CONFIG_OMAP1610 |
136 | /* If can't cleanly clock 115200 set div to 1 */ | 134 | /* If can't cleanly clock 115200 set div to 1 */ |
137 | if ((CONFIG_SYS_NS16550_CLK == 48000000) && (gd->baudrate == 115200)) { | 135 | if ((CONFIG_SYS_NS16550_CLK == 48000000) && (gd->baudrate == 115200)) { |
138 | return (26); /* return 26 for base divisor */ | 136 | return (26); /* return 26 for base divisor */ |
139 | } | 137 | } |
140 | #endif | 138 | #endif |
141 | 139 | ||
142 | #ifdef CONFIG_APTIX | 140 | #ifdef CONFIG_APTIX |
143 | #define MODE_X_DIV 13 | 141 | #define MODE_X_DIV 13 |
144 | #else | 142 | #else |
145 | #define MODE_X_DIV 16 | 143 | #define MODE_X_DIV 16 |
146 | #endif | 144 | #endif |
147 | 145 | ||
148 | /* Compute divisor value. Normally, we should simply return: | 146 | /* Compute divisor value. Normally, we should simply return: |
149 | * CONFIG_SYS_NS16550_CLK) / MODE_X_DIV / gd->baudrate | 147 | * CONFIG_SYS_NS16550_CLK) / MODE_X_DIV / gd->baudrate |
150 | * but we need to round that value by adding 0.5. | 148 | * but we need to round that value by adding 0.5. |
151 | * Rounding is especially important at high baud rates. | 149 | * Rounding is especially important at high baud rates. |
152 | */ | 150 | */ |
153 | return (CONFIG_SYS_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) / | 151 | return (CONFIG_SYS_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) / |
154 | (MODE_X_DIV * gd->baudrate); | 152 | (MODE_X_DIV * gd->baudrate); |
155 | } | 153 | } |
156 | 154 | ||
157 | #if !defined(CONFIG_SERIAL_MULTI) | 155 | #if !defined(CONFIG_SERIAL_MULTI) |
158 | int serial_init (void) | 156 | int serial_init (void) |
159 | { | 157 | { |
160 | int clock_divisor; | 158 | int clock_divisor; |
161 | 159 | ||
162 | #ifdef CONFIG_NS87308 | 160 | #ifdef CONFIG_NS87308 |
163 | initialise_ns87308(); | 161 | initialise_ns87308(); |
164 | #endif | 162 | #endif |
165 | 163 | ||
166 | #ifdef CONFIG_SYS_NS16550_COM1 | 164 | #ifdef CONFIG_SYS_NS16550_COM1 |
167 | clock_divisor = calc_divisor(serial_ports[0]); | 165 | clock_divisor = calc_divisor(serial_ports[0]); |
168 | NS16550_init(serial_ports[0], clock_divisor); | 166 | NS16550_init(serial_ports[0], clock_divisor); |
169 | #endif | 167 | #endif |
170 | #ifdef CONFIG_SYS_NS16550_COM2 | 168 | #ifdef CONFIG_SYS_NS16550_COM2 |
171 | clock_divisor = calc_divisor(serial_ports[1]); | 169 | clock_divisor = calc_divisor(serial_ports[1]); |
172 | NS16550_init(serial_ports[1], clock_divisor); | 170 | NS16550_init(serial_ports[1], clock_divisor); |
173 | #endif | 171 | #endif |
174 | #ifdef CONFIG_SYS_NS16550_COM3 | 172 | #ifdef CONFIG_SYS_NS16550_COM3 |
175 | clock_divisor = calc_divisor(serial_ports[2]); | 173 | clock_divisor = calc_divisor(serial_ports[2]); |
176 | NS16550_init(serial_ports[2], clock_divisor); | 174 | NS16550_init(serial_ports[2], clock_divisor); |
177 | #endif | 175 | #endif |
178 | #ifdef CONFIG_SYS_NS16550_COM4 | 176 | #ifdef CONFIG_SYS_NS16550_COM4 |
179 | clock_divisor = calc_divisor(serial_ports[3]); | 177 | clock_divisor = calc_divisor(serial_ports[3]); |
180 | NS16550_init(serial_ports[3], clock_divisor); | 178 | NS16550_init(serial_ports[3], clock_divisor); |
181 | #endif | 179 | #endif |
182 | 180 | ||
183 | return (0); | 181 | return (0); |
184 | } | 182 | } |
185 | #endif | 183 | #endif |
186 | 184 | ||
187 | void | 185 | void |
188 | _serial_putc(const char c,const int port) | 186 | _serial_putc(const char c,const int port) |
189 | { | 187 | { |
190 | if (c == '\n') | 188 | if (c == '\n') |
191 | NS16550_putc(PORT, '\r'); | 189 | NS16550_putc(PORT, '\r'); |
192 | 190 | ||
193 | NS16550_putc(PORT, c); | 191 | NS16550_putc(PORT, c); |
194 | } | 192 | } |
195 | 193 | ||
196 | void | 194 | void |
197 | _serial_putc_raw(const char c,const int port) | 195 | _serial_putc_raw(const char c,const int port) |
198 | { | 196 | { |
199 | NS16550_putc(PORT, c); | 197 | NS16550_putc(PORT, c); |
200 | } | 198 | } |
201 | 199 | ||
202 | void | 200 | void |
203 | _serial_puts (const char *s,const int port) | 201 | _serial_puts (const char *s,const int port) |
204 | { | 202 | { |
205 | while (*s) { | 203 | while (*s) { |
206 | _serial_putc (*s++,port); | 204 | _serial_putc (*s++,port); |
207 | } | 205 | } |
208 | } | 206 | } |
209 | 207 | ||
210 | 208 | ||
211 | int | 209 | int |
212 | _serial_getc(const int port) | 210 | _serial_getc(const int port) |
213 | { | 211 | { |
214 | return NS16550_getc(PORT); | 212 | return NS16550_getc(PORT); |
215 | } | 213 | } |
216 | 214 | ||
217 | int | 215 | int |
218 | _serial_tstc(const int port) | 216 | _serial_tstc(const int port) |
219 | { | 217 | { |
220 | return NS16550_tstc(PORT); | 218 | return NS16550_tstc(PORT); |
221 | } | 219 | } |
222 | 220 | ||
223 | void | 221 | void |
224 | _serial_setbrg (const int port) | 222 | _serial_setbrg (const int port) |
225 | { | 223 | { |
226 | int clock_divisor; | 224 | int clock_divisor; |
227 | 225 | ||
228 | clock_divisor = calc_divisor(PORT); | 226 | clock_divisor = calc_divisor(PORT); |
229 | NS16550_reinit(PORT, clock_divisor); | 227 | NS16550_reinit(PORT, clock_divisor); |
230 | } | 228 | } |
231 | 229 | ||
232 | #if defined(CONFIG_SERIAL_MULTI) | 230 | #if defined(CONFIG_SERIAL_MULTI) |
233 | static inline void | 231 | static inline void |
234 | serial_putc_dev(unsigned int dev_index,const char c) | 232 | serial_putc_dev(unsigned int dev_index,const char c) |
235 | { | 233 | { |
236 | _serial_putc(c,dev_index); | 234 | _serial_putc(c,dev_index); |
237 | } | 235 | } |
238 | #else | 236 | #else |
239 | void | 237 | void |
240 | serial_putc(const char c) | 238 | serial_putc(const char c) |
241 | { | 239 | { |
242 | _serial_putc(c,CONFIG_CONS_INDEX); | 240 | _serial_putc(c,CONFIG_CONS_INDEX); |
243 | } | 241 | } |
244 | #endif | 242 | #endif |
245 | 243 | ||
246 | #if defined(CONFIG_SERIAL_MULTI) | 244 | #if defined(CONFIG_SERIAL_MULTI) |
247 | static inline void | 245 | static inline void |
248 | serial_putc_raw_dev(unsigned int dev_index,const char c) | 246 | serial_putc_raw_dev(unsigned int dev_index,const char c) |
249 | { | 247 | { |
250 | _serial_putc_raw(c,dev_index); | 248 | _serial_putc_raw(c,dev_index); |
251 | } | 249 | } |
252 | #else | 250 | #else |
253 | void | 251 | void |
254 | serial_putc_raw(const char c) | 252 | serial_putc_raw(const char c) |
255 | { | 253 | { |
256 | _serial_putc_raw(c,CONFIG_CONS_INDEX); | 254 | _serial_putc_raw(c,CONFIG_CONS_INDEX); |
257 | } | 255 | } |
258 | #endif | 256 | #endif |
259 | 257 | ||
260 | #if defined(CONFIG_SERIAL_MULTI) | 258 | #if defined(CONFIG_SERIAL_MULTI) |
261 | static inline void | 259 | static inline void |
262 | serial_puts_dev(unsigned int dev_index,const char *s) | 260 | serial_puts_dev(unsigned int dev_index,const char *s) |
263 | { | 261 | { |
264 | _serial_puts(s,dev_index); | 262 | _serial_puts(s,dev_index); |
265 | } | 263 | } |
266 | #else | 264 | #else |
267 | void | 265 | void |
268 | serial_puts(const char *s) | 266 | serial_puts(const char *s) |
269 | { | 267 | { |
270 | _serial_puts(s,CONFIG_CONS_INDEX); | 268 | _serial_puts(s,CONFIG_CONS_INDEX); |
271 | } | 269 | } |
272 | #endif | 270 | #endif |
273 | 271 | ||
274 | #if defined(CONFIG_SERIAL_MULTI) | 272 | #if defined(CONFIG_SERIAL_MULTI) |
275 | static inline int | 273 | static inline int |
276 | serial_getc_dev(unsigned int dev_index) | 274 | serial_getc_dev(unsigned int dev_index) |
277 | { | 275 | { |
278 | return _serial_getc(dev_index); | 276 | return _serial_getc(dev_index); |
279 | } | 277 | } |
280 | #else | 278 | #else |
281 | int | 279 | int |
282 | serial_getc(void) | 280 | serial_getc(void) |
283 | { | 281 | { |
284 | return _serial_getc(CONFIG_CONS_INDEX); | 282 | return _serial_getc(CONFIG_CONS_INDEX); |
285 | } | 283 | } |
286 | #endif | 284 | #endif |
287 | 285 | ||
288 | #if defined(CONFIG_SERIAL_MULTI) | 286 | #if defined(CONFIG_SERIAL_MULTI) |
289 | static inline int | 287 | static inline int |
290 | serial_tstc_dev(unsigned int dev_index) | 288 | serial_tstc_dev(unsigned int dev_index) |
291 | { | 289 | { |
292 | return _serial_tstc(dev_index); | 290 | return _serial_tstc(dev_index); |
293 | } | 291 | } |
294 | #else | 292 | #else |
295 | int | 293 | int |
296 | serial_tstc(void) | 294 | serial_tstc(void) |
297 | { | 295 | { |
298 | return _serial_tstc(CONFIG_CONS_INDEX); | 296 | return _serial_tstc(CONFIG_CONS_INDEX); |
299 | } | 297 | } |
300 | #endif | 298 | #endif |
301 | 299 | ||
302 | #if defined(CONFIG_SERIAL_MULTI) | 300 | #if defined(CONFIG_SERIAL_MULTI) |
303 | static inline void | 301 | static inline void |
304 | serial_setbrg_dev(unsigned int dev_index) | 302 | serial_setbrg_dev(unsigned int dev_index) |
305 | { | 303 | { |
306 | _serial_setbrg(dev_index); | 304 | _serial_setbrg(dev_index); |
307 | } | 305 | } |
308 | #else | 306 | #else |
309 | void | 307 | void |
310 | serial_setbrg(void) | 308 | serial_setbrg(void) |
311 | { | 309 | { |
312 | _serial_setbrg(CONFIG_CONS_INDEX); | 310 | _serial_setbrg(CONFIG_CONS_INDEX); |
313 | } | 311 | } |
314 | #endif | 312 | #endif |
315 | 313 | ||
316 | #if defined(CONFIG_SERIAL_MULTI) | 314 | #if defined(CONFIG_SERIAL_MULTI) |
317 | 315 | ||
318 | DECLARE_ESERIAL_FUNCTIONS(1); | 316 | DECLARE_ESERIAL_FUNCTIONS(1); |
319 | struct serial_device eserial1_device = | 317 | struct serial_device eserial1_device = |
320 | INIT_ESERIAL_STRUCTURE(1,"eserial0","EUART1"); | 318 | INIT_ESERIAL_STRUCTURE(1,"eserial0","EUART1"); |
321 | DECLARE_ESERIAL_FUNCTIONS(2); | 319 | DECLARE_ESERIAL_FUNCTIONS(2); |
322 | struct serial_device eserial2_device = | 320 | struct serial_device eserial2_device = |
323 | INIT_ESERIAL_STRUCTURE(2,"eserial1","EUART2"); | 321 | INIT_ESERIAL_STRUCTURE(2,"eserial1","EUART2"); |
324 | DECLARE_ESERIAL_FUNCTIONS(3); | 322 | DECLARE_ESERIAL_FUNCTIONS(3); |
325 | struct serial_device eserial3_device = | 323 | struct serial_device eserial3_device = |
326 | INIT_ESERIAL_STRUCTURE(3,"eserial2","EUART3"); | 324 | INIT_ESERIAL_STRUCTURE(3,"eserial2","EUART3"); |
327 | DECLARE_ESERIAL_FUNCTIONS(4); | 325 | DECLARE_ESERIAL_FUNCTIONS(4); |
328 | struct serial_device eserial4_device = | 326 | struct serial_device eserial4_device = |
329 | INIT_ESERIAL_STRUCTURE(4,"eserial3","EUART4"); | 327 | INIT_ESERIAL_STRUCTURE(4,"eserial3","EUART4"); |
330 | #endif /* CONFIG_SERIAL_MULTI */ | 328 | #endif /* CONFIG_SERIAL_MULTI */ |
331 | |||
332 | #endif | ||
333 | 329 |