3 * Copyright (c) by AudioScience Inc <alsa@audioscience.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * The following is not a condition of use, merely a request:
20 * If you modify this program, particularly if you fix errors, AudioScience Inc
21 * would appreciate it if you grant us the right to use those modifications
22 * for any purpose including commercial applications.
25 #include "hpi_internal.h"
26 #include "hpimsginit.h"
29 #include <linux/pci.h>
30 #include <linux/init.h>
31 #include <linux/jiffies.h>
32 #include <linux/slab.h>
33 #include <linux/time.h>
34 #include <linux/wait.h>
35 #include <sound/core.h>
36 #include <sound/control.h>
37 #include <sound/pcm.h>
38 #include <sound/pcm_params.h>
39 #include <sound/info.h>
40 #include <sound/initval.h>
41 #include <sound/tlv.h>
42 #include <sound/hwdep.h>
45 MODULE_LICENSE("GPL");
46 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
47 MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx");
49 #if defined CONFIG_SND_DEBUG
50 /* copied from pcm_lib.c, hope later patch will make that version public
51 and this copy can be removed */
53 snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
55 snprintf(buf, size, "pcmC%dD%d%c:%d",
56 substream->pcm->card->number,
57 substream->pcm->device,
58 substream->stream ? 'c' : 'p',
63 snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
69 #if defined CONFIG_SND_DEBUG_VERBOSE
71 * snd_printddd - very verbose debug printk
72 * @format: format string
74 * Works like snd_printk() for debugging purposes.
75 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
76 * Must set snd module debug parameter to 3 to enable at runtime.
78 #define snd_printddd(format, args...) \
79 __snd_printk(3, __FILE__, __LINE__, format, ##args)
81 #define snd_printddd(format, args...) do { } while (0)
84 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
85 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
86 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
87 static int enable_hpi_hwdep = 1;
89 module_param_array(index, int, NULL, S_IRUGO);
90 MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
92 module_param_array(id, charp, NULL, S_IRUGO);
93 MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
95 module_param_array(enable, bool, NULL, S_IRUGO);
96 MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
98 module_param(enable_hpi_hwdep, bool, S_IRUGO|S_IWUSR);
99 MODULE_PARM_DESC(enable_hpi_hwdep,
100 "ALSA enable HPI hwdep for AudioScience soundcard ");
102 /* identify driver */
103 #ifdef KERNEL_ALSA_BUILD
104 static char *build_info = "Built using headers from kernel source";
105 module_param(build_info, charp, S_IRUGO);
106 MODULE_PARM_DESC(build_info, "built using headers from kernel source");
108 static char *build_info = "Built within ALSA source";
109 module_param(build_info, charp, S_IRUGO);
110 MODULE_PARM_DESC(build_info, "built within ALSA source");
113 /* set to 1 to dump every control from adapter to log */
114 static const int mixer_dump;
116 #define DEFAULT_SAMPLERATE 44100
117 static int adapter_fs = DEFAULT_SAMPLERATE;
120 #define PERIODS_MIN 2
121 #define PERIOD_BYTES_MIN 2048
122 #define BUFFER_BYTES_MAX (512 * 1024)
124 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
135 struct clk_source s[MAX_CLOCKSOURCES];
139 struct snd_card_asihpi {
140 struct snd_card *card;
153 u16 support_grouping;
155 u16 update_interval_frames;
160 /* Per stream data */
161 struct snd_card_asihpi_pcm {
162 struct timer_list timer;
163 unsigned int respawn_timer;
164 unsigned int hpi_buffer_attached;
165 unsigned int buffer_bytes;
166 unsigned int period_bytes;
167 unsigned int bytes_per_sec;
168 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
169 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
170 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
171 unsigned int drained_count;
172 struct snd_pcm_substream *substream;
174 struct hpi_format format;
177 /* universal stream verbs work with out or in stream handles */
179 /* Functions to allow driver to give a buffer to HPI for busmastering */
181 static u16 hpi_stream_host_buffer_attach(
182 u32 h_stream, /* handle to outstream. */
183 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
187 struct hpi_message hm;
188 struct hpi_response hr;
189 unsigned int obj = hpi_handle_object(h_stream);
192 return HPI_ERROR_INVALID_OBJ;
193 hpi_init_message_response(&hm, &hr, obj,
194 obj == HPI_OBJ_OSTREAM ?
195 HPI_OSTREAM_HOSTBUFFER_ALLOC :
196 HPI_ISTREAM_HOSTBUFFER_ALLOC);
198 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
201 hm.u.d.u.buffer.buffer_size = size_in_bytes;
202 hm.u.d.u.buffer.pci_address = pci_address;
203 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
204 hpi_send_recv(&hm, &hr);
208 static u16 hpi_stream_host_buffer_detach(u32 h_stream)
210 struct hpi_message hm;
211 struct hpi_response hr;
212 unsigned int obj = hpi_handle_object(h_stream);
215 return HPI_ERROR_INVALID_OBJ;
217 hpi_init_message_response(&hm, &hr, obj,
218 obj == HPI_OBJ_OSTREAM ?
219 HPI_OSTREAM_HOSTBUFFER_FREE :
220 HPI_ISTREAM_HOSTBUFFER_FREE);
222 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
224 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
225 hpi_send_recv(&hm, &hr);
229 static inline u16 hpi_stream_start(u32 h_stream)
231 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
232 return hpi_outstream_start(h_stream);
234 return hpi_instream_start(h_stream);
237 static inline u16 hpi_stream_stop(u32 h_stream)
239 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
240 return hpi_outstream_stop(h_stream);
242 return hpi_instream_stop(h_stream);
245 static inline u16 hpi_stream_get_info_ex(
249 u32 *pdata_in_buffer,
255 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
256 e = hpi_outstream_get_info_ex(h_stream, pw_state,
257 pbuffer_size, pdata_in_buffer,
258 psample_count, pauxiliary_data);
260 e = hpi_instream_get_info_ex(h_stream, pw_state,
261 pbuffer_size, pdata_in_buffer,
262 psample_count, pauxiliary_data);
266 static inline u16 hpi_stream_group_add(
270 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
271 return hpi_outstream_group_add(h_master, h_stream);
273 return hpi_instream_group_add(h_master, h_stream);
276 static inline u16 hpi_stream_group_reset(u32 h_stream)
278 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
279 return hpi_outstream_group_reset(h_stream);
281 return hpi_instream_group_reset(h_stream);
284 static inline u16 hpi_stream_group_get_map(
285 u32 h_stream, u32 *mo, u32 *mi)
287 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
288 return hpi_outstream_group_get_map(h_stream, mo, mi);
290 return hpi_instream_group_get_map(h_stream, mo, mi);
293 static u16 handle_error(u16 err, int line, char *filename)
297 "in file %s, line %d: HPI error %d\n",
298 filename, line, err);
302 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
304 /***************************** GENERAL PCM ****************/
306 static void print_hwparams(struct snd_pcm_substream *substream,
307 struct snd_pcm_hw_params *p)
310 snd_pcm_debug_name(substream, name, sizeof(name));
311 snd_printd("%s HWPARAMS\n", name);
312 snd_printd(" samplerate %d Hz\n", params_rate(p));
313 snd_printd(" channels %d\n", params_channels(p));
314 snd_printd(" format %d\n", params_format(p));
315 snd_printd(" subformat %d\n", params_subformat(p));
316 snd_printd(" buffer %d B\n", params_buffer_bytes(p));
317 snd_printd(" period %d B\n", params_period_bytes(p));
318 snd_printd(" access %d\n", params_access(p));
319 snd_printd(" period_size %d\n", params_period_size(p));
320 snd_printd(" periods %d\n", params_periods(p));
321 snd_printd(" buffer_size %d\n", params_buffer_size(p));
322 snd_printd(" %d B/s\n", params_rate(p) *
324 snd_pcm_format_width(params_format(p)) / 8);
328 static snd_pcm_format_t hpi_to_alsa_formats[] = {
330 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
331 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
332 -1, /* HPI_FORMAT_MPEG_L1 3 */
333 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
334 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
335 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
336 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
337 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
338 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
339 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
340 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
341 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
342 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
343 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
345 /* ALSA can't handle 3 byte sample size together with power-of-2
346 * constraint on buffer_bytes, so disable this format
350 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
355 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
360 for (format = HPI_FORMAT_PCM8_UNSIGNED;
361 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
362 if (hpi_to_alsa_formats[format] == alsa_format) {
363 *hpi_format = format;
368 snd_printd(KERN_WARNING "failed match for alsa format %d\n",
374 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
375 struct snd_pcm_hardware *pcmhw)
381 unsigned int rate_min = 200000;
382 unsigned int rate_max = 0;
383 unsigned int rates = 0;
385 if (asihpi->support_mrx) {
386 rates |= SNDRV_PCM_RATE_CONTINUOUS;
387 rates |= SNDRV_PCM_RATE_8000_96000;
391 /* on cards without SRC,
392 valid rates are determined by sampleclock */
393 err = hpi_mixer_get_control(asihpi->h_mixer,
394 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
395 HPI_CONTROL_SAMPLECLOCK, &h_control);
398 "No local sampleclock, err %d\n", err);
401 for (idx = -1; idx < 100; idx++) {
403 if (hpi_sample_clock_get_sample_rate(h_control,
406 } else if (hpi_sample_clock_query_local_rate(h_control,
407 idx, &sample_rate)) {
411 rate_min = min(rate_min, sample_rate);
412 rate_max = max(rate_max, sample_rate);
414 switch (sample_rate) {
416 rates |= SNDRV_PCM_RATE_5512;
419 rates |= SNDRV_PCM_RATE_8000;
422 rates |= SNDRV_PCM_RATE_11025;
425 rates |= SNDRV_PCM_RATE_16000;
428 rates |= SNDRV_PCM_RATE_22050;
431 rates |= SNDRV_PCM_RATE_32000;
434 rates |= SNDRV_PCM_RATE_44100;
437 rates |= SNDRV_PCM_RATE_48000;
440 rates |= SNDRV_PCM_RATE_64000;
443 rates |= SNDRV_PCM_RATE_88200;
446 rates |= SNDRV_PCM_RATE_96000;
449 rates |= SNDRV_PCM_RATE_176400;
452 rates |= SNDRV_PCM_RATE_192000;
454 default: /* some other rate */
455 rates |= SNDRV_PCM_RATE_KNOT;
460 pcmhw->rates = rates;
461 pcmhw->rate_min = rate_min;
462 pcmhw->rate_max = rate_max;
465 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
466 struct snd_pcm_hw_params *params)
468 struct snd_pcm_runtime *runtime = substream->runtime;
469 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
470 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
474 unsigned int bytes_per_sec;
476 print_hwparams(substream, params);
477 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
480 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
484 hpi_handle_error(hpi_format_create(&dpcm->format,
485 params_channels(params),
486 format, params_rate(params), 0, 0));
488 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
489 if (hpi_instream_reset(dpcm->h_stream) != 0)
492 if (hpi_instream_set_format(
493 dpcm->h_stream, &dpcm->format) != 0)
497 dpcm->hpi_buffer_attached = 0;
499 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
500 params_buffer_bytes(params), runtime->dma_addr);
503 "stream_host_buffer_attach succeeded %u %lu\n",
504 params_buffer_bytes(params),
505 (unsigned long)runtime->dma_addr);
507 snd_printd("stream_host_buffer_attach error %d\n",
512 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
513 &dpcm->hpi_buffer_attached,
516 snd_printdd("stream_host_buffer_attach status 0x%x\n",
517 dpcm->hpi_buffer_attached);
519 bytes_per_sec = params_rate(params) * params_channels(params);
520 width = snd_pcm_format_width(params_format(params));
521 bytes_per_sec *= width;
523 if (width < 0 || bytes_per_sec == 0)
526 dpcm->bytes_per_sec = bytes_per_sec;
527 dpcm->buffer_bytes = params_buffer_bytes(params);
528 dpcm->period_bytes = params_period_bytes(params);
534 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
536 struct snd_pcm_runtime *runtime = substream->runtime;
537 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
538 if (dpcm->hpi_buffer_attached)
539 hpi_stream_host_buffer_detach(dpcm->h_stream);
541 snd_pcm_lib_free_pages(substream);
545 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
547 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
551 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
554 struct snd_pcm_runtime *runtime = substream->runtime;
555 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
559 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */
560 expiry = max(expiry, 1); /* don't let it be zero! */
561 dpcm->timer.expires = jiffies + expiry;
562 dpcm->respawn_timer = 1;
563 add_timer(&dpcm->timer);
566 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
568 struct snd_pcm_runtime *runtime = substream->runtime;
569 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
571 dpcm->respawn_timer = 0;
572 del_timer(&dpcm->timer);
575 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
578 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
579 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
580 struct snd_pcm_substream *s;
584 snd_pcm_debug_name(substream, name, sizeof(name));
585 snd_printdd("%s trigger\n", name);
588 case SNDRV_PCM_TRIGGER_START:
589 snd_pcm_group_for_each_entry(s, substream) {
590 struct snd_pcm_runtime *runtime = s->runtime;
591 struct snd_card_asihpi_pcm *ds = runtime->private_data;
593 if (snd_pcm_substream_chip(s) != card)
596 /* don't link Cap and Play */
597 if (substream->stream != s->stream)
600 ds->drained_count = 0;
601 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
602 /* How do I know how much valid data is present
603 * in buffer? Must be at least one period!
604 * Guessing 2 periods, but if
605 * buffer is bigger it may contain even more
608 unsigned int preload = ds->period_bytes * 1;
609 snd_printddd("%d preload x%x\n", s->number, preload);
610 hpi_handle_error(hpi_outstream_write_buf(
612 &runtime->dma_area[0],
615 ds->pcm_buf_host_rw_ofs = preload;
618 if (card->support_grouping) {
619 snd_printdd("%d group\n", s->number);
620 e = hpi_stream_group_add(
624 snd_pcm_trigger_done(s, substream);
632 snd_printdd("start\n");
633 /* start the master stream */
634 snd_card_asihpi_pcm_timer_start(substream);
635 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
637 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
640 case SNDRV_PCM_TRIGGER_STOP:
641 snd_card_asihpi_pcm_timer_stop(substream);
642 snd_pcm_group_for_each_entry(s, substream) {
643 if (snd_pcm_substream_chip(s) != card)
645 /* don't link Cap and Play */
646 if (substream->stream != s->stream)
649 /*? workaround linked streams don't
650 transition to SETUP 20070706*/
651 s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
653 if (card->support_grouping) {
654 snd_printdd("%d group\n", s->number);
655 snd_pcm_trigger_done(s, substream);
659 snd_printdd("stop\n");
661 /* _prepare and _hwparams reset the stream */
662 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
663 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
665 hpi_outstream_reset(dpcm->h_stream));
667 if (card->support_grouping)
668 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
671 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
672 snd_printdd("pause release\n");
673 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
674 snd_card_asihpi_pcm_timer_start(substream);
676 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
677 snd_printdd("pause\n");
678 snd_card_asihpi_pcm_timer_stop(substream);
679 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
682 snd_printd(KERN_ERR "\tINVALID\n");
690 Without linking degenerates to getting single stream pos etc
691 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
694 pcm_buf_dma_ofs=get_buf_pos(s);
695 for_each_linked_stream(s) {
696 pcm_buf_dma_ofs=get_buf_pos(s);
697 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
698 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
700 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
701 for_each_linked_stream(s) {
702 s->pcm_buf_dma_ofs = min_buf_pos;
703 if (new_data > period_bytes) {
705 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
712 snd_pcm_period_elapsed(s);
717 /** Minimum of 2 modulo values. Works correctly when the difference between
718 * the values is less than half the modulus
720 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
721 unsigned long int modulus)
724 if (((a-b) % modulus) < (modulus/2))
732 /** Timer function, equivalent to interrupt service routine for cards
734 static void snd_card_asihpi_timer_function(unsigned long data)
736 struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data;
737 struct snd_pcm_substream *substream = dpcm->substream;
738 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
739 struct snd_pcm_runtime *runtime;
740 struct snd_pcm_substream *s;
741 unsigned int newdata = 0;
742 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
743 unsigned int remdata, xfercount, next_jiffies;
747 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
750 snd_pcm_debug_name(substream, name, sizeof(name));
752 snd_printdd("%s snd_card_asihpi_timer_function\n", name);
754 /* find minimum newdata and buffer pos in group */
755 snd_pcm_group_for_each_entry(s, substream) {
756 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
757 runtime = s->runtime;
759 if (snd_pcm_substream_chip(s) != card)
762 /* don't link Cap and Play */
763 if (substream->stream != s->stream)
766 hpi_handle_error(hpi_stream_get_info_ex(
767 ds->h_stream, &state,
768 &buffer_size, &bytes_avail,
769 &samples_played, &on_card_bytes));
771 /* number of bytes in on-card buffer */
772 runtime->delay = on_card_bytes;
775 on_card_bytes = bytes_avail;
777 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
778 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
779 if (state == HPI_STATE_STOPPED) {
780 if ((bytes_avail == 0) &&
781 (on_card_bytes < ds->pcm_buf_host_rw_ofs)) {
782 hpi_handle_error(hpi_stream_start(ds->h_stream));
783 snd_printdd("P%d start\n", s->number);
784 ds->drained_count = 0;
786 } else if (state == HPI_STATE_DRAINED) {
787 snd_printd(KERN_WARNING "P%d drained\n",
790 if (ds->drained_count > 2) {
791 snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
795 ds->drained_count = 0;
798 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
801 /* can't statically init min when wrap is involved */
802 min_buf_pos = pcm_buf_dma_ofs;
803 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
807 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
809 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
813 snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n",
814 (unsigned long)frames_to_bytes(runtime,
815 runtime->status->hw_ptr),
816 (unsigned long)frames_to_bytes(runtime,
817 runtime->control->appl_ptr));
819 snd_printdd("%d S=%d, "
820 "rw=0x%04X, dma=0x%04X, left=0x%04X, "
821 "aux=0x%04X space=0x%04X\n",
823 ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs,
825 (int)on_card_bytes, buffer_size-bytes_avail);
828 pcm_buf_dma_ofs = min_buf_pos;
830 remdata = newdata % dpcm->period_bytes;
831 xfercount = newdata - remdata; /* a multiple of period_bytes */
832 /* come back when on_card_bytes has decreased enough to allow
833 write to happen, or when data has been consumed to make another
836 if (xfercount && (on_card_bytes > dpcm->period_bytes))
837 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
839 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
841 next_jiffies = max(next_jiffies, 1U);
842 dpcm->timer.expires = jiffies + next_jiffies;
843 snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n",
844 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
846 snd_pcm_group_for_each_entry(s, substream) {
847 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
849 /* don't link Cap and Play */
850 if (substream->stream != s->stream)
853 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
856 /* Limit use of on card fifo for playback */
857 ((on_card_bytes <= ds->period_bytes) ||
858 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
862 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
863 unsigned int xfer1, xfer2;
864 char *pd = &s->runtime->dma_area[buf_ofs];
866 if (card->can_dma) { /* buffer wrap is handled at lower level */
870 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
871 xfer2 = xfercount - xfer1;
874 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
875 snd_printddd("P%d write1 0x%04X 0x%04X\n",
876 s->number, xfer1, buf_ofs);
878 hpi_outstream_write_buf(
879 ds->h_stream, pd, xfer1,
883 pd = s->runtime->dma_area;
885 snd_printddd("P%d write2 0x%04X 0x%04X\n",
887 xfercount - xfer1, buf_ofs);
889 hpi_outstream_write_buf(
895 snd_printddd("C%d read1 0x%04x\n",
898 hpi_instream_read_buf(
902 pd = s->runtime->dma_area;
903 snd_printddd("C%d read2 0x%04x\n",
906 hpi_instream_read_buf(
911 ds->pcm_buf_host_rw_ofs = ds->pcm_buf_host_rw_ofs + xfercount;
912 ds->pcm_buf_elapsed_dma_ofs = pcm_buf_dma_ofs;
913 snd_pcm_period_elapsed(s);
917 if (dpcm->respawn_timer)
918 add_timer(&dpcm->timer);
921 /***************************** PLAYBACK OPS ****************/
922 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
923 unsigned int cmd, void *arg)
925 snd_printddd(KERN_INFO "P%d ioctl %d\n", substream->number, cmd);
926 return snd_pcm_lib_ioctl(substream, cmd, arg);
929 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
932 struct snd_pcm_runtime *runtime = substream->runtime;
933 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
935 snd_printdd("P%d prepare\n", substream->number);
937 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
938 dpcm->pcm_buf_host_rw_ofs = 0;
939 dpcm->pcm_buf_dma_ofs = 0;
940 dpcm->pcm_buf_elapsed_dma_ofs = 0;
944 static snd_pcm_uframes_t
945 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
947 struct snd_pcm_runtime *runtime = substream->runtime;
948 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
949 snd_pcm_uframes_t ptr;
951 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
952 snd_printddd("P%d pointer = 0x%04lx\n", substream->number, (unsigned long)ptr);
956 static void snd_card_asihpi_playback_format(struct snd_card_asihpi *asihpi,
958 struct snd_pcm_hardware *pcmhw)
960 struct hpi_format hpi_format;
964 u32 sample_rate = 48000;
966 /* on cards without SRC, must query at valid rate,
967 * maybe set by external sync
969 err = hpi_mixer_get_control(asihpi->h_mixer,
970 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
971 HPI_CONTROL_SAMPLECLOCK, &h_control);
974 err = hpi_sample_clock_get_sample_rate(h_control,
977 for (format = HPI_FORMAT_PCM8_UNSIGNED;
978 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
979 err = hpi_format_create(&hpi_format,
980 2, format, sample_rate, 128000, 0);
982 err = hpi_outstream_query_format(h_stream,
984 if (!err && (hpi_to_alsa_formats[format] != -1))
986 (1ULL << hpi_to_alsa_formats[format]);
990 static struct snd_pcm_hardware snd_card_asihpi_playback = {
993 .buffer_bytes_max = BUFFER_BYTES_MAX,
994 .period_bytes_min = PERIOD_BYTES_MIN,
995 .period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN,
996 .periods_min = PERIODS_MIN,
997 .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
1001 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1003 struct snd_pcm_runtime *runtime = substream->runtime;
1004 struct snd_card_asihpi_pcm *dpcm;
1005 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1008 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1013 hpi_outstream_open(card->adapter_index,
1014 substream->number, &dpcm->h_stream);
1015 hpi_handle_error(err);
1018 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1023 /*? also check ASI5000 samplerate source
1024 If external, only support external rate.
1025 If internal and other stream playing, can't switch
1028 init_timer(&dpcm->timer);
1029 dpcm->timer.data = (unsigned long) dpcm;
1030 dpcm->timer.function = snd_card_asihpi_timer_function;
1031 dpcm->substream = substream;
1032 runtime->private_data = dpcm;
1033 runtime->private_free = snd_card_asihpi_runtime_free;
1035 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1036 /*?snd_card_asihpi_playback.period_bytes_min =
1037 card->out_max_chans * 4096; */
1039 snd_card_asihpi_playback_format(card, dpcm->h_stream,
1040 &snd_card_asihpi_playback);
1042 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1044 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1045 SNDRV_PCM_INFO_DOUBLE |
1046 SNDRV_PCM_INFO_BATCH |
1047 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1048 SNDRV_PCM_INFO_PAUSE |
1049 SNDRV_PCM_INFO_MMAP |
1050 SNDRV_PCM_INFO_MMAP_VALID;
1052 if (card->support_grouping)
1053 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1055 /* struct is copied, so can create initializer dynamically */
1056 runtime->hw = snd_card_asihpi_playback;
1059 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1060 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1064 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1065 card->update_interval_frames);
1067 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1068 card->update_interval_frames * 2, UINT_MAX);
1070 snd_pcm_set_sync(substream);
1072 snd_printdd("playback open\n");
1077 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1079 struct snd_pcm_runtime *runtime = substream->runtime;
1080 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1082 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1083 snd_printdd("playback close\n");
1088 static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1089 .open = snd_card_asihpi_playback_open,
1090 .close = snd_card_asihpi_playback_close,
1091 .ioctl = snd_card_asihpi_playback_ioctl,
1092 .hw_params = snd_card_asihpi_pcm_hw_params,
1093 .hw_free = snd_card_asihpi_hw_free,
1094 .prepare = snd_card_asihpi_playback_prepare,
1095 .trigger = snd_card_asihpi_trigger,
1096 .pointer = snd_card_asihpi_playback_pointer,
1099 /***************************** CAPTURE OPS ****************/
1100 static snd_pcm_uframes_t
1101 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1103 struct snd_pcm_runtime *runtime = substream->runtime;
1104 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1106 snd_printddd("capture pointer %d=%d\n",
1107 substream->number, dpcm->pcm_buf_dma_ofs);
1108 /* NOTE Unlike playback can't use actual samples_played
1109 for the capture position, because those samples aren't yet in
1110 the local buffer available for reading.
1112 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1115 static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
1116 unsigned int cmd, void *arg)
1118 return snd_pcm_lib_ioctl(substream, cmd, arg);
1121 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1123 struct snd_pcm_runtime *runtime = substream->runtime;
1124 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1126 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1127 dpcm->pcm_buf_host_rw_ofs = 0;
1128 dpcm->pcm_buf_dma_ofs = 0;
1129 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1131 snd_printdd("Capture Prepare %d\n", substream->number);
1137 static void snd_card_asihpi_capture_format(struct snd_card_asihpi *asihpi,
1139 struct snd_pcm_hardware *pcmhw)
1141 struct hpi_format hpi_format;
1145 u32 sample_rate = 48000;
1147 /* on cards without SRC, must query at valid rate,
1148 maybe set by external sync */
1149 err = hpi_mixer_get_control(asihpi->h_mixer,
1150 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1151 HPI_CONTROL_SAMPLECLOCK, &h_control);
1154 err = hpi_sample_clock_get_sample_rate(h_control,
1157 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1158 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1160 err = hpi_format_create(&hpi_format, 2, format,
1161 sample_rate, 128000, 0);
1163 err = hpi_instream_query_format(h_stream,
1167 (1ULL << hpi_to_alsa_formats[format]);
1172 static struct snd_pcm_hardware snd_card_asihpi_capture = {
1175 .buffer_bytes_max = BUFFER_BYTES_MAX,
1176 .period_bytes_min = PERIOD_BYTES_MIN,
1177 .period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN,
1178 .periods_min = PERIODS_MIN,
1179 .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
1183 static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1185 struct snd_pcm_runtime *runtime = substream->runtime;
1186 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1187 struct snd_card_asihpi_pcm *dpcm;
1190 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1194 snd_printdd("capture open adapter %d stream %d\n",
1195 card->adapter_index, substream->number);
1197 err = hpi_handle_error(
1198 hpi_instream_open(card->adapter_index,
1199 substream->number, &dpcm->h_stream));
1202 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1208 init_timer(&dpcm->timer);
1209 dpcm->timer.data = (unsigned long) dpcm;
1210 dpcm->timer.function = snd_card_asihpi_timer_function;
1211 dpcm->substream = substream;
1212 runtime->private_data = dpcm;
1213 runtime->private_free = snd_card_asihpi_runtime_free;
1215 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1216 snd_card_asihpi_capture_format(card, dpcm->h_stream,
1217 &snd_card_asihpi_capture);
1218 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1219 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1220 SNDRV_PCM_INFO_MMAP |
1221 SNDRV_PCM_INFO_MMAP_VALID;
1223 if (card->support_grouping)
1224 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1226 runtime->hw = snd_card_asihpi_capture;
1229 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1230 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1234 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1235 card->update_interval_frames);
1236 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1237 card->update_interval_frames * 2, UINT_MAX);
1239 snd_pcm_set_sync(substream);
1244 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1246 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1248 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1252 static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1253 .open = snd_card_asihpi_capture_open,
1254 .close = snd_card_asihpi_capture_close,
1255 .ioctl = snd_card_asihpi_capture_ioctl,
1256 .hw_params = snd_card_asihpi_pcm_hw_params,
1257 .hw_free = snd_card_asihpi_hw_free,
1258 .prepare = snd_card_asihpi_capture_prepare,
1259 .trigger = snd_card_asihpi_trigger,
1260 .pointer = snd_card_asihpi_capture_pointer,
1263 static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi,
1264 int device, int substreams)
1266 struct snd_pcm *pcm;
1269 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1270 asihpi->num_outstreams, asihpi->num_instreams,
1274 /* pointer to ops struct is stored, dont change ops afterwards! */
1275 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1276 &snd_card_asihpi_playback_mmap_ops);
1277 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1278 &snd_card_asihpi_capture_mmap_ops);
1280 pcm->private_data = asihpi;
1281 pcm->info_flags = 0;
1282 strcpy(pcm->name, "Asihpi PCM");
1284 /*? do we want to emulate MMAP for non-BBM cards?
1285 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1286 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1287 snd_dma_pci_data(asihpi->pci),
1288 64*1024, BUFFER_BYTES_MAX);
1293 /***************************** MIXER CONTROLS ****************/
1294 struct hpi_control {
1302 char name[44]; /* copied to snd_ctl_elem_id.name[44]; */
1305 static const char * const asihpi_tuner_band_names[] = {
1318 compile_time_assert(
1319 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1320 (HPI_TUNER_BAND_LAST+1)),
1321 assert_tuner_band_names_size);
1323 static const char * const asihpi_src_names[] = {
1340 compile_time_assert(
1341 (ARRAY_SIZE(asihpi_src_names) ==
1342 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1343 assert_src_names_size);
1345 static const char * const asihpi_dst_names[] = {
1358 compile_time_assert(
1359 (ARRAY_SIZE(asihpi_dst_names) ==
1360 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1361 assert_dst_names_size);
1363 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1364 struct snd_card_asihpi *asihpi)
1368 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1371 else if (mixer_dump)
1372 snd_printk(KERN_INFO "added %s(%d)\n", ctl->name, ctl->index);
1377 /* Convert HPI control name and location into ALSA control name */
1378 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1379 struct hpi_control *hpi_ctl,
1383 memset(snd_control, 0, sizeof(*snd_control));
1384 snd_control->name = hpi_ctl->name;
1385 snd_control->private_value = hpi_ctl->h_control;
1386 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1387 snd_control->index = 0;
1389 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1390 dir = ""; /* clock is neither capture nor playback */
1391 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1392 dir = "Capture "; /* On or towards a PCM capture destination*/
1393 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1394 (!hpi_ctl->dst_node_type))
1395 dir = "Capture "; /* On a source node that is not PCM playback */
1396 else if (hpi_ctl->src_node_type &&
1397 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1398 (hpi_ctl->dst_node_type))
1399 dir = "Monitor Playback "; /* Between an input and an output */
1401 dir = "Playback "; /* PCM Playback source, or output node */
1403 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1404 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1405 asihpi_src_names[hpi_ctl->src_node_type],
1406 hpi_ctl->src_node_index,
1407 asihpi_dst_names[hpi_ctl->dst_node_type],
1408 hpi_ctl->dst_node_index,
1410 else if (hpi_ctl->dst_node_type) {
1411 sprintf(hpi_ctl->name, "%s %d %s%s",
1412 asihpi_dst_names[hpi_ctl->dst_node_type],
1413 hpi_ctl->dst_node_index,
1416 sprintf(hpi_ctl->name, "%s %d %s%s",
1417 asihpi_src_names[hpi_ctl->src_node_type],
1418 hpi_ctl->src_node_index,
1421 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1422 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1425 /*------------------------------------------------------------
1427 ------------------------------------------------------------*/
1428 #define VOL_STEP_mB 1
1429 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1430 struct snd_ctl_elem_info *uinfo)
1432 u32 h_control = kcontrol->private_value;
1434 /* native gains are in millibels */
1439 err = hpi_volume_query_range(h_control,
1440 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1443 min_gain_mB = -10000;
1444 step_gain_mB = VOL_STEP_mB;
1447 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1449 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1450 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1451 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1455 static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1456 struct snd_ctl_elem_value *ucontrol)
1458 u32 h_control = kcontrol->private_value;
1459 short an_gain_mB[HPI_MAX_CHANNELS];
1461 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
1462 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1463 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1468 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1469 struct snd_ctl_elem_value *ucontrol)
1472 u32 h_control = kcontrol->private_value;
1473 short an_gain_mB[HPI_MAX_CHANNELS];
1476 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1478 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1479 /* change = asihpi->mixer_volume[addr][0] != left ||
1480 asihpi->mixer_volume[addr][1] != right;
1483 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1487 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1489 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1491 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1492 struct snd_ctl_elem_value *ucontrol)
1494 u32 h_control = kcontrol->private_value;
1497 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1498 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1503 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1504 struct snd_ctl_elem_value *ucontrol)
1506 u32 h_control = kcontrol->private_value;
1508 /* HPI currently only supports all or none muting of multichannel volume
1509 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1511 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1512 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1516 static int __devinit snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1517 struct hpi_control *hpi_ctl)
1519 struct snd_card *card = asihpi->card;
1520 struct snd_kcontrol_new snd_control;
1524 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1525 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1526 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1527 snd_control.info = snd_asihpi_volume_info;
1528 snd_control.get = snd_asihpi_volume_get;
1529 snd_control.put = snd_asihpi_volume_put;
1530 snd_control.tlv.p = db_scale_100;
1532 err = ctl_add(card, &snd_control, asihpi);
1536 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1537 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1538 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1539 snd_control.info = snd_asihpi_volume_mute_info;
1540 snd_control.get = snd_asihpi_volume_mute_get;
1541 snd_control.put = snd_asihpi_volume_mute_put;
1542 err = ctl_add(card, &snd_control, asihpi);
1547 /*------------------------------------------------------------
1549 ------------------------------------------------------------*/
1550 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_info *uinfo)
1553 u32 h_control = kcontrol->private_value;
1560 hpi_level_query_range(h_control, &min_gain_mB,
1561 &max_gain_mB, &step_gain_mB);
1564 min_gain_mB = -1000;
1568 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1570 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1571 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1572 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1576 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1577 struct snd_ctl_elem_value *ucontrol)
1579 u32 h_control = kcontrol->private_value;
1580 short an_gain_mB[HPI_MAX_CHANNELS];
1582 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1583 ucontrol->value.integer.value[0] =
1584 an_gain_mB[0] / HPI_UNITS_PER_dB;
1585 ucontrol->value.integer.value[1] =
1586 an_gain_mB[1] / HPI_UNITS_PER_dB;
1591 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1592 struct snd_ctl_elem_value *ucontrol)
1595 u32 h_control = kcontrol->private_value;
1596 short an_gain_mB[HPI_MAX_CHANNELS];
1599 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1601 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1602 /* change = asihpi->mixer_level[addr][0] != left ||
1603 asihpi->mixer_level[addr][1] != right;
1606 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1610 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1612 static int __devinit snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1613 struct hpi_control *hpi_ctl)
1615 struct snd_card *card = asihpi->card;
1616 struct snd_kcontrol_new snd_control;
1618 /* can't use 'volume' cos some nodes have volume as well */
1619 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1620 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1621 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1622 snd_control.info = snd_asihpi_level_info;
1623 snd_control.get = snd_asihpi_level_get;
1624 snd_control.put = snd_asihpi_level_put;
1625 snd_control.tlv.p = db_scale_level;
1627 return ctl_add(card, &snd_control, asihpi);
1630 /*------------------------------------------------------------
1632 ------------------------------------------------------------*/
1635 static const char * const asihpi_aesebu_format_names[] = {
1636 "N/A", "S/PDIF", "AES/EBU" };
1638 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1639 struct snd_ctl_elem_info *uinfo)
1641 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1643 uinfo->value.enumerated.items = 3;
1645 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1646 uinfo->value.enumerated.item =
1647 uinfo->value.enumerated.items - 1;
1649 strcpy(uinfo->value.enumerated.name,
1650 asihpi_aesebu_format_names[uinfo->value.enumerated.item]);
1655 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1656 struct snd_ctl_elem_value *ucontrol,
1657 u16 (*func)(u32, u16 *))
1659 u32 h_control = kcontrol->private_value;
1662 err = func(h_control, &source);
1664 /* default to N/A */
1665 ucontrol->value.enumerated.item[0] = 0;
1666 /* return success but set the control to N/A */
1669 if (source == HPI_AESEBU_FORMAT_SPDIF)
1670 ucontrol->value.enumerated.item[0] = 1;
1671 if (source == HPI_AESEBU_FORMAT_AESEBU)
1672 ucontrol->value.enumerated.item[0] = 2;
1677 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1678 struct snd_ctl_elem_value *ucontrol,
1679 u16 (*func)(u32, u16))
1681 u32 h_control = kcontrol->private_value;
1683 /* default to S/PDIF */
1684 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1686 if (ucontrol->value.enumerated.item[0] == 1)
1687 source = HPI_AESEBU_FORMAT_SPDIF;
1688 if (ucontrol->value.enumerated.item[0] == 2)
1689 source = HPI_AESEBU_FORMAT_AESEBU;
1691 if (func(h_control, source) != 0)
1697 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1698 struct snd_ctl_elem_value *ucontrol) {
1699 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1700 hpi_aesebu_receiver_get_format);
1703 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1704 struct snd_ctl_elem_value *ucontrol) {
1705 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1706 hpi_aesebu_receiver_set_format);
1709 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_info *uinfo)
1712 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1715 uinfo->value.integer.min = 0;
1716 uinfo->value.integer.max = 0X1F;
1717 uinfo->value.integer.step = 1;
1722 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol) {
1725 u32 h_control = kcontrol->private_value;
1728 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1729 h_control, &status));
1730 ucontrol->value.integer.value[0] = status;
1734 static int __devinit snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1735 struct hpi_control *hpi_ctl)
1737 struct snd_card *card = asihpi->card;
1738 struct snd_kcontrol_new snd_control;
1740 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1741 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1742 snd_control.info = snd_asihpi_aesebu_format_info;
1743 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1744 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1747 if (ctl_add(card, &snd_control, asihpi) < 0)
1750 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
1751 snd_control.access =
1752 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1753 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1754 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1756 return ctl_add(card, &snd_control, asihpi);
1759 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1760 struct snd_ctl_elem_value *ucontrol) {
1761 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1762 hpi_aesebu_transmitter_get_format);
1765 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_value *ucontrol) {
1767 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1768 hpi_aesebu_transmitter_set_format);
1772 static int __devinit snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1773 struct hpi_control *hpi_ctl)
1775 struct snd_card *card = asihpi->card;
1776 struct snd_kcontrol_new snd_control;
1778 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1779 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1780 snd_control.info = snd_asihpi_aesebu_format_info;
1781 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1782 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1784 return ctl_add(card, &snd_control, asihpi);
1787 /*------------------------------------------------------------
1789 ------------------------------------------------------------*/
1793 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1794 struct snd_ctl_elem_info *uinfo)
1796 u32 h_control = kcontrol->private_value;
1801 for (idx = 0; idx < 3; idx++) {
1802 err = hpi_tuner_query_gain(h_control,
1803 idx, &gain_range[idx]);
1808 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1810 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1811 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1812 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1816 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1817 struct snd_ctl_elem_value *ucontrol)
1820 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1822 u32 h_control = kcontrol->private_value;
1825 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
1826 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1831 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1832 struct snd_ctl_elem_value *ucontrol)
1835 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1837 u32 h_control = kcontrol->private_value;
1840 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1841 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
1848 static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1849 u16 *band_list, u32 len) {
1850 u32 h_control = kcontrol->private_value;
1854 for (i = 0; i < len; i++) {
1855 err = hpi_tuner_query_band(
1856 h_control, i, &band_list[i]);
1861 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1867 static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1868 struct snd_ctl_elem_info *uinfo)
1870 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1873 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1874 HPI_TUNER_BAND_LAST);
1879 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1881 uinfo->value.enumerated.items = num_bands;
1883 if (num_bands > 0) {
1884 if (uinfo->value.enumerated.item >=
1885 uinfo->value.enumerated.items)
1886 uinfo->value.enumerated.item =
1887 uinfo->value.enumerated.items - 1;
1889 strcpy(uinfo->value.enumerated.name,
1890 asihpi_tuner_band_names[
1891 tuner_bands[uinfo->value.enumerated.item]]);
1897 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1898 struct snd_ctl_elem_value *ucontrol)
1900 u32 h_control = kcontrol->private_value;
1902 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1905 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1908 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1909 HPI_TUNER_BAND_LAST);
1911 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1913 ucontrol->value.enumerated.item[0] = -1;
1914 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1915 if (tuner_bands[idx] == band) {
1916 ucontrol->value.enumerated.item[0] = idx;
1923 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1924 struct snd_ctl_elem_value *ucontrol)
1927 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1929 u32 h_control = kcontrol->private_value;
1931 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1934 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1935 HPI_TUNER_BAND_LAST);
1937 band = tuner_bands[ucontrol->value.enumerated.item[0]];
1938 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1945 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1946 struct snd_ctl_elem_info *uinfo)
1948 u32 h_control = kcontrol->private_value;
1950 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1951 u16 num_bands = 0, band_iter, idx;
1952 u32 freq_range[3], temp_freq_range[3];
1954 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1955 HPI_TUNER_BAND_LAST);
1957 freq_range[0] = INT_MAX;
1959 freq_range[2] = INT_MAX;
1961 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1962 for (idx = 0; idx < 3; idx++) {
1963 err = hpi_tuner_query_frequency(h_control,
1964 idx, tuner_bands[band_iter],
1965 &temp_freq_range[idx]);
1970 /* skip band with bogus stepping */
1971 if (temp_freq_range[2] <= 0)
1974 if (temp_freq_range[0] < freq_range[0])
1975 freq_range[0] = temp_freq_range[0];
1976 if (temp_freq_range[1] > freq_range[1])
1977 freq_range[1] = temp_freq_range[1];
1978 if (temp_freq_range[2] < freq_range[2])
1979 freq_range[2] = temp_freq_range[2];
1982 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1984 uinfo->value.integer.min = ((int)freq_range[0]);
1985 uinfo->value.integer.max = ((int)freq_range[1]);
1986 uinfo->value.integer.step = ((int)freq_range[2]);
1990 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1991 struct snd_ctl_elem_value *ucontrol)
1993 u32 h_control = kcontrol->private_value;
1996 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
1997 ucontrol->value.integer.value[0] = freq;
2002 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
2003 struct snd_ctl_elem_value *ucontrol)
2005 u32 h_control = kcontrol->private_value;
2008 freq = ucontrol->value.integer.value[0];
2009 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
2014 /* Tuner control group initializer */
2015 static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
2016 struct hpi_control *hpi_ctl)
2018 struct snd_card *card = asihpi->card;
2019 struct snd_kcontrol_new snd_control;
2021 snd_control.private_value = hpi_ctl->h_control;
2022 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2024 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
2025 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
2026 snd_control.info = snd_asihpi_tuner_gain_info;
2027 snd_control.get = snd_asihpi_tuner_gain_get;
2028 snd_control.put = snd_asihpi_tuner_gain_put;
2030 if (ctl_add(card, &snd_control, asihpi) < 0)
2034 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
2035 snd_control.info = snd_asihpi_tuner_band_info;
2036 snd_control.get = snd_asihpi_tuner_band_get;
2037 snd_control.put = snd_asihpi_tuner_band_put;
2039 if (ctl_add(card, &snd_control, asihpi) < 0)
2042 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2043 snd_control.info = snd_asihpi_tuner_freq_info;
2044 snd_control.get = snd_asihpi_tuner_freq_get;
2045 snd_control.put = snd_asihpi_tuner_freq_put;
2047 return ctl_add(card, &snd_control, asihpi);
2050 /*------------------------------------------------------------
2052 ------------------------------------------------------------*/
2053 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2054 struct snd_ctl_elem_info *uinfo)
2056 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2057 uinfo->count = HPI_MAX_CHANNELS;
2058 uinfo->value.integer.min = 0;
2059 uinfo->value.integer.max = 0x7FFFFFFF;
2063 /* linear values for 10dB steps */
2064 static int log2lin[] = {
2065 0x7FFFFFFF, /* 0dB */
2071 2147484, /* -60dB */
2086 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2087 struct snd_ctl_elem_value *ucontrol)
2089 u32 h_control = kcontrol->private_value;
2090 short an_gain_mB[HPI_MAX_CHANNELS], i;
2093 err = hpi_meter_get_peak(h_control, an_gain_mB);
2095 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2097 ucontrol->value.integer.value[i] = 0;
2098 } else if (an_gain_mB[i] >= 0) {
2099 ucontrol->value.integer.value[i] =
2100 an_gain_mB[i] << 16;
2102 /* -ve is log value in millibels < -60dB,
2103 * convert to (roughly!) linear,
2105 ucontrol->value.integer.value[i] =
2106 log2lin[an_gain_mB[i] / -1000];
2112 static int __devinit snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2113 struct hpi_control *hpi_ctl, int subidx)
2115 struct snd_card *card = asihpi->card;
2116 struct snd_kcontrol_new snd_control;
2118 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2119 snd_control.access =
2120 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2121 snd_control.info = snd_asihpi_meter_info;
2122 snd_control.get = snd_asihpi_meter_get;
2124 snd_control.index = subidx;
2126 return ctl_add(card, &snd_control, asihpi);
2129 /*------------------------------------------------------------
2130 Multiplexer controls
2131 ------------------------------------------------------------*/
2132 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2134 u32 h_control = snd_control->private_value;
2135 struct hpi_control hpi_ctl;
2137 for (s = 0; s < 32; s++) {
2138 err = hpi_multiplexer_query_source(h_control, s,
2149 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2150 struct snd_ctl_elem_info *uinfo)
2153 u16 src_node_type, src_node_index;
2154 u32 h_control = kcontrol->private_value;
2156 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2158 uinfo->value.enumerated.items =
2159 snd_card_asihpi_mux_count_sources(kcontrol);
2161 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2162 uinfo->value.enumerated.item =
2163 uinfo->value.enumerated.items - 1;
2166 hpi_multiplexer_query_source(h_control,
2167 uinfo->value.enumerated.item,
2168 &src_node_type, &src_node_index);
2170 sprintf(uinfo->value.enumerated.name, "%s %d",
2171 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2176 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2177 struct snd_ctl_elem_value *ucontrol)
2179 u32 h_control = kcontrol->private_value;
2180 u16 source_type, source_index;
2181 u16 src_node_type, src_node_index;
2184 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2185 &source_type, &source_index));
2186 /* Should cache this search result! */
2187 for (s = 0; s < 256; s++) {
2188 if (hpi_multiplexer_query_source(h_control, s,
2189 &src_node_type, &src_node_index))
2192 if ((source_type == src_node_type)
2193 && (source_index == src_node_index)) {
2194 ucontrol->value.enumerated.item[0] = s;
2198 snd_printd(KERN_WARNING
2199 "Control %x failed to match mux source %hu %hu\n",
2200 h_control, source_type, source_index);
2201 ucontrol->value.enumerated.item[0] = 0;
2205 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_value *ucontrol)
2209 u32 h_control = kcontrol->private_value;
2210 u16 source_type, source_index;
2215 e = hpi_multiplexer_query_source(h_control,
2216 ucontrol->value.enumerated.item[0],
2217 &source_type, &source_index);
2220 hpi_multiplexer_set_source(h_control,
2221 source_type, source_index));
2226 static int __devinit snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2227 struct hpi_control *hpi_ctl)
2229 struct snd_card *card = asihpi->card;
2230 struct snd_kcontrol_new snd_control;
2232 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2233 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2234 snd_control.info = snd_asihpi_mux_info;
2235 snd_control.get = snd_asihpi_mux_get;
2236 snd_control.put = snd_asihpi_mux_put;
2238 return ctl_add(card, &snd_control, asihpi);
2242 /*------------------------------------------------------------
2243 Channel mode controls
2244 ------------------------------------------------------------*/
2245 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2246 struct snd_ctl_elem_info *uinfo)
2248 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2251 "From Left", "From Right",
2252 "To Left", "To Right"
2255 u32 h_control = kcontrol->private_value;
2259 int valid_modes = 0;
2261 /* HPI channel mode values can be from 1 to 6
2262 Some adapters only support a contiguous subset
2264 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2265 if (!hpi_channel_mode_query_mode(
2266 h_control, i, &mode)) {
2267 mode_map[valid_modes] = mode;
2271 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2273 uinfo->value.enumerated.items = valid_modes;
2275 if (uinfo->value.enumerated.item >= valid_modes)
2276 uinfo->value.enumerated.item = valid_modes - 1;
2278 strcpy(uinfo->value.enumerated.name,
2279 mode_names[mode_map[uinfo->value.enumerated.item]]);
2284 static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2285 struct snd_ctl_elem_value *ucontrol)
2287 u32 h_control = kcontrol->private_value;
2290 if (hpi_channel_mode_get(h_control, &mode))
2293 ucontrol->value.enumerated.item[0] = mode - 1;
2298 static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2299 struct snd_ctl_elem_value *ucontrol)
2302 u32 h_control = kcontrol->private_value;
2306 hpi_handle_error(hpi_channel_mode_set(h_control,
2307 ucontrol->value.enumerated.item[0] + 1));
2312 static int __devinit snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2313 struct hpi_control *hpi_ctl)
2315 struct snd_card *card = asihpi->card;
2316 struct snd_kcontrol_new snd_control;
2318 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
2319 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2320 snd_control.info = snd_asihpi_cmode_info;
2321 snd_control.get = snd_asihpi_cmode_get;
2322 snd_control.put = snd_asihpi_cmode_put;
2324 return ctl_add(card, &snd_control, asihpi);
2327 /*------------------------------------------------------------
2328 Sampleclock source controls
2329 ------------------------------------------------------------*/
2330 static char *sampleclock_sources[MAX_CLOCKSOURCES] = {
2331 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2332 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2334 "Digital2", "Digital3", "Digital4", "Digital5",
2335 "Digital6", "Digital7", "Digital8"};
2337 static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2338 struct snd_ctl_elem_info *uinfo)
2340 struct snd_card_asihpi *asihpi =
2341 (struct snd_card_asihpi *)(kcontrol->private_data);
2342 struct clk_cache *clkcache = &asihpi->cc;
2343 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2345 uinfo->value.enumerated.items = clkcache->count;
2347 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2348 uinfo->value.enumerated.item =
2349 uinfo->value.enumerated.items - 1;
2351 strcpy(uinfo->value.enumerated.name,
2352 clkcache->s[uinfo->value.enumerated.item].name);
2356 static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2357 struct snd_ctl_elem_value *ucontrol)
2359 struct snd_card_asihpi *asihpi =
2360 (struct snd_card_asihpi *)(kcontrol->private_data);
2361 struct clk_cache *clkcache = &asihpi->cc;
2362 u32 h_control = kcontrol->private_value;
2363 u16 source, srcindex = 0;
2366 ucontrol->value.enumerated.item[0] = 0;
2367 if (hpi_sample_clock_get_source(h_control, &source))
2370 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2371 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
2374 for (i = 0; i < clkcache->count; i++)
2375 if ((clkcache->s[i].source == source) &&
2376 (clkcache->s[i].index == srcindex))
2379 ucontrol->value.enumerated.item[0] = i;
2384 static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2385 struct snd_ctl_elem_value *ucontrol)
2387 struct snd_card_asihpi *asihpi =
2388 (struct snd_card_asihpi *)(kcontrol->private_data);
2389 struct clk_cache *clkcache = &asihpi->cc;
2391 u32 h_control = kcontrol->private_value;
2394 item = ucontrol->value.enumerated.item[0];
2395 if (item >= clkcache->count)
2396 item = clkcache->count-1;
2398 hpi_handle_error(hpi_sample_clock_set_source(
2399 h_control, clkcache->s[item].source));
2401 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2402 hpi_handle_error(hpi_sample_clock_set_source_index(
2403 h_control, clkcache->s[item].index));
2407 /*------------------------------------------------------------
2409 ------------------------------------------------------------*/
2410 /* Need to change this to enumerated control with list of rates */
2411 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2412 struct snd_ctl_elem_info *uinfo)
2414 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2416 uinfo->value.integer.min = 8000;
2417 uinfo->value.integer.max = 192000;
2418 uinfo->value.integer.step = 100;
2423 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2424 struct snd_ctl_elem_value *ucontrol)
2426 u32 h_control = kcontrol->private_value;
2430 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2432 ucontrol->value.integer.value[0] = rate;
2434 ucontrol->value.integer.value[0] = 0;
2438 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2439 struct snd_ctl_elem_value *ucontrol)
2442 u32 h_control = kcontrol->private_value;
2444 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2445 asihpi->mixer_clkrate[addr][1] != right;
2448 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2449 ucontrol->value.integer.value[0]));
2453 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2454 struct snd_ctl_elem_info *uinfo)
2456 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2458 uinfo->value.integer.min = 8000;
2459 uinfo->value.integer.max = 192000;
2460 uinfo->value.integer.step = 100;
2465 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2466 struct snd_ctl_elem_value *ucontrol)
2468 u32 h_control = kcontrol->private_value;
2472 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2474 ucontrol->value.integer.value[0] = rate;
2476 ucontrol->value.integer.value[0] = 0;
2480 static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2481 struct hpi_control *hpi_ctl)
2483 struct snd_card *card = asihpi->card;
2484 struct snd_kcontrol_new snd_control;
2486 struct clk_cache *clkcache = &asihpi->cc;
2487 u32 hSC = hpi_ctl->h_control;
2492 snd_control.private_value = hpi_ctl->h_control;
2494 clkcache->has_local = 0;
2496 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2497 if (hpi_sample_clock_query_source(hSC,
2500 clkcache->s[i].source = source;
2501 clkcache->s[i].index = 0;
2502 clkcache->s[i].name = sampleclock_sources[source];
2503 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2505 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2506 clkcache->has_local = 1;
2509 /* already will have picked up index 0 above */
2510 for (j = 1; j < 8; j++) {
2511 if (hpi_sample_clock_query_source_index(hSC,
2512 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2515 clkcache->s[i].source =
2516 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2517 clkcache->s[i].index = j;
2518 clkcache->s[i].name = sampleclock_sources[
2519 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2522 clkcache->count = i;
2524 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2525 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2526 snd_control.info = snd_asihpi_clksrc_info;
2527 snd_control.get = snd_asihpi_clksrc_get;
2528 snd_control.put = snd_asihpi_clksrc_put;
2529 if (ctl_add(card, &snd_control, asihpi) < 0)
2533 if (clkcache->has_local) {
2534 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2535 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2536 snd_control.info = snd_asihpi_clklocal_info;
2537 snd_control.get = snd_asihpi_clklocal_get;
2538 snd_control.put = snd_asihpi_clklocal_put;
2541 if (ctl_add(card, &snd_control, asihpi) < 0)
2545 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2546 snd_control.access =
2547 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2548 snd_control.info = snd_asihpi_clkrate_info;
2549 snd_control.get = snd_asihpi_clkrate_get;
2551 return ctl_add(card, &snd_control, asihpi);
2553 /*------------------------------------------------------------
2555 ------------------------------------------------------------*/
2557 static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2559 struct snd_card *card = asihpi->card;
2560 unsigned int idx = 0;
2561 unsigned int subindex = 0;
2563 struct hpi_control hpi_ctl, prev_ctl;
2565 if (snd_BUG_ON(!asihpi))
2567 strcpy(card->mixername, "Asihpi Mixer");
2570 hpi_mixer_open(asihpi->adapter_index,
2572 hpi_handle_error(err);
2576 memset(&prev_ctl, 0, sizeof(prev_ctl));
2577 prev_ctl.control_type = -1;
2579 for (idx = 0; idx < 2000; idx++) {
2580 err = hpi_mixer_get_control_by_index(
2583 &hpi_ctl.src_node_type,
2584 &hpi_ctl.src_node_index,
2585 &hpi_ctl.dst_node_type,
2586 &hpi_ctl.dst_node_index,
2587 &hpi_ctl.control_type,
2588 &hpi_ctl.h_control);
2590 if (err == HPI_ERROR_CONTROL_DISABLED) {
2592 snd_printk(KERN_INFO
2593 "Disabled HPI Control(%d)\n",
2601 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2602 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2604 /* ASI50xx in SSX mode has multiple meters on the same node.
2605 Use subindex to create distinct ALSA controls
2606 for any duplicated controls.
2608 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2609 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2610 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2611 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2612 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2619 switch (hpi_ctl.control_type) {
2620 case HPI_CONTROL_VOLUME:
2621 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2623 case HPI_CONTROL_LEVEL:
2624 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2626 case HPI_CONTROL_MULTIPLEXER:
2627 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2629 case HPI_CONTROL_CHANNEL_MODE:
2630 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2632 case HPI_CONTROL_METER:
2633 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2635 case HPI_CONTROL_SAMPLECLOCK:
2636 err = snd_asihpi_sampleclock_add(
2639 case HPI_CONTROL_CONNECTION: /* ignore these */
2641 case HPI_CONTROL_TUNER:
2642 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2644 case HPI_CONTROL_AESEBU_TRANSMITTER:
2645 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2647 case HPI_CONTROL_AESEBU_RECEIVER:
2648 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2650 case HPI_CONTROL_VOX:
2651 case HPI_CONTROL_BITSTREAM:
2652 case HPI_CONTROL_MICROPHONE:
2653 case HPI_CONTROL_PARAMETRIC_EQ:
2654 case HPI_CONTROL_COMPANDER:
2657 snd_printk(KERN_INFO
2658 "Untranslated HPI Control"
2659 "(%d) %d %d %d %d %d\n",
2661 hpi_ctl.control_type,
2662 hpi_ctl.src_node_type,
2663 hpi_ctl.src_node_index,
2664 hpi_ctl.dst_node_type,
2665 hpi_ctl.dst_node_index);
2671 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2672 hpi_handle_error(err);
2674 snd_printk(KERN_INFO "%d mixer controls found\n", idx);
2679 /*------------------------------------------------------------
2681 ------------------------------------------------------------*/
2684 snd_asihpi_proc_read(struct snd_info_entry *entry,
2685 struct snd_info_buffer *buffer)
2687 struct snd_card_asihpi *asihpi = entry->private_data;
2694 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2696 "adapter ID=%4X\n_index=%d\n"
2697 "num_outstreams=%d\n_num_instreams=%d\n",
2698 asihpi->type, asihpi->adapter_index,
2699 asihpi->num_outstreams, asihpi->num_instreams);
2701 version = asihpi->version;
2703 "serial#=%d\n_hw version %c%d\nDSP code version %03d\n",
2704 asihpi->serial_number, ((version >> 3) & 0xf) + 'A',
2706 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2708 err = hpi_mixer_get_control(asihpi->h_mixer,
2709 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2710 HPI_CONTROL_SAMPLECLOCK, &h_control);
2713 err = hpi_sample_clock_get_sample_rate(
2715 err += hpi_sample_clock_get_source(h_control, &source);
2718 snd_iprintf(buffer, "sample_clock=%d_hz, source %s\n",
2719 rate, sampleclock_sources[source]);
2725 static void __devinit snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2727 struct snd_info_entry *entry;
2729 if (!snd_card_proc_new(asihpi->card, "info", &entry))
2730 snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read);
2733 /*------------------------------------------------------------
2735 ------------------------------------------------------------*/
2737 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2739 if (enable_hpi_hwdep)
2746 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2748 if (enable_hpi_hwdep)
2749 return asihpi_hpi_release(file);
2754 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2755 unsigned int cmd, unsigned long arg)
2757 if (enable_hpi_hwdep)
2758 return asihpi_hpi_ioctl(file, cmd, arg);
2764 /* results in /dev/snd/hwC#D0 file for each card with index #
2765 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2767 static int __devinit snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi,
2768 int device, struct snd_hwdep **rhwdep)
2770 struct snd_hwdep *hw;
2775 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2778 strcpy(hw->name, "asihpi (HPI)");
2779 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2780 hw->ops.open = snd_asihpi_hpi_open;
2781 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2782 hw->ops.release = snd_asihpi_hpi_release;
2783 hw->private_data = asihpi;
2789 /*------------------------------------------------------------
2791 ------------------------------------------------------------*/
2792 static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev,
2793 const struct pci_device_id *pci_id)
2800 struct hpi_adapter *hpi_card;
2801 struct snd_card *card;
2802 struct snd_card_asihpi *asihpi;
2808 if (dev >= SNDRV_CARDS)
2811 /* Should this be enable[hpi_card->index] ? */
2817 err = asihpi_adapter_probe(pci_dev, pci_id);
2821 hpi_card = pci_get_drvdata(pci_dev);
2822 /* first try to give the card the same index as its hardware index */
2823 err = snd_card_create(hpi_card->index,
2824 id[hpi_card->index], THIS_MODULE,
2825 sizeof(struct snd_card_asihpi),
2828 /* if that fails, try the default index==next available */
2830 snd_card_create(index[dev], id[dev],
2832 sizeof(struct snd_card_asihpi),
2836 snd_printk(KERN_WARNING
2837 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2838 hpi_card->index, card->number);
2841 snd_card_set_dev(card, &pci_dev->dev);
2843 asihpi = (struct snd_card_asihpi *) card->private_data;
2844 asihpi->card = card;
2845 asihpi->pci = pci_dev;
2846 asihpi->adapter_index = hpi_card->index;
2847 hpi_handle_error(hpi_adapter_get_info(
2848 asihpi->adapter_index,
2849 &asihpi->num_outstreams,
2850 &asihpi->num_instreams,
2852 &asihpi->serial_number, &asihpi->type));
2854 version = asihpi->version;
2855 snd_printk(KERN_INFO "adapter ID=%4X index=%d num_outstreams=%d "
2856 "num_instreams=%d S/N=%d\n"
2857 "Hw Version %c%d DSP code version %03d\n",
2858 asihpi->type, asihpi->adapter_index,
2859 asihpi->num_outstreams,
2860 asihpi->num_instreams, asihpi->serial_number,
2861 ((version >> 3) & 0xf) + 'A',
2863 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2865 pcm_substreams = asihpi->num_outstreams;
2866 if (pcm_substreams < asihpi->num_instreams)
2867 pcm_substreams = asihpi->num_instreams;
2869 err = hpi_adapter_get_property(asihpi->adapter_index,
2870 HPI_ADAPTER_PROPERTY_CAPS1,
2871 NULL, &asihpi->support_grouping);
2873 asihpi->support_grouping = 0;
2875 err = hpi_adapter_get_property(asihpi->adapter_index,
2876 HPI_ADAPTER_PROPERTY_CAPS2,
2877 &asihpi->support_mrx, NULL);
2879 asihpi->support_mrx = 0;
2881 err = hpi_adapter_get_property(asihpi->adapter_index,
2882 HPI_ADAPTER_PROPERTY_INTERVAL,
2883 NULL, &asihpi->update_interval_frames);
2885 asihpi->update_interval_frames = 512;
2887 if (!asihpi->can_dma)
2888 asihpi->update_interval_frames *= 2;
2890 hpi_handle_error(hpi_instream_open(asihpi->adapter_index,
2893 err = hpi_instream_host_buffer_free(h_stream);
2894 asihpi->can_dma = (!err);
2896 hpi_handle_error(hpi_instream_close(h_stream));
2898 err = hpi_adapter_get_property(asihpi->adapter_index,
2899 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2900 &asihpi->in_max_chans, &asihpi->out_max_chans);
2902 asihpi->in_max_chans = 2;
2903 asihpi->out_max_chans = 2;
2906 snd_printk(KERN_INFO "has dma:%d, grouping:%d, mrx:%d\n",
2908 asihpi->support_grouping,
2912 err = snd_card_asihpi_pcm_new(asihpi, 0, pcm_substreams);
2914 snd_printk(KERN_ERR "pcm_new failed\n");
2917 err = snd_card_asihpi_mixer_new(asihpi);
2919 snd_printk(KERN_ERR "mixer_new failed\n");
2923 err = hpi_mixer_get_control(asihpi->h_mixer,
2924 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2925 HPI_CONTROL_SAMPLECLOCK, &h_control);
2928 err = hpi_sample_clock_set_local_rate(
2929 h_control, adapter_fs);
2931 snd_asihpi_proc_init(asihpi);
2933 /* always create, can be enabled or disabled dynamically
2934 by enable_hwdep module param*/
2935 snd_asihpi_hpi_new(asihpi, 0, NULL);
2937 strcpy(card->driver, "ASIHPI");
2939 sprintf(card->shortname, "AudioScience ASI%4X", asihpi->type);
2940 sprintf(card->longname, "%s %i",
2941 card->shortname, asihpi->adapter_index);
2942 err = snd_card_register(card);
2945 hpi_card->snd_card_asihpi = card;
2950 snd_card_free(card);
2951 snd_printk(KERN_ERR "snd_asihpi_probe error %d\n", err);
2956 static void __devexit snd_asihpi_remove(struct pci_dev *pci_dev)
2958 struct hpi_adapter *hpi_card = pci_get_drvdata(pci_dev);
2960 snd_card_free(hpi_card->snd_card_asihpi);
2961 hpi_card->snd_card_asihpi = NULL;
2962 asihpi_adapter_remove(pci_dev);
2965 static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl) = {
2966 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2967 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2968 (kernel_ulong_t)HPI_6205},
2969 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2970 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2971 (kernel_ulong_t)HPI_6000},
2974 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2976 static struct pci_driver driver = {
2977 .name = KBUILD_MODNAME,
2978 .id_table = asihpi_pci_tbl,
2979 .probe = snd_asihpi_probe,
2980 .remove = __devexit_p(snd_asihpi_remove),
2982 /* .suspend = snd_asihpi_suspend,
2983 .resume = snd_asihpi_resume, */
2987 static int __init snd_asihpi_init(void)
2990 return pci_register_driver(&driver);
2993 static void __exit snd_asihpi_exit(void)
2996 pci_unregister_driver(&driver);
3000 module_init(snd_asihpi_init)
3001 module_exit(snd_asihpi_exit)