[U-Boot] [PATCH] nios2: add gpio based status led driver

This patch adds a gpio based status led driver. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- board/altera/common/gpioled.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 board/altera/common/gpioled.c
diff --git a/board/altera/common/gpioled.c b/board/altera/common/gpioled.c new file mode 100644 index 0000000..9a51fae --- /dev/null +++ b/board/altera/common/gpioled.c @@ -0,0 +1,30 @@ +/* + * Status LED driver based on gpio + * + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <common.h> +#include <status_led.h> +#include <asm/gpio.h> + +/* assume led is active low */ + +void __led_init(led_id_t mask, int state) +{ + gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_set(led_id_t mask, int state) +{ + gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_toggle(led_id_t mask) +{ + gpio_set_value(mask, !gpio_get_value (mask)); +}

Thomas,
Thomas Chou wrote:
This patch adds a gpio based status led driver. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
board/altera/common/gpioled.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) create mode 100644 board/altera/common/gpioled.c
diff --git a/board/altera/common/gpioled.c b/board/altera/common/gpioled.c new file mode 100644 index 0000000..9a51fae --- /dev/null +++ b/board/altera/common/gpioled.c @@ -0,0 +1,30 @@ +/*
- Status LED driver based on gpio
- Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
- */
+#include <common.h> +#include <status_led.h> +#include <asm/gpio.h>
+/* assume led is active low */
+void __led_init(led_id_t mask, int state) +{
- gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);
The direction register only exists when the PIO core hardware is configured in bidirectional mode.
+void __led_set(led_id_t mask, int state) +{
- gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1);
+}
+void __led_toggle(led_id_t mask) +{
- gpio_set_value(mask, !gpio_get_value (mask));
+}
If the PIO core hardware is configured in output-only mode, reading from data returns an undefined value.
As I recall, the older designs configured the LED PIO ports as output only ... which is why board/altera/common/epled.c was coded in such a manner.
Regards, --Scott

On 04/20/2010 09:19 PM, Scott McNutt wrote:
+void __led_init(led_id_t mask, int state) +{
- gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);
The direction register only exists when the PIO core hardware is configured in bidirectional mode.
If the PIO core hardware is configured in output-only mode, reading from data returns an undefined value.
As I recall, the older designs configured the LED PIO ports as output only ... which is why board/altera/common/epled.c was coded in such a manner.
Hi Scott,
This is not for Altera PIO interface. I followed the gpio interface of Linux, linux-2.6/Documentation/gpio.txt, and created a trivial bit addressing gpio core, which uses fewer LE and doesn't required interrupt disabled to write a bit. With this core, all output pins are bidirectional and can be read. I used it to access i2c, one-wire, leds, buttons and nand flash busy flag in nios2 linux. I didn't add irq support, because input layer of linux can do debounce. Please look at http://nioswiki.com/GPIO.
Best regards, Thomas

Thomas Chou wrote:
On 04/20/2010 09:19 PM, Scott McNutt wrote:
+void __led_init(led_id_t mask, int state) +{
- gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);
The direction register only exists when the PIO core hardware is configured in bidirectional mode.
If the PIO core hardware is configured in output-only mode, reading from data returns an undefined value.
As I recall, the older designs configured the LED PIO ports as output only ... which is why board/altera/common/epled.c was coded in such a manner.
Hi Scott,
This is not for Altera PIO interface. I followed the gpio interface of Linux, linux-2.6/Documentation/gpio.txt, and created a trivial bit addressing gpio core,
I don't think the Altera board tree is an appropriate place for code that supports custom logic blocks. If an Altera distribution provided a design that included this custom block in one of their board designs then it would probably be fine.
I'm not sure where this should go ... maybe in the driver tree?
Regards, --Scott

On 04/21/2010 12:19 AM, Scott McNutt wrote:
I don't think the Altera board tree is an appropriate place for code that supports custom logic blocks. If an Altera distribution provided a design that included this custom block in one of their board designs then it would probably be fine.
I'm not sure where this should go ... maybe in the driver tree?
Hi Scott,
Thanks. I will move it to drivers/misc.
Cheers, Thomas

