toonie.c 3.3 KB

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