toonie.c 3.3 KB

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