| 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 <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 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> |
| 17 |
|
| 18 |
#include "gpio-tangier.h" |
| 19 |
|
| 20 |
/* Intel Merrifield has 192 GPIO pins */ |
| 21 |
#define MRFLD_NGPIO 192 |
| 22 |
|
| 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), |
| 50 |
}; |
| 51 |
|
| 52 |
static const char *mrfld_gpio_get_pinctrl_dev_name(struct tng_gpio *priv) |
| 53 |
{ |
| 54 |
struct device *dev = priv->dev; |
| 55 |
struct acpi_device *adev; |
| 56 |
const char *name; |
| 57 |
|
| 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"; |
| 64 |
} |
| 65 |
|
| 66 |
return name; |
| 67 |
} |
| 68 |
|
| 69 |
static int mrfld_gpio_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 70 |
{ |
| 71 |
struct device *dev = &pdev->dev; |
| 72 |
struct tng_gpio *priv; |
| 73 |
u32 gpio_base, irq_base; |
| 74 |
void __iomem *base; |
| 75 |
int retval; |
| 76 |
|
| 77 |
retval = pcim_enable_device(pdev); |
| 78 |
if (retval) |
| 79 |
return retval; |
| 80 |
|
| 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"); |
| 84 |
|
| 85 |
irq_base = readl(base + 0 * sizeof(u32)); |
| 86 |
gpio_base = readl(base + 1 * sizeof(u32)); |
| 87 |
|
| 88 |
/* Release the IO mapping, since we already get the info from BAR1 */ |
| 89 |
pcim_iounmap_region(pdev, 1); |
| 90 |
|
| 91 |
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 92 |
if (!priv) |
| 93 |
return -ENOMEM; |
| 94 |
|
| 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"); |
| 100 |
|
| 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; |
| 106 |
|
| 107 |
priv->info.base = gpio_base; |
| 108 |
priv->info.ngpio = MRFLD_NGPIO; |
| 109 |
priv->info.first = irq_base; |
| 110 |
|
| 111 |
retval = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES); |
| 112 |
if (retval < 0) |
| 113 |
return retval; |
| 114 |
|
| 115 |
priv->irq = pci_irq_vector(pdev, 0); |
| 116 |
|
| 117 |
priv->wake_regs.gwmr = GWMR_MRFLD; |
| 118 |
priv->wake_regs.gwsr = GWSR_MRFLD; |
| 119 |
priv->wake_regs.gsir = GSIR_MRFLD; |
| 120 |
|
| 121 |
retval = devm_tng_gpio_probe(dev, priv); |
| 122 |
if (retval) |
| 123 |
return dev_err_probe(dev, retval, "tng_gpio_probe error\n"); |
| 124 |
|
| 125 |
pci_set_drvdata(pdev, priv); |
| 126 |
return 0; |
| 127 |
} |
| 128 |
|
| 129 |
static const struct pci_device_id mrfld_gpio_ids[] = { |
| 130 |
{ PCI_VDEVICE(INTEL, 0x1199) }, |
| 131 |
{ } |
| 132 |
}; |
| 133 |
MODULE_DEVICE_TABLE(pci, mrfld_gpio_ids); |
| 134 |
|
| 135 |
static struct pci_driver mrfld_gpio_driver = { |
| 136 |
.name = "gpio-merrifield", |
| 137 |
.id_table = mrfld_gpio_ids, |
| 138 |
.probe = mrfld_gpio_probe, |
| 139 |
}; |
| 140 |
module_pci_driver(mrfld_gpio_driver); |
| 141 |
|
| 142 |
MODULE_AUTHOR("Andy Shevchenko <[email protected]>"); |
| 143 |
MODULE_DESCRIPTION("Intel Merrifield SoC GPIO driver"); |
| 144 |
MODULE_LICENSE("GPL v2"); |
| 145 |
MODULE_IMPORT_NS("GPIO_TANGIER"); |