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