Angel Pons has uploaded this change for review.

View Change

bitbang_spi: Drop `set_mosi` and `get_miso` operations

The bitbang_spi code always sets SCK before doing either of these two
operations. Make `set_sck_set_mosi` and `set_sck_get_miso` mandatory and
implement them everywhere, and remove `set_mosi` and `get_miso`.

Change-Id: Id6b1edb1e01330feffc5f1ed2ca2c2ebc4fb3b66
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, 36 insertions(+), 90 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/68/49268/1
diff --git a/bitbang_spi.c b/bitbang_spi.c
index c402119..1b0692c 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -46,22 +46,12 @@

static void bitbang_spi_set_sck_set_mosi(const struct bitbang_spi_master * const master, int sck, int mosi)
{
- if (master->set_sck_set_mosi) {
- master->set_sck_set_mosi(sck, mosi);
- return;
- }
-
- master->set_sck(sck);
- master->set_mosi(mosi);
+ master->set_sck_set_mosi(sck, mosi);
}

static int bitbang_spi_set_sck_get_miso(const struct bitbang_spi_master * const master, int sck)
{
- if (master->set_sck_get_miso)
- return master->set_sck_get_miso(sck);
-
- master->set_sck(sck);
- return master->get_miso();
+ return master->set_sck_get_miso(sck);
}

static uint8_t bitbang_spi_read_byte(const struct bitbang_spi_master *master)
@@ -147,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_mosi || !master->get_miso ||
+ !master->set_sck || !master->set_sck_set_mosi || !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"
diff --git a/developerbox_spi.c b/developerbox_spi.c
index 4ff2fb6..7011c9a 100644
--- a/developerbox_spi.c
+++ b/developerbox_spi.c
@@ -104,28 +104,23 @@
cp210x_gpio_set(val << DEVELOPERBOX_SPI_SCK, 1 << DEVELOPERBOX_SPI_SCK);
}

-static void cp210x_bitbang_set_mosi(int val)
-{
- cp210x_gpio_set(val << DEVELOPERBOX_SPI_MOSI, 1 << DEVELOPERBOX_SPI_MOSI);
-}
-
-static int cp210x_bitbang_get_miso(void)
-{
- return !!(cp210x_gpio_get() & (1 << DEVELOPERBOX_SPI_MISO));
-}
-
static void cp210x_bitbang_set_sck_set_mosi(int sck, int mosi)
{
cp210x_gpio_set(sck << DEVELOPERBOX_SPI_SCK | mosi << DEVELOPERBOX_SPI_MOSI,
1 << DEVELOPERBOX_SPI_SCK | 1 << DEVELOPERBOX_SPI_MOSI);
}

+static int cp210x_bitbang_set_sck_get_miso(int sck)
+{
+ cp210x_bitbang_set_sck(sck);
+ return !!(cp210x_gpio_get() & (1 << DEVELOPERBOX_SPI_MISO));
+}
+
static const struct bitbang_spi_master bitbang_spi_master_cp210x = {
.set_cs = cp210x_bitbang_set_cs,
.set_sck = cp210x_bitbang_set_sck,
- .set_mosi = cp210x_bitbang_set_mosi,
- .get_miso = cp210x_bitbang_get_miso,
.set_sck_set_mosi = cp210x_bitbang_set_sck_set_mosi,
+ .set_sck_get_miso = cp210x_bitbang_set_sck_get_miso,
};

static int developerbox_spi_shutdown(void *data)
diff --git a/mcp6x_spi.c b/mcp6x_spi.c
index 4f82095..a0e51fc 100644
--- a/mcp6x_spi.c
+++ b/mcp6x_spi.c
@@ -74,19 +74,6 @@
mmio_writeb(mcp_gpiostate, mcp6x_spibar + 0x530);
}

