13abee457SMichael Walle // SPDX-License-Identifier: GPL-2.0-only 23abee457SMichael Walle /* 33abee457SMichael Walle * Simple MFD - I2C 43abee457SMichael Walle * 5*c753ea31SLee Jones * Author(s): 6*c753ea31SLee Jones * Michael Walle <michael@walle.cc> 7*c753ea31SLee Jones * Lee Jones <lee.jones@linaro.org> 8*c753ea31SLee Jones * 93abee457SMichael Walle * This driver creates a single register map with the intention for it to be 103abee457SMichael Walle * shared by all sub-devices. Children can use their parent's device structure 113abee457SMichael Walle * (dev.parent) in order to reference it. 123abee457SMichael Walle * 133abee457SMichael Walle * Once the register map has been successfully initialised, any sub-devices 14*c753ea31SLee Jones * represented by child nodes in Device Tree or via the MFD cells in this file 15*c753ea31SLee Jones * will be subsequently registered. 163abee457SMichael Walle */ 173abee457SMichael Walle 183abee457SMichael Walle #include <linux/i2c.h> 193abee457SMichael Walle #include <linux/kernel.h> 20*c753ea31SLee Jones #include <linux/mfd/core.h> 213abee457SMichael Walle #include <linux/module.h> 223abee457SMichael Walle #include <linux/of_platform.h> 233abee457SMichael Walle #include <linux/regmap.h> 243abee457SMichael Walle 25*c753ea31SLee Jones #include "simple-mfd-i2c.h" 26*c753ea31SLee Jones 27*c753ea31SLee Jones static const struct regmap_config regmap_config_8r_8v = { 283abee457SMichael Walle .reg_bits = 8, 293abee457SMichael Walle .val_bits = 8, 303abee457SMichael Walle }; 313abee457SMichael Walle 323abee457SMichael Walle static int simple_mfd_i2c_probe(struct i2c_client *i2c) 333abee457SMichael Walle { 34*c753ea31SLee Jones const struct simple_mfd_data *simple_mfd_data; 35*c753ea31SLee Jones const struct regmap_config *regmap_config; 363abee457SMichael Walle struct regmap *regmap; 37*c753ea31SLee Jones int ret; 383abee457SMichael Walle 39*c753ea31SLee Jones simple_mfd_data = device_get_match_data(&i2c->dev); 403abee457SMichael Walle 41*c753ea31SLee Jones /* If no regmap_config is specified, use the default 8reg and 8val bits */ 42*c753ea31SLee Jones if (!simple_mfd_data || !simple_mfd_data->regmap_config) 43*c753ea31SLee Jones regmap_config = ®map_config_8r_8v; 44*c753ea31SLee Jones else 45*c753ea31SLee Jones regmap_config = simple_mfd_data->regmap_config; 46*c753ea31SLee Jones 47*c753ea31SLee Jones regmap = devm_regmap_init_i2c(i2c, regmap_config); 483abee457SMichael Walle if (IS_ERR(regmap)) 493abee457SMichael Walle return PTR_ERR(regmap); 503abee457SMichael Walle 51*c753ea31SLee Jones /* If no MFD cells are spedified, use register the DT child nodes instead */ 52*c753ea31SLee Jones if (!simple_mfd_data || !simple_mfd_data->mfd_cell) 533abee457SMichael Walle return devm_of_platform_populate(&i2c->dev); 54*c753ea31SLee Jones 55*c753ea31SLee Jones ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, 56*c753ea31SLee Jones simple_mfd_data->mfd_cell, 57*c753ea31SLee Jones simple_mfd_data->mfd_cell_size, 58*c753ea31SLee Jones NULL, 0, NULL); 59*c753ea31SLee Jones if (ret) 60*c753ea31SLee Jones dev_err(&i2c->dev, "Failed to add child devices\n"); 61*c753ea31SLee Jones 62*c753ea31SLee Jones return ret; 633abee457SMichael Walle } 643abee457SMichael Walle 653abee457SMichael Walle static const struct of_device_id simple_mfd_i2c_of_match[] = { 66a538ad22SMichael Walle { .compatible = "kontron,sl28cpld" }, 673abee457SMichael Walle {} 683abee457SMichael Walle }; 693abee457SMichael Walle MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match); 703abee457SMichael Walle 713abee457SMichael Walle static struct i2c_driver simple_mfd_i2c_driver = { 723abee457SMichael Walle .probe_new = simple_mfd_i2c_probe, 733abee457SMichael Walle .driver = { 743abee457SMichael Walle .name = "simple-mfd-i2c", 753abee457SMichael Walle .of_match_table = simple_mfd_i2c_of_match, 763abee457SMichael Walle }, 773abee457SMichael Walle }; 783abee457SMichael Walle module_i2c_driver(simple_mfd_i2c_driver); 793abee457SMichael Walle 803abee457SMichael Walle MODULE_AUTHOR("Michael Walle <michael@walle.cc>"); 813abee457SMichael Walle MODULE_DESCRIPTION("Simple MFD - I2C driver"); 823abee457SMichael Walle MODULE_LICENSE("GPL v2"); 83