spi-pxa2xx.c (f0cf17ed76cffa365001d263ced1f130ec794917) spi-pxa2xx.c (5eb263ef08b5014cfc2539a838f39d2fd3531423)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 * Copyright (C) 2013, Intel Corporation
5 */
6
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 * Copyright (C) 2013, Intel Corporation
5 */
6
7#include <linux/acpi.h>
7#include <linux/bitops.h>
8#include <linux/bitops.h>
8#include <linux/init.h>
9#include <linux/module.h>
9#include <linux/clk.h>
10#include <linux/delay.h>
10#include <linux/device.h>
11#include <linux/device.h>
11#include <linux/ioport.h>
12#include <linux/errno.h>
13#include <linux/err.h>
12#include <linux/err.h>
13#include <linux/errno.h>
14#include <linux/gpio/consumer.h>
15#include <linux/gpio.h>
16#include <linux/init.h>
14#include <linux/interrupt.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
15#include <linux/kernel.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/mod_devicetable.h>
22#include <linux/of.h>
16#include <linux/pci.h>
17#include <linux/platform_device.h>
23#include <linux/pci.h>
24#include <linux/platform_device.h>
25#include <linux/pm_runtime.h>
26#include <linux/property.h>
27#include <linux/slab.h>
18#include <linux/spi/pxa2xx_spi.h>
19#include <linux/spi/spi.h>
28#include <linux/spi/pxa2xx_spi.h>
29#include <linux/spi/spi.h>
20#include <linux/delay.h>
21#include <linux/gpio.h>
22#include <linux/gpio/consumer.h>
23#include <linux/slab.h>
24#include <linux/clk.h>
25#include <linux/pm_runtime.h>
26#include <linux/acpi.h>
27#include <linux/of_device.h>
28
29#include "spi-pxa2xx.h"
30
31MODULE_AUTHOR("Stephen Street");
32MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
33MODULE_LICENSE("GPL");
34MODULE_ALIAS("platform:pxa2xx-spi");
35

--- 1416 unchanged lines hidden (view full) ---

1452 /* CNL-H */
1453 { PCI_VDEVICE(INTEL, 0xa32a), LPSS_CNL_SSP },
1454 { PCI_VDEVICE(INTEL, 0xa32b), LPSS_CNL_SSP },
1455 { PCI_VDEVICE(INTEL, 0xa37b), LPSS_CNL_SSP },
1456 /* CML-LP */
1457 { PCI_VDEVICE(INTEL, 0x02aa), LPSS_CNL_SSP },
1458 { PCI_VDEVICE(INTEL, 0x02ab), LPSS_CNL_SSP },
1459 { PCI_VDEVICE(INTEL, 0x02fb), LPSS_CNL_SSP },
30
31#include "spi-pxa2xx.h"
32
33MODULE_AUTHOR("Stephen Street");
34MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
35MODULE_LICENSE("GPL");
36MODULE_ALIAS("platform:pxa2xx-spi");
37

--- 1416 unchanged lines hidden (view full) ---

