wm831x-spi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 __devinit 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->bits_per_word = 16;
  32. spi->mode = SPI_MODE_0;
  33. dev_set_drvdata(&spi->dev, wm831x);
  34. wm831x->dev = &spi->dev;
  35. wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
  36. if (IS_ERR(wm831x->regmap)) {
  37. ret = PTR_ERR(wm831x->regmap);
  38. dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
  39. ret);
  40. return ret;
  41. }
  42. return wm831x_device_init(wm831x, type, spi->irq);
  43. }
  44. static int __devexit wm831x_spi_remove(struct spi_device *spi)
  45. {
  46. struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
  47. wm831x_device_exit(wm831x);
  48. return 0;
  49. }
  50. static int wm831x_spi_suspend(struct device *dev)
  51. {
  52. struct wm831x *wm831x = dev_get_drvdata(dev);
  53. return wm831x_device_suspend(wm831x);
  54. }
  55. static void wm831x_spi_shutdown(struct spi_device *spi)
  56. {
  57. struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
  58. wm831x_device_shutdown(wm831x);
  59. }
  60. static const struct dev_pm_ops wm831x_spi_pm = {
  61. .freeze = wm831x_spi_suspend,
  62. .suspend = wm831x_spi_suspend,
  63. };
  64. static const struct spi_device_id wm831x_spi_ids[] = {
  65. { "wm8310", WM8310 },
  66. { "wm8311", WM8311 },
  67. { "wm8312", WM8312 },
  68. { "wm8320", WM8320 },
  69. { "wm8321", WM8321 },
  70. { "wm8325", WM8325 },
  71. { "wm8326", WM8326 },
  72. { },
  73. };
  74. MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
  75. static struct spi_driver wm831x_spi_driver = {
  76. .driver = {
  77. .name = "wm831x",
  78. .owner = THIS_MODULE,
  79. .pm = &wm831x_spi_pm,
  80. },
  81. .id_table = wm831x_spi_ids,
  82. .probe = wm831x_spi_probe,
  83. .remove = __devexit_p(wm831x_spi_remove),
  84. .shutdown = wm831x_spi_shutdown,
  85. };
  86. static int __init wm831x_spi_init(void)
  87. {
  88. int ret;
  89. ret = spi_register_driver(&wm831x_spi_driver);
  90. if (ret != 0)
  91. pr_err("Failed to register WM831x SPI driver: %d\n", ret);
  92. return 0;
  93. }
  94. subsys_initcall(wm831x_spi_init);
  95. static void __exit wm831x_spi_exit(void)
  96. {
  97. spi_unregister_driver(&wm831x_spi_driver);
  98. }
  99. module_exit(wm831x_spi_exit);
  100. MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
  101. MODULE_LICENSE("GPL");
  102. MODULE_AUTHOR("Mark Brown");