xref: /openbmc/linux/sound/pci/lola/lola.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2d43f3010STakashi Iwai /*
3d43f3010STakashi Iwai  *  Support for Digigram Lola PCI-e boards
4d43f3010STakashi Iwai  *
5d43f3010STakashi Iwai  *  Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
6d43f3010STakashi Iwai  */
7d43f3010STakashi Iwai 
8d43f3010STakashi Iwai #ifndef _LOLA_H
9d43f3010STakashi Iwai #define _LOLA_H
10d43f3010STakashi Iwai 
11d43f3010STakashi Iwai #define DRVNAME	"snd-lola"
12d43f3010STakashi Iwai #define SFX	DRVNAME ": "
13d43f3010STakashi Iwai 
14d43f3010STakashi Iwai /*
15d43f3010STakashi Iwai  * Lola HD Audio Registers BAR0
16d43f3010STakashi Iwai  */
17d43f3010STakashi Iwai #define LOLA_BAR0_GCAP		0x00
18d43f3010STakashi Iwai #define LOLA_BAR0_VMIN		0x02
19d43f3010STakashi Iwai #define LOLA_BAR0_VMAJ		0x03
20d43f3010STakashi Iwai #define LOLA_BAR0_OUTPAY	0x04
21d43f3010STakashi Iwai #define LOLA_BAR0_INPAY		0x06
22d43f3010STakashi Iwai #define LOLA_BAR0_GCTL		0x08
23d43f3010STakashi Iwai #define LOLA_BAR0_WAKEEN	0x0c
24d43f3010STakashi Iwai #define LOLA_BAR0_STATESTS	0x0e
25d43f3010STakashi Iwai #define LOLA_BAR0_GSTS		0x10
26d43f3010STakashi Iwai #define LOLA_BAR0_OUTSTRMPAY	0x18
27d43f3010STakashi Iwai #define LOLA_BAR0_INSTRMPAY	0x1a
28d43f3010STakashi Iwai #define LOLA_BAR0_INTCTL	0x20
29d43f3010STakashi Iwai #define LOLA_BAR0_INTSTS	0x24
30d43f3010STakashi Iwai #define LOLA_BAR0_WALCLK	0x30
31d43f3010STakashi Iwai #define LOLA_BAR0_SSYNC		0x38
32d43f3010STakashi Iwai 
33d43f3010STakashi Iwai #define LOLA_BAR0_CORBLBASE	0x40
34d43f3010STakashi Iwai #define LOLA_BAR0_CORBUBASE	0x44
35d43f3010STakashi Iwai #define LOLA_BAR0_CORBWP	0x48	/* no ULONG access */
36d43f3010STakashi Iwai #define LOLA_BAR0_CORBRP	0x4a	/* no ULONG access */
37d43f3010STakashi Iwai #define LOLA_BAR0_CORBCTL	0x4c	/* no ULONG access */
38d43f3010STakashi Iwai #define LOLA_BAR0_CORBSTS	0x4d	/* UCHAR access only */
39d43f3010STakashi Iwai #define LOLA_BAR0_CORBSIZE	0x4e	/* no ULONG access */
40d43f3010STakashi Iwai 
41d43f3010STakashi Iwai #define LOLA_BAR0_RIRBLBASE	0x50
42d43f3010STakashi Iwai #define LOLA_BAR0_RIRBUBASE	0x54
43d43f3010STakashi Iwai #define LOLA_BAR0_RIRBWP	0x58
44d43f3010STakashi Iwai #define LOLA_BAR0_RINTCNT	0x5a	/* no ULONG access */
45d43f3010STakashi Iwai #define LOLA_BAR0_RIRBCTL	0x5c
46d43f3010STakashi Iwai #define LOLA_BAR0_RIRBSTS	0x5d	/* UCHAR access only */
47d43f3010STakashi Iwai #define LOLA_BAR0_RIRBSIZE	0x5e	/* no ULONG access */
48d43f3010STakashi Iwai 
49d43f3010STakashi Iwai #define LOLA_BAR0_ICW		0x60
50d43f3010STakashi Iwai #define LOLA_BAR0_IRR		0x64
51d43f3010STakashi Iwai #define LOLA_BAR0_ICS		0x68
52d43f3010STakashi Iwai #define LOLA_BAR0_DPLBASE	0x70
53d43f3010STakashi Iwai #define LOLA_BAR0_DPUBASE	0x74
54d43f3010STakashi Iwai 
55d43f3010STakashi Iwai /* stream register offsets from stream base 0x80 */
56d43f3010STakashi Iwai #define LOLA_BAR0_SD0_OFFSET	0x80
57d43f3010STakashi Iwai #define LOLA_REG0_SD_CTL	0x00
58d43f3010STakashi Iwai #define LOLA_REG0_SD_STS	0x03
59d43f3010STakashi Iwai #define LOLA_REG0_SD_LPIB	0x04
60d43f3010STakashi Iwai #define LOLA_REG0_SD_CBL	0x08
61d43f3010STakashi Iwai #define LOLA_REG0_SD_LVI	0x0c
62d43f3010STakashi Iwai #define LOLA_REG0_SD_FIFOW	0x0e
63d43f3010STakashi Iwai #define LOLA_REG0_SD_FIFOSIZE	0x10
64d43f3010STakashi Iwai #define LOLA_REG0_SD_FORMAT	0x12
65d43f3010STakashi Iwai #define LOLA_REG0_SD_BDLPL	0x18
66d43f3010STakashi Iwai #define LOLA_REG0_SD_BDLPU	0x1c
67d43f3010STakashi Iwai 
68d43f3010STakashi Iwai /*
69d43f3010STakashi Iwai  * Lola Digigram Registers BAR1
70d43f3010STakashi Iwai  */
71d43f3010STakashi Iwai #define LOLA_BAR1_FPGAVER	0x00
72d43f3010STakashi Iwai #define LOLA_BAR1_DEVER		0x04
73d43f3010STakashi Iwai #define LOLA_BAR1_UCBMV		0x08
74d43f3010STakashi Iwai #define LOLA_BAR1_JTAG		0x0c
75d43f3010STakashi Iwai #define LOLA_BAR1_UARTRX	0x10
76d43f3010STakashi Iwai #define LOLA_BAR1_UARTTX	0x14
77d43f3010STakashi Iwai #define LOLA_BAR1_UARTCR	0x18
78d43f3010STakashi Iwai #define LOLA_BAR1_NVRAMVER	0x1c
79d43f3010STakashi Iwai #define LOLA_BAR1_CTRLSPI	0x20
80d43f3010STakashi Iwai #define LOLA_BAR1_DSPI		0x24
81d43f3010STakashi Iwai #define LOLA_BAR1_AISPI		0x28
82d43f3010STakashi Iwai #define LOLA_BAR1_GRAN		0x2c
83d43f3010STakashi Iwai 
84d43f3010STakashi Iwai #define LOLA_BAR1_DINTCTL	0x80
85d43f3010STakashi Iwai #define LOLA_BAR1_DIINTCTL	0x84
86d43f3010STakashi Iwai #define LOLA_BAR1_DOINTCTL	0x88
87d43f3010STakashi Iwai #define LOLA_BAR1_LRC		0x90
88d43f3010STakashi Iwai #define LOLA_BAR1_DINTSTS	0x94
89d43f3010STakashi Iwai #define LOLA_BAR1_DIINTSTS	0x98
90d43f3010STakashi Iwai #define LOLA_BAR1_DOINTSTS	0x9c
91d43f3010STakashi Iwai 
92d43f3010STakashi Iwai #define LOLA_BAR1_DSD0_OFFSET	0xa0
93d43f3010STakashi Iwai #define LOLA_BAR1_DSD_SIZE	0x18
94d43f3010STakashi Iwai 
95d43f3010STakashi Iwai #define LOLA_BAR1_DSDnSTS       0x00
96d43f3010STakashi Iwai #define LOLA_BAR1_DSDnLPIB      0x04
97d43f3010STakashi Iwai #define LOLA_BAR1_DSDnCTL       0x08
98d43f3010STakashi Iwai #define LOLA_BAR1_DSDnLVI       0x0c
99d43f3010STakashi Iwai #define LOLA_BAR1_DSDnBDPL      0x10
100d43f3010STakashi Iwai #define LOLA_BAR1_DSDnBDPU      0x14
101d43f3010STakashi Iwai 
102d43f3010STakashi Iwai #define LOLA_BAR1_SSYNC		0x03e8
103d43f3010STakashi Iwai 
104d43f3010STakashi Iwai #define LOLA_BAR1_BOARD_CTRL	0x0f00
105d43f3010STakashi Iwai #define LOLA_BAR1_BOARD_MODE	0x0f02
106d43f3010STakashi Iwai 
107d43f3010STakashi Iwai #define LOLA_BAR1_SOURCE_GAIN_ENABLE		0x1000
108d43f3010STakashi Iwai #define LOLA_BAR1_DEST00_MIX_GAIN_ENABLE	0x1004
109d43f3010STakashi Iwai #define LOLA_BAR1_DEST31_MIX_GAIN_ENABLE	0x1080
110d43f3010STakashi Iwai #define LOLA_BAR1_SOURCE00_01_GAIN		0x1084
111d43f3010STakashi Iwai #define LOLA_BAR1_SOURCE30_31_GAIN		0x10c0
112d43f3010STakashi Iwai #define LOLA_BAR1_SOURCE_GAIN(src) \
113d43f3010STakashi Iwai 	(LOLA_BAR1_SOURCE00_01_GAIN + (src) * 2)
114d43f3010STakashi Iwai #define LOLA_BAR1_DEST00_MIX00_01_GAIN		0x10c4
115d43f3010STakashi Iwai #define LOLA_BAR1_DEST00_MIX30_31_GAIN		0x1100
116d43f3010STakashi Iwai #define LOLA_BAR1_DEST01_MIX00_01_GAIN		0x1104
117d43f3010STakashi Iwai #define LOLA_BAR1_DEST01_MIX30_31_GAIN		0x1140
118d43f3010STakashi Iwai #define LOLA_BAR1_DEST31_MIX00_01_GAIN		0x1884
119d43f3010STakashi Iwai #define LOLA_BAR1_DEST31_MIX30_31_GAIN		0x18c0
120d43f3010STakashi Iwai #define LOLA_BAR1_MIX_GAIN(dest, mix) \
121d43f3010STakashi Iwai 	(LOLA_BAR1_DEST00_MIX00_01_GAIN + (dest) * 0x40 + (mix) * 2)
122d43f3010STakashi Iwai #define LOLA_BAR1_ANALOG_CLIP_IN		0x18c4
123d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_SOURCE00_01	0x18c8
124d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_SOURCE30_31	0x1904
125d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_SOURCE(src) \
126d43f3010STakashi Iwai 	(LOLA_BAR1_PEAKMETERS_SOURCE00_01 + (src) * 2)
127d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_DEST00_01		0x1908
128d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_DEST30_31		0x1944
129d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_DEST(dest) \
130d43f3010STakashi Iwai 	(LOLA_BAR1_PEAKMETERS_DEST00_01 + (dest) * 2)
131d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_AGC00_01		0x1948
132d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_AGC14_15		0x1964
133d43f3010STakashi Iwai #define LOLA_BAR1_PEAKMETERS_AGC(x) \
134d43f3010STakashi Iwai 	(LOLA_BAR1_PEAKMETERS_AGC00_01 + (x) * 2)
135d43f3010STakashi Iwai 
136d43f3010STakashi Iwai /* GCTL reset bit */
137d43f3010STakashi Iwai #define LOLA_GCTL_RESET		(1 << 0)
138d43f3010STakashi Iwai /* GCTL unsolicited response enable bit */
139d43f3010STakashi Iwai #define LOLA_GCTL_UREN		(1 << 8)
140d43f3010STakashi Iwai 
141d43f3010STakashi Iwai /* CORB/RIRB control, read/write pointer */
142d43f3010STakashi Iwai #define LOLA_RBCTL_DMA_EN	0x02	/* enable DMA */
143d43f3010STakashi Iwai #define LOLA_RBCTL_IRQ_EN	0x01	/* enable IRQ */
144d43f3010STakashi Iwai #define LOLA_RBRWP_CLR		0x8000	/* read/write pointer clear */
145d43f3010STakashi Iwai 
146d43f3010STakashi Iwai #define LOLA_RIRB_EX_UNSOL_EV	0x40000000
147d43f3010STakashi Iwai #define LOLA_RIRB_EX_ERROR	0x80000000
148d43f3010STakashi Iwai 
149d43f3010STakashi Iwai /* CORB int mask: CMEI[0] */
150d43f3010STakashi Iwai #define LOLA_CORB_INT_CMEI	0x01
151d43f3010STakashi Iwai #define LOLA_CORB_INT_MASK	LOLA_CORB_INT_CMEI
152d43f3010STakashi Iwai 
153d43f3010STakashi Iwai /* RIRB int mask: overrun[2], response[0] */
154d43f3010STakashi Iwai #define LOLA_RIRB_INT_RESPONSE	0x01
155d43f3010STakashi Iwai #define LOLA_RIRB_INT_OVERRUN	0x04
156d43f3010STakashi Iwai #define LOLA_RIRB_INT_MASK	(LOLA_RIRB_INT_RESPONSE | LOLA_RIRB_INT_OVERRUN)
157d43f3010STakashi Iwai 
158d43f3010STakashi Iwai /* DINTCTL and DINTSTS */
159d43f3010STakashi Iwai #define LOLA_DINT_GLOBAL	0x80000000 /* global interrupt enable bit */
160d43f3010STakashi Iwai #define LOLA_DINT_CTRL		0x40000000 /* controller interrupt enable bit */
161d43f3010STakashi Iwai #define LOLA_DINT_FIFOERR	0x20000000 /* global fifo error enable bit */
162d43f3010STakashi Iwai #define LOLA_DINT_MUERR		0x10000000 /* global microcontroller underrun error */
163d43f3010STakashi Iwai 
164d43f3010STakashi Iwai /* DSDnCTL bits */
165d43f3010STakashi Iwai #define LOLA_DSD_CTL_SRST	0x01	/* stream reset bit */
166d43f3010STakashi Iwai #define LOLA_DSD_CTL_SRUN	0x02	/* stream DMA start bit */
167d43f3010STakashi Iwai #define LOLA_DSD_CTL_IOCE	0x04	/* interrupt on completion enable */
168d43f3010STakashi Iwai #define LOLA_DSD_CTL_DEIE	0x10	/* descriptor error interrupt enable */
169d43f3010STakashi Iwai #define LOLA_DSD_CTL_VLRCV	0x20	/* valid LRCountValue information in bits 8..31 */
170d43f3010STakashi Iwai #define LOLA_LRC_MASK		0xffffff00
171d43f3010STakashi Iwai 
172d43f3010STakashi Iwai /* DSDnSTS */
173d43f3010STakashi Iwai #define LOLA_DSD_STS_BCIS	0x04	/* buffer completion interrupt status */
174d43f3010STakashi Iwai #define LOLA_DSD_STS_DESE	0x10	/* descriptor error interrupt */
175d43f3010STakashi Iwai #define LOLA_DSD_STS_FIFORDY	0x20	/* fifo ready */
176d43f3010STakashi Iwai 
177d43f3010STakashi Iwai #define LOLA_CORB_ENTRIES	256
178d43f3010STakashi Iwai 
179d43f3010STakashi Iwai #define MAX_STREAM_IN_COUNT	16
180d43f3010STakashi Iwai #define MAX_STREAM_OUT_COUNT	16
181d43f3010STakashi Iwai #define MAX_STREAM_COUNT	16
182d43f3010STakashi Iwai #define MAX_PINS		MAX_STREAM_COUNT
183d43f3010STakashi Iwai #define MAX_STREAM_BUFFER_COUNT	16
184d43f3010STakashi Iwai #define MAX_AUDIO_INOUT_COUNT	16
185d43f3010STakashi Iwai 
186d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_INTERNAL    0
187d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_AES         1
188d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_AES_SYNC    2
189d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_WORDCLOCK   3
190d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_ETHERSOUND  4
191d43f3010STakashi Iwai #define LOLA_CLOCK_TYPE_VIDEO       5
192d43f3010STakashi Iwai 
193d43f3010STakashi Iwai #define LOLA_CLOCK_FORMAT_NONE      0
194d43f3010STakashi Iwai #define LOLA_CLOCK_FORMAT_NTSC      1
195d43f3010STakashi Iwai #define LOLA_CLOCK_FORMAT_PAL       2
196d43f3010STakashi Iwai 
197d43f3010STakashi Iwai #define MAX_SAMPLE_CLOCK_COUNT  48
198d43f3010STakashi Iwai 
199d43f3010STakashi Iwai /* parameters used with mixer widget's mixer capabilities */
200d43f3010STakashi Iwai #define LOLA_PEAK_METER_CAN_AGC_MASK		1
201d43f3010STakashi Iwai #define LOLA_PEAK_METER_CAN_ANALOG_CLIP_MASK	2
202d43f3010STakashi Iwai 
203d43f3010STakashi Iwai struct lola_bar {
204d43f3010STakashi Iwai 	unsigned long addr;
205d43f3010STakashi Iwai 	void __iomem *remap_addr;
206d43f3010STakashi Iwai };
207d43f3010STakashi Iwai 
208d43f3010STakashi Iwai /* CORB/RIRB */
209d43f3010STakashi Iwai struct lola_rb {
2100d9a26fcSTakashi Iwai 	__le32 *buf;		/* CORB/RIRB buffer, 8 byte per each entry */
211d43f3010STakashi Iwai 	dma_addr_t addr;	/* physical address of CORB/RIRB buffer */
212d43f3010STakashi Iwai 	unsigned short rp, wp;	/* read/write pointers */
213d43f3010STakashi Iwai 	int cmds;		/* number of pending requests */
214d43f3010STakashi Iwai };
215d43f3010STakashi Iwai 
216d43f3010STakashi Iwai /* Pin widget setup */
217d43f3010STakashi Iwai struct lola_pin {
218d43f3010STakashi Iwai 	unsigned int nid;
219d43f3010STakashi Iwai 	bool is_analog;
220d43f3010STakashi Iwai 	unsigned int amp_mute;
221d43f3010STakashi Iwai 	unsigned int amp_step_size;
222d43f3010STakashi Iwai 	unsigned int amp_num_steps;
223d43f3010STakashi Iwai 	unsigned int amp_offset;
224d43f3010STakashi Iwai 	unsigned int max_level;
225d43f3010STakashi Iwai 	unsigned int config_default_reg;
226d43f3010STakashi Iwai 	unsigned int fixed_gain_list_len;
227d43f3010STakashi Iwai 	unsigned int cur_gain_step;
228d43f3010STakashi Iwai };
229d43f3010STakashi Iwai 
230d43f3010STakashi Iwai struct lola_pin_array {
231d43f3010STakashi Iwai 	unsigned int num_pins;
2322db30020STakashi Iwai 	unsigned int num_analog_pins;
233d43f3010STakashi Iwai 	struct lola_pin pins[MAX_PINS];
234d43f3010STakashi Iwai };
235d43f3010STakashi Iwai 
236d43f3010STakashi Iwai /* Clock widget setup */
237d43f3010STakashi Iwai struct lola_sample_clock {
238d43f3010STakashi Iwai 	unsigned int type;
239d43f3010STakashi Iwai 	unsigned int format;
240d43f3010STakashi Iwai 	unsigned int freq;
241d43f3010STakashi Iwai };
242d43f3010STakashi Iwai 
243d43f3010STakashi Iwai struct lola_clock_widget {
244d43f3010STakashi Iwai 	unsigned int nid;
245d43f3010STakashi Iwai 	unsigned int items;
246d43f3010STakashi Iwai 	unsigned int cur_index;
247d43f3010STakashi Iwai 	unsigned int cur_freq;
248d43f3010STakashi Iwai 	bool cur_valid;
249d43f3010STakashi Iwai 	struct lola_sample_clock sample_clock[MAX_SAMPLE_CLOCK_COUNT];
250d43f3010STakashi Iwai 	unsigned int idx_lookup[MAX_SAMPLE_CLOCK_COUNT];
251d43f3010STakashi Iwai };
252d43f3010STakashi Iwai 
253d43f3010STakashi Iwai #define LOLA_MIXER_DIM      32
254d43f3010STakashi Iwai struct lola_mixer_array {
255d43f3010STakashi Iwai 	u32 src_gain_enable;
256d43f3010STakashi Iwai 	u32 dest_mix_gain_enable[LOLA_MIXER_DIM];
257d43f3010STakashi Iwai 	u16 src_gain[LOLA_MIXER_DIM];
258d43f3010STakashi Iwai 	u16 dest_mix_gain[LOLA_MIXER_DIM][LOLA_MIXER_DIM];
259d43f3010STakashi Iwai };
260d43f3010STakashi Iwai 
261d43f3010STakashi Iwai /* Mixer widget setup */
262d43f3010STakashi Iwai struct lola_mixer_widget {
263d43f3010STakashi Iwai 	unsigned int nid;
264d43f3010STakashi Iwai 	unsigned int caps;
2650d9a26fcSTakashi Iwai 	struct lola_mixer_array __iomem *array;
266d43f3010STakashi Iwai 	struct lola_mixer_array *array_saved;
267d43f3010STakashi Iwai 	unsigned int src_stream_outs;
268d43f3010STakashi Iwai 	unsigned int src_phys_ins;
269d43f3010STakashi Iwai 	unsigned int dest_stream_ins;
270d43f3010STakashi Iwai 	unsigned int dest_phys_outs;
271d43f3010STakashi Iwai 	unsigned int src_stream_out_ofs;
272d43f3010STakashi Iwai 	unsigned int dest_phys_out_ofs;
273d43f3010STakashi Iwai 	unsigned int src_mask;
274d43f3010STakashi Iwai 	unsigned int dest_mask;
275d43f3010STakashi Iwai };
276d43f3010STakashi Iwai 
277d43f3010STakashi Iwai /* Audio stream */
278d43f3010STakashi Iwai struct lola_stream {
279d43f3010STakashi Iwai 	unsigned int nid;	/* audio widget NID */
280d43f3010STakashi Iwai 	unsigned int index;	/* array index */
281d43f3010STakashi Iwai 	unsigned int dsd;	/* DSD index */
282d43f3010STakashi Iwai 	bool can_float;
283d43f3010STakashi Iwai 	struct snd_pcm_substream *substream; /* assigned PCM substream */
284d43f3010STakashi Iwai 	struct lola_stream *master;	/* master stream (for multi-channel) */
285d43f3010STakashi Iwai 
286d43f3010STakashi Iwai 	/* buffer setup */
287d43f3010STakashi Iwai 	unsigned int bufsize;
288d43f3010STakashi Iwai 	unsigned int period_bytes;
289d43f3010STakashi Iwai 	unsigned int frags;
290d43f3010STakashi Iwai 
291d43f3010STakashi Iwai 	/* format + channel setup */
292d43f3010STakashi Iwai 	unsigned int format_verb;
293d43f3010STakashi Iwai 
294d43f3010STakashi Iwai 	/* flags */
295d43f3010STakashi Iwai 	unsigned int opened:1;
2960f8f56c9STakashi Iwai 	unsigned int prepared:1;
2977e79f226STakashi Iwai 	unsigned int paused:1;
298d43f3010STakashi Iwai 	unsigned int running:1;
299d43f3010STakashi Iwai };
300d43f3010STakashi Iwai 
301d43f3010STakashi Iwai #define PLAY	SNDRV_PCM_STREAM_PLAYBACK
302d43f3010STakashi Iwai #define CAPT	SNDRV_PCM_STREAM_CAPTURE
303d43f3010STakashi Iwai 
304d43f3010STakashi Iwai struct lola_pcm {
305d43f3010STakashi Iwai 	unsigned int num_streams;
306*098fe3d6STakashi Iwai 	struct snd_dma_buffer *bdl; /* BDL buffer */
307d43f3010STakashi Iwai 	struct lola_stream streams[MAX_STREAM_COUNT];
308d43f3010STakashi Iwai };
309d43f3010STakashi Iwai 
310d43f3010STakashi Iwai /* card instance */
311d43f3010STakashi Iwai struct lola {
312d43f3010STakashi Iwai 	struct snd_card *card;
313d43f3010STakashi Iwai 	struct pci_dev *pci;
314d43f3010STakashi Iwai 
315d43f3010STakashi Iwai 	/* pci resources */
316d43f3010STakashi Iwai 	struct lola_bar bar[2];
317d43f3010STakashi Iwai 	int irq;
318d43f3010STakashi Iwai 
319d43f3010STakashi Iwai 	/* locks */
320d43f3010STakashi Iwai 	spinlock_t reg_lock;
321d43f3010STakashi Iwai 	struct mutex open_mutex;
322d43f3010STakashi Iwai 
323d43f3010STakashi Iwai 	/* CORB/RIRB */
324d43f3010STakashi Iwai 	struct lola_rb corb;
325d43f3010STakashi Iwai 	struct lola_rb rirb;
326d43f3010STakashi Iwai 	unsigned int res, res_ex;	/* last read values */
327d43f3010STakashi Iwai 	/* last command (for debugging) */
328d43f3010STakashi Iwai 	unsigned int last_cmd_nid, last_verb, last_data, last_extdata;
329d43f3010STakashi Iwai 
330d43f3010STakashi Iwai 	/* CORB/RIRB buffers */
331*098fe3d6STakashi Iwai 	struct snd_dma_buffer *rb;
332d43f3010STakashi Iwai 
333d43f3010STakashi Iwai 	/* unsolicited events */
334d43f3010STakashi Iwai 	unsigned int last_unsol_res;
335d43f3010STakashi Iwai 
336d43f3010STakashi Iwai 	/* streams */
337d43f3010STakashi Iwai 	struct lola_pcm pcm[2];
338d43f3010STakashi Iwai 
339d43f3010STakashi Iwai 	/* input src */
340d43f3010STakashi Iwai 	unsigned int input_src_caps_mask;
341d43f3010STakashi Iwai 	unsigned int input_src_mask;
342d43f3010STakashi Iwai 
343d43f3010STakashi Iwai 	/* pins */
344d43f3010STakashi Iwai 	struct lola_pin_array pin[2];
345d43f3010STakashi Iwai 
346d43f3010STakashi Iwai 	/* clock */
347d43f3010STakashi Iwai 	struct lola_clock_widget clock;
3487e79f226STakashi Iwai 	int ref_count_rate;
3497e79f226STakashi Iwai 	unsigned int sample_rate;
350d43f3010STakashi Iwai 
351d43f3010STakashi Iwai 	/* mixer */
352d43f3010STakashi Iwai 	struct lola_mixer_widget mixer;
353d43f3010STakashi Iwai 
354d43f3010STakashi Iwai 	/* hw info */
355d43f3010STakashi Iwai 	unsigned int version;
356d43f3010STakashi Iwai 	unsigned int lola_caps;
357d43f3010STakashi Iwai 
358d43f3010STakashi Iwai 	/* parameters */
359d43f3010STakashi Iwai 	unsigned int granularity;
360d43f3010STakashi Iwai 	unsigned int sample_rate_min;
3618bd172dcSTakashi Iwai 	unsigned int sample_rate_max;
362d43f3010STakashi Iwai 
363d43f3010STakashi Iwai 	/* flags */
364d43f3010STakashi Iwai 	unsigned int initialized:1;
365d43f3010STakashi Iwai 	unsigned int cold_reset:1;
366fe4af1b5STakashi Iwai 	unsigned int polling_mode:1;
367d43f3010STakashi Iwai 
368d43f3010STakashi Iwai 	/* for debugging */
369d43f3010STakashi Iwai 	unsigned int debug_res;
370d43f3010STakashi Iwai 	unsigned int debug_res_ex;
371d43f3010STakashi Iwai };
372d43f3010STakashi Iwai 
373d43f3010STakashi Iwai #define BAR0	0
374d43f3010STakashi Iwai #define BAR1	1
375d43f3010STakashi Iwai 
376d43f3010STakashi Iwai /* Helper macros */
377d43f3010STakashi Iwai #define lola_readl(chip, idx, name) \
378d43f3010STakashi Iwai 	readl((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
379d43f3010STakashi Iwai #define lola_readw(chip, idx, name) \
380d43f3010STakashi Iwai 	readw((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
381d43f3010STakashi Iwai #define lola_readb(chip, idx, name) \
382d43f3010STakashi Iwai 	readb((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
383d43f3010STakashi Iwai #define lola_writel(chip, idx, name, val) \
384d43f3010STakashi Iwai 	writel((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
385d43f3010STakashi Iwai #define lola_writew(chip, idx, name, val) \
386d43f3010STakashi Iwai 	writew((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
387d43f3010STakashi Iwai #define lola_writeb(chip, idx, name, val) \
388d43f3010STakashi Iwai 	writeb((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
389d43f3010STakashi Iwai 
390d43f3010STakashi Iwai #define lola_dsd_read(chip, dsd, name) \
391d43f3010STakashi Iwai 	readl((chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
392d43f3010STakashi Iwai 	      (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
393d43f3010STakashi Iwai #define lola_dsd_write(chip, dsd, name, val) \
394d43f3010STakashi Iwai 	writel((val), (chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
395d43f3010STakashi Iwai 	       (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
396d43f3010STakashi Iwai 
397d43f3010STakashi Iwai /* GET verbs HDAudio */
398d43f3010STakashi Iwai #define LOLA_VERB_GET_STREAM_FORMAT		0xa00
399d43f3010STakashi Iwai #define LOLA_VERB_GET_AMP_GAIN_MUTE		0xb00
400d43f3010STakashi Iwai #define LOLA_VERB_PARAMETERS			0xf00
401d43f3010STakashi Iwai #define LOLA_VERB_GET_POWER_STATE		0xf05
402d43f3010STakashi Iwai #define LOLA_VERB_GET_CONV			0xf06
403d43f3010STakashi Iwai #define LOLA_VERB_GET_UNSOLICITED_RESPONSE	0xf08
404d43f3010STakashi Iwai #define LOLA_VERB_GET_DIGI_CONVERT_1		0xf0d
405d43f3010STakashi Iwai #define LOLA_VERB_GET_CONFIG_DEFAULT		0xf1c
406d43f3010STakashi Iwai #define LOLA_VERB_GET_SUBSYSTEM_ID		0xf20
407d43f3010STakashi Iwai /* GET verbs Digigram */
408d43f3010STakashi Iwai #define LOLA_VERB_GET_FIXED_GAIN		0xfc0
409d43f3010STakashi Iwai #define LOLA_VERB_GET_GAIN_SELECT		0xfc1
410d43f3010STakashi Iwai #define LOLA_VERB_GET_MAX_LEVEL			0xfc2
411d43f3010STakashi Iwai #define LOLA_VERB_GET_CLOCK_LIST		0xfc3
412d43f3010STakashi Iwai #define LOLA_VERB_GET_CLOCK_SELECT		0xfc4
413d43f3010STakashi Iwai #define LOLA_VERB_GET_CLOCK_STATUS		0xfc5
414d43f3010STakashi Iwai 
415d43f3010STakashi Iwai /* SET verbs HDAudio */
416d43f3010STakashi Iwai #define LOLA_VERB_SET_STREAM_FORMAT		0x200
417d43f3010STakashi Iwai #define LOLA_VERB_SET_AMP_GAIN_MUTE		0x300
418d43f3010STakashi Iwai #define LOLA_VERB_SET_POWER_STATE		0x705
419d43f3010STakashi Iwai #define LOLA_VERB_SET_CHANNEL_STREAMID		0x706
420d43f3010STakashi Iwai #define LOLA_VERB_SET_UNSOLICITED_ENABLE	0x708
421d43f3010STakashi Iwai #define LOLA_VERB_SET_DIGI_CONVERT_1		0x70d
422d43f3010STakashi Iwai /* SET verbs Digigram */
423d43f3010STakashi Iwai #define LOLA_VERB_SET_GAIN_SELECT		0xf81
424d43f3010STakashi Iwai #define LOLA_VERB_SET_CLOCK_SELECT		0xf84
425d43f3010STakashi Iwai #define LOLA_VERB_SET_GRANULARITY_STEPS		0xf86
426d43f3010STakashi Iwai #define LOLA_VERB_SET_SOURCE_GAIN		0xf87
427d43f3010STakashi Iwai #define LOLA_VERB_SET_MIX_GAIN			0xf88
428d43f3010STakashi Iwai #define LOLA_VERB_SET_DESTINATION_GAIN		0xf89
429d43f3010STakashi Iwai #define LOLA_VERB_SET_SRC			0xf8a
430d43f3010STakashi Iwai 
431d43f3010STakashi Iwai /* Parameter IDs used with LOLA_VERB_PARAMETERS */
432d43f3010STakashi Iwai #define LOLA_PAR_VENDOR_ID			0x00
433d43f3010STakashi Iwai #define LOLA_PAR_FUNCTION_TYPE			0x05
434d43f3010STakashi Iwai #define LOLA_PAR_AUDIO_WIDGET_CAP		0x09
435d43f3010STakashi Iwai #define LOLA_PAR_PCM				0x0a
436d43f3010STakashi Iwai #define LOLA_PAR_STREAM_FORMATS			0x0b
437d43f3010STakashi Iwai #define LOLA_PAR_PIN_CAP			0x0c
438d43f3010STakashi Iwai #define LOLA_PAR_AMP_IN_CAP			0x0d
439d43f3010STakashi Iwai #define LOLA_PAR_CONNLIST_LEN			0x0e
440d43f3010STakashi Iwai #define LOLA_PAR_POWER_STATE			0x0f
441d43f3010STakashi Iwai #define LOLA_PAR_GPIO_CAP			0x11
442d43f3010STakashi Iwai #define LOLA_PAR_AMP_OUT_CAP			0x12
443d43f3010STakashi Iwai #define LOLA_PAR_SPECIFIC_CAPS			0x80
444d43f3010STakashi Iwai #define LOLA_PAR_FIXED_GAIN_LIST		0x81
445d43f3010STakashi Iwai 
446d43f3010STakashi Iwai /* extract results of LOLA_PAR_SPECIFIC_CAPS */
447d43f3010STakashi Iwai #define LOLA_AFG_MIXER_WIDGET_PRESENT(res)	((res & (1 << 21)) != 0)
448d43f3010STakashi Iwai #define LOLA_AFG_CLOCK_WIDGET_PRESENT(res)	((res & (1 << 20)) != 0)
449d43f3010STakashi Iwai #define LOLA_AFG_INPUT_PIN_COUNT(res)		((res >> 10) & 0x2ff)
450d43f3010STakashi Iwai #define LOLA_AFG_OUTPUT_PIN_COUNT(res)		((res) & 0x2ff)
451d43f3010STakashi Iwai 
452d43f3010STakashi Iwai /* extract results of LOLA_PAR_AMP_IN_CAP / LOLA_PAR_AMP_OUT_CAP */
453d43f3010STakashi Iwai #define LOLA_AMP_MUTE_CAPABLE(res)		((res & (1 << 31)) != 0)
454d43f3010STakashi Iwai #define LOLA_AMP_STEP_SIZE(res)			((res >> 24) & 0x7f)
455d43f3010STakashi Iwai #define LOLA_AMP_NUM_STEPS(res)			((res >> 12) & 0x3ff)
456d43f3010STakashi Iwai #define LOLA_AMP_OFFSET(res)			((res) & 0x3ff)
457d43f3010STakashi Iwai 
458d43f3010STakashi Iwai #define LOLA_GRANULARITY_MIN		8
459d43f3010STakashi Iwai #define LOLA_GRANULARITY_MAX		32
460d43f3010STakashi Iwai #define LOLA_GRANULARITY_STEP		8
461d43f3010STakashi Iwai 
462d43f3010STakashi Iwai /* parameters used with unsolicited command/response */
463d43f3010STakashi Iwai #define LOLA_UNSOLICITED_TAG_MASK	0x3f
464d43f3010STakashi Iwai #define LOLA_UNSOLICITED_TAG		0x1a
465d43f3010STakashi Iwai #define LOLA_UNSOLICITED_ENABLE		0x80
466d43f3010STakashi Iwai #define LOLA_UNSOL_RESP_TAG_OFFSET	26
467d43f3010STakashi Iwai 
468d43f3010STakashi Iwai /* count values in the Vendor Specific Mixer Widget's Audio Widget Capabilities */
469d43f3010STakashi Iwai #define LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(res)   ((res >> 2) & 0x1f)
47014705799SMarkus Bollinger #define LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(res)  ((res >> 7) & 0x1f)
471d43f3010STakashi Iwai 
472d43f3010STakashi Iwai int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
473d43f3010STakashi Iwai 		     unsigned int data, unsigned int extdata);
474d43f3010STakashi Iwai int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
475d43f3010STakashi Iwai 		    unsigned int data, unsigned int extdata,
476d43f3010STakashi Iwai 		    unsigned int *val, unsigned int *extval);
477d43f3010STakashi Iwai int lola_codec_flush(struct lola *chip);
478d43f3010STakashi Iwai #define lola_read_param(chip, nid, param, val) \
479d43f3010STakashi Iwai 	lola_codec_read(chip, nid, LOLA_VERB_PARAMETERS, param, 0, val, NULL)
480d43f3010STakashi Iwai 
481d43f3010STakashi Iwai /* PCM */
482d43f3010STakashi Iwai int lola_create_pcm(struct lola *chip);
483d43f3010STakashi Iwai int lola_init_pcm(struct lola *chip, int dir, int *nidp);
484d43f3010STakashi Iwai void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits);
485d43f3010STakashi Iwai 
486d43f3010STakashi Iwai /* clock */
487d43f3010STakashi Iwai int lola_init_clock_widget(struct lola *chip, int nid);
488d43f3010STakashi Iwai int lola_set_granularity(struct lola *chip, unsigned int val, bool force);
489d43f3010STakashi Iwai int lola_enable_clock_events(struct lola *chip);
490d43f3010STakashi Iwai int lola_set_clock_index(struct lola *chip, unsigned int idx);
491d43f3010STakashi Iwai int lola_set_clock(struct lola *chip, int idx);
492d43f3010STakashi Iwai int lola_set_sample_rate(struct lola *chip, int rate);
493d43f3010STakashi Iwai bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val);
4941c5d7b31STakashi Iwai unsigned int lola_sample_rate_convert(unsigned int coded);
495d43f3010STakashi Iwai 
496d43f3010STakashi Iwai /* mixer */
497d43f3010STakashi Iwai int lola_init_pins(struct lola *chip, int dir, int *nidp);
498d43f3010STakashi Iwai int lola_init_mixer_widget(struct lola *chip, int nid);
499d43f3010STakashi Iwai void lola_free_mixer(struct lola *chip);
500d43f3010STakashi Iwai int lola_create_mixer(struct lola *chip);
501d43f3010STakashi Iwai int lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute);
502d43f3010STakashi Iwai void lola_save_mixer(struct lola *chip);
503d43f3010STakashi Iwai void lola_restore_mixer(struct lola *chip);
504d43f3010STakashi Iwai int lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update);
505d43f3010STakashi Iwai 
506d43f3010STakashi Iwai /* proc */
507d43f3010STakashi Iwai #ifdef CONFIG_SND_DEBUG
508d43f3010STakashi Iwai void lola_proc_debug_new(struct lola *chip);
509d43f3010STakashi Iwai #else
510d43f3010STakashi Iwai #define lola_proc_debug_new(chip)
511d43f3010STakashi Iwai #endif
512d43f3010STakashi Iwai 
513d43f3010STakashi Iwai #endif /* _LOLA_H */
514