seq_oss.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * OSS compatible sequencer driver
  3. *
  4. * registration of device and proc
  5. *
  6. * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/mutex.h>
  25. #include <sound/core.h>
  26. #include <sound/minors.h>
  27. #include <sound/initval.h>
  28. #include "seq_oss_device.h"
  29. #include "seq_oss_synth.h"
  30. /*
  31. * module option
  32. */
  33. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  34. MODULE_DESCRIPTION("OSS-compatible sequencer module");
  35. MODULE_LICENSE("GPL");
  36. /* Takashi says this is really only for sound-service-0-, but this is OK. */
  37. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
  38. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
  39. /*
  40. * prototypes
  41. */
  42. static int register_device(void);
  43. static void unregister_device(void);
  44. #ifdef CONFIG_SND_PROC_FS
  45. static int register_proc(void);
  46. static void unregister_proc(void);
  47. #else
  48. static inline int register_proc(void) { return 0; }
  49. static inline void unregister_proc(void) {}
  50. #endif
  51. static int odev_open(struct inode *inode, struct file *file);
  52. static int odev_release(struct inode *inode, struct file *file);
  53. static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
  54. static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
  55. static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  56. static unsigned int odev_poll(struct file *file, poll_table * wait);
  57. /*
  58. * module interface
  59. */
  60. static struct snd_seq_driver seq_oss_synth_driver = {
  61. .driver = {
  62. .name = KBUILD_MODNAME,
  63. .probe = snd_seq_oss_synth_probe,
  64. .remove = snd_seq_oss_synth_remove,
  65. },
  66. .id = SNDRV_SEQ_DEV_ID_OSS,
  67. .argsize = sizeof(struct snd_seq_oss_reg),
  68. };
  69. static int __init alsa_seq_oss_init(void)
  70. {
  71. int rc;
  72. if ((rc = register_device()) < 0)
  73. goto error;
  74. if ((rc = register_proc()) < 0) {
  75. unregister_device();
  76. goto error;
  77. }
  78. if ((rc = snd_seq_oss_create_client()) < 0) {
  79. unregister_proc();
  80. unregister_device();
  81. goto error;
  82. }
  83. rc = snd_seq_driver_register(&seq_oss_synth_driver);
  84. if (rc < 0) {
  85. snd_seq_oss_delete_client();
  86. unregister_proc();
  87. unregister_device();
  88. goto error;
  89. }
  90. /* success */
  91. snd_seq_oss_synth_init();
  92. error:
  93. return rc;
  94. }
  95. static void __exit alsa_seq_oss_exit(void)
  96. {
  97. snd_seq_driver_unregister(&seq_oss_synth_driver);
  98. snd_seq_oss_delete_client();
  99. unregister_proc();
  100. unregister_device();
  101. }
  102. module_init(alsa_seq_oss_init)
  103. module_exit(alsa_seq_oss_exit)
  104. /*
  105. * ALSA minor device interface
  106. */
  107. static DEFINE_MUTEX(register_mutex);
  108. static int
  109. odev_open(struct inode *inode, struct file *file)
  110. {
  111. int level, rc;
  112. if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
  113. level = SNDRV_SEQ_OSS_MODE_MUSIC;
  114. else
  115. level = SNDRV_SEQ_OSS_MODE_SYNTH;
  116. mutex_lock(&register_mutex);
  117. rc = snd_seq_oss_open(file, level);
  118. mutex_unlock(&register_mutex);
  119. return rc;
  120. }
  121. static int
  122. odev_release(struct inode *inode, struct file *file)
  123. {
  124. struct seq_oss_devinfo *dp;
  125. if ((dp = file->private_data) == NULL)
  126. return 0;
  127. mutex_lock(&register_mutex);
  128. snd_seq_oss_release(dp);
  129. mutex_unlock(&register_mutex);
  130. return 0;
  131. }
  132. static ssize_t
  133. odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  134. {
  135. struct seq_oss_devinfo *dp;
  136. dp = file->private_data;
  137. if (snd_BUG_ON(!dp))
  138. return -ENXIO;
  139. return snd_seq_oss_read(dp, buf, count);
  140. }
  141. static ssize_t
  142. odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
  143. {
  144. struct seq_oss_devinfo *dp;
  145. dp = file->private_data;
  146. if (snd_BUG_ON(!dp))
  147. return -ENXIO;
  148. return snd_seq_oss_write(dp, buf, count, file);
  149. }
  150. static long
  151. odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  152. {
  153. struct seq_oss_devinfo *dp;
  154. dp = file->private_data;
  155. if (snd_BUG_ON(!dp))
  156. return -ENXIO;
  157. return snd_seq_oss_ioctl(dp, cmd, arg);
  158. }
  159. #ifdef CONFIG_COMPAT
  160. #define odev_ioctl_compat odev_ioctl
  161. #else
  162. #define odev_ioctl_compat NULL
  163. #endif
  164. static unsigned int
  165. odev_poll(struct file *file, poll_table * wait)
  166. {
  167. struct seq_oss_devinfo *dp;
  168. dp = file->private_data;
  169. if (snd_BUG_ON(!dp))
  170. return -ENXIO;
  171. return snd_seq_oss_poll(dp, file, wait);
  172. }
  173. /*
  174. * registration of sequencer minor device
  175. */
  176. static const struct file_operations seq_oss_f_ops =
  177. {
  178. .owner = THIS_MODULE,
  179. .read = odev_read,
  180. .write = odev_write,
  181. .open = odev_open,
  182. .release = odev_release,
  183. .poll = odev_poll,
  184. .unlocked_ioctl = odev_ioctl,
  185. .compat_ioctl = odev_ioctl_compat,
  186. .llseek = noop_llseek,
  187. };
  188. static int __init
  189. register_device(void)
  190. {
  191. int rc;
  192. mutex_lock(&register_mutex);
  193. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
  194. NULL, 0,
  195. &seq_oss_f_ops, NULL)) < 0) {
  196. pr_err("ALSA: seq_oss: can't register device seq\n");
  197. mutex_unlock(&register_mutex);
  198. return rc;
  199. }
  200. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
  201. NULL, 0,
  202. &seq_oss_f_ops, NULL)) < 0) {
  203. pr_err("ALSA: seq_oss: can't register device music\n");
  204. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
  205. mutex_unlock(&register_mutex);
  206. return rc;
  207. }
  208. mutex_unlock(&register_mutex);
  209. return 0;
  210. }
  211. static void
  212. unregister_device(void)
  213. {
  214. mutex_lock(&register_mutex);
  215. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
  216. pr_err("ALSA: seq_oss: error unregister device music\n");
  217. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
  218. pr_err("ALSA: seq_oss: error unregister device seq\n");
  219. mutex_unlock(&register_mutex);
  220. }
  221. /*
  222. * /proc interface
  223. */
  224. #ifdef CONFIG_SND_PROC_FS
  225. static struct snd_info_entry *info_entry;
  226. static void
  227. info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
  228. {
  229. mutex_lock(&register_mutex);
  230. snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
  231. snd_seq_oss_system_info_read(buf);
  232. snd_seq_oss_synth_info_read(buf);
  233. snd_seq_oss_midi_info_read(buf);
  234. mutex_unlock(&register_mutex);
  235. }
  236. static int __init
  237. register_proc(void)
  238. {
  239. struct snd_info_entry *entry;
  240. entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
  241. if (entry == NULL)
  242. return -ENOMEM;
  243. entry->content = SNDRV_INFO_CONTENT_TEXT;
  244. entry->private_data = NULL;
  245. entry->c.text.read = info_read;
  246. if (snd_info_register(entry) < 0) {
  247. snd_info_free_entry(entry);
  248. return -ENOMEM;
  249. }
  250. info_entry = entry;
  251. return 0;
  252. }
  253. static void
  254. unregister_proc(void)
  255. {
  256. snd_info_free_entry(info_entry);
  257. info_entry = NULL;
  258. }
  259. #endif /* CONFIG_SND_PROC_FS */