1 // SPDX-License-Identifier: GPL-2.0-only
6 * Michael Walle <michael@walle.cc>
7 * Lee Jones <lee.jones@linaro.org>
9 * This driver creates a single register map with the intention for it to be
10 * shared by all sub-devices. Children can use their parent's device structure
11 * (dev.parent) in order to reference it.
13 * Once the register map has been successfully initialised, any sub-devices
14 * represented by child nodes in Device Tree or via the MFD cells in this file
15 * will be subsequently registered.
18 #include <linux/i2c.h>
19 #include <linux/kernel.h>
20 #include <linux/mfd/core.h>
21 #include <linux/module.h>
22 #include <linux/of_platform.h>
23 #include <linux/regmap.h>
25 #include "simple-mfd-i2c.h"
27 static const struct regmap_config regmap_config_8r_8v = {
32 static const struct regmap_config regmap_config_16r_8v = {
37 static const struct simple_mfd_data rpi_poe_core = {
38 .regmap_config = ®map_config_16r_8v,
41 static int simple_mfd_i2c_probe(struct i2c_client *i2c)
43 const struct simple_mfd_data *simple_mfd_data;
44 const struct regmap_config *regmap_config;
45 struct regmap *regmap;
48 simple_mfd_data = device_get_match_data(&i2c->dev);
50 /* If no regmap_config is specified, use the default 8reg and 8val bits */
51 if (!simple_mfd_data || !simple_mfd_data->regmap_config)
52 regmap_config = ®map_config_8r_8v;
54 regmap_config = simple_mfd_data->regmap_config;
56 regmap = devm_regmap_init_i2c(i2c, regmap_config);
58 return PTR_ERR(regmap);
60 /* If no MFD cells are specified, register using the DT child nodes instead */
61 if (!simple_mfd_data || !simple_mfd_data->mfd_cell)
62 return devm_of_platform_populate(&i2c->dev);
64 ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
65 simple_mfd_data->mfd_cell,
66 simple_mfd_data->mfd_cell_size,
69 dev_err(&i2c->dev, "Failed to add child devices\n");
74 static const struct mfd_cell sy7636a_cells[] = {
75 { .name = "sy7636a-regulator", },
76 { .name = "sy7636a-temperature", },
79 static const struct simple_mfd_data silergy_sy7636a = {
80 .mfd_cell = sy7636a_cells,
81 .mfd_cell_size = ARRAY_SIZE(sy7636a_cells),
84 static const struct mfd_cell max5970_cells[] = {
85 { .name = "max5970-regulator", },
86 { .name = "max5970-iio", },
87 { .name = "max5970-led", },
90 static const struct simple_mfd_data maxim_max5970 = {
91 .mfd_cell = max5970_cells,
92 .mfd_cell_size = ARRAY_SIZE(max5970_cells),
95 static const struct of_device_id simple_mfd_i2c_of_match[] = {
96 { .compatible = "kontron,sl28cpld" },
97 { .compatible = "silergy,sy7636a", .data = &silergy_sy7636a},
98 { .compatible = "maxim,max5970", .data = &maxim_max5970},
99 { .compatible = "maxim,max5978", .data = &maxim_max5970},
100 { .compatible = "raspberrypi,poe-core", &rpi_poe_core },
103 MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
105 static struct i2c_driver simple_mfd_i2c_driver = {
106 .probe = simple_mfd_i2c_probe,
108 .name = "simple-mfd-i2c",
109 .of_match_table = simple_mfd_i2c_of_match,
112 module_i2c_driver(simple_mfd_i2c_driver);
114 MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
115 MODULE_DESCRIPTION("Simple MFD - I2C driver");
116 MODULE_LICENSE("GPL v2");