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