1 /* Hewlett-Packard Harmony audio driver
3 * This is a driver for the Harmony audio chipset found
4 * on the LASI ASIC of various early HP PA-RISC workstations.
6 * Copyright (C) 2004, Kyle McMartin <kyle@{debian.org,parisc-linux.org}>
8 * Based on the previous Harmony incarnations by,
9 * Copyright 2000 (c) Linuxcare Canada, Alex deVries
10 * Copyright 2000-2003 (c) Helge Deller
11 * Copyright 2001 (c) Matthieu Delahaye
12 * Copyright 2001 (c) Jean-Christophe Vaugeois
13 * Copyright 2003 (c) Laurent Canet
14 * Copyright 2004 (c) Stuart Brady
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License, version 2, as
18 * published by the Free Software Foundation.
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.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 * - graveyard and silence buffers last for lifetime of
31 * the driver. playback and capture buffers are allocated
32 * per _open()/_close().
38 #include <linux/init.h>
39 #include <linux/slab.h>
40 #include <linux/time.h>
41 #include <linux/wait.h>
42 #include <linux/delay.h>
43 #include <linux/module.h>
44 #include <linux/interrupt.h>
45 #include <linux/spinlock.h>
46 #include <linux/dma-mapping.h>
48 #include <sound/driver.h>
49 #include <sound/core.h>
50 #include <sound/pcm.h>
51 #include <sound/control.h>
52 #include <sound/rawmidi.h>
53 #include <sound/initval.h>
54 #include <sound/info.h>
57 #include <asm/hardware.h>
58 #include <asm/parisc-device.h>
62 static struct parisc_device_id snd_harmony_devtable
[] = {
63 /* bushmaster / flounder */
64 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x0007A },
66 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x0007B },
68 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x0007E },
69 /* outfield / coral II */
70 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x0007F },
74 MODULE_DEVICE_TABLE(parisc
, snd_harmony_devtable
);
76 #define NAME "harmony"
79 static unsigned int snd_harmony_rates
[] = {
80 5512, 6615, 8000, 9600,
81 11025, 16000, 18900, 22050,
82 27428, 32000, 33075, 37800,
86 static unsigned int rate_bits
[14] = {
87 HARMONY_SR_5KHZ
, HARMONY_SR_6KHZ
, HARMONY_SR_8KHZ
,
88 HARMONY_SR_9KHZ
, HARMONY_SR_11KHZ
, HARMONY_SR_16KHZ
,
89 HARMONY_SR_18KHZ
, HARMONY_SR_22KHZ
, HARMONY_SR_27KHZ
,
90 HARMONY_SR_32KHZ
, HARMONY_SR_33KHZ
, HARMONY_SR_37KHZ
,
91 HARMONY_SR_44KHZ
, HARMONY_SR_48KHZ
94 static snd_pcm_hw_constraint_list_t hw_constraint_rates
= {
95 .count
= ARRAY_SIZE(snd_harmony_rates
),
96 .list
= snd_harmony_rates
,
101 harmony_read(harmony_t
*h
, unsigned r
)
103 return __raw_readl(h
->iobase
+ r
);
107 harmony_write(harmony_t
*h
, unsigned r
, unsigned long v
)
109 __raw_writel(v
, h
->iobase
+ r
);
113 harmony_wait_for_control(harmony_t
*h
)
115 while (harmony_read(h
, HARMONY_CNTL
) & HARMONY_CNTL_C
) ;
119 harmony_reset(harmony_t
*h
)
121 harmony_write(h
, HARMONY_RESET
, 1);
123 harmony_write(h
, HARMONY_RESET
, 0);
127 harmony_disable_interrupts(harmony_t
*h
)
130 harmony_wait_for_control(h
);
131 dstatus
= harmony_read(h
, HARMONY_DSTATUS
);
132 dstatus
&= ~HARMONY_DSTATUS_IE
;
133 harmony_write(h
, HARMONY_DSTATUS
, dstatus
);
137 harmony_enable_interrupts(harmony_t
*h
)
140 harmony_wait_for_control(h
);
141 dstatus
= harmony_read(h
, HARMONY_DSTATUS
);
142 dstatus
|= HARMONY_DSTATUS_IE
;
143 harmony_write(h
, HARMONY_DSTATUS
, dstatus
);
147 harmony_mute(harmony_t
*h
)
151 spin_lock_irqsave(&h
->mixer_lock
, flags
);
152 harmony_wait_for_control(h
);
153 harmony_write(h
, HARMONY_GAINCTL
, HARMONY_GAIN_SILENCE
);
154 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
158 harmony_unmute(harmony_t
*h
)
162 spin_lock_irqsave(&h
->mixer_lock
, flags
);
163 harmony_wait_for_control(h
);
164 harmony_write(h
, HARMONY_GAINCTL
, h
->st
.gain
);
165 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
169 harmony_set_control(harmony_t
*h
)
174 spin_lock_irqsave(&h
->lock
, flags
);
176 ctrl
= (HARMONY_CNTL_C
|
177 (h
->st
.format
<< 6) |
178 (h
->st
.stereo
<< 5) |
181 harmony_wait_for_control(h
);
182 harmony_write(h
, HARMONY_CNTL
, ctrl
);
184 spin_unlock_irqrestore(&h
->lock
, flags
);
188 snd_harmony_interrupt(int irq
, void *dev
, struct pt_regs
*regs
)
194 harmony_disable_interrupts(h
);
195 harmony_wait_for_control(h
);
196 dstatus
= harmony_read(h
, HARMONY_DSTATUS
);
197 spin_unlock(&h
->lock
);
199 if (dstatus
& HARMONY_DSTATUS_PN
) {
202 h
->pbuf
.buf
+= h
->pbuf
.count
; /* PAGE_SIZE */
203 h
->pbuf
.buf
%= h
->pbuf
.size
; /* MAX_BUFS*PAGE_SIZE */
205 harmony_write(h
, HARMONY_PNXTADD
,
206 h
->pbuf
.addr
+ h
->pbuf
.buf
);
207 h
->stats
.play_intr
++;
208 spin_unlock(&h
->lock
);
209 snd_pcm_period_elapsed(h
->psubs
);
212 harmony_write(h
, HARMONY_PNXTADD
, h
->sdma
.addr
);
213 h
->stats
.silence_intr
++;
214 spin_unlock(&h
->lock
);
218 if (dstatus
& HARMONY_DSTATUS_RN
) {
221 h
->cbuf
.buf
+= h
->cbuf
.count
;
222 h
->cbuf
.buf
%= h
->cbuf
.size
;
224 harmony_write(h
, HARMONY_RNXTADD
,
225 h
->cbuf
.addr
+ h
->cbuf
.buf
);
227 spin_unlock(&h
->lock
);
228 snd_pcm_period_elapsed(h
->csubs
);
231 harmony_write(h
, HARMONY_RNXTADD
, h
->gdma
.addr
);
232 h
->stats
.graveyard_intr
++;
233 spin_unlock(&h
->lock
);
238 harmony_enable_interrupts(h
);
239 spin_unlock(&h
->lock
);
245 snd_harmony_rate_bits(int rate
)
249 for (i
= 0; i
< ARRAY_SIZE(snd_harmony_rates
); i
++)
250 if (snd_harmony_rates
[i
] == rate
)
253 return HARMONY_SR_44KHZ
;
256 static snd_pcm_hardware_t snd_harmony_playback
=
258 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
259 SNDRV_PCM_INFO_JOINT_DUPLEX
| SNDRV_PCM_INFO_MMAP_VALID
|
260 SNDRV_PCM_INFO_BLOCK_TRANSFER
),
261 .formats
= (SNDRV_PCM_FMTBIT_S16_BE
| SNDRV_PCM_FMTBIT_MU_LAW
|
262 SNDRV_PCM_FMTBIT_A_LAW
),
263 .rates
= (SNDRV_PCM_RATE_5512
| SNDRV_PCM_RATE_8000_48000
|
264 SNDRV_PCM_RATE_KNOT
),
269 .buffer_bytes_max
= MAX_BUF_SIZE
,
270 .period_bytes_min
= BUF_SIZE
,
271 .period_bytes_max
= BUF_SIZE
,
273 .periods_max
= MAX_BUFS
,
277 static snd_pcm_hardware_t snd_harmony_capture
=
279 .info
= (SNDRV_PCM_INFO_MMAP
| SNDRV_PCM_INFO_INTERLEAVED
|
280 SNDRV_PCM_INFO_JOINT_DUPLEX
| SNDRV_PCM_INFO_MMAP_VALID
|
281 SNDRV_PCM_INFO_BLOCK_TRANSFER
),
282 .formats
= (SNDRV_PCM_FMTBIT_S16_BE
| SNDRV_PCM_FMTBIT_MU_LAW
|
283 SNDRV_PCM_FMTBIT_A_LAW
),
284 .rates
= (SNDRV_PCM_RATE_5512
| SNDRV_PCM_RATE_8000_48000
|
285 SNDRV_PCM_RATE_KNOT
),
290 .buffer_bytes_max
= MAX_BUF_SIZE
,
291 .period_bytes_min
= BUF_SIZE
,
292 .period_bytes_max
= BUF_SIZE
,
294 .periods_max
= MAX_BUFS
,
299 snd_harmony_playback_trigger(snd_pcm_substream_t
*ss
, int cmd
)
301 harmony_t
*h
= snd_pcm_substream_chip(ss
);
307 spin_lock_irqsave(&h
->lock
, flags
);
309 case SNDRV_PCM_TRIGGER_START
:
311 harmony_write(h
, HARMONY_PNXTADD
, h
->pbuf
.addr
);
312 harmony_write(h
, HARMONY_RNXTADD
, h
->gdma
.addr
);
314 harmony_enable_interrupts(h
);
316 case SNDRV_PCM_TRIGGER_STOP
:
319 harmony_disable_interrupts(h
);
321 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
322 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
323 case SNDRV_PCM_TRIGGER_SUSPEND
:
325 spin_unlock_irqrestore(&h
->lock
, flags
);
329 spin_unlock_irqrestore(&h
->lock
, flags
);
335 snd_harmony_capture_trigger(snd_pcm_substream_t
*ss
, int cmd
)
337 harmony_t
*h
= snd_pcm_substream_chip(ss
);
343 spin_lock_irqsave(&h
->lock
, flags
);
345 case SNDRV_PCM_TRIGGER_START
:
347 harmony_write(h
, HARMONY_PNXTADD
, h
->sdma
.addr
);
348 harmony_write(h
, HARMONY_RNXTADD
, h
->cbuf
.addr
);
350 harmony_enable_interrupts(h
);
352 case SNDRV_PCM_TRIGGER_STOP
:
355 harmony_disable_interrupts(h
);
357 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
358 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
359 case SNDRV_PCM_TRIGGER_SUSPEND
:
361 spin_unlock_irqrestore(&h
->lock
, flags
);
365 spin_unlock_irqrestore(&h
->lock
, flags
);
371 snd_harmony_set_data_format(harmony_t
*h
, int fmt
, int force
)
373 int o
= h
->st
.format
;
377 case SNDRV_PCM_FORMAT_S16_BE
:
378 n
= HARMONY_DF_16BIT_LINEAR
;
380 case SNDRV_PCM_FORMAT_A_LAW
:
381 n
= HARMONY_DF_8BIT_ALAW
;
383 case SNDRV_PCM_FORMAT_MU_LAW
:
384 n
= HARMONY_DF_8BIT_ULAW
;
387 n
= HARMONY_DF_16BIT_LINEAR
;
391 if (force
|| o
!= n
) {
392 snd_pcm_format_set_silence(fmt
, h
->sdma
.area
, SILENCE_BUFSZ
/
393 (snd_pcm_format_physical_width(fmt
)
401 snd_harmony_playback_prepare(snd_pcm_substream_t
*ss
)
403 harmony_t
*h
= snd_pcm_substream_chip(ss
);
404 snd_pcm_runtime_t
*rt
= ss
->runtime
;
409 h
->pbuf
.size
= snd_pcm_lib_buffer_bytes(ss
);
410 h
->pbuf
.count
= snd_pcm_lib_period_bytes(ss
);
414 h
->st
.rate
= snd_harmony_rate_bits(rt
->rate
);
415 h
->st
.format
= snd_harmony_set_data_format(h
, rt
->format
, 0);
417 if (rt
->channels
== 2)
418 h
->st
.stereo
= HARMONY_SS_STEREO
;
420 h
->st
.stereo
= HARMONY_SS_MONO
;
422 harmony_set_control(h
);
424 h
->pbuf
.addr
= rt
->dma_addr
;
430 snd_harmony_capture_prepare(snd_pcm_substream_t
*ss
)
432 harmony_t
*h
= snd_pcm_substream_chip(ss
);
433 snd_pcm_runtime_t
*rt
= ss
->runtime
;
438 h
->cbuf
.size
= snd_pcm_lib_buffer_bytes(ss
);
439 h
->cbuf
.count
= snd_pcm_lib_period_bytes(ss
);
443 h
->st
.rate
= snd_harmony_rate_bits(rt
->rate
);
444 h
->st
.format
= snd_harmony_set_data_format(h
, rt
->format
, 0);
446 if (rt
->channels
== 2)
447 h
->st
.stereo
= HARMONY_SS_STEREO
;
449 h
->st
.stereo
= HARMONY_SS_MONO
;
451 harmony_set_control(h
);
453 h
->cbuf
.addr
= rt
->dma_addr
;
458 static snd_pcm_uframes_t
459 snd_harmony_playback_pointer(snd_pcm_substream_t
*ss
)
461 snd_pcm_runtime_t
*rt
= ss
->runtime
;
462 harmony_t
*h
= snd_pcm_substream_chip(ss
);
463 unsigned long pcuradd
;
464 unsigned long played
;
466 if (!(h
->st
.playing
) || (h
->psubs
== NULL
))
469 if ((h
->pbuf
.addr
== 0) || (h
->pbuf
.size
== 0))
472 pcuradd
= harmony_read(h
, HARMONY_PCURADD
);
473 played
= pcuradd
- h
->pbuf
.addr
;
476 printk(KERN_DEBUG PFX
"playback_pointer is 0x%lx-0x%lx = %d bytes\n",
477 pcuradd
, h
->pbuf
.addr
, played
);
480 if (pcuradd
> h
->pbuf
.addr
+ h
->pbuf
.size
) {
484 return bytes_to_frames(rt
, played
);
487 static snd_pcm_uframes_t
488 snd_harmony_capture_pointer(snd_pcm_substream_t
*ss
)
490 snd_pcm_runtime_t
*rt
= ss
->runtime
;
491 harmony_t
*h
= snd_pcm_substream_chip(ss
);
492 unsigned long rcuradd
;
493 unsigned long caught
;
495 if (!(h
->st
.capturing
) || (h
->csubs
== NULL
))
498 if ((h
->cbuf
.addr
== 0) || (h
->cbuf
.size
== 0))
501 rcuradd
= harmony_read(h
, HARMONY_RCURADD
);
502 caught
= rcuradd
- h
->cbuf
.addr
;
505 printk(KERN_DEBUG PFX
"capture_pointer is 0x%lx-0x%lx = %d bytes\n",
506 rcuradd
, h
->cbuf
.addr
, caught
);
509 if (rcuradd
> h
->cbuf
.addr
+ h
->cbuf
.size
) {
513 return bytes_to_frames(rt
, caught
);
517 snd_harmony_playback_open(snd_pcm_substream_t
*ss
)
519 harmony_t
*h
= snd_pcm_substream_chip(ss
);
520 snd_pcm_runtime_t
*rt
= ss
->runtime
;
524 rt
->hw
= snd_harmony_playback
;
525 snd_pcm_hw_constraint_list(rt
, 0, SNDRV_PCM_HW_PARAM_RATE
,
526 &hw_constraint_rates
);
528 err
= snd_pcm_hw_constraint_integer(rt
, SNDRV_PCM_HW_PARAM_PERIODS
);
536 snd_harmony_capture_open(snd_pcm_substream_t
*ss
)
538 harmony_t
*h
= snd_pcm_substream_chip(ss
);
539 snd_pcm_runtime_t
*rt
= ss
->runtime
;
543 rt
->hw
= snd_harmony_capture
;
544 snd_pcm_hw_constraint_list(rt
, 0, SNDRV_PCM_HW_PARAM_RATE
,
545 &hw_constraint_rates
);
547 err
= snd_pcm_hw_constraint_integer(rt
, SNDRV_PCM_HW_PARAM_PERIODS
);
555 snd_harmony_playback_close(snd_pcm_substream_t
*ss
)
557 harmony_t
*h
= snd_pcm_substream_chip(ss
);
563 snd_harmony_capture_close(snd_pcm_substream_t
*ss
)
565 harmony_t
*h
= snd_pcm_substream_chip(ss
);
571 snd_harmony_hw_params(snd_pcm_substream_t
*ss
,
572 snd_pcm_hw_params_t
*hw
)
575 harmony_t
*h
= snd_pcm_substream_chip(ss
);
577 err
= snd_pcm_lib_malloc_pages(ss
, params_buffer_bytes(hw
));
578 if (err
> 0 && h
->dma
.type
== SNDRV_DMA_TYPE_CONTINUOUS
)
579 ss
->runtime
->dma_addr
= __pa(ss
->runtime
->dma_area
);
585 snd_harmony_hw_free(snd_pcm_substream_t
*ss
)
587 return snd_pcm_lib_free_pages(ss
);
590 static snd_pcm_ops_t snd_harmony_playback_ops
= {
591 .open
= snd_harmony_playback_open
,
592 .close
= snd_harmony_playback_close
,
593 .ioctl
= snd_pcm_lib_ioctl
,
594 .hw_params
= snd_harmony_hw_params
,
595 .hw_free
= snd_harmony_hw_free
,
596 .prepare
= snd_harmony_playback_prepare
,
597 .trigger
= snd_harmony_playback_trigger
,
598 .pointer
= snd_harmony_playback_pointer
,
601 static snd_pcm_ops_t snd_harmony_capture_ops
= {
602 .open
= snd_harmony_capture_open
,
603 .close
= snd_harmony_capture_close
,
604 .ioctl
= snd_pcm_lib_ioctl
,
605 .hw_params
= snd_harmony_hw_params
,
606 .hw_free
= snd_harmony_hw_free
,
607 .prepare
= snd_harmony_capture_prepare
,
608 .trigger
= snd_harmony_capture_trigger
,
609 .pointer
= snd_harmony_capture_pointer
,
613 snd_harmony_pcm_init(harmony_t
*h
)
618 harmony_disable_interrupts(h
);
620 err
= snd_pcm_new(h
->card
, "harmony", 0, 1, 1, &pcm
);
624 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
625 &snd_harmony_playback_ops
);
626 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
627 &snd_harmony_capture_ops
);
629 pcm
->private_data
= h
;
631 strcpy(pcm
->name
, "harmony");
637 /* initialize graveyard buffer */
638 h
->dma
.type
= SNDRV_DMA_TYPE_DEV
;
639 h
->dma
.dev
= &h
->dev
->dev
;
640 err
= snd_dma_alloc_pages(h
->dma
.type
,
642 BUF_SIZE
*GRAVEYARD_BUFS
,
645 printk(KERN_ERR PFX
"cannot allocate graveyard buffer!\n");
649 /* initialize silence buffers */
650 err
= snd_dma_alloc_pages(h
->dma
.type
,
652 BUF_SIZE
*SILENCE_BUFS
,
655 printk(KERN_ERR PFX
"cannot allocate silence buffer!\n");
659 /* pre-allocate space for DMA */
660 err
= snd_pcm_lib_preallocate_pages_for_all(pcm
, h
->dma
.type
,
665 printk(KERN_ERR PFX
"buffer allocation error: %d\n", err
);
669 h
->st
.format
= snd_harmony_set_data_format(h
,
670 SNDRV_PCM_FORMAT_S16_BE
, 1);
676 snd_harmony_set_new_gain(harmony_t
*h
)
678 harmony_wait_for_control(h
);
679 harmony_write(h
, HARMONY_GAINCTL
, h
->st
.gain
);
683 snd_harmony_mixercontrol_info(snd_kcontrol_t
*kc
,
684 snd_ctl_elem_info_t
*uinfo
)
686 int mask
= (kc
->private_value
>> 16) & 0xff;
687 int left_shift
= (kc
->private_value
) & 0xff;
688 int right_shift
= (kc
->private_value
>> 8) & 0xff;
690 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
:
691 SNDRV_CTL_ELEM_TYPE_INTEGER
;
692 uinfo
->count
= left_shift
== right_shift
? 1 : 2;
693 uinfo
->value
.integer
.min
= 0;
694 uinfo
->value
.integer
.max
= mask
;
700 snd_harmony_volume_get(snd_kcontrol_t
*kc
,
701 snd_ctl_elem_value_t
*ucontrol
)
703 harmony_t
*h
= snd_kcontrol_chip(kc
);
704 int shift_left
= (kc
->private_value
) & 0xff;
705 int shift_right
= (kc
->private_value
>> 8) & 0xff;
706 int mask
= (kc
->private_value
>> 16) & 0xff;
707 int invert
= (kc
->private_value
>> 24) & 0xff;
711 spin_lock_irqsave(&h
->mixer_lock
, flags
);
713 left
= (h
->st
.gain
>> shift_left
) & mask
;
714 right
= (h
->st
.gain
>> shift_right
) & mask
;
718 right
= mask
- right
;
720 ucontrol
->value
.integer
.value
[0] = left
;
721 ucontrol
->value
.integer
.value
[1] = right
;
723 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
729 snd_harmony_volume_put(snd_kcontrol_t
*kc
,
730 snd_ctl_elem_value_t
*ucontrol
)
732 harmony_t
*h
= snd_kcontrol_chip(kc
);
733 int shift_left
= (kc
->private_value
) & 0xff;
734 int shift_right
= (kc
->private_value
>> 8) & 0xff;
735 int mask
= (kc
->private_value
>> 16) & 0xff;
736 int invert
= (kc
->private_value
>> 24) & 0xff;
738 int old_gain
= h
->st
.gain
;
741 left
= ucontrol
->value
.integer
.value
[0] & mask
;
742 right
= ucontrol
->value
.integer
.value
[1] & mask
;
745 right
= mask
- right
;
748 spin_lock_irqsave(&h
->mixer_lock
, flags
);
750 h
->st
.gain
&= ~( (mask
<< shift_right
) | (mask
<< shift_left
) );
751 h
->st
.gain
|= ( (left
<< shift_left
) | (right
<< shift_right
) );
752 snd_harmony_set_new_gain(h
);
754 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
756 return (old_gain
- h
->st
.gain
);
759 #define HARMONY_CONTROLS (sizeof(snd_harmony_controls)/ \
760 sizeof(snd_kcontrol_new_t))
762 #define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
763 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
764 .info = snd_harmony_mixercontrol_info, \
765 .get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
766 .private_value = ((left_shift) | ((right_shift) << 8) | \
767 ((mask) << 16) | ((invert) << 24)) }
769 static snd_kcontrol_new_t snd_harmony_controls
[] = {
770 HARMONY_VOLUME("Playback Volume", HARMONY_GAIN_LO_SHIFT
,
771 HARMONY_GAIN_RO_SHIFT
, HARMONY_GAIN_OUT
, 1),
772 HARMONY_VOLUME("Capture Volume", HARMONY_GAIN_LI_SHIFT
,
773 HARMONY_GAIN_RI_SHIFT
, HARMONY_GAIN_IN
, 0),
777 snd_harmony_mixer_reset(harmony_t
*h
)
781 h
->st
.gain
= HARMONY_GAIN_DEFAULT
;
786 snd_harmony_mixer_init(harmony_t
*h
)
788 snd_card_t
*card
= h
->card
;
791 snd_assert(h
!= NULL
, return -EINVAL
);
792 strcpy(card
->mixername
, "Harmony Gain control interface");
794 for (idx
= 0; idx
< HARMONY_CONTROLS
; idx
++) {
795 err
= snd_ctl_add(card
,
796 snd_ctl_new1(&snd_harmony_controls
[idx
], h
));
801 snd_harmony_mixer_reset(h
);
807 snd_harmony_free(harmony_t
*h
)
810 snd_dma_free_pages(&h
->gdma
);
812 snd_dma_free_pages(&h
->sdma
);
820 parisc_set_drvdata(h
->dev
, NULL
);
827 snd_harmony_dev_free(snd_device_t
*dev
)
829 harmony_t
*h
= dev
->device_data
;
830 return snd_harmony_free(h
);
834 snd_harmony_create(snd_card_t
*card
,
835 struct parisc_device
*padev
,
840 static snd_device_ops_t ops
= {
841 .dev_free
= snd_harmony_dev_free
,
846 h
= kmalloc(sizeof(*h
), GFP_KERNEL
);
850 memset(&h
->st
, 0, sizeof(h
->st
));
851 memset(&h
->stats
, 0, sizeof(h
->stats
));
852 memset(&h
->pbuf
, 0, sizeof(h
->pbuf
));
853 memset(&h
->cbuf
, 0, sizeof(h
->cbuf
));
859 h
->iobase
= ioremap_nocache(padev
->hpa
, HARMONY_SIZE
);
860 if (h
->iobase
== NULL
) {
861 printk(KERN_ERR PFX
"unable to remap hpa 0x%lx\n",
867 err
= request_irq(h
->irq
, snd_harmony_interrupt
, 0,
870 printk(KERN_ERR PFX
"could not obtain interrupt %d",
875 spin_lock_init(&h
->mixer_lock
);
876 spin_lock_init(&h
->lock
);
878 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
893 snd_harmony_probe(struct parisc_device
*padev
)
899 static int index
= SNDRV_DEFAULT_IDX1
;
900 static char *id
= SNDRV_DEFAULT_STR1
;
902 h
= parisc_get_drvdata(padev
);
907 card
= snd_card_new(index
, id
, THIS_MODULE
, 0);
911 err
= snd_harmony_create(card
, padev
, &h
);
916 err
= snd_harmony_pcm_init(h
);
921 err
= snd_harmony_mixer_init(h
);
926 strcpy(card
->driver
, "harmony");
927 strcpy(card
->shortname
, "Harmony");
928 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
929 card
->shortname
, h
->hpa
, h
->irq
);
931 err
= snd_card_register(card
);
937 parisc_set_drvdata(padev
, h
);
947 snd_harmony_remove(struct parisc_device
*padev
)
949 harmony_t
*h
= parisc_get_drvdata(padev
);
950 snd_card_free(h
->card
);
954 static struct parisc_driver snd_harmony_driver
= {
956 .id_table
= snd_harmony_devtable
,
957 .probe
= snd_harmony_probe
,
958 .remove
= snd_harmony_remove
,
962 alsa_harmony_init(void)
966 err
= register_parisc_driver(&snd_harmony_driver
);
968 printk(KERN_ERR PFX
"device not found\n");
976 alsa_harmony_fini(void)
980 err
= unregister_parisc_driver(&snd_harmony_driver
);
982 printk(KERN_ERR PFX
"failed to unregister\n");
988 MODULE_LICENSE("GPL");
989 MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
990 MODULE_DESCRIPTION("Harmony sound driver");
992 module_init(alsa_harmony_init
);
993 module_exit(alsa_harmony_fini
);