[U-Boot] [PATCH v4 05/16] spi: Add support for dual and quad mode

Mugunthan V N
2015-12-15T07:52:02Z

spi bus can support dual and quad wire data transfers for tx and
rx. So defining dual and quad modes for both tx and rx. Also add
support to parse bus width used for spi tx and rx transfers.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
---

Changes from v3->v4
* used op_mode_{t/r}x to hold flash tx/rx modes.

This has been tested on am437x-sk evm logs [1] and pushed a
branch for others to test [2]

[1] - http://pastebin.ubuntu.com/14024895/
[2] - git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git dm-qspi-v4

---
drivers/spi/spi-uclass.c | 35 +++++++++++++++++++++++++++++++++++
include/spi.h | 8 ++++++++
2 files changed, 43 insertions(+)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index e0f6b25..3c7ca78 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -157,6 +157,8 @@ static int spi_child_pre_probe(struct udevice *dev)

slave->max_hz = plat->max_hz;
slave->mode = plat->mode;
+ slave->op_mode_tx = plat->op_mode_tx;
+ slave->op_mode_rx = plat->op_mode_rx;

return 0;
}
@@ -369,6 +371,7 @@ int spi_slave_ofdata_to_platdata(const void *blob, int node,
struct dm_spi_slave_platdata *plat)
{
int mode = 0;
+ int value;

plat->cs = fdtdec_get_int(blob, node, "reg", -1);
plat->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", 0);
@@ -382,8 +385,40 @@ int spi_slave_ofdata_to_platdata(const void *blob, int node,
mode |= SPI_3WIRE;
if (fdtdec_get_bool(blob, node, "spi-half-duplex"))
mode |= SPI_PREAMBLE;
+
plat->mode = mode;

+ /* Device DUAL/QUAD mode */
+ value = fdtdec_get_uint(blob, node, "spi-tx-bus-width", 1);
+ switch (value) {
+ case 1:
+ break;
+ case 2:
+ plat->op_mode_tx |= SPI_OPM_TX_DUAL;
+ break;
+ case 4:
+ plat->op_mode_tx |= SPI_OPM_TX_QUAD;
+ break;
+ default:
+ error("spi-tx-bus-width %d not supported\n", value);
+ break;
+ }
+
+ value = fdtdec_get_uint(blob, node, "spi-rx-bus-width", 1);
+ switch (value) {
+ case 1:
+ break;
+ case 2:
+ plat->op_mode_rx |= SPI_OPM_RX_DUAL;
+ break;
+ case 4:
+ plat->op_mode_rx |= SPI_OPM_RX_QUAD;
+ break;
+ default:
+ error("spi-rx-bus-width %d not supported\n", value);
+ break;
+ }
+
return 0;
}

diff --git a/include/spi.h b/include/spi.h
index b4d2723..090ae1f 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -35,6 +35,8 @@
/* SPI TX operation modes */
#define SPI_OPM_TX_QPP (1 << 0)
#define SPI_OPM_TX_BP (1 << 1)
+#define SPI_OPM_TX_DUAL (1 << 2) /* transmit with 2 wires */
+#define SPI_OPM_TX_QUAD (1 << 3) /* transmit with 4 wires */

/* SPI RX operation modes */
#define SPI_OPM_RX_AS (1 << 0)
@@ -46,6 +48,8 @@
#define SPI_OPM_RX_EXTN (SPI_OPM_RX_AS | SPI_OPM_RX_AF | SPI_OPM_RX_DOUT | \
SPI_OPM_RX_DIO | SPI_OPM_RX_QOF | \
SPI_OPM_RX_QIOF)
+#define SPI_OPM_RX_DUAL (1 << 6) /* receive with 2 wires */
+#define SPI_OPM_RX_QUAD (1 << 7) /* receive with 4 wires */

/* SPI bus connection options - see enum spi_dual_flash */
#define SPI_CONN_DUAL_SHARED (1 << 0)
@@ -75,11 +79,15 @@ struct dm_spi_bus {
* @cs: Chip select number (0..n-1)
* @max_hz: Maximum bus speed that this slave can tolerate
* @mode: SPI mode to use for this device (see SPI mode flags)
+ * @op_mode_rx: SPI RX operation mode.
+ * @op_mode_tx: SPI TX operation mode.
*/
struct dm_spi_slave_platdata {
unsigned int cs;
uint max_hz;
uint mode;
+ u8 op_mode_rx;
+ u8 op_mode_tx;
};

#endif /* CONFIG_DM_SPI */
--
2.7.0.rc0.20.g4b9ab0e