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
) {
200 if (h
->psubs
&& h
->st
.playing
) {
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
) {
219 if (h
->csubs
&& h
->st
.capturing
) {
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_write(h
, HARMONY_PNXTADD
, h
->sdma
.addr
);
320 harmony_disable_interrupts(h
);
322 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
323 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
324 case SNDRV_PCM_TRIGGER_SUSPEND
:
326 spin_unlock_irqrestore(&h
->lock
, flags
);
330 spin_unlock_irqrestore(&h
->lock
, flags
);
336 snd_harmony_capture_trigger(snd_pcm_substream_t
*ss
, int cmd
)
338 harmony_t
*h
= snd_pcm_substream_chip(ss
);
344 spin_lock_irqsave(&h
->lock
, flags
);
346 case SNDRV_PCM_TRIGGER_START
:
348 harmony_write(h
, HARMONY_PNXTADD
, h
->sdma
.addr
);
349 harmony_write(h
, HARMONY_RNXTADD
, h
->cbuf
.addr
);
351 harmony_enable_interrupts(h
);
353 case SNDRV_PCM_TRIGGER_STOP
:
356 harmony_write(h
, HARMONY_RNXTADD
, h
->gdma
.addr
);
357 harmony_disable_interrupts(h
);
359 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
360 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
361 case SNDRV_PCM_TRIGGER_SUSPEND
:
363 spin_unlock_irqrestore(&h
->lock
, flags
);
367 spin_unlock_irqrestore(&h
->lock
, flags
);
373 snd_harmony_set_data_format(harmony_t
*h
, int fmt
, int force
)
375 int o
= h
->st
.format
;
379 case SNDRV_PCM_FORMAT_S16_BE
:
380 n
= HARMONY_DF_16BIT_LINEAR
;
382 case SNDRV_PCM_FORMAT_A_LAW
:
383 n
= HARMONY_DF_8BIT_ALAW
;
385 case SNDRV_PCM_FORMAT_MU_LAW
:
386 n
= HARMONY_DF_8BIT_ULAW
;
389 n
= HARMONY_DF_16BIT_LINEAR
;
393 if (force
|| o
!= n
) {
394 snd_pcm_format_set_silence(fmt
, h
->sdma
.area
, SILENCE_BUFSZ
/
395 (snd_pcm_format_physical_width(fmt
)
403 snd_harmony_playback_prepare(snd_pcm_substream_t
*ss
)
405 harmony_t
*h
= snd_pcm_substream_chip(ss
);
406 snd_pcm_runtime_t
*rt
= ss
->runtime
;
411 h
->pbuf
.size
= snd_pcm_lib_buffer_bytes(ss
);
412 h
->pbuf
.count
= snd_pcm_lib_period_bytes(ss
);
413 if (h
->pbuf
.buf
>= h
->pbuf
.size
)
417 h
->st
.rate
= snd_harmony_rate_bits(rt
->rate
);
418 h
->st
.format
= snd_harmony_set_data_format(h
, rt
->format
, 0);
420 if (rt
->channels
== 2)
421 h
->st
.stereo
= HARMONY_SS_STEREO
;
423 h
->st
.stereo
= HARMONY_SS_MONO
;
425 harmony_set_control(h
);
427 h
->pbuf
.addr
= rt
->dma_addr
;
433 snd_harmony_capture_prepare(snd_pcm_substream_t
*ss
)
435 harmony_t
*h
= snd_pcm_substream_chip(ss
);
436 snd_pcm_runtime_t
*rt
= ss
->runtime
;
441 h
->cbuf
.size
= snd_pcm_lib_buffer_bytes(ss
);
442 h
->cbuf
.count
= snd_pcm_lib_period_bytes(ss
);
443 if (h
->cbuf
.buf
>= h
->cbuf
.size
)
447 h
->st
.rate
= snd_harmony_rate_bits(rt
->rate
);
448 h
->st
.format
= snd_harmony_set_data_format(h
, rt
->format
, 0);
450 if (rt
->channels
== 2)
451 h
->st
.stereo
= HARMONY_SS_STEREO
;
453 h
->st
.stereo
= HARMONY_SS_MONO
;
455 harmony_set_control(h
);
457 h
->cbuf
.addr
= rt
->dma_addr
;
462 static snd_pcm_uframes_t
463 snd_harmony_playback_pointer(snd_pcm_substream_t
*ss
)
465 snd_pcm_runtime_t
*rt
= ss
->runtime
;
466 harmony_t
*h
= snd_pcm_substream_chip(ss
);
467 unsigned long pcuradd
;
468 unsigned long played
;
470 if (!(h
->st
.playing
) || (h
->psubs
== NULL
))
473 if ((h
->pbuf
.addr
== 0) || (h
->pbuf
.size
== 0))
476 pcuradd
= harmony_read(h
, HARMONY_PCURADD
);
477 played
= pcuradd
- h
->pbuf
.addr
;
480 printk(KERN_DEBUG PFX
"playback_pointer is 0x%lx-0x%lx = %d bytes\n",
481 pcuradd
, h
->pbuf
.addr
, played
);
484 if (pcuradd
> h
->pbuf
.addr
+ h
->pbuf
.size
) {
488 return bytes_to_frames(rt
, played
);
491 static snd_pcm_uframes_t
492 snd_harmony_capture_pointer(snd_pcm_substream_t
*ss
)
494 snd_pcm_runtime_t
*rt
= ss
->runtime
;
495 harmony_t
*h
= snd_pcm_substream_chip(ss
);
496 unsigned long rcuradd
;
497 unsigned long caught
;
499 if (!(h
->st
.capturing
) || (h
->csubs
== NULL
))
502 if ((h
->cbuf
.addr
== 0) || (h
->cbuf
.size
== 0))
505 rcuradd
= harmony_read(h
, HARMONY_RCURADD
);
506 caught
= rcuradd
- h
->cbuf
.addr
;
509 printk(KERN_DEBUG PFX
"capture_pointer is 0x%lx-0x%lx = %d bytes\n",
510 rcuradd
, h
->cbuf
.addr
, caught
);
513 if (rcuradd
> h
->cbuf
.addr
+ h
->cbuf
.size
) {
517 return bytes_to_frames(rt
, caught
);
521 snd_harmony_playback_open(snd_pcm_substream_t
*ss
)
523 harmony_t
*h
= snd_pcm_substream_chip(ss
);
524 snd_pcm_runtime_t
*rt
= ss
->runtime
;
528 rt
->hw
= snd_harmony_playback
;
529 snd_pcm_hw_constraint_list(rt
, 0, SNDRV_PCM_HW_PARAM_RATE
,
530 &hw_constraint_rates
);
532 err
= snd_pcm_hw_constraint_integer(rt
, SNDRV_PCM_HW_PARAM_PERIODS
);
540 snd_harmony_capture_open(snd_pcm_substream_t
*ss
)
542 harmony_t
*h
= snd_pcm_substream_chip(ss
);
543 snd_pcm_runtime_t
*rt
= ss
->runtime
;
547 rt
->hw
= snd_harmony_capture
;
548 snd_pcm_hw_constraint_list(rt
, 0, SNDRV_PCM_HW_PARAM_RATE
,
549 &hw_constraint_rates
);
551 err
= snd_pcm_hw_constraint_integer(rt
, SNDRV_PCM_HW_PARAM_PERIODS
);
559 snd_harmony_playback_close(snd_pcm_substream_t
*ss
)
561 harmony_t
*h
= snd_pcm_substream_chip(ss
);
567 snd_harmony_capture_close(snd_pcm_substream_t
*ss
)
569 harmony_t
*h
= snd_pcm_substream_chip(ss
);
575 snd_harmony_hw_params(snd_pcm_substream_t
*ss
,
576 snd_pcm_hw_params_t
*hw
)
579 harmony_t
*h
= snd_pcm_substream_chip(ss
);
581 err
= snd_pcm_lib_malloc_pages(ss
, params_buffer_bytes(hw
));
582 if (err
> 0 && h
->dma
.type
== SNDRV_DMA_TYPE_CONTINUOUS
)
583 ss
->runtime
->dma_addr
= __pa(ss
->runtime
->dma_area
);
589 snd_harmony_hw_free(snd_pcm_substream_t
*ss
)
591 return snd_pcm_lib_free_pages(ss
);
594 static snd_pcm_ops_t snd_harmony_playback_ops
= {
595 .open
= snd_harmony_playback_open
,
596 .close
= snd_harmony_playback_close
,
597 .ioctl
= snd_pcm_lib_ioctl
,
598 .hw_params
= snd_harmony_hw_params
,
599 .hw_free
= snd_harmony_hw_free
,
600 .prepare
= snd_harmony_playback_prepare
,
601 .trigger
= snd_harmony_playback_trigger
,
602 .pointer
= snd_harmony_playback_pointer
,
605 static snd_pcm_ops_t snd_harmony_capture_ops
= {
606 .open
= snd_harmony_capture_open
,
607 .close
= snd_harmony_capture_close
,
608 .ioctl
= snd_pcm_lib_ioctl
,
609 .hw_params
= snd_harmony_hw_params
,
610 .hw_free
= snd_harmony_hw_free
,
611 .prepare
= snd_harmony_capture_prepare
,
612 .trigger
= snd_harmony_capture_trigger
,
613 .pointer
= snd_harmony_capture_pointer
,
617 snd_harmony_pcm_init(harmony_t
*h
)
622 harmony_disable_interrupts(h
);
624 err
= snd_pcm_new(h
->card
, "harmony", 0, 1, 1, &pcm
);
628 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
629 &snd_harmony_playback_ops
);
630 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
631 &snd_harmony_capture_ops
);
633 pcm
->private_data
= h
;
635 strcpy(pcm
->name
, "harmony");
641 /* initialize graveyard buffer */
642 h
->dma
.type
= SNDRV_DMA_TYPE_DEV
;
643 h
->dma
.dev
= &h
->dev
->dev
;
644 err
= snd_dma_alloc_pages(h
->dma
.type
,
646 BUF_SIZE
*GRAVEYARD_BUFS
,
649 printk(KERN_ERR PFX
"cannot allocate graveyard buffer!\n");
653 /* initialize silence buffers */
654 err
= snd_dma_alloc_pages(h
->dma
.type
,
656 BUF_SIZE
*SILENCE_BUFS
,
659 printk(KERN_ERR PFX
"cannot allocate silence buffer!\n");
663 /* pre-allocate space for DMA */
664 err
= snd_pcm_lib_preallocate_pages_for_all(pcm
, h
->dma
.type
,
669 printk(KERN_ERR PFX
"buffer allocation error: %d\n", err
);
673 h
->st
.format
= snd_harmony_set_data_format(h
,
674 SNDRV_PCM_FORMAT_S16_BE
, 1);
680 snd_harmony_set_new_gain(harmony_t
*h
)
682 harmony_wait_for_control(h
);
683 harmony_write(h
, HARMONY_GAINCTL
, h
->st
.gain
);
687 snd_harmony_mixercontrol_info(snd_kcontrol_t
*kc
,
688 snd_ctl_elem_info_t
*uinfo
)
690 int mask
= (kc
->private_value
>> 16) & 0xff;
691 int left_shift
= (kc
->private_value
) & 0xff;
692 int right_shift
= (kc
->private_value
>> 8) & 0xff;
694 uinfo
->type
= mask
== 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN
:
695 SNDRV_CTL_ELEM_TYPE_INTEGER
;
696 uinfo
->count
= left_shift
== right_shift
? 1 : 2;
697 uinfo
->value
.integer
.min
= 0;
698 uinfo
->value
.integer
.max
= mask
;
704 snd_harmony_volume_get(snd_kcontrol_t
*kc
,
705 snd_ctl_elem_value_t
*ucontrol
)
707 harmony_t
*h
= snd_kcontrol_chip(kc
);
708 int shift_left
= (kc
->private_value
) & 0xff;
709 int shift_right
= (kc
->private_value
>> 8) & 0xff;
710 int mask
= (kc
->private_value
>> 16) & 0xff;
711 int invert
= (kc
->private_value
>> 24) & 0xff;
715 spin_lock_irqsave(&h
->mixer_lock
, flags
);
717 left
= (h
->st
.gain
>> shift_left
) & mask
;
718 right
= (h
->st
.gain
>> shift_right
) & mask
;
721 right
= mask
- right
;
724 ucontrol
->value
.integer
.value
[0] = left
;
725 if (shift_left
!= shift_right
)
726 ucontrol
->value
.integer
.value
[1] = right
;
728 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
734 snd_harmony_volume_put(snd_kcontrol_t
*kc
,
735 snd_ctl_elem_value_t
*ucontrol
)
737 harmony_t
*h
= snd_kcontrol_chip(kc
);
738 int shift_left
= (kc
->private_value
) & 0xff;
739 int shift_right
= (kc
->private_value
>> 8) & 0xff;
740 int mask
= (kc
->private_value
>> 16) & 0xff;
741 int invert
= (kc
->private_value
>> 24) & 0xff;
743 int old_gain
= h
->st
.gain
;
746 spin_lock_irqsave(&h
->mixer_lock
, flags
);
748 left
= ucontrol
->value
.integer
.value
[0] & mask
;
751 h
->st
.gain
&= ~( (mask
<< shift_left
) );
752 h
->st
.gain
|= (left
<< shift_left
);
754 if (shift_left
!= shift_right
) {
755 right
= ucontrol
->value
.integer
.value
[1] & mask
;
757 right
= mask
- right
;
758 h
->st
.gain
&= ~( (mask
<< shift_right
) );
759 h
->st
.gain
|= (right
<< shift_right
);
762 snd_harmony_set_new_gain(h
);
764 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
766 return h
->st
.gain
!= old_gain
;
770 snd_harmony_captureroute_info(snd_kcontrol_t
*kc
,
771 snd_ctl_elem_info_t
*uinfo
)
773 static char *texts
[2] = { "Line", "Mic" };
774 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
776 uinfo
->value
.enumerated
.items
= 2;
777 if (uinfo
->value
.enumerated
.item
> 1)
778 uinfo
->value
.enumerated
.item
= 1;
779 strcpy(uinfo
->value
.enumerated
.name
,
780 texts
[uinfo
->value
.enumerated
.item
]);
785 snd_harmony_captureroute_get(snd_kcontrol_t
*kc
,
786 snd_ctl_elem_value_t
*ucontrol
)
788 harmony_t
*h
= snd_kcontrol_chip(kc
);
792 spin_lock_irqsave(&h
->mixer_lock
, flags
);
794 value
= (h
->st
.gain
>> HARMONY_GAIN_IS_SHIFT
) & 1;
795 ucontrol
->value
.enumerated
.item
[0] = value
;
797 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
803 snd_harmony_captureroute_put(snd_kcontrol_t
*kc
,
804 snd_ctl_elem_value_t
*ucontrol
)
806 harmony_t
*h
= snd_kcontrol_chip(kc
);
808 int old_gain
= h
->st
.gain
;
811 spin_lock_irqsave(&h
->mixer_lock
, flags
);
813 value
= ucontrol
->value
.enumerated
.item
[0] & 1;
814 h
->st
.gain
&= ~HARMONY_GAIN_IS_MASK
;
815 h
->st
.gain
|= value
<< HARMONY_GAIN_IS_SHIFT
;
817 snd_harmony_set_new_gain(h
);
819 spin_unlock_irqrestore(&h
->mixer_lock
, flags
);
821 return h
->st
.gain
!= old_gain
;
824 #define HARMONY_CONTROLS (sizeof(snd_harmony_controls)/ \
825 sizeof(snd_kcontrol_new_t))
827 #define HARMONY_VOLUME(xname, left_shift, right_shift, mask, invert) \
828 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
829 .info = snd_harmony_mixercontrol_info, \
830 .get = snd_harmony_volume_get, .put = snd_harmony_volume_put, \
831 .private_value = ((left_shift) | ((right_shift) << 8) | \
832 ((mask) << 16) | ((invert) << 24)) }
834 static snd_kcontrol_new_t snd_harmony_controls
[] = {
835 HARMONY_VOLUME("Master Playback Volume", HARMONY_GAIN_LO_SHIFT
,
836 HARMONY_GAIN_RO_SHIFT
, HARMONY_GAIN_OUT
, 1),
837 HARMONY_VOLUME("Capture Volume", HARMONY_GAIN_LI_SHIFT
,
838 HARMONY_GAIN_RI_SHIFT
, HARMONY_GAIN_IN
, 0),
839 HARMONY_VOLUME("Monitor Volume", HARMONY_GAIN_MA_SHIFT
,
840 HARMONY_GAIN_MA_SHIFT
, HARMONY_GAIN_MA
, 1),
842 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
843 .name
= "Input Route",
844 .info
= snd_harmony_captureroute_info
,
845 .get
= snd_harmony_captureroute_get
,
846 .put
= snd_harmony_captureroute_put
848 HARMONY_VOLUME("Internal Speaker Switch", HARMONY_GAIN_SE_SHIFT
,
849 HARMONY_GAIN_SE_SHIFT
, 1, 0),
850 HARMONY_VOLUME("Line-Out Switch", HARMONY_GAIN_LE_SHIFT
,
851 HARMONY_GAIN_LE_SHIFT
, 1, 0),
852 HARMONY_VOLUME("Headphones Switch", HARMONY_GAIN_HE_SHIFT
,
853 HARMONY_GAIN_HE_SHIFT
, 1, 0),
857 snd_harmony_mixer_reset(harmony_t
*h
)
861 h
->st
.gain
= HARMONY_GAIN_DEFAULT
;
866 snd_harmony_mixer_init(harmony_t
*h
)
868 snd_card_t
*card
= h
->card
;
871 snd_assert(h
!= NULL
, return -EINVAL
);
872 strcpy(card
->mixername
, "Harmony Gain control interface");
874 for (idx
= 0; idx
< HARMONY_CONTROLS
; idx
++) {
875 err
= snd_ctl_add(card
,
876 snd_ctl_new1(&snd_harmony_controls
[idx
], h
));
881 snd_harmony_mixer_reset(h
);
887 snd_harmony_free(harmony_t
*h
)
890 snd_dma_free_pages(&h
->gdma
);
892 snd_dma_free_pages(&h
->sdma
);
900 parisc_set_drvdata(h
->dev
, NULL
);
907 snd_harmony_dev_free(snd_device_t
*dev
)
909 harmony_t
*h
= dev
->device_data
;
910 return snd_harmony_free(h
);
914 snd_harmony_create(snd_card_t
*card
,
915 struct parisc_device
*padev
,
920 static snd_device_ops_t ops
= {
921 .dev_free
= snd_harmony_dev_free
,
926 h
= kmalloc(sizeof(*h
), GFP_KERNEL
);
930 memset(&h
->st
, 0, sizeof(h
->st
));
931 memset(&h
->stats
, 0, sizeof(h
->stats
));
932 memset(&h
->pbuf
, 0, sizeof(h
->pbuf
));
933 memset(&h
->cbuf
, 0, sizeof(h
->cbuf
));
935 h
->hpa
= padev
->hpa
.start
;
939 h
->iobase
= ioremap_nocache(padev
->hpa
.start
, HARMONY_SIZE
);
940 if (h
->iobase
== NULL
) {
941 printk(KERN_ERR PFX
"unable to remap hpa 0x%lx\n",
947 err
= request_irq(h
->irq
, snd_harmony_interrupt
, 0,
950 printk(KERN_ERR PFX
"could not obtain interrupt %d",
955 spin_lock_init(&h
->mixer_lock
);
956 spin_lock_init(&h
->lock
);
958 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
963 snd_card_set_dev(card
, &padev
->dev
);
975 snd_harmony_probe(struct parisc_device
*padev
)
981 static int index
= SNDRV_DEFAULT_IDX1
;
982 static char *id
= SNDRV_DEFAULT_STR1
;
984 h
= parisc_get_drvdata(padev
);
989 card
= snd_card_new(index
, id
, THIS_MODULE
, 0);
993 err
= snd_harmony_create(card
, padev
, &h
);
998 err
= snd_harmony_pcm_init(h
);
1003 err
= snd_harmony_mixer_init(h
);
1008 strcpy(card
->driver
, "harmony");
1009 strcpy(card
->shortname
, "Harmony");
1010 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
1011 card
->shortname
, h
->hpa
, h
->irq
);
1013 err
= snd_card_register(card
);
1019 parisc_set_drvdata(padev
, h
);
1024 snd_card_free(card
);
1028 static int __devexit
1029 snd_harmony_remove(struct parisc_device
*padev
)
1031 harmony_t
*h
= parisc_get_drvdata(padev
);
1032 snd_card_free(h
->card
);
1036 static struct parisc_driver snd_harmony_driver
= {
1038 .id_table
= snd_harmony_devtable
,
1039 .probe
= snd_harmony_probe
,
1040 .remove
= snd_harmony_remove
,
1044 alsa_harmony_init(void)
1048 err
= register_parisc_driver(&snd_harmony_driver
);
1050 printk(KERN_ERR PFX
"device not found\n");
1058 alsa_harmony_fini(void)
1062 err
= unregister_parisc_driver(&snd_harmony_driver
);
1064 printk(KERN_ERR PFX
"failed to unregister\n");
1070 MODULE_LICENSE("GPL");
1071 MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>");
1072 MODULE_DESCRIPTION("Harmony sound driver");
1074 module_init(alsa_harmony_init
);
1075 module_exit(alsa_harmony_fini
);