You-Cheng Syu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/33165
Change subject: mediatek: Support GPIO based SPI CS ......................................................................
mediatek: Support GPIO based SPI CS
In some cases we might want to use GPIO based SPI CS. When using GPIO based SPI CS, we need to manually make CS low/high before/after SPI transactions.
BUG=b:132311067 TEST=Verified that b/132311067 is irreproducible now.
Change-Id: I61653fb19242b6ee6be9a45545a8b66e5c9c7cad --- M src/soc/mediatek/common/include/soc/spi_common.h M src/soc/mediatek/common/spi.c 2 files changed, 12 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/65/33165/1
diff --git a/src/soc/mediatek/common/include/soc/spi_common.h b/src/soc/mediatek/common/include/soc/spi_common.h index 162db59..2e87720 100644 --- a/src/soc/mediatek/common/include/soc/spi_common.h +++ b/src/soc/mediatek/common/include/soc/spi_common.h @@ -16,6 +16,7 @@ #ifndef MTK_COMMON_SPI_H #define MTK_COMMON_SPI_H
+#include <soc/gpio_base.h> #include <spi-generic.h>
enum { @@ -77,6 +78,7 @@ struct mtk_spi_regs *regs; int initialized; int state; + gpio_t *cs_gpio; };
extern const struct spi_ctrlr spi_ctrlr; diff --git a/src/soc/mediatek/common/spi.c b/src/soc/mediatek/common/spi.c index 71ed95a..c8aadbf 100644 --- a/src/soc/mediatek/common/spi.c +++ b/src/soc/mediatek/common/spi.c @@ -17,6 +17,7 @@ #include <assert.h> #include <console/console.h> #include <endian.h> +#include <gpio.h> #include <stdlib.h> #include <soc/pll.h> #include <soc/spi.h> @@ -87,6 +88,9 @@
clrsetbits_le32(®s->spi_pad_macro_sel_reg, SPI_PAD_SEL_MASK, pad_select); + + if (slave->cs_gpio != NULL) + gpio_output(*slave->cs_gpio, 1); }
static void mtk_spi_dump_data(const char *name, const uint8_t *data, int size) @@ -109,6 +113,9 @@ setbits_le32(®s->spi_cmd_reg, 1 << SPI_CMD_PAUSE_EN_SHIFT); mtk_slave->state = MTK_SPI_IDLE;
+ if (mtk_slave->cs_gpio != NULL) + gpio_output(*mtk_slave->cs_gpio, 0); + return 0; }
@@ -243,6 +250,9 @@ clrbits_le32(®s->spi_cmd_reg, SPI_CMD_PAUSE_EN); spi_sw_reset(regs); mtk_slave->state = MTK_SPI_IDLE; + + if (mtk_slave->cs_gpio != NULL) + gpio_output(*mtk_slave->cs_gpio, 1); }
static int spi_ctrlr_setup(const struct spi_slave *slave)