18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Support for Digigram Lola PCI-e boards
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _LOLA_H
98c2ecf20Sopenharmony_ci#define _LOLA_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define DRVNAME	"snd-lola"
128c2ecf20Sopenharmony_ci#define SFX	DRVNAME ": "
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * Lola HD Audio Registers BAR0
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci#define LOLA_BAR0_GCAP		0x00
188c2ecf20Sopenharmony_ci#define LOLA_BAR0_VMIN		0x02
198c2ecf20Sopenharmony_ci#define LOLA_BAR0_VMAJ		0x03
208c2ecf20Sopenharmony_ci#define LOLA_BAR0_OUTPAY	0x04
218c2ecf20Sopenharmony_ci#define LOLA_BAR0_INPAY		0x06
228c2ecf20Sopenharmony_ci#define LOLA_BAR0_GCTL		0x08
238c2ecf20Sopenharmony_ci#define LOLA_BAR0_WAKEEN	0x0c
248c2ecf20Sopenharmony_ci#define LOLA_BAR0_STATESTS	0x0e
258c2ecf20Sopenharmony_ci#define LOLA_BAR0_GSTS		0x10
268c2ecf20Sopenharmony_ci#define LOLA_BAR0_OUTSTRMPAY	0x18
278c2ecf20Sopenharmony_ci#define LOLA_BAR0_INSTRMPAY	0x1a
288c2ecf20Sopenharmony_ci#define LOLA_BAR0_INTCTL	0x20
298c2ecf20Sopenharmony_ci#define LOLA_BAR0_INTSTS	0x24
308c2ecf20Sopenharmony_ci#define LOLA_BAR0_WALCLK	0x30
318c2ecf20Sopenharmony_ci#define LOLA_BAR0_SSYNC		0x38
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBLBASE	0x40
348c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBUBASE	0x44
358c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBWP	0x48	/* no ULONG access */
368c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBRP	0x4a	/* no ULONG access */
378c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBCTL	0x4c	/* no ULONG access */
388c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBSTS	0x4d	/* UCHAR access only */
398c2ecf20Sopenharmony_ci#define LOLA_BAR0_CORBSIZE	0x4e	/* no ULONG access */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBLBASE	0x50
428c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBUBASE	0x54
438c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBWP	0x58
448c2ecf20Sopenharmony_ci#define LOLA_BAR0_RINTCNT	0x5a	/* no ULONG access */
458c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBCTL	0x5c
468c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBSTS	0x5d	/* UCHAR access only */
478c2ecf20Sopenharmony_ci#define LOLA_BAR0_RIRBSIZE	0x5e	/* no ULONG access */
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define LOLA_BAR0_ICW		0x60
508c2ecf20Sopenharmony_ci#define LOLA_BAR0_IRR		0x64
518c2ecf20Sopenharmony_ci#define LOLA_BAR0_ICS		0x68
528c2ecf20Sopenharmony_ci#define LOLA_BAR0_DPLBASE	0x70
538c2ecf20Sopenharmony_ci#define LOLA_BAR0_DPUBASE	0x74
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* stream register offsets from stream base 0x80 */
568c2ecf20Sopenharmony_ci#define LOLA_BAR0_SD0_OFFSET	0x80
578c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_CTL	0x00
588c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_STS	0x03
598c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_LPIB	0x04
608c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_CBL	0x08
618c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_LVI	0x0c
628c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_FIFOW	0x0e
638c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_FIFOSIZE	0x10
648c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_FORMAT	0x12
658c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_BDLPL	0x18
668c2ecf20Sopenharmony_ci#define LOLA_REG0_SD_BDLPU	0x1c
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/*
698c2ecf20Sopenharmony_ci * Lola Digigram Registers BAR1
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_ci#define LOLA_BAR1_FPGAVER	0x00
728c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEVER		0x04
738c2ecf20Sopenharmony_ci#define LOLA_BAR1_UCBMV		0x08
748c2ecf20Sopenharmony_ci#define LOLA_BAR1_JTAG		0x0c
758c2ecf20Sopenharmony_ci#define LOLA_BAR1_UARTRX	0x10
768c2ecf20Sopenharmony_ci#define LOLA_BAR1_UARTTX	0x14
778c2ecf20Sopenharmony_ci#define LOLA_BAR1_UARTCR	0x18
788c2ecf20Sopenharmony_ci#define LOLA_BAR1_NVRAMVER	0x1c
798c2ecf20Sopenharmony_ci#define LOLA_BAR1_CTRLSPI	0x20
808c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSPI		0x24
818c2ecf20Sopenharmony_ci#define LOLA_BAR1_AISPI		0x28
828c2ecf20Sopenharmony_ci#define LOLA_BAR1_GRAN		0x2c
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define LOLA_BAR1_DINTCTL	0x80
858c2ecf20Sopenharmony_ci#define LOLA_BAR1_DIINTCTL	0x84
868c2ecf20Sopenharmony_ci#define LOLA_BAR1_DOINTCTL	0x88
878c2ecf20Sopenharmony_ci#define LOLA_BAR1_LRC		0x90
888c2ecf20Sopenharmony_ci#define LOLA_BAR1_DINTSTS	0x94
898c2ecf20Sopenharmony_ci#define LOLA_BAR1_DIINTSTS	0x98
908c2ecf20Sopenharmony_ci#define LOLA_BAR1_DOINTSTS	0x9c
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSD0_OFFSET	0xa0
938c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSD_SIZE	0x18
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnSTS       0x00
968c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnLPIB      0x04
978c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnCTL       0x08
988c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnLVI       0x0c
998c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnBDPL      0x10
1008c2ecf20Sopenharmony_ci#define LOLA_BAR1_DSDnBDPU      0x14
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define LOLA_BAR1_SSYNC		0x03e8
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define LOLA_BAR1_BOARD_CTRL	0x0f00
1058c2ecf20Sopenharmony_ci#define LOLA_BAR1_BOARD_MODE	0x0f02
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define LOLA_BAR1_SOURCE_GAIN_ENABLE		0x1000
1088c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST00_MIX_GAIN_ENABLE	0x1004
1098c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST31_MIX_GAIN_ENABLE	0x1080
1108c2ecf20Sopenharmony_ci#define LOLA_BAR1_SOURCE00_01_GAIN		0x1084
1118c2ecf20Sopenharmony_ci#define LOLA_BAR1_SOURCE30_31_GAIN		0x10c0
1128c2ecf20Sopenharmony_ci#define LOLA_BAR1_SOURCE_GAIN(src) \
1138c2ecf20Sopenharmony_ci	(LOLA_BAR1_SOURCE00_01_GAIN + (src) * 2)
1148c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST00_MIX00_01_GAIN		0x10c4
1158c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST00_MIX30_31_GAIN		0x1100
1168c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST01_MIX00_01_GAIN		0x1104
1178c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST01_MIX30_31_GAIN		0x1140
1188c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST31_MIX00_01_GAIN		0x1884
1198c2ecf20Sopenharmony_ci#define LOLA_BAR1_DEST31_MIX30_31_GAIN		0x18c0
1208c2ecf20Sopenharmony_ci#define LOLA_BAR1_MIX_GAIN(dest, mix) \
1218c2ecf20Sopenharmony_ci	(LOLA_BAR1_DEST00_MIX00_01_GAIN + (dest) * 0x40 + (mix) * 2)
1228c2ecf20Sopenharmony_ci#define LOLA_BAR1_ANALOG_CLIP_IN		0x18c4
1238c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_SOURCE00_01	0x18c8
1248c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_SOURCE30_31	0x1904
1258c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_SOURCE(src) \
1268c2ecf20Sopenharmony_ci	(LOLA_BAR1_PEAKMETERS_SOURCE00_01 + (src) * 2)
1278c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_DEST00_01		0x1908
1288c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_DEST30_31		0x1944
1298c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_DEST(dest) \
1308c2ecf20Sopenharmony_ci	(LOLA_BAR1_PEAKMETERS_DEST00_01 + (dest) * 2)
1318c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_AGC00_01		0x1948
1328c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_AGC14_15		0x1964
1338c2ecf20Sopenharmony_ci#define LOLA_BAR1_PEAKMETERS_AGC(x) \
1348c2ecf20Sopenharmony_ci	(LOLA_BAR1_PEAKMETERS_AGC00_01 + (x) * 2)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/* GCTL reset bit */
1378c2ecf20Sopenharmony_ci#define LOLA_GCTL_RESET		(1 << 0)
1388c2ecf20Sopenharmony_ci/* GCTL unsolicited response enable bit */
1398c2ecf20Sopenharmony_ci#define LOLA_GCTL_UREN		(1 << 8)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* CORB/RIRB control, read/write pointer */
1428c2ecf20Sopenharmony_ci#define LOLA_RBCTL_DMA_EN	0x02	/* enable DMA */
1438c2ecf20Sopenharmony_ci#define LOLA_RBCTL_IRQ_EN	0x01	/* enable IRQ */
1448c2ecf20Sopenharmony_ci#define LOLA_RBRWP_CLR		0x8000	/* read/write pointer clear */
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define LOLA_RIRB_EX_UNSOL_EV	0x40000000
1478c2ecf20Sopenharmony_ci#define LOLA_RIRB_EX_ERROR	0x80000000
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/* CORB int mask: CMEI[0] */
1508c2ecf20Sopenharmony_ci#define LOLA_CORB_INT_CMEI	0x01
1518c2ecf20Sopenharmony_ci#define LOLA_CORB_INT_MASK	LOLA_CORB_INT_CMEI
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* RIRB int mask: overrun[2], response[0] */
1548c2ecf20Sopenharmony_ci#define LOLA_RIRB_INT_RESPONSE	0x01
1558c2ecf20Sopenharmony_ci#define LOLA_RIRB_INT_OVERRUN	0x04
1568c2ecf20Sopenharmony_ci#define LOLA_RIRB_INT_MASK	(LOLA_RIRB_INT_RESPONSE | LOLA_RIRB_INT_OVERRUN)
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci/* DINTCTL and DINTSTS */
1598c2ecf20Sopenharmony_ci#define LOLA_DINT_GLOBAL	0x80000000 /* global interrupt enable bit */
1608c2ecf20Sopenharmony_ci#define LOLA_DINT_CTRL		0x40000000 /* controller interrupt enable bit */
1618c2ecf20Sopenharmony_ci#define LOLA_DINT_FIFOERR	0x20000000 /* global fifo error enable bit */
1628c2ecf20Sopenharmony_ci#define LOLA_DINT_MUERR		0x10000000 /* global microcontroller underrun error */
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* DSDnCTL bits */
1658c2ecf20Sopenharmony_ci#define LOLA_DSD_CTL_SRST	0x01	/* stream reset bit */
1668c2ecf20Sopenharmony_ci#define LOLA_DSD_CTL_SRUN	0x02	/* stream DMA start bit */
1678c2ecf20Sopenharmony_ci#define LOLA_DSD_CTL_IOCE	0x04	/* interrupt on completion enable */
1688c2ecf20Sopenharmony_ci#define LOLA_DSD_CTL_DEIE	0x10	/* descriptor error interrupt enable */
1698c2ecf20Sopenharmony_ci#define LOLA_DSD_CTL_VLRCV	0x20	/* valid LRCountValue information in bits 8..31 */
1708c2ecf20Sopenharmony_ci#define LOLA_LRC_MASK		0xffffff00
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* DSDnSTS */
1738c2ecf20Sopenharmony_ci#define LOLA_DSD_STS_BCIS	0x04	/* buffer completion interrupt status */
1748c2ecf20Sopenharmony_ci#define LOLA_DSD_STS_DESE	0x10	/* descriptor error interrupt */
1758c2ecf20Sopenharmony_ci#define LOLA_DSD_STS_FIFORDY	0x20	/* fifo ready */
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define LOLA_CORB_ENTRIES	256
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#define MAX_STREAM_IN_COUNT	16
1808c2ecf20Sopenharmony_ci#define MAX_STREAM_OUT_COUNT	16
1818c2ecf20Sopenharmony_ci#define MAX_STREAM_COUNT	16
1828c2ecf20Sopenharmony_ci#define MAX_PINS		MAX_STREAM_COUNT
1838c2ecf20Sopenharmony_ci#define MAX_STREAM_BUFFER_COUNT	16
1848c2ecf20Sopenharmony_ci#define MAX_AUDIO_INOUT_COUNT	16
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_INTERNAL    0
1878c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_AES         1
1888c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_AES_SYNC    2
1898c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_WORDCLOCK   3
1908c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_ETHERSOUND  4
1918c2ecf20Sopenharmony_ci#define LOLA_CLOCK_TYPE_VIDEO       5
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define LOLA_CLOCK_FORMAT_NONE      0
1948c2ecf20Sopenharmony_ci#define LOLA_CLOCK_FORMAT_NTSC      1
1958c2ecf20Sopenharmony_ci#define LOLA_CLOCK_FORMAT_PAL       2
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci#define MAX_SAMPLE_CLOCK_COUNT  48
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* parameters used with mixer widget's mixer capabilities */
2008c2ecf20Sopenharmony_ci#define LOLA_PEAK_METER_CAN_AGC_MASK		1
2018c2ecf20Sopenharmony_ci#define LOLA_PEAK_METER_CAN_ANALOG_CLIP_MASK	2
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistruct lola_bar {
2048c2ecf20Sopenharmony_ci	unsigned long addr;
2058c2ecf20Sopenharmony_ci	void __iomem *remap_addr;
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* CORB/RIRB */
2098c2ecf20Sopenharmony_cistruct lola_rb {
2108c2ecf20Sopenharmony_ci	__le32 *buf;		/* CORB/RIRB buffer, 8 byte per each entry */
2118c2ecf20Sopenharmony_ci	dma_addr_t addr;	/* physical address of CORB/RIRB buffer */
2128c2ecf20Sopenharmony_ci	unsigned short rp, wp;	/* read/write pointers */
2138c2ecf20Sopenharmony_ci	int cmds;		/* number of pending requests */
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* Pin widget setup */
2178c2ecf20Sopenharmony_cistruct lola_pin {
2188c2ecf20Sopenharmony_ci	unsigned int nid;
2198c2ecf20Sopenharmony_ci	bool is_analog;
2208c2ecf20Sopenharmony_ci	unsigned int amp_mute;
2218c2ecf20Sopenharmony_ci	unsigned int amp_step_size;
2228c2ecf20Sopenharmony_ci	unsigned int amp_num_steps;
2238c2ecf20Sopenharmony_ci	unsigned int amp_offset;
2248c2ecf20Sopenharmony_ci	unsigned int max_level;
2258c2ecf20Sopenharmony_ci	unsigned int config_default_reg;
2268c2ecf20Sopenharmony_ci	unsigned int fixed_gain_list_len;
2278c2ecf20Sopenharmony_ci	unsigned int cur_gain_step;
2288c2ecf20Sopenharmony_ci};
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistruct lola_pin_array {
2318c2ecf20Sopenharmony_ci	unsigned int num_pins;
2328c2ecf20Sopenharmony_ci	unsigned int num_analog_pins;
2338c2ecf20Sopenharmony_ci	struct lola_pin pins[MAX_PINS];
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci/* Clock widget setup */
2378c2ecf20Sopenharmony_cistruct lola_sample_clock {
2388c2ecf20Sopenharmony_ci	unsigned int type;
2398c2ecf20Sopenharmony_ci	unsigned int format;
2408c2ecf20Sopenharmony_ci	unsigned int freq;
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistruct lola_clock_widget {
2448c2ecf20Sopenharmony_ci	unsigned int nid;
2458c2ecf20Sopenharmony_ci	unsigned int items;
2468c2ecf20Sopenharmony_ci	unsigned int cur_index;
2478c2ecf20Sopenharmony_ci	unsigned int cur_freq;
2488c2ecf20Sopenharmony_ci	bool cur_valid;
2498c2ecf20Sopenharmony_ci	struct lola_sample_clock sample_clock[MAX_SAMPLE_CLOCK_COUNT];
2508c2ecf20Sopenharmony_ci	unsigned int idx_lookup[MAX_SAMPLE_CLOCK_COUNT];
2518c2ecf20Sopenharmony_ci};
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci#define LOLA_MIXER_DIM      32
2548c2ecf20Sopenharmony_cistruct lola_mixer_array {
2558c2ecf20Sopenharmony_ci	u32 src_gain_enable;
2568c2ecf20Sopenharmony_ci	u32 dest_mix_gain_enable[LOLA_MIXER_DIM];
2578c2ecf20Sopenharmony_ci	u16 src_gain[LOLA_MIXER_DIM];
2588c2ecf20Sopenharmony_ci	u16 dest_mix_gain[LOLA_MIXER_DIM][LOLA_MIXER_DIM];
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci/* Mixer widget setup */
2628c2ecf20Sopenharmony_cistruct lola_mixer_widget {
2638c2ecf20Sopenharmony_ci	unsigned int nid;
2648c2ecf20Sopenharmony_ci	unsigned int caps;
2658c2ecf20Sopenharmony_ci	struct lola_mixer_array __iomem *array;
2668c2ecf20Sopenharmony_ci	struct lola_mixer_array *array_saved;
2678c2ecf20Sopenharmony_ci	unsigned int src_stream_outs;
2688c2ecf20Sopenharmony_ci	unsigned int src_phys_ins;
2698c2ecf20Sopenharmony_ci	unsigned int dest_stream_ins;
2708c2ecf20Sopenharmony_ci	unsigned int dest_phys_outs;
2718c2ecf20Sopenharmony_ci	unsigned int src_stream_out_ofs;
2728c2ecf20Sopenharmony_ci	unsigned int dest_phys_out_ofs;
2738c2ecf20Sopenharmony_ci	unsigned int src_mask;
2748c2ecf20Sopenharmony_ci	unsigned int dest_mask;
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci/* Audio stream */
2788c2ecf20Sopenharmony_cistruct lola_stream {
2798c2ecf20Sopenharmony_ci	unsigned int nid;	/* audio widget NID */
2808c2ecf20Sopenharmony_ci	unsigned int index;	/* array index */
2818c2ecf20Sopenharmony_ci	unsigned int dsd;	/* DSD index */
2828c2ecf20Sopenharmony_ci	bool can_float;
2838c2ecf20Sopenharmony_ci	struct snd_pcm_substream *substream; /* assigned PCM substream */
2848c2ecf20Sopenharmony_ci	struct lola_stream *master;	/* master stream (for multi-channel) */
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	/* buffer setup */
2878c2ecf20Sopenharmony_ci	unsigned int bufsize;
2888c2ecf20Sopenharmony_ci	unsigned int period_bytes;
2898c2ecf20Sopenharmony_ci	unsigned int frags;
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	/* format + channel setup */
2928c2ecf20Sopenharmony_ci	unsigned int format_verb;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	/* flags */
2958c2ecf20Sopenharmony_ci	unsigned int opened:1;
2968c2ecf20Sopenharmony_ci	unsigned int prepared:1;
2978c2ecf20Sopenharmony_ci	unsigned int paused:1;
2988c2ecf20Sopenharmony_ci	unsigned int running:1;
2998c2ecf20Sopenharmony_ci};
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci#define PLAY	SNDRV_PCM_STREAM_PLAYBACK
3028c2ecf20Sopenharmony_ci#define CAPT	SNDRV_PCM_STREAM_CAPTURE
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistruct lola_pcm {
3058c2ecf20Sopenharmony_ci	unsigned int num_streams;
3068c2ecf20Sopenharmony_ci	struct snd_dma_buffer bdl; /* BDL buffer */
3078c2ecf20Sopenharmony_ci	struct lola_stream streams[MAX_STREAM_COUNT];
3088c2ecf20Sopenharmony_ci};
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci/* card instance */
3118c2ecf20Sopenharmony_cistruct lola {
3128c2ecf20Sopenharmony_ci	struct snd_card *card;
3138c2ecf20Sopenharmony_ci	struct pci_dev *pci;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	/* pci resources */
3168c2ecf20Sopenharmony_ci	struct lola_bar bar[2];
3178c2ecf20Sopenharmony_ci	int irq;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	/* locks */
3208c2ecf20Sopenharmony_ci	spinlock_t reg_lock;
3218c2ecf20Sopenharmony_ci	struct mutex open_mutex;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/* CORB/RIRB */
3248c2ecf20Sopenharmony_ci	struct lola_rb corb;
3258c2ecf20Sopenharmony_ci	struct lola_rb rirb;
3268c2ecf20Sopenharmony_ci	unsigned int res, res_ex;	/* last read values */
3278c2ecf20Sopenharmony_ci	/* last command (for debugging) */
3288c2ecf20Sopenharmony_ci	unsigned int last_cmd_nid, last_verb, last_data, last_extdata;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	/* CORB/RIRB buffers */
3318c2ecf20Sopenharmony_ci	struct snd_dma_buffer rb;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	/* unsolicited events */
3348c2ecf20Sopenharmony_ci	unsigned int last_unsol_res;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	/* streams */
3378c2ecf20Sopenharmony_ci	struct lola_pcm pcm[2];
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* input src */
3408c2ecf20Sopenharmony_ci	unsigned int input_src_caps_mask;
3418c2ecf20Sopenharmony_ci	unsigned int input_src_mask;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	/* pins */
3448c2ecf20Sopenharmony_ci	struct lola_pin_array pin[2];
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	/* clock */
3478c2ecf20Sopenharmony_ci	struct lola_clock_widget clock;
3488c2ecf20Sopenharmony_ci	int ref_count_rate;
3498c2ecf20Sopenharmony_ci	unsigned int sample_rate;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	/* mixer */
3528c2ecf20Sopenharmony_ci	struct lola_mixer_widget mixer;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	/* hw info */
3558c2ecf20Sopenharmony_ci	unsigned int version;
3568c2ecf20Sopenharmony_ci	unsigned int lola_caps;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	/* parameters */
3598c2ecf20Sopenharmony_ci	unsigned int granularity;
3608c2ecf20Sopenharmony_ci	unsigned int sample_rate_min;
3618c2ecf20Sopenharmony_ci	unsigned int sample_rate_max;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	/* flags */
3648c2ecf20Sopenharmony_ci	unsigned int initialized:1;
3658c2ecf20Sopenharmony_ci	unsigned int cold_reset:1;
3668c2ecf20Sopenharmony_ci	unsigned int polling_mode:1;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	/* for debugging */
3698c2ecf20Sopenharmony_ci	unsigned int debug_res;
3708c2ecf20Sopenharmony_ci	unsigned int debug_res_ex;
3718c2ecf20Sopenharmony_ci};
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci#define BAR0	0
3748c2ecf20Sopenharmony_ci#define BAR1	1
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci/* Helper macros */
3778c2ecf20Sopenharmony_ci#define lola_readl(chip, idx, name) \
3788c2ecf20Sopenharmony_ci	readl((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3798c2ecf20Sopenharmony_ci#define lola_readw(chip, idx, name) \
3808c2ecf20Sopenharmony_ci	readw((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3818c2ecf20Sopenharmony_ci#define lola_readb(chip, idx, name) \
3828c2ecf20Sopenharmony_ci	readb((chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3838c2ecf20Sopenharmony_ci#define lola_writel(chip, idx, name, val) \
3848c2ecf20Sopenharmony_ci	writel((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3858c2ecf20Sopenharmony_ci#define lola_writew(chip, idx, name, val) \
3868c2ecf20Sopenharmony_ci	writew((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3878c2ecf20Sopenharmony_ci#define lola_writeb(chip, idx, name, val) \
3888c2ecf20Sopenharmony_ci	writeb((val), (chip)->bar[idx].remap_addr + LOLA_##idx##_##name)
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define lola_dsd_read(chip, dsd, name) \
3918c2ecf20Sopenharmony_ci	readl((chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
3928c2ecf20Sopenharmony_ci	      (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
3938c2ecf20Sopenharmony_ci#define lola_dsd_write(chip, dsd, name, val) \
3948c2ecf20Sopenharmony_ci	writel((val), (chip)->bar[BAR1].remap_addr + LOLA_BAR1_DSD0_OFFSET + \
3958c2ecf20Sopenharmony_ci	       (LOLA_BAR1_DSD_SIZE * (dsd)) + LOLA_BAR1_DSDn##name)
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci/* GET verbs HDAudio */
3988c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_STREAM_FORMAT		0xa00
3998c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_AMP_GAIN_MUTE		0xb00
4008c2ecf20Sopenharmony_ci#define LOLA_VERB_PARAMETERS			0xf00
4018c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_POWER_STATE		0xf05
4028c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_CONV			0xf06
4038c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_UNSOLICITED_RESPONSE	0xf08
4048c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_DIGI_CONVERT_1		0xf0d
4058c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_CONFIG_DEFAULT		0xf1c
4068c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_SUBSYSTEM_ID		0xf20
4078c2ecf20Sopenharmony_ci/* GET verbs Digigram */
4088c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_FIXED_GAIN		0xfc0
4098c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_GAIN_SELECT		0xfc1
4108c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_MAX_LEVEL			0xfc2
4118c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_CLOCK_LIST		0xfc3
4128c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_CLOCK_SELECT		0xfc4
4138c2ecf20Sopenharmony_ci#define LOLA_VERB_GET_CLOCK_STATUS		0xfc5
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci/* SET verbs HDAudio */
4168c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_STREAM_FORMAT		0x200
4178c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_AMP_GAIN_MUTE		0x300
4188c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_POWER_STATE		0x705
4198c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_CHANNEL_STREAMID		0x706
4208c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_UNSOLICITED_ENABLE	0x708
4218c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_DIGI_CONVERT_1		0x70d
4228c2ecf20Sopenharmony_ci/* SET verbs Digigram */
4238c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_GAIN_SELECT		0xf81
4248c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_CLOCK_SELECT		0xf84
4258c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_GRANULARITY_STEPS		0xf86
4268c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_SOURCE_GAIN		0xf87
4278c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_MIX_GAIN			0xf88
4288c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_DESTINATION_GAIN		0xf89
4298c2ecf20Sopenharmony_ci#define LOLA_VERB_SET_SRC			0xf8a
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/* Parameter IDs used with LOLA_VERB_PARAMETERS */
4328c2ecf20Sopenharmony_ci#define LOLA_PAR_VENDOR_ID			0x00
4338c2ecf20Sopenharmony_ci#define LOLA_PAR_FUNCTION_TYPE			0x05
4348c2ecf20Sopenharmony_ci#define LOLA_PAR_AUDIO_WIDGET_CAP		0x09
4358c2ecf20Sopenharmony_ci#define LOLA_PAR_PCM				0x0a
4368c2ecf20Sopenharmony_ci#define LOLA_PAR_STREAM_FORMATS			0x0b
4378c2ecf20Sopenharmony_ci#define LOLA_PAR_PIN_CAP			0x0c
4388c2ecf20Sopenharmony_ci#define LOLA_PAR_AMP_IN_CAP			0x0d
4398c2ecf20Sopenharmony_ci#define LOLA_PAR_CONNLIST_LEN			0x0e
4408c2ecf20Sopenharmony_ci#define LOLA_PAR_POWER_STATE			0x0f
4418c2ecf20Sopenharmony_ci#define LOLA_PAR_GPIO_CAP			0x11
4428c2ecf20Sopenharmony_ci#define LOLA_PAR_AMP_OUT_CAP			0x12
4438c2ecf20Sopenharmony_ci#define LOLA_PAR_SPECIFIC_CAPS			0x80
4448c2ecf20Sopenharmony_ci#define LOLA_PAR_FIXED_GAIN_LIST		0x81
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci/* extract results of LOLA_PAR_SPECIFIC_CAPS */
4478c2ecf20Sopenharmony_ci#define LOLA_AFG_MIXER_WIDGET_PRESENT(res)	((res & (1 << 21)) != 0)
4488c2ecf20Sopenharmony_ci#define LOLA_AFG_CLOCK_WIDGET_PRESENT(res)	((res & (1 << 20)) != 0)
4498c2ecf20Sopenharmony_ci#define LOLA_AFG_INPUT_PIN_COUNT(res)		((res >> 10) & 0x2ff)
4508c2ecf20Sopenharmony_ci#define LOLA_AFG_OUTPUT_PIN_COUNT(res)		((res) & 0x2ff)
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci/* extract results of LOLA_PAR_AMP_IN_CAP / LOLA_PAR_AMP_OUT_CAP */
4538c2ecf20Sopenharmony_ci#define LOLA_AMP_MUTE_CAPABLE(res)		((res & (1 << 31)) != 0)
4548c2ecf20Sopenharmony_ci#define LOLA_AMP_STEP_SIZE(res)			((res >> 24) & 0x7f)
4558c2ecf20Sopenharmony_ci#define LOLA_AMP_NUM_STEPS(res)			((res >> 12) & 0x3ff)
4568c2ecf20Sopenharmony_ci#define LOLA_AMP_OFFSET(res)			((res) & 0x3ff)
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci#define LOLA_GRANULARITY_MIN		8
4598c2ecf20Sopenharmony_ci#define LOLA_GRANULARITY_MAX		32
4608c2ecf20Sopenharmony_ci#define LOLA_GRANULARITY_STEP		8
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci/* parameters used with unsolicited command/response */
4638c2ecf20Sopenharmony_ci#define LOLA_UNSOLICITED_TAG_MASK	0x3f
4648c2ecf20Sopenharmony_ci#define LOLA_UNSOLICITED_TAG		0x1a
4658c2ecf20Sopenharmony_ci#define LOLA_UNSOLICITED_ENABLE		0x80
4668c2ecf20Sopenharmony_ci#define LOLA_UNSOL_RESP_TAG_OFFSET	26
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci/* count values in the Vendor Specific Mixer Widget's Audio Widget Capabilities */
4698c2ecf20Sopenharmony_ci#define LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(res)   ((res >> 2) & 0x1f)
4708c2ecf20Sopenharmony_ci#define LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(res)  ((res >> 7) & 0x1f)
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ciint lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb,
4738c2ecf20Sopenharmony_ci		     unsigned int data, unsigned int extdata);
4748c2ecf20Sopenharmony_ciint lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb,
4758c2ecf20Sopenharmony_ci		    unsigned int data, unsigned int extdata,
4768c2ecf20Sopenharmony_ci		    unsigned int *val, unsigned int *extval);
4778c2ecf20Sopenharmony_ciint lola_codec_flush(struct lola *chip);
4788c2ecf20Sopenharmony_ci#define lola_read_param(chip, nid, param, val) \
4798c2ecf20Sopenharmony_ci	lola_codec_read(chip, nid, LOLA_VERB_PARAMETERS, param, 0, val, NULL)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/* PCM */
4828c2ecf20Sopenharmony_ciint lola_create_pcm(struct lola *chip);
4838c2ecf20Sopenharmony_civoid lola_free_pcm(struct lola *chip);
4848c2ecf20Sopenharmony_ciint lola_init_pcm(struct lola *chip, int dir, int *nidp);
4858c2ecf20Sopenharmony_civoid lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits);
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci/* clock */
4888c2ecf20Sopenharmony_ciint lola_init_clock_widget(struct lola *chip, int nid);
4898c2ecf20Sopenharmony_ciint lola_set_granularity(struct lola *chip, unsigned int val, bool force);
4908c2ecf20Sopenharmony_ciint lola_enable_clock_events(struct lola *chip);
4918c2ecf20Sopenharmony_ciint lola_set_clock_index(struct lola *chip, unsigned int idx);
4928c2ecf20Sopenharmony_ciint lola_set_clock(struct lola *chip, int idx);
4938c2ecf20Sopenharmony_ciint lola_set_sample_rate(struct lola *chip, int rate);
4948c2ecf20Sopenharmony_cibool lola_update_ext_clock_freq(struct lola *chip, unsigned int val);
4958c2ecf20Sopenharmony_ciunsigned int lola_sample_rate_convert(unsigned int coded);
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci/* mixer */
4988c2ecf20Sopenharmony_ciint lola_init_pins(struct lola *chip, int dir, int *nidp);
4998c2ecf20Sopenharmony_ciint lola_init_mixer_widget(struct lola *chip, int nid);
5008c2ecf20Sopenharmony_civoid lola_free_mixer(struct lola *chip);
5018c2ecf20Sopenharmony_ciint lola_create_mixer(struct lola *chip);
5028c2ecf20Sopenharmony_ciint lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute);
5038c2ecf20Sopenharmony_civoid lola_save_mixer(struct lola *chip);
5048c2ecf20Sopenharmony_civoid lola_restore_mixer(struct lola *chip);
5058c2ecf20Sopenharmony_ciint lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update);
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_ci/* proc */
5088c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG
5098c2ecf20Sopenharmony_civoid lola_proc_debug_new(struct lola *chip);
5108c2ecf20Sopenharmony_ci#else
5118c2ecf20Sopenharmony_ci#define lola_proc_debug_new(chip)
5128c2ecf20Sopenharmony_ci#endif
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci#endif /* _LOLA_H */
515