13abee457SMichael Walle // SPDX-License-Identifier: GPL-2.0-only 23abee457SMichael Walle /* 33abee457SMichael Walle * Simple MFD - I2C 43abee457SMichael Walle * 53abee457SMichael Walle * This driver creates a single register map with the intention for it to be 63abee457SMichael Walle * shared by all sub-devices. Children can use their parent's device structure 73abee457SMichael Walle * (dev.parent) in order to reference it. 83abee457SMichael Walle * 93abee457SMichael Walle * Once the register map has been successfully initialised, any sub-devices 103abee457SMichael Walle * represented by child nodes in Device Tree will be subsequently registered. 113abee457SMichael Walle */ 123abee457SMichael Walle 133abee457SMichael Walle #include <linux/i2c.h> 143abee457SMichael Walle #include <linux/kernel.h> 153abee457SMichael Walle #include <linux/module.h> 163abee457SMichael Walle #include <linux/of_platform.h> 173abee457SMichael Walle #include <linux/regmap.h> 183abee457SMichael Walle 193abee457SMichael Walle static const struct regmap_config simple_regmap_config = { 203abee457SMichael Walle .reg_bits = 8, 213abee457SMichael Walle .val_bits = 8, 223abee457SMichael Walle }; 233abee457SMichael Walle 243abee457SMichael Walle static int simple_mfd_i2c_probe(struct i2c_client *i2c) 253abee457SMichael Walle { 263abee457SMichael Walle const struct regmap_config *config; 273abee457SMichael Walle struct regmap *regmap; 283abee457SMichael Walle 293abee457SMichael Walle config = device_get_match_data(&i2c->dev); 303abee457SMichael Walle if (!config) 313abee457SMichael Walle config = &simple_regmap_config; 323abee457SMichael Walle 333abee457SMichael Walle regmap = devm_regmap_init_i2c(i2c, config); 343abee457SMichael Walle if (IS_ERR(regmap)) 353abee457SMichael Walle return PTR_ERR(regmap); 363abee457SMichael Walle 373abee457SMichael Walle return devm_of_platform_populate(&i2c->dev); 383abee457SMichael Walle } 393abee457SMichael Walle 403abee457SMichael Walle static const struct of_device_id simple_mfd_i2c_of_match[] = { 41*a538ad22SMichael Walle { .compatible = "kontron,sl28cpld" }, 423abee457SMichael Walle {} 433abee457SMichael Walle }; 443abee457SMichael Walle MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match); 453abee457SMichael Walle 463abee457SMichael Walle static struct i2c_driver simple_mfd_i2c_driver = { 473abee457SMichael Walle .probe_new = simple_mfd_i2c_probe, 483abee457SMichael Walle .driver = { 493abee457SMichael Walle .name = "simple-mfd-i2c", 503abee457SMichael Walle .of_match_table = simple_mfd_i2c_of_match, 513abee457SMichael Walle }, 523abee457SMichael Walle }; 533abee457SMichael Walle module_i2c_driver(simple_mfd_i2c_driver); 543abee457SMichael Walle 553abee457SMichael Walle MODULE_AUTHOR("Michael Walle <michael@walle.cc>"); 563abee457SMichael Walle MODULE_DESCRIPTION("Simple MFD - I2C driver"); 573abee457SMichael Walle MODULE_LICENSE("GPL v2"); 58