From patchwork Sat Jul 7 09:57:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: seedshope X-Patchwork-Id: 169575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 65E262C020A for ; Sat, 7 Jul 2012 19:58:04 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BE8FF28098; Sat, 7 Jul 2012 11:57:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LgSkYBZTEGmJ; Sat, 7 Jul 2012 11:57:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 09537280C1; Sat, 7 Jul 2012 11:57:50 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C7CC28098 for ; Sat, 7 Jul 2012 11:57:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ElQEasjAJFNc for ; Sat, 7 Jul 2012 11:57:46 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by theia.denx.de (Postfix) with ESMTPS id B7C8B2808B for ; Sat, 7 Jul 2012 11:57:44 +0200 (CEST) Received: by mail-pb0-f44.google.com with SMTP id wy7so14928953pbc.3 for ; Sat, 07 Jul 2012 02:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=MIkmRHUrfJao+JnUBIvhywRJAqvXRKTALuNZShtk354=; b=gbdO16lQ1YxEJM3xPjNIhBmFQeOFkgl4Ny84YyQgTZsftlW2Y//S+CPrT2gpQEJ9fR 5+B4HSFjAaH13hwy+klhhLr2/VMZxrqMs9A4JaTEa6lxC+pZDI7j/DJJV3gLzlvwoXqq wLtG4unIT1pfOjbT/wwE7c2mPlIYXYwCXeMRI8iEK2GkXk9BDthv9YCVJ7Iz+FrkQiAV KgA/xwBQ6MjRyvw4U1Sq3ol7kz4RVQD4/rBVTvlTL7ZsKxlLunYr2ZjA0iOo8SZNvtu/ 2foIKao/GEERacnj3Pc8qZaMSQ64H5VZ2th97nhtIeZlbsQPMvlcyMUNZxAOAmqgrFaH /DvA== Received: by 10.68.192.73 with SMTP id he9mr13349124pbc.17.1341655064270; Sat, 07 Jul 2012 02:57:44 -0700 (PDT) Received: from localhost.localdomain ([221.221.18.169]) by mx.google.com with ESMTPS id qa5sm23628663pbb.19.2012.07.07.02.57.40 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 07 Jul 2012 02:57:43 -0700 (PDT) From: Zhong Hongbo To: Minkyu Kang Date: Sat, 7 Jul 2012 17:57:02 +0800 Message-Id: <1341655032-30201-4-git-send-email-bocui107@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1341655032-30201-1-git-send-email-bocui107@gmail.com> References: <1341655032-30201-1-git-send-email-bocui107@gmail.com> Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 03/13] S3C64XX: Use readl/writel to operate uart X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Zhong Hongbo Signed-off-by: Zhong Hongbo --- arch/arm/include/asm/arch-s3c64xx/s3c6400.h | 65 +-------------------------- arch/arm/include/asm/arch-s3c64xx/s3c64x0.h | 31 ------------- arch/arm/include/asm/arch-s3c64xx/uart.h | 54 ++++++++++++++++++++++ board/samsung/smdk6400/lowlevel_init.S | 8 --- drivers/serial/s3c64xx.c | 50 +++++++++++++-------- 5 files changed, 87 insertions(+), 121 deletions(-) create mode 100644 arch/arm/include/asm/arch-s3c64xx/uart.h diff --git a/arch/arm/include/asm/arch-s3c64xx/s3c6400.h b/arch/arm/include/asm/arch-s3c64xx/s3c6400.h index 5cb8976..c6b41e8 100644 --- a/arch/arm/include/asm/arch-s3c64xx/s3c6400.h +++ b/arch/arm/include/asm/arch-s3c64xx/s3c6400.h @@ -582,62 +582,6 @@ */ #define ELFIN_UART_BASE 0x7F005000 -#define ELFIN_UART0_OFFSET 0x0000 -#define ELFIN_UART1_OFFSET 0x0400 -#define ELFIN_UART2_OFFSET 0x0800 - -#define ULCON_OFFSET 0x00 -#define UCON_OFFSET 0x04 -#define UFCON_OFFSET 0x08 -#define UMCON_OFFSET 0x0C -#define UTRSTAT_OFFSET 0x10 -#define UERSTAT_OFFSET 0x14 -#define UFSTAT_OFFSET 0x18 -#define UMSTAT_OFFSET 0x1C -#define UTXH_OFFSET 0x20 -#define URXH_OFFSET 0x24 -#define UBRDIV_OFFSET 0x28 -#define UDIVSLOT_OFFSET 0x2C -#define UINTP_OFFSET 0x30 -#define UINTSP_OFFSET 0x34 -#define UINTM_OFFSET 0x38 - -#define ULCON0_REG __REG(0x7F005000) -#define UCON0_REG __REG(0x7F005004) -#define UFCON0_REG __REG(0x7F005008) -#define UMCON0_REG __REG(0x7F00500C) -#define UTRSTAT0_REG __REG(0x7F005010) -#define UERSTAT0_REG __REG(0x7F005014) -#define UFSTAT0_REG __REG(0x7F005018) -#define UMSTAT0_REG __REG(0x7F00501c) -#define UTXH0_REG __REG(0x7F005020) -#define URXH0_REG __REG(0x7F005024) -#define UBRDIV0_REG __REG(0x7F005028) -#define UDIVSLOT0_REG __REG(0x7F00502c) -#define UINTP0_REG __REG(0x7F005030) -#define UINTSP0_REG __REG(0x7F005034) -#define UINTM0_REG __REG(0x7F005038) - -#define ULCON1_REG __REG(0x7F005400) -#define UCON1_REG __REG(0x7F005404) -#define UFCON1_REG __REG(0x7F005408) -#define UMCON1_REG __REG(0x7F00540C) -#define UTRSTAT1_REG __REG(0x7F005410) -#define UERSTAT1_REG __REG(0x7F005414) -#define UFSTAT1_REG __REG(0x7F005418) -#define UMSTAT1_REG __REG(0x7F00541c) -#define UTXH1_REG __REG(0x7F005420) -#define URXH1_REG __REG(0x7F005424) -#define UBRDIV1_REG __REG(0x7F005428) -#define UDIVSLOT1_REG __REG(0x7F00542c) -#define UINTP1_REG __REG(0x7F005430) -#define UINTSP1_REG __REG(0x7F005434) -#define UINTM1_REG __REG(0x7F005438) - -#define UTRSTAT_TX_EMPTY (1 << 2) -#define UTRSTAT_RX_READY (1 << 0) -#define UART_ERR_MASK 0xF - /* * PWM timer */ @@ -804,17 +748,12 @@ #define DMC_DDR_USER_CONFIG 1 #ifndef __ASSEMBLY__ -enum s3c64xx_uarts_nr { - S3C64XX_UART0, - S3C64XX_UART1, - S3C64XX_UART2, -}; #include "s3c64x0.h" -static inline s3c64xx_uart *s3c64xx_get_base_uart(enum s3c64xx_uarts_nr nr) +static inline unsigned int s3c64xx_get_base_uart(void) { - return (s3c64xx_uart *)(ELFIN_UART_BASE + (nr * 0x400)); + return ELFIN_UART_BASE; } static inline unsigned int s3c64xx_get_base_nand(void) diff --git a/arch/arm/include/asm/arch-s3c64xx/s3c64x0.h b/arch/arm/include/asm/arch-s3c64xx/s3c64x0.h index 0bbf1d0..7add68c 100644 --- a/arch/arm/include/asm/arch-s3c64xx/s3c64x0.h +++ b/arch/arm/include/asm/arch-s3c64xx/s3c64x0.h @@ -40,37 +40,6 @@ #include -/* UART (see manual chapter 11) */ -typedef struct { - volatile u32 ULCON; - volatile u32 UCON; - volatile u32 UFCON; - volatile u32 UMCON; - volatile u32 UTRSTAT; - volatile u32 UERSTAT; - volatile u32 UFSTAT; - volatile u32 UMSTAT; -#ifdef __BIG_ENDIAN - volatile u8 res1[3]; - volatile u8 UTXH; - volatile u8 res2[3]; - volatile u8 URXH; -#else /* Little Endian */ - volatile u8 UTXH; - volatile u8 res1[3]; - volatile u8 URXH; - volatile u8 res2[3]; -#endif - volatile u32 UBRDIV; -#ifdef __BIG_ENDIAN - volatile u8 res3[2]; - volatile u16 UDIVSLOT; -#else - volatile u16 UDIVSLOT; - volatile u8 res3[2]; -#endif -} s3c64xx_uart; - /* PWM TIMER (see manual chapter 10) */ typedef struct { volatile u32 TCNTB; diff --git a/arch/arm/include/asm/arch-s3c64xx/uart.h b/arch/arm/include/asm/arch-s3c64xx/uart.h new file mode 100644 index 0000000..f3f37aa --- /dev/null +++ b/arch/arm/include/asm/arch-s3c64xx/uart.h @@ -0,0 +1,54 @@ +/* + * (C) Copyright 2012 + * Zhong Hongbo + * + * See file CREDITS for list of people who contributed to this + * project. + * + * 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 + */ + +#ifndef __ASM_ARCH_UART__ +#define __ASM_ARCH_UART__ + +#ifndef __ASSEMBLY__ + +enum s3c64xx_uarts_nr { + S3C64XX_UART0, + S3C64XX_UART1, + S3C64XX_UART2, +}; + +/* UART (see manual chapter 11) */ +struct s3c64xx_uart { + unsigned int ulcon; + unsigned int ucon; + unsigned int ufcon; + unsigned int umcon; + unsigned int utrstat; + unsigned int uerstat; + unsigned int ufstat; + unsigned int umstat; + unsigned int utxh; + unsigned int urxh; + unsigned int ubrdiv; + unsigned int udivslot; + unsigned int uintp; + unsigned int uintsp; + unsigned int uintm; +} s3c64xx_uart; +#endif +#endif diff --git a/board/samsung/smdk6400/lowlevel_init.S b/board/samsung/smdk6400/lowlevel_init.S index 4a82e4d..1142be1 100644 --- a/board/samsung/smdk6400/lowlevel_init.S +++ b/board/samsung/smdk6400/lowlevel_init.S @@ -36,14 +36,6 @@ #include -#ifdef CONFIG_SERIAL1 -#define ELFIN_UART_CONSOLE_BASE (ELFIN_UART_BASE + ELFIN_UART0_OFFSET) -#elif defined(CONFIG_SERIAL2) -#define ELFIN_UART_CONSOLE_BASE (ELFIN_UART_BASE + ELFIN_UART1_OFFSET) -#else -#define ELFIN_UART_CONSOLE_BASE (ELFIN_UART_BASE + ELFIN_UART2_OFFSET) -#endif - _TEXT_BASE: .word CONFIG_SYS_TEXT_BASE diff --git a/drivers/serial/s3c64xx.c b/drivers/serial/s3c64xx.c index a88e930..2959669 100644 --- a/drivers/serial/s3c64xx.c +++ b/drivers/serial/s3c64xx.c @@ -22,8 +22,9 @@ */ #include - +#include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -42,6 +43,11 @@ DECLARE_GLOBAL_DATA_PTR; #define barrier() asm volatile("" ::: "memory") +static inline struct s3c64xx_uart *s3c_get_base_uart(void) +{ + u32 offset = UART_NR * 0x4000; + return (struct s3c64xx_uart *)(s3c64xx_get_base_uart() + offset); +} /* * The coefficient, used to calculate the baudrate on S3C6400 UARTs is * calculated as @@ -70,15 +76,16 @@ static const int udivslot[] = { void serial_setbrg(void) { - s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR); + struct s3c64xx_uart *const uart = s3c_get_base_uart(); u32 pclk = get_PCLK(); u32 baudrate = gd->baudrate; + unsigned int val; int i; - i = (pclk / baudrate) % 16; + val = pclk / baudrate; - uart->UBRDIV = pclk / baudrate / 16 - 1; - uart->UDIVSLOT = udivslot[i]; + writel(val / 16 - 1, &uart->ubrdiv); + writew(udivslot[val % 16], &uart->udivslot); for (i = 0; i < 100; i++) barrier(); @@ -90,16 +97,19 @@ void serial_setbrg(void) */ int serial_init(void) { - s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR); + struct s3c64xx_uart *const uart = s3c_get_base_uart(); /* reset and enable FIFOs, set triggers to the maximum */ - uart->UFCON = 0xff; - uart->UMCON = 0; + writel(0, &uart->ufcon); + writel(0, &uart->umcon); /* 8N1 */ - uart->ULCON = 3; + writel(0x3, &uart->ulcon); /* No interrupts, no DMA, pure polling */ - uart->UCON = 5; - +#if defined(CONFIG_S3C6400) + writel(0x5, &uart->ucon); +#else + writel(0xe45, &uart->ucon); +#endif serial_setbrg(); return 0; @@ -112,12 +122,13 @@ int serial_init(void) */ int serial_getc(void) { - s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR); + struct s3c64xx_uart *const uart = s3c_get_base_uart(); /* wait for character to arrive */ - while (!(uart->UTRSTAT & 0x1)); + while (!(readl(&uart->utrstat) & 0x1)) + ; - return uart->URXH & 0xff; + return (int)(readb(&uart->urxh) & 0xff); } #ifdef CONFIG_MODEM_SUPPORT @@ -139,7 +150,7 @@ void enable_putc(void) */ void serial_putc(const char c) { - s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR); + struct s3c64xx_uart *const uart = s3c_get_base_uart(); #ifdef CONFIG_MODEM_SUPPORT if (be_quiet) @@ -147,9 +158,10 @@ void serial_putc(const char c) #endif /* wait for room in the tx FIFO */ - while (!(uart->UTRSTAT & 0x2)); + while (!(readl(&uart->utrstat) & 0x2)) + ; - uart->UTXH = c; + writeb(c, &uart->utxh); /* If \n, also do \r */ if (c == '\n') @@ -161,9 +173,9 @@ void serial_putc(const char c) */ int serial_tstc(void) { - s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR); + struct s3c64xx_uart *const uart = s3c_get_base_uart(); - return uart->UTRSTAT & 0x1; + return readl(&uart->utrstat) & 0x1; } void serial_puts(const char *s)