Angel Pons has uploaded this change for review.

View Change

bitbang_spi: Refactor `set_sck_set_mosi`

Set the state of MOSI before changing SCK. This makes no difference for
programmers that set both signals at once, but may improve reliability
for those that do not, because MOSI now has more time to stabilize.

Change-Id: Ia84d32965e56ca563062893ebbefbbea5c35814c
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
---
M bitbang_spi.c
M developerbox_spi.c
M mcp6x_spi.c
M nicintel_spi.c
M ogp_spi.c
M pony_spi.c
M programmer.h
M rayer_spi.c
8 files changed, 23 insertions(+), 23 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/69/49269/1
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 1b0692c..dfcf503 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -44,9 +44,9 @@
master->release_bus();
}

-static void bitbang_spi_set_sck_set_mosi(const struct bitbang_spi_master * const master, int sck, int mosi)
+static void bitbang_spi_set_mosi_set_sck(const struct bitbang_spi_master * const master, int mosi, int sck)
{
- master->set_sck_set_mosi(sck, mosi);
+ master->set_mosi_set_sck(mosi, sck);
}

static int bitbang_spi_set_sck_get_miso(const struct bitbang_spi_master * const master, int sck)
@@ -61,7 +61,7 @@

for (i = 7; i >= 0; i--) {
if (i == 0)
- bitbang_spi_set_sck_set_mosi(master, 0, 0);
+ bitbang_spi_set_mosi_set_sck(master, 0, 0);
else
bitbang_spi_set_sck(master, 0);
programmer_delay(master->half_period);
@@ -77,7 +77,7 @@
int i;

for (i = 7; i >= 0; i--) {
- bitbang_spi_set_sck_set_mosi(master, 0, (val >> i) & 1);
+ bitbang_spi_set_mosi_set_sck(master, (val >> i) & 1, 0);
programmer_delay(master->half_period);
bitbang_spi_set_sck(master, 1);
programmer_delay(master->half_period);
@@ -137,7 +137,7 @@
struct spi_master mst = spi_master_bitbang;
/* If someone forgot to initialize a bitbang function, we catch it here. */
if (!master || !master->set_cs ||
- !master->set_sck || !master->set_sck_set_mosi || !master->set_sck_get_miso ||
+ !master->set_sck || !master->set_mosi_set_sck || !master->set_sck_get_miso ||
(master->request_bus && !master->release_bus) ||
(!master->request_bus && master->release_bus)) {
msg_perr("Incomplete SPI bitbang master setting!\n"
@@ -151,7 +151,7 @@
/* Only mess with the bus if we're sure nobody else uses it. */
bitbang_spi_request_bus(master);
bitbang_spi_set_cs(master, 1);
- bitbang_spi_set_sck_set_mosi(master, 0, 0);
+ bitbang_spi_set_mosi_set_sck(master, 0, 0);
/* FIXME: Release SPI bus here and request it again for each command or
* don't release it now and only release it on programmer shutdown?
*/
diff --git a/developerbox_spi.c b/developerbox_spi.c
index 7011c9a..0c33dfb 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -104,7 +104,7 @@
cp210x_gpio_set(val << DEVELOPERBOX_SPI_SCK, 1 << DEVELOPERBOX_SPI_SCK);
}

-static void cp210x_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void cp210x_bitbang_set_mosi_set_sck(int mosi, int sck)
{
cp210x_gpio_set(sck << DEVELOPERBOX_SPI_SCK | mosi << DEVELOPERBOX_SPI_MOSI,
1 << DEVELOPERBOX_SPI_SCK | 1 << DEVELOPERBOX_SPI_MOSI);
@@ -119,7 +119,7 @@
static const struct bitbang_spi_master bitbang_spi_master_cp210x = {
.set_cs = cp210x_bitbang_set_cs,
.set_sck = cp210x_bitbang_set_sck,
- .set_sck_set_mosi = cp210x_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = cp210x_bitbang_set_mosi_set_sck,
.set_sck_get_miso = cp210x_bitbang_set_sck_get_miso,
};

diff --git a/mcp6x_spi.c b/mcp6x_spi.c
index a0e51fc..c99174c 100644
--- a/mcp6x_spi.c
+++ b/mcp6x_spi.c
@@ -74,7 +74,7 @@
mmio_writeb(mcp_gpiostate, mcp6x_spibar + 0x530);
}

-static void mcp6x_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void mcp6x_bitbang_set_mosi_set_sck(int mosi, int sck)
{
mcp_gpiostate &= ~(1 << MCP6X_SPI_SCK);
mcp_gpiostate &= ~(1 << MCP6X_SPI_MOSI);
@@ -95,7 +95,7 @@
static const struct bitbang_spi_master bitbang_spi_master_mcp6x = {
.set_cs = mcp6x_bitbang_set_cs,
.set_sck = mcp6x_bitbang_set_sck,
- .set_sck_set_mosi = mcp6x_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = mcp6x_bitbang_set_mosi_set_sck,
.set_sck_get_miso = mcp6x_bitbang_set_sck_get_miso,
.request_bus = mcp6x_request_spibus,
.release_bus = mcp6x_release_spibus,
diff --git a/nicintel_spi.c b/nicintel_spi.c
index f16c2cd..5c210cd 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -148,7 +148,7 @@
pci_mmio_writel(tmp, nicintel_spibar + FLA);
}

-static void nicintel_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void nicintel_bitbang_set_mosi_set_sck(int mosi, int sck)
{
uint32_t tmp;

@@ -174,7 +174,7 @@
static const struct bitbang_spi_master bitbang_spi_master_nicintel = {
.set_cs = nicintel_bitbang_set_cs,
.set_sck = nicintel_bitbang_set_sck,
- .set_sck_set_mosi = nicintel_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = nicintel_bitbang_set_mosi_set_sck,
.set_sck_get_miso = nicintel_bitbang_set_sck_get_miso,
.request_bus = nicintel_request_spibus,
.release_bus = nicintel_release_spibus,
diff --git a/ogp_spi.c b/ogp_spi.c
index c2a4d18..355d452 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -69,10 +69,10 @@
pci_mmio_writel(val, ogp_spibar + ogp_reg_sck);
}

-static void ogp_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void ogp_bitbang_set_mosi_set_sck(int mosi, int sck)
{
- ogp_bitbang_set_sck(sck);
pci_mmio_writel(mosi, ogp_spibar + ogp_reg_siso);
+ ogp_bitbang_set_sck(sck);
}

static int ogp_bitbang_set_sck_get_miso(int sck)
@@ -88,7 +88,7 @@
static const struct bitbang_spi_master bitbang_spi_master_ogp = {
.set_cs = ogp_bitbang_set_cs,
.set_sck = ogp_bitbang_set_sck,
- .set_sck_set_mosi = ogp_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = ogp_bitbang_set_mosi_set_sck,
.set_sck_get_miso = ogp_bitbang_set_sck_get_miso,
.request_bus = ogp_request_spibus,
.release_bus = ogp_release_spibus,
diff --git a/pony_spi.c b/pony_spi.c
index 37d0f08..131ac28 100644
--- a/pony_spi.c
+++ b/pony_spi.c
@@ -72,14 +72,14 @@
sp_set_pin(PIN_RTS, val);
}

-static void pony_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void pony_bitbang_set_mosi_set_sck(int mosi, int sck)
{
- pony_bitbang_set_sck(sck);
-
if (pony_negate_mosi)
mosi ^= 1;

sp_set_pin(PIN_DTR, mosi);
+
+ pony_bitbang_set_sck(sck);
}

static int pony_bitbang_set_sck_get_miso(int sck)
@@ -97,7 +97,7 @@
static const struct bitbang_spi_master bitbang_spi_master_pony = {
.set_cs = pony_bitbang_set_cs,
.set_sck = pony_bitbang_set_sck,
- .set_sck_set_mosi = pony_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = pony_bitbang_set_mosi_set_sck,
.set_sck_get_miso = pony_bitbang_set_sck_get_miso,
.half_period = 0,
};
@@ -197,7 +197,7 @@
* Detect if there is a compatible hardware programmer connected.
*/
pony_bitbang_set_cs(1);
- pony_bitbang_set_sck_set_mosi(1, 1);
+ pony_bitbang_set_mosi_set_sck(1, 1);

switch (type) {
case TYPE_AJAWE:
diff --git a/programmer.h b/programmer.h
index 51e7e88..9c94694 100644
--- a/programmer.h
+++ b/programmer.h
@@ -184,7 +184,7 @@
/* Note that CS# is active low, so val=0 means the chip is active. */
void (*set_cs) (int val);
void (*set_sck) (int val);
- void (*set_sck_set_mosi) (int sck, int mosi);
+ void (*set_mosi_set_sck) (int mosi, int sck);
int (*set_sck_get_miso) (int sck);
void (*request_bus) (void);
void (*release_bus) (void);
diff --git a/rayer_spi.c b/rayer_spi.c
index 1649f1b..c956a1b 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -140,7 +140,7 @@
OUTB(lpt_outbyte, lpt_iobase);
}

-static void rayer_bitbang_set_sck_set_mosi(int sck, int mosi)
+static void rayer_bitbang_set_mosi_set_sck(int mosi, int sck)
{
lpt_outbyte &= ~(1 << pinout->sck_bit);
lpt_outbyte &= ~(1 << pinout->mosi_bit);
@@ -163,7 +163,7 @@
static const struct bitbang_spi_master bitbang_spi_master_rayer = {
.set_cs = rayer_bitbang_set_cs,
.set_sck = rayer_bitbang_set_sck,
- .set_sck_set_mosi = rayer_bitbang_set_sck_set_mosi,
+ .set_mosi_set_sck = rayer_bitbang_set_mosi_set_sck,
.set_sck_get_miso = rayer_bitbang_set_sck_get_miso,
.half_period = 0,
};

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ia84d32965e56ca563062893ebbefbbea5c35814c
Gerrit-Change-Number: 49269
Gerrit-PatchSet: 1
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-MessageType: newchange