Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Driver for Digigram pcxhr soundcards
0004  *
0005  * main header file
0006  *
0007  * Copyright (c) 2004 by Digigram <alsa@digigram.com>
0008  */
0009 
0010 #ifndef __SOUND_PCXHR_H
0011 #define __SOUND_PCXHR_H
0012 
0013 #include <linux/interrupt.h>
0014 #include <linux/mutex.h>
0015 #include <sound/pcm.h>
0016 
0017 #define PCXHR_DRIVER_VERSION        0x000906    /* 0.9.6 */
0018 #define PCXHR_DRIVER_VERSION_STRING "0.9.6"     /* 0.9.6 */
0019 
0020 
0021 #define PCXHR_MAX_CARDS     6
0022 #define PCXHR_PLAYBACK_STREAMS  4
0023 
0024 #define PCXHR_GRANULARITY   96  /* min 96 and multiple of 48 */
0025 /* transfer granularity of pipes and the dsp time (MBOX4) */
0026 #define PCXHR_GRANULARITY_MIN   96
0027 /* TODO : granularity could be 64 or 128 */
0028 #define PCXHR_GRANULARITY_HR22  192 /* granularity for stereo cards */
0029 
0030 struct snd_pcxhr;
0031 struct pcxhr_mgr;
0032 
0033 struct pcxhr_stream;
0034 struct pcxhr_pipe;
0035 
0036 enum pcxhr_clock_type {
0037     PCXHR_CLOCK_TYPE_INTERNAL = 0,
0038     PCXHR_CLOCK_TYPE_WORD_CLOCK,
0039     PCXHR_CLOCK_TYPE_AES_SYNC,
0040     PCXHR_CLOCK_TYPE_AES_1,
0041     PCXHR_CLOCK_TYPE_AES_2,
0042     PCXHR_CLOCK_TYPE_AES_3,
0043     PCXHR_CLOCK_TYPE_AES_4,
0044     PCXHR_CLOCK_TYPE_MAX = PCXHR_CLOCK_TYPE_AES_4,
0045     HR22_CLOCK_TYPE_INTERNAL = PCXHR_CLOCK_TYPE_INTERNAL,
0046     HR22_CLOCK_TYPE_AES_SYNC,
0047     HR22_CLOCK_TYPE_AES_1,
0048     HR22_CLOCK_TYPE_MAX = HR22_CLOCK_TYPE_AES_1,
0049 };
0050 
0051 struct pcxhr_mgr {
0052     unsigned int num_cards;
0053     struct snd_pcxhr *chip[PCXHR_MAX_CARDS];
0054 
0055     struct pci_dev *pci;
0056 
0057     int irq;
0058 
0059     int granularity;
0060 
0061     /* card access with 1 mem bar and 2 io bar's */
0062     unsigned long port[3];
0063 
0064     /* share the name */
0065     char name[40];          /* name of this soundcard */
0066 
0067     struct pcxhr_rmh *prmh;
0068 
0069     struct mutex lock;      /* interrupt lock */
0070     struct mutex msg_lock;      /* message lock */
0071 
0072     struct mutex setup_mutex;   /* mutex used in hw_params, open and close */
0073     struct mutex mixer_mutex;   /* mutex for mixer */
0074 
0075     /* hardware interface */
0076     unsigned int dsp_loaded;    /* bit flags of loaded dsp indices */
0077     unsigned int dsp_version;   /* read from embedded once firmware is loaded */
0078     int playback_chips;
0079     int capture_chips;
0080     int fw_file_set;
0081     int firmware_num;
0082     unsigned int is_hr_stereo:1;
0083     unsigned int board_has_aes1:1;  /* if 1 board has AES1 plug and SRC */
0084     unsigned int board_has_analog:1; /* if 0 the board is digital only */
0085     unsigned int board_has_mic:1; /* if 1 the board has microphone input */
0086     unsigned int board_aes_in_192k:1;/* if 1 the aes input plugs do support 192kHz */
0087     unsigned int mono_capture:1; /* if 1 the board does mono capture */
0088     unsigned int capture_ltc:1; /* if 1 the board captures LTC input */
0089 
0090     struct snd_dma_buffer hostport;
0091 
0092     enum pcxhr_clock_type use_clock_type;   /* clock type selected by mixer */
0093     enum pcxhr_clock_type cur_clock_type;   /* current clock type synced */
0094     int sample_rate;
0095     int ref_count_rate;
0096     int timer_toggle;       /* timer interrupt toggles between the two values 0x200 and 0x300 */
0097     int dsp_time_last;      /* the last dsp time (read by interrupt) */
0098     int dsp_time_err;       /* dsp time errors */
0099     unsigned int src_it_dsp;    /* dsp interrupt source */
0100     unsigned int io_num_reg_cont;   /* backup of IO_NUM_REG_CONT */
0101     unsigned int codec_speed;   /* speed mode of the codecs */
0102     unsigned int sample_rate_real;  /* current real sample rate */
0103     int last_reg_stat;
0104     int async_err_stream_xrun;
0105     int async_err_pipe_xrun;
0106     int async_err_other_last;
0107 
0108     unsigned char xlx_cfg;      /* copy of PCXHR_XLX_CFG register */
0109     unsigned char xlx_selmic;   /* copy of PCXHR_XLX_SELMIC register */
0110     unsigned char dsp_reset;    /* copy of PCXHR_DSP_RESET register */
0111 };
0112 
0113 
0114 enum pcxhr_stream_status {
0115     PCXHR_STREAM_STATUS_FREE,
0116     PCXHR_STREAM_STATUS_OPEN,
0117     PCXHR_STREAM_STATUS_SCHEDULE_RUN,
0118     PCXHR_STREAM_STATUS_STARTED,
0119     PCXHR_STREAM_STATUS_RUNNING,
0120     PCXHR_STREAM_STATUS_SCHEDULE_STOP,
0121     PCXHR_STREAM_STATUS_STOPPED,
0122     PCXHR_STREAM_STATUS_PAUSED
0123 };
0124 
0125 struct pcxhr_stream {
0126     struct snd_pcm_substream *substream;
0127     snd_pcm_format_t format;
0128     struct pcxhr_pipe *pipe;
0129 
0130     enum pcxhr_stream_status status;    /* free, open, running, draining, pause */
0131 
0132     u_int64_t timer_abs_periods;    /* timer: samples elapsed since TRIGGER_START (multiple of period_size) */
0133     u_int32_t timer_period_frag;    /* timer: samples elapsed since last call to snd_pcm_period_elapsed (0..period_size) */
0134     u_int32_t timer_buf_periods;    /* nb of periods in the buffer that have already elapsed */
0135     int timer_is_synced;        /* if(0) : timer needs to be resynced with real hardware pointer */
0136 
0137     int channels;
0138 };
0139 
0140 
0141 enum pcxhr_pipe_status {
0142     PCXHR_PIPE_UNDEFINED,
0143     PCXHR_PIPE_DEFINED
0144 };
0145 
0146 struct pcxhr_pipe {
0147     enum pcxhr_pipe_status status;
0148     int is_capture;     /* this is a capture pipe */
0149     int first_audio;    /* first audio num */
0150 };
0151 
0152 
0153 struct snd_pcxhr {
0154     struct snd_card *card;
0155     struct pcxhr_mgr *mgr;
0156     int chip_idx;       /* zero based */
0157 
0158     struct snd_pcm *pcm;        /* PCM */
0159 
0160     struct pcxhr_pipe playback_pipe;    /* 1 stereo pipe only */
0161     struct pcxhr_pipe capture_pipe[2];  /* 1 stereo or 2 mono pipes */
0162 
0163     struct pcxhr_stream playback_stream[PCXHR_PLAYBACK_STREAMS];
0164     struct pcxhr_stream capture_stream[2];  /* 1 stereo or 2 mono streams */
0165     int nb_streams_play;
0166     int nb_streams_capt;
0167 
0168     int analog_playback_active[2];  /* Mixer : Master Playback !mute */
0169     int analog_playback_volume[2];  /* Mixer : Master Playback Volume */
0170     int analog_capture_volume[2];   /* Mixer : Master Capture Volume */
0171     int digital_playback_active[PCXHR_PLAYBACK_STREAMS][2];
0172     int digital_playback_volume[PCXHR_PLAYBACK_STREAMS][2];
0173     int digital_capture_volume[2];  /* Mixer : Digital Capture Volume */
0174     int monitoring_active[2];   /* Mixer : Monitoring Active */
0175     int monitoring_volume[2];   /* Mixer : Monitoring Volume */
0176     int audio_capture_source;   /* Mixer : Audio Capture Source */
0177     int mic_volume;         /* used by cards with MIC only */
0178     int mic_boost;          /* used by cards with MIC only */
0179     int mic_active;         /* used by cards with MIC only */
0180     int analog_capture_active;  /* used by cards with MIC only */
0181     int phantom_power;      /* used by cards with MIC only */
0182 
0183     unsigned char aes_bits[5];  /* Mixer : IEC958_AES bits */
0184 };
0185 
0186 struct pcxhr_hostport
0187 {
0188     char purgebuffer[6];
0189     char reserved[2];
0190 };
0191 
0192 /* exported */
0193 int pcxhr_create_pcm(struct snd_pcxhr *chip);
0194 int pcxhr_set_clock(struct pcxhr_mgr *mgr, unsigned int rate);
0195 int pcxhr_get_external_clock(struct pcxhr_mgr *mgr,
0196                  enum pcxhr_clock_type clock_type,
0197                  int *sample_rate);
0198 
0199 #endif /* __SOUND_PCXHR_H */