emux_hwdep.c 3.6 KB

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