wm8727.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * wm8727.c
  3. *
  4. * Created on: 15-Oct-2009
  5. * Author: neil.jones@imgtec.com
  6. *
  7. * Copyright (C) 2009 Imagination Technologies Ltd.
  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. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/ac97_codec.h>
  21. #include <sound/initval.h>
  22. #include <sound/soc.h>
  23. #include "wm8727.h"
  24. /*
  25. * Note this is a simple chip with no configuration interface, sample rate is
  26. * determined automatically by examining the Master clock and Bit clock ratios
  27. */
  28. #define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  29. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
  30. SNDRV_PCM_RATE_192000)
  31. struct snd_soc_dai wm8727_dai = {
  32. .name = "WM8727",
  33. .playback = {
  34. .stream_name = "Playback",
  35. .channels_min = 2,
  36. .channels_max = 2,
  37. .rates = WM8727_RATES,
  38. .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
  39. },
  40. };
  41. EXPORT_SYMBOL_GPL(wm8727_dai);
  42. static struct snd_soc_codec *wm8727_codec;
  43. static int wm8727_soc_probe(struct platform_device *pdev)
  44. {
  45. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  46. int ret = 0;
  47. BUG_ON(!wm8727_codec);
  48. socdev->card->codec = wm8727_codec;
  49. /* register pcms */
  50. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  51. if (ret < 0) {
  52. printk(KERN_ERR "wm8727: failed to create pcms\n");
  53. goto pcm_err;
  54. }
  55. return ret;
  56. pcm_err:
  57. kfree(socdev->card->codec);
  58. socdev->card->codec = NULL;
  59. return ret;
  60. }
  61. static int wm8727_soc_remove(struct platform_device *pdev)
  62. {
  63. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  64. snd_soc_free_pcms(socdev);
  65. return 0;
  66. }
  67. struct snd_soc_codec_device soc_codec_dev_wm8727 = {
  68. .probe = wm8727_soc_probe,
  69. .remove = wm8727_soc_remove,
  70. };
  71. EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
  72. static __devinit int wm8727_platform_probe(struct platform_device *pdev)
  73. {
  74. struct snd_soc_codec *codec;
  75. int ret;
  76. if (wm8727_codec) {
  77. dev_err(&pdev->dev, "Another WM8727 is registered\n");
  78. return -EBUSY;
  79. }
  80. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  81. if (codec == NULL)
  82. return -ENOMEM;
  83. wm8727_codec = codec;
  84. platform_set_drvdata(pdev, codec);
  85. mutex_init(&codec->mutex);
  86. codec->dev = &pdev->dev;
  87. codec->name = "WM8727";
  88. codec->owner = THIS_MODULE;
  89. codec->dai = &wm8727_dai;
  90. codec->num_dai = 1;
  91. INIT_LIST_HEAD(&codec->dapm_widgets);
  92. INIT_LIST_HEAD(&codec->dapm_paths);
  93. wm8727_dai.dev = &pdev->dev;
  94. ret = snd_soc_register_codec(codec);
  95. if (ret != 0) {
  96. dev_err(&pdev->dev, "Failed to register CODEC: %d\n", ret);
  97. goto err;
  98. }
  99. ret = snd_soc_register_dai(&wm8727_dai);
  100. if (ret != 0) {
  101. dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret);
  102. goto err_codec;
  103. }
  104. err_codec:
  105. snd_soc_unregister_codec(codec);
  106. err:
  107. kfree(codec);
  108. return ret;
  109. }
  110. static int __devexit wm8727_platform_remove(struct platform_device *pdev)
  111. {
  112. snd_soc_unregister_dai(&wm8727_dai);
  113. snd_soc_unregister_codec(platform_get_drvdata(pdev));
  114. return 0;
  115. }
  116. static struct platform_driver wm8727_codec_driver = {
  117. .driver = {
  118. .name = "wm8727-codec",
  119. .owner = THIS_MODULE,
  120. },
  121. .probe = wm8727_platform_probe,
  122. .remove = __devexit_p(wm8727_platform_remove),
  123. };
  124. static int __init wm8727_init(void)
  125. {
  126. return platform_driver_register(&wm8727_codec_driver);
  127. }
  128. module_init(wm8727_init);
  129. static void __exit wm8727_exit(void)
  130. {
  131. platform_driver_unregister(&wm8727_codec_driver);
  132. }
  133. module_exit(wm8727_exit);
  134. MODULE_DESCRIPTION("ASoC wm8727 driver");
  135. MODULE_AUTHOR("Neil Jones");
  136. MODULE_LICENSE("GPL");