emu8000_synth.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_probe(struct device *_dev)
  34. {
  35. struct snd_seq_device *dev = to_seq_dev(_dev);
  36. struct snd_emu8000 *hw;
  37. struct snd_emux *emu;
  38. hw = *(struct snd_emu8000**)SNDRV_SEQ_DEVICE_ARGPTR(dev);
  39. if (hw == NULL)
  40. return -EINVAL;
  41. if (hw->emu)
  42. return -EBUSY; /* already exists..? */
  43. if (snd_emux_new(&emu) < 0)
  44. return -ENOMEM;
  45. hw->emu = emu;
  46. snd_emu8000_ops_setup(hw);
  47. emu->hw = hw;
  48. emu->max_voices = EMU8000_DRAM_VOICES;
  49. emu->num_ports = hw->seq_ports;
  50. if (hw->memhdr) {
  51. snd_printk(KERN_ERR "memhdr is already initialized!?\n");
  52. snd_util_memhdr_free(hw->memhdr);
  53. }
  54. hw->memhdr = snd_util_memhdr_new(hw->mem_size);
  55. if (hw->memhdr == NULL) {
  56. snd_emux_free(emu);
  57. hw->emu = NULL;
  58. return -ENOMEM;
  59. }
  60. emu->memhdr = hw->memhdr;
  61. emu->midi_ports = hw->seq_ports < 2 ? hw->seq_ports : 2; /* number of virmidi ports */
  62. emu->midi_devidx = 1;
  63. emu->linear_panning = 1;
  64. emu->hwdep_idx = 2; /* FIXED */
  65. if (snd_emux_register(emu, dev->card, hw->index, "Emu8000") < 0) {
  66. snd_emux_free(emu);
  67. snd_util_memhdr_free(hw->memhdr);
  68. hw->emu = NULL;
  69. hw->memhdr = NULL;
  70. return -ENOMEM;
  71. }
  72. if (hw->mem_size > 0)
  73. snd_emu8000_pcm_new(dev->card, hw, 1);
  74. dev->driver_data = hw;
  75. return 0;
  76. }
  77. /*
  78. * free all resources
  79. */
  80. static int snd_emu8000_remove(struct device *_dev)
  81. {
  82. struct snd_seq_device *dev = to_seq_dev(_dev);
  83. struct snd_emu8000 *hw;
  84. if (dev->driver_data == NULL)
  85. return 0; /* no synth was allocated actually */
  86. hw = dev->driver_data;
  87. if (hw->pcm)
  88. snd_device_free(dev->card, hw->pcm);
  89. snd_emux_free(hw->emu);
  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 struct snd_seq_driver emu8000_driver = {
  99. .driver = {
  100. .name = KBUILD_MODNAME,
  101. .probe = snd_emu8000_probe,
  102. .remove = snd_emu8000_remove,
  103. },
  104. .id = SNDRV_SEQ_DEV_ID_EMU8000,
  105. .argsize = sizeof(struct snd_emu8000 *),
  106. };
  107. module_snd_seq_driver(emu8000_driver);