.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * SPI bus driver for the Topcliff PCH used by Intel SoCs |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
14 | 6 | */ |
---|
15 | 7 | |
---|
16 | 8 | #include <linux/delay.h> |
---|
.. | .. |
---|
130 | 122 | /** |
---|
131 | 123 | * struct pch_spi_data - Holds the SPI channel specific details |
---|
132 | 124 | * @io_remap_addr: The remapped PCI base address |
---|
| 125 | + * @io_base_addr: Base address |
---|
133 | 126 | * @master: Pointer to the SPI master structure |
---|
134 | 127 | * @work: Reference to work queue handler |
---|
135 | 128 | * @wait: Wait queue for waking up upon receiving an |
---|
.. | .. |
---|
146 | 139 | * transfer |
---|
147 | 140 | * @rx_index: Receive data count; for bookkeeping during |
---|
148 | 141 | * 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 |
---|
151 | 144 | * @n_curnt_chip: The chip number that this SPI driver currently |
---|
152 | 145 | * operates on |
---|
153 | 146 | * @current_chip: Reference to the current chip that this SPI |
---|
.. | .. |
---|
159 | 152 | * @board_dat: Reference to the SPI device data structure |
---|
160 | 153 | * @plat_dev: platform_device structure |
---|
161 | 154 | * @ch: SPI channel number |
---|
| 155 | + * @dma: Local DMA information |
---|
| 156 | + * @use_dma: True if DMA is to be used |
---|
162 | 157 | * @irq_reg_sts: Status of IRQ registration |
---|
| 158 | + * @save_total_len: Save length while data is being transferred |
---|
163 | 159 | */ |
---|
164 | 160 | struct pch_spi_data { |
---|
165 | 161 | void __iomem *io_remap_addr; |
---|
.. | .. |
---|
873 | 869 | /* Set Tx DMA */ |
---|
874 | 870 | param = &dma->param_tx; |
---|
875 | 871 | 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 */ |
---|
877 | 873 | param->tx_reg = data->io_base_addr + PCH_SPDWR; |
---|
878 | 874 | param->width = width; |
---|
879 | 875 | chan = dma_request_channel(mask, pch_spi_filter, param); |
---|
.. | .. |
---|
888 | 884 | /* Set Rx DMA */ |
---|
889 | 885 | param = &dma->param_rx; |
---|
890 | 886 | 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 */ |
---|
892 | 888 | param->rx_reg = data->io_base_addr + PCH_SPDRR; |
---|
893 | 889 | param->width = width; |
---|
894 | 890 | chan = dma_request_channel(mask, pch_spi_filter, param); |
---|
.. | .. |
---|
1008 | 1004 | spin_unlock_irqrestore(&data->lock, flags); |
---|
1009 | 1005 | |
---|
1010 | 1006 | /* 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); |
---|
1012 | 1008 | if (!dma->sg_rx_p) |
---|
1013 | 1009 | return; |
---|
1014 | 1010 | |
---|
.. | .. |
---|
1071 | 1067 | head = 0; |
---|
1072 | 1068 | } |
---|
1073 | 1069 | |
---|
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); |
---|
1075 | 1071 | if (!dma->sg_tx_p) |
---|
1076 | 1072 | return; |
---|
1077 | 1073 | |
---|
.. | .. |
---|
1239 | 1235 | "%s:data->current_msg->actual_length=%d\n", |
---|
1240 | 1236 | __func__, data->current_msg->actual_length); |
---|
1241 | 1237 | |
---|
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); |
---|
1248 | 1239 | |
---|
1249 | 1240 | spin_lock(&data->lock); |
---|
1250 | 1241 | |
---|
.. | .. |
---|
1646 | 1637 | kfree(pd_dev_save); |
---|
1647 | 1638 | } |
---|
1648 | 1639 | |
---|
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) |
---|
1651 | 1641 | { |
---|
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); |
---|
1654 | 1643 | |
---|
1655 | | - dev_dbg(&pdev->dev, "%s ENTRY\n", __func__); |
---|
| 1644 | + dev_dbg(dev, "%s ENTRY\n", __func__); |
---|
1656 | 1645 | |
---|
1657 | 1646 | pd_dev_save->board_dat->suspend_sts = true; |
---|
1658 | 1647 | |
---|
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; |
---|
1670 | 1649 | } |
---|
1671 | 1650 | |
---|
1672 | | -static int pch_spi_resume(struct pci_dev *pdev) |
---|
| 1651 | +static int __maybe_unused pch_spi_resume(struct device *dev) |
---|
1673 | 1652 | { |
---|
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); |
---|
1677 | 1654 | |
---|
1678 | | - pci_set_power_state(pdev, PCI_D0); |
---|
1679 | | - pci_restore_state(pdev); |
---|
| 1655 | + dev_dbg(dev, "%s ENTRY\n", __func__); |
---|
1680 | 1656 | |
---|
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; |
---|
1687 | 1659 | |
---|
1688 | | - /* set suspend status to false */ |
---|
1689 | | - pd_dev_save->board_dat->suspend_sts = false; |
---|
1690 | | - } |
---|
1691 | | - |
---|
1692 | | - return retval; |
---|
| 1660 | + return 0; |
---|
1693 | 1661 | } |
---|
1694 | | -#else |
---|
1695 | | -#define pch_spi_suspend NULL |
---|
1696 | | -#define pch_spi_resume NULL |
---|
1697 | 1662 | |
---|
1698 | | -#endif |
---|
| 1663 | +static SIMPLE_DEV_PM_OPS(pch_spi_pm_ops, pch_spi_suspend, pch_spi_resume); |
---|
1699 | 1664 | |
---|
1700 | 1665 | static struct pci_driver pch_spi_pcidev_driver = { |
---|
1701 | 1666 | .name = "pch_spi", |
---|
1702 | 1667 | .id_table = pch_spi_pcidev_id, |
---|
1703 | 1668 | .probe = pch_spi_probe, |
---|
1704 | 1669 | .remove = pch_spi_remove, |
---|
1705 | | - .suspend = pch_spi_suspend, |
---|
1706 | | - .resume = pch_spi_resume, |
---|
| 1670 | + .driver.pm = &pch_spi_pm_ops, |
---|
1707 | 1671 | }; |
---|
1708 | 1672 | |
---|
1709 | 1673 | static int __init pch_spi_init(void) |
---|