xref: /openbmc/linux/drivers/mfd/simple-mfd-i2c.c (revision 3abee4579484c554961bb0af92a77adc0ebd791d)
1*3abee457SMichael Walle // SPDX-License-Identifier: GPL-2.0-only
2*3abee457SMichael Walle /*
3*3abee457SMichael Walle  * Simple MFD - I2C
4*3abee457SMichael Walle  *
5*3abee457SMichael Walle  * This driver creates a single register map with the intention for it to be
6*3abee457SMichael Walle  * shared by all sub-devices.  Children can use their parent's device structure
7*3abee457SMichael Walle  * (dev.parent) in order to reference it.
8*3abee457SMichael Walle  *
9*3abee457SMichael Walle  * Once the register map has been successfully initialised, any sub-devices
10*3abee457SMichael Walle  * represented by child nodes in Device Tree will be subsequently registered.
11*3abee457SMichael Walle  */
12*3abee457SMichael Walle 
13*3abee457SMichael Walle #include <linux/i2c.h>
14*3abee457SMichael Walle #include <linux/kernel.h>
15*3abee457SMichael Walle #include <linux/module.h>
16*3abee457SMichael Walle #include <linux/of_platform.h>
17*3abee457SMichael Walle #include <linux/regmap.h>
18*3abee457SMichael Walle 
19*3abee457SMichael Walle static const struct regmap_config simple_regmap_config = {
20*3abee457SMichael Walle 	.reg_bits = 8,
21*3abee457SMichael Walle 	.val_bits = 8,
22*3abee457SMichael Walle };
23*3abee457SMichael Walle 
24*3abee457SMichael Walle static int simple_mfd_i2c_probe(struct i2c_client *i2c)
25*3abee457SMichael Walle {
26*3abee457SMichael Walle 	const struct regmap_config *config;
27*3abee457SMichael Walle 	struct regmap *regmap;
28*3abee457SMichael Walle 
29*3abee457SMichael Walle 	config = device_get_match_data(&i2c->dev);
30*3abee457SMichael Walle 	if (!config)
31*3abee457SMichael Walle 		config = &simple_regmap_config;
32*3abee457SMichael Walle 
33*3abee457SMichael Walle 	regmap = devm_regmap_init_i2c(i2c, config);
34*3abee457SMichael Walle 	if (IS_ERR(regmap))
35*3abee457SMichael Walle 		return PTR_ERR(regmap);
36*3abee457SMichael Walle 
37*3abee457SMichael Walle 	return devm_of_platform_populate(&i2c->dev);
38*3abee457SMichael Walle }
39*3abee457SMichael Walle 
40*3abee457SMichael Walle static const struct of_device_id simple_mfd_i2c_of_match[] = {
41*3abee457SMichael Walle 	{}
42*3abee457SMichael Walle };
43*3abee457SMichael Walle MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
44*3abee457SMichael Walle 
45*3abee457SMichael Walle static struct i2c_driver simple_mfd_i2c_driver = {
46*3abee457SMichael Walle 	.probe_new = simple_mfd_i2c_probe,
47*3abee457SMichael Walle 	.driver = {
48*3abee457SMichael Walle 		.name = "simple-mfd-i2c",
49*3abee457SMichael Walle 		.of_match_table = simple_mfd_i2c_of_match,
50*3abee457SMichael Walle 	},
51*3abee457SMichael Walle };
52*3abee457SMichael Walle module_i2c_driver(simple_mfd_i2c_driver);
53*3abee457SMichael Walle 
54*3abee457SMichael Walle MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
55*3abee457SMichael Walle MODULE_DESCRIPTION("Simple MFD - I2C driver");
56*3abee457SMichael Walle MODULE_LICENSE("GPL v2");
57