Lines Matching +full:int +full:- +full:map +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0-only
3 * GPIO driver for the ACCES PCIe-IDIO-24 family
6 * This driver supports the following ACCES devices: PCIe-IDIO-24,
7 * PCIe-IDI-24, PCIe-IDO-24, and PCIe-IDIO-12.
48 * 23: Built-In Self-Test (BIST) Interrupt Active
126 .mask = BIT((_id) % IDIO_24_NGPIO_PER_REG), \
133 IDIO_24_IIN_IRQ(0), IDIO_24_IIN_IRQ(1), IDIO_24_IIN_IRQ(2), /* IIN 0-2 */
134 IDIO_24_IIN_IRQ(3), IDIO_24_IIN_IRQ(4), IDIO_24_IIN_IRQ(5), /* IIN 3-5 */
135 IDIO_24_IIN_IRQ(6), IDIO_24_IIN_IRQ(7), IDIO_24_IIN_IRQ(8), /* IIN 6-8 */
136 IDIO_24_IIN_IRQ(9), IDIO_24_IIN_IRQ(10), IDIO_24_IIN_IRQ(11), /* IIN 9-11 */
137 IDIO_24_IIN_IRQ(12), IDIO_24_IIN_IRQ(13), IDIO_24_IIN_IRQ(14), /* IIN 12-14 */
138 IDIO_24_IIN_IRQ(15), IDIO_24_IIN_IRQ(16), IDIO_24_IIN_IRQ(17), /* IIN 15-17 */
139 IDIO_24_IIN_IRQ(18), IDIO_24_IIN_IRQ(19), IDIO_24_IIN_IRQ(20), /* IIN 18-20 */
140 IDIO_24_IIN_IRQ(21), IDIO_24_IIN_IRQ(22), IDIO_24_IIN_IRQ(23), /* IIN 21-23 */
141 IDIO_24_TTL_IRQ(0), IDIO_24_TTL_IRQ(1), IDIO_24_TTL_IRQ(2), /* TTL 0-2 */
142 IDIO_24_TTL_IRQ(3), IDIO_24_TTL_IRQ(4), IDIO_24_TTL_IRQ(5), /* TTL 3-5 */
143 IDIO_24_TTL_IRQ(6), IDIO_24_TTL_IRQ(7), /* TTL 6-7 */
147 * struct idio_24_gpio - GPIO device private data structure
148 * @map: regmap for the device
153 struct regmap *map; member
158 static int idio_24_handle_mask_sync(const int index, const unsigned int mask_buf_def, in idio_24_handle_mask_sync()
159 const unsigned int mask_buf, void *const irq_drv_data) in idio_24_handle_mask_sync()
161 const unsigned int type_mask = COS_ENABLE_BOTH << index; in idio_24_handle_mask_sync()
164 int ret; in idio_24_handle_mask_sync()
166 raw_spin_lock(&idio24gpio->lock); in idio_24_handle_mask_sync()
169 type = (mask_buf == mask_buf_def) ? ~type_mask : idio24gpio->irq_type; in idio_24_handle_mask_sync()
171 ret = regmap_update_bits(idio24gpio->map, IDIO_24_COS_ENABLE, type_mask, type); in idio_24_handle_mask_sync()
173 raw_spin_unlock(&idio24gpio->lock); in idio_24_handle_mask_sync()
178 static int idio_24_set_type_config(unsigned int **const buf, const unsigned int type, in idio_24_set_type_config()
179 const struct regmap_irq *const irq_data, const int idx, in idio_24_set_type_config()
182 const unsigned int offset = irq_data->reg_offset; in idio_24_set_type_config()
183 const unsigned int rising = COS_ENABLE_RISING << offset; in idio_24_set_type_config()
184 const unsigned int falling = COS_ENABLE_FALLING << offset; in idio_24_set_type_config()
185 const unsigned int mask = COS_ENABLE_BOTH << offset; in idio_24_set_type_config() local
187 unsigned int new; in idio_24_set_type_config()
188 unsigned int cos_enable; in idio_24_set_type_config()
189 int ret; in idio_24_set_type_config()
199 new = mask; in idio_24_set_type_config()
202 return -EINVAL; in idio_24_set_type_config()
205 raw_spin_lock(&idio24gpio->lock); in idio_24_set_type_config()
208 idio24gpio->irq_type = (idio24gpio->irq_type & ~mask) | (new & mask); in idio_24_set_type_config()
210 ret = regmap_read(idio24gpio->map, IDIO_24_COS_ENABLE, &cos_enable); in idio_24_set_type_config()
215 if (cos_enable & mask) { in idio_24_set_type_config()
216 ret = regmap_update_bits(idio24gpio->map, IDIO_24_COS_ENABLE, mask, in idio_24_set_type_config()
217 idio24gpio->irq_type); in idio_24_set_type_config()
223 raw_spin_unlock(&idio24gpio->lock); in idio_24_set_type_config()
228 static int idio_24_reg_mask_xlate(struct gpio_regmap *const gpio, const unsigned int base, in idio_24_reg_mask_xlate()
229 const unsigned int offset, unsigned int *const reg, in idio_24_reg_mask_xlate()
230 unsigned int *const mask) in idio_24_reg_mask_xlate() argument
232 const unsigned int out_stride = offset / IDIO_24_NGPIO_PER_REG; in idio_24_reg_mask_xlate()
233 const unsigned int in_stride = (offset - 24) / IDIO_24_NGPIO_PER_REG; in idio_24_reg_mask_xlate()
234 struct regmap *const map = gpio_regmap_get_drvdata(gpio); in idio_24_reg_mask_xlate() local
235 int err; in idio_24_reg_mask_xlate()
236 unsigned int ctrl_reg; in idio_24_reg_mask_xlate()
240 *mask = BIT(offset % IDIO_24_NGPIO_PER_REG); in idio_24_reg_mask_xlate()
254 err = regmap_read(map, IDIO_24_CONTROL_REG, &ctrl_reg); in idio_24_reg_mask_xlate()
270 return -ENOTSUPP; in idio_24_reg_mask_xlate()
273 *mask = CONTROL_REG_OUT_MODE; in idio_24_reg_mask_xlate()
277 return -EINVAL; in idio_24_reg_mask_xlate()
292 static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id) in idio_24_probe()
294 struct device *const dev = &pdev->dev; in idio_24_probe()
296 int err; in idio_24_probe()
315 dev_err(dev, "Unable to map PCI I/O addresses (%d)\n", err); in idio_24_probe()
325 "Unable to initialize PEX8311 register map\n"); in idio_24_probe()
329 return -ENOMEM; in idio_24_probe()
331 idio24gpio->map = devm_regmap_init_mmio(dev, idio_24_regs, &idio_24_regmap_config); in idio_24_probe()
332 if (IS_ERR(idio24gpio->map)) in idio_24_probe()
333 return dev_err_probe(dev, PTR_ERR(idio24gpio->map), in idio_24_probe()
334 "Unable to initialize register map\n"); in idio_24_probe()
336 raw_spin_lock_init(&idio24gpio->lock); in idio_24_probe()
339 idio24gpio->irq_type = GENMASK(7, 0); in idio_24_probe()
343 return -ENOMEM; in idio_24_probe()
345 chip->name = name; in idio_24_probe()
346 chip->status_base = IDIO_24_COS_STATUS_BASE; in idio_24_probe()
347 chip->mask_base = IDIO_24_COS_ENABLE; in idio_24_probe()
348 chip->ack_base = IDIO_24_COS_STATUS_BASE; in idio_24_probe()
349 chip->num_regs = 4; in idio_24_probe()
350 chip->irqs = idio_24_regmap_irqs; in idio_24_probe()
351 chip->num_irqs = ARRAY_SIZE(idio_24_regmap_irqs); in idio_24_probe()
352 chip->handle_mask_sync = idio_24_handle_mask_sync; in idio_24_probe()
353 chip->set_type_config = idio_24_set_type_config; in idio_24_probe()
354 chip->irq_drv_data = idio24gpio; in idio_24_probe()
357 err = regmap_write(idio24gpio->map, IDIO_24_SOFT_RESET, 0); in idio_24_probe()
368 err = devm_regmap_add_irq_chip(dev, idio24gpio->map, pdev->irq, 0, 0, chip, &chip_data); in idio_24_probe()
373 gpio_config.regmap = idio24gpio->map; in idio_24_probe()
382 gpio_config.drvdata = idio24gpio->map; in idio_24_probe()
395 .name = "pcie-idio-24",
403 MODULE_DESCRIPTION("ACCES PCIe-IDIO-24 GPIO driver");