powermac.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Driver for PowerMac AWACS
  3. * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
  4. * based on dmasound.c.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/err.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/moduleparam.h>
  25. #include <sound/core.h>
  26. #include <sound/initval.h>
  27. #include "pmac.h"
  28. #include "awacs.h"
  29. #include "burgundy.h"
  30. #define CHIP_NAME "PMac"
  31. MODULE_DESCRIPTION("PowerMac");
  32. MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
  33. MODULE_LICENSE("GPL");
  34. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  35. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  36. static int enable_beep = 1;
  37. module_param(index, int, 0444);
  38. MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
  39. module_param(id, charp, 0444);
  40. MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
  41. module_param(enable_beep, bool, 0444);
  42. MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
  43. static struct platform_device *device;
  44. /*
  45. */
  46. static int __init snd_pmac_probe(struct platform_device *devptr)
  47. {
  48. struct snd_card *card;
  49. struct snd_pmac *chip;
  50. char *name_ext;
  51. int err;
  52. card = snd_card_new(index, id, THIS_MODULE, 0);
  53. if (card == NULL)
  54. return -ENOMEM;
  55. if ((err = snd_pmac_new(card, &chip)) < 0)
  56. goto __error;
  57. card->private_data = chip;
  58. switch (chip->model) {
  59. case PMAC_BURGUNDY:
  60. strcpy(card->driver, "PMac Burgundy");
  61. strcpy(card->shortname, "PowerMac Burgundy");
  62. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  63. card->shortname, chip->device_id, chip->subframe);
  64. if ((err = snd_pmac_burgundy_init(chip)) < 0)
  65. goto __error;
  66. break;
  67. case PMAC_DACA:
  68. strcpy(card->driver, "PMac DACA");
  69. strcpy(card->shortname, "PowerMac DACA");
  70. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  71. card->shortname, chip->device_id, chip->subframe);
  72. if ((err = snd_pmac_daca_init(chip)) < 0)
  73. goto __error;
  74. break;
  75. case PMAC_TUMBLER:
  76. case PMAC_SNAPPER:
  77. name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
  78. sprintf(card->driver, "PMac %s", name_ext);
  79. sprintf(card->shortname, "PowerMac %s", name_ext);
  80. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  81. card->shortname, chip->device_id, chip->subframe);
  82. if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
  83. goto __error;
  84. break;
  85. case PMAC_TOONIE:
  86. strcpy(card->driver, "PMac Toonie");
  87. strcpy(card->shortname, "PowerMac Toonie");
  88. strcpy(card->longname, card->shortname);
  89. if ((err = snd_pmac_toonie_init(chip)) < 0)
  90. goto __error;
  91. break;
  92. case PMAC_AWACS:
  93. case PMAC_SCREAMER:
  94. name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
  95. sprintf(card->driver, "PMac %s", name_ext);
  96. sprintf(card->shortname, "PowerMac %s", name_ext);
  97. if (chip->is_pbook_3400)
  98. name_ext = " [PB3400]";
  99. else if (chip->is_pbook_G3)
  100. name_ext = " [PBG3]";
  101. else
  102. name_ext = "";
  103. sprintf(card->longname, "%s%s Rev %d",
  104. card->shortname, name_ext, chip->revision);
  105. if ((err = snd_pmac_awacs_init(chip)) < 0)
  106. goto __error;
  107. break;
  108. default:
  109. snd_printk("unsupported hardware %d\n", chip->model);
  110. err = -EINVAL;
  111. goto __error;
  112. }
  113. if ((err = snd_pmac_pcm_new(chip)) < 0)
  114. goto __error;
  115. chip->initialized = 1;
  116. if (enable_beep)
  117. snd_pmac_attach_beep(chip);
  118. snd_card_set_dev(card, &devptr->dev);
  119. if ((err = snd_card_register(card)) < 0)
  120. goto __error;
  121. platform_set_drvdata(devptr, card);
  122. return 0;
  123. __error:
  124. snd_card_free(card);
  125. return err;
  126. }
  127. static int __devexit snd_pmac_remove(struct platform_device *devptr)
  128. {
  129. snd_card_free(platform_get_drvdata(devptr));
  130. platform_set_drvdata(devptr, NULL);
  131. return 0;
  132. }
  133. #ifdef CONFIG_PM
  134. static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
  135. {
  136. struct snd_card *card = platform_get_drvdata(devptr);
  137. snd_pmac_suspend(card->private_data);
  138. return 0;
  139. }
  140. static int snd_pmac_driver_resume(struct platform_device *devptr)
  141. {
  142. struct snd_card *card = platform_get_drvdata(devptr);
  143. snd_pmac_resume(card->private_data);
  144. return 0;
  145. }
  146. #endif
  147. #define SND_PMAC_DRIVER "snd_powermac"
  148. static struct platform_driver snd_pmac_driver = {
  149. .probe = snd_pmac_probe,
  150. .remove = __devexit_p(snd_pmac_remove),
  151. #ifdef CONFIG_PM
  152. .suspend = snd_pmac_driver_suspend,
  153. .resume = snd_pmac_driver_resume,
  154. #endif
  155. .driver = {
  156. .name = SND_PMAC_DRIVER
  157. },
  158. };
  159. static int __init alsa_card_pmac_init(void)
  160. {
  161. int err;
  162. if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
  163. return err;
  164. device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
  165. if (IS_ERR(device)) {
  166. platform_driver_unregister(&snd_pmac_driver);
  167. return PTR_ERR(device);
  168. }
  169. return 0;
  170. }
  171. static void __exit alsa_card_pmac_exit(void)
  172. {
  173. platform_device_unregister(device);
  174. platform_driver_unregister(&snd_pmac_driver);
  175. }
  176. module_init(alsa_card_pmac_init)
  177. module_exit(alsa_card_pmac_exit)