hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/spi/spi-topcliff-pch.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * SPI bus driver for the Topcliff PCH used by Intel SoCs
34 *
45 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; version 2 of the License.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
146 */
157
168 #include <linux/delay.h>
....@@ -130,6 +122,7 @@
130122 /**
131123 * struct pch_spi_data - Holds the SPI channel specific details
132124 * @io_remap_addr: The remapped PCI base address
125
+ * @io_base_addr: Base address
133126 * @master: Pointer to the SPI master structure
134127 * @work: Reference to work queue handler
135128 * @wait: Wait queue for waking up upon receiving an
....@@ -146,8 +139,8 @@
146139 * transfer
147140 * @rx_index: Receive data count; for bookkeeping during
148141 * transfer
149
- * @tx_buff: Buffer for data to be transmitted
150
- * @rx_index: Buffer for Received data
142
+ * @pkt_tx_buff: Buffer for data to be transmitted
143
+ * @pkt_rx_buff: Buffer for received data
151144 * @n_curnt_chip: The chip number that this SPI driver currently
152145 * operates on
153146 * @current_chip: Reference to the current chip that this SPI
....@@ -159,7 +152,10 @@
159152 * @board_dat: Reference to the SPI device data structure
160153 * @plat_dev: platform_device structure
161154 * @ch: SPI channel number
155
+ * @dma: Local DMA information
156
+ * @use_dma: True if DMA is to be used
162157 * @irq_reg_sts: Status of IRQ registration
158
+ * @save_total_len: Save length while data is being transferred
163159 */
164160 struct pch_spi_data {
165161 void __iomem *io_remap_addr;
....@@ -873,7 +869,7 @@
873869 /* Set Tx DMA */
874870 param = &dma->param_tx;
875871 param->dma_dev = &dma_dev->dev;
876
- param->chan_id = data->ch * 2; /* Tx = 0, 2 */;
872
+ param->chan_id = data->ch * 2; /* Tx = 0, 2 */
877873 param->tx_reg = data->io_base_addr + PCH_SPDWR;
878874 param->width = width;
879875 chan = dma_request_channel(mask, pch_spi_filter, param);
....@@ -888,7 +884,7 @@
888884 /* Set Rx DMA */
889885 param = &dma->param_rx;
890886 param->dma_dev = &dma_dev->dev;
891
- param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */;
887
+ param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */
892888 param->rx_reg = data->io_base_addr + PCH_SPDRR;
893889 param->width = width;
894890 chan = dma_request_channel(mask, pch_spi_filter, param);
....@@ -1008,7 +1004,7 @@
10081004 spin_unlock_irqrestore(&data->lock, flags);
10091005
10101006 /* RX */
1011
- dma->sg_rx_p = kcalloc(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC);
1007
+ dma->sg_rx_p = kmalloc_array(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC);
10121008 if (!dma->sg_rx_p)
10131009 return;
10141010
....@@ -1071,7 +1067,7 @@
10711067 head = 0;
10721068 }
10731069
1074
- dma->sg_tx_p = kcalloc(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC);
1070
+ dma->sg_tx_p = kmalloc_array(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC);
10751071 if (!dma->sg_tx_p)
10761072 return;
10771073
....@@ -1239,12 +1235,7 @@
12391235 "%s:data->current_msg->actual_length=%d\n",
12401236 __func__, data->current_msg->actual_length);
12411237
1242
- /* check for delay */
1243
- if (data->cur_trans->delay_usecs) {
1244
- dev_dbg(&data->master->dev, "%s:delay in usec=%d\n",
1245
- __func__, data->cur_trans->delay_usecs);
1246
- udelay(data->cur_trans->delay_usecs);
1247
- }
1238
+ spi_transfer_delay_exec(data->cur_trans);
12481239
12491240 spin_lock(&data->lock);
12501241
....@@ -1646,64 +1637,37 @@
16461637 kfree(pd_dev_save);
16471638 }
16481639
1649
-#ifdef CONFIG_PM
1650
-static int pch_spi_suspend(struct pci_dev *pdev, pm_message_t state)
1640
+static int __maybe_unused pch_spi_suspend(struct device *dev)
16511641 {
1652
- int retval;
1653
- struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
1642
+ struct pch_pd_dev_save *pd_dev_save = dev_get_drvdata(dev);
16541643
1655
- dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
1644
+ dev_dbg(dev, "%s ENTRY\n", __func__);
16561645
16571646 pd_dev_save->board_dat->suspend_sts = true;
16581647
1659
- /* save config space */
1660
- retval = pci_save_state(pdev);
1661
- if (retval == 0) {
1662
- pci_enable_wake(pdev, PCI_D3hot, 0);
1663
- pci_disable_device(pdev);
1664
- pci_set_power_state(pdev, PCI_D3hot);
1665
- } else {
1666
- dev_err(&pdev->dev, "%s pci_save_state failed\n", __func__);
1667
- }
1668
-
1669
- return retval;
1648
+ return 0;
16701649 }
16711650
1672
-static int pch_spi_resume(struct pci_dev *pdev)
1651
+static int __maybe_unused pch_spi_resume(struct device *dev)
16731652 {
1674
- int retval;
1675
- struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
1676
- dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
1653
+ struct pch_pd_dev_save *pd_dev_save = dev_get_drvdata(dev);
16771654
1678
- pci_set_power_state(pdev, PCI_D0);
1679
- pci_restore_state(pdev);
1655
+ dev_dbg(dev, "%s ENTRY\n", __func__);
16801656
1681
- retval = pci_enable_device(pdev);
1682
- if (retval < 0) {
1683
- dev_err(&pdev->dev,
1684
- "%s pci_enable_device failed\n", __func__);
1685
- } else {
1686
- pci_enable_wake(pdev, PCI_D3hot, 0);
1657
+ /* set suspend status to false */
1658
+ pd_dev_save->board_dat->suspend_sts = false;
16871659
1688
- /* set suspend status to false */
1689
- pd_dev_save->board_dat->suspend_sts = false;
1690
- }
1691
-
1692
- return retval;
1660
+ return 0;
16931661 }
1694
-#else
1695
-#define pch_spi_suspend NULL
1696
-#define pch_spi_resume NULL
16971662
1698
-#endif
1663
+static SIMPLE_DEV_PM_OPS(pch_spi_pm_ops, pch_spi_suspend, pch_spi_resume);
16991664
17001665 static struct pci_driver pch_spi_pcidev_driver = {
17011666 .name = "pch_spi",
17021667 .id_table = pch_spi_pcidev_id,
17031668 .probe = pch_spi_probe,
17041669 .remove = pch_spi_remove,
1705
- .suspend = pch_spi_suspend,
1706
- .resume = pch_spi_resume,
1670
+ .driver.pm = &pch_spi_pm_ops,
17071671 };
17081672
17091673 static int __init pch_spi_init(void)