1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2023 Analog Devices, Inc.
4 * Driver for the DS4520 I/O Expander
7 #include <linux/device.h>
8 #include <linux/gpio/driver.h>
9 #include <linux/gpio/regmap.h>
10 #include <linux/i2c.h>
11 #include <linux/property.h>
12 #include <linux/regmap.h>
14 #define DS4520_PULLUP0 0xF0
15 #define DS4520_IO_CONTROL0 0xF2
16 #define DS4520_IO_STATUS0 0xF8
18 static const struct regmap_config ds4520_regmap_config = {
23 static int ds4520_gpio_probe(struct i2c_client *client)
25 struct gpio_regmap_config config = { };
26 struct device *dev = &client->dev;
27 struct regmap *regmap;
32 ret = device_property_read_u32(dev, "reg", &base);
34 return dev_err_probe(dev, ret, "Missing 'reg' property.\n");
36 ret = device_property_read_u32(dev, "ngpios", &ngpio);
38 return dev_err_probe(dev, ret, "Missing 'ngpios' property.\n");
40 regmap = devm_regmap_init_i2c(client, &ds4520_regmap_config);
42 return dev_err_probe(dev, PTR_ERR(regmap),
43 "Failed to allocate register map\n");
45 config.regmap = regmap;
49 config.reg_dat_base = base + DS4520_IO_STATUS0;
50 config.reg_set_base = base + DS4520_PULLUP0;
51 config.reg_dir_out_base = base + DS4520_IO_CONTROL0;
53 return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &config));
56 static const struct of_device_id ds4520_gpio_of_match_table[] = {
57 { .compatible = "adi,ds4520-gpio" },
60 MODULE_DEVICE_TABLE(of, ds4520_gpio_of_match_table);
62 static const struct i2c_device_id ds4520_gpio_id_table[] = {
66 MODULE_DEVICE_TABLE(i2c, ds4520_gpio_id_table);
68 static struct i2c_driver ds4520_gpio_driver = {
70 .name = "ds4520-gpio",
71 .of_match_table = ds4520_gpio_of_match_table,
73 .probe = ds4520_gpio_probe,
74 .id_table = ds4520_gpio_id_table,
76 module_i2c_driver(ds4520_gpio_driver);
78 MODULE_DESCRIPTION("DS4520 I/O Expander");
79 MODULE_AUTHOR("Okan Sahin <okan.sahin@analog.com>");
80 MODULE_LICENSE("GPL");