intel-spi-pci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <linux/ioport.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include "intel-spi.h"
  16. #define BCR 0xdc
  17. #define BCR_WPD BIT(0)
  18. static const struct intel_spi_boardinfo bxt_info = {
  19. .type = INTEL_SPI_BXT,
  20. };
  21. static int intel_spi_pci_probe(struct pci_dev *pdev,
  22. const struct pci_device_id *id)
  23. {
  24. struct intel_spi_boardinfo *info;
  25. struct intel_spi *ispi;
  26. u32 bcr;
  27. int ret;
  28. ret = pcim_enable_device(pdev);
  29. if (ret)
  30. return ret;
  31. info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
  32. GFP_KERNEL);
  33. if (!info)
  34. return -ENOMEM;
  35. /* Try to make the chip read/write */
  36. pci_read_config_dword(pdev, BCR, &bcr);
  37. if (!(bcr & BCR_WPD)) {
  38. bcr |= BCR_WPD;
  39. pci_write_config_dword(pdev, BCR, bcr);
  40. pci_read_config_dword(pdev, BCR, &bcr);
  41. }
  42. info->writeable = !!(bcr & BCR_WPD);
  43. ispi = intel_spi_probe(&pdev->dev, &pdev->resource[0], info);
  44. if (IS_ERR(ispi))
  45. return PTR_ERR(ispi);
  46. pci_set_drvdata(pdev, ispi);
  47. return 0;
  48. }
  49. static void intel_spi_pci_remove(struct pci_dev *pdev)
  50. {
  51. intel_spi_remove(pci_get_drvdata(pdev));
  52. }
  53. static const struct pci_device_id intel_spi_pci_ids[] = {
  54. { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info },
  55. { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info },
  56. { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info },
  57. { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info },
  58. { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info },
  59. { },
  60. };
  61. MODULE_DEVICE_TABLE(pci, intel_spi_pci_ids);
  62. static struct pci_driver intel_spi_pci_driver = {
  63. .name = "intel-spi",
  64. .id_table = intel_spi_pci_ids,
  65. .probe = intel_spi_pci_probe,
  66. .remove = intel_spi_pci_remove,
  67. };
  68. module_pci_driver(intel_spi_pci_driver);
  69. MODULE_DESCRIPTION("Intel PCH/PCU SPI flash PCI driver");
  70. MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
  71. MODULE_LICENSE("GPL v2");