wm8350-i2c.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 int wm8350_i2c_probe(struct i2c_client *i2c,
  25. const struct i2c_device_id *id)
  26. {
  27. struct wm8350 *wm8350;
  28. struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
  29. int ret = 0;
  30. wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
  31. if (wm8350 == NULL)
  32. return -ENOMEM;
  33. wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
  34. if (IS_ERR(wm8350->regmap)) {
  35. ret = PTR_ERR(wm8350->regmap);
  36. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  37. ret);
  38. return ret;
  39. }
  40. i2c_set_clientdata(i2c, wm8350);
  41. wm8350->dev = &i2c->dev;
  42. return wm8350_device_init(wm8350, i2c->irq, pdata);
  43. }
  44. static int wm8350_i2c_remove(struct i2c_client *i2c)
  45. {
  46. struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
  47. wm8350_device_exit(wm8350);
  48. return 0;
  49. }
  50. static const struct i2c_device_id wm8350_i2c_id[] = {
  51. { "wm8350", 0 },
  52. { "wm8351", 0 },
  53. { "wm8352", 0 },
  54. { }
  55. };
  56. MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
  57. static struct i2c_driver wm8350_i2c_driver = {
  58. .driver = {
  59. .name = "wm8350",
  60. },
  61. .probe = wm8350_i2c_probe,
  62. .remove = wm8350_i2c_remove,
  63. .id_table = wm8350_i2c_id,
  64. };
  65. static int __init wm8350_i2c_init(void)
  66. {
  67. return i2c_add_driver(&wm8350_i2c_driver);
  68. }
  69. /* init early so consumer devices can complete system boot */
  70. subsys_initcall(wm8350_i2c_init);
  71. static void __exit wm8350_i2c_exit(void)
  72. {
  73. i2c_del_driver(&wm8350_i2c_driver);
  74. }
  75. module_exit(wm8350_i2c_exit);
  76. MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
  77. MODULE_LICENSE("GPL");