module: Convert symbol namespace to string literal
[linux.git] / drivers / gpio / gpio-pci-idio-16.c
blob476cea1b5ed774d18511aaf71d8ca2d71bcc9ff0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * GPIO driver for the ACCES PCI-IDIO-16
4 * Copyright (C) 2017 William Breathitt Gray
5 */
6 #include <linux/bits.h>
7 #include <linux/device.h>
8 #include <linux/err.h>
9 #include <linux/irq.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/regmap.h>
14 #include <linux/types.h>
16 #include "gpio-idio-16.h"
18 static const struct regmap_range idio_16_wr_ranges[] = {
19 regmap_reg_range(0x0, 0x2), regmap_reg_range(0x3, 0x4),
21 static const struct regmap_range idio_16_rd_ranges[] = {
22 regmap_reg_range(0x1, 0x2), regmap_reg_range(0x5, 0x6),
24 static const struct regmap_range idio_16_precious_ranges[] = {
25 regmap_reg_range(0x2, 0x2),
27 static const struct regmap_access_table idio_16_wr_table = {
28 .yes_ranges = idio_16_wr_ranges,
29 .n_yes_ranges = ARRAY_SIZE(idio_16_wr_ranges),
31 static const struct regmap_access_table idio_16_rd_table = {
32 .yes_ranges = idio_16_rd_ranges,
33 .n_yes_ranges = ARRAY_SIZE(idio_16_rd_ranges),
35 static const struct regmap_access_table idio_16_precious_table = {
36 .yes_ranges = idio_16_precious_ranges,
37 .n_yes_ranges = ARRAY_SIZE(idio_16_precious_ranges),
39 static const struct regmap_config idio_16_regmap_config = {
40 .reg_bits = 8,
41 .reg_stride = 1,
42 .val_bits = 8,
43 .io_port = true,
44 .wr_table = &idio_16_wr_table,
45 .rd_table = &idio_16_rd_table,
46 .volatile_table = &idio_16_rd_table,
47 .precious_table = &idio_16_precious_table,
48 .cache_type = REGCACHE_FLAT,
49 .use_raw_spinlock = true,
52 /* Only input lines (GPIO 16-31) support interrupts */
53 #define IDIO_16_REGMAP_IRQ(_id) \
54 [16 + _id] = { \
55 .mask = BIT(2), \
56 .type = { .types_supported = IRQ_TYPE_EDGE_BOTH }, \
59 static const struct regmap_irq idio_16_regmap_irqs[] = {
60 IDIO_16_REGMAP_IRQ(0), IDIO_16_REGMAP_IRQ(1), IDIO_16_REGMAP_IRQ(2), /* 0-2 */
61 IDIO_16_REGMAP_IRQ(3), IDIO_16_REGMAP_IRQ(4), IDIO_16_REGMAP_IRQ(5), /* 3-5 */
62 IDIO_16_REGMAP_IRQ(6), IDIO_16_REGMAP_IRQ(7), IDIO_16_REGMAP_IRQ(8), /* 6-8 */
63 IDIO_16_REGMAP_IRQ(9), IDIO_16_REGMAP_IRQ(10), IDIO_16_REGMAP_IRQ(11), /* 9-11 */
64 IDIO_16_REGMAP_IRQ(12), IDIO_16_REGMAP_IRQ(13), IDIO_16_REGMAP_IRQ(14), /* 12-14 */
65 IDIO_16_REGMAP_IRQ(15), /* 15 */
68 static int idio_16_probe(struct pci_dev *pdev, const struct pci_device_id *id)
70 struct device *const dev = &pdev->dev;
71 int err;
72 const size_t pci_bar_index = 2;
73 struct idio_16_regmap_config config = {};
74 void __iomem *regs;
75 struct regmap *map;
77 err = pcim_enable_device(pdev);
78 if (err)
79 return dev_err_probe(dev, err, "Failed to enable PCI device\n");
81 regs = pcim_iomap_region(pdev, pci_bar_index, pci_name(pdev));
82 if (IS_ERR(regs))
83 return dev_err_probe(dev, PTR_ERR(regs), "Unable to map PCI I/O addresses\n");
85 map = devm_regmap_init_mmio(dev, regs, &idio_16_regmap_config);
86 if (IS_ERR(map))
87 return dev_err_probe(dev, PTR_ERR(map), "Unable to initialize register map\n");
89 config.parent = dev;
90 config.map = map;
91 config.regmap_irqs = idio_16_regmap_irqs;
92 config.num_regmap_irqs = ARRAY_SIZE(idio_16_regmap_irqs);
93 config.irq = pdev->irq;
94 config.filters = true;
96 return devm_idio_16_regmap_register(dev, &config);
99 static const struct pci_device_id idio_16_pci_dev_id[] = {
100 { PCI_DEVICE(0x494F, 0x0DC8) }, { 0 }
102 MODULE_DEVICE_TABLE(pci, idio_16_pci_dev_id);
104 static struct pci_driver idio_16_driver = {
105 .name = "pci-idio-16",
106 .id_table = idio_16_pci_dev_id,
107 .probe = idio_16_probe
110 module_pci_driver(idio_16_driver);
112 MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
113 MODULE_DESCRIPTION("ACCES PCI-IDIO-16 GPIO driver");
114 MODULE_LICENSE("GPL v2");
115 MODULE_IMPORT_NS("GPIO_IDIO_16");