This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- Moved to drivers/misc.
drivers/misc/Makefile | 1 + drivers/misc/gpio_led.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/gpio_led.c
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index f6df60f..55ff17f 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -28,6 +28,7 @@ LIB := $(obj)libmisc.a COBJS-$(CONFIG_ALI152X) += ali512x.o COBJS-$(CONFIG_DS4510) += ds4510.o COBJS-$(CONFIG_FSL_LAW) += fsl_law.o +COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_STATUS_LED) += status_led.o COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c new file mode 100644 index 0000000..eff1433 --- /dev/null +++ b/drivers/misc/gpio_led.c @@ -0,0 +1,30 @@ +/* + * Status LED driver based on GPIO access conventions of Linux + * + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <common.h> +#include <status_led.h> +#include <asm/gpio.h> + +/* assume led is active low */ + +void __led_init(led_id_t mask, int state) +{ + gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_set(led_id_t mask, int state) +{ + gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_toggle(led_id_t mask) +{ + gpio_set_value(mask, !gpio_get_value (mask)); +}

Dear Thomas Chou,
In message 1271810712-16238-1-git-send-email-thomas@wytron.com.tw you wrote:
This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Moved to drivers/misc.
Which boards are the users of this code?
Best regards,
Wolfgang Denk

On 04/25/2010 03:23 AM, Wolfgang Denk wrote:
Dear Thomas Chou,
In message1271810712-16238-1-git-send-email-thomas@wytron.com.tw you wrote:
This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chouthomas@wytron.com.tw
Moved to drivers/misc.
Which boards are the users of this code?
Best regards,
Wolfgang Denk
Hi Wolfgang,
It is used in the example designs of Altera NEEK and DE2 boards, which I provided for nios2 linux/uclinux on nios wiki. They are used by many nios2 users.
It may be used by other boards which support the GPIO access conventions of Linux. Though the GPIO access is not unified in u-boot currently, I think it should be the right direction to follow the conventions of Linux.
Best regards, Thomas

Dear Thomas Chou,
In message 4BD36BAE.2060903@wytron.com.tw you wrote:
This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chouthomas@wytron.com.tw
Moved to drivers/misc.
Which boards are the users of this code?
...
It is used in the example designs of Altera NEEK and DE2 boards, which I provided for nios2 linux/uclinux on nios wiki. They are used by many nios2 users.
It may be used by other boards which support the GPIO access conventions of Linux. Though the GPIO access is not unified in u-boot currently, I think it should be the right direction to follow the conventions of Linux.
I mean, which board in U-Boot uses this code? I didn't find any.
The convention is not to add unused code. If there are no real users for this, the patch should be delayed until a board gets added that actually uses it.
Best regards,
Wolfgang Denk

On 04/25/2010 06:32 AM, Wolfgang Denk wrote:
I mean, which board in U-Boot uses this code? I didn't find any.
The convention is not to add unused code. If there are no real users for this, the patch should be delayed until a board gets added that actually uses it.
Hi Wolfgang,
These nios2 boards are now supported with the nios2-generic board approach, like that of microblaze-generic, instead of adding every nios2 board to u-boot mainline. The nios2-generic board patch was applied to Scott's next branch.
The gpio led can be enabled with the following added to the board config file.
/* * STATUS LED */ #define CONFIG_STATUS_LED /* Enable status driver */ #define CONFIG_GPIO_LED /* Enable gpio led driver */
#define STATUS_LED_BIT 2 /* Bit-2 on GPIO */ #define STATUS_LED_STATE 1 /* Blinking */ #define STATUS_LED_PERIOD (500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */
Cheers, Thomas

Hi Wolfgang,
Thomas Chou wrote:
On 04/25/2010 06:32 AM, Wolfgang Denk wrote:
I mean, which board in U-Boot uses this code? I didn't find any.
I think the most accurate answer is both "all" and "none" ... and I'm not trying to be funny or disrespectful in any way. It's just so very easy to replace peripherals with these FPGA based systems.
The convention is not to add unused code. If there are no real users for this, the patch should be delayed until a board gets added that actually uses it.
My understanding is that the nios2 linux folks make use of the peripheral that this driver supports. However, the peripheral is not a standard Altera peripheral. In any case, it can essentially be used on any nios2 board as a replacement for the stock PIO peripheral.
These nios2 boards are now supported with the nios2-generic board approach, like that of microblaze-generic, instead of adding every nios2 board to u-boot mainline. The nios2-generic board patch was applied to Scott's next branch.
Correct. I asked Thomas to remove this peripheral from the Altera board tree because it was not associated with a _standard_ Altera peripheral. That is, anyone using the default configurations from Altera will never use this driver.
However, the nios2 linux folks are very likely to use it (as a replacement). And, when they build u-boot, it will probably be configured using the nios2-generic board. So this isn't a rabbit in the hat ... the code will used. It's just not directly tied to a particular PCB from a traditional point of view.
Regards, --Scott

Dear Scott McNutt,
In message 4BD39170.2040502@psyent.com you wrote:
I mean, which board in U-Boot uses this code? I didn't find any.
I think the most accurate answer is both "all" and "none" ... and I'm not trying to be funny or disrespectful in any way. It's just so very easy to replace peripherals with these FPGA based systems.
Yes, but the current number of actual users so far is zero.
However, the nios2 linux folks are very likely to use it (as a replacement). And, when they build u-boot, it will probably be configured using the nios2-generic board. So this isn't a rabbit in the hat ... the code will used. It's just not directly tied to a particular PCB from a traditional point of view.
OK. Let's add the code when there is a user for it.
Best regards,
Wolfgang Denk

Dear Thomas Chou,
In message 4BD377C9.6010809@wytron.com.tw you wrote:
The convention is not to add unused code. If there are no real users for this, the patch should be delayed until a board gets added that actually uses it.
These nios2 boards are now supported with the nios2-generic board approach, like that of microblaze-generic, instead of adding every nios2 board to u-boot mainline. The nios2-generic board patch was applied to Scott's next branch.
The gpio led can be enabled with the following added to the board config file.
As long as no board actually uses this code we should put that patch on hold. Please resubmit it as part of the patch series that adds the first board that uses this code. Thanks.
Best regards,
Wolfgang Denk

On 04/26/2010 02:14 AM, Wolfgang Denk wrote:
As long as no board actually uses this code we should put that patch on hold. Please resubmit it as part of the patch series that adds the first board that uses this code. Thanks.
Hi Wolfgang,
I sent a patch to enable some peripherals on the nios2-generic board.
04/28 [PATCH v2] nios2: add epcs, gpio led and mmc_spi to nios2-generic
This patch should be applied after the other outstanding patches. Please let me know if this is all right?
Best regards, Thomas

Dear Thomas Chou,
In message 4BD7B0B3.3010007@wytron.com.tw you wrote:
I sent a patch to enable some peripherals on the nios2-generic board.
04/28 [PATCH v2] nios2: add epcs, gpio led and mmc_spi to nios2-generic
This patch should be applied after the other outstanding patches. Please let me know if this is all right?
I don't understand how this is supposed to work? How can you enable a feature that has not been added yet? Will this not cause build errors?
I guess to make sure the code remains bisectable both should be done in a single step?
Best regards,
Wolfgang Denk

Dear Wolfgang,
Wolfgang Denk wrote:
Dear Thomas Chou,
In message 4BD7B0B3.3010007@wytron.com.tw you wrote:
I sent a patch to enable some peripherals on the nios2-generic board.
04/28 [PATCH v2] nios2: add epcs, gpio led and mmc_spi to nios2-generic
This patch should be applied after the other outstanding patches. Please let me know if this is all right?
I don't understand how this is supposed to work? How can you enable a feature that has not been added yet? Will this not cause build errors?
It can't. I won't. It will.
I guess to make sure the code remains bisectable both should be done in a single step?
I have a few patches pending in such a state -- they will not be added until the prerequisites are met.
I'd be glad to push the various prerequisite patches into a test branch ... but I've be far too busy.
Regards, --Scott

On 05/05/2010 06:30 AM, Wolfgang Denk wrote:
Dear Thomas Chou,
In message4BD7B0B3.3010007@wytron.com.tw you wrote:
I sent a patch to enable some peripherals on the nios2-generic board.
04/28 [PATCH v2] nios2: add epcs, gpio led and mmc_spi to nios2-generic
This patch should be applied after the other outstanding patches. Please let me know if this is all right?
I don't understand how this is supposed to work? How can you enable a feature that has not been added yet? Will this not cause build errors?
I guess to make sure the code remains bisectable both should be done in a single step?
Best regards,
Wolfgang Denk
Hi Wolfgang and Scott,
Please disregard the v2 patch on 04/28. I have resubmit the patch series in a way that they can be applied one-by-one without breaking others. I have tested the build on Altera dev boards using standard configuration.
04/30 [PATCH 0/6] add gpio_led and altera_spi drivers nios2: add gpio support misc: add gpio based status led driver nios2: add gpio support to nios2-generic board spi: add altera spi controller support spi_flash: support old STMicro parts with RES, v3 acked by Mike Frysinger. nios2: add spi flash support to nios2-generic board
Best regards, Thomas

This patch series add gpio_led and altera_spi support for the nios2-generic board, which is based on the Altera EP1C20 board. It enables status LED and SPI flash access on this board. It includes the outstanding patches to complete the support.
Best regards, Thomas
Thomas Chou (6): nios2: add gpio support misc: add gpio based status led driver nios2: add gpio support to nios2-generic board spi: add altera spi controller support spi_flash: support old STMicro parts with RES nios2: add spi flash support to nios2-generic board
arch/nios2/include/asm/gpio.h | 52 ++++++++++ board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/custom_fpga.h | 10 ++ board/altera/nios2-generic/gpio.c | 55 ++++++++++ drivers/misc/Makefile | 1 + drivers/misc/gpio_led.c | 30 ++++++ drivers/mtd/spi/spi_flash.c | 1 + drivers/mtd/spi/stmicro.c | 21 ++++ drivers/spi/Makefile | 1 + drivers/spi/altera_spi.c | 165 ++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 +- 11 files changed, 340 insertions(+), 3 deletions(-) create mode 100644 arch/nios2/include/asm/gpio.h create mode 100644 board/altera/nios2-generic/gpio.c create mode 100644 drivers/misc/gpio_led.c create mode 100644 drivers/spi/altera_spi.c

This patch adds driver for a trivial gpio core, which is described in http://nioswiki.com/GPIO. It is used for gpio led and nand flash interface in u-boot.
When CONFIG_SYS_GPIO_BASE is not defined, board may provide its own driver.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v4: remove () from gpio when it is not in a macro. v3: arch dir reorganized.
arch/nios2/include/asm/gpio.h | 52 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) create mode 100644 arch/nios2/include/asm/gpio.h
diff --git a/arch/nios2/include/asm/gpio.h b/arch/nios2/include/asm/gpio.h new file mode 100644 index 0000000..76c425e --- /dev/null +++ b/arch/nios2/include/asm/gpio.h @@ -0,0 +1,52 @@ +/* + * nios2 gpio driver + * + * This gpio core is described in http://nioswiki.com/GPIO + * bit[0] data + * bit[1] output enable + * + * when CONFIG_SYS_GPIO_BASE is not defined, board may provide + * its own driver. + * + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _ASM_NIOS2_GPIO_H_ +#define _ASM_NIOS2_GPIO_H_ + +#ifdef CONFIG_SYS_GPIO_BASE +#include <asm/io.h> + +static inline int gpio_direction_input(unsigned gpio) +{ + writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2)); + return 0; +} + +static inline int gpio_direction_output(unsigned gpio, int value) +{ + writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); + return 0; +} + +static inline int gpio_get_value(unsigned gpio) +{ + return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2)); +} + +static inline void gpio_set_value(unsigned gpio, int value) +{ + writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2)); +} +#else +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); +#endif /* CONFIG_SYS_GPIO_BASE */ + +#endif /* _ASM_NIOS2_GPIO_H_ */

On 30/04/10 04:34, Thomas Chou wrote:
This patch adds driver for a trivial gpio core, which is described in http://nioswiki.com/GPIO. It is used for gpio led and nand flash interface in u-boot.
When CONFIG_SYS_GPIO_BASE is not defined, board may provide its own driver.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Tested with LED on Altera 2C35 development board.
Tested-by: Ian Abbott abbotti@mev.co.uk

Applied to:
git://git.denx.de/u-boot-nios.git next
Thanks, --Scott
Thomas Chou wrote:
This patch adds driver for a trivial gpio core, which is described in http://nioswiki.com/GPIO. It is used for gpio led and nand flash interface in u-boot.
When CONFIG_SYS_GPIO_BASE is not defined, board may provide its own driver.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v4: remove () from gpio when it is not in a macro. v3: arch dir reorganized.
arch/nios2/include/asm/gpio.h | 52 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) create mode 100644 arch/nios2/include/asm/gpio.h
diff --git a/arch/nios2/include/asm/gpio.h b/arch/nios2/include/asm/gpio.h new file mode 100644 index 0000000..76c425e --- /dev/null +++ b/arch/nios2/include/asm/gpio.h @@ -0,0 +1,52 @@ +/*
- nios2 gpio driver
- This gpio core is described in http://nioswiki.com/GPIO
- bit[0] data
- bit[1] output enable
- when CONFIG_SYS_GPIO_BASE is not defined, board may provide
- its own driver.
- Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
- */
+#ifndef _ASM_NIOS2_GPIO_H_ +#define _ASM_NIOS2_GPIO_H_
+#ifdef CONFIG_SYS_GPIO_BASE +#include <asm/io.h>
+static inline int gpio_direction_input(unsigned gpio) +{
- writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2));
- return 0;
+}
+static inline int gpio_direction_output(unsigned gpio, int value) +{
- writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
- return 0;
+}
+static inline int gpio_get_value(unsigned gpio) +{
- return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2));
+}
+static inline void gpio_set_value(unsigned gpio, int value) +{
- writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
+} +#else +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); +#endif /* CONFIG_SYS_GPIO_BASE */
+#endif /* _ASM_NIOS2_GPIO_H_ */

