Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Simple MFD - I2C
0004  *
0005  * Author(s):
0006  *  Michael Walle <michael@walle.cc>
0007  *  Lee Jones <lee.jones@linaro.org>
0008  *
0009  * This driver creates a single register map with the intention for it to be
0010  * shared by all sub-devices.  Children can use their parent's device structure
0011  * (dev.parent) in order to reference it.
0012  *
0013  * Once the register map has been successfully initialised, any sub-devices
0014  * represented by child nodes in Device Tree or via the MFD cells in this file
0015  * will be subsequently registered.
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     /* If no regmap_config is specified, use the default 8reg and 8val bits */
0042     if (!simple_mfd_data || !simple_mfd_data->regmap_config)
0043         regmap_config = &regmap_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     /* If no MFD cells are spedified, use register the DT child nodes instead */
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");