Skip to content

Commit 307c897

Browse files
marckleinebuddebroonie
authored andcommitted
spi: spi-imx: replace struct spi_imx_data::bitbang by pointer to struct spi_controller
There's no need to embed the struct spi_bitbang into our private data (struct spi_imx_data), the spi core is flexible enough, so that we only need a pointer to the allocated struct spi_controller. This is also a preparation patch to add PIO based polling support to the driver. Co-developed-by: David Jander <[email protected]> Signed-off-by: David Jander <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 63cd96b commit 307c897

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

drivers/spi/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ config SPI_IMG_SPFI
414414
config SPI_IMX
415415
tristate "Freescale i.MX SPI controllers"
416416
depends on ARCH_MXC || COMPILE_TEST
417-
select SPI_BITBANG
418417
help
419418
This enables support for the Freescale i.MX SPI controllers.
420419

drivers/spi/spi-imx.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/pm_runtime.h>
1919
#include <linux/slab.h>
2020
#include <linux/spi/spi.h>
21-
#include <linux/spi/spi_bitbang.h>
2221
#include <linux/types.h>
2322
#include <linux/of.h>
2423
#include <linux/of_device.h>
@@ -86,7 +85,7 @@ struct spi_imx_devtype_data {
8685
};
8786

8887
struct spi_imx_data {
89-
struct spi_bitbang bitbang;
88+
struct spi_controller *controller;
9089
struct device *dev;
9190

9291
struct completion xfer_done;
@@ -580,7 +579,7 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
580579
* the SPI communication as the device on the other end would consider
581580
* the change of SCLK polarity as a clock tick already.
582581
*
583-
* Because spi_imx->spi_bus_clk is only set in bitbang prepare_message
582+
* Because spi_imx->spi_bus_clk is only set in prepare_message
584583
* callback, iterate over all the transfers in spi_message, find the
585584
* one with lowest bus frequency, and use that bus frequency for the
586585
* delay calculation. In case all transfers have speed_hz == 0, then
@@ -1261,7 +1260,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
12611260
spi_imx->dynamic_burst = 0;
12621261
}
12631262

1264-
if (spi_imx_can_dma(spi_imx->bitbang.master, spi, t))
1263+
if (spi_imx_can_dma(spi_imx->controller, spi, t))
12651264
spi_imx->usedma = true;
12661265
else
12671266
spi_imx->usedma = false;
@@ -1282,7 +1281,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
12821281

