162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * GPIO driver for the WinSystems WS16C48
462306a36Sopenharmony_ci * Copyright (C) 2016 William Breathitt Gray
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#include <linux/bitfield.h>
762306a36Sopenharmony_ci#include <linux/bits.h>
862306a36Sopenharmony_ci#include <linux/device.h>
962306a36Sopenharmony_ci#include <linux/err.h>
1062306a36Sopenharmony_ci#include <linux/gpio/regmap.h>
1162306a36Sopenharmony_ci#include <linux/irq.h>
1262306a36Sopenharmony_ci#include <linux/isa.h>
1362306a36Sopenharmony_ci#include <linux/kernel.h>
1462306a36Sopenharmony_ci#include <linux/module.h>
1562306a36Sopenharmony_ci#include <linux/moduleparam.h>
1662306a36Sopenharmony_ci#include <linux/spinlock.h>
1762306a36Sopenharmony_ci#include <linux/regmap.h>
1862306a36Sopenharmony_ci#include <linux/types.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define WS16C48_EXTENT 11
2162306a36Sopenharmony_ci#define MAX_NUM_WS16C48 max_num_isa_dev(WS16C48_EXTENT)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_cistatic unsigned int base[MAX_NUM_WS16C48];
2462306a36Sopenharmony_cistatic unsigned int num_ws16c48;
2562306a36Sopenharmony_cimodule_param_hw_array(base, uint, ioport, &num_ws16c48, 0);
2662306a36Sopenharmony_ciMODULE_PARM_DESC(base, "WinSystems WS16C48 base addresses");
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_cistatic unsigned int irq[MAX_NUM_WS16C48];
2962306a36Sopenharmony_cistatic unsigned int num_irq;
3062306a36Sopenharmony_cimodule_param_hw_array(irq, uint, irq, &num_irq, 0);
3162306a36Sopenharmony_ciMODULE_PARM_DESC(irq, "WinSystems WS16C48 interrupt line numbers");
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define WS16C48_DAT_BASE 0x0
3462306a36Sopenharmony_ci#define WS16C48_PAGE_LOCK 0x7
3562306a36Sopenharmony_ci#define WS16C48_PAGE_BASE 0x8
3662306a36Sopenharmony_ci#define WS16C48_POL WS16C48_PAGE_BASE
3762306a36Sopenharmony_ci#define WS16C48_ENAB WS16C48_PAGE_BASE
3862306a36Sopenharmony_ci#define WS16C48_INT_ID WS16C48_PAGE_BASE
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define PAGE_LOCK_PAGE_FIELD GENMASK(7, 6)
4162306a36Sopenharmony_ci#define POL_PAGE u8_encode_bits(1, PAGE_LOCK_PAGE_FIELD)
4262306a36Sopenharmony_ci#define ENAB_PAGE u8_encode_bits(2, PAGE_LOCK_PAGE_FIELD)
4362306a36Sopenharmony_ci#define INT_ID_PAGE u8_encode_bits(3, PAGE_LOCK_PAGE_FIELD)
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_cistatic const struct regmap_range ws16c48_wr_ranges[] = {
4662306a36Sopenharmony_ci	regmap_reg_range(0x0, 0x5), regmap_reg_range(0x7, 0xA),
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_cistatic const struct regmap_range ws16c48_rd_ranges[] = {
4962306a36Sopenharmony_ci	regmap_reg_range(0x0, 0xA),
5062306a36Sopenharmony_ci};
5162306a36Sopenharmony_cistatic const struct regmap_range ws16c48_volatile_ranges[] = {
5262306a36Sopenharmony_ci	regmap_reg_range(0x0, 0x6), regmap_reg_range(0x8, 0xA),
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_cistatic const struct regmap_access_table ws16c48_wr_table = {
5562306a36Sopenharmony_ci	.yes_ranges = ws16c48_wr_ranges,
5662306a36Sopenharmony_ci	.n_yes_ranges = ARRAY_SIZE(ws16c48_wr_ranges),
5762306a36Sopenharmony_ci};
5862306a36Sopenharmony_cistatic const struct regmap_access_table ws16c48_rd_table = {
5962306a36Sopenharmony_ci	.yes_ranges = ws16c48_rd_ranges,
6062306a36Sopenharmony_ci	.n_yes_ranges = ARRAY_SIZE(ws16c48_rd_ranges),
6162306a36Sopenharmony_ci};
6262306a36Sopenharmony_cistatic const struct regmap_access_table ws16c48_volatile_table = {
6362306a36Sopenharmony_ci	.yes_ranges = ws16c48_volatile_ranges,
6462306a36Sopenharmony_ci	.n_yes_ranges = ARRAY_SIZE(ws16c48_volatile_ranges),
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_cistatic const struct regmap_config ws16c48_regmap_config = {
6762306a36Sopenharmony_ci	.reg_bits = 8,
6862306a36Sopenharmony_ci	.reg_stride = 1,
6962306a36Sopenharmony_ci	.val_bits = 8,
7062306a36Sopenharmony_ci	.io_port = true,
7162306a36Sopenharmony_ci	.wr_table = &ws16c48_wr_table,
7262306a36Sopenharmony_ci	.rd_table = &ws16c48_rd_table,
7362306a36Sopenharmony_ci	.volatile_table = &ws16c48_volatile_table,
7462306a36Sopenharmony_ci	.cache_type = REGCACHE_FLAT,
7562306a36Sopenharmony_ci	.use_raw_spinlock = true,
7662306a36Sopenharmony_ci};
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define WS16C48_NGPIO_PER_REG 8
7962306a36Sopenharmony_ci#define WS16C48_REGMAP_IRQ(_id)							\
8062306a36Sopenharmony_ci	[_id] = {								\
8162306a36Sopenharmony_ci		.reg_offset = (_id) / WS16C48_NGPIO_PER_REG,			\
8262306a36Sopenharmony_ci		.mask = BIT((_id) % WS16C48_NGPIO_PER_REG),			\
8362306a36Sopenharmony_ci		.type = {							\
8462306a36Sopenharmony_ci			.type_reg_offset = (_id) / WS16C48_NGPIO_PER_REG,	\
8562306a36Sopenharmony_ci			.types_supported = IRQ_TYPE_EDGE_BOTH,			\
8662306a36Sopenharmony_ci		},								\
8762306a36Sopenharmony_ci	}
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* Only the first 24 lines (Port 0-2) support interrupts */
9062306a36Sopenharmony_ci#define WS16C48_NUM_IRQS 24
9162306a36Sopenharmony_cistatic const struct regmap_irq ws16c48_regmap_irqs[WS16C48_NUM_IRQS] = {
9262306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(0), WS16C48_REGMAP_IRQ(1), WS16C48_REGMAP_IRQ(2), /* 0-2 */
9362306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(3), WS16C48_REGMAP_IRQ(4), WS16C48_REGMAP_IRQ(5), /* 3-5 */
9462306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(6), WS16C48_REGMAP_IRQ(7), WS16C48_REGMAP_IRQ(8), /* 6-8 */
9562306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(9), WS16C48_REGMAP_IRQ(10), WS16C48_REGMAP_IRQ(11), /* 9-11 */
9662306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(12), WS16C48_REGMAP_IRQ(13), WS16C48_REGMAP_IRQ(14), /* 12-14 */
9762306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(15), WS16C48_REGMAP_IRQ(16), WS16C48_REGMAP_IRQ(17), /* 15-17 */
9862306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(18), WS16C48_REGMAP_IRQ(19), WS16C48_REGMAP_IRQ(20), /* 18-20 */
9962306a36Sopenharmony_ci	WS16C48_REGMAP_IRQ(21), WS16C48_REGMAP_IRQ(22), WS16C48_REGMAP_IRQ(23), /* 21-23 */
10062306a36Sopenharmony_ci};
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/**
10362306a36Sopenharmony_ci * struct ws16c48_gpio - GPIO device private data structure
10462306a36Sopenharmony_ci * @map:	regmap for the device
10562306a36Sopenharmony_ci * @lock:	synchronization lock to prevent I/O race conditions
10662306a36Sopenharmony_ci * @irq_mask:	I/O bits affected by interrupts
10762306a36Sopenharmony_ci */
10862306a36Sopenharmony_cistruct ws16c48_gpio {
10962306a36Sopenharmony_ci	struct regmap *map;
11062306a36Sopenharmony_ci	raw_spinlock_t lock;
11162306a36Sopenharmony_ci	u8 irq_mask[WS16C48_NUM_IRQS / WS16C48_NGPIO_PER_REG];
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistatic int ws16c48_handle_pre_irq(void *const irq_drv_data) __acquires(&ws16c48gpio->lock)
11562306a36Sopenharmony_ci{
11662306a36Sopenharmony_ci	struct ws16c48_gpio *const ws16c48gpio = irq_drv_data;
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	/* Lock to prevent Page/Lock register change while we handle IRQ */
11962306a36Sopenharmony_ci	raw_spin_lock(&ws16c48gpio->lock);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	return 0;
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistatic int ws16c48_handle_post_irq(void *const irq_drv_data) __releases(&ws16c48gpio->lock)
12562306a36Sopenharmony_ci{
12662306a36Sopenharmony_ci	struct ws16c48_gpio *const ws16c48gpio = irq_drv_data;
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	raw_spin_unlock(&ws16c48gpio->lock);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	return 0;
13162306a36Sopenharmony_ci}
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_cistatic int ws16c48_handle_mask_sync(const int index, const unsigned int mask_buf_def,
13462306a36Sopenharmony_ci				    const unsigned int mask_buf, void *const irq_drv_data)
13562306a36Sopenharmony_ci{
13662306a36Sopenharmony_ci	struct ws16c48_gpio *const ws16c48gpio = irq_drv_data;
13762306a36Sopenharmony_ci	unsigned long flags;
13862306a36Sopenharmony_ci	int ret = 0;
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci	raw_spin_lock_irqsave(&ws16c48gpio->lock, flags);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci	/* exit early if no change since the last mask sync */
14362306a36Sopenharmony_ci	if (mask_buf == ws16c48gpio->irq_mask[index])
14462306a36Sopenharmony_ci		goto exit_unlock;
14562306a36Sopenharmony_ci	ws16c48gpio->irq_mask[index] = mask_buf;
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci	ret = regmap_write(ws16c48gpio->map, WS16C48_PAGE_LOCK, ENAB_PAGE);
14862306a36Sopenharmony_ci	if (ret)
14962306a36Sopenharmony_ci		goto exit_unlock;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	/* Update ENAB register (inverted mask) */
15262306a36Sopenharmony_ci	ret = regmap_write(ws16c48gpio->map, WS16C48_ENAB + index, ~mask_buf);
15362306a36Sopenharmony_ci	if (ret)
15462306a36Sopenharmony_ci		goto exit_unlock;
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci	ret = regmap_write(ws16c48gpio->map, WS16C48_PAGE_LOCK, INT_ID_PAGE);
15762306a36Sopenharmony_ci	if (ret)
15862306a36Sopenharmony_ci		goto exit_unlock;
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ciexit_unlock:
16162306a36Sopenharmony_ci	raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci	return ret;
16462306a36Sopenharmony_ci}
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_cistatic int ws16c48_set_type_config(unsigned int **const buf, const unsigned int type,
16762306a36Sopenharmony_ci				   const struct regmap_irq *const irq_data, const int idx,
16862306a36Sopenharmony_ci				   void *const irq_drv_data)
16962306a36Sopenharmony_ci{
17062306a36Sopenharmony_ci	struct ws16c48_gpio *const ws16c48gpio = irq_drv_data;
17162306a36Sopenharmony_ci	unsigned int polarity;
17262306a36Sopenharmony_ci	unsigned long flags;
17362306a36Sopenharmony_ci	int ret;
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	switch (type) {
17662306a36Sopenharmony_ci	case IRQ_TYPE_EDGE_RISING:
17762306a36Sopenharmony_ci		polarity = irq_data->mask;
17862306a36Sopenharmony_ci		break;
17962306a36Sopenharmony_ci	case IRQ_TYPE_EDGE_FALLING:
18062306a36Sopenharmony_ci		polarity = 0;
18162306a36Sopenharmony_ci		break;
18262306a36Sopenharmony_ci	default:
18362306a36Sopenharmony_ci		return -EINVAL;
18462306a36Sopenharmony_ci	}
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci	raw_spin_lock_irqsave(&ws16c48gpio->lock, flags);
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	ret = regmap_write(ws16c48gpio->map, WS16C48_PAGE_LOCK, POL_PAGE);
18962306a36Sopenharmony_ci	if (ret)
19062306a36Sopenharmony_ci		goto exit_unlock;
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci	/* Set interrupt polarity */
19362306a36Sopenharmony_ci	ret = regmap_update_bits(ws16c48gpio->map, WS16C48_POL + idx, irq_data->mask, polarity);
19462306a36Sopenharmony_ci	if (ret)
19562306a36Sopenharmony_ci		goto exit_unlock;
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	ret = regmap_write(ws16c48gpio->map, WS16C48_PAGE_LOCK, INT_ID_PAGE);
19862306a36Sopenharmony_ci	if (ret)
19962306a36Sopenharmony_ci		goto exit_unlock;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ciexit_unlock:
20262306a36Sopenharmony_ci	raw_spin_unlock_irqrestore(&ws16c48gpio->lock, flags);
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci	return ret;
20562306a36Sopenharmony_ci}
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci#define WS16C48_NGPIO 48
20862306a36Sopenharmony_cistatic const char *ws16c48_names[WS16C48_NGPIO] = {
20962306a36Sopenharmony_ci	"Port 0 Bit 0", "Port 0 Bit 1", "Port 0 Bit 2", "Port 0 Bit 3",
21062306a36Sopenharmony_ci	"Port 0 Bit 4", "Port 0 Bit 5", "Port 0 Bit 6", "Port 0 Bit 7",
21162306a36Sopenharmony_ci	"Port 1 Bit 0", "Port 1 Bit 1", "Port 1 Bit 2", "Port 1 Bit 3",
21262306a36Sopenharmony_ci	"Port 1 Bit 4", "Port 1 Bit 5", "Port 1 Bit 6", "Port 1 Bit 7",
21362306a36Sopenharmony_ci	"Port 2 Bit 0", "Port 2 Bit 1", "Port 2 Bit 2", "Port 2 Bit 3",
21462306a36Sopenharmony_ci	"Port 2 Bit 4", "Port 2 Bit 5", "Port 2 Bit 6", "Port 2 Bit 7",
21562306a36Sopenharmony_ci	"Port 3 Bit 0", "Port 3 Bit 1", "Port 3 Bit 2", "Port 3 Bit 3",
21662306a36Sopenharmony_ci	"Port 3 Bit 4", "Port 3 Bit 5", "Port 3 Bit 6", "Port 3 Bit 7",
21762306a36Sopenharmony_ci	"Port 4 Bit 0", "Port 4 Bit 1", "Port 4 Bit 2", "Port 4 Bit 3",
21862306a36Sopenharmony_ci	"Port 4 Bit 4", "Port 4 Bit 5", "Port 4 Bit 6", "Port 4 Bit 7",
21962306a36Sopenharmony_ci	"Port 5 Bit 0", "Port 5 Bit 1", "Port 5 Bit 2", "Port 5 Bit 3",
22062306a36Sopenharmony_ci	"Port 5 Bit 4", "Port 5 Bit 5", "Port 5 Bit 6", "Port 5 Bit 7"
22162306a36Sopenharmony_ci};
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_cistatic int ws16c48_irq_init_hw(struct regmap *const map)
22462306a36Sopenharmony_ci{
22562306a36Sopenharmony_ci	int err;
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci	err = regmap_write(map, WS16C48_PAGE_LOCK, ENAB_PAGE);
22862306a36Sopenharmony_ci	if (err)
22962306a36Sopenharmony_ci		return err;
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	/* Disable interrupts for all lines */
23262306a36Sopenharmony_ci	err = regmap_write(map, WS16C48_ENAB + 0, 0x00);
23362306a36Sopenharmony_ci	if (err)
23462306a36Sopenharmony_ci		return err;
23562306a36Sopenharmony_ci	err = regmap_write(map, WS16C48_ENAB + 1, 0x00);
23662306a36Sopenharmony_ci	if (err)
23762306a36Sopenharmony_ci		return err;
23862306a36Sopenharmony_ci	err = regmap_write(map, WS16C48_ENAB + 2, 0x00);
23962306a36Sopenharmony_ci	if (err)
24062306a36Sopenharmony_ci		return err;
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	return regmap_write(map, WS16C48_PAGE_LOCK, INT_ID_PAGE);
24362306a36Sopenharmony_ci}
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_cistatic int ws16c48_probe(struct device *dev, unsigned int id)
24662306a36Sopenharmony_ci{
24762306a36Sopenharmony_ci	struct ws16c48_gpio *ws16c48gpio;
24862306a36Sopenharmony_ci	const char *const name = dev_name(dev);
24962306a36Sopenharmony_ci	int err;
25062306a36Sopenharmony_ci	struct gpio_regmap_config gpio_config = {};
25162306a36Sopenharmony_ci	void __iomem *regs;
25262306a36Sopenharmony_ci	struct regmap_irq_chip *chip;
25362306a36Sopenharmony_ci	struct regmap_irq_chip_data *chip_data;
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	ws16c48gpio = devm_kzalloc(dev, sizeof(*ws16c48gpio), GFP_KERNEL);
25662306a36Sopenharmony_ci	if (!ws16c48gpio)
25762306a36Sopenharmony_ci		return -ENOMEM;
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	if (!devm_request_region(dev, base[id], WS16C48_EXTENT, name)) {
26062306a36Sopenharmony_ci		dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
26162306a36Sopenharmony_ci			base[id], base[id] + WS16C48_EXTENT);
26262306a36Sopenharmony_ci		return -EBUSY;
26362306a36Sopenharmony_ci	}
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci	regs = devm_ioport_map(dev, base[id], WS16C48_EXTENT);
26662306a36Sopenharmony_ci	if (!regs)
26762306a36Sopenharmony_ci		return -ENOMEM;
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci	ws16c48gpio->map = devm_regmap_init_mmio(dev, regs, &ws16c48_regmap_config);
27062306a36Sopenharmony_ci	if (IS_ERR(ws16c48gpio->map))
27162306a36Sopenharmony_ci		return dev_err_probe(dev, PTR_ERR(ws16c48gpio->map),
27262306a36Sopenharmony_ci				     "Unable to initialize register map\n");
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
27562306a36Sopenharmony_ci	if (!chip)
27662306a36Sopenharmony_ci		return -ENOMEM;
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci	chip->name = name;
27962306a36Sopenharmony_ci	chip->status_base = WS16C48_INT_ID;
28062306a36Sopenharmony_ci	chip->mask_base = WS16C48_ENAB;
28162306a36Sopenharmony_ci	chip->ack_base = WS16C48_INT_ID;
28262306a36Sopenharmony_ci	chip->num_regs = 3;
28362306a36Sopenharmony_ci	chip->irqs = ws16c48_regmap_irqs;
28462306a36Sopenharmony_ci	chip->num_irqs = ARRAY_SIZE(ws16c48_regmap_irqs);
28562306a36Sopenharmony_ci	chip->handle_pre_irq = ws16c48_handle_pre_irq;
28662306a36Sopenharmony_ci	chip->handle_post_irq = ws16c48_handle_post_irq;
28762306a36Sopenharmony_ci	chip->handle_mask_sync = ws16c48_handle_mask_sync;
28862306a36Sopenharmony_ci	chip->set_type_config = ws16c48_set_type_config;
28962306a36Sopenharmony_ci	chip->irq_drv_data = ws16c48gpio;
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci	raw_spin_lock_init(&ws16c48gpio->lock);
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	/* Initialize to prevent spurious interrupts before we're ready */
29462306a36Sopenharmony_ci	err = ws16c48_irq_init_hw(ws16c48gpio->map);
29562306a36Sopenharmony_ci	if (err)
29662306a36Sopenharmony_ci		return err;
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci	err = devm_regmap_add_irq_chip(dev, ws16c48gpio->map, irq[id], 0, 0, chip, &chip_data);
29962306a36Sopenharmony_ci	if (err)
30062306a36Sopenharmony_ci		return dev_err_probe(dev, err, "IRQ registration failed\n");
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci	gpio_config.parent = dev;
30362306a36Sopenharmony_ci	gpio_config.regmap = ws16c48gpio->map;
30462306a36Sopenharmony_ci	gpio_config.ngpio = WS16C48_NGPIO;
30562306a36Sopenharmony_ci	gpio_config.names = ws16c48_names;
30662306a36Sopenharmony_ci	gpio_config.reg_dat_base = GPIO_REGMAP_ADDR(WS16C48_DAT_BASE);
30762306a36Sopenharmony_ci	gpio_config.reg_set_base = GPIO_REGMAP_ADDR(WS16C48_DAT_BASE);
30862306a36Sopenharmony_ci	/* Setting a GPIO to 0 allows it to be used as an input */
30962306a36Sopenharmony_ci	gpio_config.reg_dir_out_base = GPIO_REGMAP_ADDR(WS16C48_DAT_BASE);
31062306a36Sopenharmony_ci	gpio_config.ngpio_per_reg = WS16C48_NGPIO_PER_REG;
31162306a36Sopenharmony_ci	gpio_config.irq_domain = regmap_irq_get_domain(chip_data);
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci	return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config));
31462306a36Sopenharmony_ci}
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_cistatic struct isa_driver ws16c48_driver = {
31762306a36Sopenharmony_ci	.probe = ws16c48_probe,
31862306a36Sopenharmony_ci	.driver = {
31962306a36Sopenharmony_ci		.name = "ws16c48"
32062306a36Sopenharmony_ci	},
32162306a36Sopenharmony_ci};
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cimodule_isa_driver_with_irq(ws16c48_driver, num_ws16c48, num_irq);
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ciMODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
32662306a36Sopenharmony_ciMODULE_DESCRIPTION("WinSystems WS16C48 GPIO driver");
32762306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
328