wm831x-spi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 = kzalloc(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 = 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. kfree(wm831x);
  41. return ret;
  42. }
  43. return wm831x_device_init(wm831x, type, spi->irq);
  44. }
  45. static int __devexit wm831x_spi_remove(struct spi_device *spi)
  46. {
  47. struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
  48. wm831x_device_exit(wm831x);
  49. return 0;
  50. }
  51. static int wm831x_spi_suspend(struct device *dev)
  52. {
  53. struct wm831x *wm831x = dev_get_drvdata(dev);
  54. return wm831x_device_suspend(wm831x);
  55. }
  56. static void wm831x_spi_shutdown(struct spi_device *spi)
  57. {
  58. struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
  59. wm831x_device_shutdown(wm831x);
  60. }
  61. static const struct dev_pm_ops wm831x_spi_pm = {
  62. .freeze = wm831x_spi_suspend,
  63. .suspend = wm831x_spi_suspend,
  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_id);
  76. static struct spi_driver wm831x_spi_driver = {
  77. .driver = {
  78. .name = "wm831x",
  79. .bus = &spi_bus_type,
  80. .owner = THIS_MODULE,
  81. .pm = &wm831x_spi_pm,
  82. },
  83. .id_table = wm831x_spi_ids,
  84. .probe = wm831x_spi_probe,
  85. .remove = __devexit_p(wm831x_spi_remove),
  86. .shutdown = wm831x_spi_shutdown,
  87. };
  88. static int __init wm831x_spi_init(void)
  89. {
  90. int ret;
  91. ret = spi_register_driver(&wm831x_spi_driver);
  92. if (ret != 0)
  93. pr_err("Failed to register WM831x SPI driver: %d\n", ret);
  94. return 0;
  95. }
  96. subsys_initcall(wm831x_spi_init);
  97. static void __exit wm831x_spi_exit(void)
  98. {
  99. spi_unregister_driver(&wm831x_spi_driver);
  100. }
  101. module_exit(wm831x_spi_exit);
  102. MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
  103. MODULE_LICENSE("GPL");
  104. MODULE_AUTHOR("Mark Brown");