powermac.c 5.1 KB

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