2019-05-27 14:55:21 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-11-24 01:54:50 +08:00
|
|
|
/*
|
|
|
|
* GPIO driver for the ACCES 104-IDI-48 family
|
|
|
|
* Copyright (C) 2015 William Breathitt Gray
|
|
|
|
*
|
2016-05-02 06:44:55 +08:00
|
|
|
* This driver supports the following ACCES devices: 104-IDI-48A,
|
|
|
|
* 104-IDI-48AC, 104-IDI-48B, and 104-IDI-48BC.
|
2015-11-24 01:54:50 +08:00
|
|
|
*/
|
2022-07-20 21:46:01 +08:00
|
|
|
#include <linux/bits.h>
|
2015-11-24 01:54:50 +08:00
|
|
|
#include <linux/device.h>
|
2022-12-27 22:09:41 +08:00
|
|
|
#include <linux/err.h>
|
2015-11-24 01:54:50 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
|
|
|
#include <linux/interrupt.h>
|
2022-12-27 22:09:41 +08:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/irq.h>
|
2016-05-02 06:44:55 +08:00
|
|
|
#include <linux/isa.h>
|
2015-11-24 01:54:50 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2022-12-27 22:09:41 +08:00
|
|
|
#include <linux/regmap.h>
|
2022-07-20 21:46:01 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include "gpio-i8255.h"
|
|
|
|
|
|
|
|
MODULE_IMPORT_NS(I8255);
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2016-05-02 06:44:55 +08:00
|
|
|
#define IDI_48_EXTENT 8
|
|
|
|
#define MAX_NUM_IDI_48 max_num_isa_dev(IDI_48_EXTENT)
|
|
|
|
|
|
|
|
static unsigned int base[MAX_NUM_IDI_48];
|
|
|
|
static unsigned int num_idi_48;
|
2017-04-04 23:54:22 +08:00
|
|
|
module_param_hw_array(base, uint, ioport, &num_idi_48, 0);
|
2016-05-02 06:44:55 +08:00
|
|
|
MODULE_PARM_DESC(base, "ACCES 104-IDI-48 base addresses");
|
|
|
|
|
|
|
|
static unsigned int irq[MAX_NUM_IDI_48];
|
2022-08-19 00:28:13 +08:00
|
|
|
static unsigned int num_irq;
|
|
|
|
module_param_hw_array(irq, uint, irq, &num_irq, 0);
|
2016-05-02 06:44:55 +08:00
|
|
|
MODULE_PARM_DESC(irq, "ACCES 104-IDI-48 interrupt line numbers");
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
#define IDI48_IRQ_STATUS 0x7
|
|
|
|
#define IDI48_IRQ_ENABLE IDI48_IRQ_STATUS
|
|
|
|
|
2022-07-20 21:46:01 +08:00
|
|
|
/**
|
|
|
|
* struct idi_48_reg - device register structure
|
|
|
|
* @port0: Port 0 Inputs
|
|
|
|
* @unused: Unused
|
|
|
|
* @port1: Port 1 Inputs
|
|
|
|
* @irq: Read: IRQ Status Register/IRQ Clear
|
|
|
|
* Write: IRQ Enable/Disable
|
|
|
|
*/
|
|
|
|
struct idi_48_reg {
|
|
|
|
u8 port0[3];
|
|
|
|
u8 unused;
|
|
|
|
u8 port1[3];
|
|
|
|
u8 irq;
|
|
|
|
};
|
|
|
|
|
2015-11-24 01:54:50 +08:00
|
|
|
/**
|
|
|
|
* struct idi_48_gpio - GPIO device private data structure
|
|
|
|
* @chip: instance of the gpio_chip
|
2022-07-20 21:46:01 +08:00
|
|
|
* @reg: I/O address offset for the device registers
|
2015-11-24 01:54:50 +08:00
|
|
|
*/
|
|
|
|
struct idi_48_gpio {
|
|
|
|
struct gpio_chip chip;
|
2022-07-20 21:46:01 +08:00
|
|
|
struct idi_48_reg __iomem *reg;
|
2015-11-24 01:54:50 +08:00
|
|
|
};
|
|
|
|
|
2022-07-11 22:17:53 +08:00
|
|
|
static int idi_48_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
|
2015-11-24 01:54:50 +08:00
|
|
|
{
|
2019-11-06 16:54:12 +08:00
|
|
|
return GPIO_LINE_DIRECTION_IN;
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2022-07-11 22:17:53 +08:00
|
|
|
static int idi_48_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
|
2015-11-24 01:54:50 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-07-11 22:17:53 +08:00
|
|
|
static int idi_48_gpio_get(struct gpio_chip *chip, unsigned int offset)
|
2015-11-24 01:54:50 +08:00
|
|
|
{
|
2015-12-03 22:31:48 +08:00
|
|
|
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
|
2022-07-20 21:46:01 +08:00
|
|
|
void __iomem *const ppi = idi48gpio->reg;
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2022-07-20 21:46:01 +08:00
|
|
|
return i8255_get(ppi, offset);
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:00:31 +08:00
|
|
|
static int idi_48_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
|
|
|
|
unsigned long *bits)
|
|
|
|
{
|
|
|
|
struct idi_48_gpio *const idi48gpio = gpiochip_get_data(chip);
|
2022-07-20 21:46:01 +08:00
|
|
|
void __iomem *const ppi = idi48gpio->reg;
|
2018-03-22 21:00:31 +08:00
|
|
|
|
2022-07-20 21:46:01 +08:00
|
|
|
i8255_get_multiple(ppi, mask, bits, chip->ngpio);
|
2018-03-22 21:00:31 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
static const struct regmap_range idi_48_wr_ranges[] = {
|
|
|
|
regmap_reg_range(0x0, 0x6),
|
|
|
|
};
|
|
|
|
static const struct regmap_range idi_48_rd_ranges[] = {
|
|
|
|
regmap_reg_range(0x0, 0x2), regmap_reg_range(0x4, 0x7),
|
|
|
|
};
|
|
|
|
static const struct regmap_range idi_48_precious_ranges[] = {
|
|
|
|
regmap_reg_range(0x7, 0x7),
|
|
|
|
};
|
|
|
|
static const struct regmap_access_table idi_48_wr_table = {
|
|
|
|
.no_ranges = idi_48_wr_ranges,
|
|
|
|
.n_no_ranges = ARRAY_SIZE(idi_48_wr_ranges),
|
|
|
|
};
|
|
|
|
static const struct regmap_access_table idi_48_rd_table = {
|
|
|
|
.yes_ranges = idi_48_rd_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(idi_48_rd_ranges),
|
|
|
|
};
|
|
|
|
static const struct regmap_access_table idi_48_precious_table = {
|
|
|
|
.yes_ranges = idi_48_precious_ranges,
|
|
|
|
.n_yes_ranges = ARRAY_SIZE(idi_48_precious_ranges),
|
|
|
|
};
|
|
|
|
static const struct regmap_config idi48_regmap_config = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.reg_stride = 1,
|
|
|
|
.val_bits = 8,
|
|
|
|
.io_port = true,
|
|
|
|
.max_register = 0x6,
|
|
|
|
.wr_table = &idi_48_wr_table,
|
|
|
|
.rd_table = &idi_48_rd_table,
|
|
|
|
.precious_table = &idi_48_precious_table,
|
2015-11-24 01:54:50 +08:00
|
|
|
};
|
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
#define IDI48_NGPIO 48
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
#define IDI48_REGMAP_IRQ(_id) \
|
|
|
|
[_id] = { \
|
|
|
|
.mask = BIT((_id) / 8), \
|
|
|
|
.type = { .types_supported = IRQ_TYPE_EDGE_BOTH }, \
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
static const struct regmap_irq idi48_regmap_irqs[IDI48_NGPIO] = {
|
|
|
|
IDI48_REGMAP_IRQ(0), IDI48_REGMAP_IRQ(1), IDI48_REGMAP_IRQ(2), /* 0-2 */
|
|
|
|
IDI48_REGMAP_IRQ(3), IDI48_REGMAP_IRQ(4), IDI48_REGMAP_IRQ(5), /* 3-5 */
|
|
|
|
IDI48_REGMAP_IRQ(6), IDI48_REGMAP_IRQ(7), IDI48_REGMAP_IRQ(8), /* 6-8 */
|
|
|
|
IDI48_REGMAP_IRQ(9), IDI48_REGMAP_IRQ(10), IDI48_REGMAP_IRQ(11), /* 9-11 */
|
|
|
|
IDI48_REGMAP_IRQ(12), IDI48_REGMAP_IRQ(13), IDI48_REGMAP_IRQ(14), /* 12-14 */
|
|
|
|
IDI48_REGMAP_IRQ(15), IDI48_REGMAP_IRQ(16), IDI48_REGMAP_IRQ(17), /* 15-17 */
|
|
|
|
IDI48_REGMAP_IRQ(18), IDI48_REGMAP_IRQ(19), IDI48_REGMAP_IRQ(20), /* 18-20 */
|
|
|
|
IDI48_REGMAP_IRQ(21), IDI48_REGMAP_IRQ(22), IDI48_REGMAP_IRQ(23), /* 21-23 */
|
|
|
|
IDI48_REGMAP_IRQ(24), IDI48_REGMAP_IRQ(25), IDI48_REGMAP_IRQ(26), /* 24-26 */
|
|
|
|
IDI48_REGMAP_IRQ(27), IDI48_REGMAP_IRQ(28), IDI48_REGMAP_IRQ(29), /* 27-29 */
|
|
|
|
IDI48_REGMAP_IRQ(30), IDI48_REGMAP_IRQ(31), IDI48_REGMAP_IRQ(32), /* 30-32 */
|
|
|
|
IDI48_REGMAP_IRQ(33), IDI48_REGMAP_IRQ(34), IDI48_REGMAP_IRQ(35), /* 33-35 */
|
|
|
|
IDI48_REGMAP_IRQ(36), IDI48_REGMAP_IRQ(37), IDI48_REGMAP_IRQ(38), /* 36-38 */
|
|
|
|
IDI48_REGMAP_IRQ(39), IDI48_REGMAP_IRQ(40), IDI48_REGMAP_IRQ(41), /* 39-41 */
|
|
|
|
IDI48_REGMAP_IRQ(42), IDI48_REGMAP_IRQ(43), IDI48_REGMAP_IRQ(44), /* 42-44 */
|
|
|
|
IDI48_REGMAP_IRQ(45), IDI48_REGMAP_IRQ(46), IDI48_REGMAP_IRQ(47), /* 45-47 */
|
|
|
|
};
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2017-01-31 02:33:11 +08:00
|
|
|
static const char *idi48_names[IDI48_NGPIO] = {
|
|
|
|
"Bit 0 A", "Bit 1 A", "Bit 2 A", "Bit 3 A", "Bit 4 A", "Bit 5 A",
|
|
|
|
"Bit 6 A", "Bit 7 A", "Bit 8 A", "Bit 9 A", "Bit 10 A", "Bit 11 A",
|
|
|
|
"Bit 12 A", "Bit 13 A", "Bit 14 A", "Bit 15 A", "Bit 16 A", "Bit 17 A",
|
|
|
|
"Bit 18 A", "Bit 19 A", "Bit 20 A", "Bit 21 A", "Bit 22 A", "Bit 23 A",
|
|
|
|
"Bit 0 B", "Bit 1 B", "Bit 2 B", "Bit 3 B", "Bit 4 B", "Bit 5 B",
|
|
|
|
"Bit 6 B", "Bit 7 B", "Bit 8 B", "Bit 9 B", "Bit 10 B", "Bit 11 B",
|
|
|
|
"Bit 12 B", "Bit 13 B", "Bit 14 B", "Bit 15 B", "Bit 16 B", "Bit 17 B",
|
|
|
|
"Bit 18 B", "Bit 19 B", "Bit 20 B", "Bit 21 B", "Bit 22 B", "Bit 23 B"
|
|
|
|
};
|
|
|
|
|
2016-05-02 06:44:55 +08:00
|
|
|
static int idi_48_probe(struct device *dev, unsigned int id)
|
2015-11-24 01:54:50 +08:00
|
|
|
{
|
|
|
|
struct idi_48_gpio *idi48gpio;
|
|
|
|
const char *const name = dev_name(dev);
|
2022-12-27 22:09:41 +08:00
|
|
|
void __iomem *regs;
|
|
|
|
struct regmap *map;
|
|
|
|
struct regmap_irq_chip *chip;
|
|
|
|
struct regmap_irq_chip_data *chip_data;
|
2015-11-24 01:54:50 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
idi48gpio = devm_kzalloc(dev, sizeof(*idi48gpio), GFP_KERNEL);
|
|
|
|
if (!idi48gpio)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-05-02 06:44:55 +08:00
|
|
|
if (!devm_request_region(dev, base[id], IDI_48_EXTENT, name)) {
|
2016-02-04 04:15:22 +08:00
|
|
|
dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
|
2016-05-02 06:44:55 +08:00
|
|
|
base[id], base[id] + IDI_48_EXTENT);
|
2016-02-04 04:15:22 +08:00
|
|
|
return -EBUSY;
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
regs = devm_ioport_map(dev, base[id], IDI_48_EXTENT);
|
|
|
|
if (!regs)
|
2022-05-11 01:30:55 +08:00
|
|
|
return -ENOMEM;
|
2022-12-27 22:09:41 +08:00
|
|
|
idi48gpio->reg = regs;
|
|
|
|
|
|
|
|
map = devm_regmap_init_mmio(dev, regs, &idi48_regmap_config);
|
|
|
|
if (IS_ERR(map))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(map),
|
|
|
|
"Unable to initialize register map\n");
|
|
|
|
|
|
|
|
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
|
|
|
|
if (!chip)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
chip->name = name;
|
|
|
|
chip->status_base = IDI48_IRQ_STATUS;
|
|
|
|
chip->unmask_base = IDI48_IRQ_ENABLE;
|
|
|
|
chip->clear_on_unmask = true;
|
|
|
|
chip->num_regs = 1;
|
|
|
|
chip->irqs = idi48_regmap_irqs;
|
|
|
|
chip->num_irqs = ARRAY_SIZE(idi48_regmap_irqs);
|
|
|
|
|
|
|
|
err = devm_regmap_add_irq_chip(dev, map, irq[id], IRQF_SHARED, 0, chip,
|
|
|
|
&chip_data);
|
|
|
|
if (err)
|
|
|
|
return dev_err_probe(dev, err, "IRQ registration failed\n");
|
2022-05-11 01:30:55 +08:00
|
|
|
|
2015-11-24 01:54:50 +08:00
|
|
|
idi48gpio->chip.label = name;
|
|
|
|
idi48gpio->chip.parent = dev;
|
|
|
|
idi48gpio->chip.owner = THIS_MODULE;
|
|
|
|
idi48gpio->chip.base = -1;
|
2017-01-31 02:33:11 +08:00
|
|
|
idi48gpio->chip.ngpio = IDI48_NGPIO;
|
|
|
|
idi48gpio->chip.names = idi48_names;
|
2015-11-24 01:54:50 +08:00
|
|
|
idi48gpio->chip.get_direction = idi_48_gpio_get_direction;
|
|
|
|
idi48gpio->chip.direction_input = idi_48_gpio_direction_input;
|
|
|
|
idi48gpio->chip.get = idi_48_gpio_get;
|
2018-03-22 21:00:31 +08:00
|
|
|
idi48gpio->chip.get_multiple = idi_48_gpio_get_multiple;
|
2015-11-24 01:54:50 +08:00
|
|
|
|
2017-01-25 04:00:43 +08:00
|
|
|
err = devm_gpiochip_add_data(dev, &idi48gpio->chip, idi48gpio);
|
2015-11-24 01:54:50 +08:00
|
|
|
if (err) {
|
|
|
|
dev_err(dev, "GPIO registering failed (%d)\n", err);
|
2016-02-04 04:15:22 +08:00
|
|
|
return err;
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2022-12-27 22:09:41 +08:00
|
|
|
return gpiochip_irqchip_add_domain(&idi48gpio->chip,
|
|
|
|
regmap_irq_get_domain(chip_data));
|
2015-11-24 01:54:50 +08:00
|
|
|
}
|
|
|
|
|
2016-05-02 06:44:55 +08:00
|
|
|
static struct isa_driver idi_48_driver = {
|
|
|
|
.probe = idi_48_probe,
|
2015-11-24 01:54:50 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "104-idi-48"
|
|
|
|
},
|
|
|
|
};
|
2022-08-19 00:28:13 +08:00
|
|
|
module_isa_driver_with_irq(idi_48_driver, num_idi_48, num_irq);
|
2015-11-24 01:54:50 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("ACCES 104-IDI-48 GPIO driver");
|
2016-02-02 07:51:49 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|