powermac.c 4.4 KB

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