2 * Interface for hwdep device
4 * Copyright (C) 2004 Takashi Iwai <tiwai@suse.de>
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.
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.
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
22 #include <sound/driver.h>
23 #include <sound/core.h>
24 #include <sound/hwdep.h>
25 #include <asm/uaccess.h>
26 #include "emux_voice.h"
29 * open the hwdep device
32 snd_emux_hwdep_open(snd_hwdep_t
*hw
, struct file
*file
)
42 snd_emux_hwdep_release(snd_hwdep_t
*hw
, struct file
*file
)
48 #define TMP_CLIENT_ID 0x1001
54 snd_emux_hwdep_load_patch(snd_emux_t
*emu
, void __user
*arg
)
57 soundfont_patch_info_t patch
;
59 if (copy_from_user(&patch
, arg
, sizeof(patch
)))
62 if (patch
.type
>= SNDRV_SFNT_LOAD_INFO
&&
63 patch
.type
<= SNDRV_SFNT_PROBE_DATA
) {
64 err
= snd_soundfont_load(emu
->sflist
, arg
, patch
.len
+ sizeof(patch
), TMP_CLIENT_ID
);
69 return emu
->ops
.load_fx(emu
, patch
.type
, patch
.optarg
, arg
, patch
.len
+ sizeof(patch
));
80 snd_emux_hwdep_misc_mode(snd_emux_t
*emu
, void __user
*arg
)
82 struct sndrv_emux_misc_mode info
;
85 if (copy_from_user(&info
, arg
, sizeof(info
)))
87 if (info
.mode
< 0 || info
.mode
>= EMUX_MD_END
)
91 for (i
= 0; i
< emu
->num_ports
; i
++)
92 emu
->portptrs
[i
]->ctrls
[info
.mode
] = info
.value
;
94 if (info
.port
< emu
->num_ports
)
95 emu
->portptrs
[info
.port
]->ctrls
[info
.mode
] = info
.value
;
105 snd_emux_hwdep_ioctl(snd_hwdep_t
* hw
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
107 snd_emux_t
*emu
= hw
->private_data
;
110 case SNDRV_EMUX_IOCTL_VERSION
:
111 return put_user(SNDRV_EMUX_VERSION
, (unsigned int __user
*)arg
);
112 case SNDRV_EMUX_IOCTL_LOAD_PATCH
:
113 return snd_emux_hwdep_load_patch(emu
, (void __user
*)arg
);
114 case SNDRV_EMUX_IOCTL_RESET_SAMPLES
:
115 snd_soundfont_remove_samples(emu
->sflist
);
117 case SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES
:
118 snd_soundfont_remove_unlocked(emu
->sflist
);
120 case SNDRV_EMUX_IOCTL_MEM_AVAIL
:
122 int size
= snd_util_mem_avail(emu
->memhdr
);
123 return put_user(size
, (unsigned int __user
*)arg
);
126 case SNDRV_EMUX_IOCTL_MISC_MODE
:
127 return snd_emux_hwdep_misc_mode(emu
, (void __user
*)arg
);
135 * register hwdep device
139 snd_emux_init_hwdep(snd_emux_t
*emu
)
144 if ((err
= snd_hwdep_new(emu
->card
, SNDRV_EMUX_HWDEP_NAME
, emu
->hwdep_idx
, &hw
)) < 0)
147 strcpy(hw
->name
, SNDRV_EMUX_HWDEP_NAME
);
148 hw
->iface
= SNDRV_HWDEP_IFACE_EMUX_WAVETABLE
;
149 hw
->ops
.open
= snd_emux_hwdep_open
;
150 hw
->ops
.release
= snd_emux_hwdep_release
;
151 hw
->ops
.ioctl
= snd_emux_hwdep_ioctl
;
153 hw
->private_data
= emu
;
154 if ((err
= snd_card_register(emu
->card
)) < 0)
165 snd_emux_delete_hwdep(snd_emux_t
*emu
)
168 snd_device_free(emu
->card
, emu
->hwdep
);