OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [sound/] [pas2_mixer.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
#define _PAS2_MIXER_C_
2
 
3
/*
4
 * sound/pas2_mixer.c
5
 *
6
 * Mixer routines for the Pro Audio Spectrum cards.
7
 */
8
 
9
#include <linux/config.h>
10
 
11
#include "sound_config.h"
12
 
13
#if defined(CONFIG_PAS)
14
 
15
#ifndef DEB
16
#define DEB(what)               /* (what) */
17
#endif
18
 
19
extern int      translate_code;
20
extern char     pas_model;
21
extern int     *pas_osp;
22
extern int      pas_audiodev;
23
 
24
static int      rec_devices = (SOUND_MASK_MIC);         /* Default recording source */
25
static int      mode_control = 0;
26
 
27
#define POSSIBLE_RECORDING_DEVICES      (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
28
                                         SOUND_MASK_CD | SOUND_MASK_ALTPCM)
29
 
30
#define SUPPORTED_MIXER_DEVICES         (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
31
                                         SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
32
                                         SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
33
 
34
 
35
static unsigned short levels[SOUND_MIXER_NRDEVICES] =
36
{
37
  0x3232,                       /* Master Volume */
38
  0x3232,                       /* Bass */
39
  0x3232,                       /* Treble */
40
  0x5050,                       /* FM */
41
  0x4b4b,                       /* PCM */
42
  0x3232,                       /* PC Speaker */
43
  0x4b4b,                       /* Ext Line */
44
  0x4b4b,                       /* Mic */
45
  0x4b4b,                       /* CD */
46
  0x6464,                       /* Recording monitor */
47
  0x4b4b,                       /* SB PCM */
48
  0x6464                        /* Recording level */
49
};
50
 
51
void
52
mix_write (unsigned char data, int ioaddr)
53
{
54
  /*
55
   * The Revision D cards have a problem with their MVA508 interface. The
56
   * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
57
   * MSBs out of the output byte and to do a 16-bit out to the mixer port -
58
   * 1. We need to do this because it isn't timing problem but chip access
59
   * sequence problem.
60
   */
61
 
62
  if (pas_model == 4)
63
    {
64
      outw (data | (data << 8), (ioaddr ^ translate_code) - 1);
65
      outb (0x80, 0);
66
    }
67
  else
68
    pas_write (data, ioaddr);
69
}
70
 
71
static int
72
mixer_output (int right_vol, int left_vol, int div, int bits,
73
              int mixer)        /* Input or output mixer */
74
{
75
  int             left = left_vol * div / 100;
76
  int             right = right_vol * div / 100;
77
 
78
 
79
  if (bits & 0x10)
80
    {                           /*
81
                                 * Select input or output mixer
82
                                 */
83
      left |= mixer;
84
      right |= mixer;
85
    }
86
 
87
  if (bits == 0x03 || bits == 0x04)
88
    {                           /*
89
                                 * Bass and treble are mono devices
90
                                 */
91
      mix_write (0x80 | bits, 0x078B);
92
      mix_write (left, 0x078B);
93
      right_vol = left_vol;
94
    }
95
  else
96
    {
97
      mix_write (0x80 | 0x20 | bits, 0x078B);
98
      mix_write (left, 0x078B);
99
      mix_write (0x80 | 0x40 | bits, 0x078B);
100
      mix_write (right, 0x078B);
101
    }
102
 
103
  return (left_vol | (right_vol << 8));
104
}
105
 
106
void
107
set_mode (int new_mode)
108
{
109
  mix_write (0x80 | 0x05, 0x078B);
110
  mix_write (new_mode, 0x078B);
111
 
112
  mode_control = new_mode;
113
}
114
 
