File Index
Files and directories
Sign in
FILE

simple-mfd-i2c.c

File preview with syntax highlighting.

linux-6.19.14/drivers/mfd/simple-mfd-i2c.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Simple MFD - I2C
  4 *
  5 * Author(s):
  6 * 	Michael Walle <michael@walle.cc>
  7 * 	Lee Jones <lee.jones@linaro.org>
  8 *
  9 * This driver creates a single register map with the intention for it to be
 10 * shared by all sub-devices.  Children can use their parent's device structure
 11 * (dev.parent) in order to reference it.
 12 *
 13 * Once the register map has been successfully initialised, any sub-devices
 14 * represented by child nodes in Device Tree or via the MFD cells in this file
 15 * will be subsequently registered.
 16 */
 17
 18#include <linux/array_size.h>
 19#include <linux/dev_printk.h>
 20#include <linux/err.h>
 21#include <linux/i2c.h>
 22#include <linux/mfd/core.h>
 23#include <linux/mod_devicetable.h>
 24#include <linux/module.h>
 25#include <linux/of_platform.h>
 26#include <linux/platform_device.h>
 27#include <linux/property.h>
 28#include <linux/regmap.h>
 29#include <linux/stddef.h>
 30
 31#include "simple-mfd-i2c.h"
 32
 33static const struct regmap_config regmap_config_8r_8v = {
 34	.reg_bits = 8,
 35	.val_bits = 8,
 36};
 37
 38static int simple_mfd_i2c_probe(struct i2c_client *i2c)
 39{
 40	const struct simple_mfd_data *simple_mfd_data;
 41	const struct regmap_config *regmap_config;
 42	struct regmap *regmap;
 43	int ret;
 44
 45	simple_mfd_data = device_get_match_data(&i2c->dev);
 46
 47	/* If no regmap_config is specified, use the default 8reg and 8val bits */
 48	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
 49		regmap_config = &regmap_config_8r_8v;
 50	else
 51		regmap_config = simple_mfd_data->regmap_config;
 52
 53	regmap = devm_regmap_init_i2c(i2c, regmap_config);
 54	if (IS_ERR(regmap))
 55		return PTR_ERR(regmap);
 56
 57	/* If no MFD cells are specified, register using the DT child nodes instead */
 58	if (!simple_mfd_data || !simple_mfd_data->mfd_cell)
 59		return devm_of_platform_populate(&i2c->dev);
 60
 61	ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO,
 62				   simple_mfd_data->mfd_cell,
 63				   simple_mfd_data->mfd_cell_size,
 64				   NULL, 0, NULL);
 65	if (ret)
 66		dev_err(&i2c->dev, "Failed to add child devices\n");
 67
 68	return ret;
 69}
 70
 71static const struct mfd_cell sy7636a_cells[] = {
 72	{ .name = "sy7636a-regulator", },
 73	{ .name = "sy7636a-temperature", },
 74};
 75
 76static const struct simple_mfd_data silergy_sy7636a = {
 77	.mfd_cell = sy7636a_cells,
 78	.mfd_cell_size = ARRAY_SIZE(sy7636a_cells),
 79};
 80
 81static const struct mfd_cell max5970_cells[] = {
 82	{ .name = "max5970-regulator", },
 83	{ .name = "max5970-iio", },
 84	{ .name = "max5970-led", },
 85};
 86
 87static const struct simple_mfd_data maxim_max5970 = {
 88	.mfd_cell = max5970_cells,
 89	.mfd_cell_size = ARRAY_SIZE(max5970_cells),
 90};
 91
 92static const struct mfd_cell max77705_sensor_cells[] = {
 93	{ .name = "max77705-battery" },
 94	{ .name = "max77705-hwmon", },
 95};
 96
 97static const struct simple_mfd_data maxim_mon_max77705 = {
 98	.mfd_cell = max77705_sensor_cells,
 99	.mfd_cell_size = ARRAY_SIZE(max77705_sensor_cells),
100};
101
102static const struct regmap_config spacemit_p1_regmap_config = {
103	.reg_bits = 8,
104	.val_bits = 8,
105};
106
107static const struct mfd_cell spacemit_p1_cells[] = {
108	{ .name = "spacemit-p1-regulator", },
109	{ .name = "spacemit-p1-rtc", },
110};
111
112static const struct simple_mfd_data spacemit_p1 = {
113	.regmap_config = &spacemit_p1_regmap_config,
114	.mfd_cell = spacemit_p1_cells,
115	.mfd_cell_size = ARRAY_SIZE(spacemit_p1_cells),
116};
117
118static const struct of_device_id simple_mfd_i2c_of_match[] = {
119	{ .compatible = "delta,tn48m-cpld" },
120	{ .compatible = "fsl,ls1028aqds-fpga" },
121	{ .compatible = "fsl,lx2160aqds-fpga" },
122	{ .compatible = "fsl,lx2160ardb-fpga" },
123	{ .compatible = "kontron,sl28cpld" },
124	{ .compatible = "maxim,max5970", .data = &maxim_max5970 },
125	{ .compatible = "maxim,max5978", .data = &maxim_max5970 },
126	{ .compatible = "maxim,max77705-battery", .data = &maxim_mon_max77705 },
127	{ .compatible = "silergy,sy7636a", .data = &silergy_sy7636a },
128	{ .compatible = "spacemit,p1", .data = &spacemit_p1 },
129	{}
130};
131MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
132
133static struct i2c_driver simple_mfd_i2c_driver = {
134	.probe = simple_mfd_i2c_probe,
135	.driver = {
136		.name = "simple-mfd-i2c",
137		.of_match_table = simple_mfd_i2c_of_match,
138	},
139};
140module_i2c_driver(simple_mfd_i2c_driver);
141
142MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
143MODULE_DESCRIPTION("Simple MFD - I2C driver");
144MODULE_LICENSE("GPL v2");
~/ Read-only file preview.