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>
45 MODULE_LICENSE("GPL");
46 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
47 MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx");
49 #if defined CONFIG_SND_DEBUG_VERBOSE
51 * snd_printddd - very verbose debug printk
52 * @format: format string
54 * Works like snd_printk() for debugging purposes.
55 * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
56 * Must set snd module debug parameter to 3 to enable at runtime.
58 #define snd_printddd(format, args...) \
59 __snd_printk(3, __FILE__, __LINE__, format, ##args)
61 #define snd_printddd(format, args...) do { } while (0)
64 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* index 0-MAX */
65 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
66 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
67 static int enable_hpi_hwdep
= 1;
69 module_param_array(index
, int, NULL
, S_IRUGO
);
70 MODULE_PARM_DESC(index
, "ALSA index value for AudioScience soundcard.");
72 module_param_array(id
, charp
, NULL
, S_IRUGO
);
73 MODULE_PARM_DESC(id
, "ALSA ID string for AudioScience soundcard.");
75 module_param_array(enable
, bool, NULL
, S_IRUGO
);
76 MODULE_PARM_DESC(enable
, "ALSA enable AudioScience soundcard.");
78 module_param(enable_hpi_hwdep
, bool, S_IRUGO
|S_IWUSR
);
79 MODULE_PARM_DESC(enable_hpi_hwdep
,
80 "ALSA enable HPI hwdep for AudioScience soundcard ");
83 #ifdef KERNEL_ALSA_BUILD
84 static char *build_info
= "Built using headers from kernel source";
85 module_param(build_info
, charp
, S_IRUGO
);
86 MODULE_PARM_DESC(build_info
, "built using headers from kernel source");
88 static char *build_info
= "Built within ALSA source";
89 module_param(build_info
, charp
, S_IRUGO
);
90 MODULE_PARM_DESC(build_info
, "built within ALSA source");
93 /* set to 1 to dump every control from adapter to log */
94 static const int mixer_dump
;
96 #define DEFAULT_SAMPLERATE 44100
97 static int adapter_fs
= DEFAULT_SAMPLERATE
;
100 #define PERIODS_MIN 2
101 #define PERIOD_BYTES_MIN 2048
102 #define BUFFER_BYTES_MAX (512 * 1024)
104 /* convert stream to character */
105 #define SCHR(s) ((s == SNDRV_PCM_STREAM_PLAYBACK) ? 'P' : 'C')
107 /*#define TIMER_MILLISECONDS 20
108 #define FORCE_TIMER_JIFFIES ((TIMER_MILLISECONDS * HZ + 999)/1000)
111 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
122 struct clk_source s
[MAX_CLOCKSOURCES
];
126 struct snd_card_asihpi
{
127 struct snd_card
*card
;
140 u16 support_grouping
;
142 u16 update_interval_frames
;
147 /* Per stream data */
148 struct snd_card_asihpi_pcm
{
149 struct timer_list timer
;
150 unsigned int respawn_timer
;
151 unsigned int hpi_buffer_attached
;
152 unsigned int buffer_bytes
;
153 unsigned int period_bytes
;
154 unsigned int bytes_per_sec
;
155 unsigned int pcm_buf_host_rw_ofs
; /* Host R/W pos */
156 unsigned int pcm_buf_dma_ofs
; /* DMA R/W offset in buffer */
157 unsigned int pcm_buf_elapsed_dma_ofs
; /* DMA R/W offset in buffer */
158 struct snd_pcm_substream
*substream
;
160 struct hpi_format format
;
163 /* universal stream verbs work with out or in stream handles */
165 /* Functions to allow driver to give a buffer to HPI for busmastering */
167 static u16
hpi_stream_host_buffer_attach(
168 u32 h_stream
, /* handle to outstream. */
169 u32 size_in_bytes
, /* size in bytes of bus mastering buffer */
173 struct hpi_message hm
;
174 struct hpi_response hr
;
175 unsigned int obj
= hpi_handle_object(h_stream
);
178 return HPI_ERROR_INVALID_OBJ
;
179 hpi_init_message_response(&hm
, &hr
, obj
,
180 obj
== HPI_OBJ_OSTREAM
?
181 HPI_OSTREAM_HOSTBUFFER_ALLOC
:
182 HPI_ISTREAM_HOSTBUFFER_ALLOC
);
184 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
187 hm
.u
.d
.u
.buffer
.buffer_size
= size_in_bytes
;
188 hm
.u
.d
.u
.buffer
.pci_address
= pci_address
;
189 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
;
190 hpi_send_recv(&hm
, &hr
);
194 static u16
hpi_stream_host_buffer_detach(u32 h_stream
)
196 struct hpi_message hm
;
197 struct hpi_response hr
;
198 unsigned int obj
= hpi_handle_object(h_stream
);
201 return HPI_ERROR_INVALID_OBJ
;
203 hpi_init_message_response(&hm
, &hr
, obj
,
204 obj
== HPI_OBJ_OSTREAM
?
205 HPI_OSTREAM_HOSTBUFFER_FREE
:
206 HPI_ISTREAM_HOSTBUFFER_FREE
);
208 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
210 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
;
211 hpi_send_recv(&hm
, &hr
);
215 static inline u16
hpi_stream_start(u32 h_stream
)
217 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
218 return hpi_outstream_start(h_stream
);
220 return hpi_instream_start(h_stream
);
223 static inline u16
hpi_stream_stop(u32 h_stream
)
225 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
226 return hpi_outstream_stop(h_stream
);
228 return hpi_instream_stop(h_stream
);
231 static inline u16
hpi_stream_get_info_ex(
235 u32
*pdata_in_buffer
,
241 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
242 e
= hpi_outstream_get_info_ex(h_stream
, pw_state
,
243 pbuffer_size
, pdata_in_buffer
,
244 psample_count
, pauxiliary_data
);
246 e
= hpi_instream_get_info_ex(h_stream
, pw_state
,
247 pbuffer_size
, pdata_in_buffer
,
248 psample_count
, pauxiliary_data
);
252 static inline u16
hpi_stream_group_add(
256 if (hpi_handle_object(h_master
) == HPI_OBJ_OSTREAM
)
257 return hpi_outstream_group_add(h_master
, h_stream
);
259 return hpi_instream_group_add(h_master
, h_stream
);
262 static inline u16
hpi_stream_group_reset(u32 h_stream
)
264 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
265 return hpi_outstream_group_reset(h_stream
);
267 return hpi_instream_group_reset(h_stream
);
270 static inline u16
hpi_stream_group_get_map(
271 u32 h_stream
, u32
*mo
, u32
*mi
)
273 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
274 return hpi_outstream_group_get_map(h_stream
, mo
, mi
);
276 return hpi_instream_group_get_map(h_stream
, mo
, mi
);
279 static u16
handle_error(u16 err
, int line
, char *filename
)
283 "in file %s, line %d: HPI error %d\n",
284 filename
, line
, err
);
288 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
290 /***************************** GENERAL PCM ****************/
291 static void print_hwparams(struct snd_pcm_hw_params
*p
)
293 snd_printd("HWPARAMS \n");
294 snd_printd("samplerate %d \n", params_rate(p
));
295 snd_printd("Channels %d \n", params_channels(p
));
296 snd_printd("Format %d \n", params_format(p
));
297 snd_printd("subformat %d \n", params_subformat(p
));
298 snd_printd("Buffer bytes %d \n", params_buffer_bytes(p
));
299 snd_printd("Period bytes %d \n", params_period_bytes(p
));
300 snd_printd("access %d \n", params_access(p
));
301 snd_printd("period_size %d \n", params_period_size(p
));
302 snd_printd("periods %d \n", params_periods(p
));
303 snd_printd("buffer_size %d \n", params_buffer_size(p
));
306 static snd_pcm_format_t hpi_to_alsa_formats
[] = {
308 SNDRV_PCM_FORMAT_U8
, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
309 SNDRV_PCM_FORMAT_S16
, /* HPI_FORMAT_PCM16_SIGNED 2 */
310 -1, /* HPI_FORMAT_MPEG_L1 3 */
311 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L2 4 */
312 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L3 5 */
313 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
314 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
315 SNDRV_PCM_FORMAT_S16_BE
,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
316 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
317 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
318 SNDRV_PCM_FORMAT_S32
, /* HPI_FORMAT_PCM32_SIGNED 11 */
319 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
320 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
321 SNDRV_PCM_FORMAT_FLOAT
, /* HPI_FORMAT_PCM32_FLOAT 14 */
323 /* ALSA can't handle 3 byte sample size together with power-of-2
324 * constraint on buffer_bytes, so disable this format
328 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
333 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format
,
338 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
339 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
340 if (hpi_to_alsa_formats
[format
] == alsa_format
) {
341 *hpi_format
= format
;
346 snd_printd(KERN_WARNING
"failed match for alsa format %d\n",
352 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi
*asihpi
,
353 struct snd_pcm_hardware
*pcmhw
)
359 unsigned int rate_min
= 200000;
360 unsigned int rate_max
= 0;
361 unsigned int rates
= 0;
363 if (asihpi
->support_mrx
) {
364 rates
|= SNDRV_PCM_RATE_CONTINUOUS
;
365 rates
|= SNDRV_PCM_RATE_8000_96000
;
369 /* on cards without SRC,
370 valid rates are determined by sampleclock */
371 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
372 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
373 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
376 "No local sampleclock, err %d\n", err
);
379 for (idx
= -1; idx
< 100; idx
++) {
381 if (hpi_sample_clock_get_sample_rate(h_control
,
384 } else if (hpi_sample_clock_query_local_rate(h_control
,
385 idx
, &sample_rate
)) {
389 rate_min
= min(rate_min
, sample_rate
);
390 rate_max
= max(rate_max
, sample_rate
);
392 switch (sample_rate
) {
394 rates
|= SNDRV_PCM_RATE_5512
;
397 rates
|= SNDRV_PCM_RATE_8000
;
400 rates
|= SNDRV_PCM_RATE_11025
;
403 rates
|= SNDRV_PCM_RATE_16000
;
406 rates
|= SNDRV_PCM_RATE_22050
;
409 rates
|= SNDRV_PCM_RATE_32000
;
412 rates
|= SNDRV_PCM_RATE_44100
;
415 rates
|= SNDRV_PCM_RATE_48000
;
418 rates
|= SNDRV_PCM_RATE_64000
;
421 rates
|= SNDRV_PCM_RATE_88200
;
424 rates
|= SNDRV_PCM_RATE_96000
;
427 rates
|= SNDRV_PCM_RATE_176400
;
430 rates
|= SNDRV_PCM_RATE_192000
;
432 default: /* some other rate */
433 rates
|= SNDRV_PCM_RATE_KNOT
;
438 pcmhw
->rates
= rates
;
439 pcmhw
->rate_min
= rate_min
;
440 pcmhw
->rate_max
= rate_max
;
443 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream
*substream
,
444 struct snd_pcm_hw_params
*params
)
446 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
447 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
448 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
452 unsigned int bytes_per_sec
;
454 print_hwparams(params
);
455 err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(params
));
458 err
= snd_card_asihpi_format_alsa2hpi(params_format(params
), &format
);
462 snd_printdd("format %d, %d chans, %d_hz\n",
463 format
, params_channels(params
),
464 params_rate(params
));
466 hpi_handle_error(hpi_format_create(&dpcm
->format
,
467 params_channels(params
),
468 format
, params_rate(params
), 0, 0));
470 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
471 if (hpi_instream_reset(dpcm
->h_stream
) != 0)
474 if (hpi_instream_set_format(
475 dpcm
->h_stream
, &dpcm
->format
) != 0)
479 dpcm
->hpi_buffer_attached
= 0;
480 if (card
->support_mmap
) {
482 err
= hpi_stream_host_buffer_attach(dpcm
->h_stream
,
483 params_buffer_bytes(params
), runtime
->dma_addr
);
486 "stream_host_buffer_attach succeeded %u %lu\n",
487 params_buffer_bytes(params
),
488 (unsigned long)runtime
->dma_addr
);
490 snd_printd("stream_host_buffer_attach error %d\n",
495 err
= hpi_stream_get_info_ex(dpcm
->h_stream
, NULL
,
496 &dpcm
->hpi_buffer_attached
,
499 snd_printdd("stream_host_buffer_attach status 0x%x\n",
500 dpcm
->hpi_buffer_attached
);
502 bytes_per_sec
= params_rate(params
) * params_channels(params
);
503 width
= snd_pcm_format_width(params_format(params
));
504 bytes_per_sec
*= width
;
506 if (width
< 0 || bytes_per_sec
== 0)
509 dpcm
->bytes_per_sec
= bytes_per_sec
;
510 dpcm
->buffer_bytes
= params_buffer_bytes(params
);
511 dpcm
->period_bytes
= params_period_bytes(params
);
512 snd_printdd("buffer_bytes=%d, period_bytes=%d, bps=%d\n",
513 dpcm
->buffer_bytes
, dpcm
->period_bytes
, bytes_per_sec
);
519 snd_card_asihpi_hw_free(struct snd_pcm_substream
*substream
)
521 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
522 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
523 if (dpcm
->hpi_buffer_attached
)
524 hpi_stream_host_buffer_detach(dpcm
->h_stream
);
526 snd_pcm_lib_free_pages(substream
);
530 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime
*runtime
)
532 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
536 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream
*
539 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
540 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
544 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */
545 expiry
= max(expiry
, 1); /* don't let it be zero! */
546 dpcm
->timer
.expires
= jiffies
+ expiry
;
547 dpcm
->respawn_timer
= 1;
548 add_timer(&dpcm
->timer
);
551 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream
*substream
)
553 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
554 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
556 dpcm
->respawn_timer
= 0;
557 del_timer(&dpcm
->timer
);
560 static int snd_card_asihpi_trigger(struct snd_pcm_substream
*substream
,
563 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
564 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
565 struct snd_pcm_substream
*s
;
568 snd_printdd("%c%d trigger\n",
569 SCHR(substream
->stream
), substream
->number
);
571 case SNDRV_PCM_TRIGGER_START
:
572 snd_pcm_group_for_each_entry(s
, substream
) {
573 struct snd_pcm_runtime
*runtime
= s
->runtime
;
574 struct snd_card_asihpi_pcm
*ds
= runtime
->private_data
;
576 if (snd_pcm_substream_chip(s
) != card
)
579 /* don't link Cap and Play */
580 if (substream
->stream
!= s
->stream
)
583 if ((s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) &&
584 (card
->support_mmap
)) {
585 /* How do I know how much valid data is present
586 * in buffer? Must be at least one period!
587 * Guessing 2 periods, but if
588 * buffer is bigger it may contain even more
591 unsigned int preload
= ds
->period_bytes
* 1;
592 snd_printddd("%d preload x%x\n", s
->number
, preload
);
593 hpi_handle_error(hpi_outstream_write_buf(
595 &runtime
->dma_area
[0],
598 ds
->pcm_buf_host_rw_ofs
= preload
;
601 if (card
->support_grouping
) {
602 snd_printdd("\t%c%d group\n",
605 e
= hpi_stream_group_add(
609 snd_pcm_trigger_done(s
, substream
);
617 snd_printdd("start\n");
618 /* start the master stream */
619 snd_card_asihpi_pcm_timer_start(substream
);
620 if ((substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) ||
622 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
625 case SNDRV_PCM_TRIGGER_STOP
:
626 snd_card_asihpi_pcm_timer_stop(substream
);
627 snd_pcm_group_for_each_entry(s
, substream
) {
628 if (snd_pcm_substream_chip(s
) != card
)
630 /* don't link Cap and Play */
631 if (substream
->stream
!= s
->stream
)
634 /*? workaround linked streams don't
635 transition to SETUP 20070706*/
636 s
->runtime
->status
->state
= SNDRV_PCM_STATE_SETUP
;
638 if (card
->support_grouping
) {
639 snd_printdd("\t%c%d group\n",
642 snd_pcm_trigger_done(s
, substream
);
646 snd_printdd("stop\n");
648 /* _prepare and _hwparams reset the stream */
649 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
650 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
652 hpi_outstream_reset(dpcm
->h_stream
));
654 if (card
->support_grouping
)
655 hpi_handle_error(hpi_stream_group_reset(dpcm
->h_stream
));
658 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
659 snd_printdd("pause release\n");
660 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
661 snd_card_asihpi_pcm_timer_start(substream
);
663 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
664 snd_printdd("pause\n");
665 snd_card_asihpi_pcm_timer_stop(substream
);
666 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
669 snd_printd(KERN_ERR
"\tINVALID\n");
677 Without linking degenerates to getting single stream pos etc
678 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
681 pcm_buf_dma_ofs=get_buf_pos(s);
682 for_each_linked_stream(s) {
683 pcm_buf_dma_ofs=get_buf_pos(s);
684 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
685 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
687 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
688 for_each_linked_stream(s) {
689 s->pcm_buf_dma_ofs = min_buf_pos;
690 if (new_data > period_bytes) {
692 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
699 snd_pcm_period_elapsed(s);
704 /** Minimum of 2 modulo values. Works correctly when the difference between
705 * the values is less than half the modulus
707 static inline unsigned int modulo_min(unsigned int a
, unsigned int b
,
708 unsigned long int modulus
)
711 if (((a
-b
) % modulus
) < (modulus
/2))
719 /** Timer function, equivalent to interrupt service routine for cards
721 static void snd_card_asihpi_timer_function(unsigned long data
)
723 struct snd_card_asihpi_pcm
*dpcm
= (struct snd_card_asihpi_pcm
*)data
;
724 struct snd_pcm_substream
*substream
= dpcm
->substream
;
725 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
726 struct snd_pcm_runtime
*runtime
;
727 struct snd_pcm_substream
*s
;
728 unsigned int newdata
= 0;
729 unsigned int pcm_buf_dma_ofs
, min_buf_pos
= 0;
730 unsigned int remdata
, xfercount
, next_jiffies
;
734 u32 buffer_size
, bytes_avail
, samples_played
, on_card_bytes
;
736 snd_printdd("%c%d snd_card_asihpi_timer_function\n",
737 SCHR(substream
->stream
), substream
->number
);
739 /* find minimum newdata and buffer pos in group */
740 snd_pcm_group_for_each_entry(s
, substream
) {
741 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
742 runtime
= s
->runtime
;
744 if (snd_pcm_substream_chip(s
) != card
)
747 /* don't link Cap and Play */
748 if (substream
->stream
!= s
->stream
)
751 hpi_handle_error(hpi_stream_get_info_ex(
752 ds
->h_stream
, &state
,
753 &buffer_size
, &bytes_avail
,
754 &samples_played
, &on_card_bytes
));
756 /* number of bytes in on-card buffer */
757 runtime
->delay
= on_card_bytes
;
759 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
760 pcm_buf_dma_ofs
= ds
->pcm_buf_host_rw_ofs
- bytes_avail
;
761 if (state
== HPI_STATE_STOPPED
) {
762 if ((bytes_avail
== 0) &&
763 (on_card_bytes
< ds
->pcm_buf_host_rw_ofs
)) {
764 hpi_handle_error(hpi_stream_start(ds
->h_stream
));
765 snd_printdd("P%d start\n", s
->number
);
767 } else if (state
== HPI_STATE_DRAINED
) {
768 snd_printd(KERN_WARNING
"P%d drained\n",
770 /*snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
774 pcm_buf_dma_ofs
= bytes_avail
+ ds
->pcm_buf_host_rw_ofs
;
777 /* can't statically init min when wrap is involved */
778 min_buf_pos
= pcm_buf_dma_ofs
;
779 newdata
= (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
;
783 modulo_min(min_buf_pos
, pcm_buf_dma_ofs
, UINT_MAX
+1L);
785 (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
,
789 snd_printdd("hw_ptr x%04lX, appl_ptr x%04lX\n",
790 (unsigned long)frames_to_bytes(runtime
,
791 runtime
->status
->hw_ptr
),
792 (unsigned long)frames_to_bytes(runtime
,
793 runtime
->control
->appl_ptr
));
795 snd_printdd("%d %c%d S=%d, rw=%04X, dma=x%04X, left=x%04X,"
796 " aux=x%04X space=x%04X\n",
797 loops
, SCHR(s
->stream
), s
->number
,
798 state
, ds
->pcm_buf_host_rw_ofs
, pcm_buf_dma_ofs
, (int)bytes_avail
,
799 (int)on_card_bytes
, buffer_size
-bytes_avail
);
802 pcm_buf_dma_ofs
= min_buf_pos
;
804 remdata
= newdata
% dpcm
->period_bytes
;
805 xfercount
= newdata
- remdata
; /* a multiple of period_bytes */
806 /* come back when on_card_bytes has decreased enough to allow
807 write to happen, or when data has been consumed to make another
810 if (xfercount
&& (on_card_bytes
> dpcm
->period_bytes
))
811 next_jiffies
= ((on_card_bytes
- dpcm
->period_bytes
) * HZ
/ dpcm
->bytes_per_sec
);
813 next_jiffies
= ((dpcm
->period_bytes
- remdata
) * HZ
/ dpcm
->bytes_per_sec
);
815 next_jiffies
= max(next_jiffies
, 1U);
816 dpcm
->timer
.expires
= jiffies
+ next_jiffies
;
817 snd_printdd("jif %d buf pos x%04X newdata x%04X xfer x%04X\n",
818 next_jiffies
, pcm_buf_dma_ofs
, newdata
, xfercount
);
820 snd_pcm_group_for_each_entry(s
, substream
) {
821 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
823 /* don't link Cap and Play */
824 if (substream
->stream
!= s
->stream
)
827 ds
->pcm_buf_dma_ofs
= pcm_buf_dma_ofs
;
829 if (xfercount
&& (on_card_bytes
<= ds
->period_bytes
)) {
830 if (card
->support_mmap
) {
831 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
832 snd_printddd("P%d write x%04x\n",
836 hpi_outstream_write_buf(
843 snd_printddd("C%d read x%04x\n",
847 hpi_instream_read_buf(
851 ds
->pcm_buf_host_rw_ofs
= ds
->pcm_buf_host_rw_ofs
+ xfercount
;
852 } /* else R/W will be handled by read/write callbacks */
853 ds
->pcm_buf_elapsed_dma_ofs
= pcm_buf_dma_ofs
;
854 snd_pcm_period_elapsed(s
);
858 if (dpcm
->respawn_timer
)
859 add_timer(&dpcm
->timer
);
862 /***************************** PLAYBACK OPS ****************/
863 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream
*substream
,
864 unsigned int cmd
, void *arg
)
866 snd_printdd(KERN_INFO
"Playback ioctl %d\n", cmd
);
867 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
870 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream
*
873 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
874 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
876 snd_printdd("playback prepare %d\n", substream
->number
);
878 hpi_handle_error(hpi_outstream_reset(dpcm
->h_stream
));
879 dpcm
->pcm_buf_host_rw_ofs
= 0;
880 dpcm
->pcm_buf_dma_ofs
= 0;
881 dpcm
->pcm_buf_elapsed_dma_ofs
= 0;
885 static snd_pcm_uframes_t
886 snd_card_asihpi_playback_pointer(struct snd_pcm_substream
*substream
)
888 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
889 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
890 snd_pcm_uframes_t ptr
;
892 ptr
= bytes_to_frames(runtime
, dpcm
->pcm_buf_dma_ofs
% dpcm
->buffer_bytes
);
893 snd_printddd("playback_pointer=x%04lx\n", (unsigned long)ptr
);
897 static void snd_card_asihpi_playback_format(struct snd_card_asihpi
*asihpi
,
899 struct snd_pcm_hardware
*pcmhw
)
901 struct hpi_format hpi_format
;
905 u32 sample_rate
= 48000;
907 /* on cards without SRC, must query at valid rate,
908 * maybe set by external sync
910 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
911 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
912 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
915 err
= hpi_sample_clock_get_sample_rate(h_control
,
918 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
919 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
920 err
= hpi_format_create(&hpi_format
,
921 2, format
, sample_rate
, 128000, 0);
923 err
= hpi_outstream_query_format(h_stream
,
925 if (!err
&& (hpi_to_alsa_formats
[format
] != -1))
927 (1ULL << hpi_to_alsa_formats
[format
]);
931 static struct snd_pcm_hardware snd_card_asihpi_playback
= {
934 .buffer_bytes_max
= BUFFER_BYTES_MAX
,
935 .period_bytes_min
= PERIOD_BYTES_MIN
,
936 .period_bytes_max
= BUFFER_BYTES_MAX
/ PERIODS_MIN
,
937 .periods_min
= PERIODS_MIN
,
938 .periods_max
= BUFFER_BYTES_MAX
/ PERIOD_BYTES_MIN
,
942 static int snd_card_asihpi_playback_open(struct snd_pcm_substream
*substream
)
944 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
945 struct snd_card_asihpi_pcm
*dpcm
;
946 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
949 dpcm
= kzalloc(sizeof(*dpcm
), GFP_KERNEL
);
954 hpi_outstream_open(card
->adapter_index
,
955 substream
->number
, &dpcm
->h_stream
);
956 hpi_handle_error(err
);
959 if (err
== HPI_ERROR_OBJ_ALREADY_OPEN
)
964 /*? also check ASI5000 samplerate source
965 If external, only support external rate.
966 If internal and other stream playing, cant switch
969 init_timer(&dpcm
->timer
);
970 dpcm
->timer
.data
= (unsigned long) dpcm
;
971 dpcm
->timer
.function
= snd_card_asihpi_timer_function
;
972 dpcm
->substream
= substream
;
973 runtime
->private_data
= dpcm
;
974 runtime
->private_free
= snd_card_asihpi_runtime_free
;
976 snd_card_asihpi_playback
.channels_max
= card
->out_max_chans
;
977 /*?snd_card_asihpi_playback.period_bytes_min =
978 card->out_max_chans * 4096; */
980 snd_card_asihpi_playback_format(card
, dpcm
->h_stream
,
981 &snd_card_asihpi_playback
);
983 snd_card_asihpi_pcm_samplerates(card
, &snd_card_asihpi_playback
);
985 snd_card_asihpi_playback
.info
= SNDRV_PCM_INFO_INTERLEAVED
|
986 SNDRV_PCM_INFO_DOUBLE
|
987 SNDRV_PCM_INFO_BATCH
|
988 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
989 SNDRV_PCM_INFO_PAUSE
;
991 if (card
->support_mmap
)
992 snd_card_asihpi_playback
.info
|= SNDRV_PCM_INFO_MMAP
|
993 SNDRV_PCM_INFO_MMAP_VALID
;
995 if (card
->support_grouping
)
996 snd_card_asihpi_playback
.info
|= SNDRV_PCM_INFO_SYNC_START
;
998 /* struct is copied, so can create initializer dynamically */
999 runtime
->hw
= snd_card_asihpi_playback
;
1001 if (card
->support_mmap
)
1002 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1003 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1007 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1008 card
->update_interval_frames
);
1010 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1011 card
->update_interval_frames
* 2, UINT_MAX
);
1013 snd_pcm_set_sync(substream
);
1015 snd_printdd("playback open\n");
1020 static int snd_card_asihpi_playback_close(struct snd_pcm_substream
*substream
)
1022 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1023 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1025 hpi_handle_error(hpi_outstream_close(dpcm
->h_stream
));
1026 snd_printdd("playback close\n");
1031 static int snd_card_asihpi_playback_copy(struct snd_pcm_substream
*substream
,
1033 snd_pcm_uframes_t pos
,
1035 snd_pcm_uframes_t count
)
1037 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1038 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1041 len
= frames_to_bytes(runtime
, count
);
1043 if (copy_from_user(runtime
->dma_area
, src
, len
))
1046 snd_printddd("playback copy%d %u bytes\n",
1047 substream
->number
, len
);
1049 hpi_handle_error(hpi_outstream_write_buf(dpcm
->h_stream
,
1050 runtime
->dma_area
, len
, &dpcm
->format
));
1052 dpcm
->pcm_buf_host_rw_ofs
+= len
;
1057 static int snd_card_asihpi_playback_silence(struct snd_pcm_substream
*
1058 substream
, int channel
,
1059 snd_pcm_uframes_t pos
,
1060 snd_pcm_uframes_t count
)
1062 /* Usually writes silence to DMA buffer, which should be overwritten
1063 by real audio later. Our fifos cannot be overwritten, and are not
1064 free-running DMAs. Silence is output on fifo underflow.
1065 This callback is still required to allow the copy callback to be used.
1070 static struct snd_pcm_ops snd_card_asihpi_playback_ops
= {
1071 .open
= snd_card_asihpi_playback_open
,
1072 .close
= snd_card_asihpi_playback_close
,
1073 .ioctl
= snd_card_asihpi_playback_ioctl
,
1074 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1075 .hw_free
= snd_card_asihpi_hw_free
,
1076 .prepare
= snd_card_asihpi_playback_prepare
,
1077 .trigger
= snd_card_asihpi_trigger
,
1078 .pointer
= snd_card_asihpi_playback_pointer
,
1079 .copy
= snd_card_asihpi_playback_copy
,
1080 .silence
= snd_card_asihpi_playback_silence
,
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
;
1216 if (card
->support_mmap
)
1217 snd_card_asihpi_capture
.info
|= SNDRV_PCM_INFO_MMAP
|
1218 SNDRV_PCM_INFO_MMAP_VALID
;
1220 if (card
->support_grouping
)
1221 snd_card_asihpi_capture
.info
|= SNDRV_PCM_INFO_SYNC_START
;
1223 runtime
->hw
= snd_card_asihpi_capture
;
1225 if (card
->support_mmap
)
1226 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1227 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1231 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1232 card
->update_interval_frames
);
1233 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1234 card
->update_interval_frames
* 2, UINT_MAX
);
1236 snd_pcm_set_sync(substream
);
1241 static int snd_card_asihpi_capture_close(struct snd_pcm_substream
*substream
)
1243 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
1245 hpi_handle_error(hpi_instream_close(dpcm
->h_stream
));
1249 static int snd_card_asihpi_capture_copy(struct snd_pcm_substream
*substream
,
1250 int channel
, snd_pcm_uframes_t pos
,
1251 void __user
*dst
, snd_pcm_uframes_t count
)
1253 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1254 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1257 len
= frames_to_bytes(runtime
, count
);
1259 snd_printddd("capture copy%d %d bytes\n", substream
->number
, len
);
1260 hpi_handle_error(hpi_instream_read_buf(dpcm
->h_stream
,
1261 runtime
->dma_area
, len
));
1263 dpcm
->pcm_buf_host_rw_ofs
= dpcm
->pcm_buf_host_rw_ofs
+ len
;
1265 if (copy_to_user(dst
, runtime
->dma_area
, len
))
1271 static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops
= {
1272 .open
= snd_card_asihpi_capture_open
,
1273 .close
= snd_card_asihpi_capture_close
,
1274 .ioctl
= snd_card_asihpi_capture_ioctl
,
1275 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1276 .hw_free
= snd_card_asihpi_hw_free
,
1277 .prepare
= snd_card_asihpi_capture_prepare
,
1278 .trigger
= snd_card_asihpi_trigger
,
1279 .pointer
= snd_card_asihpi_capture_pointer
,
1282 static struct snd_pcm_ops snd_card_asihpi_capture_ops
= {
1283 .open
= snd_card_asihpi_capture_open
,
1284 .close
= snd_card_asihpi_capture_close
,
1285 .ioctl
= snd_card_asihpi_capture_ioctl
,
1286 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1287 .hw_free
= snd_card_asihpi_hw_free
,
1288 .prepare
= snd_card_asihpi_capture_prepare
,
1289 .trigger
= snd_card_asihpi_trigger
,
1290 .pointer
= snd_card_asihpi_capture_pointer
,
1291 .copy
= snd_card_asihpi_capture_copy
1294 static int __devinit
snd_card_asihpi_pcm_new(struct snd_card_asihpi
*asihpi
,
1295 int device
, int substreams
)
1297 struct snd_pcm
*pcm
;
1300 err
= snd_pcm_new(asihpi
->card
, "Asihpi PCM", device
,
1301 asihpi
->num_outstreams
, asihpi
->num_instreams
,
1305 /* pointer to ops struct is stored, dont change ops afterwards! */
1306 if (asihpi
->support_mmap
) {
1307 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1308 &snd_card_asihpi_playback_mmap_ops
);
1309 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1310 &snd_card_asihpi_capture_mmap_ops
);
1312 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1313 &snd_card_asihpi_playback_ops
);
1314 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1315 &snd_card_asihpi_capture_ops
);
1318 pcm
->private_data
= asihpi
;
1319 pcm
->info_flags
= 0;
1320 strcpy(pcm
->name
, "Asihpi PCM");
1322 /*? do we want to emulate MMAP for non-BBM cards?
1323 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1324 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1325 snd_dma_pci_data(asihpi
->pci
),
1326 64*1024, BUFFER_BYTES_MAX
);
1331 /***************************** MIXER CONTROLS ****************/
1332 struct hpi_control
{
1340 char name
[44]; /* copied to snd_ctl_elem_id.name[44]; */
1343 static const char * const asihpi_tuner_band_names
[] = {
1356 compile_time_assert(
1357 (ARRAY_SIZE(asihpi_tuner_band_names
) ==
1358 (HPI_TUNER_BAND_LAST
+1)),
1359 assert_tuner_band_names_size
);
1361 static const char * const asihpi_src_names
[] = {
1376 compile_time_assert(
1377 (ARRAY_SIZE(asihpi_src_names
) ==
1378 (HPI_SOURCENODE_LAST_INDEX
-HPI_SOURCENODE_NONE
+1)),
1379 assert_src_names_size
);
1381 static const char * const asihpi_dst_names
[] = {
1392 compile_time_assert(
1393 (ARRAY_SIZE(asihpi_dst_names
) ==
1394 (HPI_DESTNODE_LAST_INDEX
-HPI_DESTNODE_NONE
+1)),
1395 assert_dst_names_size
);
1397 static inline int ctl_add(struct snd_card
*card
, struct snd_kcontrol_new
*ctl
,
1398 struct snd_card_asihpi
*asihpi
)
1402 err
= snd_ctl_add(card
, snd_ctl_new1(ctl
, asihpi
));
1405 else if (mixer_dump
)
1406 snd_printk(KERN_INFO
"added %s(%d)\n", ctl
->name
, ctl
->index
);
1411 /* Convert HPI control name and location into ALSA control name */
1412 static void asihpi_ctl_init(struct snd_kcontrol_new
*snd_control
,
1413 struct hpi_control
*hpi_ctl
,
1417 memset(snd_control
, 0, sizeof(*snd_control
));
1418 snd_control
->name
= hpi_ctl
->name
;
1419 snd_control
->private_value
= hpi_ctl
->h_control
;
1420 snd_control
->iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1421 snd_control
->index
= 0;
1423 if (hpi_ctl
->dst_node_type
+ HPI_DESTNODE_NONE
== HPI_DESTNODE_ISTREAM
)
1424 dir
= "Capture "; /* On or towards a PCM capture destination*/
1425 else if ((hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1426 (!hpi_ctl
->dst_node_type
))
1427 dir
= "Capture "; /* On a source node that is not PCM playback */
1428 else if (hpi_ctl
->src_node_type
&&
1429 (hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1430 (hpi_ctl
->dst_node_type
))
1431 dir
= "Monitor Playback "; /* Between an input and an output */
1433 dir
= "Playback "; /* PCM Playback source, or output node */
1435 if (hpi_ctl
->src_node_type
&& hpi_ctl
->dst_node_type
)
1436 sprintf(hpi_ctl
->name
, "%s%d %s%d %s%s",
1437 asihpi_src_names
[hpi_ctl
->src_node_type
],
1438 hpi_ctl
->src_node_index
,
1439 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1440 hpi_ctl
->dst_node_index
,
1442 else if (hpi_ctl
->dst_node_type
) {
1443 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1444 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1445 hpi_ctl
->dst_node_index
,
1448 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1449 asihpi_src_names
[hpi_ctl
->src_node_type
],
1450 hpi_ctl
->src_node_index
,
1453 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1454 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1457 /*------------------------------------------------------------
1459 ------------------------------------------------------------*/
1460 #define VOL_STEP_mB 1
1461 static int snd_asihpi_volume_info(struct snd_kcontrol
*kcontrol
,
1462 struct snd_ctl_elem_info
*uinfo
)
1464 u32 h_control
= kcontrol
->private_value
;
1466 /* native gains are in millibels */
1471 err
= hpi_volume_query_range(h_control
,
1472 &min_gain_mB
, &max_gain_mB
, &step_gain_mB
);
1475 min_gain_mB
= -10000;
1476 step_gain_mB
= VOL_STEP_mB
;
1479 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1481 uinfo
->value
.integer
.min
= min_gain_mB
/ VOL_STEP_mB
;
1482 uinfo
->value
.integer
.max
= max_gain_mB
/ VOL_STEP_mB
;
1483 uinfo
->value
.integer
.step
= step_gain_mB
/ VOL_STEP_mB
;
1487 static int snd_asihpi_volume_get(struct snd_kcontrol
*kcontrol
,
1488 struct snd_ctl_elem_value
*ucontrol
)
1490 u32 h_control
= kcontrol
->private_value
;
1491 short an_gain_mB
[HPI_MAX_CHANNELS
];
1493 hpi_handle_error(hpi_volume_get_gain(h_control
, an_gain_mB
));
1494 ucontrol
->value
.integer
.value
[0] = an_gain_mB
[0] / VOL_STEP_mB
;
1495 ucontrol
->value
.integer
.value
[1] = an_gain_mB
[1] / VOL_STEP_mB
;
1500 static int snd_asihpi_volume_put(struct snd_kcontrol
*kcontrol
,
1501 struct snd_ctl_elem_value
*ucontrol
)
1504 u32 h_control
= kcontrol
->private_value
;
1505 short an_gain_mB
[HPI_MAX_CHANNELS
];
1508 (ucontrol
->value
.integer
.value
[0]) * VOL_STEP_mB
;
1510 (ucontrol
->value
.integer
.value
[1]) * VOL_STEP_mB
;
1511 /* change = asihpi->mixer_volume[addr][0] != left ||
1512 asihpi->mixer_volume[addr][1] != right;
1515 hpi_handle_error(hpi_volume_set_gain(h_control
, an_gain_mB
));
1519 static const DECLARE_TLV_DB_SCALE(db_scale_100
, -10000, VOL_STEP_mB
, 0);
1521 static int __devinit
snd_asihpi_volume_add(struct snd_card_asihpi
*asihpi
,
1522 struct hpi_control
*hpi_ctl
)
1524 struct snd_card
*card
= asihpi
->card
;
1525 struct snd_kcontrol_new snd_control
;
1527 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Volume");
1528 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1529 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1530 snd_control
.info
= snd_asihpi_volume_info
;
1531 snd_control
.get
= snd_asihpi_volume_get
;
1532 snd_control
.put
= snd_asihpi_volume_put
;
1533 snd_control
.tlv
.p
= db_scale_100
;
1535 return ctl_add(card
, &snd_control
, asihpi
);
1538 /*------------------------------------------------------------
1540 ------------------------------------------------------------*/
1541 static int snd_asihpi_level_info(struct snd_kcontrol
*kcontrol
,
1542 struct snd_ctl_elem_info
*uinfo
)
1544 u32 h_control
= kcontrol
->private_value
;
1551 hpi_level_query_range(h_control
, &min_gain_mB
,
1552 &max_gain_mB
, &step_gain_mB
);
1555 min_gain_mB
= -1000;
1559 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1561 uinfo
->value
.integer
.min
= min_gain_mB
/ HPI_UNITS_PER_dB
;
1562 uinfo
->value
.integer
.max
= max_gain_mB
/ HPI_UNITS_PER_dB
;
1563 uinfo
->value
.integer
.step
= step_gain_mB
/ HPI_UNITS_PER_dB
;
1567 static int snd_asihpi_level_get(struct snd_kcontrol
*kcontrol
,
1568 struct snd_ctl_elem_value
*ucontrol
)
1570 u32 h_control
= kcontrol
->private_value
;
1571 short an_gain_mB
[HPI_MAX_CHANNELS
];
1573 hpi_handle_error(hpi_level_get_gain(h_control
, an_gain_mB
));
1574 ucontrol
->value
.integer
.value
[0] =
1575 an_gain_mB
[0] / HPI_UNITS_PER_dB
;
1576 ucontrol
->value
.integer
.value
[1] =
1577 an_gain_mB
[1] / HPI_UNITS_PER_dB
;
1582 static int snd_asihpi_level_put(struct snd_kcontrol
*kcontrol
,
1583 struct snd_ctl_elem_value
*ucontrol
)
1586 u32 h_control
= kcontrol
->private_value
;
1587 short an_gain_mB
[HPI_MAX_CHANNELS
];
1590 (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1592 (ucontrol
->value
.integer
.value
[1]) * HPI_UNITS_PER_dB
;
1593 /* change = asihpi->mixer_level[addr][0] != left ||
1594 asihpi->mixer_level[addr][1] != right;
1597 hpi_handle_error(hpi_level_set_gain(h_control
, an_gain_mB
));
1601 static const DECLARE_TLV_DB_SCALE(db_scale_level
, -1000, 100, 0);
1603 static int __devinit
snd_asihpi_level_add(struct snd_card_asihpi
*asihpi
,
1604 struct hpi_control
*hpi_ctl
)
1606 struct snd_card
*card
= asihpi
->card
;
1607 struct snd_kcontrol_new snd_control
;
1609 /* can't use 'volume' cos some nodes have volume as well */
1610 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Level");
1611 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1612 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1613 snd_control
.info
= snd_asihpi_level_info
;
1614 snd_control
.get
= snd_asihpi_level_get
;
1615 snd_control
.put
= snd_asihpi_level_put
;
1616 snd_control
.tlv
.p
= db_scale_level
;
1618 return ctl_add(card
, &snd_control
, asihpi
);
1621 /*------------------------------------------------------------
1623 ------------------------------------------------------------*/
1626 static const char * const asihpi_aesebu_format_names
[] = {
1627 "N/A", "S/PDIF", "AES/EBU" };
1629 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol
*kcontrol
,
1630 struct snd_ctl_elem_info
*uinfo
)
1632 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1634 uinfo
->value
.enumerated
.items
= 3;
1636 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1637 uinfo
->value
.enumerated
.item
=
1638 uinfo
->value
.enumerated
.items
- 1;
1640 strcpy(uinfo
->value
.enumerated
.name
,
1641 asihpi_aesebu_format_names
[uinfo
->value
.enumerated
.item
]);
1646 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol
*kcontrol
,
1647 struct snd_ctl_elem_value
*ucontrol
,
1648 u16 (*func
)(u32
, u16
*))
1650 u32 h_control
= kcontrol
->private_value
;
1653 err
= func(h_control
, &source
);
1655 /* default to N/A */
1656 ucontrol
->value
.enumerated
.item
[0] = 0;
1657 /* return success but set the control to N/A */
1660 if (source
== HPI_AESEBU_FORMAT_SPDIF
)
1661 ucontrol
->value
.enumerated
.item
[0] = 1;
1662 if (source
== HPI_AESEBU_FORMAT_AESEBU
)
1663 ucontrol
->value
.enumerated
.item
[0] = 2;
1668 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol
*kcontrol
,
1669 struct snd_ctl_elem_value
*ucontrol
,
1670 u16 (*func
)(u32
, u16
))
1672 u32 h_control
= kcontrol
->private_value
;
1674 /* default to S/PDIF */
1675 u16 source
= HPI_AESEBU_FORMAT_SPDIF
;
1677 if (ucontrol
->value
.enumerated
.item
[0] == 1)
1678 source
= HPI_AESEBU_FORMAT_SPDIF
;
1679 if (ucontrol
->value
.enumerated
.item
[0] == 2)
1680 source
= HPI_AESEBU_FORMAT_AESEBU
;
1682 if (func(h_control
, source
) != 0)
1688 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol
*kcontrol
,
1689 struct snd_ctl_elem_value
*ucontrol
) {
1690 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1691 hpi_aesebu_receiver_get_format
);
1694 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol
*kcontrol
,
1695 struct snd_ctl_elem_value
*ucontrol
) {
1696 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1697 hpi_aesebu_receiver_set_format
);
1700 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol
*kcontrol
,
1701 struct snd_ctl_elem_info
*uinfo
)
1703 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1706 uinfo
->value
.integer
.min
= 0;
1707 uinfo
->value
.integer
.max
= 0X1F;
1708 uinfo
->value
.integer
.step
= 1;
1713 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol
*kcontrol
,
1714 struct snd_ctl_elem_value
*ucontrol
) {
1716 u32 h_control
= kcontrol
->private_value
;
1719 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1720 h_control
, &status
));
1721 ucontrol
->value
.integer
.value
[0] = status
;
1725 static int __devinit
snd_asihpi_aesebu_rx_add(struct snd_card_asihpi
*asihpi
,
1726 struct hpi_control
*hpi_ctl
)
1728 struct snd_card
*card
= asihpi
->card
;
1729 struct snd_kcontrol_new snd_control
;
1731 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1732 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1733 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1734 snd_control
.get
= snd_asihpi_aesebu_rx_format_get
;
1735 snd_control
.put
= snd_asihpi_aesebu_rx_format_put
;
1738 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
1741 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Status");
1742 snd_control
.access
=
1743 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
1744 snd_control
.info
= snd_asihpi_aesebu_rxstatus_info
;
1745 snd_control
.get
= snd_asihpi_aesebu_rxstatus_get
;
1747 return ctl_add(card
, &snd_control
, asihpi
);
1750 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol
*kcontrol
,
1751 struct snd_ctl_elem_value
*ucontrol
) {
1752 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1753 hpi_aesebu_transmitter_get_format
);
1756 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol
*kcontrol
,
1757 struct snd_ctl_elem_value
*ucontrol
) {
1758 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1759 hpi_aesebu_transmitter_set_format
);
1763 static int __devinit
snd_asihpi_aesebu_tx_add(struct snd_card_asihpi
*asihpi
,
1764 struct hpi_control
*hpi_ctl
)
1766 struct snd_card
*card
= asihpi
->card
;
1767 struct snd_kcontrol_new snd_control
;
1769 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1770 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1771 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1772 snd_control
.get
= snd_asihpi_aesebu_tx_format_get
;
1773 snd_control
.put
= snd_asihpi_aesebu_tx_format_put
;
1775 return ctl_add(card
, &snd_control
, asihpi
);
1778 /*------------------------------------------------------------
1780 ------------------------------------------------------------*/
1784 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol
*kcontrol
,
1785 struct snd_ctl_elem_info
*uinfo
)
1787 u32 h_control
= kcontrol
->private_value
;
1792 for (idx
= 0; idx
< 3; idx
++) {
1793 err
= hpi_tuner_query_gain(h_control
,
1794 idx
, &gain_range
[idx
]);
1799 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1801 uinfo
->value
.integer
.min
= ((int)gain_range
[0]) / HPI_UNITS_PER_dB
;
1802 uinfo
->value
.integer
.max
= ((int)gain_range
[1]) / HPI_UNITS_PER_dB
;
1803 uinfo
->value
.integer
.step
= ((int) gain_range
[2]) / HPI_UNITS_PER_dB
;
1807 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol
*kcontrol
,
1808 struct snd_ctl_elem_value
*ucontrol
)
1811 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1813 u32 h_control
= kcontrol
->private_value
;
1816 hpi_handle_error(hpi_tuner_get_gain(h_control
, &gain
));
1817 ucontrol
->value
.integer
.value
[0] = gain
/ HPI_UNITS_PER_dB
;
1822 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol
*kcontrol
,
1823 struct snd_ctl_elem_value
*ucontrol
)
1826 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1828 u32 h_control
= kcontrol
->private_value
;
1831 gain
= (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1832 hpi_handle_error(hpi_tuner_set_gain(h_control
, gain
));
1839 static int asihpi_tuner_band_query(struct snd_kcontrol
*kcontrol
,
1840 u16
*band_list
, u32 len
) {
1841 u32 h_control
= kcontrol
->private_value
;
1845 for (i
= 0; i
< len
; i
++) {
1846 err
= hpi_tuner_query_band(
1847 h_control
, i
, &band_list
[i
]);
1852 if (err
&& (err
!= HPI_ERROR_INVALID_OBJ_INDEX
))
1858 static int snd_asihpi_tuner_band_info(struct snd_kcontrol
*kcontrol
,
1859 struct snd_ctl_elem_info
*uinfo
)
1861 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1864 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1865 HPI_TUNER_BAND_LAST
);
1870 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1872 uinfo
->value
.enumerated
.items
= num_bands
;
1874 if (num_bands
> 0) {
1875 if (uinfo
->value
.enumerated
.item
>=
1876 uinfo
->value
.enumerated
.items
)
1877 uinfo
->value
.enumerated
.item
=
1878 uinfo
->value
.enumerated
.items
- 1;
1880 strcpy(uinfo
->value
.enumerated
.name
,
1881 asihpi_tuner_band_names
[
1882 tuner_bands
[uinfo
->value
.enumerated
.item
]]);
1888 static int snd_asihpi_tuner_band_get(struct snd_kcontrol
*kcontrol
,
1889 struct snd_ctl_elem_value
*ucontrol
)
1891 u32 h_control
= kcontrol
->private_value
;
1893 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1896 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1899 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1900 HPI_TUNER_BAND_LAST
);
1902 hpi_handle_error(hpi_tuner_get_band(h_control
, &band
));
1904 ucontrol
->value
.enumerated
.item
[0] = -1;
1905 for (idx
= 0; idx
< HPI_TUNER_BAND_LAST
; idx
++)
1906 if (tuner_bands
[idx
] == band
) {
1907 ucontrol
->value
.enumerated
.item
[0] = idx
;
1914 static int snd_asihpi_tuner_band_put(struct snd_kcontrol
*kcontrol
,
1915 struct snd_ctl_elem_value
*ucontrol
)
1918 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1920 u32 h_control
= kcontrol
->private_value
;
1922 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1925 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1926 HPI_TUNER_BAND_LAST
);
1928 band
= tuner_bands
[ucontrol
->value
.enumerated
.item
[0]];
1929 hpi_handle_error(hpi_tuner_set_band(h_control
, band
));
1936 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol
*kcontrol
,
1937 struct snd_ctl_elem_info
*uinfo
)
1939 u32 h_control
= kcontrol
->private_value
;
1941 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1942 u16 num_bands
= 0, band_iter
, idx
;
1943 u32 freq_range
[3], temp_freq_range
[3];
1945 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1946 HPI_TUNER_BAND_LAST
);
1948 freq_range
[0] = INT_MAX
;
1950 freq_range
[2] = INT_MAX
;
1952 for (band_iter
= 0; band_iter
< num_bands
; band_iter
++) {
1953 for (idx
= 0; idx
< 3; idx
++) {
1954 err
= hpi_tuner_query_frequency(h_control
,
1955 idx
, tuner_bands
[band_iter
],
1956 &temp_freq_range
[idx
]);
1961 /* skip band with bogus stepping */
1962 if (temp_freq_range
[2] <= 0)
1965 if (temp_freq_range
[0] < freq_range
[0])
1966 freq_range
[0] = temp_freq_range
[0];
1967 if (temp_freq_range
[1] > freq_range
[1])
1968 freq_range
[1] = temp_freq_range
[1];
1969 if (temp_freq_range
[2] < freq_range
[2])
1970 freq_range
[2] = temp_freq_range
[2];
1973 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1975 uinfo
->value
.integer
.min
= ((int)freq_range
[0]);
1976 uinfo
->value
.integer
.max
= ((int)freq_range
[1]);
1977 uinfo
->value
.integer
.step
= ((int)freq_range
[2]);
1981 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol
*kcontrol
,
1982 struct snd_ctl_elem_value
*ucontrol
)
1984 u32 h_control
= kcontrol
->private_value
;
1987 hpi_handle_error(hpi_tuner_get_frequency(h_control
, &freq
));
1988 ucontrol
->value
.integer
.value
[0] = freq
;
1993 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol
*kcontrol
,
1994 struct snd_ctl_elem_value
*ucontrol
)
1996 u32 h_control
= kcontrol
->private_value
;
1999 freq
= ucontrol
->value
.integer
.value
[0];
2000 hpi_handle_error(hpi_tuner_set_frequency(h_control
, freq
));
2005 /* Tuner control group initializer */
2006 static int __devinit
snd_asihpi_tuner_add(struct snd_card_asihpi
*asihpi
,
2007 struct hpi_control
*hpi_ctl
)
2009 struct snd_card
*card
= asihpi
->card
;
2010 struct snd_kcontrol_new snd_control
;
2012 snd_control
.private_value
= hpi_ctl
->h_control
;
2013 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2015 if (!hpi_tuner_get_gain(hpi_ctl
->h_control
, NULL
)) {
2016 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Gain");
2017 snd_control
.info
= snd_asihpi_tuner_gain_info
;
2018 snd_control
.get
= snd_asihpi_tuner_gain_get
;
2019 snd_control
.put
= snd_asihpi_tuner_gain_put
;
2021 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2025 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Band");
2026 snd_control
.info
= snd_asihpi_tuner_band_info
;
2027 snd_control
.get
= snd_asihpi_tuner_band_get
;
2028 snd_control
.put
= snd_asihpi_tuner_band_put
;
2030 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2033 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Freq");
2034 snd_control
.info
= snd_asihpi_tuner_freq_info
;
2035 snd_control
.get
= snd_asihpi_tuner_freq_get
;
2036 snd_control
.put
= snd_asihpi_tuner_freq_put
;
2038 return ctl_add(card
, &snd_control
, asihpi
);
2041 /*------------------------------------------------------------
2043 ------------------------------------------------------------*/
2044 static int snd_asihpi_meter_info(struct snd_kcontrol
*kcontrol
,
2045 struct snd_ctl_elem_info
*uinfo
)
2047 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2048 uinfo
->count
= HPI_MAX_CHANNELS
;
2049 uinfo
->value
.integer
.min
= 0;
2050 uinfo
->value
.integer
.max
= 0x7FFFFFFF;
2054 /* linear values for 10dB steps */
2055 static int log2lin
[] = {
2056 0x7FFFFFFF, /* 0dB */
2062 2147484, /* -60dB */
2077 static int snd_asihpi_meter_get(struct snd_kcontrol
*kcontrol
,
2078 struct snd_ctl_elem_value
*ucontrol
)
2080 u32 h_control
= kcontrol
->private_value
;
2081 short an_gain_mB
[HPI_MAX_CHANNELS
], i
;
2084 err
= hpi_meter_get_peak(h_control
, an_gain_mB
);
2086 for (i
= 0; i
< HPI_MAX_CHANNELS
; i
++) {
2088 ucontrol
->value
.integer
.value
[i
] = 0;
2089 } else if (an_gain_mB
[i
] >= 0) {
2090 ucontrol
->value
.integer
.value
[i
] =
2091 an_gain_mB
[i
] << 16;
2093 /* -ve is log value in millibels < -60dB,
2094 * convert to (roughly!) linear,
2096 ucontrol
->value
.integer
.value
[i
] =
2097 log2lin
[an_gain_mB
[i
] / -1000];
2103 static int __devinit
snd_asihpi_meter_add(struct snd_card_asihpi
*asihpi
,
2104 struct hpi_control
*hpi_ctl
, int subidx
)
2106 struct snd_card
*card
= asihpi
->card
;
2107 struct snd_kcontrol_new snd_control
;
2109 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Meter");
2110 snd_control
.access
=
2111 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2112 snd_control
.info
= snd_asihpi_meter_info
;
2113 snd_control
.get
= snd_asihpi_meter_get
;
2115 snd_control
.index
= subidx
;
2117 return ctl_add(card
, &snd_control
, asihpi
);
2120 /*------------------------------------------------------------
2121 Multiplexer controls
2122 ------------------------------------------------------------*/
2123 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol
*snd_control
)
2125 u32 h_control
= snd_control
->private_value
;
2126 struct hpi_control hpi_ctl
;
2128 for (s
= 0; s
< 32; s
++) {
2129 err
= hpi_multiplexer_query_source(h_control
, s
,
2140 static int snd_asihpi_mux_info(struct snd_kcontrol
*kcontrol
,
2141 struct snd_ctl_elem_info
*uinfo
)
2144 u16 src_node_type
, src_node_index
;
2145 u32 h_control
= kcontrol
->private_value
;
2147 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2149 uinfo
->value
.enumerated
.items
=
2150 snd_card_asihpi_mux_count_sources(kcontrol
);
2152 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2153 uinfo
->value
.enumerated
.item
=
2154 uinfo
->value
.enumerated
.items
- 1;
2157 hpi_multiplexer_query_source(h_control
,
2158 uinfo
->value
.enumerated
.item
,
2159 &src_node_type
, &src_node_index
);
2161 sprintf(uinfo
->value
.enumerated
.name
, "%s %d",
2162 asihpi_src_names
[src_node_type
- HPI_SOURCENODE_NONE
],
2167 static int snd_asihpi_mux_get(struct snd_kcontrol
*kcontrol
,
2168 struct snd_ctl_elem_value
*ucontrol
)
2170 u32 h_control
= kcontrol
->private_value
;
2171 u16 source_type
, source_index
;
2172 u16 src_node_type
, src_node_index
;
2175 hpi_handle_error(hpi_multiplexer_get_source(h_control
,
2176 &source_type
, &source_index
));
2177 /* Should cache this search result! */
2178 for (s
= 0; s
< 256; s
++) {
2179 if (hpi_multiplexer_query_source(h_control
, s
,
2180 &src_node_type
, &src_node_index
))
2183 if ((source_type
== src_node_type
)
2184 && (source_index
== src_node_index
)) {
2185 ucontrol
->value
.enumerated
.item
[0] = s
;
2189 snd_printd(KERN_WARNING
2190 "Control %x failed to match mux source %hu %hu\n",
2191 h_control
, source_type
, source_index
);
2192 ucontrol
->value
.enumerated
.item
[0] = 0;
2196 static int snd_asihpi_mux_put(struct snd_kcontrol
*kcontrol
,
2197 struct snd_ctl_elem_value
*ucontrol
)
2200 u32 h_control
= kcontrol
->private_value
;
2201 u16 source_type
, source_index
;
2206 e
= hpi_multiplexer_query_source(h_control
,
2207 ucontrol
->value
.enumerated
.item
[0],
2208 &source_type
, &source_index
);
2211 hpi_multiplexer_set_source(h_control
,
2212 source_type
, source_index
));
2217 static int __devinit
snd_asihpi_mux_add(struct snd_card_asihpi
*asihpi
,
2218 struct hpi_control
*hpi_ctl
)
2220 struct snd_card
*card
= asihpi
->card
;
2221 struct snd_kcontrol_new snd_control
;
2223 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Route");
2224 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2225 snd_control
.info
= snd_asihpi_mux_info
;
2226 snd_control
.get
= snd_asihpi_mux_get
;
2227 snd_control
.put
= snd_asihpi_mux_put
;
2229 return ctl_add(card
, &snd_control
, asihpi
);
2233 /*------------------------------------------------------------
2234 Channel mode controls
2235 ------------------------------------------------------------*/
2236 static int snd_asihpi_cmode_info(struct snd_kcontrol
*kcontrol
,
2237 struct snd_ctl_elem_info
*uinfo
)
2239 static const char * const mode_names
[HPI_CHANNEL_MODE_LAST
+ 1] = {
2242 "From Left", "From Right",
2243 "To Left", "To Right"
2246 u32 h_control
= kcontrol
->private_value
;
2250 int valid_modes
= 0;
2252 /* HPI channel mode values can be from 1 to 6
2253 Some adapters only support a contiguous subset
2255 for (i
= 0; i
< HPI_CHANNEL_MODE_LAST
; i
++)
2256 if (!hpi_channel_mode_query_mode(
2257 h_control
, i
, &mode
)) {
2258 mode_map
[valid_modes
] = mode
;
2262 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2264 uinfo
->value
.enumerated
.items
= valid_modes
;
2266 if (uinfo
->value
.enumerated
.item
>= valid_modes
)
2267 uinfo
->value
.enumerated
.item
= valid_modes
- 1;
2269 strcpy(uinfo
->value
.enumerated
.name
,
2270 mode_names
[mode_map
[uinfo
->value
.enumerated
.item
]]);
2275 static int snd_asihpi_cmode_get(struct snd_kcontrol
*kcontrol
,
2276 struct snd_ctl_elem_value
*ucontrol
)
2278 u32 h_control
= kcontrol
->private_value
;
2281 if (hpi_channel_mode_get(h_control
, &mode
))
2284 ucontrol
->value
.enumerated
.item
[0] = mode
- 1;
2289 static int snd_asihpi_cmode_put(struct snd_kcontrol
*kcontrol
,
2290 struct snd_ctl_elem_value
*ucontrol
)
2293 u32 h_control
= kcontrol
->private_value
;
2297 hpi_handle_error(hpi_channel_mode_set(h_control
,
2298 ucontrol
->value
.enumerated
.item
[0] + 1));
2303 static int __devinit
snd_asihpi_cmode_add(struct snd_card_asihpi
*asihpi
,
2304 struct hpi_control
*hpi_ctl
)
2306 struct snd_card
*card
= asihpi
->card
;
2307 struct snd_kcontrol_new snd_control
;
2309 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Mode");
2310 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2311 snd_control
.info
= snd_asihpi_cmode_info
;
2312 snd_control
.get
= snd_asihpi_cmode_get
;
2313 snd_control
.put
= snd_asihpi_cmode_put
;
2315 return ctl_add(card
, &snd_control
, asihpi
);
2318 /*------------------------------------------------------------
2319 Sampleclock source controls
2320 ------------------------------------------------------------*/
2321 static char *sampleclock_sources
[MAX_CLOCKSOURCES
] = {
2322 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2323 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2325 "Digital2", "Digital3", "Digital4", "Digital5",
2326 "Digital6", "Digital7", "Digital8"};
2328 static int snd_asihpi_clksrc_info(struct snd_kcontrol
*kcontrol
,
2329 struct snd_ctl_elem_info
*uinfo
)
2331 struct snd_card_asihpi
*asihpi
=
2332 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2333 struct clk_cache
*clkcache
= &asihpi
->cc
;
2334 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2336 uinfo
->value
.enumerated
.items
= clkcache
->count
;
2338 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2339 uinfo
->value
.enumerated
.item
=
2340 uinfo
->value
.enumerated
.items
- 1;
2342 strcpy(uinfo
->value
.enumerated
.name
,
2343 clkcache
->s
[uinfo
->value
.enumerated
.item
].name
);
2347 static int snd_asihpi_clksrc_get(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
;
2353 u32 h_control
= kcontrol
->private_value
;
2354 u16 source
, srcindex
= 0;
2357 ucontrol
->value
.enumerated
.item
[0] = 0;
2358 if (hpi_sample_clock_get_source(h_control
, &source
))
2361 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2362 if (hpi_sample_clock_get_source_index(h_control
, &srcindex
))
2365 for (i
= 0; i
< clkcache
->count
; i
++)
2366 if ((clkcache
->s
[i
].source
== source
) &&
2367 (clkcache
->s
[i
].index
== srcindex
))
2370 ucontrol
->value
.enumerated
.item
[0] = i
;
2375 static int snd_asihpi_clksrc_put(struct snd_kcontrol
*kcontrol
,
2376 struct snd_ctl_elem_value
*ucontrol
)
2378 struct snd_card_asihpi
*asihpi
=
2379 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2380 struct clk_cache
*clkcache
= &asihpi
->cc
;
2382 u32 h_control
= kcontrol
->private_value
;
2385 item
= ucontrol
->value
.enumerated
.item
[0];
2386 if (item
>= clkcache
->count
)
2387 item
= clkcache
->count
-1;
2389 hpi_handle_error(hpi_sample_clock_set_source(
2390 h_control
, clkcache
->s
[item
].source
));
2392 if (clkcache
->s
[item
].source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2393 hpi_handle_error(hpi_sample_clock_set_source_index(
2394 h_control
, clkcache
->s
[item
].index
));
2398 /*------------------------------------------------------------
2400 ------------------------------------------------------------*/
2401 /* Need to change this to enumerated control with list of rates */
2402 static int snd_asihpi_clklocal_info(struct snd_kcontrol
*kcontrol
,
2403 struct snd_ctl_elem_info
*uinfo
)
2405 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2407 uinfo
->value
.integer
.min
= 8000;
2408 uinfo
->value
.integer
.max
= 192000;
2409 uinfo
->value
.integer
.step
= 100;
2414 static int snd_asihpi_clklocal_get(struct snd_kcontrol
*kcontrol
,
2415 struct snd_ctl_elem_value
*ucontrol
)
2417 u32 h_control
= kcontrol
->private_value
;
2421 e
= hpi_sample_clock_get_local_rate(h_control
, &rate
);
2423 ucontrol
->value
.integer
.value
[0] = rate
;
2425 ucontrol
->value
.integer
.value
[0] = 0;
2429 static int snd_asihpi_clklocal_put(struct snd_kcontrol
*kcontrol
,
2430 struct snd_ctl_elem_value
*ucontrol
)
2433 u32 h_control
= kcontrol
->private_value
;
2435 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2436 asihpi->mixer_clkrate[addr][1] != right;
2439 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control
,
2440 ucontrol
->value
.integer
.value
[0]));
2444 static int snd_asihpi_clkrate_info(struct snd_kcontrol
*kcontrol
,
2445 struct snd_ctl_elem_info
*uinfo
)
2447 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2449 uinfo
->value
.integer
.min
= 8000;
2450 uinfo
->value
.integer
.max
= 192000;
2451 uinfo
->value
.integer
.step
= 100;
2456 static int snd_asihpi_clkrate_get(struct snd_kcontrol
*kcontrol
,
2457 struct snd_ctl_elem_value
*ucontrol
)
2459 u32 h_control
= kcontrol
->private_value
;
2463 e
= hpi_sample_clock_get_sample_rate(h_control
, &rate
);
2465 ucontrol
->value
.integer
.value
[0] = rate
;
2467 ucontrol
->value
.integer
.value
[0] = 0;
2471 static int __devinit
snd_asihpi_sampleclock_add(struct snd_card_asihpi
*asihpi
,
2472 struct hpi_control
*hpi_ctl
)
2474 struct snd_card
*card
= asihpi
->card
;
2475 struct snd_kcontrol_new snd_control
;
2477 struct clk_cache
*clkcache
= &asihpi
->cc
;
2478 u32 hSC
= hpi_ctl
->h_control
;
2483 snd_control
.private_value
= hpi_ctl
->h_control
;
2485 clkcache
->has_local
= 0;
2487 for (i
= 0; i
<= HPI_SAMPLECLOCK_SOURCE_LAST
; i
++) {
2488 if (hpi_sample_clock_query_source(hSC
,
2491 clkcache
->s
[i
].source
= source
;
2492 clkcache
->s
[i
].index
= 0;
2493 clkcache
->s
[i
].name
= sampleclock_sources
[source
];
2494 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2496 if (source
== HPI_SAMPLECLOCK_SOURCE_LOCAL
)
2497 clkcache
->has_local
= 1;
2500 /* already will have picked up index 0 above */
2501 for (j
= 1; j
< 8; j
++) {
2502 if (hpi_sample_clock_query_source_index(hSC
,
2503 j
, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
,
2506 clkcache
->s
[i
].source
=
2507 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
;
2508 clkcache
->s
[i
].index
= j
;
2509 clkcache
->s
[i
].name
= sampleclock_sources
[
2510 j
+HPI_SAMPLECLOCK_SOURCE_LAST
];
2513 clkcache
->count
= i
;
2515 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Source");
2516 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2517 snd_control
.info
= snd_asihpi_clksrc_info
;
2518 snd_control
.get
= snd_asihpi_clksrc_get
;
2519 snd_control
.put
= snd_asihpi_clksrc_put
;
2520 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2524 if (clkcache
->has_local
) {
2525 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Localrate");
2526 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2527 snd_control
.info
= snd_asihpi_clklocal_info
;
2528 snd_control
.get
= snd_asihpi_clklocal_get
;
2529 snd_control
.put
= snd_asihpi_clklocal_put
;
2532 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2536 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Rate");
2537 snd_control
.access
=
2538 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2539 snd_control
.info
= snd_asihpi_clkrate_info
;
2540 snd_control
.get
= snd_asihpi_clkrate_get
;
2542 return ctl_add(card
, &snd_control
, asihpi
);
2544 /*------------------------------------------------------------
2546 ------------------------------------------------------------*/
2548 static int __devinit
snd_card_asihpi_mixer_new(struct snd_card_asihpi
*asihpi
)
2550 struct snd_card
*card
= asihpi
->card
;
2551 unsigned int idx
= 0;
2552 unsigned int subindex
= 0;
2554 struct hpi_control hpi_ctl
, prev_ctl
;
2556 if (snd_BUG_ON(!asihpi
))
2558 strcpy(card
->mixername
, "Asihpi Mixer");
2561 hpi_mixer_open(asihpi
->adapter_index
,
2563 hpi_handle_error(err
);
2567 memset(&prev_ctl
, 0, sizeof(prev_ctl
));
2568 prev_ctl
.control_type
= -1;
2570 for (idx
= 0; idx
< 2000; idx
++) {
2571 err
= hpi_mixer_get_control_by_index(
2574 &hpi_ctl
.src_node_type
,
2575 &hpi_ctl
.src_node_index
,
2576 &hpi_ctl
.dst_node_type
,
2577 &hpi_ctl
.dst_node_index
,
2578 &hpi_ctl
.control_type
,
2579 &hpi_ctl
.h_control
);
2581 if (err
== HPI_ERROR_CONTROL_DISABLED
) {
2583 snd_printk(KERN_INFO
2584 "Disabled HPI Control(%d)\n",
2592 hpi_ctl
.src_node_type
-= HPI_SOURCENODE_NONE
;
2593 hpi_ctl
.dst_node_type
-= HPI_DESTNODE_NONE
;
2595 /* ASI50xx in SSX mode has multiple meters on the same node.
2596 Use subindex to create distinct ALSA controls
2597 for any duplicated controls.
2599 if ((hpi_ctl
.control_type
== prev_ctl
.control_type
) &&
2600 (hpi_ctl
.src_node_type
== prev_ctl
.src_node_type
) &&
2601 (hpi_ctl
.src_node_index
== prev_ctl
.src_node_index
) &&
2602 (hpi_ctl
.dst_node_type
== prev_ctl
.dst_node_type
) &&
2603 (hpi_ctl
.dst_node_index
== prev_ctl
.dst_node_index
))
2610 switch (hpi_ctl
.control_type
) {
2611 case HPI_CONTROL_VOLUME
:
2612 err
= snd_asihpi_volume_add(asihpi
, &hpi_ctl
);
2614 case HPI_CONTROL_LEVEL
:
2615 err
= snd_asihpi_level_add(asihpi
, &hpi_ctl
);
2617 case HPI_CONTROL_MULTIPLEXER
:
2618 err
= snd_asihpi_mux_add(asihpi
, &hpi_ctl
);
2620 case HPI_CONTROL_CHANNEL_MODE
:
2621 err
= snd_asihpi_cmode_add(asihpi
, &hpi_ctl
);
2623 case HPI_CONTROL_METER
:
2624 err
= snd_asihpi_meter_add(asihpi
, &hpi_ctl
, subindex
);
2626 case HPI_CONTROL_SAMPLECLOCK
:
2627 err
= snd_asihpi_sampleclock_add(
2630 case HPI_CONTROL_CONNECTION
: /* ignore these */
2632 case HPI_CONTROL_TUNER
:
2633 err
= snd_asihpi_tuner_add(asihpi
, &hpi_ctl
);
2635 case HPI_CONTROL_AESEBU_TRANSMITTER
:
2636 err
= snd_asihpi_aesebu_tx_add(asihpi
, &hpi_ctl
);
2638 case HPI_CONTROL_AESEBU_RECEIVER
:
2639 err
= snd_asihpi_aesebu_rx_add(asihpi
, &hpi_ctl
);
2641 case HPI_CONTROL_VOX
:
2642 case HPI_CONTROL_BITSTREAM
:
2643 case HPI_CONTROL_MICROPHONE
:
2644 case HPI_CONTROL_PARAMETRIC_EQ
:
2645 case HPI_CONTROL_COMPANDER
:
2648 snd_printk(KERN_INFO
2649 "Untranslated HPI Control"
2650 "(%d) %d %d %d %d %d\n",
2652 hpi_ctl
.control_type
,
2653 hpi_ctl
.src_node_type
,
2654 hpi_ctl
.src_node_index
,
2655 hpi_ctl
.dst_node_type
,
2656 hpi_ctl
.dst_node_index
);
2662 if (HPI_ERROR_INVALID_OBJ_INDEX
!= err
)
2663 hpi_handle_error(err
);
2665 snd_printk(KERN_INFO
"%d mixer controls found\n", idx
);
2670 /*------------------------------------------------------------
2672 ------------------------------------------------------------*/
2675 snd_asihpi_proc_read(struct snd_info_entry
*entry
,
2676 struct snd_info_buffer
*buffer
)
2678 struct snd_card_asihpi
*asihpi
= entry
->private_data
;
2685 snd_iprintf(buffer
, "ASIHPI driver proc file\n");
2687 "adapter ID=%4X\n_index=%d\n"
2688 "num_outstreams=%d\n_num_instreams=%d\n",
2689 asihpi
->type
, asihpi
->adapter_index
,
2690 asihpi
->num_outstreams
, asihpi
->num_instreams
);
2692 version
= asihpi
->version
;
2694 "serial#=%d\n_hw version %c%d\nDSP code version %03d\n",
2695 asihpi
->serial_number
, ((version
>> 3) & 0xf) + 'A',
2697 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2699 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2700 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2701 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2704 err
= hpi_sample_clock_get_sample_rate(
2706 err
+= hpi_sample_clock_get_source(h_control
, &source
);
2709 snd_iprintf(buffer
, "sample_clock=%d_hz, source %s\n",
2710 rate
, sampleclock_sources
[source
]);
2716 static void __devinit
snd_asihpi_proc_init(struct snd_card_asihpi
*asihpi
)
2718 struct snd_info_entry
*entry
;
2720 if (!snd_card_proc_new(asihpi
->card
, "info", &entry
))
2721 snd_info_set_text_ops(entry
, asihpi
, snd_asihpi_proc_read
);
2724 /*------------------------------------------------------------
2726 ------------------------------------------------------------*/
2728 static int snd_asihpi_hpi_open(struct snd_hwdep
*hw
, struct file
*file
)
2730 if (enable_hpi_hwdep
)
2737 static int snd_asihpi_hpi_release(struct snd_hwdep
*hw
, struct file
*file
)
2739 if (enable_hpi_hwdep
)
2740 return asihpi_hpi_release(file
);
2745 static int snd_asihpi_hpi_ioctl(struct snd_hwdep
*hw
, struct file
*file
,
2746 unsigned int cmd
, unsigned long arg
)
2748 if (enable_hpi_hwdep
)
2749 return asihpi_hpi_ioctl(file
, cmd
, arg
);
2755 /* results in /dev/snd/hwC#D0 file for each card with index #
2756 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2758 static int __devinit
snd_asihpi_hpi_new(struct snd_card_asihpi
*asihpi
,
2759 int device
, struct snd_hwdep
**rhwdep
)
2761 struct snd_hwdep
*hw
;
2766 err
= snd_hwdep_new(asihpi
->card
, "HPI", device
, &hw
);
2769 strcpy(hw
->name
, "asihpi (HPI)");
2770 hw
->iface
= SNDRV_HWDEP_IFACE_LAST
;
2771 hw
->ops
.open
= snd_asihpi_hpi_open
;
2772 hw
->ops
.ioctl
= snd_asihpi_hpi_ioctl
;
2773 hw
->ops
.release
= snd_asihpi_hpi_release
;
2774 hw
->private_data
= asihpi
;
2780 /*------------------------------------------------------------
2782 ------------------------------------------------------------*/
2783 static int __devinit
snd_asihpi_probe(struct pci_dev
*pci_dev
,
2784 const struct pci_device_id
*pci_id
)
2791 struct hpi_adapter
*hpi_card
;
2792 struct snd_card
*card
;
2793 struct snd_card_asihpi
*asihpi
;
2799 if (dev
>= SNDRV_CARDS
)
2802 /* Should this be enable[hpi_card->index] ? */
2808 err
= asihpi_adapter_probe(pci_dev
, pci_id
);
2812 hpi_card
= pci_get_drvdata(pci_dev
);
2813 /* first try to give the card the same index as its hardware index */
2814 err
= snd_card_create(hpi_card
->index
,
2815 id
[hpi_card
->index
], THIS_MODULE
,
2816 sizeof(struct snd_card_asihpi
),
2819 /* if that fails, try the default index==next available */
2821 snd_card_create(index
[dev
], id
[dev
],
2823 sizeof(struct snd_card_asihpi
),
2827 snd_printk(KERN_WARNING
2828 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2829 hpi_card
->index
, card
->number
);
2832 snd_card_set_dev(card
, &pci_dev
->dev
);
2834 asihpi
= (struct snd_card_asihpi
*) card
->private_data
;
2835 asihpi
->card
= card
;
2836 asihpi
->pci
= pci_dev
;
2837 asihpi
->adapter_index
= hpi_card
->index
;
2838 hpi_handle_error(hpi_adapter_get_info(
2839 asihpi
->adapter_index
,
2840 &asihpi
->num_outstreams
,
2841 &asihpi
->num_instreams
,
2843 &asihpi
->serial_number
, &asihpi
->type
));
2845 version
= asihpi
->version
;
2846 snd_printk(KERN_INFO
"adapter ID=%4X index=%d num_outstreams=%d "
2847 "num_instreams=%d S/N=%d\n"
2848 "Hw Version %c%d DSP code version %03d\n",
2849 asihpi
->type
, asihpi
->adapter_index
,
2850 asihpi
->num_outstreams
,
2851 asihpi
->num_instreams
, asihpi
->serial_number
,
2852 ((version
>> 3) & 0xf) + 'A',
2854 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2856 pcm_substreams
= asihpi
->num_outstreams
;
2857 if (pcm_substreams
< asihpi
->num_instreams
)
2858 pcm_substreams
= asihpi
->num_instreams
;
2860 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2861 HPI_ADAPTER_PROPERTY_CAPS1
,
2862 NULL
, &asihpi
->support_grouping
);
2864 asihpi
->support_grouping
= 0;
2866 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2867 HPI_ADAPTER_PROPERTY_CAPS2
,
2868 &asihpi
->support_mrx
, NULL
);
2870 asihpi
->support_mrx
= 0;
2872 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2873 HPI_ADAPTER_PROPERTY_INTERVAL
,
2874 NULL
, &asihpi
->update_interval_frames
);
2876 asihpi
->update_interval_frames
= 512;
2878 if (!asihpi
->support_mmap
)
2879 asihpi
->update_interval_frames
*= 2;
2881 hpi_handle_error(hpi_instream_open(asihpi
->adapter_index
,
2884 err
= hpi_instream_host_buffer_free(h_stream
);
2885 asihpi
->support_mmap
= (!err
);
2887 hpi_handle_error(hpi_instream_close(h_stream
));
2889 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2890 HPI_ADAPTER_PROPERTY_CURCHANNELS
,
2891 &asihpi
->in_max_chans
, &asihpi
->out_max_chans
);
2893 asihpi
->in_max_chans
= 2;
2894 asihpi
->out_max_chans
= 2;
2897 snd_printk(KERN_INFO
"supports mmap:%d grouping:%d mrx:%d\n",
2898 asihpi
->support_mmap
,
2899 asihpi
->support_grouping
,
2903 err
= snd_card_asihpi_pcm_new(asihpi
, 0, pcm_substreams
);
2905 snd_printk(KERN_ERR
"pcm_new failed\n");
2908 err
= snd_card_asihpi_mixer_new(asihpi
);
2910 snd_printk(KERN_ERR
"mixer_new failed\n");
2914 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2915 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2916 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2919 err
= hpi_sample_clock_set_local_rate(
2920 h_control
, adapter_fs
);
2922 snd_asihpi_proc_init(asihpi
);
2924 /* always create, can be enabled or disabled dynamically
2925 by enable_hwdep module param*/
2926 snd_asihpi_hpi_new(asihpi
, 0, NULL
);
2928 if (asihpi
->support_mmap
)
2929 strcpy(card
->driver
, "ASIHPI-MMAP");
2931 strcpy(card
->driver
, "ASIHPI");
2933 sprintf(card
->shortname
, "AudioScience ASI%4X", asihpi
->type
);
2934 sprintf(card
->longname
, "%s %i",
2935 card
->shortname
, asihpi
->adapter_index
);
2936 err
= snd_card_register(card
);
2939 hpi_card
->snd_card_asihpi
= card
;
2944 snd_card_free(card
);
2945 snd_printk(KERN_ERR
"snd_asihpi_probe error %d\n", err
);
2950 static void __devexit
snd_asihpi_remove(struct pci_dev
*pci_dev
)
2952 struct hpi_adapter
*hpi_card
= pci_get_drvdata(pci_dev
);
2954 snd_card_free(hpi_card
->snd_card_asihpi
);
2955 hpi_card
->snd_card_asihpi
= NULL
;
2956 asihpi_adapter_remove(pci_dev
);
2959 static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl
) = {
2960 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_DSP6205
,
2961 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2962 (kernel_ulong_t
)HPI_6205
},
2963 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_PCI2040
,
2964 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2965 (kernel_ulong_t
)HPI_6000
},
2968 MODULE_DEVICE_TABLE(pci
, asihpi_pci_tbl
);
2970 static struct pci_driver driver
= {
2972 .id_table
= asihpi_pci_tbl
,
2973 .probe
= snd_asihpi_probe
,
2974 .remove
= __devexit_p(snd_asihpi_remove
),
2976 /* .suspend = snd_asihpi_suspend,
2977 .resume = snd_asihpi_resume, */
2981 static int __init
snd_asihpi_init(void)
2984 return pci_register_driver(&driver
);
2987 static void __exit
snd_asihpi_exit(void)
2990 pci_unregister_driver(&driver
);
2994 module_init(snd_asihpi_init
)
2995 module_exit(snd_asihpi_exit
)