This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v2: moved to drivers/misc.
drivers/misc/Makefile | 1 + drivers/misc/gpio_led.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/gpio_led.c
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index f6df60f..55ff17f 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -28,6 +28,7 @@ LIB := $(obj)libmisc.a COBJS-$(CONFIG_ALI152X) += ali512x.o COBJS-$(CONFIG_DS4510) += ds4510.o COBJS-$(CONFIG_FSL_LAW) += fsl_law.o +COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_STATUS_LED) += status_led.o COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c new file mode 100644 index 0000000..acd6a90 --- /dev/null +++ b/drivers/misc/gpio_led.c @@ -0,0 +1,30 @@ +/* + * Status LED driver based on GPIO access conventions of Linux + * + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include <common.h> +#include <status_led.h> +#include <asm/gpio.h> + +/* assume led is active low */ + +void __led_init(led_id_t mask, int state) +{ + gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_set(led_id_t mask, int state) +{ + gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1); +} + +void __led_toggle(led_id_t mask) +{ + gpio_set_value(mask, !gpio_get_value(mask)); +}

On 30/04/10 04:34, Thomas Chou wrote:
This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Tested on Altera 2C35 development board.
Tested-by: Ian Abbott abbotti@mev.co.uk

Applied to:
git://git.denx.de/u-boot-nios.git next
Thanks, --Scott
Thomas Chou wrote:
This patch adds a status led driver followed the GPIO access conventions of Linux. The led mask is used to specify the gpio pin.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v2: moved to drivers/misc.
drivers/misc/Makefile | 1 + drivers/misc/gpio_led.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/gpio_led.c
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index f6df60f..55ff17f 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -28,6 +28,7 @@ LIB := $(obj)libmisc.a COBJS-$(CONFIG_ALI152X) += ali512x.o COBJS-$(CONFIG_DS4510) += ds4510.o COBJS-$(CONFIG_FSL_LAW) += fsl_law.o +COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_NS87308) += ns87308.o COBJS-$(CONFIG_STATUS_LED) += status_led.o COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o diff --git a/drivers/misc/gpio_led.c b/drivers/misc/gpio_led.c new file mode 100644 index 0000000..acd6a90 --- /dev/null +++ b/drivers/misc/gpio_led.c @@ -0,0 +1,30 @@ +/*
- Status LED driver based on GPIO access conventions of Linux
- Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
- */
+#include <common.h> +#include <status_led.h> +#include <asm/gpio.h>
+/* assume led is active low */
+void __led_init(led_id_t mask, int state) +{
- gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);
+}
+void __led_set(led_id_t mask, int state) +{
- gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1);
+}
+void __led_toggle(led_id_t mask) +{
- gpio_set_value(mask, !gpio_get_value(mask));
+}

This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v3: split patches for gpio and spi, based gpio on altera pio core. v2: remove mmc_spi_init()
board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/gpio.c | 55 +++++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 board/altera/nios2-generic/gpio.c
diff --git a/board/altera/nios2-generic/Makefile b/board/altera/nios2-generic/Makefile index 6780872..d1fca70 100644 --- a/board/altera/nios2-generic/Makefile +++ b/board/altera/nios2-generic/Makefile @@ -32,6 +32,7 @@ LIB = $(obj)lib$(BOARD).a 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 diff --git a/board/altera/nios2-generic/gpio.c b/board/altera/nios2-generic/gpio.c new file mode 100644 index 0000000..6c9c6c2 --- /dev/null +++ b/board/altera/nios2-generic/gpio.c @@ -0,0 +1,55 @@ +/* + * board gpio driver + * + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * Licensed under the GPL-2 or later. + */ +#include <common.h> +#include <asm/io.h> + +#ifndef CONFIG_SYS_GPIO_BASE + +#define ALTERA_PIO_BASE LED_PIO_BASE +#define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0) +#define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4) +static u32 pio_data_reg; +static u32 pio_dir_reg; + +int gpio_direction_input(unsigned gpio) +{ + u32 mask = 1 << gpio; + writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR); + return 0; +} + +int gpio_direction_output(unsigned gpio, int value) +{ + u32 mask = 1 << gpio; + if (value) + pio_data_reg |= mask; + else + pio_data_reg &= ~mask; + writel(pio_data_reg, ALTERA_PIO_DATA); + writel(pio_dir_reg |= mask, ALTERA_PIO_DIR); + return 0; +} + +int gpio_get_value(unsigned gpio) +{ + u32 mask = 1 << gpio; + if (pio_dir_reg & mask) + return (pio_data_reg & mask) ? 1 : 0; + else + return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0; +} + +void gpio_set_value(unsigned gpio, int value) +{ + u32 mask = 1 << gpio; + if (value) + pio_data_reg |= mask; + else + pio_data_reg &= ~mask; + writel(pio_data_reg, ALTERA_PIO_DATA); +} +#endif diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index e83e1e3..e4bf57b 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -63,10 +63,10 @@ * STATUS LED */ #define CONFIG_STATUS_LED /* Enable status driver */ -#define CONFIG_EPLED /* Enable LED PIO driver */ -#define CONFIG_SYS_LEDPIO_ADDR LED_PIO_BASE +#define CONFIG_GPIO_LED /* Enable GPIO LED driver */ +#define CONFIG_GPIO /* Enable GPIO driver */
-#define STATUS_LED_BIT 1 /* Bit-0 on PIO */ +#define STATUS_LED_BIT 0 /* Bit-0 on GPIO */ #define STATUS_LED_STATE 1 /* Blinking */ #define STATUS_LED_PERIOD (500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */

