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 struct tasklet_struct t;
121 void (*pcm_start)(struct snd_pcm_substream *substream);
122 void (*pcm_stop)(struct snd_pcm_substream *substream);
128 u16 support_grouping;
130 u16 update_interval_frames;
137 /* Per stream data */
138 struct snd_card_asihpi_pcm {
139 struct timer_list timer;
140 unsigned int respawn_timer;
141 unsigned int hpi_buffer_attached;
142 unsigned int buffer_bytes;
143 unsigned int period_bytes;
144 unsigned int bytes_per_sec;
145 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
146 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
147 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
148 unsigned int drained_count;
149 struct snd_pcm_substream *substream;
151 struct hpi_format format;
154 /* universal stream verbs work with out or in stream handles */
156 /* Functions to allow driver to give a buffer to HPI for busmastering */
158 static u16 hpi_stream_host_buffer_attach(
159 u32 h_stream, /* handle to outstream. */
160 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
164 struct hpi_message hm;
165 struct hpi_response hr;
166 unsigned int obj = hpi_handle_object(h_stream);
169 return HPI_ERROR_INVALID_OBJ;
170 hpi_init_message_response(&hm, &hr, obj,
171 obj == HPI_OBJ_OSTREAM ?
172 HPI_OSTREAM_HOSTBUFFER_ALLOC :
173 HPI_ISTREAM_HOSTBUFFER_ALLOC);
175 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
178 hm.u.d.u.buffer.buffer_size = size_in_bytes;
179 hm.u.d.u.buffer.pci_address = pci_address;
180 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
181 hpi_send_recv(&hm, &hr);
185 static u16 hpi_stream_host_buffer_detach(u32 h_stream)
187 struct hpi_message hm;
188 struct hpi_response hr;
189 unsigned int obj = hpi_handle_object(h_stream);
192 return HPI_ERROR_INVALID_OBJ;
194 hpi_init_message_response(&hm, &hr, obj,
195 obj == HPI_OBJ_OSTREAM ?
196 HPI_OSTREAM_HOSTBUFFER_FREE :
197 HPI_ISTREAM_HOSTBUFFER_FREE);
199 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
201 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
202 hpi_send_recv(&hm, &hr);
206 static inline u16 hpi_stream_start(u32 h_stream)
208 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
209 return hpi_outstream_start(h_stream);
211 return hpi_instream_start(h_stream);
214 static inline u16 hpi_stream_stop(u32 h_stream)
216 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
217 return hpi_outstream_stop(h_stream);
219 return hpi_instream_stop(h_stream);
222 static inline u16 hpi_stream_get_info_ex(
226 u32 *pdata_in_buffer,
232 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
233 e = hpi_outstream_get_info_ex(h_stream, pw_state,
234 pbuffer_size, pdata_in_buffer,
235 psample_count, pauxiliary_data);
237 e = hpi_instream_get_info_ex(h_stream, pw_state,
238 pbuffer_size, pdata_in_buffer,
239 psample_count, pauxiliary_data);
243 static inline u16 hpi_stream_group_add(
247 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
248 return hpi_outstream_group_add(h_master, h_stream);
250 return hpi_instream_group_add(h_master, h_stream);
253 static inline u16 hpi_stream_group_reset(u32 h_stream)
255 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
256 return hpi_outstream_group_reset(h_stream);
258 return hpi_instream_group_reset(h_stream);
261 static inline u16 hpi_stream_group_get_map(
262 u32 h_stream, u32 *mo, u32 *mi)
264 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
265 return hpi_outstream_group_get_map(h_stream, mo, mi);
267 return hpi_instream_group_get_map(h_stream, mo, mi);
270 static u16 handle_error(u16 err, int line, char *filename)
274 "in file %s, line %d: HPI error %d\n",
275 filename, line, err);
279 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
281 /***************************** GENERAL PCM ****************/
283 static void print_hwparams(struct snd_pcm_substream *substream,
284 struct snd_pcm_hw_params *p)
287 snd_pcm_debug_name(substream, name, sizeof(name));
288 snd_printdd("%s HWPARAMS\n", name);
289 snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n",
290 params_rate(p), params_channels(p),
291 params_format(p), params_subformat(p));
292 snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n",
293 params_buffer_bytes(p), params_period_bytes(p),
294 params_period_size(p), params_periods(p));
295 snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n",
296 params_buffer_size(p), params_access(p),
297 params_rate(p) * params_channels(p) *
298 snd_pcm_format_width(params_format(p)) / 8);
301 #define INVALID_FORMAT (__force snd_pcm_format_t)(-1)
303 static snd_pcm_format_t hpi_to_alsa_formats[] = {
304 INVALID_FORMAT, /* INVALID */
305 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
306 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
307 INVALID_FORMAT, /* HPI_FORMAT_MPEG_L1 3 */
308 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
309 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
310 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC2 6 */
311 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC3 7 */
312 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
313 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
314 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
315 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
316 INVALID_FORMAT, /* HPI_FORMAT_RAW_BITSTREAM 12 */
317 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
318 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
320 /* ALSA can't handle 3 byte sample size together with power-of-2
321 * constraint on buffer_bytes, so disable this format
325 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
330 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
335 for (format = HPI_FORMAT_PCM8_UNSIGNED;
336 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
337 if (hpi_to_alsa_formats[format] == alsa_format) {
338 *hpi_format = format;
343 snd_printd(KERN_WARNING "failed match for alsa format %d\n",
349 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
350 struct snd_pcm_hardware *pcmhw)
356 unsigned int rate_min = 200000;
357 unsigned int rate_max = 0;
358 unsigned int rates = 0;
360 if (asihpi->support_mrx) {
361 rates |= SNDRV_PCM_RATE_CONTINUOUS;
362 rates |= SNDRV_PCM_RATE_8000_96000;
366 /* on cards without SRC,
367 valid rates are determined by sampleclock */
368 err = hpi_mixer_get_control(asihpi->h_mixer,
369 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
370 HPI_CONTROL_SAMPLECLOCK, &h_control);
372 dev_err(&asihpi->pci->dev,
373 "No local sampleclock, err %d\n", err);
376 for (idx = -1; idx < 100; idx++) {
378 if (hpi_sample_clock_get_sample_rate(h_control,
381 } else if (hpi_sample_clock_query_local_rate(h_control,
382 idx, &sample_rate)) {
386 rate_min = min(rate_min, sample_rate);
387 rate_max = max(rate_max, sample_rate);
389 switch (sample_rate) {
391 rates |= SNDRV_PCM_RATE_5512;
394 rates |= SNDRV_PCM_RATE_8000;
397 rates |= SNDRV_PCM_RATE_11025;
400 rates |= SNDRV_PCM_RATE_16000;
403 rates |= SNDRV_PCM_RATE_22050;
406 rates |= SNDRV_PCM_RATE_32000;
409 rates |= SNDRV_PCM_RATE_44100;
412 rates |= SNDRV_PCM_RATE_48000;
415 rates |= SNDRV_PCM_RATE_64000;
418 rates |= SNDRV_PCM_RATE_88200;
421 rates |= SNDRV_PCM_RATE_96000;
424 rates |= SNDRV_PCM_RATE_176400;
427 rates |= SNDRV_PCM_RATE_192000;
429 default: /* some other rate */
430 rates |= SNDRV_PCM_RATE_KNOT;
435 pcmhw->rates = rates;
436 pcmhw->rate_min = rate_min;
437 pcmhw->rate_max = rate_max;
440 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
441 struct snd_pcm_hw_params *params)
443 struct snd_pcm_runtime *runtime = substream->runtime;
444 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
445 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
449 unsigned int bytes_per_sec;
451 print_hwparams(substream, params);
452 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
455 err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
459 hpi_handle_error(hpi_format_create(&dpcm->format,
460 params_channels(params),
461 format, params_rate(params), 0, 0));
463 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
464 if (hpi_instream_reset(dpcm->h_stream) != 0)
467 if (hpi_instream_set_format(
468 dpcm->h_stream, &dpcm->format) != 0)
472 dpcm->hpi_buffer_attached = 0;
474 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
475 params_buffer_bytes(params), runtime->dma_addr);
478 "stream_host_buffer_attach success %u %lu\n",
479 params_buffer_bytes(params),
480 (unsigned long)runtime->dma_addr);
482 snd_printd("stream_host_buffer_attach error %d\n",
487 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
488 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
490 bytes_per_sec = params_rate(params) * params_channels(params);
491 width = snd_pcm_format_width(params_format(params));
492 bytes_per_sec *= width;
494 if (width < 0 || bytes_per_sec == 0)
497 dpcm->bytes_per_sec = bytes_per_sec;
498 dpcm->buffer_bytes = params_buffer_bytes(params);
499 dpcm->period_bytes = params_period_bytes(params);
505 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
507 struct snd_pcm_runtime *runtime = substream->runtime;
508 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
509 if (dpcm->hpi_buffer_attached)
510 hpi_stream_host_buffer_detach(dpcm->h_stream);
512 snd_pcm_lib_free_pages(substream);
516 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
518 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
522 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
525 struct snd_pcm_runtime *runtime = substream->runtime;
526 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
531 expiry = max(expiry, 1); /* don't let it be zero! */
532 mod_timer(&dpcm->timer, jiffies + expiry);
533 dpcm->respawn_timer = 1;
536 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
538 struct snd_pcm_runtime *runtime = substream->runtime;
539 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
541 dpcm->respawn_timer = 0;
542 del_timer(&dpcm->timer);
545 static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
547 struct snd_card_asihpi_pcm *dpcm;
548 struct snd_card_asihpi *card;
550 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
551 card = snd_pcm_substream_chip(substream);
553 WARN_ON(in_interrupt());
554 tasklet_disable(&card->t);
555 card->llmode_streampriv = dpcm;
556 tasklet_enable(&card->t);
558 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
559 HPI_ADAPTER_PROPERTY_IRQ_RATE,
560 card->update_interval_frames, 0));
563 static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
565 struct snd_card_asihpi *card;
567 card = snd_pcm_substream_chip(substream);
569 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
570 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
573 card->llmode_streampriv = NULL;
575 tasklet_disable(&card->t);
576 card->llmode_streampriv = NULL;
577 tasklet_enable(&card->t);
581 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
584 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
585 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
586 struct snd_pcm_substream *s;
590 snd_pcm_debug_name(substream, name, sizeof(name));
593 case SNDRV_PCM_TRIGGER_START:
594 snd_printdd("%s trigger start\n", name);
595 snd_pcm_group_for_each_entry(s, substream) {
596 struct snd_pcm_runtime *runtime = s->runtime;
597 struct snd_card_asihpi_pcm *ds = runtime->private_data;
599 if (snd_pcm_substream_chip(s) != card)
602 /* don't link Cap and Play */
603 if (substream->stream != s->stream)
606 ds->drained_count = 0;
607 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
608 /* How do I know how much valid data is present
609 * in buffer? Must be at least one period!
610 * Guessing 2 periods, but if
611 * buffer is bigger it may contain even more
614 unsigned int preload = ds->period_bytes * 1;
615 snd_printddd("%d preload %d\n", s->number, preload);
616 hpi_handle_error(hpi_outstream_write_buf(
618 &runtime->dma_area[0],
621 ds->pcm_buf_host_rw_ofs = preload;
624 if (card->support_grouping) {
625 snd_printdd("%d group\n", s->number);
626 e = hpi_stream_group_add(
630 snd_pcm_trigger_done(s, substream);
638 /* start the master stream */
639 card->pcm_start(substream);
640 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
642 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
645 case SNDRV_PCM_TRIGGER_STOP:
646 snd_printdd("%s trigger stop\n", name);
647 card->pcm_stop(substream);
648 snd_pcm_group_for_each_entry(s, substream) {
649 if (snd_pcm_substream_chip(s) != card)
651 /* don't link Cap and Play */
652 if (substream->stream != s->stream)
655 /*? workaround linked streams don't
656 transition to SETUP 20070706*/
657 s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
659 if (card->support_grouping) {
660 snd_printdd("%d group\n", s->number);
661 snd_pcm_trigger_done(s, substream);
666 /* _prepare and _hwparams reset the stream */
667 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
668 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
670 hpi_outstream_reset(dpcm->h_stream));
672 if (card->support_grouping)
673 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
676 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
677 snd_printdd("%s trigger pause release\n", name);
678 card->pcm_start(substream);
679 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
681 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
682 snd_printdd("%s trigger pause push\n", name);
683 card->pcm_stop(substream);
684 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
687 snd_printd(KERN_ERR "\tINVALID\n");
695 Without linking degenerates to getting single stream pos etc
696 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
699 pcm_buf_dma_ofs=get_buf_pos(s);
700 for_each_linked_stream(s) {
701 pcm_buf_dma_ofs=get_buf_pos(s);
702 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
703 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
705 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
706 for_each_linked_stream(s) {
707 s->pcm_buf_dma_ofs = min_buf_pos;
708 if (new_data > period_bytes) {
710 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
717 snd_pcm_period_elapsed(s);
722 /** Minimum of 2 modulo values. Works correctly when the difference between
723 * the values is less than half the modulus
725 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
726 unsigned long int modulus)
729 if (((a-b) % modulus) < (modulus/2))
737 /** Timer function, equivalent to interrupt service routine for cards
739 static void snd_card_asihpi_timer_function(struct timer_list *t)
741 struct snd_card_asihpi_pcm *dpcm = from_timer(dpcm, t, timer);
742 struct snd_pcm_substream *substream = dpcm->substream;
743 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
744 struct snd_pcm_runtime *runtime;
745 struct snd_pcm_substream *s;
746 unsigned int newdata = 0;
747 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
748 unsigned int remdata, xfercount, next_jiffies;
752 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
756 snd_pcm_debug_name(substream, name, sizeof(name));
758 /* find minimum newdata and buffer pos in group */
759 snd_pcm_group_for_each_entry(s, substream) {
760 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
761 runtime = s->runtime;
763 if (snd_pcm_substream_chip(s) != card)
766 /* don't link Cap and Play */
767 if (substream->stream != s->stream)
770 hpi_handle_error(hpi_stream_get_info_ex(
771 ds->h_stream, &state,
772 &buffer_size, &bytes_avail,
773 &samples_played, &on_card_bytes));
775 /* number of bytes in on-card buffer */
776 runtime->delay = on_card_bytes;
779 on_card_bytes = bytes_avail;
781 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
782 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
783 if (state == HPI_STATE_STOPPED) {
784 if (bytes_avail == 0) {
785 hpi_handle_error(hpi_stream_start(ds->h_stream));
786 snd_printdd("P%d start\n", s->number);
787 ds->drained_count = 0;
789 } else if (state == HPI_STATE_DRAINED) {
790 snd_printd(KERN_WARNING "P%d drained\n",
793 if (ds->drained_count > 20) {
794 snd_pcm_stop_xrun(s);
798 ds->drained_count = 0;
801 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
804 /* can't statically init min when wrap is involved */
805 min_buf_pos = pcm_buf_dma_ofs;
806 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
810 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
812 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
817 "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
818 name, s->number, state,
819 ds->pcm_buf_elapsed_dma_ofs,
820 ds->pcm_buf_host_rw_ofs,
825 buffer_size-bytes_avail,
826 (unsigned long)frames_to_bytes(runtime,
827 runtime->status->hw_ptr),
828 (unsigned long)frames_to_bytes(runtime,
829 runtime->control->appl_ptr)
833 pcm_buf_dma_ofs = min_buf_pos;
835 remdata = newdata % dpcm->period_bytes;
836 xfercount = newdata - remdata; /* a multiple of period_bytes */
837 /* come back when on_card_bytes has decreased enough to allow
838 write to happen, or when data has been consumed to make another
841 if (xfercount && (on_card_bytes > dpcm->period_bytes))
842 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
844 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
846 next_jiffies = max(next_jiffies, 1U);
847 dpcm->timer.expires = jiffies + next_jiffies;
848 snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
849 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
851 snd_pcm_group_for_each_entry(s, substream) {
852 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
854 /* don't link Cap and Play */
855 if (substream->stream != s->stream)
858 /* Store dma offset for use by pointer callback */
859 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
862 /* Limit use of on card fifo for playback */
863 ((on_card_bytes <= ds->period_bytes) ||
864 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
868 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
869 unsigned int xfer1, xfer2;
870 char *pd = &s->runtime->dma_area[buf_ofs];
872 if (card->can_dma) { /* buffer wrap is handled at lower level */
876 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
877 xfer2 = xfercount - xfer1;
880 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
881 snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n",
882 s->number, xfer1, buf_ofs);
884 hpi_outstream_write_buf(
885 ds->h_stream, pd, xfer1,
889 pd = s->runtime->dma_area;
891 snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n",
893 xfercount - xfer1, buf_ofs);
895 hpi_outstream_write_buf(
901 snd_printddd("read1, C=%d, xfer=%d\n",
904 hpi_instream_read_buf(
908 pd = s->runtime->dma_area;
909 snd_printddd("read2, C=%d, xfer=%d\n",
912 hpi_instream_read_buf(
917 /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */
918 ds->pcm_buf_host_rw_ofs += xfercount;
919 ds->pcm_buf_elapsed_dma_ofs += xfercount;
920 snd_pcm_period_elapsed(s);
924 if (!card->hpi->interrupt_mode && dpcm->respawn_timer)
925 add_timer(&dpcm->timer);
928 static void snd_card_asihpi_int_task(unsigned long data)
930 struct hpi_adapter *a = (struct hpi_adapter *)data;
931 struct snd_card_asihpi *asihpi;
933 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
934 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
935 if (asihpi->llmode_streampriv)
936 snd_card_asihpi_timer_function(
937 &asihpi->llmode_streampriv->timer);
940 static void snd_card_asihpi_isr(struct hpi_adapter *a)
942 struct snd_card_asihpi *asihpi;
944 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
945 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
946 tasklet_schedule(&asihpi->t);
949 /***************************** PLAYBACK OPS ****************/
950 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
951 unsigned int cmd, void *arg)
954 snd_pcm_debug_name(substream, name, sizeof(name));
955 snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd);
956 return snd_pcm_lib_ioctl(substream, cmd, arg);
959 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
962 struct snd_pcm_runtime *runtime = substream->runtime;
963 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
965 snd_printdd("P%d prepare\n", substream->number);
967 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
968 dpcm->pcm_buf_host_rw_ofs = 0;
969 dpcm->pcm_buf_dma_ofs = 0;
970 dpcm->pcm_buf_elapsed_dma_ofs = 0;
974 static snd_pcm_uframes_t
975 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
977 struct snd_pcm_runtime *runtime = substream->runtime;
978 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
979 snd_pcm_uframes_t ptr;
981 snd_pcm_debug_name(substream, name, sizeof(name));
983 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
984 snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr);
988 static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
991 struct hpi_format hpi_format;
995 u32 sample_rate = 48000;
998 /* on cards without SRC, must query at valid rate,
999 * maybe set by external sync
1001 err = hpi_mixer_get_control(asihpi->h_mixer,
1002 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1003 HPI_CONTROL_SAMPLECLOCK, &h_control);
1006 err = hpi_sample_clock_get_sample_rate(h_control,
1009 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1010 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1011 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
1012 format, sample_rate, 128000, 0);
1014 err = hpi_outstream_query_format(h_stream, &hpi_format);
1015 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
1016 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1021 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1023 struct snd_pcm_runtime *runtime = substream->runtime;
1024 struct snd_card_asihpi_pcm *dpcm;
1025 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1026 struct snd_pcm_hardware snd_card_asihpi_playback;
1029 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1033 err = hpi_outstream_open(card->hpi->adapter->index,
1034 substream->number, &dpcm->h_stream);
1035 hpi_handle_error(err);
1038 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1043 /*? also check ASI5000 samplerate source
1044 If external, only support external rate.
1045 If internal and other stream playing, can't switch
1048 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1049 dpcm->substream = substream;
1050 runtime->private_data = dpcm;
1051 runtime->private_free = snd_card_asihpi_runtime_free;
1053 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1054 if (!card->hpi->interrupt_mode) {
1055 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1056 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
1057 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1058 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1059 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1061 size_t pbmin = card->update_interval_frames *
1062 card->out_max_chans;
1063 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1064 snd_card_asihpi_playback.period_bytes_min = pbmin;
1065 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1066 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1067 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin;
1070 /* snd_card_asihpi_playback.fifo_size = 0; */
1071 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1072 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1073 snd_card_asihpi_playback.formats =
1074 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
1076 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1078 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1079 SNDRV_PCM_INFO_DOUBLE |
1080 SNDRV_PCM_INFO_BATCH |
1081 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1082 SNDRV_PCM_INFO_PAUSE |
1083 SNDRV_PCM_INFO_MMAP |
1084 SNDRV_PCM_INFO_MMAP_VALID;
1086 if (card->support_grouping) {
1087 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1088 snd_pcm_set_sync(substream);
1091 /* struct is copied, so can create initializer dynamically */
1092 runtime->hw = snd_card_asihpi_playback;
1095 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1096 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1100 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1101 card->update_interval_frames);
1103 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1104 card->update_interval_frames, UINT_MAX);
1106 snd_printdd("playback open\n");
1111 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1113 struct snd_pcm_runtime *runtime = substream->runtime;
1114 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1116 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1117 snd_printdd("playback close\n");
1122 static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1123 .open = snd_card_asihpi_playback_open,
1124 .close = snd_card_asihpi_playback_close,
1125 .ioctl = snd_card_asihpi_playback_ioctl,
1126 .hw_params = snd_card_asihpi_pcm_hw_params,
1127 .hw_free = snd_card_asihpi_hw_free,
1128 .prepare = snd_card_asihpi_playback_prepare,
1129 .trigger = snd_card_asihpi_trigger,
1130 .pointer = snd_card_asihpi_playback_pointer,
1133 /***************************** CAPTURE OPS ****************/
1134 static snd_pcm_uframes_t
1135 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1137 struct snd_pcm_runtime *runtime = substream->runtime;
1138 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1140 snd_pcm_debug_name(substream, name, sizeof(name));
1142 snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
1143 /* NOTE Unlike playback can't use actual samples_played
1144 for the capture position, because those samples aren't yet in
1145 the local buffer available for reading.
1147 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1150 static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
1151 unsigned int cmd, void *arg)
1153 return snd_pcm_lib_ioctl(substream, cmd, arg);
1156 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1158 struct snd_pcm_runtime *runtime = substream->runtime;
1159 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1161 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1162 dpcm->pcm_buf_host_rw_ofs = 0;
1163 dpcm->pcm_buf_dma_ofs = 0;
1164 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1166 snd_printdd("Capture Prepare %d\n", substream->number);
1170 static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1173 struct hpi_format hpi_format;
1177 u32 sample_rate = 48000;
1180 /* on cards without SRC, must query at valid rate,
1181 maybe set by external sync */
1182 err = hpi_mixer_get_control(asihpi->h_mixer,
1183 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1184 HPI_CONTROL_SAMPLECLOCK, &h_control);
1187 err = hpi_sample_clock_get_sample_rate(h_control,
1190 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1191 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1193 err = hpi_format_create(&hpi_format, asihpi->in_max_chans,
1194 format, sample_rate, 128000, 0);
1196 err = hpi_instream_query_format(h_stream, &hpi_format);
1197 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
1198 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1203 static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1205 struct snd_pcm_runtime *runtime = substream->runtime;
1206 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1207 struct snd_card_asihpi_pcm *dpcm;
1208 struct snd_pcm_hardware snd_card_asihpi_capture;
1211 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1215 snd_printdd("capture open adapter %d stream %d\n",
1216 card->hpi->adapter->index, substream->number);
1218 err = hpi_handle_error(
1219 hpi_instream_open(card->hpi->adapter->index,
1220 substream->number, &dpcm->h_stream));
1223 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1228 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1229 dpcm->substream = substream;
1230 runtime->private_data = dpcm;
1231 runtime->private_free = snd_card_asihpi_runtime_free;
1233 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1234 if (!card->hpi->interrupt_mode) {
1235 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1236 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1237 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1238 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1239 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1241 size_t pbmin = card->update_interval_frames *
1242 card->out_max_chans;
1243 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1244 snd_card_asihpi_capture.period_bytes_min = pbmin;
1245 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1246 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1247 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin;
1249 /* snd_card_asihpi_capture.fifo_size = 0; */
1250 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1251 snd_card_asihpi_capture.channels_min = card->in_min_chans;
1252 snd_card_asihpi_capture.formats =
1253 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
1254 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1255 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1256 SNDRV_PCM_INFO_MMAP |
1257 SNDRV_PCM_INFO_MMAP_VALID;
1259 if (card->support_grouping)
1260 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1262 runtime->hw = snd_card_asihpi_capture;
1265 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1266 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1270 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1271 card->update_interval_frames);
1272 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1273 card->update_interval_frames, UINT_MAX);
1275 snd_pcm_set_sync(substream);
1280 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1282 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1284 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1288 static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1289 .open = snd_card_asihpi_capture_open,
1290 .close = snd_card_asihpi_capture_close,
1291 .ioctl = snd_card_asihpi_capture_ioctl,
1292 .hw_params = snd_card_asihpi_pcm_hw_params,
1293 .hw_free = snd_card_asihpi_hw_free,
1294 .prepare = snd_card_asihpi_capture_prepare,
1295 .trigger = snd_card_asihpi_trigger,
1296 .pointer = snd_card_asihpi_capture_pointer,
1299 static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1301 struct snd_pcm *pcm;
1303 u16 num_instreams, num_outstreams, x16;
1306 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1307 &num_outstreams, &num_instreams,
1310 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1311 num_outstreams, num_instreams, &pcm);
1315 /* pointer to ops struct is stored, dont change ops afterwards! */
1316 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1317 &snd_card_asihpi_playback_mmap_ops);
1318 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1319 &snd_card_asihpi_capture_mmap_ops);
1321 pcm->private_data = asihpi;
1322 pcm->info_flags = 0;
1323 strcpy(pcm->name, "Asihpi PCM");
1325 /*? do we want to emulate MMAP for non-BBM cards?
1326 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1327 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1328 snd_dma_pci_data(asihpi->pci),
1329 64*1024, BUFFER_BYTES_MAX);
1334 /***************************** MIXER CONTROLS ****************/
1335 struct hpi_control {
1343 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
1346 static const char * const asihpi_tuner_band_names[] = {
1359 /* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
1360 compile_time_assert(
1361 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1362 (HPI_TUNER_BAND_LAST+1)),
1363 assert_tuner_band_names_size);
1365 static const char * const asihpi_src_names[] = {
1383 /* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
1384 compile_time_assert(
1385 (ARRAY_SIZE(asihpi_src_names) ==
1386 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1387 assert_src_names_size);
1389 static const char * const asihpi_dst_names[] = {
1403 /* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
1404 compile_time_assert(
1405 (ARRAY_SIZE(asihpi_dst_names) ==
1406 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1407 assert_dst_names_size);
1409 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1410 struct snd_card_asihpi *asihpi)
1414 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1417 else if (mixer_dump)
1418 dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index);
1423 /* Convert HPI control name and location into ALSA control name */
1424 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1425 struct hpi_control *hpi_ctl,
1429 memset(snd_control, 0, sizeof(*snd_control));
1430 snd_control->name = hpi_ctl->name;
1431 snd_control->private_value = hpi_ctl->h_control;
1432 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1433 snd_control->index = 0;
1435 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1436 dir = ""; /* clock is neither capture nor playback */
1437 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1438 dir = "Capture "; /* On or towards a PCM capture destination*/
1439 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1440 (!hpi_ctl->dst_node_type))
1441 dir = "Capture "; /* On a source node that is not PCM playback */
1442 else if (hpi_ctl->src_node_type &&
1443 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1444 (hpi_ctl->dst_node_type))
1445 dir = "Monitor Playback "; /* Between an input and an output */
1447 dir = "Playback "; /* PCM Playback source, or output node */
1449 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1450 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1451 asihpi_src_names[hpi_ctl->src_node_type],
1452 hpi_ctl->src_node_index,
1453 asihpi_dst_names[hpi_ctl->dst_node_type],
1454 hpi_ctl->dst_node_index,
1456 else if (hpi_ctl->dst_node_type) {
1457 sprintf(hpi_ctl->name, "%s %d %s%s",
1458 asihpi_dst_names[hpi_ctl->dst_node_type],
1459 hpi_ctl->dst_node_index,
1462 sprintf(hpi_ctl->name, "%s %d %s%s",
1463 asihpi_src_names[hpi_ctl->src_node_type],
1464 hpi_ctl->src_node_index,
1467 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1468 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1471 /*------------------------------------------------------------
1473 ------------------------------------------------------------*/
1474 #define VOL_STEP_mB 1
1475 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1476 struct snd_ctl_elem_info *uinfo)
1478 u32 h_control = kcontrol->private_value;
1481 /* native gains are in millibels */
1486 err = hpi_volume_query_range(h_control,
1487 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1490 min_gain_mB = -10000;
1491 step_gain_mB = VOL_STEP_mB;
1494 err = hpi_meter_query_channels(h_control, &count);
1496 count = HPI_MAX_CHANNELS;
1498 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1499 uinfo->count = count;
1500 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1501 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1502 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1506 static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1507 struct snd_ctl_elem_value *ucontrol)
1509 u32 h_control = kcontrol->private_value;
1510 short an_gain_mB[HPI_MAX_CHANNELS];
1512 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
1513 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1514 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1519 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1520 struct snd_ctl_elem_value *ucontrol)
1522 u32 h_control = kcontrol->private_value;
1523 short an_gain_mB[HPI_MAX_CHANNELS];
1526 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1528 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1529 /* change = asihpi->mixer_volume[addr][0] != left ||
1530 asihpi->mixer_volume[addr][1] != right;
1532 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1536 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1538 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1540 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1541 struct snd_ctl_elem_value *ucontrol)
1543 u32 h_control = kcontrol->private_value;
1546 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1547 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1552 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1553 struct snd_ctl_elem_value *ucontrol)
1555 u32 h_control = kcontrol->private_value;
1556 /* HPI currently only supports all or none muting of multichannel volume
1557 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1559 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1560 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1564 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1565 struct hpi_control *hpi_ctl)
1567 struct snd_card *card = asihpi->card;
1568 struct snd_kcontrol_new snd_control;
1572 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1573 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1574 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1575 snd_control.info = snd_asihpi_volume_info;
1576 snd_control.get = snd_asihpi_volume_get;
1577 snd_control.put = snd_asihpi_volume_put;
1578 snd_control.tlv.p = db_scale_100;
1580 err = ctl_add(card, &snd_control, asihpi);
1584 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1585 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1586 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1587 snd_control.info = snd_asihpi_volume_mute_info;
1588 snd_control.get = snd_asihpi_volume_mute_get;
1589 snd_control.put = snd_asihpi_volume_mute_put;
1590 err = ctl_add(card, &snd_control, asihpi);
1595 /*------------------------------------------------------------
1597 ------------------------------------------------------------*/
1598 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1599 struct snd_ctl_elem_info *uinfo)
1601 u32 h_control = kcontrol->private_value;
1608 hpi_level_query_range(h_control, &min_gain_mB,
1609 &max_gain_mB, &step_gain_mB);
1612 min_gain_mB = -1000;
1616 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1618 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1619 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1620 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1624 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1625 struct snd_ctl_elem_value *ucontrol)
1627 u32 h_control = kcontrol->private_value;
1628 short an_gain_mB[HPI_MAX_CHANNELS];
1630 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1631 ucontrol->value.integer.value[0] =
1632 an_gain_mB[0] / HPI_UNITS_PER_dB;
1633 ucontrol->value.integer.value[1] =
1634 an_gain_mB[1] / HPI_UNITS_PER_dB;
1639 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1640 struct snd_ctl_elem_value *ucontrol)
1643 u32 h_control = kcontrol->private_value;
1644 short an_gain_mB[HPI_MAX_CHANNELS];
1647 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1649 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1650 /* change = asihpi->mixer_level[addr][0] != left ||
1651 asihpi->mixer_level[addr][1] != right;
1654 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1658 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1660 static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1661 struct hpi_control *hpi_ctl)
1663 struct snd_card *card = asihpi->card;
1664 struct snd_kcontrol_new snd_control;
1666 /* can't use 'volume' cos some nodes have volume as well */
1667 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1668 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1669 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1670 snd_control.info = snd_asihpi_level_info;
1671 snd_control.get = snd_asihpi_level_get;
1672 snd_control.put = snd_asihpi_level_put;
1673 snd_control.tlv.p = db_scale_level;
1675 return ctl_add(card, &snd_control, asihpi);
1678 /*------------------------------------------------------------
1680 ------------------------------------------------------------*/
1683 static const char * const asihpi_aesebu_format_names[] = {
1684 "N/A", "S/PDIF", "AES/EBU" };
1686 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1687 struct snd_ctl_elem_info *uinfo)
1689 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
1692 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1693 struct snd_ctl_elem_value *ucontrol,
1694 u16 (*func)(u32, u16 *))
1696 u32 h_control = kcontrol->private_value;
1699 err = func(h_control, &source);
1701 /* default to N/A */
1702 ucontrol->value.enumerated.item[0] = 0;
1703 /* return success but set the control to N/A */
1706 if (source == HPI_AESEBU_FORMAT_SPDIF)
1707 ucontrol->value.enumerated.item[0] = 1;
1708 if (source == HPI_AESEBU_FORMAT_AESEBU)
1709 ucontrol->value.enumerated.item[0] = 2;
1714 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1715 struct snd_ctl_elem_value *ucontrol,
1716 u16 (*func)(u32, u16))
1718 u32 h_control = kcontrol->private_value;
1720 /* default to S/PDIF */
1721 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1723 if (ucontrol->value.enumerated.item[0] == 1)
1724 source = HPI_AESEBU_FORMAT_SPDIF;
1725 if (ucontrol->value.enumerated.item[0] == 2)
1726 source = HPI_AESEBU_FORMAT_AESEBU;
1728 if (func(h_control, source) != 0)
1734 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol) {
1736 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1737 hpi_aesebu_receiver_get_format);
1740 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1741 struct snd_ctl_elem_value *ucontrol) {
1742 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1743 hpi_aesebu_receiver_set_format);
1746 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_info *uinfo)
1749 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1752 uinfo->value.integer.min = 0;
1753 uinfo->value.integer.max = 0X1F;
1754 uinfo->value.integer.step = 1;
1759 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1760 struct snd_ctl_elem_value *ucontrol) {
1762 u32 h_control = kcontrol->private_value;
1765 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1766 h_control, &status));
1767 ucontrol->value.integer.value[0] = status;
1771 static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1772 struct hpi_control *hpi_ctl)
1774 struct snd_card *card = asihpi->card;
1775 struct snd_kcontrol_new snd_control;
1777 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1778 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1779 snd_control.info = snd_asihpi_aesebu_format_info;
1780 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1781 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1784 if (ctl_add(card, &snd_control, asihpi) < 0)
1787 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
1788 snd_control.access =
1789 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1790 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1791 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1793 return ctl_add(card, &snd_control, asihpi);
1796 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1797 struct snd_ctl_elem_value *ucontrol) {
1798 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1799 hpi_aesebu_transmitter_get_format);
1802 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1803 struct snd_ctl_elem_value *ucontrol) {
1804 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1805 hpi_aesebu_transmitter_set_format);
1809 static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1810 struct hpi_control *hpi_ctl)
1812 struct snd_card *card = asihpi->card;
1813 struct snd_kcontrol_new snd_control;
1815 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1816 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1817 snd_control.info = snd_asihpi_aesebu_format_info;
1818 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1819 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1821 return ctl_add(card, &snd_control, asihpi);
1824 /*------------------------------------------------------------
1826 ------------------------------------------------------------*/
1830 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1831 struct snd_ctl_elem_info *uinfo)
1833 u32 h_control = kcontrol->private_value;
1838 for (idx = 0; idx < 3; idx++) {
1839 err = hpi_tuner_query_gain(h_control,
1840 idx, &gain_range[idx]);
1845 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1847 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1848 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1849 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1853 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1854 struct snd_ctl_elem_value *ucontrol)
1857 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1859 u32 h_control = kcontrol->private_value;
1862 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
1863 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1868 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1869 struct snd_ctl_elem_value *ucontrol)
1872 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1874 u32 h_control = kcontrol->private_value;
1877 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1878 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
1885 static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1886 u16 *band_list, u32 len) {
1887 u32 h_control = kcontrol->private_value;
1891 for (i = 0; i < len; i++) {
1892 err = hpi_tuner_query_band(
1893 h_control, i, &band_list[i]);
1898 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1904 static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1905 struct snd_ctl_elem_info *uinfo)
1907 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1910 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1911 HPI_TUNER_BAND_LAST);
1916 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
1919 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1920 struct snd_ctl_elem_value *ucontrol)
1922 u32 h_control = kcontrol->private_value;
1924 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1927 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1930 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1931 HPI_TUNER_BAND_LAST);
1933 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1935 ucontrol->value.enumerated.item[0] = -1;
1936 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1937 if (tuner_bands[idx] == band) {
1938 ucontrol->value.enumerated.item[0] = idx;
1945 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1946 struct snd_ctl_elem_value *ucontrol)
1949 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1951 u32 h_control = kcontrol->private_value;
1954 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1957 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1958 HPI_TUNER_BAND_LAST);
1960 idx = ucontrol->value.enumerated.item[0];
1961 if (idx >= ARRAY_SIZE(tuner_bands))
1962 idx = ARRAY_SIZE(tuner_bands) - 1;
1963 band = tuner_bands[idx];
1964 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1971 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1972 struct snd_ctl_elem_info *uinfo)
1974 u32 h_control = kcontrol->private_value;
1976 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1977 u16 num_bands = 0, band_iter, idx;
1978 u32 freq_range[3], temp_freq_range[3];
1980 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1981 HPI_TUNER_BAND_LAST);
1983 freq_range[0] = INT_MAX;
1985 freq_range[2] = INT_MAX;
1987 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1988 for (idx = 0; idx < 3; idx++) {
1989 err = hpi_tuner_query_frequency(h_control,
1990 idx, tuner_bands[band_iter],
1991 &temp_freq_range[idx]);
1996 /* skip band with bogus stepping */
1997 if (temp_freq_range[2] <= 0)
2000 if (temp_freq_range[0] < freq_range[0])
2001 freq_range[0] = temp_freq_range[0];
2002 if (temp_freq_range[1] > freq_range[1])
2003 freq_range[1] = temp_freq_range[1];
2004 if (temp_freq_range[2] < freq_range[2])
2005 freq_range[2] = temp_freq_range[2];
2008 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2010 uinfo->value.integer.min = ((int)freq_range[0]);
2011 uinfo->value.integer.max = ((int)freq_range[1]);
2012 uinfo->value.integer.step = ((int)freq_range[2]);
2016 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
2017 struct snd_ctl_elem_value *ucontrol)
2019 u32 h_control = kcontrol->private_value;
2022 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
2023 ucontrol->value.integer.value[0] = freq;
2028 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
2029 struct snd_ctl_elem_value *ucontrol)
2031 u32 h_control = kcontrol->private_value;
2034 freq = ucontrol->value.integer.value[0];
2035 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
2040 /* Tuner control group initializer */
2041 static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
2042 struct hpi_control *hpi_ctl)
2044 struct snd_card *card = asihpi->card;
2045 struct snd_kcontrol_new snd_control;
2047 snd_control.private_value = hpi_ctl->h_control;
2048 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2050 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
2051 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
2052 snd_control.info = snd_asihpi_tuner_gain_info;
2053 snd_control.get = snd_asihpi_tuner_gain_get;
2054 snd_control.put = snd_asihpi_tuner_gain_put;
2056 if (ctl_add(card, &snd_control, asihpi) < 0)
2060 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
2061 snd_control.info = snd_asihpi_tuner_band_info;
2062 snd_control.get = snd_asihpi_tuner_band_get;
2063 snd_control.put = snd_asihpi_tuner_band_put;
2065 if (ctl_add(card, &snd_control, asihpi) < 0)
2068 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2069 snd_control.info = snd_asihpi_tuner_freq_info;
2070 snd_control.get = snd_asihpi_tuner_freq_get;
2071 snd_control.put = snd_asihpi_tuner_freq_put;
2073 return ctl_add(card, &snd_control, asihpi);
2076 /*------------------------------------------------------------
2078 ------------------------------------------------------------*/
2079 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2080 struct snd_ctl_elem_info *uinfo)
2082 u32 h_control = kcontrol->private_value;
2085 err = hpi_meter_query_channels(h_control, &count);
2087 count = HPI_MAX_CHANNELS;
2089 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2090 uinfo->count = count;
2091 uinfo->value.integer.min = 0;
2092 uinfo->value.integer.max = 0x7FFFFFFF;
2096 /* linear values for 10dB steps */
2097 static int log2lin[] = {
2098 0x7FFFFFFF, /* 0dB */
2104 2147484, /* -60dB */
2119 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2120 struct snd_ctl_elem_value *ucontrol)
2122 u32 h_control = kcontrol->private_value;
2123 short an_gain_mB[HPI_MAX_CHANNELS], i;
2126 err = hpi_meter_get_peak(h_control, an_gain_mB);
2128 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2130 ucontrol->value.integer.value[i] = 0;
2131 } else if (an_gain_mB[i] >= 0) {
2132 ucontrol->value.integer.value[i] =
2133 an_gain_mB[i] << 16;
2135 /* -ve is log value in millibels < -60dB,
2136 * convert to (roughly!) linear,
2138 ucontrol->value.integer.value[i] =
2139 log2lin[an_gain_mB[i] / -1000];
2145 static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2146 struct hpi_control *hpi_ctl, int subidx)
2148 struct snd_card *card = asihpi->card;
2149 struct snd_kcontrol_new snd_control;
2151 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2152 snd_control.access =
2153 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2154 snd_control.info = snd_asihpi_meter_info;
2155 snd_control.get = snd_asihpi_meter_get;
2157 snd_control.index = subidx;
2159 return ctl_add(card, &snd_control, asihpi);
2162 /*------------------------------------------------------------
2163 Multiplexer controls
2164 ------------------------------------------------------------*/
2165 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2167 u32 h_control = snd_control->private_value;
2168 struct hpi_control hpi_ctl;
2170 for (s = 0; s < 32; s++) {
2171 err = hpi_multiplexer_query_source(h_control, s,
2182 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2183 struct snd_ctl_elem_info *uinfo)
2186 u16 src_node_type, src_node_index;
2187 u32 h_control = kcontrol->private_value;
2189 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2191 uinfo->value.enumerated.items =
2192 snd_card_asihpi_mux_count_sources(kcontrol);
2194 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2195 uinfo->value.enumerated.item =
2196 uinfo->value.enumerated.items - 1;
2199 hpi_multiplexer_query_source(h_control,
2200 uinfo->value.enumerated.item,
2201 &src_node_type, &src_node_index);
2203 sprintf(uinfo->value.enumerated.name, "%s %d",
2204 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2209 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2210 struct snd_ctl_elem_value *ucontrol)
2212 u32 h_control = kcontrol->private_value;
2213 u16 source_type, source_index;
2214 u16 src_node_type, src_node_index;
2217 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2218 &source_type, &source_index));
2219 /* Should cache this search result! */
2220 for (s = 0; s < 256; s++) {
2221 if (hpi_multiplexer_query_source(h_control, s,
2222 &src_node_type, &src_node_index))
2225 if ((source_type == src_node_type)
2226 && (source_index == src_node_index)) {
2227 ucontrol->value.enumerated.item[0] = s;
2231 snd_printd(KERN_WARNING
2232 "Control %x failed to match mux source %hu %hu\n",
2233 h_control, source_type, source_index);
2234 ucontrol->value.enumerated.item[0] = 0;
2238 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2239 struct snd_ctl_elem_value *ucontrol)
2242 u32 h_control = kcontrol->private_value;
2243 u16 source_type, source_index;
2248 e = hpi_multiplexer_query_source(h_control,
2249 ucontrol->value.enumerated.item[0],
2250 &source_type, &source_index);
2253 hpi_multiplexer_set_source(h_control,
2254 source_type, source_index));
2259 static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2260 struct hpi_control *hpi_ctl)
2262 struct snd_card *card = asihpi->card;
2263 struct snd_kcontrol_new snd_control;
2265 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2266 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2267 snd_control.info = snd_asihpi_mux_info;
2268 snd_control.get = snd_asihpi_mux_get;
2269 snd_control.put = snd_asihpi_mux_put;
2271 return ctl_add(card, &snd_control, asihpi);
2275 /*------------------------------------------------------------
2276 Channel mode controls
2277 ------------------------------------------------------------*/
2278 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2279 struct snd_ctl_elem_info *uinfo)
2281 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2284 "From Left", "From Right",
2285 "To Left", "To Right"
2288 u32 h_control = kcontrol->private_value;
2291 const char *mapped_names[6];
2292 int valid_modes = 0;
2294 /* HPI channel mode values can be from 1 to 6
2295 Some adapters only support a contiguous subset
2297 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2298 if (!hpi_channel_mode_query_mode(
2299 h_control, i, &mode)) {
2300 mapped_names[valid_modes] = mode_names[mode];
2307 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
2310 static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2311 struct snd_ctl_elem_value *ucontrol)
2313 u32 h_control = kcontrol->private_value;
2316 if (hpi_channel_mode_get(h_control, &mode))
2319 ucontrol->value.enumerated.item[0] = mode - 1;
2324 static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2325 struct snd_ctl_elem_value *ucontrol)
2328 u32 h_control = kcontrol->private_value;
2332 hpi_handle_error(hpi_channel_mode_set(h_control,
2333 ucontrol->value.enumerated.item[0] + 1));
2338 static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2339 struct hpi_control *hpi_ctl)
2341 struct snd_card *card = asihpi->card;
2342 struct snd_kcontrol_new snd_control;
2344 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
2345 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2346 snd_control.info = snd_asihpi_cmode_info;
2347 snd_control.get = snd_asihpi_cmode_get;
2348 snd_control.put = snd_asihpi_cmode_put;
2350 return ctl_add(card, &snd_control, asihpi);
2353 /*------------------------------------------------------------
2354 Sampleclock source controls
2355 ------------------------------------------------------------*/
2356 static const char * const sampleclock_sources[] = {
2357 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2358 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2359 "Prev Module", "BLU-Link",
2360 "Digital2", "Digital3", "Digital4", "Digital5",
2361 "Digital6", "Digital7", "Digital8"};
2363 /* Number of strings must match expected enumerated values */
2364 compile_time_assert(
2365 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2366 assert_sampleclock_sources_size);
2368 static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2369 struct snd_ctl_elem_info *uinfo)
2371 struct snd_card_asihpi *asihpi =
2372 (struct snd_card_asihpi *)(kcontrol->private_data);
2373 struct clk_cache *clkcache = &asihpi->cc;
2374 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2376 uinfo->value.enumerated.items = clkcache->count;
2378 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2379 uinfo->value.enumerated.item =
2380 uinfo->value.enumerated.items - 1;
2382 strcpy(uinfo->value.enumerated.name,
2383 clkcache->s[uinfo->value.enumerated.item].name);
2387 static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2388 struct snd_ctl_elem_value *ucontrol)
2390 struct snd_card_asihpi *asihpi =
2391 (struct snd_card_asihpi *)(kcontrol->private_data);
2392 struct clk_cache *clkcache = &asihpi->cc;
2393 u32 h_control = kcontrol->private_value;
2394 u16 source, srcindex = 0;
2397 ucontrol->value.enumerated.item[0] = 0;
2398 if (hpi_sample_clock_get_source(h_control, &source))
2401 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2402 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
2405 for (i = 0; i < clkcache->count; i++)
2406 if ((clkcache->s[i].source == source) &&
2407 (clkcache->s[i].index == srcindex))
2410 ucontrol->value.enumerated.item[0] = i;
2415 static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2416 struct snd_ctl_elem_value *ucontrol)
2418 struct snd_card_asihpi *asihpi =
2419 (struct snd_card_asihpi *)(kcontrol->private_data);
2420 struct clk_cache *clkcache = &asihpi->cc;
2423 u32 h_control = kcontrol->private_value;
2426 item = ucontrol->value.enumerated.item[0];
2427 if (item >= clkcache->count)
2428 item = clkcache->count-1;
2430 hpi_handle_error(hpi_sample_clock_set_source(
2431 h_control, clkcache->s[item].source));
2433 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2434 hpi_handle_error(hpi_sample_clock_set_source_index(
2435 h_control, clkcache->s[item].index));
2439 /*------------------------------------------------------------
2441 ------------------------------------------------------------*/
2442 /* Need to change this to enumerated control with list of rates */
2443 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2444 struct snd_ctl_elem_info *uinfo)
2446 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2448 uinfo->value.integer.min = 8000;
2449 uinfo->value.integer.max = 192000;
2450 uinfo->value.integer.step = 100;
2455 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2456 struct snd_ctl_elem_value *ucontrol)
2458 u32 h_control = kcontrol->private_value;
2462 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2464 ucontrol->value.integer.value[0] = rate;
2466 ucontrol->value.integer.value[0] = 0;
2470 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2471 struct snd_ctl_elem_value *ucontrol)
2474 u32 h_control = kcontrol->private_value;
2476 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2477 asihpi->mixer_clkrate[addr][1] != right;
2480 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2481 ucontrol->value.integer.value[0]));
2485 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_info *uinfo)
2488 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2490 uinfo->value.integer.min = 8000;
2491 uinfo->value.integer.max = 192000;
2492 uinfo->value.integer.step = 100;
2497 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_value *ucontrol)
2500 u32 h_control = kcontrol->private_value;
2504 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2506 ucontrol->value.integer.value[0] = rate;
2508 ucontrol->value.integer.value[0] = 0;
2512 static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2513 struct hpi_control *hpi_ctl)
2515 struct snd_card *card;
2516 struct snd_kcontrol_new snd_control;
2518 struct clk_cache *clkcache;
2519 u32 hSC = hpi_ctl->h_control;
2524 if (snd_BUG_ON(!asihpi))
2526 card = asihpi->card;
2527 clkcache = &asihpi->cc;
2528 snd_control.private_value = hpi_ctl->h_control;
2530 clkcache->has_local = 0;
2532 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2533 if (hpi_sample_clock_query_source(hSC,
2536 clkcache->s[i].source = source;
2537 clkcache->s[i].index = 0;
2538 clkcache->s[i].name = sampleclock_sources[source];
2539 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2541 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2542 clkcache->has_local = 1;
2545 /* already will have picked up index 0 above */
2546 for (j = 1; j < 8; j++) {
2547 if (hpi_sample_clock_query_source_index(hSC,
2548 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2551 clkcache->s[i].source =
2552 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2553 clkcache->s[i].index = j;
2554 clkcache->s[i].name = sampleclock_sources[
2555 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2558 clkcache->count = i;
2560 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2561 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2562 snd_control.info = snd_asihpi_clksrc_info;
2563 snd_control.get = snd_asihpi_clksrc_get;
2564 snd_control.put = snd_asihpi_clksrc_put;
2565 if (ctl_add(card, &snd_control, asihpi) < 0)
2569 if (clkcache->has_local) {
2570 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2571 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2572 snd_control.info = snd_asihpi_clklocal_info;
2573 snd_control.get = snd_asihpi_clklocal_get;
2574 snd_control.put = snd_asihpi_clklocal_put;
2577 if (ctl_add(card, &snd_control, asihpi) < 0)
2581 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2582 snd_control.access =
2583 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2584 snd_control.info = snd_asihpi_clkrate_info;
2585 snd_control.get = snd_asihpi_clkrate_get;
2587 return ctl_add(card, &snd_control, asihpi);
2589 /*------------------------------------------------------------
2591 ------------------------------------------------------------*/
2593 static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2595 struct snd_card *card;
2596 unsigned int idx = 0;
2597 unsigned int subindex = 0;
2599 struct hpi_control hpi_ctl, prev_ctl;
2601 if (snd_BUG_ON(!asihpi))
2603 card = asihpi->card;
2604 strcpy(card->mixername, "Asihpi Mixer");
2607 hpi_mixer_open(asihpi->hpi->adapter->index,
2609 hpi_handle_error(err);
2613 memset(&prev_ctl, 0, sizeof(prev_ctl));
2614 prev_ctl.control_type = -1;
2616 for (idx = 0; idx < 2000; idx++) {
2617 err = hpi_mixer_get_control_by_index(
2620 &hpi_ctl.src_node_type,
2621 &hpi_ctl.src_node_index,
2622 &hpi_ctl.dst_node_type,
2623 &hpi_ctl.dst_node_index,
2624 &hpi_ctl.control_type,
2625 &hpi_ctl.h_control);
2627 if (err == HPI_ERROR_CONTROL_DISABLED) {
2629 dev_info(&asihpi->pci->dev,
2630 "Disabled HPI Control(%d)\n",
2638 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2639 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2641 /* ASI50xx in SSX mode has multiple meters on the same node.
2642 Use subindex to create distinct ALSA controls
2643 for any duplicated controls.
2645 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2646 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2647 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2648 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2649 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2656 switch (hpi_ctl.control_type) {
2657 case HPI_CONTROL_VOLUME:
2658 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2660 case HPI_CONTROL_LEVEL:
2661 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2663 case HPI_CONTROL_MULTIPLEXER:
2664 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2666 case HPI_CONTROL_CHANNEL_MODE:
2667 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2669 case HPI_CONTROL_METER:
2670 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2672 case HPI_CONTROL_SAMPLECLOCK:
2673 err = snd_asihpi_sampleclock_add(
2676 case HPI_CONTROL_CONNECTION: /* ignore these */
2678 case HPI_CONTROL_TUNER:
2679 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2681 case HPI_CONTROL_AESEBU_TRANSMITTER:
2682 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2684 case HPI_CONTROL_AESEBU_RECEIVER:
2685 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2687 case HPI_CONTROL_VOX:
2688 case HPI_CONTROL_BITSTREAM:
2689 case HPI_CONTROL_MICROPHONE:
2690 case HPI_CONTROL_PARAMETRIC_EQ:
2691 case HPI_CONTROL_COMPANDER:
2694 dev_info(&asihpi->pci->dev,
2695 "Untranslated HPI Control (%d) %d %d %d %d %d\n",
2697 hpi_ctl.control_type,
2698 hpi_ctl.src_node_type,
2699 hpi_ctl.src_node_index,
2700 hpi_ctl.dst_node_type,
2701 hpi_ctl.dst_node_index);
2707 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2708 hpi_handle_error(err);
2710 dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx);
2715 /*------------------------------------------------------------
2717 ------------------------------------------------------------*/
2720 snd_asihpi_proc_read(struct snd_info_entry *entry,
2721 struct snd_info_buffer *buffer)
2723 struct snd_card_asihpi *asihpi = entry->private_data;
2736 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2738 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2739 &num_outstreams, &num_instreams,
2740 &version, &serial_number, &type));
2743 "Adapter type ASI%4X\nHardware Index %d\n"
2744 "%d outstreams\n%d instreams\n",
2745 type, asihpi->hpi->adapter->index,
2746 num_outstreams, num_instreams);
2749 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2750 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
2751 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2753 err = hpi_mixer_get_control(asihpi->h_mixer,
2754 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2755 HPI_CONTROL_SAMPLECLOCK, &h_control);
2758 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
2759 err += hpi_sample_clock_get_source(h_control, &source);
2762 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
2763 rate, sampleclock_sources[source]);
2767 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2769 snd_card_ro_proc_new(asihpi->card, "info", asihpi,
2770 snd_asihpi_proc_read);
2773 /*------------------------------------------------------------
2775 ------------------------------------------------------------*/
2777 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2779 if (enable_hpi_hwdep)
2786 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2788 if (enable_hpi_hwdep)
2789 return asihpi_hpi_release(file);
2794 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2795 unsigned int cmd, unsigned long arg)
2797 if (enable_hpi_hwdep)
2798 return asihpi_hpi_ioctl(file, cmd, arg);
2804 /* results in /dev/snd/hwC#D0 file for each card with index #
2805 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2807 static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, int device)
2809 struct snd_hwdep *hw;
2812 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2815 strcpy(hw->name, "asihpi (HPI)");
2816 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2817 hw->ops.open = snd_asihpi_hpi_open;
2818 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2819 hw->ops.release = snd_asihpi_hpi_release;
2820 hw->private_data = asihpi;
2824 /*------------------------------------------------------------
2826 ------------------------------------------------------------*/
2827 static int snd_asihpi_probe(struct pci_dev *pci_dev,
2828 const struct pci_device_id *pci_id)
2831 struct hpi_adapter *hpi;
2832 struct snd_card *card;
2833 struct snd_card_asihpi *asihpi;
2840 if (dev >= SNDRV_CARDS)
2843 /* Should this be enable[hpi->index] ? */
2849 /* Initialise low-level HPI driver */
2850 err = asihpi_adapter_probe(pci_dev, pci_id);
2854 hpi = pci_get_drvdata(pci_dev);
2855 adapter_index = hpi->adapter->index;
2856 /* first try to give the card the same index as its hardware index */
2857 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2858 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
2860 /* if that fails, try the default index==next available */
2861 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2862 THIS_MODULE, sizeof(struct snd_card_asihpi),
2866 dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n",
2867 adapter_index, card->number);
2870 asihpi = card->private_data;
2871 asihpi->card = card;
2872 asihpi->pci = pci_dev;
2874 hpi->snd_card = card;
2876 err = hpi_adapter_get_property(adapter_index,
2877 HPI_ADAPTER_PROPERTY_CAPS1,
2878 NULL, &asihpi->support_grouping);
2880 asihpi->support_grouping = 0;
2882 err = hpi_adapter_get_property(adapter_index,
2883 HPI_ADAPTER_PROPERTY_CAPS2,
2884 &asihpi->support_mrx, NULL);
2886 asihpi->support_mrx = 0;
2888 err = hpi_adapter_get_property(adapter_index,
2889 HPI_ADAPTER_PROPERTY_INTERVAL,
2890 NULL, &asihpi->update_interval_frames);
2892 asihpi->update_interval_frames = 512;
2894 if (hpi->interrupt_mode) {
2895 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
2896 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2897 tasklet_init(&asihpi->t, snd_card_asihpi_int_task,
2898 (unsigned long)hpi);
2899 hpi->interrupt_callback = snd_card_asihpi_isr;
2901 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
2902 asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop;
2905 hpi_handle_error(hpi_instream_open(adapter_index,
2908 err = hpi_instream_host_buffer_free(h_stream);
2909 asihpi->can_dma = (!err);
2911 hpi_handle_error(hpi_instream_close(h_stream));
2913 if (!asihpi->can_dma)
2914 asihpi->update_interval_frames *= 2;
2916 err = hpi_adapter_get_property(adapter_index,
2917 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2918 &asihpi->in_max_chans, &asihpi->out_max_chans);
2920 asihpi->in_max_chans = 2;
2921 asihpi->out_max_chans = 2;
2924 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2925 asihpi->out_min_chans = asihpi->out_max_chans;
2926 asihpi->in_min_chans = asihpi->in_max_chans;
2927 asihpi->support_grouping = 0;
2929 asihpi->out_min_chans = 1;
2930 asihpi->in_min_chans = 1;
2933 dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n",
2935 asihpi->support_grouping,
2936 asihpi->support_mrx,
2937 asihpi->update_interval_frames
2940 err = snd_card_asihpi_pcm_new(asihpi, 0);
2942 dev_err(&pci_dev->dev, "pcm_new failed\n");
2945 err = snd_card_asihpi_mixer_new(asihpi);
2947 dev_err(&pci_dev->dev, "mixer_new failed\n");
2951 err = hpi_mixer_get_control(asihpi->h_mixer,
2952 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2953 HPI_CONTROL_SAMPLECLOCK, &h_control);
2956 err = hpi_sample_clock_set_local_rate(
2957 h_control, adapter_fs);
2959 snd_asihpi_proc_init(asihpi);
2961 /* always create, can be enabled or disabled dynamically
2962 by enable_hwdep module param*/
2963 snd_asihpi_hpi_new(asihpi, 0);
2965 strcpy(card->driver, "ASIHPI");
2967 sprintf(card->shortname, "AudioScience ASI%4X",
2968 asihpi->hpi->adapter->type);
2969 sprintf(card->longname, "%s %i",
2970 card->shortname, adapter_index);
2971 err = snd_card_register(card);
2978 snd_card_free(card);
2979 dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err);
2984 static void snd_asihpi_remove(struct pci_dev *pci_dev)
2986 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2987 struct snd_card_asihpi *asihpi = hpi->snd_card->private_data;
2989 /* Stop interrupts */
2990 if (hpi->interrupt_mode) {
2991 hpi->interrupt_callback = NULL;
2992 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
2993 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
2994 tasklet_kill(&asihpi->t);
2997 snd_card_free(hpi->snd_card);
2998 hpi->snd_card = NULL;
2999 asihpi_adapter_remove(pci_dev);
3002 static const struct pci_device_id asihpi_pci_tbl[] = {
3003 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
3004 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
3005 (kernel_ulong_t)HPI_6205},
3006 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
3007 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
3008 (kernel_ulong_t)HPI_6000},
3011 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
3013 static struct pci_driver driver = {
3014 .name = KBUILD_MODNAME,
3015 .id_table = asihpi_pci_tbl,
3016 .probe = snd_asihpi_probe,
3017 .remove = snd_asihpi_remove,
3020 static int __init snd_asihpi_init(void)
3023 return pci_register_driver(&driver);
3026 static void __exit snd_asihpi_exit(void)
3029 pci_unregister_driver(&driver);
3033 module_init(snd_asihpi_init)
3034 module_exit(snd_asihpi_exit)