ice1712.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_ICE1712_H
  3. #define __SOUND_ICE1712_H
  4. /*
  5. * ALSA driver for ICEnsemble ICE1712 (Envy24)
  6. *
  7. * Copyright (c) 2000 Jaroslav Kysela <[email protected]>
  8. */
  9. #include <linux/io.h>
  10. #include <sound/control.h>
  11. #include <sound/ac97_codec.h>
  12. #include <sound/rawmidi.h>
  13. #include <sound/i2c.h>
  14. #include <sound/ak4xxx-adda.h>
  15. #include <sound/ak4114.h>
  16. #include <sound/pt2258.h>
  17. #include <sound/pcm.h>
  18. #include <sound/mpu401.h>
  19. /*
  20. * Direct registers
  21. */
  22. #define ICEREG(ice, x) ((ice)->port + ICE1712_REG_##x)
  23. #define ICE1712_REG_CONTROL 0x00 /* byte */
  24. #define ICE1712_RESET 0x80 /* soft reset whole chip */
  25. #define ICE1712_SERR_ASSERT_DS_DMA 0x40 /* disabled SERR# assertion for the DS DMA Ch-C irq otherwise enabled */
  26. #define ICE1712_DOS_VOL 0x10 /* DOS WT/FM volume control */
  27. #define ICE1712_SERR_LEVEL 0x08 /* SERR# level otherwise edge */
  28. #define ICE1712_SERR_ASSERT_SB 0x02 /* disabled SERR# assertion for SB irq otherwise enabled */
  29. #define ICE1712_NATIVE 0x01 /* native mode otherwise SB */
  30. #define ICE1712_REG_IRQMASK 0x01 /* byte */
  31. #define ICE1712_IRQ_MPU1 0x80 /* MIDI irq mask */
  32. #define ICE1712_IRQ_TIMER 0x40 /* Timer mask */
  33. #define ICE1712_IRQ_MPU2 0x20 /* Secondary MIDI irq mask */
  34. #define ICE1712_IRQ_PROPCM 0x10 /* professional multi-track */
  35. #define ICE1712_IRQ_FM 0x08 /* FM/MIDI - legacy */
  36. #define ICE1712_IRQ_PBKDS 0x04 /* playback DS channels */
  37. #define ICE1712_IRQ_CONCAP 0x02 /* consumer capture */
  38. #define ICE1712_IRQ_CONPBK 0x01 /* consumer playback */
  39. #define ICE1712_REG_IRQSTAT 0x02 /* byte */
  40. /* look to ICE1712_IRQ_* */
  41. #define ICE1712_REG_INDEX 0x03 /* byte - indirect CCIxx regs */
  42. #define ICE1712_REG_DATA 0x04 /* byte - indirect CCIxx regs */
  43. #define ICE1712_REG_NMI_STAT1 0x05 /* byte */
  44. #define ICE1712_REG_NMI_DATA 0x06 /* byte */
  45. #define ICE1712_REG_NMI_INDEX 0x07 /* byte */
  46. #define ICE1712_REG_AC97_INDEX 0x08 /* byte */
  47. #define ICE1712_REG_AC97_CMD 0x09 /* byte */
  48. #define ICE1712_AC97_COLD 0x80 /* cold reset */
  49. #define ICE1712_AC97_WARM 0x40 /* warm reset */
  50. #define ICE1712_AC97_WRITE 0x20 /* W: write, R: write in progress */
  51. #define ICE1712_AC97_READ 0x10 /* W: read, R: read in progress */
  52. #define ICE1712_AC97_READY 0x08 /* codec ready status bit */
  53. #define ICE1712_AC97_PBK_VSR 0x02 /* playback VSR */
  54. #define ICE1712_AC97_CAP_VSR 0x01 /* capture VSR */
  55. #define ICE1712_REG_AC97_DATA 0x0a /* word (little endian) */
  56. #define ICE1712_REG_MPU1_CTRL 0x0c /* byte */
  57. #define ICE1712_REG_MPU1_DATA 0x0d /* byte */
  58. #define ICE1712_REG_I2C_DEV_ADDR 0x10 /* byte */
  59. #define ICE1712_I2C_WRITE 0x01 /* write direction */
  60. #define ICE1712_REG_I2C_BYTE_ADDR 0x11 /* byte */
  61. #define ICE1712_REG_I2C_DATA 0x12 /* byte */
  62. #define ICE1712_REG_I2C_CTRL 0x13 /* byte */
  63. #define ICE1712_I2C_EEPROM 0x80 /* EEPROM exists */
  64. #define ICE1712_I2C_BUSY 0x01 /* busy bit */
  65. #define ICE1712_REG_CONCAP_ADDR 0x14 /* dword - consumer capture */
  66. #define ICE1712_REG_CONCAP_COUNT 0x18 /* word - current/base count */
  67. #define ICE1712_REG_SERR_SHADOW 0x1b /* byte */
  68. #define ICE1712_REG_MPU2_CTRL 0x1c /* byte */
  69. #define ICE1712_REG_MPU2_DATA 0x1d /* byte */
  70. #define ICE1712_REG_TIMER 0x1e /* word */
  71. /*
  72. * Indirect registers
  73. */
  74. #define ICE1712_IREG_PBK_COUNT_LO 0x00
  75. #define ICE1712_IREG_PBK_COUNT_HI 0x01
  76. #define ICE1712_IREG_PBK_CTRL 0x02
  77. #define ICE1712_IREG_PBK_LEFT 0x03 /* left volume */
  78. #define ICE1712_IREG_PBK_RIGHT 0x04 /* right volume */
  79. #define ICE1712_IREG_PBK_SOFT 0x05 /* soft volume */
  80. #define ICE1712_IREG_PBK_RATE_LO 0x06
  81. #define ICE1712_IREG_PBK_RATE_MID 0x07
  82. #define ICE1712_IREG_PBK_RATE_HI 0x08
  83. #define ICE1712_IREG_CAP_COUNT_LO 0x10
  84. #define ICE1712_IREG_CAP_COUNT_HI 0x11
  85. #define ICE1712_IREG_CAP_CTRL 0x12
  86. #define ICE1712_IREG_GPIO_DATA 0x20
  87. #define ICE1712_IREG_GPIO_WRITE_MASK 0x21
  88. #define ICE1712_IREG_GPIO_DIRECTION 0x22
  89. #define ICE1712_IREG_CONSUMER_POWERDOWN 0x30
  90. #define ICE1712_IREG_PRO_POWERDOWN 0x31
  91. /*
  92. * Consumer section direct DMA registers
  93. */
  94. #define ICEDS(ice, x) ((ice)->dmapath_port + ICE1712_DS_##x)
  95. #define ICE1712_DS_INTMASK 0x00 /* word - interrupt mask */
  96. #define ICE1712_DS_INTSTAT 0x02 /* word - interrupt status */
  97. #define ICE1712_DS_DATA 0x04 /* dword - channel data */
  98. #define ICE1712_DS_INDEX 0x08 /* dword - channel index */
  99. /*
  100. * Consumer section channel registers
  101. */
  102. #define ICE1712_DSC_ADDR0 0x00 /* dword - base address 0 */
  103. #define ICE1712_DSC_COUNT0 0x01 /* word - count 0 */
  104. #define ICE1712_DSC_ADDR1 0x02 /* dword - base address 1 */
  105. #define ICE1712_DSC_COUNT1 0x03 /* word - count 1 */
  106. #define ICE1712_DSC_CONTROL 0x04 /* byte - control & status */
  107. #define ICE1712_BUFFER1 0x80 /* buffer1 is active */
  108. #define ICE1712_BUFFER1_AUTO 0x40 /* buffer1 auto init */
  109. #define ICE1712_BUFFER0_AUTO 0x20 /* buffer0 auto init */
  110. #define ICE1712_FLUSH 0x10 /* flush FIFO */
  111. #define ICE1712_STEREO 0x08 /* stereo */
  112. #define ICE1712_16BIT 0x04 /* 16-bit data */
  113. #define ICE1712_PAUSE 0x02 /* pause */
  114. #define ICE1712_START 0x01 /* start */
  115. #define ICE1712_DSC_RATE 0x05 /* dword - rate */
  116. #define ICE1712_DSC_VOLUME 0x06 /* word - volume control */
  117. /*
  118. * Professional multi-track direct control registers
  119. */
  120. #define ICEMT(ice, x) ((ice)->profi_port + ICE1712_MT_##x)
  121. #define ICE1712_MT_IRQ 0x00 /* byte - interrupt mask */
  122. #define ICE1712_MULTI_CAPTURE 0x80 /* capture IRQ */
  123. #define ICE1712_MULTI_PLAYBACK 0x40 /* playback IRQ */
  124. #define ICE1712_MULTI_CAPSTATUS 0x02 /* capture IRQ status */
  125. #define ICE1712_MULTI_PBKSTATUS 0x01 /* playback IRQ status */
  126. #define ICE1712_MT_RATE 0x01 /* byte - sampling rate select */
  127. #define ICE1712_SPDIF_MASTER 0x10 /* S/PDIF input is master clock */
  128. #define ICE1712_MT_I2S_FORMAT 0x02 /* byte - I2S data format */
  129. #define ICE1712_MT_AC97_INDEX 0x04 /* byte - AC'97 index */
  130. #define ICE1712_MT_AC97_CMD 0x05 /* byte - AC'97 command & status */
  131. /* look to ICE1712_AC97_* */
  132. #define ICE1712_MT_AC97_DATA 0x06 /* word - AC'97 data */
  133. #define ICE1712_MT_PLAYBACK_ADDR 0x10 /* dword - playback address */
  134. #define ICE1712_MT_PLAYBACK_SIZE 0x14 /* word - playback size */
  135. #define ICE1712_MT_PLAYBACK_COUNT 0x16 /* word - playback count */
  136. #define ICE1712_MT_PLAYBACK_CONTROL 0x18 /* byte - control */
  137. #define ICE1712_CAPTURE_START_SHADOW 0x04 /* capture start */
  138. #define ICE1712_PLAYBACK_PAUSE 0x02 /* playback pause */
  139. #define ICE1712_PLAYBACK_START 0x01 /* playback start */
  140. #define ICE1712_MT_CAPTURE_ADDR 0x20 /* dword - capture address */
  141. #define ICE1712_MT_CAPTURE_SIZE 0x24 /* word - capture size */
  142. #define ICE1712_MT_CAPTURE_COUNT 0x26 /* word - capture count */
  143. #define ICE1712_MT_CAPTURE_CONTROL 0x28 /* byte - control */
  144. #define ICE1712_CAPTURE_START 0x01 /* capture start */
  145. #define ICE1712_MT_ROUTE_PSDOUT03 0x30 /* word */
  146. #define ICE1712_MT_ROUTE_SPDOUT 0x32 /* word */
  147. #define ICE1712_MT_ROUTE_CAPTURE 0x34 /* dword */
  148. #define ICE1712_MT_MONITOR_VOLUME 0x38 /* word */
  149. #define ICE1712_MT_MONITOR_INDEX 0x3a /* byte */
  150. #define ICE1712_MT_MONITOR_RATE 0x3b /* byte */
  151. #define ICE1712_MT_MONITOR_ROUTECTRL 0x3c /* byte */
  152. #define ICE1712_ROUTE_AC97 0x01 /* route digital mixer output to AC'97 */
  153. #define ICE1712_MT_MONITOR_PEAKINDEX 0x3e /* byte */
  154. #define ICE1712_MT_MONITOR_PEAKDATA 0x3f /* byte */
  155. /*
  156. * Codec configuration bits
  157. */
  158. /* PCI[60] System Configuration */
  159. #define ICE1712_CFG_CLOCK 0xc0
  160. #define ICE1712_CFG_CLOCK512 0x00 /* 22.5692Mhz, 44.1kHz*512 */
  161. #define ICE1712_CFG_CLOCK384 0x40 /* 16.9344Mhz, 44.1kHz*384 */
  162. #define ICE1712_CFG_EXT 0x80 /* external clock */
  163. #define ICE1712_CFG_2xMPU401 0x20 /* two MPU401 UARTs */
  164. #define ICE1712_CFG_NO_CON_AC97 0x10 /* consumer AC'97 codec is not present */
  165. #define ICE1712_CFG_ADC_MASK 0x0c /* one, two, three, four stereo ADCs */
  166. #define ICE1712_CFG_DAC_MASK 0x03 /* one, two, three, four stereo DACs */
  167. /* PCI[61] AC-Link Configuration */
  168. #define ICE1712_CFG_PRO_I2S 0x80 /* multitrack converter: I2S or AC'97 */
  169. #define ICE1712_CFG_AC97_PACKED 0x01 /* split or packed mode - AC'97 */
  170. /* PCI[62] I2S Features */
  171. #define ICE1712_CFG_I2S_VOLUME 0x80 /* volume/mute capability */
  172. #define ICE1712_CFG_I2S_96KHZ 0x40 /* supports 96kHz sampling */
  173. #define ICE1712_CFG_I2S_RESMASK 0x30 /* resolution mask, 16,18,20,24-bit */
  174. #define ICE1712_CFG_I2S_OTHER 0x0f /* other I2S IDs */
  175. /* PCI[63] S/PDIF Configuration */
  176. #define ICE1712_CFG_I2S_CHIPID 0xfc /* I2S chip ID */
  177. #define ICE1712_CFG_SPDIF_IN 0x02 /* S/PDIF input is present */
  178. #define ICE1712_CFG_SPDIF_OUT 0x01 /* S/PDIF output is present */
  179. /*
  180. * DMA mode values
  181. * identical with DMA_XXX on i386 architecture.
  182. */
  183. #define ICE1712_DMA_MODE_WRITE 0x48
  184. #define ICE1712_DMA_AUTOINIT 0x10
  185. /*
  186. * I2C EEPROM Address
  187. */
  188. #define ICE_I2C_EEPROM_ADDR 0xA0
  189. struct snd_ice1712;
  190. struct snd_ice1712_eeprom {
  191. unsigned int subvendor; /* PCI[2c-2f] */
  192. unsigned char size; /* size of EEPROM image in bytes */
  193. unsigned char version; /* must be 1 (or 2 for vt1724) */
  194. unsigned char data[32];
  195. unsigned int gpiomask;
  196. unsigned int gpiostate;
  197. unsigned int gpiodir;
  198. };
  199. enum {
  200. ICE_EEP1_CODEC = 0, /* 06 */
  201. ICE_EEP1_ACLINK, /* 07 */
  202. ICE_EEP1_I2SID, /* 08 */
  203. ICE_EEP1_SPDIF, /* 09 */
  204. ICE_EEP1_GPIO_MASK, /* 0a */
  205. ICE_EEP1_GPIO_STATE, /* 0b */
  206. ICE_EEP1_GPIO_DIR, /* 0c */
  207. ICE_EEP1_AC97_MAIN_LO, /* 0d */
  208. ICE_EEP1_AC97_MAIN_HI, /* 0e */
  209. ICE_EEP1_AC97_PCM_LO, /* 0f */
  210. ICE_EEP1_AC97_PCM_HI, /* 10 */
  211. ICE_EEP1_AC97_REC_LO, /* 11 */
  212. ICE_EEP1_AC97_REC_HI, /* 12 */
  213. ICE_EEP1_AC97_RECSRC, /* 13 */
  214. ICE_EEP1_DAC_ID, /* 14 */
  215. ICE_EEP1_DAC_ID1,
  216. ICE_EEP1_DAC_ID2,
  217. ICE_EEP1_DAC_ID3,
  218. ICE_EEP1_ADC_ID, /* 18 */
  219. ICE_EEP1_ADC_ID1,
  220. ICE_EEP1_ADC_ID2,
  221. ICE_EEP1_ADC_ID3
  222. };
  223. #define ice_has_con_ac97(ice) (!((ice)->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97))
  224. struct snd_ak4xxx_private {
  225. unsigned int cif:1; /* CIF mode */
  226. unsigned char caddr; /* C0 and C1 bits */
  227. unsigned int data_mask; /* DATA gpio bit */
  228. unsigned int clk_mask; /* CLK gpio bit */
  229. unsigned int cs_mask; /* bit mask for select/deselect address */
  230. unsigned int cs_addr; /* bits to select address */
  231. unsigned int cs_none; /* bits to deselect address */
  232. unsigned int add_flags; /* additional bits at init */
  233. unsigned int mask_flags; /* total mask bits */
  234. struct snd_akm4xxx_ops {
  235. void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
  236. } ops;
  237. };
  238. struct snd_ice1712_spdif {
  239. unsigned char cs8403_bits;
  240. unsigned char cs8403_stream_bits;
  241. struct snd_kcontrol *stream_ctl;
  242. struct snd_ice1712_spdif_ops {
  243. void (*open)(struct snd_ice1712 *, struct snd_pcm_substream *);
  244. void (*setup_rate)(struct snd_ice1712 *, int rate);
  245. void (*close)(struct snd_ice1712 *, struct snd_pcm_substream *);
  246. void (*default_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
  247. int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
  248. void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
  249. int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
  250. } ops;
  251. };
  252. struct snd_ice1712_card_info;
  253. struct snd_ice1712 {
  254. unsigned long conp_dma_size;
  255. unsigned long conc_dma_size;
  256. unsigned long prop_dma_size;
  257. unsigned long proc_dma_size;
  258. int irq;
  259. unsigned long port;
  260. unsigned long ddma_port;
  261. unsigned long dmapath_port;
  262. unsigned long profi_port;
  263. struct pci_dev *pci;
  264. struct snd_card *card;
  265. struct snd_pcm *pcm;
  266. struct snd_pcm *pcm_ds;
  267. struct snd_pcm *pcm_pro;
  268. struct snd_pcm_substream *playback_con_substream;
  269. struct snd_pcm_substream *playback_con_substream_ds[6];
  270. struct snd_pcm_substream *capture_con_substream;
  271. struct snd_pcm_substream *playback_pro_substream;
  272. struct snd_pcm_substream *capture_pro_substream;
  273. unsigned int playback_pro_size;
  274. unsigned int capture_pro_size;
  275. unsigned int playback_con_virt_addr[6];
  276. unsigned int playback_con_active_buf[6];
  277. unsigned int capture_con_virt_addr;
  278. unsigned int ac97_ext_id;
  279. struct snd_ac97 *ac97;
  280. struct snd_rawmidi *rmidi[2];
  281. spinlock_t reg_lock;
  282. struct snd_info_entry *proc_entry;
  283. struct snd_ice1712_eeprom eeprom;
  284. const struct snd_ice1712_card_info *card_info;
  285. unsigned int pro_volumes[20];
  286. unsigned int omni:1; /* Delta Omni I/O */
  287. unsigned int dxr_enable:1; /* Terratec DXR enable for DMX6FIRE */
  288. unsigned int vt1724:1;
  289. unsigned int vt1720:1;
  290. unsigned int has_spdif:1; /* VT1720/4 - has SPDIF I/O */
  291. unsigned int force_pdma4:1; /* VT1720/4 - PDMA4 as non-spdif */
  292. unsigned int force_rdma1:1; /* VT1720/4 - RDMA1 as non-spdif */
  293. unsigned int midi_output:1; /* VT1720/4: MIDI output triggered */
  294. unsigned int midi_input:1; /* VT1720/4: MIDI input triggered */
  295. unsigned int own_routing:1; /* VT1720/4: use own routing ctls */
  296. unsigned int num_total_dacs; /* total DACs */
  297. unsigned int num_total_adcs; /* total ADCs */
  298. unsigned int cur_rate; /* current rate */
  299. struct mutex open_mutex;
  300. struct snd_pcm_substream *pcm_reserved[4];
  301. const struct snd_pcm_hw_constraint_list *hw_rates; /* card-specific rate constraints */
  302. unsigned int akm_codecs;
  303. struct snd_akm4xxx *akm;
  304. struct snd_ice1712_spdif spdif;
  305. struct mutex i2c_mutex; /* I2C mutex for ICE1724 registers */
  306. struct snd_i2c_bus *i2c; /* I2C bus */
  307. struct snd_i2c_device *cs8427; /* CS8427 I2C device */
  308. unsigned int cs8427_timeout; /* CS8427 reset timeout in HZ/100 */
  309. struct ice1712_gpio {
  310. unsigned int direction; /* current direction bits */
  311. unsigned int write_mask; /* current mask bits */
  312. unsigned int saved[2]; /* for ewx_i2c */
  313. /* operators */
  314. void (*set_mask)(struct snd_ice1712 *ice, unsigned int data);
  315. unsigned int (*get_mask)(struct snd_ice1712 *ice);
  316. void (*set_dir)(struct snd_ice1712 *ice, unsigned int data);
  317. unsigned int (*get_dir)(struct snd_ice1712 *ice);
  318. void (*set_data)(struct snd_ice1712 *ice, unsigned int data);
  319. unsigned int (*get_data)(struct snd_ice1712 *ice);
  320. /* misc operators - move to another place? */
  321. void (*set_pro_rate)(struct snd_ice1712 *ice, unsigned int rate);
  322. void (*i2s_mclk_changed)(struct snd_ice1712 *ice);
  323. } gpio;
  324. struct mutex gpio_mutex;
  325. /* other board-specific data */
  326. void *spec;
  327. /* VT172x specific */
  328. int pro_rate_default;
  329. int (*is_spdif_master)(struct snd_ice1712 *ice);
  330. unsigned int (*get_rate)(struct snd_ice1712 *ice);
  331. void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
  332. unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
  333. int (*set_spdif_clock)(struct snd_ice1712 *ice, int type);
  334. int (*get_spdif_master_type)(struct snd_ice1712 *ice);
  335. const char * const *ext_clock_names;
  336. int ext_clock_count;
  337. void (*pro_open)(struct snd_ice1712 *, struct snd_pcm_substream *);
  338. #ifdef CONFIG_PM_SLEEP
  339. int (*pm_suspend)(struct snd_ice1712 *);
  340. int (*pm_resume)(struct snd_ice1712 *);
  341. unsigned int pm_suspend_enabled:1;
  342. unsigned int pm_saved_is_spdif_master:1;
  343. unsigned int pm_saved_spdif_ctrl;
  344. unsigned char pm_saved_spdif_cfg;
  345. unsigned int pm_saved_route;
  346. #endif
  347. };
  348. /*
  349. * gpio access functions
  350. */
  351. static inline void snd_ice1712_gpio_set_dir(struct snd_ice1712 *ice, unsigned int bits)
  352. {
  353. ice->gpio.set_dir(ice, bits);
  354. }
  355. static inline unsigned int snd_ice1712_gpio_get_dir(struct snd_ice1712 *ice)
  356. {
  357. return ice->gpio.get_dir(ice);
  358. }
  359. static inline void snd_ice1712_gpio_set_mask(struct snd_ice1712 *ice, unsigned int bits)
  360. {
  361. ice->gpio.set_mask(ice, bits);
  362. }
  363. static inline void snd_ice1712_gpio_write(struct snd_ice1712 *ice, unsigned int val)
  364. {
  365. ice->gpio.set_data(ice, val);
  366. }
  367. static inline unsigned int snd_ice1712_gpio_read(struct snd_ice1712 *ice)
  368. {
  369. return ice->gpio.get_data(ice);
  370. }
  371. /*
  372. * save and restore gpio status
  373. * The access to gpio will be protected by mutex, so don't forget to
  374. * restore!
  375. */
  376. static inline void snd_ice1712_save_gpio_status(struct snd_ice1712 *ice)
  377. {
  378. mutex_lock(&ice->gpio_mutex);
  379. ice->gpio.saved[0] = ice->gpio.direction;
  380. ice->gpio.saved[1] = ice->gpio.write_mask;
  381. }
  382. static inline void snd_ice1712_restore_gpio_status(struct snd_ice1712 *ice)
  383. {
  384. ice->gpio.set_dir(ice, ice->gpio.saved[0]);
  385. ice->gpio.set_mask(ice, ice->gpio.saved[1]);
  386. ice->gpio.direction = ice->gpio.saved[0];
  387. ice->gpio.write_mask = ice->gpio.saved[1];
  388. mutex_unlock(&ice->gpio_mutex);
  389. }
  390. /* for bit controls */
  391. #define ICE1712_GPIO(xiface, xname, xindex, mask, invert, xaccess) \
  392. { .iface = xiface, .name = xname, .access = xaccess, .info = snd_ctl_boolean_mono_info, \
  393. .get = snd_ice1712_gpio_get, .put = snd_ice1712_gpio_put, \
  394. .private_value = mask | (invert << 24) }
  395. int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
  396. int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
  397. /*
  398. * set gpio direction, write mask and data
  399. */
  400. static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice,
  401. unsigned int mask, unsigned int bits)
  402. {
  403. unsigned val;
  404. ice->gpio.direction |= mask;
  405. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  406. val = snd_ice1712_gpio_read(ice);
  407. val &= ~mask;
  408. val |= mask & bits;
  409. snd_ice1712_gpio_write(ice, val);
  410. }
  411. static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
  412. unsigned int mask)
  413. {
  414. ice->gpio.direction &= ~mask;
  415. snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
  416. return snd_ice1712_gpio_read(ice) & mask;
  417. }
  418. /* route access functions */
  419. int snd_ice1724_get_route_val(struct snd_ice1712 *ice, int shift);
  420. int snd_ice1724_put_route_val(struct snd_ice1712 *ice, unsigned int val,
  421. int shift);
  422. int snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice);
  423. int snd_ice1712_akm4xxx_init(struct snd_akm4xxx *ak,
  424. const struct snd_akm4xxx *template,
  425. const struct snd_ak4xxx_private *priv,
  426. struct snd_ice1712 *ice);
  427. void snd_ice1712_akm4xxx_free(struct snd_ice1712 *ice);
  428. int snd_ice1712_akm4xxx_build_controls(struct snd_ice1712 *ice);
  429. int snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr);
  430. static inline void snd_ice1712_write(struct snd_ice1712 *ice, u8 addr, u8 data)
  431. {
  432. outb(addr, ICEREG(ice, INDEX));
  433. outb(data, ICEREG(ice, DATA));
  434. }
  435. static inline u8 snd_ice1712_read(struct snd_ice1712 *ice, u8 addr)
  436. {
  437. outb(addr, ICEREG(ice, INDEX));
  438. return inb(ICEREG(ice, DATA));
  439. }
  440. /*
  441. * entry pointer
  442. */
  443. struct snd_ice1712_card_info {
  444. unsigned int subvendor;
  445. const char *name;
  446. const char *model;
  447. const char *driver;
  448. int (*chip_init)(struct snd_ice1712 *);
  449. void (*chip_exit)(struct snd_ice1712 *);
  450. int (*build_controls)(struct snd_ice1712 *);
  451. unsigned int no_mpu401:1;
  452. unsigned int mpu401_1_info_flags;
  453. unsigned int mpu401_2_info_flags;
  454. const char *mpu401_1_name;
  455. const char *mpu401_2_name;
  456. const unsigned int eeprom_size;
  457. const unsigned char *eeprom_data;
  458. };
  459. #endif /* __SOUND_ICE1712_H */