Skip to contentSkip to conversation

nios2 : convert altera_pio to driver model

PATCH Superseded Thomas Chou 4 participants 9 messages Sep 24, 2015 – Oct 3, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nios2 : convert altera_pio to driver model

Convert altera_pio to driver model.

---
 arch/nios2/dts/3c120_devboard.dts          |  38 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316 +++++++----------------------
 include/configs/nios2-generic.h            |  20 --
 7 files changed, 124 insertions(+), 346 deletions(-)
arch/nios2/dts/3c120_devboard.dts +38 -0
index a35f5fe..f6ac273 100644
@@ -132,6 +132,44 @@
 				clock-frequency = <62500000>;
 				u-boot,dm-pre-reloc;
 			};
+
+			user_led_pio_8out: gpio at 0x4cc0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004cc0 0x00000010>;
+				resetvalue = <255>;
+				width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "led";
+			};
+
+			user_dipsw_pio_8in: gpio at 0x4ce0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004ce0 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <8>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "dipsw";
+			};
+
+			user_pb_pio_4in: gpio at 0x4d00 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004d00 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <9>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				width = <4>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "pb";
+			};
 		};
 
 		cfi_flash_64m: flash at 0x0 {
arch/nios2/include/asm/gpio.h +1 -79

80 lines not on this page · raw message

board/altera/nios2-generic/nios2-generic.c +0 -7
index 384fee9..61d32c7 100644
@@ -37,13 +37,6 @@ int board_early_init_f(void)
 
 int board_early_init_r(void)
 {
-#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
 	return 0;
 }
 
configs/nios2-generic_defconfig +2 -0
index 9dc6a72..ad72272 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_DM_SERIAL=y
+CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
@@ -15,5 +16,6 @@ CONFIG_CMD_PING=y
 CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM=y
+CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
drivers/gpio/Kconfig +7 -0
index ef57a89..9e49471 100644
@@ -14,6 +14,13 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config ALTERA_PIO
+	bool "Altera PIO driver"
+	depends on DM_GPIO
+	help
+	  Select this to enable PIO for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 config DWAPB_GPIO
 	bool "DWAPB GPIO driver"
 	depends on DM && DM_GPIO
drivers/gpio/altera_pio.c +76 -240

362 lines not on this page · raw message

include/configs/nios2-generic.h +0 -20
index dcb90de..90ccbd1 100644
@@ -33,26 +33,6 @@
 #define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
 
 /*
- * 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_BOARD_SPECIFIC_LED
-#define CONFIG_GPIO_LED		/* Enable GPIO LED driver */
-#define CONFIG_GPIO			/* Enable GPIO driver */
-#define LED_PIO_BASE			USER_LED_PIO_8OUT_BASE
-#define LED_PIO_WIDTH			8
-#define LED_PIO_RSTVAL			0xff
-
-#define STATUS_LED_BIT			0	/* Bit-0 on GPIO */
-#define STATUS_LED_STATE		STATUS_LED_ON
-#define STATUS_LED_PERIOD	(CONFIG_SYS_HZ / 2)	/* 500 msec */
-#define STATUS_LED_BOOT			STATUS_LED_BIT
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 nios2 : convert altera_pio to driver model

Quoted 3 lines · Thomas Chou

Convert altera_pio to driver model.

Hi,

now this is quite a nice patch :-)

Quoted 11 lines
---
 arch/nios2/dts/3c120_devboard.dts          |  38 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316
+++++++---------------------- include/configs/nios2-generic.h            |
 20 --
 7 files changed, 124 insertions(+), 346 deletions(-)

[...]

