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 "hpi_version.h"
27 #include "hpimsginit.h"
32 #include <linux/pci.h>
33 #include <linux/init.h>
34 #include <linux/jiffies.h>
35 #include <linux/slab.h>
36 #include <linux/time.h>
37 #include <linux/wait.h>
38 #include <linux/module.h>
39 #include <sound/core.h>
40 #include <sound/control.h>
41 #include <sound/pcm.h>
42 #include <sound/pcm_params.h>
43 #include <sound/info.h>
44 #include <sound/initval.h>
45 #include <sound/tlv.h>
46 #include <sound/hwdep.h>
48 MODULE_LICENSE("GPL");
49 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
50 MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx "
53 #if defined CONFIG_SND_DEBUG_VERBOSE
55 * snd_printddd - very verbose debug printk
56 * @format: format string
58 * Works like snd_printk() for debugging purposes.
59 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
60 * Must set snd module debug parameter to 3 to enable at runtime.
62 #define snd_printddd(format, args...) \
63 __snd_printk(3, __FILE__, __LINE__, format, ##args)
65 #define snd_printddd(format, args...) do { } while (0)
68 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
69 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
70 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
71 static bool enable_hpi_hwdep = 1;
73 module_param_array(index, int, NULL, S_IRUGO);
74 MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
76 module_param_array(id, charp, NULL, S_IRUGO);
77 MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
79 module_param_array(enable, bool, NULL, S_IRUGO);
80 MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
82 module_param(enable_hpi_hwdep, bool, S_IRUGO|S_IWUSR);
83 MODULE_PARM_DESC(enable_hpi_hwdep,
84 "ALSA enable HPI hwdep for AudioScience soundcard ");
87 #ifdef KERNEL_ALSA_BUILD
88 static char *build_info = "Built using headers from kernel source";
89 module_param(build_info, charp, S_IRUGO);
90 MODULE_PARM_DESC(build_info, "built using headers from kernel source");
92 static char *build_info = "Built within ALSA source";
93 module_param(build_info, charp, S_IRUGO);
94 MODULE_PARM_DESC(build_info, "built within ALSA source");
97 /* set to 1 to dump every control from adapter to log */
98 static const int mixer_dump;
100 #define DEFAULT_SAMPLERATE 44100
101 static int adapter_fs = DEFAULT_SAMPLERATE;
104 #define PERIODS_MIN 2
105 #define PERIOD_BYTES_MIN 2048
106 #define BUFFER_BYTES_MAX (512 * 1024)
108 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
119 struct clk_source s[MAX_CLOCKSOURCES];
123 struct snd_card_asihpi {
124 struct snd_card *card;
126 struct hpi_adapter *hpi;
132 u16 support_grouping;
134 u16 update_interval_frames;
141 /* Per stream data */
142 struct snd_card_asihpi_pcm {
143 struct timer_list timer;
144 unsigned int respawn_timer;
145 unsigned int hpi_buffer_attached;
146 unsigned int buffer_bytes;
147 unsigned int period_bytes;
148 unsigned int bytes_per_sec;
149 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
150 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
151 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
152 unsigned int drained_count;
153 struct snd_pcm_substream *substream;
155 struct hpi_format format;
158 /* universal stream verbs work with out or in stream handles */
160 /* Functions to allow driver to give a buffer to HPI for busmastering */
162 static u16 hpi_stream_host_buffer_attach(
163 u32 h_stream, /* handle to outstream. */
164 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
168 struct hpi_message hm;
169 struct hpi_response hr;
170 unsigned int obj = hpi_handle_object(h_stream);
173 return HPI_ERROR_INVALID_OBJ;
174 hpi_init_message_response(&hm, &hr, obj,
175 obj == HPI_OBJ_OSTREAM ?
176 HPI_OSTREAM_HOSTBUFFER_ALLOC :
177 HPI_ISTREAM_HOSTBUFFER_ALLOC);
179 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
182 hm.u.d.u.buffer.buffer_size = size_in_bytes;
183 hm.u.d.u.buffer.pci_address = pci_address;
184 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
185 hpi_send_recv(&hm, &hr);
189 static u16 hpi_stream_host_buffer_detach(u32 h_stream)
191 struct hpi_message hm;
192 struct hpi_response hr;
193 unsigned int obj = hpi_handle_object(h_stream);
196 return HPI_ERROR_INVALID_OBJ;
198 hpi_init_message_response(&hm, &hr, obj,
199 obj == HPI_OBJ_OSTREAM ?
200 HPI_OSTREAM_HOSTBUFFER_FREE :
201 HPI_ISTREAM_HOSTBUFFER_FREE);
203 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
205 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
206 hpi_send_recv(&hm, &hr);
210 static inline u16 hpi_stream_start(u32 h_stream)
212 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
213 return hpi_outstream_start(h_stream);
215 return hpi_instream_start(h_stream);
218 static inline u16 hpi_stream_stop(u32 h_stream)
220 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
221 return hpi_outstream_stop(h_stream);
223 return hpi_instream_stop(h_stream);
226 static inline u16 hpi_stream_get_info_ex(
230 u32 *pdata_in_buffer,
236 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
237 e = hpi_outstream_get_info_ex(h_stream, pw_state,
238 pbuffer_size, pdata_in_buffer,
239 psample_count, pauxiliary_data);
241 e = hpi_instream_get_info_ex(h_stream, pw_state,
242 pbuffer_size, pdata_in_buffer,
243 psample_count, pauxiliary_data);
247 static inline u16 hpi_stream_group_add(
251 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
252 return hpi_outstream_group_add(h_master, h_stream);
254 return hpi_instream_group_add(h_master, h_stream);
257 static inline u16 hpi_stream_group_reset(u32 h_stream)
259 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
260 return hpi_outstream_group_reset(h_stream);
262 return hpi_instream_group_reset(h_stream);
265 static inline u16 hpi_stream_group_get_map(
266 u32 h_stream, u32 *mo, u32 *mi)
268 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
269 return hpi_outstream_group_get_map(h_stream, mo, mi);
271 return hpi_instream_group_get_map(h_stream, mo, mi);
274 static u16 handle_error(u16 err, int line, char *filename)
278 "in file %s, line %d: HPI error %d\n",
279 filename, line, err);
283 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
285 /***************************** GENERAL PCM ****************/
287 static void print_hwparams(struct snd_pcm_substream *substream,
288 struct snd_pcm_hw_params *p)
291 snd_pcm_debug_name(substream, name, sizeof(name));
292 snd_printd("%s HWPARAMS\n", name);
293 snd_printd(" samplerate %d Hz\n", params_rate(p));
294 snd_printd(" channels %d\n", params_channels(p));
295 snd_printd(" format %d\n", params_format(p));
296 snd_printd(" subformat %d\n", params_subformat(p));
297 snd_printd(" buffer %d B\n", params_buffer_bytes(p));
298 snd_printd(" period %d B\n", params_period_bytes(p));
299 snd_printd(" access %d\n", params_access(p));
300 snd_printd(" period_size %d\n", params_period_size(p));
301 snd_printd(" periods %d\n", params_periods(p));
302 snd_printd(" buffer_size %d\n", params_buffer_size(p));
303 snd_printd(" %d B/s\n", params_rate(p) *
305 snd_pcm_format_width(params_format(p)) / 8);
309 static snd_pcm_format_t hpi_to_alsa_formats[] = {
311 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
312 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
313 -1, /* HPI_FORMAT_MPEG_L1 3 */
314 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
315 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
316 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
317 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
318 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
319 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
320 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
321 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
322 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
323 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
324 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
326 /* ALSA can't handle 3 byte sample size together with power-of-2
327 * constraint on buffer_bytes, so disable this format
331 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
336 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
341 for (format = HPI_FORMAT_PCM8_UNSIGNED;
342 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
343 if (hpi_to_alsa_formats[format] == alsa_format) {
344 *hpi_format = format;
349 snd_printd(KERN_WARNING "failed match for alsa format %d\n",
355 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
356 struct snd_pcm_hardware *pcmhw)
362 unsigned int rate_min = 200000;
363 unsigned int rate_max = 0;
364 unsigned int rates = 0;
366 if (asihpi->support_mrx) {
367 rates |= SNDRV_PCM_RATE_CONTINUOUS;
368 rates |= SNDRV_PCM_RATE_8000_96000;
372 /* on cards without SRC,
373 valid rates are determined by sampleclock */
374 err = hpi_mixer_get_control(asihpi->h_mixer,
375 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
376 HPI_CONTROL_SAMPLECLOCK, &h_control);
379 "No local sampleclock, err %d\n", err);
382 for (idx = -1; idx < 100; idx++) {
384 if (hpi_sample_clock_get_sample_rate(h_control,
387 } else if (hpi_sample_clock_query_local_rate(h_control,
388 idx, &sample_rate)) {
392 rate_min = min(rate_min, sample_rate);
393 rate_max = max(rate_max, sample_rate);
395 switch (sample_rate) {
397 rates |= SNDRV_PCM_RATE_5512;
400 rates |= SNDRV_PCM_RATE_8000;
403 rates |= SNDRV_PCM_RATE_11025;
406 rates |= SNDRV_PCM_RATE_16000;
409 rates |= SNDRV_PCM_RATE_22050;
412 rates |= SNDRV_PCM_RATE_32000;
415 rates |= SNDRV_PCM_RATE_44100;
418 rates |= SNDRV_PCM_RATE_48000;
421 rates |= SNDRV_PCM_RATE_64000;
424 rates |= SNDRV_PCM_RATE_88200;
427 rates |= SNDRV_PCM_RATE_96000;
430 rates |= SNDRV_PCM_RATE_176400;
433 rates |= SNDRV_PCM_RATE_192000;
435 default: /* some other rate */
436 rates |= SNDRV_PCM_RATE_KNOT;
441 pcmhw->rates = rates;
442 pcmhw->rate_min = rate_min;
443 pcmhw->rate_max = rate_max;
446 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
447 struct snd_pcm_hw_params *params)
449 struct snd_pcm_runtime *runtime = substream->runtime;
450 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
451 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
455 unsigned int bytes_per_sec;
457 print_hwparams(substream, params);
458 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
461 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
465 hpi_handle_error(hpi_format_create(&dpcm->format,
466 params_channels(params),
467 format, params_rate(params), 0, 0));
469 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
470 if (hpi_instream_reset(dpcm->h_stream) != 0)
473 if (hpi_instream_set_format(
474 dpcm->h_stream, &dpcm->format) != 0)
478 dpcm->hpi_buffer_attached = 0;
480 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
481 params_buffer_bytes(params), runtime->dma_addr);
484 "stream_host_buffer_attach succeeded %u %lu\n",
485 params_buffer_bytes(params),
486 (unsigned long)runtime->dma_addr);
488 snd_printd("stream_host_buffer_attach error %d\n",
493 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
494 &dpcm->hpi_buffer_attached,
497 snd_printdd("stream_host_buffer_attach status 0x%x\n",
498 dpcm->hpi_buffer_attached);
501 bytes_per_sec = params_rate(params) * params_channels(params);
502 width = snd_pcm_format_width(params_format(params));
503 bytes_per_sec *= width;
505 if (width < 0 || bytes_per_sec == 0)
508 dpcm->bytes_per_sec = bytes_per_sec;
509 dpcm->buffer_bytes = params_buffer_bytes(params);
510 dpcm->period_bytes = params_period_bytes(params);
516 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
518 struct snd_pcm_runtime *runtime = substream->runtime;
519 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
520 if (dpcm->hpi_buffer_attached)
521 hpi_stream_host_buffer_detach(dpcm->h_stream);
523 snd_pcm_lib_free_pages(substream);
527 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
529 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
533 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
536 struct snd_pcm_runtime *runtime = substream->runtime;
537 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
541 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */
542 expiry = max(expiry, 1); /* don't let it be zero! */
543 dpcm->timer.expires = jiffies + expiry;
544 dpcm->respawn_timer = 1;
545 add_timer(&dpcm->timer);
548 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
550 struct snd_pcm_runtime *runtime = substream->runtime;
551 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
553 dpcm->respawn_timer = 0;
554 del_timer(&dpcm->timer);
557 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
560 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
561 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
562 struct snd_pcm_substream *s;
566 snd_pcm_debug_name(substream, name, sizeof(name));
567 snd_printdd("%s trigger\n", name);
570 case SNDRV_PCM_TRIGGER_START:
571 snd_pcm_group_for_each_entry(s, substream) {
572 struct snd_pcm_runtime *runtime = s->runtime;
573 struct snd_card_asihpi_pcm *ds = runtime->private_data;
575 if (snd_pcm_substream_chip(s) != card)
578 /* don't link Cap and Play */
579 if (substream->stream != s->stream)
582 ds->drained_count = 0;
583 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
584 /* How do I know how much valid data is present
585 * in buffer? Must be at least one period!
586 * Guessing 2 periods, but if
587 * buffer is bigger it may contain even more
590 unsigned int preload = ds->period_bytes * 1;
591 snd_printddd("%d preload x%x\n", s->number, preload);
592 hpi_handle_error(hpi_outstream_write_buf(
594 &runtime->dma_area[0],
597 ds->pcm_buf_host_rw_ofs = preload;
600 if (card->support_grouping) {
601 snd_printdd("%d group\n", s->number);
602 e = hpi_stream_group_add(
606 snd_pcm_trigger_done(s, substream);
614 snd_printdd("start\n");
615 /* start the master stream */
616 snd_card_asihpi_pcm_timer_start(substream);
617 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
619 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
622 case SNDRV_PCM_TRIGGER_STOP:
623 snd_card_asihpi_pcm_timer_stop(substream);
624 snd_pcm_group_for_each_entry(s, substream) {
625 if (snd_pcm_substream_chip(s) != card)
627 /* don't link Cap and Play */
628 if (substream->stream != s->stream)
631 /*? workaround linked streams don't
632 transition to SETUP 20070706*/
633 s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
635 if (card->support_grouping) {
636 snd_printdd("%d group\n", s->number);
637 snd_pcm_trigger_done(s, substream);
641 snd_printdd("stop\n");
643 /* _prepare and _hwparams reset the stream */
644 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
645 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
647 hpi_outstream_reset(dpcm->h_stream));
649 if (card->support_grouping)
650 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
653 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
654 snd_printdd("pause release\n");
655 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
656 snd_card_asihpi_pcm_timer_start(substream);
658 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
659 snd_printdd("pause\n");
660 snd_card_asihpi_pcm_timer_stop(substream);
661 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
664 snd_printd(KERN_ERR "\tINVALID\n");
672 Without linking degenerates to getting single stream pos etc
673 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
676 pcm_buf_dma_ofs=get_buf_pos(s);
677 for_each_linked_stream(s) {
678 pcm_buf_dma_ofs=get_buf_pos(s);
679 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
680 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
682 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
683 for_each_linked_stream(s) {
684 s->pcm_buf_dma_ofs = min_buf_pos;
685 if (new_data > period_bytes) {
687 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
694 snd_pcm_period_elapsed(s);
699 /** Minimum of 2 modulo values. Works correctly when the difference between
700 * the values is less than half the modulus
702 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
703 unsigned long int modulus)
706 if (((a-b) % modulus) < (modulus/2))
714 /** Timer function, equivalent to interrupt service routine for cards
716 static void snd_card_asihpi_timer_function(unsigned long data)
718 struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data;
719 struct snd_pcm_substream *substream = dpcm->substream;
720 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
721 struct snd_pcm_runtime *runtime;
722 struct snd_pcm_substream *s;
723 unsigned int newdata = 0;
724 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
725 unsigned int remdata, xfercount, next_jiffies;
729 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
732 snd_pcm_debug_name(substream, name, sizeof(name));
734 snd_printdd("%s snd_card_asihpi_timer_function\n", name);
736 /* find minimum newdata and buffer pos in group */
737 snd_pcm_group_for_each_entry(s, substream) {
738 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
739 runtime = s->runtime;
741 if (snd_pcm_substream_chip(s) != card)
744 /* don't link Cap and Play */
745 if (substream->stream != s->stream)
748 hpi_handle_error(hpi_stream_get_info_ex(
749 ds->h_stream, &state,
750 &buffer_size, &bytes_avail,
751 &samples_played, &on_card_bytes));
753 /* number of bytes in on-card buffer */
754 runtime->delay = on_card_bytes;
757 on_card_bytes = bytes_avail;
759 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
760 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
761 if (state == HPI_STATE_STOPPED) {
762 if (bytes_avail == 0) {
763 hpi_handle_error(hpi_stream_start(ds->h_stream));
764 snd_printdd("P%d start\n", s->number);
765 ds->drained_count = 0;
767 } else if (state == HPI_STATE_DRAINED) {
768 snd_printd(KERN_WARNING "P%d drained\n",
771 if (ds->drained_count > 20) {
773 snd_pcm_stream_lock_irqsave(s, flags);
774 snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
775 snd_pcm_stream_unlock_irqrestore(s, flags);
779 ds->drained_count = 0;
782 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
785 /* can't statically init min when wrap is involved */
786 min_buf_pos = pcm_buf_dma_ofs;
787 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
791 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
793 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
797 snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n",
798 (unsigned long)frames_to_bytes(runtime,
799 runtime->status->hw_ptr),
800 (unsigned long)frames_to_bytes(runtime,
801 runtime->control->appl_ptr));
803 snd_printdd("%d S=%d, "
804 "rw=0x%04X, dma=0x%04X, left=0x%04X, "
805 "aux=0x%04X space=0x%04X\n",
807 ds->pcm_buf_host_rw_ofs, pcm_buf_dma_ofs,
809 (int)on_card_bytes, buffer_size-bytes_avail);
812 pcm_buf_dma_ofs = min_buf_pos;
814 remdata = newdata % dpcm->period_bytes;
815 xfercount = newdata - remdata; /* a multiple of period_bytes */
816 /* come back when on_card_bytes has decreased enough to allow
817 write to happen, or when data has been consumed to make another
820 if (xfercount && (on_card_bytes > dpcm->period_bytes))
821 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
823 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
825 next_jiffies = max(next_jiffies, 1U);
826 dpcm->timer.expires = jiffies + next_jiffies;
827 snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n",
828 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
830 snd_pcm_group_for_each_entry(s, substream) {
831 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
833 /* don't link Cap and Play */
834 if (substream->stream != s->stream)
837 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
840 /* Limit use of on card fifo for playback */
841 ((on_card_bytes <= ds->period_bytes) ||
842 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
846 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
847 unsigned int xfer1, xfer2;
848 char *pd = &s->runtime->dma_area[buf_ofs];
850 if (card->can_dma) { /* buffer wrap is handled at lower level */
854 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
855 xfer2 = xfercount - xfer1;
858 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
859 snd_printddd("P%d write1 0x%04X 0x%04X\n",
860 s->number, xfer1, buf_ofs);
862 hpi_outstream_write_buf(
863 ds->h_stream, pd, xfer1,
867 pd = s->runtime->dma_area;
869 snd_printddd("P%d write2 0x%04X 0x%04X\n",
871 xfercount - xfer1, buf_ofs);
873 hpi_outstream_write_buf(
879 snd_printddd("C%d read1 0x%04x\n",
882 hpi_instream_read_buf(
886 pd = s->runtime->dma_area;
887 snd_printddd("C%d read2 0x%04x\n",
890 hpi_instream_read_buf(
895 ds->pcm_buf_host_rw_ofs += xfercount;
896 ds->pcm_buf_elapsed_dma_ofs += xfercount;
897 snd_pcm_period_elapsed(s);
901 if (dpcm->respawn_timer)
902 add_timer(&dpcm->timer);
905 /***************************** PLAYBACK OPS ****************/
906 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
907 unsigned int cmd, void *arg)
910 snd_pcm_debug_name(substream, name, sizeof(name));
911 snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd);
912 return snd_pcm_lib_ioctl(substream, cmd, arg);
915 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
918 struct snd_pcm_runtime *runtime = substream->runtime;
919 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
921 snd_printdd("P%d prepare\n", substream->number);
923 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
924 dpcm->pcm_buf_host_rw_ofs = 0;
925 dpcm->pcm_buf_dma_ofs = 0;
926 dpcm->pcm_buf_elapsed_dma_ofs = 0;
930 static snd_pcm_uframes_t
931 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
933 struct snd_pcm_runtime *runtime = substream->runtime;
934 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
935 snd_pcm_uframes_t ptr;
937 snd_pcm_debug_name(substream, name, sizeof(name));
939 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
940 snd_printddd("%s pointer = 0x%04lx\n", name, (unsigned long)ptr);
944 static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
947 struct hpi_format hpi_format;
951 u32 sample_rate = 48000;
954 /* on cards without SRC, must query at valid rate,
955 * maybe set by external sync
957 err = hpi_mixer_get_control(asihpi->h_mixer,
958 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
959 HPI_CONTROL_SAMPLECLOCK, &h_control);
962 err = hpi_sample_clock_get_sample_rate(h_control,
965 for (format = HPI_FORMAT_PCM8_UNSIGNED;
966 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
967 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
968 format, sample_rate, 128000, 0);
970 err = hpi_outstream_query_format(h_stream, &hpi_format);
971 if (!err && (hpi_to_alsa_formats[format] != -1))
972 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
977 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
979 struct snd_pcm_runtime *runtime = substream->runtime;
980 struct snd_card_asihpi_pcm *dpcm;
981 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
982 struct snd_pcm_hardware snd_card_asihpi_playback;
985 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
989 err = hpi_outstream_open(card->hpi->adapter->index,
990 substream->number, &dpcm->h_stream);
991 hpi_handle_error(err);
994 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
999 /*? also check ASI5000 samplerate source
1000 If external, only support external rate.
1001 If internal and other stream playing, can't switch
1004 init_timer(&dpcm->timer);
1005 dpcm->timer.data = (unsigned long) dpcm;
1006 dpcm->timer.function = snd_card_asihpi_timer_function;
1007 dpcm->substream = substream;
1008 runtime->private_data = dpcm;
1009 runtime->private_free = snd_card_asihpi_runtime_free;
1011 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1012 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1013 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
1014 /*?snd_card_asihpi_playback.period_bytes_min =
1015 card->out_max_chans * 4096; */
1016 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1017 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1018 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1019 /* snd_card_asihpi_playback.fifo_size = 0; */
1020 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1021 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1022 snd_card_asihpi_playback.formats =
1023 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
1025 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1027 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1028 SNDRV_PCM_INFO_DOUBLE |
1029 SNDRV_PCM_INFO_BATCH |
1030 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1031 SNDRV_PCM_INFO_PAUSE |
1032 SNDRV_PCM_INFO_MMAP |
1033 SNDRV_PCM_INFO_MMAP_VALID;
1035 if (card->support_grouping) {
1036 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1037 snd_pcm_set_sync(substream);
1040 /* struct is copied, so can create initializer dynamically */
1041 runtime->hw = snd_card_asihpi_playback;
1044 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1045 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1049 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1050 card->update_interval_frames);
1052 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1053 card->update_interval_frames * 2, UINT_MAX);
1055 snd_printdd("playback open\n");
1060 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1062 struct snd_pcm_runtime *runtime = substream->runtime;
1063 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1065 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1066 snd_printdd("playback close\n");
1071 static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1072 .open = snd_card_asihpi_playback_open,
1073 .close = snd_card_asihpi_playback_close,
1074 .ioctl = snd_card_asihpi_playback_ioctl,
1075 .hw_params = snd_card_asihpi_pcm_hw_params,
1076 .hw_free = snd_card_asihpi_hw_free,
1077 .prepare = snd_card_asihpi_playback_prepare,
1078 .trigger = snd_card_asihpi_trigger,
1079 .pointer = snd_card_asihpi_playback_pointer,
1082 /***************************** CAPTURE OPS ****************/
1083 static snd_pcm_uframes_t
1084 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1086 struct snd_pcm_runtime *runtime = substream->runtime;
1087 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1089 snd_printddd("capture pointer %d=%d\n",
1090 substream->number, dpcm->pcm_buf_dma_ofs);
1091 /* NOTE Unlike playback can't use actual samples_played
1092 for the capture position, because those samples aren't yet in
1093 the local buffer available for reading.
1095 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1098 static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
1099 unsigned int cmd, void *arg)
1101 return snd_pcm_lib_ioctl(substream, cmd, arg);
1104 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1106 struct snd_pcm_runtime *runtime = substream->runtime;
1107 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1109 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1110 dpcm->pcm_buf_host_rw_ofs = 0;
1111 dpcm->pcm_buf_dma_ofs = 0;
1112 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1114 snd_printdd("Capture Prepare %d\n", substream->number);
1120 static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1123 struct hpi_format hpi_format;
1127 u32 sample_rate = 48000;
1130 /* on cards without SRC, must query at valid rate,
1131 maybe set by external sync */
1132 err = hpi_mixer_get_control(asihpi->h_mixer,
1133 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1134 HPI_CONTROL_SAMPLECLOCK, &h_control);
1137 err = hpi_sample_clock_get_sample_rate(h_control,
1140 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1141 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1143 err = hpi_format_create(&hpi_format, asihpi->in_max_chans,
1144 format, sample_rate, 128000, 0);
1146 err = hpi_instream_query_format(h_stream, &hpi_format);
1147 if (!err && (hpi_to_alsa_formats[format] != -1))
1148 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1153 static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1155 struct snd_pcm_runtime *runtime = substream->runtime;
1156 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1157 struct snd_card_asihpi_pcm *dpcm;
1158 struct snd_pcm_hardware snd_card_asihpi_capture;
1161 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1165 snd_printdd("capture open adapter %d stream %d\n",
1166 card->hpi->adapter->index, substream->number);
1168 err = hpi_handle_error(
1169 hpi_instream_open(card->hpi->adapter->index,
1170 substream->number, &dpcm->h_stream));
1173 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1178 init_timer(&dpcm->timer);
1179 dpcm->timer.data = (unsigned long) dpcm;
1180 dpcm->timer.function = snd_card_asihpi_timer_function;
1181 dpcm->substream = substream;
1182 runtime->private_data = dpcm;
1183 runtime->private_free = snd_card_asihpi_runtime_free;
1185 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1186 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1187 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1188 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1189 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1190 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1191 /* snd_card_asihpi_capture.fifo_size = 0; */
1192 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1193 snd_card_asihpi_capture.channels_min = card->in_min_chans;
1194 snd_card_asihpi_capture.formats =
1195 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
1196 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1197 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1198 SNDRV_PCM_INFO_MMAP |
1199 SNDRV_PCM_INFO_MMAP_VALID;
1201 if (card->support_grouping)
1202 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1204 runtime->hw = snd_card_asihpi_capture;
1207 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1208 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1212 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1213 card->update_interval_frames);
1214 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1215 card->update_interval_frames * 2, UINT_MAX);
1217 snd_pcm_set_sync(substream);
1222 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1224 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1226 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1230 static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1231 .open = snd_card_asihpi_capture_open,
1232 .close = snd_card_asihpi_capture_close,
1233 .ioctl = snd_card_asihpi_capture_ioctl,
1234 .hw_params = snd_card_asihpi_pcm_hw_params,
1235 .hw_free = snd_card_asihpi_hw_free,
1236 .prepare = snd_card_asihpi_capture_prepare,
1237 .trigger = snd_card_asihpi_trigger,
1238 .pointer = snd_card_asihpi_capture_pointer,
1241 static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1243 struct snd_pcm *pcm;
1245 u16 num_instreams, num_outstreams, x16;
1248 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1249 &num_outstreams, &num_instreams,
1252 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1253 num_outstreams, num_instreams, &pcm);
1256 /* pointer to ops struct is stored, dont change ops afterwards! */
1257 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1258 &snd_card_asihpi_playback_mmap_ops);
1259 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1260 &snd_card_asihpi_capture_mmap_ops);
1262 pcm->private_data = asihpi;
1263 pcm->info_flags = 0;
1264 strcpy(pcm->name, "Asihpi PCM");
1266 /*? do we want to emulate MMAP for non-BBM cards?
1267 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1268 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1269 snd_dma_pci_data(asihpi->pci),
1270 64*1024, BUFFER_BYTES_MAX);
1275 /***************************** MIXER CONTROLS ****************/
1276 struct hpi_control {
1284 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
1287 static const char * const asihpi_tuner_band_names[] = {
1300 compile_time_assert(
1301 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1302 (HPI_TUNER_BAND_LAST+1)),
1303 assert_tuner_band_names_size);
1305 static const char * const asihpi_src_names[] = {
1322 compile_time_assert(
1323 (ARRAY_SIZE(asihpi_src_names) ==
1324 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1325 assert_src_names_size);
1327 static const char * const asihpi_dst_names[] = {
1339 compile_time_assert(
1340 (ARRAY_SIZE(asihpi_dst_names) ==
1341 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1342 assert_dst_names_size);
1344 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1345 struct snd_card_asihpi *asihpi)
1349 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1352 else if (mixer_dump)
1353 snd_printk(KERN_INFO "added %s(%d)\n", ctl->name, ctl->index);
1358 /* Convert HPI control name and location into ALSA control name */
1359 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1360 struct hpi_control *hpi_ctl,
1364 memset(snd_control, 0, sizeof(*snd_control));
1365 snd_control->name = hpi_ctl->name;
1366 snd_control->private_value = hpi_ctl->h_control;
1367 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1368 snd_control->index = 0;
1370 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1371 dir = ""; /* clock is neither capture nor playback */
1372 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1373 dir = "Capture "; /* On or towards a PCM capture destination*/
1374 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1375 (!hpi_ctl->dst_node_type))
1376 dir = "Capture "; /* On a source node that is not PCM playback */
1377 else if (hpi_ctl->src_node_type &&
1378 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1379 (hpi_ctl->dst_node_type))
1380 dir = "Monitor Playback "; /* Between an input and an output */
1382 dir = "Playback "; /* PCM Playback source, or output node */
1384 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1385 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1386 asihpi_src_names[hpi_ctl->src_node_type],
1387 hpi_ctl->src_node_index,
1388 asihpi_dst_names[hpi_ctl->dst_node_type],
1389 hpi_ctl->dst_node_index,
1391 else if (hpi_ctl->dst_node_type) {
1392 sprintf(hpi_ctl->name, "%s %d %s%s",
1393 asihpi_dst_names[hpi_ctl->dst_node_type],
1394 hpi_ctl->dst_node_index,
1397 sprintf(hpi_ctl->name, "%s %d %s%s",
1398 asihpi_src_names[hpi_ctl->src_node_type],
1399 hpi_ctl->src_node_index,
1402 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1403 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1406 /*------------------------------------------------------------
1408 ------------------------------------------------------------*/
1409 #define VOL_STEP_mB 1
1410 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1411 struct snd_ctl_elem_info *uinfo)
1413 u32 h_control = kcontrol->private_value;
1416 /* native gains are in millibels */
1421 err = hpi_volume_query_range(h_control,
1422 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1425 min_gain_mB = -10000;
1426 step_gain_mB = VOL_STEP_mB;
1429 err = hpi_meter_query_channels(h_control, &count);
1431 count = HPI_MAX_CHANNELS;
1433 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1434 uinfo->count = count;
1435 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1436 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1437 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1441 static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1442 struct snd_ctl_elem_value *ucontrol)
1444 u32 h_control = kcontrol->private_value;
1445 short an_gain_mB[HPI_MAX_CHANNELS];
1447 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
1448 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1449 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1454 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1455 struct snd_ctl_elem_value *ucontrol)
1458 u32 h_control = kcontrol->private_value;
1459 short an_gain_mB[HPI_MAX_CHANNELS];
1462 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1464 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1465 /* change = asihpi->mixer_volume[addr][0] != left ||
1466 asihpi->mixer_volume[addr][1] != right;
1469 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1473 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1475 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1477 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1478 struct snd_ctl_elem_value *ucontrol)
1480 u32 h_control = kcontrol->private_value;
1483 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1484 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1489 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1492 u32 h_control = kcontrol->private_value;
1494 /* HPI currently only supports all or none muting of multichannel volume
1495 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1497 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1498 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1502 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1503 struct hpi_control *hpi_ctl)
1505 struct snd_card *card = asihpi->card;
1506 struct snd_kcontrol_new snd_control;
1510 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1511 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1512 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1513 snd_control.info = snd_asihpi_volume_info;
1514 snd_control.get = snd_asihpi_volume_get;
1515 snd_control.put = snd_asihpi_volume_put;
1516 snd_control.tlv.p = db_scale_100;
1518 err = ctl_add(card, &snd_control, asihpi);
1522 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1523 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1524 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1525 snd_control.info = snd_asihpi_volume_mute_info;
1526 snd_control.get = snd_asihpi_volume_mute_get;
1527 snd_control.put = snd_asihpi_volume_mute_put;
1528 err = ctl_add(card, &snd_control, asihpi);
1533 /*------------------------------------------------------------
1535 ------------------------------------------------------------*/
1536 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1537 struct snd_ctl_elem_info *uinfo)
1539 u32 h_control = kcontrol->private_value;
1546 hpi_level_query_range(h_control, &min_gain_mB,
1547 &max_gain_mB, &step_gain_mB);
1550 min_gain_mB = -1000;
1554 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1556 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1557 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1558 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1562 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol)
1565 u32 h_control = kcontrol->private_value;
1566 short an_gain_mB[HPI_MAX_CHANNELS];
1568 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1569 ucontrol->value.integer.value[0] =
1570 an_gain_mB[0] / HPI_UNITS_PER_dB;
1571 ucontrol->value.integer.value[1] =
1572 an_gain_mB[1] / HPI_UNITS_PER_dB;
1577 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1578 struct snd_ctl_elem_value *ucontrol)
1581 u32 h_control = kcontrol->private_value;
1582 short an_gain_mB[HPI_MAX_CHANNELS];
1585 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1587 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1588 /* change = asihpi->mixer_level[addr][0] != left ||
1589 asihpi->mixer_level[addr][1] != right;
1592 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1596 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1598 static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1599 struct hpi_control *hpi_ctl)
1601 struct snd_card *card = asihpi->card;
1602 struct snd_kcontrol_new snd_control;
1604 /* can't use 'volume' cos some nodes have volume as well */
1605 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1606 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1607 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1608 snd_control.info = snd_asihpi_level_info;
1609 snd_control.get = snd_asihpi_level_get;
1610 snd_control.put = snd_asihpi_level_put;
1611 snd_control.tlv.p = db_scale_level;
1613 return ctl_add(card, &snd_control, asihpi);
1616 /*------------------------------------------------------------
1618 ------------------------------------------------------------*/
1621 static const char * const asihpi_aesebu_format_names[] = {
1622 "N/A", "S/PDIF", "AES/EBU" };
1624 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_info *uinfo)
1627 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1629 uinfo->value.enumerated.items = 3;
1631 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1632 uinfo->value.enumerated.item =
1633 uinfo->value.enumerated.items - 1;
1635 strcpy(uinfo->value.enumerated.name,
1636 asihpi_aesebu_format_names[uinfo->value.enumerated.item]);
1641 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1642 struct snd_ctl_elem_value *ucontrol,
1643 u16 (*func)(u32, u16 *))
1645 u32 h_control = kcontrol->private_value;
1648 err = func(h_control, &source);
1650 /* default to N/A */
1651 ucontrol->value.enumerated.item[0] = 0;
1652 /* return success but set the control to N/A */
1655 if (source == HPI_AESEBU_FORMAT_SPDIF)
1656 ucontrol->value.enumerated.item[0] = 1;
1657 if (source == HPI_AESEBU_FORMAT_AESEBU)
1658 ucontrol->value.enumerated.item[0] = 2;
1663 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1664 struct snd_ctl_elem_value *ucontrol,
1665 u16 (*func)(u32, u16))
1667 u32 h_control = kcontrol->private_value;
1669 /* default to S/PDIF */
1670 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1672 if (ucontrol->value.enumerated.item[0] == 1)
1673 source = HPI_AESEBU_FORMAT_SPDIF;
1674 if (ucontrol->value.enumerated.item[0] == 2)
1675 source = HPI_AESEBU_FORMAT_AESEBU;
1677 if (func(h_control, source) != 0)
1683 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1684 struct snd_ctl_elem_value *ucontrol) {
1685 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1686 hpi_aesebu_receiver_get_format);
1689 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol) {
1691 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1692 hpi_aesebu_receiver_set_format);
1695 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1696 struct snd_ctl_elem_info *uinfo)
1698 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1701 uinfo->value.integer.min = 0;
1702 uinfo->value.integer.max = 0X1F;
1703 uinfo->value.integer.step = 1;
1708 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_value *ucontrol) {
1711 u32 h_control = kcontrol->private_value;
1714 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1715 h_control, &status));
1716 ucontrol->value.integer.value[0] = status;
1720 static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1721 struct hpi_control *hpi_ctl)
1723 struct snd_card *card = asihpi->card;
1724 struct snd_kcontrol_new snd_control;
1726 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1727 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1728 snd_control.info = snd_asihpi_aesebu_format_info;
1729 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1730 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1733 if (ctl_add(card, &snd_control, asihpi) < 0)
1736 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
1737 snd_control.access =
1738 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1739 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1740 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1742 return ctl_add(card, &snd_control, asihpi);
1745 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol) {
1747 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1748 hpi_aesebu_transmitter_get_format);
1751 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1752 struct snd_ctl_elem_value *ucontrol) {
1753 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1754 hpi_aesebu_transmitter_set_format);
1758 static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1759 struct hpi_control *hpi_ctl)
1761 struct snd_card *card = asihpi->card;
1762 struct snd_kcontrol_new snd_control;
1764 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1765 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1766 snd_control.info = snd_asihpi_aesebu_format_info;
1767 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1768 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1770 return ctl_add(card, &snd_control, asihpi);
1773 /*------------------------------------------------------------
1775 ------------------------------------------------------------*/
1779 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_info *uinfo)
1782 u32 h_control = kcontrol->private_value;
1787 for (idx = 0; idx < 3; idx++) {
1788 err = hpi_tuner_query_gain(h_control,
1789 idx, &gain_range[idx]);
1794 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1796 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1797 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1798 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1802 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1803 struct snd_ctl_elem_value *ucontrol)
1806 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1808 u32 h_control = kcontrol->private_value;
1811 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
1812 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1817 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1818 struct snd_ctl_elem_value *ucontrol)
1821 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1823 u32 h_control = kcontrol->private_value;
1826 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1827 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
1834 static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1835 u16 *band_list, u32 len) {
1836 u32 h_control = kcontrol->private_value;
1840 for (i = 0; i < len; i++) {
1841 err = hpi_tuner_query_band(
1842 h_control, i, &band_list[i]);
1847 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1853 static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1854 struct snd_ctl_elem_info *uinfo)
1856 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1859 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1860 HPI_TUNER_BAND_LAST);
1865 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1867 uinfo->value.enumerated.items = num_bands;
1869 if (num_bands > 0) {
1870 if (uinfo->value.enumerated.item >=
1871 uinfo->value.enumerated.items)
1872 uinfo->value.enumerated.item =
1873 uinfo->value.enumerated.items - 1;
1875 strcpy(uinfo->value.enumerated.name,
1876 asihpi_tuner_band_names[
1877 tuner_bands[uinfo->value.enumerated.item]]);
1883 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1884 struct snd_ctl_elem_value *ucontrol)
1886 u32 h_control = kcontrol->private_value;
1888 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1891 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1894 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1895 HPI_TUNER_BAND_LAST);
1897 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1899 ucontrol->value.enumerated.item[0] = -1;
1900 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1901 if (tuner_bands[idx] == band) {
1902 ucontrol->value.enumerated.item[0] = idx;
1909 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1910 struct snd_ctl_elem_value *ucontrol)
1913 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1915 u32 h_control = kcontrol->private_value;
1918 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1921 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1922 HPI_TUNER_BAND_LAST);
1924 idx = ucontrol->value.enumerated.item[0];
1925 if (idx >= ARRAY_SIZE(tuner_bands))
1926 idx = ARRAY_SIZE(tuner_bands) - 1;
1927 band = tuner_bands[idx];
1928 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1935 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1936 struct snd_ctl_elem_info *uinfo)
1938 u32 h_control = kcontrol->private_value;
1940 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1941 u16 num_bands = 0, band_iter, idx;
1942 u32 freq_range[3], temp_freq_range[3];
1944 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1945 HPI_TUNER_BAND_LAST);
1947 freq_range[0] = INT_MAX;
1949 freq_range[2] = INT_MAX;
1951 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1952 for (idx = 0; idx < 3; idx++) {
1953 err = hpi_tuner_query_frequency(h_control,
1954 idx, tuner_bands[band_iter],
1955 &temp_freq_range[idx]);
1960 /* skip band with bogus stepping */
1961 if (temp_freq_range[2] <= 0)
1964 if (temp_freq_range[0] < freq_range[0])
1965 freq_range[0] = temp_freq_range[0];
1966 if (temp_freq_range[1] > freq_range[1])
1967 freq_range[1] = temp_freq_range[1];
1968 if (temp_freq_range[2] < freq_range[2])
1969 freq_range[2] = temp_freq_range[2];
1972 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1974 uinfo->value.integer.min = ((int)freq_range[0]);
1975 uinfo->value.integer.max = ((int)freq_range[1]);
1976 uinfo->value.integer.step = ((int)freq_range[2]);
1980 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1981 struct snd_ctl_elem_value *ucontrol)
1983 u32 h_control = kcontrol->private_value;
1986 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
1987 ucontrol->value.integer.value[0] = freq;
1992 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
1993 struct snd_ctl_elem_value *ucontrol)
1995 u32 h_control = kcontrol->private_value;
1998 freq = ucontrol->value.integer.value[0];
1999 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
2004 /* Tuner control group initializer */
2005 static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
2006 struct hpi_control *hpi_ctl)
2008 struct snd_card *card = asihpi->card;
2009 struct snd_kcontrol_new snd_control;
2011 snd_control.private_value = hpi_ctl->h_control;
2012 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2014 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
2015 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
2016 snd_control.info = snd_asihpi_tuner_gain_info;
2017 snd_control.get = snd_asihpi_tuner_gain_get;
2018 snd_control.put = snd_asihpi_tuner_gain_put;
2020 if (ctl_add(card, &snd_control, asihpi) < 0)
2024 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
2025 snd_control.info = snd_asihpi_tuner_band_info;
2026 snd_control.get = snd_asihpi_tuner_band_get;
2027 snd_control.put = snd_asihpi_tuner_band_put;
2029 if (ctl_add(card, &snd_control, asihpi) < 0)
2032 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2033 snd_control.info = snd_asihpi_tuner_freq_info;
2034 snd_control.get = snd_asihpi_tuner_freq_get;
2035 snd_control.put = snd_asihpi_tuner_freq_put;
2037 return ctl_add(card, &snd_control, asihpi);
2040 /*------------------------------------------------------------
2042 ------------------------------------------------------------*/
2043 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2044 struct snd_ctl_elem_info *uinfo)
2046 u32 h_control = kcontrol->private_value;
2049 err = hpi_meter_query_channels(h_control, &count);
2051 count = HPI_MAX_CHANNELS;
2053 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2054 uinfo->count = count;
2055 uinfo->value.integer.min = 0;
2056 uinfo->value.integer.max = 0x7FFFFFFF;
2060 /* linear values for 10dB steps */
2061 static int log2lin[] = {
2062 0x7FFFFFFF, /* 0dB */
2068 2147484, /* -60dB */
2083 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2084 struct snd_ctl_elem_value *ucontrol)
2086 u32 h_control = kcontrol->private_value;
2087 short an_gain_mB[HPI_MAX_CHANNELS], i;
2090 err = hpi_meter_get_peak(h_control, an_gain_mB);
2092 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2094 ucontrol->value.integer.value[i] = 0;
2095 } else if (an_gain_mB[i] >= 0) {
2096 ucontrol->value.integer.value[i] =
2097 an_gain_mB[i] << 16;
2099 /* -ve is log value in millibels < -60dB,
2100 * convert to (roughly!) linear,
2102 ucontrol->value.integer.value[i] =
2103 log2lin[an_gain_mB[i] / -1000];
2109 static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2110 struct hpi_control *hpi_ctl, int subidx)
2112 struct snd_card *card = asihpi->card;
2113 struct snd_kcontrol_new snd_control;
2115 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2116 snd_control.access =
2117 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2118 snd_control.info = snd_asihpi_meter_info;
2119 snd_control.get = snd_asihpi_meter_get;
2121 snd_control.index = subidx;
2123 return ctl_add(card, &snd_control, asihpi);
2126 /*------------------------------------------------------------
2127 Multiplexer controls
2128 ------------------------------------------------------------*/
2129 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2131 u32 h_control = snd_control->private_value;
2132 struct hpi_control hpi_ctl;
2134 for (s = 0; s < 32; s++) {
2135 err = hpi_multiplexer_query_source(h_control, s,
2146 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2147 struct snd_ctl_elem_info *uinfo)
2150 u16 src_node_type, src_node_index;
2151 u32 h_control = kcontrol->private_value;
2153 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2155 uinfo->value.enumerated.items =
2156 snd_card_asihpi_mux_count_sources(kcontrol);
2158 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2159 uinfo->value.enumerated.item =
2160 uinfo->value.enumerated.items - 1;
2163 hpi_multiplexer_query_source(h_control,
2164 uinfo->value.enumerated.item,
2165 &src_node_type, &src_node_index);
2167 sprintf(uinfo->value.enumerated.name, "%s %d",
2168 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2173 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2174 struct snd_ctl_elem_value *ucontrol)
2176 u32 h_control = kcontrol->private_value;
2177 u16 source_type, source_index;
2178 u16 src_node_type, src_node_index;
2181 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2182 &source_type, &source_index));
2183 /* Should cache this search result! */
2184 for (s = 0; s < 256; s++) {
2185 if (hpi_multiplexer_query_source(h_control, s,
2186 &src_node_type, &src_node_index))
2189 if ((source_type == src_node_type)
2190 && (source_index == src_node_index)) {
2191 ucontrol->value.enumerated.item[0] = s;
2195 snd_printd(KERN_WARNING
2196 "Control %x failed to match mux source %hu %hu\n",
2197 h_control, source_type, source_index);
2198 ucontrol->value.enumerated.item[0] = 0;
2202 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2203 struct snd_ctl_elem_value *ucontrol)
2206 u32 h_control = kcontrol->private_value;
2207 u16 source_type, source_index;
2212 e = hpi_multiplexer_query_source(h_control,
2213 ucontrol->value.enumerated.item[0],
2214 &source_type, &source_index);
2217 hpi_multiplexer_set_source(h_control,
2218 source_type, source_index));
2223 static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2224 struct hpi_control *hpi_ctl)
2226 struct snd_card *card = asihpi->card;
2227 struct snd_kcontrol_new snd_control;
2229 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2230 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2231 snd_control.info = snd_asihpi_mux_info;
2232 snd_control.get = snd_asihpi_mux_get;
2233 snd_control.put = snd_asihpi_mux_put;
2235 return ctl_add(card, &snd_control, asihpi);
2239 /*------------------------------------------------------------
2240 Channel mode controls
2241 ------------------------------------------------------------*/
2242 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2243 struct snd_ctl_elem_info *uinfo)
2245 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2248 "From Left", "From Right",
2249 "To Left", "To Right"
2252 u32 h_control = kcontrol->private_value;
2256 int valid_modes = 0;
2258 /* HPI channel mode values can be from 1 to 6
2259 Some adapters only support a contiguous subset
2261 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2262 if (!hpi_channel_mode_query_mode(
2263 h_control, i, &mode)) {
2264 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 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;
2392 u32 h_control = kcontrol->private_value;
2395 item = ucontrol->value.enumerated.item[0];
2396 if (item >= clkcache->count)
2397 item = clkcache->count-1;
2399 hpi_handle_error(hpi_sample_clock_set_source(
2400 h_control, clkcache->s[item].source));
2402 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2403 hpi_handle_error(hpi_sample_clock_set_source_index(
2404 h_control, clkcache->s[item].index));
2408 /*------------------------------------------------------------
2410 ------------------------------------------------------------*/
2411 /* Need to change this to enumerated control with list of rates */
2412 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_info *uinfo)
2415 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2417 uinfo->value.integer.min = 8000;
2418 uinfo->value.integer.max = 192000;
2419 uinfo->value.integer.step = 100;
2424 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2425 struct snd_ctl_elem_value *ucontrol)
2427 u32 h_control = kcontrol->private_value;
2431 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2433 ucontrol->value.integer.value[0] = rate;
2435 ucontrol->value.integer.value[0] = 0;
2439 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2440 struct snd_ctl_elem_value *ucontrol)
2443 u32 h_control = kcontrol->private_value;
2445 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2446 asihpi->mixer_clkrate[addr][1] != right;
2449 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2450 ucontrol->value.integer.value[0]));
2454 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_info *uinfo)
2457 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2459 uinfo->value.integer.min = 8000;
2460 uinfo->value.integer.max = 192000;
2461 uinfo->value.integer.step = 100;
2466 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2467 struct snd_ctl_elem_value *ucontrol)
2469 u32 h_control = kcontrol->private_value;
2473 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2475 ucontrol->value.integer.value[0] = rate;
2477 ucontrol->value.integer.value[0] = 0;
2481 static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2482 struct hpi_control *hpi_ctl)
2484 struct snd_card *card = asihpi->card;
2485 struct snd_kcontrol_new snd_control;
2487 struct clk_cache *clkcache = &asihpi->cc;
2488 u32 hSC = hpi_ctl->h_control;
2493 snd_control.private_value = hpi_ctl->h_control;
2495 clkcache->has_local = 0;
2497 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2498 if (hpi_sample_clock_query_source(hSC,
2501 clkcache->s[i].source = source;
2502 clkcache->s[i].index = 0;
2503 clkcache->s[i].name = sampleclock_sources[source];
2504 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2506 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2507 clkcache->has_local = 1;
2510 /* already will have picked up index 0 above */
2511 for (j = 1; j < 8; j++) {
2512 if (hpi_sample_clock_query_source_index(hSC,
2513 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2516 clkcache->s[i].source =
2517 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2518 clkcache->s[i].index = j;
2519 clkcache->s[i].name = sampleclock_sources[
2520 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2523 clkcache->count = i;
2525 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2526 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2527 snd_control.info = snd_asihpi_clksrc_info;
2528 snd_control.get = snd_asihpi_clksrc_get;
2529 snd_control.put = snd_asihpi_clksrc_put;
2530 if (ctl_add(card, &snd_control, asihpi) < 0)
2534 if (clkcache->has_local) {
2535 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2536 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2537 snd_control.info = snd_asihpi_clklocal_info;
2538 snd_control.get = snd_asihpi_clklocal_get;
2539 snd_control.put = snd_asihpi_clklocal_put;
2542 if (ctl_add(card, &snd_control, asihpi) < 0)
2546 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2547 snd_control.access =
2548 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2549 snd_control.info = snd_asihpi_clkrate_info;
2550 snd_control.get = snd_asihpi_clkrate_get;
2552 return ctl_add(card, &snd_control, asihpi);
2554 /*------------------------------------------------------------
2556 ------------------------------------------------------------*/
2558 static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2560 struct snd_card *card;
2561 unsigned int idx = 0;
2562 unsigned int subindex = 0;
2564 struct hpi_control hpi_ctl, prev_ctl;
2566 if (snd_BUG_ON(!asihpi))
2568 card = asihpi->card;
2569 strcpy(card->mixername, "Asihpi Mixer");
2572 hpi_mixer_open(asihpi->hpi->adapter->index,
2574 hpi_handle_error(err);
2578 memset(&prev_ctl, 0, sizeof(prev_ctl));
2579 prev_ctl.control_type = -1;
2581 for (idx = 0; idx < 2000; idx++) {
2582 err = hpi_mixer_get_control_by_index(
2585 &hpi_ctl.src_node_type,
2586 &hpi_ctl.src_node_index,
2587 &hpi_ctl.dst_node_type,
2588 &hpi_ctl.dst_node_index,
2589 &hpi_ctl.control_type,
2590 &hpi_ctl.h_control);
2592 if (err == HPI_ERROR_CONTROL_DISABLED) {
2594 snd_printk(KERN_INFO
2595 "Disabled HPI Control(%d)\n",
2603 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2604 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2606 /* ASI50xx in SSX mode has multiple meters on the same node.
2607 Use subindex to create distinct ALSA controls
2608 for any duplicated controls.
2610 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2611 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2612 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2613 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2614 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2621 switch (hpi_ctl.control_type) {
2622 case HPI_CONTROL_VOLUME:
2623 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2625 case HPI_CONTROL_LEVEL:
2626 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2628 case HPI_CONTROL_MULTIPLEXER:
2629 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2631 case HPI_CONTROL_CHANNEL_MODE:
2632 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2634 case HPI_CONTROL_METER:
2635 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2637 case HPI_CONTROL_SAMPLECLOCK:
2638 err = snd_asihpi_sampleclock_add(
2641 case HPI_CONTROL_CONNECTION: /* ignore these */
2643 case HPI_CONTROL_TUNER:
2644 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2646 case HPI_CONTROL_AESEBU_TRANSMITTER:
2647 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2649 case HPI_CONTROL_AESEBU_RECEIVER:
2650 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2652 case HPI_CONTROL_VOX:
2653 case HPI_CONTROL_BITSTREAM:
2654 case HPI_CONTROL_MICROPHONE:
2655 case HPI_CONTROL_PARAMETRIC_EQ:
2656 case HPI_CONTROL_COMPANDER:
2659 snd_printk(KERN_INFO
2660 "Untranslated HPI Control"
2661 "(%d) %d %d %d %d %d\n",
2663 hpi_ctl.control_type,
2664 hpi_ctl.src_node_type,
2665 hpi_ctl.src_node_index,
2666 hpi_ctl.dst_node_type,
2667 hpi_ctl.dst_node_index);
2673 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2674 hpi_handle_error(err);
2676 snd_printk(KERN_INFO "%d mixer controls found\n", idx);
2681 /*------------------------------------------------------------
2683 ------------------------------------------------------------*/
2686 snd_asihpi_proc_read(struct snd_info_entry *entry,
2687 struct snd_info_buffer *buffer)
2689 struct snd_card_asihpi *asihpi = entry->private_data;
2702 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2704 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2705 &num_outstreams, &num_instreams,
2706 &version, &serial_number, &type));
2709 "Adapter type ASI%4X\nHardware Index %d\n"
2710 "%d outstreams\n%d instreams\n",
2711 type, asihpi->hpi->adapter->index,
2712 num_outstreams, num_instreams);
2715 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2716 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
2717 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2719 err = hpi_mixer_get_control(asihpi->h_mixer,
2720 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2721 HPI_CONTROL_SAMPLECLOCK, &h_control);
2724 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
2725 err += hpi_sample_clock_get_source(h_control, &source);
2728 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
2729 rate, sampleclock_sources[source]);
2733 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2735 struct snd_info_entry *entry;
2737 if (!snd_card_proc_new(asihpi->card, "info", &entry))
2738 snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read);
2741 /*------------------------------------------------------------
2743 ------------------------------------------------------------*/
2745 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2747 if (enable_hpi_hwdep)
2754 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2756 if (enable_hpi_hwdep)
2757 return asihpi_hpi_release(file);
2762 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2763 unsigned int cmd, unsigned long arg)
2765 if (enable_hpi_hwdep)
2766 return asihpi_hpi_ioctl(file, cmd, arg);
2772 /* results in /dev/snd/hwC#D0 file for each card with index #
2773 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2775 static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi,
2776 int device, struct snd_hwdep **rhwdep)
2778 struct snd_hwdep *hw;
2783 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2786 strcpy(hw->name, "asihpi (HPI)");
2787 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2788 hw->ops.open = snd_asihpi_hpi_open;
2789 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2790 hw->ops.release = snd_asihpi_hpi_release;
2791 hw->private_data = asihpi;
2797 /*------------------------------------------------------------
2799 ------------------------------------------------------------*/
2800 static int snd_asihpi_probe(struct pci_dev *pci_dev,
2801 const struct pci_device_id *pci_id)
2804 struct hpi_adapter *hpi;
2805 struct snd_card *card;
2806 struct snd_card_asihpi *asihpi;
2813 if (dev >= SNDRV_CARDS)
2816 /* Should this be enable[hpi->index] ? */
2822 /* Initialise low-level HPI driver */
2823 err = asihpi_adapter_probe(pci_dev, pci_id);
2827 hpi = pci_get_drvdata(pci_dev);
2828 adapter_index = hpi->adapter->index;
2829 /* first try to give the card the same index as its hardware index */
2830 err = snd_card_create(adapter_index,
2831 id[adapter_index], THIS_MODULE,
2832 sizeof(struct snd_card_asihpi),
2835 /* if that fails, try the default index==next available */
2837 snd_card_create(index[dev], id[dev],
2839 sizeof(struct snd_card_asihpi),
2843 snd_printk(KERN_WARNING
2844 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2845 adapter_index, card->number);
2848 snd_card_set_dev(card, &pci_dev->dev);
2850 asihpi = card->private_data;
2851 asihpi->card = card;
2852 asihpi->pci = pci_dev;
2855 snd_printk(KERN_INFO "adapter ID=%4X index=%d\n",
2856 asihpi->hpi->adapter->type, adapter_index);
2858 err = hpi_adapter_get_property(adapter_index,
2859 HPI_ADAPTER_PROPERTY_CAPS1,
2860 NULL, &asihpi->support_grouping);
2862 asihpi->support_grouping = 0;
2864 err = hpi_adapter_get_property(adapter_index,
2865 HPI_ADAPTER_PROPERTY_CAPS2,
2866 &asihpi->support_mrx, NULL);
2868 asihpi->support_mrx = 0;
2870 err = hpi_adapter_get_property(adapter_index,
2871 HPI_ADAPTER_PROPERTY_INTERVAL,
2872 NULL, &asihpi->update_interval_frames);
2874 asihpi->update_interval_frames = 512;
2876 if (!asihpi->can_dma)
2877 asihpi->update_interval_frames *= 2;
2879 hpi_handle_error(hpi_instream_open(adapter_index,
2882 err = hpi_instream_host_buffer_free(h_stream);
2883 asihpi->can_dma = (!err);
2885 hpi_handle_error(hpi_instream_close(h_stream));
2887 err = hpi_adapter_get_property(adapter_index,
2888 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2889 &asihpi->in_max_chans, &asihpi->out_max_chans);
2891 asihpi->in_max_chans = 2;
2892 asihpi->out_max_chans = 2;
2895 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2896 asihpi->out_min_chans = asihpi->out_max_chans;
2897 asihpi->in_min_chans = asihpi->in_max_chans;
2898 asihpi->support_grouping = 0;
2900 asihpi->out_min_chans = 1;
2901 asihpi->in_min_chans = 1;
2904 snd_printk(KERN_INFO "Has dma:%d, grouping:%d, mrx:%d\n",
2906 asihpi->support_grouping,
2910 err = snd_card_asihpi_pcm_new(asihpi, 0);
2912 snd_printk(KERN_ERR "pcm_new failed\n");
2915 err = snd_card_asihpi_mixer_new(asihpi);
2917 snd_printk(KERN_ERR "mixer_new failed\n");
2921 err = hpi_mixer_get_control(asihpi->h_mixer,
2922 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2923 HPI_CONTROL_SAMPLECLOCK, &h_control);
2926 err = hpi_sample_clock_set_local_rate(
2927 h_control, adapter_fs);
2929 snd_asihpi_proc_init(asihpi);
2931 /* always create, can be enabled or disabled dynamically
2932 by enable_hwdep module param*/
2933 snd_asihpi_hpi_new(asihpi, 0, NULL);
2935 strcpy(card->driver, "ASIHPI");
2937 sprintf(card->shortname, "AudioScience ASI%4X",
2938 asihpi->hpi->adapter->type);
2939 sprintf(card->longname, "%s %i",
2940 card->shortname, adapter_index);
2941 err = snd_card_register(card);
2944 hpi->snd_card = card;
2949 snd_card_free(card);
2950 snd_printk(KERN_ERR "snd_asihpi_probe error %d\n", err);
2955 static void snd_asihpi_remove(struct pci_dev *pci_dev)
2957 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2958 snd_card_free(hpi->snd_card);
2959 hpi->snd_card = NULL;
2960 asihpi_adapter_remove(pci_dev);
2963 static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl) = {
2964 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2965 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2966 (kernel_ulong_t)HPI_6205},
2967 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2968 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2969 (kernel_ulong_t)HPI_6000},
2972 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2974 static struct pci_driver driver = {
2975 .name = KBUILD_MODNAME,
2976 .id_table = asihpi_pci_tbl,
2977 .probe = snd_asihpi_probe,
2978 .remove = snd_asihpi_remove,
2979 #ifdef CONFIG_PM_SLEEP
2980 /* .suspend = snd_asihpi_suspend,
2981 .resume = snd_asihpi_resume, */
2985 static int __init snd_asihpi_init(void)
2988 return pci_register_driver(&driver);
2991 static void __exit snd_asihpi_exit(void)
2994 pci_unregister_driver(&driver);
2998 module_init(snd_asihpi_init)
2999 module_exit(snd_asihpi_exit)