blob: 9e39e509a3ef9375db81b853b8e61983a4de9c9c [file] [log] [blame]
Markus Bollingere12229b2005-12-06 13:55:26 +01001/*
2 * Driver for Digigram pcxhr soundcards
3 *
4 * main header file
5 *
6 * Copyright (c) 2004 by Digigram <alsa@digigram.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __SOUND_PCXHR_H
24#define __SOUND_PCXHR_H
25
26#include <linux/interrupt.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010027#include <linux/mutex.h>
Markus Bollingere12229b2005-12-06 13:55:26 +010028#include <sound/pcm.h>
29
Markus Bollinger55aef452009-01-23 14:45:41 +010030#define PCXHR_DRIVER_VERSION 0x000906 /* 0.9.6 */
31#define PCXHR_DRIVER_VERSION_STRING "0.9.6" /* 0.9.6 */
Markus Bollingere12229b2005-12-06 13:55:26 +010032
33
Markus Bollinger9d948d22008-11-25 12:24:54 +010034#define PCXHR_MAX_CARDS 6
35#define PCXHR_PLAYBACK_STREAMS 4
Markus Bollingere12229b2005-12-06 13:55:26 +010036
Markus Bollinger9d948d22008-11-25 12:24:54 +010037#define PCXHR_GRANULARITY 96 /* min 96 and multiple of 48 */
38/* transfer granularity of pipes and the dsp time (MBOX4) */
39#define PCXHR_GRANULARITY_MIN 96
40/* TODO : granularity could be 64 or 128 */
41#define PCXHR_GRANULARITY_HR22 192 /* granularity for stereo cards */
Markus Bollingere12229b2005-12-06 13:55:26 +010042
43struct snd_pcxhr;
44struct pcxhr_mgr;
45
46struct pcxhr_stream;
47struct pcxhr_pipe;
48
49enum pcxhr_clock_type {
50 PCXHR_CLOCK_TYPE_INTERNAL = 0,
51 PCXHR_CLOCK_TYPE_WORD_CLOCK,
52 PCXHR_CLOCK_TYPE_AES_SYNC,
53 PCXHR_CLOCK_TYPE_AES_1,
54 PCXHR_CLOCK_TYPE_AES_2,
55 PCXHR_CLOCK_TYPE_AES_3,
56 PCXHR_CLOCK_TYPE_AES_4,
Markus Bollinger9d948d22008-11-25 12:24:54 +010057 PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
58 HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
59 HR22_CLOCK_TYPE_AES_SYNC,
60 HR22_CLOCK_TYPE_AES_1,
61 HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
Markus Bollingere12229b2005-12-06 13:55:26 +010062};
63
64struct pcxhr_mgr {
65 unsigned int num_cards;
66 struct snd_pcxhr *chip[PCXHR_MAX_CARDS];
67
68 struct pci_dev *pci;
69
70 int irq;
71
Markus Bollinger9d948d22008-11-25 12:24:54 +010072 int granularity;
73
Markus Bollingere12229b2005-12-06 13:55:26 +010074 /* card access with 1 mem bar and 2 io bar's */
75 unsigned long port[3];
76
77 /* share the name */
78 char shortname[32]; /* short name of this soundcard */
79 char longname[96]; /* name of this soundcard */
80
Markus Bollingere12229b2005-12-06 13:55:26 +010081 struct pcxhr_rmh *prmh;
Markus Bollingere12229b2005-12-06 13:55:26 +010082
Takashi Iwai9bef72b2014-09-10 12:21:38 +020083 struct mutex lock; /* interrupt lock */
84 struct mutex msg_lock; /* message lock */
Markus Bollingere12229b2005-12-06 13:55:26 +010085
Ingo Molnar62932df2006-01-16 16:34:20 +010086 struct mutex setup_mutex; /* mutex used in hw_params, open and close */
87 struct mutex mixer_mutex; /* mutex for mixer */
Markus Bollingere12229b2005-12-06 13:55:26 +010088
89 /* hardware interface */
90 unsigned int dsp_loaded; /* bit flags of loaded dsp indices */
91 unsigned int dsp_version; /* read from embedded once firmware is loaded */
Markus Bollinger9d948d22008-11-25 12:24:54 +010092 int playback_chips;
93 int capture_chips;
94 int fw_file_set;
95 int firmware_num;
Harvey Harrisone32740d9782009-02-19 11:58:37 -080096 unsigned int is_hr_stereo:1;
97 unsigned int board_has_aes1:1; /* if 1 board has AES1 plug and SRC */
98 unsigned int board_has_analog:1; /* if 0 the board is digital only */
99 unsigned int board_has_mic:1; /* if 1 the board has microphone input */
100 unsigned int board_aes_in_192k:1;/* if 1 the aes input plugs do support 192kHz */
101 unsigned int mono_capture:1; /* if 1 the board does mono capture */
Markus Bollingerfdfbaf62012-06-20 08:34:40 +0200102 unsigned int capture_ltc:1; /* if 1 the board captures LTC input */
Markus Bollingere12229b2005-12-06 13:55:26 +0100103
104 struct snd_dma_buffer hostport;
105
106 enum pcxhr_clock_type use_clock_type; /* clock type selected by mixer */
107 enum pcxhr_clock_type cur_clock_type; /* current clock type synced */
108 int sample_rate;
109 int ref_count_rate;
110 int timer_toggle; /* timer interrupt toggles between the two values 0x200 and 0x300 */
111 int dsp_time_last; /* the last dsp time (read by interrupt) */
112 int dsp_time_err; /* dsp time errors */
113 unsigned int src_it_dsp; /* dsp interrupt source */
114 unsigned int io_num_reg_cont; /* backup of IO_NUM_REG_CONT */
115 unsigned int codec_speed; /* speed mode of the codecs */
116 unsigned int sample_rate_real; /* current real sample rate */
117 int last_reg_stat;
118 int async_err_stream_xrun;
119 int async_err_pipe_xrun;
120 int async_err_other_last;
Markus Bollinger9d948d22008-11-25 12:24:54 +0100121
122 unsigned char xlx_cfg; /* copy of PCXHR_XLX_CFG register */
123 unsigned char xlx_selmic; /* copy of PCXHR_XLX_SELMIC register */
Markus Bollinger55aef452009-01-23 14:45:41 +0100124 unsigned char dsp_reset; /* copy of PCXHR_DSP_RESET register */
Markus Bollingere12229b2005-12-06 13:55:26 +0100125};
126
127
128enum pcxhr_stream_status {
129 PCXHR_STREAM_STATUS_FREE,
130 PCXHR_STREAM_STATUS_OPEN,
131 PCXHR_STREAM_STATUS_SCHEDULE_RUN,
132 PCXHR_STREAM_STATUS_STARTED,
133 PCXHR_STREAM_STATUS_RUNNING,
134 PCXHR_STREAM_STATUS_SCHEDULE_STOP,
135 PCXHR_STREAM_STATUS_STOPPED,
136 PCXHR_STREAM_STATUS_PAUSED
137};
138
139struct pcxhr_stream {
140 struct snd_pcm_substream *substream;
141 snd_pcm_format_t format;
142 struct pcxhr_pipe *pipe;
143
144 enum pcxhr_stream_status status; /* free, open, running, draining, pause */
145
146 u_int64_t timer_abs_periods; /* timer: samples elapsed since TRIGGER_START (multiple of period_size) */
147 u_int32_t timer_period_frag; /* timer: samples elapsed since last call to snd_pcm_period_elapsed (0..period_size) */
148 u_int32_t timer_buf_periods; /* nb of periods in the buffer that have already elapsed */
149 int timer_is_synced; /* if(0) : timer needs to be resynced with real hardware pointer */
150
151 int channels;
152};
153
154
155enum pcxhr_pipe_status {
156 PCXHR_PIPE_UNDEFINED,
157 PCXHR_PIPE_DEFINED
158};
159
160struct pcxhr_pipe {
161 enum pcxhr_pipe_status status;
162 int is_capture; /* this is a capture pipe */
163 int first_audio; /* first audio num */
164};
165
166
167struct snd_pcxhr {
168 struct snd_card *card;
169 struct pcxhr_mgr *mgr;
170 int chip_idx; /* zero based */
171
172 struct snd_pcm *pcm; /* PCM */
173
Markus Bollinger9d948d22008-11-25 12:24:54 +0100174 struct pcxhr_pipe playback_pipe; /* 1 stereo pipe only */
175 struct pcxhr_pipe capture_pipe[2]; /* 1 stereo or 2 mono pipes */
Markus Bollingere12229b2005-12-06 13:55:26 +0100176
177 struct pcxhr_stream playback_stream[PCXHR_PLAYBACK_STREAMS];
Markus Bollinger9d948d22008-11-25 12:24:54 +0100178 struct pcxhr_stream capture_stream[2]; /* 1 stereo or 2 mono streams */
Markus Bollingere12229b2005-12-06 13:55:26 +0100179 int nb_streams_play;
180 int nb_streams_capt;
181
Markus Bollinger9d948d22008-11-25 12:24:54 +0100182 int analog_playback_active[2]; /* Mixer : Master Playback !mute */
183 int analog_playback_volume[2]; /* Mixer : Master Playback Volume */
184 int analog_capture_volume[2]; /* Mixer : Master Capture Volume */
185 int digital_playback_active[PCXHR_PLAYBACK_STREAMS][2];
186 int digital_playback_volume[PCXHR_PLAYBACK_STREAMS][2];
187 int digital_capture_volume[2]; /* Mixer : Digital Capture Volume */
188 int monitoring_active[2]; /* Mixer : Monitoring Active */
189 int monitoring_volume[2]; /* Mixer : Monitoring Volume */
190 int audio_capture_source; /* Mixer : Audio Capture Source */
191 int mic_volume; /* used by cards with MIC only */
192 int mic_boost; /* used by cards with MIC only */
193 int mic_active; /* used by cards with MIC only */
194 int analog_capture_active; /* used by cards with MIC only */
195 int phantom_power; /* used by cards with MIC only */
196
197 unsigned char aes_bits[5]; /* Mixer : IEC958_AES bits */
Markus Bollingere12229b2005-12-06 13:55:26 +0100198};
199
200struct pcxhr_hostport
201{
202 char purgebuffer[6];
203 char reserved[2];
204};
205
206/* exported */
207int pcxhr_create_pcm(struct snd_pcxhr *chip);
208int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate);
Markus Bollinger9d948d22008-11-25 12:24:54 +0100209int pcxhr_get_external_clock(struct pcxhr_mgr *mgr,
210 enum pcxhr_clock_type clock_type,
211 int *sample_rate);
Markus Bollingere12229b2005-12-06 13:55:26 +0100212
213#endif /* __SOUND_PCXHR_H */