0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/i2c.h>
0019 #include <linux/kernel.h>
0020 #include <linux/mfd/core.h>
0021 #include <linux/module.h>
0022 #include <linux/of_platform.h>
0023 #include <linux/regmap.h>
0024
0025 #include "simple-mfd-i2c.h"
0026
0027 static const struct regmap_config regmap_config_8r_8v = {
0028 .reg_bits = 8,
0029 .val_bits = 8,
0030 };
0031
0032 static int simple_mfd_i2c_probe(struct i2c_client *i2c)
0033 {
0034 const struct simple_mfd_data *simple_mfd_data;
0035 const struct regmap_config *regmap_config;
0036 struct regmap *regmap;
0037 int ret;
0038
0039 simple_mfd_data = device_get_match_data(&i2c->dev);
0040
0041
0042 if (!simple_mfd_data || !simple_mfd_data->regmap_config)
0043 regmap_config = ®map_config_8r_8v;
0044 else
0045 regmap_config = simple_mfd_data->regmap_config;
0046
0047 regmap = devm_regmap_init_i2c(i2c, regmap_config);
0048 if (IS_ERR(regmap))
0049 return PTR_ERR(regmap);
0050
0051
0052 if (!simple_mfd_data || !simple_mfd_data->mfd_cell)
0053 return devm_of_platform_populate(&i2c->dev);
0054
0055 ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
0056 simple_mfd_data->mfd_cell,
0057 simple_mfd_data->mfd_cell_size,
0058 NULL, 0, NULL);
0059 if (ret)
0060 dev_err(&i2c->dev, "Failed to add child devices\n");
0061
0062 return ret;
0063 }
0064
0065 static const struct mfd_cell sy7636a_cells[] = {
0066 { .name = "sy7636a-regulator", },
0067 { .name = "sy7636a-temperature", },
0068 };
0069
0070 static const struct simple_mfd_data silergy_sy7636a = {
0071 .mfd_cell = sy7636a_cells,
0072 .mfd_cell_size = ARRAY_SIZE(sy7636a_cells),
0073 };
0074
0075 static const struct of_device_id simple_mfd_i2c_of_match[] = {
0076 { .compatible = "kontron,sl28cpld" },
0077 { .compatible = "silergy,sy7636a", .data = &silergy_sy7636a},
0078 {}
0079 };
0080 MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
0081
0082 static struct i2c_driver simple_mfd_i2c_driver = {
0083 .probe_new = simple_mfd_i2c_probe,
0084 .driver = {
0085 .name = "simple-mfd-i2c",
0086 .of_match_table = simple_mfd_i2c_of_match,
0087 },
0088 };
0089 module_i2c_driver(simple_mfd_i2c_driver);
0090
0091 MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
0092 MODULE_DESCRIPTION("Simple MFD - I2C driver");
0093 MODULE_LICENSE("GPL v2");