Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mtd / spi-nor / controllers / intel-spi-pci.c
blob555fe55d14aee8731363a97bc6023a6a53712146
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Intel PCH/PCU SPI flash PCI driver.
5 * Copyright (C) 2016, Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 */
9 #include <linux/ioport.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
14 #include "intel-spi.h"
16 #define BCR 0xdc
17 #define BCR_WPD BIT(0)
19 static const struct intel_spi_boardinfo bxt_info = {
20 .type = INTEL_SPI_BXT,
23 static const struct intel_spi_boardinfo cnl_info = {
24 .type = INTEL_SPI_CNL,
27 static int intel_spi_pci_probe(struct pci_dev *pdev,
28 const struct pci_device_id *id)
30 struct intel_spi_boardinfo *info;
31 struct intel_spi *ispi;
32 u32 bcr;
33 int ret;
35 ret = pcim_enable_device(pdev);
36 if (ret)
37 return ret;
39 info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
40 GFP_KERNEL);
41 if (!info)
42 return -ENOMEM;
44 /* Try to make the chip read/write */
45 pci_read_config_dword(pdev, BCR, &bcr);
46 if (!(bcr & BCR_WPD)) {
47 bcr |= BCR_WPD;
48 pci_write_config_dword(pdev, BCR, bcr);
49 pci_read_config_dword(pdev, BCR, &bcr);
51 info->writeable = !!(bcr & BCR_WPD);
53 ispi = intel_spi_probe(&pdev->dev, &pdev->resource[0], info);
54 if (IS_ERR(ispi))
55 return PTR_ERR(ispi);
57 pci_set_drvdata(pdev, ispi);
58 return 0;
61 static void intel_spi_pci_remove(struct pci_dev *pdev)
63 intel_spi_remove(pci_get_drvdata(pdev));
66 static const struct pci_device_id intel_spi_pci_ids[] = {
67 { PCI_VDEVICE(INTEL, 0x02a4), (unsigned long)&bxt_info },
68 { PCI_VDEVICE(INTEL, 0x06a4), (unsigned long)&bxt_info },
69 { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info },
70 { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info },
71 { PCI_VDEVICE(INTEL, 0x1bca), (unsigned long)&bxt_info },
72 { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info },
73 { PCI_VDEVICE(INTEL, 0x43a4), (unsigned long)&cnl_info },
74 { PCI_VDEVICE(INTEL, 0x4b24), (unsigned long)&bxt_info },
75 { PCI_VDEVICE(INTEL, 0x4da4), (unsigned long)&bxt_info },
76 { PCI_VDEVICE(INTEL, 0x7aa4), (unsigned long)&cnl_info },
77 { PCI_VDEVICE(INTEL, 0xa0a4), (unsigned long)&bxt_info },
78 { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info },
79 { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info },
80 { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)&cnl_info },
81 { PCI_VDEVICE(INTEL, 0xa3a4), (unsigned long)&bxt_info },
82 { },
84 MODULE_DEVICE_TABLE(pci, intel_spi_pci_ids);
86 static struct pci_driver intel_spi_pci_driver = {
87 .name = "intel-spi",
88 .id_table = intel_spi_pci_ids,
89 .probe = intel_spi_pci_probe,
90 .remove = intel_spi_pci_remove,
93 module_pci_driver(intel_spi_pci_driver);
95 MODULE_DESCRIPTION("Intel PCH/PCU SPI flash PCI driver");
96 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
97 MODULE_LICENSE("GPL v2");