Thomas Chou wrote:
This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v3: split patches for gpio and spi, based gpio on altera pio core. v2: remove mmc_spi_init()
board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/gpio.c | 55 +++++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 board/altera/nios2-generic/gpio.c
diff --git a/board/altera/nios2-generic/Makefile b/board/altera/nios2-generic/Makefile index 6780872..d1fca70 100644 --- a/board/altera/nios2-generic/Makefile +++ b/board/altera/nios2-generic/Makefile @@ -32,6 +32,7 @@ LIB = $(obj)lib$(BOARD).a 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
This will build a u-boot image that will not work with any of the standard configurations ... correct? ... since the GPIO component is custom (not supplied by the vendor)?
--Scott

On 04/30/2010 10:24 PM, Scott McNutt wrote:
Thomas Chou wrote:
This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v3: split patches for gpio and spi, based gpio on altera pio core. v2: remove mmc_spi_init()
board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/gpio.c | 55 +++++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 board/altera/nios2-generic/gpio.c
diff --git a/board/altera/nios2-generic/Makefile b/board/altera/nios2-generic/Makefile index 6780872..d1fca70 100644 --- a/board/altera/nios2-generic/Makefile +++ b/board/altera/nios2-generic/Makefile @@ -32,6 +32,7 @@ LIB = $(obj)lib$(BOARD).a 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
This will build a u-boot image that will not work with any of the standard configurations ... correct? ... since the GPIO component is custom (not supplied by the vendor)?
Hi Scott,
The board gpio.c driver works on Altera PIO component. It will behave exactly the same as the epled driver. I have tested it on EP1C20 an EP2C35 board with standard configuration. I believe it will work with the standard configuration on EP1S10 and EP1S40. I don't want to break anything.
It was actually the first gpio driver I wrote for nios2-linux before the custom gpio core.
Best regards, Thomas

Thomas Chou wrote:
On 04/30/2010 10:24 PM, Scott McNutt wrote:
Thomas Chou wrote:
This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v3: split patches for gpio and spi, based gpio on altera pio core. v2: remove mmc_spi_init()
board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/gpio.c | 55 +++++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 board/altera/nios2-generic/gpio.c
diff --git a/board/altera/nios2-generic/Makefile b/board/altera/nios2-generic/Makefile index 6780872..d1fca70 100644 --- a/board/altera/nios2-generic/Makefile +++ b/board/altera/nios2-generic/Makefile @@ -32,6 +32,7 @@ LIB = $(obj)lib$(BOARD).a 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
This will build a u-boot image that will not work with any of the standard configurations ... correct? ... since the GPIO component is custom (not supplied by the vendor)?
Hi Scott,
The board gpio.c driver works on Altera PIO component. It will behave exactly the same as the epled driver. I have tested it on EP1C20 an EP2C35 board with standard configuration. I believe it will work with the standard configuration on EP1S10 and EP1S40. I don't want to break anything.
Ok. I'll try to test over the weekend as well.
Thanks, --Scott

On 30/04/10 04:34, Thomas Chou wrote:
This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Tested with LED on Altera 2C35 development board.
Tested-by: Ian Abbott abbotti@mev.co.uk

Applied to:
git://git.denx.de/u-boot-nios.git next
Thanks, --Scott
Thomas Chou wrote:
This patch adds gpio support of Altera PIO component to the nios2-generic board. Though it drives only gpio_led at the moment, it supports bidirectional port to control bit-banging I2C, NAND flash busy status or button switches, etc.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v3: split patches for gpio and spi, based gpio on altera pio core. v2: remove mmc_spi_init()
board/altera/nios2-generic/Makefile | 1 + board/altera/nios2-generic/gpio.c | 55 +++++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 6 ++-- 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 board/altera/nios2-generic/gpio.c
diff --git a/board/altera/nios2-generic/Makefile b/board/altera/nios2-generic/Makefile index 6780872..d1fca70 100644 --- a/board/altera/nios2-generic/Makefile +++ b/board/altera/nios2-generic/Makefile @@ -32,6 +32,7 @@ LIB = $(obj)lib$(BOARD).a 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 diff --git a/board/altera/nios2-generic/gpio.c b/board/altera/nios2-generic/gpio.c new file mode 100644 index 0000000..6c9c6c2 --- /dev/null +++ b/board/altera/nios2-generic/gpio.c @@ -0,0 +1,55 @@ +/*
- board gpio driver
- Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw
- Licensed under the GPL-2 or later.
- */
+#include <common.h> +#include <asm/io.h>
+#ifndef CONFIG_SYS_GPIO_BASE
+#define ALTERA_PIO_BASE LED_PIO_BASE +#define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0) +#define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4) +static u32 pio_data_reg; +static u32 pio_dir_reg;
+int gpio_direction_input(unsigned gpio) +{
- u32 mask = 1 << gpio;
- writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
- return 0;
+}
+int gpio_direction_output(unsigned gpio, int value) +{
- u32 mask = 1 << gpio;
- if (value)
pio_data_reg |= mask;
- else
pio_data_reg &= ~mask;
- writel(pio_data_reg, ALTERA_PIO_DATA);
- writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
- return 0;
+}
+int gpio_get_value(unsigned gpio) +{
- u32 mask = 1 << gpio;
- if (pio_dir_reg & mask)
return (pio_data_reg & mask) ? 1 : 0;
- else
return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
+}
+void gpio_set_value(unsigned gpio, int value) +{
- u32 mask = 1 << gpio;
- if (value)
pio_data_reg |= mask;
- else
pio_data_reg &= ~mask;
- writel(pio_data_reg, ALTERA_PIO_DATA);
+} +#endif diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index e83e1e3..e4bf57b 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -63,10 +63,10 @@
- STATUS LED
*/ #define CONFIG_STATUS_LED /* Enable status driver */ -#define CONFIG_EPLED /* Enable LED PIO driver */ -#define CONFIG_SYS_LEDPIO_ADDR LED_PIO_BASE +#define CONFIG_GPIO_LED /* Enable GPIO LED driver */ +#define CONFIG_GPIO /* Enable GPIO driver */
-#define STATUS_LED_BIT 1 /* Bit-0 on PIO */ +#define STATUS_LED_BIT 0 /* Bit-0 on GPIO */ #define STATUS_LED_STATE 1 /* Blinking */ #define STATUS_LED_PERIOD (500 / CONFIG_SYS_NIOS_TMRMS) /* 500 msec */

