powermac.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 <linux/init.h>
  21. #include <linux/err.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/module.h>
  24. #include <sound/core.h>
  25. #include <sound/initval.h>
  26. #include "pmac.h"
  27. #include "awacs.h"
  28. #include "burgundy.h"
  29. #define CHIP_NAME "PMac"
  30. MODULE_DESCRIPTION("PowerMac");
  31. MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
  32. MODULE_LICENSE("GPL");
  33. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  34. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  35. static bool enable_beep = 1;
  36. module_param(index, int, 0444);
  37. MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
  38. module_param(id, charp, 0444);
  39. MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
  40. module_param(enable_beep, bool, 0444);
  41. MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
  42. static struct platform_device *device;
  43. /*
  44. */
  45. static int snd_pmac_probe(struct platform_device *devptr)
  46. {
  47. struct snd_card *card;
  48. struct snd_pmac *chip;
  49. char *name_ext;
  50. int err;
  51. err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card);
  52. if (err < 0)
  53. return err;
  54. if ((err = snd_pmac_new(card, &chip)) < 0)
  55. goto __error;
  56. card->private_data = chip;
  57. switch (chip->model) {
  58. case PMAC_BURGUNDY:
  59. strcpy(card->driver, "PMac Burgundy");
  60. strcpy(card->shortname, "PowerMac Burgundy");
  61. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  62. card->shortname, chip->device_id, chip->subframe);
  63. if ((err = snd_pmac_burgundy_init(chip)) < 0)
  64. goto __error;
  65. break;
  66. case PMAC_DACA:
  67. strcpy(card->driver, "PMac DACA");
  68. strcpy(card->shortname, "PowerMac DACA");
  69. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  70. card->shortname, chip->device_id, chip->subframe);
  71. if ((err = snd_pmac_daca_init(chip)) < 0)
  72. goto __error;
  73. break;
  74. case PMAC_TUMBLER:
  75. case PMAC_SNAPPER:
  76. name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper";
  77. sprintf(card->driver, "PMac %s", name_ext);
  78. sprintf(card->shortname, "PowerMac %s", name_ext);
  79. sprintf(card->longname, "%s (Dev %d) Sub-frame %d",
  80. card->shortname, chip->device_id, chip->subframe);
  81. err = snd_pmac_tumbler_init(chip);
  82. if (err < 0)
  83. goto __error;
  84. err = snd_pmac_tumbler_post_init();
  85. if (err < 0)
  86. goto __error;
  87. break;
  88. case PMAC_AWACS:
  89. case PMAC_SCREAMER:
  90. name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
  91. sprintf(card->driver, "PMac %s", name_ext);
  92. sprintf(card->shortname, "PowerMac %s", name_ext);
  93. if (chip->is_pbook_3400)
  94. name_ext = " [PB3400]";
  95. else if (chip->is_pbook_G3)
  96. name_ext = " [PBG3]";
  97. else
  98. name_ext = "";
  99. sprintf(card->longname, "%s%s Rev %d",
  100. card->shortname, name_ext, chip->revision);
  101. if ((err = snd_pmac_awacs_init(chip)) < 0)
  102. goto __error;
  103. break;
  104. default:
  105. snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
  106. err = -EINVAL;
  107. goto __error;
  108. }
  109. if ((err = snd_pmac_pcm_new(chip)) < 0)
  110. goto __error;
  111. chip->initialized = 1;
  112. if (enable_beep)
  113. snd_pmac_attach_beep(chip);
  114. if ((err = snd_card_register(card)) < 0)
  115. goto __error;
  116. platform_set_drvdata(devptr, card);
  117. return 0;
  118. __error:
  119. snd_card_free(card);
  120. return err;
  121. }
  122. static int snd_pmac_remove(struct platform_device *devptr)
  123. {
  124. snd_card_free(platform_get_drvdata(devptr));
  125. return 0;
  126. }
  127. #ifdef CONFIG_PM_SLEEP
  128. static int snd_pmac_driver_suspend(struct device *dev)
  129. {
  130. struct snd_card *card = dev_get_drvdata(dev);
  131. snd_pmac_suspend(card->private_data);
  132. return 0;
  133. }
  134. static int snd_pmac_driver_resume(struct device *dev)
  135. {
  136. struct snd_card *card = dev_get_drvdata(dev);
  137. snd_pmac_resume(card->private_data);
  138. return 0;
  139. }
  140. static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
  141. #define SND_PMAC_PM_OPS &snd_pmac_pm
  142. #else
  143. #define SND_PMAC_PM_OPS NULL
  144. #endif
  145. #define SND_PMAC_DRIVER "snd_powermac"
  146. static struct platform_driver snd_pmac_driver = {
  147. .probe = snd_pmac_probe,
  148. .remove = snd_pmac_remove,
  149. .driver = {
  150. .name = SND_PMAC_DRIVER,
  151. .pm = SND_PMAC_PM_OPS,
  152. },
  153. };
  154. static int __init alsa_card_pmac_init(void)
  155. {
  156. int err;
  157. if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
  158. return err;
  159. device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
  160. return 0;
  161. }
  162. static void __exit alsa_card_pmac_exit(void)
  163. {
  164. if (!IS_ERR(device))
  165. platform_device_unregister(device);
  166. platform_driver_unregister(&snd_pmac_driver);
  167. }
  168. module_init(alsa_card_pmac_init)
  169. module_exit(alsa_card_pmac_exit)