emux.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_obj(*emu);
  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 = kzalloc_objs(struct snd_emux_voice, emu->max_voices);
  73. if (emu->name == NULL || emu->voices == NULL)
  74. return -ENOMEM;
  75. /* create soundfont list */
  76. memset(&sf_cb, 0, sizeof(sf_cb));
  77. sf_cb.private_data = emu;
  78. sf_cb.sample_new = sf_sample_new;
  79. sf_cb.sample_free = sf_sample_free;
  80. if (emu->ops.sample_reset)
  81. sf_cb.sample_reset = sf_sample_reset;
  82. emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
  83. if (emu->sflist == NULL)
  84. return -ENOMEM;
  85. err = snd_emux_init_hwdep(emu);
  86. if (err < 0)
  87. return err;
  88. snd_emux_init_voices(emu);
  89. snd_emux_init_seq(emu, card, index);
  90. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  91. snd_emux_init_seq_oss(emu);
  92. #endif
  93. snd_emux_init_virmidi(emu, card);
  94. snd_emux_proc_init(emu, card, index);
  95. return 0;
  96. }
  97. EXPORT_SYMBOL(snd_emux_register);
  98. /*
  99. */
  100. int snd_emux_free(struct snd_emux *emu)
  101. {
  102. if (! emu)
  103. return -EINVAL;
  104. timer_shutdown_sync(&emu->tlist);
  105. snd_emux_proc_free(emu);
  106. snd_emux_delete_virmidi(emu);
  107. #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
  108. snd_emux_detach_seq_oss(emu);
  109. #endif
  110. snd_emux_detach_seq(emu);
  111. snd_emux_delete_hwdep(emu);
  112. snd_sf_free(emu->sflist);
  113. kfree(emu->voices);
  114. kfree_const(emu->name);
  115. kfree(emu);
  116. return 0;
  117. }
  118. EXPORT_SYMBOL(snd_emux_free);