This patch adds the driver of altera spi controller, which is used as epcs/spi flash controller. It also works with mmc_spi driver.
This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v10 remove bus check in setup slave, as spi_cs_is_valid() did it. v9 check bus in spi_cs_is_valid(). v8 fix cs activate timing. v7 add cs activate deactive to work with legacy spi_mmc driver. v6 wrong patch, same as v5. v5 tabify.
drivers/spi/Makefile | 1 + drivers/spi/altera_spi.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/altera_spi.c
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index f112ed0..dfcbb8b 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libspi.a
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c new file mode 100644 index 0000000..918b223 --- /dev/null +++ b/drivers/spi/altera_spi.c @@ -0,0 +1,165 @@ +/* + * Altera SPI driver + * + * based on bfin_spi.c + * Copyright (c) 2005-2008 Analog Devices Inc. + * Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw + * + * Licensed under the GPL-2 or later. + */ +#include <common.h> +#include <asm/io.h> +#include <malloc.h> +#include <spi.h> + +#define ALTERA_SPI_RXDATA 0 +#define ALTERA_SPI_TXDATA 4 +#define ALTERA_SPI_STATUS 8 +#define ALTERA_SPI_CONTROL 12 +#define ALTERA_SPI_SLAVE_SEL 20 + +#define ALTERA_SPI_STATUS_ROE_MSK (0x8) +#define ALTERA_SPI_STATUS_TOE_MSK (0x10) +#define ALTERA_SPI_STATUS_TMT_MSK (0x20) +#define ALTERA_SPI_STATUS_TRDY_MSK (0x40) +#define ALTERA_SPI_STATUS_RRDY_MSK (0x80) +#define ALTERA_SPI_STATUS_E_MSK (0x100) + +#define ALTERA_SPI_CONTROL_IROE_MSK (0x8) +#define ALTERA_SPI_CONTROL_ITOE_MSK (0x10) +#define ALTERA_SPI_CONTROL_ITRDY_MSK (0x40) +#define ALTERA_SPI_CONTROL_IRRDY_MSK (0x80) +#define ALTERA_SPI_CONTROL_IE_MSK (0x100) +#define ALTERA_SPI_CONTROL_SSO_MSK (0x400) + +#ifndef CONFIG_SYS_ALTERA_SPI_LIST +#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE } +#endif + +static ulong altera_spi_base_list[] = CONFIG_SYS_ALTERA_SPI_LIST; + +struct altera_spi_slave { + struct spi_slave slave; + ulong base; +}; +#define to_altera_spi_slave(s) container_of(s, struct altera_spi_slave, slave) + +__attribute__((weak)) +int spi_cs_is_valid(unsigned int bus, unsigned int cs) +{ + return bus < ARRAY_SIZE(altera_spi_base_list) && cs < 32; +} + +__attribute__((weak)) +void spi_cs_activate(struct spi_slave *slave) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + writel(1 << slave->cs, altspi->base + ALTERA_SPI_SLAVE_SEL); + writel(ALTERA_SPI_CONTROL_SSO_MSK, altspi->base + ALTERA_SPI_CONTROL); +} + +__attribute__((weak)) +void spi_cs_deactivate(struct spi_slave *slave) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + writel(0, altspi->base + ALTERA_SPI_CONTROL); + writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); +} + +void spi_init(void) +{ +} + +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, + unsigned int max_hz, unsigned int mode) +{ + struct altera_spi_slave *altspi; + + if (!spi_cs_is_valid(bus, cs)) + return NULL; + + altspi = malloc(sizeof(*altspi)); + if (!altspi) + return NULL; + + altspi->slave.bus = bus; + altspi->slave.cs = cs; + altspi->base = altera_spi_base_list[bus]; + debug("%s: bus:%i cs:%i base:%lx\n", __func__, + bus, cs, altspi->base); + + return &altspi->slave; +} + +void spi_free_slave(struct spi_slave *slave) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + free(altspi); +} + +int spi_claim_bus(struct spi_slave *slave) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + + debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs); + writel(0, altspi->base + ALTERA_SPI_CONTROL); + writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); + return 0; +} + +void spi_release_bus(struct spi_slave *slave) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + + debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs); + writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL); +} + +#ifndef CONFIG_ALTERA_SPI_IDLE_VAL +# define CONFIG_ALTERA_SPI_IDLE_VAL 0xff +#endif + +int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, + void *din, unsigned long flags) +{ + struct altera_spi_slave *altspi = to_altera_spi_slave(slave); + /* assume spi core configured to do 8 bit transfers */ + uint bytes = bitlen / 8; + const uchar *txp = dout; + uchar *rxp = din; + + debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__, + slave->bus, slave->cs, bitlen, bytes, flags); + if (bitlen == 0) + goto done; + + if (bitlen % 8) { + flags |= SPI_XFER_END; + goto done; + } + + /* empty read buffer */ + if (readl(altspi->base + ALTERA_SPI_STATUS) & + ALTERA_SPI_STATUS_RRDY_MSK) + readl(altspi->base + ALTERA_SPI_RXDATA); + if (flags & SPI_XFER_BEGIN) + spi_cs_activate(slave); + + while (bytes--) { + uchar d = txp ? *txp++ : CONFIG_ALTERA_SPI_IDLE_VAL; + debug("%s: tx:%x ", __func__, d); + writel(d, altspi->base + ALTERA_SPI_TXDATA); + while (!(readl(altspi->base + ALTERA_SPI_STATUS) & + ALTERA_SPI_STATUS_RRDY_MSK)) + ; + d = readl(altspi->base + ALTERA_SPI_RXDATA); + if (rxp) + *rxp++ = d; + debug("rx:%x\n", d); + } + done: + if (flags & SPI_XFER_END) + spi_cs_deactivate(slave); + + return 0; +}

On 30/04/10 04:34, Thomas Chou wrote:
This patch adds the driver of altera spi controller, which is used as epcs/spi flash controller. It also works with mmc_spi driver.
This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Tested with EPCS64N flash chip on Altera 2C35 development board.
Tested-by: Ian Abbott abbotti@mev.co.uk

Applied to:
git://git.denx.de/u-boot-nios.git next
Thanks, --Scott
Thomas Chou wrote:
This patch adds the driver of altera spi controller, which is used as epcs/spi flash controller. It also works with mmc_spi driver.
This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v10 remove bus check in setup slave, as spi_cs_is_valid() did it. v9 check bus in spi_cs_is_valid(). v8 fix cs activate timing. v7 add cs activate deactive to work with legacy spi_mmc driver. v6 wrong patch, same as v5. v5 tabify.
drivers/spi/Makefile | 1 + drivers/spi/altera_spi.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/altera_spi.c
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index f112ed0..dfcbb8b 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libspi.a
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c new file mode 100644 index 0000000..918b223 --- /dev/null +++ b/drivers/spi/altera_spi.c @@ -0,0 +1,165 @@ +/*
- Altera SPI driver
- based on bfin_spi.c
- Copyright (c) 2005-2008 Analog Devices Inc.
- Copyright (C) 2010 Thomas Chou thomas@wytron.com.tw
- Licensed under the GPL-2 or later.
- */
+#include <common.h> +#include <asm/io.h> +#include <malloc.h> +#include <spi.h>
+#define ALTERA_SPI_RXDATA 0 +#define ALTERA_SPI_TXDATA 4 +#define ALTERA_SPI_STATUS 8 +#define ALTERA_SPI_CONTROL 12 +#define ALTERA_SPI_SLAVE_SEL 20
+#define ALTERA_SPI_STATUS_ROE_MSK (0x8) +#define ALTERA_SPI_STATUS_TOE_MSK (0x10) +#define ALTERA_SPI_STATUS_TMT_MSK (0x20) +#define ALTERA_SPI_STATUS_TRDY_MSK (0x40) +#define ALTERA_SPI_STATUS_RRDY_MSK (0x80) +#define ALTERA_SPI_STATUS_E_MSK (0x100)
+#define ALTERA_SPI_CONTROL_IROE_MSK (0x8) +#define ALTERA_SPI_CONTROL_ITOE_MSK (0x10) +#define ALTERA_SPI_CONTROL_ITRDY_MSK (0x40) +#define ALTERA_SPI_CONTROL_IRRDY_MSK (0x80) +#define ALTERA_SPI_CONTROL_IE_MSK (0x100) +#define ALTERA_SPI_CONTROL_SSO_MSK (0x400)
+#ifndef CONFIG_SYS_ALTERA_SPI_LIST +#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE } +#endif
+static ulong altera_spi_base_list[] = CONFIG_SYS_ALTERA_SPI_LIST;
+struct altera_spi_slave {
- struct spi_slave slave;
- ulong base;
+}; +#define to_altera_spi_slave(s) container_of(s, struct altera_spi_slave, slave)
+__attribute__((weak)) +int spi_cs_is_valid(unsigned int bus, unsigned int cs) +{
- return bus < ARRAY_SIZE(altera_spi_base_list) && cs < 32;
+}
+__attribute__((weak)) +void spi_cs_activate(struct spi_slave *slave) +{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- writel(1 << slave->cs, altspi->base + ALTERA_SPI_SLAVE_SEL);
- writel(ALTERA_SPI_CONTROL_SSO_MSK, altspi->base + ALTERA_SPI_CONTROL);
+}
+__attribute__((weak)) +void spi_cs_deactivate(struct spi_slave *slave) +{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- writel(0, altspi->base + ALTERA_SPI_CONTROL);
- writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL);
+}
+void spi_init(void) +{ +}
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
unsigned int max_hz, unsigned int mode)
+{
- struct altera_spi_slave *altspi;
- if (!spi_cs_is_valid(bus, cs))
return NULL;
- altspi = malloc(sizeof(*altspi));
- if (!altspi)
return NULL;
- altspi->slave.bus = bus;
- altspi->slave.cs = cs;
- altspi->base = altera_spi_base_list[bus];
- debug("%s: bus:%i cs:%i base:%lx\n", __func__,
bus, cs, altspi->base);
- return &altspi->slave;
+}
+void spi_free_slave(struct spi_slave *slave) +{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- free(altspi);
+}
+int spi_claim_bus(struct spi_slave *slave) +{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
- writel(0, altspi->base + ALTERA_SPI_CONTROL);
- writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL);
- return 0;
+}
+void spi_release_bus(struct spi_slave *slave) +{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
- writel(0, altspi->base + ALTERA_SPI_SLAVE_SEL);
+}
+#ifndef CONFIG_ALTERA_SPI_IDLE_VAL +# define CONFIG_ALTERA_SPI_IDLE_VAL 0xff +#endif
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
void *din, unsigned long flags)
+{
- struct altera_spi_slave *altspi = to_altera_spi_slave(slave);
- /* assume spi core configured to do 8 bit transfers */
- uint bytes = bitlen / 8;
- const uchar *txp = dout;
- uchar *rxp = din;
- debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
slave->bus, slave->cs, bitlen, bytes, flags);
- if (bitlen == 0)
goto done;
- if (bitlen % 8) {
flags |= SPI_XFER_END;
goto done;
- }
- /* empty read buffer */
- if (readl(altspi->base + ALTERA_SPI_STATUS) &
ALTERA_SPI_STATUS_RRDY_MSK)
readl(altspi->base + ALTERA_SPI_RXDATA);
- if (flags & SPI_XFER_BEGIN)
spi_cs_activate(slave);
- while (bytes--) {
uchar d = txp ? *txp++ : CONFIG_ALTERA_SPI_IDLE_VAL;
debug("%s: tx:%x ", __func__, d);
writel(d, altspi->base + ALTERA_SPI_TXDATA);
while (!(readl(altspi->base + ALTERA_SPI_STATUS) &
ALTERA_SPI_STATUS_RRDY_MSK))
;
d = readl(altspi->base + ALTERA_SPI_RXDATA);
if (rxp)
*rxp++ = d;
debug("rx:%x\n", d);
- }
- done:
- if (flags & SPI_XFER_END)
spi_cs_deactivate(slave);
- return 0;
+}

