summaryrefslogtreecommitdiff
path: root/linux_spi.c
diff options
context:
space:
mode:
authorstefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2012-03-03 18:09:33 +0000
committerstefanct <stefanct@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2012-03-03 18:09:33 +0000
commit9b77f60de08e2cf0eabbfc9ab42136f0dca340e5 (patch)
tree3460628ca2658848c6e213b80684aa44fb70e2d4 /linux_spi.c
parent8a65bed843377582ce27a841c6cb84b7d9081e96 (diff)
downloadflashrom-9b77f60de08e2cf0eabbfc9ab42136f0dca340e5.tar.gz
linux_spi.c: set SPI mode, bit order and bits per word on init.
Previously we relied on a correctly set up state. Also, we start to rely on the shutdown function for cleanup after registering it, i.e. we no longer explicitly call close(fd) after register_shutdown(). Signed-off-by: Stefan Tauner <stefan.tauner@student.tuwien.ac.at> Tested-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@1512 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'linux_spi.c')
-rw-r--r--linux_spi.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/linux_spi.c b/linux_spi.c
index d994389..2ae681f 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -57,6 +57,10 @@ int linux_spi_init(void)
{
char *p, *endp, *dev;
uint32_t speed = 0;
+ /* FIXME: make the following configurable by CLI options. */
+ /* SPI mode 0 (beware this also includes: MSB first, CS active low and others */
+ const uint8_t mode = SPI_MODE_0;
+ const uint8_t bits = 8;
dev = extract_programmer_param("dev");
if (!dev || !strlen(dev)) {
@@ -81,19 +85,31 @@ int linux_spi_init(void)
return 1;
}
+ if (register_shutdown(linux_spi_shutdown, NULL))
+ return 1;
+ /* We rely on the shutdown function for cleanup from here on. */
+
if (speed > 0) {
if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) == -1) {
- msg_perr("%s: failed to set speed %dHz: %s\n",
+ msg_perr("%s: failed to set speed to %d Hz: %s\n",
__func__, speed, strerror(errno));
- close(fd);
return 1;
}
msg_pdbg("Using %d kHz clock\n", speed);
}
- if (register_shutdown(linux_spi_shutdown, NULL))
+ if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) {
+ msg_perr("%s: failed to set SPI mode to 0x%02x: %s\n",
+ __func__, mode, strerror(errno));
return 1;
+ }
+
+ if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) {
+ msg_perr("%s: failed to set the number of bits per SPI word to %u: %s\n",
+ __func__, bits == 0 ? 8 : bits, strerror(errno));
+ return 1;
+ }
register_spi_programmer(&spi_programmer_linux);