summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-06-14 09:29:53 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-06-14 09:29:53 +0200
commit253412624e0fa60a309c6691b0cd99b6c341df87 (patch)
treed261ea96f8b29388beb93ec1b05b7b972aa548c1 /drivers
parent6191ef93b25edbd75caec9213db3665f486ee433 (diff)
parentc35624d1946a4756c93bdb489f4790176b6e2dcc (diff)
downloadbarebox-253412624e0fa60a309c6691b0cd99b6c341df87.tar.gz
barebox-253412624e0fa60a309c6691b0cd99b6c341df87.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'drivers')
-rw-r--r--drivers/firmware/altera_serial.c159
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/of/base.c2
-rw-r--r--drivers/rtc/rtc-lib.c7
4 files changed, 116 insertions, 54 deletions
diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c
index b119778d72..3a0175dd07 100644
--- a/drivers/firmware/altera_serial.c
+++ b/drivers/firmware/altera_serial.c
@@ -25,11 +25,12 @@
#include <fcntl.h>
#include <fs.h>
-
/*
* Physical requirements:
- * - three free GPIOs for the signals nCONFIG, CONFIGURE_DONE, nSTATUS
- * - 32 bit per word, LSB first capable SPI master (MOSI + clock)
+ * - free GPIOs for the signals nCONFIG, CONFIGURE_DONE, nSTATUS (optionally
+ * for ARRIA 10)
+ * - 32 bit / 8 bit (ARRIA 10) per word, LSB first capable SPI master
+ * (MOSI + clock)
*
* Example how to configure this driver via device tree
*
@@ -43,6 +44,13 @@
* };
*/
+struct altera_ps_data {
+ int status_wait_max_us;
+ int t_st2ck_us;
+ int spi_bits_per_word;
+ int padding;
+};
+
struct fpga_spi {
struct firmware_handler fh;
int nstat_gpio; /* input GPIO to read the status line */
@@ -50,9 +58,36 @@ struct fpga_spi {
int nconfig_gpio; /* output GPIO to start the FPGA's config */
struct device_d *dev;
struct spi_device *spi;
+ const struct altera_ps_data *data;
bool padding_done;
};
+/* | Arria 5 | Arria 10 |
+ * t_CF2ST0 | [; 600] | [; 600] | ns
+ * t_CFG | [2;] | [2;] | µs
+ * t_STATUS | [268; 1506] | [268; 3000] | µs
+ * t_CF2ST1 | [; 1506] | [; 3000] | µs
+ * t_CF2CK | [1506;] | [3010 µs;] | µs
+ * t_ST2CK | [2;] | [10;] | µs
+ * t_CD2UM | [175; 437] | [175; 830] | µs
+ */
+
+/* Arria 5 */
+static struct altera_ps_data a5_data = {
+ .status_wait_max_us = 1506, /* max(t_CF2ST1) */
+ .t_st2ck_us = 2, /* min(t_ST2CK) */
+ .spi_bits_per_word = 32,
+ .padding = true,
+};
+
+/* Arria 10 */
+static struct altera_ps_data a10_data = {
+ .status_wait_max_us = 3000, /* max(t_CF2ST1) */
+ .t_st2ck_us = 10, /* min(t_ST2CK) */
+ .spi_bits_per_word = 8,
+ .padding = false,
+};
+
static int altera_spi_open(struct firmware_handler *fh)
{
struct fpga_spi *this = container_of(fh, struct fpga_spi, fh);
@@ -77,7 +112,6 @@ static int altera_spi_open(struct firmware_handler *fh)
(gpio_get_value(this->confd_gpio) == 0));
}
-
if (ret != 0) {
dev_err(dev, "FPGA does not acknowledge the programming initiation\n");
if (gpio_is_valid(this->nstat_gpio) && gpio_get_value(this->nstat_gpio))
@@ -94,24 +128,30 @@ static int altera_spi_open(struct firmware_handler *fh)
this->padding_done = false;
/*
- * after about 1506 µs the FPGA must acknowledge this step
- * with the STATUS line at high level
+ * after max { max(t_STATUS), max(t_CF2ST1) } the FPGA must acknowledge this
+ * step with the STATUS line at high level
*/
-
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");
+ ret = wait_on_timeout(this->data->status_wait_max_us * USECOND,
+ gpio_get_value(this->nstat_gpio));
+ if (ret) {
+ dev_err(dev, "nSTATUS still low after max(t_CF2ST1)! %d\n", ret);
return ret;
}
} else {
- udelay(1600);
+ udelay(this->data->status_wait_max_us);
}
dev_dbg(dev, "Initiating passed\n");
- /* at the end, wait at least 2 µs prior beginning writing data */
- udelay(2);
+
+ /*
+ * t_CF2CK doesn't need to be honored if nSTATUS is monitored in which
+ * case only t_ST2CK applies. As we have
+ * max(t_CF2ST1) + min(t_ST2CK) >= min(t_CF2CK)
+ * and we waited for max(t_CF2ST1) in the non-monitored
+ * case already above, only waiting for min(t_ST2CK) is fine here.
+ */
+ udelay(this->data->t_st2ck_us * USECOND);
return 0;
}
@@ -129,30 +169,38 @@ static int altera_spi_write(struct firmware_handler *fh, const void *buf, size_t
spi_message_init(&m);
- if (sz < sizeof(u32)) {
- /* simple padding */
- dummy = 0;
- memcpy(&dummy, buf, sz);
- buf = &dummy;
- sz = sizeof(u32);
- this->padding_done = true;
- }
+ if (this->data->padding) {
+ if (sz < sizeof(u32)) {
+ /* simple padding */
+ dummy = 0;
+ memcpy(&dummy, buf, sz);
+ buf = &dummy;
+ sz = sizeof(u32);
+ this->padding_done = true;
+ }
- t[0].tx_buf = buf;
- t[0].rx_buf = NULL;
- t[0].len = sz;
- spi_message_add_tail(&t[0], &m);
-
- if (sz & 0x3) { /* padding required? */
- u32 *word_buf = (u32 *)buf;
- dummy = 0;
- memcpy(&dummy, &word_buf[sz >> 2], sz & 0x3);
- t[0].len &= ~0x03;
- t[1].tx_buf = &dummy;
- t[1].rx_buf = NULL;
- t[1].len = sizeof(u32);
- spi_message_add_tail(&t[1], &m);
- this->padding_done = true;
+ t[0].tx_buf = buf;
+ t[0].rx_buf = NULL;
+ t[0].len = sz;
+ spi_message_add_tail(&t[0], &m);
+
+ if (sz & 0x3) { /* padding required? */
+ u32 *word_buf = (u32 *)buf;
+ dummy = 0;
+ memcpy(&dummy, &word_buf[sz >> 2], sz & 0x3);
+ t[0].len &= ~0x03;
+ t[1].tx_buf = &dummy;
+ t[1].rx_buf = NULL;
+ t[1].len = sizeof(u32);
+ spi_message_add_tail(&t[1], &m);
+ this->padding_done = true;
+ }
+ } else {
+ memset(&t[0], 0, sizeof(t[0]));
+ t[0].tx_buf = buf;
+ t[0].rx_buf = NULL;
+ t[0].len = sz;
+ spi_message_add_tail(&t[0], &m);
}
ret = spi_sync(this->spi, &m);
@@ -173,7 +221,7 @@ static int altera_spi_close(struct firmware_handler *fh)
dev_dbg(dev, "Finalize programming\n");
- if (this->padding_done == false) {
+ if (this->data->padding && this->padding_done == false) {
spi_message_init(&m);
t.tx_buf = &dummy;
t.rx_buf = NULL;
@@ -196,12 +244,23 @@ static int altera_spi_close(struct firmware_handler *fh)
} 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;
+
+ /*
+ * After CONF_DONE goes high, send two additional falling edges on DCLK
+ * to begin initialization and enter user mode
+ */
+ spi_message_init(&m);
+ memset(&t, 0, sizeof(t));
+ t.tx_buf = NULL;
+ t.rx_buf = NULL;
+ t.len = 2;
+ spi_message_add_tail(&t, &m);
+ return spi_sync(this->spi, &m);
}
dev_err(dev, "Programming failed due to time out\n");
@@ -267,9 +326,10 @@ out:
return ret;
}
-static void altera_spi_init_mode(struct spi_device *spi)
+static void altera_spi_init_mode(struct spi_device *spi, int spi_bits_per_word)
{
- spi->bits_per_word = 32;
+ spi->bits_per_word = spi_bits_per_word;
+
/*
* CPHA = CPOL = 0
* the FPGA expects its firmware data with LSB first
@@ -284,9 +344,14 @@ static int altera_spi_probe(struct device_d *dev)
struct firmware_handler *fh;
const char *alias = of_alias_get(dev->device_node);
const char *model = NULL;
+ const struct altera_ps_data *data;
dev_dbg(dev, "Probing FPGA firmware programmer\n");
+ rc = dev_get_drvdata(dev, (const void **)&data);
+ if (rc)
+ return rc;
+
this = xzalloc(sizeof(*this));
fh = &this->fh;
@@ -308,7 +373,9 @@ static int altera_spi_probe(struct device_d *dev)
fh->dev = dev;
this->spi = (struct spi_device *)dev->type_data;
- altera_spi_init_mode(this->spi);
+ this->data = data;
+
+ altera_spi_init_mode(this->spi, this->data->spi_bits_per_word);
this->dev = dev;
dev_dbg(dev, "Registering FPGA firmware programmer\n");
@@ -327,9 +394,9 @@ out:
}
static struct of_device_id altera_spi_id_table[] = {
- {
- .compatible = "altr,fpga-passive-serial",
- },
+ { .compatible = "altr,fpga-passive-serial", .data = &a5_data },
+ { .compatible = "altr,fpga-arria10-passive-serial", .data = &a10_data },
+ { }
};
static struct driver_d altera_spi_driver = {
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index caece3b78e..fd1665bebb 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -281,7 +281,7 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status)
if (drv_data->bytes_left == 1)
drv_data->cntl_bits &= ~REG_CONTROL_ACK;
- udelay(2);
+ udelay(2);
break;
case STATUS_MAST_RD_DATA_NO_ACK: /* 0x58 */
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c9bdd91810..33f61622ae 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1910,6 +1910,8 @@ int of_probe(void)
barebox_set_model(of_model);
memory = of_find_node_by_path("/memory");
+ if (!memory)
+ memory = of_find_node_by_type(root_node, "memory");
if (memory)
of_add_memory(memory, false);
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 83d80455da..4a2d34fcfd 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -20,13 +20,6 @@ static const unsigned char rtc_days_in_month[] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
-static const unsigned short rtc_ydays[2][13] = {
- /* Normal years */
- { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
- /* Leap years */
- { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
-};
-
#define LEAPS_THRU_END_OF(y) ((y)/4 - (y)/100 + (y)/400)
/*