blob: d0c38e1856ef5f867029a785c3a991f8a91978f3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Routines for Gravis UltraSound soundcards - Synthesizer
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 *
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
22#include <sound/driver.h>
23#include <linux/time.h>
24#include <sound/core.h>
25#include <sound/gus.h>
26
27/*
28 *
29 */
30
Takashi Iwai5e2da202005-11-17 14:36:44 +010031int snd_gus_iwffff_put_sample(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 char __user *data, long len, int atomic)
33{
Takashi Iwai5e2da202005-11-17 14:36:44 +010034 struct snd_gus_card *gus = private_data;
35 struct snd_gf1_mem_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int err;
37
38 if (wave->format & IWFFFF_WAVE_ROM)
39 return 0; /* it's probably ok - verify the address? */
40 if (wave->format & IWFFFF_WAVE_STEREO)
41 return -EINVAL; /* not supported */
42 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
43 SNDRV_GF1_MEM_OWNER_WAVE_IWFFFF,
44 NULL, wave->size,
45 wave->format & IWFFFF_WAVE_16BIT, 1,
46 wave->share_id);
47 if (block == NULL)
48 return -ENOMEM;
49 err = snd_gus_dram_write(gus, data,
50 block->ptr, wave->size);
51 if (err < 0) {
52 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
53 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
54 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
55 return err;
56 }
57 wave->address.memory = block->ptr;
58 return 0;
59}
60
Takashi Iwai5e2da202005-11-17 14:36:44 +010061int snd_gus_iwffff_get_sample(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 char __user *data, long len, int atomic)
63{
Takashi Iwai5e2da202005-11-17 14:36:44 +010064 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size,
67 wave->format & IWFFFF_WAVE_ROM ? 1 : 0);
68}
69
Takashi Iwai5e2da202005-11-17 14:36:44 +010070int snd_gus_iwffff_remove_sample(void *private_data, struct iwffff_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 int atomic)
72{
Takashi Iwai5e2da202005-11-17 14:36:44 +010073 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 if (wave->format & IWFFFF_WAVE_ROM)
76 return 0; /* it's probably ok - verify the address? */
77 return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
78}
79
80/*
81 *
82 */
83
Takashi Iwai5e2da202005-11-17 14:36:44 +010084int snd_gus_gf1_put_sample(void *private_data, struct gf1_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 char __user *data, long len, int atomic)
86{
Takashi Iwai5e2da202005-11-17 14:36:44 +010087 struct snd_gus_card *gus = private_data;
88 struct snd_gf1_mem_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 int err;
90
91 if (wave->format & GF1_WAVE_STEREO)
92 return -EINVAL; /* not supported */
93 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
94 SNDRV_GF1_MEM_OWNER_WAVE_GF1,
95 NULL, wave->size,
96 wave->format & GF1_WAVE_16BIT, 1,
97 wave->share_id);
98 if (block == NULL)
99 return -ENOMEM;
100 err = snd_gus_dram_write(gus, data,
101 block->ptr, wave->size);
102 if (err < 0) {
103 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
104 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
105 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
106 return err;
107 }
108 wave->address.memory = block->ptr;
109 return 0;
110}
111
Takashi Iwai5e2da202005-11-17 14:36:44 +0100112int snd_gus_gf1_get_sample(void *private_data, struct gf1_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 char __user *data, long len, int atomic)
114{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100115 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 return snd_gus_dram_read(gus, data, wave->address.memory, wave->size, 0);
118}
119
Takashi Iwai5e2da202005-11-17 14:36:44 +0100120int snd_gus_gf1_remove_sample(void *private_data, struct gf1_wave *wave,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 int atomic)
122{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100123 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 return snd_gf1_mem_free(&gus->gf1.mem_alloc, wave->address.memory);
126}
127
128/*
129 *
130 */
131
Takashi Iwai5e2da202005-11-17 14:36:44 +0100132int snd_gus_simple_put_sample(void *private_data, struct simple_instrument *instr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 char __user *data, long len, int atomic)
134{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100135 struct snd_gus_card *gus = private_data;
136 struct snd_gf1_mem_block *block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 int err;
138
139 if (instr->format & SIMPLE_WAVE_STEREO)
140 return -EINVAL; /* not supported */
141 block = snd_gf1_mem_alloc(&gus->gf1.mem_alloc,
142 SNDRV_GF1_MEM_OWNER_WAVE_SIMPLE,
143 NULL, instr->size,
144 instr->format & SIMPLE_WAVE_16BIT, 1,
145 instr->share_id);
146 if (block == NULL)
147 return -ENOMEM;
148 err = snd_gus_dram_write(gus, data, block->ptr, instr->size);
149 if (err < 0) {
150 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 0);
151 snd_gf1_mem_xfree(&gus->gf1.mem_alloc, block);
152 snd_gf1_mem_lock(&gus->gf1.mem_alloc, 1);
153 return err;
154 }
155 instr->address.memory = block->ptr;
156 return 0;
157}
158
Takashi Iwai5e2da202005-11-17 14:36:44 +0100159int snd_gus_simple_get_sample(void *private_data, struct simple_instrument *instr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 char __user *data, long len, int atomic)
161{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100162 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 return snd_gus_dram_read(gus, data, instr->address.memory, instr->size, 0);
165}
166
Takashi Iwai5e2da202005-11-17 14:36:44 +0100167int snd_gus_simple_remove_sample(void *private_data, struct simple_instrument *instr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 int atomic)
169{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100170 struct snd_gus_card *gus = private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 return snd_gf1_mem_free(&gus->gf1.mem_alloc, instr->address.memory);
173}