@@ -266,6 +266,14 @@ static void omap2_mcspi_set_cs(struct spi_device *spi, bool enable)
}
}
+static int omap2_get_channel_index(const struct spi_device *spi)
+{
+ if (spi->cs_gpiod)
+ return 0;
+
+ return spi->chip_select;
+}
+
static void omap2_mcspi_set_mode(struct spi_master *master)
{
struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
@@ -1062,8 +1070,8 @@ static int omap2_mcspi_setup(struct spi_device *spi)
cs = kzalloc(sizeof(*cs), GFP_KERNEL);
if (!cs)
return -ENOMEM;
- cs->base = mcspi->base + spi->chip_select * 0x14;
- cs->phys = mcspi->phys + spi->chip_select * 0x14;
+ cs->base = mcspi->base + omap2_get_channel_index(spi) * 0x14;
+ cs->phys = mcspi->phys + omap2_get_channel_index(spi) * 0x14;
cs->mode = 0;
cs->chconf0 = 0;
cs->chctrl0 = 0;
@@ -1261,7 +1269,7 @@ static int omap2_mcspi_prepare_message(struct spi_master *master,
{
struct omap2_mcspi *mcspi = spi_master_get_devdata(master);
struct omap2_mcspi_regs *ctx = &mcspi->ctx;
- struct omap2_mcspi_cs *cs;
+ struct omap2_mcspi_cs *cs, *cur_cs = msg->spi->controller_state;
/* Only a single channel can have the FORCE bit enabled
* in its chconf0 register.
@@ -1269,10 +1277,11 @@ static int omap2_mcspi_prepare_message(struct spi_master *master,
* A FORCE can remain from a last transfer having cs_change enabled
*/
list_for_each_entry(cs, &ctx->cs, node) {
- if (msg->spi->controller_state == cs)
+ if (cur_cs == cs)
continue;
- if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE)) {
+ if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE &&
+ cs->base != cur_cs->base)) {
cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
writel_relaxed(cs->chconf0,
cs->base + OMAP2_MCSPI_CHCONF0);