powermac.c 4.5 KB

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