wm831x-spi.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * wm831x-spi.c -- SPI 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/pm.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/regmap.h>
  19. #include <linux/err.h>
  20. #include <linux/mfd/wm831x/core.h>
  21. static int wm831x_spi_probe(struct spi_device *spi)
  22. {
  23. const struct spi_device_id *id = spi_get_device_id(spi);
  24. struct wm831x *wm831x;
  25. enum wm831x_parent type;
  26. int ret;
  27. type = (enum wm831x_parent)id->driver_data;
  28. wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
  29. if (wm831x == NULL)
  30. return -ENOMEM;
  31. spi->mode = SPI_MODE_0;
  32. spi_set_drvdata(spi, wm831x);
  33. wm831x->dev = &spi->dev;
  34. wm831x->regmap = devm_regmap_init_spi(spi, &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, type, spi->irq);
  42. }
  43. static int wm831x_spi_remove(struct spi_device *spi)
  44. {
  45. struct wm831x *wm831x = spi_get_drvdata(spi);
  46. wm831x_device_exit(wm831x);
  47. return 0;
  48. }
  49. static int wm831x_spi_suspend(struct device *dev)
  50. {
  51. struct wm831x *wm831x = dev_get_drvdata(dev);
  52. return wm831x_device_suspend(wm831x);
  53. }
  54. static int wm831x_spi_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 dev_pm_ops wm831x_spi_pm = {
  61. .freeze = wm831x_spi_suspend,
  62. .suspend = wm831x_spi_suspend,
  63. .poweroff = wm831x_spi_poweroff,
  64. };
  65. static const struct spi_device_id wm831x_spi_ids[] = {
  66. { "wm8310", WM8310 },
  67. { "wm8311", WM8311 },
  68. { "wm8312", WM8312 },
  69. { "wm8320", WM8320 },
  70. { "wm8321", WM8321 },
  71. { "wm8325", WM8325 },
  72. { "wm8326", WM8326 },
  73. { },
  74. };
  75. MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
  76. static struct spi_driver wm831x_spi_driver = {
  77. .driver = {
  78. .name = "wm831x",
  79. .pm = &wm831x_spi_pm,
  80. },
  81. .id_table = wm831x_spi_ids,
  82. .probe = wm831x_spi_probe,
  83. .remove = wm831x_spi_remove,
  84. };
  85. static int __init wm831x_spi_init(void)
  86. {
  87. int ret;
  88. ret = spi_register_driver(&wm831x_spi_driver);
  89. if (ret != 0)
  90. pr_err("Failed to register WM831x SPI driver: %d\n", ret);
  91. return 0;
  92. }
  93. subsys_initcall(wm831x_spi_init);
  94. static void __exit wm831x_spi_exit(void)
  95. {
  96. spi_unregister_driver(&wm831x_spi_driver);
  97. }
  98. module_exit(wm831x_spi_exit);
  99. MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
  100. MODULE_LICENSE("GPL");
  101. MODULE_AUTHOR("Mark Brown");