From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>, kernel@pengutronix.de
Subject: [RESEND][PATCH] firmware: altera: Make nSTAT GPIO optional
Date: Tue, 17 Feb 2015 20:54:40 -0800 [thread overview]
Message-ID: <1424235280-3776-1-git-send-email-andrew.smirnov@gmail.com> (raw)
By taking parts of the programming handshaking protocol on faith it is
possible to make due with only two GPIO for programming Altera
FPGAs. This is not a very advisable practice, but sometime unavoidable
in GPIO constrained designs.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/firmware/altera_serial.c | 59 ++++++++++++++++++++++++++++++----------
1 file changed, 44 insertions(+), 15 deletions(-)
diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c
index c5ffbb6..4527d27 100644
--- a/drivers/firmware/altera_serial.c
+++ b/drivers/firmware/altera_serial.c
@@ -25,6 +25,7 @@
#include <fcntl.h>
#include <fs.h>
+
/*
* Physical requirements:
* - three free GPIOs for the signals nCONFIG, CONFIGURE_DONE, nSTATUS
@@ -67,13 +68,19 @@ static int altera_spi_open(struct firmware_handler *fh)
* after about 2 µs the FPGA must acknowledge with
* STATUS and CONFIG DONE lines at low level
*/
- ret = wait_on_timeout(2 * USECOND,
+ if (gpio_is_valid(this->nstat_gpio)) {
+ ret = wait_on_timeout(2 * USECOND,
(gpio_get_value(this->nstat_gpio) == 0) &&
(gpio_get_value(this->confd_gpio) == 0));
+ } else {
+ ret = wait_on_timeout(2 * USECOND,
+ (gpio_get_value(this->confd_gpio) == 0));
+ }
+
if (ret != 0) {
dev_err(dev, "FPGA does not acknowledge the programming initiation\n");
- if (gpio_get_value(this->nstat_gpio))
+ if (gpio_is_valid(this->nstat_gpio) && gpio_get_value(this->nstat_gpio))
dev_err(dev, "STATUS is still high!\n");
if (gpio_get_value(this->confd_gpio))
dev_err(dev, "CONFIG DONE is still high!\n");
@@ -90,11 +97,16 @@ static int altera_spi_open(struct firmware_handler *fh)
* after about 1506 µs the FPGA must acknowledge this step
* with the STATUS line at high level
*/
- ret = wait_on_timeout(1600 * USECOND,
+
+ if (gpio_is_valid(this->nstat_gpio)) {
+ ret = wait_on_timeout(1600 * USECOND,
gpio_get_value(this->nstat_gpio) == 1);
- if (ret != 0) {
- dev_err(dev, "FPGA does not acknowledge the programming start\n");
- return ret;
+ if (ret != 0) {
+ dev_err(dev, "FPGA does not acknowledge the programming start\n");
+ return ret;
+ }
+ } else {
+ udelay(1600);
}
dev_dbg(dev, "Initiating passed\n");
@@ -177,16 +189,24 @@ static int altera_spi_close(struct firmware_handler *fh)
* when programming was successful,
* both status lines should be at high level
*/
- ret = wait_on_timeout(10 * USECOND,
+ if (gpio_is_valid(this->nstat_gpio)) {
+ ret = wait_on_timeout(10 * USECOND,
(gpio_get_value(this->nstat_gpio) == 1) &&
(gpio_get_value(this->confd_gpio) == 1));
+ } else {
+ ret = wait_on_timeout(10 * USECOND,
+ (gpio_get_value(this->confd_gpio) == 1));
+
+ }
+
if (ret == 0) {
dev_dbg(dev, "Programming successful\n");
return ret;
}
dev_err(dev, "Programming failed due to time out\n");
- if (gpio_get_value(this->nstat_gpio) == 0)
+ if (gpio_is_valid(this->nstat_gpio) &&
+ gpio_get_value(this->nstat_gpio) == 0)
dev_err(dev, "STATUS is still low!\n");
if (gpio_get_value(this->confd_gpio) == 0)
dev_err(dev, "CONFIG DONE is still low!\n");
@@ -201,10 +221,15 @@ static int altera_spi_of(struct device_d *dev, struct fpga_spi *this)
int ret;
name = "nstat-gpio";
- this->nstat_gpio = of_get_named_gpio(n, name, 0);
- if (this->nstat_gpio < 0) {
- ret = this->nstat_gpio;
- goto out;
+ if (!of_get_property(n, name, NULL)) {
+ dev_info(dev, "nstat-gpio is not specified, assuming it is not connected\n");
+ this->nstat_gpio = -1;
+ } else {
+ this->nstat_gpio = of_get_named_gpio(n, name, 0);
+ if (this->nstat_gpio < 0) {
+ ret = this->nstat_gpio;
+ goto out;
+ }
}
name = "confd-gpio";
@@ -225,9 +250,13 @@ static int altera_spi_of(struct device_d *dev, struct fpga_spi *this)
ret = gpio_direction_output(this->nconfig_gpio, 1);
if (ret)
return ret;
- ret = gpio_direction_input(this->nstat_gpio);
- if (ret)
- return ret;
+
+ if (gpio_is_valid(this->nstat_gpio)) {
+ ret = gpio_direction_input(this->nstat_gpio);
+ if (ret)
+ return ret;
+ }
+
ret = gpio_direction_input(this->confd_gpio);
if (ret)
return ret;
--
2.1.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2015-02-18 4:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-18 4:54 Andrey Smirnov [this message]
2015-02-19 19:50 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1424235280-3776-1-git-send-email-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=kernel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox