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