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 /* >0: print Hw params, timer vars. >1: print stream write/copy sizes */
26 #define REALLY_VERBOSE_LOGGING 0
28 #if REALLY_VERBOSE_LOGGING
29 #define VPRINTK1 snd_printd
34 #if REALLY_VERBOSE_LOGGING > 1
35 #define VPRINTK2 snd_printd
40 #include "hpi_internal.h"
41 #include "hpimsginit.h"
44 #include <linux/pci.h>
45 #include <linux/version.h>
46 #include <linux/init.h>
47 #include <linux/jiffies.h>
48 #include <linux/slab.h>
49 #include <linux/time.h>
50 #include <linux/wait.h>
51 #include <sound/core.h>
52 #include <sound/control.h>
53 #include <sound/pcm.h>
54 #include <sound/pcm_params.h>
55 #include <sound/info.h>
56 #include <sound/initval.h>
57 #include <sound/tlv.h>
58 #include <sound/hwdep.h>
61 MODULE_LICENSE("GPL");
62 MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
63 MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx");
65 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* index 0-MAX */
66 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
67 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
68 static int enable_hpi_hwdep
= 1;
70 module_param_array(index
, int, NULL
, S_IRUGO
);
71 MODULE_PARM_DESC(index
, "ALSA index value for AudioScience soundcard.");
73 module_param_array(id
, charp
, NULL
, S_IRUGO
);
74 MODULE_PARM_DESC(id
, "ALSA ID string for AudioScience soundcard.");
76 module_param_array(enable
, bool, NULL
, S_IRUGO
);
77 MODULE_PARM_DESC(enable
, "ALSA enable AudioScience soundcard.");
79 module_param(enable_hpi_hwdep
, bool, S_IRUGO
|S_IWUSR
);
80 MODULE_PARM_DESC(enable_hpi_hwdep
,
81 "ALSA enable HPI hwdep for AudioScience soundcard ");
84 #ifdef KERNEL_ALSA_BUILD
85 static char *build_info
= "Built using headers from kernel source";
86 module_param(build_info
, charp
, S_IRUGO
);
87 MODULE_PARM_DESC(build_info
, "built using headers from kernel source");
89 static char *build_info
= "Built within ALSA source";
90 module_param(build_info
, charp
, S_IRUGO
);
91 MODULE_PARM_DESC(build_info
, "built within ALSA source");
94 /* set to 1 to dump every control from adapter to log */
95 static const int mixer_dump
;
97 #define DEFAULT_SAMPLERATE 44100
98 static int adapter_fs
= DEFAULT_SAMPLERATE
;
101 #define PERIODS_MIN 2
102 #define PERIOD_BYTES_MIN 2048
103 #define BUFFER_BYTES_MAX (512 * 1024)
105 /* convert stream to character */
106 #define SCHR(s) ((s == SNDRV_PCM_STREAM_PLAYBACK) ? 'P' : 'C')
108 /*#define TIMER_MILLISECONDS 20
109 #define FORCE_TIMER_JIFFIES ((TIMER_MILLISECONDS * HZ + 999)/1000)
112 #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
123 struct clk_source s
[MAX_CLOCKSOURCES
];
127 struct snd_card_asihpi
{
128 struct snd_card
*card
;
141 u16 support_grouping
;
143 u16 update_interval_frames
;
148 /* Per stream data */
149 struct snd_card_asihpi_pcm
{
150 struct timer_list timer
;
151 unsigned int respawn_timer
;
152 unsigned int hpi_buffer_attached
;
153 unsigned int buffer_bytes
;
154 unsigned int period_bytes
;
155 unsigned int bytes_per_sec
;
156 unsigned int pcm_buf_host_rw_ofs
; /* Host R/W pos */
157 unsigned int pcm_buf_dma_ofs
; /* DMA R/W offset in buffer */
158 unsigned int pcm_buf_elapsed_dma_ofs
; /* DMA R/W offset in buffer */
159 struct snd_pcm_substream
*substream
;
161 struct hpi_format format
;
164 /* universal stream verbs work with out or in stream handles */
166 /* Functions to allow driver to give a buffer to HPI for busmastering */
168 static u16
hpi_stream_host_buffer_attach(
169 u32 h_stream
, /* handle to outstream. */
170 u32 size_in_bytes
, /* size in bytes of bus mastering buffer */
174 struct hpi_message hm
;
175 struct hpi_response hr
;
176 unsigned int obj
= hpi_handle_object(h_stream
);
179 return HPI_ERROR_INVALID_OBJ
;
180 hpi_init_message_response(&hm
, &hr
, obj
,
181 obj
== HPI_OBJ_OSTREAM
?
182 HPI_OSTREAM_HOSTBUFFER_ALLOC
:
183 HPI_ISTREAM_HOSTBUFFER_ALLOC
);
185 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
188 hm
.u
.d
.u
.buffer
.buffer_size
= size_in_bytes
;
189 hm
.u
.d
.u
.buffer
.pci_address
= pci_address
;
190 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
;
191 hpi_send_recv(&hm
, &hr
);
195 static u16
hpi_stream_host_buffer_detach(u32 h_stream
)
197 struct hpi_message hm
;
198 struct hpi_response hr
;
199 unsigned int obj
= hpi_handle_object(h_stream
);
202 return HPI_ERROR_INVALID_OBJ
;
204 hpi_init_message_response(&hm
, &hr
, obj
,
205 obj
== HPI_OBJ_OSTREAM
?
206 HPI_OSTREAM_HOSTBUFFER_FREE
:
207 HPI_ISTREAM_HOSTBUFFER_FREE
);
209 hpi_handle_to_indexes(h_stream
, &hm
.adapter_index
,
211 hm
.u
.d
.u
.buffer
.command
= HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
;
212 hpi_send_recv(&hm
, &hr
);
216 static inline u16
hpi_stream_start(u32 h_stream
)
218 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
219 return hpi_outstream_start(h_stream
);
221 return hpi_instream_start(h_stream
);
224 static inline u16
hpi_stream_stop(u32 h_stream
)
226 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
227 return hpi_outstream_stop(h_stream
);
229 return hpi_instream_stop(h_stream
);
232 static inline u16
hpi_stream_get_info_ex(
236 u32
*pdata_in_buffer
,
242 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
243 e
= hpi_outstream_get_info_ex(h_stream
, pw_state
,
244 pbuffer_size
, pdata_in_buffer
,
245 psample_count
, pauxiliary_data
);
247 e
= hpi_instream_get_info_ex(h_stream
, pw_state
,
248 pbuffer_size
, pdata_in_buffer
,
249 psample_count
, pauxiliary_data
);
253 static inline u16
hpi_stream_group_add(
257 if (hpi_handle_object(h_master
) == HPI_OBJ_OSTREAM
)
258 return hpi_outstream_group_add(h_master
, h_stream
);
260 return hpi_instream_group_add(h_master
, h_stream
);
263 static inline u16
hpi_stream_group_reset(u32 h_stream
)
265 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
266 return hpi_outstream_group_reset(h_stream
);
268 return hpi_instream_group_reset(h_stream
);
271 static inline u16
hpi_stream_group_get_map(
272 u32 h_stream
, u32
*mo
, u32
*mi
)
274 if (hpi_handle_object(h_stream
) == HPI_OBJ_OSTREAM
)
275 return hpi_outstream_group_get_map(h_stream
, mo
, mi
);
277 return hpi_instream_group_get_map(h_stream
, mo
, mi
);
280 static u16
handle_error(u16 err
, int line
, char *filename
)
284 "in file %s, line %d: HPI error %d\n",
285 filename
, line
, err
);
289 #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__)
291 /***************************** GENERAL PCM ****************/
292 #if REALLY_VERBOSE_LOGGING
293 static void print_hwparams(struct snd_pcm_hw_params
*p
)
295 snd_printd("HWPARAMS \n");
296 snd_printd("samplerate %d \n", params_rate(p
));
297 snd_printd("Channels %d \n", params_channels(p
));
298 snd_printd("Format %d \n", params_format(p
));
299 snd_printd("subformat %d \n", params_subformat(p
));
300 snd_printd("Buffer bytes %d \n", params_buffer_bytes(p
));
301 snd_printd("Period bytes %d \n", params_period_bytes(p
));
302 snd_printd("access %d \n", params_access(p
));
303 snd_printd("period_size %d \n", params_period_size(p
));
304 snd_printd("periods %d \n", params_periods(p
));
305 snd_printd("buffer_size %d \n", params_buffer_size(p
));
308 #define print_hwparams(x)
311 static snd_pcm_format_t hpi_to_alsa_formats
[] = {
313 SNDRV_PCM_FORMAT_U8
, /* HPI_FORMAT_PCM8_UNSIGNED 1 */
314 SNDRV_PCM_FORMAT_S16
, /* HPI_FORMAT_PCM16_SIGNED 2 */
315 -1, /* HPI_FORMAT_MPEG_L1 3 */
316 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L2 4 */
317 SNDRV_PCM_FORMAT_MPEG
, /* HPI_FORMAT_MPEG_L3 5 */
318 -1, /* HPI_FORMAT_DOLBY_AC2 6 */
319 -1, /* HPI_FORMAT_DOLBY_AC3 7 */
320 SNDRV_PCM_FORMAT_S16_BE
,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */
321 -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */
322 -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */
323 SNDRV_PCM_FORMAT_S32
, /* HPI_FORMAT_PCM32_SIGNED 11 */
324 -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */
325 -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */
326 SNDRV_PCM_FORMAT_FLOAT
, /* HPI_FORMAT_PCM32_FLOAT 14 */
328 /* ALSA can't handle 3 byte sample size together with power-of-2
329 * constraint on buffer_bytes, so disable this format
333 /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */
338 static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format
,
343 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
344 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
345 if (hpi_to_alsa_formats
[format
] == alsa_format
) {
346 *hpi_format
= format
;
351 snd_printd(KERN_WARNING
"failed match for alsa format %d\n",
357 static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi
*asihpi
,
358 struct snd_pcm_hardware
*pcmhw
)
364 unsigned int rate_min
= 200000;
365 unsigned int rate_max
= 0;
366 unsigned int rates
= 0;
368 if (asihpi
->support_mrx
) {
369 rates
|= SNDRV_PCM_RATE_CONTINUOUS
;
370 rates
|= SNDRV_PCM_RATE_8000_96000
;
374 /* on cards without SRC,
375 valid rates are determined by sampleclock */
376 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
377 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
378 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
381 "No local sampleclock, err %d\n", err
);
384 for (idx
= 0; idx
< 100; idx
++) {
385 if (hpi_sample_clock_query_local_rate(
386 h_control
, idx
, &sample_rate
)) {
389 "Local rate query failed\n");
394 rate_min
= min(rate_min
, sample_rate
);
395 rate_max
= max(rate_max
, sample_rate
);
397 switch (sample_rate
) {
399 rates
|= SNDRV_PCM_RATE_5512
;
402 rates
|= SNDRV_PCM_RATE_8000
;
405 rates
|= SNDRV_PCM_RATE_11025
;
408 rates
|= SNDRV_PCM_RATE_16000
;
411 rates
|= SNDRV_PCM_RATE_22050
;
414 rates
|= SNDRV_PCM_RATE_32000
;
417 rates
|= SNDRV_PCM_RATE_44100
;
420 rates
|= SNDRV_PCM_RATE_48000
;
423 rates
|= SNDRV_PCM_RATE_64000
;
426 rates
|= SNDRV_PCM_RATE_88200
;
429 rates
|= SNDRV_PCM_RATE_96000
;
432 rates
|= SNDRV_PCM_RATE_176400
;
435 rates
|= SNDRV_PCM_RATE_192000
;
437 default: /* some other rate */
438 rates
|= SNDRV_PCM_RATE_KNOT
;
443 /* printk(KERN_INFO "Supported rates %X %d %d\n",
444 rates, rate_min, rate_max); */
445 pcmhw
->rates
= rates
;
446 pcmhw
->rate_min
= rate_min
;
447 pcmhw
->rate_max
= rate_max
;
450 static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream
*substream
,
451 struct snd_pcm_hw_params
*params
)
453 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
454 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
455 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
459 unsigned int bytes_per_sec
;
461 print_hwparams(params
);
462 err
= snd_pcm_lib_malloc_pages(substream
, params_buffer_bytes(params
));
465 err
= snd_card_asihpi_format_alsa2hpi(params_format(params
), &format
);
469 VPRINTK1(KERN_INFO
"format %d, %d chans, %d_hz\n",
470 format
, params_channels(params
),
471 params_rate(params
));
473 hpi_handle_error(hpi_format_create(&dpcm
->format
,
474 params_channels(params
),
475 format
, params_rate(params
), 0, 0));
477 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
) {
478 if (hpi_instream_reset(dpcm
->h_stream
) != 0)
481 if (hpi_instream_set_format(
482 dpcm
->h_stream
, &dpcm
->format
) != 0)
486 dpcm
->hpi_buffer_attached
= 0;
487 if (card
->support_mmap
) {
489 err
= hpi_stream_host_buffer_attach(dpcm
->h_stream
,
490 params_buffer_bytes(params
), runtime
->dma_addr
);
493 "stream_host_buffer_attach succeeded %u %lu\n",
494 params_buffer_bytes(params
),
495 (unsigned long)runtime
->dma_addr
);
498 "stream_host_buffer_attach error %d\n",
503 err
= hpi_stream_get_info_ex(dpcm
->h_stream
, NULL
,
504 &dpcm
->hpi_buffer_attached
,
507 VPRINTK1(KERN_INFO
"stream_host_buffer_attach status 0x%x\n",
508 dpcm
->hpi_buffer_attached
);
510 bytes_per_sec
= params_rate(params
) * params_channels(params
);
511 width
= snd_pcm_format_width(params_format(params
));
512 bytes_per_sec
*= width
;
514 if (width
< 0 || bytes_per_sec
== 0)
517 dpcm
->bytes_per_sec
= bytes_per_sec
;
518 dpcm
->buffer_bytes
= params_buffer_bytes(params
);
519 dpcm
->period_bytes
= params_period_bytes(params
);
520 VPRINTK1(KERN_INFO
"buffer_bytes=%d, period_bytes=%d, bps=%d\n",
521 dpcm
->buffer_bytes
, dpcm
->period_bytes
, bytes_per_sec
);
527 snd_card_asihpi_hw_free(struct snd_pcm_substream
*substream
)
529 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
530 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
531 if (dpcm
->hpi_buffer_attached
)
532 hpi_stream_host_buffer_detach(dpcm
->h_stream
);
534 snd_pcm_lib_free_pages(substream
);
538 static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime
*runtime
)
540 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
544 static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream
*
547 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
548 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
552 /*? (dpcm->period_bytes * HZ / dpcm->bytes_per_sec); */
553 expiry
= max(expiry
, 1); /* don't let it be zero! */
554 dpcm
->timer
.expires
= jiffies
+ expiry
;
555 dpcm
->respawn_timer
= 1;
556 add_timer(&dpcm
->timer
);
559 static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream
*substream
)
561 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
562 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
564 dpcm
->respawn_timer
= 0;
565 del_timer(&dpcm
->timer
);
568 static int snd_card_asihpi_trigger(struct snd_pcm_substream
*substream
,
571 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
572 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
573 struct snd_pcm_substream
*s
;
576 VPRINTK1(KERN_INFO
"%c%d trigger\n",
577 SCHR(substream
->stream
), substream
->number
);
579 case SNDRV_PCM_TRIGGER_START
:
580 snd_pcm_group_for_each_entry(s
, substream
) {
581 struct snd_pcm_runtime
*runtime
= s
->runtime
;
582 struct snd_card_asihpi_pcm
*ds
= runtime
->private_data
;
584 if (snd_pcm_substream_chip(s
) != card
)
587 /* don't link Cap and Play */
588 if (substream
->stream
!= s
->stream
)
591 if ((s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) &&
592 (card
->support_mmap
)) {
593 /* How do I know how much valid data is present
594 * in buffer? Must be at least one period!
595 * Guessing 2 periods, but if
596 * buffer is bigger it may contain even more
599 unsigned int preload
= ds
->period_bytes
* 1;
600 VPRINTK2(KERN_INFO
"%d preload x%x\n", s
->number
, preload
);
601 hpi_handle_error(hpi_outstream_write_buf(
603 &runtime
->dma_area
[0],
606 ds
->pcm_buf_host_rw_ofs
= preload
;
609 if (card
->support_grouping
) {
610 VPRINTK1(KERN_INFO
"\t%c%d group\n",
613 e
= hpi_stream_group_add(
617 snd_pcm_trigger_done(s
, substream
);
625 VPRINTK1(KERN_INFO
"start\n");
626 /* start the master stream */
627 snd_card_asihpi_pcm_timer_start(substream
);
628 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
629 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
632 case SNDRV_PCM_TRIGGER_STOP
:
633 snd_card_asihpi_pcm_timer_stop(substream
);
634 snd_pcm_group_for_each_entry(s
, substream
) {
635 if (snd_pcm_substream_chip(s
) != card
)
637 /* don't link Cap and Play */
638 if (substream
->stream
!= s
->stream
)
641 /*? workaround linked streams don't
642 transition to SETUP 20070706*/
643 s
->runtime
->status
->state
= SNDRV_PCM_STATE_SETUP
;
645 if (card
->support_grouping
) {
646 VPRINTK1(KERN_INFO
"\t%c%d group\n",
649 snd_pcm_trigger_done(s
, substream
);
653 VPRINTK1(KERN_INFO
"stop\n");
655 /* _prepare and _hwparams reset the stream */
656 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
657 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
659 hpi_outstream_reset(dpcm
->h_stream
));
661 if (card
->support_grouping
)
662 hpi_handle_error(hpi_stream_group_reset(dpcm
->h_stream
));
665 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
666 VPRINTK1(KERN_INFO
"pause release\n");
667 hpi_handle_error(hpi_stream_start(dpcm
->h_stream
));
668 snd_card_asihpi_pcm_timer_start(substream
);
670 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
671 VPRINTK1(KERN_INFO
"pause\n");
672 snd_card_asihpi_pcm_timer_stop(substream
);
673 hpi_handle_error(hpi_stream_stop(dpcm
->h_stream
));
676 snd_printd(KERN_ERR
"\tINVALID\n");
684 Without linking degenerates to getting single stream pos etc
685 Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
688 pcm_buf_dma_ofs=get_buf_pos(s);
689 for_each_linked_stream(s) {
690 pcm_buf_dma_ofs=get_buf_pos(s);
691 min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes)
692 new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos)
694 timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
695 for_each_linked_stream(s) {
696 s->pcm_buf_dma_ofs = min_buf_pos;
697 if (new_data > period_bytes) {
699 irq_pos = (irq_pos + period_bytes) % buffer_bytes;
706 snd_pcm_period_elapsed(s);
711 /** Minimum of 2 modulo values. Works correctly when the difference between
712 * the values is less than half the modulus
714 static inline unsigned int modulo_min(unsigned int a
, unsigned int b
,
715 unsigned long int modulus
)
718 if (((a
-b
) % modulus
) < (modulus
/2))
726 /** Timer function, equivalent to interrupt service routine for cards
728 static void snd_card_asihpi_timer_function(unsigned long data
)
730 struct snd_card_asihpi_pcm
*dpcm
= (struct snd_card_asihpi_pcm
*)data
;
731 struct snd_pcm_substream
*substream
= dpcm
->substream
;
732 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
733 struct snd_pcm_runtime
*runtime
;
734 struct snd_pcm_substream
*s
;
735 unsigned int newdata
= 0;
736 unsigned int pcm_buf_dma_ofs
, min_buf_pos
= 0;
737 unsigned int remdata
, xfercount
, next_jiffies
;
741 u32 buffer_size
, bytes_avail
, samples_played
, on_card_bytes
;
743 VPRINTK1(KERN_INFO
"%c%d snd_card_asihpi_timer_function\n",
744 SCHR(substream
->stream
), substream
->number
);
746 /* find minimum newdata and buffer pos in group */
747 snd_pcm_group_for_each_entry(s
, substream
) {
748 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
749 runtime
= s
->runtime
;
751 if (snd_pcm_substream_chip(s
) != card
)
754 /* don't link Cap and Play */
755 if (substream
->stream
!= s
->stream
)
758 hpi_handle_error(hpi_stream_get_info_ex(
759 ds
->h_stream
, &state
,
760 &buffer_size
, &bytes_avail
,
761 &samples_played
, &on_card_bytes
));
763 /* number of bytes in on-card buffer */
764 runtime
->delay
= on_card_bytes
;
766 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
767 pcm_buf_dma_ofs
= ds
->pcm_buf_host_rw_ofs
- bytes_avail
;
768 if (state
== HPI_STATE_STOPPED
) {
769 if ((bytes_avail
== 0) &&
770 (on_card_bytes
< ds
->pcm_buf_host_rw_ofs
)) {
771 hpi_handle_error(hpi_stream_start(ds
->h_stream
));
772 VPRINTK1(KERN_INFO
"P%d start\n", s
->number
);
774 } else if (state
== HPI_STATE_DRAINED
) {
775 VPRINTK1(KERN_WARNING
"P%d drained\n",
777 /*snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
781 pcm_buf_dma_ofs
= bytes_avail
+ ds
->pcm_buf_host_rw_ofs
;
784 /* can't statically init min when wrap is involved */
785 min_buf_pos
= pcm_buf_dma_ofs
;
786 newdata
= (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
;
790 modulo_min(min_buf_pos
, pcm_buf_dma_ofs
, UINT_MAX
+1L);
792 (pcm_buf_dma_ofs
- ds
->pcm_buf_elapsed_dma_ofs
) % ds
->buffer_bytes
,
796 VPRINTK1(KERN_INFO
"PB timer hw_ptr x%04lX, appl_ptr x%04lX\n",
797 (unsigned long)frames_to_bytes(runtime
,
798 runtime
->status
->hw_ptr
),
799 (unsigned long)frames_to_bytes(runtime
,
800 runtime
->control
->appl_ptr
));
802 VPRINTK1(KERN_INFO
"%d %c%d S=%d, rw=%04X, dma=x%04X, left=x%04X,"
803 " aux=x%04X space=x%04X\n",
804 loops
, SCHR(s
->stream
), s
->number
,
805 state
, ds
->pcm_buf_host_rw_ofs
, pcm_buf_dma_ofs
, (int)bytes_avail
,
806 (int)on_card_bytes
, buffer_size
-bytes_avail
);
809 pcm_buf_dma_ofs
= min_buf_pos
;
811 remdata
= newdata
% dpcm
->period_bytes
;
812 xfercount
= newdata
- remdata
; /* a multiple of period_bytes */
813 /* come back when on_card_bytes has decreased enough to allow
814 write to happen, or when data has been consumed to make another
817 if (xfercount
&& (on_card_bytes
> dpcm
->period_bytes
))
818 next_jiffies
= ((on_card_bytes
- dpcm
->period_bytes
) * HZ
/ dpcm
->bytes_per_sec
);
820 next_jiffies
= ((dpcm
->period_bytes
- remdata
) * HZ
/ dpcm
->bytes_per_sec
);
822 next_jiffies
= max(next_jiffies
, 1U);
823 dpcm
->timer
.expires
= jiffies
+ next_jiffies
;
824 VPRINTK1(KERN_INFO
"jif %d buf pos x%04X newdata x%04X xfer x%04X\n",
825 next_jiffies
, pcm_buf_dma_ofs
, newdata
, xfercount
);
827 snd_pcm_group_for_each_entry(s
, substream
) {
828 struct snd_card_asihpi_pcm
*ds
= s
->runtime
->private_data
;
830 /* don't link Cap and Play */
831 if (substream
->stream
!= s
->stream
)
834 ds
->pcm_buf_dma_ofs
= pcm_buf_dma_ofs
;
836 if (xfercount
&& (on_card_bytes
<= ds
->period_bytes
)) {
837 if (card
->support_mmap
) {
838 if (s
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
839 VPRINTK2(KERN_INFO
"P%d write x%04x\n",
843 hpi_outstream_write_buf(
850 VPRINTK2(KERN_INFO
"C%d read x%04x\n",
854 hpi_instream_read_buf(
858 ds
->pcm_buf_host_rw_ofs
= ds
->pcm_buf_host_rw_ofs
+ xfercount
;
859 } /* else R/W will be handled by read/write callbacks */
860 ds
->pcm_buf_elapsed_dma_ofs
= pcm_buf_dma_ofs
;
861 snd_pcm_period_elapsed(s
);
865 if (dpcm
->respawn_timer
)
866 add_timer(&dpcm
->timer
);
869 /***************************** PLAYBACK OPS ****************/
870 static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream
*substream
,
871 unsigned int cmd
, void *arg
)
873 /* snd_printd(KERN_INFO "Playback ioctl %d\n", cmd); */
874 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
877 static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream
*
880 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
881 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
883 VPRINTK1(KERN_INFO
"playback prepare %d\n", substream
->number
);
885 hpi_handle_error(hpi_outstream_reset(dpcm
->h_stream
));
886 dpcm
->pcm_buf_host_rw_ofs
= 0;
887 dpcm
->pcm_buf_dma_ofs
= 0;
888 dpcm
->pcm_buf_elapsed_dma_ofs
= 0;
892 static snd_pcm_uframes_t
893 snd_card_asihpi_playback_pointer(struct snd_pcm_substream
*substream
)
895 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
896 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
897 snd_pcm_uframes_t ptr
;
899 ptr
= bytes_to_frames(runtime
, dpcm
->pcm_buf_dma_ofs
% dpcm
->buffer_bytes
);
900 /* VPRINTK2(KERN_INFO "playback_pointer=x%04lx\n", (unsigned long)ptr); */
904 static void snd_card_asihpi_playback_format(struct snd_card_asihpi
*asihpi
,
906 struct snd_pcm_hardware
*pcmhw
)
908 struct hpi_format hpi_format
;
912 u32 sample_rate
= 48000;
914 /* on cards without SRC, must query at valid rate,
915 * maybe set by external sync
917 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
918 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
919 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
922 err
= hpi_sample_clock_get_sample_rate(h_control
,
925 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
926 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
927 err
= hpi_format_create(&hpi_format
,
928 2, format
, sample_rate
, 128000, 0);
930 err
= hpi_outstream_query_format(h_stream
,
932 if (!err
&& (hpi_to_alsa_formats
[format
] != -1))
934 (1ULL << hpi_to_alsa_formats
[format
]);
938 static struct snd_pcm_hardware snd_card_asihpi_playback
= {
941 .buffer_bytes_max
= BUFFER_BYTES_MAX
,
942 .period_bytes_min
= PERIOD_BYTES_MIN
,
943 .period_bytes_max
= BUFFER_BYTES_MAX
/ PERIODS_MIN
,
944 .periods_min
= PERIODS_MIN
,
945 .periods_max
= BUFFER_BYTES_MAX
/ PERIOD_BYTES_MIN
,
949 static int snd_card_asihpi_playback_open(struct snd_pcm_substream
*substream
)
951 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
952 struct snd_card_asihpi_pcm
*dpcm
;
953 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
956 dpcm
= kzalloc(sizeof(*dpcm
), GFP_KERNEL
);
961 hpi_outstream_open(card
->adapter_index
,
962 substream
->number
, &dpcm
->h_stream
);
963 hpi_handle_error(err
);
966 if (err
== HPI_ERROR_OBJ_ALREADY_OPEN
)
971 /*? also check ASI5000 samplerate source
972 If external, only support external rate.
973 If internal and other stream playing, cant switch
976 init_timer(&dpcm
->timer
);
977 dpcm
->timer
.data
= (unsigned long) dpcm
;
978 dpcm
->timer
.function
= snd_card_asihpi_timer_function
;
979 dpcm
->substream
= substream
;
980 runtime
->private_data
= dpcm
;
981 runtime
->private_free
= snd_card_asihpi_runtime_free
;
983 snd_card_asihpi_playback
.channels_max
= card
->out_max_chans
;
984 /*?snd_card_asihpi_playback.period_bytes_min =
985 card->out_max_chans * 4096; */
987 snd_card_asihpi_playback_format(card
, dpcm
->h_stream
,
988 &snd_card_asihpi_playback
);
990 snd_card_asihpi_pcm_samplerates(card
, &snd_card_asihpi_playback
);
992 snd_card_asihpi_playback
.info
= SNDRV_PCM_INFO_INTERLEAVED
|
993 SNDRV_PCM_INFO_DOUBLE
|
994 SNDRV_PCM_INFO_BATCH
|
995 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
996 SNDRV_PCM_INFO_PAUSE
;
998 if (card
->support_mmap
)
999 snd_card_asihpi_playback
.info
|= SNDRV_PCM_INFO_MMAP
|
1000 SNDRV_PCM_INFO_MMAP_VALID
;
1002 if (card
->support_grouping
)
1003 snd_card_asihpi_playback
.info
|= SNDRV_PCM_INFO_SYNC_START
;
1005 /* struct is copied, so can create initializer dynamically */
1006 runtime
->hw
= snd_card_asihpi_playback
;
1008 if (card
->support_mmap
)
1009 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1010 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1014 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1015 card
->update_interval_frames
);
1016 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1017 card
->update_interval_frames
* 2, UINT_MAX
);
1019 snd_pcm_set_sync(substream
);
1021 VPRINTK1(KERN_INFO
"playback open\n");
1026 static int snd_card_asihpi_playback_close(struct snd_pcm_substream
*substream
)
1028 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1029 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1031 hpi_handle_error(hpi_outstream_close(dpcm
->h_stream
));
1032 VPRINTK1(KERN_INFO
"playback close\n");
1037 static int snd_card_asihpi_playback_copy(struct snd_pcm_substream
*substream
,
1039 snd_pcm_uframes_t pos
,
1041 snd_pcm_uframes_t count
)
1043 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1044 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1047 len
= frames_to_bytes(runtime
, count
);
1049 if (copy_from_user(runtime
->dma_area
, src
, len
))
1052 VPRINTK2(KERN_DEBUG
"playback copy%d %u bytes\n",
1053 substream
->number
, len
);
1055 hpi_handle_error(hpi_outstream_write_buf(dpcm
->h_stream
,
1056 runtime
->dma_area
, len
, &dpcm
->format
));
1058 dpcm
->pcm_buf_host_rw_ofs
= dpcm
->pcm_buf_host_rw_ofs
+ len
;
1063 static int snd_card_asihpi_playback_silence(struct snd_pcm_substream
*
1064 substream
, int channel
,
1065 snd_pcm_uframes_t pos
,
1066 snd_pcm_uframes_t count
)
1069 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1070 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1072 len
= frames_to_bytes(runtime
, count
);
1073 VPRINTK1(KERN_INFO
"playback silence %u bytes\n", len
);
1075 memset(runtime
->dma_area
, 0, len
);
1076 hpi_handle_error(hpi_outstream_write_buf(dpcm
->h_stream
,
1077 runtime
->dma_area
, len
, &dpcm
->format
));
1081 static struct snd_pcm_ops snd_card_asihpi_playback_ops
= {
1082 .open
= snd_card_asihpi_playback_open
,
1083 .close
= snd_card_asihpi_playback_close
,
1084 .ioctl
= snd_card_asihpi_playback_ioctl
,
1085 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1086 .hw_free
= snd_card_asihpi_hw_free
,
1087 .prepare
= snd_card_asihpi_playback_prepare
,
1088 .trigger
= snd_card_asihpi_trigger
,
1089 .pointer
= snd_card_asihpi_playback_pointer
,
1090 .copy
= snd_card_asihpi_playback_copy
,
1091 .silence
= snd_card_asihpi_playback_silence
,
1094 static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops
= {
1095 .open
= snd_card_asihpi_playback_open
,
1096 .close
= snd_card_asihpi_playback_close
,
1097 .ioctl
= snd_card_asihpi_playback_ioctl
,
1098 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1099 .hw_free
= snd_card_asihpi_hw_free
,
1100 .prepare
= snd_card_asihpi_playback_prepare
,
1101 .trigger
= snd_card_asihpi_trigger
,
1102 .pointer
= snd_card_asihpi_playback_pointer
,
1105 /***************************** CAPTURE OPS ****************/
1106 static snd_pcm_uframes_t
1107 snd_card_asihpi_capture_pointer(struct snd_pcm_substream
*substream
)
1109 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1110 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1112 VPRINTK2(KERN_INFO
"capture pointer %d=%d\n",
1113 substream
->number
, dpcm
->pcm_buf_dma_ofs
);
1114 /* NOTE Unlike playback can't use actual samples_played
1115 for the capture position, because those samples aren't yet in
1116 the local buffer available for reading.
1118 return bytes_to_frames(runtime
, dpcm
->pcm_buf_dma_ofs
% dpcm
->buffer_bytes
);
1121 static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream
*substream
,
1122 unsigned int cmd
, void *arg
)
1124 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
1127 static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream
*substream
)
1129 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1130 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1132 hpi_handle_error(hpi_instream_reset(dpcm
->h_stream
));
1133 dpcm
->pcm_buf_host_rw_ofs
= 0;
1134 dpcm
->pcm_buf_dma_ofs
= 0;
1135 dpcm
->pcm_buf_elapsed_dma_ofs
= 0;
1137 VPRINTK1("Capture Prepare %d\n", substream
->number
);
1143 static void snd_card_asihpi_capture_format(struct snd_card_asihpi
*asihpi
,
1145 struct snd_pcm_hardware
*pcmhw
)
1147 struct hpi_format hpi_format
;
1151 u32 sample_rate
= 48000;
1153 /* on cards without SRC, must query at valid rate,
1154 maybe set by external sync */
1155 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
1156 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
1157 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
1160 err
= hpi_sample_clock_get_sample_rate(h_control
,
1163 for (format
= HPI_FORMAT_PCM8_UNSIGNED
;
1164 format
<= HPI_FORMAT_PCM24_SIGNED
; format
++) {
1166 err
= hpi_format_create(&hpi_format
, 2, format
,
1167 sample_rate
, 128000, 0);
1169 err
= hpi_instream_query_format(h_stream
,
1173 (1ULL << hpi_to_alsa_formats
[format
]);
1178 static struct snd_pcm_hardware snd_card_asihpi_capture
= {
1181 .buffer_bytes_max
= BUFFER_BYTES_MAX
,
1182 .period_bytes_min
= PERIOD_BYTES_MIN
,
1183 .period_bytes_max
= BUFFER_BYTES_MAX
/ PERIODS_MIN
,
1184 .periods_min
= PERIODS_MIN
,
1185 .periods_max
= BUFFER_BYTES_MAX
/ PERIOD_BYTES_MIN
,
1189 static int snd_card_asihpi_capture_open(struct snd_pcm_substream
*substream
)
1191 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1192 struct snd_card_asihpi
*card
= snd_pcm_substream_chip(substream
);
1193 struct snd_card_asihpi_pcm
*dpcm
;
1196 dpcm
= kzalloc(sizeof(*dpcm
), GFP_KERNEL
);
1200 VPRINTK1("hpi_instream_open adapter %d stream %d\n",
1201 card
->adapter_index
, substream
->number
);
1203 err
= hpi_handle_error(
1204 hpi_instream_open(card
->adapter_index
,
1205 substream
->number
, &dpcm
->h_stream
));
1208 if (err
== HPI_ERROR_OBJ_ALREADY_OPEN
)
1214 init_timer(&dpcm
->timer
);
1215 dpcm
->timer
.data
= (unsigned long) dpcm
;
1216 dpcm
->timer
.function
= snd_card_asihpi_timer_function
;
1217 dpcm
->substream
= substream
;
1218 runtime
->private_data
= dpcm
;
1219 runtime
->private_free
= snd_card_asihpi_runtime_free
;
1221 snd_card_asihpi_capture
.channels_max
= card
->in_max_chans
;
1222 snd_card_asihpi_capture_format(card
, dpcm
->h_stream
,
1223 &snd_card_asihpi_capture
);
1224 snd_card_asihpi_pcm_samplerates(card
, &snd_card_asihpi_capture
);
1225 snd_card_asihpi_capture
.info
= SNDRV_PCM_INFO_INTERLEAVED
;
1227 if (card
->support_mmap
)
1228 snd_card_asihpi_capture
.info
|= SNDRV_PCM_INFO_MMAP
|
1229 SNDRV_PCM_INFO_MMAP_VALID
;
1231 if (card
->support_grouping
)
1232 snd_card_asihpi_capture
.info
|= SNDRV_PCM_INFO_SYNC_START
;
1234 runtime
->hw
= snd_card_asihpi_capture
;
1236 if (card
->support_mmap
)
1237 err
= snd_pcm_hw_constraint_pow2(runtime
, 0,
1238 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
);
1242 snd_pcm_hw_constraint_step(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1243 card
->update_interval_frames
);
1244 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1245 card
->update_interval_frames
* 2, UINT_MAX
);
1247 snd_pcm_set_sync(substream
);
1252 static int snd_card_asihpi_capture_close(struct snd_pcm_substream
*substream
)
1254 struct snd_card_asihpi_pcm
*dpcm
= substream
->runtime
->private_data
;
1256 hpi_handle_error(hpi_instream_close(dpcm
->h_stream
));
1260 static int snd_card_asihpi_capture_copy(struct snd_pcm_substream
*substream
,
1261 int channel
, snd_pcm_uframes_t pos
,
1262 void __user
*dst
, snd_pcm_uframes_t count
)
1264 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1265 struct snd_card_asihpi_pcm
*dpcm
= runtime
->private_data
;
1268 len
= frames_to_bytes(runtime
, count
);
1270 VPRINTK2(KERN_INFO
"capture copy%d %d bytes\n", substream
->number
, len
);
1271 hpi_handle_error(hpi_instream_read_buf(dpcm
->h_stream
,
1272 runtime
->dma_area
, len
));
1274 dpcm
->pcm_buf_host_rw_ofs
= dpcm
->pcm_buf_host_rw_ofs
+ len
;
1276 if (copy_to_user(dst
, runtime
->dma_area
, len
))
1282 static struct snd_pcm_ops snd_card_asihpi_capture_mmap_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
,
1293 static struct snd_pcm_ops snd_card_asihpi_capture_ops
= {
1294 .open
= snd_card_asihpi_capture_open
,
1295 .close
= snd_card_asihpi_capture_close
,
1296 .ioctl
= snd_card_asihpi_capture_ioctl
,
1297 .hw_params
= snd_card_asihpi_pcm_hw_params
,
1298 .hw_free
= snd_card_asihpi_hw_free
,
1299 .prepare
= snd_card_asihpi_capture_prepare
,
1300 .trigger
= snd_card_asihpi_trigger
,
1301 .pointer
= snd_card_asihpi_capture_pointer
,
1302 .copy
= snd_card_asihpi_capture_copy
1305 static int __devinit
snd_card_asihpi_pcm_new(struct snd_card_asihpi
*asihpi
,
1306 int device
, int substreams
)
1308 struct snd_pcm
*pcm
;
1311 err
= snd_pcm_new(asihpi
->card
, "Asihpi PCM", device
,
1312 asihpi
->num_outstreams
, asihpi
->num_instreams
,
1316 /* pointer to ops struct is stored, dont change ops afterwards! */
1317 if (asihpi
->support_mmap
) {
1318 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1319 &snd_card_asihpi_playback_mmap_ops
);
1320 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1321 &snd_card_asihpi_capture_mmap_ops
);
1323 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1324 &snd_card_asihpi_playback_ops
);
1325 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1326 &snd_card_asihpi_capture_ops
);
1329 pcm
->private_data
= asihpi
;
1330 pcm
->info_flags
= 0;
1331 strcpy(pcm
->name
, "Asihpi PCM");
1333 /*? do we want to emulate MMAP for non-BBM cards?
1334 Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
1335 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1336 snd_dma_pci_data(asihpi
->pci
),
1337 64*1024, BUFFER_BYTES_MAX
);
1342 /***************************** MIXER CONTROLS ****************/
1343 struct hpi_control
{
1351 char name
[44]; /* copied to snd_ctl_elem_id.name[44]; */
1354 static const char * const asihpi_tuner_band_names
[] = {
1367 compile_time_assert(
1368 (ARRAY_SIZE(asihpi_tuner_band_names
) ==
1369 (HPI_TUNER_BAND_LAST
+1)),
1370 assert_tuner_band_names_size
);
1372 static const char * const asihpi_src_names
[] = {
1387 compile_time_assert(
1388 (ARRAY_SIZE(asihpi_src_names
) ==
1389 (HPI_SOURCENODE_LAST_INDEX
-HPI_SOURCENODE_NONE
+1)),
1390 assert_src_names_size
);
1392 static const char * const asihpi_dst_names
[] = {
1403 compile_time_assert(
1404 (ARRAY_SIZE(asihpi_dst_names
) ==
1405 (HPI_DESTNODE_LAST_INDEX
-HPI_DESTNODE_NONE
+1)),
1406 assert_dst_names_size
);
1408 static inline int ctl_add(struct snd_card
*card
, struct snd_kcontrol_new
*ctl
,
1409 struct snd_card_asihpi
*asihpi
)
1413 err
= snd_ctl_add(card
, snd_ctl_new1(ctl
, asihpi
));
1416 else if (mixer_dump
)
1417 snd_printk(KERN_INFO
"added %s(%d)\n", ctl
->name
, ctl
->index
);
1422 /* Convert HPI control name and location into ALSA control name */
1423 static void asihpi_ctl_init(struct snd_kcontrol_new
*snd_control
,
1424 struct hpi_control
*hpi_ctl
,
1428 memset(snd_control
, 0, sizeof(*snd_control
));
1429 snd_control
->name
= hpi_ctl
->name
;
1430 snd_control
->private_value
= hpi_ctl
->h_control
;
1431 snd_control
->iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
1432 snd_control
->index
= 0;
1434 if (hpi_ctl
->dst_node_type
+ HPI_DESTNODE_NONE
== HPI_DESTNODE_ISTREAM
)
1435 dir
= "Capture "; /* On or towards a PCM capture destination*/
1436 else if ((hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1437 (!hpi_ctl
->dst_node_type
))
1438 dir
= "Capture "; /* On a source node that is not PCM playback */
1439 else if (hpi_ctl
->src_node_type
&&
1440 (hpi_ctl
->src_node_type
+ HPI_SOURCENODE_NONE
!= HPI_SOURCENODE_OSTREAM
) &&
1441 (hpi_ctl
->dst_node_type
))
1442 dir
= "Monitor Playback "; /* Between an input and an output */
1444 dir
= "Playback "; /* PCM Playback source, or output node */
1446 if (hpi_ctl
->src_node_type
&& hpi_ctl
->dst_node_type
)
1447 sprintf(hpi_ctl
->name
, "%s%d %s%d %s%s",
1448 asihpi_src_names
[hpi_ctl
->src_node_type
],
1449 hpi_ctl
->src_node_index
,
1450 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1451 hpi_ctl
->dst_node_index
,
1453 else if (hpi_ctl
->dst_node_type
) {
1454 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1455 asihpi_dst_names
[hpi_ctl
->dst_node_type
],
1456 hpi_ctl
->dst_node_index
,
1459 sprintf(hpi_ctl
->name
, "%s %d %s%s",
1460 asihpi_src_names
[hpi_ctl
->src_node_type
],
1461 hpi_ctl
->src_node_index
,
1464 /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
1465 hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
1468 /*------------------------------------------------------------
1470 ------------------------------------------------------------*/
1471 #define VOL_STEP_mB 1
1472 static int snd_asihpi_volume_info(struct snd_kcontrol
*kcontrol
,
1473 struct snd_ctl_elem_info
*uinfo
)
1475 u32 h_control
= kcontrol
->private_value
;
1477 /* native gains are in millibels */
1482 err
= hpi_volume_query_range(h_control
,
1483 &min_gain_mB
, &max_gain_mB
, &step_gain_mB
);
1486 min_gain_mB
= -10000;
1487 step_gain_mB
= VOL_STEP_mB
;
1490 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1492 uinfo
->value
.integer
.min
= min_gain_mB
/ VOL_STEP_mB
;
1493 uinfo
->value
.integer
.max
= max_gain_mB
/ VOL_STEP_mB
;
1494 uinfo
->value
.integer
.step
= step_gain_mB
/ VOL_STEP_mB
;
1498 static int snd_asihpi_volume_get(struct snd_kcontrol
*kcontrol
,
1499 struct snd_ctl_elem_value
*ucontrol
)
1501 u32 h_control
= kcontrol
->private_value
;
1502 short an_gain_mB
[HPI_MAX_CHANNELS
];
1504 hpi_handle_error(hpi_volume_get_gain(h_control
, an_gain_mB
));
1505 ucontrol
->value
.integer
.value
[0] = an_gain_mB
[0] / VOL_STEP_mB
;
1506 ucontrol
->value
.integer
.value
[1] = an_gain_mB
[1] / VOL_STEP_mB
;
1511 static int snd_asihpi_volume_put(struct snd_kcontrol
*kcontrol
,
1512 struct snd_ctl_elem_value
*ucontrol
)
1515 u32 h_control
= kcontrol
->private_value
;
1516 short an_gain_mB
[HPI_MAX_CHANNELS
];
1519 (ucontrol
->value
.integer
.value
[0]) * VOL_STEP_mB
;
1521 (ucontrol
->value
.integer
.value
[1]) * VOL_STEP_mB
;
1522 /* change = asihpi->mixer_volume[addr][0] != left ||
1523 asihpi->mixer_volume[addr][1] != right;
1526 hpi_handle_error(hpi_volume_set_gain(h_control
, an_gain_mB
));
1530 static const DECLARE_TLV_DB_SCALE(db_scale_100
, -10000, VOL_STEP_mB
, 0);
1532 static int __devinit
snd_asihpi_volume_add(struct snd_card_asihpi
*asihpi
,
1533 struct hpi_control
*hpi_ctl
)
1535 struct snd_card
*card
= asihpi
->card
;
1536 struct snd_kcontrol_new snd_control
;
1538 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Volume");
1539 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1540 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1541 snd_control
.info
= snd_asihpi_volume_info
;
1542 snd_control
.get
= snd_asihpi_volume_get
;
1543 snd_control
.put
= snd_asihpi_volume_put
;
1544 snd_control
.tlv
.p
= db_scale_100
;
1546 return ctl_add(card
, &snd_control
, asihpi
);
1549 /*------------------------------------------------------------
1551 ------------------------------------------------------------*/
1552 static int snd_asihpi_level_info(struct snd_kcontrol
*kcontrol
,
1553 struct snd_ctl_elem_info
*uinfo
)
1555 u32 h_control
= kcontrol
->private_value
;
1562 hpi_level_query_range(h_control
, &min_gain_mB
,
1563 &max_gain_mB
, &step_gain_mB
);
1566 min_gain_mB
= -1000;
1570 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1572 uinfo
->value
.integer
.min
= min_gain_mB
/ HPI_UNITS_PER_dB
;
1573 uinfo
->value
.integer
.max
= max_gain_mB
/ HPI_UNITS_PER_dB
;
1574 uinfo
->value
.integer
.step
= step_gain_mB
/ HPI_UNITS_PER_dB
;
1578 static int snd_asihpi_level_get(struct snd_kcontrol
*kcontrol
,
1579 struct snd_ctl_elem_value
*ucontrol
)
1581 u32 h_control
= kcontrol
->private_value
;
1582 short an_gain_mB
[HPI_MAX_CHANNELS
];
1584 hpi_handle_error(hpi_level_get_gain(h_control
, an_gain_mB
));
1585 ucontrol
->value
.integer
.value
[0] =
1586 an_gain_mB
[0] / HPI_UNITS_PER_dB
;
1587 ucontrol
->value
.integer
.value
[1] =
1588 an_gain_mB
[1] / HPI_UNITS_PER_dB
;
1593 static int snd_asihpi_level_put(struct snd_kcontrol
*kcontrol
,
1594 struct snd_ctl_elem_value
*ucontrol
)
1597 u32 h_control
= kcontrol
->private_value
;
1598 short an_gain_mB
[HPI_MAX_CHANNELS
];
1601 (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1603 (ucontrol
->value
.integer
.value
[1]) * HPI_UNITS_PER_dB
;
1604 /* change = asihpi->mixer_level[addr][0] != left ||
1605 asihpi->mixer_level[addr][1] != right;
1608 hpi_handle_error(hpi_level_set_gain(h_control
, an_gain_mB
));
1612 static const DECLARE_TLV_DB_SCALE(db_scale_level
, -1000, 100, 0);
1614 static int __devinit
snd_asihpi_level_add(struct snd_card_asihpi
*asihpi
,
1615 struct hpi_control
*hpi_ctl
)
1617 struct snd_card
*card
= asihpi
->card
;
1618 struct snd_kcontrol_new snd_control
;
1620 /* can't use 'volume' cos some nodes have volume as well */
1621 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Level");
1622 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
1623 SNDRV_CTL_ELEM_ACCESS_TLV_READ
;
1624 snd_control
.info
= snd_asihpi_level_info
;
1625 snd_control
.get
= snd_asihpi_level_get
;
1626 snd_control
.put
= snd_asihpi_level_put
;
1627 snd_control
.tlv
.p
= db_scale_level
;
1629 return ctl_add(card
, &snd_control
, asihpi
);
1632 /*------------------------------------------------------------
1634 ------------------------------------------------------------*/
1637 static const char * const asihpi_aesebu_format_names
[] = {
1638 "N/A", "S/PDIF", "AES/EBU" };
1640 static int snd_asihpi_aesebu_format_info(struct snd_kcontrol
*kcontrol
,
1641 struct snd_ctl_elem_info
*uinfo
)
1643 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1645 uinfo
->value
.enumerated
.items
= 3;
1647 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1648 uinfo
->value
.enumerated
.item
=
1649 uinfo
->value
.enumerated
.items
- 1;
1651 strcpy(uinfo
->value
.enumerated
.name
,
1652 asihpi_aesebu_format_names
[uinfo
->value
.enumerated
.item
]);
1657 static int snd_asihpi_aesebu_format_get(struct snd_kcontrol
*kcontrol
,
1658 struct snd_ctl_elem_value
*ucontrol
,
1659 u16 (*func
)(u32
, u16
*))
1661 u32 h_control
= kcontrol
->private_value
;
1664 err
= func(h_control
, &source
);
1666 /* default to N/A */
1667 ucontrol
->value
.enumerated
.item
[0] = 0;
1668 /* return success but set the control to N/A */
1671 if (source
== HPI_AESEBU_FORMAT_SPDIF
)
1672 ucontrol
->value
.enumerated
.item
[0] = 1;
1673 if (source
== HPI_AESEBU_FORMAT_AESEBU
)
1674 ucontrol
->value
.enumerated
.item
[0] = 2;
1679 static int snd_asihpi_aesebu_format_put(struct snd_kcontrol
*kcontrol
,
1680 struct snd_ctl_elem_value
*ucontrol
,
1681 u16 (*func
)(u32
, u16
))
1683 u32 h_control
= kcontrol
->private_value
;
1685 /* default to S/PDIF */
1686 u16 source
= HPI_AESEBU_FORMAT_SPDIF
;
1688 if (ucontrol
->value
.enumerated
.item
[0] == 1)
1689 source
= HPI_AESEBU_FORMAT_SPDIF
;
1690 if (ucontrol
->value
.enumerated
.item
[0] == 2)
1691 source
= HPI_AESEBU_FORMAT_AESEBU
;
1693 if (func(h_control
, source
) != 0)
1699 static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol
*kcontrol
,
1700 struct snd_ctl_elem_value
*ucontrol
) {
1701 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1702 hpi_aesebu_receiver_get_format
);
1705 static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol
*kcontrol
,
1706 struct snd_ctl_elem_value
*ucontrol
) {
1707 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1708 hpi_aesebu_receiver_set_format
);
1711 static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol
*kcontrol
,
1712 struct snd_ctl_elem_info
*uinfo
)
1714 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1717 uinfo
->value
.integer
.min
= 0;
1718 uinfo
->value
.integer
.max
= 0X1F;
1719 uinfo
->value
.integer
.step
= 1;
1724 static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol
*kcontrol
,
1725 struct snd_ctl_elem_value
*ucontrol
) {
1727 u32 h_control
= kcontrol
->private_value
;
1730 hpi_handle_error(hpi_aesebu_receiver_get_error_status(
1731 h_control
, &status
));
1732 ucontrol
->value
.integer
.value
[0] = status
;
1736 static int __devinit
snd_asihpi_aesebu_rx_add(struct snd_card_asihpi
*asihpi
,
1737 struct hpi_control
*hpi_ctl
)
1739 struct snd_card
*card
= asihpi
->card
;
1740 struct snd_kcontrol_new snd_control
;
1742 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1743 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1744 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1745 snd_control
.get
= snd_asihpi_aesebu_rx_format_get
;
1746 snd_control
.put
= snd_asihpi_aesebu_rx_format_put
;
1749 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
1752 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Status");
1753 snd_control
.access
=
1754 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
1755 snd_control
.info
= snd_asihpi_aesebu_rxstatus_info
;
1756 snd_control
.get
= snd_asihpi_aesebu_rxstatus_get
;
1758 return ctl_add(card
, &snd_control
, asihpi
);
1761 static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol
*kcontrol
,
1762 struct snd_ctl_elem_value
*ucontrol
) {
1763 return snd_asihpi_aesebu_format_get(kcontrol
, ucontrol
,
1764 hpi_aesebu_transmitter_get_format
);
1767 static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol
*kcontrol
,
1768 struct snd_ctl_elem_value
*ucontrol
) {
1769 return snd_asihpi_aesebu_format_put(kcontrol
, ucontrol
,
1770 hpi_aesebu_transmitter_set_format
);
1774 static int __devinit
snd_asihpi_aesebu_tx_add(struct snd_card_asihpi
*asihpi
,
1775 struct hpi_control
*hpi_ctl
)
1777 struct snd_card
*card
= asihpi
->card
;
1778 struct snd_kcontrol_new snd_control
;
1780 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Format");
1781 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
1782 snd_control
.info
= snd_asihpi_aesebu_format_info
;
1783 snd_control
.get
= snd_asihpi_aesebu_tx_format_get
;
1784 snd_control
.put
= snd_asihpi_aesebu_tx_format_put
;
1786 return ctl_add(card
, &snd_control
, asihpi
);
1789 /*------------------------------------------------------------
1791 ------------------------------------------------------------*/
1795 static int snd_asihpi_tuner_gain_info(struct snd_kcontrol
*kcontrol
,
1796 struct snd_ctl_elem_info
*uinfo
)
1798 u32 h_control
= kcontrol
->private_value
;
1803 for (idx
= 0; idx
< 3; idx
++) {
1804 err
= hpi_tuner_query_gain(h_control
,
1805 idx
, &gain_range
[idx
]);
1810 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1812 uinfo
->value
.integer
.min
= ((int)gain_range
[0]) / HPI_UNITS_PER_dB
;
1813 uinfo
->value
.integer
.max
= ((int)gain_range
[1]) / HPI_UNITS_PER_dB
;
1814 uinfo
->value
.integer
.step
= ((int) gain_range
[2]) / HPI_UNITS_PER_dB
;
1818 static int snd_asihpi_tuner_gain_get(struct snd_kcontrol
*kcontrol
,
1819 struct snd_ctl_elem_value
*ucontrol
)
1822 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1824 u32 h_control
= kcontrol
->private_value
;
1827 hpi_handle_error(hpi_tuner_get_gain(h_control
, &gain
));
1828 ucontrol
->value
.integer
.value
[0] = gain
/ HPI_UNITS_PER_dB
;
1833 static int snd_asihpi_tuner_gain_put(struct snd_kcontrol
*kcontrol
,
1834 struct snd_ctl_elem_value
*ucontrol
)
1837 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1839 u32 h_control
= kcontrol
->private_value
;
1842 gain
= (ucontrol
->value
.integer
.value
[0]) * HPI_UNITS_PER_dB
;
1843 hpi_handle_error(hpi_tuner_set_gain(h_control
, gain
));
1850 static int asihpi_tuner_band_query(struct snd_kcontrol
*kcontrol
,
1851 u16
*band_list
, u32 len
) {
1852 u32 h_control
= kcontrol
->private_value
;
1856 for (i
= 0; i
< len
; i
++) {
1857 err
= hpi_tuner_query_band(
1858 h_control
, i
, &band_list
[i
]);
1863 if (err
&& (err
!= HPI_ERROR_INVALID_OBJ_INDEX
))
1869 static int snd_asihpi_tuner_band_info(struct snd_kcontrol
*kcontrol
,
1870 struct snd_ctl_elem_info
*uinfo
)
1872 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1875 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1876 HPI_TUNER_BAND_LAST
);
1881 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1883 uinfo
->value
.enumerated
.items
= num_bands
;
1885 if (num_bands
> 0) {
1886 if (uinfo
->value
.enumerated
.item
>=
1887 uinfo
->value
.enumerated
.items
)
1888 uinfo
->value
.enumerated
.item
=
1889 uinfo
->value
.enumerated
.items
- 1;
1891 strcpy(uinfo
->value
.enumerated
.name
,
1892 asihpi_tuner_band_names
[
1893 tuner_bands
[uinfo
->value
.enumerated
.item
]]);
1899 static int snd_asihpi_tuner_band_get(struct snd_kcontrol
*kcontrol
,
1900 struct snd_ctl_elem_value
*ucontrol
)
1902 u32 h_control
= kcontrol
->private_value
;
1904 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1907 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1910 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1911 HPI_TUNER_BAND_LAST
);
1913 hpi_handle_error(hpi_tuner_get_band(h_control
, &band
));
1915 ucontrol
->value
.enumerated
.item
[0] = -1;
1916 for (idx
= 0; idx
< HPI_TUNER_BAND_LAST
; idx
++)
1917 if (tuner_bands
[idx
] == band
) {
1918 ucontrol
->value
.enumerated
.item
[0] = idx
;
1925 static int snd_asihpi_tuner_band_put(struct snd_kcontrol
*kcontrol
,
1926 struct snd_ctl_elem_value
*ucontrol
)
1929 struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
1931 u32 h_control
= kcontrol
->private_value
;
1933 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1936 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1937 HPI_TUNER_BAND_LAST
);
1939 band
= tuner_bands
[ucontrol
->value
.enumerated
.item
[0]];
1940 hpi_handle_error(hpi_tuner_set_band(h_control
, band
));
1947 static int snd_asihpi_tuner_freq_info(struct snd_kcontrol
*kcontrol
,
1948 struct snd_ctl_elem_info
*uinfo
)
1950 u32 h_control
= kcontrol
->private_value
;
1952 u16 tuner_bands
[HPI_TUNER_BAND_LAST
];
1953 u16 num_bands
= 0, band_iter
, idx
;
1954 u32 freq_range
[3], temp_freq_range
[3];
1956 num_bands
= asihpi_tuner_band_query(kcontrol
, tuner_bands
,
1957 HPI_TUNER_BAND_LAST
);
1959 freq_range
[0] = INT_MAX
;
1961 freq_range
[2] = INT_MAX
;
1963 for (band_iter
= 0; band_iter
< num_bands
; band_iter
++) {
1964 for (idx
= 0; idx
< 3; idx
++) {
1965 err
= hpi_tuner_query_frequency(h_control
,
1966 idx
, tuner_bands
[band_iter
],
1967 &temp_freq_range
[idx
]);
1972 /* skip band with bogus stepping */
1973 if (temp_freq_range
[2] <= 0)
1976 if (temp_freq_range
[0] < freq_range
[0])
1977 freq_range
[0] = temp_freq_range
[0];
1978 if (temp_freq_range
[1] > freq_range
[1])
1979 freq_range
[1] = temp_freq_range
[1];
1980 if (temp_freq_range
[2] < freq_range
[2])
1981 freq_range
[2] = temp_freq_range
[2];
1984 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1986 uinfo
->value
.integer
.min
= ((int)freq_range
[0]);
1987 uinfo
->value
.integer
.max
= ((int)freq_range
[1]);
1988 uinfo
->value
.integer
.step
= ((int)freq_range
[2]);
1992 static int snd_asihpi_tuner_freq_get(struct snd_kcontrol
*kcontrol
,
1993 struct snd_ctl_elem_value
*ucontrol
)
1995 u32 h_control
= kcontrol
->private_value
;
1998 hpi_handle_error(hpi_tuner_get_frequency(h_control
, &freq
));
1999 ucontrol
->value
.integer
.value
[0] = freq
;
2004 static int snd_asihpi_tuner_freq_put(struct snd_kcontrol
*kcontrol
,
2005 struct snd_ctl_elem_value
*ucontrol
)
2007 u32 h_control
= kcontrol
->private_value
;
2010 freq
= ucontrol
->value
.integer
.value
[0];
2011 hpi_handle_error(hpi_tuner_set_frequency(h_control
, freq
));
2016 /* Tuner control group initializer */
2017 static int __devinit
snd_asihpi_tuner_add(struct snd_card_asihpi
*asihpi
,
2018 struct hpi_control
*hpi_ctl
)
2020 struct snd_card
*card
= asihpi
->card
;
2021 struct snd_kcontrol_new snd_control
;
2023 snd_control
.private_value
= hpi_ctl
->h_control
;
2024 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2026 if (!hpi_tuner_get_gain(hpi_ctl
->h_control
, NULL
)) {
2027 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Gain");
2028 snd_control
.info
= snd_asihpi_tuner_gain_info
;
2029 snd_control
.get
= snd_asihpi_tuner_gain_get
;
2030 snd_control
.put
= snd_asihpi_tuner_gain_put
;
2032 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2036 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Band");
2037 snd_control
.info
= snd_asihpi_tuner_band_info
;
2038 snd_control
.get
= snd_asihpi_tuner_band_get
;
2039 snd_control
.put
= snd_asihpi_tuner_band_put
;
2041 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2044 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Freq");
2045 snd_control
.info
= snd_asihpi_tuner_freq_info
;
2046 snd_control
.get
= snd_asihpi_tuner_freq_get
;
2047 snd_control
.put
= snd_asihpi_tuner_freq_put
;
2049 return ctl_add(card
, &snd_control
, asihpi
);
2052 /*------------------------------------------------------------
2054 ------------------------------------------------------------*/
2055 static int snd_asihpi_meter_info(struct snd_kcontrol
*kcontrol
,
2056 struct snd_ctl_elem_info
*uinfo
)
2058 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2059 uinfo
->count
= HPI_MAX_CHANNELS
;
2060 uinfo
->value
.integer
.min
= 0;
2061 uinfo
->value
.integer
.max
= 0x7FFFFFFF;
2065 /* linear values for 10dB steps */
2066 static int log2lin
[] = {
2067 0x7FFFFFFF, /* 0dB */
2073 2147484, /* -60dB */
2088 static int snd_asihpi_meter_get(struct snd_kcontrol
*kcontrol
,
2089 struct snd_ctl_elem_value
*ucontrol
)
2091 u32 h_control
= kcontrol
->private_value
;
2092 short an_gain_mB
[HPI_MAX_CHANNELS
], i
;
2095 err
= hpi_meter_get_peak(h_control
, an_gain_mB
);
2097 for (i
= 0; i
< HPI_MAX_CHANNELS
; i
++) {
2099 ucontrol
->value
.integer
.value
[i
] = 0;
2100 } else if (an_gain_mB
[i
] >= 0) {
2101 ucontrol
->value
.integer
.value
[i
] =
2102 an_gain_mB
[i
] << 16;
2104 /* -ve is log value in millibels < -60dB,
2105 * convert to (roughly!) linear,
2107 ucontrol
->value
.integer
.value
[i
] =
2108 log2lin
[an_gain_mB
[i
] / -1000];
2114 static int __devinit
snd_asihpi_meter_add(struct snd_card_asihpi
*asihpi
,
2115 struct hpi_control
*hpi_ctl
, int subidx
)
2117 struct snd_card
*card
= asihpi
->card
;
2118 struct snd_kcontrol_new snd_control
;
2120 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Meter");
2121 snd_control
.access
=
2122 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2123 snd_control
.info
= snd_asihpi_meter_info
;
2124 snd_control
.get
= snd_asihpi_meter_get
;
2126 snd_control
.index
= subidx
;
2128 return ctl_add(card
, &snd_control
, asihpi
);
2131 /*------------------------------------------------------------
2132 Multiplexer controls
2133 ------------------------------------------------------------*/
2134 static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol
*snd_control
)
2136 u32 h_control
= snd_control
->private_value
;
2137 struct hpi_control hpi_ctl
;
2139 for (s
= 0; s
< 32; s
++) {
2140 err
= hpi_multiplexer_query_source(h_control
, s
,
2151 static int snd_asihpi_mux_info(struct snd_kcontrol
*kcontrol
,
2152 struct snd_ctl_elem_info
*uinfo
)
2155 u16 src_node_type
, src_node_index
;
2156 u32 h_control
= kcontrol
->private_value
;
2158 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2160 uinfo
->value
.enumerated
.items
=
2161 snd_card_asihpi_mux_count_sources(kcontrol
);
2163 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2164 uinfo
->value
.enumerated
.item
=
2165 uinfo
->value
.enumerated
.items
- 1;
2168 hpi_multiplexer_query_source(h_control
,
2169 uinfo
->value
.enumerated
.item
,
2170 &src_node_type
, &src_node_index
);
2172 sprintf(uinfo
->value
.enumerated
.name
, "%s %d",
2173 asihpi_src_names
[src_node_type
- HPI_SOURCENODE_NONE
],
2178 static int snd_asihpi_mux_get(struct snd_kcontrol
*kcontrol
,
2179 struct snd_ctl_elem_value
*ucontrol
)
2181 u32 h_control
= kcontrol
->private_value
;
2182 u16 source_type
, source_index
;
2183 u16 src_node_type
, src_node_index
;
2186 hpi_handle_error(hpi_multiplexer_get_source(h_control
,
2187 &source_type
, &source_index
));
2188 /* Should cache this search result! */
2189 for (s
= 0; s
< 256; s
++) {
2190 if (hpi_multiplexer_query_source(h_control
, s
,
2191 &src_node_type
, &src_node_index
))
2194 if ((source_type
== src_node_type
)
2195 && (source_index
== src_node_index
)) {
2196 ucontrol
->value
.enumerated
.item
[0] = s
;
2200 snd_printd(KERN_WARNING
2201 "Control %x failed to match mux source %hu %hu\n",
2202 h_control
, source_type
, source_index
);
2203 ucontrol
->value
.enumerated
.item
[0] = 0;
2207 static int snd_asihpi_mux_put(struct snd_kcontrol
*kcontrol
,
2208 struct snd_ctl_elem_value
*ucontrol
)
2211 u32 h_control
= kcontrol
->private_value
;
2212 u16 source_type
, source_index
;
2217 e
= hpi_multiplexer_query_source(h_control
,
2218 ucontrol
->value
.enumerated
.item
[0],
2219 &source_type
, &source_index
);
2222 hpi_multiplexer_set_source(h_control
,
2223 source_type
, source_index
));
2228 static int __devinit
snd_asihpi_mux_add(struct snd_card_asihpi
*asihpi
,
2229 struct hpi_control
*hpi_ctl
)
2231 struct snd_card
*card
= asihpi
->card
;
2232 struct snd_kcontrol_new snd_control
;
2234 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Route");
2235 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2236 snd_control
.info
= snd_asihpi_mux_info
;
2237 snd_control
.get
= snd_asihpi_mux_get
;
2238 snd_control
.put
= snd_asihpi_mux_put
;
2240 return ctl_add(card
, &snd_control
, asihpi
);
2244 /*------------------------------------------------------------
2245 Channel mode controls
2246 ------------------------------------------------------------*/
2247 static int snd_asihpi_cmode_info(struct snd_kcontrol
*kcontrol
,
2248 struct snd_ctl_elem_info
*uinfo
)
2250 static const char * const mode_names
[HPI_CHANNEL_MODE_LAST
+ 1] = {
2253 "From Left", "From Right",
2254 "To Left", "To Right"
2257 u32 h_control
= kcontrol
->private_value
;
2261 int valid_modes
= 0;
2263 /* HPI channel mode values can be from 1 to 6
2264 Some adapters only support a contiguous subset
2266 for (i
= 0; i
< HPI_CHANNEL_MODE_LAST
; i
++)
2267 if (!hpi_channel_mode_query_mode(
2268 h_control
, i
, &mode
)) {
2269 mode_map
[valid_modes
] = mode
;
2273 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2275 uinfo
->value
.enumerated
.items
= valid_modes
;
2277 if (uinfo
->value
.enumerated
.item
>= valid_modes
)
2278 uinfo
->value
.enumerated
.item
= valid_modes
- 1;
2280 strcpy(uinfo
->value
.enumerated
.name
,
2281 mode_names
[mode_map
[uinfo
->value
.enumerated
.item
]]);
2286 static int snd_asihpi_cmode_get(struct snd_kcontrol
*kcontrol
,
2287 struct snd_ctl_elem_value
*ucontrol
)
2289 u32 h_control
= kcontrol
->private_value
;
2292 if (hpi_channel_mode_get(h_control
, &mode
))
2295 ucontrol
->value
.enumerated
.item
[0] = mode
- 1;
2300 static int snd_asihpi_cmode_put(struct snd_kcontrol
*kcontrol
,
2301 struct snd_ctl_elem_value
*ucontrol
)
2304 u32 h_control
= kcontrol
->private_value
;
2308 hpi_handle_error(hpi_channel_mode_set(h_control
,
2309 ucontrol
->value
.enumerated
.item
[0] + 1));
2314 static int __devinit
snd_asihpi_cmode_add(struct snd_card_asihpi
*asihpi
,
2315 struct hpi_control
*hpi_ctl
)
2317 struct snd_card
*card
= asihpi
->card
;
2318 struct snd_kcontrol_new snd_control
;
2320 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Mode");
2321 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2322 snd_control
.info
= snd_asihpi_cmode_info
;
2323 snd_control
.get
= snd_asihpi_cmode_get
;
2324 snd_control
.put
= snd_asihpi_cmode_put
;
2326 return ctl_add(card
, &snd_control
, asihpi
);
2329 /*------------------------------------------------------------
2330 Sampleclock source controls
2331 ------------------------------------------------------------*/
2332 static char *sampleclock_sources
[MAX_CLOCKSOURCES
] = {
2333 "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header",
2334 "SMPTE", "Digital1", "Auto", "Network", "Invalid",
2336 "Digital2", "Digital3", "Digital4", "Digital5",
2337 "Digital6", "Digital7", "Digital8"};
2339 static int snd_asihpi_clksrc_info(struct snd_kcontrol
*kcontrol
,
2340 struct snd_ctl_elem_info
*uinfo
)
2342 struct snd_card_asihpi
*asihpi
=
2343 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2344 struct clk_cache
*clkcache
= &asihpi
->cc
;
2345 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2347 uinfo
->value
.enumerated
.items
= clkcache
->count
;
2349 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2350 uinfo
->value
.enumerated
.item
=
2351 uinfo
->value
.enumerated
.items
- 1;
2353 strcpy(uinfo
->value
.enumerated
.name
,
2354 clkcache
->s
[uinfo
->value
.enumerated
.item
].name
);
2358 static int snd_asihpi_clksrc_get(struct snd_kcontrol
*kcontrol
,
2359 struct snd_ctl_elem_value
*ucontrol
)
2361 struct snd_card_asihpi
*asihpi
=
2362 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2363 struct clk_cache
*clkcache
= &asihpi
->cc
;
2364 u32 h_control
= kcontrol
->private_value
;
2365 u16 source
, srcindex
= 0;
2368 ucontrol
->value
.enumerated
.item
[0] = 0;
2369 if (hpi_sample_clock_get_source(h_control
, &source
))
2372 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2373 if (hpi_sample_clock_get_source_index(h_control
, &srcindex
))
2376 for (i
= 0; i
< clkcache
->count
; i
++)
2377 if ((clkcache
->s
[i
].source
== source
) &&
2378 (clkcache
->s
[i
].index
== srcindex
))
2381 ucontrol
->value
.enumerated
.item
[0] = i
;
2386 static int snd_asihpi_clksrc_put(struct snd_kcontrol
*kcontrol
,
2387 struct snd_ctl_elem_value
*ucontrol
)
2389 struct snd_card_asihpi
*asihpi
=
2390 (struct snd_card_asihpi
*)(kcontrol
->private_data
);
2391 struct clk_cache
*clkcache
= &asihpi
->cc
;
2393 u32 h_control
= kcontrol
->private_value
;
2396 item
= ucontrol
->value
.enumerated
.item
[0];
2397 if (item
>= clkcache
->count
)
2398 item
= clkcache
->count
-1;
2400 hpi_handle_error(hpi_sample_clock_set_source(
2401 h_control
, clkcache
->s
[item
].source
));
2403 if (clkcache
->s
[item
].source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2404 hpi_handle_error(hpi_sample_clock_set_source_index(
2405 h_control
, clkcache
->s
[item
].index
));
2409 /*------------------------------------------------------------
2411 ------------------------------------------------------------*/
2412 /* Need to change this to enumerated control with list of rates */
2413 static int snd_asihpi_clklocal_info(struct snd_kcontrol
*kcontrol
,
2414 struct snd_ctl_elem_info
*uinfo
)
2416 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2418 uinfo
->value
.integer
.min
= 8000;
2419 uinfo
->value
.integer
.max
= 192000;
2420 uinfo
->value
.integer
.step
= 100;
2425 static int snd_asihpi_clklocal_get(struct snd_kcontrol
*kcontrol
,
2426 struct snd_ctl_elem_value
*ucontrol
)
2428 u32 h_control
= kcontrol
->private_value
;
2432 e
= hpi_sample_clock_get_local_rate(h_control
, &rate
);
2434 ucontrol
->value
.integer
.value
[0] = rate
;
2436 ucontrol
->value
.integer
.value
[0] = 0;
2440 static int snd_asihpi_clklocal_put(struct snd_kcontrol
*kcontrol
,
2441 struct snd_ctl_elem_value
*ucontrol
)
2444 u32 h_control
= kcontrol
->private_value
;
2446 /* change = asihpi->mixer_clkrate[addr][0] != left ||
2447 asihpi->mixer_clkrate[addr][1] != right;
2450 hpi_handle_error(hpi_sample_clock_set_local_rate(h_control
,
2451 ucontrol
->value
.integer
.value
[0]));
2455 static int snd_asihpi_clkrate_info(struct snd_kcontrol
*kcontrol
,
2456 struct snd_ctl_elem_info
*uinfo
)
2458 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2460 uinfo
->value
.integer
.min
= 8000;
2461 uinfo
->value
.integer
.max
= 192000;
2462 uinfo
->value
.integer
.step
= 100;
2467 static int snd_asihpi_clkrate_get(struct snd_kcontrol
*kcontrol
,
2468 struct snd_ctl_elem_value
*ucontrol
)
2470 u32 h_control
= kcontrol
->private_value
;
2474 e
= hpi_sample_clock_get_sample_rate(h_control
, &rate
);
2476 ucontrol
->value
.integer
.value
[0] = rate
;
2478 ucontrol
->value
.integer
.value
[0] = 0;
2482 static int __devinit
snd_asihpi_sampleclock_add(struct snd_card_asihpi
*asihpi
,
2483 struct hpi_control
*hpi_ctl
)
2485 struct snd_card
*card
= asihpi
->card
;
2486 struct snd_kcontrol_new snd_control
;
2488 struct clk_cache
*clkcache
= &asihpi
->cc
;
2489 u32 hSC
= hpi_ctl
->h_control
;
2494 snd_control
.private_value
= hpi_ctl
->h_control
;
2496 clkcache
->has_local
= 0;
2498 for (i
= 0; i
<= HPI_SAMPLECLOCK_SOURCE_LAST
; i
++) {
2499 if (hpi_sample_clock_query_source(hSC
,
2502 clkcache
->s
[i
].source
= source
;
2503 clkcache
->s
[i
].index
= 0;
2504 clkcache
->s
[i
].name
= sampleclock_sources
[source
];
2505 if (source
== HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
)
2507 if (source
== HPI_SAMPLECLOCK_SOURCE_LOCAL
)
2508 clkcache
->has_local
= 1;
2511 /* already will have picked up index 0 above */
2512 for (j
= 1; j
< 8; j
++) {
2513 if (hpi_sample_clock_query_source_index(hSC
,
2514 j
, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
,
2517 clkcache
->s
[i
].source
=
2518 HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT
;
2519 clkcache
->s
[i
].index
= j
;
2520 clkcache
->s
[i
].name
= sampleclock_sources
[
2521 j
+HPI_SAMPLECLOCK_SOURCE_LAST
];
2524 clkcache
->count
= i
;
2526 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Source");
2527 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2528 snd_control
.info
= snd_asihpi_clksrc_info
;
2529 snd_control
.get
= snd_asihpi_clksrc_get
;
2530 snd_control
.put
= snd_asihpi_clksrc_put
;
2531 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2535 if (clkcache
->has_local
) {
2536 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Localrate");
2537 snd_control
.access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
;
2538 snd_control
.info
= snd_asihpi_clklocal_info
;
2539 snd_control
.get
= snd_asihpi_clklocal_get
;
2540 snd_control
.put
= snd_asihpi_clklocal_put
;
2543 if (ctl_add(card
, &snd_control
, asihpi
) < 0)
2547 asihpi_ctl_init(&snd_control
, hpi_ctl
, "Rate");
2548 snd_control
.access
=
2549 SNDRV_CTL_ELEM_ACCESS_VOLATILE
| SNDRV_CTL_ELEM_ACCESS_READ
;
2550 snd_control
.info
= snd_asihpi_clkrate_info
;
2551 snd_control
.get
= snd_asihpi_clkrate_get
;
2553 return ctl_add(card
, &snd_control
, asihpi
);
2555 /*------------------------------------------------------------
2557 ------------------------------------------------------------*/
2559 static int __devinit
snd_card_asihpi_mixer_new(struct snd_card_asihpi
*asihpi
)
2561 struct snd_card
*card
= asihpi
->card
;
2562 unsigned int idx
= 0;
2563 unsigned int subindex
= 0;
2565 struct hpi_control hpi_ctl
, prev_ctl
;
2567 if (snd_BUG_ON(!asihpi
))
2569 strcpy(card
->mixername
, "Asihpi Mixer");
2572 hpi_mixer_open(asihpi
->adapter_index
,
2574 hpi_handle_error(err
);
2578 memset(&prev_ctl
, 0, sizeof(prev_ctl
));
2579 prev_ctl
.control_type
= -1;
2581 for (idx
= 0; idx
< 2000; idx
++) {
2582 err
= hpi_mixer_get_control_by_index(
2585 &hpi_ctl
.src_node_type
,
2586 &hpi_ctl
.src_node_index
,
2587 &hpi_ctl
.dst_node_type
,
2588 &hpi_ctl
.dst_node_index
,
2589 &hpi_ctl
.control_type
,
2590 &hpi_ctl
.h_control
);
2592 if (err
== HPI_ERROR_CONTROL_DISABLED
) {
2594 snd_printk(KERN_INFO
2595 "Disabled HPI Control(%d)\n",
2603 hpi_ctl
.src_node_type
-= HPI_SOURCENODE_NONE
;
2604 hpi_ctl
.dst_node_type
-= HPI_DESTNODE_NONE
;
2606 /* ASI50xx in SSX mode has multiple meters on the same node.
2607 Use subindex to create distinct ALSA controls
2608 for any duplicated controls.
2610 if ((hpi_ctl
.control_type
== prev_ctl
.control_type
) &&
2611 (hpi_ctl
.src_node_type
== prev_ctl
.src_node_type
) &&
2612 (hpi_ctl
.src_node_index
== prev_ctl
.src_node_index
) &&
2613 (hpi_ctl
.dst_node_type
== prev_ctl
.dst_node_type
) &&
2614 (hpi_ctl
.dst_node_index
== prev_ctl
.dst_node_index
))
2621 switch (hpi_ctl
.control_type
) {
2622 case HPI_CONTROL_VOLUME
:
2623 err
= snd_asihpi_volume_add(asihpi
, &hpi_ctl
);
2625 case HPI_CONTROL_LEVEL
:
2626 err
= snd_asihpi_level_add(asihpi
, &hpi_ctl
);
2628 case HPI_CONTROL_MULTIPLEXER
:
2629 err
= snd_asihpi_mux_add(asihpi
, &hpi_ctl
);
2631 case HPI_CONTROL_CHANNEL_MODE
:
2632 err
= snd_asihpi_cmode_add(asihpi
, &hpi_ctl
);
2634 case HPI_CONTROL_METER
:
2635 err
= snd_asihpi_meter_add(asihpi
, &hpi_ctl
, subindex
);
2637 case HPI_CONTROL_SAMPLECLOCK
:
2638 err
= snd_asihpi_sampleclock_add(
2641 case HPI_CONTROL_CONNECTION
: /* ignore these */
2643 case HPI_CONTROL_TUNER
:
2644 err
= snd_asihpi_tuner_add(asihpi
, &hpi_ctl
);
2646 case HPI_CONTROL_AESEBU_TRANSMITTER
:
2647 err
= snd_asihpi_aesebu_tx_add(asihpi
, &hpi_ctl
);
2649 case HPI_CONTROL_AESEBU_RECEIVER
:
2650 err
= snd_asihpi_aesebu_rx_add(asihpi
, &hpi_ctl
);
2652 case HPI_CONTROL_VOX
:
2653 case HPI_CONTROL_BITSTREAM
:
2654 case HPI_CONTROL_MICROPHONE
:
2655 case HPI_CONTROL_PARAMETRIC_EQ
:
2656 case HPI_CONTROL_COMPANDER
:
2659 snd_printk(KERN_INFO
2660 "Untranslated HPI Control"
2661 "(%d) %d %d %d %d %d\n",
2663 hpi_ctl
.control_type
,
2664 hpi_ctl
.src_node_type
,
2665 hpi_ctl
.src_node_index
,
2666 hpi_ctl
.dst_node_type
,
2667 hpi_ctl
.dst_node_index
);
2673 if (HPI_ERROR_INVALID_OBJ_INDEX
!= err
)
2674 hpi_handle_error(err
);
2676 snd_printk(KERN_INFO
"%d mixer controls found\n", idx
);
2681 /*------------------------------------------------------------
2683 ------------------------------------------------------------*/
2686 snd_asihpi_proc_read(struct snd_info_entry
*entry
,
2687 struct snd_info_buffer
*buffer
)
2689 struct snd_card_asihpi
*asihpi
= entry
->private_data
;
2696 snd_iprintf(buffer
, "ASIHPI driver proc file\n");
2698 "adapter ID=%4X\n_index=%d\n"
2699 "num_outstreams=%d\n_num_instreams=%d\n",
2700 asihpi
->type
, asihpi
->adapter_index
,
2701 asihpi
->num_outstreams
, asihpi
->num_instreams
);
2703 version
= asihpi
->version
;
2705 "serial#=%d\n_hw version %c%d\nDSP code version %03d\n",
2706 asihpi
->serial_number
, ((version
>> 3) & 0xf) + 'A',
2708 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2710 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2711 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2712 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2715 err
= hpi_sample_clock_get_sample_rate(
2717 err
+= hpi_sample_clock_get_source(h_control
, &source
);
2720 snd_iprintf(buffer
, "sample_clock=%d_hz, source %s\n",
2721 rate
, sampleclock_sources
[source
]);
2727 static void __devinit
snd_asihpi_proc_init(struct snd_card_asihpi
*asihpi
)
2729 struct snd_info_entry
*entry
;
2731 if (!snd_card_proc_new(asihpi
->card
, "info", &entry
))
2732 snd_info_set_text_ops(entry
, asihpi
, snd_asihpi_proc_read
);
2735 /*------------------------------------------------------------
2737 ------------------------------------------------------------*/
2739 static int snd_asihpi_hpi_open(struct snd_hwdep
*hw
, struct file
*file
)
2741 if (enable_hpi_hwdep
)
2748 static int snd_asihpi_hpi_release(struct snd_hwdep
*hw
, struct file
*file
)
2750 if (enable_hpi_hwdep
)
2751 return asihpi_hpi_release(file
);
2756 static int snd_asihpi_hpi_ioctl(struct snd_hwdep
*hw
, struct file
*file
,
2757 unsigned int cmd
, unsigned long arg
)
2759 if (enable_hpi_hwdep
)
2760 return asihpi_hpi_ioctl(file
, cmd
, arg
);
2766 /* results in /dev/snd/hwC#D0 file for each card with index #
2767 also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
2769 static int __devinit
snd_asihpi_hpi_new(struct snd_card_asihpi
*asihpi
,
2770 int device
, struct snd_hwdep
**rhwdep
)
2772 struct snd_hwdep
*hw
;
2777 err
= snd_hwdep_new(asihpi
->card
, "HPI", device
, &hw
);
2780 strcpy(hw
->name
, "asihpi (HPI)");
2781 hw
->iface
= SNDRV_HWDEP_IFACE_LAST
;
2782 hw
->ops
.open
= snd_asihpi_hpi_open
;
2783 hw
->ops
.ioctl
= snd_asihpi_hpi_ioctl
;
2784 hw
->ops
.release
= snd_asihpi_hpi_release
;
2785 hw
->private_data
= asihpi
;
2791 /*------------------------------------------------------------
2793 ------------------------------------------------------------*/
2794 static int __devinit
snd_asihpi_probe(struct pci_dev
*pci_dev
,
2795 const struct pci_device_id
*pci_id
)
2802 struct hpi_adapter
*hpi_card
;
2803 struct snd_card
*card
;
2804 struct snd_card_asihpi
*asihpi
;
2810 if (dev
>= SNDRV_CARDS
)
2813 /* Should this be enable[hpi_card->index] ? */
2819 err
= asihpi_adapter_probe(pci_dev
, pci_id
);
2823 hpi_card
= pci_get_drvdata(pci_dev
);
2824 /* first try to give the card the same index as its hardware index */
2825 err
= snd_card_create(hpi_card
->index
,
2826 id
[hpi_card
->index
], THIS_MODULE
,
2827 sizeof(struct snd_card_asihpi
),
2830 /* if that fails, try the default index==next available */
2832 snd_card_create(index
[dev
], id
[dev
],
2834 sizeof(struct snd_card_asihpi
),
2838 snd_printk(KERN_WARNING
2839 "**** WARNING **** Adapter index %d->ALSA index %d\n",
2840 hpi_card
->index
, card
->number
);
2843 asihpi
= (struct snd_card_asihpi
*) card
->private_data
;
2844 asihpi
->card
= card
;
2845 asihpi
->pci
= hpi_card
->pci
;
2846 asihpi
->adapter_index
= hpi_card
->index
;
2847 hpi_handle_error(hpi_adapter_get_info(
2848 asihpi
->adapter_index
,
2849 &asihpi
->num_outstreams
,
2850 &asihpi
->num_instreams
,
2852 &asihpi
->serial_number
, &asihpi
->type
));
2854 version
= asihpi
->version
;
2855 snd_printk(KERN_INFO
"adapter ID=%4X index=%d num_outstreams=%d "
2856 "num_instreams=%d S/N=%d\n"
2857 "Hw Version %c%d DSP code version %03d\n",
2858 asihpi
->type
, asihpi
->adapter_index
,
2859 asihpi
->num_outstreams
,
2860 asihpi
->num_instreams
, asihpi
->serial_number
,
2861 ((version
>> 3) & 0xf) + 'A',
2863 ((version
>> 13) * 100) + ((version
>> 7) & 0x3f));
2865 pcm_substreams
= asihpi
->num_outstreams
;
2866 if (pcm_substreams
< asihpi
->num_instreams
)
2867 pcm_substreams
= asihpi
->num_instreams
;
2869 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2870 HPI_ADAPTER_PROPERTY_CAPS1
,
2871 NULL
, &asihpi
->support_grouping
);
2873 asihpi
->support_grouping
= 0;
2875 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2876 HPI_ADAPTER_PROPERTY_CAPS2
,
2877 &asihpi
->support_mrx
, NULL
);
2879 asihpi
->support_mrx
= 0;
2881 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2882 HPI_ADAPTER_PROPERTY_INTERVAL
,
2883 NULL
, &asihpi
->update_interval_frames
);
2885 asihpi
->update_interval_frames
= 512;
2887 hpi_handle_error(hpi_instream_open(asihpi
->adapter_index
,
2890 err
= hpi_instream_host_buffer_free(h_stream
);
2891 asihpi
->support_mmap
= (!err
);
2893 hpi_handle_error(hpi_instream_close(h_stream
));
2895 err
= hpi_adapter_get_property(asihpi
->adapter_index
,
2896 HPI_ADAPTER_PROPERTY_CURCHANNELS
,
2897 &asihpi
->in_max_chans
, &asihpi
->out_max_chans
);
2899 asihpi
->in_max_chans
= 2;
2900 asihpi
->out_max_chans
= 2;
2903 snd_printk(KERN_INFO
"supports mmap:%d grouping:%d mrx:%d\n",
2904 asihpi
->support_mmap
,
2905 asihpi
->support_grouping
,
2910 err
= snd_card_asihpi_pcm_new(asihpi
, 0, pcm_substreams
);
2912 snd_printk(KERN_ERR
"pcm_new failed\n");
2915 err
= snd_card_asihpi_mixer_new(asihpi
);
2917 snd_printk(KERN_ERR
"mixer_new failed\n");
2921 err
= hpi_mixer_get_control(asihpi
->h_mixer
,
2922 HPI_SOURCENODE_CLOCK_SOURCE
, 0, 0, 0,
2923 HPI_CONTROL_SAMPLECLOCK
, &h_control
);
2926 err
= hpi_sample_clock_set_local_rate(
2927 h_control
, adapter_fs
);
2929 snd_asihpi_proc_init(asihpi
);
2931 /* always create, can be enabled or disabled dynamically
2932 by enable_hwdep module param*/
2933 snd_asihpi_hpi_new(asihpi
, 0, NULL
);
2935 if (asihpi
->support_mmap
)
2936 strcpy(card
->driver
, "ASIHPI-MMAP");
2938 strcpy(card
->driver
, "ASIHPI");
2940 sprintf(card
->shortname
, "AudioScience ASI%4X", asihpi
->type
);
2941 sprintf(card
->longname
, "%s %i",
2942 card
->shortname
, asihpi
->adapter_index
);
2943 err
= snd_card_register(card
);
2945 hpi_card
->snd_card_asihpi
= card
;
2950 snd_card_free(card
);
2951 snd_printk(KERN_ERR
"snd_asihpi_probe error %d\n", err
);
2956 static void __devexit
snd_asihpi_remove(struct pci_dev
*pci_dev
)
2958 struct hpi_adapter
*hpi_card
= pci_get_drvdata(pci_dev
);
2960 snd_card_free(hpi_card
->snd_card_asihpi
);
2961 hpi_card
->snd_card_asihpi
= NULL
;
2962 asihpi_adapter_remove(pci_dev
);
2965 static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl
) = {
2966 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_DSP6205
,
2967 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2968 (kernel_ulong_t
)HPI_6205
},
2969 {HPI_PCI_VENDOR_ID_TI
, HPI_PCI_DEV_ID_PCI2040
,
2970 HPI_PCI_VENDOR_ID_AUDIOSCIENCE
, PCI_ANY_ID
, 0, 0,
2971 (kernel_ulong_t
)HPI_6000
},
2974 MODULE_DEVICE_TABLE(pci
, asihpi_pci_tbl
);
2976 static struct pci_driver driver
= {
2978 .id_table
= asihpi_pci_tbl
,
2979 .probe
= snd_asihpi_probe
,
2980 .remove
= __devexit_p(snd_asihpi_remove
),
2982 /* .suspend = snd_asihpi_suspend,
2983 .resume = snd_asihpi_resume, */
2987 static int __init
snd_asihpi_init(void)
2990 return pci_register_driver(&driver
);
2993 static void __exit
snd_asihpi_exit(void)
2996 pci_unregister_driver(&driver
);
3000 module_init(snd_asihpi_init
)
3001 module_exit(snd_asihpi_exit
)