snd-aoa-codec-toonie.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifdef CONFIG_PM
  47. static int toonie_suspend(struct codec_info_item *cii, pm_message_t state)
  48. {
  49. /* can we turn it off somehow? */
  50. return 0;
  51. }
  52. static int toonie_resume(struct codec_info_item *cii)
  53. {
  54. return 0;
  55. }
  56. #endif /* CONFIG_PM */
  57. static struct codec_info toonie_codec_info = {
  58. .transfers = toonie_transfers,
  59. .sysclock_factor = 256,
  60. .bus_factor = 64,
  61. .owner = THIS_MODULE,
  62. #ifdef CONFIG_PM
  63. .suspend = toonie_suspend,
  64. .resume = toonie_resume,
  65. #endif
  66. };
  67. static int toonie_init_codec(struct aoa_codec *codec)
  68. {
  69. struct toonie *toonie = codec_to_toonie(codec);
  70. if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, toonie, &ops)) {
  71. printk(KERN_ERR PFX "failed to create toonie snd device!\n");
  72. return -ENODEV;
  73. }
  74. /* nothing connected? what a joke! */
  75. if (toonie->codec.connected != 1)
  76. return -ENOTCONN;
  77. if (toonie->codec.soundbus_dev->attach_codec(toonie->codec.soundbus_dev,
  78. aoa_get_card(),
  79. &toonie_codec_info, toonie)) {
  80. printk(KERN_ERR PFX "error creating toonie pcm\n");
  81. return -ENODEV;
  82. }
  83. return 0;
  84. }
  85. static void toonie_exit_codec(struct aoa_codec *codec)
  86. {
  87. struct toonie *toonie = codec_to_toonie(codec);
  88. if (!toonie->codec.soundbus_dev) {
  89. printk(KERN_ERR PFX "toonie_exit_codec called without soundbus_dev!\n");
  90. return;
  91. }
  92. toonie->codec.soundbus_dev->detach_codec(toonie->codec.soundbus_dev, toonie);
  93. }
  94. static struct toonie *toonie;
  95. static int __init toonie_init(void)
  96. {
  97. toonie = kzalloc(sizeof(struct toonie), GFP_KERNEL);
  98. if (!toonie)
  99. return -ENOMEM;
  100. strlcpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name));
  101. toonie->codec.owner = THIS_MODULE;
  102. toonie->codec.init = toonie_init_codec;
  103. toonie->codec.exit = toonie_exit_codec;
  104. if (aoa_codec_register(&toonie->codec)) {
  105. kfree(toonie);
  106. return -EINVAL;
  107. }
  108. return 0;
  109. }
  110. static void __exit toonie_exit(void)
  111. {
  112. aoa_codec_unregister(&toonie->codec);
  113. kfree(toonie);
  114. }
  115. module_init(toonie_init);
  116. module_exit(toonie_exit);