Some old STMicro parts do not support JEDEC ID (0x9f). This patch uses RES (0xab) to get Electronic ID and translates it to JEDEC ID. This is needed to support the SPI flash chip on Altera EP1C20 board.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v2: move the logic to stmicro's probe function.
drivers/mtd/spi/spi_flash.c | 1 + drivers/mtd/spi/stmicro.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 612f819..c8e4bdd 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -147,6 +147,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, #endif #ifdef CONFIG_SPI_FLASH_STMICRO case 0x20: + case 0xff: flash = spi_flash_probe_stmicro(spi, idcode); break; #endif diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c index ae0d047..21e9b00 100644 --- a/drivers/mtd/spi/stmicro.c +++ b/drivers/mtd/spi/stmicro.c @@ -46,6 +46,7 @@ #define CMD_M25PXX_DP 0xb9 /* Deep Power-down */ #define CMD_M25PXX_RES 0xab /* Release from DP, and Read Signature */
+#define STM_ID_M25P10 0x11 #define STM_ID_M25P16 0x15 #define STM_ID_M25P20 0x12 #define STM_ID_M25P32 0x16 @@ -78,6 +79,13 @@ static inline struct stmicro_spi_flash *to_stmicro_spi_flash(struct spi_flash
static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { { + .idcode1 = STM_ID_M25P10, + .page_size = 256, + .pages_per_sector = 128, + .nr_sectors = 4, + .name = "M25P10", + }, + { .idcode1 = STM_ID_M25P16, .page_size = 256, .pages_per_sector = 256, @@ -316,6 +324,19 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) struct stmicro_spi_flash *stm; unsigned int i;
+ if (idcode[0] == 0xff) { + i = spi_flash_cmd(spi, CMD_M25PXX_RES, + idcode, 4); + if (i) + return NULL; + if ((idcode[3] & 0xf0) == 0x10) { + idcode[0] = 0x20; + idcode[1] = 0x20; + idcode[2] = idcode[3] + 1; + } else + return NULL; + } + for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) { params = &stmicro_spi_flash_table[i]; if (params->idcode1 == idcode[2]) {

On Thursday 29 April 2010 23:34:17 Thomas Chou wrote:
--- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -147,6 +147,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, #endif #ifdef CONFIG_SPI_FLASH_STMICRO case 0x20:
- case 0xff: flash = spi_flash_probe_stmicro(spi, idcode); break;
#endif
hrm, this kind of sucks, but i guess for now it's fine. stick a comment in there about why we're sending the normal error byte to the stmicro function. /* Let the stmicro func handle non-JEDEC ids */ -mike

On 04/30/2010 08:48 PM, Mike Frysinger wrote:
On Thursday 29 April 2010 23:34:17 Thomas Chou wrote:
--- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -147,6 +147,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, #endif #ifdef CONFIG_SPI_FLASH_STMICRO case 0x20:
- case 0xff: flash = spi_flash_probe_stmicro(spi, idcode); break; #endif
hrm, this kind of sucks, but i guess for now it's fine. stick a comment in there about why we're sending the normal error byte to the stmicro function. /* Let the stmicro func handle non-JEDEC ids */ -mike
Hi Mike,
I added the comment. Thank you very much.
Best regards, Thomas

Some old STMicro parts do not support JEDEC ID (0x9f). This patch uses RES (0xab) to get Electronic ID and translates it to JEDEC ID.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v3: add comment as Mike suggested for 0xff id switch. v2: move the logic to stmicro's probe function
drivers/mtd/spi/spi_flash.c | 1 + drivers/mtd/spi/stmicro.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 612f819..c8e4bdd 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -147,6 +147,7 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, #endif #ifdef CONFIG_SPI_FLASH_STMICRO case 0x20: + case 0xff: /* Let the stmicro func handle non-JEDEC ids */ flash = spi_flash_probe_stmicro(spi, idcode); break; #endif diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c index ae0d047..21e9b00 100644 --- a/drivers/mtd/spi/stmicro.c +++ b/drivers/mtd/spi/stmicro.c @@ -46,6 +46,7 @@ #define CMD_M25PXX_DP 0xb9 /* Deep Power-down */ #define CMD_M25PXX_RES 0xab /* Release from DP, and Read Signature */
+#define STM_ID_M25P10 0x11 #define STM_ID_M25P16 0x15 #define STM_ID_M25P20 0x12 #define STM_ID_M25P32 0x16 @@ -78,6 +79,13 @@ static inline struct stmicro_spi_flash *to_stmicro_spi_flash(struct spi_flash
static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { { + .idcode1 = STM_ID_M25P10, + .page_size = 256, + .pages_per_sector = 128, + .nr_sectors = 4, + .name = "M25P10", + }, + { .idcode1 = STM_ID_M25P16, .page_size = 256, .pages_per_sector = 256, @@ -316,6 +324,19 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) struct stmicro_spi_flash *stm; unsigned int i;
+ if (idcode[0] == 0xff) { + i = spi_flash_cmd(spi, CMD_M25PXX_RES, + idcode, 4); + if (i) + return NULL; + if ((idcode[3] & 0xf0) == 0x10) { + idcode[0] = 0x20; + idcode[1] = 0x20; + idcode[2] = idcode[3] + 1; + } else + return NULL; + } + for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) { params = &stmicro_spi_flash_table[i]; if (params->idcode1 == idcode[2]) {

On Friday 30 April 2010 09:11:20 Thomas Chou wrote:
Some old STMicro parts do not support JEDEC ID (0x9f). This patch uses RES (0xab) to get Electronic ID and translates it to JEDEC ID.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Acked-by: Mike Frysinger vapier@gentoo.org
if we want to do non-jedec stuff in other parts, we can worry about refactoring this code then -mike

ive merged this into my sf branch and will push out next merge window if Wolfgang doesnt pick it up before that -mike

On 05/05/2010 03:21 PM, Mike Frysinger wrote:
ive merged this into my sf branch and will push out next merge window if Wolfgang doesnt pick it up before that -mike
Hi Mike,
You are so nice. Thanks again.
Best regards, Thomas

Dear Mike Frysinger,
In message 201005050321.49140.vapier@gentoo.org you wrote:
ive merged this into my sf branch and will push out next merge window if Wolfgang doesnt pick it up before that
Just let me know what you (and Thomas) prefer, and what exactly (which patch[es] from this series) the "it" is that should be picked up (or not).
Best regards,
Wolfgang Denk

On Wednesday 05 May 2010 15:57:29 Wolfgang Denk wrote:
Mike Frysinger wrote:
ive merged this into my sf branch and will push out next merge window if Wolfgang doesnt pick it up before that
Just let me know what you (and Thomas) prefer
doesnt matter to me whether you pull my branch now or after the merge window: git://git.denx.de/u-boot-blackfin.git sf
and what exactly (which patch[es] from this series) the "it" is that should be picked up (or not).
there is only one patch in this thread ...
referring to all the patches in my branch, none are "bugfixes" persay which is why i didnt know if you wanted to let them sit until next merge window. -mike

Dear Wolfgang,
On 05/06/2010 03:57 AM, Wolfgang Denk wrote:
Dear Mike Frysinger,
In message201005050321.49140.vapier@gentoo.org you wrote:
ive merged this into my sf branch and will push out next merge window if Wolfgang doesnt pick it up before that
Just let me know what you (and Thomas) prefer, and what exactly (which patch[es] from this series) the "it" is that should be picked up (or not).
These patches were submitted within this merge window. I just resubmitted the outstanding patches in a series as you suggested. It would be nice if you can merge them in this release. The current u-boot supports only very old, obsolete Altera dev boards, most newer boards are not supported. I hope we can work together to let these patches merged, so that most Altera's dev boards can be supported.
The drivers for gpio, altera_spi, spi_flash and mmc_spi are important as Altera includes them in their example design.
Best regards, Thomas

This patch enables the altera_spi and spi_flash drivers for the nios2-generic board. It allows access to the EPCS/SPI flash on the Altera EP1C20 board.
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v3: split patches for gpio and spi. v2: remove mmc_spi_init()
board/altera/nios2-generic/custom_fpga.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/board/altera/nios2-generic/custom_fpga.h b/board/altera/nios2-generic/custom_fpga.h index 761f605..a11add5 100644 --- a/board/altera/nios2-generic/custom_fpga.h +++ b/board/altera/nios2-generic/custom_fpga.h @@ -35,6 +35,16 @@ #define CONFIG_SMC91111 #define CONFIG_SMC_USE_32_BIT
+/* epcs_controller.epcs_control_port is a altera_avalon_epcs_flash_controller */ +#define EPCS_CONTROLLER_REG_BASE 0x82100200 +#define CONFIG_SYS_ALTERA_SPI_LIST { EPCS_CONTROLLER_REG_BASE } +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_SF +#define CONFIG_SF_DEFAULT_SPEED 30000000 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_STMICRO + /* jtag_uart.avalon_jtag_slave is a altera_avalon_jtag_uart */ #define CONFIG_SYS_JTAG_UART_BASE 0x821208b0

On 30/04/10 04:34, Thomas Chou wrote:
This patch enables the altera_spi and spi_flash drivers for the nios2-generic board. It allows access to the EPCS/SPI flash on the Altera EP1C20 board.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
Tested with EPCS64N flash chip on Altera 2C35 development board.
Tested-by: Ian Abbott abbotti@mev.co.uk

Thomas,
I applied this to: git://git.denx.de/u-boot-nios.git testing
after merging with Mike's 'sf' branch at: git://git.denx.de/u-boot-blackfin
so we can pickup: [PATCH 5/6 v3] spi_flash: support old STMicro parts with RES
I'll merge once Mike's changes are available upstream. In the meantime, the nios testing branch has the entire patch series available.
Regards, --Scott
Thomas Chou wrote:
This patch enables the altera_spi and spi_flash drivers for the nios2-generic board. It allows access to the EPCS/SPI flash on the Altera EP1C20 board.
Signed-off-by: Thomas Chou thomas@wytron.com.tw
v3: split patches for gpio and spi. v2: remove mmc_spi_init()
board/altera/nios2-generic/custom_fpga.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/board/altera/nios2-generic/custom_fpga.h b/board/altera/nios2-generic/custom_fpga.h index 761f605..a11add5 100644 --- a/board/altera/nios2-generic/custom_fpga.h +++ b/board/altera/nios2-generic/custom_fpga.h @@ -35,6 +35,16 @@ #define CONFIG_SMC91111 #define CONFIG_SMC_USE_32_BIT
+/* epcs_controller.epcs_control_port is a altera_avalon_epcs_flash_controller */ +#define EPCS_CONTROLLER_REG_BASE 0x82100200 +#define CONFIG_SYS_ALTERA_SPI_LIST { EPCS_CONTROLLER_REG_BASE } +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_SF +#define CONFIG_SF_DEFAULT_SPEED 30000000 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_STMICRO
/* jtag_uart.avalon_jtag_slave is a altera_avalon_jtag_uart */ #define CONFIG_SYS_JTAG_UART_BASE 0x821208b0

Since Wolfgang requests that new driver should be used with a board, these peripherals are added to the nios2-generic board.
It will exercise drivers in these outstanding patches, 04/17 [PATCH v4] nios2: add gpio support 04/21 [PATCH v2] misc: add gpio based status led driver 04/27 [PATCH v8] spi: add altera spi controller support 04/27 [PATCH v3] mmc: add generic mmc spi driver
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- board/altera/nios2-generic/custom_fpga.h | 29 ++++++++++++++++++++++++++++ board/altera/nios2-generic/nios2-generic.c | 13 ++++++++++++ include/configs/nios2-generic.h | 9 ++++++- 3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/board/altera/nios2-generic/custom_fpga.h b/board/altera/nios2-generic/custom_fpga.h index 761f605..4e51ea3 100644 --- a/board/altera/nios2-generic/custom_fpga.h +++ b/board/altera/nios2-generic/custom_fpga.h @@ -63,4 +63,33 @@ /* sysid.control_slave is a altera_avalon_sysid */ #define CONFIG_SYS_SYSID_BASE 0x821208b8
+/* epcs_controller.epcs_control_port is a altera_avalon_epcs_flash_controller */ +#define CONFIG_SYS_SPI_BASE 0x82100200 +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_SF +#define CONFIG_SF_DEFAULT_SPEED 30000000 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_STMICRO + +/* gpio_0.avalon_slave_0 is a gpio */ +#define CONFIG_SYS_GPIO_BASE 0x82120900 + +/* mmc_spi.spi_control_port is a altera_avalon_spi */ +#define MMC_SPI_BASE 0x82120940 +#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE, MMC_SPI_BASE } +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_MMC +#define CONFIG_MMC +#define CONFIG_GENERIC_MMC +#define CONFIG_CMD_MMC_SPI +#define CONFIG_MMC_SPI +#define CONFIG_MMC_SPI_BUS 1 +#define CONFIG_MMC_SPI_CS 0 +#define CONFIG_MMC_SPI_SPEED 30000000 +#define CONFIG_MMC_SPI_MODE SPI_MODE_3 +#define CONFIG_CMD_FAT +#define CONFIG_DOS_PARTITION + #endif /* _CUSTOM_FPGA_H_ */ diff --git a/board/altera/nios2-generic/nios2-generic.c b/board/altera/nios2-generic/nios2-generic.c index 89848cf..f19fb1a 100644 --- a/board/altera/nios2-generic/nios2-generic.c +++ b/board/altera/nios2-generic/nios2-generic.c @@ -24,6 +24,7 @@
#include <common.h> #include <netdev.h> +#include <mmc_spi.h>
void text_base_hook(void); /* nop hook for text_base.S */
@@ -66,3 +67,15 @@ int board_eth_init(bd_t *bis) return rc; } #endif + +#ifdef CONFIG_GENERIC_MMC +int board_mmc_init(bd_t *bis) +{ + int rc = 0; +#ifdef CONFIG_MMC_SPI + rc = mmc_spi_init(CONFIG_MMC_SPI_BUS, CONFIG_MMC_SPI_CS, + CONFIG_MMC_SPI_SPEED, CONFIG_MMC_SPI_MODE); +#endif + return rc; +} +#endif diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index e83e1e3..3716275 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -63,6 +63,7 @@ * STATUS LED */ #define CONFIG_STATUS_LED /* Enable status driver */ +#undef CONFIG_GPIO_LED /* Enable GPIO LED driver */ #define CONFIG_EPLED /* Enable LED PIO driver */ #define CONFIG_SYS_LEDPIO_ADDR LED_PIO_BASE
@@ -108,7 +109,7 @@ #define CONFIG_ENV_SIZE 0x10000 /* 64k, 1 sector */ #define CONFIG_ENV_OVERWRITE /* Serial change Ok */ #define CONFIG_ENV_ADDR ((CONFIG_SYS_RESET_ADDR + \ - CONFIG_SYS_MONITOR_LEN) | \ + 0x40000) | \ CONFIG_SYS_FLASH_BASE)
/* @@ -119,7 +120,11 @@ * -The stack is placed below global data (&grows down). */ #define CONFIG_MONITOR_IS_IN_RAM -#define CONFIG_SYS_MONITOR_LEN 0x40000 /* Reserve 256k */ +#if defined(CONFIG_CMD_FAT) +# define CONFIG_SYS_MONITOR_LEN 0x80000 /* Reserve 512k */ +#else +# define CONFIG_SYS_MONITOR_LEN 0x40000 /* Reserve 256k */ +#endif #define CONFIG_SYS_MONITOR_BASE (CONFIG_SYS_SDRAM_BASE + \ CONFIG_SYS_SDRAM_SIZE - \ CONFIG_SYS_MONITOR_LEN)

Since Wolfgang requests that new driver should be used with a board, these peripherals are added to the nios2-generic board.
It will exercise drivers in these outstanding patches, 04/17 [PATCH v4] nios2: add gpio support 04/21 [PATCH v2] misc: add gpio based status led driver 04/28 [PATCH v9] spi: add altera spi controller support 04/28 [PATCH v4] mmc: add generic mmc spi driver
Signed-off-by: Thomas Chou thomas@wytron.com.tw --- v2 remove mmc_spi_init() from nios2-generic.c.
board/altera/nios2-generic/custom_fpga.h | 29 +++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 9 +++++++-- 2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/board/altera/nios2-generic/custom_fpga.h b/board/altera/nios2-generic/custom_fpga.h index 761f605..4e51ea3 100644 --- a/board/altera/nios2-generic/custom_fpga.h +++ b/board/altera/nios2-generic/custom_fpga.h @@ -63,4 +63,33 @@ /* sysid.control_slave is a altera_avalon_sysid */ #define CONFIG_SYS_SYSID_BASE 0x821208b8
+/* epcs_controller.epcs_control_port is a altera_avalon_epcs_flash_controller */ +#define CONFIG_SYS_SPI_BASE 0x82100200 +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_SF +#define CONFIG_SF_DEFAULT_SPEED 30000000 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_STMICRO + +/* gpio_0.avalon_slave_0 is a gpio */ +#define CONFIG_SYS_GPIO_BASE 0x82120900 + +/* mmc_spi.spi_control_port is a altera_avalon_spi */ +#define MMC_SPI_BASE 0x82120940 +#define CONFIG_SYS_ALTERA_SPI_LIST { CONFIG_SYS_SPI_BASE, MMC_SPI_BASE } +#define CONFIG_ALTERA_SPI +#define CONFIG_CMD_SPI +#define CONFIG_CMD_MMC +#define CONFIG_MMC +#define CONFIG_GENERIC_MMC +#define CONFIG_CMD_MMC_SPI +#define CONFIG_MMC_SPI +#define CONFIG_MMC_SPI_BUS 1 +#define CONFIG_MMC_SPI_CS 0 +#define CONFIG_MMC_SPI_SPEED 30000000 +#define CONFIG_MMC_SPI_MODE SPI_MODE_3 +#define CONFIG_CMD_FAT +#define CONFIG_DOS_PARTITION + #endif /* _CUSTOM_FPGA_H_ */ diff --git a/include/configs/nios2-generic.h b/include/configs/nios2-generic.h index e83e1e3..3716275 100644 --- a/include/configs/nios2-generic.h +++ b/include/configs/nios2-generic.h @@ -63,6 +63,7 @@ * STATUS LED */ #define CONFIG_STATUS_LED /* Enable status driver */ +#undef CONFIG_GPIO_LED /* Enable GPIO LED driver */ #define CONFIG_EPLED /* Enable LED PIO driver */ #define CONFIG_SYS_LEDPIO_ADDR LED_PIO_BASE
@@ -108,7 +109,7 @@ #define CONFIG_ENV_SIZE 0x10000 /* 64k, 1 sector */ #define CONFIG_ENV_OVERWRITE /* Serial change Ok */ #define CONFIG_ENV_ADDR ((CONFIG_SYS_RESET_ADDR + \ - CONFIG_SYS_MONITOR_LEN) | \ + 0x40000) | \ CONFIG_SYS_FLASH_BASE)
/* @@ -119,7 +120,11 @@ * -The stack is placed below global data (&grows down). */ #define CONFIG_MONITOR_IS_IN_RAM -#define CONFIG_SYS_MONITOR_LEN 0x40000 /* Reserve 256k */ +#if defined(CONFIG_CMD_FAT) +# define CONFIG_SYS_MONITOR_LEN 0x80000 /* Reserve 512k */ +#else +# define CONFIG_SYS_MONITOR_LEN 0x40000 /* Reserve 256k */ +#endif #define CONFIG_SYS_MONITOR_BASE (CONFIG_SYS_SDRAM_BASE + \ CONFIG_SYS_SDRAM_SIZE - \ CONFIG_SYS_MONITOR_LEN)

On Tuesday, April 20, 2010 20:45:12 Thomas Chou wrote:
+void __led_init(led_id_t mask, int state) +{
- gpio_direction_output(mask, (state == STATUS_LED_ON) ? 0 : 1);
+}
+void __led_set(led_id_t mask, int state) +{
- gpio_set_value(mask, (state == STATUS_LED_ON) ? 0 : 1);
+}
are these checks correct ? "on" means a value of "1" with GPIO lines, but here you're setting the value to 0 when the state is "on". so perhaps they should both read: ..., state == STATUS_LED_ON);
+void __led_toggle(led_id_t mask) +{
- gpio_set_value(mask, !gpio_get_value (mask));
+}
no space before the (mask) -mike
participants (5)
-
Ian Abbott
-
Mike Frysinger
-
Scott McNutt
-
Thomas Chou
-
Wolfgang Denk