From patchwork Mon Dec 27 02:46:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Chou X-Patchwork-Id: 76731 X-Patchwork-Delegate: smcnutt@psyent.com 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 86CDD1007D2 for ; Mon, 27 Dec 2010 13:45:06 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DD0A528087; Mon, 27 Dec 2010 03:45:04 +0100 (CET) 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 rmeS9gH7jMab; Mon, 27 Dec 2010 03:45:04 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0946A28084; Mon, 27 Dec 2010 03:45:03 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0050C28084 for ; Mon, 27 Dec 2010 03:44:59 +0100 (CET) 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 TazLqgjsJ9bz for ; Mon, 27 Dec 2010 03:44:58 +0100 (CET) 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 www.wytron.com.tw (www.wytron.com.tw [211.75.82.101]) by theia.denx.de (Postfix) with ESMTPS id E10752807E for ; Mon, 27 Dec 2010 03:44:57 +0100 (CET) Received: from [192.168.1.15] (helo=darkstar.wytron.com.tw) by www.wytron.com.tw with esmtp (Exim 4.69) (envelope-from ) id 1PX34x-0003vg-3l; Mon, 27 Dec 2010 10:44:55 +0800 From: Thomas Chou To: Scott McNutt Date: Mon, 27 Dec 2010 10:46:01 +0800 Message-Id: <1293417961-8247-1-git-send-email-thomas@wytron.com.tw> X-Mailer: git-send-email 1.7.3.4 X-SA-Exim-Connect-IP: 192.168.1.15 X-SA-Exim-Mail-From: thomas@wytron.com.tw X-SA-Exim-Scanned: No (on www.wytron.com.tw); SAEximRunCond expanded to false Cc: u-boot@lists.denx.de, nios2-dev@sopc.et.ntust.edu.tw Subject: [U-Boot] [PATCH] nios2: add gpio_is_valid X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 Signed-off-by: Thomas Chou --- arch/nios2/include/asm/gpio.h | 6 ++++++ board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/gpio.c | 6 ++++++ 3 files changed, 13 insertions(+), 0 deletions(-) diff --git a/arch/nios2/include/asm/gpio.h b/arch/nios2/include/asm/gpio.h index 36a7132..4b21c8f 100644 --- a/arch/nios2/include/asm/gpio.h +++ b/arch/nios2/include/asm/gpio.h @@ -52,6 +52,11 @@ static inline void gpio_set_value(unsigned gpio, int value) { writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); } + +static inline int gpio_is_valid(int number) +{ + return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH; +} #else extern int gpio_request(unsigned gpio, const char *label); extern int gpio_free(unsigned gpio); @@ -59,6 +64,7 @@ extern int gpio_direction_input(unsigned gpio); extern int gpio_direction_output(unsigned gpio, int value); extern int gpio_get_value(unsigned gpio); extern void gpio_set_value(unsigned gpio, int value); +extern int gpio_is_valid(int number); #endif /* CONFIG_SYS_GPIO_BASE */ #endif /* _ASM_NIOS2_GPIO_H_ */ diff --git a/board/altera/nios2-generic/custom_fpga.h b/board/altera/nios2-generic/custom_fpga.h index a11add5..f7f3853 100644 --- a/board/altera/nios2-generic/custom_fpga.h +++ b/board/altera/nios2-generic/custom_fpga.h @@ -50,6 +50,7 @@ /* led_pio.s1 is a altera_avalon_pio */ #define LED_PIO_BASE 0x82120870 +#define LED_PIO_WIDTH 8 /* high_res_timer.s1 is a altera_avalon_timer */ #define CONFIG_SYS_TIMER_BASE 0x82120820 diff --git a/board/altera/nios2-generic/gpio.c b/board/altera/nios2-generic/gpio.c index 8c639ce..4a30564 100644 --- a/board/altera/nios2-generic/gpio.c +++ b/board/altera/nios2-generic/gpio.c @@ -10,6 +10,7 @@ #ifndef CONFIG_SYS_GPIO_BASE #define ALTERA_PIO_BASE LED_PIO_BASE +#define ALTERA_PIO_WIDTH LED_PIO_WIDTH #define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0) #define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4) static u32 pio_data_reg; @@ -62,4 +63,9 @@ void gpio_set_value(unsigned gpio, int value) pio_data_reg &= ~mask; writel(pio_data_reg, ALTERA_PIO_DATA); } + +int gpio_is_valid(int number) +{ + return ((unsigned)number) < ALTERA_PIO_WIDTH; +} #endif