emux.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
  4. *
  5. * Routines for control of EMU WaveTable chip
  6. */
  7. #include <linux/wait.h>
  8. #include <linux/slab.h>
  9. #include <linux/string.h>
  10. #include <sound/core.h>
  11. #include <sound/emux_synth.h>
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include "emux_voice.h"
  15. MODULE_AUTHOR("Takashi Iwai");
  16. MODULE_DESCRIPTION("Routines for control of EMU WaveTable chip");
  17. MODULE_LICENSE("GPL");
  18. /*
  19. * create a new hardware dependent device for Emu8000/Emu10k1
  20. */
  21. int snd_emux_new(struct snd_emux **remu)
  22. {
  23. struct snd_emux *emu;
  24. *remu = NULL;
  25. emu = kzalloc(sizeof(*emu), GFP_KERNEL);
  26. if (emu == NULL)
  27. return -ENOMEM;
  28. spin_lock_init(&emu->voice_lock);
  29. mutex_init(&emu->register_mutex);
  30. emu->client = -1;
  31. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  32. emu->oss_synth = NULL;
  33. #endif
  34. emu->max_voices = 0;
  35. emu->use_time = 0;
  36. timer_setup(&emu->tlist, snd_emux_timer_callback, 0);
  37. emu->timer_active = 0;
  38. *remu = emu;
  39. return 0;
  40. }
  41. EXPORT_SYMBOL(snd_emux_new);
  42. /*
  43. */
  44. static int sf_sample_new(void *private_data, struct snd_sf_sample *sp,
  45. struct snd_util_memhdr *hdr,
  46. const void __user *buf, long count)
  47. {
  48. struct snd_emux *emu = private_data;
  49. return emu->ops.sample_new(emu, sp, hdr, buf, count);
  50. }
  51. static int sf_sample_free(void *private_data, struct snd_sf_sample *sp,
  52. struct snd_util_memhdr *hdr)
  53. {
  54. struct snd_emux *emu = private_data;
  55. return emu->ops.sample_free(emu, sp, hdr);
  56. }
  57. static void sf_sample_reset(void *private_data)
  58. {
  59. struct snd_emux *emu = private_data;
  60. emu->ops.sample_reset(emu);
  61. }
  62. int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name)
  63. {
  64. int err;
  65. struct snd_sf_callback sf_cb;
  66. if (snd_BUG_ON(!emu->hw || emu->max_voices <= 0))
  67. return -EINVAL;
  68. if (snd_BUG_ON(!card || !name))
  69. return -EINVAL;
  70. emu->card = card;
  71. emu->name = kstrdup_const(name, GFP_KERNEL);
  72. emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
  73. GFP_KERNEL);
  74. if (emu->name == NULL || emu->voices == NULL)
  75. return -ENOMEM;
  76. /* create soundfont list */
  77. memset(&sf_cb, 0, sizeof(sf_cb));
  78. sf_cb.private_data = emu;
  79. sf_cb.sample_new = sf_sample_new;
  80. sf_cb.sample_free = sf_sample_free;
  81. if (emu->ops.sample_reset)
  82. sf_cb.sample_reset = sf_sample_reset;
  83. emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
  84. if (emu->sflist == NULL)
  85. return -ENOMEM;
  86. err = snd_emux_init_hwdep(emu);
  87. if (err < 0)
  88. return err;
  89. snd_emux_init_voices(emu);
  90. snd_emux_init_seq(emu, card, index);
  91. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  92. snd_emux_init_seq_oss(emu);
  93. #endif
  94. snd_emux_init_virmidi(emu, card);
  95. snd_emux_proc_init(emu, card, index);
  96. return 0;
  97. }
  98. EXPORT_SYMBOL(snd_emux_register);
  99. /*
  100. */
  101. int snd_emux_free(struct snd_emux *emu)
  102. {
  103. if (! emu)
  104. return -EINVAL;
  105. timer_shutdown_sync(&emu->tlist);
  106. snd_emux_proc_free(emu);
  107. snd_emux_delete_virmidi(emu);
  108. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  109. snd_emux_detach_seq_oss(emu);
  110. #endif
  111. snd_emux_detach_seq(emu);
  112. snd_emux_delete_hwdep(emu);
  113. snd_sf_free(emu->sflist);
  114. kfree(emu->voices);
  115. kfree_const(emu->name);
  116. kfree(emu);
  117. return 0;
  118. }
  119. EXPORT_SYMBOL(snd_emux_free);