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 mcp23s08_info
*info
;
14 struct device
*dev
= &client
->dev
;
18 mcp
= devm_kzalloc(dev
, sizeof(*mcp
), GFP_KERNEL
);
22 info
= i2c_get_match_data(client
);
24 return dev_err_probe(dev
, -EINVAL
, "invalid device type\n");
26 mcp
->reg_shift
= info
->reg_shift
;
27 mcp
->chip
.ngpio
= info
->ngpio
;
28 mcp
->chip
.label
= info
->label
;
29 mcp
->regmap
= devm_regmap_init_i2c(client
, info
->regmap
);
30 if (IS_ERR(mcp
->regmap
))
31 return PTR_ERR(mcp
->regmap
);
33 mcp
->irq
= client
->irq
;
34 mcp
->pinctrl_desc
.name
= "mcp23xxx-pinctrl";
36 ret
= mcp23s08_probe_one(mcp
, dev
, client
->addr
, info
->type
, -1);
40 i2c_set_clientdata(client
, mcp
);
45 static const struct mcp23s08_info mcp23008_i2c
= {
46 .regmap
= &mcp23x08_regmap
,
53 static const struct mcp23s08_info mcp23017_i2c
= {
54 .regmap
= &mcp23x17_regmap
,
61 static const struct mcp23s08_info mcp23018_i2c
= {
62 .regmap
= &mcp23x17_regmap
,
69 static const struct i2c_device_id mcp230xx_id
[] = {
70 { "mcp23008", (kernel_ulong_t
)&mcp23008_i2c
},
71 { "mcp23017", (kernel_ulong_t
)&mcp23017_i2c
},
72 { "mcp23018", (kernel_ulong_t
)&mcp23018_i2c
},
75 MODULE_DEVICE_TABLE(i2c
, mcp230xx_id
);
77 static const struct of_device_id mcp23s08_i2c_of_match
[] = {
78 { .compatible
= "microchip,mcp23008", .data
= &mcp23008_i2c
},
79 { .compatible
= "microchip,mcp23017", .data
= &mcp23017_i2c
},
80 { .compatible
= "microchip,mcp23018", .data
= &mcp23018_i2c
},
81 /* NOTE: The use of the mcp prefix is deprecated and will be removed. */
82 { .compatible
= "mcp,mcp23008", .data
= &mcp23008_i2c
},
83 { .compatible
= "mcp,mcp23017", .data
= &mcp23017_i2c
},
86 MODULE_DEVICE_TABLE(of
, mcp23s08_i2c_of_match
);
88 static struct i2c_driver mcp230xx_driver
= {
91 .of_match_table
= mcp23s08_i2c_of_match
,
93 .probe
= mcp230xx_probe
,
94 .id_table
= mcp230xx_id
,
97 static int __init
mcp23s08_i2c_init(void)
99 return i2c_add_driver(&mcp230xx_driver
);
103 * Register after I²C postcore initcall and before
104 * subsys initcalls that may rely on these GPIOs.
106 subsys_initcall(mcp23s08_i2c_init
);
108 static void mcp23s08_i2c_exit(void)
110 i2c_del_driver(&mcp230xx_driver
);
112 module_exit(mcp23s08_i2c_exit
);
114 MODULE_DESCRIPTION("MCP23S08 I2C GPIO driver");
115 MODULE_LICENSE("GPL");