115
static int
116
pas_mixer_set (int whichDev, unsigned int level)
117
{
118
  int             left, right, devmask, changed, i, mixer = 0;
119
 
120
  DEB (printk ("static int pas_mixer_set(int whichDev = %d, unsigned int level = %X)\n", whichDev, level));
121
 
122
  left = level & 0x7f;
123
  right = (level & 0x7f00) >> 8;
124
 
125
  if (whichDev < SOUND_MIXER_NRDEVICES)
126
    if ((1 << whichDev) & rec_devices)
127
      mixer = 0x20;
128
    else
129
      mixer = 0x00;
130
 
131
  switch (whichDev)
132
    {
133
    case SOUND_MIXER_VOLUME:    /* Master volume (0-63) */
134
      levels[whichDev] = mixer_output (right, left, 63, 0x01, 0);
135
      break;
136
 
137
      /*
138
       * Note! Bass and Treble are mono devices. Will use just the left
139
       * channel.
140
       */
141
    case SOUND_MIXER_BASS:      /* Bass (0-12) */
142
      levels[whichDev] = mixer_output (right, left, 12, 0x03, 0);
143
      break;
144
    case SOUND_MIXER_TREBLE:    /* Treble (0-12) */
145
      levels[whichDev] = mixer_output (right, left, 12, 0x04, 0);
146
      break;
147
 
148
    case SOUND_MIXER_SYNTH:     /* Internal synthesizer (0-31) */
149
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x00, mixer);
150
      break;
151
    case SOUND_MIXER_PCM:       /* PAS PCM (0-31) */
152
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x05, mixer);
153
      break;
154
    case SOUND_MIXER_ALTPCM:    /* SB PCM (0-31) */
155
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x07, mixer);
156
      break;
157
    case SOUND_MIXER_SPEAKER:   /* PC speaker (0-31) */
158
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x06, mixer);
159
      break;
160
    case SOUND_MIXER_LINE:      /* External line (0-31) */
161
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x02, mixer);
162
      break;
163
    case SOUND_MIXER_CD:        /* CD (0-31) */
164
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x03, mixer);
165
      break;
166
    case SOUND_MIXER_MIC:       /* External microphone (0-31) */
167
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x04, mixer);
168
      break;
169
    case SOUND_MIXER_IMIX:      /* Recording monitor (0-31) (Output mixer only) */
170
      levels[whichDev] = mixer_output (right, left, 31, 0x10 | 0x01,
171
                                       0x00);
172
      break;
173
    case SOUND_MIXER_RECLEV:    /* Recording level (0-15) */
174
      levels[whichDev] = mixer_output (right, left, 15, 0x02, 0);
175
      break;
176
 
177
 
178
    case SOUND_MIXER_RECSRC:
179
      devmask = level & POSSIBLE_RECORDING_DEVICES;
180
 
181
      changed = devmask ^ rec_devices;
182
      rec_devices = devmask;
183
 
184
      for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
185
        if (changed & (1 << i))
186
          {
187
            pas_mixer_set (i, levels[i]);
188
          }
189
      return rec_devices;
190
      break;
191
 
192
    default:
193
      return -(EINVAL);
194
    }
195
 
196
  return (levels[whichDev]);
197
}
198
 
199
/*****/
200
 
201
static void
202
pas_mixer_reset (void)
203
{
204
  int             foo;
205
 
206
  DEB (printk ("pas2_mixer.c: void pas_mixer_reset(void)\n"));
207
 
208
  for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
209
    pas_mixer_set (foo, levels[foo]);
210
 
211
  set_mode (0x04 | 0x01);
212
}
213
 
