wm8350-i2c.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
  3. *
  4. * Copyright 2007, 2008 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Liam Girdwood
  7. * linux@wolfsonmicro.com
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/i2c.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mfd/wm8350/core.h>
  22. #include <linux/regmap.h>
  23. #include <linux/slab.h>
  24. static const struct regmap_config wm8350_regmap = {
  25. .reg_bits = 8,
  26. .val_bits = 16,
  27. };
  28. static int wm8350_i2c_probe(struct i2c_client *i2c,
  29. const struct i2c_device_id *id)
  30. {
  31. struct wm8350 *wm8350;
  32. int ret = 0;
  33. wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
  34. if (wm8350 == NULL)
  35. return -ENOMEM;
  36. wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
  37. if (IS_ERR(wm8350->regmap)) {
  38. ret = PTR_ERR(wm8350->regmap);
  39. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  40. ret);
  41. return ret;
  42. }
  43. i2c_set_clientdata(i2c, wm8350);
  44. wm8350->dev = &i2c->dev;
  45. return wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data);
  46. }
  47. static int wm8350_i2c_remove(struct i2c_client *i2c)
  48. {
  49. struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
  50. wm8350_device_exit(wm8350);
  51. return 0;
  52. }
  53. static const struct i2c_device_id wm8350_i2c_id[] = {
  54. { "wm8350", 0 },
  55. { "wm8351", 0 },
  56. { "wm8352", 0 },
  57. { }
  58. };
  59. MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
  60. static struct i2c_driver wm8350_i2c_driver = {
  61. .driver = {
  62. .name = "wm8350",
  63. .owner = THIS_MODULE,
  64. },
  65. .probe = wm8350_i2c_probe,
  66. .remove = wm8350_i2c_remove,
  67. .id_table = wm8350_i2c_id,
  68. };
  69. static int __init wm8350_i2c_init(void)
  70. {
  71. return i2c_add_driver(&wm8350_i2c_driver);
  72. }
  73. /* init early so consumer devices can complete system boot */
  74. subsys_initcall(wm8350_i2c_init);
  75. static void __exit wm8350_i2c_exit(void)
  76. {
  77. i2c_del_driver(&wm8350_i2c_driver);
  78. }
  79. module_exit(wm8350_i2c_exit);
  80. MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
  81. MODULE_LICENSE("GPL");