Commit 8db79547 authored by Linus Walleij's avatar Linus Walleij Committed by Mark Brown

spi: ath79: Convert to use CS GPIO descriptors

This converts the ATH79 SPI master driver to use GPIO descriptors
for chip select handling.

The ATH79 driver was requesting the GPIO and driving it from the
bitbang .chipselect callback. Do not request it anymore as the SPI
core will request it, remove the line inversion semantics for the
GPIO case (handled by gpiolib) and let the SPI core deal with
requesting the GPIO line from the device tree node of the controller.

This driver can be instantiated from a board file (no device tree)
but the board files only use native CS (no GPIO lines) so we should
be fine just letting the SPI core grab the GPIO from the device.

The fact that the driver is actively driving the GPIO in the
ath79_spi_chipselect() callback is confusing since the host does
not set SPI_MASTER_GPIO_SS so this should not ever get called when
using GPIO CS. I put in a comment about this.

Cc: Felix Fietkau <nbd@nbd.name>
Cc: Alban Bedel <albeu@free.fr>
Cc: Linuxarm <linuxarm@huawei.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent f3186dd8
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h> #include <linux/spi/spi_bitbang.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -78,9 +78,16 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active) ...@@ -78,9 +78,16 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active)
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
} }
if (gpio_is_valid(spi->cs_gpio)) { if (spi->cs_gpiod) {
/* SPI is normally active-low */ /*
gpio_set_value_cansleep(spi->cs_gpio, cs_high); * SPI chipselect is normally active-low, but
* inversion semantics are handled by gpiolib.
*
* FIXME: is this ever used? The driver doesn't
* set SPI_MASTER_GPIO_SS so this callback should not
* get called if a CS GPIO is found by the SPI core.
*/
gpiod_set_value_cansleep(spi->cs_gpiod, is_active);
} else { } else {
u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
...@@ -118,21 +125,8 @@ static void ath79_spi_disable(struct ath79_spi *sp) ...@@ -118,21 +125,8 @@ static void ath79_spi_disable(struct ath79_spi *sp)
static int ath79_spi_setup_cs(struct spi_device *spi) static int ath79_spi_setup_cs(struct spi_device *spi)
{ {
struct ath79_spi *sp = ath79_spidev_to_sp(spi); struct ath79_spi *sp = ath79_spidev_to_sp(spi);
int status;
status = 0; if (!spi->cs_gpiod) {
if (gpio_is_valid(spi->cs_gpio)) {
unsigned long flags;
flags = GPIOF_DIR_OUT;
if (spi->mode & SPI_CS_HIGH)
flags |= GPIOF_INIT_LOW;
else
flags |= GPIOF_INIT_HIGH;
status = gpio_request_one(spi->cs_gpio, flags,
dev_name(&spi->dev));
} else {
u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
if (spi->mode & SPI_CS_HIGH) if (spi->mode & SPI_CS_HIGH)
...@@ -143,13 +137,7 @@ static int ath79_spi_setup_cs(struct spi_device *spi) ...@@ -143,13 +137,7 @@ static int ath79_spi_setup_cs(struct spi_device *spi)
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
} }
return status; return 0;
}
static void ath79_spi_cleanup_cs(struct spi_device *spi)
{
if (gpio_is_valid(spi->cs_gpio))
gpio_free(spi->cs_gpio);
} }
static int ath79_spi_setup(struct spi_device *spi) static int ath79_spi_setup(struct spi_device *spi)
...@@ -163,15 +151,12 @@ static int ath79_spi_setup(struct spi_device *spi) ...@@ -163,15 +151,12 @@ static int ath79_spi_setup(struct spi_device *spi)
} }
status = spi_bitbang_setup(spi); status = spi_bitbang_setup(spi);
if (status && !spi->controller_state)
ath79_spi_cleanup_cs(spi);
return status; return status;
} }
static void ath79_spi_cleanup(struct spi_device *spi) static void ath79_spi_cleanup(struct spi_device *spi)
{ {
ath79_spi_cleanup_cs(spi);
spi_bitbang_cleanup(spi); spi_bitbang_cleanup(spi);
} }
...@@ -225,6 +210,7 @@ static int ath79_spi_probe(struct platform_device *pdev) ...@@ -225,6 +210,7 @@ static int ath79_spi_probe(struct platform_device *pdev)
pdata = dev_get_platdata(&pdev->dev); pdata = dev_get_platdata(&pdev->dev);
master->use_gpio_descriptors = true;
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
master->setup = ath79_spi_setup; master->setup = ath79_spi_setup;
master->cleanup = ath79_spi_cleanup; master->cleanup = ath79_spi_cleanup;
......
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