1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Intel PCH/PCU SPI flash PCI driver.
4 *
5 * Copyright (C) 2016, Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 */
8
9 #include <linux/ioport.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
13
14 #include "intel-spi.h"
15
16 #define BCR 0xdc
17 #define BCR_WPD BIT(0)
18
intel_spi_pci_set_writeable(void __iomem * base,void * data)19 static bool intel_spi_pci_set_writeable(void __iomem *base, void *data)
20 {
21 struct pci_dev *pdev = data;
22 u32 bcr;
23
24 /* Try to make the chip read/write */
25 pci_read_config_dword(pdev, BCR, &bcr);
26 if (!(bcr & BCR_WPD)) {
27 bcr |= BCR_WPD;
28 pci_write_config_dword(pdev, BCR, bcr);
29 pci_read_config_dword(pdev, BCR, &bcr);
30 }
31
32 return bcr & BCR_WPD;
33 }
34
35 static const struct intel_spi_boardinfo bxt_info = {
36 .type = INTEL_SPI_BXT,
37 .set_writeable = intel_spi_pci_set_writeable,
38 };
39
40 static const struct intel_spi_boardinfo cnl_info = {
41 .type = INTEL_SPI_CNL,
42 .set_writeable = intel_spi_pci_set_writeable,
43 };
44
intel_spi_pci_probe(struct pci_dev * pdev,const struct pci_device_id * id)45 static int intel_spi_pci_probe(struct pci_dev *pdev,
46 const struct pci_device_id *id)
47 {
48 struct intel_spi_boardinfo *info;
49 struct intel_spi *ispi;
50 int ret;
51
52 ret = pcim_enable_device(pdev);
53 if (ret)
54 return ret;
55
56 info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
57 GFP_KERNEL);
58 if (!info)
59 return -ENOMEM;
60
61 info->data = pdev;
62 ispi = intel_spi_probe(&pdev->dev, &pdev->resource[0], info);
63 if (IS_ERR(ispi))
64 return PTR_ERR(ispi);
65
66 pci_set_drvdata(pdev, ispi);
67 return 0;
68 }
69
intel_spi_pci_remove(struct pci_dev * pdev)70 static void intel_spi_pci_remove(struct pci_dev *pdev)
71 {
72 intel_spi_remove(pci_get_drvdata(pdev));
73 }
74
75 static const struct pci_device_id intel_spi_pci_ids[] = {
76 { PCI_VDEVICE(INTEL, 0x02a4), (unsigned long)&bxt_info },
77 { PCI_VDEVICE(INTEL, 0x06a4), (unsigned long)&bxt_info },
78 { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info },
79 { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info },
80 { PCI_VDEVICE(INTEL, 0x1bca), (unsigned long)&bxt_info },
81 { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info },
82 { PCI_VDEVICE(INTEL, 0x43a4), (unsigned long)&cnl_info },
83 { PCI_VDEVICE(INTEL, 0x4b24), (unsigned long)&bxt_info },
84 { PCI_VDEVICE(INTEL, 0x4da4), (unsigned long)&bxt_info },
85 { PCI_VDEVICE(INTEL, 0x7aa4), (unsigned long)&cnl_info },
86 { PCI_VDEVICE(INTEL, 0xa0a4), (unsigned long)&bxt_info },
87 { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info },
88 { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info },
89 { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)&cnl_info },
90 { PCI_VDEVICE(INTEL, 0xa3a4), (unsigned long)&bxt_info },
91 { },
92 };
93 MODULE_DEVICE_TABLE(pci, intel_spi_pci_ids);
94
95 static struct pci_driver intel_spi_pci_driver = {
96 .name = "intel-spi",
97 .id_table = intel_spi_pci_ids,
98 .probe = intel_spi_pci_probe,
99 .remove = intel_spi_pci_remove,
100 };
101
102 module_pci_driver(intel_spi_pci_driver);
103
104 MODULE_DESCRIPTION("Intel PCH/PCU SPI flash PCI driver");
105 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
106 MODULE_LICENSE("GPL v2");
107