Quoted 15 lines
drivers/gpio/altera_pio.c +3 -10
+static int altera_pio_get_value(struct udevice *dev, unsigned pin)
 {
-	int i;
-	int j;
-	int gidx;
-	u32 mask;
+	struct altera_pio_platdata *plat = dev_get_platdata(dev);
+	struct altera_pio_regs *const regs = plat->regs;
 
-	for (i = 0; i < pio_num; ++i) {
-		printf("Altera PIO % 2d, @0x%08x, "
-			"width: %u, label: %s\n",
-		       i, pios[i].base, pios[i].width, pios[i].label);
-		gidx = pios[i].gidx;
-		for (j = gidx; j < (gidx + pios[i].width); ++j) {

drivers/gpio/altera_pio.c line 60

Quoted 10 lines
drivers/gpio/altera_pio.c +1 -9
-			mask = 1 << (j - gidx);
-			printf("\tGPIO % 4d: %s %s [%c] %s\n",
-				gpios[j].num,
-				gpios[j].pio->sh_dir & mask ? "out" : " in",
-				gpio_get_value(gpios[j].num) ? "set" : "clr",
-				altera_pio_is_gidx_used(j) ? 'x' : ' ',
-				gpios[j].reqlabel);
-		}
-	}
+	return !!(readl(&regs->data) & (1 << pin));

You can drop the double negation here, the API design is done such that 0 is log. low and non-zero is log. high .

[...]

Thanks!

#2 lore raw

PATCH v2 1/1 nios2 : convert altera_pio to driver model

In reply to Thomas Chou

Convert altera_pio to driver model.

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.

 arch/nios2/dts/3c120_devboard.dts          |  41 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316 +++++++----------------------
 include/configs/nios2-generic.h            |  20 --
 7 files changed, 127 insertions(+), 346 deletions(-)
arch/nios2/dts/3c120_devboard.dts +41 -0
index a35f5fe..06c9422 100644
@@ -68,6 +68,9 @@
 				<0x00004400 0x08004400 0x00000040>,
 				<0x00004800 0x08004800 0x00000040>,
 				<0x00004c80 0x08004c80 0x00000020>,
+				<0x00004cc0 0x08004cc0 0x00000010>,
+				<0x00004ce0 0x08004ce0 0x00000010>,
+				<0x00004d00 0x08004d00 0x00000010>,
 				<0x00004d50 0x08004d50 0x00000008>,
 				<0x00008000 0x08008000 0x00000020>,
 				<0x00400000 0x08400000 0x00000020>;
@@ -132,6 +135,44 @@
 				clock-frequency = <62500000>;
 				u-boot,dm-pre-reloc;
 			};
+
+			user_led_pio_8out: gpio at 0x4cc0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004cc0 0x00000010>;
+				resetvalue = <255>;
+				width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "led";
+			};
+
+			user_dipsw_pio_8in: gpio at 0x4ce0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004ce0 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <8>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "dipsw";
+			};
+
+			user_pb_pio_4in: gpio at 0x4d00 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004d00 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <9>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				width = <4>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "pb";
+			};
 		};
 
 		cfi_flash_64m: flash at 0x0 {
arch/nios2/include/asm/gpio.h +1 -79

80 lines not on this page · raw message

board/altera/nios2-generic/nios2-generic.c +0 -7
index 384fee9..61d32c7 100644
@@ -37,13 +37,6 @@ int board_early_init_f(void)
 
 int board_early_init_r(void)
 {
-#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
 	return 0;
 }
 
configs/nios2-generic_defconfig +2 -0
index 9dc6a72..ad72272 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_DM_SERIAL=y
+CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
@@ -15,5 +16,6 @@ CONFIG_CMD_PING=y
 CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM=y
+CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
drivers/gpio/Kconfig +7 -0
index ef57a89..9e49471 100644
@@ -14,6 +14,13 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config ALTERA_PIO
+	bool "Altera PIO driver"
+	depends on DM_GPIO
+	help
+	  Select this to enable PIO for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 config DWAPB_GPIO
 	bool "DWAPB GPIO driver"
 	depends on DM && DM_GPIO
drivers/gpio/altera_pio.c +76 -240

362 lines not on this page · raw message

include/configs/nios2-generic.h +0 -20
index dcb90de..90ccbd1 100644
@@ -33,26 +33,6 @@
 #define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
 
 /*
- * 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_BOARD_SPECIFIC_LED
-#define CONFIG_GPIO_LED		/* Enable GPIO LED driver */
-#define CONFIG_GPIO			/* Enable GPIO driver */
-#define LED_PIO_BASE			USER_LED_PIO_8OUT_BASE
-#define LED_PIO_WIDTH			8
-#define LED_PIO_RSTVAL			0xff
-
-#define STATUS_LED_BIT			0	/* Bit-0 on GPIO */
-#define STATUS_LED_STATE		STATUS_LED_ON
-#define STATUS_LED_PERIOD	(CONFIG_SYS_HZ / 2)	/* 500 msec */
-#define STATUS_LED_BOOT			STATUS_LED_BIT
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#3 lore raw

PATCH v3 1/1 nios2 : convert altera_pio to driver model

In reply to Thomas Chou

Convert altera_pio to driver model.

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.

v3
change gpio_count device tree binding.

 arch/nios2/dts/3c120_devboard.dts          |  41 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316 +++++++----------------------
 include/configs/nios2-generic.h            |  20 --
 7 files changed, 127 insertions(+), 346 deletions(-)
arch/nios2/dts/3c120_devboard.dts +41 -0
index a35f5fe..781a652 100644
@@ -68,6 +68,9 @@
 				<0x00004400 0x08004400 0x00000040>,
 				<0x00004800 0x08004800 0x00000040>,
 				<0x00004c80 0x08004c80 0x00000020>,
+				<0x00004cc0 0x08004cc0 0x00000010>,
+				<0x00004ce0 0x08004ce0 0x00000010>,
+				<0x00004d00 0x08004d00 0x00000010>,
 				<0x00004d50 0x08004d50 0x00000008>,
 				<0x00008000 0x08008000 0x00000020>,
 				<0x00400000 0x08400000 0x00000020>;
@@ -132,6 +135,44 @@
 				clock-frequency = <62500000>;
 				u-boot,dm-pre-reloc;
 			};
