1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) by AudioScience Inc <support@audioscience.com>
6 * The following is not a condition of use, merely a request:
7 * If you modify this program, particularly if you fix errors, AudioScience Inc
8 * would appreciate it if you grant us the right to use those modifications
9 * for any purpose including commercial applications.
12 #include "hpi_internal.h"
13 #include "hpi_version.h"
14 #include "hpimsginit.h"
18 #include <linux/pci.h>
19 #include <linux/init.h>
20 #include <linux/jiffies.h>
21 #include <linux/slab.h>
22 #include <linux/time.h>
23 #include <linux/wait.h>
24 #include <linux/module.h>
25 #include <sound/core.h>
26 #include <sound/control.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/info.h>
30 #include <sound/initval.h>
31 #include <sound/tlv.h>
32 #include <sound/hwdep.h>
34 MODULE_LICENSE("GPL");
35 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
36 MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx "
39 #if defined CONFIG_SND_DEBUG_VERBOSE
41 * snd_printddd - very verbose debug printk
42 * @format: format string
44 * Works like snd_printk() for debugging purposes.
45 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
46 * Must set snd module debug parameter to 3 to enable at runtime.
48 #define snd_printddd(format, args...) \
49 __snd_printk(3, __FILE__, __LINE__, format, ##args)
51 #define snd_printddd(format, args...) do { } while (0)
54 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
55 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
56 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
57 static bool enable_hpi_hwdep = 1;
59 module_param_array(index, int, NULL, 0444);
60 MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
62 module_param_array(id, charp, NULL, 0444);
63 MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
65 module_param_array(enable, bool, NULL, 0444);
66 MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
68 module_param(enable_hpi_hwdep, bool, 0644);
69 MODULE_PARM_DESC(enable_hpi_hwdep,
70 "ALSA enable HPI hwdep for AudioScience soundcard ");
73 #ifdef KERNEL_ALSA_BUILD
74 static char *build_info = "Built using headers from kernel source";
75 module_param(build_info, charp, 0444);
76 MODULE_PARM_DESC(build_info, "Built using headers from kernel source");
78 static char *build_info = "Built within ALSA source";
79 module_param(build_info, charp, 0444);
80 MODULE_PARM_DESC(build_info, "Built within ALSA source");
83 /* set to 1 to dump every control from adapter to log */
84 static const int mixer_dump;
86 #define DEFAULT_SAMPLERATE 44100
87 static int adapter_fs = DEFAULT_SAMPLERATE;
91 #define PERIOD_BYTES_MIN 2048
92 #define BUFFER_BYTES_MAX (512 * 1024)
94 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
105 struct clk_source s[MAX_CLOCKSOURCES];
109 struct snd_card_asihpi {
110 struct snd_card *card;
112 struct hpi_adapter *hpi;
114 /* In low latency mode there is only one stream, a pointer to its
115 * private data is stored here on trigger and cleared on stop.
116 * The interrupt handler uses it as a parameter when calling
117 * snd_card_asihpi_timer_function().
119 struct snd_card_asihpi_pcm *llmode_streampriv;
120 void (*pcm_start)(struct snd_pcm_substream *substream);
121 void (*pcm_stop)(struct snd_pcm_substream *substream);
127 u16 support_grouping;
129 u16 update_interval_frames;
136 /* Per stream data */
137 struct snd_card_asihpi_pcm {
138 struct timer_list timer;
139 unsigned int respawn_timer;
140 unsigned int hpi_buffer_attached;
141 unsigned int buffer_bytes;
142 unsigned int period_bytes;
143 unsigned int bytes_per_sec;
144 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
145 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
146 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
147 unsigned int drained_count;
148 struct snd_pcm_substream *substream;
150 struct hpi_format format;
153 /* universal stream verbs work with out or in stream handles */
155 /* Functions to allow driver to give a buffer to HPI for busmastering */
157 static u16 hpi_stream_host_buffer_attach(
158 u32 h_stream, /* handle to outstream. */
159 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
163 struct hpi_message hm;
164 struct hpi_response hr;
165 unsigned int obj = hpi_handle_object(h_stream);
168 return HPI_ERROR_INVALID_OBJ;
169 hpi_init_message_response(&hm, &hr, obj,
170 obj == HPI_OBJ_OSTREAM ?
171 HPI_OSTREAM_HOSTBUFFER_ALLOC :
172 HPI_ISTREAM_HOSTBUFFER_ALLOC);
174 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
177 hm.u.d.u.buffer.buffer_size = size_in_bytes;
178 hm.u.d.u.buffer.pci_address = pci_address;
179 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
180 hpi_send_recv(&hm, &hr);
184 static u16 hpi_stream_host_buffer_detach(u32 h_stream)
186 struct hpi_message hm;
187 struct hpi_response hr;
188 unsigned int obj = hpi_handle_object(h_stream);
191 return HPI_ERROR_INVALID_OBJ;
193 hpi_init_message_response(&hm, &hr, obj,
194 obj == HPI_OBJ_OSTREAM ?
195 HPI_OSTREAM_HOSTBUFFER_FREE :
196 HPI_ISTREAM_HOSTBUFFER_FREE);
198 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
200 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
201 hpi_send_recv(&hm, &hr);
205 static inline u16 hpi_stream_start(u32 h_stream)
207 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
208 return hpi_outstream_start(h_stream);
210 return hpi_instream_start(h_stream);
213 static inline u16 hpi_stream_stop(u32 h_stream)
215 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
216 return hpi_outstream_stop(h_stream);
218 return hpi_instream_stop(h_stream);
221 static inline u16 hpi_stream_get_info_ex(
225 u32 *pdata_in_buffer,
231 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
232 e = hpi_outstream_get_info_ex(h_stream, pw_state,
233 pbuffer_size, pdata_in_buffer,
234 psample_count, pauxiliary_data);
236 e = hpi_instream_get_info_ex(h_stream, pw_state,
237 pbuffer_size, pdata_in_buffer,
238 psample_count, pauxiliary_data);
242 static inline u16 hpi_stream_group_add(
246 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
247 return hpi_outstream_group_add(h_master, h_stream);
249 return hpi_instream_group_add(h_master, h_stream);
252 static inline u16 hpi_stream_group_reset(u32 h_stream)
254 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
255 return hpi_outstream_group_reset(h_stream);
257 return hpi_instream_group_reset(h_stream);
260 static u16 handle_error(u16 err, int line, char *filename)
264 "in file %s, line %d: HPI error %d\n",
265 filename, line, err);
269 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
271 /***************************** GENERAL PCM ****************/
273 static void print_hwparams(struct snd_pcm_substream *substream,
274 struct snd_pcm_hw_params *p)
277 snd_pcm_debug_name(substream, name, sizeof(name));
278 snd_printdd("%s HWPARAMS\n", name);
279 snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n",
280 params_rate(p), params_channels(p),
281 params_format(p), params_subformat(p));
282 snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n",
283 params_buffer_bytes(p), params_period_bytes(p),
284 params_period_size(p), params_periods(p));
285 snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n",
286 params_buffer_size(p), params_access(p),
287 params_rate(p) * params_channels(p) *
288 snd_pcm_format_width(params_format(p)) / 8);
291 #define INVALID_FORMAT (__force snd_pcm_format_t)(-1)
293 static const snd_pcm_format_t hpi_to_alsa_formats[] = {
294 INVALID_FORMAT, /* INVALID */
295 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
296 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
297 INVALID_FORMAT, /* HPI_FORMAT_MPEG_L1 3 */
298 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
299 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
300 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC2 6 */
301 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC3 7 */
302 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
303 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
304 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
305 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
306 INVALID_FORMAT, /* HPI_FORMAT_RAW_BITSTREAM 12 */
307 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
308 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
310 /* ALSA can't handle 3 byte sample size together with power-of-2
311 * constraint on buffer_bytes, so disable this format
315 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
320 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
325 for (format = HPI_FORMAT_PCM8_UNSIGNED;
326 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
327 if (hpi_to_alsa_formats[format] == alsa_format) {
328 *hpi_format = format;
333 snd_printd(KERN_WARNING "failed match for alsa format %d\n",
339 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
340 struct snd_pcm_hardware *pcmhw)
346 unsigned int rate_min = 200000;
347 unsigned int rate_max = 0;
348 unsigned int rates = 0;
350 if (asihpi->support_mrx) {
351 rates |= SNDRV_PCM_RATE_CONTINUOUS;
352 rates |= SNDRV_PCM_RATE_8000_96000;
356 /* on cards without SRC,
357 valid rates are determined by sampleclock */
358 err = hpi_mixer_get_control(asihpi->h_mixer,
359 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
360 HPI_CONTROL_SAMPLECLOCK, &h_control);
362 dev_err(&asihpi->pci->dev,
363 "No local sampleclock, err %d\n", err);
366 for (idx = -1; idx < 100; idx++) {
368 if (hpi_sample_clock_get_sample_rate(h_control,
371 } else if (hpi_sample_clock_query_local_rate(h_control,
372 idx, &sample_rate)) {
376 rate_min = min(rate_min, sample_rate);
377 rate_max = max(rate_max, sample_rate);
379 switch (sample_rate) {
381 rates |= SNDRV_PCM_RATE_5512;
384 rates |= SNDRV_PCM_RATE_8000;
387 rates |= SNDRV_PCM_RATE_11025;
390 rates |= SNDRV_PCM_RATE_16000;
393 rates |= SNDRV_PCM_RATE_22050;
396 rates |= SNDRV_PCM_RATE_32000;
399 rates |= SNDRV_PCM_RATE_44100;
402 rates |= SNDRV_PCM_RATE_48000;
405 rates |= SNDRV_PCM_RATE_64000;
408 rates |= SNDRV_PCM_RATE_88200;
411 rates |= SNDRV_PCM_RATE_96000;
414 rates |= SNDRV_PCM_RATE_176400;
417 rates |= SNDRV_PCM_RATE_192000;
419 default: /* some other rate */
420 rates |= SNDRV_PCM_RATE_KNOT;
425 pcmhw->rates = rates;
426 pcmhw->rate_min = rate_min;
427 pcmhw->rate_max = rate_max;
430 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
431 struct snd_pcm_hw_params *params)
433 struct snd_pcm_runtime *runtime = substream->runtime;
434 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
435 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
439 unsigned int bytes_per_sec;
441 print_hwparams(substream, params);
442 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
446 hpi_handle_error(hpi_format_create(&dpcm->format,
447 params_channels(params),
448 format, params_rate(params), 0, 0));
450 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
451 if (hpi_instream_reset(dpcm->h_stream) != 0)
454 if (hpi_instream_set_format(
455 dpcm->h_stream, &dpcm->format) != 0)
459 dpcm->hpi_buffer_attached = 0;
461 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
462 params_buffer_bytes(params), runtime->dma_addr);
465 "stream_host_buffer_attach success %u %lu\n",
466 params_buffer_bytes(params),
467 (unsigned long)runtime->dma_addr);
469 snd_printd("stream_host_buffer_attach error %d\n",
474 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
475 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
477 bytes_per_sec = params_rate(params) * params_channels(params);
478 width = snd_pcm_format_width(params_format(params));
479 bytes_per_sec *= width;
481 if (width < 0 || bytes_per_sec == 0)
484 dpcm->bytes_per_sec = bytes_per_sec;
485 dpcm->buffer_bytes = params_buffer_bytes(params);
486 dpcm->period_bytes = params_period_bytes(params);
492 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
494 struct snd_pcm_runtime *runtime = substream->runtime;
495 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
496 if (dpcm->hpi_buffer_attached)
497 hpi_stream_host_buffer_detach(dpcm->h_stream);
502 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
504 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
508 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
511 struct snd_pcm_runtime *runtime = substream->runtime;
512 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
517 expiry = max(expiry, 1); /* don't let it be zero! */
518 mod_timer(&dpcm->timer, jiffies + expiry);
519 dpcm->respawn_timer = 1;
522 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
524 struct snd_pcm_runtime *runtime = substream->runtime;
525 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
527 dpcm->respawn_timer = 0;
528 del_timer(&dpcm->timer);
531 static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
533 struct snd_card_asihpi_pcm *dpcm;
534 struct snd_card_asihpi *card;
536 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
537 card = snd_pcm_substream_chip(substream);
539 WARN_ON(in_interrupt());
540 card->llmode_streampriv = dpcm;
542 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
543 HPI_ADAPTER_PROPERTY_IRQ_RATE,
544 card->update_interval_frames, 0));
547 static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
549 struct snd_card_asihpi *card;
551 card = snd_pcm_substream_chip(substream);
553 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
554 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
556 card->llmode_streampriv = NULL;
559 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
562 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
563 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
564 struct snd_pcm_substream *s;
568 snd_pcm_debug_name(substream, name, sizeof(name));
571 case SNDRV_PCM_TRIGGER_START:
572 snd_printdd("%s trigger start\n", name);
573 snd_pcm_group_for_each_entry(s, substream) {
574 struct snd_pcm_runtime *runtime = s->runtime;
575 struct snd_card_asihpi_pcm *ds = runtime->private_data;
577 if (snd_pcm_substream_chip(s) != card)
580 /* don't link Cap and Play */
581 if (substream->stream != s->stream)
584 ds->drained_count = 0;
585 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
586 /* How do I know how much valid data is present
587 * in buffer? Must be at least one period!
588 * Guessing 2 periods, but if
589 * buffer is bigger it may contain even more
592 unsigned int preload = ds->period_bytes * 1;
593 snd_printddd("%d preload %d\n", s->number, preload);
594 hpi_handle_error(hpi_outstream_write_buf(
596 &runtime->dma_area[0],
599 ds->pcm_buf_host_rw_ofs = preload;
602 if (card->support_grouping) {
603 snd_printdd("%d group\n", s->number);
604 e = hpi_stream_group_add(
608 snd_pcm_trigger_done(s, substream);
616 /* start the master stream */
617 card->pcm_start(substream);
618 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
620 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
623 case SNDRV_PCM_TRIGGER_STOP:
624 snd_printdd("%s trigger stop\n", name);
625 card->pcm_stop(substream);
626 snd_pcm_group_for_each_entry(s, substream) {
627 if (snd_pcm_substream_chip(s) != card)
629 /* don't link Cap and Play */
630 if (substream->stream != s->stream)
633 /*? workaround linked streams don't
634 transition to SETUP 20070706*/
635 __snd_pcm_set_state(s->runtime, SNDRV_PCM_STATE_SETUP);
637 if (card->support_grouping) {
638 snd_printdd("%d group\n", s->number);
639 snd_pcm_trigger_done(s, substream);
644 /* _prepare and _hwparams reset the stream */
645 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
646 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
648 hpi_outstream_reset(dpcm->h_stream));
650 if (card->support_grouping)
651 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
654 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
655 snd_printdd("%s trigger pause release\n", name);
656 card->pcm_start(substream);
657 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
659 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
660 snd_printdd("%s trigger pause push\n", name);
661 card->pcm_stop(substream);
662 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
665 snd_printd(KERN_ERR "\tINVALID\n");
673 Without linking degenerates to getting single stream pos etc
674 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
677 pcm_buf_dma_ofs=get_buf_pos(s);
678 for_each_linked_stream(s) {
679 pcm_buf_dma_ofs=get_buf_pos(s);
680 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
681 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
683 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
684 for_each_linked_stream(s) {
685 s->pcm_buf_dma_ofs = min_buf_pos;
686 if (new_data > period_bytes) {
688 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
695 snd_pcm_period_elapsed(s);
700 /** Minimum of 2 modulo values. Works correctly when the difference between
701 * the values is less than half the modulus
703 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
704 unsigned long int modulus)
707 if (((a-b) % modulus) < (modulus/2))
715 /** Timer function, equivalent to interrupt service routine for cards
717 static void snd_card_asihpi_timer_function(struct timer_list *t)
719 struct snd_card_asihpi_pcm *dpcm = from_timer(dpcm, t, timer);
720 struct snd_pcm_substream *substream = dpcm->substream;
721 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
722 struct snd_pcm_runtime *runtime;
723 struct snd_pcm_substream *s;
724 unsigned int newdata = 0;
725 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
726 unsigned int remdata, xfercount, next_jiffies;
729 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
733 snd_pcm_debug_name(substream, name, sizeof(name));
735 /* find minimum newdata and buffer pos in group */
736 snd_pcm_group_for_each_entry(s, substream) {
737 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
738 runtime = s->runtime;
740 if (snd_pcm_substream_chip(s) != card)
743 /* don't link Cap and Play */
744 if (substream->stream != s->stream)
747 hpi_handle_error(hpi_stream_get_info_ex(
748 ds->h_stream, &state,
749 &buffer_size, &bytes_avail,
750 &samples_played, &on_card_bytes));
752 /* number of bytes in on-card buffer */
753 runtime->delay = on_card_bytes;
756 on_card_bytes = bytes_avail;
758 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
759 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
760 if (state == HPI_STATE_STOPPED) {
761 if (bytes_avail == 0) {
762 hpi_handle_error(hpi_stream_start(ds->h_stream));
763 snd_printdd("P%d start\n", s->number);
764 ds->drained_count = 0;
766 } else if (state == HPI_STATE_DRAINED) {
767 snd_printd(KERN_WARNING "P%d drained\n",
770 if (ds->drained_count > 20) {
771 snd_pcm_stop_xrun(s);
775 ds->drained_count = 0;
778 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
781 /* can't statically init min when wrap is involved */
782 min_buf_pos = pcm_buf_dma_ofs;
783 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
787 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
789 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
794 "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
795 name, s->number, state,
796 ds->pcm_buf_elapsed_dma_ofs,
797 ds->pcm_buf_host_rw_ofs,
802 buffer_size-bytes_avail,
803 (unsigned long)frames_to_bytes(runtime,
804 runtime->status->hw_ptr),
805 (unsigned long)frames_to_bytes(runtime,
806 runtime->control->appl_ptr)
809 pcm_buf_dma_ofs = min_buf_pos;
811 remdata = newdata % dpcm->period_bytes;
812 xfercount = newdata - remdata; /* a multiple of period_bytes */
813 /* come back when on_card_bytes has decreased enough to allow
814 write to happen, or when data has been consumed to make another
817 if (xfercount && (on_card_bytes > dpcm->period_bytes))
818 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
820 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
822 next_jiffies = max(next_jiffies, 1U);
823 dpcm->timer.expires = jiffies + next_jiffies;
824 snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
825 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
827 snd_pcm_group_for_each_entry(s, substream) {
828 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
830 /* don't link Cap and Play */
831 if (substream->stream != s->stream)
834 /* Store dma offset for use by pointer callback */
835 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
838 /* Limit use of on card fifo for playback */
839 ((on_card_bytes <= ds->period_bytes) ||
840 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
844 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
845 unsigned int xfer1, xfer2;
846 char *pd = &s->runtime->dma_area[buf_ofs];
848 if (card->can_dma) { /* buffer wrap is handled at lower level */
852 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
853 xfer2 = xfercount - xfer1;
856 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
857 snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n",
858 s->number, xfer1, buf_ofs);
860 hpi_outstream_write_buf(
861 ds->h_stream, pd, xfer1,
865 pd = s->runtime->dma_area;
867 snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n",
869 xfercount - xfer1, buf_ofs);
871 hpi_outstream_write_buf(
877 snd_printddd("read1, C=%d, xfer=%d\n",
880 hpi_instream_read_buf(
884 pd = s->runtime->dma_area;
885 snd_printddd("read2, C=%d, xfer=%d\n",
888 hpi_instream_read_buf(
893 /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */
894 ds->pcm_buf_host_rw_ofs += xfercount;
895 ds->pcm_buf_elapsed_dma_ofs += xfercount;
896 snd_pcm_period_elapsed(s);
900 if (!card->hpi->interrupt_mode && dpcm->respawn_timer)
901 add_timer(&dpcm->timer);
904 static void snd_card_asihpi_isr(struct hpi_adapter *a)
906 struct snd_card_asihpi *asihpi;
908 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
909 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
910 if (asihpi->llmode_streampriv)
911 snd_card_asihpi_timer_function(
912 &asihpi->llmode_streampriv->timer);
915 /***************************** PLAYBACK OPS ****************/
916 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
919 struct snd_pcm_runtime *runtime = substream->runtime;
920 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
922 snd_printdd("P%d prepare\n", substream->number);
924 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
925 dpcm->pcm_buf_host_rw_ofs = 0;
926 dpcm->pcm_buf_dma_ofs = 0;
927 dpcm->pcm_buf_elapsed_dma_ofs = 0;
931 static snd_pcm_uframes_t
932 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
934 struct snd_pcm_runtime *runtime = substream->runtime;
935 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
936 snd_pcm_uframes_t ptr;
938 snd_pcm_debug_name(substream, name, sizeof(name));
940 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
941 snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr);
945 static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
948 struct hpi_format hpi_format;
952 u32 sample_rate = 48000;
955 /* on cards without SRC, must query at valid rate,
956 * maybe set by external sync
958 err = hpi_mixer_get_control(asihpi->h_mixer,
959 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
960 HPI_CONTROL_SAMPLECLOCK, &h_control);
963 err = hpi_sample_clock_get_sample_rate(h_control,
966 for (format = HPI_FORMAT_PCM8_UNSIGNED;
967 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
968 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
969 format, sample_rate, 128000, 0);
971 err = hpi_outstream_query_format(h_stream, &hpi_format);
972 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
973 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
978 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
980 struct snd_pcm_runtime *runtime = substream->runtime;
981 struct snd_card_asihpi_pcm *dpcm;
982 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
983 struct snd_pcm_hardware snd_card_asihpi_playback;
986 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
990 err = hpi_outstream_open(card->hpi->adapter->index,
991 substream->number, &dpcm->h_stream);
992 hpi_handle_error(err);
995 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1000 /*? also check ASI5000 samplerate source
1001 If external, only support external rate.
1002 If internal and other stream playing, can't switch
1005 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1006 dpcm->substream = substream;
1007 runtime->private_data = dpcm;
1008 runtime->private_free = snd_card_asihpi_runtime_free;
1010 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1011 if (!card->hpi->interrupt_mode) {
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_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1015 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1016 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1018 size_t pbmin = card->update_interval_frames *
1019 card->out_max_chans;
1020 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1021 snd_card_asihpi_playback.period_bytes_min = pbmin;
1022 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1023 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1024 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin;
1027 /* snd_card_asihpi_playback.fifo_size = 0; */
1028 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1029 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1030 snd_card_asihpi_playback.formats =
1031 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
1033 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1035 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1036 SNDRV_PCM_INFO_DOUBLE |
1037 SNDRV_PCM_INFO_BATCH |
1038 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1039 SNDRV_PCM_INFO_PAUSE |
1040 SNDRV_PCM_INFO_MMAP |
1041 SNDRV_PCM_INFO_MMAP_VALID;
1043 if (card->support_grouping) {
1044 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1045 snd_pcm_set_sync(substream);
1048 /* struct is copied, so can create initializer dynamically */
1049 runtime->hw = snd_card_asihpi_playback;
1052 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1053 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1057 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1058 card->update_interval_frames);
1060 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1061 card->update_interval_frames, UINT_MAX);
1063 snd_printdd("playback open\n");
1068 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1070 struct snd_pcm_runtime *runtime = substream->runtime;
1071 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1073 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1074 snd_printdd("playback close\n");
1079 static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1080 .open = snd_card_asihpi_playback_open,
1081 .close = snd_card_asihpi_playback_close,
1082 .hw_params = snd_card_asihpi_pcm_hw_params,
1083 .hw_free = snd_card_asihpi_hw_free,
1084 .prepare = snd_card_asihpi_playback_prepare,
1085 .trigger = snd_card_asihpi_trigger,
1086 .pointer = snd_card_asihpi_playback_pointer,
1089 /***************************** CAPTURE OPS ****************/
1090 static snd_pcm_uframes_t
1091 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1093 struct snd_pcm_runtime *runtime = substream->runtime;
1094 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1096 snd_pcm_debug_name(substream, name, sizeof(name));
1098 snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
1099 /* NOTE Unlike playback can't use actual samples_played
1100 for the capture position, because those samples aren't yet in
1101 the local buffer available for reading.
1103 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1106 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1108 struct snd_pcm_runtime *runtime = substream->runtime;
1109 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1111 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1112 dpcm->pcm_buf_host_rw_ofs = 0;
1113 dpcm->pcm_buf_dma_ofs = 0;
1114 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1116 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] != INVALID_FORMAT))
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 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1179 dpcm->substream = substream;
1180 runtime->private_data = dpcm;
1181 runtime->private_free = snd_card_asihpi_runtime_free;
1183 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1184 if (!card->hpi->interrupt_mode) {
1185 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1186 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1187 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1188 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1189 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1191 size_t pbmin = card->update_interval_frames *
1192 card->out_max_chans;
1193 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1194 snd_card_asihpi_capture.period_bytes_min = pbmin;
1195 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1196 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1197 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin;
1199 /* snd_card_asihpi_capture.fifo_size = 0; */
1200 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1201 snd_card_asihpi_capture.channels_min = card->in_min_chans;
1202 snd_card_asihpi_capture.formats =
1203 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
1204 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1205 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1206 SNDRV_PCM_INFO_MMAP |
1207 SNDRV_PCM_INFO_MMAP_VALID;
1209 if (card->support_grouping)
1210 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1212 runtime->hw = snd_card_asihpi_capture;
1215 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1216 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1220 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1221 card->update_interval_frames);
1222 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1223 card->update_interval_frames, UINT_MAX);
1225 snd_pcm_set_sync(substream);
1230 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1232 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1234 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1238 static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1239 .open = snd_card_asihpi_capture_open,
1240 .close = snd_card_asihpi_capture_close,
1241 .hw_params = snd_card_asihpi_pcm_hw_params,
1242 .hw_free = snd_card_asihpi_hw_free,
1243 .prepare = snd_card_asihpi_capture_prepare,
1244 .trigger = snd_card_asihpi_trigger,
1245 .pointer = snd_card_asihpi_capture_pointer,
1248 static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1250 struct snd_pcm *pcm;
1252 u16 num_instreams, num_outstreams, x16;
1255 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1256 &num_outstreams, &num_instreams,
1259 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1260 num_outstreams, num_instreams, &pcm);
1264 /* pointer to ops struct is stored, dont change ops afterwards! */
1265 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1266 &snd_card_asihpi_playback_mmap_ops);
1267 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1268 &snd_card_asihpi_capture_mmap_ops);
1270 pcm->private_data = asihpi;
1271 pcm->info_flags = 0;
1272 strcpy(pcm->name, "Asihpi PCM");
1274 /*? do we want to emulate MMAP for non-BBM cards?
1275 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1276 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1278 64*1024, BUFFER_BYTES_MAX);
1283 /***************************** MIXER CONTROLS ****************/
1284 struct hpi_control {
1292 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
1295 static const char * const asihpi_tuner_band_names[] = {
1308 /* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
1309 compile_time_assert(
1310 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1311 (HPI_TUNER_BAND_LAST+1)),
1312 assert_tuner_band_names_size);
1314 static const char * const asihpi_src_names[] = {
1332 /* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
1333 compile_time_assert(
1334 (ARRAY_SIZE(asihpi_src_names) ==
1335 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1336 assert_src_names_size);
1338 static const char * const asihpi_dst_names[] = {
1352 /* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
1353 compile_time_assert(
1354 (ARRAY_SIZE(asihpi_dst_names) ==
1355 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1356 assert_dst_names_size);
1358 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1359 struct snd_card_asihpi *asihpi)
1363 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1366 else if (mixer_dump)
1367 dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index);
1372 /* Convert HPI control name and location into ALSA control name */
1373 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1374 struct hpi_control *hpi_ctl,
1378 memset(snd_control, 0, sizeof(*snd_control));
1379 snd_control->name = hpi_ctl->name;
1380 snd_control->private_value = hpi_ctl->h_control;
1381 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1382 snd_control->index = 0;
1384 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1385 dir = ""; /* clock is neither capture nor playback */
1386 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1387 dir = "Capture "; /* On or towards a PCM capture destination*/
1388 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1389 (!hpi_ctl->dst_node_type))
1390 dir = "Capture "; /* On a source node that is not PCM playback */
1391 else if (hpi_ctl->src_node_type &&
1392 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1393 (hpi_ctl->dst_node_type))
1394 dir = "Monitor Playback "; /* Between an input and an output */
1396 dir = "Playback "; /* PCM Playback source, or output node */
1398 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1399 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1400 asihpi_src_names[hpi_ctl->src_node_type],
1401 hpi_ctl->src_node_index,
1402 asihpi_dst_names[hpi_ctl->dst_node_type],
1403 hpi_ctl->dst_node_index,
1405 else if (hpi_ctl->dst_node_type) {
1406 sprintf(hpi_ctl->name, "%s %d %s%s",
1407 asihpi_dst_names[hpi_ctl->dst_node_type],
1408 hpi_ctl->dst_node_index,
1411 sprintf(hpi_ctl->name, "%s %d %s%s",
1412 asihpi_src_names[hpi_ctl->src_node_type],
1413 hpi_ctl->src_node_index,
1416 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1417 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1420 /*------------------------------------------------------------
1422 ------------------------------------------------------------*/
1423 #define VOL_STEP_mB 1
1424 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1425 struct snd_ctl_elem_info *uinfo)
1427 u32 h_control = kcontrol->private_value;
1430 /* native gains are in millibels */
1435 err = hpi_volume_query_range(h_control,
1436 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1439 min_gain_mB = -10000;
1440 step_gain_mB = VOL_STEP_mB;
1443 err = hpi_meter_query_channels(h_control, &count);
1445 count = HPI_MAX_CHANNELS;
1447 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1448 uinfo->count = count;
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)
1471 u32 h_control = kcontrol->private_value;
1472 short an_gain_mB[HPI_MAX_CHANNELS];
1475 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1477 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1478 /* change = asihpi->mixer_volume[addr][0] != left ||
1479 asihpi->mixer_volume[addr][1] != right;
1481 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1485 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1487 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1489 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1490 struct snd_ctl_elem_value *ucontrol)
1492 u32 h_control = kcontrol->private_value;
1495 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1496 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1501 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1502 struct snd_ctl_elem_value *ucontrol)
1504 u32 h_control = kcontrol->private_value;
1505 /* HPI currently only supports all or none muting of multichannel volume
1506 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1508 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1509 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1513 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1514 struct hpi_control *hpi_ctl)
1516 struct snd_card *card = asihpi->card;
1517 struct snd_kcontrol_new snd_control;
1521 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1522 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1523 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1524 snd_control.info = snd_asihpi_volume_info;
1525 snd_control.get = snd_asihpi_volume_get;
1526 snd_control.put = snd_asihpi_volume_put;
1527 snd_control.tlv.p = db_scale_100;
1529 err = ctl_add(card, &snd_control, asihpi);
1533 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1534 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1535 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1536 snd_control.info = snd_asihpi_volume_mute_info;
1537 snd_control.get = snd_asihpi_volume_mute_get;
1538 snd_control.put = snd_asihpi_volume_mute_put;
1539 err = ctl_add(card, &snd_control, asihpi);
1544 /*------------------------------------------------------------
1546 ------------------------------------------------------------*/
1547 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1548 struct snd_ctl_elem_info *uinfo)
1550 u32 h_control = kcontrol->private_value;
1557 hpi_level_query_range(h_control, &min_gain_mB,
1558 &max_gain_mB, &step_gain_mB);
1561 min_gain_mB = -1000;
1565 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1567 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1568 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1569 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1573 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1574 struct snd_ctl_elem_value *ucontrol)
1576 u32 h_control = kcontrol->private_value;
1577 short an_gain_mB[HPI_MAX_CHANNELS];
1579 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1580 ucontrol->value.integer.value[0] =
1581 an_gain_mB[0] / HPI_UNITS_PER_dB;
1582 ucontrol->value.integer.value[1] =
1583 an_gain_mB[1] / HPI_UNITS_PER_dB;
1588 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1589 struct snd_ctl_elem_value *ucontrol)
1592 u32 h_control = kcontrol->private_value;
1593 short an_gain_mB[HPI_MAX_CHANNELS];
1596 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1598 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1599 /* change = asihpi->mixer_level[addr][0] != left ||
1600 asihpi->mixer_level[addr][1] != right;
1603 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1607 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1609 static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1610 struct hpi_control *hpi_ctl)
1612 struct snd_card *card = asihpi->card;
1613 struct snd_kcontrol_new snd_control;
1615 /* can't use 'volume' cos some nodes have volume as well */
1616 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1617 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1618 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1619 snd_control.info = snd_asihpi_level_info;
1620 snd_control.get = snd_asihpi_level_get;
1621 snd_control.put = snd_asihpi_level_put;
1622 snd_control.tlv.p = db_scale_level;
1624 return ctl_add(card, &snd_control, asihpi);
1627 /*------------------------------------------------------------
1629 ------------------------------------------------------------*/
1632 static const char * const asihpi_aesebu_format_names[] = {
1633 "N/A", "S/PDIF", "AES/EBU" };
1635 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_info *uinfo)
1638 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
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 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
1868 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1869 struct snd_ctl_elem_value *ucontrol)
1871 u32 h_control = kcontrol->private_value;
1873 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1876 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1877 __always_unused u32 num_bands;
1879 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1880 HPI_TUNER_BAND_LAST);
1882 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1884 ucontrol->value.enumerated.item[0] = -1;
1885 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1886 if (tuner_bands[idx] == band) {
1887 ucontrol->value.enumerated.item[0] = idx;
1894 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1895 struct snd_ctl_elem_value *ucontrol)
1898 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1900 u32 h_control = kcontrol->private_value;
1903 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1904 __always_unused u32 num_bands;
1906 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1907 HPI_TUNER_BAND_LAST);
1909 idx = ucontrol->value.enumerated.item[0];
1910 if (idx >= ARRAY_SIZE(tuner_bands))
1911 idx = ARRAY_SIZE(tuner_bands) - 1;
1912 band = tuner_bands[idx];
1913 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1920 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1921 struct snd_ctl_elem_info *uinfo)
1923 u32 h_control = kcontrol->private_value;
1925 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1926 u16 num_bands = 0, band_iter, idx;
1927 u32 freq_range[3], temp_freq_range[3];
1929 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1930 HPI_TUNER_BAND_LAST);
1932 freq_range[0] = INT_MAX;
1934 freq_range[2] = INT_MAX;
1936 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1937 for (idx = 0; idx < 3; idx++) {
1938 err = hpi_tuner_query_frequency(h_control,
1939 idx, tuner_bands[band_iter],
1940 &temp_freq_range[idx]);
1945 /* skip band with bogus stepping */
1946 if (temp_freq_range[2] <= 0)
1949 if (temp_freq_range[0] < freq_range[0])
1950 freq_range[0] = temp_freq_range[0];
1951 if (temp_freq_range[1] > freq_range[1])
1952 freq_range[1] = temp_freq_range[1];
1953 if (temp_freq_range[2] < freq_range[2])
1954 freq_range[2] = temp_freq_range[2];
1957 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1959 uinfo->value.integer.min = ((int)freq_range[0]);
1960 uinfo->value.integer.max = ((int)freq_range[1]);
1961 uinfo->value.integer.step = ((int)freq_range[2]);
1965 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1966 struct snd_ctl_elem_value *ucontrol)
1968 u32 h_control = kcontrol->private_value;
1971 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
1972 ucontrol->value.integer.value[0] = freq;
1977 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
1978 struct snd_ctl_elem_value *ucontrol)
1980 u32 h_control = kcontrol->private_value;
1983 freq = ucontrol->value.integer.value[0];
1984 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
1989 /* Tuner control group initializer */
1990 static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
1991 struct hpi_control *hpi_ctl)
1993 struct snd_card *card = asihpi->card;
1994 struct snd_kcontrol_new snd_control;
1996 snd_control.private_value = hpi_ctl->h_control;
1997 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1999 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
2000 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
2001 snd_control.info = snd_asihpi_tuner_gain_info;
2002 snd_control.get = snd_asihpi_tuner_gain_get;
2003 snd_control.put = snd_asihpi_tuner_gain_put;
2005 if (ctl_add(card, &snd_control, asihpi) < 0)
2009 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
2010 snd_control.info = snd_asihpi_tuner_band_info;
2011 snd_control.get = snd_asihpi_tuner_band_get;
2012 snd_control.put = snd_asihpi_tuner_band_put;
2014 if (ctl_add(card, &snd_control, asihpi) < 0)
2017 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2018 snd_control.info = snd_asihpi_tuner_freq_info;
2019 snd_control.get = snd_asihpi_tuner_freq_get;
2020 snd_control.put = snd_asihpi_tuner_freq_put;
2022 return ctl_add(card, &snd_control, asihpi);
2025 /*------------------------------------------------------------
2027 ------------------------------------------------------------*/
2028 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2029 struct snd_ctl_elem_info *uinfo)
2031 u32 h_control = kcontrol->private_value;
2034 err = hpi_meter_query_channels(h_control, &count);
2036 count = HPI_MAX_CHANNELS;
2038 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2039 uinfo->count = count;
2040 uinfo->value.integer.min = 0;
2041 uinfo->value.integer.max = 0x7FFFFFFF;
2045 /* linear values for 10dB steps */
2046 static const int log2lin[] = {
2047 0x7FFFFFFF, /* 0dB */
2053 2147484, /* -60dB */
2068 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2069 struct snd_ctl_elem_value *ucontrol)
2071 u32 h_control = kcontrol->private_value;
2072 short an_gain_mB[HPI_MAX_CHANNELS], i;
2075 err = hpi_meter_get_peak(h_control, an_gain_mB);
2077 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2079 ucontrol->value.integer.value[i] = 0;
2080 } else if (an_gain_mB[i] >= 0) {
2081 ucontrol->value.integer.value[i] =
2082 an_gain_mB[i] << 16;
2084 /* -ve is log value in millibels < -60dB,
2085 * convert to (roughly!) linear,
2087 ucontrol->value.integer.value[i] =
2088 log2lin[an_gain_mB[i] / -1000];
2094 static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2095 struct hpi_control *hpi_ctl, int subidx)
2097 struct snd_card *card = asihpi->card;
2098 struct snd_kcontrol_new snd_control;
2100 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2101 snd_control.access =
2102 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2103 snd_control.info = snd_asihpi_meter_info;
2104 snd_control.get = snd_asihpi_meter_get;
2106 snd_control.index = subidx;
2108 return ctl_add(card, &snd_control, asihpi);
2111 /*------------------------------------------------------------
2112 Multiplexer controls
2113 ------------------------------------------------------------*/
2114 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2116 u32 h_control = snd_control->private_value;
2117 struct hpi_control hpi_ctl;
2119 for (s = 0; s < 32; s++) {
2120 err = hpi_multiplexer_query_source(h_control, s,
2131 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2132 struct snd_ctl_elem_info *uinfo)
2134 u16 src_node_type, src_node_index;
2135 u32 h_control = kcontrol->private_value;
2137 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2139 uinfo->value.enumerated.items =
2140 snd_card_asihpi_mux_count_sources(kcontrol);
2142 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2143 uinfo->value.enumerated.item =
2144 uinfo->value.enumerated.items - 1;
2146 hpi_multiplexer_query_source(h_control,
2147 uinfo->value.enumerated.item,
2148 &src_node_type, &src_node_index);
2150 sprintf(uinfo->value.enumerated.name, "%s %d",
2151 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2156 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2157 struct snd_ctl_elem_value *ucontrol)
2159 u32 h_control = kcontrol->private_value;
2160 u16 source_type, source_index;
2161 u16 src_node_type, src_node_index;
2164 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2165 &source_type, &source_index));
2166 /* Should cache this search result! */
2167 for (s = 0; s < 256; s++) {
2168 if (hpi_multiplexer_query_source(h_control, s,
2169 &src_node_type, &src_node_index))
2172 if ((source_type == src_node_type)
2173 && (source_index == src_node_index)) {
2174 ucontrol->value.enumerated.item[0] = s;
2178 snd_printd(KERN_WARNING
2179 "Control %x failed to match mux source %hu %hu\n",
2180 h_control, source_type, source_index);
2181 ucontrol->value.enumerated.item[0] = 0;
2185 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2186 struct snd_ctl_elem_value *ucontrol)
2189 u32 h_control = kcontrol->private_value;
2190 u16 source_type, source_index;
2195 e = hpi_multiplexer_query_source(h_control,
2196 ucontrol->value.enumerated.item[0],
2197 &source_type, &source_index);
2200 hpi_multiplexer_set_source(h_control,
2201 source_type, source_index));
2206 static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2207 struct hpi_control *hpi_ctl)
2209 struct snd_card *card = asihpi->card;
2210 struct snd_kcontrol_new snd_control;
2212 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2213 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2214 snd_control.info = snd_asihpi_mux_info;
2215 snd_control.get = snd_asihpi_mux_get;
2216 snd_control.put = snd_asihpi_mux_put;
2218 return ctl_add(card, &snd_control, asihpi);
2222 /*------------------------------------------------------------
2223 Channel mode controls
2224 ------------------------------------------------------------*/
2225 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2226 struct snd_ctl_elem_info *uinfo)
2228 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2231 "From Left", "From Right",
2232 "To Left", "To Right"
2235 u32 h_control = kcontrol->private_value;
2238 const char *mapped_names[6];
2239 int valid_modes = 0;
2241 /* HPI channel mode values can be from 1 to 6
2242 Some adapters only support a contiguous subset
2244 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2245 if (!hpi_channel_mode_query_mode(
2246 h_control, i, &mode)) {
2247 mapped_names[valid_modes] = mode_names[mode];
2254 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
2257 static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2258 struct snd_ctl_elem_value *ucontrol)
2260 u32 h_control = kcontrol->private_value;
2263 if (hpi_channel_mode_get(h_control, &mode))
2266 ucontrol->value.enumerated.item[0] = mode - 1;
2271 static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2272 struct snd_ctl_elem_value *ucontrol)
2275 u32 h_control = kcontrol->private_value;
2279 hpi_handle_error(hpi_channel_mode_set(h_control,
2280 ucontrol->value.enumerated.item[0] + 1));
2285 static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2286 struct hpi_control *hpi_ctl)
2288 struct snd_card *card = asihpi->card;
2289 struct snd_kcontrol_new snd_control;
2291 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
2292 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2293 snd_control.info = snd_asihpi_cmode_info;
2294 snd_control.get = snd_asihpi_cmode_get;
2295 snd_control.put = snd_asihpi_cmode_put;
2297 return ctl_add(card, &snd_control, asihpi);
2300 /*------------------------------------------------------------
2301 Sampleclock source controls
2302 ------------------------------------------------------------*/
2303 static const char * const sampleclock_sources[] = {
2304 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2305 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2306 "Prev Module", "BLU-Link",
2307 "Digital2", "Digital3", "Digital4", "Digital5",
2308 "Digital6", "Digital7", "Digital8"};
2310 /* Number of strings must match expected enumerated values */
2311 compile_time_assert(
2312 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2313 assert_sampleclock_sources_size);
2315 static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2316 struct snd_ctl_elem_info *uinfo)
2318 struct snd_card_asihpi *asihpi =
2319 (struct snd_card_asihpi *)(kcontrol->private_data);
2320 struct clk_cache *clkcache = &asihpi->cc;
2321 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2323 uinfo->value.enumerated.items = clkcache->count;
2325 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2326 uinfo->value.enumerated.item =
2327 uinfo->value.enumerated.items - 1;
2329 strcpy(uinfo->value.enumerated.name,
2330 clkcache->s[uinfo->value.enumerated.item].name);
2334 static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2335 struct snd_ctl_elem_value *ucontrol)
2337 struct snd_card_asihpi *asihpi =
2338 (struct snd_card_asihpi *)(kcontrol->private_data);
2339 struct clk_cache *clkcache = &asihpi->cc;
2340 u32 h_control = kcontrol->private_value;
2341 u16 source, srcindex = 0;
2344 ucontrol->value.enumerated.item[0] = 0;
2345 if (hpi_sample_clock_get_source(h_control, &source))
2348 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2349 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
2352 for (i = 0; i < clkcache->count; i++)
2353 if ((clkcache->s[i].source == source) &&
2354 (clkcache->s[i].index == srcindex))
2357 ucontrol->value.enumerated.item[0] = i;
2362 static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2363 struct snd_ctl_elem_value *ucontrol)
2365 struct snd_card_asihpi *asihpi =
2366 (struct snd_card_asihpi *)(kcontrol->private_data);
2367 struct clk_cache *clkcache = &asihpi->cc;
2370 u32 h_control = kcontrol->private_value;
2373 item = ucontrol->value.enumerated.item[0];
2374 if (item >= clkcache->count)
2375 item = clkcache->count-1;
2377 hpi_handle_error(hpi_sample_clock_set_source(
2378 h_control, clkcache->s[item].source));
2380 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2381 hpi_handle_error(hpi_sample_clock_set_source_index(
2382 h_control, clkcache->s[item].index));
2386 /*------------------------------------------------------------
2388 ------------------------------------------------------------*/
2389 /* Need to change this to enumerated control with list of rates */
2390 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2391 struct snd_ctl_elem_info *uinfo)
2393 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2395 uinfo->value.integer.min = 8000;
2396 uinfo->value.integer.max = 192000;
2397 uinfo->value.integer.step = 100;
2402 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2405 u32 h_control = kcontrol->private_value;
2409 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2411 ucontrol->value.integer.value[0] = rate;
2413 ucontrol->value.integer.value[0] = 0;
2417 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2418 struct snd_ctl_elem_value *ucontrol)
2421 u32 h_control = kcontrol->private_value;
2423 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2424 asihpi->mixer_clkrate[addr][1] != right;
2427 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2428 ucontrol->value.integer.value[0]));
2432 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2433 struct snd_ctl_elem_info *uinfo)
2435 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2437 uinfo->value.integer.min = 8000;
2438 uinfo->value.integer.max = 192000;
2439 uinfo->value.integer.step = 100;
2444 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2445 struct snd_ctl_elem_value *ucontrol)
2447 u32 h_control = kcontrol->private_value;
2451 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2453 ucontrol->value.integer.value[0] = rate;
2455 ucontrol->value.integer.value[0] = 0;
2459 static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2460 struct hpi_control *hpi_ctl)
2462 struct snd_card *card;
2463 struct snd_kcontrol_new snd_control;
2465 struct clk_cache *clkcache;
2466 u32 hSC = hpi_ctl->h_control;
2471 if (snd_BUG_ON(!asihpi))
2473 card = asihpi->card;
2474 clkcache = &asihpi->cc;
2475 snd_control.private_value = hpi_ctl->h_control;
2477 clkcache->has_local = 0;
2479 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2480 if (hpi_sample_clock_query_source(hSC,
2483 clkcache->s[i].source = source;
2484 clkcache->s[i].index = 0;
2485 clkcache->s[i].name = sampleclock_sources[source];
2486 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2488 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2489 clkcache->has_local = 1;
2492 /* already will have picked up index 0 above */
2493 for (j = 1; j < 8; j++) {
2494 if (hpi_sample_clock_query_source_index(hSC,
2495 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2498 clkcache->s[i].source =
2499 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2500 clkcache->s[i].index = j;
2501 clkcache->s[i].name = sampleclock_sources[
2502 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2505 clkcache->count = i;
2507 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2508 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2509 snd_control.info = snd_asihpi_clksrc_info;
2510 snd_control.get = snd_asihpi_clksrc_get;
2511 snd_control.put = snd_asihpi_clksrc_put;
2512 if (ctl_add(card, &snd_control, asihpi) < 0)
2516 if (clkcache->has_local) {
2517 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2518 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2519 snd_control.info = snd_asihpi_clklocal_info;
2520 snd_control.get = snd_asihpi_clklocal_get;
2521 snd_control.put = snd_asihpi_clklocal_put;
2524 if (ctl_add(card, &snd_control, asihpi) < 0)
2528 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2529 snd_control.access =
2530 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2531 snd_control.info = snd_asihpi_clkrate_info;
2532 snd_control.get = snd_asihpi_clkrate_get;
2534 return ctl_add(card, &snd_control, asihpi);
2536 /*------------------------------------------------------------
2538 ------------------------------------------------------------*/
2540 static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2542 struct snd_card *card;
2543 unsigned int idx = 0;
2544 unsigned int subindex = 0;
2546 struct hpi_control hpi_ctl, prev_ctl;
2548 if (snd_BUG_ON(!asihpi))
2550 card = asihpi->card;
2551 strcpy(card->mixername, "Asihpi Mixer");
2554 hpi_mixer_open(asihpi->hpi->adapter->index,
2556 hpi_handle_error(err);
2560 memset(&prev_ctl, 0, sizeof(prev_ctl));
2561 prev_ctl.control_type = -1;
2563 for (idx = 0; idx < 2000; idx++) {
2564 err = hpi_mixer_get_control_by_index(
2567 &hpi_ctl.src_node_type,
2568 &hpi_ctl.src_node_index,
2569 &hpi_ctl.dst_node_type,
2570 &hpi_ctl.dst_node_index,
2571 &hpi_ctl.control_type,
2572 &hpi_ctl.h_control);
2574 if (err == HPI_ERROR_CONTROL_DISABLED) {
2576 dev_info(&asihpi->pci->dev,
2577 "Disabled HPI Control(%d)\n",
2585 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2586 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2588 /* ASI50xx in SSX mode has multiple meters on the same node.
2589 Use subindex to create distinct ALSA controls
2590 for any duplicated controls.
2592 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2593 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2594 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2595 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2596 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2603 switch (hpi_ctl.control_type) {
2604 case HPI_CONTROL_VOLUME:
2605 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2607 case HPI_CONTROL_LEVEL:
2608 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2610 case HPI_CONTROL_MULTIPLEXER:
2611 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2613 case HPI_CONTROL_CHANNEL_MODE:
2614 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2616 case HPI_CONTROL_METER:
2617 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2619 case HPI_CONTROL_SAMPLECLOCK:
2620 err = snd_asihpi_sampleclock_add(
2623 case HPI_CONTROL_CONNECTION: /* ignore these */
2625 case HPI_CONTROL_TUNER:
2626 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2628 case HPI_CONTROL_AESEBU_TRANSMITTER:
2629 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2631 case HPI_CONTROL_AESEBU_RECEIVER:
2632 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2634 case HPI_CONTROL_VOX:
2635 case HPI_CONTROL_BITSTREAM:
2636 case HPI_CONTROL_MICROPHONE:
2637 case HPI_CONTROL_PARAMETRIC_EQ:
2638 case HPI_CONTROL_COMPANDER:
2641 dev_info(&asihpi->pci->dev,
2642 "Untranslated HPI Control (%d) %d %d %d %d %d\n",
2644 hpi_ctl.control_type,
2645 hpi_ctl.src_node_type,
2646 hpi_ctl.src_node_index,
2647 hpi_ctl.dst_node_type,
2648 hpi_ctl.dst_node_index);
2654 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2655 hpi_handle_error(err);
2657 dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx);
2662 /*------------------------------------------------------------
2664 ------------------------------------------------------------*/
2667 snd_asihpi_proc_read(struct snd_info_entry *entry,
2668 struct snd_info_buffer *buffer)
2670 struct snd_card_asihpi *asihpi = entry->private_data;
2683 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2685 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2686 &num_outstreams, &num_instreams,
2687 &version, &serial_number, &type));
2690 "Adapter type ASI%4X\nHardware Index %d\n"
2691 "%d outstreams\n%d instreams\n",
2692 type, asihpi->hpi->adapter->index,
2693 num_outstreams, num_instreams);
2696 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2697 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
2698 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2700 err = hpi_mixer_get_control(asihpi->h_mixer,
2701 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2702 HPI_CONTROL_SAMPLECLOCK, &h_control);
2705 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
2706 err += hpi_sample_clock_get_source(h_control, &source);
2709 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
2710 rate, sampleclock_sources[source]);
2714 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2716 snd_card_ro_proc_new(asihpi->card, "info", asihpi,
2717 snd_asihpi_proc_read);
2720 /*------------------------------------------------------------
2722 ------------------------------------------------------------*/
2724 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2726 if (enable_hpi_hwdep)
2733 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2735 if (enable_hpi_hwdep)
2736 return asihpi_hpi_release(file);
2741 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2742 unsigned int cmd, unsigned long arg)
2744 if (enable_hpi_hwdep)
2745 return asihpi_hpi_ioctl(file, cmd, arg);
2751 /* results in /dev/snd/hwC#D0 file for each card with index #
2752 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2754 static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, int device)
2756 struct snd_hwdep *hw;
2759 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2762 strcpy(hw->name, "asihpi (HPI)");
2763 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2764 hw->ops.open = snd_asihpi_hpi_open;
2765 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2766 hw->ops.release = snd_asihpi_hpi_release;
2767 hw->private_data = asihpi;
2771 /*------------------------------------------------------------
2773 ------------------------------------------------------------*/
2774 static int snd_asihpi_probe(struct pci_dev *pci_dev,
2775 const struct pci_device_id *pci_id)
2778 struct hpi_adapter *hpi;
2779 struct snd_card *card;
2780 struct snd_card_asihpi *asihpi;
2787 if (dev >= SNDRV_CARDS)
2790 /* Should this be enable[hpi->index] ? */
2796 /* Initialise low-level HPI driver */
2797 err = asihpi_adapter_probe(pci_dev, pci_id);
2801 hpi = pci_get_drvdata(pci_dev);
2802 adapter_index = hpi->adapter->index;
2803 /* first try to give the card the same index as its hardware index */
2804 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2805 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
2807 /* if that fails, try the default index==next available */
2808 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2809 THIS_MODULE, sizeof(struct snd_card_asihpi),
2813 dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n",
2814 adapter_index, card->number);
2817 asihpi = card->private_data;
2818 asihpi->card = card;
2819 asihpi->pci = pci_dev;
2821 hpi->snd_card = card;
2823 err = hpi_adapter_get_property(adapter_index,
2824 HPI_ADAPTER_PROPERTY_CAPS1,
2825 NULL, &asihpi->support_grouping);
2827 asihpi->support_grouping = 0;
2829 err = hpi_adapter_get_property(adapter_index,
2830 HPI_ADAPTER_PROPERTY_CAPS2,
2831 &asihpi->support_mrx, NULL);
2833 asihpi->support_mrx = 0;
2835 err = hpi_adapter_get_property(adapter_index,
2836 HPI_ADAPTER_PROPERTY_INTERVAL,
2837 NULL, &asihpi->update_interval_frames);
2839 asihpi->update_interval_frames = 512;
2841 if (hpi->interrupt_mode) {
2842 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
2843 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2844 hpi->interrupt_callback = snd_card_asihpi_isr;
2846 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
2847 asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop;
2850 hpi_handle_error(hpi_instream_open(adapter_index,
2853 err = hpi_instream_host_buffer_free(h_stream);
2854 asihpi->can_dma = (!err);
2856 hpi_handle_error(hpi_instream_close(h_stream));
2858 if (!asihpi->can_dma)
2859 asihpi->update_interval_frames *= 2;
2861 err = hpi_adapter_get_property(adapter_index,
2862 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2863 &asihpi->in_max_chans, &asihpi->out_max_chans);
2865 asihpi->in_max_chans = 2;
2866 asihpi->out_max_chans = 2;
2869 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2870 asihpi->out_min_chans = asihpi->out_max_chans;
2871 asihpi->in_min_chans = asihpi->in_max_chans;
2872 asihpi->support_grouping = 0;
2874 asihpi->out_min_chans = 1;
2875 asihpi->in_min_chans = 1;
2878 dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n",
2880 asihpi->support_grouping,
2881 asihpi->support_mrx,
2882 asihpi->update_interval_frames
2885 err = snd_card_asihpi_pcm_new(asihpi, 0);
2887 dev_err(&pci_dev->dev, "pcm_new failed\n");
2890 err = snd_card_asihpi_mixer_new(asihpi);
2892 dev_err(&pci_dev->dev, "mixer_new failed\n");
2896 err = hpi_mixer_get_control(asihpi->h_mixer,
2897 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2898 HPI_CONTROL_SAMPLECLOCK, &h_control);
2901 err = hpi_sample_clock_set_local_rate(
2902 h_control, adapter_fs);
2904 snd_asihpi_proc_init(asihpi);
2906 /* always create, can be enabled or disabled dynamically
2907 by enable_hwdep module param*/
2908 snd_asihpi_hpi_new(asihpi, 0);
2910 strcpy(card->driver, "ASIHPI");
2912 sprintf(card->shortname, "AudioScience ASI%4X",
2913 asihpi->hpi->adapter->type);
2914 sprintf(card->longname, "%s %i",
2915 card->shortname, adapter_index);
2916 err = snd_card_register(card);
2923 snd_card_free(card);
2924 dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err);
2929 static void snd_asihpi_remove(struct pci_dev *pci_dev)
2931 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2933 /* Stop interrupts */
2934 if (hpi->interrupt_mode) {
2935 hpi->interrupt_callback = NULL;
2936 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
2937 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
2940 snd_card_free(hpi->snd_card);
2941 hpi->snd_card = NULL;
2942 asihpi_adapter_remove(pci_dev);
2945 static const struct pci_device_id asihpi_pci_tbl[] = {
2946 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2947 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2948 (kernel_ulong_t)HPI_6205},
2949 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2950 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2951 (kernel_ulong_t)HPI_6000},
2954 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2956 static struct pci_driver driver = {
2957 .name = KBUILD_MODNAME,
2958 .id_table = asihpi_pci_tbl,
2959 .probe = snd_asihpi_probe,
2960 .remove = snd_asihpi_remove,
2963 static int __init snd_asihpi_init(void)
2966 return pci_register_driver(&driver);
2969 static void __exit snd_asihpi_exit(void)
2972 pci_unregister_driver(&driver);
2976 module_init(snd_asihpi_init)
2977 module_exit(snd_asihpi_exit)