Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Intel PCH/PCU SPI flash PCI driver. |
| 3 | * |
| 4 | * Copyright (C) 2016, Intel Corporation |
| 5 | * Author: Mika Westerberg <mika.westerberg@linux.intel.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/ioport.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/pci.h> |
| 16 | |
| 17 | #include "intel-spi.h" |
| 18 | |
| 19 | #define BCR 0xdc |
| 20 | #define BCR_WPD BIT(0) |
| 21 | |
| 22 | static const struct intel_spi_boardinfo bxt_info = { |
| 23 | .type = INTEL_SPI_BXT, |
| 24 | }; |
| 25 | |
| 26 | static int intel_spi_pci_probe(struct pci_dev *pdev, |
| 27 | const struct pci_device_id *id) |
| 28 | { |
| 29 | struct intel_spi_boardinfo *info; |
| 30 | struct intel_spi *ispi; |
| 31 | u32 bcr; |
| 32 | int ret; |
| 33 | |
| 34 | ret = pcim_enable_device(pdev); |
| 35 | if (ret) |
| 36 | return ret; |
| 37 | |
| 38 | info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info), |
| 39 | GFP_KERNEL); |
| 40 | if (!info) |
| 41 | return -ENOMEM; |
| 42 | |
| 43 | /* Try to make the chip read/write */ |
| 44 | pci_read_config_dword(pdev, BCR, &bcr); |
| 45 | if (!(bcr & BCR_WPD)) { |
| 46 | bcr |= BCR_WPD; |
| 47 | pci_write_config_dword(pdev, BCR, bcr); |
| 48 | pci_read_config_dword(pdev, BCR, &bcr); |
| 49 | } |
| 50 | info->writeable = !!(bcr & BCR_WPD); |
| 51 | |
| 52 | ispi = intel_spi_probe(&pdev->dev, &pdev->resource[0], info); |
| 53 | if (IS_ERR(ispi)) |
| 54 | return PTR_ERR(ispi); |
| 55 | |
| 56 | pci_set_drvdata(pdev, ispi); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static void intel_spi_pci_remove(struct pci_dev *pdev) |
| 61 | { |
| 62 | intel_spi_remove(pci_get_drvdata(pdev)); |
| 63 | } |
| 64 | |
| 65 | static const struct pci_device_id intel_spi_pci_ids[] = { |
Mika Westerberg | 824af37 | 2017-09-21 16:19:46 +0300 | [diff] [blame] | 66 | { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info }, |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 67 | { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info }, |
Mika Westerberg | d92b0f1 | 2017-09-21 16:19:45 +0300 | [diff] [blame] | 68 | { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info }, |
Kuppuswamy Sathyanarayanan | ec0a9f6 | 2017-10-29 15:17:35 -0700 | [diff] [blame] | 69 | { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info }, |
Mika Westerberg | fe60283 | 2017-06-29 14:45:42 +0300 | [diff] [blame] | 70 | { }, |
| 71 | }; |
| 72 | MODULE_DEVICE_TABLE(pci, intel_spi_pci_ids); |
| 73 | |
| 74 | static struct pci_driver intel_spi_pci_driver = { |
| 75 | .name = "intel-spi", |
| 76 | .id_table = intel_spi_pci_ids, |
| 77 | .probe = intel_spi_pci_probe, |
| 78 | .remove = intel_spi_pci_remove, |
| 79 | }; |
| 80 | |
| 81 | module_pci_driver(intel_spi_pci_driver); |
| 82 | |
| 83 | MODULE_DESCRIPTION("Intel PCH/PCU SPI flash PCI driver"); |
| 84 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); |
| 85 | MODULE_LICENSE("GPL v2"); |