Replace nios2-generic's gpio.c with dedicated driver.
Subsystems (2)
cover Replace nios2-generic's gpio.c with dedicated driver.
Let's have a dedicated driver for Altera's PIO ip core, which does not have to be duplicated for each board using PIO.
Joachim Foerster (2):
gpio: Add driver for Altera's PIO core board/nios2-generic: Use altera_pio driver and remove board specific
driver
arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/Makefile | 1 - board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/gpio.c | 71 ------- board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 4 + 8 files changed, 324 insertions(+), 74 deletions(-) delete mode 100644 board/altera/nios2-generic/gpio.c create mode 100644 drivers/gpio/altera_pio.c
Signature · 1 line
1.7.6
PATCH 1/2 gpio: Add driver for Altera's PIO core
This driver may handle multiple PIO cores and thus needs to be setup by calling the altera_pio_init() function within the early board setup routine.
The driver comes with some extras, see below the copyleft header.
--- arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 drivers/gpio/altera_pio.c
arch/nios2/include/asm/gpio.h +11 -2
@@ -5,8 +5,8 @@* bit[0] data * bit[1] output enable * -* when CONFIG_SYS_GPIO_BASE is not defined, board may provide -* its own driver. +* When CONFIG_SYS_GPIO_BASE is not defined, the board may either +* provide its own driver or the altera_pio driver may be used. * * Copyright (C) 2010 Thomas Chou <[email protected]> *
@@ -58,6 +58,15 @@ static inline int gpio_is_valid(int number) return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH; }#else +#ifdef CONFIG_ALTERA_PIO +extern int altera_pio_init (u32 base,u8 width,char iot, +u32 rstval,u32 negmask, +const char *label); + +extern void altera_pio_info (void ); +#define gpio_status () altera_pio_info() +#endif +extern int gpio_request (unsigned gpio,const char *label);extern int gpio_free (unsigned gpio);extern int gpio_direction_input (unsigned gpio);
board/altera/nios2-generic/custom_fpga.h +1 -0
@@ -51,6 +51,7 @@/* led_pio.s1 is a altera_avalon_pio */ #define LED_PIO_BASE 0x82120870#define LED_PIO_WIDTH 8 +#define LED_PIO_RSTVAL 0x0/* high_res_timer.s1 is a altera_avalon_timer */ #define CONFIG_SYS_TIMER_BASE 0x82120820
board/altera/nios2-generic/nios2-generic.c +8 -0
@@ -26,6 +26,7 @@#include <netdev.h> #include <mtd/cfi_flash.h> #include <asm/io.h> +#include <asm/gpio.h> void text_base_hook (void );/* nop hook for text_base.S */
@@ -43,6 +44,13 @@ void early_flash_cmd_reset(void)int board_early_init_f (void ) {text_base_hook (); +#ifdef CONFIG_ALTERA_PIO +#ifdef LED_PIO_BASE +altera_pio_init (LED_PIO_BASE ,LED_PIO_WIDTH ,'o' , +LED_PIO_RSTVAL , (1 <<LED_PIO_WIDTH ) -1 , +"led" ); +#endif +#endif #if defined(CONFIG_ENV_IS_IN_FLASH ) && defined(CONFIG_ENV_ADDR )early_flash_cmd_reset ();#endif
drivers/gpio/Makefile +1 -0
@@ -34,6 +34,7 @@ COBJS-$(CONFIG_PCA953X) += pca953x.o COBJS-$(CONFIG_S5P) += s5p_gpio.o COBJS-$(CONFIG_TEGRA2_GPIO) += tegra2_gpio.o COBJS-$(CONFIG_DA8XX_GPIO) += da8xx_gpio.o +COBJS-$(CONFIG_ALTERA_PIO) += altera_pio.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/gpio/altera_pio.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 1/2 gpio: Add driver for Altera's PIO core
Quoted 7 lines · Joachim Foerster
This driver may handle multiple PIO cores and thus needs to be setup by calling the
altera_pio_init()function within the early board setup routine.The driver comes with some extras, see below the copyleft header.
Signed-off-by Joachim Foerster<[email protected]>
Quoted 8 lines
--- arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+), 2 deletions(-)create mode 100644
drivers/gpio/altera_pio.c
Hi Joachim,
Please fix these warning. Thanks.
$ ./MAKEALL nios2-generic Configuring for nios2-generic board... altera_pio.c: In function `altera_pio_info': altera_pio.c:189: warning: ` ' flag used with `%u' printf format
checkpatch.pl
ERROR: do not initialise statics to 0 or NULL
#209: FILE: drivers/gpio/altera_pio.c:71:
+static int pio_num = 0;
ERROR: do not initialise statics to 0 or NULL
#217: FILE: drivers/gpio/altera_pio.c:79:
+static int pio_gpio_num = 0;
Otherwise,
Best regards,
Thomas
cover Replace nios2-generic's gpio.c with dedicated driver.
Let's have a dedicated driver for Altera's PIO ip core, which does not have to be duplicated for each board using PIO.
Joachim Foerster (2):
gpio: Add driver for Altera's PIO core board/nios2-generic: Use altera_pio driver and remove board specific
driver
Changes for v2:
PATCH 1/2: - get rid of checkpatch warnings about init.ing static - use %d instead of %u together the usage of the space-flag PATCH 2/2: nothing
arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/Makefile | 1 - board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/gpio.c | 71 ------- board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 4 + 8 files changed, 324 insertions(+), 74 deletions(-) delete mode 100644 board/altera/nios2-generic/gpio.c create mode 100644 drivers/gpio/altera_pio.c
Signature · 1 line
1.7.6
PATCH v2 1/2 gpio: Add driver for Altera's PIO core
This driver may handle multiple PIO cores and thus needs to be setup by calling the altera_pio_init() function within the early board setup routine.
The driver comes with some extras, see below the copyleft header.
--- arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 drivers/gpio/altera_pio.c
arch/nios2/include/asm/gpio.h +11 -2
@@ -5,8 +5,8 @@* bit[0] data * bit[1] output enable * -* when CONFIG_SYS_GPIO_BASE is not defined, board may provide -* its own driver. +* When CONFIG_SYS_GPIO_BASE is not defined, the board may either +* provide its own driver or the altera_pio driver may be used. * * Copyright (C) 2010 Thomas Chou <[email protected]> *
@@ -58,6 +58,15 @@ static inline int gpio_is_valid(int number) return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH; }#else +#ifdef CONFIG_ALTERA_PIO +extern int altera_pio_init (u32 base,u8 width,char iot, +u32 rstval,u32 negmask, +const char *label); + +extern void altera_pio_info (void ); +#define gpio_status () altera_pio_info() +#endif +extern int gpio_request (unsigned gpio,const char *label);extern int gpio_free (unsigned gpio);extern int gpio_direction_input (unsigned gpio);
board/altera/nios2-generic/custom_fpga.h +1 -0
@@ -51,6 +51,7 @@/* led_pio.s1 is a altera_avalon_pio */ #define LED_PIO_BASE 0x82120870#define LED_PIO_WIDTH 8 +#define LED_PIO_RSTVAL 0x0/* high_res_timer.s1 is a altera_avalon_timer */ #define CONFIG_SYS_TIMER_BASE 0x82120820
board/altera/nios2-generic/nios2-generic.c +8 -0
@@ -26,6 +26,7 @@#include <netdev.h> #include <mtd/cfi_flash.h> #include <asm/io.h> +#include <asm/gpio.h> void text_base_hook (void );/* nop hook for text_base.S */
@@ -43,6 +44,13 @@ void early_flash_cmd_reset(void)int board_early_init_f (void ) {text_base_hook (); +#ifdef CONFIG_ALTERA_PIO +#ifdef LED_PIO_BASE +altera_pio_init (LED_PIO_BASE ,LED_PIO_WIDTH ,'o' , +LED_PIO_RSTVAL , (1 <<LED_PIO_WIDTH ) -1 , +"led" ); +#endif +#endif #if defined(CONFIG_ENV_IS_IN_FLASH ) && defined(CONFIG_ENV_ADDR )early_flash_cmd_reset ();#endif
drivers/gpio/Makefile +1 -0
@@ -34,6 +34,7 @@ COBJS-$(CONFIG_PCA953X) += pca953x.o COBJS-$(CONFIG_S5P) += s5p_gpio.o COBJS-$(CONFIG_TEGRA2_GPIO) += tegra2_gpio.o COBJS-$(CONFIG_DA8XX_GPIO) += da8xx_gpio.o +COBJS-$(CONFIG_ALTERA_PIO) += altera_pio.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/gpio/altera_pio.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
1.7.6
Thomas Chou
AppliedPATCH v2 1/2 gpio: Add driver for Altera's PIO core
Quoted 8 lines · Joachim Foerster
This driver may handle multiple PIO cores and thus needs to be setup by calling the
altera_pio_init()function within the early board setup routine.The driver comes with some extras, see below the copyleft header.
Signed-off-by Joachim Foerster<[email protected]>Tested-by Thomas Chou<[email protected]>
Quoted 8 lines
--- arch/nios2/include/asm/gpio.h | 13 +- board/altera/nios2-generic/custom_fpga.h | 1 + board/altera/nios2-generic/nios2-generic.c | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/altera_pio.c | 299 ++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+), 2 deletions(-)create mode 100644
drivers/gpio/altera_pio.c
Hi Joachim,
Applied. Thanks.
Best regards,
Thomas
PATCH v2 2/2 board/nios2-generic: Use altera_pio driver and remove board specific driver
In reply to Joachim Foerster--- board/altera/nios2-generic/Makefile | 1 - board/altera/nios2-generic/gpio.c | 71 ----------------------------------- include/configs/nios2-generic.h | 4 ++ 3 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 board/altera/nios2-generic/gpio.c
board/altera/nios2-generic/Makefile +0 -1
@@ -32,7 +32,6 @@ LIB = $(obj)lib$(BOARD).o COBJS-y := $(BOARD).o COBJS-$(CONFIG_CMD_IDE) += ../common/cfide.o COBJS-$(CONFIG_EPLED) += ../common/epled.o -COBJS-$(CONFIG_GPIO) += gpio.o COBJS-$(CONFIG_SEVENSEG) += ../common/sevenseg.o SOBJS-y := text_base.o
board/altera/nios2-generic/gpio.c deleted +0 -71
71 lines not on this page · raw message
include/configs/nios2-generic.h +4 -0
@@ -63,6 +63,10 @@/* * STATUS LED */ +#define CONFIG_ALTERA_PIO +#define CONFIG_SYS_ALTERA_PIO_NUM 1 +#define CONFIG_SYS_ALTERA_PIO_GPIO_NUM LED_PIO_WIDTH +#define CONFIG_STATUS_LED /* Enable status driver */ #define CONFIG_GPIO_LED /* Enable GPIO LED driver */ #define CONFIG_GPIO /* Enable GPIO driver */
Signature · 1 line
1.7.6
Thomas Chou
AppliedPATCH v2 2/2 board/nios2-generic: Use altera_pio driver and remove board specific driver
Quoted 7 lines · Joachim Foerster
Signed-off-by Joachim Foerster<[email protected]>--- board/altera/nios2-generic/Makefile | 1 - board/altera/nios2-generic/gpio.c | 71 ----------------------------------- include/configs/nios2-generic.h | 4 ++ 3 files changed, 4 insertions(+), 72 deletions(-)delete mode 100644
board/altera/nios2-generic/gpio.c
Hi Joachim,
Applied. Thanks.
Best regards,
Thomas
PATCH 1/2 gpio: Add driver for Altera's PIO core
In reply to Thomas ChouQuoted 18 lines · Thomas Chou
Quoted 14 lines · Joachim Foerster
This driver may handle multiple PIO cores and thus needs to be setup by calling the
altera_pio_init()function within the early board setup routine.The driver comes with some extras, see below the copyleft header.
Signed-off-by: Joachim Foerster<[email protected]>
---arch/nios2/include/asm/gpio.h| 13 +-board/altera/nios2-generic/custom_fpga.h| 1 +board/altera/nios2-generic/nios2-generic.c| 8 +drivers/gpio/Makefile| 1 +drivers/gpio/altera_pio.c| 299 ++++++++++++++++++++++++++++Quoted 2 lines
5 files changed, 320 insertions(+), 2 deletions(-)create mode 100644
drivers/gpio/altera_pio.c
Quoted 8 lines
Hi Joachim,
Please fix these warning. Thanks.
$ ./MAKEALL nios2-generic Configuring for nios2-generic board... altera_pio.c: In function `altera_pio_info': altera_pio.c:189: warning: ` ' flag used with `%u' printf format
Ok, I'll use %d - in this case it is the same. Does anybody know why %u warns about space-flag usage? Is space-flag + %u indeed evil ?
Quoted 5 lines
Otherwise,
Tested-by Thomas Chou <[email protected]>Best regards,
Thomas
Thanks for reviewing.
Signature · 7 lines
Joachim Foerster Missing Link Electronics http://www.missinglinkelectronics.com Office EU: +49 (731) 141-149-0 Office US: +1 (408) 457-0700 email: joachim.foerster at missinglinkelectronics.com
PATCH 2/2 board/nios2-generic: Use altera_pio driver and remove board specific driver
In reply to Joachim Foerster--- board/altera/nios2-generic/Makefile | 1 - board/altera/nios2-generic/gpio.c | 71 ----------------------------------- include/configs/nios2-generic.h | 4 ++ 3 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 board/altera/nios2-generic/gpio.c
board/altera/nios2-generic/Makefile +0 -1
@@ -32,7 +32,6 @@ LIB = $(obj)lib$(BOARD).o COBJS-y := $(BOARD).o COBJS-$(CONFIG_CMD_IDE) += ../common/cfide.o COBJS-$(CONFIG_EPLED) += ../common/epled.o -COBJS-$(CONFIG_GPIO) += gpio.o COBJS-$(CONFIG_SEVENSEG) += ../common/sevenseg.o SOBJS-y := text_base.o
board/altera/nios2-generic/gpio.c deleted +0 -71
71 lines not on this page · raw message
include/configs/nios2-generic.h +4 -0
@@ -63,6 +63,10 @@/* * STATUS LED */ +#define CONFIG_ALTERA_PIO +#define CONFIG_SYS_ALTERA_PIO_NUM 1 +#define CONFIG_SYS_ALTERA_PIO_GPIO_NUM LED_PIO_WIDTH +#define CONFIG_STATUS_LED /* Enable status driver */ #define CONFIG_GPIO_LED /* Enable GPIO LED driver */ #define CONFIG_GPIO /* Enable GPIO driver */
Signature · 1 line
1.7.6