emu8000_synth.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * and (c) 1999 Steve Ratcliffe <steve@parabola.demon.co.uk>
  4. * Copyright (C) 1999-2000 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * Emu8000 synth plug-in routine
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include "emu8000_local.h"
  23. #include <linux/init.h>
  24. #include <sound/initval.h>
  25. MODULE_AUTHOR("Takashi Iwai, Steve Ratcliffe");
  26. MODULE_DESCRIPTION("Emu8000 synth plug-in routine");
  27. MODULE_LICENSE("GPL");
  28. /*----------------------------------------------------------------*/
  29. /*
  30. * create a new hardware dependent device for Emu8000
  31. */
  32. static int snd_emu8000_new_device(struct snd_seq_device *dev)
  33. {
  34. struct snd_emu8000 *hw;
  35. struct snd_emux *emu;
  36. hw = *(struct snd_emu8000**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
  37. if (hw == NULL)
  38. return -EINVAL;
  39. if (hw->emu)
  40. return -EBUSY; /* already exists..? */
  41. if (snd_emux_new(&emu) < 0)
  42. return -ENOMEM;
  43. hw->emu = emu;
  44. snd_emu8000_ops_setup(hw);
  45. emu->hw = hw;
  46. emu->max_voices = EMU8000_DRAM_VOICES;
  47. emu->num_ports = hw->seq_ports;
  48. if (hw->memhdr) {
  49. snd_printk(KERN_ERR "memhdr is already initialized!?\n");
  50. snd_util_memhdr_free(hw->memhdr);
  51. }
  52. hw->memhdr = snd_util_memhdr_new(hw->mem_size);
  53. if (hw->memhdr == NULL) {
  54. snd_emux_free(emu);
  55. hw->emu = NULL;
  56. return -ENOMEM;
  57. }
  58. emu->memhdr = hw->memhdr;
  59. emu->midi_ports = hw->seq_ports < 2 ? hw->seq_ports : 2; /* number of virmidi ports */
  60. emu->midi_devidx = 1;
  61. emu->linear_panning = 1;
  62. emu->hwdep_idx = 2; /* FIXED */
  63. if (snd_emux_register(emu, dev->card, hw->index, "Emu8000") < 0) {
  64. snd_emux_free(emu);
  65. snd_util_memhdr_free(hw->memhdr);
  66. hw->emu = NULL;
  67. hw->memhdr = NULL;
  68. return -ENOMEM;
  69. }
  70. if (hw->mem_size > 0)
  71. snd_emu8000_pcm_new(dev->card, hw, 1);
  72. dev->driver_data = hw;
  73. return 0;
  74. }
  75. /*
  76. * free all resources
  77. */
  78. static int snd_emu8000_delete_device(struct snd_seq_device *dev)
  79. {
  80. struct snd_emu8000 *hw;
  81. if (dev->driver_data == NULL)
  82. return 0; /* no synth was allocated actually */
  83. hw = dev->driver_data;
  84. if (hw->pcm)
  85. snd_device_free(dev->card, hw->pcm);
  86. if (hw->emu)
  87. snd_emux_free(hw->emu);
  88. if (hw->memhdr)
  89. snd_util_memhdr_free(hw->memhdr);
  90. hw->emu = NULL;
  91. hw->memhdr = NULL;
  92. return 0;
  93. }
  94. /*
  95. * INIT part
  96. */
  97. static int __init alsa_emu8000_init(void)
  98. {
  99. static struct snd_seq_dev_ops ops = {
  100. snd_emu8000_new_device,
  101. snd_emu8000_delete_device,
  102. };
  103. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
  104. sizeof(struct snd_emu8000*));
  105. }
  106. static void __exit alsa_emu8000_exit(void)
  107. {
  108. snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000);
  109. }
  110. module_init(alsa_emu8000_init)
  111. module_exit(alsa_emu8000_exit)