wm8727.c 3.8 KB

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