Skip to content

Commit 8a6553e

Browse files
Linus Walleijbroonie
authored andcommitted
spi: stm32: Switch to use GPIO descriptors for CS
This switches the STM32 SPI driver over to using GPIO descriptors for chip select. Instead of the callbacks for picking the GPIO lines using the legacy API we just let the core handle it all using descriptors. Cc: Fabien Dessenne <[email protected]> Cc: Amelie Delaunay <[email protected]> Cc: Cezary Gapinski <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 10e413f commit 8a6553e

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

drivers/spi/spi-stm32.c

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <linux/clk.h>
1010
#include <linux/delay.h>
1111
#include <linux/dmaengine.h>
12-
#include <linux/gpio.h>
1312
#include <linux/interrupt.h>
1413
#include <linux/iopoll.h>
1514
#include <linux/module.h>
@@ -973,29 +972,6 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
973972
return IRQ_HANDLED;
974973
}
975974

976-
/**
977-
* stm32_spi_setup - setup device chip select
978-
*/
979-
static int stm32_spi_setup(struct spi_device *spi_dev)
980-
{
981-
int ret = 0;
982-
983-
if (!gpio_is_valid(spi_dev->cs_gpio)) {
984-
dev_err(&spi_dev->dev, "%d is not a valid gpio\n",
985-
spi_dev->cs_gpio);
986-
return -EINVAL;
987-
}
988-
989-
dev_dbg(&spi_dev->dev, "%s: set gpio%d output %s\n", __func__,
990-
spi_dev->cs_gpio,
991-
(spi_dev->mode & SPI_CS_HIGH) ? "low" : "high");
992-
993-
ret = gpio_direction_output(spi_dev->cs_gpio,
994-
!(spi_dev->mode & SPI_CS_HIGH));
995-
996-
return ret;
997-
}
998-
999975
/**
1000976
* stm32_spi_prepare_msg - set up the controller to transfer a single message
1001977
*/
@@ -1810,7 +1786,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
18101786
struct spi_master *master;
18111787
struct stm32_spi *spi;
18121788
struct resource *res;
1813-
int i, ret;
1789+
int ret;
18141790

18151791
master = spi_alloc_master(&pdev->dev, sizeof(struct stm32_spi));
18161792
if (!master) {
@@ -1898,7 +1874,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
18981874
master->bits_per_word_mask = spi->cfg->get_bpw_mask(spi);
18991875
master->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min;
19001876
master->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max;
1901-
master->setup = stm32_spi_setup;
1877+
master->use_gpio_descriptors = true;
19021878
master->prepare_message = stm32_spi_prepare_msg;
19031879
master->transfer_one = stm32_spi_transfer_one;
19041880
master->unprepare_message = stm32_spi_unprepare_msg;
@@ -1928,29 +1904,12 @@ static int stm32_spi_probe(struct platform_device *pdev)
19281904
goto err_dma_release;
19291905
}
19301906

1931-
if (!master->cs_gpios) {
1907+
if (!master->cs_gpiods) {
19321908
dev_err(&pdev->dev, "no CS gpios available\n");
19331909
ret = -EINVAL;
19341910
goto err_dma_release;
19351911
}
19361912

1937-
for (i = 0; i < master->num_chipselect; i++) {
1938-
if (!gpio_is_valid(master->cs_gpios[i])) {
1939-
dev_err(&pdev->dev, "%i is not a valid gpio\n",
1940-
master->cs_gpios[i]);
1941-
ret = -EINVAL;
1942-
goto err_dma_release;
1943-
}
1944-
1945-
ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i],
1946-
DRIVER_NAME);
1947-
if (ret) {
1948-
dev_err(&pdev->dev, "can't get CS gpio %i\n",
1949-
master->cs_gpios[i]);
1950-
goto err_dma_release;
1951-
}
1952-
}
1953-
19541913
dev_info(&pdev->dev, "driver initialized\n");
19551914

19561915
return 0;

0 commit comments

Comments
 (0)