mc13xxx-i2c.c 2.8 KB

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