mc13xxx-i2c.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/mutex.h>
  13. #include <linux/mfd/core.h>
  14. #include <linux/mfd/mc13xxx.h>
  15. #include <linux/of.h>
  16. #include <linux/of_device.h>
  17. #include <linux/of_gpio.h>
  18. #include <linux/i2c.h>
  19. #include <linux/err.h>
  20. #include "mc13xxx.h"
  21. static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
  22. {
  23. .name = "mc13892",
  24. .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
  25. }, {
  26. .name = "mc34708",
  27. .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
  28. }, {
  29. /* sentinel */
  30. }
  31. };
  32. MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
  33. static const struct of_device_id mc13xxx_dt_ids[] = {
  34. {
  35. .compatible = "fsl,mc13892",
  36. .data = &mc13xxx_variant_mc13892,
  37. }, {
  38. .compatible = "fsl,mc34708",
  39. .data = &mc13xxx_variant_mc34708,
  40. }, {
  41. /* sentinel */
  42. }
  43. };
  44. MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
  45. static struct regmap_config mc13xxx_regmap_i2c_config = {
  46. .reg_bits = 8,
  47. .val_bits = 24,
  48. .max_register = MC13XXX_NUMREGS,
  49. .cache_type = REGCACHE_NONE,
  50. };
  51. static int mc13xxx_i2c_probe(struct i2c_client *client,
  52. const struct i2c_device_id *id)
  53. {
  54. struct mc13xxx *mc13xxx;
  55. struct mc13xxx_platform_data *pdata = dev_get_platdata(&client->dev);
  56. int ret;
  57. mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
  58. if (!mc13xxx)
  59. return -ENOMEM;
  60. dev_set_drvdata(&client->dev, mc13xxx);
  61. mc13xxx->dev = &client->dev;
  62. mutex_init(&mc13xxx->lock);
  63. mc13xxx->regmap = devm_regmap_init_i2c(client,
  64. &mc13xxx_regmap_i2c_config);
  65. if (IS_ERR(mc13xxx->regmap)) {
  66. ret = PTR_ERR(mc13xxx->regmap);
  67. dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
  68. ret);
  69. return ret;
  70. }
  71. if (client->dev.of_node) {
  72. const struct of_device_id *of_id =
  73. of_match_device(mc13xxx_dt_ids, &client->dev);
  74. mc13xxx->variant = of_id->data;
  75. } else {
  76. mc13xxx->variant = (void *)id->driver_data;
  77. }
  78. ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
  79. return ret;
  80. }
  81. static int mc13xxx_i2c_remove(struct i2c_client *client)
  82. {
  83. struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev);
  84. mc13xxx_common_cleanup(mc13xxx);
  85. return 0;
  86. }
  87. static struct i2c_driver mc13xxx_i2c_driver = {
  88. .id_table = mc13xxx_i2c_device_id,
  89. .driver = {
  90. .owner = THIS_MODULE,
  91. .name = "mc13xxx",
  92. .of_match_table = mc13xxx_dt_ids,
  93. },
  94. .probe = mc13xxx_i2c_probe,
  95. .remove = mc13xxx_i2c_remove,
  96. };
  97. static int __init mc13xxx_i2c_init(void)
  98. {
  99. return i2c_add_driver(&mc13xxx_i2c_driver);
  100. }
  101. subsys_initcall(mc13xxx_i2c_init);
  102. static void __exit mc13xxx_i2c_exit(void)
  103. {
  104. i2c_del_driver(&mc13xxx_i2c_driver);
  105. }
  106. module_exit(mc13xxx_i2c_exit);
  107. MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
  108. MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
  109. MODULE_LICENSE("GPL v2");