summaryrefslogtreecommitdiff
path: root/drivers/mtd
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2012-02-13 23:15:25 +0100
committerWolfgang Denk <wd@denx.de>2012-02-13 23:15:25 +0100
commite9d44b35beb45869863f3ca6929089d9df4df3e5 (patch)
tree4382c3c41c944e23dc846393e52275b63d302ba3 /drivers/mtd
parent06576b2efcf3d67797437488e90e989b8b48c9f2 (diff)
parentf61ec45eb5ad819520396f91385ef3855059c1dd (diff)
downloadu-boot-imx-e9d44b35beb45869863f3ca6929089d9df4df3e5.zip
u-boot-imx-e9d44b35beb45869863f3ca6929089d9df4df3e5.tar.gz
u-boot-imx-e9d44b35beb45869863f3ca6929089d9df4df3e5.tar.bz2
Merge branch 'sf' of git://git.denx.de/u-boot-blackfin
* 'sf' of git://git.denx.de/u-boot-blackfin: README: Add description of SPI Flash (SF) command configuration sf command: allow default bus and chip selects sf: eeprom_m95xxx: set a sane default timeout sf: eeprom_m95xxx: fix up style
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/spi/eeprom_m95xxx.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/drivers/mtd/spi/eeprom_m95xxx.c b/drivers/mtd/spi/eeprom_m95xxx.c
index ef8ed6f..88b6c34 100644
--- a/drivers/mtd/spi/eeprom_m95xxx.c
+++ b/drivers/mtd/spi/eeprom_m95xxx.c
@@ -37,33 +37,37 @@
#define CONFIG_DEFAULT_SPI_MODE SPI_MODE_0
#endif
-ssize_t spi_read (uchar *addr, int alen, uchar *buffer, int len)
+#ifndef CONFIG_SYS_SPI_WRITE_TOUT
+#define CONFIG_SYS_SPI_WRITE_TOUT (5 * CONFIG_SYS_HZ)
+#endif
+
+ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len)
{
struct spi_slave *slave;
u8 cmd = SPI_EEPROM_READ;
slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000,
CONFIG_DEFAULT_SPI_MODE);
- if(!slave)
+ if (!slave)
return 0;
spi_claim_bus(slave);
/* command */
- if(spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN))
+ if (spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN))
return -1;
/*
- * if alen == 3, addr[0] is the block number, we never use it here. All we
- * need are the lower 16 bits
+ * if alen == 3, addr[0] is the block number, we never use it here.
+ * All we need are the lower 16 bits.
*/
if (alen == 3)
addr++;
/* address, and data */
- if(spi_xfer(slave, 16, addr, NULL, 0))
+ if (spi_xfer(slave, 16, addr, NULL, 0))
return -1;
- if(spi_xfer(slave, 8 * len, NULL, buffer, SPI_XFER_END))
+ if (spi_xfer(slave, 8 * len, NULL, buffer, SPI_XFER_END))
return -1;
spi_release_bus(slave);
@@ -71,7 +75,7 @@ ssize_t spi_read (uchar *addr, int alen, uchar *buffer, int len)
return len;
}
-ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len)
+ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len)
{
struct spi_slave *slave;
char buf[3];
@@ -85,7 +89,7 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len)
spi_claim_bus(slave);
buf[0] = SPI_EEPROM_WREN;
- if(spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END))
+ if (spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END))
return -1;
buf[0] = SPI_EEPROM_WRITE;
@@ -98,9 +102,9 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len)
memcpy(buf + 1, addr, alen);
/* command + addr, then data */
- if(spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN))
+ if (spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN))
return -1;
- if(spi_xfer(slave, len * 8, buffer, NULL, SPI_XFER_END))
+ if (spi_xfer(slave, len * 8, buffer, NULL, SPI_XFER_END))
return -1;
start = get_timer(0);
@@ -115,7 +119,7 @@ ssize_t spi_write (uchar *addr, int alen, uchar *buffer, int len)
} while (get_timer(start) < CONFIG_SYS_SPI_WRITE_TOUT);
if (buf[1] & 1)
- printf ("*** spi_write: Time out while writing!\n");
+ printf("*** spi_write: Timeout while writing!\n");
spi_release_bus(slave);
spi_free_slave(slave);