gpio-merrifield.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel Merrifield SoC GPIO driver
  4. *
  5. * Copyright (c) 2016, 2023 Intel Corporation.
  6. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/bitops.h>
  10. #include <linux/device.h>
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/types.h>
  16. #include "gpio-tangier.h"
  17. /* Intel Merrifield has 192 GPIO pins */
  18. #define MRFLD_NGPIO 192
  19. static const struct tng_gpio_pinrange mrfld_gpio_ranges[] = {
  20. GPIO_PINRANGE(0, 11, 146),
  21. GPIO_PINRANGE(12, 13, 144),
  22. GPIO_PINRANGE(14, 15, 35),
  23. GPIO_PINRANGE(16, 16, 164),
  24. GPIO_PINRANGE(17, 18, 105),
  25. GPIO_PINRANGE(19, 22, 101),
  26. GPIO_PINRANGE(23, 30, 107),
  27. GPIO_PINRANGE(32, 43, 67),
  28. GPIO_PINRANGE(44, 63, 195),
  29. GPIO_PINRANGE(64, 67, 140),
  30. GPIO_PINRANGE(68, 69, 165),
  31. GPIO_PINRANGE(70, 71, 65),
  32. GPIO_PINRANGE(72, 76, 228),
  33. GPIO_PINRANGE(77, 86, 37),
  34. GPIO_PINRANGE(87, 87, 48),
  35. GPIO_PINRANGE(88, 88, 47),
  36. GPIO_PINRANGE(89, 96, 49),
  37. GPIO_PINRANGE(97, 97, 34),
  38. GPIO_PINRANGE(102, 119, 83),
  39. GPIO_PINRANGE(120, 123, 79),
  40. GPIO_PINRANGE(124, 135, 115),
  41. GPIO_PINRANGE(137, 142, 158),
  42. GPIO_PINRANGE(154, 163, 24),
  43. GPIO_PINRANGE(164, 176, 215),
  44. GPIO_PINRANGE(177, 189, 127),
  45. GPIO_PINRANGE(190, 191, 178),
  46. };
  47. static const char *mrfld_gpio_get_pinctrl_dev_name(struct tng_gpio *priv)
  48. {
  49. struct device *dev = priv->dev;
  50. struct acpi_device *adev;
  51. const char *name;
  52. adev = acpi_dev_get_first_match_dev("INTC1002", NULL, -1);
  53. if (adev) {
  54. name = devm_kstrdup(dev, acpi_dev_name(adev), GFP_KERNEL);
  55. acpi_dev_put(adev);
  56. } else {
  57. name = "pinctrl-merrifield";
  58. }
  59. return name;
  60. }
  61. static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  62. {
  63. struct device *dev = &pdev->dev;
  64. struct tng_gpio *priv;
  65. u32 gpio_base, irq_base;
  66. void __iomem *base;
  67. int retval;
  68. retval = pcim_enable_device(pdev);
  69. if (retval)
  70. return retval;
  71. retval = pcim_iomap_regions(pdev, BIT(1) | BIT(0), pci_name(pdev));
  72. if (retval)
  73. return dev_err_probe(dev, retval, "I/O memory mapping error\n");
  74. base = pcim_iomap_table(pdev)[1];
  75. irq_base = readl(base + 0 * sizeof(u32));
  76. gpio_base = readl(base + 1 * sizeof(u32));
  77. /* Release the IO mapping, since we already get the info from BAR1 */
  78. pcim_iounmap_regions(pdev, BIT(1));
  79. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  80. if (!priv)
  81. return -ENOMEM;
  82. priv->dev = dev;
  83. priv->reg_base = pcim_iomap_table(pdev)[0];
  84. priv->pin_info.pin_ranges = mrfld_gpio_ranges;
  85. priv->pin_info.nranges = ARRAY_SIZE(mrfld_gpio_ranges);
  86. priv->pin_info.name = mrfld_gpio_get_pinctrl_dev_name(priv);
  87. if (!priv->pin_info.name)
  88. return -ENOMEM;
  89. priv->info.base = gpio_base;
  90. priv->info.ngpio = MRFLD_NGPIO;
  91. priv->info.first = irq_base;
  92. retval = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
  93. if (retval < 0)
  94. return retval;
  95. priv->irq = pci_irq_vector(pdev, 0);
  96. priv->wake_regs.gwmr = GWMR_MRFLD;
  97. priv->wake_regs.gwsr = GWSR_MRFLD;
  98. priv->wake_regs.gsir = GSIR_MRFLD;
  99. retval = devm_tng_gpio_probe(dev, priv);
  100. if (retval)
  101. return dev_err_probe(dev, retval, "tng_gpio_probe error\n");
  102. pci_set_drvdata(pdev, priv);
  103. return 0;
  104. }
  105. static const struct pci_device_id mrfld_gpio_ids[] = {
  106. { PCI_VDEVICE(INTEL, 0x1199) },
  107. { }
  108. };
  109. MODULE_DEVICE_TABLE(pci, mrfld_gpio_ids);
  110. static struct pci_driver mrfld_gpio_driver = {
  111. .name = "gpio-merrifield",
  112. .id_table = mrfld_gpio_ids,
  113. .probe = mrfld_gpio_probe,
  114. };
  115. module_pci_driver(mrfld_gpio_driver);
  116. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
  117. MODULE_DESCRIPTION("Intel Merrifield SoC GPIO driver");
  118. MODULE_LICENSE("GPL v2");
  119. MODULE_IMPORT_NS(GPIO_TANGIER);