patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / core / seq / instr / ainstr_fm.c
1 /*
2  *  FM (OPL2/3) Instrument routines
3  *  Copyright (c) 2000 Uros Bizjak <uros@kss-loka.si>
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18  *
19  */
20  
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/sched.h>
24 #include <sound/core.h>
25 #include <sound/ainstr_fm.h>
26 #include <sound/initval.h>
27 #include <asm/uaccess.h>
28
29 MODULE_AUTHOR("Uros Bizjak <uros@kss-loka.si>");
30 MODULE_DESCRIPTION("Advanced Linux Sound Architecture FM Instrument support.");
31 MODULE_LICENSE("GPL");
32 MODULE_CLASSES("{sound}");
33 MODULE_SUPPORTED_DEVICE("sound");
34
35 char *snd_seq_fm_id = SNDRV_SEQ_INSTR_ID_OPL2_3;
36
37 static int snd_seq_fm_put(void *private_data, snd_seq_kinstr_t *instr,
38                           char __user *instr_data, long len, int atomic, int cmd)
39 {
40         fm_instrument_t *ip;
41         fm_xinstrument_t ix;
42         int idx;
43
44         if (cmd != SNDRV_SEQ_INSTR_PUT_CMD_CREATE)
45                 return -EINVAL;
46         /* copy instrument data */
47         if (len < (long)sizeof(ix))
48                 return -EINVAL;
49         if (copy_from_user(&ix, instr_data, sizeof(ix)))
50                 return -EFAULT;
51         if (ix.stype != FM_STRU_INSTR)
52                 return -EINVAL;
53         ip = (fm_instrument_t *)KINSTR_DATA(instr);
54         ip->share_id[0] = le32_to_cpu(ix.share_id[0]);
55         ip->share_id[1] = le32_to_cpu(ix.share_id[1]);
56         ip->share_id[2] = le32_to_cpu(ix.share_id[2]);
57         ip->share_id[3] = le32_to_cpu(ix.share_id[3]);
58         ip->type = ix.type;
59         for (idx = 0; idx < 4; idx++) {
60                 ip->op[idx].am_vib = ix.op[idx].am_vib;
61                 ip->op[idx].ksl_level = ix.op[idx].ksl_level;
62                 ip->op[idx].attack_decay = ix.op[idx].attack_decay;
63                 ip->op[idx].sustain_release = ix.op[idx].sustain_release;
64                 ip->op[idx].wave_select = ix.op[idx].wave_select;
65         }
66         for (idx = 0; idx < 2; idx++) {
67                 ip->feedback_connection[idx] = ix.feedback_connection[idx];
68         }
69         ip->echo_delay = ix.echo_delay;
70         ip->echo_atten = ix.echo_atten;
71         ip->chorus_spread = ix.chorus_spread;
72         ip->trnsps = ix.trnsps;
73         ip->fix_dur = ix.fix_dur;
74         ip->modes = ix.modes;
75         ip->fix_key = ix.fix_key;
76         return 0;
77 }
78
79 static int snd_seq_fm_get(void *private_data, snd_seq_kinstr_t *instr,
80                           char __user *instr_data, long len, int atomic,
81                           int cmd)
82 {
83         fm_instrument_t *ip;
84         fm_xinstrument_t ix;
85         int idx;
86         
87         if (cmd != SNDRV_SEQ_INSTR_GET_CMD_FULL)
88                 return -EINVAL;
89         if (len < (long)sizeof(ix))
90                 return -ENOMEM;
91         memset(&ix, 0, sizeof(ix));
92         ip = (fm_instrument_t *)KINSTR_DATA(instr);
93         ix.stype = FM_STRU_INSTR;
94         ix.share_id[0] = cpu_to_le32(ip->share_id[0]);
95         ix.share_id[1] = cpu_to_le32(ip->share_id[1]);
96         ix.share_id[2] = cpu_to_le32(ip->share_id[2]);
97         ix.share_id[3] = cpu_to_le32(ip->share_id[3]);
98         ix.type = ip->type;
99         for (idx = 0; idx < 4; idx++) {
100                 ix.op[idx].am_vib = ip->op[idx].am_vib;
101                 ix.op[idx].ksl_level = ip->op[idx].ksl_level;
102                 ix.op[idx].attack_decay = ip->op[idx].attack_decay;
103                 ix.op[idx].sustain_release = ip->op[idx].sustain_release;
104                 ix.op[idx].wave_select = ip->op[idx].wave_select;
105         }
106         for (idx = 0; idx < 2; idx++) {
107                 ix.feedback_connection[idx] = ip->feedback_connection[idx];
108         }
109         if (copy_to_user(instr_data, &ix, sizeof(ix)))
110                 return -EFAULT;
111         ix.echo_delay = ip->echo_delay;
112         ix.echo_atten = ip->echo_atten;
113         ix.chorus_spread = ip->chorus_spread;
114         ix.trnsps = ip->trnsps;
115         ix.fix_dur = ip->fix_dur;
116         ix.modes = ip->modes;
117         ix.fix_key = ip->fix_key;
118         return 0;
119 }
120
121 static int snd_seq_fm_get_size(void *private_data, snd_seq_kinstr_t *instr,
122                                long *size)
123 {
124         *size = sizeof(fm_xinstrument_t);
125         return 0;
126 }
127
128 int snd_seq_fm_init(snd_seq_kinstr_ops_t *ops,
129                     snd_seq_kinstr_ops_t *next)
130 {
131         memset(ops, 0, sizeof(*ops));
132         // ops->private_data = private_data;
133         ops->add_len = sizeof(fm_instrument_t);
134         ops->instr_type = snd_seq_fm_id;
135         ops->put = snd_seq_fm_put;
136         ops->get = snd_seq_fm_get;
137         ops->get_size = snd_seq_fm_get_size;
138         // ops->remove = snd_seq_fm_remove;
139         // ops->notify = snd_seq_fm_notify;
140         ops->next = next;
141         return 0;
142 }
143
144 /*
145  *  Init part
146  */
147
148 static int __init alsa_ainstr_fm_init(void)
149 {
150         return 0;
151 }
152
153 static void __exit alsa_ainstr_fm_exit(void)
154 {
155 }
156
157 module_init(alsa_ainstr_fm_init)
158 module_exit(alsa_ainstr_fm_exit)
159
160 EXPORT_SYMBOL(snd_seq_fm_id);
161 EXPORT_SYMBOL(snd_seq_fm_init);