3 * Copyright (c) by AudioScience Inc <alsa@audioscience.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * The following is not a condition of use, merely a request:
20 * If you modify this program, particularly if you fix errors, AudioScience Inc
21 * would appreciate it if you grant us the right to use those modifications
22 * for any purpose including commercial applications.
25 #include "hpi_internal.h"
26 #include "hpimsginit.h"
29 #include <linux/pci.h>
30 #include <linux/version.h>
31 #include <linux/init.h>
32 #include <linux/jiffies.h>
33 #include <linux/slab.h>
34 #include <linux/time.h>
35 #include <linux/wait.h>
36 #include <sound/core.h>
37 #include <sound/control.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/info.h>
41 #include <sound/initval.h>
42 #include <sound/tlv.h>
43 #include <sound/hwdep.h>
46 MODULE_LICENSE("GPL");
47 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
48 MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx");
50 #if defined CONFIG_SND_DEBUG
51 /* copied from pcm_lib.c, hope later patch will make that version public
52 and this copy can be removed */
53 static void pcm_debug_name(struct snd_pcm_substream
*substream
,
54 char *name
, size_t len
)
56 snprintf(name
, len
, "pcmC%dD%d%c:%d",
57 substream
->pcm
->card
->number
,
58 substream
->pcm
->device
,
59 substream
->stream
? 'c' : 'p',
62 #define DEBUG_NAME(substream, name) char name[16]; pcm_debug_name(substream, name, sizeof(name))
64 #define pcm_debug_name(s, n, l) do { } while (0)
65 #define DEBUG_NAME(name, substream) do { } while (0)
68 #if defined CONFIG_SND_DEBUG_VERBOSE
70 * snd_printddd - very verbose debug printk
71 * @format: format string
73 * Works like snd_printk() for debugging purposes.
74 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
75 * Must set snd module debug parameter to 3 to enable at runtime.
77 #define snd_printddd(format, args...) \
78 __snd_printk(3, __FILE__, __LINE__, format, ##args)
80 #define snd_printddd(format, args...) do { } while (0)
83 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* index 0-MAX */
84 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
85 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
86 static int enable_hpi_hwdep
= 1;
88 module_param_array(index
, int, NULL
, S_IRUGO
);
89 MODULE_PARM_DESC(index
, "ALSA index value for AudioScience soundcard.");
91 module_param_array(id
, charp
, NULL
, S_IRUGO
);
92 MODULE_PARM_DESC(id
, "ALSA ID string for AudioScience soundcard.");
94 module_param_array(enable
, bool, NULL
, S_IRUGO
);
95 MODULE_PARM_DESC(enable
, "ALSA enable AudioScience soundcard.");
97 module_param(enable_hpi_hwdep
, bool, S_IRUGO
|S_IWUSR
);
98 MODULE_PARM_DESC(enable_hpi_hwdep
,
99 "ALSA enable HPI hwdep for AudioScience soundcard ");
101 /* identify driver */
102 #ifdef KERNEL_ALSA_BUILD
103 static char *build_info
= "Built using headers from kernel source";
104 module_param(build_info
, charp
, S_IRUGO
);
105 MODULE_PARM_DESC(build_info
, "built using headers from kernel source");
107 static char *build_info
= "Built within ALSA source";
108 module_param(build_info
, charp
, S_IRUGO
);
109 MODULE_PARM_DESC(build_info
, "built within ALSA source");
112 /* set to 1 to dump every control from adapter to log */
113 static const int mixer_dump
;
115 #define DEFAULT_SAMPLERATE 44100
116 static int adapter_fs
= DEFAULT_SAMPLERATE
;
119 #define PERIODS_MIN 2
120 #define PERIOD_BYTES_MIN 2048
121 #define BUFFER_BYTES_MAX (512 * 1024)
123 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
134 struct clk_source s
[MAX_CLOCKSOURCES
];
138 struct snd_card_asihpi
{
139 struct snd_card
*card
;
152 u16 support_grouping
;
154 u16 update_interval_frames
;
159 /* Per stream data */
160 struct snd_card_asihpi_pcm
{
161 struct timer_list timer
;
162 unsigned int respawn_timer
;
163 unsigned int hpi_buffer_attached
;
164 unsigned int buffer_bytes
;
165 unsigned int period_bytes
;
166 unsigned int bytes_per_sec
;
167 unsigned int pcm_buf_host_rw_ofs
; /* Host R/W pos */
168 unsigned int pcm_buf_dma_ofs
; /* DMA R/W offset in buffer */
169 unsigned int pcm_buf_elapsed_dma_ofs
; /* DMA R/W offset in buffer */
170 unsigned int drained_count
;
171 struct snd_pcm_substream
*substream
;
173 struct hpi_format format
;
176 /* universal stream verbs work with out or in stream handles */
178 /* Functions to allow driver to give a buffer to HPI for busmastering */
180 static u16
hpi_stream_host_buffer_attach(
181 u32 h_stream
, /* handle to outstream. */
182 u32 size_in_bytes
, /* size in bytes of bus mastering buffer */
186 struct hpi_message hm
;
187 struct hpi_response hr
;
188 unsigned int obj
= hpi_handle_object(h_stream
);
191 return HPI_ERROR_INVALID_OBJ
;
192 hpi_init_message_response(&hm
, &hr
, obj
,
193 obj
== HPI_OBJ_OSTREAM
?
194 HPI_OSTREAM_HOSTBUFFER_ALLOC
:
195 HPI_ISTREAM_HOSTBUFFER_ALLOC
);
197 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
200 hm
.u
.d
.u
.buffer
.buffer_size
= size_in_bytes
;
201 hm
.u
.d
.u
.buffer
.pci_address
= pci_address
;
202 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
;
203 hpi_send_recv(&hm
, &hr
);
207 static u16
hpi_stream_host_buffer_detach(u32 h_stream
)
209 struct hpi_message hm
;
210 struct hpi_response hr
;
211 unsigned int obj
= hpi_handle_object(h_stream
);
214 return HPI_ERROR_INVALID_OBJ
;
216 hpi_init_message_response(&hm
, &hr
, obj
,
217 obj
== HPI_OBJ_OSTREAM
?
218 HPI_OSTREAM_HOSTBUFFER_FREE
:
219 HPI_ISTREAM_HOSTBUFFER_FREE
);
221 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
223 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
;
224 hpi_send_recv(&hm
, &hr
);
228 static inline u16
hpi_stream_start(u32 h_stream
)
230 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
231 return hpi_outstream_start(h_stream
);
233 return hpi_instream_start(h_stream
);
236 static inline u16
hpi_stream_stop(u32 h_stream
)
238 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
239 return hpi_outstream_stop(h_stream
);
241 return hpi_instream_stop(h_stream
);
244 static inline u16
hpi_stream_get_info_ex(
248 u32
*pdata_in_buffer
,
254 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
255 e
= hpi_outstream_get_info_ex(h_stream
, pw_state
,
256 pbuffer_size
, pdata_in_buffer
,
257 psample_count
, pauxiliary_data
);
259 e
= hpi_instream_get_info_ex(h_stream
, pw_state
,
260 pbuffer_size
, pdata_in_buffer
,
261 psample_count
, pauxiliary_data
);
265 static inline u16
hpi_stream_group_add(
269 if (hpi_handle_object(h_master
) == HPI_OBJ_OSTREAM
)
270 return hpi_outstream_group_add(h_master
, h_stream
);
272 return hpi_instream_group_add(h_master
, h_stream
);
275 static inline u16
hpi_stream_group_reset(u32 h_stream
)
277 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
278 return hpi_outstream_group_reset(h_stream
);
280 return hpi_instream_group_reset(h_stream
);
283 static inline u16
hpi_stream_group_get_map(
284 u32 h_stream
, u32
*mo
, u32
*mi
)
286 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
287 return hpi_outstream_group_get_map(h_stream
, mo
, mi
);
289 return hpi_instream_group_get_map(h_stream
, mo
, mi
);
292 static u16
handle_error(u16 err
, int line
, char *filename
)
296 "in file %s, line %d: HPI error %d\n",
297 filename
, line
, err
);
301 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
303 /***************************** GENERAL PCM ****************/
305 static void print_hwparams(struct snd_pcm_substream
*substream
,
306 struct snd_pcm_hw_params
*p
)
308 DEBUG_NAME(substream
, name
);
309 snd_printd("%s HWPARAMS\n", name
);
310 snd_printd(" samplerate %d Hz\n", params_rate(p
));
311 snd_printd(" channels %d\n", params_channels(p
));
312 snd_printd(" format %d\n", params_format(p
));
313 snd_printd(" subformat %d\n", params_subformat(p
));
314 snd_printd(" buffer %d B\n", params_buffer_bytes(p
));
315 snd_printd(" period %d B\n", params_period_bytes(p
));
316 snd_printd(" access %d\n", params_access(p
));
317 snd_printd(" period_size %d\n", params_period_size(p
));
318 snd_printd(" periods %d\n", params_periods(p
));
319 snd_printd(" buffer_size %d\n", params_buffer_size(p
));
320 snd_printd(" %d B/s\n", params_rate(p
) *
322 snd_pcm_format_width(params_format(p
)) / 8);
326 static snd_pcm_format_t hpi_to_alsa_formats
[] = {
328 SNDRV_PCM_FORMAT_U8
, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
329 SNDRV_PCM_FORMAT_S16
, /* HPI_FORMAT_PCM16_SIGNED 2 */
330 -1, /* HPI_FORMAT_MPEG_L1 3 */
331 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L2 4 */
332 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L3 5 */
333 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
334 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
335 SNDRV_PCM_FORMAT_S16_BE
,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
336 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
337 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
338 SNDRV_PCM_FORMAT_S32
, /* HPI_FORMAT_PCM32_SIGNED 11 */
339 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
340 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
341 SNDRV_PCM_FORMAT_FLOAT
, /* HPI_FORMAT_PCM32_FLOAT 14 */
343 /* ALSA can't handle 3 byte sample size together with power-of-2
344 * constraint on buffer_bytes, so disable this format
348 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
353 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format
,
358 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
359 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
360 if (hpi_to_alsa_formats
[format
] == alsa_format
) {
361 *hpi_format
= format
;
366 snd_printd(KERN_WARNING
"failed match for alsa format %d\n",
372 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi
*asihpi
,
373 struct snd_pcm_hardware
*pcmhw
)
379 unsigned int rate_min
= 200000;
380 unsigned int rate_max
= 0;
381 unsigned int rates
= 0;
383 if (asihpi
->support_mrx
) {
384 rates
|= SNDRV_PCM_RATE_CONTINUOUS
;
385 rates
|= SNDRV_PCM_RATE_8000_96000
;
389 /* on cards without SRC,
390 valid rates are determined by sampleclock */
391 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
392 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
393 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
396 "No local sampleclock, err %d\n", err
);
399 for (idx
= -1; idx
< 100; idx
++) {
401 if (hpi_sample_clock_get_sample_rate(h_control
,
404 } else if (hpi_sample_clock_query_local_rate(h_control
,
405 idx
, &sample_rate
)) {
409 rate_min
= min(rate_min
, sample_rate
);
410 rate_max
= max(rate_max
, sample_rate
);
412 switch (sample_rate
) {
414 rates
|= SNDRV_PCM_RATE_5512
;
417 rates
|= SNDRV_PCM_RATE_8000
;
420 rates
|= SNDRV_PCM_RATE_11025
;
423 rates
|= SNDRV_PCM_RATE_16000
;
426 rates
|= SNDRV_PCM_RATE_22050
;
429 rates
|= SNDRV_PCM_RATE_32000
;
432 rates
|= SNDRV_PCM_RATE_44100
;
435 rates
|= SNDRV_PCM_RATE_48000
;
438 rates
|= SNDRV_PCM_RATE_64000
;
441 rates
|= SNDRV_PCM_RATE_88200
;
444 rates
|= SNDRV_PCM_RATE_96000
;
447 rates
|= SNDRV_PCM_RATE_176400
;
450 rates
|= SNDRV_PCM_RATE_192000
;
452 default: /* some other rate */
453 rates
|= SNDRV_PCM_RATE_KNOT
;
458 pcmhw
->rates
= rates
;
459 pcmhw
->rate_min
= rate_min
;
460 pcmhw
->rate_max
= rate_max
;
463 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream
*substream
,
464 struct snd_pcm_hw_params
*params
)
466 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
467 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
468 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
472 unsigned int bytes_per_sec
;
474 print_hwparams(substream
, params
);
475 err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(params
));
478 err
= snd_card_asihpi_format_alsa2hpi(params_format(params
), &format
);
482 hpi_handle_error(hpi_format_create(&dpcm
->format
,
483 params_channels(params
),
484 format
, params_rate(params
), 0, 0));
486 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
487 if (hpi_instream_reset(dpcm
->h_stream
) != 0)
490 if (hpi_instream_set_format(
491 dpcm
->h_stream
, &dpcm
->format
) != 0)
495 dpcm
->hpi_buffer_attached
= 0;
497 err
= hpi_stream_host_buffer_attach(dpcm
->h_stream
,
498 params_buffer_bytes(params
), runtime
->dma_addr
);
501 "stream_host_buffer_attach succeeded %u %lu\n",
502 params_buffer_bytes(params
),
503 (unsigned long)runtime
->dma_addr
);
505 snd_printd("stream_host_buffer_attach error %d\n",
510 err
= hpi_stream_get_info_ex(dpcm
->h_stream
, NULL
,
511 &dpcm
->hpi_buffer_attached
,
514 snd_printdd("stream_host_buffer_attach status 0x%x\n",
515 dpcm
->hpi_buffer_attached
);
517 bytes_per_sec
= params_rate(params
) * params_channels(params
);
518 width
= snd_pcm_format_width(params_format(params
));
519 bytes_per_sec
*= width
;
521 if (width
< 0 || bytes_per_sec
== 0)
524 dpcm
->bytes_per_sec
= bytes_per_sec
;
525 dpcm
->buffer_bytes
= params_buffer_bytes(params
);
526 dpcm
->period_bytes
= params_period_bytes(params
);
532 snd_card_asihpi_hw_free(struct snd_pcm_substream
*substream
)
534 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
535 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
536 if (dpcm
->hpi_buffer_attached
)
537 hpi_stream_host_buffer_detach(dpcm
->h_stream
);
539 snd_pcm_lib_free_pages(substream
);
543 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime
*runtime
)
545 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
549 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream
*
552 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
553 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
557 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */
558 expiry
= max(expiry
, 1); /* don't let it be zero! */
559 dpcm
->timer
.expires
= jiffies
+ expiry
;
560 dpcm
->respawn_timer
= 1;
561 add_timer(&dpcm
->timer
);
564 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream
*substream
)
566 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
567 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
569 dpcm
->respawn_timer
= 0;
570 del_timer(&dpcm
->timer
);
573 static int snd_card_asihpi_trigger(struct snd_pcm_substream
*substream
,
576 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
577 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
578 struct snd_pcm_substream
*s
;
580 DEBUG_NAME(substream
, name
);
582 snd_printdd("%s trigger\n", name
);
585 case SNDRV_PCM_TRIGGER_START
:
586 snd_pcm_group_for_each_entry(s
, substream
) {
587 struct snd_pcm_runtime
*runtime
= s
->runtime
;
588 struct snd_card_asihpi_pcm
*ds
= runtime
->private_data
;
590 if (snd_pcm_substream_chip(s
) != card
)
593 /* don't link Cap and Play */
594 if (substream
->stream
!= s
->stream
)
597 ds
->drained_count
= 0;
598 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
599 /* How do I know how much valid data is present
600 * in buffer? Must be at least one period!
601 * Guessing 2 periods, but if
602 * buffer is bigger it may contain even more
605 unsigned int preload
= ds
->period_bytes
* 1;
606 snd_printddd("%d preload x%x\n", s
->number
, preload
);
607 hpi_handle_error(hpi_outstream_write_buf(
609 &runtime
->dma_area
[0],
612 ds
->pcm_buf_host_rw_ofs
= preload
;
615 if (card
->support_grouping
) {
616 snd_printdd("%d group\n", s
->number
);
617 e
= hpi_stream_group_add(
621 snd_pcm_trigger_done(s
, substream
);
629 snd_printdd("start\n");
630 /* start the master stream */
631 snd_card_asihpi_pcm_timer_start(substream
);
632 if ((substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) ||
634 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
637 case SNDRV_PCM_TRIGGER_STOP
:
638 snd_card_asihpi_pcm_timer_stop(substream
);
639 snd_pcm_group_for_each_entry(s
, substream
) {
640 if (snd_pcm_substream_chip(s
) != card
)
642 /* don't link Cap and Play */
643 if (substream
->stream
!= s
->stream
)
646 /*? workaround linked streams don't
647 transition to SETUP 20070706*/
648 s
->runtime
->status
->state
= SNDRV_PCM_STATE_SETUP
;
650 if (card
->support_grouping
) {
651 snd_printdd("%d group\n", s
->number
);
652 snd_pcm_trigger_done(s
, substream
);
656 snd_printdd("stop\n");
658 /* _prepare and _hwparams reset the stream */
659 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
660 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
662 hpi_outstream_reset(dpcm
->h_stream
));
664 if (card
->support_grouping
)
665 hpi_handle_error(hpi_stream_group_reset(dpcm
->h_stream
));
668 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
669 snd_printdd("pause release\n");
670 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
671 snd_card_asihpi_pcm_timer_start(substream
);
673 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
674 snd_printdd("pause\n");
675 snd_card_asihpi_pcm_timer_stop(substream
);
676 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
679 snd_printd(KERN_ERR
"\tINVALID\n");
687 Without linking degenerates to getting single stream pos etc
688 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
691 pcm_buf_dma_ofs=get_buf_pos(s);
692 for_each_linked_stream(s) {
693 pcm_buf_dma_ofs=get_buf_pos(s);
694 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
695 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
697 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
698 for_each_linked_stream(s) {
699 s->pcm_buf_dma_ofs = min_buf_pos;
700 if (new_data > period_bytes) {
702 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
709 snd_pcm_period_elapsed(s);
714 /** Minimum of 2 modulo values. Works correctly when the difference between
715 * the values is less than half the modulus
717 static inline unsigned int modulo_min(unsigned int a
, unsigned int b
,
718 unsigned long int modulus
)
721 if (((a
-b
) % modulus
) < (modulus
/2))
729 /** Timer function, equivalent to interrupt service routine for cards
731 static void snd_card_asihpi_timer_function(unsigned long data
)
733 struct snd_card_asihpi_pcm
*dpcm
= (struct snd_card_asihpi_pcm
*)data
;
734 struct snd_pcm_substream
*substream
= dpcm
->substream
;
735 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
736 struct snd_pcm_runtime
*runtime
;
737 struct snd_pcm_substream
*s
;
738 unsigned int newdata
= 0;
739 unsigned int pcm_buf_dma_ofs
, min_buf_pos
= 0;
740 unsigned int remdata
, xfercount
, next_jiffies
;
744 u32 buffer_size
, bytes_avail
, samples_played
, on_card_bytes
;
745 DEBUG_NAME(substream
, name
);
747 snd_printdd("%s snd_card_asihpi_timer_function\n", name
);
749 /* find minimum newdata and buffer pos in group */
750 snd_pcm_group_for_each_entry(s
, substream
) {
751 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
752 runtime
= s
->runtime
;
754 if (snd_pcm_substream_chip(s
) != card
)
757 /* don't link Cap and Play */
758 if (substream
->stream
!= s
->stream
)
761 hpi_handle_error(hpi_stream_get_info_ex(
762 ds
->h_stream
, &state
,
763 &buffer_size
, &bytes_avail
,
764 &samples_played
, &on_card_bytes
));
766 /* number of bytes in on-card buffer */
767 runtime
->delay
= on_card_bytes
;
770 on_card_bytes
= bytes_avail
;
772 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
773 pcm_buf_dma_ofs
= ds
->pcm_buf_host_rw_ofs
- bytes_avail
;
774 if (state
== HPI_STATE_STOPPED
) {
775 if ((bytes_avail
== 0) &&
776 (on_card_bytes
< ds
->pcm_buf_host_rw_ofs
)) {
777 hpi_handle_error(hpi_stream_start(ds
->h_stream
));
778 snd_printdd("P%d start\n", s
->number
);
779 ds
->drained_count
= 0;
781 } else if (state
== HPI_STATE_DRAINED
) {
782 snd_printd(KERN_WARNING
"P%d drained\n",
785 if (ds
->drained_count
> 2) {
786 snd_pcm_stop(s
, SNDRV_PCM_STATE_XRUN
);
790 ds
->drained_count
= 0;
793 pcm_buf_dma_ofs
= bytes_avail
+ ds
->pcm_buf_host_rw_ofs
;
796 /* can't statically init min when wrap is involved */
797 min_buf_pos
= pcm_buf_dma_ofs
;
798 newdata
= (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
;
802 modulo_min(min_buf_pos
, pcm_buf_dma_ofs
, UINT_MAX
+1L);
804 (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
,
808 snd_printdd("hw_ptr 0x%04lX, appl_ptr 0x%04lX\n",
809 (unsigned long)frames_to_bytes(runtime
,
810 runtime
->status
->hw_ptr
),
811 (unsigned long)frames_to_bytes(runtime
,
812 runtime
->control
->appl_ptr
));
814 snd_printdd("%d S=%d, "
815 "rw=0x%04X, dma=0x%04X, left=0x%04X, "
816 "aux=0x%04X space=0x%04X\n",
818 ds
->pcm_buf_host_rw_ofs
, pcm_buf_dma_ofs
,
820 (int)on_card_bytes
, buffer_size
-bytes_avail
);
823 pcm_buf_dma_ofs
= min_buf_pos
;
825 remdata
= newdata
% dpcm
->period_bytes
;
826 xfercount
= newdata
- remdata
; /* a multiple of period_bytes */
827 /* come back when on_card_bytes has decreased enough to allow
828 write to happen, or when data has been consumed to make another
831 if (xfercount
&& (on_card_bytes
> dpcm
->period_bytes
))
832 next_jiffies
= ((on_card_bytes
- dpcm
->period_bytes
) * HZ
/ dpcm
->bytes_per_sec
);
834 next_jiffies
= ((dpcm
->period_bytes
- remdata
) * HZ
/ dpcm
->bytes_per_sec
);
836 next_jiffies
= max(next_jiffies
, 1U);
837 dpcm
->timer
.expires
= jiffies
+ next_jiffies
;
838 snd_printdd("jif %d buf pos 0x%04X newdata 0x%04X xfer 0x%04X\n",
839 next_jiffies
, pcm_buf_dma_ofs
, newdata
, xfercount
);
841 snd_pcm_group_for_each_entry(s
, substream
) {
842 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
844 /* don't link Cap and Play */
845 if (substream
->stream
!= s
->stream
)
848 ds
->pcm_buf_dma_ofs
= pcm_buf_dma_ofs
;
851 /* Limit use of on card fifo for playback */
852 ((on_card_bytes
<= ds
->period_bytes
) ||
853 (s
->stream
== SNDRV_PCM_STREAM_CAPTURE
)))
857 unsigned int buf_ofs
= ds
->pcm_buf_host_rw_ofs
% ds
->buffer_bytes
;
858 unsigned int xfer1
, xfer2
;
859 char *pd
= &s
->runtime
->dma_area
[buf_ofs
];
861 if (card
->can_dma
) { /* buffer wrap is handled at lower level */
865 xfer1
= min(xfercount
, ds
->buffer_bytes
- buf_ofs
);
866 xfer2
= xfercount
- xfer1
;
869 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
870 snd_printddd("P%d write1 0x%04X 0x%04X\n",
871 s
->number
, xfer1
, buf_ofs
);
873 hpi_outstream_write_buf(
874 ds
->h_stream
, pd
, xfer1
,
878 pd
= s
->runtime
->dma_area
;
880 snd_printddd("P%d write2 0x%04X 0x%04X\n",
882 xfercount
- xfer1
, buf_ofs
);
884 hpi_outstream_write_buf(
890 snd_printddd("C%d read1 0x%04x\n",
893 hpi_instream_read_buf(
897 pd
= s
->runtime
->dma_area
;
898 snd_printddd("C%d read2 0x%04x\n",
901 hpi_instream_read_buf(
906 ds
->pcm_buf_host_rw_ofs
= ds
->pcm_buf_host_rw_ofs
+ xfercount
;
907 ds
->pcm_buf_elapsed_dma_ofs
= pcm_buf_dma_ofs
;
908 snd_pcm_period_elapsed(s
);
912 if (dpcm
->respawn_timer
)
913 add_timer(&dpcm
->timer
);
916 /***************************** PLAYBACK OPS ****************/
917 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream
*substream
,
918 unsigned int cmd
, void *arg
)
920 snd_printddd(KERN_INFO
"P%d ioctl %d\n", substream
->number
, cmd
);
921 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
924 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream
*
927 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
928 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
930 snd_printdd("P%d prepare\n", substream
->number
);
932 hpi_handle_error(hpi_outstream_reset(dpcm
->h_stream
));
933 dpcm
->pcm_buf_host_rw_ofs
= 0;
934 dpcm
->pcm_buf_dma_ofs
= 0;
935 dpcm
->pcm_buf_elapsed_dma_ofs
= 0;
939 static snd_pcm_uframes_t
940 snd_card_asihpi_playback_pointer(struct snd_pcm_substream
*substream
)
942 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
943 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
944 snd_pcm_uframes_t ptr
;
946 ptr
= bytes_to_frames(runtime
, dpcm
->pcm_buf_dma_ofs
% dpcm
->buffer_bytes
);
947 snd_printddd("P%d pointer = 0x%04lx\n", substream
->number
, (unsigned long)ptr
);
951 static void snd_card_asihpi_playback_format(struct snd_card_asihpi
*asihpi
,
953 struct snd_pcm_hardware
*pcmhw
)
955 struct hpi_format hpi_format
;
959 u32 sample_rate
= 48000;
961 /* on cards without SRC, must query at valid rate,
962 * maybe set by external sync
964 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
965 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
966 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
969 err
= hpi_sample_clock_get_sample_rate(h_control
,
972 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
973 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
974 err
= hpi_format_create(&hpi_format
,
975 2, format
, sample_rate
, 128000, 0);
977 err
= hpi_outstream_query_format(h_stream
,
979 if (!err
&& (hpi_to_alsa_formats
[format
] != -1))
981 (1ULL << hpi_to_alsa_formats
[format
]);
985 static struct snd_pcm_hardware snd_card_asihpi_playback
= {
988 .buffer_bytes_max
= BUFFER_BYTES_MAX
,
989 .period_bytes_min
= PERIOD_BYTES_MIN
,
990 .period_bytes_max
= BUFFER_BYTES_MAX
/ PERIODS_MIN
,
991 .periods_min
= PERIODS_MIN
,
992 .periods_max
= BUFFER_BYTES_MAX
/ PERIOD_BYTES_MIN
,
996 static int snd_card_asihpi_playback_open(struct snd_pcm_substream
*substream
)
998 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
999 struct snd_card_asihpi_pcm
*dpcm
;
1000 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
1003 dpcm
= kzalloc(sizeof(*dpcm
), GFP_KERNEL
);
1008 hpi_outstream_open(card
->adapter_index
,
1009 substream
->number
, &dpcm
->h_stream
);
1010 hpi_handle_error(err
);
1013 if (err
== HPI_ERROR_OBJ_ALREADY_OPEN
)
1018 /*? also check ASI5000 samplerate source
1019 If external, only support external rate.
1020 If internal and other stream playing, can't switch
1023 init_timer(&dpcm
->timer
);
1024 dpcm
->timer
.data
= (unsigned long) dpcm
;
1025 dpcm
->timer
.function
= snd_card_asihpi_timer_function
;
1026 dpcm
->substream
= substream
;
1027 runtime
->private_data
= dpcm
;
1028 runtime
->private_free
= snd_card_asihpi_runtime_free
;
1030 snd_card_asihpi_playback
.channels_max
= card
->out_max_chans
;
1031 /*?snd_card_asihpi_playback.period_bytes_min =
1032 card->out_max_chans * 4096; */
1034 snd_card_asihpi_playback_format(card
, dpcm
->h_stream
,
1035 &snd_card_asihpi_playback
);
1037 snd_card_asihpi_pcm_samplerates(card
, &snd_card_asihpi_playback
);
1039 snd_card_asihpi_playback
.info
= SNDRV_PCM_INFO_INTERLEAVED
|
1040 SNDRV_PCM_INFO_DOUBLE
|
1041 SNDRV_PCM_INFO_BATCH
|
1042 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
1043 SNDRV_PCM_INFO_PAUSE
|
1044 SNDRV_PCM_INFO_MMAP
|
1045 SNDRV_PCM_INFO_MMAP_VALID
;
1047 if (card
->support_grouping
)
1048 snd_card_asihpi_playback
.info
|= SNDRV_PCM_INFO_SYNC_START
;
1050 /* struct is copied, so can create initializer dynamically */
1051 runtime
->hw
= snd_card_asihpi_playback
;
1054 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1055 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1059 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1060 card
->update_interval_frames
);
1062 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1063 card
->update_interval_frames
* 2, UINT_MAX
);
1065 snd_pcm_set_sync(substream
);
1067 snd_printdd("playback open\n");
1072 static int snd_card_asihpi_playback_close(struct snd_pcm_substream
*substream
)
1074 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1075 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1077 hpi_handle_error(hpi_outstream_close(dpcm
->h_stream
));
1078 snd_printdd("playback close\n");
1083 static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops
= {
1084 .open
= snd_card_asihpi_playback_open
,
1085 .close
= snd_card_asihpi_playback_close
,
1086 .ioctl
= snd_card_asihpi_playback_ioctl
,
1087 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1088 .hw_free
= snd_card_asihpi_hw_free
,
1089 .prepare
= snd_card_asihpi_playback_prepare
,
1090 .trigger
= snd_card_asihpi_trigger
,
1091 .pointer
= snd_card_asihpi_playback_pointer
,
1094 /***************************** CAPTURE OPS ****************/
1095 static snd_pcm_uframes_t
1096 snd_card_asihpi_capture_pointer(struct snd_pcm_substream
*substream
)
1098 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1099 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1101 snd_printddd("capture pointer %d=%d\n",
1102 substream
->number
, dpcm
->pcm_buf_dma_ofs
);
1103 /* NOTE Unlike playback can't use actual samples_played
1104 for the capture position, because those samples aren't yet in
1105 the local buffer available for reading.
1107 return bytes_to_frames(runtime
, dpcm
->pcm_buf_dma_ofs
% dpcm
->buffer_bytes
);
1110 static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream
*substream
,
1111 unsigned int cmd
, void *arg
)
1113 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1116 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream
*substream
)
1118 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1119 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1121 hpi_handle_error(hpi_instream_reset(dpcm
->h_stream
));
1122 dpcm
->pcm_buf_host_rw_ofs
= 0;
1123 dpcm
->pcm_buf_dma_ofs
= 0;
1124 dpcm
->pcm_buf_elapsed_dma_ofs
= 0;
1126 snd_printdd("Capture Prepare %d\n", substream
->number
);
1132 static void snd_card_asihpi_capture_format(struct snd_card_asihpi
*asihpi
,
1134 struct snd_pcm_hardware
*pcmhw
)
1136 struct hpi_format hpi_format
;
1140 u32 sample_rate
= 48000;
1142 /* on cards without SRC, must query at valid rate,
1143 maybe set by external sync */
1144 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
1145 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
1146 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
1149 err
= hpi_sample_clock_get_sample_rate(h_control
,
1152 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
1153 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
1155 err
= hpi_format_create(&hpi_format
, 2, format
,
1156 sample_rate
, 128000, 0);
1158 err
= hpi_instream_query_format(h_stream
,
1162 (1ULL << hpi_to_alsa_formats
[format
]);
1167 static struct snd_pcm_hardware snd_card_asihpi_capture
= {
1170 .buffer_bytes_max
= BUFFER_BYTES_MAX
,
1171 .period_bytes_min
= PERIOD_BYTES_MIN
,
1172 .period_bytes_max
= BUFFER_BYTES_MAX
/ PERIODS_MIN
,
1173 .periods_min
= PERIODS_MIN
,
1174 .periods_max
= BUFFER_BYTES_MAX
/ PERIOD_BYTES_MIN
,
1178 static int snd_card_asihpi_capture_open(struct snd_pcm_substream
*substream
)
1180 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1181 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
1182 struct snd_card_asihpi_pcm
*dpcm
;
1185 dpcm
= kzalloc(sizeof(*dpcm
), GFP_KERNEL
);
1189 snd_printdd("capture open adapter %d stream %d\n",
1190 card
->adapter_index
, substream
->number
);
1192 err
= hpi_handle_error(
1193 hpi_instream_open(card
->adapter_index
,
1194 substream
->number
, &dpcm
->h_stream
));
1197 if (err
== HPI_ERROR_OBJ_ALREADY_OPEN
)
1203 init_timer(&dpcm
->timer
);
1204 dpcm
->timer
.data
= (unsigned long) dpcm
;
1205 dpcm
->timer
.function
= snd_card_asihpi_timer_function
;
1206 dpcm
->substream
= substream
;
1207 runtime
->private_data
= dpcm
;
1208 runtime
->private_free
= snd_card_asihpi_runtime_free
;
1210 snd_card_asihpi_capture
.channels_max
= card
->in_max_chans
;
1211 snd_card_asihpi_capture_format(card
, dpcm
->h_stream
,
1212 &snd_card_asihpi_capture
);
1213 snd_card_asihpi_pcm_samplerates(card
, &snd_card_asihpi_capture
);
1214 snd_card_asihpi_capture
.info
= SNDRV_PCM_INFO_INTERLEAVED
|
1215 SNDRV_PCM_INFO_MMAP
|
1216 SNDRV_PCM_INFO_MMAP_VALID
;
1218 if (card
->support_grouping
)
1219 snd_card_asihpi_capture
.info
|= SNDRV_PCM_INFO_SYNC_START
;
1221 runtime
->hw
= snd_card_asihpi_capture
;
1224 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1225 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1229 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1230 card
->update_interval_frames
);
1231 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1232 card
->update_interval_frames
* 2, UINT_MAX
);
1234 snd_pcm_set_sync(substream
);
1239 static int snd_card_asihpi_capture_close(struct snd_pcm_substream
*substream
)
1241 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
1243 hpi_handle_error(hpi_instream_close(dpcm
->h_stream
));
1247 static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops
= {
1248 .open
= snd_card_asihpi_capture_open
,
1249 .close
= snd_card_asihpi_capture_close
,
1250 .ioctl
= snd_card_asihpi_capture_ioctl
,
1251 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1252 .hw_free
= snd_card_asihpi_hw_free
,
1253 .prepare
= snd_card_asihpi_capture_prepare
,
1254 .trigger
= snd_card_asihpi_trigger
,
1255 .pointer
= snd_card_asihpi_capture_pointer
,
1258 static int __devinit
snd_card_asihpi_pcm_new(struct snd_card_asihpi
*asihpi
,
1259 int device
, int substreams
)
1261 struct snd_pcm
*pcm
;
1264 err
= snd_pcm_new(asihpi
->card
, "Asihpi PCM", device
,
1265 asihpi
->num_outstreams
, asihpi
->num_instreams
,
1269 /* pointer to ops struct is stored, dont change ops afterwards! */
1270 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1271 &snd_card_asihpi_playback_mmap_ops
);
1272 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1273 &snd_card_asihpi_capture_mmap_ops
);
1275 pcm
->private_data
= asihpi
;
1276 pcm
->info_flags
= 0;
1277 strcpy(pcm
->name
, "Asihpi PCM");
1279 /*? do we want to emulate MMAP for non-BBM cards?
1280 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1281 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1282 snd_dma_pci_data(asihpi
->pci
),
1283 64*1024, BUFFER_BYTES_MAX
);
1288 /***************************** MIXER CONTROLS ****************/
1289 struct hpi_control
{
1297 char name
[44]; /* copied to snd_ctl_elem_id.name[44]; */
1300 static const char * const asihpi_tuner_band_names
[] = {
1313 compile_time_assert(
1314 (ARRAY_SIZE(asihpi_tuner_band_names
) ==
1315 (HPI_TUNER_BAND_LAST
+1)),
1316 assert_tuner_band_names_size
);
1318 static const char * const asihpi_src_names
[] = {
1333 compile_time_assert(
1334 (ARRAY_SIZE(asihpi_src_names
) ==
1335 (HPI_SOURCENODE_LAST_INDEX
-HPI_SOURCENODE_NONE
+1)),
1336 assert_src_names_size
);
1338 static const char * const asihpi_dst_names
[] = {
1349 compile_time_assert(
1350 (ARRAY_SIZE(asihpi_dst_names
) ==
1351 (HPI_DESTNODE_LAST_INDEX
-HPI_DESTNODE_NONE
+1)),
1352 assert_dst_names_size
);
1354 static inline int ctl_add(struct snd_card
*card
, struct snd_kcontrol_new
*ctl
,
1355 struct snd_card_asihpi
*asihpi
)
1359 err
= snd_ctl_add(card
, snd_ctl_new1(ctl
, asihpi
));
1362 else if (mixer_dump
)
1363 snd_printk(KERN_INFO
"added %s(%d)\n", ctl
->name
, ctl
->index
);
1368 /* Convert HPI control name and location into ALSA control name */
1369 static void asihpi_ctl_init(struct snd_kcontrol_new
*snd_control
,
1370 struct hpi_control
*hpi_ctl
,
1374 memset(snd_control
, 0, sizeof(*snd_control
));
1375 snd_control
->name
= hpi_ctl
->name
;
1376 snd_control
->private_value
= hpi_ctl
->h_control
;
1377 snd_control
->iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1378 snd_control
->index
= 0;
1380 if (hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
== HPI_SOURCENODE_CLOCK_SOURCE
)
1381 dir
= ""; /* clock is neither capture nor playback */
1382 else if (hpi_ctl
->dst_node_type
+ HPI_DESTNODE_NONE
== HPI_DESTNODE_ISTREAM
)
1383 dir
= "Capture "; /* On or towards a PCM capture destination*/
1384 else if ((hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1385 (!hpi_ctl
->dst_node_type
))
1386 dir
= "Capture "; /* On a source node that is not PCM playback */
1387 else if (hpi_ctl
->src_node_type
&&
1388 (hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1389 (hpi_ctl
->dst_node_type
))
1390 dir
= "Monitor Playback "; /* Between an input and an output */
1392 dir
= "Playback "; /* PCM Playback source, or output node */
1394 if (hpi_ctl
->src_node_type
&& hpi_ctl
->dst_node_type
)
1395 sprintf(hpi_ctl
->name
, "%s %d %s %d %s%s",
1396 asihpi_src_names
[hpi_ctl
->src_node_type
],
1397 hpi_ctl
->src_node_index
,
1398 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1399 hpi_ctl
->dst_node_index
,
1401 else if (hpi_ctl
->dst_node_type
) {
1402 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1403 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1404 hpi_ctl
->dst_node_index
,
1407 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1408 asihpi_src_names
[hpi_ctl
->src_node_type
],
1409 hpi_ctl
->src_node_index
,
1412 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1413 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1416 /*------------------------------------------------------------
1418 ------------------------------------------------------------*/
1419 #define VOL_STEP_mB 1
1420 static int snd_asihpi_volume_info(struct snd_kcontrol
*kcontrol
,
1421 struct snd_ctl_elem_info
*uinfo
)
1423 u32 h_control
= kcontrol
->private_value
;
1425 /* native gains are in millibels */
1430 err
= hpi_volume_query_range(h_control
,
1431 &min_gain_mB
, &max_gain_mB
, &step_gain_mB
);
1434 min_gain_mB
= -10000;
1435 step_gain_mB
= VOL_STEP_mB
;
1438 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1440 uinfo
->value
.integer
.min
= min_gain_mB
/ VOL_STEP_mB
;
1441 uinfo
->value
.integer
.max
= max_gain_mB
/ VOL_STEP_mB
;
1442 uinfo
->value
.integer
.step
= step_gain_mB
/ VOL_STEP_mB
;
1446 static int snd_asihpi_volume_get(struct snd_kcontrol
*kcontrol
,
1447 struct snd_ctl_elem_value
*ucontrol
)
1449 u32 h_control
= kcontrol
->private_value
;
1450 short an_gain_mB
[HPI_MAX_CHANNELS
];
1452 hpi_handle_error(hpi_volume_get_gain(h_control
, an_gain_mB
));
1453 ucontrol
->value
.integer
.value
[0] = an_gain_mB
[0] / VOL_STEP_mB
;
1454 ucontrol
->value
.integer
.value
[1] = an_gain_mB
[1] / VOL_STEP_mB
;
1459 static int snd_asihpi_volume_put(struct snd_kcontrol
*kcontrol
,
1460 struct snd_ctl_elem_value
*ucontrol
)
1463 u32 h_control
= kcontrol
->private_value
;
1464 short an_gain_mB
[HPI_MAX_CHANNELS
];
1467 (ucontrol
->value
.integer
.value
[0]) * VOL_STEP_mB
;
1469 (ucontrol
->value
.integer
.value
[1]) * VOL_STEP_mB
;
1470 /* change = asihpi->mixer_volume[addr][0] != left ||
1471 asihpi->mixer_volume[addr][1] != right;
1474 hpi_handle_error(hpi_volume_set_gain(h_control
, an_gain_mB
));
1478 static const DECLARE_TLV_DB_SCALE(db_scale_100
, -10000, VOL_STEP_mB
, 0);
1480 static int __devinit
snd_asihpi_volume_add(struct snd_card_asihpi
*asihpi
,
1481 struct hpi_control
*hpi_ctl
)
1483 struct snd_card
*card
= asihpi
->card
;
1484 struct snd_kcontrol_new snd_control
;
1486 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Volume");
1487 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1488 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1489 snd_control
.info
= snd_asihpi_volume_info
;
1490 snd_control
.get
= snd_asihpi_volume_get
;
1491 snd_control
.put
= snd_asihpi_volume_put
;
1492 snd_control
.tlv
.p
= db_scale_100
;
1494 return ctl_add(card
, &snd_control
, asihpi
);
1497 /*------------------------------------------------------------
1499 ------------------------------------------------------------*/
1500 static int snd_asihpi_level_info(struct snd_kcontrol
*kcontrol
,
1501 struct snd_ctl_elem_info
*uinfo
)
1503 u32 h_control
= kcontrol
->private_value
;
1510 hpi_level_query_range(h_control
, &min_gain_mB
,
1511 &max_gain_mB
, &step_gain_mB
);
1514 min_gain_mB
= -1000;
1518 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1520 uinfo
->value
.integer
.min
= min_gain_mB
/ HPI_UNITS_PER_dB
;
1521 uinfo
->value
.integer
.max
= max_gain_mB
/ HPI_UNITS_PER_dB
;
1522 uinfo
->value
.integer
.step
= step_gain_mB
/ HPI_UNITS_PER_dB
;
1526 static int snd_asihpi_level_get(struct snd_kcontrol
*kcontrol
,
1527 struct snd_ctl_elem_value
*ucontrol
)
1529 u32 h_control
= kcontrol
->private_value
;
1530 short an_gain_mB
[HPI_MAX_CHANNELS
];
1532 hpi_handle_error(hpi_level_get_gain(h_control
, an_gain_mB
));
1533 ucontrol
->value
.integer
.value
[0] =
1534 an_gain_mB
[0] / HPI_UNITS_PER_dB
;
1535 ucontrol
->value
.integer
.value
[1] =
1536 an_gain_mB
[1] / HPI_UNITS_PER_dB
;
1541 static int snd_asihpi_level_put(struct snd_kcontrol
*kcontrol
,
1542 struct snd_ctl_elem_value
*ucontrol
)
1545 u32 h_control
= kcontrol
->private_value
;
1546 short an_gain_mB
[HPI_MAX_CHANNELS
];
1549 (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1551 (ucontrol
->value
.integer
.value
[1]) * HPI_UNITS_PER_dB
;
1552 /* change = asihpi->mixer_level[addr][0] != left ||
1553 asihpi->mixer_level[addr][1] != right;
1556 hpi_handle_error(hpi_level_set_gain(h_control
, an_gain_mB
));
1560 static const DECLARE_TLV_DB_SCALE(db_scale_level
, -1000, 100, 0);
1562 static int __devinit
snd_asihpi_level_add(struct snd_card_asihpi
*asihpi
,
1563 struct hpi_control
*hpi_ctl
)
1565 struct snd_card
*card
= asihpi
->card
;
1566 struct snd_kcontrol_new snd_control
;
1568 /* can't use 'volume' cos some nodes have volume as well */
1569 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Level");
1570 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1571 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1572 snd_control
.info
= snd_asihpi_level_info
;
1573 snd_control
.get
= snd_asihpi_level_get
;
1574 snd_control
.put
= snd_asihpi_level_put
;
1575 snd_control
.tlv
.p
= db_scale_level
;
1577 return ctl_add(card
, &snd_control
, asihpi
);
1580 /*------------------------------------------------------------
1582 ------------------------------------------------------------*/
1585 static const char * const asihpi_aesebu_format_names
[] = {
1586 "N/A", "S/PDIF", "AES/EBU" };
1588 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol
*kcontrol
,
1589 struct snd_ctl_elem_info
*uinfo
)
1591 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1593 uinfo
->value
.enumerated
.items
= 3;
1595 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1596 uinfo
->value
.enumerated
.item
=
1597 uinfo
->value
.enumerated
.items
- 1;
1599 strcpy(uinfo
->value
.enumerated
.name
,
1600 asihpi_aesebu_format_names
[uinfo
->value
.enumerated
.item
]);
1605 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol
*kcontrol
,
1606 struct snd_ctl_elem_value
*ucontrol
,
1607 u16 (*func
)(u32
, u16
*))
1609 u32 h_control
= kcontrol
->private_value
;
1612 err
= func(h_control
, &source
);
1614 /* default to N/A */
1615 ucontrol
->value
.enumerated
.item
[0] = 0;
1616 /* return success but set the control to N/A */
1619 if (source
== HPI_AESEBU_FORMAT_SPDIF
)
1620 ucontrol
->value
.enumerated
.item
[0] = 1;
1621 if (source
== HPI_AESEBU_FORMAT_AESEBU
)
1622 ucontrol
->value
.enumerated
.item
[0] = 2;
1627 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol
*kcontrol
,
1628 struct snd_ctl_elem_value
*ucontrol
,
1629 u16 (*func
)(u32
, u16
))
1631 u32 h_control
= kcontrol
->private_value
;
1633 /* default to S/PDIF */
1634 u16 source
= HPI_AESEBU_FORMAT_SPDIF
;
1636 if (ucontrol
->value
.enumerated
.item
[0] == 1)
1637 source
= HPI_AESEBU_FORMAT_SPDIF
;
1638 if (ucontrol
->value
.enumerated
.item
[0] == 2)
1639 source
= HPI_AESEBU_FORMAT_AESEBU
;
1641 if (func(h_control
, source
) != 0)
1647 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol
*kcontrol
,
1648 struct snd_ctl_elem_value
*ucontrol
) {
1649 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1650 hpi_aesebu_receiver_get_format
);
1653 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol
*kcontrol
,
1654 struct snd_ctl_elem_value
*ucontrol
) {
1655 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1656 hpi_aesebu_receiver_set_format
);
1659 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol
*kcontrol
,
1660 struct snd_ctl_elem_info
*uinfo
)
1662 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1665 uinfo
->value
.integer
.min
= 0;
1666 uinfo
->value
.integer
.max
= 0X1F;
1667 uinfo
->value
.integer
.step
= 1;
1672 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol
*kcontrol
,
1673 struct snd_ctl_elem_value
*ucontrol
) {
1675 u32 h_control
= kcontrol
->private_value
;
1678 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1679 h_control
, &status
));
1680 ucontrol
->value
.integer
.value
[0] = status
;
1684 static int __devinit
snd_asihpi_aesebu_rx_add(struct snd_card_asihpi
*asihpi
,
1685 struct hpi_control
*hpi_ctl
)
1687 struct snd_card
*card
= asihpi
->card
;
1688 struct snd_kcontrol_new snd_control
;
1690 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1691 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1692 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1693 snd_control
.get
= snd_asihpi_aesebu_rx_format_get
;
1694 snd_control
.put
= snd_asihpi_aesebu_rx_format_put
;
1697 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
1700 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Status");
1701 snd_control
.access
=
1702 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
1703 snd_control
.info
= snd_asihpi_aesebu_rxstatus_info
;
1704 snd_control
.get
= snd_asihpi_aesebu_rxstatus_get
;
1706 return ctl_add(card
, &snd_control
, asihpi
);
1709 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol
*kcontrol
,
1710 struct snd_ctl_elem_value
*ucontrol
) {
1711 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1712 hpi_aesebu_transmitter_get_format
);
1715 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol
*kcontrol
,
1716 struct snd_ctl_elem_value
*ucontrol
) {
1717 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1718 hpi_aesebu_transmitter_set_format
);
1722 static int __devinit
snd_asihpi_aesebu_tx_add(struct snd_card_asihpi
*asihpi
,
1723 struct hpi_control
*hpi_ctl
)
1725 struct snd_card
*card
= asihpi
->card
;
1726 struct snd_kcontrol_new snd_control
;
1728 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1729 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1730 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1731 snd_control
.get
= snd_asihpi_aesebu_tx_format_get
;
1732 snd_control
.put
= snd_asihpi_aesebu_tx_format_put
;
1734 return ctl_add(card
, &snd_control
, asihpi
);
1737 /*------------------------------------------------------------
1739 ------------------------------------------------------------*/
1743 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol
*kcontrol
,
1744 struct snd_ctl_elem_info
*uinfo
)
1746 u32 h_control
= kcontrol
->private_value
;
1751 for (idx
= 0; idx
< 3; idx
++) {
1752 err
= hpi_tuner_query_gain(h_control
,
1753 idx
, &gain_range
[idx
]);
1758 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1760 uinfo
->value
.integer
.min
= ((int)gain_range
[0]) / HPI_UNITS_PER_dB
;
1761 uinfo
->value
.integer
.max
= ((int)gain_range
[1]) / HPI_UNITS_PER_dB
;
1762 uinfo
->value
.integer
.step
= ((int) gain_range
[2]) / HPI_UNITS_PER_dB
;
1766 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol
*kcontrol
,
1767 struct snd_ctl_elem_value
*ucontrol
)
1770 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1772 u32 h_control
= kcontrol
->private_value
;
1775 hpi_handle_error(hpi_tuner_get_gain(h_control
, &gain
));
1776 ucontrol
->value
.integer
.value
[0] = gain
/ HPI_UNITS_PER_dB
;
1781 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol
*kcontrol
,
1782 struct snd_ctl_elem_value
*ucontrol
)
1785 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1787 u32 h_control
= kcontrol
->private_value
;
1790 gain
= (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1791 hpi_handle_error(hpi_tuner_set_gain(h_control
, gain
));
1798 static int asihpi_tuner_band_query(struct snd_kcontrol
*kcontrol
,
1799 u16
*band_list
, u32 len
) {
1800 u32 h_control
= kcontrol
->private_value
;
1804 for (i
= 0; i
< len
; i
++) {
1805 err
= hpi_tuner_query_band(
1806 h_control
, i
, &band_list
[i
]);
1811 if (err
&& (err
!= HPI_ERROR_INVALID_OBJ_INDEX
))
1817 static int snd_asihpi_tuner_band_info(struct snd_kcontrol
*kcontrol
,
1818 struct snd_ctl_elem_info
*uinfo
)
1820 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1823 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1824 HPI_TUNER_BAND_LAST
);
1829 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1831 uinfo
->value
.enumerated
.items
= num_bands
;
1833 if (num_bands
> 0) {
1834 if (uinfo
->value
.enumerated
.item
>=
1835 uinfo
->value
.enumerated
.items
)
1836 uinfo
->value
.enumerated
.item
=
1837 uinfo
->value
.enumerated
.items
- 1;
1839 strcpy(uinfo
->value
.enumerated
.name
,
1840 asihpi_tuner_band_names
[
1841 tuner_bands
[uinfo
->value
.enumerated
.item
]]);
1847 static int snd_asihpi_tuner_band_get(struct snd_kcontrol
*kcontrol
,
1848 struct snd_ctl_elem_value
*ucontrol
)
1850 u32 h_control
= kcontrol
->private_value
;
1852 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1855 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1858 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1859 HPI_TUNER_BAND_LAST
);
1861 hpi_handle_error(hpi_tuner_get_band(h_control
, &band
));
1863 ucontrol
->value
.enumerated
.item
[0] = -1;
1864 for (idx
= 0; idx
< HPI_TUNER_BAND_LAST
; idx
++)
1865 if (tuner_bands
[idx
] == band
) {
1866 ucontrol
->value
.enumerated
.item
[0] = idx
;
1873 static int snd_asihpi_tuner_band_put(struct snd_kcontrol
*kcontrol
,
1874 struct snd_ctl_elem_value
*ucontrol
)
1877 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1879 u32 h_control
= kcontrol
->private_value
;
1881 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1884 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1885 HPI_TUNER_BAND_LAST
);
1887 band
= tuner_bands
[ucontrol
->value
.enumerated
.item
[0]];
1888 hpi_handle_error(hpi_tuner_set_band(h_control
, band
));
1895 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol
*kcontrol
,
1896 struct snd_ctl_elem_info
*uinfo
)
1898 u32 h_control
= kcontrol
->private_value
;
1900 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1901 u16 num_bands
= 0, band_iter
, idx
;
1902 u32 freq_range
[3], temp_freq_range
[3];
1904 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1905 HPI_TUNER_BAND_LAST
);
1907 freq_range
[0] = INT_MAX
;
1909 freq_range
[2] = INT_MAX
;
1911 for (band_iter
= 0; band_iter
< num_bands
; band_iter
++) {
1912 for (idx
= 0; idx
< 3; idx
++) {
1913 err
= hpi_tuner_query_frequency(h_control
,
1914 idx
, tuner_bands
[band_iter
],
1915 &temp_freq_range
[idx
]);
1920 /* skip band with bogus stepping */
1921 if (temp_freq_range
[2] <= 0)
1924 if (temp_freq_range
[0] < freq_range
[0])
1925 freq_range
[0] = temp_freq_range
[0];
1926 if (temp_freq_range
[1] > freq_range
[1])
1927 freq_range
[1] = temp_freq_range
[1];
1928 if (temp_freq_range
[2] < freq_range
[2])
1929 freq_range
[2] = temp_freq_range
[2];
1932 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1934 uinfo
->value
.integer
.min
= ((int)freq_range
[0]);
1935 uinfo
->value
.integer
.max
= ((int)freq_range
[1]);
1936 uinfo
->value
.integer
.step
= ((int)freq_range
[2]);
1940 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol
*kcontrol
,
1941 struct snd_ctl_elem_value
*ucontrol
)
1943 u32 h_control
= kcontrol
->private_value
;
1946 hpi_handle_error(hpi_tuner_get_frequency(h_control
, &freq
));
1947 ucontrol
->value
.integer
.value
[0] = freq
;
1952 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol
*kcontrol
,
1953 struct snd_ctl_elem_value
*ucontrol
)
1955 u32 h_control
= kcontrol
->private_value
;
1958 freq
= ucontrol
->value
.integer
.value
[0];
1959 hpi_handle_error(hpi_tuner_set_frequency(h_control
, freq
));
1964 /* Tuner control group initializer */
1965 static int __devinit
snd_asihpi_tuner_add(struct snd_card_asihpi
*asihpi
,
1966 struct hpi_control
*hpi_ctl
)
1968 struct snd_card
*card
= asihpi
->card
;
1969 struct snd_kcontrol_new snd_control
;
1971 snd_control
.private_value
= hpi_ctl
->h_control
;
1972 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1974 if (!hpi_tuner_get_gain(hpi_ctl
->h_control
, NULL
)) {
1975 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Gain");
1976 snd_control
.info
= snd_asihpi_tuner_gain_info
;
1977 snd_control
.get
= snd_asihpi_tuner_gain_get
;
1978 snd_control
.put
= snd_asihpi_tuner_gain_put
;
1980 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
1984 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Band");
1985 snd_control
.info
= snd_asihpi_tuner_band_info
;
1986 snd_control
.get
= snd_asihpi_tuner_band_get
;
1987 snd_control
.put
= snd_asihpi_tuner_band_put
;
1989 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
1992 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Freq");
1993 snd_control
.info
= snd_asihpi_tuner_freq_info
;
1994 snd_control
.get
= snd_asihpi_tuner_freq_get
;
1995 snd_control
.put
= snd_asihpi_tuner_freq_put
;
1997 return ctl_add(card
, &snd_control
, asihpi
);
2000 /*------------------------------------------------------------
2002 ------------------------------------------------------------*/
2003 static int snd_asihpi_meter_info(struct snd_kcontrol
*kcontrol
,
2004 struct snd_ctl_elem_info
*uinfo
)
2006 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2007 uinfo
->count
= HPI_MAX_CHANNELS
;
2008 uinfo
->value
.integer
.min
= 0;
2009 uinfo
->value
.integer
.max
= 0x7FFFFFFF;
2013 /* linear values for 10dB steps */
2014 static int log2lin
[] = {
2015 0x7FFFFFFF, /* 0dB */
2021 2147484, /* -60dB */
2036 static int snd_asihpi_meter_get(struct snd_kcontrol
*kcontrol
,
2037 struct snd_ctl_elem_value
*ucontrol
)
2039 u32 h_control
= kcontrol
->private_value
;
2040 short an_gain_mB
[HPI_MAX_CHANNELS
], i
;
2043 err
= hpi_meter_get_peak(h_control
, an_gain_mB
);
2045 for (i
= 0; i
< HPI_MAX_CHANNELS
; i
++) {
2047 ucontrol
->value
.integer
.value
[i
] = 0;
2048 } else if (an_gain_mB
[i
] >= 0) {
2049 ucontrol
->value
.integer
.value
[i
] =
2050 an_gain_mB
[i
] << 16;
2052 /* -ve is log value in millibels < -60dB,
2053 * convert to (roughly!) linear,
2055 ucontrol
->value
.integer
.value
[i
] =
2056 log2lin
[an_gain_mB
[i
] / -1000];
2062 static int __devinit
snd_asihpi_meter_add(struct snd_card_asihpi
*asihpi
,
2063 struct hpi_control
*hpi_ctl
, int subidx
)
2065 struct snd_card
*card
= asihpi
->card
;
2066 struct snd_kcontrol_new snd_control
;
2068 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Meter");
2069 snd_control
.access
=
2070 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2071 snd_control
.info
= snd_asihpi_meter_info
;
2072 snd_control
.get
= snd_asihpi_meter_get
;
2074 snd_control
.index
= subidx
;
2076 return ctl_add(card
, &snd_control
, asihpi
);
2079 /*------------------------------------------------------------
2080 Multiplexer controls
2081 ------------------------------------------------------------*/
2082 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol
*snd_control
)
2084 u32 h_control
= snd_control
->private_value
;
2085 struct hpi_control hpi_ctl
;
2087 for (s
= 0; s
< 32; s
++) {
2088 err
= hpi_multiplexer_query_source(h_control
, s
,
2099 static int snd_asihpi_mux_info(struct snd_kcontrol
*kcontrol
,
2100 struct snd_ctl_elem_info
*uinfo
)
2103 u16 src_node_type
, src_node_index
;
2104 u32 h_control
= kcontrol
->private_value
;
2106 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2108 uinfo
->value
.enumerated
.items
=
2109 snd_card_asihpi_mux_count_sources(kcontrol
);
2111 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2112 uinfo
->value
.enumerated
.item
=
2113 uinfo
->value
.enumerated
.items
- 1;
2116 hpi_multiplexer_query_source(h_control
,
2117 uinfo
->value
.enumerated
.item
,
2118 &src_node_type
, &src_node_index
);
2120 sprintf(uinfo
->value
.enumerated
.name
, "%s %d",
2121 asihpi_src_names
[src_node_type
- HPI_SOURCENODE_NONE
],
2126 static int snd_asihpi_mux_get(struct snd_kcontrol
*kcontrol
,
2127 struct snd_ctl_elem_value
*ucontrol
)
2129 u32 h_control
= kcontrol
->private_value
;
2130 u16 source_type
, source_index
;
2131 u16 src_node_type
, src_node_index
;
2134 hpi_handle_error(hpi_multiplexer_get_source(h_control
,
2135 &source_type
, &source_index
));
2136 /* Should cache this search result! */
2137 for (s
= 0; s
< 256; s
++) {
2138 if (hpi_multiplexer_query_source(h_control
, s
,
2139 &src_node_type
, &src_node_index
))
2142 if ((source_type
== src_node_type
)
2143 && (source_index
== src_node_index
)) {
2144 ucontrol
->value
.enumerated
.item
[0] = s
;
2148 snd_printd(KERN_WARNING
2149 "Control %x failed to match mux source %hu %hu\n",
2150 h_control
, source_type
, source_index
);
2151 ucontrol
->value
.enumerated
.item
[0] = 0;
2155 static int snd_asihpi_mux_put(struct snd_kcontrol
*kcontrol
,
2156 struct snd_ctl_elem_value
*ucontrol
)
2159 u32 h_control
= kcontrol
->private_value
;
2160 u16 source_type
, source_index
;
2165 e
= hpi_multiplexer_query_source(h_control
,
2166 ucontrol
->value
.enumerated
.item
[0],
2167 &source_type
, &source_index
);
2170 hpi_multiplexer_set_source(h_control
,
2171 source_type
, source_index
));
2176 static int __devinit
snd_asihpi_mux_add(struct snd_card_asihpi
*asihpi
,
2177 struct hpi_control
*hpi_ctl
)
2179 struct snd_card
*card
= asihpi
->card
;
2180 struct snd_kcontrol_new snd_control
;
2182 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Route");
2183 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2184 snd_control
.info
= snd_asihpi_mux_info
;
2185 snd_control
.get
= snd_asihpi_mux_get
;
2186 snd_control
.put
= snd_asihpi_mux_put
;
2188 return ctl_add(card
, &snd_control
, asihpi
);
2192 /*------------------------------------------------------------
2193 Channel mode controls
2194 ------------------------------------------------------------*/
2195 static int snd_asihpi_cmode_info(struct snd_kcontrol
*kcontrol
,
2196 struct snd_ctl_elem_info
*uinfo
)
2198 static const char * const mode_names
[HPI_CHANNEL_MODE_LAST
+ 1] = {
2201 "From Left", "From Right",
2202 "To Left", "To Right"
2205 u32 h_control
= kcontrol
->private_value
;
2209 int valid_modes
= 0;
2211 /* HPI channel mode values can be from 1 to 6
2212 Some adapters only support a contiguous subset
2214 for (i
= 0; i
< HPI_CHANNEL_MODE_LAST
; i
++)
2215 if (!hpi_channel_mode_query_mode(
2216 h_control
, i
, &mode
)) {
2217 mode_map
[valid_modes
] = mode
;
2221 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2223 uinfo
->value
.enumerated
.items
= valid_modes
;
2225 if (uinfo
->value
.enumerated
.item
>= valid_modes
)
2226 uinfo
->value
.enumerated
.item
= valid_modes
- 1;
2228 strcpy(uinfo
->value
.enumerated
.name
,
2229 mode_names
[mode_map
[uinfo
->value
.enumerated
.item
]]);
2234 static int snd_asihpi_cmode_get(struct snd_kcontrol
*kcontrol
,
2235 struct snd_ctl_elem_value
*ucontrol
)
2237 u32 h_control
= kcontrol
->private_value
;
2240 if (hpi_channel_mode_get(h_control
, &mode
))
2243 ucontrol
->value
.enumerated
.item
[0] = mode
- 1;
2248 static int snd_asihpi_cmode_put(struct snd_kcontrol
*kcontrol
,
2249 struct snd_ctl_elem_value
*ucontrol
)
2252 u32 h_control
= kcontrol
->private_value
;
2256 hpi_handle_error(hpi_channel_mode_set(h_control
,
2257 ucontrol
->value
.enumerated
.item
[0] + 1));
2262 static int __devinit
snd_asihpi_cmode_add(struct snd_card_asihpi
*asihpi
,
2263 struct hpi_control
*hpi_ctl
)
2265 struct snd_card
*card
= asihpi
->card
;
2266 struct snd_kcontrol_new snd_control
;
2268 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Mode");
2269 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2270 snd_control
.info
= snd_asihpi_cmode_info
;
2271 snd_control
.get
= snd_asihpi_cmode_get
;
2272 snd_control
.put
= snd_asihpi_cmode_put
;
2274 return ctl_add(card
, &snd_control
, asihpi
);
2277 /*------------------------------------------------------------
2278 Sampleclock source controls
2279 ------------------------------------------------------------*/
2280 static char *sampleclock_sources
[MAX_CLOCKSOURCES
] = {
2281 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2282 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2284 "Digital2", "Digital3", "Digital4", "Digital5",
2285 "Digital6", "Digital7", "Digital8"};
2287 static int snd_asihpi_clksrc_info(struct snd_kcontrol
*kcontrol
,
2288 struct snd_ctl_elem_info
*uinfo
)
2290 struct snd_card_asihpi
*asihpi
=
2291 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2292 struct clk_cache
*clkcache
= &asihpi
->cc
;
2293 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2295 uinfo
->value
.enumerated
.items
= clkcache
->count
;
2297 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2298 uinfo
->value
.enumerated
.item
=
2299 uinfo
->value
.enumerated
.items
- 1;
2301 strcpy(uinfo
->value
.enumerated
.name
,
2302 clkcache
->s
[uinfo
->value
.enumerated
.item
].name
);
2306 static int snd_asihpi_clksrc_get(struct snd_kcontrol
*kcontrol
,
2307 struct snd_ctl_elem_value
*ucontrol
)
2309 struct snd_card_asihpi
*asihpi
=
2310 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2311 struct clk_cache
*clkcache
= &asihpi
->cc
;
2312 u32 h_control
= kcontrol
->private_value
;
2313 u16 source
, srcindex
= 0;
2316 ucontrol
->value
.enumerated
.item
[0] = 0;
2317 if (hpi_sample_clock_get_source(h_control
, &source
))
2320 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2321 if (hpi_sample_clock_get_source_index(h_control
, &srcindex
))
2324 for (i
= 0; i
< clkcache
->count
; i
++)
2325 if ((clkcache
->s
[i
].source
== source
) &&
2326 (clkcache
->s
[i
].index
== srcindex
))
2329 ucontrol
->value
.enumerated
.item
[0] = i
;
2334 static int snd_asihpi_clksrc_put(struct snd_kcontrol
*kcontrol
,
2335 struct snd_ctl_elem_value
*ucontrol
)
2337 struct snd_card_asihpi
*asihpi
=
2338 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2339 struct clk_cache
*clkcache
= &asihpi
->cc
;
2341 u32 h_control
= kcontrol
->private_value
;
2344 item
= ucontrol
->value
.enumerated
.item
[0];
2345 if (item
>= clkcache
->count
)
2346 item
= clkcache
->count
-1;
2348 hpi_handle_error(hpi_sample_clock_set_source(
2349 h_control
, clkcache
->s
[item
].source
));
2351 if (clkcache
->s
[item
].source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2352 hpi_handle_error(hpi_sample_clock_set_source_index(
2353 h_control
, clkcache
->s
[item
].index
));
2357 /*------------------------------------------------------------
2359 ------------------------------------------------------------*/
2360 /* Need to change this to enumerated control with list of rates */
2361 static int snd_asihpi_clklocal_info(struct snd_kcontrol
*kcontrol
,
2362 struct snd_ctl_elem_info
*uinfo
)
2364 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2366 uinfo
->value
.integer
.min
= 8000;
2367 uinfo
->value
.integer
.max
= 192000;
2368 uinfo
->value
.integer
.step
= 100;
2373 static int snd_asihpi_clklocal_get(struct snd_kcontrol
*kcontrol
,
2374 struct snd_ctl_elem_value
*ucontrol
)
2376 u32 h_control
= kcontrol
->private_value
;
2380 e
= hpi_sample_clock_get_local_rate(h_control
, &rate
);
2382 ucontrol
->value
.integer
.value
[0] = rate
;
2384 ucontrol
->value
.integer
.value
[0] = 0;
2388 static int snd_asihpi_clklocal_put(struct snd_kcontrol
*kcontrol
,
2389 struct snd_ctl_elem_value
*ucontrol
)
2392 u32 h_control
= kcontrol
->private_value
;
2394 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2395 asihpi->mixer_clkrate[addr][1] != right;
2398 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control
,
2399 ucontrol
->value
.integer
.value
[0]));
2403 static int snd_asihpi_clkrate_info(struct snd_kcontrol
*kcontrol
,
2404 struct snd_ctl_elem_info
*uinfo
)
2406 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2408 uinfo
->value
.integer
.min
= 8000;
2409 uinfo
->value
.integer
.max
= 192000;
2410 uinfo
->value
.integer
.step
= 100;
2415 static int snd_asihpi_clkrate_get(struct snd_kcontrol
*kcontrol
,
2416 struct snd_ctl_elem_value
*ucontrol
)
2418 u32 h_control
= kcontrol
->private_value
;
2422 e
= hpi_sample_clock_get_sample_rate(h_control
, &rate
);
2424 ucontrol
->value
.integer
.value
[0] = rate
;
2426 ucontrol
->value
.integer
.value
[0] = 0;
2430 static int __devinit
snd_asihpi_sampleclock_add(struct snd_card_asihpi
*asihpi
,
2431 struct hpi_control
*hpi_ctl
)
2433 struct snd_card
*card
= asihpi
->card
;
2434 struct snd_kcontrol_new snd_control
;
2436 struct clk_cache
*clkcache
= &asihpi
->cc
;
2437 u32 hSC
= hpi_ctl
->h_control
;
2442 snd_control
.private_value
= hpi_ctl
->h_control
;
2444 clkcache
->has_local
= 0;
2446 for (i
= 0; i
<= HPI_SAMPLECLOCK_SOURCE_LAST
; i
++) {
2447 if (hpi_sample_clock_query_source(hSC
,
2450 clkcache
->s
[i
].source
= source
;
2451 clkcache
->s
[i
].index
= 0;
2452 clkcache
->s
[i
].name
= sampleclock_sources
[source
];
2453 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2455 if (source
== HPI_SAMPLECLOCK_SOURCE_LOCAL
)
2456 clkcache
->has_local
= 1;
2459 /* already will have picked up index 0 above */
2460 for (j
= 1; j
< 8; j
++) {
2461 if (hpi_sample_clock_query_source_index(hSC
,
2462 j
, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
,
2465 clkcache
->s
[i
].source
=
2466 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
;
2467 clkcache
->s
[i
].index
= j
;
2468 clkcache
->s
[i
].name
= sampleclock_sources
[
2469 j
+HPI_SAMPLECLOCK_SOURCE_LAST
];
2472 clkcache
->count
= i
;
2474 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Source");
2475 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2476 snd_control
.info
= snd_asihpi_clksrc_info
;
2477 snd_control
.get
= snd_asihpi_clksrc_get
;
2478 snd_control
.put
= snd_asihpi_clksrc_put
;
2479 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2483 if (clkcache
->has_local
) {
2484 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Localrate");
2485 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2486 snd_control
.info
= snd_asihpi_clklocal_info
;
2487 snd_control
.get
= snd_asihpi_clklocal_get
;
2488 snd_control
.put
= snd_asihpi_clklocal_put
;
2491 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2495 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Rate");
2496 snd_control
.access
=
2497 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2498 snd_control
.info
= snd_asihpi_clkrate_info
;
2499 snd_control
.get
= snd_asihpi_clkrate_get
;
2501 return ctl_add(card
, &snd_control
, asihpi
);
2503 /*------------------------------------------------------------
2505 ------------------------------------------------------------*/
2507 static int __devinit
snd_card_asihpi_mixer_new(struct snd_card_asihpi
*asihpi
)
2509 struct snd_card
*card
= asihpi
->card
;
2510 unsigned int idx
= 0;
2511 unsigned int subindex
= 0;
2513 struct hpi_control hpi_ctl
, prev_ctl
;
2515 if (snd_BUG_ON(!asihpi
))
2517 strcpy(card
->mixername
, "Asihpi Mixer");
2520 hpi_mixer_open(asihpi
->adapter_index
,
2522 hpi_handle_error(err
);
2526 memset(&prev_ctl
, 0, sizeof(prev_ctl
));
2527 prev_ctl
.control_type
= -1;
2529 for (idx
= 0; idx
< 2000; idx
++) {
2530 err
= hpi_mixer_get_control_by_index(
2533 &hpi_ctl
.src_node_type
,
2534 &hpi_ctl
.src_node_index
,
2535 &hpi_ctl
.dst_node_type
,
2536 &hpi_ctl
.dst_node_index
,
2537 &hpi_ctl
.control_type
,
2538 &hpi_ctl
.h_control
);
2540 if (err
== HPI_ERROR_CONTROL_DISABLED
) {
2542 snd_printk(KERN_INFO
2543 "Disabled HPI Control(%d)\n",
2551 hpi_ctl
.src_node_type
-= HPI_SOURCENODE_NONE
;
2552 hpi_ctl
.dst_node_type
-= HPI_DESTNODE_NONE
;
2554 /* ASI50xx in SSX mode has multiple meters on the same node.
2555 Use subindex to create distinct ALSA controls
2556 for any duplicated controls.
2558 if ((hpi_ctl
.control_type
== prev_ctl
.control_type
) &&
2559 (hpi_ctl
.src_node_type
== prev_ctl
.src_node_type
) &&
2560 (hpi_ctl
.src_node_index
== prev_ctl
.src_node_index
) &&
2561 (hpi_ctl
.dst_node_type
== prev_ctl
.dst_node_type
) &&
2562 (hpi_ctl
.dst_node_index
== prev_ctl
.dst_node_index
))
2569 switch (hpi_ctl
.control_type
) {
2570 case HPI_CONTROL_VOLUME
:
2571 err
= snd_asihpi_volume_add(asihpi
, &hpi_ctl
);
2573 case HPI_CONTROL_LEVEL
:
2574 err
= snd_asihpi_level_add(asihpi
, &hpi_ctl
);
2576 case HPI_CONTROL_MULTIPLEXER
:
2577 err
= snd_asihpi_mux_add(asihpi
, &hpi_ctl
);
2579 case HPI_CONTROL_CHANNEL_MODE
:
2580 err
= snd_asihpi_cmode_add(asihpi
, &hpi_ctl
);
2582 case HPI_CONTROL_METER
:
2583 err
= snd_asihpi_meter_add(asihpi
, &hpi_ctl
, subindex
);
2585 case HPI_CONTROL_SAMPLECLOCK
:
2586 err
= snd_asihpi_sampleclock_add(
2589 case HPI_CONTROL_CONNECTION
: /* ignore these */
2591 case HPI_CONTROL_TUNER
:
2592 err
= snd_asihpi_tuner_add(asihpi
, &hpi_ctl
);
2594 case HPI_CONTROL_AESEBU_TRANSMITTER
:
2595 err
= snd_asihpi_aesebu_tx_add(asihpi
, &hpi_ctl
);
2597 case HPI_CONTROL_AESEBU_RECEIVER
:
2598 err
= snd_asihpi_aesebu_rx_add(asihpi
, &hpi_ctl
);
2600 case HPI_CONTROL_VOX
:
2601 case HPI_CONTROL_BITSTREAM
:
2602 case HPI_CONTROL_MICROPHONE
:
2603 case HPI_CONTROL_PARAMETRIC_EQ
:
2604 case HPI_CONTROL_COMPANDER
:
2607 snd_printk(KERN_INFO
2608 "Untranslated HPI Control"
2609 "(%d) %d %d %d %d %d\n",
2611 hpi_ctl
.control_type
,
2612 hpi_ctl
.src_node_type
,
2613 hpi_ctl
.src_node_index
,
2614 hpi_ctl
.dst_node_type
,
2615 hpi_ctl
.dst_node_index
);
2621 if (HPI_ERROR_INVALID_OBJ_INDEX
!= err
)
2622 hpi_handle_error(err
);
2624 snd_printk(KERN_INFO
"%d mixer controls found\n", idx
);
2629 /*------------------------------------------------------------
2631 ------------------------------------------------------------*/
2634 snd_asihpi_proc_read(struct snd_info_entry
*entry
,
2635 struct snd_info_buffer
*buffer
)
2637 struct snd_card_asihpi
*asihpi
= entry
->private_data
;
2644 snd_iprintf(buffer
, "ASIHPI driver proc file\n");
2646 "adapter ID=%4X\n_index=%d\n"
2647 "num_outstreams=%d\n_num_instreams=%d\n",
2648 asihpi
->type
, asihpi
->adapter_index
,
2649 asihpi
->num_outstreams
, asihpi
->num_instreams
);
2651 version
= asihpi
->version
;
2653 "serial#=%d\n_hw version %c%d\nDSP code version %03d\n",
2654 asihpi
->serial_number
, ((version
>> 3) & 0xf) + 'A',
2656 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2658 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2659 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2660 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2663 err
= hpi_sample_clock_get_sample_rate(
2665 err
+= hpi_sample_clock_get_source(h_control
, &source
);
2668 snd_iprintf(buffer
, "sample_clock=%d_hz, source %s\n",
2669 rate
, sampleclock_sources
[source
]);
2675 static void __devinit
snd_asihpi_proc_init(struct snd_card_asihpi
*asihpi
)
2677 struct snd_info_entry
*entry
;
2679 if (!snd_card_proc_new(asihpi
->card
, "info", &entry
))
2680 snd_info_set_text_ops(entry
, asihpi
, snd_asihpi_proc_read
);
2683 /*------------------------------------------------------------
2685 ------------------------------------------------------------*/
2687 static int snd_asihpi_hpi_open(struct snd_hwdep
*hw
, struct file
*file
)
2689 if (enable_hpi_hwdep
)
2696 static int snd_asihpi_hpi_release(struct snd_hwdep
*hw
, struct file
*file
)
2698 if (enable_hpi_hwdep
)
2699 return asihpi_hpi_release(file
);
2704 static int snd_asihpi_hpi_ioctl(struct snd_hwdep
*hw
, struct file
*file
,
2705 unsigned int cmd
, unsigned long arg
)
2707 if (enable_hpi_hwdep
)
2708 return asihpi_hpi_ioctl(file
, cmd
, arg
);
2714 /* results in /dev/snd/hwC#D0 file for each card with index #
2715 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2717 static int __devinit
snd_asihpi_hpi_new(struct snd_card_asihpi
*asihpi
,
2718 int device
, struct snd_hwdep
**rhwdep
)
2720 struct snd_hwdep
*hw
;
2725 err
= snd_hwdep_new(asihpi
->card
, "HPI", device
, &hw
);
2728 strcpy(hw
->name
, "asihpi (HPI)");
2729 hw
->iface
= SNDRV_HWDEP_IFACE_LAST
;
2730 hw
->ops
.open
= snd_asihpi_hpi_open
;
2731 hw
->ops
.ioctl
= snd_asihpi_hpi_ioctl
;
2732 hw
->ops
.release
= snd_asihpi_hpi_release
;
2733 hw
->private_data
= asihpi
;
2739 /*------------------------------------------------------------
2741 ------------------------------------------------------------*/
2742 static int __devinit
snd_asihpi_probe(struct pci_dev
*pci_dev
,
2743 const struct pci_device_id
*pci_id
)
2750 struct hpi_adapter
*hpi_card
;
2751 struct snd_card
*card
;
2752 struct snd_card_asihpi
*asihpi
;
2758 if (dev
>= SNDRV_CARDS
)
2761 /* Should this be enable[hpi_card->index] ? */
2767 err
= asihpi_adapter_probe(pci_dev
, pci_id
);
2771 hpi_card
= pci_get_drvdata(pci_dev
);
2772 /* first try to give the card the same index as its hardware index */
2773 err
= snd_card_create(hpi_card
->index
,
2774 id
[hpi_card
->index
], THIS_MODULE
,
2775 sizeof(struct snd_card_asihpi
),
2778 /* if that fails, try the default index==next available */
2780 snd_card_create(index
[dev
], id
[dev
],
2782 sizeof(struct snd_card_asihpi
),
2786 snd_printk(KERN_WARNING
2787 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2788 hpi_card
->index
, card
->number
);
2791 snd_card_set_dev(card
, &pci_dev
->dev
);
2793 asihpi
= (struct snd_card_asihpi
*) card
->private_data
;
2794 asihpi
->card
= card
;
2795 asihpi
->pci
= pci_dev
;
2796 asihpi
->adapter_index
= hpi_card
->index
;
2797 hpi_handle_error(hpi_adapter_get_info(
2798 asihpi
->adapter_index
,
2799 &asihpi
->num_outstreams
,
2800 &asihpi
->num_instreams
,
2802 &asihpi
->serial_number
, &asihpi
->type
));
2804 version
= asihpi
->version
;
2805 snd_printk(KERN_INFO
"adapter ID=%4X index=%d num_outstreams=%d "
2806 "num_instreams=%d S/N=%d\n"
2807 "Hw Version %c%d DSP code version %03d\n",
2808 asihpi
->type
, asihpi
->adapter_index
,
2809 asihpi
->num_outstreams
,
2810 asihpi
->num_instreams
, asihpi
->serial_number
,
2811 ((version
>> 3) & 0xf) + 'A',
2813 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2815 pcm_substreams
= asihpi
->num_outstreams
;
2816 if (pcm_substreams
< asihpi
->num_instreams
)
2817 pcm_substreams
= asihpi
->num_instreams
;
2819 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2820 HPI_ADAPTER_PROPERTY_CAPS1
,
2821 NULL
, &asihpi
->support_grouping
);
2823 asihpi
->support_grouping
= 0;
2825 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2826 HPI_ADAPTER_PROPERTY_CAPS2
,
2827 &asihpi
->support_mrx
, NULL
);
2829 asihpi
->support_mrx
= 0;
2831 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2832 HPI_ADAPTER_PROPERTY_INTERVAL
,
2833 NULL
, &asihpi
->update_interval_frames
);
2835 asihpi
->update_interval_frames
= 512;
2837 if (!asihpi
->can_dma
)
2838 asihpi
->update_interval_frames
*= 2;
2840 hpi_handle_error(hpi_instream_open(asihpi
->adapter_index
,
2843 err
= hpi_instream_host_buffer_free(h_stream
);
2844 asihpi
->can_dma
= (!err
);
2846 hpi_handle_error(hpi_instream_close(h_stream
));
2848 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2849 HPI_ADAPTER_PROPERTY_CURCHANNELS
,
2850 &asihpi
->in_max_chans
, &asihpi
->out_max_chans
);
2852 asihpi
->in_max_chans
= 2;
2853 asihpi
->out_max_chans
= 2;
2856 snd_printk(KERN_INFO
"has dma:%d, grouping:%d, mrx:%d\n",
2858 asihpi
->support_grouping
,
2862 err
= snd_card_asihpi_pcm_new(asihpi
, 0, pcm_substreams
);
2864 snd_printk(KERN_ERR
"pcm_new failed\n");
2867 err
= snd_card_asihpi_mixer_new(asihpi
);
2869 snd_printk(KERN_ERR
"mixer_new failed\n");
2873 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2874 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2875 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2878 err
= hpi_sample_clock_set_local_rate(
2879 h_control
, adapter_fs
);
2881 snd_asihpi_proc_init(asihpi
);
2883 /* always create, can be enabled or disabled dynamically
2884 by enable_hwdep module param*/
2885 snd_asihpi_hpi_new(asihpi
, 0, NULL
);
2887 strcpy(card
->driver
, "ASIHPI");
2889 sprintf(card
->shortname
, "AudioScience ASI%4X", asihpi
->type
);
2890 sprintf(card
->longname
, "%s %i",
2891 card
->shortname
, asihpi
->adapter_index
);
2892 err
= snd_card_register(card
);
2895 hpi_card
->snd_card_asihpi
= card
;
2900 snd_card_free(card
);
2901 snd_printk(KERN_ERR
"snd_asihpi_probe error %d\n", err
);
2906 static void __devexit
snd_asihpi_remove(struct pci_dev
*pci_dev
)
2908 struct hpi_adapter
*hpi_card
= pci_get_drvdata(pci_dev
);
2910 snd_card_free(hpi_card
->snd_card_asihpi
);
2911 hpi_card
->snd_card_asihpi
= NULL
;
2912 asihpi_adapter_remove(pci_dev
);
2915 static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl
) = {
2916 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_DSP6205
,
2917 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2918 (kernel_ulong_t
)HPI_6205
},
2919 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_PCI2040
,
2920 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2921 (kernel_ulong_t
)HPI_6000
},
2924 MODULE_DEVICE_TABLE(pci
, asihpi_pci_tbl
);
2926 static struct pci_driver driver
= {
2928 .id_table
= asihpi_pci_tbl
,
2929 .probe
= snd_asihpi_probe
,
2930 .remove
= __devexit_p(snd_asihpi_remove
),
2932 /* .suspend = snd_asihpi_suspend,
2933 .resume = snd_asihpi_resume, */
2937 static int __init
snd_asihpi_init(void)
2940 return pci_register_driver(&driver
);
2943 static void __exit
snd_asihpi_exit(void)
2946 pci_unregister_driver(&driver
);
2950 module_init(snd_asihpi_init
)
2951 module_exit(snd_asihpi_exit
)