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