emux_hwdep.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Interface for hwdep device
  3. *
  4. * Copyright (C) 2004 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <sound/core.h>
  23. #include <sound/hwdep.h>
  24. #include <asm/uaccess.h>
  25. #include "emux_voice.h"
  26. /*
  27. * open the hwdep device
  28. */
  29. static int
  30. snd_emux_hwdep_open(struct snd_hwdep *hw, struct file *file)
  31. {
  32. return 0;
  33. }
  34. /*
  35. * close the device
  36. */
  37. static int
  38. snd_emux_hwdep_release(struct snd_hwdep *hw, struct file *file)
  39. {
  40. return 0;
  41. }
  42. #define TMP_CLIENT_ID 0x1001
  43. /*
  44. * load patch
  45. */
  46. static int
  47. snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)
  48. {
  49. int err;
  50. struct soundfont_patch_info patch;
  51. if (copy_from_user(&patch, arg, sizeof(patch)))
  52. return -EFAULT;
  53. if (patch.type >= SNDRV_SFNT_LOAD_INFO &&
  54. patch.type <= SNDRV_SFNT_PROBE_DATA) {
  55. err = snd_soundfont_load(emu->sflist, arg, patch.len + sizeof(patch), TMP_CLIENT_ID);
  56. if (err < 0)
  57. return err;
  58. } else {
  59. if (emu->ops.load_fx)
  60. return emu->ops.load_fx(emu, patch.type, patch.optarg, arg, patch.len + sizeof(patch));
  61. else
  62. return -EINVAL;
  63. }
  64. return 0;
  65. }
  66. /*
  67. * set misc mode
  68. */
  69. static int
  70. snd_emux_hwdep_misc_mode(struct snd_emux *emu, void __user *arg)
  71. {
  72. struct snd_emux_misc_mode info;
  73. int i;
  74. if (copy_from_user(&info, arg, sizeof(info)))
  75. return -EFAULT;
  76. if (info.mode < 0 || info.mode >= EMUX_MD_END)
  77. return -EINVAL;
  78. if (info.port < 0) {
  79. for (i = 0; i < emu->num_ports; i++)
  80. emu->portptrs[i]->ctrls[info.mode] = info.value;
  81. } else {
  82. if (info.port < emu->num_ports)
  83. emu->portptrs[info.port]->ctrls[info.mode] = info.value;
  84. }
  85. return 0;
  86. }
  87. /*
  88. * ioctl
  89. */
  90. static int
  91. snd_emux_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
  92. unsigned int cmd, unsigned long arg)
  93. {
  94. struct snd_emux *emu = hw->private_data;
  95. switch (cmd) {
  96. case SNDRV_EMUX_IOCTL_VERSION:
  97. return put_user(SNDRV_EMUX_VERSION, (unsigned int __user *)arg);
  98. case SNDRV_EMUX_IOCTL_LOAD_PATCH:
  99. return snd_emux_hwdep_load_patch(emu, (void __user *)arg);
  100. case SNDRV_EMUX_IOCTL_RESET_SAMPLES:
  101. snd_soundfont_remove_samples(emu->sflist);
  102. break;
  103. case SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES:
  104. snd_soundfont_remove_unlocked(emu->sflist);
  105. break;
  106. case SNDRV_EMUX_IOCTL_MEM_AVAIL:
  107. if (emu->memhdr) {
  108. int size = snd_util_mem_avail(emu->memhdr);
  109. return put_user(size, (unsigned int __user *)arg);
  110. }
  111. break;
  112. case SNDRV_EMUX_IOCTL_MISC_MODE:
  113. return snd_emux_hwdep_misc_mode(emu, (void __user *)arg);
  114. }
  115. return 0;
  116. }
  117. /*
  118. * register hwdep device
  119. */
  120. int
  121. snd_emux_init_hwdep(struct snd_emux *emu)
  122. {
  123. struct snd_hwdep *hw;
  124. int err;
  125. if ((err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw)) < 0)
  126. return err;
  127. emu->hwdep = hw;
  128. strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
  129. hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
  130. hw->ops.open = snd_emux_hwdep_open;
  131. hw->ops.release = snd_emux_hwdep_release;
  132. hw->ops.ioctl = snd_emux_hwdep_ioctl;
  133. hw->exclusive = 1;
  134. hw->private_data = emu;
  135. if ((err = snd_card_register(emu->card)) < 0)
  136. return err;
  137. return 0;
  138. }
  139. /*
  140. * unregister
  141. */
  142. void
  143. snd_emux_delete_hwdep(struct snd_emux *emu)
  144. {
  145. if (emu->hwdep) {
  146. snd_device_free(emu->card, emu->hwdep);
  147. emu->hwdep = NULL;
  148. }
  149. }