UPSTREAM: linux_spi: Stop messing up the units of SPI speed
'speed' is stored in Hz, so rename the variable to 'speed_hz' to
clarify any potential confusion. Also, when printing the speed after
setting it with an ioctl, convert it to kHz to match the units given
in the message.
Corresponding to flashrom svn r1769.
Original-Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Original-Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
(cherry picked from commit 69dd09d8818b338743e796276c9d39ff78ed5065)
BUG=b:153598437
BRANCH=none
TEST=builds
Tested-by: Nikolai Artemiev <nartemiev@chromium.org>
Signed-off-by: Nikolai Artemiev <nartemiev@chromium.org>
Change-Id: I356211f8d08906ba276d4e300f523cb5251fc99a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/2209943
Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
diff --git a/linux_spi.c b/linux_spi.c
index d3af2d0..c91c846 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -165,7 +165,7 @@
int linux_spi_init(void)
{
char *p, *endp, *dev;
- uint32_t speed = 0;
+ uint32_t speed_hz = 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;
@@ -190,7 +190,7 @@
p = extract_programmer_param("speed");
if (p && strlen(p)) {
- speed = (uint32_t)strtoul(p, &endp, 10) * 1000;
+ speed_hz = (uint32_t)strtoul(p, &endp, 10) * 1000;
if (p == endp) {
msg_perr("%s: invalid clock: %s kHz\n", __func__, p);
return 1;
@@ -211,14 +211,14 @@
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) {
+ if (speed_hz > 0) {
+ if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed_hz) == -1) {
msg_perr("%s: failed to set speed to %d Hz: %s\n",
- __func__, speed, strerror(errno));
+ __func__, speed_hz, strerror(errno));
return 1;
}
- msg_pdbg("Using %d kHz clock\n", speed);
+ msg_pdbg("Using %d kHz clock\n", speed_hz/1000);
}
if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) {