1454 /* CNL-H */
1455 { PCI_VDEVICE(INTEL, 0xa32a), LPSS_CNL_SSP },
1456 { PCI_VDEVICE(INTEL, 0xa32b), LPSS_CNL_SSP },
1457 { PCI_VDEVICE(INTEL, 0xa37b), LPSS_CNL_SSP },
1458 /* CML-LP */
1459 { PCI_VDEVICE(INTEL, 0x02aa), LPSS_CNL_SSP },
1460 { PCI_VDEVICE(INTEL, 0x02ab), LPSS_CNL_SSP },
1461 { PCI_VDEVICE(INTEL, 0x02fb), LPSS_CNL_SSP },
1460 /* CML-H */
1461 { PCI_VDEVICE(INTEL, 0x06aa), LPSS_CNL_SSP },
1462 { PCI_VDEVICE(INTEL, 0x06ab), LPSS_CNL_SSP },
1463 { PCI_VDEVICE(INTEL, 0x06fb), LPSS_CNL_SSP },
1464 /* TGL-LP */
1465 { PCI_VDEVICE(INTEL, 0xa0aa), LPSS_CNL_SSP },
1466 { PCI_VDEVICE(INTEL, 0xa0ab), LPSS_CNL_SSP },
1467 { PCI_VDEVICE(INTEL, 0xa0de), LPSS_CNL_SSP },
1468 { PCI_VDEVICE(INTEL, 0xa0df), LPSS_CNL_SSP },
1469 { PCI_VDEVICE(INTEL, 0xa0fb), LPSS_CNL_SSP },
1470 { PCI_VDEVICE(INTEL, 0xa0fd), LPSS_CNL_SSP },
1471 { PCI_VDEVICE(INTEL, 0xa0fe), LPSS_CNL_SSP },
1472 { },
1473};
1474
1475static const struct of_device_id pxa2xx_spi_of_match[] = {
1476 { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP },
1477 {},
1478};
1479MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match);
1480
1481#ifdef CONFIG_ACPI
1482
1462 /* TGL-LP */
1463 { PCI_VDEVICE(INTEL, 0xa0aa), LPSS_CNL_SSP },
1464 { PCI_VDEVICE(INTEL, 0xa0ab), LPSS_CNL_SSP },
1465 { PCI_VDEVICE(INTEL, 0xa0de), LPSS_CNL_SSP },
1466 { PCI_VDEVICE(INTEL, 0xa0df), LPSS_CNL_SSP },
1467 { PCI_VDEVICE(INTEL, 0xa0fb), LPSS_CNL_SSP },
1468 { PCI_VDEVICE(INTEL, 0xa0fd), LPSS_CNL_SSP },
1469 { PCI_VDEVICE(INTEL, 0xa0fe), LPSS_CNL_SSP },
1470 { },
1471};
1472
1473static const struct of_device_id pxa2xx_spi_of_match[] = {
1474 { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP },
1475 {},
1476};
1477MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match);
1478
1479#ifdef CONFIG_ACPI
1480
1483static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1481static int pxa2xx_spi_get_port_id(struct device *dev)
1484{
1482{
1483 struct acpi_device *adev;
1485 unsigned int devid;
1486 int port_id = -1;
1487
1484 unsigned int devid;
1485 int port_id = -1;
1486
1487 adev = ACPI_COMPANION(dev);
1488 if (adev && adev->pnp.unique_id &&
1489 !kstrtouint(adev->pnp.unique_id, 0, &devid))
1490 port_id = devid;
1491 return port_id;
1492}
1493
1494#else /* !CONFIG_ACPI */
1495
1488 if (adev && adev->pnp.unique_id &&
1489 !kstrtouint(adev->pnp.unique_id, 0, &devid))
1490 port_id = devid;
1491 return port_id;
1492}
1493
1494#else /* !CONFIG_ACPI */
1495
1496static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
1496static int pxa2xx_spi_get_port_id(struct device *dev)
1497{
1498 return -1;
1499}
1500
1501#endif /* CONFIG_ACPI */
1502
1503
1504#ifdef CONFIG_PCI

--- 4 unchanged lines hidden (view full) ---

1509}
1510
1511#endif /* CONFIG_PCI */
1512
1513static struct pxa2xx_spi_controller *
1514pxa2xx_spi_init_pdata(struct platform_device *pdev)
1515{
1516 struct pxa2xx_spi_controller *pdata;
1497{
1498 return -1;
1499}
1500
1501#endif /* CONFIG_ACPI */
1502
1503
1504#ifdef CONFIG_PCI

--- 4 unchanged lines hidden (view full) ---

1509}
1510
1511#endif /* CONFIG_PCI */
1512
1513static struct pxa2xx_spi_controller *
1514pxa2xx_spi_init_pdata(struct platform_device *pdev)
1515{
1516 struct pxa2xx_spi_controller *pdata;
1517 struct acpi_device *adev;
1518 struct ssp_device *ssp;
1519 struct resource *res;
1517 struct ssp_device *ssp;
1518 struct resource *res;
1520 const struct acpi_device_id *adev_id = NULL;
1519 struct device *parent = pdev->dev.parent;
1520 struct pci_dev *pcidev = dev_is_pci(parent) ? to_pci_dev(parent) : NULL;
1521 const struct pci_device_id *pcidev_id = NULL;
1521 const struct pci_device_id *pcidev_id = NULL;
1522 const struct of_device_id *of_id = NULL;
1523 enum pxa_ssp_type type;
1522 enum pxa_ssp_type type;
1523 const void *match;
1524
1524
1525 adev = ACPI_COMPANION(&pdev->dev);
1525 if (pcidev)
1526 pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
1526
1527
1527 if (pdev->dev.of_node)
1528 of_id = of_match_device(pdev->dev.driver->of_match_table,
1529 &pdev->dev);
1530 else if (dev_is_pci(pdev->dev.parent))
1531 pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match,
1532 to_pci_dev(pdev->dev.parent));
1533 else if (adev)
1534 adev_id = acpi_match_device(pdev->dev.driver->acpi_match_table,
1535 &pdev->dev);
1536 else
1537 return NULL;
1538
1539 if (adev_id)
1540 type = (enum pxa_ssp_type)adev_id->driver_data;
1528 match = device_get_match_data(&pdev->dev);
1529 if (match)
1530 type = (enum pxa_ssp_type)match;
1541 else if (pcidev_id)
1542 type = (enum pxa_ssp_type)pcidev_id->driver_data;
1531 else if (pcidev_id)
1532 type = (enum pxa_ssp_type)pcidev_id->driver_data;
1543 else if (of_id)
1544 type = (enum pxa_ssp_type)of_id->data;
1545 else
1546 return NULL;
1547
1548 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1549 if (!pdata)
1550 return NULL;
1551
1533 else
1534 return NULL;
1535
1536 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1537 if (!pdata)
1538 return NULL;
1539
1540 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1541 if (!res)
1542 return NULL;
1543
1552 ssp = &pdata->ssp;
1553
1544 ssp = &pdata->ssp;
1545
1554 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1546 ssp->phys_base = res->start;
1555 ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
1556 if (IS_ERR(ssp->mmio_base))
1557 return NULL;
1558
1547 ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
1548 if (IS_ERR(ssp->mmio_base))
1549 return NULL;
1550
1559 ssp->phys_base = res->start;
1560
1561#ifdef CONFIG_PCI
1562 if (pcidev_id) {
1551#ifdef CONFIG_PCI
1552 if (pcidev_id) {
1563 pdata->tx_param = pdev->dev.parent;
1564 pdata->rx_param = pdev->dev.parent;
1553 pdata->tx_param = parent;
1554 pdata->rx_param = parent;
1565 pdata->dma_filter = pxa2xx_spi_idma_filter;
1566 }
1567#endif
1568
1569 ssp->clk = devm_clk_get(&pdev->dev, NULL);
1555 pdata->dma_filter = pxa2xx_spi_idma_filter;
1556 }
1557#endif
1558
1559 ssp->clk = devm_clk_get(&pdev->dev, NULL);
1560 if (IS_ERR(ssp->clk))
1561 return NULL;
1562
1570 ssp->irq = platform_get_irq(pdev, 0);
1563 ssp->irq = platform_get_irq(pdev, 0);
1564 if (ssp->irq < 0)
1565 return NULL;
1566
1571 ssp->type = type;
1567 ssp->type = type;
1572 ssp->pdev = pdev;
1573 ssp->port_id = pxa2xx_spi_get_port_id(adev);
1568 ssp->dev = &pdev->dev;
1569 ssp->port_id = pxa2xx_spi_get_port_id(&pdev->dev);
1574
1570
1575 pdata->is_slave = of_property_read_bool(pdev->dev.of_node, "spi-slave");
1571 pdata->is_slave = device_property_read_bool(&pdev->dev, "spi-slave");
1576 pdata->num_chipselect = 1;
1577 pdata->enable_dma = true;
1578 pdata->dma_burst_size = 1;
1579
1580 return pdata;
1581}
1582
1583static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,

