Commit 585d18f7 authored by Gregory CLEMENT's avatar Gregory CLEMENT Committed by Mark Brown

spi: atmel: Configure GPIO per CS instead of by controller

Instead of setting up the GPIO configuration for the whole controller,
do it at CS level. It will allow to mix internal CS and GPIO CS, which
is not possible with the current implementation.
Signed-off-by: default avatarGregory CLEMENT <gregory.clement@bootlin.com>
Link: https://lore.kernel.org/r/20191017141846.7523-4-gregory.clement@bootlin.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7cbb16b2
...@@ -275,7 +275,6 @@ struct atmel_spi { ...@@ -275,7 +275,6 @@ struct atmel_spi {
bool use_dma; bool use_dma;
bool use_pdc; bool use_pdc;
bool use_cs_gpios;
bool keep_cs; bool keep_cs;
bool cs_active; bool cs_active;
...@@ -348,7 +347,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) ...@@ -348,7 +347,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
} }
mr = spi_readl(as, MR); mr = spi_readl(as, MR);
if (as->use_cs_gpios) if (asd->npcs_pin)
gpiod_set_value(asd->npcs_pin, 1); gpiod_set_value(asd->npcs_pin, 1);
} else { } else {
u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0; u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
...@@ -365,7 +364,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) ...@@ -365,7 +364,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
mr = spi_readl(as, MR); mr = spi_readl(as, MR);
mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr); mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);
if (as->use_cs_gpios && spi->chip_select != 0) if (asd->npcs_pin && spi->chip_select != 0)
gpiod_set_value(asd->npcs_pin, 1); gpiod_set_value(asd->npcs_pin, 1);
spi_writel(as, MR, mr); spi_writel(as, MR, mr);
} }
...@@ -389,7 +388,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi) ...@@ -389,7 +388,7 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr); dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr);
if (!as->use_cs_gpios) if (!asd->npcs_pin)
spi_writel(as, CR, SPI_BIT(LASTXFER)); spi_writel(as, CR, SPI_BIT(LASTXFER));
else if (atmel_spi_is_v2(as) || spi->chip_select != 0) else if (atmel_spi_is_v2(as) || spi->chip_select != 0)
gpiod_set_value(asd->npcs_pin, 0); gpiod_set_value(asd->npcs_pin, 0);
...@@ -1176,7 +1175,7 @@ static int atmel_spi_setup(struct spi_device *spi) ...@@ -1176,7 +1175,7 @@ static int atmel_spi_setup(struct spi_device *spi)
as = spi_master_get_devdata(spi->master); as = spi_master_get_devdata(spi->master);
/* see notes above re chipselect */ /* see notes above re chipselect */
if (!as->use_cs_gpios && (spi->mode & SPI_CS_HIGH)) { if (!spi->cs_gpiod && (spi->mode & SPI_CS_HIGH)) {
dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n"); dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n");
return -EINVAL; return -EINVAL;
} }
...@@ -1186,9 +1185,9 @@ static int atmel_spi_setup(struct spi_device *spi) ...@@ -1186,9 +1185,9 @@ static int atmel_spi_setup(struct spi_device *spi)
csr |= SPI_BIT(CPOL); csr |= SPI_BIT(CPOL);
if (!(spi->mode & SPI_CPHA)) if (!(spi->mode & SPI_CPHA))
csr |= SPI_BIT(NCPHA); csr |= SPI_BIT(NCPHA);
if (!as->use_cs_gpios)
csr |= SPI_BIT(CSAAT);
if (!spi->cs_gpiod)
csr |= SPI_BIT(CSAAT);
csr |= SPI_BF(DLYBS, 0); csr |= SPI_BF(DLYBS, 0);
word_delay_csr = atmel_word_delay_csr(spi, as); word_delay_csr = atmel_word_delay_csr(spi, as);
...@@ -1206,20 +1205,8 @@ static int atmel_spi_setup(struct spi_device *spi) ...@@ -1206,20 +1205,8 @@ static int atmel_spi_setup(struct spi_device *spi)
if (!asd) if (!asd)
return -ENOMEM; return -ENOMEM;
/* if (spi->cs_gpiod)
* If use_cs_gpios is true this means that we have "cs-gpios"
* defined in the device tree node so we should have
* gotten the GPIO lines from the device tree inside the
* SPI core. Warn if this is not the case but continue since
* CS GPIOs are after all optional.
*/
if (as->use_cs_gpios) {
if (!spi->cs_gpiod) {
dev_err(&spi->dev,
"host claims to use CS GPIOs but no CS found in DT by the SPI core\n");
}
asd->npcs_pin = spi->cs_gpiod; asd->npcs_pin = spi->cs_gpiod;
}
spi->controller_state = asd; spi->controller_state = asd;
} }
...@@ -1551,13 +1538,10 @@ static int atmel_spi_probe(struct platform_device *pdev) ...@@ -1551,13 +1538,10 @@ static int atmel_spi_probe(struct platform_device *pdev)
* discovered by the SPI core when registering the SPI master * discovered by the SPI core when registering the SPI master
* and assigned to each SPI device. * and assigned to each SPI device.
*/ */
as->use_cs_gpios = true;
if (atmel_spi_is_v2(as) && if (atmel_spi_is_v2(as) &&
pdev->dev.of_node && pdev->dev.of_node &&
!of_get_property(pdev->dev.of_node, "cs-gpios", NULL)) { !of_get_property(pdev->dev.of_node, "cs-gpios", NULL))
as->use_cs_gpios = false;
master->num_chipselect = 4; master->num_chipselect = 4;
}
as->use_dma = false; as->use_dma = false;
as->use_pdc = false; as->use_pdc = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment