514 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 * Support for Digigram Lola PCI-e boards4 *5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>6 */7 8#ifndef _LOLA_H9#define _LOLA_H10 11#define DRVNAME "snd-lola"12#define SFX DRVNAME ": "13 14/*15 * Lola HD Audio Registers BAR016 */17#define LOLA_BAR0_GCAP 0x0018#define LOLA_BAR0_VMIN 0x0219#define LOLA_BAR0_VMAJ 0x0320#define LOLA_BAR0_OUTPAY 0x0421#define LOLA_BAR0_INPAY 0x0622#define LOLA_BAR0_GCTL 0x0823#define LOLA_BAR0_WAKEEN 0x0c24#define LOLA_BAR0_STATESTS 0x0e25#define LOLA_BAR0_GSTS 0x1026#define LOLA_BAR0_OUTSTRMPAY 0x1827#define LOLA_BAR0_INSTRMPAY 0x1a28#define LOLA_BAR0_INTCTL 0x2029#define LOLA_BAR0_INTSTS 0x2430#define LOLA_BAR0_WALCLK 0x3031#define LOLA_BAR0_SSYNC 0x3832 33#define LOLA_BAR0_CORBLBASE 0x4034#define LOLA_BAR0_CORBUBASE 0x4435#define LOLA_BAR0_CORBWP 0x48 /* no ULONG access */36#define LOLA_BAR0_CORBRP 0x4a /* no ULONG access */37#define LOLA_BAR0_CORBCTL 0x4c /* no ULONG access */38#define LOLA_BAR0_CORBSTS 0x4d /* UCHAR access only */39#define LOLA_BAR0_CORBSIZE 0x4e /* no ULONG access */40 41#define LOLA_BAR0_RIRBLBASE 0x5042#define LOLA_BAR0_RIRBUBASE 0x5443#define LOLA_BAR0_RIRBWP 0x5844#define LOLA_BAR0_RINTCNT 0x5a /* no ULONG access */45#define LOLA_BAR0_RIRBCTL 0x5c46#define LOLA_BAR0_RIRBSTS 0x5d /* UCHAR access only */47#define LOLA_BAR0_RIRBSIZE 0x5e /* no ULONG access */48 49#define LOLA_BAR0_ICW 0x6050#define LOLA_BAR0_IRR 0x6451#define LOLA_BAR0_ICS 0x6852#define LOLA_BAR0_DPLBASE 0x7053#define LOLA_BAR0_DPUBASE 0x7454 55/* stream register offsets from stream base 0x80 */56#define LOLA_BAR0_SD0_OFFSET 0x8057#define LOLA_REG0_SD_CTL 0x0058#define LOLA_REG0_SD_STS 0x0359#define LOLA_REG0_SD_LPIB 0x0460#define LOLA_REG0_SD_CBL 0x0861#define LOLA_REG0_SD_LVI 0x0c62#define LOLA_REG0_SD_FIFOW 0x0e63#define LOLA_REG0_SD_FIFOSIZE 0x1064#define LOLA_REG0_SD_FORMAT 0x1265#define LOLA_REG0_SD_BDLPL 0x1866#define LOLA_REG0_SD_BDLPU 0x1c67 68/*69 * Lola Digigram Registers BAR170 */71#define LOLA_BAR1_FPGAVER 0x0072#define LOLA_BAR1_DEVER 0x0473#define LOLA_BAR1_UCBMV 0x0874#define LOLA_BAR1_JTAG 0x0c75#define LOLA_BAR1_UARTRX 0x1076#define LOLA_BAR1_UARTTX 0x1477#define LOLA_BAR1_UARTCR 0x1878#define LOLA_BAR1_NVRAMVER 0x1c79#define LOLA_BAR1_CTRLSPI 0x2080#define LOLA_BAR1_DSPI 0x2481#define LOLA_BAR1_AISPI 0x2882#define LOLA_BAR1_GRAN 0x2c83 84#define LOLA_BAR1_DINTCTL 0x8085#define LOLA_BAR1_DIINTCTL 0x8486#define LOLA_BAR1_DOINTCTL 0x8887#define LOLA_BAR1_LRC 0x9088#define LOLA_BAR1_DINTSTS 0x9489#define LOLA_BAR1_DIINTSTS 0x9890#define LOLA_BAR1_DOINTSTS 0x9c91 92#define LOLA_BAR1_DSD0_OFFSET 0xa093#define LOLA_BAR1_DSD_SIZE 0x1894 95#define LOLA_BAR1_DSDnSTS 0x0096#define LOLA_BAR1_DSDnLPIB 0x0497#define LOLA_BAR1_DSDnCTL 0x0898#define LOLA_BAR1_DSDnLVI 0x0c99#define LOLA_BAR1_DSDnBDPL 0x10100#define LOLA_BAR1_DSDnBDPU 0x14101 102#define LOLA_BAR1_SSYNC 0x03e8103 104#define LOLA_BAR1_BOARD_CTRL 0x0f00105#define LOLA_BAR1_BOARD_MODE 0x0f02106 107#define LOLA_BAR1_SOURCE_GAIN_ENABLE 0x1000108#define LOLA_BAR1_DEST00_MIX_GAIN_ENABLE 0x1004109#define LOLA_BAR1_DEST31_MIX_GAIN_ENABLE 0x1080110#define LOLA_BAR1_SOURCE00_01_GAIN 0x1084111#define LOLA_BAR1_SOURCE30_31_GAIN 0x10c0112#define LOLA_BAR1_SOURCE_GAIN(src) \113 (LOLA_BAR1_SOURCE00_01_GAIN + (src) * 2)114#define LOLA_BAR1_DEST00_MIX00_01_GAIN 0x10c4115#define LOLA_BAR1_DEST00_MIX30_31_GAIN 0x1100116#define LOLA_BAR1_DEST01_MIX00_01_GAIN 0x1104117#define LOLA_BAR1_DEST01_MIX30_31_GAIN 0x1140118#define LOLA_BAR1_DEST31_MIX00_01_GAIN 0x1884119#define LOLA_BAR1_DEST31_MIX30_31_GAIN 0x18c0120#define LOLA_BAR1_MIX_GAIN(dest, mix) \121 (LOLA_BAR1_DEST00_MIX00_01_GAIN + (dest) * 0x40 + (mix) * 2)122#define LOLA_BAR1_ANALOG_CLIP_IN 0x18c4123#define LOLA_BAR1_PEAKMETERS_SOURCE00_01 0x18c8124#define LOLA_BAR1_PEAKMETERS_SOURCE30_31 0x1904125#define LOLA_BAR1_PEAKMETERS_SOURCE(src) \126 (LOLA_BAR1_PEAKMETERS_SOURCE00_01 + (src) * 2)127#define LOLA_BAR1_PEAKMETERS_DEST00_01 0x1908128#define LOLA_BAR1_PEAKMETERS_DEST30_31 0x1944129#define LOLA_BAR1_PEAKMETERS_DEST(dest) \130 (LOLA_BAR1_PEAKMETERS_DEST00_01 + (dest) * 2)131#define LOLA_BAR1_PEAKMETERS_AGC00_01 0x1948132#define LOLA_BAR1_PEAKMETERS_AGC14_15 0x1964133#define LOLA_BAR1_PEAKMETERS_AGC(x) \134 (LOLA_BAR1_PEAKMETERS_AGC00_01 + (x) * 2)135 136/* GCTL reset bit */137#define LOLA_GCTL_RESET (1 << 0)138/* GCTL unsolicited response enable bit */139#define LOLA_GCTL_UREN (1 << 8)140 141/* CORB/RIRB control, read/write pointer */142#define LOLA_RBCTL_DMA_EN 0x02 /* enable DMA */143#define LOLA_RBCTL_IRQ_EN 0x01 /* enable IRQ */144#define LOLA_RBRWP_CLR 0x8000 /* read/write pointer clear */145 146#define LOLA_RIRB_EX_UNSOL_EV 0x40000000147#define LOLA_RIRB_EX_ERROR 0x80000000148 149/* CORB int mask: CMEI[0] */150#define LOLA_CORB_INT_CMEI 0x01151#define LOLA_CORB_INT_MASK LOLA_CORB_INT_CMEI152 153/* RIRB int mask: overrun[2], response[0] */154#define LOLA_RIRB_INT_RESPONSE 0x01155#define LOLA_RIRB_INT_OVERRUN 0x04156#define LOLA_RIRB_INT_MASK (LOLA_RIRB_INT_RESPONSE | LOLA_RIRB_INT_OVERRUN)157 158/* DINTCTL and DINTSTS */159#define LOLA_DINT_GLOBAL 0x80000000 /* global interrupt enable bit */160#define LOLA_DINT_CTRL 0x40000000 /* controller interrupt enable bit */161#define LOLA_DINT_FIFOERR 0x20000000 /* global fifo error enable bit */162#define LOLA_DINT_MUERR 0x10000000 /* global microcontroller underrun error */163 164/* DSDnCTL bits */165#define LOLA_DSD_CTL_SRST 0x01 /* stream reset bit */166#define LOLA_DSD_CTL_SRUN 0x02 /* stream DMA start bit */167#define LOLA_DSD_CTL_IOCE 0x04 /* interrupt on completion enable */168#define LOLA_DSD_CTL_DEIE 0x10 /* descriptor error interrupt enable */169#define LOLA_DSD_CTL_VLRCV 0x20 /* valid LRCountValue information in bits 8..31 */170#define LOLA_LRC_MASK 0xffffff00171 172/* DSDnSTS */173#define LOLA_DSD_STS_BCIS 0x04 /* buffer completion interrupt status */174#define LOLA_DSD_STS_DESE 0x10 /* descriptor error interrupt */175#define LOLA_DSD_STS_FIFORDY 0x20 /* fifo ready */176 177#define LOLA_CORB_ENTRIES 256178 179#define MAX_STREAM_IN_COUNT 16180#define MAX_STREAM_OUT_COUNT 16181#define MAX_STREAM_COUNT 16182#define MAX_PINS MAX_STREAM_COUNT183#define MAX_STREAM_BUFFER_COUNT 16184#define MAX_AUDIO_INOUT_COUNT 16185 186#define LOLA_CLOCK_TYPE_INTERNAL 0187#define LOLA_CLOCK_TYPE_AES 1188#define LOLA_CLOCK_TYPE_AES_SYNC 2189#define LOLA_CLOCK_TYPE_WORDCLOCK 3190#define LOLA_CLOCK_TYPE_ETHERSOUND 4191#define LOLA_CLOCK_TYPE_VIDEO 5192 193#define LOLA_CLOCK_FORMAT_NONE 0194#define LOLA_CLOCK_FORMAT_NTSC 1195#define LOLA_CLOCK_FORMAT_PAL 2196 197#define MAX_SAMPLE_CLOCK_COUNT 48198 199/* parameters used with mixer widget's mixer capabilities */200#define LOLA_PEAK_METER_CAN_AGC_MASK 1201#define LOLA_PEAK_METER_CAN_ANALOG_CLIP_MASK 2202 203struct lola_bar {204 unsigned long addr;205 void __iomem *remap_addr;206};207 208/* CORB/RIRB */209struct lola_rb {210 __le32 *buf; /* CORB/RIRB buffer, 8 byte per each entry */211 dma_addr_t addr; /* physical address of CORB/RIRB buffer */212 unsigned short rp, wp; /* read/write pointers */213 int cmds; /* number of pending requests */214};215 216/* Pin widget setup */217struct lola_pin {218 unsigned int nid;219 bool is_analog;220 unsigned int amp_mute;221 unsigned int amp_step_size;222 unsigned int amp_num_steps;223 unsigned int amp_offset;224 unsigned int max_level;225 unsigned int config_default_reg;226 unsigned int fixed_gain_list_len;227 unsigned int cur_gain_step;228};229 230struct lola_pin_array {231 unsigned int num_pins;232 unsigned int num_analog_pins;233 struct lola_pin pins[MAX_PINS];234};235 236/* Clock widget setup */237struct lola_sample_clock {238 unsigned int type;239 unsigned int format;240 unsigned int freq;241};242 243struct lola_clock_widget {244 unsigned int nid;245 unsigned int items;246 unsigned int cur_index;247 unsigned int cur_freq;248 bool cur_valid;249 struct lola_sample_clock sample_clock[MAX_SAMPLE_CLOCK_COUNT];250 unsigned int idx_lookup[MAX_SAMPLE_CLOCK_COUNT];251};252 253#define LOLA_MIXER_DIM 32254struct lola_mixer_array {255 u32 src_gain_enable;256 u32 dest_mix_gain_enable[LOLA_MIXER_DIM];257 u16 src_gain[LOLA_MIXER_DIM];258 u16 dest_mix_gain[LOLA_MIXER_DIM][LOLA_MIXER_DIM];259};260 261/* Mixer widget setup */262struct lola_mixer_widget {263 unsigned int nid;264 unsigned int caps;265 struct lola_mixer_array __iomem *array;266 struct lola_mixer_array *array_saved;267 unsigned int src_stream_outs;268 unsigned int src_phys_ins;269 unsigned int dest_stream_ins;270 unsigned int dest_phys_outs;271 unsigned int src_stream_out_ofs;272 unsigned int dest_phys_out_ofs;273 unsigned int src_mask;274 unsigned int dest_mask;275};276 277/* Audio stream */278struct lola_stream {279 unsigned int nid; /* audio widget NID */280 unsigned int index; /* array index */281 unsigned int dsd; /* DSD index */282 bool can_float;283 struct snd_pcm_substream *substream; /* assigned PCM substream */284 struct lola_stream *master; /* master stream (for multi-channel) */285 286 /* buffer setup */287 unsigned int bufsize;288 unsigned int period_bytes;289 unsigned int frags;290 291 /* format + channel setup */292 unsigned int format_verb;293 294 /* flags */295 unsigned int opened:1;296 unsigned int prepared:1;297 unsigned int paused:1;298 unsigned int running:1;299};300 301#define PLAY SNDRV_PCM_STREAM_PLAYBACK302#define CAPT SNDRV_PCM_STREAM_CAPTURE303 304struct lola_pcm {305 unsigned int num_streams;306 struct snd_dma_buffer *bdl; /* BDL buffer */307 struct lola_stream streams[MAX_STREAM_COUNT];308};309 310/* card instance */311struct lola {312 struct snd_card *card;313 struct pci_dev *pci;314 315 /* pci resources */316 struct lola_bar bar[2];317 int irq;318 319 /* locks */320 spinlock_t reg_lock;321 struct mutex open_mutex;322 323 /* CORB/RIRB */324 struct lola_rb corb;325 struct lola_rb rirb;326 unsigned int res, res_ex; /* last read values */327 /* last command (for debugging) */328 unsigned int last_cmd_nid, last_verb, last_data, last_extdata;329 330 /* CORB/RIRB buffers */331 struct snd_dma_buffer *rb;332 333 /* unsolicited events */334 unsigned int last_unsol_res;335 336 /* streams */337 struct lola_pcm pcm[2];338 339 /* input src */340 unsigned int input_src_caps_mask;341 unsigned int input_src_mask;342 343 /* pins */344 struct lola_pin_array pin[2];345 346 /* clock */347 struct lola_clock_widget clock;348 int ref_count_rate;349 unsigned int sample_rate;350 351 /* mixer */352 struct lola_mixer_widget mixer;353 354 /* hw info */355 unsigned int version;356 unsigned int lola_caps;357 358 /* parameters */359 unsigned int granularity;360 unsigned int sample_rate_min;361 unsigned int sample_rate_max;362 363 /* flags */364 unsigned int initialized:1;365 unsigned int cold_reset:1;366 unsigned int polling_mode:1;367 368 /* for debugging */369 unsigned int debug_res;370 unsigned int debug_res_ex;371};372 373#define BAR0 0374#define BAR1 1375 376/* Helper macros */377#define lola_readl(chip, idx, name) \378 readl((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)379#define lola_readw(chip, idx, name) \380 readw((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)381#define lola_readb(chip, idx, name) \382 readb((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)383#define lola_writel(chip, idx, name, val) \384 writel((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)385#define lola_writew(chip, idx, name, val) \386 writew((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)387#define lola_writeb(chip, idx, name, val) \388 writeb((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)389 390#define lola_dsd_read(chip, dsd, name) \391 readl((chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \392 (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)393#define lola_dsd_write(chip, dsd, name, val) \394 writel((val), (chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \395 (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)396 397/* GET verbs HDAudio */398#define LOLA_VERB_GET_STREAM_FORMAT 0xa00399#define LOLA_VERB_GET_AMP_GAIN_MUTE 0xb00400#define LOLA_VERB_PARAMETERS 0xf00401#define LOLA_VERB_GET_POWER_STATE 0xf05402#define LOLA_VERB_GET_CONV 0xf06403#define LOLA_VERB_GET_UNSOLICITED_RESPONSE 0xf08404#define LOLA_VERB_GET_DIGI_CONVERT_1 0xf0d405#define LOLA_VERB_GET_CONFIG_DEFAULT 0xf1c406#define LOLA_VERB_GET_SUBSYSTEM_ID 0xf20407/* GET verbs Digigram */408#define LOLA_VERB_GET_FIXED_GAIN 0xfc0409#define LOLA_VERB_GET_GAIN_SELECT 0xfc1410#define LOLA_VERB_GET_MAX_LEVEL 0xfc2411#define LOLA_VERB_GET_CLOCK_LIST 0xfc3412#define LOLA_VERB_GET_CLOCK_SELECT 0xfc4413#define LOLA_VERB_GET_CLOCK_STATUS 0xfc5414 415/* SET verbs HDAudio */416#define LOLA_VERB_SET_STREAM_FORMAT 0x200417#define LOLA_VERB_SET_AMP_GAIN_MUTE 0x300418#define LOLA_VERB_SET_POWER_STATE 0x705419#define LOLA_VERB_SET_CHANNEL_STREAMID 0x706420#define LOLA_VERB_SET_UNSOLICITED_ENABLE 0x708421#define LOLA_VERB_SET_DIGI_CONVERT_1 0x70d422/* SET verbs Digigram */423#define LOLA_VERB_SET_GAIN_SELECT 0xf81424#define LOLA_VERB_SET_CLOCK_SELECT 0xf84425#define LOLA_VERB_SET_GRANULARITY_STEPS 0xf86426#define LOLA_VERB_SET_SOURCE_GAIN 0xf87427#define LOLA_VERB_SET_MIX_GAIN 0xf88428#define LOLA_VERB_SET_DESTINATION_GAIN 0xf89429#define LOLA_VERB_SET_SRC 0xf8a430 431/* Parameter IDs used with LOLA_VERB_PARAMETERS */432#define LOLA_PAR_VENDOR_ID 0x00433#define LOLA_PAR_FUNCTION_TYPE 0x05434#define LOLA_PAR_AUDIO_WIDGET_CAP 0x09435#define LOLA_PAR_PCM 0x0a436#define LOLA_PAR_STREAM_FORMATS 0x0b437#define LOLA_PAR_PIN_CAP 0x0c438#define LOLA_PAR_AMP_IN_CAP 0x0d439#define LOLA_PAR_CONNLIST_LEN 0x0e440#define LOLA_PAR_POWER_STATE 0x0f441#define LOLA_PAR_GPIO_CAP 0x11442#define LOLA_PAR_AMP_OUT_CAP 0x12443#define LOLA_PAR_SPECIFIC_CAPS 0x80444#define LOLA_PAR_FIXED_GAIN_LIST 0x81445 446/* extract results of LOLA_PAR_SPECIFIC_CAPS */447#define LOLA_AFG_MIXER_WIDGET_PRESENT(res) ((res & (1 << 21)) != 0)448#define LOLA_AFG_CLOCK_WIDGET_PRESENT(res) ((res & (1 << 20)) != 0)449#define LOLA_AFG_INPUT_PIN_COUNT(res) ((res >> 10) & 0x2ff)450#define LOLA_AFG_OUTPUT_PIN_COUNT(res) ((res) & 0x2ff)451 452/* extract results of LOLA_PAR_AMP_IN_CAP / LOLA_PAR_AMP_OUT_CAP */453#define LOLA_AMP_MUTE_CAPABLE(res) ((res & (1 << 31)) != 0)454#define LOLA_AMP_STEP_SIZE(res) ((res >> 24) & 0x7f)455#define LOLA_AMP_NUM_STEPS(res) ((res >> 12) & 0x3ff)456#define LOLA_AMP_OFFSET(res) ((res) & 0x3ff)457 458#define LOLA_GRANULARITY_MIN 8459#define LOLA_GRANULARITY_MAX 32460#define LOLA_GRANULARITY_STEP 8461 462/* parameters used with unsolicited command/response */463#define LOLA_UNSOLICITED_TAG_MASK 0x3f464#define LOLA_UNSOLICITED_TAG 0x1a465#define LOLA_UNSOLICITED_ENABLE 0x80466#define LOLA_UNSOL_RESP_TAG_OFFSET 26467 468/* count values in the Vendor Specific Mixer Widget's Audio Widget Capabilities */469#define LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(res) ((res >> 2) & 0x1f)470#define LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(res) ((res >> 7) & 0x1f)471 472int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,473 unsigned int data, unsigned int extdata);474int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,475 unsigned int data, unsigned int extdata,476 unsigned int *val, unsigned int *extval);477int lola_codec_flush(struct lola *chip);478#define lola_read_param(chip, nid, param, val) \479 lola_codec_read(chip, nid, LOLA_VERB_PARAMETERS, param, 0, val, NULL)480 481/* PCM */482int lola_create_pcm(struct lola *chip);483int lola_init_pcm(struct lola *chip, int dir, int *nidp);484void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits);485 486/* clock */487int lola_init_clock_widget(struct lola *chip, int nid);488int lola_set_granularity(struct lola *chip, unsigned int val, bool force);489int lola_enable_clock_events(struct lola *chip);490int lola_set_clock_index(struct lola *chip, unsigned int idx);491int lola_set_clock(struct lola *chip, int idx);492int lola_set_sample_rate(struct lola *chip, int rate);493bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val);494unsigned int lola_sample_rate_convert(unsigned int coded);495 496/* mixer */497int lola_init_pins(struct lola *chip, int dir, int *nidp);498int lola_init_mixer_widget(struct lola *chip, int nid);499void lola_free_mixer(struct lola *chip);500int lola_create_mixer(struct lola *chip);501int lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute);502void lola_save_mixer(struct lola *chip);503void lola_restore_mixer(struct lola *chip);504int lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update);505 506/* proc */507#ifdef CONFIG_SND_DEBUG508void lola_proc_debug_new(struct lola *chip);509#else510#define lola_proc_debug_new(chip)511#endif512 513#endif /* _LOLA_H */514