xonar_pcm179x.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * card driver for models with PCM1796 DACs (Xonar D2/D2X/HDAV1.3/ST/STX)
  3. *
  4. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  5. *
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License, version 2.
  9. *
  10. * This driver is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this driver; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. * Xonar D2/D2X
  20. * ------------
  21. *
  22. * CMI8788:
  23. *
  24. * SPI 0 -> 1st PCM1796 (front)
  25. * SPI 1 -> 2nd PCM1796 (surround)
  26. * SPI 2 -> 3rd PCM1796 (center/LFE)
  27. * SPI 4 -> 4th PCM1796 (back)
  28. *
  29. * GPIO 2 -> M0 of CS5381
  30. * GPIO 3 -> M1 of CS5381
  31. * GPIO 5 <- external power present (D2X only)
  32. * GPIO 7 -> ALT
  33. * GPIO 8 -> enable output to speakers
  34. *
  35. * CM9780:
  36. *
  37. * LINE_OUT -> input of ADC
  38. *
  39. * AUX_IN <- aux
  40. * VIDEO_IN <- CD
  41. * FMIC_IN <- mic
  42. *
  43. * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
  44. */
  45. /*
  46. * Xonar HDAV1.3 (Deluxe)
  47. * ----------------------
  48. *
  49. * CMI8788:
  50. *
  51. * I²C <-> PCM1796 (addr 1001100) (front)
  52. *
  53. * GPI 0 <- external power present
  54. *
  55. * GPIO 0 -> enable HDMI (0) or speaker (1) output
  56. * GPIO 2 -> M0 of CS5381
  57. * GPIO 3 -> M1 of CS5381
  58. * GPIO 4 <- daughterboard detection
  59. * GPIO 5 <- daughterboard detection
  60. * GPIO 6 -> ?
  61. * GPIO 7 -> ?
  62. * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
  63. *
  64. * UART <-> HDMI controller
  65. *
  66. * CM9780:
  67. *
  68. * LINE_OUT -> input of ADC
  69. *
  70. * AUX_IN <- aux
  71. * CD_IN <- CD
  72. * MIC_IN <- mic
  73. *
  74. * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
  75. *
  76. * no daughterboard
  77. * ----------------
  78. *
  79. * GPIO 4 <- 1
  80. *
  81. * H6 daughterboard
  82. * ----------------
  83. *
  84. * GPIO 4 <- 0
  85. * GPIO 5 <- 0
  86. *
  87. * I²C <-> PCM1796 (addr 1001101) (surround)
  88. * <-> PCM1796 (addr 1001110) (center/LFE)
  89. * <-> PCM1796 (addr 1001111) (back)
  90. *
  91. * unknown daughterboard
  92. * ---------------------
  93. *
  94. * GPIO 4 <- 0
  95. * GPIO 5 <- 1
  96. *
  97. * I²C <-> CS4362A (addr 0011000) (surround, center/LFE, back)
  98. */
  99. /*
  100. * Xonar Essence ST (Deluxe)/STX (II)
  101. * ----------------------------------
  102. *
  103. * CMI8788:
  104. *
  105. * I²C <-> PCM1792A (addr 1001100)
  106. * <-> CS2000 (addr 1001110) (ST only)
  107. *
  108. * ADC1 MCLK -> REF_CLK of CS2000 (ST only)
  109. *
  110. * GPI 0 <- external power present (STX only)
  111. *
  112. * GPIO 0 -> enable output to speakers
  113. * GPIO 1 -> route HP to front panel (0) or rear jack (1)
  114. * GPIO 2 -> M0 of CS5381
  115. * GPIO 3 -> M1 of CS5381
  116. * GPIO 4 <- daughterboard detection
  117. * GPIO 5 <- daughterboard detection
  118. * GPIO 6 -> ?
  119. * GPIO 7 -> route output to speaker jacks (0) or HP (1)
  120. * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
  121. *
  122. * PCM1792A:
  123. *
  124. * SCK <- CLK_OUT of CS2000 (ST only)
  125. *
  126. * CM9780:
  127. *
  128. * LINE_OUT -> input of ADC
  129. *
  130. * AUX_IN <- aux
  131. * MIC_IN <- mic
  132. *
  133. * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
  134. *
  135. * H6 daughterboard
  136. * ----------------
  137. *
  138. * GPIO 4 <- 0
  139. * GPIO 5 <- 0
  140. */
  141. /*
  142. * Xonar Xense
  143. * -----------
  144. *
  145. * CMI8788:
  146. *
  147. * I²C <-> PCM1796 (addr 1001100) (front)
  148. * <-> CS4362A (addr 0011000) (surround, center/LFE, back)
  149. * <-> CS2000 (addr 1001110)
  150. *
  151. * ADC1 MCLK -> REF_CLK of CS2000
  152. *
  153. * GPI 0 <- external power present
  154. *
  155. * GPIO 0 -> enable output
  156. * GPIO 1 -> route HP to front panel (0) or rear jack (1)
  157. * GPIO 2 -> M0 of CS5381
  158. * GPIO 3 -> M1 of CS5381
  159. * GPIO 4 -> enable output
  160. * GPIO 5 -> enable output
  161. * GPIO 6 -> ?
  162. * GPIO 7 -> route output to HP (0) or speaker (1)
  163. * GPIO 8 -> route input jack to mic-in (0) or line-in (1)
  164. *
  165. * CM9780:
  166. *
  167. * LINE_OUT -> input of ADC
  168. *
  169. * AUX_IN <- aux
  170. * VIDEO_IN <- ?
  171. * FMIC_IN <- mic
  172. *
  173. * GPO 0 -> route line-in (0) or AC97 output (1) to CS5381 input
  174. * GPO 1 -> route mic-in from input jack (0) or front panel header (1)
  175. */
  176. #include <linux/pci.h>
  177. #include <linux/delay.h>
  178. #include <linux/mutex.h>
  179. #include <sound/ac97_codec.h>
  180. #include <sound/control.h>
  181. #include <sound/core.h>
  182. #include <sound/info.h>
  183. #include <sound/pcm.h>
  184. #include <sound/pcm_params.h>
  185. #include <sound/tlv.h>
  186. #include "xonar.h"
  187. #include "cm9780.h"
  188. #include "pcm1796.h"
  189. #include "cs2000.h"
  190. #define GPIO_D2X_EXT_POWER 0x0020
  191. #define GPIO_D2_ALT 0x0080
  192. #define GPIO_D2_OUTPUT_ENABLE 0x0100
  193. #define GPI_EXT_POWER 0x01
  194. #define GPIO_INPUT_ROUTE 0x0100
  195. #define GPIO_HDAV_OUTPUT_ENABLE 0x0001
  196. #define GPIO_HDAV_MAGIC 0x00c0
  197. #define GPIO_DB_MASK 0x0030
  198. #define GPIO_DB_H6 0x0000
  199. #define GPIO_ST_OUTPUT_ENABLE 0x0001
  200. #define GPIO_ST_HP_REAR 0x0002
  201. #define GPIO_ST_MAGIC 0x0040
  202. #define GPIO_ST_HP 0x0080
  203. #define GPIO_XENSE_OUTPUT_ENABLE (0x0001 | 0x0010 | 0x0020)
  204. #define GPIO_XENSE_SPEAKERS 0x0080
  205. #define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ii, /W=0 */
  206. #define I2C_DEVICE_CS2000 0x9c /* 100111, 0, /W=0 */
  207. #define PCM1796_REG_BASE 16
  208. struct xonar_pcm179x {
  209. struct xonar_generic generic;
  210. unsigned int dacs;
  211. u8 pcm1796_regs[4][5];
  212. unsigned int current_rate;
  213. bool h6;
  214. bool hp_active;
  215. s8 hp_gain_offset;
  216. bool has_cs2000;
  217. u8 cs2000_regs[0x1f];
  218. bool broken_i2c;
  219. };
  220. struct xonar_hdav {
  221. struct xonar_pcm179x pcm179x;
  222. struct xonar_hdmi hdmi;
  223. };
  224. static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
  225. u8 reg, u8 value)
  226. {
  227. /* maps ALSA channel pair number to SPI output */
  228. static const u8 codec_map[4] = {
  229. 0, 1, 2, 4
  230. };
  231. oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
  232. OXYGEN_SPI_DATA_LENGTH_2 |
  233. OXYGEN_SPI_CLOCK_160 |
  234. (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
  235. OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
  236. (reg << 8) | value);
  237. }
  238. static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
  239. u8 reg, u8 value)
  240. {
  241. oxygen_write_i2c(chip, I2C_DEVICE_PCM1796(codec), reg, value);
  242. }
  243. static void pcm1796_write(struct oxygen *chip, unsigned int codec,
  244. u8 reg, u8 value)
  245. {
  246. struct xonar_pcm179x *data = chip->model_data;
  247. if ((chip->model.function_flags & OXYGEN_FUNCTION_2WIRE_SPI_MASK) ==
  248. OXYGEN_FUNCTION_SPI)
  249. pcm1796_write_spi(chip, codec, reg, value);
  250. else
  251. pcm1796_write_i2c(chip, codec, reg, value);
  252. if ((unsigned int)(reg - PCM1796_REG_BASE)
  253. < ARRAY_SIZE(data->pcm1796_regs[codec]))
  254. data->pcm1796_regs[codec][reg - PCM1796_REG_BASE] = value;
  255. }
  256. static void pcm1796_write_cached(struct oxygen *chip, unsigned int codec,
  257. u8 reg, u8 value)
  258. {
  259. struct xonar_pcm179x *data = chip->model_data;
  260. if (value != data->pcm1796_regs[codec][reg - PCM1796_REG_BASE])
  261. pcm1796_write(chip, codec, reg, value);
  262. }
  263. static void cs2000_write(struct oxygen *chip, u8 reg, u8 value)
  264. {
  265. struct xonar_pcm179x *data = chip->model_data;
  266. oxygen_write_i2c(chip, I2C_DEVICE_CS2000, reg, value);
  267. data->cs2000_regs[reg] = value;
  268. }
  269. static void cs2000_write_cached(struct oxygen *chip, u8 reg, u8 value)
  270. {
  271. struct xonar_pcm179x *data = chip->model_data;
  272. if (value != data->cs2000_regs[reg])
  273. cs2000_write(chip, reg, value);
  274. }
  275. static void pcm1796_registers_init(struct oxygen *chip)
  276. {
  277. struct xonar_pcm179x *data = chip->model_data;
  278. unsigned int i;
  279. s8 gain_offset;
  280. msleep(1);
  281. gain_offset = data->hp_active ? data->hp_gain_offset : 0;
  282. for (i = 0; i < data->dacs; ++i) {
  283. /* set ATLD before ATL/ATR */
  284. pcm1796_write(chip, i, 18,
  285. data->pcm1796_regs[0][18 - PCM1796_REG_BASE]);
  286. pcm1796_write(chip, i, 16, chip->dac_volume[i * 2]
  287. + gain_offset);
  288. pcm1796_write(chip, i, 17, chip->dac_volume[i * 2 + 1]
  289. + gain_offset);
  290. pcm1796_write(chip, i, 19,
  291. data->pcm1796_regs[0][19 - PCM1796_REG_BASE]);
  292. pcm1796_write(chip, i, 20,
  293. data->pcm1796_regs[0][20 - PCM1796_REG_BASE]);
  294. pcm1796_write(chip, i, 21, 0);
  295. gain_offset = 0;
  296. }
  297. }
  298. static void pcm1796_init(struct oxygen *chip)
  299. {
  300. struct xonar_pcm179x *data = chip->model_data;
  301. data->pcm1796_regs[0][18 - PCM1796_REG_BASE] =
  302. PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
  303. if (!data->broken_i2c)
  304. data->pcm1796_regs[0][18 - PCM1796_REG_BASE] |= PCM1796_MUTE;
  305. data->pcm1796_regs[0][19 - PCM1796_REG_BASE] =
  306. PCM1796_FLT_SHARP | PCM1796_ATS_1;
  307. data->pcm1796_regs[0][20 - PCM1796_REG_BASE] =
  308. data->h6 ? PCM1796_OS_64 : PCM1796_OS_128;
  309. pcm1796_registers_init(chip);
  310. data->current_rate = 48000;
  311. }
  312. static void xonar_d2_init(struct oxygen *chip)
  313. {
  314. struct xonar_pcm179x *data = chip->model_data;
  315. data->generic.anti_pop_delay = 300;
  316. data->generic.output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
  317. data->dacs = 4;
  318. pcm1796_init(chip);
  319. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
  320. oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
  321. oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
  322. xonar_init_cs53x1(chip);
  323. xonar_enable_output(chip);
  324. snd_component_add(chip->card, "PCM1796");
  325. snd_component_add(chip->card, "CS5381");
  326. }
  327. static void xonar_d2x_init(struct oxygen *chip)
  328. {
  329. struct xonar_pcm179x *data = chip->model_data;
  330. data->generic.ext_power_reg = OXYGEN_GPIO_DATA;
  331. data->generic.ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
  332. data->generic.ext_power_bit = GPIO_D2X_EXT_POWER;
  333. oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
  334. xonar_init_ext_power(chip);
  335. xonar_d2_init(chip);
  336. }
  337. static void xonar_hdav_init(struct oxygen *chip)
  338. {
  339. struct xonar_hdav *data = chip->model_data;
  340. oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
  341. OXYGEN_2WIRE_LENGTH_8 |
  342. OXYGEN_2WIRE_INTERRUPT_MASK |
  343. OXYGEN_2WIRE_SPEED_STANDARD);
  344. data->pcm179x.generic.anti_pop_delay = 100;
  345. data->pcm179x.generic.output_enable_bit = GPIO_HDAV_OUTPUT_ENABLE;
  346. data->pcm179x.generic.ext_power_reg = OXYGEN_GPI_DATA;
  347. data->pcm179x.generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
  348. data->pcm179x.generic.ext_power_bit = GPI_EXT_POWER;
  349. data->pcm179x.dacs = chip->model.dac_channels_mixer / 2;
  350. data->pcm179x.h6 = chip->model.dac_channels_mixer > 2;
  351. pcm1796_init(chip);
  352. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
  353. GPIO_HDAV_MAGIC | GPIO_INPUT_ROUTE);
  354. oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_INPUT_ROUTE);
  355. xonar_init_cs53x1(chip);
  356. xonar_init_ext_power(chip);
  357. xonar_hdmi_init(chip, &data->hdmi);
  358. xonar_enable_output(chip);
  359. snd_component_add(chip->card, "PCM1796");
  360. snd_component_add(chip->card, "CS5381");
  361. }
  362. static void xonar_st_init_i2c(struct oxygen *chip)
  363. {
  364. oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
  365. OXYGEN_2WIRE_LENGTH_8 |
  366. OXYGEN_2WIRE_INTERRUPT_MASK |
  367. OXYGEN_2WIRE_SPEED_STANDARD);
  368. }
  369. static void xonar_st_init_common(struct oxygen *chip)
  370. {
  371. struct xonar_pcm179x *data = chip->model_data;
  372. data->generic.output_enable_bit = GPIO_ST_OUTPUT_ENABLE;
  373. data->dacs = chip->model.dac_channels_mixer / 2;
  374. data->h6 = chip->model.dac_channels_mixer > 2;
  375. data->hp_gain_offset = 2*-18;
  376. pcm1796_init(chip);
  377. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
  378. GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
  379. GPIO_ST_MAGIC | GPIO_ST_HP);
  380. oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
  381. GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
  382. xonar_init_cs53x1(chip);
  383. xonar_enable_output(chip);
  384. snd_component_add(chip->card, "PCM1792A");
  385. snd_component_add(chip->card, "CS5381");
  386. }
  387. static void cs2000_registers_init(struct oxygen *chip)
  388. {
  389. struct xonar_pcm179x *data = chip->model_data;
  390. cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_FREEZE);
  391. cs2000_write(chip, CS2000_DEV_CTRL, 0);
  392. cs2000_write(chip, CS2000_DEV_CFG_1,
  393. CS2000_R_MOD_SEL_1 |
  394. (0 << CS2000_R_SEL_SHIFT) |
  395. CS2000_AUX_OUT_SRC_REF_CLK |
  396. CS2000_EN_DEV_CFG_1);
  397. cs2000_write(chip, CS2000_DEV_CFG_2,
  398. (0 << CS2000_LOCK_CLK_SHIFT) |
  399. CS2000_FRAC_N_SRC_STATIC);
  400. cs2000_write(chip, CS2000_RATIO_0 + 0, 0x00); /* 1.0 */
  401. cs2000_write(chip, CS2000_RATIO_0 + 1, 0x10);
  402. cs2000_write(chip, CS2000_RATIO_0 + 2, 0x00);
  403. cs2000_write(chip, CS2000_RATIO_0 + 3, 0x00);
  404. cs2000_write(chip, CS2000_FUN_CFG_1,
  405. data->cs2000_regs[CS2000_FUN_CFG_1]);
  406. cs2000_write(chip, CS2000_FUN_CFG_2, 0);
  407. cs2000_write(chip, CS2000_GLOBAL_CFG, CS2000_EN_DEV_CFG_2);
  408. msleep(3); /* PLL lock delay */
  409. }
  410. static void xonar_st_init(struct oxygen *chip)
  411. {
  412. struct xonar_pcm179x *data = chip->model_data;
  413. data->generic.anti_pop_delay = 100;
  414. data->h6 = chip->model.dac_channels_mixer > 2;
  415. data->has_cs2000 = 1;
  416. data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
  417. data->broken_i2c = true;
  418. oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
  419. OXYGEN_RATE_48000 |
  420. OXYGEN_I2S_FORMAT_I2S |
  421. OXYGEN_I2S_MCLK(data->h6 ? MCLK_256 : MCLK_512) |
  422. OXYGEN_I2S_BITS_16 |
  423. OXYGEN_I2S_MASTER |
  424. OXYGEN_I2S_BCLK_64);
  425. xonar_st_init_i2c(chip);
  426. cs2000_registers_init(chip);
  427. xonar_st_init_common(chip);
  428. snd_component_add(chip->card, "CS2000");
  429. }
  430. static void xonar_stx_init(struct oxygen *chip)
  431. {
  432. struct xonar_pcm179x *data = chip->model_data;
  433. xonar_st_init_i2c(chip);
  434. data->generic.anti_pop_delay = 800;
  435. data->generic.ext_power_reg = OXYGEN_GPI_DATA;
  436. data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
  437. data->generic.ext_power_bit = GPI_EXT_POWER;
  438. xonar_init_ext_power(chip);
  439. xonar_st_init_common(chip);
  440. }
  441. static void xonar_xense_init(struct oxygen *chip)
  442. {
  443. struct xonar_pcm179x *data = chip->model_data;
  444. data->generic.ext_power_reg = OXYGEN_GPI_DATA;
  445. data->generic.ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
  446. data->generic.ext_power_bit = GPI_EXT_POWER;
  447. xonar_init_ext_power(chip);
  448. data->generic.anti_pop_delay = 100;
  449. data->has_cs2000 = 1;
  450. data->cs2000_regs[CS2000_FUN_CFG_1] = CS2000_REF_CLK_DIV_1;
  451. oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
  452. OXYGEN_RATE_48000 |
  453. OXYGEN_I2S_FORMAT_I2S |
  454. OXYGEN_I2S_MCLK(MCLK_512) |
  455. OXYGEN_I2S_BITS_16 |
  456. OXYGEN_I2S_MASTER |
  457. OXYGEN_I2S_BCLK_64);
  458. xonar_st_init_i2c(chip);
  459. cs2000_registers_init(chip);
  460. data->generic.output_enable_bit = GPIO_XENSE_OUTPUT_ENABLE;
  461. data->dacs = 1;
  462. data->hp_gain_offset = 2*-18;
  463. pcm1796_init(chip);
  464. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
  465. GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
  466. GPIO_ST_MAGIC | GPIO_XENSE_SPEAKERS);
  467. oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
  468. GPIO_INPUT_ROUTE | GPIO_ST_HP_REAR |
  469. GPIO_XENSE_SPEAKERS);
  470. xonar_init_cs53x1(chip);
  471. xonar_enable_output(chip);
  472. snd_component_add(chip->card, "PCM1796");
  473. snd_component_add(chip->card, "CS5381");
  474. snd_component_add(chip->card, "CS2000");
  475. }
  476. static void xonar_d2_cleanup(struct oxygen *chip)
  477. {
  478. xonar_disable_output(chip);
  479. }
  480. static void xonar_hdav_cleanup(struct oxygen *chip)
  481. {
  482. xonar_hdmi_cleanup(chip);
  483. xonar_disable_output(chip);
  484. msleep(2);
  485. }
  486. static void xonar_st_cleanup(struct oxygen *chip)
  487. {
  488. xonar_disable_output(chip);
  489. }
  490. static void xonar_d2_suspend(struct oxygen *chip)
  491. {
  492. xonar_d2_cleanup(chip);
  493. }
  494. static void xonar_hdav_suspend(struct oxygen *chip)
  495. {
  496. xonar_hdav_cleanup(chip);
  497. }
  498. static void xonar_st_suspend(struct oxygen *chip)
  499. {
  500. xonar_st_cleanup(chip);
  501. }
  502. static void xonar_d2_resume(struct oxygen *chip)
  503. {
  504. pcm1796_registers_init(chip);
  505. xonar_enable_output(chip);
  506. }
  507. static void xonar_hdav_resume(struct oxygen *chip)
  508. {
  509. struct xonar_hdav *data = chip->model_data;
  510. pcm1796_registers_init(chip);
  511. xonar_hdmi_resume(chip, &data->hdmi);
  512. xonar_enable_output(chip);
  513. }
  514. static void xonar_stx_resume(struct oxygen *chip)
  515. {
  516. pcm1796_registers_init(chip);
  517. xonar_enable_output(chip);
  518. }
  519. static void xonar_st_resume(struct oxygen *chip)
  520. {
  521. cs2000_registers_init(chip);
  522. xonar_stx_resume(chip);
  523. }
  524. static void update_pcm1796_oversampling(struct oxygen *chip)
  525. {
  526. struct xonar_pcm179x *data = chip->model_data;
  527. unsigned int i;
  528. u8 reg;
  529. if (data->current_rate <= 48000 && !data->h6)
  530. reg = PCM1796_OS_128;
  531. else
  532. reg = PCM1796_OS_64;
  533. for (i = 0; i < data->dacs; ++i)
  534. pcm1796_write_cached(chip, i, 20, reg);
  535. }
  536. static void set_pcm1796_params(struct oxygen *chip,
  537. struct snd_pcm_hw_params *params)
  538. {
  539. struct xonar_pcm179x *data = chip->model_data;
  540. msleep(1);
  541. data->current_rate = params_rate(params);
  542. update_pcm1796_oversampling(chip);
  543. }
  544. static void update_pcm1796_volume(struct oxygen *chip)
  545. {
  546. struct xonar_pcm179x *data = chip->model_data;
  547. unsigned int i;
  548. s8 gain_offset;
  549. gain_offset = data->hp_active ? data->hp_gain_offset : 0;
  550. for (i = 0; i < data->dacs; ++i) {
  551. pcm1796_write_cached(chip, i, 16, chip->dac_volume[i * 2]
  552. + gain_offset);
  553. pcm1796_write_cached(chip, i, 17, chip->dac_volume[i * 2 + 1]
  554. + gain_offset);
  555. gain_offset = 0;
  556. }
  557. }
  558. static void update_pcm1796_mute(struct oxygen *chip)
  559. {
  560. struct xonar_pcm179x *data = chip->model_data;
  561. unsigned int i;
  562. u8 value;
  563. value = PCM1796_DMF_DISABLED | PCM1796_FMT_24_I2S | PCM1796_ATLD;
  564. if (chip->dac_mute)
  565. value |= PCM1796_MUTE;
  566. for (i = 0; i < data->dacs; ++i)
  567. pcm1796_write_cached(chip, i, 18, value);
  568. }
  569. static void update_cs2000_rate(struct oxygen *chip, unsigned int rate)
  570. {
  571. struct xonar_pcm179x *data = chip->model_data;
  572. u8 rate_mclk, reg;
  573. switch (rate) {
  574. case 32000:
  575. case 64000:
  576. rate_mclk = OXYGEN_RATE_32000;
  577. break;
  578. case 44100:
  579. case 88200:
  580. case 176400:
  581. rate_mclk = OXYGEN_RATE_44100;
  582. break;
  583. default:
  584. case 48000:
  585. case 96000:
  586. case 192000:
  587. rate_mclk = OXYGEN_RATE_48000;
  588. break;
  589. }
  590. if (rate <= 96000 && (rate > 48000 || data->h6)) {
  591. rate_mclk |= OXYGEN_I2S_MCLK(MCLK_256);
  592. reg = CS2000_REF_CLK_DIV_1;
  593. } else {
  594. rate_mclk |= OXYGEN_I2S_MCLK(MCLK_512);
  595. reg = CS2000_REF_CLK_DIV_2;
  596. }
  597. oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, rate_mclk,
  598. OXYGEN_I2S_RATE_MASK | OXYGEN_I2S_MCLK_MASK);
  599. cs2000_write_cached(chip, CS2000_FUN_CFG_1, reg);
  600. msleep(3); /* PLL lock delay */
  601. }
  602. static void set_st_params(struct oxygen *chip,
  603. struct snd_pcm_hw_params *params)
  604. {
  605. update_cs2000_rate(chip, params_rate(params));
  606. set_pcm1796_params(chip, params);
  607. }
  608. static void set_hdav_params(struct oxygen *chip,
  609. struct snd_pcm_hw_params *params)
  610. {
  611. struct xonar_hdav *data = chip->model_data;
  612. set_pcm1796_params(chip, params);
  613. xonar_set_hdmi_params(chip, &data->hdmi, params);
  614. }
  615. static const struct snd_kcontrol_new alt_switch = {
  616. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  617. .name = "Analog Loopback Switch",
  618. .info = snd_ctl_boolean_mono_info,
  619. .get = xonar_gpio_bit_switch_get,
  620. .put = xonar_gpio_bit_switch_put,
  621. .private_value = GPIO_D2_ALT,
  622. };
  623. static int rolloff_info(struct snd_kcontrol *ctl,
  624. struct snd_ctl_elem_info *info)
  625. {
  626. static const char *const names[2] = {
  627. "Sharp Roll-off", "Slow Roll-off"
  628. };
  629. return snd_ctl_enum_info(info, 1, 2, names);
  630. }
  631. static int rolloff_get(struct snd_kcontrol *ctl,
  632. struct snd_ctl_elem_value *value)
  633. {
  634. struct oxygen *chip = ctl->private_data;
  635. struct xonar_pcm179x *data = chip->model_data;
  636. value->value.enumerated.item[0] =
  637. (data->pcm1796_regs[0][19 - PCM1796_REG_BASE] &
  638. PCM1796_FLT_MASK) != PCM1796_FLT_SHARP;
  639. return 0;
  640. }
  641. static int rolloff_put(struct snd_kcontrol *ctl,
  642. struct snd_ctl_elem_value *value)
  643. {
  644. struct oxygen *chip = ctl->private_data;
  645. struct xonar_pcm179x *data = chip->model_data;
  646. unsigned int i;
  647. int changed;
  648. u8 reg;
  649. mutex_lock(&chip->mutex);
  650. reg = data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
  651. reg &= ~PCM1796_FLT_MASK;
  652. if (!value->value.enumerated.item[0])
  653. reg |= PCM1796_FLT_SHARP;
  654. else
  655. reg |= PCM1796_FLT_SLOW;
  656. changed = reg != data->pcm1796_regs[0][19 - PCM1796_REG_BASE];
  657. if (changed) {
  658. for (i = 0; i < data->dacs; ++i)
  659. pcm1796_write(chip, i, 19, reg);
  660. }
  661. mutex_unlock(&chip->mutex);
  662. return changed;
  663. }
  664. static const struct snd_kcontrol_new rolloff_control = {
  665. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  666. .name = "DAC Filter Playback Enum",
  667. .info = rolloff_info,
  668. .get = rolloff_get,
  669. .put = rolloff_put,
  670. };
  671. static const struct snd_kcontrol_new hdav_hdmi_control = {
  672. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  673. .name = "HDMI Playback Switch",
  674. .info = snd_ctl_boolean_mono_info,
  675. .get = xonar_gpio_bit_switch_get,
  676. .put = xonar_gpio_bit_switch_put,
  677. .private_value = GPIO_HDAV_OUTPUT_ENABLE | XONAR_GPIO_BIT_INVERT,
  678. };
  679. static int st_output_switch_info(struct snd_kcontrol *ctl,
  680. struct snd_ctl_elem_info *info)
  681. {
  682. static const char *const names[3] = {
  683. "Speakers", "Headphones", "FP Headphones"
  684. };
  685. return snd_ctl_enum_info(info, 1, 3, names);
  686. }
  687. static int st_output_switch_get(struct snd_kcontrol *ctl,
  688. struct snd_ctl_elem_value *value)
  689. {
  690. struct oxygen *chip = ctl->private_data;
  691. u16 gpio;
  692. gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
  693. if (!(gpio & GPIO_ST_HP))
  694. value->value.enumerated.item[0] = 0;
  695. else if (gpio & GPIO_ST_HP_REAR)
  696. value->value.enumerated.item[0] = 1;
  697. else
  698. value->value.enumerated.item[0] = 2;
  699. return 0;
  700. }
  701. static int st_output_switch_put(struct snd_kcontrol *ctl,
  702. struct snd_ctl_elem_value *value)
  703. {
  704. struct oxygen *chip = ctl->private_data;
  705. struct xonar_pcm179x *data = chip->model_data;
  706. u16 gpio_old, gpio;
  707. mutex_lock(&chip->mutex);
  708. gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
  709. gpio = gpio_old;
  710. switch (value->value.enumerated.item[0]) {
  711. case 0:
  712. gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
  713. break;
  714. case 1:
  715. gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
  716. break;
  717. case 2:
  718. gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
  719. break;
  720. }
  721. oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
  722. data->hp_active = gpio & GPIO_ST_HP;
  723. update_pcm1796_volume(chip);
  724. mutex_unlock(&chip->mutex);
  725. return gpio != gpio_old;
  726. }
  727. static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
  728. struct snd_ctl_elem_info *info)
  729. {
  730. static const char *const names[4] = {
  731. "< 32 ohms", "32-64 ohms", "64-300 ohms", "300-600 ohms"
  732. };
  733. return snd_ctl_enum_info(info, 1, 4, names);
  734. }
  735. static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
  736. struct snd_ctl_elem_value *value)
  737. {
  738. struct oxygen *chip = ctl->private_data;
  739. struct xonar_pcm179x *data = chip->model_data;
  740. mutex_lock(&chip->mutex);
  741. if (data->hp_gain_offset < 2*-12)
  742. value->value.enumerated.item[0] = 0;
  743. else if (data->hp_gain_offset < 2*-6)
  744. value->value.enumerated.item[0] = 1;
  745. else if (data->hp_gain_offset < 0)
  746. value->value.enumerated.item[0] = 2;
  747. else
  748. value->value.enumerated.item[0] = 3;
  749. mutex_unlock(&chip->mutex);
  750. return 0;
  751. }
  752. static int st_hp_volume_offset_put(struct snd_kcontrol *ctl,
  753. struct snd_ctl_elem_value *value)
  754. {
  755. static const s8 offsets[] = { 2*-18, 2*-12, 2*-6, 0 };
  756. struct oxygen *chip = ctl->private_data;
  757. struct xonar_pcm179x *data = chip->model_data;
  758. s8 offset;
  759. int changed;
  760. if (value->value.enumerated.item[0] > 3)
  761. return -EINVAL;
  762. offset = offsets[value->value.enumerated.item[0]];
  763. mutex_lock(&chip->mutex);
  764. changed = offset != data->hp_gain_offset;
  765. if (changed) {
  766. data->hp_gain_offset = offset;
  767. update_pcm1796_volume(chip);
  768. }
  769. mutex_unlock(&chip->mutex);
  770. return changed;
  771. }
  772. static const struct snd_kcontrol_new st_controls[] = {
  773. {
  774. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  775. .name = "Analog Output",
  776. .info = st_output_switch_info,
  777. .get = st_output_switch_get,
  778. .put = st_output_switch_put,
  779. },
  780. {
  781. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  782. .name = "Headphones Impedance Playback Enum",
  783. .info = st_hp_volume_offset_info,
  784. .get = st_hp_volume_offset_get,
  785. .put = st_hp_volume_offset_put,
  786. },
  787. };
  788. static int xense_output_switch_get(struct snd_kcontrol *ctl,
  789. struct snd_ctl_elem_value *value)
  790. {
  791. struct oxygen *chip = ctl->private_data;
  792. u16 gpio;
  793. gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
  794. if (gpio & GPIO_XENSE_SPEAKERS)
  795. value->value.enumerated.item[0] = 0;
  796. else if (!(gpio & GPIO_XENSE_SPEAKERS) && (gpio & GPIO_ST_HP_REAR))
  797. value->value.enumerated.item[0] = 1;
  798. else
  799. value->value.enumerated.item[0] = 2;
  800. return 0;
  801. }
  802. static int xense_output_switch_put(struct snd_kcontrol *ctl,
  803. struct snd_ctl_elem_value *value)
  804. {
  805. struct oxygen *chip = ctl->private_data;
  806. struct xonar_pcm179x *data = chip->model_data;
  807. u16 gpio_old, gpio;
  808. mutex_lock(&chip->mutex);
  809. gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
  810. gpio = gpio_old;
  811. switch (value->value.enumerated.item[0]) {
  812. case 0:
  813. gpio |= GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR;
  814. break;
  815. case 1:
  816. gpio = (gpio | GPIO_ST_HP_REAR) & ~GPIO_XENSE_SPEAKERS;
  817. break;
  818. case 2:
  819. gpio &= ~(GPIO_XENSE_SPEAKERS | GPIO_ST_HP_REAR);
  820. break;
  821. }
  822. oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
  823. data->hp_active = !(gpio & GPIO_XENSE_SPEAKERS);
  824. update_pcm1796_volume(chip);
  825. mutex_unlock(&chip->mutex);
  826. return gpio != gpio_old;
  827. }
  828. static const struct snd_kcontrol_new xense_controls[] = {
  829. {
  830. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  831. .name = "Analog Output",
  832. .info = st_output_switch_info,
  833. .get = xense_output_switch_get,
  834. .put = xense_output_switch_put,
  835. },
  836. {
  837. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  838. .name = "Headphones Impedance Playback Enum",
  839. .info = st_hp_volume_offset_info,
  840. .get = st_hp_volume_offset_get,
  841. .put = st_hp_volume_offset_put,
  842. },
  843. };
  844. static void xonar_line_mic_ac97_switch(struct oxygen *chip,
  845. unsigned int reg, unsigned int mute)
  846. {
  847. if (reg == AC97_LINE) {
  848. spin_lock_irq(&chip->reg_lock);
  849. oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
  850. mute ? GPIO_INPUT_ROUTE : 0,
  851. GPIO_INPUT_ROUTE);
  852. spin_unlock_irq(&chip->reg_lock);
  853. }
  854. }
  855. static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
  856. static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
  857. {
  858. if (!strncmp(template->name, "CD Capture ", 11))
  859. /* CD in is actually connected to the video in pin */
  860. template->private_value ^= AC97_CD ^ AC97_VIDEO;
  861. return 0;
  862. }
  863. static int xonar_st_h6_control_filter(struct snd_kcontrol_new *template)
  864. {
  865. if (!strncmp(template->name, "Master Playback ", 16))
  866. /* no volume/mute, as I²C to the third DAC does not work */
  867. return 1;
  868. return 0;
  869. }
  870. static int add_pcm1796_controls(struct oxygen *chip)
  871. {
  872. struct xonar_pcm179x *data = chip->model_data;
  873. int err;
  874. if (!data->broken_i2c) {
  875. err = snd_ctl_add(chip->card,
  876. snd_ctl_new1(&rolloff_control, chip));
  877. if (err < 0)
  878. return err;
  879. }
  880. return 0;
  881. }
  882. static int xonar_d2_mixer_init(struct oxygen *chip)
  883. {
  884. int err;
  885. err = snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
  886. if (err < 0)
  887. return err;
  888. err = add_pcm1796_controls(chip);
  889. if (err < 0)
  890. return err;
  891. return 0;
  892. }
  893. static int xonar_hdav_mixer_init(struct oxygen *chip)
  894. {
  895. int err;
  896. err = snd_ctl_add(chip->card, snd_ctl_new1(&hdav_hdmi_control, chip));
  897. if (err < 0)
  898. return err;
  899. err = add_pcm1796_controls(chip);
  900. if (err < 0)
  901. return err;
  902. return 0;
  903. }
  904. static int xonar_st_mixer_init(struct oxygen *chip)
  905. {
  906. unsigned int i;
  907. int err;
  908. for (i = 0; i < ARRAY_SIZE(st_controls); ++i) {
  909. err = snd_ctl_add(chip->card,
  910. snd_ctl_new1(&st_controls[i], chip));
  911. if (err < 0)
  912. return err;
  913. }
  914. err = add_pcm1796_controls(chip);
  915. if (err < 0)
  916. return err;
  917. return 0;
  918. }
  919. static int xonar_xense_mixer_init(struct oxygen *chip)
  920. {
  921. unsigned int i;
  922. int err;
  923. for (i = 0; i < ARRAY_SIZE(xense_controls); ++i) {
  924. err = snd_ctl_add(chip->card,
  925. snd_ctl_new1(&xense_controls[i], chip));
  926. if (err < 0)
  927. return err;
  928. }
  929. err = add_pcm1796_controls(chip);
  930. if (err < 0)
  931. return err;
  932. return 0;
  933. }
  934. static void dump_pcm1796_registers(struct oxygen *chip,
  935. struct snd_info_buffer *buffer)
  936. {
  937. struct xonar_pcm179x *data = chip->model_data;
  938. unsigned int dac, i;
  939. for (dac = 0; dac < data->dacs; ++dac) {
  940. snd_iprintf(buffer, "\nPCM1796 %u:", dac + 1);
  941. for (i = 0; i < 5; ++i)
  942. snd_iprintf(buffer, " %02x",
  943. data->pcm1796_regs[dac][i]);
  944. }
  945. snd_iprintf(buffer, "\n");
  946. }
  947. static void dump_cs2000_registers(struct oxygen *chip,
  948. struct snd_info_buffer *buffer)
  949. {
  950. struct xonar_pcm179x *data = chip->model_data;
  951. unsigned int i;
  952. if (data->has_cs2000) {
  953. snd_iprintf(buffer, "\nCS2000:\n00: ");
  954. for (i = 1; i < 0x10; ++i)
  955. snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
  956. snd_iprintf(buffer, "\n10:");
  957. for (i = 0x10; i < 0x1f; ++i)
  958. snd_iprintf(buffer, " %02x", data->cs2000_regs[i]);
  959. snd_iprintf(buffer, "\n");
  960. }
  961. }
  962. static void dump_st_registers(struct oxygen *chip,
  963. struct snd_info_buffer *buffer)
  964. {
  965. dump_pcm1796_registers(chip, buffer);
  966. dump_cs2000_registers(chip, buffer);
  967. }
  968. static const struct oxygen_model model_xonar_d2 = {
  969. .longname = "Asus Virtuoso 200",
  970. .chip = "AV200",
  971. .init = xonar_d2_init,
  972. .control_filter = xonar_d2_control_filter,
  973. .mixer_init = xonar_d2_mixer_init,
  974. .cleanup = xonar_d2_cleanup,
  975. .suspend = xonar_d2_suspend,
  976. .resume = xonar_d2_resume,
  977. .set_dac_params = set_pcm1796_params,
  978. .set_adc_params = xonar_set_cs53x1_params,
  979. .update_dac_volume = update_pcm1796_volume,
  980. .update_dac_mute = update_pcm1796_mute,
  981. .dump_registers = dump_pcm1796_registers,
  982. .dac_tlv = pcm1796_db_scale,
  983. .model_data_size = sizeof(struct xonar_pcm179x),
  984. .device_config = PLAYBACK_0_TO_I2S |
  985. PLAYBACK_1_TO_SPDIF |
  986. CAPTURE_0_FROM_I2S_2 |
  987. CAPTURE_1_FROM_SPDIF |
  988. MIDI_OUTPUT |
  989. MIDI_INPUT |
  990. AC97_CD_INPUT,
  991. .dac_channels_pcm = 8,
  992. .dac_channels_mixer = 8,
  993. .dac_volume_min = 255 - 2*60,
  994. .dac_volume_max = 255,
  995. .misc_flags = OXYGEN_MISC_MIDI,
  996. .function_flags = OXYGEN_FUNCTION_SPI |
  997. OXYGEN_FUNCTION_ENABLE_SPI_4_5,
  998. .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
  999. .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
  1000. .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
  1001. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  1002. };
  1003. static const struct oxygen_model model_xonar_hdav = {
  1004. .longname = "Asus Virtuoso 200",
  1005. .chip = "AV200",
  1006. .init = xonar_hdav_init,
  1007. .mixer_init = xonar_hdav_mixer_init,
  1008. .cleanup = xonar_hdav_cleanup,
  1009. .suspend = xonar_hdav_suspend,
  1010. .resume = xonar_hdav_resume,
  1011. .pcm_hardware_filter = xonar_hdmi_pcm_hardware_filter,
  1012. .set_dac_params = set_hdav_params,
  1013. .set_adc_params = xonar_set_cs53x1_params,
  1014. .update_dac_volume = update_pcm1796_volume,
  1015. .update_dac_mute = update_pcm1796_mute,
  1016. .uart_input = xonar_hdmi_uart_input,
  1017. .ac97_switch = xonar_line_mic_ac97_switch,
  1018. .dump_registers = dump_pcm1796_registers,
  1019. .dac_tlv = pcm1796_db_scale,
  1020. .model_data_size = sizeof(struct xonar_hdav),
  1021. .device_config = PLAYBACK_0_TO_I2S |
  1022. PLAYBACK_1_TO_SPDIF |
  1023. CAPTURE_0_FROM_I2S_2 |
  1024. CAPTURE_1_FROM_SPDIF,
  1025. .dac_channels_pcm = 8,
  1026. .dac_channels_mixer = 2,
  1027. .dac_volume_min = 255 - 2*60,
  1028. .dac_volume_max = 255,
  1029. .misc_flags = OXYGEN_MISC_MIDI,
  1030. .function_flags = OXYGEN_FUNCTION_2WIRE,
  1031. .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
  1032. .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
  1033. .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
  1034. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  1035. };
  1036. static const struct oxygen_model model_xonar_st = {
  1037. .longname = "Asus Virtuoso 100",
  1038. .chip = "AV200",
  1039. .init = xonar_st_init,
  1040. .mixer_init = xonar_st_mixer_init,
  1041. .cleanup = xonar_st_cleanup,
  1042. .suspend = xonar_st_suspend,
  1043. .resume = xonar_st_resume,
  1044. .set_dac_params = set_st_params,
  1045. .set_adc_params = xonar_set_cs53x1_params,
  1046. .update_dac_volume = update_pcm1796_volume,
  1047. .update_dac_mute = update_pcm1796_mute,
  1048. .ac97_switch = xonar_line_mic_ac97_switch,
  1049. .dump_registers = dump_st_registers,
  1050. .dac_tlv = pcm1796_db_scale,
  1051. .model_data_size = sizeof(struct xonar_pcm179x),
  1052. .device_config = PLAYBACK_0_TO_I2S |
  1053. PLAYBACK_1_TO_SPDIF |
  1054. CAPTURE_0_FROM_I2S_2 |
  1055. CAPTURE_1_FROM_SPDIF |
  1056. AC97_FMIC_SWITCH,
  1057. .dac_channels_pcm = 2,
  1058. .dac_channels_mixer = 2,
  1059. .dac_volume_min = 255 - 2*60,
  1060. .dac_volume_max = 255,
  1061. .function_flags = OXYGEN_FUNCTION_2WIRE,
  1062. .dac_mclks = OXYGEN_MCLKS(512, 128, 128),
  1063. .adc_mclks = OXYGEN_MCLKS(256, 128, 128),
  1064. .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
  1065. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  1066. };
  1067. int get_xonar_pcm179x_model(struct oxygen *chip,
  1068. const struct pci_device_id *id)
  1069. {
  1070. switch (id->subdevice) {
  1071. case 0x8269:
  1072. chip->model = model_xonar_d2;
  1073. chip->model.shortname = "Xonar D2";
  1074. break;
  1075. case 0x82b7:
  1076. chip->model = model_xonar_d2;
  1077. chip->model.shortname = "Xonar D2X";
  1078. chip->model.init = xonar_d2x_init;
  1079. break;
  1080. case 0x8314:
  1081. chip->model = model_xonar_hdav;
  1082. oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
  1083. switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
  1084. default:
  1085. chip->model.shortname = "Xonar HDAV1.3";
  1086. break;
  1087. case GPIO_DB_H6:
  1088. chip->model.shortname = "Xonar HDAV1.3+H6";
  1089. chip->model.dac_channels_mixer = 8;
  1090. chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
  1091. break;
  1092. }
  1093. break;
  1094. case 0x835d:
  1095. chip->model = model_xonar_st;
  1096. oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
  1097. switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
  1098. default:
  1099. chip->model.shortname = "Xonar ST";
  1100. break;
  1101. case GPIO_DB_H6:
  1102. chip->model.shortname = "Xonar ST+H6";
  1103. chip->model.control_filter = xonar_st_h6_control_filter;
  1104. chip->model.dac_channels_pcm = 8;
  1105. chip->model.dac_channels_mixer = 8;
  1106. chip->model.dac_volume_min = 255;
  1107. chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
  1108. break;
  1109. }
  1110. break;
  1111. case 0x835c:
  1112. chip->model = model_xonar_st;
  1113. chip->model.shortname = "Xonar STX";
  1114. chip->model.init = xonar_stx_init;
  1115. chip->model.resume = xonar_stx_resume;
  1116. chip->model.set_dac_params = set_pcm1796_params;
  1117. break;
  1118. case 0x85f4:
  1119. chip->model = model_xonar_st;
  1120. oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_DB_MASK);
  1121. switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DB_MASK) {
  1122. default:
  1123. chip->model.shortname = "Xonar STX II";
  1124. break;
  1125. case GPIO_DB_H6:
  1126. chip->model.shortname = "Xonar STX II+H6";
  1127. chip->model.dac_channels_pcm = 8;
  1128. chip->model.dac_channels_mixer = 8;
  1129. chip->model.dac_mclks = OXYGEN_MCLKS(256, 128, 128);
  1130. break;
  1131. }
  1132. chip->model.init = xonar_stx_init;
  1133. chip->model.resume = xonar_stx_resume;
  1134. chip->model.set_dac_params = set_pcm1796_params;
  1135. break;
  1136. case 0x8428:
  1137. chip->model = model_xonar_st;
  1138. chip->model.shortname = "Xonar Xense";
  1139. chip->model.chip = "AV100";
  1140. chip->model.init = xonar_xense_init;
  1141. chip->model.mixer_init = xonar_xense_mixer_init;
  1142. break;
  1143. default:
  1144. return -EINVAL;
  1145. }
  1146. return 0;
  1147. }