snd-aoa-codec-toonie.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Apple Onboard Audio driver for Toonie codec
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * GPL v2, can be found in COPYING.
  7. *
  8. *
  9. * This is a driver for the toonie codec chip. This chip is present
  10. * on the Mac Mini and is nothing but a DAC.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
  15. MODULE_LICENSE("GPL");
  16. MODULE_DESCRIPTION("toonie codec driver for snd-aoa");
  17. #include "../aoa.h"
  18. #include "../soundbus/soundbus.h"
  19. #define PFX "snd-aoa-codec-toonie: "
  20. struct toonie {
  21. struct aoa_codec codec;
  22. };
  23. #define codec_to_toonie(c) container_of(c, struct toonie, codec)
  24. static int toonie_dev_register(struct snd_device *dev)
  25. {
  26. return 0;
  27. }
  28. static struct snd_device_ops ops = {
  29. .dev_register = toonie_dev_register,
  30. };
  31. static struct transfer_info toonie_transfers[] = {
  32. /* This thing *only* has analog output,
  33. * the rates are taken from Info.plist
  34. * from Darwin. */
  35. {
  36. .formats = SNDRV_PCM_FMTBIT_S16_BE |
  37. SNDRV_PCM_FMTBIT_S24_BE,
  38. .rates = SNDRV_PCM_RATE_32000 |
  39. SNDRV_PCM_RATE_44100 |
  40. SNDRV_PCM_RATE_48000 |
  41. SNDRV_PCM_RATE_88200 |
  42. SNDRV_PCM_RATE_96000,
  43. },
  44. {}
  45. };
  46. static int toonie_usable(struct codec_info_item *cii,
  47. struct transfer_info *ti,
  48. struct transfer_info *out)
  49. {
  50. return 1;
  51. }
  52. #ifdef CONFIG_PM
  53. static int toonie_suspend(struct codec_info_item *cii, pm_message_t state)
  54. {
  55. /* can we turn it off somehow? */
  56. return 0;
  57. }
  58. static int toonie_resume(struct codec_info_item *cii)
  59. {
  60. return 0;
  61. }
  62. #endif /* CONFIG_PM */
  63. static struct codec_info toonie_codec_info = {
  64. .transfers = toonie_transfers,
  65. .sysclock_factor = 256,
  66. .bus_factor = 64,
  67. .owner = THIS_MODULE,
  68. .usable = toonie_usable,
  69. #ifdef CONFIG_PM
  70. .suspend = toonie_suspend,
  71. .resume = toonie_resume,
  72. #endif
  73. };
  74. static int toonie_init_codec(struct aoa_codec *codec)
  75. {
  76. struct toonie *toonie = codec_to_toonie(codec);
  77. /* nothing connected? what a joke! */
  78. if (toonie->codec.connected != 1)
  79. return -ENOTCONN;
  80. if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, toonie, &ops)) {
  81. printk(KERN_ERR PFX "failed to create toonie snd device!\n");
  82. return -ENODEV;
  83. }
  84. if (toonie->codec.soundbus_dev->attach_codec(toonie->codec.soundbus_dev,
  85. aoa_get_card(),
  86. &toonie_codec_info, toonie)) {
  87. printk(KERN_ERR PFX "error creating toonie pcm\n");
  88. snd_device_free(aoa_get_card(), toonie);
  89. return -ENODEV;
  90. }
  91. return 0;
  92. }
  93. static void toonie_exit_codec(struct aoa_codec *codec)
  94. {
  95. struct toonie *toonie = codec_to_toonie(codec);
  96. if (!toonie->codec.soundbus_dev) {
  97. printk(KERN_ERR PFX "toonie_exit_codec called without soundbus_dev!\n");
  98. return;
  99. }
  100. toonie->codec.soundbus_dev->detach_codec(toonie->codec.soundbus_dev, toonie);
  101. }
  102. static struct toonie *toonie;
  103. static int __init toonie_init(void)
  104. {
  105. toonie = kzalloc(sizeof(struct toonie), GFP_KERNEL);
  106. if (!toonie)
  107. return -ENOMEM;
  108. strlcpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name));
  109. toonie->codec.owner = THIS_MODULE;
  110. toonie->codec.init = toonie_init_codec;
  111. toonie->codec.exit = toonie_exit_codec;
  112. if (aoa_codec_register(&toonie->codec)) {
  113. kfree(toonie);
  114. return -EINVAL;
  115. }
  116. return 0;
  117. }
  118. static void __exit toonie_exit(void)
  119. {
  120. aoa_codec_unregister(&toonie->codec);
  121. kfree(toonie);
  122. }
  123. module_init(toonie_init);
  124. module_exit(toonie_exit);