1 // SPDX-License-Identifier: GPL-2.0-only
2 /* MCP23S08 I2C GPIO driver */
5 #include <linux/mod_devicetable.h>
6 #include <linux/module.h>
7 #include <linux/regmap.h>
9 #include "pinctrl-mcp23s08.h"
11 static int mcp230xx_probe(struct i2c_client *client)
13 const struct i2c_device_id *id = i2c_client_get_device_id(client);
14 struct device *dev = &client->dev;
15 unsigned int type = id->driver_data;
19 mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL);
25 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x08_regmap);
28 mcp->chip.label = "mcp23008";
32 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
35 mcp->chip.label = "mcp23017";
39 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
42 mcp->chip.label = "mcp23018";
46 dev_err(dev, "invalid device type (%d)\n", type);
50 if (IS_ERR(mcp->regmap))
51 return PTR_ERR(mcp->regmap);
53 mcp->irq = client->irq;
54 mcp->pinctrl_desc.name = "mcp23xxx-pinctrl";
56 ret = mcp23s08_probe_one(mcp, dev, client->addr, type, -1);
60 i2c_set_clientdata(client, mcp);
65 static const struct i2c_device_id mcp230xx_id[] = {
66 { "mcp23008", MCP_TYPE_008 },
67 { "mcp23017", MCP_TYPE_017 },
68 { "mcp23018", MCP_TYPE_018 },
71 MODULE_DEVICE_TABLE(i2c, mcp230xx_id);
73 static const struct of_device_id mcp23s08_i2c_of_match[] = {
75 .compatible = "microchip,mcp23008",
76 .data = (void *) MCP_TYPE_008,
79 .compatible = "microchip,mcp23017",
80 .data = (void *) MCP_TYPE_017,
83 .compatible = "microchip,mcp23018",
84 .data = (void *) MCP_TYPE_018,
86 /* NOTE: The use of the mcp prefix is deprecated and will be removed. */
88 .compatible = "mcp,mcp23008",
89 .data = (void *) MCP_TYPE_008,
92 .compatible = "mcp,mcp23017",
93 .data = (void *) MCP_TYPE_017,
97 MODULE_DEVICE_TABLE(of, mcp23s08_i2c_of_match);
99 static struct i2c_driver mcp230xx_driver = {
102 .of_match_table = mcp23s08_i2c_of_match,
104 .probe = mcp230xx_probe,
105 .id_table = mcp230xx_id,
108 static int __init mcp23s08_i2c_init(void)
110 return i2c_add_driver(&mcp230xx_driver);
114 * Register after I²C postcore initcall and before
115 * subsys initcalls that may rely on these GPIOs.
117 subsys_initcall(mcp23s08_i2c_init);
119 static void mcp23s08_i2c_exit(void)
121 i2c_del_driver(&mcp230xx_driver);
123 module_exit(mcp23s08_i2c_exit);
125 MODULE_LICENSE("GPL");