214
int
215
pas_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg)
216
{
217
  DEB (printk ("pas2_mixer.c: int pas_mixer_ioctl(unsigned int cmd = %X, unsigned int arg = %X)\n", cmd, arg));
218
 
219
  if (cmd == SOUND_MIXER_PRIVATE1)      /* Set loudness bit */
220
    {
221
      int             level = get_user ((int *) arg);
222
 
223
      if (level == -1)          /* Return current settings */
224
        {
225
          if (mode_control & 0x04)
226
            return snd_ioctl_return ((int *) arg, 1);
227
          else
228
            return snd_ioctl_return ((int *) arg, 0);
229
        }
230
      else
231
        {
232
          mode_control &= ~0x04;
233
          if (level)
234
            mode_control |= 0x04;
235
          set_mode (mode_control);
236
          return snd_ioctl_return ((int *) arg, !!level);       /* 0 or 1 */
237
        }
238
    }
239
 
240
 
241
  if (cmd == SOUND_MIXER_PRIVATE2)      /* Set enhance bit */
242
    {
243
      int             level = get_user ((int *) arg);
244
 
245
      if (level == -1)          /* Return current settings */
246
        {
247
          if (!(mode_control & 0x03))
248
            return snd_ioctl_return ((int *) arg, 0);
249
          return snd_ioctl_return ((int *) arg, ((mode_control & 0x03) + 1) * 20);
250
        }
251
      else
252
        {
253
          int             i = 0;
254
 
255
          level &= 0x7f;
256
          if (level)
257
            i = (level / 20) - 1;
258
 
259
          mode_control &= ~0x03;
260
          mode_control |= i & 0x03;
261
          set_mode (mode_control);
262
 
263
          if (i)
264
            i = (i + 1) * 20;
265
 
266
          return i;
267
        }
268
    }
269
 
270
  if (cmd == SOUND_MIXER_PRIVATE3)      /* Set mute bit */
271
    {
272
      int             level = get_user ((int *) arg);
273
 
274
      if (level == -1)          /* Return current settings */
275
        {
276
          return snd_ioctl_return ((int *) arg,
277
                                   !(pas_read (0x0B8A) &
278
                                     0x20));
279
        }
280
      else
281
        {
282
          if (level)
283
            pas_write (pas_read (0x0B8A) & (~0x20),
284
                       0x0B8A);
285
          else
286
            pas_write (pas_read (0x0B8A) | 0x20,
287
                       0x0B8A);
288
 
289
          return !(pas_read (0x0B8A) & 0x20);
290
        }
291
    }
292
 
293
  if (((cmd >> 8) & 0xff) == 'M')
294
    {
295
      if (_IOC_DIR (cmd) & _IOC_WRITE)
296
        return snd_ioctl_return ((int *) arg, pas_mixer_set (cmd & 0xff, get_user ((int *) arg)));
297
      else
298
        {                       /*
299
                                 * Read parameters
300
                                 */
301
 
302
          switch (cmd & 0xff)
303
            {
304
 
305
            case SOUND_MIXER_RECSRC:
306
              return snd_ioctl_return ((int *) arg, rec_devices);
307
              break;
308
 
309
            case SOUND_MIXER_STEREODEVS:
310
              return snd_ioctl_return ((int *) arg, SUPPORTED_MIXER_DEVICES & ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE));
311
              break;
312
 
313
            case SOUND_MIXER_DEVMASK:
314
              return snd_ioctl_return ((int *) arg, SUPPORTED_MIXER_DEVICES);
315
              break;
316
 
317
            case SOUND_MIXER_RECMASK:
318
              return snd_ioctl_return ((int *) arg, POSSIBLE_RECORDING_DEVICES & SUPPORTED_MIXER_DEVICES);
319
              break;
320
 
321
            case SOUND_MIXER_CAPS:
322
              return snd_ioctl_return ((int *) arg, 0);          /* No special capabilities */
323
              break;
324
 
325
 
326
            default:
327
              return snd_ioctl_return ((int *) arg, levels[cmd & 0xff]);
328
            }
329
        }
330
    }
331
  return -(EINVAL);
332
}
333
 
334
static struct mixer_operations pas_mixer_operations =
335
{
336
  "PAS16",
337
  "Pro Audio Spectrum 16",
338
  pas_mixer_ioctl
339
};
340
 
341
int
342
pas_init_mixer (void)
343
{
344
  pas_mixer_reset ();
345
 
346
  if (num_mixers < MAX_MIXER_DEV)
347
    {
348
      audio_devs[pas_audiodev]->mixer_dev = num_mixers;
349
      mixer_devs[num_mixers++] = &pas_mixer_operations;
350
    }
351
  return 1;
352
}
353
 
354
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.