mc13xxx-i2c.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 = MC13XXX_ID_MC13892,
  25. }, {
  26. /* sentinel */
  27. }
  28. };
  29. MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
  30. static const struct of_device_id mc13xxx_dt_ids[] = {
  31. {
  32. .compatible = "fsl,mc13892",
  33. .data = (void *) &mc13xxx_i2c_device_id[0],
  34. }, {
  35. /* sentinel */
  36. }
  37. };
  38. MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
  39. static struct regmap_config mc13xxx_regmap_i2c_config = {
  40. .reg_bits = 8,
  41. .val_bits = 24,
  42. .max_register = MC13XXX_NUMREGS,
  43. .cache_type = REGCACHE_NONE,
  44. };
  45. static int mc13xxx_i2c_probe(struct i2c_client *client,
  46. const struct i2c_device_id *id)
  47. {
  48. const struct of_device_id *of_id;
  49. struct i2c_driver *idrv = to_i2c_driver(client->dev.driver);
  50. struct mc13xxx *mc13xxx;
  51. struct mc13xxx_platform_data *pdata = dev_get_platdata(&client->dev);
  52. int ret;
  53. of_id = of_match_device(mc13xxx_dt_ids, &client->dev);
  54. if (of_id)
  55. idrv->id_table = (const struct i2c_device_id*) of_id->data;
  56. mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL);
  57. if (!mc13xxx)
  58. return -ENOMEM;
  59. dev_set_drvdata(&client->dev, mc13xxx);
  60. mc13xxx->dev = &client->dev;
  61. mutex_init(&mc13xxx->lock);
  62. mc13xxx->regmap = regmap_init_i2c(client, &mc13xxx_regmap_i2c_config);
  63. if (IS_ERR(mc13xxx->regmap)) {
  64. ret = PTR_ERR(mc13xxx->regmap);
  65. dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
  66. ret);
  67. dev_set_drvdata(&client->dev, NULL);
  68. kfree(mc13xxx);
  69. return ret;
  70. }
  71. ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
  72. if (ret == 0 && (id->driver_data != mc13xxx->ictype))
  73. dev_warn(mc13xxx->dev,
  74. "device id doesn't match auto detection!\n");
  75. return ret;
  76. }
  77. static int __devexit mc13xxx_i2c_remove(struct i2c_client *client)
  78. {
  79. struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev);
  80. mc13xxx_common_cleanup(mc13xxx);
  81. return 0;
  82. }
  83. static struct i2c_driver mc13xxx_i2c_driver = {
  84. .id_table = mc13xxx_i2c_device_id,
  85. .driver = {
  86. .owner = THIS_MODULE,
  87. .name = "mc13xxx",
  88. .of_match_table = mc13xxx_dt_ids,
  89. },
  90. .probe = mc13xxx_i2c_probe,
  91. .remove = __devexit_p(mc13xxx_i2c_remove),
  92. };
  93. static int __init mc13xxx_i2c_init(void)
  94. {
  95. return i2c_add_driver(&mc13xxx_i2c_driver);
  96. }
  97. subsys_initcall(mc13xxx_i2c_init);
  98. static void __exit mc13xxx_i2c_exit(void)
  99. {
  100. i2c_del_driver(&mc13xxx_i2c_driver);
  101. }
  102. module_exit(mc13xxx_i2c_exit);
  103. MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
  104. MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
  105. MODULE_LICENSE("GPL v2");