mc13xxx-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2009-2010 Creative Product Design
  4. * Marc Reilly [email protected]
  5. */
  6. #include <linux/slab.h>
  7. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/mfd/core.h>
  10. #include <linux/mfd/mc13xxx.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/i2c.h>
  15. #include <linux/err.h>
  16. #include "mc13xxx.h"
  17. static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
  18. {
  19. .name = "mc13892",
  20. .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
  21. }, {
  22. .name = "mc34708",
  23. .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
  24. }, {
  25. /* sentinel */
  26. }
  27. };
  28. MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
  29. static const struct of_device_id mc13xxx_dt_ids[] = {
  30. {
  31. .compatible = "fsl,mc13892",
  32. .data = &mc13xxx_variant_mc13892,
  33. }, {
  34. .compatible = "fsl,mc34708",
  35. .data = &mc13xxx_variant_mc34708,
  36. }, {
  37. /* sentinel */
  38. }
  39. };
  40. MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
  41. static const struct regmap_config mc13xxx_regmap_i2c_config = {
  42. .reg_bits = 8,
  43. .val_bits = 24,
  44. .max_register = MC13XXX_NUMREGS,
  45. .cache_type = REGCACHE_NONE,
  46. };
  47. static int mc13xxx_i2c_probe(struct i2c_client *client,
  48. const struct i2c_device_id *id)
  49. {
  50. struct mc13xxx *mc13xxx;
  51. int ret;
  52. mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
  53. if (!mc13xxx)
  54. return -ENOMEM;
  55. dev_set_drvdata(&client->dev, mc13xxx);
  56. mc13xxx->irq = client->irq;
  57. mc13xxx->regmap = devm_regmap_init_i2c(client,
  58. &mc13xxx_regmap_i2c_config);
  59. if (IS_ERR(mc13xxx->regmap)) {
  60. ret = PTR_ERR(mc13xxx->regmap);
  61. dev_err(&client->dev, "Failed to initialize regmap: %d\n", ret);
  62. return ret;
  63. }
  64. if (client->dev.of_node) {
  65. const struct of_device_id *of_id =
  66. of_match_device(mc13xxx_dt_ids, &client->dev);
  67. mc13xxx->variant = of_id->data;
  68. } else {
  69. mc13xxx->variant = (void *)id->driver_data;
  70. }
  71. return mc13xxx_common_init(&client->dev);
  72. }
  73. static void mc13xxx_i2c_remove(struct i2c_client *client)
  74. {
  75. mc13xxx_common_exit(&client->dev);
  76. }
  77. static struct i2c_driver mc13xxx_i2c_driver = {
  78. .id_table = mc13xxx_i2c_device_id,
  79. .driver = {
  80. .name = "mc13xxx",
  81. .of_match_table = mc13xxx_dt_ids,
  82. },
  83. .probe = mc13xxx_i2c_probe,
  84. .remove = mc13xxx_i2c_remove,
  85. };
  86. static int __init mc13xxx_i2c_init(void)
  87. {
  88. return i2c_add_driver(&mc13xxx_i2c_driver);
  89. }
  90. subsys_initcall(mc13xxx_i2c_init);
  91. static void __exit mc13xxx_i2c_exit(void)
  92. {
  93. i2c_del_driver(&mc13xxx_i2c_driver);
  94. }
  95. module_exit(mc13xxx_i2c_exit);
  96. MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
  97. MODULE_AUTHOR("Marc Reilly <[email protected]");
  98. MODULE_LICENSE("GPL v2");