mc13xxx-i2c.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. dev_set_drvdata(&client->dev, NULL);
  70. return ret;
  71. }
  72. if (client->dev.of_node) {
  73. const struct of_device_id *of_id =
  74. of_match_device(mc13xxx_dt_ids, &client->dev);
  75. mc13xxx->variant = of_id->data;
  76. } else {
  77. mc13xxx->variant = (void *)id->driver_data;
  78. }
  79. ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
  80. return ret;
  81. }
  82. static int mc13xxx_i2c_remove(struct i2c_client *client)
  83. {
  84. struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev);
  85. mc13xxx_common_cleanup(mc13xxx);
  86. return 0;
  87. }
  88. static struct i2c_driver mc13xxx_i2c_driver = {
  89. .id_table = mc13xxx_i2c_device_id,
  90. .driver = {
  91. .owner = THIS_MODULE,
  92. .name = "mc13xxx",
  93. .of_match_table = mc13xxx_dt_ids,
  94. },
  95. .probe = mc13xxx_i2c_probe,
  96. .remove = mc13xxx_i2c_remove,
  97. };
  98. static int __init mc13xxx_i2c_init(void)
  99. {
  100. return i2c_add_driver(&mc13xxx_i2c_driver);
  101. }
  102. subsys_initcall(mc13xxx_i2c_init);
  103. static void __exit mc13xxx_i2c_exit(void)
  104. {
  105. i2c_del_driver(&mc13xxx_i2c_driver);
  106. }
  107. module_exit(mc13xxx_i2c_exit);
  108. MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
  109. MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
  110. MODULE_LICENSE("GPL v2");