Previously we relied on a correctly set up state.

---
untested.

Signed-off-by: Stefan Tauner <[email protected]>
---
 linux_spi.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/linux_spi.c b/linux_spi.c
index d994389..d29c59a 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -57,6 +57,8 @@ int linux_spi_init(void)
 {
        char *p, *endp, *dev;
        uint32_t speed = 0;
+       /* FIXME: make the following configurable by CLI options. */
+       uint8_t mode = SPI_MODE_0, lsb = 0, bits = 0; /* mode 0, msb first, 8 
bits */
 
        dev = extract_programmer_param("dev");
        if (!dev || !strlen(dev)) {
@@ -92,6 +94,27 @@ int linux_spi_init(void)
                msg_pdbg("Using %d kHz clock\n", speed);
        }
 
+       if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) {
+               msg_perr("%s: failed to set SPI mode to %u: %s\n",
+                        __func__, mode, strerror(errno));
+               close(fd);
+               return 1;
+       }
+
+       if (ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb) == -1) {
+               msg_perr("%s: failed to set SPI justification to %u: %s\n",
+                        __func__, lsb, strerror(errno));
+               close(fd);
+               return 1;
+       }
+
+       if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits) == -1) {
+               msg_perr("%s: failed to set the number of bits in an SPI word 
to %u: %s\n",
+                        __func__, bits, strerror(errno));
+               close(fd);
+               return 1;
+       }
+
        if (register_shutdown(linux_spi_shutdown, NULL))
                return 1;
 
-- 
1.7.1


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to