powermac.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_AWACS:
  86. case PMAC_SCREAMER:
  87. name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
  88. sprintf(card->driver, "PMac %s", name_ext);
  89. sprintf(card->shortname, "PowerMac %s", name_ext);
  90. if (chip->is_pbook_3400)
  91. name_ext = " [PB3400]";
  92. else if (chip->is_pbook_G3)
  93. name_ext = " [PBG3]";
  94. else
  95. name_ext = "";
  96. sprintf(card->longname, "%s%s Rev %d",
  97. card->shortname, name_ext, chip->revision);
  98. if ((err = snd_pmac_awacs_init(chip)) < 0)
  99. goto __error;
  100. break;
  101. default:
  102. snd_printk("unsupported hardware %d\n", chip->model);
  103. err = -EINVAL;
  104. goto __error;
  105. }
  106. if ((err = snd_pmac_pcm_new(chip)) < 0)
  107. goto __error;
  108. chip->initialized = 1;
  109. if (enable_beep)
  110. snd_pmac_attach_beep(chip);
  111. snd_card_set_dev(card, &devptr->dev);
  112. if ((err = snd_card_register(card)) < 0)
  113. goto __error;
  114. platform_set_drvdata(devptr, card);
  115. return 0;
  116. __error:
  117. snd_card_free(card);
  118. return err;
  119. }
  120. static int __devexit snd_pmac_remove(struct platform_device *devptr)
  121. {
  122. snd_card_free(platform_get_drvdata(devptr));
  123. platform_set_drvdata(devptr, NULL);
  124. return 0;
  125. }
  126. #ifdef CONFIG_PM
  127. static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
  128. {
  129. struct snd_card *card = platform_get_drvdata(devptr);
  130. snd_pmac_suspend(card->private_data);
  131. return 0;
  132. }
  133. static int snd_pmac_driver_resume(struct platform_device *devptr)
  134. {
  135. struct snd_card *card = platform_get_drvdata(devptr);
  136. snd_pmac_resume(card->private_data);
  137. return 0;
  138. }
  139. #endif
  140. #define SND_PMAC_DRIVER "snd_powermac"
  141. static struct platform_driver snd_pmac_driver = {
  142. .probe = snd_pmac_probe,
  143. .remove = __devexit_p(snd_pmac_remove),
  144. #ifdef CONFIG_PM
  145. .suspend = snd_pmac_driver_suspend,
  146. .resume = snd_pmac_driver_resume,
  147. #endif
  148. .driver = {
  149. .name = SND_PMAC_DRIVER
  150. },
  151. };
  152. static int __init alsa_card_pmac_init(void)
  153. {
  154. int err;
  155. if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
  156. return err;
  157. device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
  158. return 0;
  159. }
  160. static void __exit alsa_card_pmac_exit(void)
  161. {
  162. if (!IS_ERR(device))
  163. platform_device_unregister(device);
  164. platform_driver_unregister(&snd_pmac_driver);
  165. }
  166. module_init(alsa_card_pmac_init)
  167. module_exit(alsa_card_pmac_exit)