~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/oss/emu10k1/mixer.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  **********************************************************************
  3  *     mixer.c - /dev/mixer interface for emu10k1 driver
  4  *     Copyright 1999, 2000 Creative Labs, Inc.
  5  *
  6  **********************************************************************
  7  *
  8  *     Date                 Author          Summary of changes
  9  *     ----                 ------          ------------------
 10  *     October 20, 1999     Bertrand Lee    base code release
 11  *     November 2, 1999     Alan Cox        cleaned up stuff
 12  *
 13  **********************************************************************
 14  *
 15  *     This program is free software; you can redistribute it and/or
 16  *     modify it under the terms of the GNU General Public License as
 17  *     published by the Free Software Foundation; either version 2 of
 18  *     the License, or (at your option) any later version.
 19  *
 20  *     This program is distributed in the hope that it will be useful,
 21  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 22  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23  *     GNU General Public License for more details.
 24  *
 25  *     You should have received a copy of the GNU General Public
 26  *     License along with this program; if not, write to the Free
 27  *     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 28  *     USA.
 29  *
 30  **********************************************************************
 31  */
 32 
 33 #include <linux/module.h>
 34 #include <asm/uaccess.h>
 35 #include <linux/fs.h>
 36 
 37 #include "hwaccess.h"
 38 #include "8010.h"
 39 #include "recmgr.h"
 40 
 41 
 42 static const u32 bass_table[41][5] = {
 43         { 0x3e4f844f, 0x84ed4cc3, 0x3cc69927, 0x7b03553a, 0xc4da8486 },
 44         { 0x3e69a17a, 0x84c280fb, 0x3cd77cd4, 0x7b2f2a6f, 0xc4b08d1d },
 45         { 0x3e82ff42, 0x849991d5, 0x3ce7466b, 0x7b5917c6, 0xc48863ee },
 46         { 0x3e9bab3c, 0x847267f0, 0x3cf5ffe8, 0x7b813560, 0xc461f22c },
 47         { 0x3eb3b275, 0x844ced29, 0x3d03b295, 0x7ba79a1c, 0xc43d223b },
 48         { 0x3ecb2174, 0x84290c8b, 0x3d106714, 0x7bcc5ba3, 0xc419dfa5 },
 49         { 0x3ee2044b, 0x8406b244, 0x3d1c2561, 0x7bef8e77, 0xc3f8170f },
 50         { 0x3ef86698, 0x83e5cb96, 0x3d26f4d8, 0x7c114600, 0xc3d7b625 },
 51         { 0x3f0e5390, 0x83c646c9, 0x3d30dc39, 0x7c319498, 0xc3b8ab97 },
 52         { 0x3f23d60b, 0x83a81321, 0x3d39e1af, 0x7c508b9c, 0xc39ae704 },
 53         { 0x3f38f884, 0x838b20d2, 0x3d420ad2, 0x7c6e3b75, 0xc37e58f1 },
 54         { 0x3f4dc52c, 0x836f60ef, 0x3d495cab, 0x7c8ab3a6, 0xc362f2be },
 55         { 0x3f6245e8, 0x8354c565, 0x3d4fdbb8, 0x7ca602d6, 0xc348a69b },
 56         { 0x3f76845f, 0x833b40ec, 0x3d558bf0, 0x7cc036df, 0xc32f677c },
 57         { 0x3f8a8a03, 0x8322c6fb, 0x3d5a70c4, 0x7cd95cd7, 0xc317290b },
 58         { 0x3f9e6014, 0x830b4bc3, 0x3d5e8d25, 0x7cf1811a, 0xc2ffdfa5 },
 59         { 0x3fb20fae, 0x82f4c420, 0x3d61e37f, 0x7d08af56, 0xc2e9804a },
 60         { 0x3fc5a1cc, 0x82df2592, 0x3d6475c3, 0x7d1ef294, 0xc2d40096 },
 61         { 0x3fd91f55, 0x82ca6632, 0x3d664564, 0x7d345541, 0xc2bf56b9 },
 62         { 0x3fec9120, 0x82b67cac, 0x3d675356, 0x7d48e138, 0xc2ab796e },
 63         { 0x40000000, 0x82a36037, 0x3d67a012, 0x7d5c9fc9, 0xc2985fee },
 64         { 0x401374c7, 0x8291088a, 0x3d672b93, 0x7d6f99c3, 0xc28601f2 },
 65         { 0x4026f857, 0x827f6dd7, 0x3d65f559, 0x7d81d77c, 0xc27457a3 },
 66         { 0x403a939f, 0x826e88c5, 0x3d63fc63, 0x7d9360d4, 0xc2635996 },
 67         { 0x404e4faf, 0x825e5266, 0x3d613f32, 0x7da43d42, 0xc25300c6 },
 68         { 0x406235ba, 0x824ec434, 0x3d5dbbc3, 0x7db473d7, 0xc243468e },
 69         { 0x40764f1f, 0x823fd80c, 0x3d596f8f, 0x7dc40b44, 0xc23424a2 },
 70         { 0x408aa576, 0x82318824, 0x3d545787, 0x7dd309e2, 0xc2259509 },
 71         { 0x409f4296, 0x8223cf0b, 0x3d4e7012, 0x7de175b5, 0xc2179218 },
 72         { 0x40b430a0, 0x8216a7a1, 0x3d47b505, 0x7def5475, 0xc20a1670 },
 73         { 0x40c97a0a, 0x820a0d12, 0x3d4021a1, 0x7dfcab8d, 0xc1fd1cf5 },
 74         { 0x40df29a6, 0x81fdfad6, 0x3d37b08d, 0x7e098028, 0xc1f0a0ca },
 75         { 0x40f54ab1, 0x81f26ca9, 0x3d2e5bd1, 0x7e15d72b, 0xc1e49d52 },
 76         { 0x410be8da, 0x81e75e89, 0x3d241cce, 0x7e21b544, 0xc1d90e24 },
 77         { 0x41231051, 0x81dcccb3, 0x3d18ec37, 0x7e2d1ee6, 0xc1cdef10 },
 78         { 0x413acdd0, 0x81d2b39e, 0x3d0cc20a, 0x7e38184e, 0xc1c33c13 },
 79         { 0x41532ea7, 0x81c90ffb, 0x3cff9585, 0x7e42a58b, 0xc1b8f15a },
 80         { 0x416c40cd, 0x81bfdeb2, 0x3cf15d21, 0x7e4cca7c, 0xc1af0b3f },
 81         { 0x418612ea, 0x81b71cdc, 0x3ce20e85, 0x7e568ad3, 0xc1a58640 },
 82         { 0x41a0b465, 0x81aec7c5, 0x3cd19e7c, 0x7e5fea1e, 0xc19c5f03 },
 83         { 0x41bc3573, 0x81a6dcea, 0x3cc000e9, 0x7e68ebc2, 0xc1939250 }
 84 };
 85 
 86 static const u32 treble_table[41][5] = {
 87         { 0x0125cba9, 0xfed5debd, 0x00599b6c, 0x0d2506da, 0xfa85b354 },
 88         { 0x0142f67e, 0xfeb03163, 0x0066cd0f, 0x0d14c69d, 0xfa914473 },
 89         { 0x016328bd, 0xfe860158, 0x0075b7f2, 0x0d03eb27, 0xfa9d32d2 },
 90         { 0x0186b438, 0xfe56c982, 0x00869234, 0x0cf27048, 0xfaa97fca },
 91         { 0x01adf358, 0xfe21f5fe, 0x00999842, 0x0ce051c2, 0xfab62ca5 },
 92         { 0x01d949fa, 0xfde6e287, 0x00af0d8d, 0x0ccd8b4a, 0xfac33aa7 },
 93         { 0x02092669, 0xfda4d8bf, 0x00c73d4c, 0x0cba1884, 0xfad0ab07 },
 94         { 0x023e0268, 0xfd5b0e4a, 0x00e27b54, 0x0ca5f509, 0xfade7ef2 },
 95         { 0x0278645c, 0xfd08a2b0, 0x01012509, 0x0c911c63, 0xfaecb788 },
 96         { 0x02b8e091, 0xfcac9d1a, 0x0123a262, 0x0c7b8a14, 0xfafb55df },
 97         { 0x03001a9a, 0xfc45e9ce, 0x014a6709, 0x0c65398f, 0xfb0a5aff },
 98         { 0x034ec6d7, 0xfbd3576b, 0x0175f397, 0x0c4e2643, 0xfb19c7e4 },
 99         { 0x03a5ac15, 0xfb5393ee, 0x01a6d6ed, 0x0c364b94, 0xfb299d7c },
100         { 0x0405a562, 0xfac52968, 0x01ddafae, 0x0c1da4e2, 0xfb39dca5 },
101         { 0x046fa3fe, 0xfa267a66, 0x021b2ddd, 0x0c042d8d, 0xfb4a8631 },
102         { 0x04e4b17f, 0xf975be0f, 0x0260149f, 0x0be9e0f2, 0xfb5b9ae0 },
103         { 0x0565f220, 0xf8b0fbe5, 0x02ad3c29, 0x0bceba73, 0xfb6d1b60 },
104         { 0x05f4a745, 0xf7d60722, 0x030393d4, 0x0bb2b578, 0xfb7f084d },
105         { 0x06923236, 0xf6e279bd, 0x03642465, 0x0b95cd75, 0xfb916233 },
106         { 0x07401713, 0xf5d3aef9, 0x03d01283, 0x0b77fded, 0xfba42984 },
107         { 0x08000000, 0xf4a6bd88, 0x0448a161, 0x0b594278, 0xfbb75e9f },
108         { 0x08d3c097, 0xf3587131, 0x04cf35a4, 0x0b3996c9, 0xfbcb01cb },
109         { 0x09bd59a2, 0xf1e543f9, 0x05655880, 0x0b18f6b2, 0xfbdf1333 },
110         { 0x0abefd0f, 0xf04956ca, 0x060cbb12, 0x0af75e2c, 0xfbf392e8 },
111         { 0x0bdb123e, 0xee806984, 0x06c739fe, 0x0ad4c962, 0xfc0880dd },
112         { 0x0d143a94, 0xec85d287, 0x0796e150, 0x0ab134b0, 0xfc1ddce5 },
113         { 0x0e6d5664, 0xea547598, 0x087df0a0, 0x0a8c9cb6, 0xfc33a6ad },
114         { 0x0fe98a2a, 0xe7e6ba35, 0x097edf83, 0x0a66fe5b, 0xfc49ddc2 },
115         { 0x118c4421, 0xe536813a, 0x0a9c6248, 0x0a4056d7, 0xfc608185 },
116         { 0x1359422e, 0xe23d19eb, 0x0bd96efb, 0x0a18a3bf, 0xfc77912c },
117         { 0x1554982b, 0xdef33645, 0x0d3942bd, 0x09efe312, 0xfc8f0bc1 },
118         { 0x1782b68a, 0xdb50deb1, 0x0ebf676d, 0x09c6133f, 0xfca6f019 },
119         { 0x19e8715d, 0xd74d64fd, 0x106fb999, 0x099b3337, 0xfcbf3cd6 },
120         { 0x1c8b07b8, 0xd2df56ab, 0x124e6ec8, 0x096f4274, 0xfcd7f060 },
121         { 0x1f702b6d, 0xcdfc6e92, 0x14601c10, 0x0942410b, 0xfcf108e5 },
122         { 0x229e0933, 0xc89985cd, 0x16a9bcfa, 0x09142fb5, 0xfd0a8451 },
123         { 0x261b5118, 0xc2aa8409, 0x1930bab6, 0x08e50fdc, 0xfd24604d },
124         { 0x29ef3f5d, 0xbc224f28, 0x1bfaf396, 0x08b4e3aa, 0xfd3e9a3b },
125         { 0x2e21a59b, 0xb4f2ba46, 0x1f0ec2d6, 0x0883ae15, 0xfd592f33 },
126         { 0x32baf44b, 0xad0c7429, 0x227308a3, 0x085172eb, 0xfd741bfd },
127         { 0x37c4448b, 0xa45ef51d, 0x262f3267, 0x081e36dc, 0xfd8f5d14 }
128 };
129 
130 
131 static void set_bass(struct emu10k1_card *card, int l, int r)
132 {
133         int i;
134 
135         l = (l * 40 + 50) / 100;
136         r = (r * 40 + 50) / 100;
137 
138         for (i = 0; i < 5; i++)
139                 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + card->mgr.ctrl_gpr[SOUND_MIXER_BASS][0] + i, 0, bass_table[l][i]);
140 }
141 
142 static void set_treble(struct emu10k1_card *card, int l, int r)
143 {
144         int i;
145 
146         l = (l * 40 + 50) / 100;
147         r = (r * 40 + 50) / 100;
148 
149         for (i = 0; i < 5; i++)
150                 sblive_writeptr(card, (card->is_audigy ? A_GPR_BASE : GPR_BASE) + card->mgr.ctrl_gpr[SOUND_MIXER_TREBLE][0] + i , 0, treble_table[l][i]);
151 }
152 
153 const char volume_params[SOUND_MIXER_NRDEVICES]= {
154 /* Used by the ac97 driver */
155         [SOUND_MIXER_VOLUME]    =       VOL_6BIT,
156         [SOUND_MIXER_BASS]      =       VOL_4BIT,
157         [SOUND_MIXER_TREBLE]    =       VOL_4BIT,
158         [SOUND_MIXER_PCM]       =       VOL_5BIT,
159         [SOUND_MIXER_SPEAKER]   =       VOL_4BIT,
160         [SOUND_MIXER_LINE]      =       VOL_5BIT,
161         [SOUND_MIXER_MIC]       =       VOL_5BIT,
162         [SOUND_MIXER_CD]        =       VOL_5BIT,
163         [SOUND_MIXER_ALTPCM]    =       VOL_6BIT,
164         [SOUND_MIXER_IGAIN]     =       VOL_4BIT,
165         [SOUND_MIXER_LINE1]     =       VOL_5BIT,
166         [SOUND_MIXER_PHONEIN]   =       VOL_5BIT,
167         [SOUND_MIXER_PHONEOUT]  =       VOL_6BIT,
168         [SOUND_MIXER_VIDEO]     =       VOL_5BIT,
169 /* Not used by the ac97 driver */
170         [SOUND_MIXER_SYNTH]     =       VOL_5BIT,
171         [SOUND_MIXER_IMIX]      =       VOL_5BIT,
172         [SOUND_MIXER_RECLEV]    =       VOL_5BIT,
173         [SOUND_MIXER_OGAIN]     =       VOL_5BIT,
174         [SOUND_MIXER_LINE2]     =       VOL_5BIT,
175         [SOUND_MIXER_LINE3]     =       VOL_5BIT,
176         [SOUND_MIXER_DIGITAL1]  =       VOL_5BIT,
177         [SOUND_MIXER_DIGITAL2]  =       VOL_5BIT,
178         [SOUND_MIXER_DIGITAL3]  =       VOL_5BIT,
179         [SOUND_MIXER_RADIO]     =       VOL_5BIT,
180         [SOUND_MIXER_MONITOR]   =       VOL_5BIT
181 };
182 
183 /* Mixer file operations */
184 static int emu10k1_private_mixer(struct emu10k1_card *card, unsigned int cmd, unsigned long arg)
185 {
186         struct mixer_private_ioctl *ctl;
187         struct dsp_patch *patch;
188         u32 size, page;
189         int addr, size_reg, i, ret;
190         unsigned int id, ch;
191 
192         switch (cmd) {
193 
194         case SOUND_MIXER_PRIVATE3:
195 
196                 ctl = (struct mixer_private_ioctl *) kmalloc(sizeof(struct mixer_private_ioctl), GFP_KERNEL);
197                 if (ctl == NULL)
198                         return -ENOMEM;
199 
200                 if (copy_from_user(ctl, (void *) arg, sizeof(struct mixer_private_ioctl))) {
201                         kfree(ctl);
202                         return -EFAULT;
203                 }
204 
205                 ret = 0;
206                 switch (ctl->cmd) {
207 #ifdef DBGEMU
208                 case CMD_WRITEFN0:
209                         emu10k1_writefn0_2(card, ctl->val[0], ctl->val[1], ctl->val[2]);
210                         break;
211 #endif
212                 case CMD_WRITEPTR:
213 #ifdef DBGEMU
214                         if (ctl->val[1] >= 0x40 || ctl->val[0] >= 0x1000) {
215 #else
216                         if (ctl->val[1] >= 0x40 || ctl->val[0] >= 0x1000 || ((ctl->val[0] < 0x100 ) &&
217                     //Any register allowed raw access goes here:
218                                      (ctl->val[0] != A_SPDIF_SAMPLERATE) && (ctl->val[0] != A_DBG)
219                         )
220                                 ) {
221 #endif
222                                 ret = -EINVAL;
223                                 break;
224                         }
225                         sblive_writeptr(card, ctl->val[0], ctl->val[1], ctl->val[2]);
226                         break;
227 
228                 case CMD_READFN0:
229                         ctl->val[2] = emu10k1_readfn0(card, ctl->val[0]);
230 
231                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
232                                 ret = -EFAULT;
233 
234                         break;
235 
236                 case CMD_READPTR:
237                         if (ctl->val[1] >= 0x40 || (ctl->val[0] & 0x7ff) > 0xff) {
238                                 ret = -EINVAL;
239                                 break;
240                         }
241 
242                         if ((ctl->val[0] & 0x7ff) > 0x3f)
243                                 ctl->val[1] = 0x00;
244 
245                         ctl->val[2] = sblive_readptr(card, ctl->val[0], ctl->val[1]);
246 
247                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
248                                 ret = -EFAULT;
249 
250                         break;
251 
252                 case CMD_SETRECSRC:
253                         switch (ctl->val[0]) {
254                         case WAVERECORD_AC97:
255                                 if (card->is_aps) {
256                                         ret = -EINVAL;
257                                         break;
258                                 }
259 
260                                 card->wavein.recsrc = WAVERECORD_AC97;
261                                 break;
262 
263                         case WAVERECORD_MIC:
264                                 card->wavein.recsrc = WAVERECORD_MIC;
265                                 break;
266 
267                         case WAVERECORD_FX:
268                                 card->wavein.recsrc = WAVERECORD_FX;
269                                 card->wavein.fxwc = ctl->val[1] & 0xffff;
270 
271                                 if (!card->wavein.fxwc)
272                                         ret = -EINVAL;
273 
274                                 break;
275 
276                         default:
277                                 ret = -EINVAL;
278                                 break;
279                         }
280                         break;
281 
282                 case CMD_GETRECSRC:
283                         ctl->val[0] = card->wavein.recsrc;
284                         ctl->val[1] = card->wavein.fxwc;
285                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
286                                 ret = -EFAULT;
287 
288                         break;
289 
290                 case CMD_GETVOICEPARAM:
291                         ctl->val[0] = card->waveout.send_routing[0];
292                         ctl->val[1] = card->waveout.send_dcba[0];
293 
294                         ctl->val[2] = card->waveout.send_routing[1];
295                         ctl->val[3] = card->waveout.send_dcba[1];
296 
297                         ctl->val[4] = card->waveout.send_routing[2];
298                         ctl->val[5] = card->waveout.send_dcba[2];
299 
300                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
301                                 ret = -EFAULT;
302 
303                         break;
304 
305                 case CMD_SETVOICEPARAM:
306                         card->waveout.send_routing[0] = ctl->val[0];
307                         card->waveout.send_dcba[0] = ctl->val[1];
308 
309                         card->waveout.send_routing[1] = ctl->val[2];
310                         card->waveout.send_dcba[1] = ctl->val[3];
311 
312                         card->waveout.send_routing[2] = ctl->val[4];
313                         card->waveout.send_dcba[2] = ctl->val[5];
314 
315                         break;
316                 
317                 case CMD_SETMCH_FX:
318                         card->mchannel_fx = ctl->val[0] & 0x000f;
319                         break;
320                 
321                 case CMD_GETPATCH:
322                         if (ctl->val[0] == 0) {
323                                 if (copy_to_user((void *) arg, &card->mgr.rpatch, sizeof(struct dsp_rpatch)))
324                                         ret = -EFAULT;
325                         } else {
326                                 if ((ctl->val[0] - 1) / PATCHES_PER_PAGE >= card->mgr.current_pages) {
327                                         ret = -EINVAL;
328                                         break;
329                                 }
330 
331                                 if (copy_to_user((void *) arg, PATCH(&card->mgr, ctl->val[0] - 1), sizeof(struct dsp_patch)))
332                                         ret = -EFAULT;
333                         }
334 
335                         break;
336 
337                 case CMD_GETGPR:
338                         id = ctl->val[0];
339 
340                         if (id > NUM_GPRS) {
341                                 ret = -EINVAL;
342                                 break;
343                         }
344 
345                         if (copy_to_user((void *) arg, &card->mgr.gpr[id], sizeof(struct dsp_gpr)))
346                                 ret = -EFAULT;
347 
348                         break;
349 
350                 case CMD_GETCTLGPR:
351                         addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, &((char *) ctl->val)[PATCH_NAME_SIZE]);
352                         ctl->val[0] = sblive_readptr(card, addr, 0);
353 
354                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
355                                 ret = -EFAULT;
356 
357                         break;
358 
359                 case CMD_SETPATCH:
360                         if (ctl->val[0] == 0)
361                                 memcpy(&card->mgr.rpatch, &ctl->val[1], sizeof(struct dsp_rpatch));
362                         else {
363                                 page = (ctl->val[0] - 1) / PATCHES_PER_PAGE;
364                                 if (page > MAX_PATCHES_PAGES) {
365                                         ret = -EINVAL;
366                                         break;
367                                 }
368 
369                                 if (page >= card->mgr.current_pages) {
370                                         for (i = card->mgr.current_pages; i < page + 1; i++) {
371                                                 card->mgr.patch[i] = (void *)__get_free_page(GFP_KERNEL);
372                                                 if(card->mgr.patch[i] == NULL) {
373                                                         card->mgr.current_pages = i;
374                                                         ret = -ENOMEM;
375                                                         break;
376                                                 }
377                                                 memset(card->mgr.patch[i], 0, PAGE_SIZE);
378                                         }
379                                         card->mgr.current_pages = page + 1;
380                                 }
381 
382                                 patch = PATCH(&card->mgr, ctl->val[0] - 1);
383 
384                                 memcpy(patch, &ctl->val[1], sizeof(struct dsp_patch));
385 
386                                 if (patch->code_size == 0) {
387                                         for(i = page + 1; i < card->mgr.current_pages; i++)
388                                                 free_page((unsigned long) card->mgr.patch[i]);
389 
390                                         card->mgr.current_pages = page + 1;
391                                 }
392                         }
393                         break;
394 
395                 case CMD_SETGPR:
396                         if (ctl->val[0] > NUM_GPRS) {
397                                 ret = -EINVAL;
398                                 break;
399                         }
400 
401                         memcpy(&card->mgr.gpr[ctl->val[0]], &ctl->val[1], sizeof(struct dsp_gpr));
402                         break;
403 
404                 case CMD_SETCTLGPR:
405                         addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, (char *) ctl->val + PATCH_NAME_SIZE);
406                         emu10k1_set_control_gpr(card, addr, *((s32 *)((char *) ctl->val + 2 * PATCH_NAME_SIZE)), 0);
407                         break;
408 
409                 case CMD_SETGPOUT:
410                         if ( ((ctl->val[0] > 2) && (!card->is_audigy))
411                              || (ctl->val[0] > 15) || ctl->val[1] > 1) {
412                                 ret= -EINVAL;
413                                 break;
414                         }
415 
416                         if (card->is_audigy)
417                                 emu10k1_writefn0(card, (1 << 24) | ((ctl->val[0]) << 16) | A_IOCFG, ctl->val[1]);
418                         else
419                                 emu10k1_writefn0(card, (1 << 24) | (((ctl->val[0]) + 10) << 16) | HCFG, ctl->val[1]);
420                         break;
421 
422                 case CMD_GETGPR2OSS:
423                         id = ctl->val[0];
424                         ch = ctl->val[1];
425 
426                         if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
427                                 ret = -EINVAL;
428                                 break;
429                         }
430 
431                         ctl->val[2] = card->mgr.ctrl_gpr[id][ch];
432 
433                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
434                                 ret = -EFAULT;
435 
436                         break;
437 
438                 case CMD_SETGPR2OSS:
439                         id = ctl->val[0];
440                         /* 0 == left, 1 == right */
441                         ch = ctl->val[1];
442                         addr = ctl->val[2];
443 
444                         if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
445                                 ret = -EINVAL;
446                                 break;
447                         }
448 
449                         card->mgr.ctrl_gpr[id][ch] = addr;
450 
451                         if (card->is_aps)
452                                 break;
453 
454                         if (addr >= 0) {
455                                 unsigned int state = card->ac97->mixer_state[id];
456 
457                                 if (ch == 1) {
458                                         state >>= 8;
459                                         card->ac97->stereo_mixers |= (1 << id);
460                                 }
461 
462                                 card->ac97->supported_mixers |= (1 << id);
463 
464                                 if (id == SOUND_MIXER_TREBLE) {
465                                         set_treble(card, card->ac97->mixer_state[id] & 0xff, (card->ac97->mixer_state[id] >> 8) & 0xff);
466                                 } else if (id == SOUND_MIXER_BASS) {
467                                         set_bass(card, card->ac97->mixer_state[id] & 0xff, (card->ac97->mixer_state[id] >> 8) & 0xff);
468                                 } else
469                                         emu10k1_set_volume_gpr(card, addr, state & 0xff,
470                                                                volume_params[id]);
471                         } else {
472                                 card->ac97->stereo_mixers &= ~(1 << id);
473                                 card->ac97->stereo_mixers |= card->ac97_stereo_mixers;
474 
475                                 if (ch == 0) {
476                                         card->ac97->supported_mixers &= ~(1 << id);
477                                         card->ac97->supported_mixers |= card->ac97_supported_mixers;
478                                 }
479                         }
480                         break;
481 
482                 case CMD_SETPASSTHROUGH:
483                         card->pt.selected = ctl->val[0] ? 1 : 0;
484                         if (card->pt.state != PT_STATE_INACTIVE)
485                                 break;
486 
487                         card->pt.spcs_to_use = ctl->val[0] & 0x07;
488                         break;
489 
490                 case CMD_PRIVATE3_VERSION:
491                         ctl->val[0] = PRIVATE3_VERSION; //private3 version
492                         ctl->val[1] = MAJOR_VER;        //major driver version
493                         ctl->val[2] = MINOR_VER;        //minor driver version
494                         ctl->val[3] = card->is_audigy;  //1=card is audigy
495 
496                         if (card->is_audigy)
497                                 ctl->val[4]=emu10k1_readfn0(card, 0x18);
498 
499                         if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
500                                 ret = -EFAULT;
501                         break;
502 
503                 case CMD_AC97_BOOST:
504                         if (ctl->val[0])
505                                 emu10k1_ac97_write(card->ac97, 0x18, 0x0);      
506                         else
507                                 emu10k1_ac97_write(card->ac97, 0x18, 0x0808);
508                         break;
509                 default:
510                         ret = -EINVAL;
511                         break;
512                 }
513 
514                 kfree(ctl);
515                 return ret;
516                 break;
517 
518         case SOUND_MIXER_PRIVATE4:
519 
520                 if (copy_from_user(&size, (void *) arg, sizeof(size)))
521                         return -EFAULT;
522 
523                 DPD(2, "External tram size %#x\n", size);
524 
525                 if (size > 0x1fffff)
526                         return -EINVAL;
527 
528                 size_reg = 0;
529 
530                 if (size != 0) {
531                         size = (size - 1) >> 14;
532 
533                         while (size) {
534                                 size >>= 1;
535                                 size_reg++;
536                         }
537 
538                         size = 0x4000 << size_reg;
539                 }
540 
541                 DPD(2, "External tram size %#x %#x\n", size, size_reg);
542 
543                 if (size != card->tankmem.size) {
544                         if (card->tankmem.size > 0) {
545                                 emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 1);
546 
547                                 sblive_writeptr_tag(card, 0, TCB, 0, TCBS, 0, TAGLIST_END);
548 
549                                 pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
550 
551                                 card->tankmem.size = 0;
552                         }
553 
554                         if (size != 0) {
555                                 card->tankmem.addr = pci_alloc_consistent(card->pci_dev, size, &card->tankmem.dma_handle);
556                                 if (card->tankmem.addr == NULL)
557                                         return -ENOMEM;
558 
559                                 card->tankmem.size = size;
560 
561                                 sblive_writeptr_tag(card, 0, TCB, (u32) card->tankmem.dma_handle, TCBS,(u32) size_reg, TAGLIST_END);
562 
563                                 emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 0);
564                         }
565                 }
566                 return 0;
567                 break;
568 
569         default:
570                 break;
571         }
572 
573         return -EINVAL;
574 }
575 
576 static int emu10k1_dsp_mixer(struct emu10k1_card *card, unsigned int oss_mixer, unsigned long arg)
577 {
578         unsigned int left, right;
579         int val;
580         int scale;
581 
582         card->ac97->modcnt++;
583 
584         if (get_user(val, (int *)arg))
585                 return -EFAULT;
586 
587         /* cleanse input a little */
588         right = ((val >> 8)  & 0xff);
589         left = (val  & 0xff);
590 
591         if (right > 100) right = 100;
592         if (left > 100) left = 100;
593 
594         card->ac97->mixer_state[oss_mixer] = (right << 8) | left;
595         if (oss_mixer == SOUND_MIXER_TREBLE) {
596                 set_treble(card, left, right);
597                 return 0;
598         } if (oss_mixer == SOUND_MIXER_BASS) {
599                 set_bass(card, left, right);
600                 return 0;
601         }
602 
603         if (oss_mixer == SOUND_MIXER_VOLUME)
604                 scale = 1 << card->ac97->bit_resolution;
605         else
606                 scale = volume_params[oss_mixer];
607 
608         emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left, scale);
609         emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right, scale);
610 
611         if (card->ac97_supported_mixers & (1 << oss_mixer))
612                 card->ac97->write_mixer(card->ac97, oss_mixer, left, right);
613 
614         return 0;
615 }
616 
617 static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
618 {
619         int ret;
620         struct emu10k1_card *card = file->private_data;
621         unsigned int oss_mixer = _IOC_NR(cmd);
622         
623         ret = -EINVAL;
624         if (!card->is_aps) {
625                 if (cmd == SOUND_MIXER_INFO) {
626                         mixer_info info;
627 
628                         strlcpy(info.id, card->ac97->name, sizeof(info.id));
629 
630                         if (card->is_audigy)
631                                 strlcpy(info.name, "Audigy - Emu10k1", sizeof(info.name));
632                         else
633                                 strlcpy(info.name, "Creative SBLive - Emu10k1", sizeof(info.name));
634                                 
635                         info.modify_counter = card->ac97->modcnt;
636 
637                         if (copy_to_user((void *)arg, &info, sizeof(info)))
638                                 return -EFAULT;
639 
640                         return 0;
641                 }
642 
643                 if ((_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) && oss_mixer <= SOUND_MIXER_NRDEVICES)
644                         ret = emu10k1_dsp_mixer(card, oss_mixer, arg);
645                 else
646                         ret = card->ac97->mixer_ioctl(card->ac97, cmd, arg);
647         }
648         
649         if (ret < 0)
650                 ret = emu10k1_private_mixer(card, cmd, arg);
651 
652         return ret;
653 }
654 
655 static int emu10k1_mixer_open(struct inode *inode, struct file *file)
656 {
657         int minor = iminor(inode);
658         struct emu10k1_card *card = NULL;
659         struct list_head *entry;
660 
661         DPF(4, "emu10k1_mixer_open()\n");
662 
663         list_for_each(entry, &emu10k1_devs) {
664                 card = list_entry(entry, struct emu10k1_card, list);
665 
666                 if (card->ac97->dev_mixer == minor)
667                         goto match;
668         }
669 
670         return -ENODEV;
671 
672       match:
673         file->private_data = card;
674         return 0;
675 }
676 
677 static int emu10k1_mixer_release(struct inode *inode, struct file *file)
678 {
679         DPF(4, "emu10k1_mixer_release()\n");
680         return 0;
681 }
682 
683 struct file_operations emu10k1_mixer_fops = {
684         .owner          = THIS_MODULE,
685         .llseek         = no_llseek,
686         .ioctl          = emu10k1_mixer_ioctl,
687         .open           = emu10k1_mixer_open,
688         .release        = emu10k1_mixer_release,
689 };
690 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp