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 const 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_card_asihpi_format_alsa2hpi(params_format(params), &format);
456 hpi_handle_error(hpi_format_create(&dpcm->format,
457 params_channels(params),
458 format, params_rate(params), 0, 0));
460 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
461 if (hpi_instream_reset(dpcm->h_stream) != 0)
464 if (hpi_instream_set_format(
465 dpcm->h_stream, &dpcm->format) != 0)
469 dpcm->hpi_buffer_attached = 0;
471 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
472 params_buffer_bytes(params), runtime->dma_addr);
475 "stream_host_buffer_attach success %u %lu\n",
476 params_buffer_bytes(params),
477 (unsigned long)runtime->dma_addr);
479 snd_printd("stream_host_buffer_attach error %d\n",
484 err = hpi_stream_get_info_ex(dpcm->h_stream, NULL,
485 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
487 bytes_per_sec = params_rate(params) * params_channels(params);
488 width = snd_pcm_format_width(params_format(params));
489 bytes_per_sec *= width;
491 if (width < 0 || bytes_per_sec == 0)
494 dpcm->bytes_per_sec = bytes_per_sec;
495 dpcm->buffer_bytes = params_buffer_bytes(params);
496 dpcm->period_bytes = params_period_bytes(params);
502 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
504 struct snd_pcm_runtime *runtime = substream->runtime;
505 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
506 if (dpcm->hpi_buffer_attached)
507 hpi_stream_host_buffer_detach(dpcm->h_stream);
512 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
514 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
518 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
521 struct snd_pcm_runtime *runtime = substream->runtime;
522 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
527 expiry = max(expiry, 1); /* don't let it be zero! */
528 mod_timer(&dpcm->timer, jiffies + expiry);
529 dpcm->respawn_timer = 1;
532 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
534 struct snd_pcm_runtime *runtime = substream->runtime;
535 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
537 dpcm->respawn_timer = 0;
538 del_timer(&dpcm->timer);
541 static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
543 struct snd_card_asihpi_pcm *dpcm;
544 struct snd_card_asihpi *card;
546 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
547 card = snd_pcm_substream_chip(substream);
549 WARN_ON(in_interrupt());
550 tasklet_disable(&card->t);
551 card->llmode_streampriv = dpcm;
552 tasklet_enable(&card->t);
554 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
555 HPI_ADAPTER_PROPERTY_IRQ_RATE,
556 card->update_interval_frames, 0));
559 static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
561 struct snd_card_asihpi *card;
563 card = snd_pcm_substream_chip(substream);
565 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
566 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
569 card->llmode_streampriv = NULL;
571 tasklet_disable(&card->t);
572 card->llmode_streampriv = NULL;
573 tasklet_enable(&card->t);
577 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
580 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
581 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
582 struct snd_pcm_substream *s;
586 snd_pcm_debug_name(substream, name, sizeof(name));
589 case SNDRV_PCM_TRIGGER_START:
590 snd_printdd("%s trigger start\n", name);
591 snd_pcm_group_for_each_entry(s, substream) {
592 struct snd_pcm_runtime *runtime = s->runtime;
593 struct snd_card_asihpi_pcm *ds = runtime->private_data;
595 if (snd_pcm_substream_chip(s) != card)
598 /* don't link Cap and Play */
599 if (substream->stream != s->stream)
602 ds->drained_count = 0;
603 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
604 /* How do I know how much valid data is present
605 * in buffer? Must be at least one period!
606 * Guessing 2 periods, but if
607 * buffer is bigger it may contain even more
610 unsigned int preload = ds->period_bytes * 1;
611 snd_printddd("%d preload %d\n", s->number, preload);
612 hpi_handle_error(hpi_outstream_write_buf(
614 &runtime->dma_area[0],
617 ds->pcm_buf_host_rw_ofs = preload;
620 if (card->support_grouping) {
621 snd_printdd("%d group\n", s->number);
622 e = hpi_stream_group_add(
626 snd_pcm_trigger_done(s, substream);
634 /* start the master stream */
635 card->pcm_start(substream);
636 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
638 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
641 case SNDRV_PCM_TRIGGER_STOP:
642 snd_printdd("%s trigger stop\n", name);
643 card->pcm_stop(substream);
644 snd_pcm_group_for_each_entry(s, substream) {
645 if (snd_pcm_substream_chip(s) != card)
647 /* don't link Cap and Play */
648 if (substream->stream != s->stream)
651 /*? workaround linked streams don't
652 transition to SETUP 20070706*/
653 s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
655 if (card->support_grouping) {
656 snd_printdd("%d group\n", s->number);
657 snd_pcm_trigger_done(s, substream);
662 /* _prepare and _hwparams reset the stream */
663 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
664 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
666 hpi_outstream_reset(dpcm->h_stream));
668 if (card->support_grouping)
669 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
672 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
673 snd_printdd("%s trigger pause release\n", name);
674 card->pcm_start(substream);
675 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
677 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
678 snd_printdd("%s trigger pause push\n", name);
679 card->pcm_stop(substream);
680 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
683 snd_printd(KERN_ERR "\tINVALID\n");
691 Without linking degenerates to getting single stream pos etc
692 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
695 pcm_buf_dma_ofs=get_buf_pos(s);
696 for_each_linked_stream(s) {
697 pcm_buf_dma_ofs=get_buf_pos(s);
698 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
699 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
701 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
702 for_each_linked_stream(s) {
703 s->pcm_buf_dma_ofs = min_buf_pos;
704 if (new_data > period_bytes) {
706 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
713 snd_pcm_period_elapsed(s);
718 /** Minimum of 2 modulo values. Works correctly when the difference between
719 * the values is less than half the modulus
721 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
722 unsigned long int modulus)
725 if (((a-b) % modulus) < (modulus/2))
733 /** Timer function, equivalent to interrupt service routine for cards
735 static void snd_card_asihpi_timer_function(struct timer_list *t)
737 struct snd_card_asihpi_pcm *dpcm = from_timer(dpcm, t, timer);
738 struct snd_pcm_substream *substream = dpcm->substream;
739 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
740 struct snd_pcm_runtime *runtime;
741 struct snd_pcm_substream *s;
742 unsigned int newdata = 0;
743 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
744 unsigned int remdata, xfercount, next_jiffies;
748 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
752 snd_pcm_debug_name(substream, name, sizeof(name));
754 /* find minimum newdata and buffer pos in group */
755 snd_pcm_group_for_each_entry(s, substream) {
756 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
757 runtime = s->runtime;
759 if (snd_pcm_substream_chip(s) != card)
762 /* don't link Cap and Play */
763 if (substream->stream != s->stream)
766 hpi_handle_error(hpi_stream_get_info_ex(
767 ds->h_stream, &state,
768 &buffer_size, &bytes_avail,
769 &samples_played, &on_card_bytes));
771 /* number of bytes in on-card buffer */
772 runtime->delay = on_card_bytes;
775 on_card_bytes = bytes_avail;
777 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
778 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
779 if (state == HPI_STATE_STOPPED) {
780 if (bytes_avail == 0) {
781 hpi_handle_error(hpi_stream_start(ds->h_stream));
782 snd_printdd("P%d start\n", s->number);
783 ds->drained_count = 0;
785 } else if (state == HPI_STATE_DRAINED) {
786 snd_printd(KERN_WARNING "P%d drained\n",
789 if (ds->drained_count > 20) {
790 snd_pcm_stop_xrun(s);
794 ds->drained_count = 0;
797 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
800 /* can't statically init min when wrap is involved */
801 min_buf_pos = pcm_buf_dma_ofs;
802 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
806 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
808 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
813 "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
814 name, s->number, state,
815 ds->pcm_buf_elapsed_dma_ofs,
816 ds->pcm_buf_host_rw_ofs,
821 buffer_size-bytes_avail,
822 (unsigned long)frames_to_bytes(runtime,
823 runtime->status->hw_ptr),
824 (unsigned long)frames_to_bytes(runtime,
825 runtime->control->appl_ptr)
829 pcm_buf_dma_ofs = min_buf_pos;
831 remdata = newdata % dpcm->period_bytes;
832 xfercount = newdata - remdata; /* a multiple of period_bytes */
833 /* come back when on_card_bytes has decreased enough to allow
834 write to happen, or when data has been consumed to make another
837 if (xfercount && (on_card_bytes > dpcm->period_bytes))
838 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
840 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
842 next_jiffies = max(next_jiffies, 1U);
843 dpcm->timer.expires = jiffies + next_jiffies;
844 snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
845 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
847 snd_pcm_group_for_each_entry(s, substream) {
848 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
850 /* don't link Cap and Play */
851 if (substream->stream != s->stream)
854 /* Store dma offset for use by pointer callback */
855 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
858 /* Limit use of on card fifo for playback */
859 ((on_card_bytes <= ds->period_bytes) ||
860 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
864 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
865 unsigned int xfer1, xfer2;
866 char *pd = &s->runtime->dma_area[buf_ofs];
868 if (card->can_dma) { /* buffer wrap is handled at lower level */
872 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
873 xfer2 = xfercount - xfer1;
876 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
877 snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n",
878 s->number, xfer1, buf_ofs);
880 hpi_outstream_write_buf(
881 ds->h_stream, pd, xfer1,
885 pd = s->runtime->dma_area;
887 snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n",
889 xfercount - xfer1, buf_ofs);
891 hpi_outstream_write_buf(
897 snd_printddd("read1, C=%d, xfer=%d\n",
900 hpi_instream_read_buf(
904 pd = s->runtime->dma_area;
905 snd_printddd("read2, C=%d, xfer=%d\n",
908 hpi_instream_read_buf(
913 /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */
914 ds->pcm_buf_host_rw_ofs += xfercount;
915 ds->pcm_buf_elapsed_dma_ofs += xfercount;
916 snd_pcm_period_elapsed(s);
920 if (!card->hpi->interrupt_mode && dpcm->respawn_timer)
921 add_timer(&dpcm->timer);
924 static void snd_card_asihpi_int_task(struct tasklet_struct *t)
926 struct snd_card_asihpi *asihpi = from_tasklet(asihpi, t, t);
927 struct hpi_adapter *a = asihpi->hpi;
929 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
930 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
931 if (asihpi->llmode_streampriv)
932 snd_card_asihpi_timer_function(
933 &asihpi->llmode_streampriv->timer);
936 static void snd_card_asihpi_isr(struct hpi_adapter *a)
938 struct snd_card_asihpi *asihpi;
940 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
941 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
942 tasklet_schedule(&asihpi->t);
945 /***************************** PLAYBACK OPS ****************/
946 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
949 struct snd_pcm_runtime *runtime = substream->runtime;
950 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
952 snd_printdd("P%d prepare\n", substream->number);
954 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
955 dpcm->pcm_buf_host_rw_ofs = 0;
956 dpcm->pcm_buf_dma_ofs = 0;
957 dpcm->pcm_buf_elapsed_dma_ofs = 0;
961 static snd_pcm_uframes_t
962 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
964 struct snd_pcm_runtime *runtime = substream->runtime;
965 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
966 snd_pcm_uframes_t ptr;
968 snd_pcm_debug_name(substream, name, sizeof(name));
970 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
971 snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr);
975 static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
978 struct hpi_format hpi_format;
982 u32 sample_rate = 48000;
985 /* on cards without SRC, must query at valid rate,
986 * maybe set by external sync
988 err = hpi_mixer_get_control(asihpi->h_mixer,
989 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
990 HPI_CONTROL_SAMPLECLOCK, &h_control);
993 err = hpi_sample_clock_get_sample_rate(h_control,
996 for (format = HPI_FORMAT_PCM8_UNSIGNED;
997 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
998 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
999 format, sample_rate, 128000, 0);
1001 err = hpi_outstream_query_format(h_stream, &hpi_format);
1002 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
1003 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1008 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1010 struct snd_pcm_runtime *runtime = substream->runtime;
1011 struct snd_card_asihpi_pcm *dpcm;
1012 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1013 struct snd_pcm_hardware snd_card_asihpi_playback;
1016 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1020 err = hpi_outstream_open(card->hpi->adapter->index,
1021 substream->number, &dpcm->h_stream);
1022 hpi_handle_error(err);
1025 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1030 /*? also check ASI5000 samplerate source
1031 If external, only support external rate.
1032 If internal and other stream playing, can't switch
1035 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1036 dpcm->substream = substream;
1037 runtime->private_data = dpcm;
1038 runtime->private_free = snd_card_asihpi_runtime_free;
1040 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1041 if (!card->hpi->interrupt_mode) {
1042 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1043 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
1044 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1045 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1046 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1048 size_t pbmin = card->update_interval_frames *
1049 card->out_max_chans;
1050 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1051 snd_card_asihpi_playback.period_bytes_min = pbmin;
1052 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1053 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1054 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin;
1057 /* snd_card_asihpi_playback.fifo_size = 0; */
1058 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1059 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1060 snd_card_asihpi_playback.formats =
1061 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
1063 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1065 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1066 SNDRV_PCM_INFO_DOUBLE |
1067 SNDRV_PCM_INFO_BATCH |
1068 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1069 SNDRV_PCM_INFO_PAUSE |
1070 SNDRV_PCM_INFO_MMAP |
1071 SNDRV_PCM_INFO_MMAP_VALID;
1073 if (card->support_grouping) {
1074 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1075 snd_pcm_set_sync(substream);
1078 /* struct is copied, so can create initializer dynamically */
1079 runtime->hw = snd_card_asihpi_playback;
1082 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1083 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1087 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1088 card->update_interval_frames);
1090 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1091 card->update_interval_frames, UINT_MAX);
1093 snd_printdd("playback open\n");
1098 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1100 struct snd_pcm_runtime *runtime = substream->runtime;
1101 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1103 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1104 snd_printdd("playback close\n");
1109 static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1110 .open = snd_card_asihpi_playback_open,
1111 .close = snd_card_asihpi_playback_close,
1112 .hw_params = snd_card_asihpi_pcm_hw_params,
1113 .hw_free = snd_card_asihpi_hw_free,
1114 .prepare = snd_card_asihpi_playback_prepare,
1115 .trigger = snd_card_asihpi_trigger,
1116 .pointer = snd_card_asihpi_playback_pointer,
1119 /***************************** CAPTURE OPS ****************/
1120 static snd_pcm_uframes_t
1121 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1123 struct snd_pcm_runtime *runtime = substream->runtime;
1124 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1126 snd_pcm_debug_name(substream, name, sizeof(name));
1128 snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
1129 /* NOTE Unlike playback can't use actual samples_played
1130 for the capture position, because those samples aren't yet in
1131 the local buffer available for reading.
1133 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1136 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1138 struct snd_pcm_runtime *runtime = substream->runtime;
1139 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1141 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1142 dpcm->pcm_buf_host_rw_ofs = 0;
1143 dpcm->pcm_buf_dma_ofs = 0;
1144 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1146 snd_printdd("Capture Prepare %d\n", substream->number);
1150 static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1153 struct hpi_format hpi_format;
1157 u32 sample_rate = 48000;
1160 /* on cards without SRC, must query at valid rate,
1161 maybe set by external sync */
1162 err = hpi_mixer_get_control(asihpi->h_mixer,
1163 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1164 HPI_CONTROL_SAMPLECLOCK, &h_control);
1167 err = hpi_sample_clock_get_sample_rate(h_control,
1170 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1171 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1173 err = hpi_format_create(&hpi_format, asihpi->in_max_chans,
1174 format, sample_rate, 128000, 0);
1176 err = hpi_instream_query_format(h_stream, &hpi_format);
1177 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
1178 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1183 static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1185 struct snd_pcm_runtime *runtime = substream->runtime;
1186 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1187 struct snd_card_asihpi_pcm *dpcm;
1188 struct snd_pcm_hardware snd_card_asihpi_capture;
1191 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1195 snd_printdd("capture open adapter %d stream %d\n",
1196 card->hpi->adapter->index, substream->number);
1198 err = hpi_handle_error(
1199 hpi_instream_open(card->hpi->adapter->index,
1200 substream->number, &dpcm->h_stream));
1203 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1208 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1209 dpcm->substream = substream;
1210 runtime->private_data = dpcm;
1211 runtime->private_free = snd_card_asihpi_runtime_free;
1213 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1214 if (!card->hpi->interrupt_mode) {
1215 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1216 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1217 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1218 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1219 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1221 size_t pbmin = card->update_interval_frames *
1222 card->out_max_chans;
1223 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1224 snd_card_asihpi_capture.period_bytes_min = pbmin;
1225 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1226 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1227 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin;
1229 /* snd_card_asihpi_capture.fifo_size = 0; */
1230 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1231 snd_card_asihpi_capture.channels_min = card->in_min_chans;
1232 snd_card_asihpi_capture.formats =
1233 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
1234 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1235 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1236 SNDRV_PCM_INFO_MMAP |
1237 SNDRV_PCM_INFO_MMAP_VALID;
1239 if (card->support_grouping)
1240 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1242 runtime->hw = snd_card_asihpi_capture;
1245 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1246 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1250 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1251 card->update_interval_frames);
1252 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1253 card->update_interval_frames, UINT_MAX);
1255 snd_pcm_set_sync(substream);
1260 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1262 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1264 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1268 static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1269 .open = snd_card_asihpi_capture_open,
1270 .close = snd_card_asihpi_capture_close,
1271 .hw_params = snd_card_asihpi_pcm_hw_params,
1272 .hw_free = snd_card_asihpi_hw_free,
1273 .prepare = snd_card_asihpi_capture_prepare,
1274 .trigger = snd_card_asihpi_trigger,
1275 .pointer = snd_card_asihpi_capture_pointer,
1278 static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1280 struct snd_pcm *pcm;
1282 u16 num_instreams, num_outstreams, x16;
1285 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1286 &num_outstreams, &num_instreams,
1289 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1290 num_outstreams, num_instreams, &pcm);
1294 /* pointer to ops struct is stored, dont change ops afterwards! */
1295 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1296 &snd_card_asihpi_playback_mmap_ops);
1297 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1298 &snd_card_asihpi_capture_mmap_ops);
1300 pcm->private_data = asihpi;
1301 pcm->info_flags = 0;
1302 strcpy(pcm->name, "Asihpi PCM");
1304 /*? do we want to emulate MMAP for non-BBM cards?
1305 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1306 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1308 64*1024, BUFFER_BYTES_MAX);
1313 /***************************** MIXER CONTROLS ****************/
1314 struct hpi_control {
1322 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
1325 static const char * const asihpi_tuner_band_names[] = {
1338 /* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
1339 compile_time_assert(
1340 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1341 (HPI_TUNER_BAND_LAST+1)),
1342 assert_tuner_band_names_size);
1344 static const char * const asihpi_src_names[] = {
1362 /* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
1363 compile_time_assert(
1364 (ARRAY_SIZE(asihpi_src_names) ==
1365 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1366 assert_src_names_size);
1368 static const char * const asihpi_dst_names[] = {
1382 /* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
1383 compile_time_assert(
1384 (ARRAY_SIZE(asihpi_dst_names) ==
1385 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1386 assert_dst_names_size);
1388 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1389 struct snd_card_asihpi *asihpi)
1393 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1396 else if (mixer_dump)
1397 dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index);
1402 /* Convert HPI control name and location into ALSA control name */
1403 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1404 struct hpi_control *hpi_ctl,
1408 memset(snd_control, 0, sizeof(*snd_control));
1409 snd_control->name = hpi_ctl->name;
1410 snd_control->private_value = hpi_ctl->h_control;
1411 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1412 snd_control->index = 0;
1414 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1415 dir = ""; /* clock is neither capture nor playback */
1416 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1417 dir = "Capture "; /* On or towards a PCM capture destination*/
1418 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1419 (!hpi_ctl->dst_node_type))
1420 dir = "Capture "; /* On a source node that is not PCM playback */
1421 else if (hpi_ctl->src_node_type &&
1422 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1423 (hpi_ctl->dst_node_type))
1424 dir = "Monitor Playback "; /* Between an input and an output */
1426 dir = "Playback "; /* PCM Playback source, or output node */
1428 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1429 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1430 asihpi_src_names[hpi_ctl->src_node_type],
1431 hpi_ctl->src_node_index,
1432 asihpi_dst_names[hpi_ctl->dst_node_type],
1433 hpi_ctl->dst_node_index,
1435 else if (hpi_ctl->dst_node_type) {
1436 sprintf(hpi_ctl->name, "%s %d %s%s",
1437 asihpi_dst_names[hpi_ctl->dst_node_type],
1438 hpi_ctl->dst_node_index,
1441 sprintf(hpi_ctl->name, "%s %d %s%s",
1442 asihpi_src_names[hpi_ctl->src_node_type],
1443 hpi_ctl->src_node_index,
1446 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1447 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1450 /*------------------------------------------------------------
1452 ------------------------------------------------------------*/
1453 #define VOL_STEP_mB 1
1454 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1455 struct snd_ctl_elem_info *uinfo)
1457 u32 h_control = kcontrol->private_value;
1460 /* native gains are in millibels */
1465 err = hpi_volume_query_range(h_control,
1466 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1469 min_gain_mB = -10000;
1470 step_gain_mB = VOL_STEP_mB;
1473 err = hpi_meter_query_channels(h_control, &count);
1475 count = HPI_MAX_CHANNELS;
1477 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1478 uinfo->count = count;
1479 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1480 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1481 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1485 static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1486 struct snd_ctl_elem_value *ucontrol)
1488 u32 h_control = kcontrol->private_value;
1489 short an_gain_mB[HPI_MAX_CHANNELS];
1491 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
1492 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1493 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1498 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1499 struct snd_ctl_elem_value *ucontrol)
1501 u32 h_control = kcontrol->private_value;
1502 short an_gain_mB[HPI_MAX_CHANNELS];
1505 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1507 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1508 /* change = asihpi->mixer_volume[addr][0] != left ||
1509 asihpi->mixer_volume[addr][1] != right;
1511 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1515 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1517 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1519 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1520 struct snd_ctl_elem_value *ucontrol)
1522 u32 h_control = kcontrol->private_value;
1525 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1526 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1531 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_value *ucontrol)
1534 u32 h_control = kcontrol->private_value;
1535 /* HPI currently only supports all or none muting of multichannel volume
1536 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1538 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1539 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1543 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1544 struct hpi_control *hpi_ctl)
1546 struct snd_card *card = asihpi->card;
1547 struct snd_kcontrol_new snd_control;
1551 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1552 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1553 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1554 snd_control.info = snd_asihpi_volume_info;
1555 snd_control.get = snd_asihpi_volume_get;
1556 snd_control.put = snd_asihpi_volume_put;
1557 snd_control.tlv.p = db_scale_100;
1559 err = ctl_add(card, &snd_control, asihpi);
1563 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1564 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1565 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1566 snd_control.info = snd_asihpi_volume_mute_info;
1567 snd_control.get = snd_asihpi_volume_mute_get;
1568 snd_control.put = snd_asihpi_volume_mute_put;
1569 err = ctl_add(card, &snd_control, asihpi);
1574 /*------------------------------------------------------------
1576 ------------------------------------------------------------*/
1577 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1578 struct snd_ctl_elem_info *uinfo)
1580 u32 h_control = kcontrol->private_value;
1587 hpi_level_query_range(h_control, &min_gain_mB,
1588 &max_gain_mB, &step_gain_mB);
1591 min_gain_mB = -1000;
1595 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1597 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1598 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1599 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1603 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1604 struct snd_ctl_elem_value *ucontrol)
1606 u32 h_control = kcontrol->private_value;
1607 short an_gain_mB[HPI_MAX_CHANNELS];
1609 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1610 ucontrol->value.integer.value[0] =
1611 an_gain_mB[0] / HPI_UNITS_PER_dB;
1612 ucontrol->value.integer.value[1] =
1613 an_gain_mB[1] / HPI_UNITS_PER_dB;
1618 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_value *ucontrol)
1622 u32 h_control = kcontrol->private_value;
1623 short an_gain_mB[HPI_MAX_CHANNELS];
1626 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1628 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1629 /* change = asihpi->mixer_level[addr][0] != left ||
1630 asihpi->mixer_level[addr][1] != right;
1633 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1637 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1639 static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1640 struct hpi_control *hpi_ctl)
1642 struct snd_card *card = asihpi->card;
1643 struct snd_kcontrol_new snd_control;
1645 /* can't use 'volume' cos some nodes have volume as well */
1646 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1647 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1648 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1649 snd_control.info = snd_asihpi_level_info;
1650 snd_control.get = snd_asihpi_level_get;
1651 snd_control.put = snd_asihpi_level_put;
1652 snd_control.tlv.p = db_scale_level;
1654 return ctl_add(card, &snd_control, asihpi);
1657 /*------------------------------------------------------------
1659 ------------------------------------------------------------*/
1662 static const char * const asihpi_aesebu_format_names[] = {
1663 "N/A", "S/PDIF", "AES/EBU" };
1665 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1666 struct snd_ctl_elem_info *uinfo)
1668 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
1671 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1672 struct snd_ctl_elem_value *ucontrol,
1673 u16 (*func)(u32, u16 *))
1675 u32 h_control = kcontrol->private_value;
1678 err = func(h_control, &source);
1680 /* default to N/A */
1681 ucontrol->value.enumerated.item[0] = 0;
1682 /* return success but set the control to N/A */
1685 if (source == HPI_AESEBU_FORMAT_SPDIF)
1686 ucontrol->value.enumerated.item[0] = 1;
1687 if (source == HPI_AESEBU_FORMAT_AESEBU)
1688 ucontrol->value.enumerated.item[0] = 2;
1693 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1694 struct snd_ctl_elem_value *ucontrol,
1695 u16 (*func)(u32, u16))
1697 u32 h_control = kcontrol->private_value;
1699 /* default to S/PDIF */
1700 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1702 if (ucontrol->value.enumerated.item[0] == 1)
1703 source = HPI_AESEBU_FORMAT_SPDIF;
1704 if (ucontrol->value.enumerated.item[0] == 2)
1705 source = HPI_AESEBU_FORMAT_AESEBU;
1707 if (func(h_control, source) != 0)
1713 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_value *ucontrol) {
1715 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1716 hpi_aesebu_receiver_get_format);
1719 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1720 struct snd_ctl_elem_value *ucontrol) {
1721 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1722 hpi_aesebu_receiver_set_format);
1725 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1726 struct snd_ctl_elem_info *uinfo)
1728 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1731 uinfo->value.integer.min = 0;
1732 uinfo->value.integer.max = 0X1F;
1733 uinfo->value.integer.step = 1;
1738 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1739 struct snd_ctl_elem_value *ucontrol) {
1741 u32 h_control = kcontrol->private_value;
1744 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1745 h_control, &status));
1746 ucontrol->value.integer.value[0] = status;
1750 static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1751 struct hpi_control *hpi_ctl)
1753 struct snd_card *card = asihpi->card;
1754 struct snd_kcontrol_new snd_control;
1756 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1757 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1758 snd_control.info = snd_asihpi_aesebu_format_info;
1759 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1760 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1763 if (ctl_add(card, &snd_control, asihpi) < 0)
1766 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
1767 snd_control.access =
1768 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1769 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1770 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1772 return ctl_add(card, &snd_control, asihpi);
1775 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1776 struct snd_ctl_elem_value *ucontrol) {
1777 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1778 hpi_aesebu_transmitter_get_format);
1781 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol) {
1783 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1784 hpi_aesebu_transmitter_set_format);
1788 static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1789 struct hpi_control *hpi_ctl)
1791 struct snd_card *card = asihpi->card;
1792 struct snd_kcontrol_new snd_control;
1794 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1795 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1796 snd_control.info = snd_asihpi_aesebu_format_info;
1797 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1798 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1800 return ctl_add(card, &snd_control, asihpi);
1803 /*------------------------------------------------------------
1805 ------------------------------------------------------------*/
1809 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1810 struct snd_ctl_elem_info *uinfo)
1812 u32 h_control = kcontrol->private_value;
1817 for (idx = 0; idx < 3; idx++) {
1818 err = hpi_tuner_query_gain(h_control,
1819 idx, &gain_range[idx]);
1824 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1826 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1827 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1828 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1832 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1833 struct snd_ctl_elem_value *ucontrol)
1836 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1838 u32 h_control = kcontrol->private_value;
1841 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
1842 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1847 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1848 struct snd_ctl_elem_value *ucontrol)
1851 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1853 u32 h_control = kcontrol->private_value;
1856 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1857 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
1864 static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1865 u16 *band_list, u32 len) {
1866 u32 h_control = kcontrol->private_value;
1870 for (i = 0; i < len; i++) {
1871 err = hpi_tuner_query_band(
1872 h_control, i, &band_list[i]);
1877 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1883 static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1884 struct snd_ctl_elem_info *uinfo)
1886 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1889 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1890 HPI_TUNER_BAND_LAST);
1895 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
1898 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1899 struct snd_ctl_elem_value *ucontrol)
1901 u32 h_control = kcontrol->private_value;
1903 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1906 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1907 __always_unused u32 num_bands;
1909 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1910 HPI_TUNER_BAND_LAST);
1912 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1914 ucontrol->value.enumerated.item[0] = -1;
1915 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1916 if (tuner_bands[idx] == band) {
1917 ucontrol->value.enumerated.item[0] = idx;
1924 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1925 struct snd_ctl_elem_value *ucontrol)
1928 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1930 u32 h_control = kcontrol->private_value;
1933 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1934 __always_unused u32 num_bands;
1936 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1937 HPI_TUNER_BAND_LAST);
1939 idx = ucontrol->value.enumerated.item[0];
1940 if (idx >= ARRAY_SIZE(tuner_bands))
1941 idx = ARRAY_SIZE(tuner_bands) - 1;
1942 band = tuner_bands[idx];
1943 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1950 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1951 struct snd_ctl_elem_info *uinfo)
1953 u32 h_control = kcontrol->private_value;
1955 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1956 u16 num_bands = 0, band_iter, idx;
1957 u32 freq_range[3], temp_freq_range[3];
1959 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1960 HPI_TUNER_BAND_LAST);
1962 freq_range[0] = INT_MAX;
1964 freq_range[2] = INT_MAX;
1966 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1967 for (idx = 0; idx < 3; idx++) {
1968 err = hpi_tuner_query_frequency(h_control,
1969 idx, tuner_bands[band_iter],
1970 &temp_freq_range[idx]);
1975 /* skip band with bogus stepping */
1976 if (temp_freq_range[2] <= 0)
1979 if (temp_freq_range[0] < freq_range[0])
1980 freq_range[0] = temp_freq_range[0];
1981 if (temp_freq_range[1] > freq_range[1])
1982 freq_range[1] = temp_freq_range[1];
1983 if (temp_freq_range[2] < freq_range[2])
1984 freq_range[2] = temp_freq_range[2];
1987 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1989 uinfo->value.integer.min = ((int)freq_range[0]);
1990 uinfo->value.integer.max = ((int)freq_range[1]);
1991 uinfo->value.integer.step = ((int)freq_range[2]);
1995 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1996 struct snd_ctl_elem_value *ucontrol)
1998 u32 h_control = kcontrol->private_value;
2001 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
2002 ucontrol->value.integer.value[0] = freq;
2007 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
2008 struct snd_ctl_elem_value *ucontrol)
2010 u32 h_control = kcontrol->private_value;
2013 freq = ucontrol->value.integer.value[0];
2014 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
2019 /* Tuner control group initializer */
2020 static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
2021 struct hpi_control *hpi_ctl)
2023 struct snd_card *card = asihpi->card;
2024 struct snd_kcontrol_new snd_control;
2026 snd_control.private_value = hpi_ctl->h_control;
2027 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2029 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
2030 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
2031 snd_control.info = snd_asihpi_tuner_gain_info;
2032 snd_control.get = snd_asihpi_tuner_gain_get;
2033 snd_control.put = snd_asihpi_tuner_gain_put;
2035 if (ctl_add(card, &snd_control, asihpi) < 0)
2039 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
2040 snd_control.info = snd_asihpi_tuner_band_info;
2041 snd_control.get = snd_asihpi_tuner_band_get;
2042 snd_control.put = snd_asihpi_tuner_band_put;
2044 if (ctl_add(card, &snd_control, asihpi) < 0)
2047 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2048 snd_control.info = snd_asihpi_tuner_freq_info;
2049 snd_control.get = snd_asihpi_tuner_freq_get;
2050 snd_control.put = snd_asihpi_tuner_freq_put;
2052 return ctl_add(card, &snd_control, asihpi);
2055 /*------------------------------------------------------------
2057 ------------------------------------------------------------*/
2058 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_info *uinfo)
2061 u32 h_control = kcontrol->private_value;
2064 err = hpi_meter_query_channels(h_control, &count);
2066 count = HPI_MAX_CHANNELS;
2068 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2069 uinfo->count = count;
2070 uinfo->value.integer.min = 0;
2071 uinfo->value.integer.max = 0x7FFFFFFF;
2075 /* linear values for 10dB steps */
2076 static const int log2lin[] = {
2077 0x7FFFFFFF, /* 0dB */
2083 2147484, /* -60dB */
2098 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2101 u32 h_control = kcontrol->private_value;
2102 short an_gain_mB[HPI_MAX_CHANNELS], i;
2105 err = hpi_meter_get_peak(h_control, an_gain_mB);
2107 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2109 ucontrol->value.integer.value[i] = 0;
2110 } else if (an_gain_mB[i] >= 0) {
2111 ucontrol->value.integer.value[i] =
2112 an_gain_mB[i] << 16;
2114 /* -ve is log value in millibels < -60dB,
2115 * convert to (roughly!) linear,
2117 ucontrol->value.integer.value[i] =
2118 log2lin[an_gain_mB[i] / -1000];
2124 static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2125 struct hpi_control *hpi_ctl, int subidx)
2127 struct snd_card *card = asihpi->card;
2128 struct snd_kcontrol_new snd_control;
2130 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2131 snd_control.access =
2132 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2133 snd_control.info = snd_asihpi_meter_info;
2134 snd_control.get = snd_asihpi_meter_get;
2136 snd_control.index = subidx;
2138 return ctl_add(card, &snd_control, asihpi);
2141 /*------------------------------------------------------------
2142 Multiplexer controls
2143 ------------------------------------------------------------*/
2144 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2146 u32 h_control = snd_control->private_value;
2147 struct hpi_control hpi_ctl;
2149 for (s = 0; s < 32; s++) {
2150 err = hpi_multiplexer_query_source(h_control, s,
2161 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2162 struct snd_ctl_elem_info *uinfo)
2164 u16 src_node_type, src_node_index;
2165 u32 h_control = kcontrol->private_value;
2167 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2169 uinfo->value.enumerated.items =
2170 snd_card_asihpi_mux_count_sources(kcontrol);
2172 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2173 uinfo->value.enumerated.item =
2174 uinfo->value.enumerated.items - 1;
2176 hpi_multiplexer_query_source(h_control,
2177 uinfo->value.enumerated.item,
2178 &src_node_type, &src_node_index);
2180 sprintf(uinfo->value.enumerated.name, "%s %d",
2181 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2186 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2187 struct snd_ctl_elem_value *ucontrol)
2189 u32 h_control = kcontrol->private_value;
2190 u16 source_type, source_index;
2191 u16 src_node_type, src_node_index;
2194 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2195 &source_type, &source_index));
2196 /* Should cache this search result! */
2197 for (s = 0; s < 256; s++) {
2198 if (hpi_multiplexer_query_source(h_control, s,
2199 &src_node_type, &src_node_index))
2202 if ((source_type == src_node_type)
2203 && (source_index == src_node_index)) {
2204 ucontrol->value.enumerated.item[0] = s;
2208 snd_printd(KERN_WARNING
2209 "Control %x failed to match mux source %hu %hu\n",
2210 h_control, source_type, source_index);
2211 ucontrol->value.enumerated.item[0] = 0;
2215 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2216 struct snd_ctl_elem_value *ucontrol)
2219 u32 h_control = kcontrol->private_value;
2220 u16 source_type, source_index;
2225 e = hpi_multiplexer_query_source(h_control,
2226 ucontrol->value.enumerated.item[0],
2227 &source_type, &source_index);
2230 hpi_multiplexer_set_source(h_control,
2231 source_type, source_index));
2236 static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2237 struct hpi_control *hpi_ctl)
2239 struct snd_card *card = asihpi->card;
2240 struct snd_kcontrol_new snd_control;
2242 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2243 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2244 snd_control.info = snd_asihpi_mux_info;
2245 snd_control.get = snd_asihpi_mux_get;
2246 snd_control.put = snd_asihpi_mux_put;
2248 return ctl_add(card, &snd_control, asihpi);
2252 /*------------------------------------------------------------
2253 Channel mode controls
2254 ------------------------------------------------------------*/
2255 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2256 struct snd_ctl_elem_info *uinfo)
2258 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2261 "From Left", "From Right",
2262 "To Left", "To Right"
2265 u32 h_control = kcontrol->private_value;
2268 const char *mapped_names[6];
2269 int valid_modes = 0;
2271 /* HPI channel mode values can be from 1 to 6
2272 Some adapters only support a contiguous subset
2274 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2275 if (!hpi_channel_mode_query_mode(
2276 h_control, i, &mode)) {
2277 mapped_names[valid_modes] = mode_names[mode];
2284 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
2287 static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2288 struct snd_ctl_elem_value *ucontrol)
2290 u32 h_control = kcontrol->private_value;
2293 if (hpi_channel_mode_get(h_control, &mode))
2296 ucontrol->value.enumerated.item[0] = mode - 1;
2301 static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2302 struct snd_ctl_elem_value *ucontrol)
2305 u32 h_control = kcontrol->private_value;
2309 hpi_handle_error(hpi_channel_mode_set(h_control,
2310 ucontrol->value.enumerated.item[0] + 1));
2315 static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2316 struct hpi_control *hpi_ctl)
2318 struct snd_card *card = asihpi->card;
2319 struct snd_kcontrol_new snd_control;
2321 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
2322 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2323 snd_control.info = snd_asihpi_cmode_info;
2324 snd_control.get = snd_asihpi_cmode_get;
2325 snd_control.put = snd_asihpi_cmode_put;
2327 return ctl_add(card, &snd_control, asihpi);
2330 /*------------------------------------------------------------
2331 Sampleclock source controls
2332 ------------------------------------------------------------*/
2333 static const char * const sampleclock_sources[] = {
2334 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2335 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2336 "Prev Module", "BLU-Link",
2337 "Digital2", "Digital3", "Digital4", "Digital5",
2338 "Digital6", "Digital7", "Digital8"};
2340 /* Number of strings must match expected enumerated values */
2341 compile_time_assert(
2342 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2343 assert_sampleclock_sources_size);
2345 static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2346 struct snd_ctl_elem_info *uinfo)
2348 struct snd_card_asihpi *asihpi =
2349 (struct snd_card_asihpi *)(kcontrol->private_data);
2350 struct clk_cache *clkcache = &asihpi->cc;
2351 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2353 uinfo->value.enumerated.items = clkcache->count;
2355 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2356 uinfo->value.enumerated.item =
2357 uinfo->value.enumerated.items - 1;
2359 strcpy(uinfo->value.enumerated.name,
2360 clkcache->s[uinfo->value.enumerated.item].name);
2364 static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2365 struct snd_ctl_elem_value *ucontrol)
2367 struct snd_card_asihpi *asihpi =
2368 (struct snd_card_asihpi *)(kcontrol->private_data);
2369 struct clk_cache *clkcache = &asihpi->cc;
2370 u32 h_control = kcontrol->private_value;
2371 u16 source, srcindex = 0;
2374 ucontrol->value.enumerated.item[0] = 0;
2375 if (hpi_sample_clock_get_source(h_control, &source))
2378 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2379 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
2382 for (i = 0; i < clkcache->count; i++)
2383 if ((clkcache->s[i].source == source) &&
2384 (clkcache->s[i].index == srcindex))
2387 ucontrol->value.enumerated.item[0] = i;
2392 static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2393 struct snd_ctl_elem_value *ucontrol)
2395 struct snd_card_asihpi *asihpi =
2396 (struct snd_card_asihpi *)(kcontrol->private_data);
2397 struct clk_cache *clkcache = &asihpi->cc;
2400 u32 h_control = kcontrol->private_value;
2403 item = ucontrol->value.enumerated.item[0];
2404 if (item >= clkcache->count)
2405 item = clkcache->count-1;
2407 hpi_handle_error(hpi_sample_clock_set_source(
2408 h_control, clkcache->s[item].source));
2410 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2411 hpi_handle_error(hpi_sample_clock_set_source_index(
2412 h_control, clkcache->s[item].index));
2416 /*------------------------------------------------------------
2418 ------------------------------------------------------------*/
2419 /* Need to change this to enumerated control with list of rates */
2420 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2421 struct snd_ctl_elem_info *uinfo)
2423 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2425 uinfo->value.integer.min = 8000;
2426 uinfo->value.integer.max = 192000;
2427 uinfo->value.integer.step = 100;
2432 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2433 struct snd_ctl_elem_value *ucontrol)
2435 u32 h_control = kcontrol->private_value;
2439 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2441 ucontrol->value.integer.value[0] = rate;
2443 ucontrol->value.integer.value[0] = 0;
2447 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2448 struct snd_ctl_elem_value *ucontrol)
2451 u32 h_control = kcontrol->private_value;
2453 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2454 asihpi->mixer_clkrate[addr][1] != right;
2457 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2458 ucontrol->value.integer.value[0]));
2462 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2463 struct snd_ctl_elem_info *uinfo)
2465 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2467 uinfo->value.integer.min = 8000;
2468 uinfo->value.integer.max = 192000;
2469 uinfo->value.integer.step = 100;
2474 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2475 struct snd_ctl_elem_value *ucontrol)
2477 u32 h_control = kcontrol->private_value;
2481 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2483 ucontrol->value.integer.value[0] = rate;
2485 ucontrol->value.integer.value[0] = 0;
2489 static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2490 struct hpi_control *hpi_ctl)
2492 struct snd_card *card;
2493 struct snd_kcontrol_new snd_control;
2495 struct clk_cache *clkcache;
2496 u32 hSC = hpi_ctl->h_control;
2501 if (snd_BUG_ON(!asihpi))
2503 card = asihpi->card;
2504 clkcache = &asihpi->cc;
2505 snd_control.private_value = hpi_ctl->h_control;
2507 clkcache->has_local = 0;
2509 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2510 if (hpi_sample_clock_query_source(hSC,
2513 clkcache->s[i].source = source;
2514 clkcache->s[i].index = 0;
2515 clkcache->s[i].name = sampleclock_sources[source];
2516 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2518 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2519 clkcache->has_local = 1;
2522 /* already will have picked up index 0 above */
2523 for (j = 1; j < 8; j++) {
2524 if (hpi_sample_clock_query_source_index(hSC,
2525 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2528 clkcache->s[i].source =
2529 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2530 clkcache->s[i].index = j;
2531 clkcache->s[i].name = sampleclock_sources[
2532 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2535 clkcache->count = i;
2537 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2538 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2539 snd_control.info = snd_asihpi_clksrc_info;
2540 snd_control.get = snd_asihpi_clksrc_get;
2541 snd_control.put = snd_asihpi_clksrc_put;
2542 if (ctl_add(card, &snd_control, asihpi) < 0)
2546 if (clkcache->has_local) {
2547 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2548 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2549 snd_control.info = snd_asihpi_clklocal_info;
2550 snd_control.get = snd_asihpi_clklocal_get;
2551 snd_control.put = snd_asihpi_clklocal_put;
2554 if (ctl_add(card, &snd_control, asihpi) < 0)
2558 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2559 snd_control.access =
2560 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2561 snd_control.info = snd_asihpi_clkrate_info;
2562 snd_control.get = snd_asihpi_clkrate_get;
2564 return ctl_add(card, &snd_control, asihpi);
2566 /*------------------------------------------------------------
2568 ------------------------------------------------------------*/
2570 static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2572 struct snd_card *card;
2573 unsigned int idx = 0;
2574 unsigned int subindex = 0;
2576 struct hpi_control hpi_ctl, prev_ctl;
2578 if (snd_BUG_ON(!asihpi))
2580 card = asihpi->card;
2581 strcpy(card->mixername, "Asihpi Mixer");
2584 hpi_mixer_open(asihpi->hpi->adapter->index,
2586 hpi_handle_error(err);
2590 memset(&prev_ctl, 0, sizeof(prev_ctl));
2591 prev_ctl.control_type = -1;
2593 for (idx = 0; idx < 2000; idx++) {
2594 err = hpi_mixer_get_control_by_index(
2597 &hpi_ctl.src_node_type,
2598 &hpi_ctl.src_node_index,
2599 &hpi_ctl.dst_node_type,
2600 &hpi_ctl.dst_node_index,
2601 &hpi_ctl.control_type,
2602 &hpi_ctl.h_control);
2604 if (err == HPI_ERROR_CONTROL_DISABLED) {
2606 dev_info(&asihpi->pci->dev,
2607 "Disabled HPI Control(%d)\n",
2615 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2616 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2618 /* ASI50xx in SSX mode has multiple meters on the same node.
2619 Use subindex to create distinct ALSA controls
2620 for any duplicated controls.
2622 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2623 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2624 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2625 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2626 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2633 switch (hpi_ctl.control_type) {
2634 case HPI_CONTROL_VOLUME:
2635 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2637 case HPI_CONTROL_LEVEL:
2638 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2640 case HPI_CONTROL_MULTIPLEXER:
2641 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2643 case HPI_CONTROL_CHANNEL_MODE:
2644 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2646 case HPI_CONTROL_METER:
2647 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2649 case HPI_CONTROL_SAMPLECLOCK:
2650 err = snd_asihpi_sampleclock_add(
2653 case HPI_CONTROL_CONNECTION: /* ignore these */
2655 case HPI_CONTROL_TUNER:
2656 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2658 case HPI_CONTROL_AESEBU_TRANSMITTER:
2659 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2661 case HPI_CONTROL_AESEBU_RECEIVER:
2662 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2664 case HPI_CONTROL_VOX:
2665 case HPI_CONTROL_BITSTREAM:
2666 case HPI_CONTROL_MICROPHONE:
2667 case HPI_CONTROL_PARAMETRIC_EQ:
2668 case HPI_CONTROL_COMPANDER:
2671 dev_info(&asihpi->pci->dev,
2672 "Untranslated HPI Control (%d) %d %d %d %d %d\n",
2674 hpi_ctl.control_type,
2675 hpi_ctl.src_node_type,
2676 hpi_ctl.src_node_index,
2677 hpi_ctl.dst_node_type,
2678 hpi_ctl.dst_node_index);
2684 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2685 hpi_handle_error(err);
2687 dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx);
2692 /*------------------------------------------------------------
2694 ------------------------------------------------------------*/
2697 snd_asihpi_proc_read(struct snd_info_entry *entry,
2698 struct snd_info_buffer *buffer)
2700 struct snd_card_asihpi *asihpi = entry->private_data;
2713 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2715 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2716 &num_outstreams, &num_instreams,
2717 &version, &serial_number, &type));
2720 "Adapter type ASI%4X\nHardware Index %d\n"
2721 "%d outstreams\n%d instreams\n",
2722 type, asihpi->hpi->adapter->index,
2723 num_outstreams, num_instreams);
2726 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2727 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
2728 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2730 err = hpi_mixer_get_control(asihpi->h_mixer,
2731 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2732 HPI_CONTROL_SAMPLECLOCK, &h_control);
2735 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
2736 err += hpi_sample_clock_get_source(h_control, &source);
2739 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
2740 rate, sampleclock_sources[source]);
2744 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2746 snd_card_ro_proc_new(asihpi->card, "info", asihpi,
2747 snd_asihpi_proc_read);
2750 /*------------------------------------------------------------
2752 ------------------------------------------------------------*/
2754 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2756 if (enable_hpi_hwdep)
2763 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2765 if (enable_hpi_hwdep)
2766 return asihpi_hpi_release(file);
2771 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2772 unsigned int cmd, unsigned long arg)
2774 if (enable_hpi_hwdep)
2775 return asihpi_hpi_ioctl(file, cmd, arg);
2781 /* results in /dev/snd/hwC#D0 file for each card with index #
2782 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2784 static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, int device)
2786 struct snd_hwdep *hw;
2789 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2792 strcpy(hw->name, "asihpi (HPI)");
2793 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2794 hw->ops.open = snd_asihpi_hpi_open;
2795 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2796 hw->ops.release = snd_asihpi_hpi_release;
2797 hw->private_data = asihpi;
2801 /*------------------------------------------------------------
2803 ------------------------------------------------------------*/
2804 static int snd_asihpi_probe(struct pci_dev *pci_dev,
2805 const struct pci_device_id *pci_id)
2808 struct hpi_adapter *hpi;
2809 struct snd_card *card;
2810 struct snd_card_asihpi *asihpi;
2817 if (dev >= SNDRV_CARDS)
2820 /* Should this be enable[hpi->index] ? */
2826 /* Initialise low-level HPI driver */
2827 err = asihpi_adapter_probe(pci_dev, pci_id);
2831 hpi = pci_get_drvdata(pci_dev);
2832 adapter_index = hpi->adapter->index;
2833 /* first try to give the card the same index as its hardware index */
2834 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2835 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
2837 /* if that fails, try the default index==next available */
2838 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2839 THIS_MODULE, sizeof(struct snd_card_asihpi),
2843 dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n",
2844 adapter_index, card->number);
2847 asihpi = card->private_data;
2848 asihpi->card = card;
2849 asihpi->pci = pci_dev;
2851 hpi->snd_card = card;
2853 err = hpi_adapter_get_property(adapter_index,
2854 HPI_ADAPTER_PROPERTY_CAPS1,
2855 NULL, &asihpi->support_grouping);
2857 asihpi->support_grouping = 0;
2859 err = hpi_adapter_get_property(adapter_index,
2860 HPI_ADAPTER_PROPERTY_CAPS2,
2861 &asihpi->support_mrx, NULL);
2863 asihpi->support_mrx = 0;
2865 err = hpi_adapter_get_property(adapter_index,
2866 HPI_ADAPTER_PROPERTY_INTERVAL,
2867 NULL, &asihpi->update_interval_frames);
2869 asihpi->update_interval_frames = 512;
2871 if (hpi->interrupt_mode) {
2872 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
2873 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2874 tasklet_setup(&asihpi->t, snd_card_asihpi_int_task);
2875 hpi->interrupt_callback = snd_card_asihpi_isr;
2877 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
2878 asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop;
2881 hpi_handle_error(hpi_instream_open(adapter_index,
2884 err = hpi_instream_host_buffer_free(h_stream);
2885 asihpi->can_dma = (!err);
2887 hpi_handle_error(hpi_instream_close(h_stream));
2889 if (!asihpi->can_dma)
2890 asihpi->update_interval_frames *= 2;
2892 err = hpi_adapter_get_property(adapter_index,
2893 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2894 &asihpi->in_max_chans, &asihpi->out_max_chans);
2896 asihpi->in_max_chans = 2;
2897 asihpi->out_max_chans = 2;
2900 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2901 asihpi->out_min_chans = asihpi->out_max_chans;
2902 asihpi->in_min_chans = asihpi->in_max_chans;
2903 asihpi->support_grouping = 0;
2905 asihpi->out_min_chans = 1;
2906 asihpi->in_min_chans = 1;
2909 dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n",
2911 asihpi->support_grouping,
2912 asihpi->support_mrx,
2913 asihpi->update_interval_frames
2916 err = snd_card_asihpi_pcm_new(asihpi, 0);
2918 dev_err(&pci_dev->dev, "pcm_new failed\n");
2921 err = snd_card_asihpi_mixer_new(asihpi);
2923 dev_err(&pci_dev->dev, "mixer_new failed\n");
2927 err = hpi_mixer_get_control(asihpi->h_mixer,
2928 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2929 HPI_CONTROL_SAMPLECLOCK, &h_control);
2932 err = hpi_sample_clock_set_local_rate(
2933 h_control, adapter_fs);
2935 snd_asihpi_proc_init(asihpi);
2937 /* always create, can be enabled or disabled dynamically
2938 by enable_hwdep module param*/
2939 snd_asihpi_hpi_new(asihpi, 0);
2941 strcpy(card->driver, "ASIHPI");
2943 sprintf(card->shortname, "AudioScience ASI%4X",
2944 asihpi->hpi->adapter->type);
2945 sprintf(card->longname, "%s %i",
2946 card->shortname, adapter_index);
2947 err = snd_card_register(card);
2954 snd_card_free(card);
2955 dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err);
2960 static void snd_asihpi_remove(struct pci_dev *pci_dev)
2962 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2963 struct snd_card_asihpi *asihpi = hpi->snd_card->private_data;
2965 /* Stop interrupts */
2966 if (hpi->interrupt_mode) {
2967 hpi->interrupt_callback = NULL;
2968 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
2969 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
2970 tasklet_kill(&asihpi->t);
2973 snd_card_free(hpi->snd_card);
2974 hpi->snd_card = NULL;
2975 asihpi_adapter_remove(pci_dev);
2978 static const struct pci_device_id asihpi_pci_tbl[] = {
2979 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2980 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2981 (kernel_ulong_t)HPI_6205},
2982 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2983 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2984 (kernel_ulong_t)HPI_6000},
2987 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2989 static struct pci_driver driver = {
2990 .name = KBUILD_MODNAME,
2991 .id_table = asihpi_pci_tbl,
2992 .probe = snd_asihpi_probe,
2993 .remove = snd_asihpi_remove,
2996 static int __init snd_asihpi_init(void)
2999 return pci_register_driver(&driver);
3002 static void __exit snd_asihpi_exit(void)
3005 pci_unregister_driver(&driver);
3009 module_init(snd_asihpi_init)
3010 module_exit(snd_asihpi_exit)