spi-intel-pci.c 3.4 KB

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