wm831x-i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs
  3. *
  4. * Copyright 2009,2010 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/i2c.h>
  17. #include <linux/delay.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/slab.h>
  20. #include <linux/err.h>
  21. #include <linux/regmap.h>
  22. #include <linux/mfd/wm831x/core.h>
  23. #include <linux/mfd/wm831x/pdata.h>
  24. static int wm831x_i2c_probe(struct i2c_client *i2c,
  25. const struct i2c_device_id *id)
  26. {
  27. struct wm831x *wm831x;
  28. int ret;
  29. wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
  30. if (wm831x == NULL)
  31. return -ENOMEM;
  32. i2c_set_clientdata(i2c, wm831x);
  33. wm831x->dev = &i2c->dev;
  34. wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
  35. if (IS_ERR(wm831x->regmap)) {
  36. ret = PTR_ERR(wm831x->regmap);
  37. dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
  38. ret);
  39. return ret;
  40. }
  41. return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
  42. }
  43. static int wm831x_i2c_remove(struct i2c_client *i2c)
  44. {
  45. struct wm831x *wm831x = i2c_get_clientdata(i2c);
  46. wm831x_device_exit(wm831x);
  47. return 0;
  48. }
  49. static int wm831x_i2c_suspend(struct device *dev)
  50. {
  51. struct wm831x *wm831x = dev_get_drvdata(dev);
  52. return wm831x_device_suspend(wm831x);
  53. }
  54. static int wm831x_i2c_poweroff(struct device *dev)
  55. {
  56. struct wm831x *wm831x = dev_get_drvdata(dev);
  57. wm831x_device_shutdown(wm831x);
  58. return 0;
  59. }
  60. static const struct i2c_device_id wm831x_i2c_id[] = {
  61. { "wm8310", WM8310 },
  62. { "wm8311", WM8311 },
  63. { "wm8312", WM8312 },
  64. { "wm8320", WM8320 },
  65. { "wm8321", WM8321 },
  66. { "wm8325", WM8325 },
  67. { "wm8326", WM8326 },
  68. { }
  69. };
  70. MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
  71. static const struct dev_pm_ops wm831x_pm_ops = {
  72. .suspend = wm831x_i2c_suspend,
  73. .poweroff = wm831x_i2c_poweroff,
  74. };
  75. static struct i2c_driver wm831x_i2c_driver = {
  76. .driver = {
  77. .name = "wm831x",
  78. .pm = &wm831x_pm_ops,
  79. },
  80. .probe = wm831x_i2c_probe,
  81. .remove = wm831x_i2c_remove,
  82. .id_table = wm831x_i2c_id,
  83. };
  84. static int __init wm831x_i2c_init(void)
  85. {
  86. int ret;
  87. ret = i2c_add_driver(&wm831x_i2c_driver);
  88. if (ret != 0)
  89. pr_err("Failed to register wm831x I2C driver: %d\n", ret);
  90. return ret;
  91. }
  92. subsys_initcall(wm831x_i2c_init);
  93. static void __exit wm831x_i2c_exit(void)
  94. {
  95. i2c_del_driver(&wm831x_i2c_driver);
  96. }
  97. module_exit(wm831x_i2c_exit);