1 // SPDX-License-Identifier: GPL-2.0-only
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");
36 MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx "
39 #ifdef ASIHPI_VERBOSE_DEBUG
40 #define asihpi_dbg(format, args...) pr_debug(format, ##args)
42 #define asihpi_dbg(format, args...) do { } while (0)
45 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
46 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
47 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
48 static bool enable_hpi_hwdep = 1;
50 module_param_array(index, int, NULL, 0444);
51 MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
53 module_param_array(id, charp, NULL, 0444);
54 MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
56 module_param_array(enable, bool, NULL, 0444);
57 MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
59 module_param(enable_hpi_hwdep, bool, 0644);
60 MODULE_PARM_DESC(enable_hpi_hwdep,
61 "ALSA enable HPI hwdep for AudioScience soundcard ");
64 #ifdef KERNEL_ALSA_BUILD
65 static char *build_info = "Built using headers from kernel source";
66 module_param(build_info, charp, 0444);
67 MODULE_PARM_DESC(build_info, "Built using headers from kernel source");
69 static char *build_info = "Built within ALSA source";
70 module_param(build_info, charp, 0444);
71 MODULE_PARM_DESC(build_info, "Built within ALSA source");
74 /* set to 1 to dump every control from adapter to log */
75 static const int mixer_dump;
77 #define DEFAULT_SAMPLERATE 44100
78 static int adapter_fs = DEFAULT_SAMPLERATE;
82 #define PERIOD_BYTES_MIN 2048
83 #define BUFFER_BYTES_MAX (512 * 1024)
85 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
96 struct clk_source s[MAX_CLOCKSOURCES];
100 struct snd_card_asihpi {
101 struct snd_card *card;
103 struct hpi_adapter *hpi;
105 /* In low latency mode there is only one stream, a pointer to its
106 * private data is stored here on trigger and cleared on stop.
107 * The interrupt handler uses it as a parameter when calling
108 * snd_card_asihpi_timer_function().
110 struct snd_card_asihpi_pcm *llmode_streampriv;
111 void (*pcm_start)(struct snd_pcm_substream *substream);
112 void (*pcm_stop)(struct snd_pcm_substream *substream);
118 u16 support_grouping;
120 u16 update_interval_frames;
127 /* Per stream data */
128 struct snd_card_asihpi_pcm {
129 struct timer_list timer;
130 unsigned int respawn_timer;
131 unsigned int hpi_buffer_attached;
132 unsigned int buffer_bytes;
133 unsigned int period_bytes;
134 unsigned int bytes_per_sec;
135 unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */
136 unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */
137 unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */
138 unsigned int drained_count;
139 struct snd_pcm_substream *substream;
141 struct hpi_format format;
144 /* universal stream verbs work with out or in stream handles */
146 /* Functions to allow driver to give a buffer to HPI for busmastering */
148 static u16 hpi_stream_host_buffer_attach(
149 u32 h_stream, /* handle to outstream. */
150 u32 size_in_bytes, /* size in bytes of bus mastering buffer */
154 struct hpi_message hm;
155 struct hpi_response hr;
156 unsigned int obj = hpi_handle_object(h_stream);
159 return HPI_ERROR_INVALID_OBJ;
160 hpi_init_message_response(&hm, &hr, obj,
161 obj == HPI_OBJ_OSTREAM ?
162 HPI_OSTREAM_HOSTBUFFER_ALLOC :
163 HPI_ISTREAM_HOSTBUFFER_ALLOC);
165 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
168 hm.u.d.u.buffer.buffer_size = size_in_bytes;
169 hm.u.d.u.buffer.pci_address = pci_address;
170 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
171 hpi_send_recv(&hm, &hr);
175 static u16 hpi_stream_host_buffer_detach(u32 h_stream)
177 struct hpi_message hm;
178 struct hpi_response hr;
179 unsigned int obj = hpi_handle_object(h_stream);
182 return HPI_ERROR_INVALID_OBJ;
184 hpi_init_message_response(&hm, &hr, obj,
185 obj == HPI_OBJ_OSTREAM ?
186 HPI_OSTREAM_HOSTBUFFER_FREE :
187 HPI_ISTREAM_HOSTBUFFER_FREE);
189 hpi_handle_to_indexes(h_stream, &hm.adapter_index,
191 hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
192 hpi_send_recv(&hm, &hr);
196 static inline u16 hpi_stream_start(u32 h_stream)
198 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
199 return hpi_outstream_start(h_stream);
201 return hpi_instream_start(h_stream);
204 static inline u16 hpi_stream_stop(u32 h_stream)
206 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
207 return hpi_outstream_stop(h_stream);
209 return hpi_instream_stop(h_stream);
212 static inline u16 hpi_stream_get_info_ex(
216 u32 *pdata_in_buffer,
222 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
223 e = hpi_outstream_get_info_ex(h_stream, pw_state,
224 pbuffer_size, pdata_in_buffer,
225 psample_count, pauxiliary_data);
227 e = hpi_instream_get_info_ex(h_stream, pw_state,
228 pbuffer_size, pdata_in_buffer,
229 psample_count, pauxiliary_data);
233 static inline u16 hpi_stream_group_add(
237 if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM)
238 return hpi_outstream_group_add(h_master, h_stream);
240 return hpi_instream_group_add(h_master, h_stream);
243 static inline u16 hpi_stream_group_reset(u32 h_stream)
245 if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM)
246 return hpi_outstream_group_reset(h_stream);
248 return hpi_instream_group_reset(h_stream);
251 static u16 handle_error(u16 err, int line, char *filename)
254 pr_warn("in file %s, line %d: HPI error %d\n",
255 filename, line, err);
259 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
261 /***************************** GENERAL PCM ****************/
263 static void print_hwparams(struct snd_pcm_substream *substream,
264 struct snd_pcm_hw_params *p)
266 struct device *dev = substream->pcm->card->dev;
269 snd_pcm_debug_name(substream, name, sizeof(name));
270 dev_dbg(dev, "%s HWPARAMS\n", name);
271 dev_dbg(dev, " samplerate=%dHz channels=%d format=%d subformat=%d\n",
272 params_rate(p), params_channels(p),
273 params_format(p), params_subformat(p));
274 dev_dbg(dev, " buffer=%dB period=%dB period_size=%dB periods=%d\n",
275 params_buffer_bytes(p), params_period_bytes(p),
276 params_period_size(p), params_periods(p));
277 dev_dbg(dev, " buffer_size=%d access=%d data_rate=%dB/s\n",
278 params_buffer_size(p), params_access(p),
279 params_rate(p) * params_channels(p) *
280 snd_pcm_format_width(params_format(p)) / 8);
283 #define INVALID_FORMAT (__force snd_pcm_format_t)(-1)
285 static const snd_pcm_format_t hpi_to_alsa_formats[] = {
286 INVALID_FORMAT, /* INVALID */
287 SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
288 SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */
289 INVALID_FORMAT, /* HPI_FORMAT_MPEG_L1 3 */
290 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */
291 SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */
292 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC2 6 */
293 INVALID_FORMAT, /* HPI_FORMAT_DOLBY_AC3 7 */
294 SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
295 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
296 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
297 SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */
298 INVALID_FORMAT, /* HPI_FORMAT_RAW_BITSTREAM 12 */
299 INVALID_FORMAT, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
300 SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */
302 /* ALSA can't handle 3 byte sample size together with power-of-2
303 * constraint on buffer_bytes, so disable this format
307 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
312 static int snd_card_asihpi_format_alsa2hpi(struct snd_card_asihpi *asihpi,
313 snd_pcm_format_t alsa_format,
318 for (format = HPI_FORMAT_PCM8_UNSIGNED;
319 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
320 if (hpi_to_alsa_formats[format] == alsa_format) {
321 *hpi_format = format;
326 dev_dbg(asihpi->card->dev, "failed match for alsa format %d\n",
332 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
333 struct snd_pcm_hardware *pcmhw)
339 unsigned int rate_min = 200000;
340 unsigned int rate_max = 0;
341 unsigned int rates = 0;
343 if (asihpi->support_mrx) {
344 rates |= SNDRV_PCM_RATE_CONTINUOUS;
345 rates |= SNDRV_PCM_RATE_8000_96000;
349 /* on cards without SRC,
350 valid rates are determined by sampleclock */
351 err = hpi_mixer_get_control(asihpi->h_mixer,
352 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
353 HPI_CONTROL_SAMPLECLOCK, &h_control);
355 dev_err(&asihpi->pci->dev,
356 "No local sampleclock, err %d\n", err);
359 for (idx = -1; idx < 100; idx++) {
361 if (hpi_sample_clock_get_sample_rate(h_control,
364 } else if (hpi_sample_clock_query_local_rate(h_control,
365 idx, &sample_rate)) {
369 rate_min = min(rate_min, sample_rate);
370 rate_max = max(rate_max, sample_rate);
372 switch (sample_rate) {
374 rates |= SNDRV_PCM_RATE_5512;
377 rates |= SNDRV_PCM_RATE_8000;
380 rates |= SNDRV_PCM_RATE_11025;
383 rates |= SNDRV_PCM_RATE_16000;
386 rates |= SNDRV_PCM_RATE_22050;
389 rates |= SNDRV_PCM_RATE_32000;
392 rates |= SNDRV_PCM_RATE_44100;
395 rates |= SNDRV_PCM_RATE_48000;
398 rates |= SNDRV_PCM_RATE_64000;
401 rates |= SNDRV_PCM_RATE_88200;
404 rates |= SNDRV_PCM_RATE_96000;
407 rates |= SNDRV_PCM_RATE_176400;
410 rates |= SNDRV_PCM_RATE_192000;
412 default: /* some other rate */
413 rates |= SNDRV_PCM_RATE_KNOT;
418 pcmhw->rates = rates;
419 pcmhw->rate_min = rate_min;
420 pcmhw->rate_max = rate_max;
423 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
424 struct snd_pcm_hw_params *params)
426 struct snd_pcm_runtime *runtime = substream->runtime;
427 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
428 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
432 unsigned int bytes_per_sec;
434 print_hwparams(substream, params);
435 err = snd_card_asihpi_format_alsa2hpi(card, params_format(params), &format);
439 hpi_handle_error(hpi_format_create(&dpcm->format,
440 params_channels(params),
441 format, params_rate(params), 0, 0));
443 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
444 if (hpi_instream_reset(dpcm->h_stream) != 0)
447 if (hpi_instream_set_format(
448 dpcm->h_stream, &dpcm->format) != 0)
452 dpcm->hpi_buffer_attached = 0;
454 err = hpi_stream_host_buffer_attach(dpcm->h_stream,
455 params_buffer_bytes(params), runtime->dma_addr);
457 dev_dbg(card->card->dev,
458 "stream_host_buffer_attach success %u %lu\n",
459 params_buffer_bytes(params),
460 (unsigned long)runtime->dma_addr);
462 dev_dbg(card->card->dev,
463 "stream_host_buffer_attach error %d\n", err);
467 hpi_stream_get_info_ex(dpcm->h_stream, NULL,
468 &dpcm->hpi_buffer_attached, NULL, NULL, NULL);
470 bytes_per_sec = params_rate(params) * params_channels(params);
471 width = snd_pcm_format_width(params_format(params));
472 bytes_per_sec *= width;
474 if (width < 0 || bytes_per_sec == 0)
477 dpcm->bytes_per_sec = bytes_per_sec;
478 dpcm->buffer_bytes = params_buffer_bytes(params);
479 dpcm->period_bytes = params_period_bytes(params);
485 snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
487 struct snd_pcm_runtime *runtime = substream->runtime;
488 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
489 if (dpcm->hpi_buffer_attached)
490 hpi_stream_host_buffer_detach(dpcm->h_stream);
495 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
497 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
501 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
504 struct snd_pcm_runtime *runtime = substream->runtime;
505 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
510 expiry = max(expiry, 1); /* don't let it be zero! */
511 mod_timer(&dpcm->timer, jiffies + expiry);
512 dpcm->respawn_timer = 1;
515 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
517 struct snd_pcm_runtime *runtime = substream->runtime;
518 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
520 dpcm->respawn_timer = 0;
521 del_timer(&dpcm->timer);
524 static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
526 struct snd_card_asihpi_pcm *dpcm;
527 struct snd_card_asihpi *card;
529 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
530 card = snd_pcm_substream_chip(substream);
532 WARN_ON(in_interrupt());
533 card->llmode_streampriv = dpcm;
535 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
536 HPI_ADAPTER_PROPERTY_IRQ_RATE,
537 card->update_interval_frames, 0));
540 static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
542 struct snd_card_asihpi *card;
544 card = snd_pcm_substream_chip(substream);
546 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
547 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
549 card->llmode_streampriv = NULL;
552 static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
555 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
556 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
557 struct snd_pcm_substream *s;
561 snd_pcm_debug_name(substream, name, sizeof(name));
564 case SNDRV_PCM_TRIGGER_START:
565 dev_dbg(card->card->dev, "%s trigger start\n", name);
566 snd_pcm_group_for_each_entry(s, substream) {
567 struct snd_pcm_runtime *runtime = s->runtime;
568 struct snd_card_asihpi_pcm *ds = runtime->private_data;
570 if (snd_pcm_substream_chip(s) != card)
573 /* don't link Cap and Play */
574 if (substream->stream != s->stream)
577 ds->drained_count = 0;
578 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
579 /* How do I know how much valid data is present
580 * in buffer? Must be at least one period!
581 * Guessing 2 periods, but if
582 * buffer is bigger it may contain even more
585 unsigned int preload = ds->period_bytes * 1;
586 asihpi_dbg("%d preload %d\n", s->number, preload);
587 hpi_handle_error(hpi_outstream_write_buf(
589 &runtime->dma_area[0],
592 ds->pcm_buf_host_rw_ofs = preload;
595 if (card->support_grouping) {
596 dev_dbg(card->card->dev, "%d group\n", s->number);
597 e = hpi_stream_group_add(
601 snd_pcm_trigger_done(s, substream);
609 /* start the master stream */
610 card->pcm_start(substream);
611 if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) ||
613 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
616 case SNDRV_PCM_TRIGGER_STOP:
617 dev_dbg(card->card->dev, "%s trigger stop\n", name);
618 card->pcm_stop(substream);
619 snd_pcm_group_for_each_entry(s, substream) {
620 if (snd_pcm_substream_chip(s) != card)
622 /* don't link Cap and Play */
623 if (substream->stream != s->stream)
626 /*? workaround linked streams don't
627 transition to SETUP 20070706*/
628 __snd_pcm_set_state(s->runtime, SNDRV_PCM_STATE_SETUP);
630 if (card->support_grouping) {
631 dev_dbg(card->card->dev, "%d group\n", s->number);
632 snd_pcm_trigger_done(s, substream);
637 /* _prepare and _hwparams reset the stream */
638 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
639 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
641 hpi_outstream_reset(dpcm->h_stream));
643 if (card->support_grouping)
644 hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream));
647 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
648 dev_dbg(card->card->dev, "%s trigger pause release\n", name);
649 card->pcm_start(substream);
650 hpi_handle_error(hpi_stream_start(dpcm->h_stream));
652 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
653 dev_dbg(card->card->dev, "%s trigger pause push\n", name);
654 card->pcm_stop(substream);
655 hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
658 dev_dbg(card->card->dev, "\tINVALID\n");
666 Without linking degenerates to getting single stream pos etc
667 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
670 pcm_buf_dma_ofs=get_buf_pos(s);
671 for_each_linked_stream(s) {
672 pcm_buf_dma_ofs=get_buf_pos(s);
673 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
674 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
676 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
677 for_each_linked_stream(s) {
678 s->pcm_buf_dma_ofs = min_buf_pos;
679 if (new_data > period_bytes) {
681 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
688 snd_pcm_period_elapsed(s);
693 /** Minimum of 2 modulo values. Works correctly when the difference between
694 * the values is less than half the modulus
696 static inline unsigned int modulo_min(unsigned int a, unsigned int b,
697 unsigned long int modulus)
700 if (((a-b) % modulus) < (modulus/2))
708 /** Timer function, equivalent to interrupt service routine for cards
710 static void snd_card_asihpi_timer_function(struct timer_list *t)
712 struct snd_card_asihpi_pcm *dpcm = from_timer(dpcm, t, timer);
713 struct snd_pcm_substream *substream = dpcm->substream;
714 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
715 struct snd_pcm_runtime *runtime;
716 struct snd_pcm_substream *s;
717 unsigned int newdata = 0;
718 unsigned int pcm_buf_dma_ofs, min_buf_pos = 0;
719 unsigned int remdata, xfercount, next_jiffies;
722 u32 buffer_size, bytes_avail, samples_played, on_card_bytes;
726 snd_pcm_debug_name(substream, name, sizeof(name));
728 /* find minimum newdata and buffer pos in group */
729 snd_pcm_group_for_each_entry(s, substream) {
730 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
731 runtime = s->runtime;
733 if (snd_pcm_substream_chip(s) != card)
736 /* don't link Cap and Play */
737 if (substream->stream != s->stream)
740 hpi_handle_error(hpi_stream_get_info_ex(
741 ds->h_stream, &state,
742 &buffer_size, &bytes_avail,
743 &samples_played, &on_card_bytes));
745 /* number of bytes in on-card buffer */
746 runtime->delay = on_card_bytes;
749 on_card_bytes = bytes_avail;
751 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
752 pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail;
753 if (state == HPI_STATE_STOPPED) {
754 if (bytes_avail == 0) {
755 hpi_handle_error(hpi_stream_start(ds->h_stream));
756 dev_dbg(card->card->dev,
757 "P%d start\n", s->number);
758 ds->drained_count = 0;
760 } else if (state == HPI_STATE_DRAINED) {
761 dev_dbg(card->card->dev,
762 "P%d drained\n", s->number);
764 if (ds->drained_count > 20) {
765 snd_pcm_stop_xrun(s);
769 ds->drained_count = 0;
772 pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs;
775 /* can't statically init min when wrap is involved */
776 min_buf_pos = pcm_buf_dma_ofs;
777 newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes;
781 modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L);
783 (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes,
788 "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
789 name, s->number, state,
790 ds->pcm_buf_elapsed_dma_ofs,
791 ds->pcm_buf_host_rw_ofs,
796 buffer_size-bytes_avail,
797 (unsigned long)frames_to_bytes(runtime,
798 runtime->status->hw_ptr),
799 (unsigned long)frames_to_bytes(runtime,
800 runtime->control->appl_ptr)
803 pcm_buf_dma_ofs = min_buf_pos;
805 remdata = newdata % dpcm->period_bytes;
806 xfercount = newdata - remdata; /* a multiple of period_bytes */
807 /* come back when on_card_bytes has decreased enough to allow
808 write to happen, or when data has been consumed to make another
811 if (xfercount && (on_card_bytes > dpcm->period_bytes))
812 next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec);
814 next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec);
816 next_jiffies = max(next_jiffies, 1U);
817 dpcm->timer.expires = jiffies + next_jiffies;
818 asihpi_dbg("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
819 next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
821 snd_pcm_group_for_each_entry(s, substream) {
822 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
824 /* don't link Cap and Play */
825 if (substream->stream != s->stream)
828 /* Store dma offset for use by pointer callback */
829 ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs;
832 /* Limit use of on card fifo for playback */
833 ((on_card_bytes <= ds->period_bytes) ||
834 (s->stream == SNDRV_PCM_STREAM_CAPTURE)))
838 unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes;
839 unsigned int xfer1, xfer2;
840 char *pd = &s->runtime->dma_area[buf_ofs];
842 if (card->can_dma) { /* buffer wrap is handled at lower level */
846 xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs);
847 xfer2 = xfercount - xfer1;
850 if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
851 asihpi_dbg("write1, P=%d, xfer=%d, buf_ofs=%d\n",
852 s->number, xfer1, buf_ofs);
854 hpi_outstream_write_buf(
855 ds->h_stream, pd, xfer1,
859 pd = s->runtime->dma_area;
861 asihpi_dbg("write2, P=%d, xfer=%d, buf_ofs=%d\n",
863 xfercount - xfer1, buf_ofs);
865 hpi_outstream_write_buf(
871 asihpi_dbg("read1, C=%d, xfer=%d\n",
874 hpi_instream_read_buf(
878 pd = s->runtime->dma_area;
879 asihpi_dbg("read2, C=%d, xfer=%d\n",
882 hpi_instream_read_buf(
887 /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */
888 ds->pcm_buf_host_rw_ofs += xfercount;
889 ds->pcm_buf_elapsed_dma_ofs += xfercount;
890 snd_pcm_period_elapsed(s);
894 if (!card->hpi->interrupt_mode && dpcm->respawn_timer)
895 add_timer(&dpcm->timer);
898 static void snd_card_asihpi_isr(struct hpi_adapter *a)
900 struct snd_card_asihpi *asihpi;
902 WARN_ON(!a || !a->snd_card || !a->snd_card->private_data);
903 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
904 if (asihpi->llmode_streampriv)
905 snd_card_asihpi_timer_function(
906 &asihpi->llmode_streampriv->timer);
909 /***************************** PLAYBACK OPS ****************/
910 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
913 struct snd_pcm_runtime *runtime = substream->runtime;
914 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
916 hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
917 dpcm->pcm_buf_host_rw_ofs = 0;
918 dpcm->pcm_buf_dma_ofs = 0;
919 dpcm->pcm_buf_elapsed_dma_ofs = 0;
923 static snd_pcm_uframes_t
924 snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
926 struct snd_pcm_runtime *runtime = substream->runtime;
927 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
928 snd_pcm_uframes_t ptr;
930 snd_pcm_debug_name(substream, name, sizeof(name));
932 ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
933 asihpi_dbg("%s, pointer=%ld\n", name, (unsigned long)ptr);
937 static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi,
940 struct hpi_format hpi_format;
944 u32 sample_rate = 48000;
947 /* on cards without SRC, must query at valid rate,
948 * maybe set by external sync
950 err = hpi_mixer_get_control(asihpi->h_mixer,
951 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
952 HPI_CONTROL_SAMPLECLOCK, &h_control);
955 err = hpi_sample_clock_get_sample_rate(h_control,
958 for (format = HPI_FORMAT_PCM8_UNSIGNED;
959 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
960 err = hpi_format_create(&hpi_format, asihpi->out_max_chans,
961 format, sample_rate, 128000, 0);
963 err = hpi_outstream_query_format(h_stream, &hpi_format);
964 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
965 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
970 static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
972 struct snd_pcm_runtime *runtime = substream->runtime;
973 struct snd_card_asihpi_pcm *dpcm;
974 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
975 struct snd_pcm_hardware snd_card_asihpi_playback;
978 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
982 err = hpi_outstream_open(card->hpi->adapter->index,
983 substream->number, &dpcm->h_stream);
984 hpi_handle_error(err);
987 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
992 /*? also check ASI5000 samplerate source
993 If external, only support external rate.
994 If internal and other stream playing, can't switch
997 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
998 dpcm->substream = substream;
999 runtime->private_data = dpcm;
1000 runtime->private_free = snd_card_asihpi_runtime_free;
1002 memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback));
1003 if (!card->hpi->interrupt_mode) {
1004 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1005 snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN;
1006 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1007 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1008 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1010 size_t pbmin = card->update_interval_frames *
1011 card->out_max_chans;
1012 snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX;
1013 snd_card_asihpi_playback.period_bytes_min = pbmin;
1014 snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1015 snd_card_asihpi_playback.periods_min = PERIODS_MIN;
1016 snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin;
1019 /* snd_card_asihpi_playback.fifo_size = 0; */
1020 snd_card_asihpi_playback.channels_max = card->out_max_chans;
1021 snd_card_asihpi_playback.channels_min = card->out_min_chans;
1022 snd_card_asihpi_playback.formats =
1023 snd_card_asihpi_playback_formats(card, dpcm->h_stream);
1025 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback);
1027 snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
1028 SNDRV_PCM_INFO_DOUBLE |
1029 SNDRV_PCM_INFO_BATCH |
1030 SNDRV_PCM_INFO_BLOCK_TRANSFER |
1031 SNDRV_PCM_INFO_PAUSE |
1032 SNDRV_PCM_INFO_MMAP |
1033 SNDRV_PCM_INFO_MMAP_VALID;
1035 if (card->support_grouping) {
1036 snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
1037 snd_pcm_set_sync(substream);
1040 /* struct is copied, so can create initializer dynamically */
1041 runtime->hw = snd_card_asihpi_playback;
1044 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1045 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1049 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1050 card->update_interval_frames);
1052 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1053 card->update_interval_frames, UINT_MAX);
1058 static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
1060 struct snd_pcm_runtime *runtime = substream->runtime;
1061 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1063 hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
1067 static const struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
1068 .open = snd_card_asihpi_playback_open,
1069 .close = snd_card_asihpi_playback_close,
1070 .hw_params = snd_card_asihpi_pcm_hw_params,
1071 .hw_free = snd_card_asihpi_hw_free,
1072 .prepare = snd_card_asihpi_playback_prepare,
1073 .trigger = snd_card_asihpi_trigger,
1074 .pointer = snd_card_asihpi_playback_pointer,
1077 /***************************** CAPTURE OPS ****************/
1078 static snd_pcm_uframes_t
1079 snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
1081 struct snd_pcm_runtime *runtime = substream->runtime;
1082 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1084 snd_pcm_debug_name(substream, name, sizeof(name));
1086 asihpi_dbg("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
1087 /* NOTE Unlike playback can't use actual samples_played
1088 for the capture position, because those samples aren't yet in
1089 the local buffer available for reading.
1091 return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
1094 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
1096 struct snd_pcm_runtime *runtime = substream->runtime;
1097 struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
1099 hpi_handle_error(hpi_instream_reset(dpcm->h_stream));
1100 dpcm->pcm_buf_host_rw_ofs = 0;
1101 dpcm->pcm_buf_dma_ofs = 0;
1102 dpcm->pcm_buf_elapsed_dma_ofs = 0;
1107 static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi,
1110 struct hpi_format hpi_format;
1114 u32 sample_rate = 48000;
1117 /* on cards without SRC, must query at valid rate,
1118 maybe set by external sync */
1119 err = hpi_mixer_get_control(asihpi->h_mixer,
1120 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
1121 HPI_CONTROL_SAMPLECLOCK, &h_control);
1124 err = hpi_sample_clock_get_sample_rate(h_control,
1127 for (format = HPI_FORMAT_PCM8_UNSIGNED;
1128 format <= HPI_FORMAT_PCM24_SIGNED; format++) {
1130 err = hpi_format_create(&hpi_format, asihpi->in_max_chans,
1131 format, sample_rate, 128000, 0);
1133 err = hpi_instream_query_format(h_stream, &hpi_format);
1134 if (!err && (hpi_to_alsa_formats[format] != INVALID_FORMAT))
1135 formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1140 static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1142 struct snd_pcm_runtime *runtime = substream->runtime;
1143 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
1144 struct snd_card_asihpi_pcm *dpcm;
1145 struct snd_pcm_hardware snd_card_asihpi_capture;
1148 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
1153 dev_dbg(card->card->dev, "capture open adapter %d stream %d\n",
1154 card->hpi->adapter->index, substream->number);
1156 err = hpi_handle_error(
1157 hpi_instream_open(card->hpi->adapter->index,
1158 substream->number, &dpcm->h_stream));
1161 if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
1166 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1167 dpcm->substream = substream;
1168 runtime->private_data = dpcm;
1169 runtime->private_free = snd_card_asihpi_runtime_free;
1171 memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture));
1172 if (!card->hpi->interrupt_mode) {
1173 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1174 snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN;
1175 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1176 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1177 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN;
1179 size_t pbmin = card->update_interval_frames *
1180 card->out_max_chans;
1181 snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX;
1182 snd_card_asihpi_capture.period_bytes_min = pbmin;
1183 snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN;
1184 snd_card_asihpi_capture.periods_min = PERIODS_MIN;
1185 snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin;
1187 /* snd_card_asihpi_capture.fifo_size = 0; */
1188 snd_card_asihpi_capture.channels_max = card->in_max_chans;
1189 snd_card_asihpi_capture.channels_min = card->in_min_chans;
1190 snd_card_asihpi_capture.formats =
1191 snd_card_asihpi_capture_formats(card, dpcm->h_stream);
1192 snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture);
1193 snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED |
1194 SNDRV_PCM_INFO_MMAP |
1195 SNDRV_PCM_INFO_MMAP_VALID;
1197 if (card->support_grouping)
1198 snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START;
1200 runtime->hw = snd_card_asihpi_capture;
1203 err = snd_pcm_hw_constraint_pow2(runtime, 0,
1204 SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
1208 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1209 card->update_interval_frames);
1210 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
1211 card->update_interval_frames, UINT_MAX);
1213 snd_pcm_set_sync(substream);
1218 static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
1220 struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
1222 hpi_handle_error(hpi_instream_close(dpcm->h_stream));
1226 static const struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
1227 .open = snd_card_asihpi_capture_open,
1228 .close = snd_card_asihpi_capture_close,
1229 .hw_params = snd_card_asihpi_pcm_hw_params,
1230 .hw_free = snd_card_asihpi_hw_free,
1231 .prepare = snd_card_asihpi_capture_prepare,
1232 .trigger = snd_card_asihpi_trigger,
1233 .pointer = snd_card_asihpi_capture_pointer,
1236 static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device)
1238 struct snd_pcm *pcm;
1240 u16 num_instreams, num_outstreams, x16;
1243 err = hpi_adapter_get_info(asihpi->hpi->adapter->index,
1244 &num_outstreams, &num_instreams,
1247 err = snd_pcm_new(asihpi->card, "Asihpi PCM", device,
1248 num_outstreams, num_instreams, &pcm);
1252 /* pointer to ops struct is stored, dont change ops afterwards! */
1253 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1254 &snd_card_asihpi_playback_mmap_ops);
1255 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
1256 &snd_card_asihpi_capture_mmap_ops);
1258 pcm->private_data = asihpi;
1259 pcm->info_flags = 0;
1260 strcpy(pcm->name, "Asihpi PCM");
1262 /*? do we want to emulate MMAP for non-BBM cards?
1263 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1264 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
1266 64*1024, BUFFER_BYTES_MAX);
1271 /***************************** MIXER CONTROLS ****************/
1272 struct hpi_control {
1280 char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */
1283 static const char * const asihpi_tuner_band_names[] = {
1296 /* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */
1297 compile_time_assert(
1298 (ARRAY_SIZE(asihpi_tuner_band_names) ==
1299 (HPI_TUNER_BAND_LAST+1)),
1300 assert_tuner_band_names_size);
1302 static const char * const asihpi_src_names[] = {
1320 /* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */
1321 compile_time_assert(
1322 (ARRAY_SIZE(asihpi_src_names) ==
1323 (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)),
1324 assert_src_names_size);
1326 static const char * const asihpi_dst_names[] = {
1340 /* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */
1341 compile_time_assert(
1342 (ARRAY_SIZE(asihpi_dst_names) ==
1343 (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)),
1344 assert_dst_names_size);
1346 static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
1347 struct snd_card_asihpi *asihpi)
1351 err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
1354 else if (mixer_dump)
1355 dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index);
1360 /* Convert HPI control name and location into ALSA control name */
1361 static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
1362 struct hpi_control *hpi_ctl,
1366 memset(snd_control, 0, sizeof(*snd_control));
1367 snd_control->name = hpi_ctl->name;
1368 snd_control->private_value = hpi_ctl->h_control;
1369 snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1370 snd_control->index = 0;
1372 if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE)
1373 dir = ""; /* clock is neither capture nor playback */
1374 else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM)
1375 dir = "Capture "; /* On or towards a PCM capture destination*/
1376 else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1377 (!hpi_ctl->dst_node_type))
1378 dir = "Capture "; /* On a source node that is not PCM playback */
1379 else if (hpi_ctl->src_node_type &&
1380 (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) &&
1381 (hpi_ctl->dst_node_type))
1382 dir = "Monitor Playback "; /* Between an input and an output */
1384 dir = "Playback "; /* PCM Playback source, or output node */
1386 if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
1387 sprintf(hpi_ctl->name, "%s %d %s %d %s%s",
1388 asihpi_src_names[hpi_ctl->src_node_type],
1389 hpi_ctl->src_node_index,
1390 asihpi_dst_names[hpi_ctl->dst_node_type],
1391 hpi_ctl->dst_node_index,
1393 else if (hpi_ctl->dst_node_type) {
1394 sprintf(hpi_ctl->name, "%s %d %s%s",
1395 asihpi_dst_names[hpi_ctl->dst_node_type],
1396 hpi_ctl->dst_node_index,
1399 sprintf(hpi_ctl->name, "%s %d %s%s",
1400 asihpi_src_names[hpi_ctl->src_node_type],
1401 hpi_ctl->src_node_index,
1406 /*------------------------------------------------------------
1408 ------------------------------------------------------------*/
1409 #define VOL_STEP_mB 1
1410 static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
1411 struct snd_ctl_elem_info *uinfo)
1413 u32 h_control = kcontrol->private_value;
1416 /* native gains are in millibels */
1421 err = hpi_volume_query_range(h_control,
1422 &min_gain_mB, &max_gain_mB, &step_gain_mB);
1425 min_gain_mB = -10000;
1426 step_gain_mB = VOL_STEP_mB;
1429 err = hpi_meter_query_channels(h_control, &count);
1431 count = HPI_MAX_CHANNELS;
1433 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1434 uinfo->count = count;
1435 uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
1436 uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
1437 uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
1441 static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
1442 struct snd_ctl_elem_value *ucontrol)
1444 u32 h_control = kcontrol->private_value;
1445 short an_gain_mB[HPI_MAX_CHANNELS];
1447 hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB));
1448 ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
1449 ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
1454 static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
1455 struct snd_ctl_elem_value *ucontrol)
1457 u32 h_control = kcontrol->private_value;
1458 short an_gain_mB[HPI_MAX_CHANNELS];
1461 (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
1463 (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
1464 /* change = asihpi->mixer_volume[addr][0] != left ||
1465 asihpi->mixer_volume[addr][1] != right;
1467 hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB));
1471 static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
1473 #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info
1475 static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol,
1476 struct snd_ctl_elem_value *ucontrol)
1478 u32 h_control = kcontrol->private_value;
1481 hpi_handle_error(hpi_volume_get_mute(h_control, &mute));
1482 ucontrol->value.integer.value[0] = mute ? 0 : 1;
1487 static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol,
1488 struct snd_ctl_elem_value *ucontrol)
1490 u32 h_control = kcontrol->private_value;
1491 /* HPI currently only supports all or none muting of multichannel volume
1492 ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted
1494 int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS;
1495 hpi_handle_error(hpi_volume_set_mute(h_control, mute));
1499 static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
1500 struct hpi_control *hpi_ctl)
1502 struct snd_card *card = asihpi->card;
1503 struct snd_kcontrol_new snd_control;
1507 asihpi_ctl_init(&snd_control, hpi_ctl, "Volume");
1508 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1509 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1510 snd_control.info = snd_asihpi_volume_info;
1511 snd_control.get = snd_asihpi_volume_get;
1512 snd_control.put = snd_asihpi_volume_put;
1513 snd_control.tlv.p = db_scale_100;
1515 err = ctl_add(card, &snd_control, asihpi);
1519 if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) {
1520 asihpi_ctl_init(&snd_control, hpi_ctl, "Switch");
1521 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1522 snd_control.info = snd_asihpi_volume_mute_info;
1523 snd_control.get = snd_asihpi_volume_mute_get;
1524 snd_control.put = snd_asihpi_volume_mute_put;
1525 err = ctl_add(card, &snd_control, asihpi);
1530 /*------------------------------------------------------------
1532 ------------------------------------------------------------*/
1533 static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
1534 struct snd_ctl_elem_info *uinfo)
1536 u32 h_control = kcontrol->private_value;
1543 hpi_level_query_range(h_control, &min_gain_mB,
1544 &max_gain_mB, &step_gain_mB);
1547 min_gain_mB = -1000;
1551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1553 uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
1554 uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
1555 uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
1559 static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_value *ucontrol)
1562 u32 h_control = kcontrol->private_value;
1563 short an_gain_mB[HPI_MAX_CHANNELS];
1565 hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB));
1566 ucontrol->value.integer.value[0] =
1567 an_gain_mB[0] / HPI_UNITS_PER_dB;
1568 ucontrol->value.integer.value[1] =
1569 an_gain_mB[1] / HPI_UNITS_PER_dB;
1574 static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
1575 struct snd_ctl_elem_value *ucontrol)
1578 u32 h_control = kcontrol->private_value;
1579 short an_gain_mB[HPI_MAX_CHANNELS];
1582 (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1584 (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
1585 /* change = asihpi->mixer_level[addr][0] != left ||
1586 asihpi->mixer_level[addr][1] != right;
1589 hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB));
1593 static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
1595 static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
1596 struct hpi_control *hpi_ctl)
1598 struct snd_card *card = asihpi->card;
1599 struct snd_kcontrol_new snd_control;
1601 /* can't use 'volume' cos some nodes have volume as well */
1602 asihpi_ctl_init(&snd_control, hpi_ctl, "Level");
1603 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1604 SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1605 snd_control.info = snd_asihpi_level_info;
1606 snd_control.get = snd_asihpi_level_get;
1607 snd_control.put = snd_asihpi_level_put;
1608 snd_control.tlv.p = db_scale_level;
1610 return ctl_add(card, &snd_control, asihpi);
1613 /*------------------------------------------------------------
1615 ------------------------------------------------------------*/
1618 static const char * const asihpi_aesebu_format_names[] = {
1619 "N/A", "S/PDIF", "AES/EBU" };
1621 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_info *uinfo)
1624 return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names);
1627 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
1628 struct snd_ctl_elem_value *ucontrol,
1629 u16 (*func)(u32, u16 *))
1631 u32 h_control = kcontrol->private_value;
1634 err = func(h_control, &source);
1636 /* default to N/A */
1637 ucontrol->value.enumerated.item[0] = 0;
1638 /* return success but set the control to N/A */
1641 if (source == HPI_AESEBU_FORMAT_SPDIF)
1642 ucontrol->value.enumerated.item[0] = 1;
1643 if (source == HPI_AESEBU_FORMAT_AESEBU)
1644 ucontrol->value.enumerated.item[0] = 2;
1649 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
1650 struct snd_ctl_elem_value *ucontrol,
1651 u16 (*func)(u32, u16))
1653 u32 h_control = kcontrol->private_value;
1655 /* default to S/PDIF */
1656 u16 source = HPI_AESEBU_FORMAT_SPDIF;
1658 if (ucontrol->value.enumerated.item[0] == 1)
1659 source = HPI_AESEBU_FORMAT_SPDIF;
1660 if (ucontrol->value.enumerated.item[0] == 2)
1661 source = HPI_AESEBU_FORMAT_AESEBU;
1663 if (func(h_control, source) != 0)
1669 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
1670 struct snd_ctl_elem_value *ucontrol) {
1671 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1672 hpi_aesebu_receiver_get_format);
1675 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
1676 struct snd_ctl_elem_value *ucontrol) {
1677 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1678 hpi_aesebu_receiver_set_format);
1681 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
1682 struct snd_ctl_elem_info *uinfo)
1684 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1687 uinfo->value.integer.min = 0;
1688 uinfo->value.integer.max = 0X1F;
1689 uinfo->value.integer.step = 1;
1694 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
1695 struct snd_ctl_elem_value *ucontrol) {
1697 u32 h_control = kcontrol->private_value;
1700 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1701 h_control, &status));
1702 ucontrol->value.integer.value[0] = status;
1706 static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
1707 struct hpi_control *hpi_ctl)
1709 struct snd_card *card = asihpi->card;
1710 struct snd_kcontrol_new snd_control;
1712 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1713 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1714 snd_control.info = snd_asihpi_aesebu_format_info;
1715 snd_control.get = snd_asihpi_aesebu_rx_format_get;
1716 snd_control.put = snd_asihpi_aesebu_rx_format_put;
1719 if (ctl_add(card, &snd_control, asihpi) < 0)
1722 asihpi_ctl_init(&snd_control, hpi_ctl, "Status");
1723 snd_control.access =
1724 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
1725 snd_control.info = snd_asihpi_aesebu_rxstatus_info;
1726 snd_control.get = snd_asihpi_aesebu_rxstatus_get;
1728 return ctl_add(card, &snd_control, asihpi);
1731 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
1732 struct snd_ctl_elem_value *ucontrol) {
1733 return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
1734 hpi_aesebu_transmitter_get_format);
1737 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
1738 struct snd_ctl_elem_value *ucontrol) {
1739 return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
1740 hpi_aesebu_transmitter_set_format);
1744 static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
1745 struct hpi_control *hpi_ctl)
1747 struct snd_card *card = asihpi->card;
1748 struct snd_kcontrol_new snd_control;
1750 asihpi_ctl_init(&snd_control, hpi_ctl, "Format");
1751 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1752 snd_control.info = snd_asihpi_aesebu_format_info;
1753 snd_control.get = snd_asihpi_aesebu_tx_format_get;
1754 snd_control.put = snd_asihpi_aesebu_tx_format_put;
1756 return ctl_add(card, &snd_control, asihpi);
1759 /*------------------------------------------------------------
1761 ------------------------------------------------------------*/
1765 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
1766 struct snd_ctl_elem_info *uinfo)
1768 u32 h_control = kcontrol->private_value;
1773 for (idx = 0; idx < 3; idx++) {
1774 err = hpi_tuner_query_gain(h_control,
1775 idx, &gain_range[idx]);
1780 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1782 uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
1783 uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
1784 uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
1788 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
1789 struct snd_ctl_elem_value *ucontrol)
1792 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1794 u32 h_control = kcontrol->private_value;
1797 hpi_handle_error(hpi_tuner_get_gain(h_control, &gain));
1798 ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
1803 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
1804 struct snd_ctl_elem_value *ucontrol)
1807 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1809 u32 h_control = kcontrol->private_value;
1812 gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
1813 hpi_handle_error(hpi_tuner_set_gain(h_control, gain));
1820 static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
1821 u16 *band_list, u32 len) {
1822 u32 h_control = kcontrol->private_value;
1826 for (i = 0; i < len; i++) {
1827 err = hpi_tuner_query_band(
1828 h_control, i, &band_list[i]);
1833 if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
1839 static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
1840 struct snd_ctl_elem_info *uinfo)
1842 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1845 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1846 HPI_TUNER_BAND_LAST);
1851 return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names);
1854 static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
1855 struct snd_ctl_elem_value *ucontrol)
1857 u32 h_control = kcontrol->private_value;
1859 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1862 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1863 __always_unused u32 num_bands;
1865 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1866 HPI_TUNER_BAND_LAST);
1868 hpi_handle_error(hpi_tuner_get_band(h_control, &band));
1870 ucontrol->value.enumerated.item[0] = -1;
1871 for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
1872 if (tuner_bands[idx] == band) {
1873 ucontrol->value.enumerated.item[0] = idx;
1880 static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
1881 struct snd_ctl_elem_value *ucontrol)
1884 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1886 u32 h_control = kcontrol->private_value;
1889 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1890 __always_unused u32 num_bands;
1892 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1893 HPI_TUNER_BAND_LAST);
1895 idx = ucontrol->value.enumerated.item[0];
1896 if (idx >= ARRAY_SIZE(tuner_bands))
1897 idx = ARRAY_SIZE(tuner_bands) - 1;
1898 band = tuner_bands[idx];
1899 hpi_handle_error(hpi_tuner_set_band(h_control, band));
1906 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
1907 struct snd_ctl_elem_info *uinfo)
1909 u32 h_control = kcontrol->private_value;
1911 u16 tuner_bands[HPI_TUNER_BAND_LAST];
1912 u16 num_bands = 0, band_iter, idx;
1913 u32 freq_range[3], temp_freq_range[3];
1915 num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
1916 HPI_TUNER_BAND_LAST);
1918 freq_range[0] = INT_MAX;
1920 freq_range[2] = INT_MAX;
1922 for (band_iter = 0; band_iter < num_bands; band_iter++) {
1923 for (idx = 0; idx < 3; idx++) {
1924 err = hpi_tuner_query_frequency(h_control,
1925 idx, tuner_bands[band_iter],
1926 &temp_freq_range[idx]);
1931 /* skip band with bogus stepping */
1932 if (temp_freq_range[2] <= 0)
1935 if (temp_freq_range[0] < freq_range[0])
1936 freq_range[0] = temp_freq_range[0];
1937 if (temp_freq_range[1] > freq_range[1])
1938 freq_range[1] = temp_freq_range[1];
1939 if (temp_freq_range[2] < freq_range[2])
1940 freq_range[2] = temp_freq_range[2];
1943 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1945 uinfo->value.integer.min = ((int)freq_range[0]);
1946 uinfo->value.integer.max = ((int)freq_range[1]);
1947 uinfo->value.integer.step = ((int)freq_range[2]);
1951 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
1952 struct snd_ctl_elem_value *ucontrol)
1954 u32 h_control = kcontrol->private_value;
1957 hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq));
1958 ucontrol->value.integer.value[0] = freq;
1963 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
1964 struct snd_ctl_elem_value *ucontrol)
1966 u32 h_control = kcontrol->private_value;
1969 freq = ucontrol->value.integer.value[0];
1970 hpi_handle_error(hpi_tuner_set_frequency(h_control, freq));
1975 /* Tuner control group initializer */
1976 static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
1977 struct hpi_control *hpi_ctl)
1979 struct snd_card *card = asihpi->card;
1980 struct snd_kcontrol_new snd_control;
1982 snd_control.private_value = hpi_ctl->h_control;
1983 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
1985 if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) {
1986 asihpi_ctl_init(&snd_control, hpi_ctl, "Gain");
1987 snd_control.info = snd_asihpi_tuner_gain_info;
1988 snd_control.get = snd_asihpi_tuner_gain_get;
1989 snd_control.put = snd_asihpi_tuner_gain_put;
1991 if (ctl_add(card, &snd_control, asihpi) < 0)
1995 asihpi_ctl_init(&snd_control, hpi_ctl, "Band");
1996 snd_control.info = snd_asihpi_tuner_band_info;
1997 snd_control.get = snd_asihpi_tuner_band_get;
1998 snd_control.put = snd_asihpi_tuner_band_put;
2000 if (ctl_add(card, &snd_control, asihpi) < 0)
2003 asihpi_ctl_init(&snd_control, hpi_ctl, "Freq");
2004 snd_control.info = snd_asihpi_tuner_freq_info;
2005 snd_control.get = snd_asihpi_tuner_freq_get;
2006 snd_control.put = snd_asihpi_tuner_freq_put;
2008 return ctl_add(card, &snd_control, asihpi);
2011 /*------------------------------------------------------------
2013 ------------------------------------------------------------*/
2014 static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
2015 struct snd_ctl_elem_info *uinfo)
2017 u32 h_control = kcontrol->private_value;
2020 err = hpi_meter_query_channels(h_control, &count);
2022 count = HPI_MAX_CHANNELS;
2024 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2025 uinfo->count = count;
2026 uinfo->value.integer.min = 0;
2027 uinfo->value.integer.max = 0x7FFFFFFF;
2031 /* linear values for 10dB steps */
2032 static const int log2lin[] = {
2033 0x7FFFFFFF, /* 0dB */
2039 2147484, /* -60dB */
2054 static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
2055 struct snd_ctl_elem_value *ucontrol)
2057 u32 h_control = kcontrol->private_value;
2058 short an_gain_mB[HPI_MAX_CHANNELS], i;
2061 err = hpi_meter_get_peak(h_control, an_gain_mB);
2063 for (i = 0; i < HPI_MAX_CHANNELS; i++) {
2065 ucontrol->value.integer.value[i] = 0;
2066 } else if (an_gain_mB[i] >= 0) {
2067 ucontrol->value.integer.value[i] =
2068 an_gain_mB[i] << 16;
2070 /* -ve is log value in millibels < -60dB,
2071 * convert to (roughly!) linear,
2073 ucontrol->value.integer.value[i] =
2074 log2lin[an_gain_mB[i] / -1000];
2080 static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
2081 struct hpi_control *hpi_ctl, int subidx)
2083 struct snd_card *card = asihpi->card;
2084 struct snd_kcontrol_new snd_control;
2086 asihpi_ctl_init(&snd_control, hpi_ctl, "Meter");
2087 snd_control.access =
2088 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2089 snd_control.info = snd_asihpi_meter_info;
2090 snd_control.get = snd_asihpi_meter_get;
2092 snd_control.index = subidx;
2094 return ctl_add(card, &snd_control, asihpi);
2097 /*------------------------------------------------------------
2098 Multiplexer controls
2099 ------------------------------------------------------------*/
2100 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
2102 u32 h_control = snd_control->private_value;
2103 struct hpi_control hpi_ctl;
2105 for (s = 0; s < 32; s++) {
2106 err = hpi_multiplexer_query_source(h_control, s,
2117 static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
2118 struct snd_ctl_elem_info *uinfo)
2120 u16 src_node_type, src_node_index;
2121 u32 h_control = kcontrol->private_value;
2123 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2125 uinfo->value.enumerated.items =
2126 snd_card_asihpi_mux_count_sources(kcontrol);
2128 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2129 uinfo->value.enumerated.item =
2130 uinfo->value.enumerated.items - 1;
2132 hpi_multiplexer_query_source(h_control,
2133 uinfo->value.enumerated.item,
2134 &src_node_type, &src_node_index);
2136 sprintf(uinfo->value.enumerated.name, "%s %d",
2137 asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE],
2142 static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
2143 struct snd_ctl_elem_value *ucontrol)
2145 u32 h_control = kcontrol->private_value;
2146 u16 source_type, source_index;
2147 u16 src_node_type, src_node_index;
2150 hpi_handle_error(hpi_multiplexer_get_source(h_control,
2151 &source_type, &source_index));
2152 /* Should cache this search result! */
2153 for (s = 0; s < 256; s++) {
2154 if (hpi_multiplexer_query_source(h_control, s,
2155 &src_node_type, &src_node_index))
2158 if ((source_type == src_node_type)
2159 && (source_index == src_node_index)) {
2160 ucontrol->value.enumerated.item[0] = s;
2164 pr_warn("%s: Control %x failed to match mux source %hu %hu\n",
2165 __func__, h_control, source_type, source_index);
2166 ucontrol->value.enumerated.item[0] = 0;
2170 static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
2171 struct snd_ctl_elem_value *ucontrol)
2174 u32 h_control = kcontrol->private_value;
2175 u16 source_type, source_index;
2180 e = hpi_multiplexer_query_source(h_control,
2181 ucontrol->value.enumerated.item[0],
2182 &source_type, &source_index);
2185 hpi_multiplexer_set_source(h_control,
2186 source_type, source_index));
2191 static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
2192 struct hpi_control *hpi_ctl)
2194 struct snd_card *card = asihpi->card;
2195 struct snd_kcontrol_new snd_control;
2197 asihpi_ctl_init(&snd_control, hpi_ctl, "Route");
2198 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2199 snd_control.info = snd_asihpi_mux_info;
2200 snd_control.get = snd_asihpi_mux_get;
2201 snd_control.put = snd_asihpi_mux_put;
2203 return ctl_add(card, &snd_control, asihpi);
2207 /*------------------------------------------------------------
2208 Channel mode controls
2209 ------------------------------------------------------------*/
2210 static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
2211 struct snd_ctl_elem_info *uinfo)
2213 static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = {
2216 "From Left", "From Right",
2217 "To Left", "To Right"
2220 u32 h_control = kcontrol->private_value;
2223 const char *mapped_names[6];
2224 int valid_modes = 0;
2226 /* HPI channel mode values can be from 1 to 6
2227 Some adapters only support a contiguous subset
2229 for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
2230 if (!hpi_channel_mode_query_mode(
2231 h_control, i, &mode)) {
2232 mapped_names[valid_modes] = mode_names[mode];
2239 return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names);
2242 static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
2243 struct snd_ctl_elem_value *ucontrol)
2245 u32 h_control = kcontrol->private_value;
2248 if (hpi_channel_mode_get(h_control, &mode))
2251 ucontrol->value.enumerated.item[0] = mode - 1;
2256 static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
2257 struct snd_ctl_elem_value *ucontrol)
2260 u32 h_control = kcontrol->private_value;
2264 hpi_handle_error(hpi_channel_mode_set(h_control,
2265 ucontrol->value.enumerated.item[0] + 1));
2270 static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
2271 struct hpi_control *hpi_ctl)
2273 struct snd_card *card = asihpi->card;
2274 struct snd_kcontrol_new snd_control;
2276 asihpi_ctl_init(&snd_control, hpi_ctl, "Mode");
2277 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
2278 snd_control.info = snd_asihpi_cmode_info;
2279 snd_control.get = snd_asihpi_cmode_get;
2280 snd_control.put = snd_asihpi_cmode_put;
2282 return ctl_add(card, &snd_control, asihpi);
2285 /*------------------------------------------------------------
2286 Sampleclock source controls
2287 ------------------------------------------------------------*/
2288 static const char * const sampleclock_sources[] = {
2289 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2290 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2291 "Prev Module", "BLU-Link",
2292 "Digital2", "Digital3", "Digital4", "Digital5",
2293 "Digital6", "Digital7", "Digital8"};
2295 /* Number of strings must match expected enumerated values */
2296 compile_time_assert(
2297 (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES),
2298 assert_sampleclock_sources_size);
2300 static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_info *uinfo)
2303 struct snd_card_asihpi *asihpi =
2304 (struct snd_card_asihpi *)(kcontrol->private_data);
2305 struct clk_cache *clkcache = &asihpi->cc;
2306 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2308 uinfo->value.enumerated.items = clkcache->count;
2310 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2311 uinfo->value.enumerated.item =
2312 uinfo->value.enumerated.items - 1;
2314 strcpy(uinfo->value.enumerated.name,
2315 clkcache->s[uinfo->value.enumerated.item].name);
2319 static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
2320 struct snd_ctl_elem_value *ucontrol)
2322 struct snd_card_asihpi *asihpi =
2323 (struct snd_card_asihpi *)(kcontrol->private_data);
2324 struct clk_cache *clkcache = &asihpi->cc;
2325 u32 h_control = kcontrol->private_value;
2326 u16 source, srcindex = 0;
2329 ucontrol->value.enumerated.item[0] = 0;
2330 if (hpi_sample_clock_get_source(h_control, &source))
2333 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2334 if (hpi_sample_clock_get_source_index(h_control, &srcindex))
2337 for (i = 0; i < clkcache->count; i++)
2338 if ((clkcache->s[i].source == source) &&
2339 (clkcache->s[i].index == srcindex))
2342 ucontrol->value.enumerated.item[0] = i;
2347 static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
2348 struct snd_ctl_elem_value *ucontrol)
2350 struct snd_card_asihpi *asihpi =
2351 (struct snd_card_asihpi *)(kcontrol->private_data);
2352 struct clk_cache *clkcache = &asihpi->cc;
2355 u32 h_control = kcontrol->private_value;
2358 item = ucontrol->value.enumerated.item[0];
2359 if (item >= clkcache->count)
2360 item = clkcache->count-1;
2362 hpi_handle_error(hpi_sample_clock_set_source(
2363 h_control, clkcache->s[item].source));
2365 if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2366 hpi_handle_error(hpi_sample_clock_set_source_index(
2367 h_control, clkcache->s[item].index));
2371 /*------------------------------------------------------------
2373 ------------------------------------------------------------*/
2374 /* Need to change this to enumerated control with list of rates */
2375 static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
2376 struct snd_ctl_elem_info *uinfo)
2378 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2380 uinfo->value.integer.min = 8000;
2381 uinfo->value.integer.max = 192000;
2382 uinfo->value.integer.step = 100;
2387 static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
2388 struct snd_ctl_elem_value *ucontrol)
2390 u32 h_control = kcontrol->private_value;
2394 e = hpi_sample_clock_get_local_rate(h_control, &rate);
2396 ucontrol->value.integer.value[0] = rate;
2398 ucontrol->value.integer.value[0] = 0;
2402 static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2406 u32 h_control = kcontrol->private_value;
2408 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2409 asihpi->mixer_clkrate[addr][1] != right;
2412 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control,
2413 ucontrol->value.integer.value[0]));
2417 static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
2418 struct snd_ctl_elem_info *uinfo)
2420 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2422 uinfo->value.integer.min = 8000;
2423 uinfo->value.integer.max = 192000;
2424 uinfo->value.integer.step = 100;
2429 static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_value *ucontrol)
2432 u32 h_control = kcontrol->private_value;
2436 e = hpi_sample_clock_get_sample_rate(h_control, &rate);
2438 ucontrol->value.integer.value[0] = rate;
2440 ucontrol->value.integer.value[0] = 0;
2444 static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
2445 struct hpi_control *hpi_ctl)
2447 struct snd_card *card;
2448 struct snd_kcontrol_new snd_control;
2450 struct clk_cache *clkcache;
2451 u32 hSC = hpi_ctl->h_control;
2456 if (snd_BUG_ON(!asihpi))
2458 card = asihpi->card;
2459 clkcache = &asihpi->cc;
2460 snd_control.private_value = hpi_ctl->h_control;
2462 clkcache->has_local = 0;
2464 for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
2465 if (hpi_sample_clock_query_source(hSC,
2468 clkcache->s[i].source = source;
2469 clkcache->s[i].index = 0;
2470 clkcache->s[i].name = sampleclock_sources[source];
2471 if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
2473 if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
2474 clkcache->has_local = 1;
2477 /* already will have picked up index 0 above */
2478 for (j = 1; j < 8; j++) {
2479 if (hpi_sample_clock_query_source_index(hSC,
2480 j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
2483 clkcache->s[i].source =
2484 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
2485 clkcache->s[i].index = j;
2486 clkcache->s[i].name = sampleclock_sources[
2487 j+HPI_SAMPLECLOCK_SOURCE_LAST];
2490 clkcache->count = i;
2492 asihpi_ctl_init(&snd_control, hpi_ctl, "Source");
2493 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2494 snd_control.info = snd_asihpi_clksrc_info;
2495 snd_control.get = snd_asihpi_clksrc_get;
2496 snd_control.put = snd_asihpi_clksrc_put;
2497 if (ctl_add(card, &snd_control, asihpi) < 0)
2501 if (clkcache->has_local) {
2502 asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate");
2503 snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
2504 snd_control.info = snd_asihpi_clklocal_info;
2505 snd_control.get = snd_asihpi_clklocal_get;
2506 snd_control.put = snd_asihpi_clklocal_put;
2509 if (ctl_add(card, &snd_control, asihpi) < 0)
2513 asihpi_ctl_init(&snd_control, hpi_ctl, "Rate");
2514 snd_control.access =
2515 SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
2516 snd_control.info = snd_asihpi_clkrate_info;
2517 snd_control.get = snd_asihpi_clkrate_get;
2519 return ctl_add(card, &snd_control, asihpi);
2521 /*------------------------------------------------------------
2523 ------------------------------------------------------------*/
2525 static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
2527 struct snd_card *card;
2528 unsigned int idx = 0;
2529 unsigned int subindex = 0;
2531 struct hpi_control hpi_ctl, prev_ctl;
2533 if (snd_BUG_ON(!asihpi))
2535 card = asihpi->card;
2536 strcpy(card->mixername, "Asihpi Mixer");
2539 hpi_mixer_open(asihpi->hpi->adapter->index,
2541 hpi_handle_error(err);
2545 memset(&prev_ctl, 0, sizeof(prev_ctl));
2546 prev_ctl.control_type = -1;
2548 for (idx = 0; idx < 2000; idx++) {
2549 err = hpi_mixer_get_control_by_index(
2552 &hpi_ctl.src_node_type,
2553 &hpi_ctl.src_node_index,
2554 &hpi_ctl.dst_node_type,
2555 &hpi_ctl.dst_node_index,
2556 &hpi_ctl.control_type,
2557 &hpi_ctl.h_control);
2559 if (err == HPI_ERROR_CONTROL_DISABLED) {
2561 dev_info(&asihpi->pci->dev,
2562 "Disabled HPI Control(%d)\n",
2570 hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE;
2571 hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE;
2573 /* ASI50xx in SSX mode has multiple meters on the same node.
2574 Use subindex to create distinct ALSA controls
2575 for any duplicated controls.
2577 if ((hpi_ctl.control_type == prev_ctl.control_type) &&
2578 (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
2579 (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
2580 (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
2581 (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
2588 switch (hpi_ctl.control_type) {
2589 case HPI_CONTROL_VOLUME:
2590 err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
2592 case HPI_CONTROL_LEVEL:
2593 err = snd_asihpi_level_add(asihpi, &hpi_ctl);
2595 case HPI_CONTROL_MULTIPLEXER:
2596 err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
2598 case HPI_CONTROL_CHANNEL_MODE:
2599 err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
2601 case HPI_CONTROL_METER:
2602 err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
2604 case HPI_CONTROL_SAMPLECLOCK:
2605 err = snd_asihpi_sampleclock_add(
2608 case HPI_CONTROL_CONNECTION: /* ignore these */
2610 case HPI_CONTROL_TUNER:
2611 err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
2613 case HPI_CONTROL_AESEBU_TRANSMITTER:
2614 err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
2616 case HPI_CONTROL_AESEBU_RECEIVER:
2617 err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
2619 case HPI_CONTROL_VOX:
2620 case HPI_CONTROL_BITSTREAM:
2621 case HPI_CONTROL_MICROPHONE:
2622 case HPI_CONTROL_PARAMETRIC_EQ:
2623 case HPI_CONTROL_COMPANDER:
2626 dev_info(&asihpi->pci->dev,
2627 "Untranslated HPI Control (%d) %d %d %d %d %d\n",
2629 hpi_ctl.control_type,
2630 hpi_ctl.src_node_type,
2631 hpi_ctl.src_node_index,
2632 hpi_ctl.dst_node_type,
2633 hpi_ctl.dst_node_index);
2639 if (HPI_ERROR_INVALID_OBJ_INDEX != err)
2640 hpi_handle_error(err);
2642 dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx);
2647 /*------------------------------------------------------------
2649 ------------------------------------------------------------*/
2652 snd_asihpi_proc_read(struct snd_info_entry *entry,
2653 struct snd_info_buffer *buffer)
2655 struct snd_card_asihpi *asihpi = entry->private_data;
2668 snd_iprintf(buffer, "ASIHPI driver proc file\n");
2670 hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index,
2671 &num_outstreams, &num_instreams,
2672 &version, &serial_number, &type));
2675 "Adapter type ASI%4X\nHardware Index %d\n"
2676 "%d outstreams\n%d instreams\n",
2677 type, asihpi->hpi->adapter->index,
2678 num_outstreams, num_instreams);
2681 "Serial#%d\nHardware version %c%d\nDSP code version %03d\n",
2682 serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7,
2683 ((version >> 13) * 100) + ((version >> 7) & 0x3f));
2685 err = hpi_mixer_get_control(asihpi->h_mixer,
2686 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2687 HPI_CONTROL_SAMPLECLOCK, &h_control);
2690 err = hpi_sample_clock_get_sample_rate(h_control, &rate);
2691 err += hpi_sample_clock_get_source(h_control, &source);
2694 snd_iprintf(buffer, "Sample Clock %dHz, source %s\n",
2695 rate, sampleclock_sources[source]);
2699 static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
2701 snd_card_ro_proc_new(asihpi->card, "info", asihpi,
2702 snd_asihpi_proc_read);
2705 /*------------------------------------------------------------
2707 ------------------------------------------------------------*/
2709 static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
2711 if (enable_hpi_hwdep)
2718 static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
2720 if (enable_hpi_hwdep)
2721 return asihpi_hpi_release(file);
2726 static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
2727 unsigned int cmd, unsigned long arg)
2729 if (enable_hpi_hwdep)
2730 return asihpi_hpi_ioctl(file, cmd, arg);
2736 /* results in /dev/snd/hwC#D0 file for each card with index #
2737 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2739 static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, int device)
2741 struct snd_hwdep *hw;
2744 err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
2747 strcpy(hw->name, "asihpi (HPI)");
2748 hw->iface = SNDRV_HWDEP_IFACE_LAST;
2749 hw->ops.open = snd_asihpi_hpi_open;
2750 hw->ops.ioctl = snd_asihpi_hpi_ioctl;
2751 hw->ops.release = snd_asihpi_hpi_release;
2752 hw->private_data = asihpi;
2756 /*------------------------------------------------------------
2758 ------------------------------------------------------------*/
2759 static int snd_asihpi_probe(struct pci_dev *pci_dev,
2760 const struct pci_device_id *pci_id)
2763 struct hpi_adapter *hpi;
2764 struct snd_card *card;
2765 struct snd_card_asihpi *asihpi;
2772 if (dev >= SNDRV_CARDS)
2775 /* Should this be enable[hpi->index] ? */
2781 /* Initialise low-level HPI driver */
2782 err = asihpi_adapter_probe(pci_dev, pci_id);
2786 hpi = pci_get_drvdata(pci_dev);
2787 adapter_index = hpi->adapter->index;
2788 /* first try to give the card the same index as its hardware index */
2789 err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index],
2790 THIS_MODULE, sizeof(struct snd_card_asihpi), &card);
2792 /* if that fails, try the default index==next available */
2793 err = snd_card_new(&pci_dev->dev, index[dev], id[dev],
2794 THIS_MODULE, sizeof(struct snd_card_asihpi),
2798 dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n",
2799 adapter_index, card->number);
2802 asihpi = card->private_data;
2803 asihpi->card = card;
2804 asihpi->pci = pci_dev;
2806 hpi->snd_card = card;
2808 err = hpi_adapter_get_property(adapter_index,
2809 HPI_ADAPTER_PROPERTY_CAPS1,
2810 NULL, &asihpi->support_grouping);
2812 asihpi->support_grouping = 0;
2814 err = hpi_adapter_get_property(adapter_index,
2815 HPI_ADAPTER_PROPERTY_CAPS2,
2816 &asihpi->support_mrx, NULL);
2818 asihpi->support_mrx = 0;
2820 err = hpi_adapter_get_property(adapter_index,
2821 HPI_ADAPTER_PROPERTY_INTERVAL,
2822 NULL, &asihpi->update_interval_frames);
2824 asihpi->update_interval_frames = 512;
2826 if (hpi->interrupt_mode) {
2827 asihpi->pcm_start = snd_card_asihpi_pcm_int_start;
2828 asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop;
2829 hpi->interrupt_callback = snd_card_asihpi_isr;
2831 asihpi->pcm_start = snd_card_asihpi_pcm_timer_start;
2832 asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop;
2835 hpi_handle_error(hpi_instream_open(adapter_index,
2838 err = hpi_instream_host_buffer_free(h_stream);
2839 asihpi->can_dma = (!err);
2841 hpi_handle_error(hpi_instream_close(h_stream));
2843 if (!asihpi->can_dma)
2844 asihpi->update_interval_frames *= 2;
2846 err = hpi_adapter_get_property(adapter_index,
2847 HPI_ADAPTER_PROPERTY_CURCHANNELS,
2848 &asihpi->in_max_chans, &asihpi->out_max_chans);
2850 asihpi->in_max_chans = 2;
2851 asihpi->out_max_chans = 2;
2854 if (asihpi->out_max_chans > 2) { /* assume LL mode */
2855 asihpi->out_min_chans = asihpi->out_max_chans;
2856 asihpi->in_min_chans = asihpi->in_max_chans;
2857 asihpi->support_grouping = 0;
2859 asihpi->out_min_chans = 1;
2860 asihpi->in_min_chans = 1;
2863 dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n",
2865 asihpi->support_grouping,
2866 asihpi->support_mrx,
2867 asihpi->update_interval_frames
2870 err = snd_card_asihpi_pcm_new(asihpi, 0);
2872 dev_err(&pci_dev->dev, "pcm_new failed\n");
2875 err = snd_card_asihpi_mixer_new(asihpi);
2877 dev_err(&pci_dev->dev, "mixer_new failed\n");
2881 err = hpi_mixer_get_control(asihpi->h_mixer,
2882 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
2883 HPI_CONTROL_SAMPLECLOCK, &h_control);
2886 err = hpi_sample_clock_set_local_rate(
2887 h_control, adapter_fs);
2889 snd_asihpi_proc_init(asihpi);
2891 /* always create, can be enabled or disabled dynamically
2892 by enable_hwdep module param*/
2893 snd_asihpi_hpi_new(asihpi, 0);
2895 strcpy(card->driver, "ASIHPI");
2897 sprintf(card->shortname, "AudioScience ASI%4X",
2898 asihpi->hpi->adapter->type);
2899 sprintf(card->longname, "%s %i",
2900 card->shortname, adapter_index);
2901 err = snd_card_register(card);
2908 snd_card_free(card);
2909 dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err);
2914 static void snd_asihpi_remove(struct pci_dev *pci_dev)
2916 struct hpi_adapter *hpi = pci_get_drvdata(pci_dev);
2918 /* Stop interrupts */
2919 if (hpi->interrupt_mode) {
2920 hpi->interrupt_callback = NULL;
2921 hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index,
2922 HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0));
2925 snd_card_free(hpi->snd_card);
2926 hpi->snd_card = NULL;
2927 asihpi_adapter_remove(pci_dev);
2930 static const struct pci_device_id asihpi_pci_tbl[] = {
2931 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
2932 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2933 (kernel_ulong_t)HPI_6205},
2934 {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
2935 HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
2936 (kernel_ulong_t)HPI_6000},
2939 MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
2941 static struct pci_driver driver = {
2942 .name = KBUILD_MODNAME,
2943 .id_table = asihpi_pci_tbl,
2944 .probe = snd_asihpi_probe,
2945 .remove = snd_asihpi_remove,
2948 static int __init snd_asihpi_init(void)
2951 return pci_register_driver(&driver);
2954 static void __exit snd_asihpi_exit(void)
2957 pci_unregister_driver(&driver);
2961 module_init(snd_asihpi_init)
2962 module_exit(snd_asihpi_exit)