12831282
static void spi_imx_sdma_exit(struct spi_imx_data *spi_imx)
12841283
{
1285-
struct spi_controller *controller = spi_imx->bitbang.master;
1284+
struct spi_controller *controller = spi_imx->controller;
12861285

12871286
if (controller->dma_rx) {
12881287
dma_release_channel(controller->dma_rx);
@@ -1324,7 +1323,7 @@ static int spi_imx_sdma_init(struct device *dev, struct spi_imx_data *spi_imx,
13241323
init_completion(&spi_imx->dma_tx_completion);
13251324
controller->can_dma = spi_imx_can_dma;
13261325
controller->max_dma_len = MAX_SDMA_BD_BYTES;
1327-
spi_imx->bitbang.master->flags = SPI_CONTROLLER_MUST_RX |
1326+
spi_imx->controller->flags = SPI_CONTROLLER_MUST_RX |
13281327
SPI_CONTROLLER_MUST_TX;
13291328

13301329
return 0;
@@ -1367,7 +1366,7 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
13671366
struct dma_async_tx_descriptor *desc_tx, *desc_rx;
13681367
unsigned long transfer_timeout;
13691368
unsigned long timeout;
1370-
struct spi_controller *controller = spi_imx->bitbang.master;
1369+
struct spi_controller *controller = spi_imx->controller;
13711370
struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg;
13721371
struct scatterlist *last_sg = sg_last(rx->sgl, rx->nents);
13731372
unsigned int bytes_per_word, i;
@@ -1450,7 +1449,7 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
14501449
return -ETIMEDOUT;
14511450
}
14521451

1453-
return transfer->len;
1452+
return 0;
14541453
/* fallback to pio */
14551454
dma_failure_no_start:
14561455
transfer->error |= SPI_TRANS_FAIL_NO_START;
@@ -1486,14 +1485,14 @@ static int spi_imx_pio_transfer(struct spi_device *spi,
14861485
return -ETIMEDOUT;
14871486
}
14881487

1489-
return transfer->len;
1488+
return 0;
14901489
}
14911490

14921491
static int spi_imx_pio_transfer_slave(struct spi_device *spi,
14931492
struct spi_transfer *transfer)
14941493
{
14951494
struct spi_imx_data *spi_imx = spi_controller_get_devdata(spi->controller);
1496-
int ret = transfer->len;
1495+
int ret = 0;
14971496

14981497
if (is_imx53_ecspi(spi_imx) &&
14991498
transfer->len > MX53_MAX_TRANSFER_BYTES) {
@@ -1533,11 +1532,13 @@ static int spi_imx_pio_transfer_slave(struct spi_device *spi,
15331532
return ret;
15341533
}
15351534

1536-
static int spi_imx_transfer(struct spi_device *spi,
1535+
static int spi_imx_transfer_one(struct spi_controller *controller,
1536+
struct spi_device *spi,
15371537
struct spi_transfer *transfer)
15381538
{
15391539
struct spi_imx_data *spi_imx = spi_controller_get_devdata(spi->controller);
15401540

1541+
spi_imx_setupxfer(spi, transfer);
15411542
transfer->effective_speed_hz = spi_imx->spi_bus_clk;
15421543

15431544
/* flush rxfifo before transfer */
@@ -1642,7 +1643,7 @@ static int spi_imx_probe(struct platform_device *pdev)
16421643
controller->use_gpio_descriptors = true;
16431644

16441645
spi_imx = spi_controller_get_devdata(controller);
1645-
spi_imx->bitbang.master = controller;
1646+
spi_imx->controller = controller;
16461647
spi_imx->dev = &pdev->dev;
16471648
spi_imx->slave_mode = slave_mode;
16481649

@@ -1659,20 +1660,20 @@ static int spi_imx_probe(struct platform_device *pdev)
16591660
else
16601661
controller->num_chipselect = 3;
16611662

1662-
spi_imx->bitbang.setup_transfer = spi_imx_setupxfer;
1663-
spi_imx->bitbang.txrx_bufs = spi_imx_transfer;
1664-
spi_imx->bitbang.master->setup = spi_imx_setup;
1665-
spi_imx->bitbang.master->cleanup = spi_imx_cleanup;
1666-
spi_imx->bitbang.master->prepare_message = spi_imx_prepare_message;
1667-
spi_imx->bitbang.master->unprepare_message = spi_imx_unprepare_message;
1668-
spi_imx->bitbang.master->slave_abort = spi_imx_slave_abort;
1669-
spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
1663+
spi_imx->controller->transfer_one = spi_imx_transfer_one;
1664+
spi_imx->controller->setup = spi_imx_setup;
1665+
spi_imx->controller->cleanup = spi_imx_cleanup;
1666+
spi_imx->controller->prepare_message = spi_imx_prepare_message;
1667+
spi_imx->controller->unprepare_message = spi_imx_unprepare_message;
1668+
spi_imx->controller->slave_abort = spi_imx_slave_abort;
1669+
spi_imx->controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
1670+
16701671
if (is_imx35_cspi(spi_imx) || is_imx51_ecspi(spi_imx) ||
16711672
is_imx53_ecspi(spi_imx))
1672-
spi_imx->bitbang.master->mode_bits |= SPI_LOOP | SPI_READY;
1673+
spi_imx->controller->mode_bits |= SPI_LOOP | SPI_READY;
16731674

16741675
if (is_imx51_ecspi(spi_imx) || is_imx53_ecspi(spi_imx))
1675-
spi_imx->bitbang.master->mode_bits |= SPI_RX_CPHA_FLIP;
1676+
spi_imx->controller->mode_bits |= SPI_RX_CPHA_FLIP;
16761677

16771678
if (is_imx51_ecspi(spi_imx) &&
16781679
device_property_read_u32(&pdev->dev, "cs-gpios", NULL))
@@ -1681,7 +1682,7 @@ static int spi_imx_probe(struct platform_device *pdev)
16811682
* setting the burst length to the word size. This is
16821683
* considerably faster than manually controlling the CS.
16831684
*/
1684-
spi_imx->bitbang.master->mode_bits |= SPI_CS_WORD;
1685+
spi_imx->controller->mode_bits |= SPI_CS_WORD;
16851686

16861687
spi_imx->spi_drctl = spi_drctl;
16871688

@@ -1754,18 +1755,18 @@ static int spi_imx_probe(struct platform_device *pdev)
17541755
spi_imx->devtype_data->intctrl(spi_imx, 0);
17551756

17561757
controller->dev.of_node = pdev->dev.of_node;
1757-
ret = spi_bitbang_start(&spi_imx->bitbang);
1758+
ret = spi_register_controller(controller);
17581759
if (ret) {
1759-
dev_err_probe(&pdev->dev, ret, "bitbang start failed\n");
1760-
goto out_bitbang_start;
1760+
dev_err_probe(&pdev->dev, ret, "register controller failed\n");
1761+
goto out_register_controller;
17611762
}
17621763

17631764
pm_runtime_mark_last_busy(spi_imx->dev);
17641765
pm_runtime_put_autosuspend(spi_imx->dev);
17651766

17661767
return ret;
17671768

1768-
out_bitbang_start:
1769+
out_register_controller:
17691770
if (spi_imx->devtype_data->has_dmamode)
17701771
spi_imx_sdma_exit(spi_imx);
17711772
out_runtime_pm_put:
@@ -1788,7 +1789,7 @@ static int spi_imx_remove(struct platform_device *pdev)
17881789
struct spi_imx_data *spi_imx = spi_controller_get_devdata(controller);
17891790
int ret;
17901791

1791-
spi_bitbang_stop(&spi_imx->bitbang);
1792+
spi_unregister_controller(controller);
17921793

17931794
ret = pm_runtime_resume_and_get(spi_imx->dev);
17941795
if (ret < 0) {
@@ -1803,7 +1804,6 @@ static int spi_imx_remove(struct platform_device *pdev)
18031804
pm_runtime_disable(spi_imx->dev);
18041805

18051806
spi_imx_sdma_exit(spi_imx);
1806-
spi_controller_put(controller);
18071807

18081808
return 0;
18091809
}

0 commit comments

Comments
 (0)