hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/spi/spi-pic32.c
....@@ -1,17 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Microchip PIC32 SPI controller driver.
34 *
45 * Purna Chandra Mandal <purna.mandal@microchip.com>
56 * Copyright (c) 2016, Microchip Technology Inc.
6
- *
7
- * This program is free software; you can distribute it and/or modify it
8
- * under the terms of the GNU General Public License (Version 2) as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
- * for more details.
157 */
168
179 #include <linux/clk.h>
....@@ -560,7 +552,7 @@
560552 dev_err(&spi->dev, "wait error/timedout\n");
561553 if (dma_issued) {
562554 dmaengine_terminate_all(master->dma_rx);
563
- dmaengine_terminate_all(master->dma_rx);
555
+ dmaengine_terminate_all(master->dma_tx);
564556 }
565557 ret = -ETIMEDOUT;
566558 } else {
....@@ -615,25 +607,30 @@
615607 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
616608 }
617609
618
-static void pic32_spi_dma_prep(struct pic32_spi *pic32s, struct device *dev)
610
+static int pic32_spi_dma_prep(struct pic32_spi *pic32s, struct device *dev)
619611 {
620612 struct spi_master *master = pic32s->master;
621
- dma_cap_mask_t mask;
613
+ int ret = 0;
622614
623
- dma_cap_zero(mask);
624
- dma_cap_set(DMA_SLAVE, mask);
615
+ master->dma_rx = dma_request_chan(dev, "spi-rx");
616
+ if (IS_ERR(master->dma_rx)) {
617
+ if (PTR_ERR(master->dma_rx) == -EPROBE_DEFER)
618
+ ret = -EPROBE_DEFER;
619
+ else
620
+ dev_warn(dev, "RX channel not found.\n");
625621
626
- master->dma_rx = dma_request_slave_channel_compat(mask, NULL, NULL,
627
- dev, "spi-rx");
628
- if (!master->dma_rx) {
629
- dev_warn(dev, "RX channel not found.\n");
622
+ master->dma_rx = NULL;
630623 goto out_err;
631624 }
632625
633
- master->dma_tx = dma_request_slave_channel_compat(mask, NULL, NULL,
634
- dev, "spi-tx");
635
- if (!master->dma_tx) {
636
- dev_warn(dev, "TX channel not found.\n");
626
+ master->dma_tx = dma_request_chan(dev, "spi-tx");
627
+ if (IS_ERR(master->dma_tx)) {
628
+ if (PTR_ERR(master->dma_tx) == -EPROBE_DEFER)
629
+ ret = -EPROBE_DEFER;
630
+ else
631
+ dev_warn(dev, "TX channel not found.\n");
632
+
633
+ master->dma_tx = NULL;
637634 goto out_err;
638635 }
639636
....@@ -643,14 +640,20 @@
643640 /* DMA chnls allocated and prepared */
644641 set_bit(PIC32F_DMA_PREP, &pic32s->flags);
645642
646
- return;
643
+ return 0;
647644
648645 out_err:
649
- if (master->dma_rx)
646
+ if (master->dma_rx) {
650647 dma_release_channel(master->dma_rx);
648
+ master->dma_rx = NULL;
649
+ }
651650
652
- if (master->dma_tx)
651
+ if (master->dma_tx) {
653652 dma_release_channel(master->dma_tx);
653
+ master->dma_tx = NULL;
654
+ }
655
+
656
+ return ret;
654657 }
655658
656659 static void pic32_spi_dma_unprep(struct pic32_spi *pic32s)
....@@ -720,22 +723,16 @@
720723
721724 /* get irq resources: err-irq, rx-irq, tx-irq */
722725 pic32s->fault_irq = platform_get_irq_byname(pdev, "fault");
723
- if (pic32s->fault_irq < 0) {
724
- dev_err(&pdev->dev, "fault-irq not found\n");
726
+ if (pic32s->fault_irq < 0)
725727 return pic32s->fault_irq;
726
- }
727728
728729 pic32s->rx_irq = platform_get_irq_byname(pdev, "rx");
729
- if (pic32s->rx_irq < 0) {
730
- dev_err(&pdev->dev, "rx-irq not found\n");
730
+ if (pic32s->rx_irq < 0)
731731 return pic32s->rx_irq;
732
- }
733732
734733 pic32s->tx_irq = platform_get_irq_byname(pdev, "tx");
735
- if (pic32s->tx_irq < 0) {
736
- dev_err(&pdev->dev, "tx-irq not found\n");
734
+ if (pic32s->tx_irq < 0)
737735 return pic32s->tx_irq;
738
- }
739736
740737 /* get clock */
741738 pic32s->clk = devm_clk_get(&pdev->dev, "mck0");
....@@ -775,7 +772,7 @@
775772 if (ret)
776773 goto err_master;
777774
778
- master->dev.of_node = of_node_get(pdev->dev.of_node);
775
+ master->dev.of_node = pdev->dev.of_node;
779776 master->mode_bits = SPI_MODE_3 | SPI_MODE_0 | SPI_CS_HIGH;
780777 master->num_chipselect = 1; /* single chip-select */
781778 master->max_speed_hz = clk_get_rate(pic32s->clk);
....@@ -791,7 +788,10 @@
791788 master->unprepare_transfer_hardware = pic32_spi_unprepare_hardware;
792789
793790 /* optional DMA support */
794
- pic32_spi_dma_prep(pic32s, &pdev->dev);
791
+ ret = pic32_spi_dma_prep(pic32s, &pdev->dev);
792
+ if (ret)
793
+ goto err_bailout;
794
+
795795 if (test_bit(PIC32F_DMA_PREP, &pic32s->flags))
796796 master->can_dma = pic32_spi_can_dma;
797797