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, const struct i2c_device_id *id)
13 struct device *dev = &client->dev;
14 unsigned int type = id->driver_data;
18 mcp = devm_kzalloc(dev, sizeof(*mcp), GFP_KERNEL);
24 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x08_regmap);
27 mcp->chip.label = "mcp23008";
31 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
34 mcp->chip.label = "mcp23017";
38 mcp->regmap = devm_regmap_init_i2c(client, &mcp23x17_regmap);
41 mcp->chip.label = "mcp23018";
45 dev_err(dev, "invalid device type (%d)\n", type);
49 if (IS_ERR(mcp->regmap))
50 return PTR_ERR(mcp->regmap);
52 mcp->irq = client->irq;
53 mcp->pinctrl_desc.name = "mcp23xxx-pinctrl";
55 ret = mcp23s08_probe_one(mcp, dev, client->addr, type, -1);
59 i2c_set_clientdata(client, mcp);
64 static const struct i2c_device_id mcp230xx_id[] = {
65 { "mcp23008", MCP_TYPE_008 },
66 { "mcp23017", MCP_TYPE_017 },
67 { "mcp23018", MCP_TYPE_018 },
70 MODULE_DEVICE_TABLE(i2c, mcp230xx_id);
72 static const struct of_device_id mcp23s08_i2c_of_match[] = {
74 .compatible = "microchip,mcp23008",
75 .data = (void *) MCP_TYPE_008,
78 .compatible = "microchip,mcp23017",
79 .data = (void *) MCP_TYPE_017,
82 .compatible = "microchip,mcp23018",
83 .data = (void *) MCP_TYPE_018,
85 /* NOTE: The use of the mcp prefix is deprecated and will be removed. */
87 .compatible = "mcp,mcp23008",
88 .data = (void *) MCP_TYPE_008,
91 .compatible = "mcp,mcp23017",
92 .data = (void *) MCP_TYPE_017,
96 MODULE_DEVICE_TABLE(of, mcp23s08_i2c_of_match);
98 static struct i2c_driver mcp230xx_driver = {
101 .of_match_table = mcp23s08_i2c_of_match,
103 .probe = mcp230xx_probe,
104 .id_table = mcp230xx_id,
107 static int __init mcp23s08_i2c_init(void)
109 return i2c_add_driver(&mcp230xx_driver);
113 * Register after I²C postcore initcall and before
114 * subsys initcalls that may rely on these GPIOs.
116 subsys_initcall(mcp23s08_i2c_init);
118 static void mcp23s08_i2c_exit(void)
120 i2c_del_driver(&mcp230xx_driver);
122 module_exit(mcp23s08_i2c_exit);
124 MODULE_LICENSE("GPL");