|
18 | 18 | #include <linux/err.h>
|
19 | 19 | #include <linux/delay.h>
|
20 | 20 | #include <linux/device.h>
|
| 21 | +#include <linux/dma-direction.h> |
| 22 | +#include <linux/dma-mapping.h> |
21 | 23 | #include <linux/dmaengine.h>
|
22 | 24 | #include <linux/bitops.h>
|
23 | 25 | #include <linux/interrupt.h>
|
24 | 26 | #include <linux/module.h>
|
| 27 | +#include <linux/property.h> |
25 | 28 | #include <linux/platform_device.h>
|
26 | 29 | #include <linux/sched.h>
|
27 | 30 | #include <linux/scatterlist.h>
|
28 | 31 | #include <linux/spi/spi.h>
|
29 | 32 |
|
30 |
| -#include <linux/platform_data/dma-ep93xx.h> |
31 |
| -#include <linux/platform_data/spi-ep93xx.h> |
32 |
| - |
33 | 33 | #define SSPCR0 0x0000
|
34 | 34 | #define SSPCR0_SPO BIT(6)
|
35 | 35 | #define SSPCR0_SPH BIT(7)
|
@@ -92,8 +92,6 @@ struct ep93xx_spi {
|
92 | 92 | size_t fifo_level;
|
93 | 93 | struct dma_chan *dma_rx;
|
94 | 94 | struct dma_chan *dma_tx;
|
95 |
| - struct ep93xx_dma_data dma_rx_data; |
96 |
| - struct ep93xx_dma_data dma_tx_data; |
97 | 95 | struct sg_table rx_sgt;
|
98 | 96 | struct sg_table tx_sgt;
|
99 | 97 | void *zeropage;
|
@@ -575,46 +573,23 @@ static int ep93xx_spi_unprepare_hardware(struct spi_controller *host)
|
575 | 573 | return 0;
|
576 | 574 | }
|
577 | 575 |
|
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) |
579 | 577 | {
|
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; |
590 | 578 | int ret;
|
591 | 579 |
|
592 | 580 | espi->zeropage = (void *)get_zeroed_page(GFP_KERNEL);
|
593 | 581 | if (!espi->zeropage)
|
594 | 582 | return -ENOMEM;
|
595 | 583 |
|
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"); |
607 | 587 | goto fail_free_page;
|
608 | 588 | }
|
609 | 589 |
|
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"); |
618 | 593 | goto fail_release_rx;
|
619 | 594 | }
|
620 | 595 |
|
@@ -647,18 +622,11 @@ static void ep93xx_spi_release_dma(struct ep93xx_spi *espi)
|
647 | 622 | static int ep93xx_spi_probe(struct platform_device *pdev)
|
648 | 623 | {
|
649 | 624 | struct spi_controller *host;
|
650 |
| - struct ep93xx_spi_info *info; |
651 | 625 | struct ep93xx_spi *espi;
|
652 | 626 | struct resource *res;
|
653 | 627 | int irq;
|
654 | 628 | int error;
|
655 | 629 |
|
656 |
| - info = dev_get_platdata(&pdev->dev); |
657 |
| - if (!info) { |
658 |
| - dev_err(&pdev->dev, "missing platform data\n"); |
659 |
| - return -EINVAL; |
660 |
| - } |
661 |
| - |
662 | 630 | irq = platform_get_irq(pdev, 0);
|
663 | 631 | if (irq < 0)
|
664 | 632 | return irq;
|
@@ -713,12 +681,17 @@ static int ep93xx_spi_probe(struct platform_device *pdev)
|
713 | 681 | goto fail_release_host;
|
714 | 682 | }
|
715 | 683 |
|
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) |
717 | 689 | dev_warn(&pdev->dev, "DMA setup failed. Falling back to PIO\n");
|
718 | 690 |
|
719 | 691 | /* make sure that the hardware is disabled */
|
720 | 692 | writel(0, espi->mmio + SSPCR1);
|
721 | 693 |
|
| 694 | + device_set_node(&host->dev, dev_fwnode(&pdev->dev)); |
722 | 695 | error = devm_spi_register_controller(&pdev->dev, host);
|
723 | 696 | if (error) {
|
724 | 697 | dev_err(&pdev->dev, "failed to register SPI host\n");
|
@@ -746,9 +719,16 @@ static void ep93xx_spi_remove(struct platform_device *pdev)
|
746 | 719 | ep93xx_spi_release_dma(espi);
|
747 | 720 | }
|
748 | 721 |
|
| 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 | + |
749 | 728 | static struct platform_driver ep93xx_spi_driver = {
|
750 | 729 | .driver = {
|
751 | 730 | .name = "ep93xx-spi",
|
| 731 | + .of_match_table = ep93xx_spi_of_ids, |
752 | 732 | },
|
753 | 733 | .probe = ep93xx_spi_probe,
|
754 | 734 | .remove_new = ep93xx_spi_remove,
|
|
0 commit comments