Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 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> |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 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 | |
| 19 | static const struct intel_spi_boardinfo bxt_info = { |
| 20 | .type = INTEL_SPI_BXT, |
| 21 | }; |
| 22 | |
| 23 | static int intel_spi_pci_probe(struct pci_dev *pdev, |
| 24 | const struct pci_device_id *id) |
| 25 | { |
| 26 | struct intel_spi_boardinfo *info; |
| 27 | struct intel_spi *ispi; |
| 28 | u32 bcr; |
| 29 | int ret; |
| 30 | |
| 31 | ret = pcim_enable_device(pdev); |
| 32 | if (ret) |
| 33 | return ret; |
| 34 | |
| 35 | info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info), |
| 36 | GFP_KERNEL); |
| 37 | if (!info) |
| 38 | return -ENOMEM; |
| 39 | |
| 40 | /* Try to make the chip read/write */ |
| 41 | pci_read_config_dword(pdev, BCR, &bcr); |
| 42 | if (!(bcr & BCR_WPD)) { |
| 43 | bcr |= BCR_WPD; |
| 44 | pci_write_config_dword(pdev, BCR, bcr); |
| 45 | pci_read_config_dword(pdev, BCR, &bcr); |
| 46 | } |
| 47 | info->writeable = !!(bcr & BCR_WPD); |
| 48 | |
| 49 | ispi = intel_spi_probe(&pdev->dev, &pdev->resource[0], info); |
| 50 | if (IS_ERR(ispi)) |
| 51 | return PTR_ERR(ispi); |
| 52 | |
| 53 | pci_set_drvdata(pdev, ispi); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static void intel_spi_pci_remove(struct pci_dev *pdev) |
| 58 | { |
| 59 | intel_spi_remove(pci_get_drvdata(pdev)); |
| 60 | } |
| 61 | |
| 62 | static const struct pci_device_id intel_spi_pci_ids[] = { |
Mika Westerberg | e43f53c | 2019-04-16 12:11:10 +0300 | [diff] [blame] | 63 | { PCI_VDEVICE(INTEL, 0x02a4), (unsigned long)&bxt_info }, |
Mika Westerberg | 824af37 | 2017-09-21 16:19:46 +0300 | [diff] [blame] | 64 | { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info }, |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 65 | { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info }, |
Mika Westerberg | 42460c3 | 2018-08-30 11:42:57 +0300 | [diff] [blame] | 66 | { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info }, |
Mika Westerberg | d92b0f1 | 2017-09-21 16:19:45 +0300 | [diff] [blame] | 67 | { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info }, |
Kuppuswamy Sathyanarayanan | ec0a9f6 | 2017-10-29 15:17:35 -0700 | [diff] [blame] | 68 | { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info }, |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 69 | { }, |
| 70 | }; |
| 71 | MODULE_DEVICE_TABLE(pci, intel_spi_pci_ids); |
| 72 | |
| 73 | static struct pci_driver intel_spi_pci_driver = { |
| 74 | .name = "intel-spi", |
| 75 | .id_table = intel_spi_pci_ids, |
| 76 | .probe = intel_spi_pci_probe, |
| 77 | .remove = intel_spi_pci_remove, |
| 78 | }; |
| 79 | |
| 80 | module_pci_driver(intel_spi_pci_driver); |
| 81 | |
| 82 | MODULE_DESCRIPTION("Intel PCH/PCU SPI flash PCI driver"); |
| 83 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); |
| 84 | MODULE_LICENSE("GPL v2"); |