emu8000_synth.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/module.h>
  25. #include <sound/initval.h>
  26. MODULE_AUTHOR("Takashi Iwai, Steve Ratcliffe");
  27. MODULE_DESCRIPTION("Emu8000 synth plug-in routine");
  28. MODULE_LICENSE("GPL");
  29. /*----------------------------------------------------------------*/
  30. /*
  31. * create a new hardware dependent device for Emu8000
  32. */
  33. static int snd_emu8000_new_device(struct snd_seq_device *dev)
  34. {
  35. struct snd_emu8000 *hw;
  36. struct snd_emux *emu;
  37. hw = *(struct snd_emu8000**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
  38. if (hw == NULL)
  39. return -EINVAL;
  40. if (hw->emu)
  41. return -EBUSY; /* already exists..? */
  42. if (snd_emux_new(&emu) < 0)
  43. return -ENOMEM;
  44. hw->emu = emu;
  45. snd_emu8000_ops_setup(hw);
  46. emu->hw = hw;
  47. emu->max_voices = EMU8000_DRAM_VOICES;
  48. emu->num_ports = hw->seq_ports;
  49. if (hw->memhdr) {
  50. snd_printk(KERN_ERR "memhdr is already initialized!?\n");
  51. snd_util_memhdr_free(hw->memhdr);
  52. }
  53. hw->memhdr = snd_util_memhdr_new(hw->mem_size);
  54. if (hw->memhdr == NULL) {
  55. snd_emux_free(emu);
  56. hw->emu = NULL;
  57. return -ENOMEM;
  58. }
  59. emu->memhdr = hw->memhdr;
  60. emu->midi_ports = hw->seq_ports < 2 ? hw->seq_ports : 2; /* number of virmidi ports */
  61. emu->midi_devidx = 1;
  62. emu->linear_panning = 1;
  63. emu->hwdep_idx = 2; /* FIXED */
  64. if (snd_emux_register(emu, dev->card, hw->index, "Emu8000") < 0) {
  65. snd_emux_free(emu);
  66. snd_util_memhdr_free(hw->memhdr);
  67. hw->emu = NULL;
  68. hw->memhdr = NULL;
  69. return -ENOMEM;
  70. }
  71. if (hw->mem_size > 0)
  72. snd_emu8000_pcm_new(dev->card, hw, 1);
  73. dev->driver_data = hw;
  74. return 0;
  75. }
  76. /*
  77. * free all resources
  78. */
  79. static int snd_emu8000_delete_device(struct snd_seq_device *dev)
  80. {
  81. struct snd_emu8000 *hw;
  82. if (dev->driver_data == NULL)
  83. return 0; /* no synth was allocated actually */
  84. hw = dev->driver_data;
  85. if (hw->pcm)
  86. snd_device_free(dev->card, hw->pcm);
  87. if (hw->emu)
  88. snd_emux_free(hw->emu);
  89. if (hw->memhdr)
  90. snd_util_memhdr_free(hw->memhdr);
  91. hw->emu = NULL;
  92. hw->memhdr = NULL;
  93. return 0;
  94. }
  95. /*
  96. * INIT part
  97. */
  98. static int __init alsa_emu8000_init(void)
  99. {
  100. static struct snd_seq_dev_ops ops = {
  101. snd_emu8000_new_device,
  102. snd_emu8000_delete_device,
  103. };
  104. return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
  105. sizeof(struct snd_emu8000*));
  106. }
  107. static void __exit alsa_emu8000_exit(void)
  108. {
  109. snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_EMU8000);
  110. }
  111. module_init(alsa_emu8000_init)
  112. module_exit(alsa_emu8000_exit)