simple-mfd-i2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include <linux/i2c.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/regmap.h>
  17. static const struct regmap_config simple_regmap_config = {
  18. .reg_bits = 8,
  19. .val_bits = 8,
  20. };
  21. static int simple_mfd_i2c_probe(struct i2c_client *i2c)
  22. {
  23. const struct regmap_config *config;
  24. struct regmap *regmap;
  25. config = device_get_match_data(&i2c->dev);
  26. if (!config)
  27. config = &simple_regmap_config;
  28. regmap = devm_regmap_init_i2c(i2c, config);
  29. if (IS_ERR(regmap))
  30. return PTR_ERR(regmap);
  31. return devm_of_platform_populate(&i2c->dev);
  32. }
  33. static const struct of_device_id simple_mfd_i2c_of_match[] = {
  34. { .compatible = "kontron,sl28cpld" },
  35. {}
  36. };
  37. MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
  38. static struct i2c_driver simple_mfd_i2c_driver = {
  39. .probe_new = simple_mfd_i2c_probe,
  40. .driver = {
  41. .name = "simple-mfd-i2c",
  42. .of_match_table = simple_mfd_i2c_of_match,
  43. },
  44. };
  45. module_i2c_driver(simple_mfd_i2c_driver);
  46. MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
  47. MODULE_DESCRIPTION("Simple MFD - I2C driver");
  48. MODULE_LICENSE("GPL v2");