1 diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
2 index 29502238e510..a84dc2c07d48 100644
3 --- a/include/linux/pci_ids.h
4 +++ b/include/linux/pci_ids.h
6 #define PCI_VENDOR_ID_SGI 0x10a9
7 #define PCI_DEVICE_ID_SGI_IOC3 0x0003
8 #define PCI_DEVICE_ID_SGI_LITHIUM 0x1002
9 +#define PCI_DEVICE_ID_SGI_RAD1 0x0005
10 #define PCI_DEVICE_ID_SGI_IOC4 0x100a
12 #define PCI_VENDOR_ID_WINBOND 0x10ad
13 diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
14 index 4105d9f653d9..f2ddbdb2d4dc 100644
15 --- a/sound/pci/Kconfig
16 +++ b/sound/pci/Kconfig
17 @@ -907,6 +907,12 @@ config SND_YMFPCI
18 To compile this driver as a module, choose M here: the module
19 will be called snd-ymfpci.
23 + depends on SND && SGI_IP30
25 + Say 'Y' or 'M' to include support for SGI RAD1 Pro Audio in Octane.
29 source "sound/pci/hda/Kconfig"
30 diff --git a/arch/mips/pci/pci-bridge.c b/arch/mips/pci/pci-bridge.c
31 index 28b0eb5b844e..9df13ce313b5 100644
32 --- a/arch/mips/pci/pci-bridge.c
33 +++ b/arch/mips/pci/pci-bridge.c
34 @@ -368,6 +368,9 @@ bridge_disable_swapping_dma(struct pci_dev *dev)
35 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3,
36 bridge_disable_swapping_dma);
38 +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_RAD1,
39 + bridge_disable_swapping_dma);
42 bridge_init(struct platform_device *pdev)
44 diff --git a/sound/pci/Makefile b/sound/pci/Makefile
45 index 04cac7469139..9186ff609192 100644
46 --- a/sound/pci/Makefile
47 +++ b/sound/pci/Makefile
48 @@ -22,6 +22,7 @@ snd-fm801-objs := fm801.o
49 snd-intel8x0-objs := intel8x0.o
50 snd-intel8x0m-objs := intel8x0m.o
51 snd-maestro3-objs := maestro3.o
52 +snd-rad1-objs := rad1.o
53 snd-rme32-objs := rme32.o
54 snd-rme96-objs := rme96.o
55 snd-sis7019-objs := sis7019.o
56 @@ -48,6 +49,7 @@ obj-$(CONFIG_SND_FM801) += snd-fm801.o
57 obj-$(CONFIG_SND_INTEL8X0) += snd-intel8x0.o
58 obj-$(CONFIG_SND_INTEL8X0M) += snd-intel8x0m.o
59 obj-$(CONFIG_SND_MAESTRO3) += snd-maestro3.o
60 +obj-$(CONFIG_SND_RAD1) += snd-rad1.o
61 obj-$(CONFIG_SND_RME32) += snd-rme32.o
62 obj-$(CONFIG_SND_RME96) += snd-rme96.o
63 obj-$(CONFIG_SND_SIS7019) += snd-sis7019.o
64 diff --git a/include/sound/rad1.h b/include/sound/rad1.h
66 index 000000000000..3acbb6cd36f2
68 +++ b/include/sound/rad1.h
71 + * This file is subject to the terms and conditions of the GNU General Public
72 + * License. See the file "COPYING" in the main directory of this archive
75 + * Copyright (C) 2004-2007 Stanislaw Skowronek <skylark@unaligned.org>
76 + * Copyright (C) 2018 René Rebe <rene@exactcode.de>
79 +#ifndef _SOUND_RAD1_H
80 +#define _SOUND_RAD1_H
82 +#include <linux/types.h>
84 +#define RAD1_ADATRX 0
87 +#define RAD1_ADATSUBRX 3
88 +#define RAD1_AESSUBRX 4
89 +#define RAD1_ADATTX 5
92 +#define RAD1_STATUS 8
95 + u32 pci_status; /* 0x00000000 */
96 + u32 adat_rx_msc_ust; /* 0x00000004 */
97 + u32 adat_rx_msc0_submsc; /* 0x00000008 */
98 + u32 aes_rx_msc_ust; /* 0x0000000c */
99 + u32 aes_rx_msc0_submsc; /* 0x00000010 */
100 + u32 adc_msc_ust; /* 0x00000014 */
101 + u32 adc_msc0_submsc; /* 0x00000018 */
102 + u32 adat_tx_msc_ust; /* 0x0000001c */
103 + u32 adat_tx_msc0_submsc; /* 0x00000020 */
104 + u32 aes_tx_msc_ust; /* 0x00000024 */
105 + u32 aes_tx_msc0_submsc; /* 0x00000028 */
106 + u32 dac_msc_ust; /* 0x0000002c */
107 + u32 ust_register; /* 0x00000030 */
108 + u32 gpio_status; /* 0x00000034 */
109 + u32 chip_status1; /* 0x00000038 */
110 + u32 chip_status0; /* 0x0000003c */
112 + u32 ust_clock_control; /* 0x00000040 */
113 + u32 adat_rx_control; /* 0x00000044 */
114 + u32 aes_rx_control; /* 0x00000048 */
115 + u32 adc_control; /* 0x0000004c */
116 + u32 adat_tx_control; /* 0x00000050 */
117 + u32 aes_tx_control; /* 0x00000054 */
118 + u32 dac_control; /* 0x00000058 */
119 + u32 status_timer; /* 0x0000005c */
123 + u32 misc_control; /* 0x00000070 */
124 + u32 pci_holdoff; /* 0x00000074 */
125 + u32 pci_arb_control; /* 0x00000078 */
127 + u32 volume_control; /* 0x0000007c */
129 + u32 reset; /* 0x00000080 */
131 + u32 gpio0; /* 0x00000084 */
132 + u32 gpio1; /* 0x00000088 */
133 + u32 gpio2; /* 0x0000008c */
134 + u32 gpio3; /* 0x00000090 */
138 + u32 clockgen_ictl; /* 0x000000a0 */
139 + u32 clockgen_rem; /* 0x000000a4 */
140 + u32 freq_synth_mux_sel[4]; /* 0x000000a8 */
141 + u32 mpll0_lock_control; /* 0x000000b8 */
142 + u32 mpll1_lock_control; /* 0x000000bc */
146 + /* descriptor RAM */
148 + u32 loadr; /* 0x00000400 + 12*idx */
149 + u32 hiadr; /* 0x00000404 + 12*idx */
150 + u32 control; /* 0x00000408 + 12*idx */
153 + /* running descriptors */
162 + u32 adat_subcode_txa_u[24]; /* 0x00001000 */
163 + u32 adat_subcode_txa_unused; /* 0x00001060 */
167 + u32 adat_subcode_txb_u[24]; /* 0x00001080 */
168 + u32 adat_subcode_txb_unused; /* 0x000010e0 */
172 + u32 aes_subcode_txa_lu[6]; /* 0x00001100 */
173 + u32 aes_subcode_txa_lc[6]; /* 0x00001118 */
174 + u32 aes_subcode_txa_lv[6]; /* 0x00001130 */
175 + u32 aes_subcode_txa_ru[6]; /* 0x00001148 */
176 + u32 aes_subcode_txa_rc[6]; /* 0x00001160 */
177 + u32 aes_subcode_txa_rv0[2]; /* 0x00001178 */
178 + u32 aes_subcode_txb_lu[6]; /* 0x00001180 */
179 + u32 aes_subcode_txb_lc[6]; /* 0x00001198 */
180 + u32 aes_subcode_txb_lv[6]; /* 0x000011b0 */
181 + u32 aes_subcode_txb_ru[6]; /* 0x000011c8 */
182 + u32 aes_subcode_txb_rc[6]; /* 0x000011e0 */
183 + u32 aes_subcode_txb_rv0[2]; /* 0x000011f8 */
184 + u32 aes_subcode_txa_rv2[4]; /* 0x00001200 */
185 + u32 aes_subcode_txb_rv2[4]; /* 0x00001210 */
186 + u32 aes_subcode_tx_unused; /* 0x00001220 */
189 +#endif /* _SOUND_RAD1_H */
190 diff --git a/sound/pci/rad1.c b/sound/pci/rad1.c
192 index 000000000000..24318b1c9187
194 +++ b/sound/pci/rad1.c
197 + * rad1.c - ALSA driver for SGI RAD1 (as found in Octane and Octane2)
198 + * Copyright (C) 2004-2007 by Stanislaw Skowronek <skylark@unaligned.org>
199 + * Copyright (C) 2018 René Rebe <rene@exactcode.de>
201 + * This program is free software; you can redistribute it and/or modify
202 + * it under the terms of the GNU General Public License as published by
203 + * the Free Software Foundation; either version 2 of the License, or
204 + * (at your option) any later version.
206 + * This program is distributed in the hope that it will be useful,
207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
209 + * GNU General Public License for more details.
211 + * You should have received a copy of the GNU General Public License
212 + * along with this program; if not, write to the Free Software
213 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA
216 +#include <linux/delay.h>
217 +#include <linux/init.h>
218 +#include <linux/pci.h>
219 +#include <linux/slab.h>
220 +#include <linux/timer.h>
221 +#include <linux/spinlock.h>
222 +#include <linux/module.h>
224 +#include <sound/core.h>
225 +#include <sound/initval.h>
226 +#include <sound/pcm.h>
227 +#include <sound/control.h>
229 +#include <sound/rad1.h>
231 +struct snd_rad1_pipe {
232 + unsigned long pma; /* physical addr of the ring */
233 + int *vma; /* virtual addr of the ring */
234 + struct snd_pcm_substream *subs; /* ALSA substream */
235 + struct snd_pcm *pcm;
236 + unsigned int pnum; /* number of periods */
237 + unsigned int plen; /* length of period (in bytes) */
238 + unsigned int hptr; /* hardware pointer */
239 + int adma; /* DMA active flag */
240 + unsigned int qptr; /* queue pointer */
245 + struct snd_card *card;
246 + struct pci_dev *pci;
247 + unsigned long mmio_phys;
248 + volatile struct rad1regs *mmio;
250 + struct timer_list timer;
251 + struct snd_rad1_pipe pipes[9];
254 + int last_aesrx_rate;
256 + /* card controls */
257 + unsigned int attctrl; /* Attenuation control */
258 + unsigned int rt_adc; /* ADC routing */
259 + unsigned int rt_aesr; /* AES Rx routing */
260 + unsigned int rt_adat; /* ADAT Rx routing */
261 + unsigned int rt_opto; /* Optical Out routing */
264 +/* ----------------------------------------------------------------------- */
267 +/* ----------------------------------------------------------------------- */
268 +/* Hardware initialization, DMa, Pipe setup */
270 +snd_rad1_hw_init(struct snd_rad1 *chip)
272 + /* The hex values listed here are, for the most part, unknown values
273 + * determined by running portions of the IRIX kernel inside of Linux
274 + * as a userland application and then extracting the run-time info.
276 + * We could define them via macros if we wanted, but the macro names
277 + * would be no more intelligible as RAD1_ANCIENT_MU_* than they are
278 + * simple hex numbers, so until the purpose of each value is known,
279 + * they shall remain as simple hex numbers.
281 + * The same applies for pretty much any other hex number found in
282 + * driver that isn't a bit mask or some sort. One day, we may figure
283 + * it all out, and create an appropriate header file to define them
284 + * all as intelligible macros.
286 + volatile struct rad1regs *mmio = chip->mmio;
288 + mmio->reset = 0xffffffff;
290 + mmio->reset = 0xffe3cffe;
291 + mmio->pci_holdoff = 0x08000010;
292 + mmio->pci_arb_control = 0x00fac688;
295 + /* Mike 03000000; LineIn 05000000 */
296 + mmio->adc_control = 0x03000000;
297 + chip->rt_adc = 0x03000000;
300 + mmio->dac_control = 0x20000000;
302 + /* Optical In 00000018; AES In 00000010 */
303 + mmio->aes_rx_control = 0x00000018;
304 + chip->rt_aesr = 0x00000018;
307 + mmio->aes_tx_control = 0x40000000;
309 + /* Disabled a0000000; Optical In a0000018 */
310 + mmio->adat_rx_control = 0xa0000000;
311 + chip->rt_adat = 0xa0000000;
314 + mmio->adat_tx_control = 0x20000000;
315 + mmio->gpio3 = 0x00000002;
316 + mmio->misc_control = 0x00001500;
317 + mmio->mpll0_lock_control = 0x9fffffff;
318 + mmio->mpll1_lock_control = 0x9fffffff;
319 + mmio->reset = 0xffe3c0fe;
321 + mmio->clockgen_ictl = 0x02000001;
322 + mmio->reset = 0xffe24070;
324 + mmio->reset = 0xffe20000;
325 + mmio->gpio2 = 0x00000002;
326 + mmio->volume_control = 0xd6d6d6d6;
327 + chip->attctrl = 0xd6d6d6d6;
330 + /* AES-Optical Out 00001040; AES-AES Out 00001440 */
331 + mmio->misc_control = 0x00001040;
332 + chip->rt_opto = 0x00001040;
333 + mmio->reset = 0xffe20100;
334 + mmio->freq_synth_mux_sel[3] = 0x00000001;
335 + mmio->clockgen_rem = 0x0000ffff;
336 + mmio->clockgen_ictl = 0x10000603;
337 + mmio->reset = 0xffe20000;
338 + mmio->reset = 0xffe20200;
339 + mmio->freq_synth_mux_sel[2] = 0x00000001;
340 + mmio->clockgen_rem = 0x0000ffff;
341 + mmio->clockgen_ictl = 0x20000603;
342 + mmio->reset = 0xffe20000;
343 + mmio->reset = 0xffe20400;
344 + mmio->freq_synth_mux_sel[1] = 0x00000001;
345 + mmio->clockgen_rem = 0x0000ffff;
346 + mmio->clockgen_ictl = 0x40000603;
347 + mmio->reset = 0xffe20000;
348 + mmio->reset = 0xffe20800;
349 + mmio->freq_synth_mux_sel[0] = 0x00000001;
350 + mmio->clockgen_rem = 0x0000ffff;
351 + mmio->clockgen_ictl = 0x80000603;
352 + mmio->reset = 0xffe20000;
353 + mmio->gpio1 = 0x00000003;
358 +snd_rad1_setup_dma_pipe(struct snd_rad1 *chip, int pidx)
360 + struct snd_rad1_pipe *pipe = (chip->pipes + pidx);
361 + volatile struct rad1regs *mmio = chip->mmio;
363 + if ((-pipe->pnum * pipe->plen) & 0x7f)
364 + printk(KERN_WARNING "rad1: pipe %d has unaligned size %d\n",
365 + pidx, (pipe->pnum * pipe->plen));
367 + mmio->pci_descr[pidx].hiadr = (pipe->pma >> 32);
368 + mmio->pci_descr[pidx].loadr = (pipe->pma & 0xffffffff);
369 + mmio->pci_descr[pidx].control = (((-pipe->pnum * pipe->plen) &
370 + 0xffffff80) | (pidx << 3));
372 + mmio->pci_hiadr[pidx] = (pipe->pma >> 32);
373 + mmio->pci_lc[pidx].loadr = (pipe->pma & 0xffffffff);
374 + mmio->pci_lc[pidx].control = (((-pipe->pnum * pipe->plen) &
375 + 0xffffff80) | (pidx << 3));
379 +snd_rad1_activate_timer(struct snd_rad1 *chip)
381 + if (!chip->timer_active) {
382 + chip->timer.expires = (jiffies + 1);
383 + add_timer(&chip->timer);
384 + chip->timer_active = 1;
389 +snd_rad1_run_pipe(struct snd_rad1 *chip, int pidx, int adma)
391 + struct snd_rad1_pipe *pipe = (chip->pipes + pidx);
392 + volatile struct rad1regs *mmio = chip->mmio;
394 + if (pipe->adma != adma) {
399 + mmio->adc_control = (chip->rt_adc | adma);
402 + mmio->dac_control = (0x20000000 | adma);
405 + mmio->aes_rx_control = (chip->rt_aesr | adma);
408 + mmio->aes_tx_control = (0x40000000 | adma);
414 + snd_rad1_activate_timer(chip);
418 +snd_rad1_poll_pipe(struct snd_rad1 *chip, int pidx, int is_tx)
420 + struct snd_rad1_pipe *pipe = (chip->pipes + pidx);
421 + unsigned long flags;
422 + unsigned int hptr = (pipe->pnum * pipe->plen) +
423 + (chip->mmio->pci_lc[pidx].control & 0xffffff80);
425 + spin_lock_irqsave(&chip->lock, flags);
426 + if (pipe->adma && pipe->subs) {
427 + /* use hardware pointer to detect period crossing */
428 + if ((hptr / pipe->plen) != (pipe->hptr / pipe->plen)) {
430 + pipe->qptr = (hptr / 8);
432 + pipe->qptr = (pipe->hptr / 8);
433 + spin_unlock_irqrestore(&chip->lock, flags);
434 + snd_pcm_period_elapsed(pipe->subs);
435 + spin_lock_irqsave(&chip->lock, flags);
439 + spin_unlock_irqrestore(&chip->lock, flags);
443 +snd_rad1_poll_timer(struct timer_list *chip_virt)
445 + struct snd_rad1 *chip = from_timer(chip, chip_virt, timer);
448 + if (chip->pipes[RAD1_ADC].adma) {
449 + snd_rad1_poll_pipe(chip, RAD1_ADC, 0);
453 + if (chip->pipes[RAD1_DAC].adma) {
454 + snd_rad1_poll_pipe(chip, RAD1_DAC, 1);
458 + if (chip->pipes[RAD1_AESRX].adma) {
459 + snd_rad1_poll_pipe(chip, RAD1_AESRX, 0);
463 + if (chip->pipes[RAD1_AESTX].adma) {
464 + snd_rad1_poll_pipe(chip, RAD1_AESTX, 1);
469 + chip->timer.expires = (jiffies + 1);
470 + add_timer(&chip->timer);
472 + chip->timer_active = 0;
476 +snd_rad1_free_pipe(struct snd_pcm_substream *substream, int pidx)
478 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
479 + struct snd_rad1_pipe *pipe = (chip->pipes + pidx);
480 + unsigned long flags;
482 + spin_lock_irqsave(&chip->lock, flags);
483 + snd_rad1_run_pipe(chip, pidx, 0);
485 + spin_unlock_irqrestore(&chip->lock, flags);
487 + return snd_pcm_lib_free_pages(substream);
491 +snd_rad1_gcd(long x, long y)
510 +snd_rad1_red_frac(long *n, long *d, long max)
512 + long gcd = snd_rad1_gcd(*n, *d);
514 + if (unlikely(!gcd))
520 + /* XXX: Lose precision [sic] */
521 + while ((*n > max) || (*d > max)) {
528 +snd_rad1_set_aestx_subcode(struct snd_rad1 *chip, unsigned char *sub_lc,
529 + unsigned char *sub_rc)
531 + volatile struct rad1regs *mmio = chip->mmio;
532 + unsigned int i, j, lc[6], rc[6];
534 + for (i = 0; i < 6; i++) {
537 + for (j = 0; j < 4; j++) {
538 + lc[i] |= (sub_lc[i * 4 + j] << (j << 3));
539 + rc[i] |= (sub_rc[i * 4 + j] << (j << 3));
543 + for (i = 0; i < 6; i++) {
544 + mmio->aes_subcode_txa_lu[i] = 0x00000000;
545 + mmio->aes_subcode_txa_lc[i] = lc[i];
546 + mmio->aes_subcode_txa_lv[i] = 0x00000000;
547 + mmio->aes_subcode_txa_ru[i] = 0x00000000;
548 + mmio->aes_subcode_txa_rc[i] = rc[i];
549 + mmio->aes_subcode_txb_lu[i] = 0x00000000;
550 + mmio->aes_subcode_txb_lc[i] = lc[i];
551 + mmio->aes_subcode_txb_lv[i] = 0x00000000;
552 + mmio->aes_subcode_txb_ru[i] = 0x00000000;
553 + mmio->aes_subcode_txb_rc[i] = rc[i];
556 + for (i = 0; i < 2; i++) {
557 + mmio->aes_subcode_txa_rv0[i] = 0x00000000;
558 + mmio->aes_subcode_txb_rv0[i] = 0x00000000;
561 + for (i = 0; i < 4; i++) {
562 + mmio->aes_subcode_txa_rv2[i] = 0x00000000;
563 + mmio->aes_subcode_txb_rv2[i] = 0x00000000;
568 +snd_rad1_genset_aestx_subcode(struct snd_rad1 *chip, int rate)
571 + unsigned char lc[24], rc[24];
573 + for (i = 0; i < 24; i++) {
578 + lc[0] = 0x04; /* PRO=0, !AUDIO=0, COPY=1, PRE=000, MODE=00 */
580 + lc[1] = 0x01; /* Laser Optical, CD IEC-908 */
582 + lc[2] = 0x10; /* SOURCE=0000, CHANNEL=0001 */
583 + rc[2] = 0x20; /* SOURCE=0000, CHANNEL=0010 */
586 + * RAD1 systems have generally decent clock sources,
587 + * so we mark them as Level I
591 + lc[3] = 0x0c; /* Level I, 32 kHz */
595 + lc[3] = 0x00; /* Level I, 44.1 kHz */
599 + lc[3] = 0x04; /* Level I, 48 kHz */
603 + /* Not a valid IEC-958 sample rate */
604 + lc[3] = 0x10; /* Level III, 44.1 kHz */
607 + snd_rad1_set_aestx_subcode(chip, lc, rc);
611 +snd_rad1_set_cg(struct snd_rad1 *chip, int cg, long rate,
612 + long base, unsigned muxsel)
614 + volatile struct rad1regs *mmio = chip->mmio;
618 + snd_rad1_red_frac(&base, &rate, 0xffff);
619 + div = (base / rate);
620 + rem = (base % rate);
621 + snd_rad1_red_frac(&rem, &rate, 0xffff);
622 + flags = (((rem * 2) < rate) ? 0x600 : 0x200);
624 + mmio->reset = 0xffe20000 | (0x100 << cg);
625 + mmio->freq_synth_mux_sel[3 - cg] = muxsel;
626 + mmio->clockgen_rem = (rem << 16) | (0x10000 - rate);
627 + mmio->clockgen_ictl = (flags | (0x10000000 << cg) | (div - 1));
628 + mmio->reset = 0xffe20000;
631 +/* Select best master clock source for low jitter */
633 +snd_rad1_set_cgms(struct snd_rad1 *chip, int cg, long rate)
635 + if (!(176400 % rate))
636 + snd_rad1_set_cg(chip, cg, rate, 176400, 0);
638 + snd_rad1_set_cg(chip, cg, rate, 192000, 1);
642 +snd_rad1_setrate_pipe(struct snd_rad1 *chip, int pidx, int rate)
644 + if (pidx == RAD1_ADC)
645 + snd_rad1_set_cgms(chip, 0, rate);
647 + if (pidx == RAD1_DAC)
648 + snd_rad1_set_cgms(chip, 1, rate);
650 + if (pidx == RAD1_AESTX) {
651 + snd_rad1_set_cgms(chip, 2, rate);
652 + snd_rad1_genset_aestx_subcode(chip, rate);
657 +snd_rad1_prepare_pipe(struct snd_pcm_substream *substream, int pidx)
659 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
660 + struct snd_pcm_runtime *runtime = substream->runtime;
661 + struct snd_rad1_pipe *pipe = (chip->pipes + pidx);
662 + unsigned long flags;
664 + spin_lock_irqsave(&chip->lock, flags);
665 + snd_rad1_run_pipe(chip, pidx, 0);
666 + spin_unlock_irqrestore(&chip->lock, flags);
668 + pipe->subs = substream;
669 + pipe->vma = (int *)runtime->dma_area;
670 + pipe->pma = runtime->dma_addr;
671 + pipe->pnum = runtime->periods;
672 + pipe->plen = frames_to_bytes(runtime, runtime->period_size);
674 + snd_rad1_setrate_pipe(chip, pidx, runtime->rate);
678 + snd_rad1_setup_dma_pipe(chip, pidx);
684 +snd_rad1_detect_aesrx_rate(struct snd_rad1 *chip, struct snd_pcm_hardware *hw)
687 + unsigned sc = (((chip->mmio->chip_status0) >> 24) & 7);
688 + static int rates[8] = {0, 48000, 44100, 32000, 48000,
689 + 44100, 44056, 32000};
692 + printk(KERN_INFO "rad1: Warning: Recording from an unlocked "
693 + "IEC958 source. Assuming sample rate: %d.\n",
694 + chip->last_aesrx_rate);
695 + rate = chip->last_aesrx_rate;
699 + chip->last_aesrx_rate = rate;
700 + hw->rate_min = rate;
701 + hw->rate_max = rate;
705 + hw->rates = SNDRV_PCM_RATE_32000;
708 + hw->rates = SNDRV_PCM_RATE_CONTINUOUS;
711 + hw->rates = SNDRV_PCM_RATE_48000;
714 + hw->rates = SNDRV_PCM_RATE_44100;
720 +snd_rad1_trigger_pipe(struct snd_pcm_substream *substream, int pidx, int cmd)
722 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
726 + case SNDRV_PCM_TRIGGER_START:
727 + case SNDRV_PCM_TRIGGER_RESUME:
728 + snd_rad1_run_pipe(chip, pidx, 1);
730 + case SNDRV_PCM_TRIGGER_STOP:
731 + case SNDRV_PCM_TRIGGER_SUSPEND:
732 + snd_rad1_run_pipe(chip, pidx, 0);
741 +static snd_pcm_uframes_t
742 +snd_rad1_ptr_pipe(struct snd_pcm_substream *substream, int pidx)
744 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
746 + return chip->pipes[pidx].qptr;
749 +/* ----------------------------------------------------------------------- */
752 +/* ----------------------------------------------------------------------- */
754 +static struct snd_pcm_hardware
756 + .info = (SNDRV_PCM_INFO_INTERLEAVED |
757 + SNDRV_PCM_INFO_MMAP |
758 + SNDRV_PCM_INFO_MMAP_VALID |
759 + SNDRV_PCM_INFO_BLOCK_TRANSFER),
760 + .rates = (SNDRV_PCM_RATE_CONTINUOUS |
761 + SNDRV_PCM_RATE_32000 |
762 + SNDRV_PCM_RATE_44100 |
763 + SNDRV_PCM_RATE_48000),
764 + .formats = SNDRV_PCM_FMTBIT_S24_BE,
769 + .buffer_bytes_max = 1048576,
770 + .period_bytes_min = 4096,
771 + .period_bytes_max = 4096,
773 + .periods_max = 256,
777 +snd_rad1_adc_open(struct snd_pcm_substream *substream)
779 + struct snd_pcm_runtime *runtime = substream->runtime;
781 + runtime->hw = snd_rad1_adc_hw;
787 +snd_rad1_adc_close(struct snd_pcm_substream *substream)
789 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
791 + snd_rad1_run_pipe(chip, RAD1_ADC, 0);
797 +snd_rad1_adc_params(struct snd_pcm_substream *substream,
798 + struct snd_pcm_hw_params *hw_params)
800 + return snd_pcm_lib_malloc_pages(substream,
801 + params_buffer_bytes(hw_params));
805 +snd_rad1_adc_free(struct snd_pcm_substream *substream)
807 + return snd_rad1_free_pipe(substream, RAD1_ADC);
811 +snd_rad1_adc_prepare(struct snd_pcm_substream *substream)
813 + return snd_rad1_prepare_pipe(substream, RAD1_ADC);
817 +snd_rad1_adc_trigger(struct snd_pcm_substream *substream, int cmd)
819 + return snd_rad1_trigger_pipe(substream, RAD1_ADC, cmd);
822 +static snd_pcm_uframes_t
823 +snd_rad1_adc_ptr(struct snd_pcm_substream *substream)
825 + return snd_rad1_ptr_pipe(substream, RAD1_ADC);
828 +static struct snd_pcm_ops
829 +snd_rad1_adc_ops = {
830 + .open = snd_rad1_adc_open,
831 + .close = snd_rad1_adc_close,
832 + .hw_params = snd_rad1_adc_params,
833 + .hw_free = snd_rad1_adc_free,
834 + .prepare = snd_rad1_adc_prepare,
835 + .trigger = snd_rad1_adc_trigger,
836 + .pointer = snd_rad1_adc_ptr,
837 + .ioctl = snd_pcm_lib_ioctl,
841 +snd_rad1_adc_pcm_free(struct snd_pcm *pcm)
843 + snd_pcm_lib_preallocate_free_for_all(pcm);
847 +snd_rad1_new_adc(struct snd_rad1 *chip, int dev)
849 + struct snd_pcm *pcm;
852 + err = snd_pcm_new(chip->card, "RAD1 ADC", dev, 0, 1, &pcm);
853 + if (unlikely(err < 0))
856 + pcm->private_data = chip;
857 + pcm->private_free = snd_rad1_adc_pcm_free;
858 + strlcpy(pcm->name, "RAD1 ADC", sizeof(pcm->name));
859 + chip->pipes[RAD1_ADC].pcm = pcm;
860 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rad1_adc_ops);
861 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
862 + snd_dma_pci_data(chip->pci),
868 +/* ----------------------------------------------------------------------- */
871 +/* ----------------------------------------------------------------------- */
874 +snd_pcm_hardware snd_rad1_dac_hw = {
875 + .info = (SNDRV_PCM_INFO_INTERLEAVED |
876 + SNDRV_PCM_INFO_MMAP |
877 + SNDRV_PCM_INFO_MMAP_VALID |
878 + SNDRV_PCM_INFO_BLOCK_TRANSFER),
879 + .rates = (SNDRV_PCM_RATE_CONTINUOUS |
880 + SNDRV_PCM_RATE_32000 |
881 + SNDRV_PCM_RATE_44100 |
882 + SNDRV_PCM_RATE_48000),
883 + .formats = SNDRV_PCM_FMTBIT_S24_BE,
888 + .buffer_bytes_max = 1048576,
889 + .period_bytes_min = 4096,
890 + .period_bytes_max = 4096,
892 + .periods_max = 256,
896 +snd_rad1_dac_open(struct snd_pcm_substream *substream)
898 + struct snd_pcm_runtime *runtime = substream->runtime;
900 + runtime->hw = snd_rad1_dac_hw;
906 +snd_rad1_dac_close(struct snd_pcm_substream *substream)
908 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
910 + snd_rad1_run_pipe(chip, RAD1_DAC, 0);
916 +snd_rad1_dac_params(struct snd_pcm_substream *substream,
917 + struct snd_pcm_hw_params *hw_params)
919 + return snd_pcm_lib_malloc_pages(substream,
920 + params_buffer_bytes(hw_params));
924 +snd_rad1_dac_free(struct snd_pcm_substream *substream)
926 + return snd_rad1_free_pipe(substream, RAD1_DAC);
930 +snd_rad1_dac_prepare(struct snd_pcm_substream *substream)
932 + return snd_rad1_prepare_pipe(substream, RAD1_DAC);
936 +snd_rad1_dac_trigger(struct snd_pcm_substream *substream, int cmd)
938 + return snd_rad1_trigger_pipe(substream, RAD1_DAC, cmd);
941 +static snd_pcm_uframes_t
942 +snd_rad1_dac_ptr(struct snd_pcm_substream *substream)
944 + return snd_rad1_ptr_pipe(substream, RAD1_DAC);
947 +static struct snd_pcm_ops
948 +snd_rad1_dac_ops = {
949 + .open = snd_rad1_dac_open,
950 + .close = snd_rad1_dac_close,
951 + .hw_params = snd_rad1_dac_params,
952 + .hw_free = snd_rad1_dac_free,
953 + .prepare = snd_rad1_dac_prepare,
954 + .trigger = snd_rad1_dac_trigger,
955 + .pointer = snd_rad1_dac_ptr,
956 + .ioctl = snd_pcm_lib_ioctl,
960 +snd_rad1_dac_pcm_free(struct snd_pcm *pcm)
962 + snd_pcm_lib_preallocate_free_for_all(pcm);
966 +snd_rad1_new_dac(struct snd_rad1 *chip, int dev)
968 + struct snd_pcm *pcm;
971 + err = snd_pcm_new(chip->card, "RAD1 DAC", dev, 1, 0, &pcm);
972 + if (unlikely(err < 0))
975 + pcm->private_data = chip;
976 + pcm->private_free = snd_rad1_dac_pcm_free;
977 + strlcpy(pcm->name, "RAD1 DAC", sizeof(pcm->name));
978 + chip->pipes[RAD1_DAC].pcm = pcm;
979 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rad1_dac_ops);
980 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
981 + snd_dma_pci_data(chip->pci),
987 +/* ----------------------------------------------------------------------- */
990 +/* ----------------------------------------------------------------------- */
992 +static struct snd_pcm_hardware
993 +snd_rad1_aesrx_hw = {
994 + .info = (SNDRV_PCM_INFO_INTERLEAVED |
995 + SNDRV_PCM_INFO_MMAP |
996 + SNDRV_PCM_INFO_MMAP_VALID |
997 + SNDRV_PCM_INFO_BLOCK_TRANSFER),
998 + .rates = (SNDRV_PCM_RATE_32000 |
999 + SNDRV_PCM_RATE_44100 |
1000 + SNDRV_PCM_RATE_48000),
1001 + .formats = SNDRV_PCM_FMTBIT_S24_BE,
1002 + .rate_min = 32000,
1003 + .rate_max = 48000,
1004 + .channels_min = 2,
1005 + .channels_max = 2,
1006 + .buffer_bytes_max = 1048576,
1007 + .period_bytes_min = 4096,
1008 + .period_bytes_max = 4096,
1010 + .periods_max = 256,
1014 +snd_rad1_aesrx_open(struct snd_pcm_substream *substream)
1016 + struct snd_pcm_runtime *runtime = substream->runtime;
1017 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
1019 + runtime->hw = snd_rad1_aesrx_hw;
1020 + snd_rad1_detect_aesrx_rate(chip, &runtime->hw);
1026 +snd_rad1_aesrx_close(struct snd_pcm_substream *substream)
1028 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
1030 + snd_rad1_run_pipe(chip, RAD1_AESRX, 0);
1036 +snd_rad1_aesrx_params(struct snd_pcm_substream *substream,
1037 + struct snd_pcm_hw_params *hw_params)
1039 + return snd_pcm_lib_malloc_pages(substream,
1040 + params_buffer_bytes(hw_params));
1044 +snd_rad1_aesrx_free(struct snd_pcm_substream *substream)
1046 + return snd_rad1_free_pipe(substream, RAD1_AESRX);
1050 +snd_rad1_aesrx_prepare(struct snd_pcm_substream *substream)
1052 + return snd_rad1_prepare_pipe(substream, RAD1_AESRX);
1056 +snd_rad1_aesrx_trigger(struct snd_pcm_substream *substream, int cmd)
1058 + return snd_rad1_trigger_pipe(substream, RAD1_AESRX, cmd);
1061 +static snd_pcm_uframes_t
1062 +snd_rad1_aesrx_ptr(struct snd_pcm_substream *substream)
1064 + return snd_rad1_ptr_pipe(substream, RAD1_AESRX);
1067 +static struct snd_pcm_ops
1068 +snd_rad1_aesrx_ops = {
1069 + .open = snd_rad1_aesrx_open,
1070 + .close = snd_rad1_aesrx_close,
1071 + .hw_params = snd_rad1_aesrx_params,
1072 + .hw_free = snd_rad1_aesrx_free,
1073 + .prepare = snd_rad1_aesrx_prepare,
1074 + .trigger = snd_rad1_aesrx_trigger,
1075 + .pointer = snd_rad1_aesrx_ptr,
1076 + .ioctl = snd_pcm_lib_ioctl,
1080 +snd_rad1_aesrx_pcm_free(struct snd_pcm *pcm)
1082 + snd_pcm_lib_preallocate_free_for_all(pcm);
1086 +snd_rad1_new_aesrx(struct snd_rad1 *chip, int dev)
1088 + struct snd_pcm *pcm;
1091 + err = snd_pcm_new(chip->card, "RAD1 AES Rx", dev, 0, 1, &pcm);
1092 + if (unlikely(err < 0))
1095 + pcm->private_data = chip;
1096 + pcm->private_free = snd_rad1_aesrx_pcm_free;
1097 + strlcpy(pcm->name, "RAD1 AES Rx", sizeof(pcm->name));
1098 + chip->pipes[RAD1_AESRX].pcm = pcm;
1099 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rad1_aesrx_ops);
1100 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1101 + snd_dma_pci_data(chip->pci),
1103 + chip->last_aesrx_rate = 44100;
1108 +/* ----------------------------------------------------------------------- */
1111 +/* ----------------------------------------------------------------------- */
1113 +static struct snd_pcm_hardware
1114 +snd_rad1_aestx_hw = {
1115 + .info = (SNDRV_PCM_INFO_INTERLEAVED |
1116 + SNDRV_PCM_INFO_MMAP |
1117 + SNDRV_PCM_INFO_MMAP_VALID |
1118 + SNDRV_PCM_INFO_BLOCK_TRANSFER),
1119 + .rates = (SNDRV_PCM_RATE_32000 |
1120 + SNDRV_PCM_RATE_44100 |
1121 + SNDRV_PCM_RATE_48000),
1122 + .formats = SNDRV_PCM_FMTBIT_S24_BE,
1123 + .rate_min = 32000,
1124 + .rate_max = 48000,
1125 + .channels_min = 2,
1126 + .channels_max = 2,
1127 + .buffer_bytes_max = 1048576,
1128 + .period_bytes_min = 4096,
1129 + .period_bytes_max = 4096,
1131 + .periods_max = 256,
1135 +snd_rad1_aestx_open(struct snd_pcm_substream *substream)
1137 + struct snd_pcm_runtime *runtime = substream->runtime;
1139 + runtime->hw = snd_rad1_aestx_hw;
1145 +snd_rad1_aestx_close(struct snd_pcm_substream *substream)
1147 + struct snd_rad1 *chip = snd_pcm_substream_chip(substream);
1149 + snd_rad1_run_pipe(chip, RAD1_AESTX, 0);
1155 +snd_rad1_aestx_params(struct snd_pcm_substream *substream,
1156 + struct snd_pcm_hw_params *hw_params)
1158 + return snd_pcm_lib_malloc_pages(substream,
1159 + params_buffer_bytes(hw_params));
1163 +snd_rad1_aestx_free(struct snd_pcm_substream *substream)
1165 + return snd_rad1_free_pipe(substream, RAD1_AESTX);
1169 +snd_rad1_aestx_prepare(struct snd_pcm_substream *substream)
1171 + return snd_rad1_prepare_pipe(substream, RAD1_AESTX);
1175 +snd_rad1_aestx_trigger(struct snd_pcm_substream *substream, int cmd)
1177 + return snd_rad1_trigger_pipe(substream, RAD1_AESTX, cmd);
1180 +static snd_pcm_uframes_t
1181 +snd_rad1_aestx_ptr(struct snd_pcm_substream *substream)
1183 + return snd_rad1_ptr_pipe(substream, RAD1_AESTX);
1186 +static struct snd_pcm_ops
1187 +snd_rad1_aestx_ops = {
1188 + .open = snd_rad1_aestx_open,
1189 + .close = snd_rad1_aestx_close,
1190 + .hw_params = snd_rad1_aestx_params,
1191 + .hw_free = snd_rad1_aestx_free,
1192 + .prepare = snd_rad1_aestx_prepare,
1193 + .trigger = snd_rad1_aestx_trigger,
1194 + .pointer = snd_rad1_aestx_ptr,
1195 + .ioctl = snd_pcm_lib_ioctl,
1199 +snd_rad1_aestx_pcm_free(struct snd_pcm *pcm)
1201 + snd_pcm_lib_preallocate_free_for_all(pcm);
1205 +snd_rad1_new_aestx(struct snd_rad1 *chip, int dev)
1207 + struct snd_pcm *pcm;
1210 + err = snd_pcm_new(chip->card, "RAD1 AES Tx", dev, 1, 0, &pcm);
1211 + if (unlikely(err < 0))
1214 + pcm->private_data = chip;
1215 + pcm->private_free = snd_rad1_aestx_pcm_free;
1216 + strlcpy(pcm->name, "RAD1 AES Tx", sizeof(pcm->name));
1217 + chip->pipes[RAD1_AESTX].pcm = pcm;
1218 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rad1_aestx_ops);
1219 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1220 + snd_dma_pci_data(chip->pci),
1226 +/* ----------------------------------------------------------------------- */
1229 +/* ----------------------------------------------------------------------- */
1230 +/* Volume control */
1232 +snd_rad1_control_pv_info(struct snd_kcontrol *kcontrol,
1233 + struct snd_ctl_elem_info *uinfo)
1235 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1237 + uinfo->value.integer.min = 0;
1238 + uinfo->value.integer.max = 255;
1244 +snd_rad1_control_pv_get(struct snd_kcontrol *kcontrol,
1245 + struct snd_ctl_elem_value *u)
1247 + int shift = (kcontrol->private_value * 16);
1248 + unsigned long flags;
1249 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1251 + spin_lock_irqsave(&chip->lock, flags);
1252 + u->value.integer.value[0] = ((chip->attctrl >> shift) & 0xff);
1253 + u->value.integer.value[1] = ((chip->attctrl >> (8 + shift)) & 0xff);
1254 + spin_unlock_irqrestore(&chip->lock, flags);
1260 +snd_rad1_control_pv_put(struct snd_kcontrol *kcontrol,
1261 + struct snd_ctl_elem_value *u)
1264 + int shift = (kcontrol->private_value * 16);
1265 + unsigned long flags;
1266 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1268 + spin_lock_irqsave(&chip->lock, flags);
1269 + if (u->value.integer.value[0] != ((chip->attctrl >> shift) & 0xff))
1272 + if (u->value.integer.value[1] != ((chip->attctrl >> (8 + shift)) & 0xff))
1276 + chip->attctrl &= (0xffff << (16 - shift));
1277 + chip->attctrl |= (u->value.integer.value[0] << shift);
1278 + chip->attctrl |= (u->value.integer.value[1] << (8 + shift));
1279 + chip->mmio->volume_control = chip->attctrl;
1281 + spin_unlock_irqrestore(&chip->lock, flags);
1286 +/* ----------------------------------------------------------------------- */
1289 +/* ----------------------------------------------------------------------- */
1290 +/* AES Tx route control */
1292 +snd_rad1_control_tr_info(struct snd_kcontrol *kcontrol,
1293 + struct snd_ctl_elem_info *uinfo)
1295 + static char *rts[2] = {"Optical", "Coaxial"};
1297 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1299 + uinfo->value.enumerated.items = 2;
1301 + if (uinfo->value.enumerated.item > 1)
1302 + uinfo->value.enumerated.item = 1;
1304 + strlcpy(uinfo->value.enumerated.name,
1305 + rts[uinfo->value.enumerated.item],
1306 + sizeof(uinfo->value.enumerated.name));
1312 +snd_rad1_control_tr_get(struct snd_kcontrol *kcontrol,
1313 + struct snd_ctl_elem_value *u)
1315 + unsigned long flags;
1316 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1318 + spin_lock_irqsave(&chip->lock, flags);
1319 + if (chip->rt_opto == 0x00001440)
1320 + u->value.enumerated.item[0] = 1;
1322 + u->value.enumerated.item[0] = 0;
1323 + spin_unlock_irqrestore(&chip->lock, flags);
1329 +snd_rad1_control_tr_put(struct snd_kcontrol *kcontrol,
1330 + struct snd_ctl_elem_value *u)
1333 + unsigned long flags;
1334 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1336 + spin_lock_irqsave(&chip->lock, flags);
1337 + if (u->value.enumerated.item[0] && (chip->rt_opto != 0x00001440))
1340 + if (!u->value.enumerated.item[0] && (chip->rt_opto == 0x00001440))
1344 + if (u->value.enumerated.item[0])
1345 + chip->rt_opto = 0x00001440;
1347 + chip->rt_opto = 0x00001040;
1348 + chip->mmio->misc_control = chip->rt_opto;
1350 + spin_unlock_irqrestore(&chip->lock, flags);
1355 +/* ----------------------------------------------------------------------- */
1358 +/* ----------------------------------------------------------------------- */
1359 +/* AES Rx route control */
1361 +snd_rad1_control_rr_get(struct snd_kcontrol *kcontrol,
1362 + struct snd_ctl_elem_value *u)
1364 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1365 + unsigned long flags;
1367 + spin_lock_irqsave(&chip->lock, flags);
1368 + if (chip->rt_aesr == 0x00000010)
1369 + u->value.enumerated.item[0] = 1;
1371 + u->value.enumerated.item[0] = 0;
1372 + spin_unlock_irqrestore(&chip->lock, flags);
1378 +snd_rad1_control_rr_put(struct snd_kcontrol *kcontrol,
1379 + struct snd_ctl_elem_value *u)
1381 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1382 + unsigned long flags;
1385 + spin_lock_irqsave(&chip->lock, flags);
1386 + if (u->value.enumerated.item[0] && (chip->rt_aesr != 0x00000010))
1389 + if (!u->value.enumerated.item[0] && (chip->rt_aesr == 0x00000010))
1393 + if (u->value.enumerated.item[0]) {
1394 + chip->rt_aesr = 0x00000010;
1395 + chip->rt_adat = 0xa0000018;
1397 + chip->rt_aesr = 0x00000018;
1398 + chip->rt_adat = 0xa0000000;
1400 + chip->mmio->aes_rx_control = (chip->rt_aesr |
1401 + chip->pipes[RAD1_AESRX].adma);
1402 + chip->mmio->adat_rx_control = (chip->rt_adat |
1403 + chip->pipes[RAD1_ADATRX].adma);
1405 + spin_unlock_irqrestore(&chip->lock, flags);
1411 +/* ----------------------------------------------------------------------- */
1414 +/* ----------------------------------------------------------------------- */
1415 +/* ADC route control */
1417 +snd_rad1_control_ar_info(struct snd_kcontrol *kcontrol,
1418 + struct snd_ctl_elem_info *uinfo)
1420 + static char *rts[2] = {"Mic", "Line"};
1422 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1424 + uinfo->value.enumerated.items = 2;
1426 + if (uinfo->value.enumerated.item > 1)
1427 + uinfo->value.enumerated.item = 1;
1429 + strlcpy(uinfo->value.enumerated.name,
1430 + rts[uinfo->value.enumerated.item],
1431 + sizeof(uinfo->value.enumerated.name));
1437 +snd_rad1_control_ar_get(struct snd_kcontrol *kcontrol,
1438 + struct snd_ctl_elem_value *u)
1440 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1441 + unsigned long flags;
1443 + spin_lock_irqsave(&chip->lock, flags);
1444 + if (chip->rt_adc == 0x05000000)
1445 + u->value.enumerated.item[0] = 1;
1447 + u->value.enumerated.item[0] = 0;
1448 + spin_unlock_irqrestore(&chip->lock, flags);
1454 +snd_rad1_control_ar_put(struct snd_kcontrol *kcontrol,
1455 + struct snd_ctl_elem_value *u)
1457 + struct snd_rad1 *chip = snd_kcontrol_chip(kcontrol);
1458 + unsigned long flags;
1461 + spin_lock_irqsave(&chip->lock, flags);
1462 + if (u->value.enumerated.item[0] && (chip->rt_adc != 0x05000000))
1465 + if (!u->value.enumerated.item[0] && (chip->rt_adc == 0x05000000))
1469 + if (u->value.enumerated.item[0])
1470 + chip->rt_adc = 0x05000000;
1472 + chip->rt_adc = 0x03000000;
1473 + chip->mmio->adc_control = (chip->rt_adc |
1474 + chip->pipes[RAD1_ADC].adma);
1476 + spin_unlock_irqrestore(&chip->lock, flags);
1481 +/* ----------------------------------------------------------------------- */
1484 +/* ----------------------------------------------------------------------- */
1486 +static struct snd_kcontrol_new
1487 +snd_rad1_controls[] = {
1489 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1490 + .name = "Master Playback Volume",
1491 + .info = snd_rad1_control_pv_info,
1492 + .get = snd_rad1_control_pv_get,
1493 + .put = snd_rad1_control_pv_put,
1494 + .private_value = 1
1497 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1498 + .name = "Line Capture Volume",
1499 + .info = snd_rad1_control_pv_info,
1500 + .get = snd_rad1_control_pv_get,
1501 + .put = snd_rad1_control_pv_put,
1502 + .private_value = 0
1505 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1506 + .name = "IEC958 Playback Routing",
1507 + .info = snd_rad1_control_tr_info,
1508 + .get = snd_rad1_control_tr_get,
1509 + .put = snd_rad1_control_tr_put
1512 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1513 + .name = "IEC958 Capture Routing",
1514 + .info = snd_rad1_control_tr_info, /* clone */
1515 + .get = snd_rad1_control_rr_get,
1516 + .put = snd_rad1_control_rr_put
1519 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1520 + .name = "Line Capture Routing",
1521 + .info = snd_rad1_control_ar_info,
1522 + .get = snd_rad1_control_ar_get,
1523 + .put = snd_rad1_control_ar_put
1528 +snd_rad1_add_controls(struct snd_rad1 *chip)
1532 + for (idx = 0; idx < 5; idx++) {
1533 + err = snd_ctl_add(chip->card,
1534 + snd_ctl_new1(&snd_rad1_controls[idx], chip));
1535 + if (unlikely(err < 0))
1542 +/* ----------------------------------------------------------------------- */
1545 +/* ----------------------------------------------------------------------- */
1546 +/* Create/Probe/Free/Module */
1549 +snd_rad1_free(struct snd_rad1 *chip)
1552 + iounmap((void *)(chip->mmio));
1553 + chip->mmio = NULL;
1561 +snd_rad1_dev_free(struct snd_device *device)
1563 + struct snd_rad1 *chip = device->device_data;
1565 + return snd_rad1_free(chip);
1569 +snd_rad1_create(struct snd_card *card, struct pci_dev *pci,
1570 + struct snd_rad1 **rchip)
1572 + int error = -ENODEV;
1573 + struct snd_rad1 *chip;
1574 + static struct snd_device_ops ops = {
1575 + .dev_free = snd_rad1_dev_free,
1580 + if (unlikely(pci_enable_device(pci)))
1583 + if (unlikely(pci_request_regions(pci, "rad1")))
1584 + goto out_disable_dev;
1586 + pci_write_config_byte(pci, PCI_LATENCY_TIMER, 64);
1587 + pci_set_master(pci);
1589 + chip = kzalloc(sizeof(struct snd_rad1), GFP_KERNEL);
1590 + if (unlikely(!chip)) {
1592 + goto out_rel_region;
1595 + timer_setup(&chip->timer, snd_rad1_poll_timer, 0);
1597 + chip->card = card;
1600 + spin_lock_init(&chip->lock);
1602 + chip->mmio_phys = pci_resource_start(pci, 0);
1603 + chip->mmio = ioremap_nocache(chip->mmio_phys,
1604 + pci_resource_len(pci, 0));
1606 + snd_rad1_hw_init(chip);
1608 + if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops))
1609 + goto out_rad1_free;
1611 + snd_card_set_dev(card, &pci->dev);
1617 + snd_rad1_free(chip);
1619 + pci_release_regions(pci);
1621 + pci_disable_device(pci);
1626 +static struct pci_device_id
1628 + { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_RAD1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
1632 +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
1633 +static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
1634 +static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
1638 +snd_rad1_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1640 + struct snd_card *card;
1641 + struct snd_rad1 *chip;
1644 + if (unlikely(ndev >= SNDRV_CARDS))
1647 + if (unlikely(!enable[ndev])) {
1652 + err = snd_card_new(&pci->dev, index[ndev], id[ndev], THIS_MODULE, 0, &card);
1653 + if (unlikely(err < 0))
1656 + err = snd_rad1_create(card, pci, &chip);
1657 + if (unlikely(err < 0)) {
1658 + snd_card_free(card);
1662 + strlcpy(card->driver, "RAD1", sizeof(card->driver));
1663 + strlcpy(card->shortname, "RADAudio", sizeof(card->shortname));
1664 + snprintf(card->longname, sizeof(card->longname),
1665 + "SGI RAD Audio at 0x%lx", chip->mmio_phys);
1667 + /* create pipes */
1668 + snd_rad1_new_dac(chip, 0);
1669 + snd_rad1_new_adc(chip, 1);
1670 + snd_rad1_new_aestx(chip, 2);
1671 + snd_rad1_new_aesrx(chip, 3);
1672 + snd_rad1_add_controls(chip);
1674 + err = snd_card_register(card);
1675 + if (unlikely(err < 0)) {
1676 + snd_card_free(card);
1680 + pci_set_drvdata(pci, card);
1687 +snd_rad1_remove(struct pci_dev *pci)
1689 + snd_card_free(pci_get_drvdata(pci));
1690 + pci_set_drvdata(pci, NULL);
1693 +MODULE_DEVICE_TABLE(pci, snd_rad1_ids);
1695 +static struct pci_driver
1698 + .id_table = snd_rad1_ids,
1699 + .probe = snd_rad1_probe,
1700 + .remove = snd_rad1_remove,
1704 +alsa_card_rad1_init(void)
1706 + return pci_register_driver(&rad1_driver);
1710 +alsa_card_rad1_exit(void)
1712 + pci_unregister_driver(&rad1_driver);
1715 +MODULE_AUTHOR("Stanislaw Skowronek <skylark@unaligned.org>");
1716 +MODULE_AUTHOR("René Rebe <rene@exactcode.de");
1717 +MODULE_DESCRIPTION("SGI Octane (IP30) RAD1 ALSA driver");
1718 +MODULE_LICENSE("GPL");
1719 +MODULE_VERSION("0.42.3");
1721 +module_init(alsa_card_rad1_init)
1722 +module_exit(alsa_card_rad1_exit)