18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_ICE1712_H
38c2ecf20Sopenharmony_ci#define __SOUND_ICE1712_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *   ALSA driver for ICEnsemble ICE1712 (Envy24)
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *	Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/io.h>
128c2ecf20Sopenharmony_ci#include <sound/control.h>
138c2ecf20Sopenharmony_ci#include <sound/ac97_codec.h>
148c2ecf20Sopenharmony_ci#include <sound/rawmidi.h>
158c2ecf20Sopenharmony_ci#include <sound/i2c.h>
168c2ecf20Sopenharmony_ci#include <sound/ak4xxx-adda.h>
178c2ecf20Sopenharmony_ci#include <sound/ak4114.h>
188c2ecf20Sopenharmony_ci#include <sound/pt2258.h>
198c2ecf20Sopenharmony_ci#include <sound/pcm.h>
208c2ecf20Sopenharmony_ci#include <sound/mpu401.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci *  Direct registers
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define ICEREG(ice, x) ((ice)->port + ICE1712_REG_##x)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define ICE1712_REG_CONTROL		0x00	/* byte */
308c2ecf20Sopenharmony_ci#define   ICE1712_RESET			0x80	/* soft reset whole chip */
318c2ecf20Sopenharmony_ci#define   ICE1712_SERR_ASSERT_DS_DMA	0x40    /* disabled SERR# assertion for the DS DMA Ch-C irq otherwise enabled */
328c2ecf20Sopenharmony_ci#define   ICE1712_DOS_VOL		0x10    /* DOS WT/FM volume control */
338c2ecf20Sopenharmony_ci#define   ICE1712_SERR_LEVEL		0x08	/* SERR# level otherwise edge */
348c2ecf20Sopenharmony_ci#define   ICE1712_SERR_ASSERT_SB	0x02	/* disabled SERR# assertion for SB irq otherwise enabled */
358c2ecf20Sopenharmony_ci#define   ICE1712_NATIVE		0x01	/* native mode otherwise SB */
368c2ecf20Sopenharmony_ci#define ICE1712_REG_IRQMASK		0x01	/* byte */
378c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_MPU1		0x80	/* MIDI irq mask */
388c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_TIMER		0x40	/* Timer mask */
398c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_MPU2		0x20	/* Secondary MIDI irq mask */
408c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_PROPCM		0x10	/* professional multi-track */
418c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_FM		0x08	/* FM/MIDI - legacy */
428c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_PBKDS		0x04	/* playback DS channels */
438c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_CONCAP		0x02	/* consumer capture */
448c2ecf20Sopenharmony_ci#define   ICE1712_IRQ_CONPBK		0x01	/* consumer playback */
458c2ecf20Sopenharmony_ci#define ICE1712_REG_IRQSTAT		0x02	/* byte */
468c2ecf20Sopenharmony_ci/* look to ICE1712_IRQ_* */
478c2ecf20Sopenharmony_ci#define ICE1712_REG_INDEX		0x03	/* byte - indirect CCIxx regs */
488c2ecf20Sopenharmony_ci#define ICE1712_REG_DATA		0x04	/* byte - indirect CCIxx regs */
498c2ecf20Sopenharmony_ci#define ICE1712_REG_NMI_STAT1		0x05	/* byte */
508c2ecf20Sopenharmony_ci#define ICE1712_REG_NMI_DATA		0x06	/* byte */
518c2ecf20Sopenharmony_ci#define ICE1712_REG_NMI_INDEX		0x07	/* byte */
528c2ecf20Sopenharmony_ci#define ICE1712_REG_AC97_INDEX		0x08	/* byte */
538c2ecf20Sopenharmony_ci#define ICE1712_REG_AC97_CMD		0x09	/* byte */
548c2ecf20Sopenharmony_ci#define   ICE1712_AC97_COLD		0x80	/* cold reset */
558c2ecf20Sopenharmony_ci#define   ICE1712_AC97_WARM		0x40	/* warm reset */
568c2ecf20Sopenharmony_ci#define   ICE1712_AC97_WRITE		0x20	/* W: write, R: write in progress */
578c2ecf20Sopenharmony_ci#define   ICE1712_AC97_READ		0x10	/* W: read, R: read in progress */
588c2ecf20Sopenharmony_ci#define   ICE1712_AC97_READY		0x08	/* codec ready status bit */
598c2ecf20Sopenharmony_ci#define   ICE1712_AC97_PBK_VSR		0x02	/* playback VSR */
608c2ecf20Sopenharmony_ci#define   ICE1712_AC97_CAP_VSR		0x01	/* capture VSR */
618c2ecf20Sopenharmony_ci#define ICE1712_REG_AC97_DATA		0x0a	/* word (little endian) */
628c2ecf20Sopenharmony_ci#define ICE1712_REG_MPU1_CTRL		0x0c	/* byte */
638c2ecf20Sopenharmony_ci#define ICE1712_REG_MPU1_DATA		0x0d	/* byte */
648c2ecf20Sopenharmony_ci#define ICE1712_REG_I2C_DEV_ADDR	0x10	/* byte */
658c2ecf20Sopenharmony_ci#define   ICE1712_I2C_WRITE		0x01	/* write direction */
668c2ecf20Sopenharmony_ci#define ICE1712_REG_I2C_BYTE_ADDR	0x11	/* byte */
678c2ecf20Sopenharmony_ci#define ICE1712_REG_I2C_DATA		0x12	/* byte */
688c2ecf20Sopenharmony_ci#define ICE1712_REG_I2C_CTRL		0x13	/* byte */
698c2ecf20Sopenharmony_ci#define   ICE1712_I2C_EEPROM		0x80	/* EEPROM exists */
708c2ecf20Sopenharmony_ci#define   ICE1712_I2C_BUSY		0x01	/* busy bit */
718c2ecf20Sopenharmony_ci#define ICE1712_REG_CONCAP_ADDR		0x14	/* dword - consumer capture */
728c2ecf20Sopenharmony_ci#define ICE1712_REG_CONCAP_COUNT	0x18	/* word - current/base count */
738c2ecf20Sopenharmony_ci#define ICE1712_REG_SERR_SHADOW		0x1b	/* byte */
748c2ecf20Sopenharmony_ci#define ICE1712_REG_MPU2_CTRL		0x1c	/* byte */
758c2ecf20Sopenharmony_ci#define ICE1712_REG_MPU2_DATA		0x1d	/* byte */
768c2ecf20Sopenharmony_ci#define ICE1712_REG_TIMER		0x1e	/* word */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ci *  Indirect registers
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_COUNT_LO	0x00
838c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_COUNT_HI	0x01
848c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_CTRL		0x02
858c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_LEFT		0x03	/* left volume */
868c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_RIGHT		0x04	/* right volume */
878c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_SOFT		0x05	/* soft volume */
888c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_RATE_LO	0x06
898c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_RATE_MID	0x07
908c2ecf20Sopenharmony_ci#define ICE1712_IREG_PBK_RATE_HI	0x08
918c2ecf20Sopenharmony_ci#define ICE1712_IREG_CAP_COUNT_LO	0x10
928c2ecf20Sopenharmony_ci#define ICE1712_IREG_CAP_COUNT_HI	0x11
938c2ecf20Sopenharmony_ci#define ICE1712_IREG_CAP_CTRL		0x12
948c2ecf20Sopenharmony_ci#define ICE1712_IREG_GPIO_DATA		0x20
958c2ecf20Sopenharmony_ci#define ICE1712_IREG_GPIO_WRITE_MASK	0x21
968c2ecf20Sopenharmony_ci#define ICE1712_IREG_GPIO_DIRECTION	0x22
978c2ecf20Sopenharmony_ci#define ICE1712_IREG_CONSUMER_POWERDOWN	0x30
988c2ecf20Sopenharmony_ci#define ICE1712_IREG_PRO_POWERDOWN	0x31
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci *  Consumer section direct DMA registers
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define ICEDS(ice, x) ((ice)->dmapath_port + ICE1712_DS_##x)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define ICE1712_DS_INTMASK		0x00	/* word - interrupt mask */
1078c2ecf20Sopenharmony_ci#define ICE1712_DS_INTSTAT		0x02	/* word - interrupt status */
1088c2ecf20Sopenharmony_ci#define ICE1712_DS_DATA			0x04	/* dword - channel data */
1098c2ecf20Sopenharmony_ci#define ICE1712_DS_INDEX		0x08	/* dword - channel index */
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/*
1128c2ecf20Sopenharmony_ci *  Consumer section channel registers
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define ICE1712_DSC_ADDR0		0x00	/* dword - base address 0 */
1168c2ecf20Sopenharmony_ci#define ICE1712_DSC_COUNT0		0x01	/* word - count 0 */
1178c2ecf20Sopenharmony_ci#define ICE1712_DSC_ADDR1		0x02	/* dword - base address 1 */
1188c2ecf20Sopenharmony_ci#define ICE1712_DSC_COUNT1		0x03	/* word - count 1 */
1198c2ecf20Sopenharmony_ci#define ICE1712_DSC_CONTROL		0x04	/* byte - control & status */
1208c2ecf20Sopenharmony_ci#define   ICE1712_BUFFER1		0x80	/* buffer1 is active */
1218c2ecf20Sopenharmony_ci#define   ICE1712_BUFFER1_AUTO		0x40	/* buffer1 auto init */
1228c2ecf20Sopenharmony_ci#define   ICE1712_BUFFER0_AUTO		0x20	/* buffer0 auto init */
1238c2ecf20Sopenharmony_ci#define   ICE1712_FLUSH			0x10	/* flush FIFO */
1248c2ecf20Sopenharmony_ci#define   ICE1712_STEREO		0x08	/* stereo */
1258c2ecf20Sopenharmony_ci#define   ICE1712_16BIT			0x04	/* 16-bit data */
1268c2ecf20Sopenharmony_ci#define   ICE1712_PAUSE			0x02	/* pause */
1278c2ecf20Sopenharmony_ci#define   ICE1712_START			0x01	/* start */
1288c2ecf20Sopenharmony_ci#define ICE1712_DSC_RATE		0x05	/* dword - rate */
1298c2ecf20Sopenharmony_ci#define ICE1712_DSC_VOLUME		0x06	/* word - volume control */
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/*
1328c2ecf20Sopenharmony_ci *  Professional multi-track direct control registers
1338c2ecf20Sopenharmony_ci */
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define ICEMT(ice, x) ((ice)->profi_port + ICE1712_MT_##x)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define ICE1712_MT_IRQ			0x00	/* byte - interrupt mask */
1388c2ecf20Sopenharmony_ci#define   ICE1712_MULTI_CAPTURE		0x80	/* capture IRQ */
1398c2ecf20Sopenharmony_ci#define   ICE1712_MULTI_PLAYBACK	0x40	/* playback IRQ */
1408c2ecf20Sopenharmony_ci#define   ICE1712_MULTI_CAPSTATUS	0x02	/* capture IRQ status */
1418c2ecf20Sopenharmony_ci#define   ICE1712_MULTI_PBKSTATUS	0x01	/* playback IRQ status */
1428c2ecf20Sopenharmony_ci#define ICE1712_MT_RATE			0x01	/* byte - sampling rate select */
1438c2ecf20Sopenharmony_ci#define   ICE1712_SPDIF_MASTER		0x10	/* S/PDIF input is master clock */
1448c2ecf20Sopenharmony_ci#define ICE1712_MT_I2S_FORMAT		0x02	/* byte - I2S data format */
1458c2ecf20Sopenharmony_ci#define ICE1712_MT_AC97_INDEX		0x04	/* byte - AC'97 index */
1468c2ecf20Sopenharmony_ci#define ICE1712_MT_AC97_CMD		0x05	/* byte - AC'97 command & status */
1478c2ecf20Sopenharmony_ci/* look to ICE1712_AC97_* */
1488c2ecf20Sopenharmony_ci#define ICE1712_MT_AC97_DATA		0x06	/* word - AC'97 data */
1498c2ecf20Sopenharmony_ci#define ICE1712_MT_PLAYBACK_ADDR	0x10	/* dword - playback address */
1508c2ecf20Sopenharmony_ci#define ICE1712_MT_PLAYBACK_SIZE	0x14	/* word - playback size */
1518c2ecf20Sopenharmony_ci#define ICE1712_MT_PLAYBACK_COUNT	0x16	/* word - playback count */
1528c2ecf20Sopenharmony_ci#define ICE1712_MT_PLAYBACK_CONTROL	0x18	/* byte - control */
1538c2ecf20Sopenharmony_ci#define   ICE1712_CAPTURE_START_SHADOW	0x04	/* capture start */
1548c2ecf20Sopenharmony_ci#define   ICE1712_PLAYBACK_PAUSE	0x02	/* playback pause */
1558c2ecf20Sopenharmony_ci#define   ICE1712_PLAYBACK_START	0x01	/* playback start */
1568c2ecf20Sopenharmony_ci#define ICE1712_MT_CAPTURE_ADDR		0x20	/* dword - capture address */
1578c2ecf20Sopenharmony_ci#define ICE1712_MT_CAPTURE_SIZE		0x24	/* word - capture size */
1588c2ecf20Sopenharmony_ci#define ICE1712_MT_CAPTURE_COUNT	0x26	/* word - capture count */
1598c2ecf20Sopenharmony_ci#define ICE1712_MT_CAPTURE_CONTROL	0x28	/* byte - control */
1608c2ecf20Sopenharmony_ci#define   ICE1712_CAPTURE_START		0x01	/* capture start */
1618c2ecf20Sopenharmony_ci#define ICE1712_MT_ROUTE_PSDOUT03	0x30	/* word */
1628c2ecf20Sopenharmony_ci#define ICE1712_MT_ROUTE_SPDOUT		0x32	/* word */
1638c2ecf20Sopenharmony_ci#define ICE1712_MT_ROUTE_CAPTURE	0x34	/* dword */
1648c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_VOLUME	0x38	/* word */
1658c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_INDEX	0x3a	/* byte */
1668c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_RATE		0x3b	/* byte */
1678c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_ROUTECTRL	0x3c	/* byte */
1688c2ecf20Sopenharmony_ci#define   ICE1712_ROUTE_AC97		0x01	/* route digital mixer output to AC'97 */
1698c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_PEAKINDEX	0x3e	/* byte */
1708c2ecf20Sopenharmony_ci#define ICE1712_MT_MONITOR_PEAKDATA	0x3f	/* byte */
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/*
1738c2ecf20Sopenharmony_ci *  Codec configuration bits
1748c2ecf20Sopenharmony_ci */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* PCI[60] System Configuration */
1778c2ecf20Sopenharmony_ci#define ICE1712_CFG_CLOCK	0xc0
1788c2ecf20Sopenharmony_ci#define   ICE1712_CFG_CLOCK512	0x00	/* 22.5692Mhz, 44.1kHz*512 */
1798c2ecf20Sopenharmony_ci#define   ICE1712_CFG_CLOCK384  0x40	/* 16.9344Mhz, 44.1kHz*384 */
1808c2ecf20Sopenharmony_ci#define   ICE1712_CFG_EXT	0x80	/* external clock */
1818c2ecf20Sopenharmony_ci#define ICE1712_CFG_2xMPU401	0x20	/* two MPU401 UARTs */
1828c2ecf20Sopenharmony_ci#define ICE1712_CFG_NO_CON_AC97 0x10	/* consumer AC'97 codec is not present */
1838c2ecf20Sopenharmony_ci#define ICE1712_CFG_ADC_MASK	0x0c	/* one, two, three, four stereo ADCs */
1848c2ecf20Sopenharmony_ci#define ICE1712_CFG_DAC_MASK	0x03	/* one, two, three, four stereo DACs */
1858c2ecf20Sopenharmony_ci/* PCI[61] AC-Link Configuration */
1868c2ecf20Sopenharmony_ci#define ICE1712_CFG_PRO_I2S	0x80	/* multitrack converter: I2S or AC'97 */
1878c2ecf20Sopenharmony_ci#define ICE1712_CFG_AC97_PACKED	0x01	/* split or packed mode - AC'97 */
1888c2ecf20Sopenharmony_ci/* PCI[62] I2S Features */
1898c2ecf20Sopenharmony_ci#define ICE1712_CFG_I2S_VOLUME	0x80	/* volume/mute capability */
1908c2ecf20Sopenharmony_ci#define ICE1712_CFG_I2S_96KHZ	0x40	/* supports 96kHz sampling */
1918c2ecf20Sopenharmony_ci#define ICE1712_CFG_I2S_RESMASK	0x30	/* resolution mask, 16,18,20,24-bit */
1928c2ecf20Sopenharmony_ci#define ICE1712_CFG_I2S_OTHER	0x0f	/* other I2S IDs */
1938c2ecf20Sopenharmony_ci/* PCI[63] S/PDIF Configuration */
1948c2ecf20Sopenharmony_ci#define ICE1712_CFG_I2S_CHIPID	0xfc	/* I2S chip ID */
1958c2ecf20Sopenharmony_ci#define ICE1712_CFG_SPDIF_IN	0x02	/* S/PDIF input is present */
1968c2ecf20Sopenharmony_ci#define ICE1712_CFG_SPDIF_OUT	0x01	/* S/PDIF output is present */
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci/*
1998c2ecf20Sopenharmony_ci * DMA mode values
2008c2ecf20Sopenharmony_ci * identical with DMA_XXX on i386 architecture.
2018c2ecf20Sopenharmony_ci */
2028c2ecf20Sopenharmony_ci#define ICE1712_DMA_MODE_WRITE		0x48
2038c2ecf20Sopenharmony_ci#define ICE1712_DMA_AUTOINIT		0x10
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/*
2078c2ecf20Sopenharmony_ci * I2C EEPROM Address
2088c2ecf20Sopenharmony_ci */
2098c2ecf20Sopenharmony_ci#define ICE_I2C_EEPROM_ADDR		0xA0
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistruct snd_ice1712;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistruct snd_ice1712_eeprom {
2148c2ecf20Sopenharmony_ci	unsigned int subvendor;	/* PCI[2c-2f] */
2158c2ecf20Sopenharmony_ci	unsigned char size;	/* size of EEPROM image in bytes */
2168c2ecf20Sopenharmony_ci	unsigned char version;	/* must be 1 (or 2 for vt1724) */
2178c2ecf20Sopenharmony_ci	unsigned char data[32];
2188c2ecf20Sopenharmony_ci	unsigned int gpiomask;
2198c2ecf20Sopenharmony_ci	unsigned int gpiostate;
2208c2ecf20Sopenharmony_ci	unsigned int gpiodir;
2218c2ecf20Sopenharmony_ci};
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cienum {
2248c2ecf20Sopenharmony_ci	ICE_EEP1_CODEC = 0,	/* 06 */
2258c2ecf20Sopenharmony_ci	ICE_EEP1_ACLINK,	/* 07 */
2268c2ecf20Sopenharmony_ci	ICE_EEP1_I2SID,		/* 08 */
2278c2ecf20Sopenharmony_ci	ICE_EEP1_SPDIF,		/* 09 */
2288c2ecf20Sopenharmony_ci	ICE_EEP1_GPIO_MASK,	/* 0a */
2298c2ecf20Sopenharmony_ci	ICE_EEP1_GPIO_STATE,	/* 0b */
2308c2ecf20Sopenharmony_ci	ICE_EEP1_GPIO_DIR,	/* 0c */
2318c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_MAIN_LO,	/* 0d */
2328c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_MAIN_HI,	/* 0e */
2338c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_PCM_LO,	/* 0f */
2348c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_PCM_HI,	/* 10 */
2358c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_REC_LO,	/* 11 */
2368c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_REC_HI,	/* 12 */
2378c2ecf20Sopenharmony_ci	ICE_EEP1_AC97_RECSRC,	/* 13 */
2388c2ecf20Sopenharmony_ci	ICE_EEP1_DAC_ID,	/* 14 */
2398c2ecf20Sopenharmony_ci	ICE_EEP1_DAC_ID1,
2408c2ecf20Sopenharmony_ci	ICE_EEP1_DAC_ID2,
2418c2ecf20Sopenharmony_ci	ICE_EEP1_DAC_ID3,
2428c2ecf20Sopenharmony_ci	ICE_EEP1_ADC_ID,	/* 18 */
2438c2ecf20Sopenharmony_ci	ICE_EEP1_ADC_ID1,
2448c2ecf20Sopenharmony_ci	ICE_EEP1_ADC_ID2,
2458c2ecf20Sopenharmony_ci	ICE_EEP1_ADC_ID3
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci#define ice_has_con_ac97(ice)	(!((ice)->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97))
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistruct snd_ak4xxx_private {
2528c2ecf20Sopenharmony_ci	unsigned int cif:1;		/* CIF mode */
2538c2ecf20Sopenharmony_ci	unsigned char caddr;		/* C0 and C1 bits */
2548c2ecf20Sopenharmony_ci	unsigned int data_mask;		/* DATA gpio bit */
2558c2ecf20Sopenharmony_ci	unsigned int clk_mask;		/* CLK gpio bit */
2568c2ecf20Sopenharmony_ci	unsigned int cs_mask;		/* bit mask for select/deselect address */
2578c2ecf20Sopenharmony_ci	unsigned int cs_addr;		/* bits to select address */
2588c2ecf20Sopenharmony_ci	unsigned int cs_none;		/* bits to deselect address */
2598c2ecf20Sopenharmony_ci	unsigned int add_flags;		/* additional bits at init */
2608c2ecf20Sopenharmony_ci	unsigned int mask_flags;	/* total mask bits */
2618c2ecf20Sopenharmony_ci	struct snd_akm4xxx_ops {
2628c2ecf20Sopenharmony_ci		void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
2638c2ecf20Sopenharmony_ci	} ops;
2648c2ecf20Sopenharmony_ci};
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistruct snd_ice1712_spdif {
2678c2ecf20Sopenharmony_ci	unsigned char cs8403_bits;
2688c2ecf20Sopenharmony_ci	unsigned char cs8403_stream_bits;
2698c2ecf20Sopenharmony_ci	struct snd_kcontrol *stream_ctl;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	struct snd_ice1712_spdif_ops {
2728c2ecf20Sopenharmony_ci		void (*open)(struct snd_ice1712 *, struct snd_pcm_substream *);
2738c2ecf20Sopenharmony_ci		void (*setup_rate)(struct snd_ice1712 *, int rate);
2748c2ecf20Sopenharmony_ci		void (*close)(struct snd_ice1712 *, struct snd_pcm_substream *);
2758c2ecf20Sopenharmony_ci		void (*default_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
2768c2ecf20Sopenharmony_ci		int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
2778c2ecf20Sopenharmony_ci		void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
2788c2ecf20Sopenharmony_ci		int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
2798c2ecf20Sopenharmony_ci	} ops;
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistruct snd_ice1712_card_info;
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_cistruct snd_ice1712 {
2858c2ecf20Sopenharmony_ci	unsigned long conp_dma_size;
2868c2ecf20Sopenharmony_ci	unsigned long conc_dma_size;
2878c2ecf20Sopenharmony_ci	unsigned long prop_dma_size;
2888c2ecf20Sopenharmony_ci	unsigned long proc_dma_size;
2898c2ecf20Sopenharmony_ci	int irq;
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	unsigned long port;
2928c2ecf20Sopenharmony_ci	unsigned long ddma_port;
2938c2ecf20Sopenharmony_ci	unsigned long dmapath_port;
2948c2ecf20Sopenharmony_ci	unsigned long profi_port;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	struct pci_dev *pci;
2978c2ecf20Sopenharmony_ci	struct snd_card *card;
2988c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
2998c2ecf20Sopenharmony_ci	struct snd_pcm *pcm_ds;
3008c2ecf20Sopenharmony_ci	struct snd_pcm *pcm_pro;
3018c2ecf20Sopenharmony_ci	struct snd_pcm_substream *playback_con_substream;
3028c2ecf20Sopenharmony_ci	struct snd_pcm_substream *playback_con_substream_ds[6];
3038c2ecf20Sopenharmony_ci	struct snd_pcm_substream *capture_con_substream;
3048c2ecf20Sopenharmony_ci	struct snd_pcm_substream *playback_pro_substream;
3058c2ecf20Sopenharmony_ci	struct snd_pcm_substream *capture_pro_substream;
3068c2ecf20Sopenharmony_ci	unsigned int playback_pro_size;
3078c2ecf20Sopenharmony_ci	unsigned int capture_pro_size;
3088c2ecf20Sopenharmony_ci	unsigned int playback_con_virt_addr[6];
3098c2ecf20Sopenharmony_ci	unsigned int playback_con_active_buf[6];
3108c2ecf20Sopenharmony_ci	unsigned int capture_con_virt_addr;
3118c2ecf20Sopenharmony_ci	unsigned int ac97_ext_id;
3128c2ecf20Sopenharmony_ci	struct snd_ac97 *ac97;
3138c2ecf20Sopenharmony_ci	struct snd_rawmidi *rmidi[2];
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	spinlock_t reg_lock;
3168c2ecf20Sopenharmony_ci	struct snd_info_entry *proc_entry;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	struct snd_ice1712_eeprom eeprom;
3198c2ecf20Sopenharmony_ci	const struct snd_ice1712_card_info *card_info;
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	unsigned int pro_volumes[20];
3228c2ecf20Sopenharmony_ci	unsigned int omni:1;		/* Delta Omni I/O */
3238c2ecf20Sopenharmony_ci	unsigned int dxr_enable:1;	/* Terratec DXR enable for DMX6FIRE */
3248c2ecf20Sopenharmony_ci	unsigned int vt1724:1;
3258c2ecf20Sopenharmony_ci	unsigned int vt1720:1;
3268c2ecf20Sopenharmony_ci	unsigned int has_spdif:1;	/* VT1720/4 - has SPDIF I/O */
3278c2ecf20Sopenharmony_ci	unsigned int force_pdma4:1;	/* VT1720/4 - PDMA4 as non-spdif */
3288c2ecf20Sopenharmony_ci	unsigned int force_rdma1:1;	/* VT1720/4 - RDMA1 as non-spdif */
3298c2ecf20Sopenharmony_ci	unsigned int midi_output:1;	/* VT1720/4: MIDI output triggered */
3308c2ecf20Sopenharmony_ci	unsigned int midi_input:1;	/* VT1720/4: MIDI input triggered */
3318c2ecf20Sopenharmony_ci	unsigned int own_routing:1;	/* VT1720/4: use own routing ctls */
3328c2ecf20Sopenharmony_ci	unsigned int num_total_dacs;	/* total DACs */
3338c2ecf20Sopenharmony_ci	unsigned int num_total_adcs;	/* total ADCs */
3348c2ecf20Sopenharmony_ci	unsigned int cur_rate;		/* current rate */
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	struct mutex open_mutex;
3378c2ecf20Sopenharmony_ci	struct snd_pcm_substream *pcm_reserved[4];
3388c2ecf20Sopenharmony_ci	const struct snd_pcm_hw_constraint_list *hw_rates; /* card-specific rate constraints */
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	unsigned int akm_codecs;
3418c2ecf20Sopenharmony_ci	struct snd_akm4xxx *akm;
3428c2ecf20Sopenharmony_ci	struct snd_ice1712_spdif spdif;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	struct mutex i2c_mutex;	/* I2C mutex for ICE1724 registers */
3458c2ecf20Sopenharmony_ci	struct snd_i2c_bus *i2c;		/* I2C bus */
3468c2ecf20Sopenharmony_ci	struct snd_i2c_device *cs8427;	/* CS8427 I2C device */
3478c2ecf20Sopenharmony_ci	unsigned int cs8427_timeout;	/* CS8427 reset timeout in HZ/100 */
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	struct ice1712_gpio {
3508c2ecf20Sopenharmony_ci		unsigned int direction;		/* current direction bits */
3518c2ecf20Sopenharmony_ci		unsigned int write_mask;	/* current mask bits */
3528c2ecf20Sopenharmony_ci		unsigned int saved[2];		/* for ewx_i2c */
3538c2ecf20Sopenharmony_ci		/* operators */
3548c2ecf20Sopenharmony_ci		void (*set_mask)(struct snd_ice1712 *ice, unsigned int data);
3558c2ecf20Sopenharmony_ci		unsigned int (*get_mask)(struct snd_ice1712 *ice);
3568c2ecf20Sopenharmony_ci		void (*set_dir)(struct snd_ice1712 *ice, unsigned int data);
3578c2ecf20Sopenharmony_ci		unsigned int (*get_dir)(struct snd_ice1712 *ice);
3588c2ecf20Sopenharmony_ci		void (*set_data)(struct snd_ice1712 *ice, unsigned int data);
3598c2ecf20Sopenharmony_ci		unsigned int (*get_data)(struct snd_ice1712 *ice);
3608c2ecf20Sopenharmony_ci		/* misc operators - move to another place? */
3618c2ecf20Sopenharmony_ci		void (*set_pro_rate)(struct snd_ice1712 *ice, unsigned int rate);
3628c2ecf20Sopenharmony_ci		void (*i2s_mclk_changed)(struct snd_ice1712 *ice);
3638c2ecf20Sopenharmony_ci	} gpio;
3648c2ecf20Sopenharmony_ci	struct mutex gpio_mutex;
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	/* other board-specific data */
3678c2ecf20Sopenharmony_ci	void *spec;
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci	/* VT172x specific */
3708c2ecf20Sopenharmony_ci	int pro_rate_default;
3718c2ecf20Sopenharmony_ci	int (*is_spdif_master)(struct snd_ice1712 *ice);
3728c2ecf20Sopenharmony_ci	unsigned int (*get_rate)(struct snd_ice1712 *ice);
3738c2ecf20Sopenharmony_ci	void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
3748c2ecf20Sopenharmony_ci	unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
3758c2ecf20Sopenharmony_ci	int (*set_spdif_clock)(struct snd_ice1712 *ice, int type);
3768c2ecf20Sopenharmony_ci	int (*get_spdif_master_type)(struct snd_ice1712 *ice);
3778c2ecf20Sopenharmony_ci	const char * const *ext_clock_names;
3788c2ecf20Sopenharmony_ci	int ext_clock_count;
3798c2ecf20Sopenharmony_ci	void (*pro_open)(struct snd_ice1712 *, struct snd_pcm_substream *);
3808c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
3818c2ecf20Sopenharmony_ci	int (*pm_suspend)(struct snd_ice1712 *);
3828c2ecf20Sopenharmony_ci	int (*pm_resume)(struct snd_ice1712 *);
3838c2ecf20Sopenharmony_ci	unsigned int pm_suspend_enabled:1;
3848c2ecf20Sopenharmony_ci	unsigned int pm_saved_is_spdif_master:1;
3858c2ecf20Sopenharmony_ci	unsigned int pm_saved_spdif_ctrl;
3868c2ecf20Sopenharmony_ci	unsigned char pm_saved_spdif_cfg;
3878c2ecf20Sopenharmony_ci	unsigned int pm_saved_route;
3888c2ecf20Sopenharmony_ci#endif
3898c2ecf20Sopenharmony_ci};
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/*
3938c2ecf20Sopenharmony_ci * gpio access functions
3948c2ecf20Sopenharmony_ci */
3958c2ecf20Sopenharmony_cistatic inline void snd_ice1712_gpio_set_dir(struct snd_ice1712 *ice, unsigned int bits)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	ice->gpio.set_dir(ice, bits);
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistatic inline unsigned int snd_ice1712_gpio_get_dir(struct snd_ice1712 *ice)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	return ice->gpio.get_dir(ice);
4038c2ecf20Sopenharmony_ci}
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_cistatic inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits)
4068c2ecf20Sopenharmony_ci{
4078c2ecf20Sopenharmony_ci	ice->gpio.set_mask(ice, bits);
4088c2ecf20Sopenharmony_ci}
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_cistatic inline void snd_ice1712_gpio_write(struct snd_ice1712 *ice, unsigned int val)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	ice->gpio.set_data(ice, val);
4138c2ecf20Sopenharmony_ci}
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_cistatic inline unsigned int snd_ice1712_gpio_read(struct snd_ice1712 *ice)
4168c2ecf20Sopenharmony_ci{
4178c2ecf20Sopenharmony_ci	return ice->gpio.get_data(ice);
4188c2ecf20Sopenharmony_ci}
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci/*
4218c2ecf20Sopenharmony_ci * save and restore gpio status
4228c2ecf20Sopenharmony_ci * The access to gpio will be protected by mutex, so don't forget to
4238c2ecf20Sopenharmony_ci * restore!
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_cistatic inline void snd_ice1712_save_gpio_status(struct snd_ice1712 *ice)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	mutex_lock(&ice->gpio_mutex);
4288c2ecf20Sopenharmony_ci	ice->gpio.saved[0] = ice->gpio.direction;
4298c2ecf20Sopenharmony_ci	ice->gpio.saved[1] = ice->gpio.write_mask;
4308c2ecf20Sopenharmony_ci}
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic inline void snd_ice1712_restore_gpio_status(struct snd_ice1712 *ice)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	ice->gpio.set_dir(ice, ice->gpio.saved[0]);
4358c2ecf20Sopenharmony_ci	ice->gpio.set_mask(ice, ice->gpio.saved[1]);
4368c2ecf20Sopenharmony_ci	ice->gpio.direction = ice->gpio.saved[0];
4378c2ecf20Sopenharmony_ci	ice->gpio.write_mask = ice->gpio.saved[1];
4388c2ecf20Sopenharmony_ci	mutex_unlock(&ice->gpio_mutex);
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci/* for bit controls */
4428c2ecf20Sopenharmony_ci#define ICE1712_GPIO(xiface, xname, xindex, mask, invert, xaccess) \
4438c2ecf20Sopenharmony_ci{ .iface = xiface, .name = xname, .access = xaccess, .info = snd_ctl_boolean_mono_info, \
4448c2ecf20Sopenharmony_ci  .get = snd_ice1712_gpio_get, .put = snd_ice1712_gpio_put, \
4458c2ecf20Sopenharmony_ci  .private_value = mask | (invert << 24) }
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ciint snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
4488c2ecf20Sopenharmony_ciint snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci/*
4518c2ecf20Sopenharmony_ci * set gpio direction, write mask and data
4528c2ecf20Sopenharmony_ci */
4538c2ecf20Sopenharmony_cistatic inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice,
4548c2ecf20Sopenharmony_ci					       unsigned int mask, unsigned int bits)
4558c2ecf20Sopenharmony_ci{
4568c2ecf20Sopenharmony_ci	unsigned val;
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	ice->gpio.direction |= mask;
4598c2ecf20Sopenharmony_ci	snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
4608c2ecf20Sopenharmony_ci	val = snd_ice1712_gpio_read(ice);
4618c2ecf20Sopenharmony_ci	val &= ~mask;
4628c2ecf20Sopenharmony_ci	val |= mask & bits;
4638c2ecf20Sopenharmony_ci	snd_ice1712_gpio_write(ice, val);
4648c2ecf20Sopenharmony_ci}
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cistatic inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
4678c2ecf20Sopenharmony_ci					      unsigned int mask)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	ice->gpio.direction &= ~mask;
4708c2ecf20Sopenharmony_ci	snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
4718c2ecf20Sopenharmony_ci	return  snd_ice1712_gpio_read(ice) & mask;
4728c2ecf20Sopenharmony_ci}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci/* route access functions */
4758c2ecf20Sopenharmony_ciint snd_ice1724_get_route_val(struct snd_ice1712 *ice, int shift);
4768c2ecf20Sopenharmony_ciint snd_ice1724_put_route_val(struct snd_ice1712 *ice, unsigned int val,
4778c2ecf20Sopenharmony_ci								int shift);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ciint snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice);
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ciint snd_ice1712_akm4xxx_init(struct snd_akm4xxx *ak,
4828c2ecf20Sopenharmony_ci			     const struct snd_akm4xxx *template,
4838c2ecf20Sopenharmony_ci			     const struct snd_ak4xxx_private *priv,
4848c2ecf20Sopenharmony_ci			     struct snd_ice1712 *ice);
4858c2ecf20Sopenharmony_civoid snd_ice1712_akm4xxx_free(struct snd_ice1712 *ice);
4868c2ecf20Sopenharmony_ciint snd_ice1712_akm4xxx_build_controls(struct snd_ice1712 *ice);
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ciint snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr);
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_cistatic inline void snd_ice1712_write(struct snd_ice1712 *ice, u8 addr, u8 data)
4918c2ecf20Sopenharmony_ci{
4928c2ecf20Sopenharmony_ci	outb(addr, ICEREG(ice, INDEX));
4938c2ecf20Sopenharmony_ci	outb(data, ICEREG(ice, DATA));
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_cistatic inline u8 snd_ice1712_read(struct snd_ice1712 *ice, u8 addr)
4978c2ecf20Sopenharmony_ci{
4988c2ecf20Sopenharmony_ci	outb(addr, ICEREG(ice, INDEX));
4998c2ecf20Sopenharmony_ci	return inb(ICEREG(ice, DATA));
5008c2ecf20Sopenharmony_ci}
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci/*
5048c2ecf20Sopenharmony_ci * entry pointer
5058c2ecf20Sopenharmony_ci */
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_cistruct snd_ice1712_card_info {
5088c2ecf20Sopenharmony_ci	unsigned int subvendor;
5098c2ecf20Sopenharmony_ci	const char *name;
5108c2ecf20Sopenharmony_ci	const char *model;
5118c2ecf20Sopenharmony_ci	const char *driver;
5128c2ecf20Sopenharmony_ci	int (*chip_init)(struct snd_ice1712 *);
5138c2ecf20Sopenharmony_ci	void (*chip_exit)(struct snd_ice1712 *);
5148c2ecf20Sopenharmony_ci	int (*build_controls)(struct snd_ice1712 *);
5158c2ecf20Sopenharmony_ci	unsigned int no_mpu401:1;
5168c2ecf20Sopenharmony_ci	unsigned int mpu401_1_info_flags;
5178c2ecf20Sopenharmony_ci	unsigned int mpu401_2_info_flags;
5188c2ecf20Sopenharmony_ci	const char *mpu401_1_name;
5198c2ecf20Sopenharmony_ci	const char *mpu401_2_name;
5208c2ecf20Sopenharmony_ci	const unsigned int eeprom_size;
5218c2ecf20Sopenharmony_ci	const unsigned char *eeprom_data;
5228c2ecf20Sopenharmony_ci};
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci#endif /* __SOUND_ICE1712_H */
526