1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Driver for Digigram pcxhr soundcards 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * main header file 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * Copyright (c) 2004 by Digigram <alsa@digigram.com> 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #ifndef __SOUND_PCXHR_H 11*4882a593Smuzhiyun #define __SOUND_PCXHR_H 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #include <linux/interrupt.h> 14*4882a593Smuzhiyun #include <linux/mutex.h> 15*4882a593Smuzhiyun #include <sound/pcm.h> 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun #define PCXHR_DRIVER_VERSION 0x000906 /* 0.9.6 */ 18*4882a593Smuzhiyun #define PCXHR_DRIVER_VERSION_STRING "0.9.6" /* 0.9.6 */ 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun #define PCXHR_MAX_CARDS 6 22*4882a593Smuzhiyun #define PCXHR_PLAYBACK_STREAMS 4 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #define PCXHR_GRANULARITY 96 /* min 96 and multiple of 48 */ 25*4882a593Smuzhiyun /* transfer granularity of pipes and the dsp time (MBOX4) */ 26*4882a593Smuzhiyun #define PCXHR_GRANULARITY_MIN 96 27*4882a593Smuzhiyun /* TODO : granularity could be 64 or 128 */ 28*4882a593Smuzhiyun #define PCXHR_GRANULARITY_HR22 192 /* granularity for stereo cards */ 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun struct snd_pcxhr; 31*4882a593Smuzhiyun struct pcxhr_mgr; 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun struct pcxhr_stream; 34*4882a593Smuzhiyun struct pcxhr_pipe; 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun enum pcxhr_clock_type { 37*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_INTERNAL = 0, 38*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_WORD_CLOCK, 39*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_AES_SYNC, 40*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_AES_1, 41*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_AES_2, 42*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_AES_3, 43*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_AES_4, 44*4882a593Smuzhiyun PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4, 45*4882a593Smuzhiyun HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL, 46*4882a593Smuzhiyun HR22_CLOCK_TYPE_AES_SYNC, 47*4882a593Smuzhiyun HR22_CLOCK_TYPE_AES_1, 48*4882a593Smuzhiyun HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1, 49*4882a593Smuzhiyun }; 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun struct pcxhr_mgr { 52*4882a593Smuzhiyun unsigned int num_cards; 53*4882a593Smuzhiyun struct snd_pcxhr *chip[PCXHR_MAX_CARDS]; 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun struct pci_dev *pci; 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun int irq; 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun int granularity; 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun /* card access with 1 mem bar and 2 io bar's */ 62*4882a593Smuzhiyun unsigned long port[3]; 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun /* share the name */ 65*4882a593Smuzhiyun char name[40]; /* name of this soundcard */ 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun struct pcxhr_rmh *prmh; 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun struct mutex lock; /* interrupt lock */ 70*4882a593Smuzhiyun struct mutex msg_lock; /* message lock */ 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun struct mutex setup_mutex; /* mutex used in hw_params, open and close */ 73*4882a593Smuzhiyun struct mutex mixer_mutex; /* mutex for mixer */ 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun /* hardware interface */ 76*4882a593Smuzhiyun unsigned int dsp_loaded; /* bit flags of loaded dsp indices */ 77*4882a593Smuzhiyun unsigned int dsp_version; /* read from embedded once firmware is loaded */ 78*4882a593Smuzhiyun int playback_chips; 79*4882a593Smuzhiyun int capture_chips; 80*4882a593Smuzhiyun int fw_file_set; 81*4882a593Smuzhiyun int firmware_num; 82*4882a593Smuzhiyun unsigned int is_hr_stereo:1; 83*4882a593Smuzhiyun unsigned int board_has_aes1:1; /* if 1 board has AES1 plug and SRC */ 84*4882a593Smuzhiyun unsigned int board_has_analog:1; /* if 0 the board is digital only */ 85*4882a593Smuzhiyun unsigned int board_has_mic:1; /* if 1 the board has microphone input */ 86*4882a593Smuzhiyun unsigned int board_aes_in_192k:1;/* if 1 the aes input plugs do support 192kHz */ 87*4882a593Smuzhiyun unsigned int mono_capture:1; /* if 1 the board does mono capture */ 88*4882a593Smuzhiyun unsigned int capture_ltc:1; /* if 1 the board captures LTC input */ 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun struct snd_dma_buffer hostport; 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun enum pcxhr_clock_type use_clock_type; /* clock type selected by mixer */ 93*4882a593Smuzhiyun enum pcxhr_clock_type cur_clock_type; /* current clock type synced */ 94*4882a593Smuzhiyun int sample_rate; 95*4882a593Smuzhiyun int ref_count_rate; 96*4882a593Smuzhiyun int timer_toggle; /* timer interrupt toggles between the two values 0x200 and 0x300 */ 97*4882a593Smuzhiyun int dsp_time_last; /* the last dsp time (read by interrupt) */ 98*4882a593Smuzhiyun int dsp_time_err; /* dsp time errors */ 99*4882a593Smuzhiyun unsigned int src_it_dsp; /* dsp interrupt source */ 100*4882a593Smuzhiyun unsigned int io_num_reg_cont; /* backup of IO_NUM_REG_CONT */ 101*4882a593Smuzhiyun unsigned int codec_speed; /* speed mode of the codecs */ 102*4882a593Smuzhiyun unsigned int sample_rate_real; /* current real sample rate */ 103*4882a593Smuzhiyun int last_reg_stat; 104*4882a593Smuzhiyun int async_err_stream_xrun; 105*4882a593Smuzhiyun int async_err_pipe_xrun; 106*4882a593Smuzhiyun int async_err_other_last; 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun unsigned char xlx_cfg; /* copy of PCXHR_XLX_CFG register */ 109*4882a593Smuzhiyun unsigned char xlx_selmic; /* copy of PCXHR_XLX_SELMIC register */ 110*4882a593Smuzhiyun unsigned char dsp_reset; /* copy of PCXHR_DSP_RESET register */ 111*4882a593Smuzhiyun }; 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun enum pcxhr_stream_status { 115*4882a593Smuzhiyun PCXHR_STREAM_STATUS_FREE, 116*4882a593Smuzhiyun PCXHR_STREAM_STATUS_OPEN, 117*4882a593Smuzhiyun PCXHR_STREAM_STATUS_SCHEDULE_RUN, 118*4882a593Smuzhiyun PCXHR_STREAM_STATUS_STARTED, 119*4882a593Smuzhiyun PCXHR_STREAM_STATUS_RUNNING, 120*4882a593Smuzhiyun PCXHR_STREAM_STATUS_SCHEDULE_STOP, 121*4882a593Smuzhiyun PCXHR_STREAM_STATUS_STOPPED, 122*4882a593Smuzhiyun PCXHR_STREAM_STATUS_PAUSED 123*4882a593Smuzhiyun }; 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun struct pcxhr_stream { 126*4882a593Smuzhiyun struct snd_pcm_substream *substream; 127*4882a593Smuzhiyun snd_pcm_format_t format; 128*4882a593Smuzhiyun struct pcxhr_pipe *pipe; 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun enum pcxhr_stream_status status; /* free, open, running, draining, pause */ 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun u_int64_t timer_abs_periods; /* timer: samples elapsed since TRIGGER_START (multiple of period_size) */ 133*4882a593Smuzhiyun u_int32_t timer_period_frag; /* timer: samples elapsed since last call to snd_pcm_period_elapsed (0..period_size) */ 134*4882a593Smuzhiyun u_int32_t timer_buf_periods; /* nb of periods in the buffer that have already elapsed */ 135*4882a593Smuzhiyun int timer_is_synced; /* if(0) : timer needs to be resynced with real hardware pointer */ 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun int channels; 138*4882a593Smuzhiyun }; 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun enum pcxhr_pipe_status { 142*4882a593Smuzhiyun PCXHR_PIPE_UNDEFINED, 143*4882a593Smuzhiyun PCXHR_PIPE_DEFINED 144*4882a593Smuzhiyun }; 145*4882a593Smuzhiyun 146*4882a593Smuzhiyun struct pcxhr_pipe { 147*4882a593Smuzhiyun enum pcxhr_pipe_status status; 148*4882a593Smuzhiyun int is_capture; /* this is a capture pipe */ 149*4882a593Smuzhiyun int first_audio; /* first audio num */ 150*4882a593Smuzhiyun }; 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun struct snd_pcxhr { 154*4882a593Smuzhiyun struct snd_card *card; 155*4882a593Smuzhiyun struct pcxhr_mgr *mgr; 156*4882a593Smuzhiyun int chip_idx; /* zero based */ 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun struct snd_pcm *pcm; /* PCM */ 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun struct pcxhr_pipe playback_pipe; /* 1 stereo pipe only */ 161*4882a593Smuzhiyun struct pcxhr_pipe capture_pipe[2]; /* 1 stereo or 2 mono pipes */ 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun struct pcxhr_stream playback_stream[PCXHR_PLAYBACK_STREAMS]; 164*4882a593Smuzhiyun struct pcxhr_stream capture_stream[2]; /* 1 stereo or 2 mono streams */ 165*4882a593Smuzhiyun int nb_streams_play; 166*4882a593Smuzhiyun int nb_streams_capt; 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun int analog_playback_active[2]; /* Mixer : Master Playback !mute */ 169*4882a593Smuzhiyun int analog_playback_volume[2]; /* Mixer : Master Playback Volume */ 170*4882a593Smuzhiyun int analog_capture_volume[2]; /* Mixer : Master Capture Volume */ 171*4882a593Smuzhiyun int digital_playback_active[PCXHR_PLAYBACK_STREAMS][2]; 172*4882a593Smuzhiyun int digital_playback_volume[PCXHR_PLAYBACK_STREAMS][2]; 173*4882a593Smuzhiyun int digital_capture_volume[2]; /* Mixer : Digital Capture Volume */ 174*4882a593Smuzhiyun int monitoring_active[2]; /* Mixer : Monitoring Active */ 175*4882a593Smuzhiyun int monitoring_volume[2]; /* Mixer : Monitoring Volume */ 176*4882a593Smuzhiyun int audio_capture_source; /* Mixer : Audio Capture Source */ 177*4882a593Smuzhiyun int mic_volume; /* used by cards with MIC only */ 178*4882a593Smuzhiyun int mic_boost; /* used by cards with MIC only */ 179*4882a593Smuzhiyun int mic_active; /* used by cards with MIC only */ 180*4882a593Smuzhiyun int analog_capture_active; /* used by cards with MIC only */ 181*4882a593Smuzhiyun int phantom_power; /* used by cards with MIC only */ 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun unsigned char aes_bits[5]; /* Mixer : IEC958_AES bits */ 184*4882a593Smuzhiyun }; 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun struct pcxhr_hostport 187*4882a593Smuzhiyun { 188*4882a593Smuzhiyun char purgebuffer[6]; 189*4882a593Smuzhiyun char reserved[2]; 190*4882a593Smuzhiyun }; 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun /* exported */ 193*4882a593Smuzhiyun int pcxhr_create_pcm(struct snd_pcxhr *chip); 194*4882a593Smuzhiyun int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate); 195*4882a593Smuzhiyun int pcxhr_get_external_clock(struct pcxhr_mgr *mgr, 196*4882a593Smuzhiyun enum pcxhr_clock_type clock_type, 197*4882a593Smuzhiyun int *sample_rate); 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun #endif /* __SOUND_PCXHR_H */ 200