Leonard König has uploaded this change for review.

View Change

linux_spi: add configurable spimode

Signed-off-by: Leonard König <leonard.r.koenig@googlemail.com>
Change-Id: I650cb20efd7a34c5c12bec187e25a4757388dcf8
---
M flashrom.8.tmpl
M linux_spi.c
2 files changed, 40 insertions(+), 2 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/25/38725/1
diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index aa5bcd4..1d0cff8 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -1079,6 +1079,12 @@
.sp
.B " flashrom \-p linux_spi:dev=/dev/spidevX.Y,spispeed=8000"
.sp
+Similarly, you can set the SPI mode with the optional
+.B spimode
+parameter. The mode can be either 0/1/2/3 from the kernel interface, ie.
+SPI mode 0 meaning that (CPOL,CPHA) is (0,0), a mode of 1 meaning (0,1), a mode
+of 2 (1,0) and a mode of 3 (1,1).
+.sp
Please note that the linux_spi driver only works on Linux.
.SS
.BR "mstarddc_spi " programmer
diff --git a/linux_spi.c b/linux_spi.c
index aa73c18..c890b12 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -73,9 +73,9 @@
{
char *p, *endp, *dev;
uint32_t speed_hz = 2 * 1000 * 1000;
- /* 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;
+ uint8_t mode = SPI_MODE_0;
+ /* FIXME: make the following configurable by CLI options. */
const uint8_t bits = 8;

p = extract_programmer_param("spispeed");
@@ -92,6 +92,38 @@
speed_hz / 1000);
}
free(p);
+ p = extract_programmer_param("spimode");
+ if (p && strlen(p)) {
+ unsigned long x = strtoul(p, &endp, 10);
+ if (p == endp || x > 3 /* SPI_MODE_3 */) {
+ msg_perr("%s: invalid mode: %s\n", __func__, p);
+ free(p);
+ return 1;
+ }
+ switch (x) {
+ case 0:
+ mode = SPI_MODE_0;
+ break;
+ case 1:
+ mode = SPI_MODE_1;
+ break;
+ case 2:
+ mode = SPI_MODE_2;
+ break;
+ case 3:
+ mode = SPI_MODE_3;
+ break;
+ default:
+ /* unreachable */
+ break;
+ }
+ } else {
+ msg_pinfo("Using default %"PRIu8" mode. "
+ "Use 'spimode' parameter to override.\n",
+ mode);
+ }
+ free(p);
+

dev = extract_programmer_param("dev");
if (!dev || !strlen(dev)) {

To view, visit change 38725. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I650cb20efd7a34c5c12bec187e25a4757388dcf8
Gerrit-Change-Number: 38725
Gerrit-PatchSet: 1
Gerrit-Owner: Leonard König <leonard.r.koenig@googlemail.com>
Gerrit-MessageType: newchange