Skip to content

Commit e79e7c2

Browse files
maquefelarndb
authored andcommitted
spi: ep93xx: add DT support for Cirrus EP93xx
- add OF ID match table - add device tree DMA request, so we can probe defer, in case DMA is not ready yet - drop DMA platform code Signed-off-by: Nikita Shubin <[email protected]> Tested-by: Alexander Sverdlin <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Mark Brown <[email protected]> Acked-by: Alexander Sverdlin <[email protected]> Acked-by: Vinod Koul <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent cb02917 commit e79e7c2

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

drivers/spi/spi-ep93xx.c

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
#include <linux/err.h>
1919
#include <linux/delay.h>
2020
#include <linux/device.h>
21+
#include <linux/dma-direction.h>
22+
#include <linux/dma-mapping.h>
2123
#include <linux/dmaengine.h>
2224
#include <linux/bitops.h>
2325
#include <linux/interrupt.h>
2426
#include <linux/module.h>
27+
#include <linux/property.h>
2528
#include <linux/platform_device.h>
2629
#include <linux/sched.h>
2730
#include <linux/scatterlist.h>
2831
#include <linux/spi/spi.h>
2932

30-
#include <linux/platform_data/dma-ep93xx.h>
31-
#include <linux/platform_data/spi-ep93xx.h>
32-
3333
#define SSPCR0 0x0000
3434
#define SSPCR0_SPO BIT(6)
3535
#define SSPCR0_SPH BIT(7)
@@ -92,8 +92,6 @@ struct ep93xx_spi {
9292
size_t fifo_level;
9393
struct dma_chan *dma_rx;
9494
struct dma_chan *dma_tx;
95-
struct ep93xx_dma_data dma_rx_data;
96-
struct ep93xx_dma_data dma_tx_data;
9795
struct sg_table rx_sgt;
9896
struct sg_table tx_sgt;
9997
void *zeropage;
@@ -575,46 +573,23 @@ static int ep93xx_spi_unprepare_hardware(struct spi_controller *host)
575573
return 0;
576574
}
577575

578-
static bool ep93xx_spi_dma_filter(struct dma_chan *chan, void *filter_param)
576+
static int ep93xx_spi_setup_dma(struct device *dev, struct ep93xx_spi *espi)
579577
{
580-
if (ep93xx_dma_chan_is_m2p(chan))
581-
return false;
582-
583-
chan->private = filter_param;
584-
return true;
585-
}
586-
587-
static int ep93xx_spi_setup_dma(struct ep93xx_spi *espi)
588-
{
589-
dma_cap_mask_t mask;
590578
int ret;
591579

592580
espi->zeropage = (void *)get_zeroed_page(GFP_KERNEL);
593581
if (!espi->zeropage)
594582
return -ENOMEM;
595583

596-
dma_cap_zero(mask);
597-
dma_cap_set(DMA_SLAVE, mask);
598-
599-
espi->dma_rx_data.port = EP93XX_DMA_SSP;
600-
espi->dma_rx_data.direction = DMA_DEV_TO_MEM;
601-
espi->dma_rx_data.name = "ep93xx-spi-rx";
602-
603-
espi->dma_rx = dma_request_channel(mask, ep93xx_spi_dma_filter,
604-
&espi->dma_rx_data);
605-
if (!espi->dma_rx) {
606-
ret = -ENODEV;
584+
espi->dma_rx = dma_request_chan(dev, "rx");
585+
if (IS_ERR(espi->dma_rx)) {
586+
ret = dev_err_probe(dev, PTR_ERR(espi->dma_rx), "rx DMA setup failed");
607587
goto fail_free_page;
608588
}
609589

610-
espi->dma_tx_data.port = EP93XX_DMA_SSP;
611-
espi->dma_tx_data.direction = DMA_MEM_TO_DEV;
612-
espi->dma_tx_data.name = "ep93xx-spi-tx";
613-
614-
espi->dma_tx = dma_request_channel(mask, ep93xx_spi_dma_filter,
615-
&espi->dma_tx_data);
616-
if (!espi->dma_tx) {
617-
ret = -ENODEV;
590+
espi->dma_tx = dma_request_chan(dev, "tx");
591+
if (IS_ERR(espi->dma_tx)) {
592+
ret = dev_err_probe(dev, PTR_ERR(espi->dma_tx), "tx DMA setup failed");
618593
goto fail_release_rx;
619594
}
620595

@@ -647,18 +622,11 @@ static void ep93xx_spi_release_dma(struct ep93xx_spi *espi)
647622
static int ep93xx_spi_probe(struct platform_device *pdev)
648623
{
649624
struct spi_controller *host;
650-
struct ep93xx_spi_info *info;
651625
struct ep93xx_spi *espi;
652626
struct resource *res;
653627
int irq;
654628
int error;
655629

656-
info = dev_get_platdata(&pdev->dev);
657-
if (!info) {
658-
dev_err(&pdev->dev, "missing platform data\n");
659-
return -EINVAL;
660-
}
661-
662630
irq = platform_get_irq(pdev, 0);
663631
if (irq < 0)
664632
return irq;
@@ -713,12 +681,17 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
713681
goto fail_release_host;
714682
}
715683

716-
if (info->use_dma && ep93xx_spi_setup_dma(espi))
684+
error = ep93xx_spi_setup_dma(&pdev->dev, espi);
685+
if (error == -EPROBE_DEFER)
686+
goto fail_release_host;
687+
688+
if (error)
717689
dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n");
718690

719691
/* make sure that the hardware is disabled */
720692
writel(0, espi->mmio + SSPCR1);
721693

694+
device_set_node(&host->dev, dev_fwnode(&pdev->dev));
722695
error = devm_spi_register_controller(&pdev->dev, host);
723696
if (error) {
724697
dev_err(&pdev->dev, "failed to register SPI host\n");
@@ -746,9 +719,16 @@ static void ep93xx_spi_remove(struct platform_device *pdev)
746719
ep93xx_spi_release_dma(espi);
747720
}
748721

722+
static const struct of_device_id ep93xx_spi_of_ids[] = {
723+
{ .compatible = "cirrus,ep9301-spi" },
724+
{ /* sentinel */ }
725+
};
726+
MODULE_DEVICE_TABLE(of, ep93xx_spi_of_ids);
727+
749728
static struct platform_driver ep93xx_spi_driver = {
750729
.driver = {
751730
.name = "ep93xx-spi",
731+
.of_match_table = ep93xx_spi_of_ids,
752732
},
753733
.probe = ep93xx_spi_probe,
754734
.remove_new = ep93xx_spi_remove,

0 commit comments

Comments
 (0)