]>
Commit | Line | Data |
---|---|---|
1802d0be | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1ceacea2 WBG |
2 | /* |
3 | * GPIO driver for the ACCES 104-IDIO-16 family | |
4 | * Copyright (C) 2015 William Breathitt Gray | |
5 | * | |
86ea8a95 WBG |
6 | * This driver supports the following ACCES devices: 104-IDIO-16, |
7 | * 104-IDIO-16E, 104-IDO-16, 104-IDIO-8, 104-IDIO-8E, and 104-IDO-8. | |
1ceacea2 | 8 | */ |
2c210c9a | 9 | #include <linux/bits.h> |
1ceacea2 | 10 | #include <linux/device.h> |
2c210c9a | 11 | #include <linux/err.h> |
1ceacea2 | 12 | #include <linux/ioport.h> |
2c210c9a | 13 | #include <linux/irq.h> |
86ea8a95 | 14 | #include <linux/isa.h> |
1ceacea2 WBG |
15 | #include <linux/kernel.h> |
16 | #include <linux/module.h> | |
17 | #include <linux/moduleparam.h> | |
2c210c9a | 18 | #include <linux/regmap.h> |
cc442e4d | 19 | #include <linux/types.h> |
1ceacea2 | 20 | |
c4ec384c WBG |
21 | #include "gpio-idio-16.h" |
22 | ||
86ea8a95 WBG |
23 | #define IDIO_16_EXTENT 8 |
24 | #define MAX_NUM_IDIO_16 max_num_isa_dev(IDIO_16_EXTENT) | |
25 | ||
26 | static unsigned int base[MAX_NUM_IDIO_16]; | |
27 | static unsigned int num_idio_16; | |
d759f906 | 28 | module_param_hw_array(base, uint, ioport, &num_idio_16, 0); |
86ea8a95 WBG |
29 | MODULE_PARM_DESC(base, "ACCES 104-IDIO-16 base addresses"); |
30 | ||
31 | static unsigned int irq[MAX_NUM_IDIO_16]; | |
c6074f3f WBG |
32 | static unsigned int num_irq; |
33 | module_param_hw_array(irq, uint, irq, &num_irq, 0); | |
86ea8a95 | 34 | MODULE_PARM_DESC(irq, "ACCES 104-IDIO-16 interrupt line numbers"); |
1ceacea2 | 35 | |
2c210c9a WBG |
36 | static const struct regmap_range idio_16_wr_ranges[] = { |
37 | regmap_reg_range(0x0, 0x2), regmap_reg_range(0x4, 0x4), | |
1ceacea2 | 38 | }; |
2c210c9a WBG |
39 | static const struct regmap_range idio_16_rd_ranges[] = { |
40 | regmap_reg_range(0x1, 0x2), regmap_reg_range(0x5, 0x5), | |
a1184147 | 41 | }; |
2c210c9a WBG |
42 | static const struct regmap_range idio_16_precious_ranges[] = { |
43 | regmap_reg_range(0x2, 0x2), | |
44 | }; | |
45 | static const struct regmap_access_table idio_16_wr_table = { | |
46 | .yes_ranges = idio_16_wr_ranges, | |
47 | .n_yes_ranges = ARRAY_SIZE(idio_16_wr_ranges), | |
48 | }; | |
49 | static const struct regmap_access_table idio_16_rd_table = { | |
50 | .yes_ranges = idio_16_rd_ranges, | |
51 | .n_yes_ranges = ARRAY_SIZE(idio_16_rd_ranges), | |
52 | }; | |
53 | static const struct regmap_access_table idio_16_precious_table = { | |
54 | .yes_ranges = idio_16_precious_ranges, | |
55 | .n_yes_ranges = ARRAY_SIZE(idio_16_precious_ranges), | |
56 | }; | |
57 | static const struct regmap_config idio_16_regmap_config = { | |
58 | .reg_bits = 8, | |
59 | .reg_stride = 1, | |
60 | .val_bits = 8, | |
61 | .io_port = true, | |
62 | .wr_table = &idio_16_wr_table, | |
63 | .rd_table = &idio_16_rd_table, | |
64 | .volatile_table = &idio_16_rd_table, | |
65 | .precious_table = &idio_16_precious_table, | |
66 | .cache_type = REGCACHE_FLAT, | |
67 | .use_raw_spinlock = true, | |
e0af4b5e WBG |
68 | }; |
69 | ||
2c210c9a WBG |
70 | /* Only input lines (GPIO 16-31) support interrupts */ |
71 | #define IDIO_16_REGMAP_IRQ(_id) \ | |
72 | [16 + _id] = { \ | |
73 | .mask = BIT(_id), \ | |
74 | .type = { .types_supported = IRQ_TYPE_EDGE_BOTH }, \ | |
75 | } | |
82e4613d | 76 | |
2c210c9a WBG |
77 | static const struct regmap_irq idio_16_regmap_irqs[] = { |
78 | IDIO_16_REGMAP_IRQ(0), IDIO_16_REGMAP_IRQ(1), IDIO_16_REGMAP_IRQ(2), /* 0-2 */ | |
79 | IDIO_16_REGMAP_IRQ(3), IDIO_16_REGMAP_IRQ(4), IDIO_16_REGMAP_IRQ(5), /* 3-5 */ | |
80 | IDIO_16_REGMAP_IRQ(6), IDIO_16_REGMAP_IRQ(7), IDIO_16_REGMAP_IRQ(8), /* 6-8 */ | |
81 | IDIO_16_REGMAP_IRQ(9), IDIO_16_REGMAP_IRQ(10), IDIO_16_REGMAP_IRQ(11), /* 9-11 */ | |
82 | IDIO_16_REGMAP_IRQ(12), IDIO_16_REGMAP_IRQ(13), IDIO_16_REGMAP_IRQ(14), /* 12-14 */ | |
83 | IDIO_16_REGMAP_IRQ(15), /* 15 */ | |
84 | }; | |
82e4613d | 85 | |
86ea8a95 | 86 | static int idio_16_probe(struct device *dev, unsigned int id) |
1ceacea2 | 87 | { |
6e0171b4 | 88 | const char *const name = dev_name(dev); |
2c210c9a WBG |
89 | struct idio_16_regmap_config config = {}; |
90 | void __iomem *regs; | |
91 | struct regmap *map; | |
1ceacea2 | 92 | |
86ea8a95 | 93 | if (!devm_request_region(dev, base[id], IDIO_16_EXTENT, name)) { |
cb32389c | 94 | dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", |
86ea8a95 | 95 | base[id], base[id] + IDIO_16_EXTENT); |
cb32389c | 96 | return -EBUSY; |
1ceacea2 WBG |
97 | } |
98 | ||
2c210c9a WBG |
99 | regs = devm_ioport_map(dev, base[id], IDIO_16_EXTENT); |
100 | if (!regs) | |
e0a574ef WBG |
101 | return -ENOMEM; |
102 | ||
2c210c9a WBG |
103 | map = devm_regmap_init_mmio(dev, regs, &idio_16_regmap_config); |
104 | if (IS_ERR(map)) | |
105 | return dev_err_probe(dev, PTR_ERR(map), "Unable to initialize register map\n"); | |
82e4613d | 106 | |
2c210c9a WBG |
107 | config.parent = dev; |
108 | config.map = map; | |
109 | config.regmap_irqs = idio_16_regmap_irqs; | |
110 | config.num_regmap_irqs = ARRAY_SIZE(idio_16_regmap_irqs); | |
111 | config.irq = irq[id]; | |
112 | config.no_status = true; | |
a1184147 | 113 | |
2c210c9a | 114 | return devm_idio_16_regmap_register(dev, &config); |
1ceacea2 WBG |
115 | } |
116 | ||
86ea8a95 WBG |
117 | static struct isa_driver idio_16_driver = { |
118 | .probe = idio_16_probe, | |
1ceacea2 WBG |
119 | .driver = { |
120 | .name = "104-idio-16" | |
121 | }, | |
1ceacea2 WBG |
122 | }; |
123 | ||
c6074f3f | 124 | module_isa_driver_with_irq(idio_16_driver, num_idio_16, num_irq); |
1ceacea2 WBG |
125 | |
126 | MODULE_AUTHOR("William Breathitt Gray <[email protected]>"); | |
127 | MODULE_DESCRIPTION("ACCES 104-IDIO-16 GPIO driver"); | |
22aeddb5 | 128 | MODULE_LICENSE("GPL v2"); |
cdd30ebb | 129 | MODULE_IMPORT_NS("GPIO_IDIO_16"); |