emux_hwdep.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/core.h>
  22. #include <sound/hwdep.h>
  23. #include <asm/uaccess.h>
  24. #include "emux_voice.h"
  25. /*
  26. * open the hwdep device
  27. */
  28. static int
  29. snd_emux_hwdep_open(struct snd_hwdep *hw, struct file *file)
  30. {
  31. return 0;
  32. }
  33. /*
  34. * close the device
  35. */
  36. static int
  37. snd_emux_hwdep_release(struct snd_hwdep *hw, struct file *file)
  38. {
  39. return 0;
  40. }
  41. #define TMP_CLIENT_ID 0x1001
  42. /*
  43. * load patch
  44. */
  45. static int
  46. snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)
  47. {
  48. int err;
  49. struct soundfont_patch_info patch;
  50. if (copy_from_user(&patch, arg, sizeof(patch)))
  51. return -EFAULT;
  52. if (patch.type >= SNDRV_SFNT_LOAD_INFO &&
  53. patch.type <= SNDRV_SFNT_PROBE_DATA) {
  54. err = snd_soundfont_load(emu->sflist, arg, patch.len + sizeof(patch), TMP_CLIENT_ID);
  55. if (err < 0)
  56. return err;
  57. } else {
  58. if (emu->ops.load_fx)
  59. return emu->ops.load_fx(emu, patch.type, patch.optarg, arg, patch.len + sizeof(patch));
  60. else
  61. return -EINVAL;
  62. }
  63. return 0;
  64. }
  65. /*
  66. * set misc mode
  67. */
  68. static int
  69. snd_emux_hwdep_misc_mode(struct snd_emux *emu, void __user *arg)
  70. {
  71. struct snd_emux_misc_mode info;
  72. int i;
  73. if (copy_from_user(&info, arg, sizeof(info)))
  74. return -EFAULT;
  75. if (info.mode < 0 || info.mode >= EMUX_MD_END)
  76. return -EINVAL;
  77. if (info.port < 0) {
  78. for (i = 0; i < emu->num_ports; i++)
  79. emu->portptrs[i]->ctrls[info.mode] = info.value;
  80. } else {
  81. if (info.port < emu->num_ports)
  82. emu->portptrs[info.port]->ctrls[info.mode] = info.value;
  83. }
  84. return 0;
  85. }
  86. /*
  87. * ioctl
  88. */
  89. static int
  90. snd_emux_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
  91. unsigned int cmd, unsigned long arg)
  92. {
  93. struct snd_emux *emu = hw->private_data;
  94. switch (cmd) {
  95. case SNDRV_EMUX_IOCTL_VERSION:
  96. return put_user(SNDRV_EMUX_VERSION, (unsigned int __user *)arg);
  97. case SNDRV_EMUX_IOCTL_LOAD_PATCH:
  98. return snd_emux_hwdep_load_patch(emu, (void __user *)arg);
  99. case SNDRV_EMUX_IOCTL_RESET_SAMPLES:
  100. snd_soundfont_remove_samples(emu->sflist);
  101. break;
  102. case SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES:
  103. snd_soundfont_remove_unlocked(emu->sflist);
  104. break;
  105. case SNDRV_EMUX_IOCTL_MEM_AVAIL:
  106. if (emu->memhdr) {
  107. int size = snd_util_mem_avail(emu->memhdr);
  108. return put_user(size, (unsigned int __user *)arg);
  109. }
  110. break;
  111. case SNDRV_EMUX_IOCTL_MISC_MODE:
  112. return snd_emux_hwdep_misc_mode(emu, (void __user *)arg);
  113. }
  114. return 0;
  115. }
  116. /*
  117. * register hwdep device
  118. */
  119. int
  120. snd_emux_init_hwdep(struct snd_emux *emu)
  121. {
  122. struct snd_hwdep *hw;
  123. int err;
  124. if ((err = snd_hwdep_new(emu->card, SNDRV_EMUX_HWDEP_NAME, emu->hwdep_idx, &hw)) < 0)
  125. return err;
  126. emu->hwdep = hw;
  127. strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
  128. hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
  129. hw->ops.open = snd_emux_hwdep_open;
  130. hw->ops.release = snd_emux_hwdep_release;
  131. hw->ops.ioctl = snd_emux_hwdep_ioctl;
  132. hw->exclusive = 1;
  133. hw->private_data = emu;
  134. if ((err = snd_card_register(emu->card)) < 0)
  135. return err;
  136. return 0;
  137. }
  138. /*
  139. * unregister
  140. */
  141. void
  142. snd_emux_delete_hwdep(struct snd_emux *emu)
  143. {
  144. if (emu->hwdep) {
  145. snd_device_free(emu->card, emu->hwdep);
  146. emu->hwdep = NULL;
  147. }
  148. }