+
+			user_led_pio_8out: gpio at 0x4cc0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004cc0 0x00000010>;
+				resetvalue = <255>;
+				altr,gpio-bank-width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "led";
+			};
+
+			user_dipsw_pio_8in: gpio at 0x4ce0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004ce0 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <8>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				altr,gpio-bank-width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "dipsw";
+			};
+
+			user_pb_pio_4in: gpio at 0x4d00 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004d00 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <9>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				altr,gpio-bank-width = <4>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "pb";
+			};
 		};
 
 		cfi_flash_64m: flash at 0x0 {
arch/nios2/include/asm/gpio.h +1 -79

80 lines not on this page · raw message

board/altera/nios2-generic/nios2-generic.c +0 -7
index 384fee9..61d32c7 100644
@@ -37,13 +37,6 @@ int board_early_init_f(void)
 
 int board_early_init_r(void)
 {
-#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
 	return 0;
 }
 
configs/nios2-generic_defconfig +2 -0
index 9dc6a72..ad72272 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_DM_SERIAL=y
+CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
@@ -15,5 +16,6 @@ CONFIG_CMD_PING=y
 CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM=y
+CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
drivers/gpio/Kconfig +7 -0
index ef57a89..9e49471 100644
@@ -14,6 +14,13 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config ALTERA_PIO
+	bool "Altera PIO driver"
+	depends on DM_GPIO
+	help
+	  Select this to enable PIO for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 config DWAPB_GPIO
 	bool "DWAPB GPIO driver"
 	depends on DM && DM_GPIO
drivers/gpio/altera_pio.c +76 -240

362 lines not on this page · raw message

include/configs/nios2-generic.h +0 -20
index dcb90de..90ccbd1 100644
@@ -33,26 +33,6 @@
 #define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
 
 /*
- * 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_BOARD_SPECIFIC_LED
-#define CONFIG_GPIO_LED		/* Enable GPIO LED driver */
-#define CONFIG_GPIO			/* Enable GPIO driver */
-#define LED_PIO_BASE			USER_LED_PIO_8OUT_BASE
-#define LED_PIO_WIDTH			8
-#define LED_PIO_RSTVAL			0xff
-
-#define STATUS_LED_BIT			0	/* Bit-0 on GPIO */
-#define STATUS_LED_STATE		STATUS_LED_ON
-#define STATUS_LED_PERIOD	(CONFIG_SYS_HZ / 2)	/* 500 msec */
-#define STATUS_LED_BOOT			STATUS_LED_BIT
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#4 lore raw

PATCH v3 1/1 nios2 : convert altera_pio to driver model

Hi Thomas,

Quoted 11 lines · thomas at wytron.com.tw

Convert altera_pio to driver model.

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.

v3
change gpio_count device tree binding.

Quoted 9 lines
 arch/nios2/dts/3c120_devboard.dts          |  41 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316 +++++++----------------------
 include/configs/nios2-generic.h            |  20 --
 7 files changed, 127 insertions(+), 346 deletions(-)

Thanks
Chin Liang

#5 lore raw

PATCH v3 1/1 nios2 : convert altera_pio to driver model

In reply to Thomas Chou
Quoted 11 lines · Thomas Chou

Convert altera_pio to driver model.

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.

v3
change gpio_count device tree binding.

Quoted 8 lines
 arch/nios2/dts/3c120_devboard.dts          |  41 ++++
 arch/nios2/include/asm/gpio.h              |  80 +-------
 board/altera/nios2-generic/nios2-generic.c |   7 -
 configs/nios2-generic_defconfig            |   2 +
 drivers/gpio/Kconfig                       |   7 +
 drivers/gpio/altera_pio.c                  | 316 +++++++----------------------
 include/configs/nios2-generic.h            |  20 --
 7 files changed, 127 insertions(+), 346 deletions(-)

See question below.

[snip]

Quoted 4 lines
drivers/gpio/altera_pio.c +1 -2
-int gpio_direction_output(unsigned gpio, int value)
+static int altera_pio_ofdata_to_platdata(struct udevice *dev)
 {
-       u32 mask;

drivers/gpio/altera_pio.c line 93

Quoted 10 lines
drivers/gpio/altera_pio.c +3 -6
-       struct altera_pio *pio;
+       struct altera_pio_platdata *plat = dev_get_platdata(dev);
 
-       pio = altera_pio_get_and_mask(gpio, &mask);
-       if (!pio)
-               return -1;
-       if (pio->iot == 'i')
-               return -1;
+       plat->regs = ioremap(dev_get_addr(dev),
+               sizeof(struct altera_pio_regs));

Do we need the ioremap() or can we rely on the 'ranges' handling?

[snip]

#6 lore raw

PATCH v3 1/1 nios2 : convert altera_pio to driver model

Hi Simon,

Quoted 1 line · Simon Glass

Do we need the ioremap() or can we rely on the 'ranges' handling?

Yes, we do need ioremap() at least for mips, nios2 and alike. For these archs, the virtual address that CPU sees is not the same as physical address on bus. The virtual address space of these CPus are divided to cached kernel space, uncached kernel space, and managed user space. For main memory, we would use cached kernel space to run u-boot. While for peripheral access, we would use uncached kernel space. The device tree describes hardware, and the reg address have to be physical address. We need to map the reg address to uncached kernel virtual address. This is what ioremap() for. It is not related to ranges translation. Though we do need the range translation patch from Stefan as there might be bridges between the buses.

Thanks a lot for your review.

Best regards,
Thomas Chou

#7 lore raw

PATCH v4 1/1 nios2 : convert altera_pio to driver model

In reply to Thomas Chou

Convert altera_pio to driver model.

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.
v3
change gpio_count device tree binding.
v4
change gpio width default to 32.
doc dts binding.

 arch/nios2/dts/3c120_devboard.dts            |  41 ++++
 arch/nios2/include/asm/gpio.h                |  80 +------
 board/altera/nios2-generic/nios2-generic.c   |   7 -
 configs/nios2-generic_defconfig              |   2 +
 doc/device-tree-bindings/gpio/altera_pio.txt |  28 +++
 drivers/gpio/Kconfig                         |   7 +
 drivers/gpio/altera_pio.c                    | 316 +++++++--------------------
 include/configs/nios2-generic.h              |  20 --
 8 files changed, 155 insertions(+), 346 deletions(-)
 create mode 100644 doc/device-tree-bindings/gpio/altera_pio.txt
arch/nios2/dts/3c120_devboard.dts +41 -0
index a35f5fe..781a652 100644
@@ -68,6 +68,9 @@
 				<0x00004400 0x08004400 0x00000040>,
 				<0x00004800 0x08004800 0x00000040>,
 				<0x00004c80 0x08004c80 0x00000020>,
+				<0x00004cc0 0x08004cc0 0x00000010>,
+				<0x00004ce0 0x08004ce0 0x00000010>,
+				<0x00004d00 0x08004d00 0x00000010>,
 				<0x00004d50 0x08004d50 0x00000008>,
 				<0x00008000 0x08008000 0x00000020>,
 				<0x00400000 0x08400000 0x00000020>;
@@ -132,6 +135,44 @@
 				clock-frequency = <62500000>;
 				u-boot,dm-pre-reloc;
 			};
+
+			user_led_pio_8out: gpio at 0x4cc0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004cc0 0x00000010>;
+				resetvalue = <255>;
+				altr,gpio-bank-width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "led";
+			};
+
+			user_dipsw_pio_8in: gpio at 0x4ce0 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004ce0 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <8>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				altr,gpio-bank-width = <8>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "dipsw";
+			};
+
+			user_pb_pio_4in: gpio at 0x4d00 {
+				compatible = "altr,pio-1.0";
+				reg = <0x00004d00 0x00000010>;
+				interrupt-parent = <&cpu>;
+				interrupts = <9>;
+				edge_type = <2>;
+				level_trigger = <0>;
+				resetvalue = <0>;
+				altr,gpio-bank-width = <4>;
+				#gpio-cells = <2>;
+				gpio-controller;
+				gpio-bank-name = "pb";
+			};
 		};
 
 		cfi_flash_64m: flash at 0x0 {
arch/nios2/include/asm/gpio.h +1 -79

80 lines not on this page · raw message

board/altera/nios2-generic/nios2-generic.c +0 -7
index 384fee9..61d32c7 100644
@@ -37,13 +37,6 @@ int board_early_init_f(void)
 
 int board_early_init_r(void)
 {
-#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
 	return 0;
 }
 
configs/nios2-generic_defconfig +2 -0
index 9dc6a72..ad72272 100644
@@ -1,5 +1,6 @@
 CONFIG_NIOS2=y
 CONFIG_DM_SERIAL=y
+CONFIG_DM_GPIO=y
 CONFIG_TARGET_NIOS2_GENERIC=y
 CONFIG_DEFAULT_DEVICE_TREE="3c120_devboard"
 CONFIG_HUSH_PARSER=y
@@ -15,5 +16,6 @@ CONFIG_CMD_PING=y
 CONFIG_OF_CONTROL=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_DM=y
+CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
doc/device-tree-bindings/gpio/altera_pio.txt new file +28 -0
new file mode 100644
index 0000000..cf71eb2
@@ -0,0 +1,28 @@
+Altera GPIO controller bindings
+
+Required properties:
+- compatible:
+  - "altr,pio-1.0"
+- reg: Physical base address and length of the controller's registers.
+
+Optional properties:
+- altr,gpio-bank-width: Width of the GPIO bank. This defines how many pins the
+  GPIO device has. Ranges between 1-32. Optional and defaults to 32 if not
+  specified.
+- gpio-bank-name: bank name attached to this device.
+
+Example:
+
+user_led_pio_8out: gpio@0x4cc0 {
+	compatible = "altr,pio-1.0";
+	reg = <0x00004cc0 0x00000010>;
+	resetvalue = <255>;
+	altr,gpio-bank-width = <8>;
+	#gpio-cells = <2>;
+	gpio-controller;
+	gpio-bank-name = "led";
+};
+
+In this example, the gpio can be accessed as led[0..7] using gpio command of
+u-boot.
+==> gpio clear led0
drivers/gpio/Kconfig +7 -0
index ef57a89..9e49471 100644
@@ -14,6 +14,13 @@ config DM_GPIO
 	  particular GPIOs that they provide. The uclass interface
 	  is defined in include/asm-generic/gpio.h.
 
+config ALTERA_PIO
+	bool "Altera PIO driver"
+	depends on DM_GPIO
+	help
+	  Select this to enable PIO for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 config DWAPB_GPIO
 	bool "DWAPB GPIO driver"
 	depends on DM && DM_GPIO
drivers/gpio/altera_pio.c +76 -240

362 lines not on this page · raw message

include/configs/nios2-generic.h +0 -20
index dcb90de..90ccbd1 100644
@@ -33,26 +33,6 @@
 #define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
 
 /*
- * 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_BOARD_SPECIFIC_LED
-#define CONFIG_GPIO_LED		/* Enable GPIO LED driver */
-#define CONFIG_GPIO			/* Enable GPIO driver */
-#define LED_PIO_BASE			USER_LED_PIO_8OUT_BASE
-#define LED_PIO_WIDTH			8
-#define LED_PIO_RSTVAL			0xff
-
-#define STATUS_LED_BIT			0	/* Bit-0 on GPIO */
-#define STATUS_LED_STATE		STATUS_LED_ON
-#define STATUS_LED_PERIOD	(CONFIG_SYS_HZ / 2)	/* 500 msec */
-#define STATUS_LED_BOOT			STATUS_LED_BIT
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#8 lore raw

PATCH v4 1/1 nios2 : convert altera_pio to driver model

Quoted 4 lines · Thomas Chou

Convert altera_pio to driver model.

Quoted 10 lines

---
v2
fix ranges of pio in dts
fix coding style as Marek suggested.
v3
change gpio_count device tree binding.
v4
change gpio width default to 32.
doc dts binding.

Applied to u-boot-nios.