--- 15 unchanged lines hidden (view full) ---

1599 default:
1600 break;
1601 }
1602 }
1603
1604 return cs;
1605}
1606
1572 pdata->num_chipselect = 1;
1573 pdata->enable_dma = true;
1574 pdata->dma_burst_size = 1;
1575
1576 return pdata;
1577}
1578
1579static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,

--- 15 unchanged lines hidden (view full) ---

1595 default:
1596 break;
1597 }
1598 }
1599
1600 return cs;
1601}
1602
1607static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi)
1608{
1609 return MAX_DMA_LEN;
1610}
1611
1612static int pxa2xx_spi_probe(struct platform_device *pdev)
1613{
1614 struct device *dev = &pdev->dev;
1615 struct pxa2xx_spi_controller *platform_info;
1616 struct spi_controller *controller;
1617 struct driver_data *drv_data;
1618 struct ssp_device *ssp;
1619 const struct lpss_config *config;

--- 89 unchanged lines hidden (view full) ---

1709 if (platform_info->enable_dma) {
1710 status = pxa2xx_spi_dma_setup(drv_data);
1711 if (status) {
1712 dev_warn(dev, "no DMA channels available, using PIO\n");
1713 platform_info->enable_dma = false;
1714 } else {
1715 controller->can_dma = pxa2xx_spi_can_dma;
1716 controller->max_dma_len = MAX_DMA_LEN;
1603static int pxa2xx_spi_probe(struct platform_device *pdev)
1604{
1605 struct device *dev = &pdev->dev;
1606 struct pxa2xx_spi_controller *platform_info;
1607 struct spi_controller *controller;
1608 struct driver_data *drv_data;
1609 struct ssp_device *ssp;
1610 const struct lpss_config *config;

--- 89 unchanged lines hidden (view full) ---

1700 if (platform_info->enable_dma) {
1701 status = pxa2xx_spi_dma_setup(drv_data);
1702 if (status) {
1703 dev_warn(dev, "no DMA channels available, using PIO\n");
1704 platform_info->enable_dma = false;
1705 } else {
1706 controller->can_dma = pxa2xx_spi_can_dma;
1707 controller->max_dma_len = MAX_DMA_LEN;
1717 controller->max_transfer_size =
1718 pxa2xx_spi_max_dma_transfer_size;
1719 }
1720 }
1721
1722 /* Enable SOC clock */
1723 status = clk_prepare_enable(ssp->clk);
1724 if (status)
1725 goto out_error_dma_irq_alloc;
1726

--- 262 unchanged lines hidden ---
1708 }
1709 }
1710
1711 /* Enable SOC clock */
1712 status = clk_prepare_enable(ssp->clk);
1713 if (status)
1714 goto out_error_dma_irq_alloc;
1715

--- 262 unchanged lines hidden ---