1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Support for Digigram Lola PCI-e boards
5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
11 #define DRVNAME "snd-lola"
12 #define SFX DRVNAME ": "
15 * Lola HD Audio Registers BAR0
17 #define LOLA_BAR0_GCAP 0x00
18 #define LOLA_BAR0_VMIN 0x02
19 #define LOLA_BAR0_VMAJ 0x03
20 #define LOLA_BAR0_OUTPAY 0x04
21 #define LOLA_BAR0_INPAY 0x06
22 #define LOLA_BAR0_GCTL 0x08
23 #define LOLA_BAR0_WAKEEN 0x0c
24 #define LOLA_BAR0_STATESTS 0x0e
25 #define LOLA_BAR0_GSTS 0x10
26 #define LOLA_BAR0_OUTSTRMPAY 0x18
27 #define LOLA_BAR0_INSTRMPAY 0x1a
28 #define LOLA_BAR0_INTCTL 0x20
29 #define LOLA_BAR0_INTSTS 0x24
30 #define LOLA_BAR0_WALCLK 0x30
31 #define LOLA_BAR0_SSYNC 0x38
33 #define LOLA_BAR0_CORBLBASE 0x40
34 #define LOLA_BAR0_CORBUBASE 0x44
35 #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 */
41 #define LOLA_BAR0_RIRBLBASE 0x50
42 #define LOLA_BAR0_RIRBUBASE 0x54
43 #define LOLA_BAR0_RIRBWP 0x58
44 #define LOLA_BAR0_RINTCNT 0x5a /* no ULONG access */
45 #define LOLA_BAR0_RIRBCTL 0x5c
46 #define LOLA_BAR0_RIRBSTS 0x5d /* UCHAR access only */
47 #define LOLA_BAR0_RIRBSIZE 0x5e /* no ULONG access */
49 #define LOLA_BAR0_ICW 0x60
50 #define LOLA_BAR0_IRR 0x64
51 #define LOLA_BAR0_ICS 0x68
52 #define LOLA_BAR0_DPLBASE 0x70
53 #define LOLA_BAR0_DPUBASE 0x74
55 /* stream register offsets from stream base 0x80 */
56 #define LOLA_BAR0_SD0_OFFSET 0x80
57 #define LOLA_REG0_SD_CTL 0x00
58 #define LOLA_REG0_SD_STS 0x03
59 #define LOLA_REG0_SD_LPIB 0x04
60 #define LOLA_REG0_SD_CBL 0x08
61 #define LOLA_REG0_SD_LVI 0x0c
62 #define LOLA_REG0_SD_FIFOW 0x0e
63 #define LOLA_REG0_SD_FIFOSIZE 0x10
64 #define LOLA_REG0_SD_FORMAT 0x12
65 #define LOLA_REG0_SD_BDLPL 0x18
66 #define LOLA_REG0_SD_BDLPU 0x1c
69 * Lola Digigram Registers BAR1
71 #define LOLA_BAR1_FPGAVER 0x00
72 #define LOLA_BAR1_DEVER 0x04
73 #define LOLA_BAR1_UCBMV 0x08
74 #define LOLA_BAR1_JTAG 0x0c
75 #define LOLA_BAR1_UARTRX 0x10
76 #define LOLA_BAR1_UARTTX 0x14
77 #define LOLA_BAR1_UARTCR 0x18
78 #define LOLA_BAR1_NVRAMVER 0x1c
79 #define LOLA_BAR1_CTRLSPI 0x20
80 #define LOLA_BAR1_DSPI 0x24
81 #define LOLA_BAR1_AISPI 0x28
82 #define LOLA_BAR1_GRAN 0x2c
84 #define LOLA_BAR1_DINTCTL 0x80
85 #define LOLA_BAR1_DIINTCTL 0x84
86 #define LOLA_BAR1_DOINTCTL 0x88
87 #define LOLA_BAR1_LRC 0x90
88 #define LOLA_BAR1_DINTSTS 0x94
89 #define LOLA_BAR1_DIINTSTS 0x98
90 #define LOLA_BAR1_DOINTSTS 0x9c
92 #define LOLA_BAR1_DSD0_OFFSET 0xa0
93 #define LOLA_BAR1_DSD_SIZE 0x18
95 #define LOLA_BAR1_DSDnSTS 0x00
96 #define LOLA_BAR1_DSDnLPIB 0x04
97 #define LOLA_BAR1_DSDnCTL 0x08
98 #define LOLA_BAR1_DSDnLVI 0x0c
99 #define LOLA_BAR1_DSDnBDPL 0x10
100 #define LOLA_BAR1_DSDnBDPU 0x14
102 #define LOLA_BAR1_SSYNC 0x03e8
104 #define LOLA_BAR1_BOARD_CTRL 0x0f00
105 #define LOLA_BAR1_BOARD_MODE 0x0f02
107 #define LOLA_BAR1_SOURCE_GAIN_ENABLE 0x1000
108 #define LOLA_BAR1_DEST00_MIX_GAIN_ENABLE 0x1004
109 #define LOLA_BAR1_DEST31_MIX_GAIN_ENABLE 0x1080
110 #define LOLA_BAR1_SOURCE00_01_GAIN 0x1084
111 #define LOLA_BAR1_SOURCE30_31_GAIN 0x10c0
112 #define LOLA_BAR1_SOURCE_GAIN(src) \
113 (LOLA_BAR1_SOURCE00_01_GAIN + (src) * 2)
114 #define LOLA_BAR1_DEST00_MIX00_01_GAIN 0x10c4
115 #define LOLA_BAR1_DEST00_MIX30_31_GAIN 0x1100
116 #define LOLA_BAR1_DEST01_MIX00_01_GAIN 0x1104
117 #define LOLA_BAR1_DEST01_MIX30_31_GAIN 0x1140
118 #define LOLA_BAR1_DEST31_MIX00_01_GAIN 0x1884
119 #define LOLA_BAR1_DEST31_MIX30_31_GAIN 0x18c0
120 #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 0x18c4
123 #define LOLA_BAR1_PEAKMETERS_SOURCE00_01 0x18c8
124 #define LOLA_BAR1_PEAKMETERS_SOURCE30_31 0x1904
125 #define LOLA_BAR1_PEAKMETERS_SOURCE(src) \
126 (LOLA_BAR1_PEAKMETERS_SOURCE00_01 + (src) * 2)
127 #define LOLA_BAR1_PEAKMETERS_DEST00_01 0x1908
128 #define LOLA_BAR1_PEAKMETERS_DEST30_31 0x1944
129 #define LOLA_BAR1_PEAKMETERS_DEST(dest) \
130 (LOLA_BAR1_PEAKMETERS_DEST00_01 + (dest) * 2)
131 #define LOLA_BAR1_PEAKMETERS_AGC00_01 0x1948
132 #define LOLA_BAR1_PEAKMETERS_AGC14_15 0x1964
133 #define LOLA_BAR1_PEAKMETERS_AGC(x) \
134 (LOLA_BAR1_PEAKMETERS_AGC00_01 + (x) * 2)
137 #define LOLA_GCTL_RESET (1 << 0)
138 /* GCTL unsolicited response enable bit */
139 #define LOLA_GCTL_UREN (1 << 8)
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 */
146 #define LOLA_RIRB_EX_UNSOL_EV 0x40000000
147 #define LOLA_RIRB_EX_ERROR 0x80000000
149 /* CORB int mask: CMEI[0] */
150 #define LOLA_CORB_INT_CMEI 0x01
151 #define LOLA_CORB_INT_MASK LOLA_CORB_INT_CMEI
153 /* RIRB int mask: overrun[2], response[0] */
154 #define LOLA_RIRB_INT_RESPONSE 0x01
155 #define LOLA_RIRB_INT_OVERRUN 0x04
156 #define LOLA_RIRB_INT_MASK (LOLA_RIRB_INT_RESPONSE | LOLA_RIRB_INT_OVERRUN)
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 */
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 0xffffff00
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 */
177 #define LOLA_CORB_ENTRIES 256
179 #define MAX_STREAM_IN_COUNT 16
180 #define MAX_STREAM_OUT_COUNT 16
181 #define MAX_STREAM_COUNT 16
182 #define MAX_PINS MAX_STREAM_COUNT
183 #define MAX_STREAM_BUFFER_COUNT 16
184 #define MAX_AUDIO_INOUT_COUNT 16
186 #define LOLA_CLOCK_TYPE_INTERNAL 0
187 #define LOLA_CLOCK_TYPE_AES 1
188 #define LOLA_CLOCK_TYPE_AES_SYNC 2
189 #define LOLA_CLOCK_TYPE_WORDCLOCK 3
190 #define LOLA_CLOCK_TYPE_ETHERSOUND 4
191 #define LOLA_CLOCK_TYPE_VIDEO 5
193 #define LOLA_CLOCK_FORMAT_NONE 0
194 #define LOLA_CLOCK_FORMAT_NTSC 1
195 #define LOLA_CLOCK_FORMAT_PAL 2
197 #define MAX_SAMPLE_CLOCK_COUNT 48
199 /* parameters used with mixer widget's mixer capabilities */
200 #define LOLA_PEAK_METER_CAN_AGC_MASK 1
201 #define LOLA_PEAK_METER_CAN_ANALOG_CLIP_MASK 2
205 void __iomem
*remap_addr
;
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 */
216 /* Pin widget setup */
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
;
230 struct lola_pin_array
{
231 unsigned int num_pins
;
232 unsigned int num_analog_pins
;
233 struct lola_pin pins
[MAX_PINS
];
236 /* Clock widget setup */
237 struct lola_sample_clock
{
243 struct lola_clock_widget
{
246 unsigned int cur_index
;
247 unsigned int cur_freq
;
249 struct lola_sample_clock sample_clock
[MAX_SAMPLE_CLOCK_COUNT
];
250 unsigned int idx_lookup
[MAX_SAMPLE_CLOCK_COUNT
];
253 #define LOLA_MIXER_DIM 32
254 struct lola_mixer_array
{
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
];
261 /* Mixer widget setup */
262 struct lola_mixer_widget
{
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
;
279 unsigned int nid
; /* audio widget NID */
280 unsigned int index
; /* array index */
281 unsigned int dsd
; /* DSD index */
283 struct snd_pcm_substream
*substream
; /* assigned PCM substream */
284 struct lola_stream
*master
; /* master stream (for multi-channel) */
287 unsigned int bufsize
;
288 unsigned int period_bytes
;
291 /* format + channel setup */
292 unsigned int format_verb
;
295 unsigned int opened
:1;
296 unsigned int prepared
:1;
297 unsigned int paused
:1;
298 unsigned int running
:1;
301 #define PLAY SNDRV_PCM_STREAM_PLAYBACK
302 #define CAPT SNDRV_PCM_STREAM_CAPTURE
305 unsigned int num_streams
;
306 struct snd_dma_buffer bdl
; /* BDL buffer */
307 struct lola_stream streams
[MAX_STREAM_COUNT
];
312 struct snd_card
*card
;
316 struct lola_bar bar
[2];
321 struct mutex open_mutex
;
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
;
330 /* CORB/RIRB buffers */
331 struct snd_dma_buffer rb
;
333 /* unsolicited events */
334 unsigned int last_unsol_res
;
337 struct lola_pcm pcm
[2];
340 unsigned int input_src_caps_mask
;
341 unsigned int input_src_mask
;
344 struct lola_pin_array pin
[2];
347 struct lola_clock_widget clock
;
349 unsigned int sample_rate
;
352 struct lola_mixer_widget mixer
;
355 unsigned int version
;
356 unsigned int lola_caps
;
359 unsigned int granularity
;
360 unsigned int sample_rate_min
;
361 unsigned int sample_rate_max
;
364 unsigned int initialized
:1;
365 unsigned int cold_reset
:1;
366 unsigned int polling_mode
:1;
369 unsigned int debug_res
;
370 unsigned int debug_res_ex
;
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)
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)
397 /* GET verbs HDAudio */
398 #define LOLA_VERB_GET_STREAM_FORMAT 0xa00
399 #define LOLA_VERB_GET_AMP_GAIN_MUTE 0xb00
400 #define LOLA_VERB_PARAMETERS 0xf00
401 #define LOLA_VERB_GET_POWER_STATE 0xf05
402 #define LOLA_VERB_GET_CONV 0xf06
403 #define LOLA_VERB_GET_UNSOLICITED_RESPONSE 0xf08
404 #define LOLA_VERB_GET_DIGI_CONVERT_1 0xf0d
405 #define LOLA_VERB_GET_CONFIG_DEFAULT 0xf1c
406 #define LOLA_VERB_GET_SUBSYSTEM_ID 0xf20
407 /* GET verbs Digigram */
408 #define LOLA_VERB_GET_FIXED_GAIN 0xfc0
409 #define LOLA_VERB_GET_GAIN_SELECT 0xfc1
410 #define LOLA_VERB_GET_MAX_LEVEL 0xfc2
411 #define LOLA_VERB_GET_CLOCK_LIST 0xfc3
412 #define LOLA_VERB_GET_CLOCK_SELECT 0xfc4
413 #define LOLA_VERB_GET_CLOCK_STATUS 0xfc5
415 /* SET verbs HDAudio */
416 #define LOLA_VERB_SET_STREAM_FORMAT 0x200
417 #define LOLA_VERB_SET_AMP_GAIN_MUTE 0x300
418 #define LOLA_VERB_SET_POWER_STATE 0x705
419 #define LOLA_VERB_SET_CHANNEL_STREAMID 0x706
420 #define LOLA_VERB_SET_UNSOLICITED_ENABLE 0x708
421 #define LOLA_VERB_SET_DIGI_CONVERT_1 0x70d
422 /* SET verbs Digigram */
423 #define LOLA_VERB_SET_GAIN_SELECT 0xf81
424 #define LOLA_VERB_SET_CLOCK_SELECT 0xf84
425 #define LOLA_VERB_SET_GRANULARITY_STEPS 0xf86
426 #define LOLA_VERB_SET_SOURCE_GAIN 0xf87
427 #define LOLA_VERB_SET_MIX_GAIN 0xf88
428 #define LOLA_VERB_SET_DESTINATION_GAIN 0xf89
429 #define LOLA_VERB_SET_SRC 0xf8a
431 /* Parameter IDs used with LOLA_VERB_PARAMETERS */
432 #define LOLA_PAR_VENDOR_ID 0x00
433 #define LOLA_PAR_FUNCTION_TYPE 0x05
434 #define LOLA_PAR_AUDIO_WIDGET_CAP 0x09
435 #define LOLA_PAR_PCM 0x0a
436 #define LOLA_PAR_STREAM_FORMATS 0x0b
437 #define LOLA_PAR_PIN_CAP 0x0c
438 #define LOLA_PAR_AMP_IN_CAP 0x0d
439 #define LOLA_PAR_CONNLIST_LEN 0x0e
440 #define LOLA_PAR_POWER_STATE 0x0f
441 #define LOLA_PAR_GPIO_CAP 0x11
442 #define LOLA_PAR_AMP_OUT_CAP 0x12
443 #define LOLA_PAR_SPECIFIC_CAPS 0x80
444 #define LOLA_PAR_FIXED_GAIN_LIST 0x81
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)
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)
458 #define LOLA_GRANULARITY_MIN 8
459 #define LOLA_GRANULARITY_MAX 32
460 #define LOLA_GRANULARITY_STEP 8
462 /* parameters used with unsolicited command/response */
463 #define LOLA_UNSOLICITED_TAG_MASK 0x3f
464 #define LOLA_UNSOLICITED_TAG 0x1a
465 #define LOLA_UNSOLICITED_ENABLE 0x80
466 #define LOLA_UNSOL_RESP_TAG_OFFSET 26
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)
472 int lola_codec_write(struct lola
*chip
, unsigned int nid
, unsigned int verb
,
473 unsigned int data
, unsigned int extdata
);
474 int 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
);
477 int 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)
482 int lola_create_pcm(struct lola
*chip
);
483 void lola_free_pcm(struct lola
*chip
);
484 int lola_init_pcm(struct lola
*chip
, int dir
, int *nidp
);
485 void lola_pcm_update(struct lola
*chip
, struct lola_pcm
*pcm
, unsigned int bits
);
488 int lola_init_clock_widget(struct lola
*chip
, int nid
);
489 int lola_set_granularity(struct lola
*chip
, unsigned int val
, bool force
);
490 int lola_enable_clock_events(struct lola
*chip
);
491 int lola_set_clock_index(struct lola
*chip
, unsigned int idx
);
492 int lola_set_clock(struct lola
*chip
, int idx
);
493 int lola_set_sample_rate(struct lola
*chip
, int rate
);
494 bool lola_update_ext_clock_freq(struct lola
*chip
, unsigned int val
);
495 unsigned int lola_sample_rate_convert(unsigned int coded
);
498 int lola_init_pins(struct lola
*chip
, int dir
, int *nidp
);
499 int lola_init_mixer_widget(struct lola
*chip
, int nid
);
500 void lola_free_mixer(struct lola
*chip
);
501 int lola_create_mixer(struct lola
*chip
);
502 int lola_setup_all_analog_gains(struct lola
*chip
, int dir
, bool mute
);
503 void lola_save_mixer(struct lola
*chip
);
504 void lola_restore_mixer(struct lola
*chip
);
505 int lola_set_src_config(struct lola
*chip
, unsigned int src_mask
, bool update
);
508 #ifdef CONFIG_SND_DEBUG
509 void lola_proc_debug_new(struct lola
*chip
);
511 #define lola_proc_debug_new(chip)