From: Jean-Christophe PLAGNIOL-VILLARD Date: Fri, 27 Mar 2009 22:26:43 +0000 (+0100) Subject: at91rm9200: move serial driver to drivers/serial X-Git-Tag: v2009.06-rc1~66^2~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=beebd851cdbc9dd070bcdfec1fd8f17e3cc91bc0;p=u-boot at91rm9200: move serial driver to drivers/serial add CONFIG_AT91RM9200_USART to activate the driver Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- diff --git a/cpu/arm920t/at91rm9200/Makefile b/cpu/arm920t/at91rm9200/Makefile index ab4c52c8fb..67f17fadfe 100644 --- a/cpu/arm920t/at91rm9200/Makefile +++ b/cpu/arm920t/at91rm9200/Makefile @@ -26,7 +26,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)lib$(SOC).a COBJS = bcm5221.o dm9161.o ether.o i2c.o interrupts.o \ - lxt972.o serial.o usb.o spi.o + lxt972.o usb.o spi.o SOBJS = lowlevel_init.o SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) diff --git a/cpu/arm920t/at91rm9200/serial.c b/cpu/arm920t/at91rm9200/serial.c deleted file mode 100644 index d563445492..0000000000 --- a/cpu/arm920t/at91rm9200/serial.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * (C) Copyright 2002 - * Lineo, Inc - * Bernhard Kuhn - * - * (C) Copyright 2002 - * Sysgo Real-Time Solutions, GmbH - * Marius Groeger - * - * (C) Copyright 2002 - * Sysgo Real-Time Solutions, GmbH - * Alex Zuepke - * - * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include - -DECLARE_GLOBAL_DATA_PTR; - -#if !defined(CONFIG_DBGU) && !defined(CONFIG_USART0) && !defined(CONFIG_USART1) -#error must define one of CONFIG_DBGU or CONFIG_USART0 or CONFIG_USART1 -#endif - -/* ggi thunder */ -#ifdef CONFIG_DBGU -AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU; -#endif -#ifdef CONFIG_USART0 -AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US0; -#endif -#ifdef CONFIG_USART1 -AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US1; -#endif - -void serial_setbrg (void) -{ - int baudrate; - - if ((baudrate = gd->baudrate) <= 0) - baudrate = CONFIG_BAUDRATE; - /* MASTER_CLOCK/(16 * baudrate) */ - us->US_BRGR = (AT91C_MASTER_CLOCK >> 4) / (unsigned)baudrate; -} - -int serial_init (void) -{ - /* make any port initializations specific to this port */ -#ifdef CONFIG_DBGU - *AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD; /* PA 31 & 30 */ - *AT91C_PMC_PCER = 1 << AT91C_ID_SYS; /* enable clock */ -#endif -#ifdef CONFIG_USART0 - *AT91C_PIOA_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0; - *AT91C_PMC_PCER |= 1 << AT91C_ID_USART0; /* enable clock */ -#endif -#ifdef CONFIG_USART1 - *AT91C_PIOB_PDR = AT91C_PB21_TXD1 | AT91C_PB20_RXD1; - *AT91C_PMC_PCER |= 1 << AT91C_ID_USART1; /* enable clock */ -#endif - serial_setbrg (); - - us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX; - us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; - us->US_MR = - (AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | - AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT); - us->US_IMR = ~0ul; - return (0); -} - -void serial_putc (const char c) -{ - if (c == '\n') - serial_putc ('\r'); - while ((us->US_CSR & AT91C_US_TXRDY) == 0); - us->US_THR = c; -} - -void serial_puts (const char *s) -{ - while (*s) { - serial_putc (*s++); - } -} - -int serial_getc (void) -{ - while ((us->US_CSR & AT91C_US_RXRDY) == 0); - return us->US_RHR; -} - -int serial_tstc (void) -{ - return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY); -} diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 696d5fbbba..bb99a349ac 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -26,6 +26,7 @@ include $(TOPDIR)/config.mk LIB := $(obj)libserial.a COBJS-$(CONFIG_ARM_DCC) += arm_dcc.o +COBJS-$(CONFIG_AT91RM9200_USART) += at91rm9200_usart.o COBJS-$(CONFIG_ATMEL_USART) += atmel_usart.o COBJS-$(CONFIG_MCFUART) += mcfuart.o COBJS-$(CONFIG_NS9750_UART) += ns9750_serial.o diff --git a/drivers/serial/at91rm9200_usart.c b/drivers/serial/at91rm9200_usart.c new file mode 100644 index 0000000000..d563445492 --- /dev/null +++ b/drivers/serial/at91rm9200_usart.c @@ -0,0 +1,113 @@ +/* + * (C) Copyright 2002 + * Lineo, Inc + * Bernhard Kuhn + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Marius Groeger + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH + * Alex Zuepke + * + * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +#if !defined(CONFIG_DBGU) && !defined(CONFIG_USART0) && !defined(CONFIG_USART1) +#error must define one of CONFIG_DBGU or CONFIG_USART0 or CONFIG_USART1 +#endif + +/* ggi thunder */ +#ifdef CONFIG_DBGU +AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU; +#endif +#ifdef CONFIG_USART0 +AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US0; +#endif +#ifdef CONFIG_USART1 +AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US1; +#endif + +void serial_setbrg (void) +{ + int baudrate; + + if ((baudrate = gd->baudrate) <= 0) + baudrate = CONFIG_BAUDRATE; + /* MASTER_CLOCK/(16 * baudrate) */ + us->US_BRGR = (AT91C_MASTER_CLOCK >> 4) / (unsigned)baudrate; +} + +int serial_init (void) +{ + /* make any port initializations specific to this port */ +#ifdef CONFIG_DBGU + *AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD; /* PA 31 & 30 */ + *AT91C_PMC_PCER = 1 << AT91C_ID_SYS; /* enable clock */ +#endif +#ifdef CONFIG_USART0 + *AT91C_PIOA_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0; + *AT91C_PMC_PCER |= 1 << AT91C_ID_USART0; /* enable clock */ +#endif +#ifdef CONFIG_USART1 + *AT91C_PIOB_PDR = AT91C_PB21_TXD1 | AT91C_PB20_RXD1; + *AT91C_PMC_PCER |= 1 << AT91C_ID_USART1; /* enable clock */ +#endif + serial_setbrg (); + + us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX; + us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; + us->US_MR = + (AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | + AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT); + us->US_IMR = ~0ul; + return (0); +} + +void serial_putc (const char c) +{ + if (c == '\n') + serial_putc ('\r'); + while ((us->US_CSR & AT91C_US_TXRDY) == 0); + us->US_THR = c; +} + +void serial_puts (const char *s) +{ + while (*s) { + serial_putc (*s++); + } +} + +int serial_getc (void) +{ + while ((us->US_CSR & AT91C_US_RXRDY) == 0); + return us->US_RHR; +} + +int serial_tstc (void) +{ + return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY); +} diff --git a/include/configs/at91rm9200dk.h b/include/configs/at91rm9200dk.h index 5a980d353e..56128c153e 100644 --- a/include/configs/at91rm9200dk.h +++ b/include/configs/at91rm9200dk.h @@ -88,6 +88,7 @@ */ /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/at91rm9200ek.h b/include/configs/at91rm9200ek.h index 692ccdb71b..a018873fd6 100644 --- a/include/configs/at91rm9200ek.h +++ b/include/configs/at91rm9200ek.h @@ -112,6 +112,7 @@ * define one of these to choose the DBGU, * USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/cmc_pu2.h b/include/configs/cmc_pu2.h index e5c74e136f..80559bf191 100644 --- a/include/configs/cmc_pu2.h +++ b/include/configs/cmc_pu2.h @@ -88,6 +88,7 @@ */ /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #undef CONFIG_DBGU #define CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/csb637.h b/include/configs/csb637.h index 761c0dca39..e1cdc7f66e 100644 --- a/include/configs/csb637.h +++ b/include/configs/csb637.h @@ -90,6 +90,7 @@ */ /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/kb9202.h b/include/configs/kb9202.h index 1ce8c6974a..7dd81e69cb 100644 --- a/include/configs/kb9202.h +++ b/include/configs/kb9202.h @@ -72,6 +72,7 @@ */ /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/m501sk.h b/include/configs/m501sk.h index a432850519..1e7d90ed98 100644 --- a/include/configs/m501sk.h +++ b/include/configs/m501sk.h @@ -110,6 +110,7 @@ #define CONFIG_CMC_PU2 /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1 diff --git a/include/configs/mp2usb.h b/include/configs/mp2usb.h index edaa17403f..3225ce714c 100644 --- a/include/configs/mp2usb.h +++ b/include/configs/mp2usb.h @@ -95,6 +95,7 @@ */ /* define one of these to choose the DBGU, USART0 or USART1 as console */ +#define CONFIG_AT91RM9200_USART #define CONFIG_DBGU #undef CONFIG_USART0 #undef CONFIG_USART1