-static void mcp6x_bitbang_set_mosi(int val)
-{
- mcp_gpiostate &= ~(1 << MCP6X_SPI_MOSI);
- mcp_gpiostate |= (val << MCP6X_SPI_MOSI);
- mmio_writeb(mcp_gpiostate, mcp6x_spibar + 0x530);
-}
-
-static int mcp6x_bitbang_get_miso(void)
-{
- mcp_gpiostate = mmio_readb(mcp6x_spibar + 0x530);
- return (mcp_gpiostate >> MCP6X_SPI_MISO) & 0x1;
-}
-
static void mcp6x_bitbang_set_sck_set_mosi(int sck, int mosi)
{
mcp_gpiostate &= ~(1 << MCP6X_SPI_SCK);
@@ -108,8 +95,6 @@
static const struct bitbang_spi_master bitbang_spi_master_mcp6x = {
.set_cs = mcp6x_bitbang_set_cs,
.set_sck = mcp6x_bitbang_set_sck,
- .set_mosi = mcp6x_bitbang_set_mosi,
- .get_miso = mcp6x_bitbang_get_miso,
.set_sck_set_mosi = mcp6x_bitbang_set_sck_set_mosi,
.set_sck_get_miso = mcp6x_bitbang_set_sck_get_miso,
.request_bus = mcp6x_request_spibus,
diff --git a/nicintel_spi.c b/nicintel_spi.c
index c068e75..f16c2cd 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -148,25 +148,6 @@
pci_mmio_writel(tmp, nicintel_spibar + FLA);
}

-static void nicintel_bitbang_set_mosi(int val)
-{
- uint32_t tmp;
-
- tmp = pci_mmio_readl(nicintel_spibar + FLA);
- tmp &= ~BIT(FL_SI);
- tmp |= (val << FL_SI);
- pci_mmio_writel(tmp, nicintel_spibar + FLA);
-}
-
-static int nicintel_bitbang_get_miso(void)
-{
- uint32_t tmp;
-
- tmp = pci_mmio_readl(nicintel_spibar + FLA);
- tmp = (tmp >> FL_SO) & 0x1;
- return tmp;
-}
-
static void nicintel_bitbang_set_sck_set_mosi(int sck, int mosi)
{
uint32_t tmp;
@@ -193,8 +174,6 @@
static const struct bitbang_spi_master bitbang_spi_master_nicintel = {
.set_cs = nicintel_bitbang_set_cs,
.set_sck = nicintel_bitbang_set_sck,
- .set_mosi = nicintel_bitbang_set_mosi,
- .get_miso = nicintel_bitbang_get_miso,
.set_sck_set_mosi = nicintel_bitbang_set_sck_set_mosi,
.set_sck_get_miso = nicintel_bitbang_set_sck_get_miso,
.request_bus = nicintel_request_spibus,
diff --git a/ogp_spi.c b/ogp_spi.c
index e603edb..c2a4d18 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -69,13 +69,16 @@
pci_mmio_writel(val, ogp_spibar + ogp_reg_sck);
}

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

-static int ogp_bitbang_get_miso(void)
+static int ogp_bitbang_set_sck_get_miso(int sck)
{
+ ogp_bitbang_set_sck(sck);
+
uint32_t tmp;

tmp = pci_mmio_readl(ogp_spibar + ogp_reg_siso);
@@ -85,8 +88,8 @@
static const struct bitbang_spi_master bitbang_spi_master_ogp = {
.set_cs = ogp_bitbang_set_cs,
.set_sck = ogp_bitbang_set_sck,
- .set_mosi = ogp_bitbang_set_mosi,
- .get_miso = ogp_bitbang_get_miso,
+ .set_sck_set_mosi = ogp_bitbang_set_sck_set_mosi,
+ .set_sck_get_miso = ogp_bitbang_set_sck_get_miso,
.request_bus = ogp_request_spibus,
.release_bus = ogp_release_spibus,
.half_period = 0,
diff --git a/pony_spi.c b/pony_spi.c
index ed9d326..37d0f08 100644
--- a/pony_spi.c
+++ b/pony_spi.c
@@ -72,16 +72,20 @@
sp_set_pin(PIN_RTS, val);
}

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

- sp_set_pin(PIN_DTR, val);
+ if (pony_negate_mosi)
+ mosi ^= 1;
+
+ sp_set_pin(PIN_DTR, mosi);
}

-static int pony_bitbang_get_miso(void)
+static int pony_bitbang_set_sck_get_miso(int sck)
{
+ pony_bitbang_set_sck(sck);
+
int tmp = sp_get_pin(PIN_CTS);

if (pony_negate_miso)
@@ -93,8 +97,8 @@
static const struct bitbang_spi_master bitbang_spi_master_pony = {
.set_cs = pony_bitbang_set_cs,
.set_sck = pony_bitbang_set_sck,
- .set_mosi = pony_bitbang_set_mosi,
- .get_miso = pony_bitbang_get_miso,
+ .set_sck_set_mosi = pony_bitbang_set_sck_set_mosi,
+ .set_sck_get_miso = pony_bitbang_set_sck_get_miso,
.half_period = 0,
};

@@ -193,8 +197,7 @@
* Detect if there is a compatible hardware programmer connected.
*/
pony_bitbang_set_cs(1);
- pony_bitbang_set_sck(1);
- pony_bitbang_set_mosi(1);
+ pony_bitbang_set_sck_set_mosi(1, 1);

switch (type) {
case TYPE_AJAWE:
diff --git a/programmer.h b/programmer.h
index d66d239..51e7e88 100644
--- a/programmer.h
+++ b/programmer.h
@@ -184,13 +184,10 @@
/* 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_mosi) (int val);
- int (*get_miso) (void);
- void (*request_bus) (void);
- void (*release_bus) (void);
- /* optional functions to optimize xfers */
void (*set_sck_set_mosi) (int sck, int mosi);
int (*set_sck_get_miso) (int sck);
+ void (*request_bus) (void);
+ void (*release_bus) (void);
/* Length of half a clock period in usecs. */
unsigned int half_period;
};
diff --git a/rayer_spi.c b/rayer_spi.c
index 8c7f53e..1649f1b 100644
--- a/rayer_spi.c
+++ b/rayer_spi.c
@@ -140,13 +140,6 @@
OUTB(lpt_outbyte, lpt_iobase);
}

-static void rayer_bitbang_set_mosi(int val)
-{
- lpt_outbyte &= ~(1 << pinout->mosi_bit);
- lpt_outbyte |= (val << pinout->mosi_bit);
- OUTB(lpt_outbyte, lpt_iobase);
-}
-
static void rayer_bitbang_set_sck_set_mosi(int sck, int mosi)
{
lpt_outbyte &= ~(1 << pinout->sck_bit);
@@ -156,8 +149,10 @@
OUTB(lpt_outbyte, lpt_iobase);
}

-static int rayer_bitbang_get_miso(void)
+static int rayer_bitbang_set_sck_get_miso(int sck)
{
+ rayer_bitbang_set_sck(sck);
+
uint8_t tmp;

tmp = INB(lpt_iobase + 1) ^ 0x80; // bit.7 inverted
@@ -168,9 +163,8 @@
static const struct bitbang_spi_master bitbang_spi_master_rayer = {
.set_cs = rayer_bitbang_set_cs,
.set_sck = rayer_bitbang_set_sck,
- .set_mosi = rayer_bitbang_set_mosi,
.set_sck_set_mosi = rayer_bitbang_set_sck_set_mosi,
- .get_miso = rayer_bitbang_get_miso,
+ .set_sck_get_miso = rayer_bitbang_set_sck_get_miso,
.half_period = 0,
};


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

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